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