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