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