mmnet_machdep.c revision 1.6 1 1.6 skrll /* $Id: mmnet_machdep.c,v 1.6 2020/04/18 11:00:40 skrll Exp $ */
2 1.6 skrll /* $NetBSD: mmnet_machdep.c,v 1.6 2020/04/18 11:00:40 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.6 skrll __KERNEL_RCSID(0, "$NetBSD: mmnet_machdep.c,v 1.6 2020/04/18 11:00:40 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
86 1.1 aymeric #include <sys/param.h>
87 1.1 aymeric #include <sys/bus.h>
88 1.1 aymeric #include <sys/device.h>
89 1.1 aymeric #include <sys/systm.h>
90 1.1 aymeric #include <sys/kernel.h>
91 1.1 aymeric #include <sys/exec.h>
92 1.1 aymeric #include <sys/proc.h>
93 1.1 aymeric #include <sys/msgbuf.h>
94 1.1 aymeric #include <sys/reboot.h>
95 1.1 aymeric #include <sys/termios.h>
96 1.1 aymeric #include <sys/ksyms.h>
97 1.1 aymeric
98 1.1 aymeric #include <uvm/uvm_extern.h>
99 1.1 aymeric
100 1.1 aymeric #include <dev/cons.h>
101 1.1 aymeric
102 1.1 aymeric #include <machine/db_machdep.h>
103 1.1 aymeric #include <ddb/db_sym.h>
104 1.1 aymeric #include <ddb/db_extern.h>
105 1.1 aymeric
106 1.1 aymeric #define DRAM_BLOCKS 1
107 1.1 aymeric #include <machine/bootconfig.h>
108 1.1 aymeric #include <machine/cpu.h>
109 1.1 aymeric #include <machine/frame.h>
110 1.1 aymeric #include <arm/undefined.h>
111 1.1 aymeric
112 1.1 aymeric #include <arm/arm32/machdep.h>
113 1.1 aymeric
114 1.1 aymeric #include <arm/at91/at91reg.h>
115 1.1 aymeric #include <arm/at91/at91var.h>
116 1.1 aymeric
117 1.1 aymeric #include <dev/ic/comreg.h>
118 1.1 aymeric #include <dev/ic/comvar.h>
119 1.1 aymeric
120 1.1 aymeric #include <machine/autoconf.h>
121 1.1 aymeric
122 1.1 aymeric #include "isa.h"
123 1.1 aymeric
124 1.1 aymeric #include <arm/at91/at91sam9260reg.h>
125 1.1 aymeric #include <arm/at91/at91sam9260busvar.h>
126 1.1 aymeric
127 1.1 aymeric #include "ksyms.h"
128 1.1 aymeric
129 1.1 aymeric #include <arm/at91/at91busvar.h>
130 1.1 aymeric #include <arm/at91/at91pdcreg.h>
131 1.1 aymeric #include <arm/at91/at91dbgureg.h>
132 1.1 aymeric #include <arm/at91/at91reg.h>
133 1.1 aymeric #include <arm/at91/at91streg.h>
134 1.1 aymeric
135 1.1 aymeric /* boot configuration: */
136 1.1 aymeric BootConfig bootconfig; /* Boot config storage */
137 1.1 aymeric char *boot_args = NULL;
138 1.1 aymeric char *boot_file = NULL;
139 1.1 aymeric
140 1.1 aymeric /* hmmm */
141 1.1 aymeric static struct arm32_dma_range mmnet_dma_ranges[4];
142 1.1 aymeric static struct at91bus_machdep mmnetbus;
143 1.1 aymeric static at91bus_tag_t old_at91bus_tag;
144 1.1 aymeric
145 1.1 aymeric /* Prototypes */
146 1.1 aymeric static void mmnet_device_register(device_t dev, void *aux);
147 1.1 aymeric static void mmnetbus_init(struct at91bus_clocks *);
148 1.1 aymeric static void mmnetbus_peripheral_clock(int pid, int enable);
149 1.1 aymeric static uint32_t mmnetbus_gpio_mask(int pid);
150 1.1 aymeric
151 1.1 aymeric
152 1.1 aymeric /*
153 1.1 aymeric * void cpu_reboot(int howto, char *bootstr)
154 1.1 aymeric *
155 1.1 aymeric * Reboots the system
156 1.1 aymeric *
157 1.1 aymeric * Deal with any syncing, unmounting, dumping and shutdown hooks,
158 1.1 aymeric * then reset the CPU.
159 1.1 aymeric */
160 1.1 aymeric void
161 1.1 aymeric cpu_reboot(int howto, char *bootstr)
162 1.1 aymeric {
163 1.1 aymeric
164 1.1 aymeric /*
165 1.1 aymeric * If we are still cold then hit the air brakes
166 1.1 aymeric * and crash to earth fast
167 1.1 aymeric */
168 1.1 aymeric if (cold) {
169 1.1 aymeric doshutdownhooks();
170 1.1 aymeric pmf_system_shutdown(boothowto);
171 1.1 aymeric printf("\r\n");
172 1.1 aymeric printf("The operating system has halted.\r\n");
173 1.1 aymeric printf("Please press any key to reboot.\r\n");
174 1.1 aymeric cngetc();
175 1.1 aymeric printf("\r\nrebooting...\r\n");
176 1.1 aymeric goto reset;
177 1.1 aymeric }
178 1.1 aymeric
179 1.1 aymeric /* Disable console buffering */
180 1.1 aymeric
181 1.1 aymeric /*
182 1.1 aymeric * If RB_NOSYNC was not specified sync the discs.
183 1.1 aymeric * Note: Unless cold is set to 1 here, syslogd will die during the
184 1.1 aymeric * unmount. It looks like syslogd is getting woken up only to find
185 1.1 aymeric * that it cannot page part of the binary in as the filesystem has
186 1.1 aymeric * been unmounted.
187 1.1 aymeric */
188 1.1 aymeric if (!(howto & RB_NOSYNC))
189 1.1 aymeric bootsync();
190 1.1 aymeric
191 1.1 aymeric /* Say NO to interrupts */
192 1.1 aymeric splhigh();
193 1.1 aymeric
194 1.1 aymeric /* Do a dump if requested. */
195 1.1 aymeric if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
196 1.1 aymeric dumpsys();
197 1.5 skrll
198 1.1 aymeric /* Run any shutdown hooks */
199 1.1 aymeric doshutdownhooks();
200 1.1 aymeric
201 1.1 aymeric pmf_system_shutdown(boothowto);
202 1.1 aymeric
203 1.1 aymeric /* Make sure IRQ's are disabled */
204 1.1 aymeric IRQdisable;
205 1.1 aymeric
206 1.1 aymeric if (howto & RB_HALT) {
207 1.1 aymeric printf("\r\n");
208 1.1 aymeric printf("The operating system has halted.\r\n");
209 1.1 aymeric printf("Please press any key to reboot.\r\n");
210 1.1 aymeric cngetc();
211 1.1 aymeric }
212 1.1 aymeric
213 1.1 aymeric printf("\r\nrebooting...\r\n");
214 1.1 aymeric reset:
215 1.1 aymeric /*
216 1.1 aymeric * Make really really sure that all interrupts are disabled,
217 1.1 aymeric * and poke the Internal Bus and Peripheral Bus reset lines.
218 1.1 aymeric */
219 1.1 aymeric (void) disable_interrupts(I32_bit|F32_bit);
220 1.1 aymeric STREG(ST_WDMR) = ST_WDMR_EXTEN | ST_WDMR_RSTEN | 1;
221 1.1 aymeric STREG(ST_CR) = ST_CR_WDRST;
222 1.1 aymeric for (;;);
223 1.1 aymeric }
224 1.1 aymeric
225 1.1 aymeric /*
226 1.4 skrll * vaddr_t initarm(...)
227 1.1 aymeric *
228 1.1 aymeric * Initial entry point on startup. This gets called before main() is
229 1.1 aymeric * entered.
230 1.1 aymeric * It should be responsible for setting up everything that must be
231 1.1 aymeric * in place when main is called.
232 1.1 aymeric * This includes
233 1.1 aymeric * Taking a copy of the boot configuration structure.
234 1.1 aymeric * Initialising the physical console so characters can be printed.
235 1.1 aymeric * Setting up page tables for the kernel
236 1.1 aymeric * Initialising interrupt controllers to a sane default state
237 1.1 aymeric */
238 1.4 skrll vaddr_t
239 1.1 aymeric initarm(void *arg)
240 1.1 aymeric {
241 1.4 skrll vaddr_t sp;
242 1.1 aymeric /*
243 1.1 aymeric * basic AT91 initialization:
244 1.1 aymeric */
245 1.1 aymeric if (at91bus_init())
246 1.1 aymeric panic("%s: at91bus_init() failed", __FUNCTION__);
247 1.1 aymeric
248 1.1 aymeric if (AT91_CHIP_ID() == AT91SAM9260_CHIP_ID) {
249 1.1 aymeric memcpy(&mmnetbus, at91bus_tag, sizeof(mmnetbus));
250 1.1 aymeric mmnetbus.init = mmnetbus_init;
251 1.1 aymeric mmnetbus.peripheral_clock = mmnetbus_peripheral_clock;
252 1.1 aymeric mmnetbus.gpio_mask = mmnetbus_gpio_mask;
253 1.1 aymeric old_at91bus_tag = at91bus_tag;
254 1.1 aymeric at91bus_tag = &mmnetbus;
255 1.1 aymeric }
256 1.1 aymeric
257 1.1 aymeric /* Fake bootconfig structure for the benefit of pmap.c */
258 1.1 aymeric /* XXX must make the memory description h/w independent */
259 1.1 aymeric bootconfig.dramblocks = 1;
260 1.1 aymeric bootconfig.dram[0].address = 0x20000000UL;
261 1.1 aymeric bootconfig.dram[0].pages = 0x04000000UL / PAGE_SIZE;
262 1.4 skrll sp = at91bus_setup(&bootconfig);
263 1.1 aymeric
264 1.1 aymeric if (AT91_CHIP_ID() != AT91SAM9260_CHIP_ID)
265 1.1 aymeric panic("%s: processor is not AT91SAM9260", __FUNCTION__);
266 1.1 aymeric
267 1.1 aymeric /* we've a specific device_register routine */
268 1.1 aymeric evbarm_device_register = mmnet_device_register;
269 1.1 aymeric
270 1.1 aymeric /* We return the new stack pointer address */
271 1.4 skrll return sp;
272 1.1 aymeric }
273 1.1 aymeric
274 1.1 aymeric
275 1.1 aymeric bus_dma_tag_t
276 1.1 aymeric at91_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
277 1.1 aymeric {
278 1.1 aymeric int i;
279 1.1 aymeric struct arm32_bus_dma_tag *dmat;
280 1.1 aymeric
281 1.1 aymeric for (i = 0; i < bootconfig.dramblocks; i++) {
282 1.1 aymeric mmnet_dma_ranges[i].dr_sysbase = bootconfig.dram[i].address;
283 1.1 aymeric mmnet_dma_ranges[i].dr_busbase = bootconfig.dram[i].address;
284 1.5 skrll mmnet_dma_ranges[i].dr_len = bootconfig.dram[i].pages *
285 1.1 aymeric PAGE_SIZE;
286 1.1 aymeric }
287 1.1 aymeric
288 1.1 aymeric dmat = dma_tag_template;
289 1.1 aymeric
290 1.1 aymeric dmat->_ranges = mmnet_dma_ranges;
291 1.1 aymeric dmat->_nranges = bootconfig.dramblocks;
292 1.1 aymeric
293 1.1 aymeric return dmat;
294 1.1 aymeric }
295 1.1 aymeric
296 1.1 aymeric void mmnetbus_init(struct at91bus_clocks *clocks)
297 1.1 aymeric {
298 1.1 aymeric (*old_at91bus_tag->init)(clocks);
299 1.1 aymeric }
300 1.1 aymeric
301 1.1 aymeric uint32_t mmnetbus_gpio_mask(int pid)
302 1.1 aymeric {
303 1.1 aymeric switch (pid) {
304 1.1 aymeric case PID_PIOA: return ~0x00000300U;
305 1.1 aymeric case PID_PIOB: return ~0x0000783FU;
306 1.1 aymeric case PID_PIOC: return ~0x00000000U;
307 1.1 aymeric default: return ~0x00000000U;
308 1.1 aymeric }
309 1.1 aymeric }
310 1.1 aymeric
311 1.1 aymeric void mmnetbus_peripheral_clock(int pid, int enable)
312 1.1 aymeric {
313 1.1 aymeric switch (pid) {
314 1.1 aymeric case PID_TWI:
315 1.1 aymeric if (enable) {
316 1.1 aymeric PIOA_WRITE(PIO_ASR, 0x06000000);
317 1.1 aymeric PIOA_WRITE(PIO_PDR, 0x06000000);
318 1.1 aymeric PIOA_WRITE(PIO_MDER, 0x06000000);
319 1.1 aymeric }
320 1.1 aymeric break;
321 1.1 aymeric
322 1.1 aymeric case PID_SPI0:
323 1.1 aymeric if (enable) {
324 1.1 aymeric PIOA_WRITE(PIO_ASR, 0x0000000f);
325 1.1 aymeric PIOA_WRITE(PIO_PDR, 0x0000000f);
326 1.1 aymeric }
327 1.1 aymeric break;
328 1.1 aymeric
329 1.1 aymeric case PID_SPI1:
330 1.1 aymeric if (enable) {
331 1.1 aymeric PIOB_WRITE(PIO_ASR, 0x0000000f);
332 1.1 aymeric PIOB_WRITE(PIO_PDR, 0x0000000f);
333 1.1 aymeric }
334 1.1 aymeric break;
335 1.1 aymeric }
336 1.1 aymeric (*old_at91bus_tag->peripheral_clock)(pid, enable);
337 1.1 aymeric }
338 1.1 aymeric
339 1.1 aymeric
340 1.1 aymeric static void mmnet_device_register(device_t dev, void *aux)
341 1.1 aymeric {
342 1.1 aymeric #if 0
343 1.1 aymeric if (device_is_a(dev, "at91semac")) {
344 1.1 aymeric // propagate mac address from u-boot
345 1.1 aymeric }
346 1.1 aymeric #endif
347 1.1 aymeric }
348