]> git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/platform/drvAppleI386Generic/AppleI386PlatformExpert.cpp
xnu-344.12.2.tar.gz
[apple/xnu.git] / iokit / Drivers / platform / drvAppleI386Generic / AppleI386PlatformExpert.cpp
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 */
27
28 #include <IOKit/system.h>
29
30 #include <architecture/i386/kernBootStruct.h>
31
32 #include <IOKit/IORegistryEntry.h>
33 #include <libkern/c++/OSContainers.h>
34 #include <IOKit/IOLib.h>
35 #include <libkern/c++/OSUnserialize.h>
36
37 #include <IOKit/platform/ApplePlatformExpert.h>
38 #include "AppleI386PlatformExpert.h"
39
40 #include <IOKit/assert.h>
41
42 __BEGIN_DECLS
43 extern void kdreboot(void);
44 __END_DECLS
45 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
46
47 #define super IOPlatformExpert
48
49 OSSymbol * gIntelPICName;
50
51 OSDefineMetaClassAndStructors(AppleI386PlatformExpert, IOPlatformExpert)
52
53 IOService * AppleI386PlatformExpert::probe(IOService * /* provider */,
54 SInt32 * score )
55 {
56 *score = 2000;
57
58 return (this);
59 }
60
61 bool AppleI386PlatformExpert::start(IOService * provider)
62 {
63 gIntelPICName = (OSSymbol *) OSSymbol::withCStringNoCopy("intel-pic");
64
65 setBootROMType(kBootROMTypeNewWorld); /* hammer to new world for i386 */
66
67 // setupPIC(provider);
68
69 if (!super::start(provider))
70 return false;
71
72 // Install halt/restart handler.
73
74 PE_halt_restart = handlePEHaltRestart;
75
76 return true;
77 }
78
79 IOService * AppleI386PlatformExpert::createNub(OSDictionary * from)
80 {
81 IOService * nub;
82 OSData * prop;
83 KERNBOOTSTRUCT * bootStruct;
84
85 nub = super::createNub(from);
86
87 if (nub)
88 {
89 if (0 == strcmp( "pci", nub->getName()))
90 {
91 bootStruct = (KERNBOOTSTRUCT *) PE_state.bootArgs;
92 prop = OSData::withBytesNoCopy(&bootStruct->pciInfo,
93 sizeof(bootStruct->pciInfo));
94 assert(prop);
95 if (prop)
96 from->setObject( "pci-bus-info", prop);
97 }
98 else if (0 != strcmp("intel-pic", nub->getName()))
99 {
100 setupPIC(nub);
101 }
102 }
103
104 return (nub);
105 }
106
107 #define kNumVectors 16
108
109 void
110 AppleI386PlatformExpert::setupPIC(IOService *nub)
111 {
112 int i;
113 OSDictionary * propTable;
114 OSArray * controller;
115 OSArray * specifier;
116 OSData * tmpData;
117 long tmpLong;
118
119 propTable = nub->getPropertyTable();
120
121 //
122 // For the moment.. assume a classic 8259 interrupt controller
123 // with 16 interrupts.
124 //
125 // Later, this will be changed to detect a APIC and/or MP-Table
126 // and then will set the nubs appropriately.
127
128 // Create the interrupt specifer array.
129 specifier = OSArray::withCapacity(kNumVectors);
130 assert(specifier);
131 for (i = 0; i < kNumVectors; i++) {
132 tmpLong = i;
133 tmpData = OSData::withBytes(&tmpLong, sizeof(tmpLong));
134 specifier->setObject(tmpData);
135 }
136
137 // Create the interrupt controller array.
138 controller = OSArray::withCapacity(kNumVectors);
139 assert(controller);
140 for (i = 0; i < kNumVectors; i++)
141 controller->setObject(gIntelPICName);
142
143 // Put the two arrays into the property table.
144 propTable->setObject(gIOInterruptControllersKey, controller);
145 propTable->setObject(gIOInterruptSpecifiersKey, specifier);
146
147 // Release the arrays after being added to the property table.
148 specifier->release();
149 controller->release();
150 }
151
152 bool
153 AppleI386PlatformExpert::matchNubWithPropertyTable(IOService * nub,
154 OSDictionary * propTable )
155 {
156 OSString * nameProp;
157 OSString * match;
158
159 if (0 == (nameProp = (OSString *) nub->getProperty(gIONameKey)))
160 return (false);
161
162 if ( 0 == (match = (OSString *) propTable->getObject(gIONameMatchKey)))
163 return (false);
164
165 return (match->isEqualTo( nameProp ));
166 }
167
168 bool AppleI386PlatformExpert::getMachineName( char * name, int maxLength )
169 {
170 strncpy( name, "x86", maxLength );
171
172 return (true);
173 }
174
175 bool AppleI386PlatformExpert::getModelName( char * name, int maxLength )
176 {
177 strncpy( name, "x86", maxLength );
178
179 return (true);
180 }
181
182 int AppleI386PlatformExpert::handlePEHaltRestart( unsigned int type )
183 {
184 int ret = 1;
185
186 switch ( type )
187 {
188 case kPERestartCPU:
189 // Use the pexpert service to reset the system through
190 // the keyboard controller.
191 kdreboot();
192 break;
193
194 case kPEHaltCPU:
195 default:
196 ret = -1;
197 break;
198 }
199
200 return ret;
201 }