2 * Copyright (c) 1999-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1999-2000 Apple Computer, Inc. All rights reserved.
36 #include <machine/machine_routines.h>
37 #include <pexpert/pexpert.h>
38 #include <kern/cpu_number.h>
41 #include <machine/machine_routines.h>
43 #include <IOKit/IOLib.h>
44 #include <IOKit/IOPlatformExpert.h>
45 #include <IOKit/pwr_mgt/RootDomain.h>
46 #include <IOKit/pwr_mgt/IOPMPrivate.h>
47 #include <IOKit/IOUserClient.h>
48 #include <IOKit/IOKitKeysPrivate.h>
49 #include <IOKit/IOCPU.h>
51 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
52 #include <kern/queue.h>
54 typedef kern_return_t (*iocpu_platform_action_t
)(void * refcon0
, void * refcon1
, uint32_t priority
,
55 void * param1
, void * param2
, void * param3
,
58 struct iocpu_platform_action_entry
61 iocpu_platform_action_t action
;
66 struct iocpu_platform_action_entry
* alloc_list
;
68 typedef struct iocpu_platform_action_entry iocpu_platform_action_entry_t
;
70 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
72 #define kBootCPUNumber 0
80 kQueueHaltRestart
= 4,
85 const OSSymbol
* gIOPlatformSleepActionKey
;
86 const OSSymbol
* gIOPlatformWakeActionKey
;
87 const OSSymbol
* gIOPlatformQuiesceActionKey
;
88 const OSSymbol
* gIOPlatformActiveActionKey
;
89 const OSSymbol
* gIOPlatformHaltRestartActionKey
;
90 const OSSymbol
* gIOPlatformPanicActionKey
;
92 static queue_head_t gActionQueues
[kQueueCount
];
93 static const OSSymbol
* gActionSymbols
[kQueueCount
];
95 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
98 iocpu_add_platform_action(queue_head_t
* queue
, iocpu_platform_action_entry_t
* entry
)
100 iocpu_platform_action_entry_t
* next
;
102 queue_iterate(queue
, next
, iocpu_platform_action_entry_t
*, link
)
104 if (next
->priority
> entry
->priority
)
106 queue_insert_before(queue
, entry
, next
, iocpu_platform_action_entry_t
*, link
);
110 queue_enter(queue
, entry
, iocpu_platform_action_entry_t
*, link
); // at tail
114 iocpu_remove_platform_action(iocpu_platform_action_entry_t
* entry
)
116 remque(&entry
->link
);
120 iocpu_run_platform_actions(queue_head_t
* queue
, uint32_t first_priority
, uint32_t last_priority
,
121 void * param1
, void * param2
, void * param3
)
123 kern_return_t ret
= KERN_SUCCESS
;
124 kern_return_t result
= KERN_SUCCESS
;
125 iocpu_platform_action_entry_t
* next
;
127 queue_iterate(queue
, next
, iocpu_platform_action_entry_t
*, link
)
129 uint32_t pri
= (next
->priority
< 0) ? -next
->priority
: next
->priority
;
130 if ((pri
>= first_priority
) && (pri
<= last_priority
))
132 //kprintf("[%p]", next->action);
133 ret
= (*next
->action
)(next
->refcon0
, next
->refcon1
, pri
, param1
, param2
, param3
, next
->name
);
135 if (KERN_SUCCESS
== result
)
141 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
143 extern "C" kern_return_t
144 IOCPURunPlatformQuiesceActions(void)
146 return (iocpu_run_platform_actions(&gActionQueues
[kQueueQuiesce
], 0, 0U-1,
150 extern "C" kern_return_t
151 IOCPURunPlatformActiveActions(void)
153 return (iocpu_run_platform_actions(&gActionQueues
[kQueueActive
], 0, 0U-1,
157 extern "C" kern_return_t
158 IOCPURunPlatformHaltRestartActions(uint32_t message
)
160 return (iocpu_run_platform_actions(&gActionQueues
[kQueueHaltRestart
], 0, 0U-1,
161 (void *)(uintptr_t) message
, NULL
, NULL
));
164 extern "C" kern_return_t
165 IOCPURunPlatformPanicActions(uint32_t message
)
167 return (iocpu_run_platform_actions(&gActionQueues
[kQueuePanic
], 0, 0U-1,
168 (void *)(uintptr_t) message
, NULL
, NULL
));
171 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
174 IOServicePlatformAction(void * refcon0
, void * refcon1
, uint32_t priority
,
175 void * param1
, void * param2
, void * param3
,
176 const char * service_name
)
179 IOService
* service
= (IOService
*) refcon0
;
180 const OSSymbol
* function
= (const OSSymbol
*) refcon1
;
182 kprintf("%s -> %s\n", function
->getCStringNoCopy(), service_name
);
184 ret
= service
->callPlatformFunction(function
, false,
185 (void *)(uintptr_t) priority
, param1
, param2
, param3
);
191 IOInstallServicePlatformAction(IOService
* service
, uint32_t qidx
)
193 iocpu_platform_action_entry_t
* entry
;
196 const OSSymbol
* key
= gActionSymbols
[qidx
];
197 queue_head_t
* queue
= &gActionQueues
[qidx
];
201 num
= OSDynamicCast(OSNumber
, service
->getProperty(key
));
212 case kQueueHaltRestart
:
219 queue_iterate(queue
, entry
, iocpu_platform_action_entry_t
*, link
)
221 if (service
== entry
->refcon0
) return;
225 entry
= IONew(iocpu_platform_action_entry_t
, 1);
226 entry
->action
= &IOServicePlatformAction
;
227 entry
->name
= service
->getName();
228 priority
= num
->unsigned32BitValue();
230 entry
->priority
= -priority
;
232 entry
->priority
= priority
;
233 entry
->refcon0
= service
;
234 entry
->refcon1
= (void *) key
;
236 iocpu_add_platform_action(queue
, entry
);
239 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
242 IOCPUInitialize(void)
244 for (uint32_t qidx
= kQueueSleep
; qidx
< kQueueCount
; qidx
++)
246 queue_init(&gActionQueues
[qidx
]);
249 gIOPlatformSleepActionKey
= gActionSymbols
[kQueueSleep
]
250 = OSSymbol::withCStringNoCopy(kIOPlatformSleepActionKey
);
251 gIOPlatformWakeActionKey
= gActionSymbols
[kQueueWake
]
252 = OSSymbol::withCStringNoCopy(kIOPlatformWakeActionKey
);
253 gIOPlatformQuiesceActionKey
= gActionSymbols
[kQueueQuiesce
]
254 = OSSymbol::withCStringNoCopy(kIOPlatformQuiesceActionKey
);
255 gIOPlatformActiveActionKey
= gActionSymbols
[kQueueActive
]
256 = OSSymbol::withCStringNoCopy(kIOPlatformActiveActionKey
);
257 gIOPlatformHaltRestartActionKey
= gActionSymbols
[kQueueHaltRestart
]
258 = OSSymbol::withCStringNoCopy(kIOPlatformHaltRestartActionKey
);
259 gIOPlatformPanicActionKey
= gActionSymbols
[kQueuePanic
]
260 = OSSymbol::withCStringNoCopy(kIOPlatformPanicActionKey
);
264 IOInstallServicePlatformActions(IOService
* service
)
266 IOInstallServicePlatformAction(service
, kQueueHaltRestart
);
267 IOInstallServicePlatformAction(service
, kQueuePanic
);
269 return (kIOReturnSuccess
);
273 IORemoveServicePlatformActions(IOService
* service
)
275 iocpu_platform_action_entry_t
* entry
;
276 iocpu_platform_action_entry_t
* next
;
278 for (uint32_t qidx
= kQueueSleep
; qidx
< kQueueCount
; qidx
++)
280 next
= (typeof(entry
)) queue_first(&gActionQueues
[qidx
]);
281 while (!queue_end(&gActionQueues
[qidx
], &next
->link
))
284 next
= (typeof(entry
)) queue_next(&entry
->link
);
285 if (service
== entry
->refcon0
)
287 iocpu_remove_platform_action(entry
);
288 IODelete(entry
, iocpu_platform_action_entry_t
, 1);
293 return (kIOReturnSuccess
);
297 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
299 kern_return_t
PE_cpu_start(cpu_id_t target
,
300 vm_offset_t start_paddr
, vm_offset_t arg_paddr
)
302 IOCPU
*targetCPU
= OSDynamicCast(IOCPU
, (OSObject
*)target
);
304 if (targetCPU
== 0) return KERN_FAILURE
;
305 return targetCPU
->startCPU(start_paddr
, arg_paddr
);
308 void PE_cpu_halt(cpu_id_t target
)
310 IOCPU
*targetCPU
= OSDynamicCast(IOCPU
, (OSObject
*)target
);
312 if (targetCPU
) targetCPU
->haltCPU();
315 void PE_cpu_signal(cpu_id_t source
, cpu_id_t target
)
317 IOCPU
*sourceCPU
= OSDynamicCast(IOCPU
, (OSObject
*)source
);
318 IOCPU
*targetCPU
= OSDynamicCast(IOCPU
, (OSObject
*)target
);
320 if (sourceCPU
&& targetCPU
) sourceCPU
->signalCPU(targetCPU
);
323 void PE_cpu_signal_deferred(cpu_id_t source
, cpu_id_t target
)
325 IOCPU
*sourceCPU
= OSDynamicCast(IOCPU
, (OSObject
*)source
);
326 IOCPU
*targetCPU
= OSDynamicCast(IOCPU
, (OSObject
*)target
);
328 if (sourceCPU
&& targetCPU
) sourceCPU
->signalCPUDeferred(targetCPU
);
331 void PE_cpu_signal_cancel(cpu_id_t source
, cpu_id_t target
)
333 IOCPU
*sourceCPU
= OSDynamicCast(IOCPU
, (OSObject
*)source
);
334 IOCPU
*targetCPU
= OSDynamicCast(IOCPU
, (OSObject
*)target
);
336 if (sourceCPU
&& targetCPU
) sourceCPU
->signalCPUCancel(targetCPU
);
339 void PE_cpu_machine_init(cpu_id_t target
, boolean_t bootb
)
341 IOCPU
*targetCPU
= OSDynamicCast(IOCPU
, (OSObject
*)target
);
343 if (targetCPU
) targetCPU
->initCPU(bootb
);
346 void PE_cpu_machine_quiesce(cpu_id_t target
)
348 IOCPU
*targetCPU
= OSDynamicCast(IOCPU
, (OSObject
*)target
);
350 if (targetCPU
) targetCPU
->quiesceCPU();
354 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
356 #define super IOService
358 OSDefineMetaClassAndAbstractStructors(IOCPU
, IOService
);
359 OSMetaClassDefineReservedUnused(IOCPU
, 0);
360 OSMetaClassDefineReservedUnused(IOCPU
, 1);
361 OSMetaClassDefineReservedUnused(IOCPU
, 2);
362 OSMetaClassDefineReservedUnused(IOCPU
, 3);
363 OSMetaClassDefineReservedUnused(IOCPU
, 4);
364 OSMetaClassDefineReservedUnused(IOCPU
, 5);
365 OSMetaClassDefineReservedUnused(IOCPU
, 6);
366 OSMetaClassDefineReservedUnused(IOCPU
, 7);
368 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
370 static OSArray
*gIOCPUs
;
371 static const OSSymbol
*gIOCPUStateKey
;
372 static OSString
*gIOCPUStateNames
[kIOCPUStateCount
];
374 void IOCPUSleepKernel(void)
378 IOCPU
*bootCPU
= NULL
;
379 IOPMrootDomain
*rootDomain
= IOService::getPMRootDomain();
381 kprintf("IOCPUSleepKernel\n");
383 IORegistryIterator
* iter
;
387 rootDomain
->tracePoint( kIOPMTracePointSleepPlatformActions
);
389 iter
= IORegistryIterator::iterateOver( gIOServicePlane
,
390 kIORegistryIterateRecursively
);
398 all
= iter
->iterateAll();
400 while (!iter
->isValid());
405 while((service
= (IOService
*) all
->getFirstObject()))
407 for (uint32_t qidx
= kQueueSleep
; qidx
<= kQueueActive
; qidx
++)
409 IOInstallServicePlatformAction(service
, qidx
);
411 all
->removeObject(service
);
417 iocpu_run_platform_actions(&gActionQueues
[kQueueSleep
], 0, 0U-1,
420 rootDomain
->tracePoint( kIOPMTracePointSleepCPUs
);
422 numCPUs
= gIOCPUs
->getCount();
427 target
= OSDynamicCast(IOCPU
, gIOCPUs
->getObject(cnt
));
429 // We make certain that the bootCPU is the last to sleep
430 // We'll skip it for now, and halt it after finishing the
432 if (target
->getCPUNumber() == kBootCPUNumber
)
435 } else if (target
->getCPUState() == kIOCPUStateRunning
)
441 assert(bootCPU
!= NULL
);
442 assert(cpu_number() == 0);
444 rootDomain
->tracePoint( kIOPMTracePointSleepPlatformDriver
);
446 // Now sleep the boot CPU.
449 rootDomain
->tracePoint( kIOPMTracePointWakePlatformActions
);
451 iocpu_run_platform_actions(&gActionQueues
[kQueueWake
], 0, 0U-1,
454 iocpu_platform_action_entry_t
* entry
;
455 for (uint32_t qidx
= kQueueSleep
; qidx
<= kQueueActive
; qidx
++)
457 while (!(queue_empty(&gActionQueues
[qidx
])))
459 entry
= (typeof(entry
)) queue_first(&gActionQueues
[qidx
]);
460 iocpu_remove_platform_action(entry
);
461 IODelete(entry
, iocpu_platform_action_entry_t
, 1);
465 rootDomain
->tracePoint( kIOPMTracePointWakeCPUs
);
467 // Wake the other CPUs.
468 for (cnt
= 0; cnt
< numCPUs
; cnt
++)
470 target
= OSDynamicCast(IOCPU
, gIOCPUs
->getObject(cnt
));
472 // Skip the already-woken boot CPU.
473 if ((target
->getCPUNumber() != kBootCPUNumber
)
474 && (target
->getCPUState() == kIOCPUStateStopped
))
476 processor_start(target
->getMachProcessor());
481 void IOCPU::initCPUs(void)
484 gIOCPUs
= OSArray::withCapacity(1);
486 gIOCPUStateKey
= OSSymbol::withCStringNoCopy("IOCPUState");
488 gIOCPUStateNames
[kIOCPUStateUnregistered
] =
489 OSString::withCStringNoCopy("Unregistered");
490 gIOCPUStateNames
[kIOCPUStateUninitalized
] =
491 OSString::withCStringNoCopy("Uninitalized");
492 gIOCPUStateNames
[kIOCPUStateStopped
] =
493 OSString::withCStringNoCopy("Stopped");
494 gIOCPUStateNames
[kIOCPUStateRunning
] =
495 OSString::withCStringNoCopy("Running");
499 bool IOCPU::start(IOService
*provider
)
501 OSData
*busFrequency
, *cpuFrequency
, *timebaseFrequency
;
503 if (!super::start(provider
)) return false;
510 gIOCPUs
->setObject(this);
512 // Correct the bus, cpu and timebase frequencies in the device tree.
513 if (gPEClockFrequencyInfo
.bus_frequency_hz
< 0x100000000ULL
) {
514 busFrequency
= OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo
.bus_clock_rate_hz
, 4);
516 busFrequency
= OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo
.bus_frequency_hz
, 8);
518 provider
->setProperty("bus-frequency", busFrequency
);
519 busFrequency
->release();
521 if (gPEClockFrequencyInfo
.cpu_frequency_hz
< 0x100000000ULL
) {
522 cpuFrequency
= OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo
.cpu_clock_rate_hz
, 4);
524 cpuFrequency
= OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo
.cpu_frequency_hz
, 8);
526 provider
->setProperty("clock-frequency", cpuFrequency
);
527 cpuFrequency
->release();
529 timebaseFrequency
= OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo
.timebase_frequency_hz
, 4);
530 provider
->setProperty("timebase-frequency", timebaseFrequency
);
531 timebaseFrequency
->release();
533 super::setProperty("IOCPUID", getRegistryEntryID(), sizeof(uint64_t)*8);
536 setCPUState(kIOCPUStateUnregistered
);
541 OSObject
*IOCPU::getProperty(const OSSymbol
*aKey
) const
543 if (aKey
== gIOCPUStateKey
) return gIOCPUStateNames
[_cpuState
];
545 return super::getProperty(aKey
);
548 bool IOCPU::setProperty(const OSSymbol
*aKey
, OSObject
*anObject
)
550 if (aKey
== gIOCPUStateKey
) {
554 return super::setProperty(aKey
, anObject
);
557 bool IOCPU::serializeProperties(OSSerialize
*serialize
) const
560 OSDictionary
*dict
= dictionaryWithProperties();
561 if (!dict
) return false;
562 dict
->setObject(gIOCPUStateKey
, gIOCPUStateNames
[_cpuState
]);
563 result
= dict
->serialize(serialize
);
568 IOReturn
IOCPU::setProperties(OSObject
*properties
)
570 OSDictionary
*dict
= OSDynamicCast(OSDictionary
, properties
);
574 if (dict
== 0) return kIOReturnUnsupported
;
576 stateStr
= OSDynamicCast(OSString
, dict
->getObject(gIOCPUStateKey
));
578 result
= IOUserClient::clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator
);
579 if (result
!= kIOReturnSuccess
) return result
;
581 if (setProperty(gIOCPUStateKey
, stateStr
)) return kIOReturnSuccess
;
583 return kIOReturnUnsupported
;
586 return kIOReturnUnsupported
;
589 void IOCPU::signalCPU(IOCPU */
*target*/
)
593 void IOCPU::signalCPUDeferred(IOCPU
*target
)
595 // Our CPU may not support deferred IPIs,
596 // so send a regular IPI by default
600 void IOCPU::signalCPUCancel(IOCPU */
*target*/
)
602 // Meant to cancel signals sent by
603 // signalCPUDeferred; unsupported
607 void IOCPU::enableCPUTimeBase(bool /*enable*/)
611 UInt32
IOCPU::getCPUNumber(void)
616 void IOCPU::setCPUNumber(UInt32 cpuNumber
)
618 _cpuNumber
= cpuNumber
;
619 super::setProperty("IOCPUNumber", _cpuNumber
, 32);
622 UInt32
IOCPU::getCPUState(void)
627 void IOCPU::setCPUState(UInt32 cpuState
)
629 if (cpuState
< kIOCPUStateCount
) {
630 _cpuState
= cpuState
;
634 OSArray
*IOCPU::getCPUGroup(void)
639 UInt32
IOCPU::getCPUGroupSize(void)
641 return _cpuGroup
->getCount();
644 processor_t
IOCPU::getMachProcessor(void)
646 return machProcessor
;
650 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
653 #define super IOInterruptController
655 OSDefineMetaClassAndStructors(IOCPUInterruptController
, IOInterruptController
);
657 OSMetaClassDefineReservedUnused(IOCPUInterruptController
, 0);
658 OSMetaClassDefineReservedUnused(IOCPUInterruptController
, 1);
659 OSMetaClassDefineReservedUnused(IOCPUInterruptController
, 2);
660 OSMetaClassDefineReservedUnused(IOCPUInterruptController
, 3);
661 OSMetaClassDefineReservedUnused(IOCPUInterruptController
, 4);
662 OSMetaClassDefineReservedUnused(IOCPUInterruptController
, 5);
666 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
669 IOReturn
IOCPUInterruptController::initCPUInterruptController(int sources
)
673 if (!super::init()) return kIOReturnInvalid
;
677 cpus
= (IOCPU
**)IOMalloc(numCPUs
* sizeof(IOCPU
*));
678 if (cpus
== 0) return kIOReturnNoMemory
;
679 bzero(cpus
, numCPUs
* sizeof(IOCPU
*));
681 vectors
= (IOInterruptVector
*)IOMalloc(numCPUs
* sizeof(IOInterruptVector
));
682 if (vectors
== 0) return kIOReturnNoMemory
;
683 bzero(vectors
, numCPUs
* sizeof(IOInterruptVector
));
685 // Allocate locks for the
686 for (cnt
= 0; cnt
< numCPUs
; cnt
++) {
687 vectors
[cnt
].interruptLock
= IOLockAlloc();
688 if (vectors
[cnt
].interruptLock
== NULL
) {
689 for (cnt
= 0; cnt
< numCPUs
; cnt
++) {
690 if (vectors
[cnt
].interruptLock
!= NULL
)
691 IOLockFree(vectors
[cnt
].interruptLock
);
693 return kIOReturnNoResources
;
697 ml_init_max_cpus(numCPUs
);
699 return kIOReturnSuccess
;
702 void IOCPUInterruptController::registerCPUInterruptController(void)
706 getPlatform()->registerInterruptController(gPlatformInterruptControllerName
,
710 void IOCPUInterruptController::setCPUInterruptProperties(IOService
*service
)
718 if ((service
->getProperty(gIOInterruptControllersKey
) != 0) &&
719 (service
->getProperty(gIOInterruptSpecifiersKey
) != 0))
722 // Create the interrupt specifer array.
723 specifier
= OSArray::withCapacity(numCPUs
);
724 for (cnt
= 0; cnt
< numCPUs
; cnt
++) {
726 tmpData
= OSData::withBytes(&tmpLong
, sizeof(tmpLong
));
727 specifier
->setObject(tmpData
);
731 // Create the interrupt controller array.
732 controller
= OSArray::withCapacity(numCPUs
);
733 for (cnt
= 0; cnt
< numCPUs
; cnt
++) {
734 controller
->setObject(gPlatformInterruptControllerName
);
737 // Put the two arrays into the property table.
738 service
->setProperty(gIOInterruptControllersKey
, controller
);
739 service
->setProperty(gIOInterruptSpecifiersKey
, specifier
);
740 controller
->release();
741 specifier
->release();
744 void IOCPUInterruptController::enableCPUInterrupt(IOCPU
*cpu
)
746 IOInterruptHandler handler
= OSMemberFunctionCast(
747 IOInterruptHandler
, this, &IOCPUInterruptController::handleInterrupt
);
749 ml_install_interrupt_handler(cpu
, cpu
->getCPUNumber(), this, handler
, 0);
751 // Ensure that the increment is seen by all processors
752 OSIncrementAtomic(&enabledCPUs
);
754 if (enabledCPUs
== numCPUs
) {
755 IOService::cpusRunning();
760 IOReturn
IOCPUInterruptController::registerInterrupt(IOService
*nub
,
763 IOInterruptHandler handler
,
766 IOInterruptVector
*vector
;
768 if (source
>= numCPUs
) return kIOReturnNoResources
;
770 vector
= &vectors
[source
];
772 // Get the lock for this vector.
773 IOTakeLock(vector
->interruptLock
);
775 // Make sure the vector is not in use.
776 if (vector
->interruptRegistered
) {
777 IOUnlock(vector
->interruptLock
);
778 return kIOReturnNoResources
;
781 // Fill in vector with the client's info.
782 vector
->handler
= handler
;
784 vector
->source
= source
;
785 vector
->target
= target
;
786 vector
->refCon
= refCon
;
788 // Get the vector ready. It starts hard disabled.
789 vector
->interruptDisabledHard
= 1;
790 vector
->interruptDisabledSoft
= 1;
791 vector
->interruptRegistered
= 1;
793 IOUnlock(vector
->interruptLock
);
795 if (enabledCPUs
!= numCPUs
) {
796 assert_wait(this, THREAD_UNINT
);
797 thread_block(THREAD_CONTINUE_NULL
);
800 return kIOReturnSuccess
;
803 IOReturn
IOCPUInterruptController::getInterruptType(IOService */
*nub*/
,
807 if (interruptType
== 0) return kIOReturnBadArgument
;
809 *interruptType
= kIOInterruptTypeLevel
;
811 return kIOReturnSuccess
;
814 IOReturn
IOCPUInterruptController::enableInterrupt(IOService */
*nub*/
,
817 // ml_set_interrupts_enabled(true);
818 return kIOReturnSuccess
;
821 IOReturn
IOCPUInterruptController::disableInterrupt(IOService */
*nub*/
,
824 // ml_set_interrupts_enabled(false);
825 return kIOReturnSuccess
;
828 IOReturn
IOCPUInterruptController::causeInterrupt(IOService */
*nub*/
,
831 ml_cause_interrupt();
832 return kIOReturnSuccess
;
835 IOReturn
IOCPUInterruptController::handleInterrupt(void */
*refCon*/
,
839 IOInterruptVector
*vector
;
841 vector
= &vectors
[source
];
843 if (!vector
->interruptRegistered
) return kIOReturnInvalid
;
845 vector
->handler(vector
->target
, vector
->refCon
,
846 vector
->nub
, vector
->source
);
848 return kIOReturnSuccess
;
851 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */