1/*
2 * Copyright (c) 2019-2019 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#if !__IIG
30#if KERNEL
31#include <IOKit/IOBufferMemoryDescriptor.h>
32#endif
33#endif
34
35
36#ifndef _IOKIT_UIOBUFFERMEMORYDESCRIPTOR_H
37#define _IOKIT_UIOBUFFERMEMORYDESCRIPTOR_H
38
39#include <DriverKit/IOMemoryDescriptor.iig>
40
41/*!
42 * @class IOBufferMemoryDescriptor
43 *
44 * @abstract
45 * IOBufferMemoryDescriptor describes a memory buffer allocated in the callers address space.
46 *
47 * @discussion
48 * To allocate memory for I/O or sharing, use IOBufferMemoryDescriptor::Create().
49 * IOBufferMemoryDescriptor can be handed to any API that expects an IOMemoryDescriptor.
50 */
51
52class KERNEL IOBufferMemoryDescriptor : public IOMemoryDescriptor
53{
54public:
55
56    /*!
57     * @brief       Create an IOBufferMemoryDescriptor.
58     * @param       options Pass the flags 	kIOMemoryDirectionIn, kIOMemoryDirectionOut or kIOMemoryDirectionOutIn
59     *              to set the direction of the i/o
60     * @param       capacity Maximum length of the memory buffer. The descriptor has no valid data
61     *              and zero length until set with SetLength().
62     * @param       memory Created descriptor with +1 retain count to be released by the caller.
63     * @param       alignment For small less-than-page-size buffers, control the alignment of the memory buffer.
64     *              Pass zero for no guaranteed alignment.
65     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
66     */
67	static kern_return_t
68	Create(
69		uint64_t options,
70		uint64_t capacity,
71		uint64_t alignment,
72		IOBufferMemoryDescriptor ** memory);
73
74	virtual bool
75	init() override;
76
77	virtual void
78	free() override;
79
80    /*!
81     * @brief       Obtain the address and length of the memory buffer.
82     * @param       range An IOAddressSegment structure filled out with the address and length of the memory buffer.
83     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
84     */
85	kern_return_t
86	GetAddressRange(IOAddressSegment * range) LOCALONLY;
87
88    /*!
89     * @brief       Set the valid length of the memory buffer.
90     * @discussion  IOBufferMemoryDescriptor have capacity allocated at Create() but no valid data until set
91     *              with this method.
92     * @param       length New valid length of the memory described.
93     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
94     */
95	virtual kern_return_t
96	SetLength(uint64_t length);
97};
98
99#endif /* ! _IOKIT_UIOBUFFERMEMORYDESCRIPTOR_H */
100