|
|
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: /* Copyright (c) 1993 NeXT Computer, Inc. All rights reserved.
25: *
26: * IODeviceDescription.m.
27: *
28: * HISTORY
29: * 08-Jan-93 Doug Mitchell at NeXT
30: * Created.
31: */
32:
33: #import <objc/List.h>
34: #import <driverkit/IODeviceDescription.h>
35: #import <driverkit/IODeviceDescriptionPrivate.h>
36: #import <driverkit/KernBus.h>
37: #import <driverkit/KernDeviceDescription.h>
38:
39: struct _private {
40: unsigned int *interrupts;
41: unsigned int numInterrupts;
42: IORange *memoryRanges;
43: unsigned int numMemoryRanges;
44: };
45:
46: @implementation IODeviceDescription
47:
48: - init
49: {
50: return [self _initWithDelegate:nil];
51: }
52:
53: - free
54: {
55: struct _private *private = _private;
56:
57: if (private->numInterrupts > 0)
58: IOFree(private->interrupts,
59: private->numInterrupts * sizeof (*private->interrupts));
60: if (private->numMemoryRanges > 0)
61: IOFree(private->memoryRanges,
62: private->numMemoryRanges * sizeof (*private->memoryRanges));
63: IOFree(private, sizeof (*private));
64:
65: if (_devicePort != PORT_NULL)
66: destroy_dev_port(_devicePort); // XXX
67:
68: return [super free];
69: }
70:
71: - (port_t)devicePort
72: {
73: return _devicePort;
74: }
75:
76: - (void)setDevicePort: (port_t)devicePort
77: {
78: _devicePort = devicePort;
79: }
80:
81: - directDevice
82: {
83: return _directDevice;
84: }
85:
86: - (void)setDirectDevice: directDevice
87: {
88: _directDevice = directDevice;
89: }
90:
91: - (void)setConfigTable: (IOConfigTable *)configTable
92: {
93: /* nop */
94: }
95:
96: - (IOConfigTable *)configTable
97: {
98: return [_delegate configTable];
99: }
100:
101: - getDevicePath:(char *)path maxLength:(int)maxLen useAlias:(BOOL)doAlias
102: {
103: return( NULL);
104: }
105:
106: - (char *) matchDevicePath:(char *)matchPath
107: {
108: return( NULL);
109: }
110:
111: @end
112:
113: @implementation IODeviceDescription(IOInterrupt)
114: - (unsigned int) interrupt
115: {
116: return [self interruptList][0];
117: }
118:
119: - (unsigned int *) interruptList
120: {
121: struct _private *private = _private;
122:
123: if (private->numInterrupts == 0)
124: private->interrupts = [self
125: _fetchItemList:[[self _delegate]
126: resourcesForKey:IRQ_LEVELS_KEY]
127: returnedNum:&private->numInterrupts];
128: return private->interrupts;
129: }
130:
131: - (unsigned int) numInterrupts
132: {
133: struct _private *private = _private;
134:
135: if (private->numInterrupts == 0)
136: private->interrupts = [self
137: _fetchItemList:[[self _delegate]
138: resourcesForKey:IRQ_LEVELS_KEY]
139: returnedNum:&private->numInterrupts];
140: return private->numInterrupts;
141: }
142:
143: - (IOReturn) setInterruptList:(unsigned int *)aList num:(unsigned int) length
144: {
145: IOReturn ret = IO_R_RESOURCE;
146:
147: if ([[self _delegate]
148: allocateItems:aList numItems:length
149: forKey:IRQ_LEVELS_KEY] != nil) {
150:
151: struct _private *private = (struct _private *)_private;
152: if (private->numInterrupts > 0)
153: IOFree(private->interrupts,
154: private->numInterrupts * sizeof (*private->interrupts));
155: private->numInterrupts = 0;
156: ret = IO_R_SUCCESS;
157: }
158: return ret;
159: }
160: @end
161:
162: @implementation IODeviceDescription(IOMemory)
163: - (IORange *) memoryRangeList
164: {
165: struct _private *private = _private;
166:
167: if (private->numMemoryRanges == 0)
168: private->memoryRanges =
169: [self
170: _fetchRangeList:[[self _delegate]
171: resourcesForKey:MEM_MAPS_KEY]
172: returnedNum:&private->numMemoryRanges];
173: return private->memoryRanges;
174: }
175:
176: - (unsigned int) numMemoryRanges
177: {
178: struct _private *private = _private;
179:
180: if (private->numMemoryRanges == 0)
181: private->memoryRanges =
182: [self
183: _fetchRangeList:[[self _delegate]
184: resourcesForKey:MEM_MAPS_KEY]
185: returnedNum:&private->numMemoryRanges];
186: return private->numMemoryRanges;
187: }
188:
189: - (IOReturn) setMemoryRangeList:(IORange *)aList num:(unsigned int) length
190: {
191: IOReturn ret = IO_R_RESOURCE;
192: Range *ranges;
193: int i;
194:
195: ranges = (Range *)IOMalloc(sizeof(Range) * length);
196: for (i=0; i<length; i++) {
197: ranges[i].base = aList[i].start;
198: ranges[i].length = aList[i].size;
199: }
200: if ([[self _delegate]
201: allocateRanges:ranges numRanges:length forKey:MEM_MAPS_KEY]
202: != nil) {
203:
204: struct _private *private = (struct _private *)_private;
205: if (private->numMemoryRanges > 0)
206: IOFree(private->memoryRanges,
207: private->numMemoryRanges * sizeof (*private->memoryRanges));
208: private->numMemoryRanges = 0;
209: ret = IO_R_SUCCESS;
210: }
211: IOFree(ranges, sizeof(Range) * length);
212: return ret;
213: }
214:
215: @end
216:
217: @implementation IODeviceDescription(Private)
218:
219: - _initWithDelegate:delegate
220: {
221: _private = (void *)IOMalloc(sizeof (struct _private));
222: bzero(_private, sizeof (struct _private));
223:
224: _delegate = delegate;
225:
226: return self;
227: }
228:
229: - _delegate
230: {
231: return _delegate;
232: }
233:
234: - _deviceClass
235: {
236: return nil;
237: }
238:
239: - (void *)_fetchItemList: list
240: returnedNum: (unsigned int *)returnedNum
241: {
242: unsigned int *array = 0;
243: int i, num;
244:
245: num = [list count];
246: if (num > 0) {
247: array = (void *)IOMalloc(num * sizeof (*array));
248: for (i = 0; i < num; i++)
249: array[i] = [[list objectAt:i] item];
250: }
251:
252: *returnedNum = num;
253: return array;
254: }
255:
256: - (void *)_fetchRangeList: list
257: returnedNum: (unsigned int *)returnedNum
258: {
259: IORange *array = 0;
260: Range range;
261: int i, num;
262:
263: num = [list count];
264: if (num > 0) {
265: array = (void *)IOMalloc(num * sizeof (*array));
266: for (i = 0; i < num; i++) {
267: range = [[list objectAt:i] range];
268: array[i].start = range.base;
269: array[i].size = range.length;
270: }
271: }
272:
273: *returnedNum = num;
274: return array;
275: }
276:
277: - lookUpProperty:(const char *)propertyName
278: value:(unsigned char *)value
279: length:(unsigned int *)length
280: selector:(SEL)selector
281: isString:(BOOL)isString
282: {
283: id rtn = nil;
284: char * str;
285:
286: if( [self respondsTo:selector]) {
287: // guarantee a minimal size so most methods don't have to check
288: if( (isString == NO) || ((strlen( value) + 32) <= *length))
289: rtn = objc_msgSend( self, selector, value, length );
290: }
291:
292: if( nil == rtn) {
293: if( (str = [[self configTable] valueForStringKey:propertyName])) {
294: if( (strlen( str) + 1) < *length) {
295: strcpy( value, str);
296: rtn = self;
297: }
298: }
299: }
300:
301: return( rtn);
302: }
303:
304: - property_IODeviceClass:(char *)classes length:(unsigned int *)maxLen
305: {
306: return( nil);
307: }
308:
309: - property_IODeviceType:(char *)classes length:(unsigned int *)maxLen
310: {
311: return( nil);
312: }
313:
314: - (char *) nodeName
315: {
316: return( NULL);
317: }
318:
319: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.