|
|
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: * Copyright (c) 1993 NeXT Computer, Inc. ! 26: * ! 27: * ISA/EISA device description class. ! 28: * ! 29: * HISTORY ! 30: * ! 31: * 18Jan93 Brian Pinkerton at NeXT ! 32: * Created. ! 33: */ ! 34: ! 35: #define KERNEL_PRIVATE 1 ! 36: ! 37: #import <objc/List.h> ! 38: ! 39: #import <driverkit/KernDeviceDescription.h> ! 40: #import <driverkit/i386/EISAKernBus.h> ! 41: ! 42: #import <driverkit/i386/IOEISADeviceDescription.h> ! 43: #import <driverkit/i386/IOEISADeviceDescriptionPrivate.h> ! 44: #import <driverkit/IODeviceDescriptionPrivate.h> ! 45: #import <driverkit/IOProperties.h> ! 46: ! 47: struct _private { ! 48: unsigned int *channels; ! 49: unsigned int numChannels; ! 50: IORange *portRanges; ! 51: unsigned int numPortRanges; ! 52: BOOL valid; ! 53: unsigned int slotNum; ! 54: unsigned long slotID; ! 55: }; ! 56: ! 57: @implementation IOEISADeviceDescription ! 58: ! 59: - free ! 60: { ! 61: struct _private *private = _eisa_private; ! 62: ! 63: if (private->numChannels > 0) ! 64: IOFree(private->channels, ! 65: private->numChannels * sizeof (*private->channels)); ! 66: if (private->numPortRanges > 0) ! 67: IOFree(private->portRanges, ! 68: private->numPortRanges * sizeof (*private->portRanges)); ! 69: ! 70: IOFree(private, sizeof (*private)); ! 71: ! 72: return [super free]; ! 73: } ! 74: ! 75: - (unsigned int) channel ! 76: { ! 77: return [self channelList][0]; ! 78: } ! 79: ! 80: ! 81: - (unsigned int *) channelList ! 82: { ! 83: struct _private *private = _eisa_private; ! 84: ! 85: if (private->numChannels == 0) ! 86: private->channels = [self ! 87: _fetchItemList:[[self _delegate] ! 88: resourcesForKey:DMA_CHANNELS_KEY] ! 89: returnedNum:&private->numChannels]; ! 90: return private->channels; ! 91: } ! 92: ! 93: - (unsigned int) numChannels ! 94: { ! 95: struct _private *private = _eisa_private; ! 96: ! 97: if (private->numChannels == 0) ! 98: private->channels = [self ! 99: _fetchItemList:[[self _delegate] ! 100: resourcesForKey:DMA_CHANNELS_KEY] ! 101: returnedNum:&private->numChannels]; ! 102: return private->numChannels; ! 103: } ! 104: ! 105: - (IORange *) portRangeList ! 106: { ! 107: struct _private *private = _eisa_private; ! 108: ! 109: if (private->numPortRanges == 0) ! 110: private->portRanges = [self ! 111: _fetchRangeList:[[self _delegate] ! 112: resourcesForKey:IO_PORTS_KEY] ! 113: returnedNum:&private->numPortRanges]; ! 114: return private->portRanges; ! 115: } ! 116: ! 117: - (unsigned int) numPortRanges ! 118: { ! 119: struct _private *private = _eisa_private; ! 120: ! 121: if (private->numPortRanges == 0) ! 122: private->portRanges = [self ! 123: _fetchRangeList:[[self _delegate] ! 124: resourcesForKey:IO_PORTS_KEY] ! 125: returnedNum:&private->numPortRanges]; ! 126: return private->numPortRanges; ! 127: } ! 128: ! 129: ! 130: - (IOReturn) setChannelList:(unsigned int *)aList num:(unsigned int) length ! 131: { ! 132: IOReturn ret = IO_R_RESOURCE; ! 133: ! 134: if ([[self _delegate] ! 135: allocateItems:aList numItems:length ! 136: forKey:DMA_CHANNELS_KEY] != nil) { ! 137: ! 138: struct _private *private = (struct _private *)_eisa_private; ! 139: if (private->numChannels > 0) ! 140: IOFree(private->channels, ! 141: private->numChannels * sizeof (*private->channels)); ! 142: private->numChannels = 0; ! 143: ret = IO_R_SUCCESS; ! 144: } ! 145: return ret; ! 146: } ! 147: ! 148: - (IOReturn) setPortRangeList:(IORange *)aList num:(unsigned int) length ! 149: { ! 150: IOReturn ret = IO_R_RESOURCE; ! 151: Range *ranges; ! 152: int i; ! 153: ! 154: ranges = (Range *)IOMalloc(sizeof(Range) * length); ! 155: for (i=0; i<length; i++) { ! 156: ranges[i].base = aList[i].start; ! 157: ranges[i].length = aList[i].size; ! 158: } ! 159: if ([[self _delegate] ! 160: allocateRanges:ranges numRanges:length forKey:IO_PORTS_KEY] != nil) { ! 161: ! 162: struct _private *private = (struct _private *)_eisa_private; ! 163: if (private->numPortRanges > 0) ! 164: IOFree(private->portRanges, ! 165: private->numPortRanges * sizeof (*private->portRanges)); ! 166: private->numPortRanges = 0; ! 167: ret = IO_R_SUCCESS; ! 168: } ! 169: IOFree(ranges, sizeof(Range) * length); ! 170: return ret; ! 171: } ! 172: ! 173: - (IOReturn) getEISASlotNumber : (unsigned int *) slotNum ! 174: { ! 175: struct _private *private = _eisa_private; ! 176: ! 177: if (private->valid) { ! 178: if (slotNum) *slotNum = private->slotNum; ! 179: return IO_R_SUCCESS; ! 180: } ! 181: return IO_R_NO_DEVICE; ! 182: } ! 183: ! 184: ! 185: - (IOReturn) getEISASlotID : (unsigned long *) slotID ! 186: { ! 187: struct _private *private = _eisa_private; ! 188: ! 189: if (private->valid) { ! 190: if (slotID) *slotID = private->slotID; ! 191: return IO_R_SUCCESS; ! 192: } ! 193: return IO_R_NO_DEVICE; ! 194: } ! 195: ! 196: @end ! 197: ! 198: @implementation IOEISADeviceDescription(Private) ! 199: ! 200: - _initWithDelegate:delegate ! 201: { ! 202: struct _private *private; ! 203: id theEISABus = [KernBus lookupBusInstanceWithName:"EISA" busId:0]; ! 204: ! 205: [super _initWithDelegate:delegate]; ! 206: _eisa_private = (void *)IOMalloc(sizeof (struct _private)); ! 207: bzero(_eisa_private, sizeof (struct _private)); ! 208: private = _eisa_private; ! 209: ! 210: private->valid = ( (theEISABus != nil) && ! 211: ([theEISABus getEISASlotNumber: &(private->slotNum) ! 212: slotID: &(private->slotID) ! 213: usingDeviceDescription: delegate] == IO_R_SUCCESS) ); ! 214: ! 215: return self; ! 216: } ! 217: ! 218: - property_IODeviceType:(char *)types length:(unsigned int *)maxLen ! 219: { ! 220: strcpy( types, IOTypePCComp); ! 221: return( self); ! 222: } ! 223: ! 224: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.