]> git.saurik.com Git - apple/xnu.git/blob - pexpert/ppc/pe_identify_machine.c
xnu-344.tar.gz
[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
50 // Try to get the values from the device tree.
51 if (DTFindEntry("device_type", "cpu", &cpu) == kSuccess) {
52 if (DTGetProperty(cpu, "bus-frequency",
53 (void **)&value, &size) == kSuccess)
54 gPEClockFrequencyInfo.bus_clock_rate_hz = *value;
55 else {
56 if (DTLookupEntry(0, "/", &root) == kSuccess)
57 if (DTGetProperty(root, "clock-frequency",
58 (void **)&value, &size) == kSuccess)
59 gPEClockFrequencyInfo.bus_clock_rate_hz = *value;
60 }
61
62 if (DTGetProperty(cpu, "clock-frequency",
63 (void **)&value, &size) == kSuccess)
64 gPEClockFrequencyInfo.cpu_clock_rate_hz = *value;
65
66 if (DTGetProperty(cpu, "timebase-frequency",
67 (void **)&value, &size) == kSuccess)
68 gPEClockFrequencyInfo.dec_clock_rate_hz = *value;
69 }
70
71 // Set the num / den pairs form the hz values.
72 gPEClockFrequencyInfo.bus_clock_rate_num = gPEClockFrequencyInfo.bus_clock_rate_hz;
73 gPEClockFrequencyInfo.bus_clock_rate_den = 1;
74
75 gPEClockFrequencyInfo.bus_to_cpu_rate_num =
76 (2 * gPEClockFrequencyInfo.cpu_clock_rate_hz) / gPEClockFrequencyInfo.bus_clock_rate_hz;
77 gPEClockFrequencyInfo.bus_to_cpu_rate_den = 2;
78
79 gPEClockFrequencyInfo.bus_to_dec_rate_num = 1;
80 gPEClockFrequencyInfo.bus_to_dec_rate_den =
81 gPEClockFrequencyInfo.bus_clock_rate_hz / gPEClockFrequencyInfo.dec_clock_rate_hz;
82 }
83
84 /* get_io_base_addr():
85 *
86 * Get the base address of the io controller.
87 */
88 vm_offset_t get_io_base_addr(void)
89 {
90 DTEntry entryP;
91 vm_offset_t *address;
92 int size;
93
94 if ((DTFindEntry("device_type", "dbdma", &entryP) == kSuccess)
95 || (DTFindEntry("device_type", "mac-io", &entryP) == kSuccess))
96 {
97 if (DTGetProperty(entryP, "AAPL,address", (void **)&address, &size) == kSuccess)
98 return *address;
99
100 if (DTGetProperty(entryP, "assigned-addresses", (void **)&address, &size) == kSuccess)
101 // address calculation not correct
102 return *(address+2);
103 }
104
105 panic("Can't find this machine's io base address\n");
106 return 0;
107 }
108
109 boolean_t PE_init_ethernet_debugger(void)
110 {
111 boolean_t result;
112 #if 0
113 DTEntry entryP;
114 vm_offset_t *address;
115 unsigned char *netAddr;
116 int size;
117 vm_offset_t io;
118
119 if ((io = get_io_base_addr())
120 && (DTFindEntry("name", "mace", &entryP) == kSuccess)
121 && (DTGetProperty(entryP, "local-mac-address", (void **)&netAddr, &size) == kSuccess)
122 && (DTGetProperty(entryP, "reg", (void **)&address, &size) == kSuccess)
123 && (size == (2 * 3 * sizeof(vm_offset_t)) ))
124 {
125 extern boolean_t kdp_mace_init(void *baseAddresses[3],
126 unsigned char *netAddr);
127 void *maceAddrs[3];
128
129 // address calculation not correct
130 maceAddrs[0] = (void *) io_map(io + address[0], address[1]);
131 maceAddrs[1] = (void *) io_map(io + address[2], 0x1000);
132 maceAddrs[2] = (void *) (((vm_offset_t)maceAddrs[1])
133 + address[4] - address[2]);
134 result = kdp_mace_init( maceAddrs, netAddr );
135
136 } else
137 #endif
138 result = FALSE;
139
140 return result;
141 }
142
143 vm_offset_t PE_find_scc(void)
144 {
145 vm_offset_t io;
146 DTEntry entryP;
147
148 if ((io = get_io_base_addr())
149 && (DTFindEntry("name", "escc", &entryP) == kSuccess))
150 io += 0x12000; /* Offset to legacy SCC Registers */
151 else
152 io = 0;
153
154 return io;
155 }