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