#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: integrator_machdep.c,v 1.82 2023/06/24 05:43:26 msaitoh Exp $");
#include "opt_arm_debug.h"
#include "opt_console.h"
#include "opt_ddb.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 <sys/intr.h>
#include <uvm/uvm_extern.h>
#include <dev/cons.h>
#include <machine/db_machdep.h>
#include <ddb/db_sym.h>
#include <ddb/db_extern.h>
#include <machine/bootconfig.h>
#include <arm/locore.h>
#include <arm/undefined.h>
#include <arm/arm32/machdep.h>
#include <evbarm/integrator/integrator_boot.h>
#include "pci.h"
#include "ksyms.h"
void ifpga_reset(void) __attribute__((noreturn));
#define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
#define KERNEL_VM_SIZE 0x0C000000
BootConfig bootconfig;
char *boot_args = NULL;
char *boot_file = NULL;
static void integrator_sdram_bounds (paddr_t *, psize_t *);
void consinit(void);
#include "vga.h"
#if NVGA > 0
#include <dev/ic/mc6845reg.h>
#include <dev/ic/pcdisplayvar.h>
#include <dev/ic/vgareg.h>
#include <dev/ic/vgavar.h>
#endif
#include "pckbc.h"
#if NPCKBC > 0
#include <dev/ic/i8042reg.h>
#include <dev/ic/pckbcvar.h>
#endif
#include "com.h"
#if NCOM > 0
#include <dev/ic/comreg.h>
#include <dev/ic/comvar.h>
#ifndef CONCOMADDR
#define CONCOMADDR 0x3f8
#endif
#endif
#ifndef CONSPEED
#define CONSPEED B115200
#endif
#ifndef CONMODE
#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)
#endif
int comcnspeed = CONSPEED;
int comcnmode = CONMODE;
#include "plcom.h"
#if (NPLCOM > 0)
#include <evbarm/dev/plcomreg.h>
#include <evbarm/dev/plcomvar.h>
#include <evbarm/ifpga/ifpgamem.h>
#include <evbarm/ifpga/ifpgareg.h>
#include <evbarm/ifpga/ifpgavar.h>
#endif
#ifndef CONSDEVNAME
#define CONSDEVNAME "plcom"
#endif
#ifndef PLCONSPEED
#define PLCONSPEED B38400
#endif
#ifndef PLCONMODE
#define PLCONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)
#endif
#ifndef PLCOMCNUNIT
#define PLCOMCNUNIT -1
#endif
int plcomcnspeed = PLCONSPEED;
int plcomcnmode = PLCONMODE;
#if 0
extern struct consdev kcomcons;
static void kcomcnputc(dev_t, int);
#endif
void
cpu_reboot(int howto, char *bootstr)
{
if (cold) {
doshutdownhooks();
pmf_system_shutdown(boothowto);
printf("The operating system has halted.\n");
printf("Please press any key to reboot.\n\n");
cngetc();
printf("rebooting...\n");
ifpga_reset();
}
if (!(howto & RB_NOSYNC))
bootsync();
splhigh();
if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
dumpsys();
doshutdownhooks();
pmf_system_shutdown(boothowto);
IRQdisable;
if (howto & RB_HALT) {
printf("The operating system has halted.\n");
printf("Please press any key to reboot.\n\n");
cngetc();
}
printf("rebooting...\n");
ifpga_reset();
}
static const struct pmap_devmap integrator_devmap[] = {
#if NPLCOM > 0 && defined(PLCONSOLE)
DEVMAP_ENTRY(
UART0_BOOT_BASE,
IFPGA_IO_BASE + IFPGA_UART0,
1024 * 1024
),
DEVMAP_ENTRY(
UART1_BOOT_BASE,
IFPGA_IO_BASE + IFPGA_UART1,
1024 * 1024
),
#endif
#if NPCI > 0
DEVMAP_ENTRY(
IFPGA_PCI_IO_VBASE,
IFPGA_PCI_IO_BASE,
IFPGA_PCI_IO_VSIZE
),
DEVMAP_ENTRY(
IFPGA_PCI_CONF_VBASE,
IFPGA_PCI_CONF_BASE,
IFPGA_PCI_CONF_VSIZE
),
#endif
DEVMAP_ENTRY_END
};
vaddr_t
initarm(void *arg)
{
extern int KERNEL_BASE_phys[];
paddr_t memstart;
psize_t memsize;
if (set_cpufuncs())
panic("cpu not recognized!");
pmap_devmap_bootstrap((vaddr_t)armreg_ttbr_read() & -L1_TABLE_SIZE,
integrator_devmap);
cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
consinit();
#define BDSTR(s) _BDSTR(s)
#define _BDSTR(s) #s
printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n");
integrator_sdram_bounds(&memstart, &memsize);
#if defined(INTEGRATOR_CP)
memstart = 0;
#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;
bootconfig.dram[0].flags = BOOT_DRAM_CAN_DMA;
arm32_bootmem_init(bootconfig.dram[0].address,
bootconfig.dram[0].pages * PAGE_SIZE, (unsigned int) KERNEL_BASE_phys);
arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_LOW, 0, integrator_devmap,
false);
#ifdef VERBOSE_INIT_ARM
printf("done.\n");
#endif
return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
}
void
consinit(void)
{
static int consinit_called = 0;
#if 0
char *console = CONSDEVNAME;
#endif
if (consinit_called != 0)
return;
consinit_called = 1;
#if NPLCOM > 0 && defined(PLCONSOLE)
if (PLCOMCNUNIT == 0) {
extern struct bus_space ifpga_common_bs_tag;
static struct plcom_instance ifpga_pi1 = {
#if defined(INTEGRATOR_CP)
.pi_type = PLCOM_TYPE_PL011,
#else
.pi_type = PLCOM_TYPE_PL010,
#endif
.pi_iot = &ifpga_common_bs_tag,
.pi_size = IFPGA_UART_SIZE,
.pi_iobase = IFPGA_UART0
};
if (plcomcnattach(&ifpga_pi1, plcomcnspeed, IFPGA_UART_CLK,
plcomcnmode, PLCOMCNUNIT))
panic("can't init serial console");
return;
} else if (PLCOMCNUNIT == 1) {
extern struct bus_space ifpga_common_bs_tag;
static struct plcom_instance ifpga_pi1 = {
#if defined(INTEGRATOR_CP)
.pi_type = PLCOM_TYPE_PL011,
#else
.pi_type = PLCOM_TYPE_PL010,
#endif
.pi_iot = &ifpga_common_bs_tag,
.pi_size = IFPGA_UART_SIZE,
.pi_iobase = IFPGA_UART1
};
if (plcomcnattach(&ifpga_pi1, plcomcnspeed, IFPGA_UART_CLK,
plcomcnmode, PLCOMCNUNIT))
panic("can't init serial console");
return;
}
#endif
#if (NCOM > 0)
if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed,
COM_FREQ, COM_TYPE_NORMAL, comcnmode))
panic("can't init serial console @%x", CONCOMADDR);
return;
#endif
panic("No serial console configured");
}
static void
integrator_sdram_bounds(paddr_t *memstart, psize_t *memsize)
{
volatile unsigned long *cm_sdram
= (volatile unsigned long *)0x10000020;
volatile unsigned long *cm_stat
= (volatile unsigned long *)0x10000010;
*memstart = *cm_stat & 0x00ff0000;
switch ((*cm_sdram >> 2) & 0x7)
{
case 0:
*memsize = 16 * 1024 * 1024;
break;
case 1:
*memsize = 32 * 1024 * 1024;
break;
case 2:
*memsize = 64 * 1024 * 1024;
break;
case 3:
*memsize = 128 * 1024 * 1024;
break;
case 4:
*memsize = 256 * 1024 * 1024 - *memstart;
break;
default:
printf("CM_SDRAM returns unknown value, using 16M\n");
*memsize = 16 * 1024 * 1024;
break;
}
}