mmnet_machdep.c revision 1.4 1 1.4 skrll /* $Id: mmnet_machdep.c,v 1.4 2019/07/16 14:41:47 skrll Exp $ */
2 1.4 skrll /* $NetBSD: mmnet_machdep.c,v 1.4 2019/07/16 14:41:47 skrll Exp $ */
3 1.1 aymeric
4 1.1 aymeric /*
5 1.1 aymeric * Copyright (c) 2007 Embedtronics Oy
6 1.1 aymeric * Based on tsarm_machdep.c
7 1.1 aymeric *
8 1.1 aymeric * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
9 1.1 aymeric * All rights reserved.
10 1.1 aymeric *
11 1.1 aymeric * Based on code written by Jason R. Thorpe and Steve C. Woodford for
12 1.1 aymeric * Wasabi Systems, Inc.
13 1.1 aymeric *
14 1.1 aymeric * Redistribution and use in source and binary forms, with or without
15 1.1 aymeric * modification, are permitted provided that the following conditions
16 1.1 aymeric * are met:
17 1.1 aymeric * 1. Redistributions of source code must retain the above copyright
18 1.1 aymeric * notice, this list of conditions and the following disclaimer.
19 1.1 aymeric * 2. Redistributions in binary form must reproduce the above copyright
20 1.1 aymeric * notice, this list of conditions and the following disclaimer in the
21 1.1 aymeric * documentation and/or other materials provided with the distribution.
22 1.1 aymeric * 3. All advertising materials mentioning features or use of this software
23 1.1 aymeric * must display the following acknowledgement:
24 1.1 aymeric * This product includes software developed for the NetBSD Project by
25 1.1 aymeric * Wasabi Systems, Inc.
26 1.1 aymeric * 4. The name of Wasabi Systems, Inc. may not be used to endorse
27 1.1 aymeric * or promote products derived from this software without specific prior
28 1.1 aymeric * written permission.
29 1.1 aymeric *
30 1.1 aymeric * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
31 1.1 aymeric * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 1.1 aymeric * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 1.1 aymeric * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
34 1.1 aymeric * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 1.1 aymeric * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 1.1 aymeric * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 1.1 aymeric * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 1.1 aymeric * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 1.1 aymeric * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 1.1 aymeric * POSSIBILITY OF SUCH DAMAGE.
41 1.1 aymeric */
42 1.1 aymeric
43 1.1 aymeric /*
44 1.1 aymeric * Copyright (c) 1997,1998 Mark Brinicombe.
45 1.1 aymeric * Copyright (c) 1997,1998 Causality Limited.
46 1.1 aymeric * All rights reserved.
47 1.1 aymeric *
48 1.1 aymeric * Redistribution and use in source and binary forms, with or without
49 1.1 aymeric * modification, are permitted provided that the following conditions
50 1.1 aymeric * are met:
51 1.1 aymeric * 1. Redistributions of source code must retain the above copyright
52 1.1 aymeric * notice, this list of conditions and the following disclaimer.
53 1.1 aymeric * 2. Redistributions in binary form must reproduce the above copyright
54 1.1 aymeric * notice, this list of conditions and the following disclaimer in the
55 1.1 aymeric * documentation and/or other materials provided with the distribution.
56 1.1 aymeric * 3. All advertising materials mentioning features or use of this software
57 1.1 aymeric * must display the following acknowledgement:
58 1.1 aymeric * This product includes software developed by Mark Brinicombe
59 1.1 aymeric * for the NetBSD Project.
60 1.1 aymeric * 4. The name of the company nor the name of the author may be used to
61 1.1 aymeric * endorse or promote products derived from this software without specific
62 1.1 aymeric * prior written permission.
63 1.1 aymeric *
64 1.1 aymeric * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
65 1.1 aymeric * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
66 1.1 aymeric * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
67 1.1 aymeric * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
68 1.1 aymeric * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
69 1.1 aymeric * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
70 1.1 aymeric * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 1.1 aymeric * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 1.1 aymeric * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 1.1 aymeric * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 1.1 aymeric * SUCH DAMAGE.
75 1.1 aymeric *
76 1.1 aymeric * Machine dependant functions for kernel setup for Iyonix.
77 1.1 aymeric */
78 1.1 aymeric /* Adaptation for Propox MMnet by Aymeric Vincent is in the public domain */
79 1.1 aymeric
80 1.1 aymeric #include <sys/cdefs.h>
81 1.4 skrll __KERNEL_RCSID(0, "$NetBSD: mmnet_machdep.c,v 1.4 2019/07/16 14:41:47 skrll Exp $");
82 1.1 aymeric
83 1.1 aymeric #include "opt_ddb.h"
84 1.1 aymeric #include "opt_kgdb.h"
85 1.1 aymeric #include "opt_pmap_debug.h"
86 1.1 aymeric
87 1.1 aymeric #include <sys/param.h>
88 1.1 aymeric #include <sys/bus.h>
89 1.1 aymeric #include <sys/device.h>
90 1.1 aymeric #include <sys/systm.h>
91 1.1 aymeric #include <sys/kernel.h>
92 1.1 aymeric #include <sys/exec.h>
93 1.1 aymeric #include <sys/proc.h>
94 1.1 aymeric #include <sys/msgbuf.h>
95 1.1 aymeric #include <sys/reboot.h>
96 1.1 aymeric #include <sys/termios.h>
97 1.1 aymeric #include <sys/ksyms.h>
98 1.1 aymeric
99 1.1 aymeric #include <uvm/uvm_extern.h>
100 1.1 aymeric
101 1.1 aymeric #include <dev/cons.h>
102 1.1 aymeric
103 1.1 aymeric #include <machine/db_machdep.h>
104 1.1 aymeric #include <ddb/db_sym.h>
105 1.1 aymeric #include <ddb/db_extern.h>
106 1.1 aymeric
107 1.1 aymeric #define DRAM_BLOCKS 1
108 1.1 aymeric #include <machine/bootconfig.h>
109 1.1 aymeric #include <machine/cpu.h>
110 1.1 aymeric #include <machine/frame.h>
111 1.1 aymeric #include <arm/undefined.h>
112 1.1 aymeric
113 1.1 aymeric #include <arm/arm32/machdep.h>
114 1.1 aymeric
115 1.1 aymeric #include <arm/at91/at91reg.h>
116 1.1 aymeric #include <arm/at91/at91var.h>
117 1.1 aymeric
118 1.1 aymeric #include <dev/ic/comreg.h>
119 1.1 aymeric #include <dev/ic/comvar.h>
120 1.1 aymeric
121 1.1 aymeric #include <machine/autoconf.h>
122 1.1 aymeric
123 1.1 aymeric #include "isa.h"
124 1.1 aymeric
125 1.1 aymeric #include <arm/at91/at91sam9260reg.h>
126 1.1 aymeric #include <arm/at91/at91sam9260busvar.h>
127 1.1 aymeric
128 1.1 aymeric #include "ksyms.h"
129 1.1 aymeric
130 1.1 aymeric #include <arm/at91/at91busvar.h>
131 1.1 aymeric #include <arm/at91/at91pdcreg.h>
132 1.1 aymeric #include <arm/at91/at91dbgureg.h>
133 1.1 aymeric #include <arm/at91/at91reg.h>
134 1.1 aymeric #include <arm/at91/at91streg.h>
135 1.1 aymeric
136 1.1 aymeric /* boot configuration: */
137 1.1 aymeric BootConfig bootconfig; /* Boot config storage */
138 1.1 aymeric char *boot_args = NULL;
139 1.1 aymeric char *boot_file = NULL;
140 1.1 aymeric
141 1.1 aymeric /* hmmm */
142 1.1 aymeric static struct arm32_dma_range mmnet_dma_ranges[4];
143 1.1 aymeric static struct at91bus_machdep mmnetbus;
144 1.1 aymeric static at91bus_tag_t old_at91bus_tag;
145 1.1 aymeric
146 1.1 aymeric /* Prototypes */
147 1.1 aymeric static void mmnet_device_register(device_t dev, void *aux);
148 1.1 aymeric static void mmnetbus_init(struct at91bus_clocks *);
149 1.1 aymeric static void mmnetbus_peripheral_clock(int pid, int enable);
150 1.1 aymeric static uint32_t mmnetbus_gpio_mask(int pid);
151 1.1 aymeric
152 1.1 aymeric
153 1.1 aymeric /*
154 1.1 aymeric * void cpu_reboot(int howto, char *bootstr)
155 1.1 aymeric *
156 1.1 aymeric * Reboots the system
157 1.1 aymeric *
158 1.1 aymeric * Deal with any syncing, unmounting, dumping and shutdown hooks,
159 1.1 aymeric * then reset the CPU.
160 1.1 aymeric */
161 1.1 aymeric void
162 1.1 aymeric cpu_reboot(int howto, char *bootstr)
163 1.1 aymeric {
164 1.1 aymeric
165 1.1 aymeric /*
166 1.1 aymeric * If we are still cold then hit the air brakes
167 1.1 aymeric * and crash to earth fast
168 1.1 aymeric */
169 1.1 aymeric if (cold) {
170 1.1 aymeric doshutdownhooks();
171 1.1 aymeric pmf_system_shutdown(boothowto);
172 1.1 aymeric printf("\r\n");
173 1.1 aymeric printf("The operating system has halted.\r\n");
174 1.1 aymeric printf("Please press any key to reboot.\r\n");
175 1.1 aymeric cngetc();
176 1.1 aymeric printf("\r\nrebooting...\r\n");
177 1.1 aymeric goto reset;
178 1.1 aymeric }
179 1.1 aymeric
180 1.1 aymeric /* Disable console buffering */
181 1.1 aymeric
182 1.1 aymeric /*
183 1.1 aymeric * If RB_NOSYNC was not specified sync the discs.
184 1.1 aymeric * Note: Unless cold is set to 1 here, syslogd will die during the
185 1.1 aymeric * unmount. It looks like syslogd is getting woken up only to find
186 1.1 aymeric * that it cannot page part of the binary in as the filesystem has
187 1.1 aymeric * been unmounted.
188 1.1 aymeric */
189 1.1 aymeric if (!(howto & RB_NOSYNC))
190 1.1 aymeric bootsync();
191 1.1 aymeric
192 1.1 aymeric /* Say NO to interrupts */
193 1.1 aymeric splhigh();
194 1.1 aymeric
195 1.1 aymeric /* Do a dump if requested. */
196 1.1 aymeric if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
197 1.1 aymeric dumpsys();
198 1.1 aymeric
199 1.1 aymeric /* Run any shutdown hooks */
200 1.1 aymeric doshutdownhooks();
201 1.1 aymeric
202 1.1 aymeric pmf_system_shutdown(boothowto);
203 1.1 aymeric
204 1.1 aymeric /* Make sure IRQ's are disabled */
205 1.1 aymeric IRQdisable;
206 1.1 aymeric
207 1.1 aymeric if (howto & RB_HALT) {
208 1.1 aymeric printf("\r\n");
209 1.1 aymeric printf("The operating system has halted.\r\n");
210 1.1 aymeric printf("Please press any key to reboot.\r\n");
211 1.1 aymeric cngetc();
212 1.1 aymeric }
213 1.1 aymeric
214 1.1 aymeric printf("\r\nrebooting...\r\n");
215 1.1 aymeric reset:
216 1.1 aymeric /*
217 1.1 aymeric * Make really really sure that all interrupts are disabled,
218 1.1 aymeric * and poke the Internal Bus and Peripheral Bus reset lines.
219 1.1 aymeric */
220 1.1 aymeric (void) disable_interrupts(I32_bit|F32_bit);
221 1.1 aymeric STREG(ST_WDMR) = ST_WDMR_EXTEN | ST_WDMR_RSTEN | 1;
222 1.1 aymeric STREG(ST_CR) = ST_CR_WDRST;
223 1.1 aymeric for (;;);
224 1.1 aymeric }
225 1.1 aymeric
226 1.1 aymeric /*
227 1.4 skrll * vaddr_t initarm(...)
228 1.1 aymeric *
229 1.1 aymeric * Initial entry point on startup. This gets called before main() is
230 1.1 aymeric * entered.
231 1.1 aymeric * It should be responsible for setting up everything that must be
232 1.1 aymeric * in place when main is called.
233 1.1 aymeric * This includes
234 1.1 aymeric * Taking a copy of the boot configuration structure.
235 1.1 aymeric * Initialising the physical console so characters can be printed.
236 1.1 aymeric * Setting up page tables for the kernel
237 1.1 aymeric * Initialising interrupt controllers to a sane default state
238 1.1 aymeric */
239 1.4 skrll vaddr_t
240 1.1 aymeric initarm(void *arg)
241 1.1 aymeric {
242 1.4 skrll vaddr_t sp;
243 1.1 aymeric /*
244 1.1 aymeric * basic AT91 initialization:
245 1.1 aymeric */
246 1.1 aymeric if (at91bus_init())
247 1.1 aymeric panic("%s: at91bus_init() failed", __FUNCTION__);
248 1.1 aymeric
249 1.1 aymeric if (AT91_CHIP_ID() == AT91SAM9260_CHIP_ID) {
250 1.1 aymeric memcpy(&mmnetbus, at91bus_tag, sizeof(mmnetbus));
251 1.1 aymeric mmnetbus.init = mmnetbus_init;
252 1.1 aymeric mmnetbus.peripheral_clock = mmnetbus_peripheral_clock;
253 1.1 aymeric mmnetbus.gpio_mask = mmnetbus_gpio_mask;
254 1.1 aymeric old_at91bus_tag = at91bus_tag;
255 1.1 aymeric at91bus_tag = &mmnetbus;
256 1.1 aymeric }
257 1.1 aymeric
258 1.1 aymeric /* Fake bootconfig structure for the benefit of pmap.c */
259 1.1 aymeric /* XXX must make the memory description h/w independent */
260 1.1 aymeric bootconfig.dramblocks = 1;
261 1.1 aymeric bootconfig.dram[0].address = 0x20000000UL;
262 1.1 aymeric bootconfig.dram[0].pages = 0x04000000UL / PAGE_SIZE;
263 1.4 skrll sp = at91bus_setup(&bootconfig);
264 1.1 aymeric
265 1.1 aymeric if (AT91_CHIP_ID() != AT91SAM9260_CHIP_ID)
266 1.1 aymeric panic("%s: processor is not AT91SAM9260", __FUNCTION__);
267 1.1 aymeric
268 1.1 aymeric /* we've a specific device_register routine */
269 1.1 aymeric evbarm_device_register = mmnet_device_register;
270 1.1 aymeric
271 1.1 aymeric /* We return the new stack pointer address */
272 1.4 skrll return sp;
273 1.1 aymeric }
274 1.1 aymeric
275 1.1 aymeric
276 1.1 aymeric bus_dma_tag_t
277 1.1 aymeric at91_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
278 1.1 aymeric {
279 1.1 aymeric int i;
280 1.1 aymeric struct arm32_bus_dma_tag *dmat;
281 1.1 aymeric
282 1.1 aymeric for (i = 0; i < bootconfig.dramblocks; i++) {
283 1.1 aymeric mmnet_dma_ranges[i].dr_sysbase = bootconfig.dram[i].address;
284 1.1 aymeric mmnet_dma_ranges[i].dr_busbase = bootconfig.dram[i].address;
285 1.1 aymeric mmnet_dma_ranges[i].dr_len = bootconfig.dram[i].pages *
286 1.1 aymeric PAGE_SIZE;
287 1.1 aymeric }
288 1.1 aymeric
289 1.1 aymeric dmat = dma_tag_template;
290 1.1 aymeric
291 1.1 aymeric dmat->_ranges = mmnet_dma_ranges;
292 1.1 aymeric dmat->_nranges = bootconfig.dramblocks;
293 1.1 aymeric
294 1.1 aymeric return dmat;
295 1.1 aymeric }
296 1.1 aymeric
297 1.1 aymeric void mmnetbus_init(struct at91bus_clocks *clocks)
298 1.1 aymeric {
299 1.1 aymeric (*old_at91bus_tag->init)(clocks);
300 1.1 aymeric }
301 1.1 aymeric
302 1.1 aymeric uint32_t mmnetbus_gpio_mask(int pid)
303 1.1 aymeric {
304 1.1 aymeric switch (pid) {
305 1.1 aymeric case PID_PIOA: return ~0x00000300U;
306 1.1 aymeric case PID_PIOB: return ~0x0000783FU;
307 1.1 aymeric case PID_PIOC: return ~0x00000000U;
308 1.1 aymeric default: return ~0x00000000U;
309 1.1 aymeric }
310 1.1 aymeric }
311 1.1 aymeric
312 1.1 aymeric void mmnetbus_peripheral_clock(int pid, int enable)
313 1.1 aymeric {
314 1.1 aymeric switch (pid) {
315 1.1 aymeric case PID_TWI:
316 1.1 aymeric if (enable) {
317 1.1 aymeric PIOA_WRITE(PIO_ASR, 0x06000000);
318 1.1 aymeric PIOA_WRITE(PIO_PDR, 0x06000000);
319 1.1 aymeric PIOA_WRITE(PIO_MDER, 0x06000000);
320 1.1 aymeric }
321 1.1 aymeric break;
322 1.1 aymeric
323 1.1 aymeric case PID_SPI0:
324 1.1 aymeric if (enable) {
325 1.1 aymeric PIOA_WRITE(PIO_ASR, 0x0000000f);
326 1.1 aymeric PIOA_WRITE(PIO_PDR, 0x0000000f);
327 1.1 aymeric }
328 1.1 aymeric break;
329 1.1 aymeric
330 1.1 aymeric case PID_SPI1:
331 1.1 aymeric if (enable) {
332 1.1 aymeric PIOB_WRITE(PIO_ASR, 0x0000000f);
333 1.1 aymeric PIOB_WRITE(PIO_PDR, 0x0000000f);
334 1.1 aymeric }
335 1.1 aymeric break;
336 1.1 aymeric }
337 1.1 aymeric (*old_at91bus_tag->peripheral_clock)(pid, enable);
338 1.1 aymeric }
339 1.1 aymeric
340 1.1 aymeric
341 1.1 aymeric static void mmnet_device_register(device_t dev, void *aux)
342 1.1 aymeric {
343 1.1 aymeric #if 0
344 1.1 aymeric if (device_is_a(dev, "at91semac")) {
345 1.1 aymeric // propagate mac address from u-boot
346 1.1 aymeric }
347 1.1 aymeric #endif
348 1.1 aymeric }
349