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