|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*
26: * Copyright (c) 1993, 1994 NeXT Computer, Inc.
27: *
28: * Exported interface for Kernel Bus Resource Object(s).
29: *
30: * HISTORY
31: *
32: * 1 Jul 1994 ? at NeXT
33: * Modifications to support shared interrupts.
34: * 16 Mar 1994 ? at NeXT
35: * Added range mapping.
36: * 24 Feb 1994 ? at NeXT
37: * Major rewrite.
38: * 29 Oct 1993 ? at NeXT
39: * Created.
40: */
41:
42: #ifdef DRIVER_PRIVATE
43:
44: #import <objc/Object.h>
45:
46: #import <mach/mach_types.h>
47:
48: /*
49: * The item object can be used to
50: * allocate a small number (max 1024)
51: * of items { base, base + count },
52: * individually. The only
53: * constraint placed upon this
54: * range is that it may not
55: * wrap around.
56: */
57:
58: @interface KernBusItemResource : Object
59: {
60: @private
61: id _owner;
62: unsigned int _count;
63: unsigned int _base;
64: id _kind;
65: int _itemCount;
66: void *_items;
67: }
68:
69: - initWithItemCount: (unsigned int)count
70: itemBase: (unsigned int)base
71: itemKind: kind
72: owner: owner;
73: - initWithItemCount: (unsigned int)count
74: itemKind: kind
75: owner: owner;
76:
77: - reserveItem: (unsigned int)item;
78: - shareItem: (unsigned int)item;
79:
80: - (unsigned int)findFreeItem;
81:
82: @end
83:
84: @interface KernBusItem : Object
85: {
86: @private
87: id _resource;
88: unsigned int _item;
89: int _useCount;
90: BOOL _shareable;
91: }
92:
93: - initForResource: resource
94: item: (unsigned int)item
95: shareable: (BOOL)shareable;
96: - dealloc;
97:
98: - share;
99: - (unsigned int)item;
100:
101: @end
102:
103: /*
104: * The range object is used to allocate
105: * ranges of values in a large,
106: * potentially sparse address space.
107: * It does support the full range
108: * of address values, where a full
109: * range {0, maxunsigned int + 1} is
110: * denoted as (Range) { 0, 0 }.
111: */
112:
113: typedef struct _Range {
114: unsigned int base;
115: unsigned int length;
116: } Range;
117:
118: #define RangeMAX ((Range) { 0, 0 })
119:
120: static __inline__
121: BOOL
122: rangeIsValid(
123: Range range
124: )
125: {
126: unsigned int end = range.base + range.length;
127:
128: if (end > 0 && end <= range.base)
129: return NO;
130:
131: return YES;
132: }
133:
134: @interface KernBusRangeResource : Object
135: {
136: @private
137: id _owner;
138: unsigned int _base;
139: unsigned int _end;
140: id _kind;
141: int _rangeCount;
142: void *_ranges;
143: }
144:
145: - initWithExtent: (Range)extent
146: kind: kind
147: owner: owner;
148:
149: - reserveRange: (Range)range;
150: - shareRange: (Range)range;
151:
152: - (Range)findFreeRangeWithSize:(unsigned int)size
153: alignment:(unsigned int)align;
154:
155: @end
156:
157: @interface KernBusRange : Object
158: {
159: @private
160: void *_next;
161: id _resource;
162: unsigned int _base;
163: unsigned int _end;
164: int _useCount;
165: BOOL _shareable;
166: int _mappingCount;
167: }
168:
169: - initForResource: resource
170: range: (Range)range
171: shareable: (BOOL)shareable;
172: - dealloc;
173:
174: - share;
175: - (Range)range;
176:
177: @end
178:
179: /*
180: * A mapping is basically an
181: * an alias for a range.
182: * Multiple mappings for a
183: * particular range can be
184: * created, and each one
185: * can refer either to the
186: * entire range, or only a
187: * portion of it.
188: */
189:
190: @interface KernBusRangeMapping : Object
191: {
192: @private
193: id _range;
194: Range _mappedRange;
195: }
196:
197: - initWithRange: range
198: subRange: (Range)subRange;
199:
200: - (Range)mappedRange;
201:
202: @end
203:
204: /*
205: * The generic bus object is
206: * available for subclassing by
207: * specific bus architectures.
208: * The bus object defines the
209: * system resources (interrupt
210: * sources, dma channels,
211: * physical memory regions,
212: * io port ranges), which
213: * need to be allocated among
214: * the device drivers.
215: */
216:
217: @interface KernBus : Object
218: {
219: @private
220: void *_resources;
221: int _activeResourceCount;
222: int _busId;
223: }
224:
225: - (BOOL)areResourcesActive;
226:
227: /*
228: * Returns a NULL-terminated array of the names of resources
229: * defined by this bus.
230: */
231: - (const char **)resourceNames;
232:
233: /*
234: * Creates a KernDeviceDescription from an IOConfigTable.
235: */
236: + deviceDescriptionFromConfigTable:table;
237:
238: /*
239: * Allocates resource objects for a device description.
240: * Returns the device description.
241: */
242: - allocateResourcesForDeviceDescription:descr;
243:
244: - _insertResource: object withKey: (const char *)key;
245: - _deleteResourceWithKey: (const char *)key;
246: - _lookupResourceWithKey: (const char *)key;
247:
248: + registerBusClass:busClass name:(char *)name;
249: + registerBusInstance:busInstance name:(char *)busName busId:(int)index;
250: + lookupBusClassWithName:(char *)name;
251: + lookupBusInstanceWithName:(char *)busName busId:(int)index;
252:
253: /*
254: * Returns NO if the bus does not want to configure the driver.
255: */
256: + (BOOL)configureDriverWithTable:configTable;
257:
258: - (int)busId;
259: - (void)setBusId:(int)busId;
260:
261: /*
262: * Called when bus is detected, before drivers are probed
263: */
264: + (BOOL)probeBus:configTable;
265:
266: @end
267:
268: /*
269: * Classes which implement
270: * hardware bus interrupts
271: * must adopt this protocol.
272: */
273:
274: @protocol KernBusInterrupt
275:
276: - attachDeviceInterrupt: deviceInterrupt;
277: - attachDeviceInterrupt: deviceInterrupt
278: atLevel: (int)level;
279: - detachDeviceInterrupt: deviceInterrupt;
280:
281: - suspend;
282: - resume;
283:
284: @end
285:
286: #endif /* DRIVER_PRIVATE */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.