| @@ -1,525 +1,528 @@ | | | @@ -1,525 +1,528 @@ |
1 | /* $NetBSD: machdep.c,v 1.18 2020/07/16 11:49:37 jmcneill Exp $ */ | | 1 | /* $NetBSD: machdep.c,v 1.19 2020/07/19 06:31:13 simonb Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright 2001, 2002 Wasabi Systems, Inc. | | 4 | * Copyright 2001, 2002 Wasabi Systems, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc. | | 7 | * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
15 | * notice, this list of conditions and the following disclaimer in the | | 15 | * notice, this list of conditions and the following disclaimer in the |
16 | * documentation and/or other materials provided with the distribution. | | 16 | * documentation and/or other materials provided with the distribution. |
17 | * 3. All advertising materials mentioning features or use of this software | | 17 | * 3. All advertising materials mentioning features or use of this software |
18 | * must display the following acknowledgement: | | 18 | * must display the following acknowledgement: |
19 | * This product includes software developed for the NetBSD Project by | | 19 | * This product includes software developed for the NetBSD Project by |
20 | * Wasabi Systems, Inc. | | 20 | * Wasabi Systems, Inc. |
21 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse | | 21 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse |
22 | * or promote products derived from this software without specific prior | | 22 | * or promote products derived from this software without specific prior |
23 | * written permission. | | 23 | * written permission. |
24 | * | | 24 | * |
25 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND | | 25 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND |
26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
27 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 27 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
28 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | | 28 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC |
29 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 29 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
35 | * POSSIBILITY OF SUCH DAMAGE. | | 35 | * POSSIBILITY OF SUCH DAMAGE. |
36 | */ | | 36 | */ |
37 | | | 37 | |
38 | /* | | 38 | /* |
39 | * Copyright (c) 1992, 1993 | | 39 | * Copyright (c) 1992, 1993 |
40 | * The Regents of the University of California. All rights reserved. | | 40 | * The Regents of the University of California. All rights reserved. |
41 | * | | 41 | * |
42 | * This code is derived from software contributed to Berkeley by | | 42 | * This code is derived from software contributed to Berkeley by |
43 | * the Systems Programming Group of the University of Utah Computer | | 43 | * the Systems Programming Group of the University of Utah Computer |
44 | * Science Department, The Mach Operating System project at | | 44 | * Science Department, The Mach Operating System project at |
45 | * Carnegie-Mellon University and Ralph Campbell. | | 45 | * Carnegie-Mellon University and Ralph Campbell. |
46 | * | | 46 | * |
47 | * Redistribution and use in source and binary forms, with or without | | 47 | * Redistribution and use in source and binary forms, with or without |
48 | * modification, are permitted provided that the following conditions | | 48 | * modification, are permitted provided that the following conditions |
49 | * are met: | | 49 | * are met: |
50 | * 1. Redistributions of source code must retain the above copyright | | 50 | * 1. Redistributions of source code must retain the above copyright |
51 | * notice, this list of conditions and the following disclaimer. | | 51 | * notice, this list of conditions and the following disclaimer. |
52 | * 2. Redistributions in binary form must reproduce the above copyright | | 52 | * 2. Redistributions in binary form must reproduce the above copyright |
53 | * notice, this list of conditions and the following disclaimer in the | | 53 | * notice, this list of conditions and the following disclaimer in the |
54 | * documentation and/or other materials provided with the distribution. | | 54 | * documentation and/or other materials provided with the distribution. |
55 | * 3. Neither the name of the University nor the names of its contributors | | 55 | * 3. Neither the name of the University nor the names of its contributors |
56 | * may be used to endorse or promote products derived from this software | | 56 | * may be used to endorse or promote products derived from this software |
57 | * without specific prior written permission. | | 57 | * without specific prior written permission. |
58 | * | | 58 | * |
59 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 59 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
60 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 60 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
61 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 61 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
62 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 62 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
63 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 63 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
64 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 64 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
65 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 65 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
66 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 66 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
67 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 67 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
68 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 68 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
69 | * SUCH DAMAGE. | | 69 | * SUCH DAMAGE. |
70 | * | | 70 | * |
71 | * @(#)machdep.c 8.3 (Berkeley) 1/12/94 | | 71 | * @(#)machdep.c 8.3 (Berkeley) 1/12/94 |
72 | * from: Utah Hdr: machdep.c 1.63 91/04/24 | | 72 | * from: Utah Hdr: machdep.c 1.63 91/04/24 |
73 | */ | | 73 | */ |
74 | /* | | 74 | /* |
75 | * Copyright (c) 1988 University of Utah. | | 75 | * Copyright (c) 1988 University of Utah. |
76 | * | | 76 | * |
77 | * This code is derived from software contributed to Berkeley by | | 77 | * This code is derived from software contributed to Berkeley by |
78 | * the Systems Programming Group of the University of Utah Computer | | 78 | * the Systems Programming Group of the University of Utah Computer |
79 | * Science Department, The Mach Operating System project at | | 79 | * Science Department, The Mach Operating System project at |
80 | * Carnegie-Mellon University and Ralph Campbell. | | 80 | * Carnegie-Mellon University and Ralph Campbell. |
81 | * | | 81 | * |
82 | * Redistribution and use in source and binary forms, with or without | | 82 | * Redistribution and use in source and binary forms, with or without |
83 | * modification, are permitted provided that the following conditions | | 83 | * modification, are permitted provided that the following conditions |
84 | * are met: | | 84 | * are met: |
85 | * 1. Redistributions of source code must retain the above copyright | | 85 | * 1. Redistributions of source code must retain the above copyright |
86 | * notice, this list of conditions and the following disclaimer. | | 86 | * notice, this list of conditions and the following disclaimer. |
87 | * 2. Redistributions in binary form must reproduce the above copyright | | 87 | * 2. Redistributions in binary form must reproduce the above copyright |
88 | * notice, this list of conditions and the following disclaimer in the | | 88 | * notice, this list of conditions and the following disclaimer in the |
89 | * documentation and/or other materials provided with the distribution. | | 89 | * documentation and/or other materials provided with the distribution. |
90 | * 3. All advertising materials mentioning features or use of this software | | 90 | * 3. All advertising materials mentioning features or use of this software |
91 | * must display the following acknowledgement: | | 91 | * must display the following acknowledgement: |
92 | * This product includes software developed by the University of | | 92 | * This product includes software developed by the University of |
93 | * California, Berkeley and its contributors. | | 93 | * California, Berkeley and its contributors. |
94 | * 4. Neither the name of the University nor the names of its contributors | | 94 | * 4. Neither the name of the University nor the names of its contributors |
95 | * may be used to endorse or promote products derived from this software | | 95 | * may be used to endorse or promote products derived from this software |
96 | * without specific prior written permission. | | 96 | * without specific prior written permission. |
97 | * | | 97 | * |
98 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 98 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
99 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 99 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
100 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 100 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
101 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 101 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
102 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 102 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
103 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 103 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
104 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 104 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
105 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 105 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
106 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 106 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
107 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 107 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
108 | * SUCH DAMAGE. | | 108 | * SUCH DAMAGE. |
109 | * | | 109 | * |
110 | * @(#)machdep.c 8.3 (Berkeley) 1/12/94 | | 110 | * @(#)machdep.c 8.3 (Berkeley) 1/12/94 |
111 | * from: Utah Hdr: machdep.c 1.63 91/04/24 | | 111 | * from: Utah Hdr: machdep.c 1.63 91/04/24 |
112 | */ | | 112 | */ |
113 | | | 113 | |
114 | #include "opt_multiprocessor.h" | | 114 | #include "opt_multiprocessor.h" |
115 | | | 115 | |
116 | #include <sys/cdefs.h> | | 116 | #include <sys/cdefs.h> |
117 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.18 2020/07/16 11:49:37 jmcneill Exp $"); | | 117 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.19 2020/07/19 06:31:13 simonb Exp $"); |
118 | | | 118 | |
119 | #include <sys/param.h> | | 119 | #include <sys/param.h> |
120 | #include <sys/systm.h> | | 120 | #include <sys/systm.h> |
121 | #include <sys/kernel.h> | | 121 | #include <sys/kernel.h> |
122 | #include <sys/buf.h> | | 122 | #include <sys/buf.h> |
123 | #include <sys/cpu.h> | | 123 | #include <sys/cpu.h> |
124 | #include <sys/reboot.h> | | 124 | #include <sys/reboot.h> |
125 | #include <sys/mount.h> | | 125 | #include <sys/mount.h> |
126 | #include <sys/kcore.h> | | 126 | #include <sys/kcore.h> |
127 | #include <sys/boot_flag.h> | | 127 | #include <sys/boot_flag.h> |
128 | #include <sys/termios.h> | | 128 | #include <sys/termios.h> |
129 | #include <sys/ksyms.h> | | 129 | #include <sys/ksyms.h> |
130 | | | 130 | |
131 | #include <uvm/uvm_extern.h> | | 131 | #include <uvm/uvm_extern.h> |
132 | | | 132 | |
133 | #include <dev/cons.h> | | 133 | #include <dev/cons.h> |
134 | | | 134 | |
135 | #include "ksyms.h" | | 135 | #include "ksyms.h" |
136 | | | 136 | |
137 | #if NKSYMS || defined(DDB) || defined(LKM) | | 137 | #if NKSYMS || defined(DDB) || defined(LKM) |
138 | #include <machine/db_machdep.h> | | 138 | #include <machine/db_machdep.h> |
139 | #include <ddb/db_extern.h> | | 139 | #include <ddb/db_extern.h> |
140 | #endif | | 140 | #endif |
141 | | | 141 | |
142 | #include <machine/psl.h> | | 142 | #include <machine/psl.h> |
143 | #include <machine/locore.h> | | 143 | #include <machine/locore.h> |
144 | | | 144 | |
145 | #include <mips/cavium/autoconf.h> | | 145 | #include <mips/cavium/autoconf.h> |
146 | #include <mips/cavium/octeonvar.h> | | 146 | #include <mips/cavium/octeonvar.h> |
147 | #include <mips/cavium/include/iobusvar.h> | | 147 | #include <mips/cavium/include/iobusvar.h> |
148 | #include <mips/cavium/include/bootbusvar.h> | | 148 | #include <mips/cavium/include/bootbusvar.h> |
149 | | | 149 | |
150 | #include <mips/cavium/dev/octeon_uartreg.h> | | 150 | #include <mips/cavium/dev/octeon_uartreg.h> |
151 | #include <mips/cavium/dev/octeon_ciureg.h> | | 151 | #include <mips/cavium/dev/octeon_ciureg.h> |
152 | #include <mips/cavium/dev/octeon_gpioreg.h> | | 152 | #include <mips/cavium/dev/octeon_gpioreg.h> |
153 | | | 153 | |
154 | #include <evbmips/cavium/octeon_uboot.h> | | 154 | #include <evbmips/cavium/octeon_uboot.h> |
155 | | | 155 | |
156 | #include <dev/fdt/fdtvar.h> | | 156 | #include <dev/fdt/fdtvar.h> |
| | | 157 | #include <dev/fdt/fdt_private.h> |
157 | | | 158 | |
158 | static void mach_init_vector(void); | | 159 | static void mach_init_vector(void); |
159 | static void mach_init_bus_space(void); | | 160 | static void mach_init_bus_space(void); |
160 | static void mach_init_console(void); | | 161 | static void mach_init_console(void); |
161 | static void mach_init_memory(void); | | 162 | static void mach_init_memory(void); |
162 | static void parse_boot_args(void); | | 163 | static void parse_boot_args(void); |
163 | | | 164 | |
164 | #include "com.h" | | 165 | #include "com.h" |
165 | #if NCOM > 0 | | 166 | #if NCOM > 0 |
166 | #include <dev/ic/comreg.h> | | 167 | #include <dev/ic/comreg.h> |
167 | #include <dev/ic/comvar.h> | | 168 | #include <dev/ic/comvar.h> |
168 | int comcnrate = 115200; /* XXX should be config option */ | | 169 | int comcnrate = 115200; /* XXX should be config option */ |
169 | #endif /* NCOM > 0 */ | | 170 | #endif /* NCOM > 0 */ |
170 | | | 171 | |
171 | /* Maps for VM objects. */ | | 172 | /* Maps for VM objects. */ |
172 | struct vm_map *phys_map = NULL; | | 173 | struct vm_map *phys_map = NULL; |
173 | | | 174 | |
174 | int netboot; | | 175 | int netboot; |
175 | | | 176 | |
176 | phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX]; | | 177 | phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX]; |
177 | int mem_cluster_cnt; | | 178 | int mem_cluster_cnt; |
178 | extern char kernel_text[]; | | 179 | extern char kernel_text[]; |
179 | extern char edata[]; | | 180 | extern char edata[]; |
180 | extern char end[]; | | 181 | extern char end[]; |
181 | | | 182 | |
182 | void mach_init(uint64_t, uint64_t, uint64_t, uint64_t); | | 183 | void mach_init(uint64_t, uint64_t, uint64_t, uint64_t); |
183 | | | 184 | |
184 | struct octeon_config octeon_configuration; | | 185 | struct octeon_config octeon_configuration; |
185 | struct octeon_btdesc octeon_btdesc; | | 186 | struct octeon_btdesc octeon_btdesc; |
186 | struct octeon_btinfo octeon_btinfo; | | 187 | struct octeon_btinfo octeon_btinfo; |
187 | | | 188 | |
188 | char octeon_nmi_stack[PAGE_SIZE] __section(".data1") __aligned(PAGE_SIZE); | | 189 | char octeon_nmi_stack[PAGE_SIZE] __section(".data1") __aligned(PAGE_SIZE); |
189 | | | 190 | |
190 | /* | | 191 | /* |
191 | * Do all the stuff that locore normally does before calling main(). | | 192 | * Do all the stuff that locore normally does before calling main(). |
192 | */ | | 193 | */ |
193 | void | | 194 | void |
194 | mach_init(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3) | | 195 | mach_init(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3) |
195 | { | | 196 | { |
196 | uint64_t btinfo_paddr; | | 197 | uint64_t btinfo_paddr; |
197 | void *fdt_data; | | 198 | void *fdt_data; |
198 | | | 199 | |
199 | /* clear the BSS segment */ | | 200 | /* clear the BSS segment */ |
200 | memset(edata, 0, end - edata); | | 201 | memset(edata, 0, end - edata); |
201 | | | 202 | |
202 | cpu_reset_address = octeon_soft_reset; | | 203 | cpu_reset_address = octeon_soft_reset; |
203 | | | 204 | |
204 | KASSERT(MIPS_XKPHYS_P(arg3)); | | 205 | KASSERT(MIPS_XKPHYS_P(arg3)); |
205 | btinfo_paddr = mips3_ld(arg3 + OCTEON_BTINFO_PADDR_OFFSET); | | 206 | btinfo_paddr = mips3_ld(arg3 + OCTEON_BTINFO_PADDR_OFFSET); |
206 | | | 207 | |
207 | /* XXX KASSERT these addresses? */ | | 208 | /* XXX KASSERT these addresses? */ |
208 | memcpy(&octeon_btdesc, (void *)arg3, sizeof(octeon_btdesc)); | | 209 | memcpy(&octeon_btdesc, (void *)arg3, sizeof(octeon_btdesc)); |
209 | if ((octeon_btdesc.obt_desc_ver == OCTEON_SUPPORTED_DESCRIPTOR_VERSION) && | | 210 | if ((octeon_btdesc.obt_desc_ver == OCTEON_SUPPORTED_DESCRIPTOR_VERSION) && |
210 | (octeon_btdesc.obt_desc_size == sizeof(octeon_btdesc))) { | | 211 | (octeon_btdesc.obt_desc_size == sizeof(octeon_btdesc))) { |
211 | btinfo_paddr = MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE, | | 212 | btinfo_paddr = MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE, |
212 | octeon_btdesc.obt_boot_info_addr); | | 213 | octeon_btdesc.obt_boot_info_addr); |
213 | } else { | | 214 | } else { |
214 | panic("unknown boot descriptor size %u", | | 215 | panic("unknown boot descriptor size %u", |
215 | octeon_btdesc.obt_desc_size); | | 216 | octeon_btdesc.obt_desc_size); |
216 | } | | 217 | } |
217 | memcpy(&octeon_btinfo, (void *)btinfo_paddr, sizeof(octeon_btinfo)); | | 218 | memcpy(&octeon_btinfo, (void *)btinfo_paddr, sizeof(octeon_btinfo)); |
218 | parse_boot_args(); | | 219 | parse_boot_args(); |
219 | | | 220 | |
220 | octeon_cal_timer(octeon_btinfo.obt_eclock_hz); | | 221 | octeon_cal_timer(octeon_btinfo.obt_eclock_hz); |
221 | | | 222 | |
222 | cpu_setmodel("Cavium Octeon %s", | | 223 | cpu_setmodel("Cavium Octeon %s", |
223 | octeon_cpu_model(mips_options.mips_cpu_id)); | | 224 | octeon_cpu_model(mips_options.mips_cpu_id)); |
224 | | | 225 | |
225 | if (octeon_btinfo.obt_minor_version >= 3 && | | 226 | if (octeon_btinfo.obt_minor_version >= 3 && |
226 | octeon_btinfo.obt_fdt_addr != 0) { | | 227 | octeon_btinfo.obt_fdt_addr != 0) { |
227 | fdt_data = (void *)MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE, | | 228 | fdt_data = (void *)MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE, |
228 | octeon_btinfo.obt_fdt_addr); | | 229 | octeon_btinfo.obt_fdt_addr); |
229 | fdtbus_init(fdt_data); | | 230 | fdtbus_init(fdt_data); |
230 | } | | 231 | } |
231 | | | 232 | |
232 | mach_init_vector(); | | 233 | mach_init_vector(); |
233 | | | 234 | |
234 | uvm_md_init(); | | 235 | uvm_md_init(); |
235 | | | 236 | |
236 | mach_init_bus_space(); | | 237 | mach_init_bus_space(); |
237 | | | 238 | |
238 | mach_init_console(); | | 239 | mach_init_console(); |
239 | | | 240 | |
240 | #ifdef DEBUG | | 241 | #ifdef DEBUG |
241 | /* Show a couple of boot desc/info params for positive feedback */ | | 242 | /* Show a couple of boot desc/info params for positive feedback */ |
242 | printf(">> boot desc eclock = %d\n", octeon_btdesc.obt_eclock); | | 243 | printf(">> boot desc eclock = %d\n", octeon_btdesc.obt_eclock); |
243 | printf(">> boot info board = %d\n", octeon_btinfo.obt_board_type); | | 244 | printf(">> boot info board = %d\n", octeon_btinfo.obt_board_type); |
244 | #endif /* DEBUG */ | | 245 | #endif /* DEBUG */ |
245 | | | 246 | |
246 | mach_init_memory(); | | 247 | mach_init_memory(); |
247 | | | 248 | |
248 | /* | | 249 | /* |
249 | * Allocate uarea page for lwp0 and set it. | | 250 | * Allocate uarea page for lwp0 and set it. |
250 | */ | | 251 | */ |
251 | mips_init_lwp0_uarea(); | | 252 | mips_init_lwp0_uarea(); |
252 | | | 253 | |
253 | #if 0 | | 254 | #if 0 |
254 | curcpu()->ci_nmi_stack = octeon_nmi_stack + sizeof(octeon_nmi_stack) - sizeof(struct kernframe); | | 255 | curcpu()->ci_nmi_stack = octeon_nmi_stack + sizeof(octeon_nmi_stack) - sizeof(struct kernframe); |
255 | *(uint64_t *)MIPS_PHYS_TO_KSEG0(0x800) = (intptr_t)octeon_reset_vector; | | 256 | *(uint64_t *)MIPS_PHYS_TO_KSEG0(0x800) = (intptr_t)octeon_reset_vector; |
256 | const uint64_t wdog_reg = MIPS_PHYS_TO_XKPHYS_UNCACHED(CIU_WDOG0); | | 257 | const uint64_t wdog_reg = MIPS_PHYS_TO_XKPHYS_UNCACHED(CIU_WDOG0); |
257 | uint64_t wdog = mips3_ld(wdog_reg); | | 258 | uint64_t wdog = mips3_ld(wdog_reg); |
258 | wdog &= ~(CIU_WDOGX_MODE|CIU_WDOGX_LEN); | | 259 | wdog &= ~(CIU_WDOGX_MODE|CIU_WDOGX_LEN); |
259 | wdog |= __SHIFTIN(3, CIU_WDOGX_MODE); | | 260 | wdog |= __SHIFTIN(3, CIU_WDOGX_MODE); |
260 | wdog |= CIU_WDOGX_LEN; // max period | | 261 | wdog |= CIU_WDOGX_LEN; // max period |
261 | mips64_sd_a64(wdog_reg, wdog); | | 262 | mips64_sd_a64(wdog_reg, wdog); |
262 | printf("Watchdog enabled!\n"); | | 263 | printf("Watchdog enabled!\n"); |
263 | #endif | | 264 | #endif |
264 | | | 265 | |
265 | #if defined(DDB) | | 266 | #if defined(DDB) |
266 | if (boothowto & RB_KDB) | | 267 | if (boothowto & RB_KDB) |
267 | Debugger(); | | 268 | Debugger(); |
268 | #endif | | 269 | #endif |
269 | } | | 270 | } |
270 | | | 271 | |
271 | void | | 272 | void |
272 | consinit(void) | | 273 | consinit(void) |
273 | { | | 274 | { |
274 | | | 275 | |
275 | /* | | 276 | /* |
276 | * Everything related to console initialization is done | | 277 | * Everything related to console initialization is done |
277 | * in mach_init(). | | 278 | * in mach_init(). |
278 | */ | | 279 | */ |
279 | } | | 280 | } |
280 | | | 281 | |
281 | void | | 282 | void |
282 | mach_init_vector(void) | | 283 | mach_init_vector(void) |
283 | { | | 284 | { |
284 | | | 285 | |
285 | /* Make sure exception base at 0 (MIPS_COP_0_EBASE) */ | | 286 | /* Make sure exception base at 0 (MIPS_COP_0_EBASE) */ |
286 | __asm __volatile("mtc0 %0, $15, 1" : : "r"(0x80000000) ); | | 287 | __asm __volatile("mtc0 %0, $15, 1" : : "r"(0x80000000) ); |
287 | | | 288 | |
288 | /* | | 289 | /* |
289 | * Set up the exception vectors and CPU-specific function | | 290 | * Set up the exception vectors and CPU-specific function |
290 | * vectors early on. We need the wbflush() vector set up | | 291 | * vectors early on. We need the wbflush() vector set up |
291 | * before comcnattach() is called (or at least before the | | 292 | * before comcnattach() is called (or at least before the |
292 | * first printf() after that is called). | | 293 | * first printf() after that is called). |
293 | * Also clears the I+D caches. | | 294 | * Also clears the I+D caches. |
294 | */ | | 295 | */ |
295 | mips_vector_init(NULL, true); | | 296 | mips_vector_init(NULL, true); |
296 | } | | 297 | } |
297 | | | 298 | |
298 | void | | 299 | void |
299 | mach_init_bus_space(void) | | 300 | mach_init_bus_space(void) |
300 | { | | 301 | { |
301 | struct octeon_config *mcp = &octeon_configuration; | | 302 | struct octeon_config *mcp = &octeon_configuration; |
302 | | | 303 | |
303 | octeon_dma_init(mcp); | | 304 | octeon_dma_init(mcp); |
304 | | | 305 | |
305 | iobus_bootstrap(mcp); | | 306 | iobus_bootstrap(mcp); |
306 | bootbus_bootstrap(mcp); | | 307 | bootbus_bootstrap(mcp); |
307 | } | | 308 | } |
308 | | | 309 | |
309 | void | | 310 | void |
310 | mach_init_console(void) | | 311 | mach_init_console(void) |
311 | { | | 312 | { |
312 | #if NCOM > 0 | | 313 | #if NCOM > 0 |
313 | struct octeon_config *mcp = &octeon_configuration; | | 314 | struct octeon_config *mcp = &octeon_configuration; |
314 | int status; | | 315 | int status; |
315 | extern int octuart_com_cnattach(bus_space_tag_t, int, int); | | 316 | extern int octuart_com_cnattach(bus_space_tag_t, int, int); |
316 | | | 317 | |
317 | /* | | 318 | /* |
318 | * Delay to allow firmware putchars to complete. | | 319 | * Delay to allow firmware putchars to complete. |
319 | * FIFO depth * character time. | | 320 | * FIFO depth * character time. |
320 | * character time = (1000000 / (defaultrate / 10)) | | 321 | * character time = (1000000 / (defaultrate / 10)) |
321 | */ | | 322 | */ |
322 | delay(640000000 / comcnrate); | | 323 | delay(640000000 / comcnrate); |
323 | | | 324 | |
324 | status = octuart_com_cnattach( | | 325 | status = octuart_com_cnattach( |
325 | &mcp->mc_iobus_bust, | | 326 | &mcp->mc_iobus_bust, |
326 | 0, /* XXX port 0 */ | | 327 | 0, /* XXX port 0 */ |
327 | comcnrate); | | 328 | comcnrate); |
328 | if (status != 0) | | 329 | if (status != 0) |
329 | panic("can't initialize console!"); /* XXX print to nowhere! */ | | 330 | panic("can't initialize console!"); /* XXX print to nowhere! */ |
330 | #else | | 331 | #else |
331 | panic("octeon: not configured to use serial console"); | | 332 | panic("octeon: not configured to use serial console"); |
332 | #endif /* NCOM > 0 */ | | 333 | #endif /* NCOM > 0 */ |
333 | } | | 334 | } |
334 | | | 335 | |
335 | static void | | 336 | static void |
336 | mach_init_memory(void) | | 337 | mach_init_memory(void) |
337 | { | | 338 | { |
338 | struct octeon_bootmem_desc *memdesc; | | 339 | struct octeon_bootmem_desc *memdesc; |
339 | struct octeon_bootmem_block_header *block; | | 340 | struct octeon_bootmem_block_header *block; |
340 | paddr_t blockaddr; | | 341 | paddr_t blockaddr; |
341 | int i; | | 342 | int i; |
342 | | | 343 | |
343 | mem_cluster_cnt = 0; | | 344 | mem_cluster_cnt = 0; |
344 | | | 345 | |
345 | if (octeon_btinfo.obt_phy_mem_desc_addr == 0) | | 346 | if (octeon_btinfo.obt_phy_mem_desc_addr == 0) |
346 | panic("bootmem desc is missing"); | | 347 | panic("bootmem desc is missing"); |
347 | | | 348 | |
348 | memdesc = (void *)MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE, | | 349 | memdesc = (void *)MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE, |
349 | octeon_btinfo.obt_phy_mem_desc_addr); | | 350 | octeon_btinfo.obt_phy_mem_desc_addr); |
350 | printf("u-boot bootmem desc @ 0x%x version %d.%d\n", | | 351 | printf("u-boot bootmem desc @ 0x%x version %d.%d\n", |
351 | octeon_btinfo.obt_phy_mem_desc_addr, | | 352 | octeon_btinfo.obt_phy_mem_desc_addr, |
352 | memdesc->bmd_major_version, memdesc->bmd_minor_version); | | 353 | memdesc->bmd_major_version, memdesc->bmd_minor_version); |
353 | if (memdesc->bmd_major_version > 3) | | 354 | if (memdesc->bmd_major_version > 3) |
354 | panic("unhandled bootmem desc version %d.%d", | | 355 | panic("unhandled bootmem desc version %d.%d", |
355 | memdesc->bmd_major_version, memdesc->bmd_minor_version); | | 356 | memdesc->bmd_major_version, memdesc->bmd_minor_version); |
356 | | | 357 | |
357 | blockaddr = memdesc->bmd_head_addr; | | 358 | blockaddr = memdesc->bmd_head_addr; |
358 | if (blockaddr == 0) | | 359 | if (blockaddr == 0) |
359 | panic("bootmem list is empty"); | | 360 | panic("bootmem list is empty"); |
360 | | | 361 | |
361 | for (i = 0; i < VM_PHYSSEG_MAX && blockaddr != 0; | | 362 | for (i = 0; i < VM_PHYSSEG_MAX && blockaddr != 0; |
362 | i++, blockaddr = block->bbh_next_block_addr) { | | 363 | i++, blockaddr = block->bbh_next_block_addr) { |
363 | block = (void *)MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE, blockaddr); | | 364 | block = (void *)MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE, blockaddr); |
364 | | | 365 | |
365 | mem_clusters[mem_cluster_cnt].start = blockaddr; | | 366 | mem_clusters[mem_cluster_cnt].start = blockaddr; |
366 | mem_clusters[mem_cluster_cnt].size = block->bbh_size; | | 367 | mem_clusters[mem_cluster_cnt].size = block->bbh_size; |
367 | mem_cluster_cnt++; | | 368 | mem_cluster_cnt++; |
368 | } | | 369 | } |
369 | | | 370 | |
370 | physmem = btoc(octeon_btinfo.obt_dram_size * 1024 * 1024); | | 371 | physmem = btoc(octeon_btinfo.obt_dram_size * 1024 * 1024); |
371 | | | 372 | |
372 | #ifdef MULTIPROCESSOR | | 373 | #ifdef MULTIPROCESSOR |
373 | const u_int cores = mipsNN_cp0_ebase_read() & MIPS_EBASE_CPUNUM; | | 374 | const u_int cores = mipsNN_cp0_ebase_read() & MIPS_EBASE_CPUNUM; |
374 | mem_clusters[0].start = cores * 4096; | | 375 | mem_clusters[0].start = cores * 4096; |
375 | #endif | | 376 | #endif |
376 | | | 377 | |
377 | /* | | 378 | /* |
378 | * Load the rest of the available pages into the VM system. | | 379 | * Load the rest of the available pages into the VM system. |
379 | */ | | 380 | */ |
380 | mips_page_physload(mips_trunc_page(kernel_text), mips_round_page(end), | | 381 | mips_page_physload(mips_trunc_page(kernel_text), mips_round_page(end), |
381 | mem_clusters, mem_cluster_cnt, NULL, 0); | | 382 | mem_clusters, mem_cluster_cnt, NULL, 0); |
382 | | | 383 | |
383 | /* | | 384 | /* |
384 | * Initialize error message buffer (at end of core). | | 385 | * Initialize error message buffer (at end of core). |
385 | */ | | 386 | */ |
386 | mips_init_msgbuf(); | | 387 | mips_init_msgbuf(); |
387 | | | 388 | |
388 | pmap_bootstrap(); | | 389 | pmap_bootstrap(); |
389 | } | | 390 | } |
390 | | | 391 | |
391 | void | | 392 | void |
392 | parse_boot_args(void) | | 393 | parse_boot_args(void) |
393 | { | | 394 | { |
394 | int i; | | 395 | int i; |
395 | char *arg, *p; | | 396 | char *arg, *p; |
396 | | | 397 | |
397 | for (i = 0; i < octeon_btdesc.obt_argc; i++) { | | 398 | for (i = 0; i < octeon_btdesc.obt_argc; i++) { |
398 | arg = (char *)MIPS_PHYS_TO_KSEG0(octeon_btdesc.obt_argv[i]); | | 399 | arg = (char *)MIPS_PHYS_TO_KSEG0(octeon_btdesc.obt_argv[i]); |
399 | if (*arg == '-') { | | 400 | if (*arg == '-') { |
400 | for (p = arg + 1; *p; p++) { | | 401 | for (p = arg + 1; *p; p++) { |
401 | switch (*p) { | | 402 | switch (*p) { |
402 | case '1': | | 403 | case '1': |
403 | boothowto |= RB_MD1; | | 404 | boothowto |= RB_MD1; |
404 | break; | | 405 | break; |
405 | case 's': | | 406 | case 's': |
406 | boothowto |= RB_SINGLE; | | 407 | boothowto |= RB_SINGLE; |
407 | break; | | 408 | break; |
408 | case 'd': | | 409 | case 'd': |
409 | boothowto |= RB_KDB; | | 410 | boothowto |= RB_KDB; |
410 | break; | | 411 | break; |
411 | case 'a': | | 412 | case 'a': |
412 | boothowto |= RB_ASKNAME; | | 413 | boothowto |= RB_ASKNAME; |
413 | break; | | 414 | break; |
414 | case 'q': | | 415 | case 'q': |
415 | boothowto |= AB_QUIET; | | 416 | boothowto |= AB_QUIET; |
416 | break; | | 417 | break; |
417 | case 'v': | | 418 | case 'v': |
418 | boothowto |= AB_VERBOSE; | | 419 | boothowto |= AB_VERBOSE; |
419 | break; | | 420 | break; |
420 | case 'x': | | 421 | case 'x': |
421 | boothowto |= AB_DEBUG; | | 422 | boothowto |= AB_DEBUG; |
422 | break; | | 423 | break; |
423 | case 'z': | | 424 | case 'z': |
424 | boothowto |= AB_SILENT; | | 425 | boothowto |= AB_SILENT; |
425 | break; | | 426 | break; |
426 | } | | 427 | } |
427 | } | | 428 | } |
428 | } | | 429 | } |
429 | if (strncmp(arg, "root=", 5) == 0) | | 430 | if (strncmp(arg, "root=", 5) == 0) |
430 | rootspec = strchr(arg, '=') + 1; | | 431 | rootspec = strchr(arg, '=') + 1; |
431 | } | | 432 | } |
432 | } | | 433 | } |
433 | | | 434 | |
434 | /* | | 435 | /* |
435 | * cpu_startup | | 436 | * cpu_startup |
436 | * cpu_reboot | | 437 | * cpu_reboot |
437 | */ | | 438 | */ |
438 | | | 439 | |
439 | int waittime = -1; | | 440 | int waittime = -1; |
440 | | | 441 | |
441 | /* | | 442 | /* |
442 | * Allocate memory for variable-sized tables, | | 443 | * Allocate memory for variable-sized tables, |
443 | */ | | 444 | */ |
444 | void | | 445 | void |
445 | cpu_startup(void) | | 446 | cpu_startup(void) |
446 | { | | 447 | { |
447 | #ifdef MULTIPROCESSOR | | 448 | #ifdef MULTIPROCESSOR |
448 | // Create a kcpuset so we can see on which CPUs the kernel was started. | | 449 | // Create a kcpuset so we can see on which CPUs the kernel was started. |
449 | kcpuset_create(&cpus_booted, true); | | 450 | kcpuset_create(&cpus_booted, true); |
450 | #endif | | 451 | #endif |
451 | | | 452 | |
452 | /* | | 453 | /* |
453 | * Do the common startup items. | | 454 | * Do the common startup items. |
454 | */ | | 455 | */ |
455 | cpu_startup_common(); | | 456 | cpu_startup_common(); |
456 | | | 457 | |
457 | /* | | 458 | /* |
458 | * Virtual memory is bootstrapped -- notify the bus spaces | | 459 | * Virtual memory is bootstrapped -- notify the bus spaces |
459 | * that memory allocation is now safe. | | 460 | * that memory allocation is now safe. |
460 | */ | | 461 | */ |
461 | octeon_configuration.mc_mallocsafe = 1; | | 462 | octeon_configuration.mc_mallocsafe = 1; |
| | | 463 | |
| | | 464 | fdtbus_intr_init(); |
462 | } | | 465 | } |
463 | | | 466 | |
464 | void | | 467 | void |
465 | cpu_reboot(int howto, char *bootstr) | | 468 | cpu_reboot(int howto, char *bootstr) |
466 | { | | 469 | { |
467 | | | 470 | |
468 | /* Take a snapshot before clobbering any registers. */ | | 471 | /* Take a snapshot before clobbering any registers. */ |
469 | savectx(curpcb); | | 472 | savectx(curpcb); |
470 | | | 473 | |
471 | if (cold) { | | 474 | if (cold) { |
472 | howto |= RB_HALT; | | 475 | howto |= RB_HALT; |
473 | goto haltsys; | | 476 | goto haltsys; |
474 | } | | 477 | } |
475 | | | 478 | |
476 | /* If "always halt" was specified as a boot flag, obey. */ | | 479 | /* If "always halt" was specified as a boot flag, obey. */ |
477 | if (boothowto & RB_HALT) | | 480 | if (boothowto & RB_HALT) |
478 | howto |= RB_HALT; | | 481 | howto |= RB_HALT; |
479 | | | 482 | |
480 | boothowto = howto; | | 483 | boothowto = howto; |
481 | if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) { | | 484 | if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) { |
482 | waittime = 0; | | 485 | waittime = 0; |
483 | vfs_shutdown(); | | 486 | vfs_shutdown(); |
484 | | | 487 | |
485 | /* | | 488 | /* |
486 | * If we've been adjusting the clock, the todr | | 489 | * If we've been adjusting the clock, the todr |
487 | * will be out of synch; adjust it now. | | 490 | * will be out of synch; adjust it now. |
488 | */ | | 491 | */ |
489 | resettodr(); | | 492 | resettodr(); |
490 | } | | 493 | } |
491 | | | 494 | |
492 | splhigh(); | | 495 | splhigh(); |
493 | | | 496 | |
494 | if (howto & RB_DUMP) | | 497 | if (howto & RB_DUMP) |
495 | dumpsys(); | | 498 | dumpsys(); |
496 | | | 499 | |
497 | haltsys: | | 500 | haltsys: |
498 | doshutdownhooks(); | | 501 | doshutdownhooks(); |
499 | | | 502 | |
500 | if (howto & RB_HALT) { | | 503 | if (howto & RB_HALT) { |
501 | printf("\n"); | | 504 | printf("\n"); |
502 | printf("The operating system has halted.\n"); | | 505 | printf("The operating system has halted.\n"); |
503 | printf("Please press any key to reboot.\n\n"); | | 506 | printf("Please press any key to reboot.\n\n"); |
504 | cnpollc(1); /* For proper keyboard command handling */ | | 507 | cnpollc(1); /* For proper keyboard command handling */ |
505 | cngetc(); | | 508 | cngetc(); |
506 | cnpollc(0); | | 509 | cnpollc(0); |
507 | } | | 510 | } |
508 | | | 511 | |
509 | printf("%s\n\n", ((howto & RB_HALT) != 0) ? "halted." : "rebooting..."); | | 512 | printf("%s\n\n", ((howto & RB_HALT) != 0) ? "halted." : "rebooting..."); |
510 | | | 513 | |
511 | /* | | 514 | /* |
512 | * Need a small delay here, otherwise we see the first few characters of | | 515 | * Need a small delay here, otherwise we see the first few characters of |
513 | * the warning below. | | 516 | * the warning below. |
514 | */ | | 517 | */ |
515 | delay(80000); | | 518 | delay(80000); |
516 | | | 519 | |
517 | octeon_soft_reset(); | | 520 | octeon_soft_reset(); |
518 | | | 521 | |
519 | delay(1000000); | | 522 | delay(1000000); |
520 | | | 523 | |
521 | printf("WARNING: reset failed!\nSpinning..."); | | 524 | printf("WARNING: reset failed!\nSpinning..."); |
522 | | | 525 | |
523 | for (;;) | | 526 | for (;;) |
524 | /* spin forever */ ; /* XXX */ | | 527 | /* spin forever */ ; /* XXX */ |
525 | } | | 528 | } |