]> git.saurik.com Git - apple/xnu.git/blob - iokit/DriverKit/IOBufferMemoryDescriptor.iig
449d66ea549d9b7f872194a5dde77324ae7c0023
[apple/xnu.git] / iokit / DriverKit / IOBufferMemoryDescriptor.iig
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 * Methods in this class are used for memory that was supplied as a parameter.
50 * IOBufferMemoryDescriptor can be handed to any API that expects an IOMemoryDescriptor.
51 */
52
53 class KERNEL IOBufferMemoryDescriptor : public IOMemoryDescriptor
54 {
55 public:
56
57 /*!
58 * @brief Create an IOBufferMemoryDescriptor.
59 * @param options Pass the flags kIOMemoryDirectionIn, kIOMemoryDirectionOut or kIOMemoryDirectionOutIn
60 * to set the direction of the i/o
61 * @param capacity Maximum length of the memory buffer. The descriptor has no valid data
62 * and zero length until set with SetLength().
63 * @param memory Created descriptor with +1 retain count to be released by the caller.
64 * @param alignment For small less-than-page-size buffers, control the alignment of the memory buffer.
65 * Pass zero for no guaranteed alignment.
66 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
67 */
68 static kern_return_t
69 Create(
70 uint64_t options,
71 uint64_t capacity,
72 uint64_t alignment,
73 IOBufferMemoryDescriptor ** memory);
74
75 virtual bool
76 init() override;
77
78 virtual void
79 free() override;
80
81 /*!
82 * @brief Obtain the address and length of the memory buffer.
83 * @param range An IOAddressSegment structure filled out with the address and length of the memory buffer.
84 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
85 */
86 kern_return_t
87 GetAddressRange(IOAddressSegment * range) LOCALONLY;
88
89 /*!
90 * @brief Set the valid length of the memory buffer.
91 * @discussion IOBufferMemoryDescriptor have capacity allocated at Create() but no valid data until set
92 * with this method.
93 * @param length New valid length of the memory described.
94 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
95 */
96 virtual kern_return_t
97 SetLength(uint64_t length);
98 };
99
100 #endif /* ! _IOKIT_UIOBUFFERMEMORYDESCRIPTOR_H */