]> git.saurik.com Git - apple/xnu.git/blob - pexpert/ppc/pe_identify_machine.c
3ff1df2f4571f2b4efc7096e3c9569728f3ea004
[apple/xnu.git] / pexpert / ppc / pe_identify_machine.c
1 /*
2 * Copyright (c) 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 #include <pexpert/protos.h>
23 #include <pexpert/pexpert.h>
24 #include <pexpert/ppc/powermac.h>
25 #include <pexpert/device_tree.h>
26
27 /* External declarations */
28
29 unsigned int LockTimeOut = 12500000;
30
31 /* pe_identify_machine:
32 *
33 * Sets up platform parameters.
34 * Returns: nothing
35 */
36 void pe_identify_machine(void)
37 {
38 DTEntry cpu, root;
39 unsigned long *value;
40 int size;
41
42 // Clear the gPEClockFrequencyInfo struct
43 bzero((void *)&gPEClockFrequencyInfo, sizeof(clock_frequency_info_t));
44
45 // Start with default values.
46 gPEClockFrequencyInfo.bus_clock_rate_hz = 100000000;
47 gPEClockFrequencyInfo.cpu_clock_rate_hz = 300000000;
48 gPEClockFrequencyInfo.dec_clock_rate_hz = 25000000;
49 gPEClockFrequencyInfo.timebase_frequency_hz = 25000000;
50
51 // Try to get the values from the device tree.
52 if (DTFindEntry("device_type", "cpu", &cpu) == kSuccess) {
53 if (DTGetProperty(cpu, "bus-frequency",
54 (void **)&value, &size) == kSuccess)
55 gPEClockFrequencyInfo.bus_clock_rate_hz = *value;
56 else {
57 if (DTLookupEntry(0, "/", &root) == kSuccess)
58 if (DTGetProperty(root, "clock-frequency",
59 (void **)&value, &size) == kSuccess)
60 gPEClockFrequencyInfo.bus_clock_rate_hz = *value;
61 }
62
63 if (DTGetProperty(cpu, "clock-frequency",
64 (void **)&value, &size) == kSuccess)
65 gPEClockFrequencyInfo.cpu_clock_rate_hz = *value;
66
67 if (DTGetProperty(cpu, "timebase-frequency",
68 (void **)&value, &size) == kSuccess) {
69 gPEClockFrequencyInfo.dec_clock_rate_hz = *value;
70 gPEClockFrequencyInfo.timebase_frequency_hz= *value;
71 }
72 }
73
74 // Set the num / den pairs form the hz values.
75 gPEClockFrequencyInfo.timebase_frequency_num = gPEClockFrequencyInfo.timebase_frequency_hz;
76 gPEClockFrequencyInfo.timebase_frequency_den = 1;
77
78 gPEClockFrequencyInfo.bus_clock_rate_num = gPEClockFrequencyInfo.bus_clock_rate_hz;
79 gPEClockFrequencyInfo.bus_clock_rate_den = 1;
80
81 gPEClockFrequencyInfo.bus_to_cpu_rate_num =
82 (2 * gPEClockFrequencyInfo.cpu_clock_rate_hz) / gPEClockFrequencyInfo.bus_clock_rate_hz;
83 gPEClockFrequencyInfo.bus_to_cpu_rate_den = 2;
84
85 gPEClockFrequencyInfo.bus_to_dec_rate_num = 1;
86 gPEClockFrequencyInfo.bus_to_dec_rate_den =
87 gPEClockFrequencyInfo.bus_clock_rate_hz / gPEClockFrequencyInfo.dec_clock_rate_hz;
88 }
89
90 /* get_io_base_addr():
91 *
92 * Get the base address of the io controller.
93 */
94 vm_offset_t get_io_base_addr(void)
95 {
96 DTEntry entryP;
97 vm_offset_t *address;
98 int size;
99
100 if ((DTFindEntry("device_type", "dbdma", &entryP) == kSuccess)
101 || (DTFindEntry("device_type", "mac-io", &entryP) == kSuccess))
102 {
103 if (DTGetProperty(entryP, "AAPL,address", (void **)&address, &size) == kSuccess)
104 return *address;
105
106 if (DTGetProperty(entryP, "assigned-addresses", (void **)&address, &size) == kSuccess)
107 // address calculation not correct
108 return *(address+2);
109 }
110
111 panic("Can't find this machine's io base address\n");
112 return 0;
113 }
114
115 boolean_t PE_init_ethernet_debugger(void)
116 {
117 boolean_t result;
118 #if 0
119 DTEntry entryP;
120 vm_offset_t *address;
121 unsigned char *netAddr;
122 int size;
123 vm_offset_t io;
124
125 if ((io = get_io_base_addr())
126 && (DTFindEntry("name", "mace", &entryP) == kSuccess)
127 && (DTGetProperty(entryP, "local-mac-address", (void **)&netAddr, &size) == kSuccess)
128 && (DTGetProperty(entryP, "reg", (void **)&address, &size) == kSuccess)
129 && (size == (2 * 3 * sizeof(vm_offset_t)) ))
130 {
131 extern boolean_t kdp_mace_init(void *baseAddresses[3],
132 unsigned char *netAddr);
133 void *maceAddrs[3];
134
135 // address calculation not correct
136 maceAddrs[0] = (void *) io_map(io + address[0], address[1]);
137 maceAddrs[1] = (void *) io_map(io + address[2], 0x1000);
138 maceAddrs[2] = (void *) (((vm_offset_t)maceAddrs[1])
139 + address[4] - address[2]);
140 result = kdp_mace_init( maceAddrs, netAddr );
141
142 } else
143 #endif
144 result = FALSE;
145
146 return result;
147 }
148
149 vm_offset_t PE_find_scc(void)
150 {
151 vm_offset_t io;
152 DTEntry entryP;
153
154 if ((io = get_io_base_addr())
155 && (DTFindEntry("name", "escc", &entryP) == kSuccess))
156 io += 0x12000; /* Offset to legacy SCC Registers */
157 else
158 io = 0;
159
160 return io;
161 }