Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  PS3 bootwrapper support.
0004  *
0005  *  Copyright (C) 2007 Sony Computer Entertainment Inc.
0006  *  Copyright 2007 Sony Corp.
0007  */
0008 
0009 #include <stdarg.h>
0010 #include <stddef.h>
0011 #include "types.h"
0012 #include "elf.h"
0013 #include "string.h"
0014 #include "stdio.h"
0015 #include "page.h"
0016 #include "ops.h"
0017 
0018 extern int lv1_panic(u64 in_1);
0019 extern int lv1_get_logical_partition_id(u64 *out_1);
0020 extern int lv1_get_logical_ppe_id(u64 *out_1);
0021 extern int lv1_get_repository_node_value(u64 in_1, u64 in_2, u64 in_3,
0022     u64 in_4, u64 in_5, u64 *out_1, u64 *out_2);
0023 
0024 BSS_STACK(4096);
0025 
0026 /* A buffer that may be edited by tools operating on a zImage binary so as to
0027  * edit the command line passed to vmlinux (by setting /chosen/bootargs).
0028  * The buffer is put in it's own section so that tools may locate it easier.
0029  */
0030 
0031 static char cmdline[BOOT_COMMAND_LINE_SIZE]
0032     __attribute__((__section__("__builtin_cmdline")));
0033 
0034 static void prep_cmdline(void *chosen)
0035 {
0036     if (cmdline[0] == '\0')
0037         getprop(chosen, "bootargs", cmdline, BOOT_COMMAND_LINE_SIZE-1);
0038     else
0039         setprop_str(chosen, "bootargs", cmdline);
0040 
0041     printf("cmdline: '%s'\n", cmdline);
0042 }
0043 
0044 static void ps3_console_write(const char *buf, int len)
0045 {
0046 }
0047 
0048 static void ps3_exit(void)
0049 {
0050     printf("ps3_exit\n");
0051 
0052     /* lv1_panic will shutdown the lpar. */
0053 
0054     lv1_panic(0); /* zero = do not reboot */
0055     while (1);
0056 }
0057 
0058 static int ps3_repository_read_rm_size(u64 *rm_size)
0059 {
0060     int result;
0061     u64 lpar_id;
0062     u64 ppe_id;
0063     u64 v2;
0064 
0065     result = lv1_get_logical_partition_id(&lpar_id);
0066 
0067     if (result)
0068         return -1;
0069 
0070     result = lv1_get_logical_ppe_id(&ppe_id);
0071 
0072     if (result)
0073         return -1;
0074 
0075     /*
0076      * n1: 0000000062690000 : ....bi..
0077      * n2: 7075000000000000 : pu......
0078      * n3: 0000000000000001 : ........
0079      * n4: 726d5f73697a6500 : rm_size.
0080     */
0081 
0082     result = lv1_get_repository_node_value(lpar_id, 0x0000000062690000ULL,
0083         0x7075000000000000ULL, ppe_id, 0x726d5f73697a6500ULL, rm_size,
0084         &v2);
0085 
0086     printf("%s:%d: ppe_id  %lu \n", __func__, __LINE__,
0087         (unsigned long)ppe_id);
0088     printf("%s:%d: lpar_id %lu \n", __func__, __LINE__,
0089         (unsigned long)lpar_id);
0090     printf("%s:%d: rm_size %llxh \n", __func__, __LINE__, *rm_size);
0091 
0092     return result ? -1 : 0;
0093 }
0094 
0095 void ps3_copy_vectors(void)
0096 {
0097     extern char __system_reset_kernel[];
0098 
0099     memcpy((void *)0x100, __system_reset_kernel, 512);
0100     flush_cache((void *)0x100, 512);
0101 }
0102 
0103 void platform_init(void)
0104 {
0105     const u32 heapsize = 0x1000000 - (u32)_end; /* 16MiB */
0106     void *chosen;
0107     unsigned long ft_addr;
0108     u64 rm_size;
0109 
0110     console_ops.write = ps3_console_write;
0111     platform_ops.exit = ps3_exit;
0112 
0113     printf("\n-- PS3 bootwrapper --\n");
0114 
0115     simple_alloc_init(_end, heapsize, 32, 64);
0116     fdt_init(_dtb_start);
0117 
0118     chosen = finddevice("/chosen");
0119 
0120     ps3_repository_read_rm_size(&rm_size);
0121     dt_fixup_memory(0, rm_size);
0122 
0123     if (&_initrd_end > &_initrd_start) {
0124         setprop_val(chosen, "linux,initrd-start", (u32)(_initrd_start));
0125         setprop_val(chosen, "linux,initrd-end", (u32)(_initrd_end));
0126     }
0127 
0128     prep_cmdline(chosen);
0129 
0130     ft_addr = dt_ops.finalize();
0131 
0132     ps3_copy_vectors();
0133 
0134     printf(" flat tree at 0x%lx\n\r", ft_addr);
0135 
0136     ((kernel_entry_t)0)(ft_addr, 0, NULL);
0137 
0138     ps3_exit();
0139 }