1 // SPDX-License-Identifier: GPL-2.0-only 2 #include <linux/types.h> 3 #include <linux/init.h> 4 #include <linux/libfdt.h> 5 #include <linux/string.h> 6 #include <asm/pgtable.h> 7 #include <asm/setup.h> 8 9 #include "pi.h" 10 11 static char early_cmdline[COMMAND_LINE_SIZE]; 12 13 static char *get_early_cmdline(uintptr_t dtb_pa) 14 { 15 const char *fdt_cmdline = NULL; 16 unsigned int fdt_cmdline_size = 0; 17 int chosen_node; 18 19 if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { 20 chosen_node = fdt_path_offset((void *)dtb_pa, "/chosen"); 21 if (chosen_node >= 0) { 22 fdt_cmdline = fdt_getprop((void *)dtb_pa, chosen_node, 23 "bootargs", NULL); 24 if (fdt_cmdline) { 25 fdt_cmdline_size = strlen(fdt_cmdline); 26 strscpy(early_cmdline, fdt_cmdline, 27 COMMAND_LINE_SIZE); 28 } 29 } 30 } 31 32 if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || 33 IS_ENABLED(CONFIG_CMDLINE_FORCE) || 34 fdt_cmdline_size == 0 /* CONFIG_CMDLINE_FALLBACK */) { 35 strlcat(early_cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE); 36 } 37 38 return early_cmdline; 39 } 40 41 static u64 match_noXlvl(char *cmdline) 42 { 43 if (strstr(cmdline, "no4lvl")) 44 return SATP_MODE_48; 45 else if (strstr(cmdline, "no5lvl")) 46 return SATP_MODE_57; 47 48 return 0; 49 } 50 51 u64 set_satp_mode_from_cmdline(uintptr_t dtb_pa) 52 { 53 char *cmdline = get_early_cmdline(dtb_pa); 54 55 return match_noXlvl(cmdline); 56 } 57 58 static bool match_nokaslr(char *cmdline) 59 { 60 return strstr(cmdline, "nokaslr"); 61 } 62 63 bool set_nokaslr_from_cmdline(uintptr_t dtb_pa) 64 { 65 char *cmdline = get_early_cmdline(dtb_pa); 66 67 return match_nokaslr(cmdline); 68 } 69