#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.55 2024/05/13 00:08:06 msaitoh Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
#include "opt_modular.h"
#include "opt_md.h"
#include "opt_com.h"
#include "ksyms.h"
#include "opt_kloader.h"
#ifndef KLOADER_KERNEL_PATH
#define KLOADER_KERNEL_PATH "/netbsd"
#endif
#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/boot_flag.h>
#include <sys/cpu.h>
#include <sys/conf.h>
#include <sys/queue.h>
#include <sys/bus.h>
#include <uvm/uvm_extern.h>
#include <dev/cons.h>
#include <dev/ic/comreg.h>
#include <machine/db_machdep.h>
#include <ddb/db_sym.h>
#include <ddb/db_extern.h>
#ifdef KGDB
#include <sys/kgdb.h>
#endif
#include <machine/bootconfig.h>
#include <machine/bootinfo.h>
#ifdef KLOADER
#include <machine/kloader.h>
#endif
#include <arm/locore.h>
#include <arm/undefined.h>
#include <arm/arm32/machdep.h>
#include <arm/xscale/pxa2x0cpu.h>
#include <arm/xscale/pxa2x0reg.h>
#include <arm/xscale/pxa2x0var.h>
#include <arm/xscale/pxa2x0_gpio.h>
#include <arm/sa11x0/sa11x0_ostvar.h>
#include <arch/zaurus/zaurus/zaurus_reg.h>
#include <arch/zaurus/zaurus/zaurus_var.h>
#include <zaurus/dev/scoopreg.h>
#include <zaurus/dev/zlcdvar.h>
#include <zaurus/dev/w100lcdvar.h>
#if 0
#include "apm.h"
#endif
#if NAPM > 0
#include <zaurus/dev/zapmvar.h>
#endif
#define KERNEL_TEXT_BASE ((vaddr_t)&KERNEL_BASE_virt)
#ifndef KERNEL_VM_BASE
#define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
#endif
#define KERNEL_VM_SIZE 0x0c000000
int zaurusmod;
BootConfig bootconfig;
char *boot_file = NULL;
char *boot_args = NULL;
paddr_t physical_start;
paddr_t physical_freestart;
paddr_t physical_freeend;
paddr_t physical_end;
u_int free_pages;
#ifndef PMAP_STATIC_L1S
int max_processes = 64;
#endif
pv_addr_t minidataclean;
paddr_t msgbufphys;
#define KERNEL_PT_SYS 0
#define KERNEL_PT_KERNEL 1
#define KERNEL_PT_KERNEL_NUM ((KERNEL_VM_BASE - KERNEL_BASE) >> 22)
#define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
#define KERNEL_PT_VMDATA_NUM 4
#define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
const char *console =
#ifdef FFUARTCONSOLE
"ffuart";
#else
"glass";
#endif
int glass_console = 0;
#ifdef KLOADER
pv_addr_t bootinfo_pt;
pv_addr_t bootinfo_pg;
struct kloader_bootinfo kbootinfo;
int kloader_howto = 0;
#else
struct bootinfo _bootinfo;
#endif
struct bootinfo *bootinfo;
struct btinfo_howto *bi_howto;
extern char etext[], end[];
extern void *esym;
#if NKSYMS || defined(DDB) || defined(MODULAR)
#include <sys/exec_elf.h>
#endif
#define KERNEL_BASE_PHYS ((paddr_t)&KERNEL_BASE_phys)
#define BOOTINFO_PAGE (KERNEL_BASE_PHYS - PAGE_SIZE)
void consinit(void);
void dumpsys(void);
#ifdef KGDB
void kgdb_port_init(void);
#endif
#ifdef KLOADER
static int parseboot(char *arg, char **filename, int *howto);
static char *gettrailer(char *arg);
static int parseopts(const char *opts, int *howto);
#endif
#if defined(CPU_XSCALE_PXA250)
static struct pxa2x0_gpioconf pxa25x_boarddep_gpioconf[] = {
{ 34, GPIO_ALT_FN_1_IN },
{ 35, GPIO_ALT_FN_1_IN },
{ 39, GPIO_ALT_FN_2_OUT },
{ 40, GPIO_ALT_FN_2_OUT },
{ 41, GPIO_ALT_FN_2_OUT },
{ 44, GPIO_ALT_FN_1_IN },
{ 45, GPIO_ALT_FN_2_OUT },
{ -1 }
};
static struct pxa2x0_gpioconf *pxa25x_zaurus_gpioconf[] = {
pxa25x_com_btuart_gpioconf,
pxa25x_com_ffuart_gpioconf,
pxa25x_com_stuart_gpioconf,
pxa25x_boarddep_gpioconf,
NULL
};
#else
static struct pxa2x0_gpioconf *pxa25x_zaurus_gpioconf[] = {
NULL
};
#endif
#if defined(CPU_XSCALE_PXA270)
static struct pxa2x0_gpioconf pxa27x_boarddep_gpioconf[] = {
{ 34, GPIO_ALT_FN_1_IN },
{ 35, GPIO_ALT_FN_1_IN },
{ 39, GPIO_ALT_FN_2_OUT },
{ 40, GPIO_ALT_FN_2_OUT },
{ 41, GPIO_ALT_FN_2_OUT },
{ 44, GPIO_ALT_FN_1_IN },
{ 45, GPIO_ALT_FN_2_OUT },
{ 104, GPIO_ALT_FN_1_OUT },
{ -1 }
};
static struct pxa2x0_gpioconf *pxa27x_zaurus_gpioconf[] = {
pxa27x_com_btuart_gpioconf,
pxa27x_com_ffuart_gpioconf,
pxa27x_com_stuart_gpioconf,
pxa27x_i2c_gpioconf,
pxa27x_i2s_gpioconf,
pxa27x_pxamci_gpioconf,
pxa27x_boarddep_gpioconf,
NULL
};
#else
static struct pxa2x0_gpioconf *pxa27x_zaurus_gpioconf[] = {
NULL
};
#endif
void
cpu_reboot(int howto, char *bootstr)
{
if (cold) {
howto |= RB_HALT;
goto haltsys;
}
boothowto = howto;
#ifdef KLOADER
if ((howto & RB_HALT) == 0 && panicstr == NULL) {
char *filename = NULL;
if ((howto & RB_STRING) && (bootstr != NULL)) {
if (parseboot(bootstr, &filename, &kloader_howto) == 0){
filename = NULL;
kloader_howto = 0;
}
}
if (kloader_howto != 0) {
printf("howto: 0x%x\n", kloader_howto);
}
if (filename != NULL) {
kloader_reboot_setup(filename);
} else {
kloader_reboot_setup(KLOADER_KERNEL_PATH);
}
}
#endif
if (!(howto & RB_NOSYNC)) {
bootsync();
}
delay(3 * 1000 * 1000);
splhigh();
if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
dumpsys();
haltsys:
doshutdownhooks();
pmf_system_shutdown(boothowto);
IRQdisable;
if (howto & RB_HALT) {
#if NAPM > 0
if (howto & RB_POWERDOWN) {
printf("\nAttempting to power down...\n");
zapm_poweroff();
}
#endif
printf("The operating system has halted.\n");
printf("Please press any key to reboot.\n\n");
cngetc();
}
#ifdef KLOADER
else if (panicstr == NULL) {
delay(1 * 1000 * 1000);
kloader_reboot();
printf("\n");
printf("Failed to load a new kernel.\n");
printf("Please press any key to reboot.\n\n");
cngetc();
}
#endif
printf("rebooting...\n");
delay(1 * 1000 * 1000);
zaurus_restart();
printf("REBOOT FAILED!!!\n");
for (;;)
continue;
}
void
zaurus_restart(void)
{
uint32_t rv;
if (ZAURUS_ISC1000 || ZAURUS_ISC3000) {
rv = pxa2x0_memctl_read(MEMCTL_MSC0);
if ((rv & 0xffff0000) == 0x7ff00000) {
pxa2x0_memctl_write(MEMCTL_MSC0,
(rv & 0xffff) | 0x7ee00000);
}
pxa2x0_gpio_set_function(89, GPIO_OUT | GPIO_SET);
} else {
ioreg_write(ZAURUS_POWMAN_VBASE + POWMAN_RCSR,
POWMAN_HWR|POWMAN_WDR|POWMAN_SMR|POWMAN_GPR);
saost_reset();
}
delay(1 * 1000 * 1000);
}
static inline pd_entry_t *
read_ttb(void)
{
u_long ttb;
__asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb));
return (pd_entry_t *)(ttb & ~((1 << 14) - 1));
}
static const struct pmap_devmap zaurus_devmap[] = {
DEVMAP_ENTRY(
ZAURUS_GPIO_VBASE,
PXA2X0_GPIO_BASE,
PXA2X0_GPIO_SIZE
),
DEVMAP_ENTRY(
ZAURUS_CLKMAN_VBASE,
PXA2X0_CLKMAN_BASE,
PXA2X0_CLKMAN_SIZE
),
DEVMAP_ENTRY(
ZAURUS_INTCTL_VBASE,
PXA2X0_INTCTL_BASE,
PXA2X0_INTCTL_SIZE
),
DEVMAP_ENTRY(
ZAURUS_MEMCTL_VBASE,
PXA2X0_MEMCTL_BASE,
PXA2X0_MEMCTL_SIZE
),
DEVMAP_ENTRY(
ZAURUS_SCOOP0_VBASE,
C3000_SCOOP0_BASE,
SCOOP_SIZE
),
DEVMAP_ENTRY(
ZAURUS_SCOOP1_VBASE,
C3000_SCOOP1_BASE,
SCOOP_SIZE
),
DEVMAP_ENTRY(
ZAURUS_FFUART_VBASE,
PXA2X0_FFUART_BASE,
4 * COM_NPORTS
),
DEVMAP_ENTRY(
ZAURUS_BTUART_VBASE,
PXA2X0_BTUART_BASE,
4 * COM_NPORTS
),
DEVMAP_ENTRY(
ZAURUS_STUART_VBASE,
PXA2X0_STUART_BASE,
4 * COM_NPORTS
),
DEVMAP_ENTRY(
ZAURUS_POWMAN_VBASE,
PXA2X0_POWMAN_BASE,
PXA2X0_POWMAN_SIZE
),
DEVMAP_ENTRY_END
};
void green_on(int virt);
void
green_on(int virt)
{
volatile uint16_t *p;
if (virt) {
p = (volatile uint16_t *)(ZAURUS_SCOOP0_VBASE + SCOOP_GPWR);
} else {
p = (volatile uint16_t *)(C3000_SCOOP0_BASE + SCOOP_GPWR);
}
*p |= (1 << SCOOP0_LED_GREEN);
}
void irda_on(int virt);
void
irda_on(int virt)
{
volatile uint16_t *p;
if (virt) {
int o = C3000_SCOOP1_BASE - trunc_page(C3000_SCOOP1_BASE);
p = (volatile uint16_t *)(ZAURUS_SCOOP1_VBASE + o + SCOOP_GPWR);
} else {
p = (volatile uint16_t *)(C3000_SCOOP1_BASE + SCOOP_GPWR);
}
*p &= ~(1 << SCOOP1_IR_ON);
}
static int
hw_isc1000(void)
{
const u_long baseaddr = ZAURUS_SCOOP1_VBASE +
(C3000_SCOOP1_BASE - trunc_page(C3000_SCOOP1_BASE));
uint16_t mcr, cdr, csr, cpr, ccr, irr, irm, imr, isr;
uint16_t gpcr, gpwr, gprr;
mcr = ioreg16_read(baseaddr + SCOOP_MCR);
cdr = ioreg16_read(baseaddr + SCOOP_CDR);
csr = ioreg16_read(baseaddr + SCOOP_CSR);
cpr = ioreg16_read(baseaddr + SCOOP_CPR);
ccr = ioreg16_read(baseaddr + SCOOP_CCR);
irr = ioreg16_read(baseaddr + SCOOP_IRR);
irm = ioreg16_read(baseaddr + SCOOP_IRM);
imr = ioreg16_read(baseaddr + SCOOP_IMR);
isr = ioreg16_read(baseaddr + SCOOP_ISR);
gpcr = ioreg16_read(baseaddr + SCOOP_GPCR);
gpwr = ioreg16_read(baseaddr + SCOOP_GPWR);
gprr = ioreg16_read(baseaddr + SCOOP_GPRR);
if (mcr == 0 && cdr == 0 && csr == 0 && cpr == 0 && ccr == 0 &&
irr == 0 && irm == 0 && imr == 0 && isr == 0 &&
gpcr == 0 && gpwr == 0 && gprr == 0) {
return 1;
}
return 0;
}
vaddr_t
initarm(void *arg)
{
extern char KERNEL_BASE_phys[], KERNEL_BASE_virt[];
int loop;
int loop1;
u_int l1pagetable;
paddr_t memstart;
psize_t memsize;
struct pxa2x0_gpioconf **zaurus_gpioconf;
u_int *magicaddr;
#if NKSYMS || defined(DDB) || defined(MODULAR)
u_int symbolsize;
#endif
pxa2x0_memctl_bootstrap(PXA2X0_MEMCTL_BASE);
if (set_cpufuncs())
panic("cpu not recognized!");
pxa2x0_intr_bootstrap(PXA2X0_INTCTL_BASE);
pmap_devmap_bootstrap((vaddr_t)read_ttb(), zaurus_devmap);
pxa2x0_memctl_bootstrap(ZAURUS_MEMCTL_VBASE);
pxa2x0_intr_bootstrap(ZAURUS_INTCTL_VBASE);
magicaddr = (u_int *)(KERNEL_BASE_PHYS - BOOTARGS_BUFSIZ);
if (*magicaddr == BOOTARGS_MAGIC) {
#ifdef KLOADER
bootinfo = &kbootinfo.bootinfo;
#else
bootinfo = &_bootinfo;
#endif
memcpy(bootinfo, (void *)(KERNEL_BASE_PHYS - BOOTINFO_MAXSIZE),
BOOTINFO_MAXSIZE);
bi_howto = lookup_bootinfo(BTINFO_HOWTO);
boothowto = (bi_howto != NULL) ? bi_howto->howto : RB_AUTOBOOT;
} else {
boothowto = RB_AUTOBOOT;
}
*magicaddr = 0xdeadbeef;
if (boothowto & RB_MD1) {
console = "ffuart";
}
memstart = PXA2X0_SDRAM0_START;
memsize = 0x04000000;
if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X) {
if (hw_isc1000())
zaurusmod = ZAURUS_C1000;
else
zaurusmod = ZAURUS_C3000;
zaurus_gpioconf = pxa27x_zaurus_gpioconf;
} else {
zaurusmod = ZAURUS_C860;
if (cputype == CPU_ID_PXA250B) {
memsize = 0x02000000;
}
zaurus_gpioconf = pxa25x_zaurus_gpioconf;
}
pxa2x0_gpio_bootstrap(ZAURUS_GPIO_VBASE);
pxa2x0_gpio_config(zaurus_gpioconf);
pxa2x0_clkman_bootstrap(ZAURUS_CLKMAN_VBASE);
if (strcmp(console, "glass") != 0)
consinit();
#ifdef KGDB
kgdb_port_init();
#endif
#ifdef VERBOSE_INIT_ARM
printf("\nNetBSD/zaurus booting ...\n");
#endif
#ifdef KLOADER
kloader_bootinfo_set(&kbootinfo, 0, NULL, NULL, true);
#endif
#ifdef VERBOSE_INIT_ARM
printf("initarm: Configuring system ...\n");
#endif
bootconfig.dramblocks = 1;
bootconfig.dram[0].address = memstart;
bootconfig.dram[0].pages = memsize / PAGE_SIZE;
physical_start = bootconfig.dram[0].address;
physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
physical_freestart = PXA2X0_SDRAM0_START + 0x9000;
physical_freeend = BOOTINFO_PAGE;
physmem = (physical_end - physical_start) / PAGE_SIZE;
#ifdef VERBOSE_INIT_ARM
printf("physmemory: %lu pages at 0x%08lx -> 0x%08lx\n", physmem,
physical_start, physical_end - 1);
#endif
#ifdef VERBOSE_INIT_ARM
printf("Allocating page tables\n");
#endif
free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
#ifdef VERBOSE_INIT_ARM
printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
physical_freestart, free_pages, free_pages);
#endif
#define valloc_pages(var, np) \
alloc_pages((var).pv_pa, (np)); \
(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
#define alloc_pages(var, np) \
physical_freeend -= ((np) * PAGE_SIZE); \
if (physical_freeend < physical_freestart) \
panic("initarm: out of memory"); \
(var) = physical_freeend; \
free_pages -= (np); \
memset((char *)(var), 0, ((np) * PAGE_SIZE));
loop1 = 0;
for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
&& kernel_l1pt.pv_pa == 0) {
valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
} else {
valloc_pages(kernel_pt_table[loop1],
L2_TABLE_SIZE / PAGE_SIZE);
++loop1;
}
}
#ifdef KLOADER
valloc_pages(bootinfo_pt, L2_TABLE_SIZE / PAGE_SIZE);
#endif
if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
panic("initarm: Failed to align the kernel page directory");
alloc_pages(systempage.pv_pa, 1);
valloc_pages(irqstack, IRQ_STACK_SIZE);
valloc_pages(abtstack, ABT_STACK_SIZE);
valloc_pages(undstack, UND_STACK_SIZE);
valloc_pages(kernelstack, UPAGES);
#ifdef DIAGNOSTIC
KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
#endif
valloc_pages(minidataclean, 1);
#ifdef KLOADER
bootinfo_pg.pv_pa = BOOTINFO_PAGE;
bootinfo_pg.pv_va = KERNEL_BASE + bootinfo_pg.pv_pa - physical_start;
#endif
#ifdef VERBOSE_INIT_ARM
printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
irqstack.pv_va);
printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
abtstack.pv_va);
printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
undstack.pv_va);
printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
kernelstack.pv_va);
printf("minidataclean: p0x%08lx v0x%08lx, size = %ld\n",
minidataclean.pv_pa, minidataclean.pv_va,
xscale_minidata_clean_size);
#ifdef KLOADER
printf("bootinfo_pg: p0x%08lx v0x%08lx\n", bootinfo_pg.pv_pa,
bootinfo_pg.pv_va);
#endif
#endif
alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
#ifdef VERBOSE_INIT_ARM
printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
#endif
l1pagetable = kernel_l1pt.pv_pa;
pmap_link_l2pt(l1pagetable, 0x00000000,
&kernel_pt_table[KERNEL_PT_SYS]);
for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
&kernel_pt_table[KERNEL_PT_KERNEL + loop]);
for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
&kernel_pt_table[KERNEL_PT_VMDATA + loop]);
#ifdef KLOADER
pmap_link_l2pt(l1pagetable, PXA2X0_SDRAM0_START, &bootinfo_pt);
#endif
pmap_curmaxkvaddr =
KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
esym = end;
#if NKSYMS || defined(DDB) || defined(MODULAR)
symbolsize = 0;
Elf_Ehdr *eh = (Elf_Ehdr *)end;
#ifdef VERBOSE_INIT_ARM
printf("Checking ELF MAGIC at end: %02x %02x %02x %02x\n",
end[0], end[1], end[2], end[3]);
#endif
if (memcmp(eh->e_ident, ELFMAG, SELFMAG) == 0) {
Elf_Shdr *sh;
#ifdef VERBOSE_INIT_ARM
printf("ELF header found at end\n");
#endif
sh = (Elf_Shdr *)((char *)end + eh->e_shoff);
for (loop = 0; loop < eh->e_shnum; loop++, sh++) {
#ifdef VERBOSE_INIT_ARM
printf("Checking ELF header %d\n", loop);
#endif
if (sh->sh_type != SHT_SYMTAB &&
sh->sh_type != SHT_STRTAB) {
continue;
}
#ifdef VERBOSE_INIT_ARM
printf("Section[%2d]: offset = %d, size = %d\n",
loop, sh->sh_offset, sh->sh_size);
#endif
if (sh->sh_offset > 0 &&
(sh->sh_offset + sh->sh_size) > symbolsize) {
symbolsize = sh->sh_offset + sh->sh_size;
}
#ifdef VERBOSE_INIT_ARM
printf("Updating symbolsize = %d\n", symbolsize);
#endif
}
esym = (char *)esym + symbolsize;
}
#ifdef VERBOSE_INIT_ARM
printf("symbolsize = %d\n", symbolsize);
#endif
#endif
#ifdef VERBOSE_INIT_ARM
printf("Mapping kernel\n");
#endif
{
size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
size_t totalsize = (uintptr_t) esym - KERNEL_TEXT_BASE;
u_int logical;
textsize = (textsize + PGOFSET) & ~PGOFSET;
totalsize = (totalsize + PGOFSET) & ~PGOFSET;
logical = KERNEL_TEXT_BASE - KERNEL_BASE;
logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
physical_start + logical, textsize,
VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
physical_start + logical, totalsize - textsize,
VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
}
#ifdef VERBOSE_INIT_ARM
printf("Constructing L2 page tables\n");
#endif
pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
}
#ifdef KLOADER
pmap_map_chunk(l1pagetable, bootinfo_pt.pv_va, bootinfo_pt.pv_pa,
L2_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
pmap_map_chunk(l1pagetable, bootinfo_pg.pv_va, bootinfo_pg.pv_pa,
PAGE_SIZE, VM_PROT_ALL, PTE_CACHE);
#endif
xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
minidataclean.pv_pa);
#if 0
pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
#else
pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
#endif
pmap_devmap_bootstrap(l1pagetable, zaurus_devmap);
xscale_cache_clean_addr = 0xff000000U;
{
physical_freestart = physical_start +
((((uintptr_t) esym + PGOFSET) & ~PGOFSET) - KERNEL_BASE);
physical_freeend = physical_end;
free_pages =
(physical_freeend - physical_freestart) / PAGE_SIZE;
}
#ifdef VERBOSE_INIT_ARM
printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
physical_freestart, free_pages, free_pages);
printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
#endif
cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
cpu_setttb(kernel_l1pt.pv_pa, true);
cpu_tlb_flushID();
cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
#ifdef VERBOSE_INIT_ARM
printf("bootstrap done.\n");
#endif
arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
#ifdef VERBOSE_INIT_ARM
printf("init subsystems: stacks ");
#endif
set_stackptr(PSR_IRQ32_MODE,
irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
set_stackptr(PSR_ABT32_MODE,
abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
set_stackptr(PSR_UND32_MODE,
undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
#ifdef VERBOSE_INIT_ARM
printf("vectors ");
#endif
data_abort_handler_address = (u_int)data_abort_handler;
prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
undefined_handler_address = (u_int)undefinedinstruction_bounce;
#ifdef VERBOSE_INIT_ARM
printf("undefined ");
#endif
undefined_init();
#ifdef VERBOSE_INIT_ARM
printf("page ");
#endif
uvm_md_init();
uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
atop(physical_freestart), atop(physical_freeend),
VM_FREELIST_DEFAULT);
#ifdef VERBOSE_INIT_ARM
printf("pmap ");
#endif
pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
#ifdef VERBOSE_INIT_ARM
printf("\n");
#endif
#ifdef __HAVE_MEMORY_DISK__
md_root_setconf(memory_disk, sizeof memory_disk);
#endif
#if NKSYMS || defined(DDB) || defined(MODULAR)
if (symbolsize > 0)
ksyms_addsyms_elf(symbolsize, &end, esym);
#endif
#ifdef KGDB
if (boothowto & RB_KDB) {
kgdb_debug_init = 1;
kgdb_connect(1);
}
#endif
#ifdef DDB
db_machine_init();
if (boothowto & RB_KDB)
Debugger();
#endif
return kernelstack.pv_va + USPACE_SVC_STACK_TOP;
}
void *
lookup_bootinfo(int type)
{
struct btinfo_common *help;
int n;
if (bootinfo == NULL)
return (NULL);
n = bootinfo->nentries;
help = (struct btinfo_common *)(bootinfo->info);
while (n--) {
if (help->type == type)
return (help);
help = (struct btinfo_common *)((char *)help + help->len);
}
return (NULL);
}
#ifdef KLOADER
static int
parseboot(char *arg, char **filename, int *howto)
{
char *opts = NULL;
*filename = NULL;
*howto = 0;
if (arg == NULL || *arg == '\0')
return 1;
if (arg[0] == '-') {
opts = arg;
} else {
*filename = arg;
opts = gettrailer(arg);
if (opts == NULL || *opts == '\0') {
opts = NULL;
} else if (*opts != '-') {
printf("invalid arguments\n");
return 0;
}
}
if (opts) {
if (parseopts(opts, howto) == 0) {
return 0;
}
}
return 1;
}
static char *
gettrailer(char *arg)
{
static char nullstr[] = "";
char *options;
if ((options = strchr(arg, ' ')) == NULL)
return nullstr;
else
*options++ = '\0';
while (*options == ' ')
options++;
return options;
}
static int
parseopts(const char *opts, int *howto)
{
int r, tmpopt = *howto;
opts++;
while (*opts && *opts != ' ') {
r = 0;
BOOT_FLAG(*opts, r);
if (r == 0) {
printf("-%c: unknown flag\n", *opts);
return 0;
}
tmpopt |= r;
opts++;
}
*howto = tmpopt;
return 1;
}
#endif
#include "com.h"
#if (NCOM > 0)
#include <dev/ic/comvar.h>
#endif
#include "lcd.h"
#include "w100lcd.h"
#include "wsdisplay.h"
#ifndef CONSPEED
#define CONSPEED B9600
#endif
#ifndef CONMODE
#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)
#endif
int comcnspeed = CONSPEED;
int comcnmode = CONMODE;
#ifdef KGDB
#ifndef KGDB_DEVNAME
#define KGDB_DEVNAME "ffuart"
#endif
const char kgdb_devname[] = KGDB_DEVNAME;
#if (NCOM > 0)
#ifndef KGDB_DEVMODE
#define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)
#endif
int comkgdbmode = KGDB_DEVMODE;
#endif
#endif
void
consinit(void)
{
static int consinit_called = 0;
#if (NCOM > 0) && defined(COM_PXA2X0)
paddr_t paddr;
u_int cken = 0;
#endif
if (consinit_called)
return;
consinit_called = 1;
#if (NCOM > 0) && defined(COM_PXA2X0)
#ifdef KGDB
if (strcmp(kgdb_devname, console) == 0) {
} else
#endif
if (strcmp(console, "ffuart") == 0) {
paddr = PXA2X0_FFUART_BASE;
cken = CKEN_FFUART;
} else if (strcmp(console, "btuart") == 0) {
paddr = PXA2X0_BTUART_BASE;
cken = CKEN_BTUART;
} else if (strcmp(console, "stuart") == 0) {
paddr = PXA2X0_STUART_BASE;
cken = CKEN_STUART;
irda_on(0);
} else
#endif
if (strcmp(console, "glass") == 0) {
#if ((NLCD > 0) || (NW100LCD > 0)) && (NWSDISPLAY > 0)
glass_console = 1;
#if NLCD > 0
if (ZAURUS_ISC1000 || ZAURUS_ISC3000)
lcd_cnattach();
#endif
#if NW100LCD > 0
if (ZAURUS_ISC860)
w100lcd_cnattach();
#endif
#endif
}
#if (NCOM > 0) && defined(COM_PXA2X0)
if (cken != 0 && comcnattach(&pxa2x0_a4x_bs_tag, paddr, comcnspeed,
PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode) == 0) {
pxa2x0_clkman_config(cken, 1);
}
#endif
}
#ifdef KGDB
void
kgdb_port_init(void)
{
#if (NCOM > 0) && defined(COM_PXA2X0)
paddr_t paddr;
u_int cken;
if (strcmp(kgdb_devname, "ffuart") == 0) {
paddr = PXA2X0_FFUART_BASE;
cken = CKEN_FFUART;
} else if (strcmp(kgdb_devname, "btuart") == 0) {
paddr = PXA2X0_BTUART_BASE;
cken = CKEN_BTUART;
} else if (strcmp(kgdb_devname, "stuart") == 0) {
paddr = PXA2X0_STUART_BASE;
cken = CKEN_STUART;
irda_on(0);
} else
return;
if (com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
kgdb_rate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode) == 0) {
pxa2x0_clkman_config(cken, 1);
}
#endif
}
#endif