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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  PS3 bootwrapper support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2007 Sony Computer Entertainment Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright 2007 Sony Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "types.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "elf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "string.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "stdio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "page.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "ops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) extern int lv1_panic(u64 in_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) extern int lv1_get_logical_partition_id(u64 *out_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) extern int lv1_get_logical_ppe_id(u64 *out_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) extern int lv1_get_repository_node_value(u64 in_1, u64 in_2, u64 in_3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	u64 in_4, u64 in_5, u64 *out_1, u64 *out_2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define DBG(fmt...) printf(fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static inline int __attribute__ ((format (printf, 1, 2))) DBG(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	const char *fmt, ...) {return 0;}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) BSS_STACK(4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /* A buffer that may be edited by tools operating on a zImage binary so as to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * edit the command line passed to vmlinux (by setting /chosen/bootargs).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * The buffer is put in it's own section so that tools may locate it easier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static char cmdline[BOOT_COMMAND_LINE_SIZE]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	__attribute__((__section__("__builtin_cmdline")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static void prep_cmdline(void *chosen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (cmdline[0] == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		getprop(chosen, "bootargs", cmdline, BOOT_COMMAND_LINE_SIZE-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		setprop_str(chosen, "bootargs", cmdline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	printf("cmdline: '%s'\n", cmdline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static void ps3_console_write(const char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static void ps3_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	printf("ps3_exit\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	/* lv1_panic will shutdown the lpar. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	lv1_panic(0); /* zero = do not reboot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	while (1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static int ps3_repository_read_rm_size(u64 *rm_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	u64 lpar_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	u64 ppe_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	u64 v2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	result = lv1_get_logical_partition_id(&lpar_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	result = lv1_get_logical_ppe_id(&ppe_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return -1;
^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) 	 * n1: 0000000062690000 : ....bi..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 * n2: 7075000000000000 : pu......
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 * n3: 0000000000000001 : ........
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 * n4: 726d5f73697a6500 : rm_size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	result = lv1_get_repository_node_value(lpar_id, 0x0000000062690000ULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		0x7075000000000000ULL, ppe_id, 0x726d5f73697a6500ULL, rm_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		&v2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	printf("%s:%d: ppe_id  %lu \n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		(unsigned long)ppe_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	printf("%s:%d: lpar_id %lu \n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		(unsigned long)lpar_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	printf("%s:%d: rm_size %llxh \n", __func__, __LINE__, *rm_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return result ? -1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) void ps3_copy_vectors(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	extern char __system_reset_kernel[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	memcpy((void *)0x100, __system_reset_kernel, 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	flush_cache((void *)0x100, 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) void platform_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	const u32 heapsize = 0x1000000 - (u32)_end; /* 16MiB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	void *chosen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	unsigned long ft_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	u64 rm_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	console_ops.write = ps3_console_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	platform_ops.exit = ps3_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	printf("\n-- PS3 bootwrapper --\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	simple_alloc_init(_end, heapsize, 32, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	fdt_init(_dtb_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	chosen = finddevice("/chosen");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	ps3_repository_read_rm_size(&rm_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	dt_fixup_memory(0, rm_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (&_initrd_end > &_initrd_start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		setprop_val(chosen, "linux,initrd-start", (u32)(_initrd_start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		setprop_val(chosen, "linux,initrd-end", (u32)(_initrd_end));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	prep_cmdline(chosen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	ft_addr = dt_ops.finalize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	ps3_copy_vectors();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	printf(" flat tree at 0x%lx\n\r", ft_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	((kernel_entry_t)0)(ft_addr, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	ps3_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }