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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Big Endian PROM code for SNI RM machines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * License.  See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 2005-2006 Florian Lohoff (flo@rfc822.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 2005-2006 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/addrspace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/sni.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/mipsprom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/mipsregs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/bootinfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /* special SNI prom calls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * This does not exist in all proms - SINIX compares
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * the prom env variable "version" against "2.0008"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * or greater. If lesser it tries to probe interesting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define PROM_GET_MEMCONF	58
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define PROM_GET_HWCONF		61
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define PROM_VEC		(u64 *)CKSEG1ADDR(0x1fc00000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define PROM_ENTRY(x)		(PROM_VEC + (x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define ___prom_putchar		((int *(*)(int))PROM_ENTRY(PROM_PUTCHAR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define ___prom_getenv		((char *(*)(char *))PROM_ENTRY(PROM_GETENV))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define ___prom_get_memconf	((void (*)(void *))PROM_ENTRY(PROM_GET_MEMCONF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define ___prom_get_hwconf	((u32 (*)(void))PROM_ENTRY(PROM_GET_HWCONF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /* O32 stack has to be 8-byte aligned. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static u64 o32_stk[4096];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define O32_STK	  (&o32_stk[ARRAY_SIZE(o32_stk)])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define __PROM_O32(fun, arg) fun arg __asm__(#fun); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 				     __asm__(#fun " = call_o32")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) int   __PROM_O32(__prom_putchar, (int *(*)(int), void *, int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) char *__PROM_O32(__prom_getenv, (char *(*)(char *), void *, char *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) void  __PROM_O32(__prom_get_memconf, (void (*)(void *), void *, void *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) u32   __PROM_O32(__prom_get_hwconf, (u32 (*)(void), void *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define _prom_putchar(x)     __prom_putchar(___prom_putchar, O32_STK, x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define _prom_getenv(x)	     __prom_getenv(___prom_getenv, O32_STK, x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define _prom_get_memconf(x) __prom_get_memconf(___prom_get_memconf, O32_STK, x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define _prom_get_hwconf()   __prom_get_hwconf(___prom_get_hwconf, O32_STK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define _prom_putchar(x)     ___prom_putchar(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define _prom_getenv(x)	     ___prom_getenv(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define _prom_get_memconf(x) ___prom_get_memconf(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define _prom_get_hwconf(x)  ___prom_get_hwconf(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) void prom_putchar(char c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	_prom_putchar(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^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) char *prom_getenv(char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return _prom_getenv(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) void *prom_get_hwconf(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	u32 hwconf = _prom_get_hwconf();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (hwconf == 0xffffffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return (void *)CKSEG1ADDR(hwconf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) void __init prom_free_prom_memory(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * /proc/cpuinfo system type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) char *system_type = "Unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) const char *get_system_type(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return system_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static void __init sni_mem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	int i, memsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct membank {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		u32		size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		u32		base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		u32		size2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		u32		pad1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		u32		pad2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	} memconf[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	int brd_type = *(unsigned char *)SNI_IDPROM_BRDTYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	/* MemSIZE from prom in 16MByte chunks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	memsize = *((unsigned char *) SNI_IDPROM_MEMSIZE) * 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	pr_debug("IDProm memsize: %u MByte\n", memsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	/* get memory bank layout from prom */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	_prom_get_memconf(&memconf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	pr_debug("prom_get_mem_conf memory configuration:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	for (i = 0; i < 8 && memconf[i].size; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		if (brd_type == SNI_BRD_PCI_TOWER ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		    brd_type == SNI_BRD_PCI_TOWER_CPLUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			if (memconf[i].base >= 0x20000000 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			    memconf[i].base <  0x30000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				memconf[i].base -= 0x20000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		pr_debug("Bank%d: %08x @ %08x\n", i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			memconf[i].size, memconf[i].base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		memblock_add(memconf[i].base, memconf[i].size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) void __init prom_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	int argc = fw_arg0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	u32 *argv = (u32 *)CKSEG0ADDR(fw_arg1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	sni_mem_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	/* copy prom cmdline parameters to kernel cmdline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	for (i = 1; i < argc; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		strcat(arcs_cmdline, (char *)CKSEG0ADDR(argv[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		if (i < (argc - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			strcat(arcs_cmdline, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }