Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* Prom access routines for the sun3x */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/traps.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/sun3xprom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/idprom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/segment.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/sun3ints.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/openprom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/machines.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) void (*sun3x_putchar)(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) int (*sun3x_getchar)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) int (*sun3x_mayget)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) int (*sun3x_mayput)(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) void (*sun3x_prom_reboot)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) e_vector sun3x_prom_abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct linux_romvec *romvec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /* prom vector table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) e_vector *sun3x_prom_vbr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /* Handle returning to the prom */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) void sun3x_halt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	/* Disable interrupts while we mess with things */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	/* Restore prom vbr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	/* Restore prom NMI clock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) //	sun3x_disable_intreg(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	sun3_enable_irq(7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/* Let 'er rip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	asm volatile ("trap #14");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	/* Restore everything */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	sun3_disable_irq(7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	sun3_enable_irq(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	asm volatile ("movec %0,%%vbr" : : "r" ((void*)vectors));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) void sun3x_reboot(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	/* This never returns, don't bother saving things */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	/* Restore prom vbr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	/* Restore prom NMI clock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	sun3_disable_irq(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	sun3_enable_irq(7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	/* Let 'er rip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	(*romvec->pv_reboot)("vmlinux");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static void sun3x_prom_write(struct console *co, const char *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)                              unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	while (count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		if (*s == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			sun3x_putchar('\r');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		sun3x_putchar(*s++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) /* debug console - write-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static struct console sun3x_debug = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	.name	= "debug",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	.write	= sun3x_prom_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	.flags	= CON_PRINTBUFFER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	.index	= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) void __init sun3x_prom_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	/* Read the vector table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	sun3x_putchar = *(void (**)(int)) (SUN3X_P_PUTCHAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	sun3x_getchar = *(int (**)(void)) (SUN3X_P_GETCHAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	sun3x_mayget = *(int (**)(void))  (SUN3X_P_MAYGET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	sun3x_mayput = *(int (**)(int))   (SUN3X_P_MAYPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	sun3x_prom_reboot = *(void (**)(void)) (SUN3X_P_REBOOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	sun3x_prom_abort = *(e_vector *)  (SUN3X_P_ABORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	romvec = (struct linux_romvec *)SUN3X_PROM_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	idprom_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (!((idprom->id_machtype & SM_ARCH_MASK) == SM_SUN3X)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		pr_warn("Machine reports strange type %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			idprom->id_machtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		pr_warn("Pretending it's a 3/80, but very afraid...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		idprom->id_machtype = SM_SUN3X | SM_3_80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	/* point trap #14 at abort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 * XXX this is futile since we restore the vbr first - oops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	vectors[VEC_TRAP14] = sun3x_prom_abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static int __init sun3x_debug_setup(char *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	/* If debug=prom was specified, start the debug console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (MACH_IS_SUN3X && !strcmp(arg, "prom"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		register_console(&sun3x_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) early_param("debug", sun3x_debug_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* some prom functions to export */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int prom_getintdefault(int node, char *property, int deflt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	return deflt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int prom_getbool (int node, char *prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) void prom_printf(char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) void prom_halt (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	sun3x_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* Get the idprom and stuff it into buffer 'idbuf'.  Returns the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * format type.  'num_bytes' is the number of bytes that your idbuf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  * has space for.  Returns 0xff on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) unsigned char
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) prom_get_idprom(char *idbuf, int num_bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)         int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	/* make a copy of the idprom structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	for (i = 0; i < num_bytes; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		idbuf[i] = ((char *)SUN3X_IDPROM)[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)         return idbuf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }