2 * OpenBIOS Sparc OBIO driver
4 * (C) 2004 Stefan Reinauer <stepan@openbios.org>
5 * (C) 2005 Ed Schouten <ed@fxq.nl>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
14 #include "libopenbios/bindings.h"
15 #include "kernel/kernel.h"
16 #include "libc/byteorder.h"
17 #include "libc/vsprintf.h"
19 #include "drivers/drivers.h"
20 #include "arch/common/nvram.h"
21 #include "libopenbios/ofmem.h"
25 #define PROMDEV_KBD 0 /* input from keyboard */
26 #define PROMDEV_SCREEN 0 /* output to screen */
27 #define PROMDEV_TTYA 1 /* in/out to ttya */
29 /* "NCPU" is an historical name that's now a bit of a misnomer. The sun4m
30 * architecture registers NCPU CPU-specific interrupts along with one
31 * system-wide interrupt, regardless of the number of actual CPUs installed.
32 * See the comment on "NCPU" at <http://stuff.mit.edu/afs/athena/astaff/
33 * project/opssrc/sys.sunos/sun4m/devaddr.h>.
37 /* DECLARE data structures for the nodes. */
38 DECLARE_UNNAMED_NODE( ob_obio
, INSTALL_OPEN
, sizeof(int) );
41 ob_new_obio_device(const char *name
, const char *type
)
57 map_reg(uint64_t base
, uint64_t offset
, unsigned long size
, int map
,
74 addr
= (unsigned long)map_io(base
+ offset
, size
);
89 ob_reg(uint64_t base
, uint64_t offset
, unsigned long size
, int map
)
91 return map_reg(base
, offset
, size
, map
, 0);
107 ob_eccmemctl_init(uint64_t base
)
109 uint32_t version
, *regs
;
113 fword("find-device");
116 push_str("eccmemctl");
117 fword("device-name");
124 regs
= (uint32_t *)map_reg(ECC_BASE
, 0, ECC_SIZE
, 1, ECC_BASE
>> 32);
140 fword("encode-string");
144 fword("finish-device");
147 static unsigned char *nvram
;
149 #define NVRAM_OB_START (0)
150 #define NVRAM_OB_SIZE ((NVRAM_IDPROM - NVRAM_OB_START) & ~15)
153 arch_nvram_get(char *data
)
155 memcpy(data
, &nvram
[NVRAM_OB_START
], NVRAM_OB_SIZE
);
159 arch_nvram_put(char *data
)
161 memcpy(&nvram
[NVRAM_OB_START
], data
, NVRAM_OB_SIZE
);
165 arch_nvram_size(void)
167 return NVRAM_OB_SIZE
;
171 ss5_init(uint64_t base
)
173 ob_new_obio_device("slavioconfig", NULL
);
175 ob_reg(base
, SLAVIO_SCONFIG
, SCONFIG_REGS
, 0);
177 fword("finish-device");
181 ob_nvram_init(uint64_t base
, uint64_t offset
)
183 ob_new_obio_device("eeprom", NULL
);
185 nvram
= (unsigned char *)ob_reg(base
, offset
, NVRAM_SIZE
, 1);
187 PUSH((unsigned long)nvram
);
195 fword("finish-device");
199 fword("find-device");
201 PUSH((long)&nvram
[NVRAM_IDPROM
]);
203 fword("encode-bytes");
209 ob_fd_init(uint64_t base
, uint64_t offset
, int intr
)
213 ob_new_obio_device("SUNW,fdtwo", "block");
215 addr
= ob_reg(base
, offset
, FD_REGS
, 1);
219 fword("is-deblocker");
221 ob_floppy_init("/obio", "SUNW,fdtwo", 0, addr
);
223 fword("finish-device");
227 ob_auxio_init(uint64_t base
, uint64_t offset
)
229 ob_new_obio_device("auxio", NULL
);
231 ob_reg(base
, offset
, AUXIO_REGS
, 0);
233 fword("finish-device");
236 volatile unsigned char *power_reg
;
237 volatile unsigned int *reset_reg
;
240 sparc32_reset_all(void)
245 // AUX 2 (Software Powerdown Control) and reset
247 ob_aux2_reset_init(uint64_t base
, uint64_t offset
, int intr
)
249 ob_new_obio_device("power", NULL
);
251 power_reg
= (void *)ob_reg(base
, offset
, AUXIO2_REGS
, 1);
253 // Not in device tree
254 reset_reg
= map_io(base
+ (uint64_t)SLAVIO_RESET
, RESET_REGS
);
256 bind_func("sparc32-reset-all", sparc32_reset_all
);
257 push_str("' sparc32-reset-all to reset-all");
262 fword("finish-device");
265 volatile struct sun4m_timer_regs
*counter_regs
;
268 ob_counter_init(uint64_t base
, unsigned long offset
)
272 ob_new_obio_device("counter", NULL
);
274 for (i
= 0; i
< SUN4M_NCPU
; i
++) {
277 if (i
!= 0) fword("encode+");
278 PUSH(offset
+ (i
* PAGE_SIZE
));
289 PUSH(offset
+ 0x10000);
300 counter_regs
= map_io(base
+ (uint64_t)offset
, sizeof(*counter_regs
));
301 counter_regs
->cfg
= 0xffffffff;
302 counter_regs
->l10_timer_limit
= (((1000000/100) + 1) << 10);
303 counter_regs
->cpu_timers
[0].l14_timer_limit
= 0;
304 counter_regs
->cpu_timers
[0].cntrl
= 1;
306 for (i
= 0; i
< SUN4M_NCPU
; i
++) {
307 PUSH((unsigned long)&counter_regs
->cpu_timers
[i
]);
312 PUSH((unsigned long)&counter_regs
->l10_timer_limit
);
318 fword("finish-device");
321 static volatile struct sun4m_intregs
*intregs
;
324 ob_interrupt_init(uint64_t base
, unsigned long offset
)
328 ob_new_obio_device("interrupt", NULL
);
330 for (i
= 0; i
< SUN4M_NCPU
; i
++) {
333 if (i
!= 0) fword("encode+");
334 PUSH(offset
+ (i
* PAGE_SIZE
));
337 PUSH(INTERRUPT_REGS
);
345 PUSH(offset
+ 0x10000);
348 PUSH(INTERRUPT_REGS
);
355 intregs
= map_io(base
| (uint64_t)offset
, sizeof(*intregs
));
356 intregs
->clear
= ~SUN4M_INT_MASKALL
;
357 intregs
->cpu_intregs
[0].clear
= ~0x17fff;
359 for (i
= 0; i
< SUN4M_NCPU
; i
++) {
360 PUSH((unsigned long)&intregs
->cpu_intregs
[i
]);
365 PUSH((unsigned long)&intregs
->tbt
);
371 fword("finish-device");
374 /* SMP CPU boot structure */
382 static struct smp_cfg
*smp_header
;
385 start_cpu(unsigned int pc
, unsigned int context_ptr
, unsigned int context
, int cpu
)
392 smp_header
->smp_entry
= pc
;
393 smp_header
->smp_ctxtbl
= context_ptr
;
394 smp_header
->smp_ctx
= context
;
395 smp_header
->valid
= cpu
;
397 intregs
->cpu_intregs
[cpu
].set
= SUN4M_SOFT_INT(14);
403 ob_smp_init(unsigned long mem_size
)
405 // See arch/sparc32/entry.S for memory layout
406 smp_header
= (struct smp_cfg
*)map_io((uint64_t)(mem_size
- 0x100),
407 sizeof(struct smp_cfg
));
411 ob_obio_open(__attribute__((unused
))int *idx
)
418 ob_obio_close(__attribute__((unused
))int *idx
)
420 selfword("close-deblocker");
424 ob_obio_initialize(__attribute__((unused
))int *idx
)
427 fword("find-device");
431 fword("device-name");
433 push_str("hierarchical");
434 fword("device-type");
438 push_str("#address-cells");
443 push_str("#size-cells");
446 fword("finish-device");
450 ob_set_obio_ranges(uint64_t base
)
453 fword("find-device");
462 PUSH(base
& 0xffffffff);
473 ob_obio_decodeunit(__attribute__((unused
)) int *idx
)
475 fword("decode-unit-sbus");
480 ob_obio_encodeunit(__attribute__((unused
)) int *idx
)
482 fword("encode-unit-sbus");
485 NODE_METHODS(ob_obio
) = {
486 { NULL
, ob_obio_initialize
},
487 { "open", ob_obio_open
},
488 { "close", ob_obio_close
},
489 { "encode-unit", ob_obio_encodeunit
},
490 { "decode-unit", ob_obio_decodeunit
},
495 ob_obio_init(uint64_t slavio_base
, unsigned long fd_offset
,
496 unsigned long counter_offset
, unsigned long intr_offset
,
497 unsigned long aux1_offset
, unsigned long aux2_offset
,
498 unsigned long mem_size
)
501 // All devices were integrated to NCR89C105, see
502 // http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
504 //printk("Initializing OBIO devices...\n");
506 REGISTER_NAMED_NODE(ob_obio
, "/obio");
509 ob_set_obio_ranges(slavio_base
);
511 // Zilog Z8530 serial ports, see http://www.zilog.com
512 // Must be before zs@0,0 or Linux won't boot
513 ob_zs_init(slavio_base
, SLAVIO_ZS1
, ZS_INTR
, 0, 0);
515 ob_zs_init(slavio_base
, SLAVIO_ZS
, ZS_INTR
, 1, 1);
517 // M48T08 NVRAM, see http://www.st.com
518 ob_nvram_init(slavio_base
, SLAVIO_NVRAM
);
521 if (fd_offset
!= (unsigned long) -1)
522 ob_fd_init(slavio_base
, fd_offset
, FD_INTR
);
524 ob_auxio_init(slavio_base
, aux1_offset
);
526 if (aux2_offset
!= (unsigned long) -1)
527 ob_aux2_reset_init(slavio_base
, aux2_offset
, AUXIO2_INTR
);
529 ob_counter_init(slavio_base
, counter_offset
);
531 ob_interrupt_init(slavio_base
, intr_offset
);
533 ob_smp_init(mem_size
);