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