1bb611c8fSApple OSS Distributions /*
2bb611c8fSApple OSS Distributions * Copyright (c) 2019 Apple Computer, Inc. All rights reserved.
3bb611c8fSApple OSS Distributions *
4bb611c8fSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5bb611c8fSApple OSS Distributions *
6bb611c8fSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7bb611c8fSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8bb611c8fSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9bb611c8fSApple OSS Distributions * compliance with the License. The rights granted to you under the License
10bb611c8fSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11bb611c8fSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12bb611c8fSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13bb611c8fSApple OSS Distributions * terms of an Apple operating system software license agreement.
14bb611c8fSApple OSS Distributions *
15bb611c8fSApple OSS Distributions * Please obtain a copy of the License at
16bb611c8fSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17bb611c8fSApple OSS Distributions *
18bb611c8fSApple OSS Distributions * The Original Code and all software distributed under the License are
19bb611c8fSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20bb611c8fSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21bb611c8fSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22bb611c8fSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23bb611c8fSApple OSS Distributions * Please see the License for the specific language governing rights and
24bb611c8fSApple OSS Distributions * limitations under the License.
25bb611c8fSApple OSS Distributions *
26bb611c8fSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27bb611c8fSApple OSS Distributions */
28bb611c8fSApple OSS Distributions
29bb611c8fSApple OSS Distributions extern "C" {
30bb611c8fSApple OSS Distributions #include <mach/task.h>
31bb611c8fSApple OSS Distributions #include <pexpert/pexpert.h>
32bb611c8fSApple OSS Distributions };
33bb611c8fSApple OSS Distributions
34e6231be0SApple OSS Distributions #include <machine/machine_routines.h>
35bb611c8fSApple OSS Distributions #include <IOKit/IOPlatformExpert.h>
36bb611c8fSApple OSS Distributions #include <IOKit/IOService.h>
37bb611c8fSApple OSS Distributions #include <IOKit/PassthruInterruptController.h>
38bb611c8fSApple OSS Distributions
39bb611c8fSApple OSS Distributions #define super IOInterruptController
40bb611c8fSApple OSS Distributions OSDefineMetaClassAndStructors(PassthruInterruptController, IOInterruptController);
41bb611c8fSApple OSS Distributions
42bb611c8fSApple OSS Distributions bool
init(void)43bb611c8fSApple OSS Distributions PassthruInterruptController::init(void)
44bb611c8fSApple OSS Distributions {
45bb611c8fSApple OSS Distributions if (!super::init() ||
46bb611c8fSApple OSS Distributions !this->setProperty(gPlatformInterruptControllerName, kOSBooleanTrue) ||
47bb611c8fSApple OSS Distributions !this->attach(getPlatform())) {
48bb611c8fSApple OSS Distributions return false;
49bb611c8fSApple OSS Distributions }
50bb611c8fSApple OSS Distributions registerService();
51bb611c8fSApple OSS Distributions if (getPlatform()->registerInterruptController(gPlatformInterruptControllerName, this) != kIOReturnSuccess) {
52bb611c8fSApple OSS Distributions return false;
53bb611c8fSApple OSS Distributions }
54bb611c8fSApple OSS Distributions if (semaphore_create(kernel_task, &child_sentinel, SYNC_POLICY_FIFO, 0) != KERN_SUCCESS) {
55bb611c8fSApple OSS Distributions return false;
56bb611c8fSApple OSS Distributions }
57bb611c8fSApple OSS Distributions return true;
58bb611c8fSApple OSS Distributions }
59bb611c8fSApple OSS Distributions
60bb611c8fSApple OSS Distributions void
setCPUInterruptProperties(IOService * service)61bb611c8fSApple OSS Distributions PassthruInterruptController::setCPUInterruptProperties(IOService *service)
62bb611c8fSApple OSS Distributions {
63bb611c8fSApple OSS Distributions if ((service->getProperty(gIOInterruptControllersKey) != NULL) &&
64bb611c8fSApple OSS Distributions (service->getProperty(gIOInterruptSpecifiersKey) != NULL)) {
65bb611c8fSApple OSS Distributions return;
66bb611c8fSApple OSS Distributions }
67bb611c8fSApple OSS Distributions
68bb611c8fSApple OSS Distributions long zero = 0;
69bb611c8fSApple OSS Distributions OSArray *specifier = OSArray::withCapacity(1);
70*e7776783SApple OSS Distributions OSData *tmpData = OSData::withValue(zero);
71bb611c8fSApple OSS Distributions specifier->setObject(tmpData);
72bb611c8fSApple OSS Distributions tmpData->release();
73bb611c8fSApple OSS Distributions service->setProperty(gIOInterruptSpecifiersKey, specifier);
74bb611c8fSApple OSS Distributions specifier->release();
75bb611c8fSApple OSS Distributions
76bb611c8fSApple OSS Distributions OSArray *controller = OSArray::withCapacity(1);
77bb611c8fSApple OSS Distributions controller->setObject(gPlatformInterruptControllerName);
78bb611c8fSApple OSS Distributions service->setProperty(gIOInterruptControllersKey, controller);
79bb611c8fSApple OSS Distributions controller->release();
80bb611c8fSApple OSS Distributions }
81bb611c8fSApple OSS Distributions
82bb611c8fSApple OSS Distributions IOReturn
registerInterrupt(IOService * nub,int source,void * target,IOInterruptHandler handler,void * refCon)83bb611c8fSApple OSS Distributions PassthruInterruptController::registerInterrupt(IOService *nub,
84bb611c8fSApple OSS Distributions int source,
85bb611c8fSApple OSS Distributions void *target,
86bb611c8fSApple OSS Distributions IOInterruptHandler handler,
87bb611c8fSApple OSS Distributions void *refCon)
88bb611c8fSApple OSS Distributions {
89bb611c8fSApple OSS Distributions child_handler = handler;
90bb611c8fSApple OSS Distributions child_nub = nub;
91bb611c8fSApple OSS Distributions child_target = target;
92bb611c8fSApple OSS Distributions child_refCon = refCon;
93bb611c8fSApple OSS Distributions
94bb611c8fSApple OSS Distributions // Wake up waitForChildController() to tell it that AIC is registered
95bb611c8fSApple OSS Distributions semaphore_signal(child_sentinel);
96bb611c8fSApple OSS Distributions return kIOReturnSuccess;
97bb611c8fSApple OSS Distributions }
98bb611c8fSApple OSS Distributions
99bb611c8fSApple OSS Distributions void *
waitForChildController(void)100bb611c8fSApple OSS Distributions PassthruInterruptController::waitForChildController(void)
101bb611c8fSApple OSS Distributions {
102bb611c8fSApple OSS Distributions // Block if child controller isn't registered yet. Assumes that this
103bb611c8fSApple OSS Distributions // is only called from one place.
104bb611c8fSApple OSS Distributions semaphore_wait(child_sentinel);
105bb611c8fSApple OSS Distributions
106bb611c8fSApple OSS Distributions // NOTE: Assumes that AppleInterruptController passes |this| as the target argument.
107bb611c8fSApple OSS Distributions return child_target;
108bb611c8fSApple OSS Distributions }
109bb611c8fSApple OSS Distributions
110bb611c8fSApple OSS Distributions IOReturn
getInterruptType(IOService *,int,int * interruptType)111bb611c8fSApple OSS Distributions PassthruInterruptController::getInterruptType(IOService */*nub*/,
112bb611c8fSApple OSS Distributions int /*source*/,
113bb611c8fSApple OSS Distributions int *interruptType)
114bb611c8fSApple OSS Distributions {
115bb611c8fSApple OSS Distributions if (interruptType == NULL) {
116bb611c8fSApple OSS Distributions return kIOReturnBadArgument;
117bb611c8fSApple OSS Distributions }
118bb611c8fSApple OSS Distributions
119bb611c8fSApple OSS Distributions *interruptType = kIOInterruptTypeLevel;
120bb611c8fSApple OSS Distributions
121bb611c8fSApple OSS Distributions return kIOReturnSuccess;
122bb611c8fSApple OSS Distributions }
123bb611c8fSApple OSS Distributions
124bb611c8fSApple OSS Distributions IOReturn
enableInterrupt(IOService *,int)125bb611c8fSApple OSS Distributions PassthruInterruptController::enableInterrupt(IOService */*nub*/,
126bb611c8fSApple OSS Distributions int /*source*/)
127bb611c8fSApple OSS Distributions {
128bb611c8fSApple OSS Distributions return kIOReturnSuccess;
129bb611c8fSApple OSS Distributions }
130bb611c8fSApple OSS Distributions
131bb611c8fSApple OSS Distributions IOReturn
disableInterrupt(IOService *,int)132bb611c8fSApple OSS Distributions PassthruInterruptController::disableInterrupt(IOService */*nub*/,
133bb611c8fSApple OSS Distributions int /*source*/)
134bb611c8fSApple OSS Distributions {
135bb611c8fSApple OSS Distributions return kIOReturnSuccess;
136bb611c8fSApple OSS Distributions }
137bb611c8fSApple OSS Distributions
138bb611c8fSApple OSS Distributions IOReturn
causeInterrupt(IOService *,int)139bb611c8fSApple OSS Distributions PassthruInterruptController::causeInterrupt(IOService */*nub*/,
140bb611c8fSApple OSS Distributions int /*source*/)
141bb611c8fSApple OSS Distributions {
142bb611c8fSApple OSS Distributions ml_cause_interrupt();
143bb611c8fSApple OSS Distributions return kIOReturnSuccess;
144bb611c8fSApple OSS Distributions }
145bb611c8fSApple OSS Distributions
146bb611c8fSApple OSS Distributions IOReturn
handleInterrupt(void *,IOService *,int source)147bb611c8fSApple OSS Distributions PassthruInterruptController::handleInterrupt(void */*refCon*/,
148bb611c8fSApple OSS Distributions IOService */*nub*/,
149bb611c8fSApple OSS Distributions int source)
150bb611c8fSApple OSS Distributions {
151bb611c8fSApple OSS Distributions panic("handleInterrupt shouldn't be invoked directly");
152bb611c8fSApple OSS Distributions }
153bb611c8fSApple OSS Distributions
154bb611c8fSApple OSS Distributions void
externalInterrupt(void)155bb611c8fSApple OSS Distributions PassthruInterruptController::externalInterrupt(void)
156bb611c8fSApple OSS Distributions {
157bb611c8fSApple OSS Distributions child_handler(child_target, child_refCon, child_nub, 0);
158bb611c8fSApple OSS Distributions }
159