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 #ifndef lint
35 static const char rcsid[] =
36 "$FreeBSD: releng/5.0/sys/powerpc/powerpc/ofw_machdep.c 103602 2002-09-19 04:31:39Z grehan $";
37 #endif /* not lint */
38
39 #include <sys/param.h>
40 #include <sys/bus.h>
41 #include <sys/systm.h>
42 #include <sys/conf.h>
43 #include <sys/disk.h>
44 #include <sys/disklabel.h>
45 #include <sys/fcntl.h>
46 #include <sys/malloc.h>
47 #include <sys/stat.h>
48
49 #include <net/ethernet.h>
50
51 #include <dev/ofw/openfirm.h>
52
53 #include <vm/vm.h>
54 #include <vm/vm_param.h>
55 #include <vm/vm_page.h>
56
57 #include <machine/powerpc.h>
58 #include <machine/ofw_machdep.h>
59 #include <powerpc/ofw/ofw_pci.h>
60
61 #define OFMEM_REGIONS 32
62 static struct mem_region OFmem[OFMEM_REGIONS + 1], OFavail[OFMEM_REGIONS + 3];
63
64 extern long ofmsr;
65 extern struct pmap ofw_pmap;
66 extern int pmap_bootstrapped;
67 static int (*ofwcall)(void *);
68
69 /*
70 * This is called during powerpc_init, before the system is really initialized.
71 * It shall provide the total and the available regions of RAM.
72 * Both lists must have a zero-size entry as terminator.
73 * The available regions need not take the kernel into account, but needs
74 * to provide space for two additional entry beyond the terminating one.
75 */
76 void
77 mem_regions(struct mem_region **memp, int *memsz,
78 struct mem_region **availp, int *availsz)
79 {
80 int phandle;
81 int asz, msz;
82
83 /*
84 * Get memory.
85 */
86 if ((phandle = OF_finddevice("/memory")) == -1
87 || (msz = OF_getprop(phandle, "reg",
88 OFmem, sizeof OFmem[0] * OFMEM_REGIONS))
89 <= 0
90 || (asz = OF_getprop(phandle, "available",
91 OFavail, sizeof OFavail[0] * OFMEM_REGIONS))
92 <= 0)
93 panic("no memory?");
94 *memp = OFmem;
95 *memsz = msz / sizeof(struct mem_region);
96 *availp = OFavail;
97 *availsz = asz / sizeof(struct mem_region);
98 }
99
100 void
101 set_openfirm_callback(int (*openfirm)(void *))
102 {
103
104 ofwcall = openfirm;
105 }
106
107 int
108 openfirmware(void *args)
109 {
110 long oldmsr;
111 int result;
112 u_int srsave[16];
113 u_int i;
114
115 __asm __volatile( "\t"
116 "sync\n\t"
117 "mfmsr %0\n\t"
118 "mtmsr %1\n\t"
119 "isync\n"
120 : "=r" (oldmsr)
121 : "r" (ofmsr)
122 );
123
124 if (pmap_bootstrapped) {
125 /*
126 * Swap the kernel's address space with OpenFirmware's
127 */
128 for (i = 0; i < 16; i++) {
129 srsave[i] = mfsrin(i << ADDR_SR_SHFT);
130 mtsrin(i << ADDR_SR_SHFT, ofw_pmap.pm_sr[i]);
131 }
132
133 /*
134 * Clear battable[] translations
135 */
136 __asm __volatile("mtdbatu 2, %0\n"
137 "mtdbatu 3, %0" : : "r" (0));
138 isync();
139 }
140
141 result = ofwcall(args);
142
143 if (pmap_bootstrapped) {
144 /*
145 * Restore the kernel's addr space. The isync() doesn;t
146 * work outside the loop unless mtsrin() is open-coded
147 * in an asm statement :(
148 */
149 for (i = 0; i < 16; i++) {
150 mtsrin(i << ADDR_SR_SHFT, srsave[i]);
151 isync();
152 }
153 }
154
155 __asm( "\t"
156 "mtmsr %0\n\t"
157 "isync\n"
158 : : "r" (oldmsr)
159 );
160
161 return (result);
162 }
163
164 void
165 ppc_exit()
166 {
167
168 OF_exit();
169 }
170
171 void
172 ppc_boot(str)
173 char *str;
174 {
175
176 OF_boot(str);
177 }
178
179 void
180 OF_getetheraddr(device_t dev, u_char *addr)
181 {
182 phandle_t node;
183
184 node = ofw_pci_find_node(dev);
185 OF_getprop(node, "local-mac-address", addr, ETHER_ADDR_LEN);
186 }
Cache object: ae6a3cffd22ca69f6a8e36e47b901535
|