2 * Copyright (c) 1999-2016 Apple 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@
30 #include <machine/machine_routines.h>
31 #include <pexpert/pexpert.h>
32 #include <kern/cpu_number.h>
35 #include <machine/machine_routines.h>
37 #include <IOKit/IOLib.h>
38 #include <IOKit/IOPlatformExpert.h>
39 #include <IOKit/pwr_mgt/RootDomain.h>
40 #include <IOKit/pwr_mgt/IOPMPrivate.h>
41 #include <IOKit/IOUserClient.h>
42 #include <IOKit/IOKitKeysPrivate.h>
43 #include <IOKit/IOCPU.h>
44 #include "IOKitKernelInternal.h"
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
47 #include <kern/queue.h>
49 extern "C" void console_suspend();
50 extern "C" void console_resume();
52 typedef kern_return_t (*iocpu_platform_action_t
)(void * refcon0
, void * refcon1
, uint32_t priority
,
53 void * param1
, void * param2
, void * param3
,
56 struct iocpu_platform_action_entry
59 iocpu_platform_action_t action
;
64 struct iocpu_platform_action_entry
* alloc_list
;
66 typedef struct iocpu_platform_action_entry iocpu_platform_action_entry_t
;
68 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
70 #define kBootCPUNumber 0
78 kQueueHaltRestart
= 4,
83 const OSSymbol
* gIOPlatformSleepActionKey
;
84 const OSSymbol
* gIOPlatformWakeActionKey
;
85 const OSSymbol
* gIOPlatformQuiesceActionKey
;
86 const OSSymbol
* gIOPlatformActiveActionKey
;
87 const OSSymbol
* gIOPlatformHaltRestartActionKey
;
88 const OSSymbol
* gIOPlatformPanicActionKey
;
90 static queue_head_t gActionQueues
[kQueueCount
];
91 static const OSSymbol
* gActionSymbols
[kQueueCount
];
93 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
96 iocpu_add_platform_action(queue_head_t
* queue
, iocpu_platform_action_entry_t
* entry
)
98 iocpu_platform_action_entry_t
* next
;
100 queue_iterate(queue
, next
, iocpu_platform_action_entry_t
*, link
)
102 if (next
->priority
> entry
->priority
)
104 queue_insert_before(queue
, entry
, next
, iocpu_platform_action_entry_t
*, link
);
108 queue_enter(queue
, entry
, iocpu_platform_action_entry_t
*, link
); // at tail
112 iocpu_remove_platform_action(iocpu_platform_action_entry_t
* entry
)
114 remque(&entry
->link
);
118 iocpu_run_platform_actions(queue_head_t
* queue
, uint32_t first_priority
, uint32_t last_priority
,
119 void * param1
, void * param2
, void * param3
)
121 kern_return_t ret
= KERN_SUCCESS
;
122 kern_return_t result
= KERN_SUCCESS
;
123 iocpu_platform_action_entry_t
* next
;
125 queue_iterate(queue
, next
, iocpu_platform_action_entry_t
*, link
)
127 uint32_t pri
= (next
->priority
< 0) ? -next
->priority
: next
->priority
;
128 if ((pri
>= first_priority
) && (pri
<= last_priority
))
130 //kprintf("[%p]", next->action);
131 ret
= (*next
->action
)(next
->refcon0
, next
->refcon1
, pri
, param1
, param2
, param3
, next
->name
);
133 if (KERN_SUCCESS
== result
)
139 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
141 extern "C" kern_return_t
142 IOCPURunPlatformQuiesceActions(void)
144 return (iocpu_run_platform_actions(&gActionQueues
[kQueueQuiesce
], 0, 0U-1,
148 extern "C" kern_return_t
149 IOCPURunPlatformActiveActions(void)
151 return (iocpu_run_platform_actions(&gActionQueues
[kQueueActive
], 0, 0U-1,
155 extern "C" kern_return_t
156 IOCPURunPlatformHaltRestartActions(uint32_t message
)
158 if (!gActionQueues
[kQueueHaltRestart
].next
) return (kIOReturnNotReady
);
159 return (iocpu_run_platform_actions(&gActionQueues
[kQueueHaltRestart
], 0, 0U-1,
160 (void *)(uintptr_t) message
, NULL
, NULL
));
163 extern "C" kern_return_t
164 IOCPURunPlatformPanicActions(uint32_t message
)
166 if (!gActionQueues
[kQueuePanic
].next
) return (kIOReturnNotReady
);
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);
446 rootDomain
->tracePoint( kIOPMTracePointSleepPlatformDriver
);
448 // Now sleep the boot CPU.
451 rootDomain
->tracePoint( kIOPMTracePointWakePlatformActions
);
455 iocpu_run_platform_actions(&gActionQueues
[kQueueWake
], 0, 0U-1,
458 iocpu_platform_action_entry_t
* entry
;
459 for (uint32_t qidx
= kQueueSleep
; qidx
<= kQueueActive
; qidx
++)
461 while (!(queue_empty(&gActionQueues
[qidx
])))
463 entry
= (typeof(entry
)) queue_first(&gActionQueues
[qidx
]);
464 iocpu_remove_platform_action(entry
);
465 IODelete(entry
, iocpu_platform_action_entry_t
, 1);
469 rootDomain
->tracePoint( kIOPMTracePointWakeCPUs
);
471 // Wake the other CPUs.
472 for (cnt
= 0; cnt
< numCPUs
; cnt
++)
474 target
= OSDynamicCast(IOCPU
, gIOCPUs
->getObject(cnt
));
476 // Skip the already-woken boot CPU.
477 if ((target
->getCPUNumber() != kBootCPUNumber
)
478 && (target
->getCPUState() == kIOCPUStateStopped
))
480 processor_start(target
->getMachProcessor());
485 void IOCPU::initCPUs(void)
488 gIOCPUs
= OSArray::withCapacity(1);
490 gIOCPUStateKey
= OSSymbol::withCStringNoCopy("IOCPUState");
492 gIOCPUStateNames
[kIOCPUStateUnregistered
] =
493 OSString::withCStringNoCopy("Unregistered");
494 gIOCPUStateNames
[kIOCPUStateUninitalized
] =
495 OSString::withCStringNoCopy("Uninitalized");
496 gIOCPUStateNames
[kIOCPUStateStopped
] =
497 OSString::withCStringNoCopy("Stopped");
498 gIOCPUStateNames
[kIOCPUStateRunning
] =
499 OSString::withCStringNoCopy("Running");
503 bool IOCPU::start(IOService
*provider
)
505 OSData
*busFrequency
, *cpuFrequency
, *timebaseFrequency
;
507 if (!super::start(provider
)) return false;
514 gIOCPUs
->setObject(this);
516 // Correct the bus, cpu and timebase frequencies in the device tree.
517 if (gPEClockFrequencyInfo
.bus_frequency_hz
< 0x100000000ULL
) {
518 busFrequency
= OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo
.bus_clock_rate_hz
, 4);
520 busFrequency
= OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo
.bus_frequency_hz
, 8);
522 provider
->setProperty("bus-frequency", busFrequency
);
523 busFrequency
->release();
525 if (gPEClockFrequencyInfo
.cpu_frequency_hz
< 0x100000000ULL
) {
526 cpuFrequency
= OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo
.cpu_clock_rate_hz
, 4);
528 cpuFrequency
= OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo
.cpu_frequency_hz
, 8);
530 provider
->setProperty("clock-frequency", cpuFrequency
);
531 cpuFrequency
->release();
533 timebaseFrequency
= OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo
.timebase_frequency_hz
, 4);
534 provider
->setProperty("timebase-frequency", timebaseFrequency
);
535 timebaseFrequency
->release();
537 super::setProperty("IOCPUID", getRegistryEntryID(), sizeof(uint64_t)*8);
540 setCPUState(kIOCPUStateUnregistered
);
545 OSObject
*IOCPU::getProperty(const OSSymbol
*aKey
) const
547 if (aKey
== gIOCPUStateKey
) return gIOCPUStateNames
[_cpuState
];
549 return super::getProperty(aKey
);
552 bool IOCPU::setProperty(const OSSymbol
*aKey
, OSObject
*anObject
)
554 if (aKey
== gIOCPUStateKey
) {
558 return super::setProperty(aKey
, anObject
);
561 bool IOCPU::serializeProperties(OSSerialize
*serialize
) const
564 OSDictionary
*dict
= dictionaryWithProperties();
565 if (!dict
) return false;
566 dict
->setObject(gIOCPUStateKey
, gIOCPUStateNames
[_cpuState
]);
567 result
= dict
->serialize(serialize
);
572 IOReturn
IOCPU::setProperties(OSObject
*properties
)
574 OSDictionary
*dict
= OSDynamicCast(OSDictionary
, properties
);
578 if (dict
== 0) return kIOReturnUnsupported
;
580 stateStr
= OSDynamicCast(OSString
, dict
->getObject(gIOCPUStateKey
));
582 result
= IOUserClient::clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator
);
583 if (result
!= kIOReturnSuccess
) return result
;
585 if (setProperty(gIOCPUStateKey
, stateStr
)) return kIOReturnSuccess
;
587 return kIOReturnUnsupported
;
590 return kIOReturnUnsupported
;
593 void IOCPU::signalCPU(IOCPU */
*target*/
)
597 void IOCPU::signalCPUDeferred(IOCPU
*target
)
599 // Our CPU may not support deferred IPIs,
600 // so send a regular IPI by default
604 void IOCPU::signalCPUCancel(IOCPU */
*target*/
)
606 // Meant to cancel signals sent by
607 // signalCPUDeferred; unsupported
611 void IOCPU::enableCPUTimeBase(bool /*enable*/)
615 UInt32
IOCPU::getCPUNumber(void)
620 void IOCPU::setCPUNumber(UInt32 cpuNumber
)
622 _cpuNumber
= cpuNumber
;
623 super::setProperty("IOCPUNumber", _cpuNumber
, 32);
626 UInt32
IOCPU::getCPUState(void)
631 void IOCPU::setCPUState(UInt32 cpuState
)
633 if (cpuState
< kIOCPUStateCount
) {
634 _cpuState
= cpuState
;
638 OSArray
*IOCPU::getCPUGroup(void)
643 UInt32
IOCPU::getCPUGroupSize(void)
645 return _cpuGroup
->getCount();
648 processor_t
IOCPU::getMachProcessor(void)
650 return machProcessor
;
654 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
657 #define super IOInterruptController
659 OSDefineMetaClassAndStructors(IOCPUInterruptController
, IOInterruptController
);
661 OSMetaClassDefineReservedUnused(IOCPUInterruptController
, 0);
662 OSMetaClassDefineReservedUnused(IOCPUInterruptController
, 1);
663 OSMetaClassDefineReservedUnused(IOCPUInterruptController
, 2);
664 OSMetaClassDefineReservedUnused(IOCPUInterruptController
, 3);
665 OSMetaClassDefineReservedUnused(IOCPUInterruptController
, 4);
666 OSMetaClassDefineReservedUnused(IOCPUInterruptController
, 5);
670 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
673 IOReturn
IOCPUInterruptController::initCPUInterruptController(int sources
)
677 if (!super::init()) return kIOReturnInvalid
;
681 cpus
= (IOCPU
**)IOMalloc(numCPUs
* sizeof(IOCPU
*));
682 if (cpus
== 0) return kIOReturnNoMemory
;
683 bzero(cpus
, numCPUs
* sizeof(IOCPU
*));
685 vectors
= (IOInterruptVector
*)IOMalloc(numCPUs
* sizeof(IOInterruptVector
));
686 if (vectors
== 0) return kIOReturnNoMemory
;
687 bzero(vectors
, numCPUs
* sizeof(IOInterruptVector
));
689 // Allocate locks for the
690 for (cnt
= 0; cnt
< numCPUs
; cnt
++) {
691 vectors
[cnt
].interruptLock
= IOLockAlloc();
692 if (vectors
[cnt
].interruptLock
== NULL
) {
693 for (cnt
= 0; cnt
< numCPUs
; cnt
++) {
694 if (vectors
[cnt
].interruptLock
!= NULL
)
695 IOLockFree(vectors
[cnt
].interruptLock
);
697 return kIOReturnNoResources
;
701 ml_init_max_cpus(numCPUs
);
703 return kIOReturnSuccess
;
706 void IOCPUInterruptController::registerCPUInterruptController(void)
710 getPlatform()->registerInterruptController(gPlatformInterruptControllerName
,
714 void IOCPUInterruptController::setCPUInterruptProperties(IOService
*service
)
722 if ((service
->getProperty(gIOInterruptControllersKey
) != 0) &&
723 (service
->getProperty(gIOInterruptSpecifiersKey
) != 0))
726 // Create the interrupt specifer array.
727 specifier
= OSArray::withCapacity(numCPUs
);
728 for (cnt
= 0; cnt
< numCPUs
; cnt
++) {
730 tmpData
= OSData::withBytes(&tmpLong
, sizeof(tmpLong
));
731 specifier
->setObject(tmpData
);
735 // Create the interrupt controller array.
736 controller
= OSArray::withCapacity(numCPUs
);
737 for (cnt
= 0; cnt
< numCPUs
; cnt
++) {
738 controller
->setObject(gPlatformInterruptControllerName
);
741 // Put the two arrays into the property table.
742 service
->setProperty(gIOInterruptControllersKey
, controller
);
743 service
->setProperty(gIOInterruptSpecifiersKey
, specifier
);
744 controller
->release();
745 specifier
->release();
748 void IOCPUInterruptController::enableCPUInterrupt(IOCPU
*cpu
)
750 IOInterruptHandler handler
= OSMemberFunctionCast(
751 IOInterruptHandler
, this, &IOCPUInterruptController::handleInterrupt
);
753 ml_install_interrupt_handler(cpu
, cpu
->getCPUNumber(), this, handler
, 0);
755 // Ensure that the increment is seen by all processors
756 OSIncrementAtomic(&enabledCPUs
);
758 if (enabledCPUs
== numCPUs
) {
759 IOService::cpusRunning();
764 IOReturn
IOCPUInterruptController::registerInterrupt(IOService
*nub
,
767 IOInterruptHandler handler
,
770 IOInterruptVector
*vector
;
772 if (source
>= numCPUs
) return kIOReturnNoResources
;
774 vector
= &vectors
[source
];
776 // Get the lock for this vector.
777 IOTakeLock(vector
->interruptLock
);
779 // Make sure the vector is not in use.
780 if (vector
->interruptRegistered
) {
781 IOUnlock(vector
->interruptLock
);
782 return kIOReturnNoResources
;
785 // Fill in vector with the client's info.
786 vector
->handler
= handler
;
788 vector
->source
= source
;
789 vector
->target
= target
;
790 vector
->refCon
= refCon
;
792 // Get the vector ready. It starts hard disabled.
793 vector
->interruptDisabledHard
= 1;
794 vector
->interruptDisabledSoft
= 1;
795 vector
->interruptRegistered
= 1;
797 IOUnlock(vector
->interruptLock
);
799 if (enabledCPUs
!= numCPUs
) {
800 assert_wait(this, THREAD_UNINT
);
801 thread_block(THREAD_CONTINUE_NULL
);
804 return kIOReturnSuccess
;
807 IOReturn
IOCPUInterruptController::getInterruptType(IOService */
*nub*/
,
811 if (interruptType
== 0) return kIOReturnBadArgument
;
813 *interruptType
= kIOInterruptTypeLevel
;
815 return kIOReturnSuccess
;
818 IOReturn
IOCPUInterruptController::enableInterrupt(IOService */
*nub*/
,
821 // ml_set_interrupts_enabled(true);
822 return kIOReturnSuccess
;
825 IOReturn
IOCPUInterruptController::disableInterrupt(IOService */
*nub*/
,
828 // ml_set_interrupts_enabled(false);
829 return kIOReturnSuccess
;
832 IOReturn
IOCPUInterruptController::causeInterrupt(IOService */
*nub*/
,
835 ml_cause_interrupt();
836 return kIOReturnSuccess
;
839 IOReturn
IOCPUInterruptController::handleInterrupt(void */
*refCon*/
,
843 IOInterruptVector
*vector
;
845 vector
= &vectors
[source
];
847 if (!vector
->interruptRegistered
) return kIOReturnInvalid
;
849 vector
->handler(vector
->target
, vector
->refCon
,
850 vector
->nub
, vector
->source
);
852 return kIOReturnSuccess
;
855 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */