]> git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/platform/drvApplePlatformExpert/ApplePlatformExpert.cpp
f14b821bbe3aaea90a42b0eab8fac6f3969c1143
[apple/xnu.git] / iokit / Drivers / platform / drvApplePlatformExpert / ApplePlatformExpert.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 * HISTORY
24 *
25 */
26
27 #include <IOKit/IODeviceTreeSupport.h>
28 #include <IOKit/IORangeAllocator.h>
29 #include <IOKit/nvram/IONVRAMController.h>
30
31 #include <IOKit/platform/ApplePlatformExpert.h>
32
33
34 const OSSymbol *gGetDefaultBusSpeedsKey;
35
36 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
37
38 #define super IODTPlatformExpert
39
40 OSDefineMetaClassAndAbstractStructors(ApplePlatformExpert, IODTPlatformExpert);
41
42 OSMetaClassDefineReservedUnused(ApplePlatformExpert, 0);
43 OSMetaClassDefineReservedUnused(ApplePlatformExpert, 1);
44 OSMetaClassDefineReservedUnused(ApplePlatformExpert, 2);
45 OSMetaClassDefineReservedUnused(ApplePlatformExpert, 3);
46
47 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
48
49 bool ApplePlatformExpert::start( IOService * provider )
50 {
51 UInt16 romVersion;
52
53 gGetDefaultBusSpeedsKey = OSSymbol::withCString("GetDefaultBusSpeeds");
54
55 if (provider->getProperty(gIODTNWInterruptMappingKey)) {
56 // new world interrupt mapping => new world, for now
57 setBootROMType(kBootROMTypeNewWorld);
58 } else {
59 setBootROMType(kBootROMTypeOldWorld);
60
61 // Get the Rom Minor Version from the 68k ROM.
62 romVersion = ml_phys_read(0xffc00010) & 0x0000ffff;
63 provider->setProperty("rom-version", &romVersion, sizeof(romVersion));
64 }
65
66 return super::start(provider);
67 }
68
69 bool ApplePlatformExpert::configure( IOService * provider )
70 {
71 IORangeAllocator * physicalRanges;
72
73 if((physicalRanges = getPhysicalRangeAllocator())) {
74 physicalRanges->allocateRange(0,0x80000000); // RAM
75 physicalRanges->allocateRange(0xff000000,0x01000000); // ROM
76 }
77 return(super::configure(provider));
78 }
79
80 const char * ApplePlatformExpert::deleteList ( void )
81 {
82 return( "('packages', 'psuedo-usb', 'psuedo-hid', 'multiboot', 'rtas')" );
83 }
84
85 const char * ApplePlatformExpert::excludeList( void )
86 {
87 return( "('chosen', 'memory', 'openprom', 'AAPL,ROM', 'rom', 'options', 'aliases')");
88 }
89
90 void ApplePlatformExpert::registerNVRAMController( IONVRAMController * nvram )
91 {
92 IOReturn err;
93 enum { kXPRAMTimeToGMTOffset = 0xEC };
94
95 super::registerNVRAMController(nvram);
96
97 // Here we are saving off the time zone info that's in PRAM.
98 // This probably should be a separate call that the
99 // ApplePlatformExpert does in it's initialization. -ECH
100
101 err = readXPRAM(kXPRAMTimeToGMTOffset, (UInt8 *)&_timeToGMT,
102 sizeof(_timeToGMT));
103 if (err == kIOReturnSuccess) {
104 // Convert from a SInt24 - sign extend from bit 23.
105 if (_timeToGMT & (1 << 23))
106 _timeToGMT |= 0xFF000000;
107 else
108 _timeToGMT &= 0x00FFFFFF;
109 }
110 }
111
112 #define SECS_BETWEEN_1904_1970 2082844800
113
114 long ApplePlatformExpert::getGMTTimeOfDay(void)
115 {
116 long localtime;
117
118 // to avid to hang the kernel at boot
119 // I set a limit of 15 seconds waiting
120 // for the real time clock.
121 mach_timespec_t t;
122 t.tv_sec = 30;
123 t.tv_nsec = 0;
124 if (waitForService(resourceMatching("IORTC"), &t ) != NULL) {
125 if (PE_read_write_time_of_day(kPEReadTOD, &localtime) == 0)
126 return (localtime - _timeToGMT - SECS_BETWEEN_1904_1970);
127 }
128 else
129 IOLog("ApplePlatformExpert::getGMTTimeOfDay can not provide time of day RTC did not show up\n");
130
131 return(0);
132 }
133
134 void ApplePlatformExpert::setGMTTimeOfDay(long secs)
135 {
136 // to avid to hang the kernel at boot
137 // I set a limit of 15 seconds waiting
138 // for the real time clock.
139 mach_timespec_t t;
140 t.tv_sec = 30;
141 t.tv_nsec = 0;
142 if (waitForService(resourceMatching("IORTC"), &t ) != NULL) {
143 secs += SECS_BETWEEN_1904_1970;
144 secs += _timeToGMT;
145 PE_read_write_time_of_day(kPEWriteTOD, &secs);
146 }
147 else
148 IOLog("ApplePlatformExpert::setGMTTimeOfDay can not set time of day RTC did not show up\n");
149
150 }
151
152 bool ApplePlatformExpert::getMachineName(char *name, int maxLength)
153 {
154 strncpy(name, "Power Macintosh", maxLength);
155
156 return true;
157 }