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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Copyright (C) Paul Mackerras 1997.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include "types.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include "elf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include "string.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "stdio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "page.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "ops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "of.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /* Value picked to match that used by yaboot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define PROG_START	0x01400000	/* only used on 64-bit systems */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define RAM_END		(512<<20)	/* Fixme: use OF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define	ONE_MB		0x100000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static unsigned long claim_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) void epapr_platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 			 unsigned long r6, unsigned long r7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static void *of_try_claim(unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	unsigned long addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	if (claim_base == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 		claim_base = _ALIGN_UP((unsigned long)_end, ONE_MB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	for(; claim_base < RAM_END; claim_base += ONE_MB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 		printf("    trying: 0x%08lx\n\r", claim_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		addr = (unsigned long) of_claim(claim_base, size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		if (addr != PROM_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	if (addr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	claim_base = PAGE_ALIGN(claim_base + size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	return (void *)addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static void of_image_hdr(const void *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	const Elf64_Ehdr *elf64 = hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	if (elf64->e_ident[EI_CLASS] == ELFCLASS64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 		 * Maintain a "magic" minimum address. This keeps some older
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 		 * firmware platforms running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 		if (claim_base < PROG_START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 			claim_base = PROG_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static void of_platform_init(unsigned long a1, unsigned long a2, void *promptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	platform_ops.image_hdr = of_image_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	platform_ops.malloc = of_try_claim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	platform_ops.exit = of_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	platform_ops.vmlinux_alloc = of_vmlinux_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	dt_ops.finddevice = of_finddevice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	dt_ops.getprop = of_getprop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	dt_ops.setprop = of_setprop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	of_console_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	of_init(promptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	loader_info.promptr = promptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	if (a1 && a2 && a2 != 0xdeadbeef) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 		loader_info.initrd_addr = a1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 		loader_info.initrd_size = a2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	}
^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) void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 		   unsigned long r6, unsigned long r7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 	/* Detect OF vs. ePAPR boot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 	if (r5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 		of_platform_init(r3, r4, (void *)r5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 		epapr_platform_init(r3, r4, r5, r6, r7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)