]> git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/platform/drvApplePlatformExpert/ApplePlatformExpert.cpp
03f9ffd3081a9e492029bb58588cc07a828c3b10
[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_OSREFERENCE_HEADER_START@
5 *
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * HISTORY
32 *
33 */
34
35 #include <IOKit/IODeviceTreeSupport.h>
36 #include <IOKit/IORangeAllocator.h>
37 #include <IOKit/nvram/IONVRAMController.h>
38
39 #include <IOKit/platform/ApplePlatformExpert.h>
40
41
42 const OSSymbol *gGetDefaultBusSpeedsKey;
43
44 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
45
46 #define super IODTPlatformExpert
47
48 OSDefineMetaClassAndAbstractStructors(ApplePlatformExpert, IODTPlatformExpert);
49
50 OSMetaClassDefineReservedUnused(ApplePlatformExpert, 0);
51 OSMetaClassDefineReservedUnused(ApplePlatformExpert, 1);
52 OSMetaClassDefineReservedUnused(ApplePlatformExpert, 2);
53 OSMetaClassDefineReservedUnused(ApplePlatformExpert, 3);
54
55 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
56
57 bool ApplePlatformExpert::start( IOService * provider )
58 {
59 UInt16 romVersion;
60
61 gGetDefaultBusSpeedsKey = OSSymbol::withCString("GetDefaultBusSpeeds");
62
63 if (provider->getProperty(gIODTNWInterruptMappingKey)) {
64 // new world interrupt mapping => new world, for now
65 setBootROMType(kBootROMTypeNewWorld);
66 } else {
67 setBootROMType(kBootROMTypeOldWorld);
68
69 // Get the Rom Minor Version from the 68k ROM.
70 romVersion = ml_phys_read_64(0xffc00010ULL) & 0x0000ffff;
71 provider->setProperty("rom-version", &romVersion, sizeof(romVersion));
72 }
73
74 return super::start(provider);
75 }
76
77 bool ApplePlatformExpert::configure( IOService * provider )
78 {
79 IORangeAllocator * physicalRanges;
80
81 if((physicalRanges = getPhysicalRangeAllocator())) {
82 physicalRanges->allocateRange(0,0x80000000); // RAM
83 physicalRanges->allocateRange(0xff000000,0x01000000); // ROM
84 }
85 return(super::configure(provider));
86 }
87
88 const char * ApplePlatformExpert::deleteList ( void )
89 {
90 return( "('packages', 'psuedo-usb', 'psuedo-hid', 'multiboot', 'rtas')" );
91 }
92
93 const char * ApplePlatformExpert::excludeList( void )
94 {
95 return( "('chosen', 'memory', 'openprom', 'AAPL,ROM', 'rom', 'options', 'aliases')");
96 }
97
98 void ApplePlatformExpert::registerNVRAMController( IONVRAMController * nvram )
99 {
100 IOReturn err;
101 enum { kXPRAMTimeToGMTOffset = 0xEC };
102
103 super::registerNVRAMController(nvram);
104
105 // Here we are saving off the time zone info that's in PRAM.
106 // This probably should be a separate call that the
107 // ApplePlatformExpert does in it's initialization. -ECH
108
109 err = readXPRAM(kXPRAMTimeToGMTOffset, (UInt8 *)&_timeToGMT,
110 sizeof(_timeToGMT));
111 if (err == kIOReturnSuccess) {
112 // Convert from a SInt24 - sign extend from bit 23.
113 if (_timeToGMT & (1 << 23))
114 _timeToGMT |= 0xFF000000;
115 else
116 _timeToGMT &= 0x00FFFFFF;
117 }
118 }
119
120 #define SECS_BETWEEN_1904_1970 2082844800
121
122 long ApplePlatformExpert::getGMTTimeOfDay(void)
123 {
124 long localtime;
125
126 // to avid to hang the kernel at boot
127 // I set a limit of 15 seconds waiting
128 // for the real time clock.
129 mach_timespec_t t;
130 t.tv_sec = 30;
131 t.tv_nsec = 0;
132 if (waitForService(resourceMatching("IORTC"), &t ) != NULL) {
133 if (PE_read_write_time_of_day(kPEReadTOD, &localtime) == 0)
134 return (localtime - _timeToGMT - SECS_BETWEEN_1904_1970);
135 }
136 else
137 IOLog("ApplePlatformExpert::getGMTTimeOfDay can not provide time of day RTC did not show up\n");
138
139 return(0);
140 }
141
142 void ApplePlatformExpert::setGMTTimeOfDay(long secs)
143 {
144 // to avid to hang the kernel at boot
145 // I set a limit of 15 seconds waiting
146 // for the real time clock.
147 mach_timespec_t t;
148 t.tv_sec = 30;
149 t.tv_nsec = 0;
150 if (waitForService(resourceMatching("IORTC"), &t ) != NULL) {
151 secs += SECS_BETWEEN_1904_1970;
152 secs += _timeToGMT;
153 PE_read_write_time_of_day(kPEWriteTOD, &secs);
154 }
155 else
156 IOLog("ApplePlatformExpert::setGMTTimeOfDay can not set time of day RTC did not show up\n");
157
158 }
159
160 bool ApplePlatformExpert::getMachineName(char *name, int maxLength)
161 {
162 strncpy(name, "Power Macintosh", maxLength);
163
164 return true;
165 }