1/*
2 * Copyright (c) 1998-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 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
30 *
31 * HISTORY
32 *
33 */
34
35#ifndef _IOKIT_IODEVICEMEMORY_H
36#define _IOKIT_IODEVICEMEMORY_H
37
38#include <IOKit/IOMemoryDescriptor.h>
39#include <libkern/c++/OSPtr.h>
40
41/*! @class IODeviceMemory
42 * @abstract An IOMemoryDescriptor used for device physical memory ranges.
43 * @discussion The IODeviceMemory class is a simple subclass of IOMemoryDescriptor that uses its methods to describe a single range of physical memory on a device. IODeviceMemory objects are usually looked up with IOService or IOPCIDevice accessors, and are created by memory-mapped bus families. IODeviceMemory implements only some factory methods in addition to the methods of IOMemoryDescriptor.
44 */
45
46class IODeviceMemory : public IOMemoryDescriptor
47{
48 OSDeclareDefaultStructors(IODeviceMemory);
49
50public:
51
52/*! @struct InitElement
53 * @field start First physical address in the range.
54 * @field length Length of the range.
55 * @field tag 32-bit value not interpreted by IODeviceMemory or IOMemoryDescriptor, for use by the bus family. */
56
57 struct InitElement {
58 IOPhysicalAddress start;
59 IOPhysicalLength length;
60 IOOptionBits tag;
61 };
62
63/*! @function arrayFromList
64 * @abstract Constructs an OSArray of IODeviceMemory instances, each describing one physical range, and a tag value.
65 * @discussion This method creates IODeviceMemory instances for each physical range passed in an IODeviceMemory::InitElement array. Each element consists of a physical address, length and tag value for the IODeviceMemory. The instances are returned as a created OSArray.
66 * @param list An array of IODeviceMemory::InitElement structures.
67 * @param count The number of elements in the list.
68 * @result Returns a created OSArray of IODeviceMemory objects, to be released by the caller, or zero on failure. */
69
70 static OSPtr<OSArray> arrayFromList(
71 InitElement list[],
72 IOItemCount count );
73
74/*! @function withRange
75 * @abstract Constructs an IODeviceMemory instance, describing one physical range.
76 * @discussion This method creates an IODeviceMemory instance for one physical range passed as a physical address and length. It just calls IOMemoryDescriptor::withPhysicalAddress.
77 * @param start The physical address of the first byte in the memory.
78 * @param length The length of memory.
79 * @result Returns the created IODeviceMemory on success, to be released by the caller, or zero on failure. */
80
81 static OSPtr<IODeviceMemory> withRange(
82 IOPhysicalAddress start,
83 IOPhysicalLength length );
84
85/*! @function withSubRange
86 * @abstract Constructs an IODeviceMemory instance, describing a subset of an existing IODeviceMemory range.
87 * @discussion This method creates an IODeviceMemory instance for a subset of an existing IODeviceMemory range, passed as a physical address offset and length. It just calls IOMemoryDescriptor::withSubRange.
88 * @param of The parent IODeviceMemory of which a subrange is to be used for the new descriptor, which will be retained by the subrange IODeviceMemory.
89 * @param offset A byte offset into the parent's memory.
90 * @param length The length of the subrange.
91 * @result Returns the created IODeviceMemory on success, to be released by the caller, or zero on failure. */
92
93 static OSPtr<IODeviceMemory> withSubRange(
94 IODeviceMemory * of,
95 IOPhysicalAddress offset,
96 IOPhysicalLength length );
97};
98
99#endif /* ! _IOKIT_IODEVICEMEMORY_H */
100