|
|
1.1 root 1: /*
2: * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * The contents of this file constitute Original Code as defined in and
7: * are subject to the Apple Public Source License Version 1.1 (the
8: * "License"). You may not use this file except in compliance with the
9: * License. Please obtain a copy of the License at
10: * http://www.apple.com/publicsource and read it before using this file.
11: *
12: * This Original Code and all software distributed under the License are
13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17: * License for the specific language governing rights and limitations
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22: /*
23: * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
24: *
25: * HISTORY
26: * 23 Nov 98 sdouglas created from objc version.
27: */
28:
29: #include <IOKit/system.h>
30:
31: #include <IOKit/pci/IOPCIBridge.h>
32: #include <IOKit/pci/IOPCIDevice.h>
33: #include <IOKit/pci/IOAGPDevice.h>
34: #include <IOKit/IOPlatformExpert.h>
35:
36: #include <IOKit/IOLib.h>
37: #include <IOKit/assert.h>
38:
39: #include <libkern/c++/OSContainers.h>
40:
41: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
42:
43: #define super IOService
44:
45: OSDefineMetaClassAndStructors(IOPCIDevice, IOService)
46:
47: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
48:
49: // stub driver has two power states, off and on
50: #define number_of_power_states 2
51:
52: static IOPMPowerState ourPowerStates[number_of_power_states] = {
53: {1,IOPMNotAttainable,0,0,0,0,0,0,0,0,0,0},
54: {1,IOPMNotAttainable,0,IOPMPowerOn,0,0,0,0,0,0,0,0}
55: };
56:
57:
58: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
59: // attach
60: //
61: // If the device is an expansion slot device,
62: // we volunteer to do power managment for the device,
63: // and all we do is request power stay on. The effect is
64: // to prevent system sleep. If a driver is loaded which can
65: // power manage the device, it will contact us and we
66: // will relinquish this control. This prevents the system
67: // from sleeping when there are non-power-managed
68: // PCI cards installed.
69: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
70: bool IOPCIDevice::attach( IOService * provider )
71: {
72: if ( getProperty("AAPL,slot-name") != NULL ) {
73: PMinit(); // initialize superclass variables
74: pm_vars->thePlatform->PMRegisterDevice((IOService *)this,(IOService *)this); // register as policy-maker
75: registerControllingDriver(this,ourPowerStates,number_of_power_states); // register as controlling driver
76: changeStateToPriv( number_of_power_states-1); // clamp power on
77: }
78: return super::attach(provider);
79: }
80:
81:
82: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
83: // maxCapabilityForDomainState
84: //
85: // If the power domain is supplying power, the device
86: // can be on. If there is no power it can only be off.
87: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
88: unsigned long IOPCIDevice::maxCapabilityForDomainState(
89: IOPMPowerFlags domainState )
90: {
91: if( domainState & IOPMPowerOn )
92: return number_of_power_states-1;
93: else
94: return 0;
95: }
96:
97:
98: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
99: // initialPowerStateForDomainState
100: //
101: // This is our first information about the power domain state.
102: // If power is on in the new state, the device is on.
103: // If domain power is off, the device is also off.
104: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
105: unsigned long IOPCIDevice::initialPowerStateForDomainState(
106: IOPMPowerFlags domainState )
107: {
108: if( domainState & IOPMPowerOn )
109: return number_of_power_states-1;
110: else
111: return 0;
112: }
113:
114:
115: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
116: // powerStateForDomainState
117: //
118: // The power domain may be changing state.
119: // If power is on in the new state, the device will be on.
120: // If domain power is off, the device will be off.
121: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
122: unsigned long IOPCIDevice::powerStateForDomainState(
123: IOPMPowerFlags domainState )
124: {
125: if( domainState & IOPMPowerOn )
126: return pm_vars->myCurrentState;
127: else
128: return 0;
129: }
130:
131:
132: //*********************************************************************************
133: // joinPMtree
134: //
135: // A policy-maker for our PCI device calls here when initializing,
136: // to be attached into the power management hierarchy.
137: // We are currently the (stub) policy-maker for the device, so we
138: // attach this driver and then pull ourselves out of the picture.
139: //
140: // This overrides the default function of the IOService joinPMtree.
141: //*********************************************************************************
142: void IOPCIDevice::joinPMtree ( IOService * driver )
143: {
144: if ( getProperty("AAPL,slot-name") != NULL ) {
145: pm_vars->myParent->addChild(driver); // attach new driver to our parent
146: changeStateToPriv(0); // release our clamp
147: pm_vars->myParent->removeChild(this); // detach ourselves
148: PMstop(); // free structures, etc.
149: }
150: else {
151: super::joinPMtree(driver); // oops, they shouldn't have called here
152: }
153: }
154:
155: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
156:
157: bool IOPCIDevice::matchPropertyTable( OSDictionary * table )
158: {
159: return( parent->matchNubWithPropertyTable( this, table ));
160: }
161:
162: bool IOPCIDevice::compareName( OSString * name, OSString ** matched = 0 ) const
163: {
164: return( parent->compareNubName( this, name, matched ));
165: }
166:
167: IOReturn IOPCIDevice::getResources( void )
168: {
169: return( parent->getNubResources( this ));
170: }
171:
172: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
173:
174: UInt32 IOPCIDevice::configRead32( IOPCIAddressSpace _space,
175: UInt8 offset )
176: {
177: return( parent->configRead32( _space, offset & 0xfc ));
178: }
179:
180: void IOPCIDevice::configWrite32( IOPCIAddressSpace _space,
181: UInt8 offset, UInt32 data )
182: {
183: parent->configWrite32( _space, offset & 0xfc, data );
184: }
185:
186: UInt32 IOPCIDevice::configRead32( UInt8 offset )
187: {
188: return( parent->configRead32( space, offset & 0xfc ));
189: }
190:
191: void IOPCIDevice::configWrite32( UInt8 offset, UInt32 data )
192: {
193: parent->configWrite32( space, offset & 0xfc, data );
194: }
195:
196: UInt32 IOPCIDevice::findPCICapability( UInt8 capabilityID )
197: {
198: return( parent->configRead32( space, capabilityID ));
199: }
200:
201: UInt32 IOPCIDevice::setConfigBits( UInt8 reg, UInt32 mask, UInt32 value )
202: {
203: UInt32 was;
204: UInt32 bits;
205:
206: bits = configRead32( reg );
207: was = (bits & mask);
208: bits &= ~mask;
209: bits |= (value & mask);
210: configWrite32( reg, bits );
211:
212: return( was );
213: }
214:
215: bool IOPCIDevice::setBusMasterEnable( bool enable )
216: {
217: return( 0 != setConfigBits( kIOPCIConfigCommand, kIOPCICommandBusMaster,
218: enable ? kIOPCICommandBusMaster : 0));
219: }
220:
221: bool IOPCIDevice::setMemoryEnable( bool enable )
222: {
223: return( 0 != setConfigBits( kIOPCIConfigCommand, kIOPCICommandMemorySpace,
224: enable ? kIOPCICommandMemorySpace : 0));
225: }
226:
227: bool IOPCIDevice::setIOEnable( bool enable, bool /* exclusive = false */ )
228: {
229: // exclusive is TODO.
230: return( 0 != setConfigBits( kIOPCIConfigCommand, kIOPCICommandIOSpace,
231: enable ? kIOPCICommandIOSpace : 0));
232: }
233:
234: UInt8 IOPCIDevice::getBusNumber( void )
235: {
236: return( space.s.busNum );
237: }
238:
239: UInt8 IOPCIDevice::getDeviceNumber( void )
240: {
241: return( space.s.deviceNum );
242: }
243:
244: UInt8 IOPCIDevice::getFunctionNumber( void )
245: {
246: return( space.s.functionNum );
247: }
248:
249: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
250:
251: IODeviceMemory * IOPCIDevice::getDeviceMemoryWithRegister( UInt8 reg )
252: {
253: OSArray * array;
254: IODeviceMemory * range;
255: unsigned int i = 0;
256:
257: array = (OSArray *) getProperty( gIODeviceMemoryKey);
258: if( 0 == array)
259: return( 0);
260:
261: while( (range = (IODeviceMemory *) array->getObject( i++ ))) {
262: if( reg == (range->getTag() & 0xff))
263: break;
264: }
265:
266: return( range);
267: }
268:
269: IOMemoryMap * IOPCIDevice:: mapDeviceMemoryWithRegister( UInt8 reg,
270: IOOptionBits options = 0 )
271: {
272: IODeviceMemory * range;
273: IOMemoryMap * map;
274:
275: range = getDeviceMemoryWithRegister( reg );
276: if( range)
277: map = range->map( options );
278: else
279: map = 0;
280:
281: return( map );
282: }
283:
284: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
285:
286: IODeviceMemory * IOPCIDevice::ioDeviceMemory( void )
287: {
288: return( parent->ioDeviceMemory() );
289: }
290:
291: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
292:
293: IOService * IOPCIDevice::matchLocation( IOService * /* client */ )
294: {
295: return( this );
296: }
297:
298: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
299:
300: #undef super
301: #define super IOPCIDevice
302:
303: OSDefineMetaClassAndStructors(IOAGPDevice, IOPCIDevice)
304:
305: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
306:
307: IOReturn IOAGPDevice::createAGPSpace( IOOptionBits options,
308: IOPhysicalAddress * address,
309: IOPhysicalLength * length )
310: {
311: return( parent->createAGPSpace( space, options, address, length ));
312: }
313:
314: IOReturn IOAGPDevice::destroyAGPSpace( void )
315: {
316: return( parent->destroyAGPSpace( space ));
317: }
318:
319: IORangeAllocator * IOAGPDevice::getAGPRangeAllocator( void )
320: {
321: return( parent->getAGPRangeAllocator( space ));
322: }
323:
324: IOOptionBits IOAGPDevice::getAGPStatus( IOOptionBits options = 0 )
325: {
326: return( parent->getAGPStatus( space, options ));
327: }
328:
329: IOReturn IOAGPDevice::commitAGPMemory( IOMemoryDescriptor * memory,
330: IOByteCount agpOffset,
331: IOOptionBits options = 0 )
332: {
333: return( parent->commitAGPMemory ( space, memory, agpOffset, options ));
334: }
335:
336: IOReturn IOAGPDevice::releaseAGPMemory( IOMemoryDescriptor * memory,
337: IOByteCount agpOffset )
338: {
339: return( parent->releaseAGPMemory ( space, memory, agpOffset ));
340: }
341:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.