1 /*
2 * Copyright (C) 1996 Wolfgang Solfrank.
3 * Copyright (C) 1996 TooLs GmbH.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by TooLs GmbH.
17 * 4. The name of TooLs GmbH may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * $NetBSD: ofw_machdep.c,v 1.5 2000/05/23 13:25:43 tsubai Exp $
32 */
33
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD: releng/5.2/sys/powerpc/powerpc/ofw_machdep.c 115614 2003-06-01 09:25:17Z phk $");
36
37 #include <sys/param.h>
38 #include <sys/bus.h>
39 #include <sys/systm.h>
40 #include <sys/conf.h>
41 #include <sys/disk.h>
42 #include <sys/fcntl.h>
43 #include <sys/malloc.h>
44 #include <sys/stat.h>
45
46 #include <net/ethernet.h>
47
48 #include <dev/ofw/openfirm.h>
49
50 #include <vm/vm.h>
51 #include <vm/vm_param.h>
52 #include <vm/vm_page.h>
53
54 #include <machine/powerpc.h>
55 #include <machine/ofw_machdep.h>
56 #include <powerpc/ofw/ofw_pci.h>
57
58 #define OFMEM_REGIONS 32
59 static struct mem_region OFmem[OFMEM_REGIONS + 1], OFavail[OFMEM_REGIONS + 3];
60
61 extern long ofmsr;
62 extern struct pmap ofw_pmap;
63 extern int pmap_bootstrapped;
64 static int (*ofwcall)(void *);
65
66 /*
67 * This is called during powerpc_init, before the system is really initialized.
68 * It shall provide the total and the available regions of RAM.
69 * Both lists must have a zero-size entry as terminator.
70 * The available regions need not take the kernel into account, but needs
71 * to provide space for two additional entry beyond the terminating one.
72 */
73 void
74 mem_regions(struct mem_region **memp, int *memsz,
75 struct mem_region **availp, int *availsz)
76 {
77 int phandle;
78 int asz, msz;
79
80 /*
81 * Get memory.
82 */
83 if ((phandle = OF_finddevice("/memory")) == -1
84 || (msz = OF_getprop(phandle, "reg",
85 OFmem, sizeof OFmem[0] * OFMEM_REGIONS))
86 <= 0
87 || (asz = OF_getprop(phandle, "available",
88 OFavail, sizeof OFavail[0] * OFMEM_REGIONS))
89 <= 0)
90 panic("no memory?");
91 *memp = OFmem;
92 *memsz = msz / sizeof(struct mem_region);
93 *availp = OFavail;
94 *availsz = asz / sizeof(struct mem_region);
95 }
96
97 void
98 set_openfirm_callback(int (*openfirm)(void *))
99 {
100
101 ofwcall = openfirm;
102 }
103
104 int
105 openfirmware(void *args)
106 {
107 long oldmsr;
108 int result;
109 u_int srsave[16];
110 u_int i;
111
112 __asm __volatile( "\t"
113 "sync\n\t"
114 "mfmsr %0\n\t"
115 "mtmsr %1\n\t"
116 "isync\n"
117 : "=r" (oldmsr)
118 : "r" (ofmsr)
119 );
120
121 if (pmap_bootstrapped) {
122 /*
123 * Swap the kernel's address space with OpenFirmware's
124 */
125 for (i = 0; i < 16; i++) {
126 srsave[i] = mfsrin(i << ADDR_SR_SHFT);
127 mtsrin(i << ADDR_SR_SHFT, ofw_pmap.pm_sr[i]);
128 }
129
130 /*
131 * Clear battable[] translations
132 */
133 __asm __volatile("mtdbatu 2, %0\n"
134 "mtdbatu 3, %0" : : "r" (0));
135 isync();
136 }
137
138 result = ofwcall(args);
139
140 if (pmap_bootstrapped) {
141 /*
142 * Restore the kernel's addr space. The isync() doesn;t
143 * work outside the loop unless mtsrin() is open-coded
144 * in an asm statement :(
145 */
146 for (i = 0; i < 16; i++) {
147 mtsrin(i << ADDR_SR_SHFT, srsave[i]);
148 isync();
149 }
150 }
151
152 __asm( "\t"
153 "mtmsr %0\n\t"
154 "isync\n"
155 : : "r" (oldmsr)
156 );
157
158 return (result);
159 }
160
161 void
162 ppc_exit()
163 {
164
165 OF_exit();
166 }
167
168 void
169 ppc_boot(str)
170 char *str;
171 {
172
173 OF_boot(str);
174 }
175
176 void
177 OF_getetheraddr(device_t dev, u_char *addr)
178 {
179 phandle_t node;
180
181 node = ofw_pci_find_node(dev);
182 OF_getprop(node, "local-mac-address", addr, ETHER_ADDR_LEN);
183 }
Cache object: bd24545595cd7dbe6cc9aa94b15181fe
|