]> git.saurik.com Git - apple/xnu.git/blame - pexpert/ppc/pe_identify_machine.c
xnu-792.6.61.tar.gz
[apple/xnu.git] / pexpert / ppc / pe_identify_machine.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
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.
1c79356b 11 *
37839358
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
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.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22#include <pexpert/protos.h>
23#include <pexpert/pexpert.h>
24#include <pexpert/ppc/powermac.h>
25#include <pexpert/device_tree.h>
26
1c79356b
A
27/* pe_identify_machine:
28 *
29 * Sets up platform parameters.
30 * Returns: nothing
31 */
32void pe_identify_machine(void)
33{
34 DTEntry cpu, root;
35 unsigned long *value;
36 int size;
37
38 // Clear the gPEClockFrequencyInfo struct
39 bzero((void *)&gPEClockFrequencyInfo, sizeof(clock_frequency_info_t));
40
41 // Start with default values.
43866e37
A
42 gPEClockFrequencyInfo.timebase_frequency_hz = 25000000;
43 gPEClockFrequencyInfo.bus_clock_rate_hz = 100000000;
44 gPEClockFrequencyInfo.cpu_clock_rate_hz = 300000000;
90556fb8 45
1c79356b
A
46 // Try to get the values from the device tree.
47 if (DTFindEntry("device_type", "cpu", &cpu) == kSuccess) {
43866e37
A
48 // Find the time base frequency first.
49 if (DTGetProperty(cpu, "timebase-frequency", (void **)&value, &size) == kSuccess) {
50 // timebase_frequency_hz is only 32 bits, and the device tree should never provide 64 bits
51 // so this if should never be taken.
52 if (size == 8) gPEClockFrequencyInfo.timebase_frequency_hz = *(unsigned long long *)value;
53 else gPEClockFrequencyInfo.timebase_frequency_hz = *value;
54 }
55 gPEClockFrequencyInfo.dec_clock_rate_hz = gPEClockFrequencyInfo.timebase_frequency_hz;
56
57 // Find the bus frequency next. Try the cpu node, then the root.
58 if (DTGetProperty(cpu, "bus-frequency", (void **)&value, &size) == kSuccess) {
59 if (size == 8) gPEClockFrequencyInfo.bus_frequency_hz = *(unsigned long long *)value;
60 else gPEClockFrequencyInfo.bus_frequency_hz = *value;
61 } else {
62 if (DTLookupEntry(0, "/", &root) == kSuccess) {
63 if (DTGetProperty(root, "clock-frequency", (void **)&value, &size) == kSuccess) {
64 if (size == 8) gPEClockFrequencyInfo.bus_frequency_hz = *(unsigned long long *)value;
65 else gPEClockFrequencyInfo.bus_frequency_hz = *value;
66 }
67 }
1c79356b
A
68 }
69
43866e37
A
70 gPEClockFrequencyInfo.bus_frequency_min_hz = gPEClockFrequencyInfo.bus_frequency_hz;
71 gPEClockFrequencyInfo.bus_frequency_max_hz = gPEClockFrequencyInfo.bus_frequency_hz;
72
73 if (gPEClockFrequencyInfo.bus_frequency_hz < 0x100000000ULL)
74 gPEClockFrequencyInfo.bus_clock_rate_hz = gPEClockFrequencyInfo.bus_frequency_hz;
75 else
76 gPEClockFrequencyInfo.bus_clock_rate_hz = 0xFFFFFFFF;
1c79356b 77
43866e37
A
78 // Find the cpu frequency last.
79 if (DTGetProperty(cpu, "clock-frequency", (void **)&value, &size) == kSuccess) {
80 if (size == 8) gPEClockFrequencyInfo.cpu_frequency_hz = *(unsigned long long *)value;
81 else gPEClockFrequencyInfo.cpu_frequency_hz = *value;
90556fb8 82 }
43866e37
A
83
84 gPEClockFrequencyInfo.cpu_frequency_min_hz = gPEClockFrequencyInfo.cpu_frequency_hz;
85 gPEClockFrequencyInfo.cpu_frequency_max_hz = gPEClockFrequencyInfo.cpu_frequency_hz;
86
87 if (gPEClockFrequencyInfo.cpu_frequency_hz < 0x100000000ULL)
88 gPEClockFrequencyInfo.cpu_clock_rate_hz = gPEClockFrequencyInfo.cpu_frequency_hz;
89 else
90 gPEClockFrequencyInfo.cpu_clock_rate_hz = 0xFFFFFFFF;
1c79356b
A
91 }
92
93 // Set the num / den pairs form the hz values.
90556fb8
A
94 gPEClockFrequencyInfo.timebase_frequency_num = gPEClockFrequencyInfo.timebase_frequency_hz;
95 gPEClockFrequencyInfo.timebase_frequency_den = 1;
43866e37 96
1c79356b
A
97 gPEClockFrequencyInfo.bus_clock_rate_num = gPEClockFrequencyInfo.bus_clock_rate_hz;
98 gPEClockFrequencyInfo.bus_clock_rate_den = 1;
99
100 gPEClockFrequencyInfo.bus_to_cpu_rate_num =
101 (2 * gPEClockFrequencyInfo.cpu_clock_rate_hz) / gPEClockFrequencyInfo.bus_clock_rate_hz;
102 gPEClockFrequencyInfo.bus_to_cpu_rate_den = 2;
103
104 gPEClockFrequencyInfo.bus_to_dec_rate_num = 1;
105 gPEClockFrequencyInfo.bus_to_dec_rate_den =
106 gPEClockFrequencyInfo.bus_clock_rate_hz / gPEClockFrequencyInfo.dec_clock_rate_hz;
107}
108
109/* get_io_base_addr():
110 *
111 * Get the base address of the io controller.
112 */
113vm_offset_t get_io_base_addr(void)
114{
115 DTEntry entryP;
116 vm_offset_t *address;
117 int size;
118
119 if ((DTFindEntry("device_type", "dbdma", &entryP) == kSuccess)
120 || (DTFindEntry("device_type", "mac-io", &entryP) == kSuccess))
121 {
122 if (DTGetProperty(entryP, "AAPL,address", (void **)&address, &size) == kSuccess)
123 return *address;
124
125 if (DTGetProperty(entryP, "assigned-addresses", (void **)&address, &size) == kSuccess)
126 // address calculation not correct
127 return *(address+2);
128 }
129
130 panic("Can't find this machine's io base address\n");
131 return 0;
132}
133
55e303ae 134vm_offset_t PE_find_scc(void)
1c79356b 135{
55e303ae
A
136 vm_offset_t io, sccadd;
137 DTEntry entryP;
138 vm_offset_t *sccregs;
139 unsigned int sccrsize;
140
141 if(!(io = get_io_base_addr())) { /* Get the I/O controller base address */
142 return (vm_offset_t)0; /* Hmmm, no I/O??? What gives??? How'd we even boot? */
143 }
144
145
146/* Note: if we find a escc-legacy, we need to kind of hack because it can be either an offset
147 into the iobase or the actual address itself. ORint the two should provide the correct
148 for either */
149
150 sccadd = 0; /* Assume none for now */
151
152 if(DTFindEntry("name", "escc-legacy", &entryP) == kSuccess) { /* Find the old fashioned serial port */
153 if (DTGetProperty(entryP, "reg", (void **)&sccregs, &sccrsize) == kSuccess) { /* Do we have some registers? */
154 sccadd = ((vm_offset_t)*sccregs | io); /* Get the address */
155 }
156 }
157
158 if(DTFindEntry("name", "escc", &entryP) == kSuccess) { /* Well, see if we just have the new fangled one */
159 sccadd = io + 0x12000; /* Yeah, but still return the oldie goldie... */
160 }
161
162 return sccadd; /* Return it if you found it */
1c79356b
A
163}
164
55e303ae 165unsigned int PE_init_taproot(vm_offset_t *taddr)
1c79356b 166{
55e303ae
A
167 DTEntry entryP;
168 vm_offset_t *tappdata;
169 unsigned int tappsize;
170
171
172 if(DTFindEntry("name", "memory-map", &entryP) != kSuccess) return 0; /* no memory map */
173
174 if (DTGetProperty(entryP, "TapRoot", (void **)&tappdata, &tappsize) != kSuccess) return 0; /* No TapRoot */
175
176 tappdata[1] = (tappdata[1] + 4095 ) & -4096; /* Make sure this is a whole page */
177
178 *taddr = io_map_spec(tappdata[0], tappdata[1]); /* Map it in and return the address */
179 tappdata[0] = *taddr; /* Also change property */
180 return tappdata[1]; /* And the size */
1c79356b 181}