LoongArch: Support booting with FDT from efi system table
PATCH 1/1 LoongArch: Support booting with FDT from efi system table
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
--- arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 + arch/loongarch/include/asm/setup.h | 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++- 6 files changed, 106 insertions(+), 3 deletions(-)
arch/loongarch/Kconfig +2 -0
@@ -111,6 +111,8 @@ config LOONGARCH select MODULES_USE_ELF_RELA if MODULES select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select OF + select OF_EARLY_FLATTREE select PCI select PCI_DOMAINS_GENERIC select PCI_ECAM if ACPI
arch/loongarch/include/asm/efi.h +1 -0
@@ -9,6 +9,7 @@void __init efi_init (void );void __init efi_runtime_init (void ); +void __init *efi_fdt_pointer (void );void efifb_setup_from_dmi (struct screen_info *si,const char *opt);#define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004/* Bit 2: CSR.CRMD.IE */
arch/loongarch/include/asm/setup.h +1 -0
@@ -13,6 +13,7 @@extern unsigned long eentry;extern unsigned long tlbrentry; +extern char original_cmdline[COMMAND_LINE_SIZE ];extern void tlb_init (int cpu);extern void cpu_cache_init (void );extern void cache_error_setup (void );
arch/loongarch/kernel/efi.c +26 -1
@@ -37,7 +37,7 @@ static efi_config_table_type_t arch_tables[] __initdata = {void __init efi_runtime_init (void ) { -if (!efi_enabled (EFI_BOOT )) +if (!efi_enabled (EFI_BOOT ) || !efi_systab->runtime)return ;if (efi_runtime_disabled ()) {
@@ -101,3 +101,28 @@ void __init efi_init(void)early_memunmap (tbl,sizeof (*tbl)); } } + +/* parse the fdt pointer from efi system table */ +void __init *efi_fdt_pointer (void ) +{ +int i; +void *fdt =NULL ; +efi_config_table_t *tables; + +if (!efi_systab) { +pr_err ("Can't find EFI system table.\n" ); +return NULL ; + } + + tables = (efi_config_table_t *) efi_systab->tables; + +for (i =0 ; i < efi_systab->nr_tables; i++) +if (efi_guidcmp (tables[i].guid,DEVICE_TREE_GUID ) ==0 ) { + fdt = (void *)early_memremap_ro ( + (resource_size_t )tables[i].table, +sizeof (efi_config_table_t)); +break ; + } + +return fdt; +}
arch/loongarch/kernel/env.c +3 -0
@@ -11,6 +11,7 @@#include <asm/early_ioremap.h> #include <asm/bootinfo.h> #include <asm/loongson.h> +#include <asm/setup.h> u64 efi_system_table;struct loongson_system_configuration loongson_sysconf;
@@ -27,6 +28,8 @@ void __init init_environ(void)clear_bit (EFI_BOOT , &efi.flags);strscpy (boot_command_line, cmdline,COMMAND_LINE_SIZE ); +/* Save unparsed command line copy for FDT */ +strscpy (original_cmdline, boot_command_line,COMMAND_LINE_SIZE );early_memunmap (cmdline,COMMAND_LINE_SIZE ); efi_system_table = fw_arg2;
arch/loongarch/kernel/setup.c +73 -2
117 lines not on this page · raw message
Signature · 1 line
2.31.1
Quoted 22 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
Signed-off-by Binbin Zhou <[email protected]>---
arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 +arch/loongarch/include/asm/setup.h| 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++-6 files changed, 106 insertions(+), 3 deletions(-)arch/loongarch/Kconfig +0
-0@@ -111,6 +111,8 @@ config LOONGARCH
Quoted 5 lines
select
MODULES_USE_ELF_RELAif MODULES
selectNEED_PER_CPU_EMBED_FIRST_CHUNK
selectNEED_PER_CPU_PAGE_FIRST_CHUNK
+ select OF
+ selectOF_EARLY_FLATTREE
I don't like unconditionally enabling OF or OF_EARLY_FLATTREE because they are not needed for Loongson-3 workstations or servers. And you are already fusing the code with #ifdef CONFIG_OF_EARLY_FLATTREE anyway:
/* snip */
arch/loongarch/kernel/setup.c
Quoted 4 lines
arch/loongarch/kernel/setup.c +0
-0
/* snip */
Quoted 3 lines
arch/loongarch/kernel/setup.c +3
-0+static void __init fdt_setup (void ) +{ +#ifdef CONFIG_OF_EARLY_FLATTREE
Signature · 2 lines
Xi Ruoyao <[email protected]> School of Aerospace Science and Technology, Xidian University
Huacai Chen
maintainerHi, Ruoyao,
Quoted 19 lines · Xi Ruoyao
Quoted 17 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
Signed-off-by Binbin Zhou <[email protected]>--- arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 + arch/loongarch/include/asm/setup.h | 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++- 6 files changed, 106 insertions(+), 3 deletions(-)
Quoted 14 lines
arch/loongarch/Kconfig config LOONGARCH · line 115
Quoted 10 lines
arch/loongarch/Kconfig +2
-0@@ -111,6 +111,8 @@ config LOONGARCH select MODULES_USE_ELF_RELA if MODULES select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select OF + select OF_EARLY_FLATTREEI don't like unconditionally enabling OF or
OF_EARLY_FLATTREEbecause they are not needed for Loongson-3 workstations or servers. And you are already fusing the code with #ifdefCONFIG_OF_EARLY_FLATTREEanyway:
I also don't like it. But the kernel test robot will use allyesconfig/allnoconfig/allmodconfig/randconfig to test kernel building. If we don't select OF unconditionally, there will be a ton of build errors. :( And on the other hand, ARM64 & RISCV also selects OF unconditionally.
Huacai
Quoted 18 lines
/* snip */
arch/loongarch/kernel/setup.c
Quoted 4 lines
arch/loongarch/kernel/setup.c +0
-0/* snip */
arch/loongarch/kernel/setup.c static void __init prefill_possible_map(void) · line 465
Quoted 3 lines
arch/loongarch/kernel/setup.c +3
-0+static void __init fdt_setup (void ) +{ +#ifdef CONFIG_OF_EARLY_FLATTREE --
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University
WANG Xuerui
reviewerHi,
Quoted 6 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
CPU models or even indeed ISA subsets/levels have nothing to do with boot protocol support. Theoretically, there's nothing stopping Loongson-2 or even Loongson-1 models from enjoying full UEFI support, even if Loongson the company decides not to do so. I can't imagine any reason for mentioning Loongson-2K aside from company PR which generally doesn't belong in commit messages...
Quoted 16 lines
Signed-off-by Binbin Zhou <[email protected]>--- arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 + arch/loongarch/include/asm/setup.h | 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++- 6 files changed, 106 insertions(+), 3 deletions(-)arch/loongarch/Kconfig +0
-0
arch/loongarch/Kconfig config LOONGARCH · line 115
Quoted 5 lines
arch/loongarch/Kconfig +2
-0@@ -111,6 +111,8 @@ config LOONGARCH select MODULES_USE_ELF_RELA if MODULES select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select OF + select OF_EARLY_FLATTREE
I agree with Ruoyao that maybe this should not be unconditionally enabled.
You may as well allow the user to select the DT options themselves without providing another MACH_xxx config, because the Loongson 2K1000LA and 2K0500 are also capable of at least LA64 baseline, thus still MACH_LOONGSON64.
Quoted 121 lines
arch/loongarch/Kconfig +0
-0select PCI select PCI_DOMAINS_GENERIC select PCI_ECAM if ACPIarch/loongarch/include/asm/efi.h +1
-0@@ -9,6 +9,7 @@void __init efi_init (void );void __init efi_runtime_init (void ); +void __init *efi_fdt_pointer (void );void efifb_setup_from_dmi (struct screen_info *si,const char *opt);#define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004/* Bit 2: CSR.CRMD.IE */ arch/loongarch/include/asm/setup.h +1
-0@@ -13,6 +13,7 @@extern unsigned long eentry;extern unsigned long tlbrentry; +extern char original_cmdline[COMMAND_LINE_SIZE ];extern void tlb_init (int cpu);extern void cpu_cache_init (void );extern void cache_error_setup (void );arch/loongarch/kernel/efi.c +26
-1@@ -37,7 +37,7 @@ static efi_config_table_type_t arch_tables[] __initdata = {void __init efi_runtime_init (void ) { -if (!efi_enabled (EFI_BOOT )) +if (!efi_enabled (EFI_BOOT ) || !efi_systab->runtime)return ;if (efi_runtime_disabled ()) {@@ -101,3 +101,28 @@ void __init efi_init(void)early_memunmap (tbl,sizeof (*tbl)); } } + +/* parse the fdt pointer from efi system table */ +void __init *efi_fdt_pointer (void ) +{ +int i; +void *fdt =NULL ; +efi_config_table_t *tables; + +if (!efi_systab) { +pr_err ("Can't find EFI system table.\n" ); +return NULL ; + } + + tables = (efi_config_table_t *) efi_systab->tables; + +for (i =0 ; i < efi_systab->nr_tables; i++) +if (efi_guidcmp (tables[i].guid,DEVICE_TREE_GUID ) ==0 ) { + fdt = (void *)early_memremap_ro ( + (resource_size_t )tables[i].table, +sizeof (efi_config_table_t)); +break ; + } + +return fdt; +}arch/loongarch/kernel/env.c +3
-0@@ -11,6 +11,7 @@#include <asm/early_ioremap.h> #include <asm/bootinfo.h> #include <asm/loongson.h> +#include <asm/setup.h> u64 efi_system_table;struct loongson_system_configuration loongson_sysconf;@@ -27,6 +28,8 @@ void __init init_environ(void)clear_bit (EFI_BOOT , &efi.flags);strscpy (boot_command_line, cmdline,COMMAND_LINE_SIZE ); +/* Save unparsed command line copy for FDT */ +strscpy (original_cmdline, boot_command_line,COMMAND_LINE_SIZE );early_memunmap (cmdline,COMMAND_LINE_SIZE ); efi_system_table = fw_arg2;arch/loongarch/kernel/setup.c +9
-0@@ -29,6 +29,9 @@#include <linux/device.h> #include <linux/dma-map-ops.h> #include <linux/swiotlb.h> +#include <linux/of_fdt.h> +#include <linux/of_address.h> +#include <linux/libfdt.h> #include <asm/addrspace.h> #include <asm/bootinfo.h> @@ -67,6 +70,7 @@ static const char dmi_empty_string[] = " ";* * These are initialized so they are in the .data section */ +char original_cmdline[COMMAND_LINE_SIZE ]__initdata ;static int num_standard_resources;static struct resource *standard_resources;@@ -281,6 +285,47 @@ static void __init check_kernel_sections_mem(void) } } +static void __init bootcmdline_init (char **cmdline_p) +{ +/* +* If CONFIG_CMDLINE_FORCE is enabled then initializing the command line +* is trivial - we simply use the built-in command line unconditionally &
arch/loongarch/kernel/setup.c static void __init check_kernel_sections_mem(void) · line 302
Quoted 10 lines
arch/loongarch/kernel/setup.c +10
-0+* unmodified. +*/ +if (IS_ENABLED (CONFIG_CMDLINE_FORCE )) { +strscpy (boot_command_line,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); +return ; + } + +#ifdef CONFIG_OF_FLATTREE +/* +* This is for CONFIG_CMDLINE_EXTEND or CONFIG_CMDLINE_BOOTLOADER.
Why mention CONFIG_CMDLINE_EXTEND and CONFIG_CMDLINE_BOOTLOADER if you're guarding the block with CONFIG_OF_FLATTREE?
arch/loongarch/kernel/setup.c static void __init check_kernel_sections_mem(void) · line 307
Quoted 5 lines
arch/loongarch/kernel/setup.c +5
-0+* +* If CONFIG_CMDLINE_BOOTLOADER is enabled, we need to determine if the +* system is ACPI-based or FDT-based. +* +* For ACPI-based system: nothing need to do.
nit: "nothing to do".
Quoted 70 lines
arch/loongarch/kernel/setup.c +47
-2+* +* For FDT-based system: the boot_command_line will be overwritten by +* early_init_dt_scan_chosen(), so we need to append original_cmdline(the +* original copy of boot_command_line) to boot_command_line. +* +* As for the built-in command line, if CONFIG_CMDLINE_EXTEND is enabled, +* both ACPI-based and FDT-based system will append the built-in command +* line to the boot_command_line themselves, and no additional processing +* is required here. +*/ +if (initial_boot_params) { +if (boot_command_line[0 ]) +strlcat (boot_command_line," " ,COMMAND_LINE_SIZE ); + +strlcat (boot_command_line, original_cmdline,COMMAND_LINE_SIZE ); + } +#endif + + *cmdline_p = boot_command_line; +} +/* * arch_mem_init - initialize memory management subsystem */ @@ -291,6 +336,8 @@ static void __init arch_mem_init(char **cmdline_p)check_kernel_sections_mem (); +early_init_fdt_scan_reserved_mem (); +/* * In order to reduce the possibility of kernel panic when failed to * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate @@ -413,20 +460,44 @@ static void __init prefill_possible_map(void) }#endif +static void __init fdt_setup (void ) +{ +#ifdef CONFIG_OF_EARLY_FLATTREE +void *fdt_pointer; + +/* ACPI-based systems do not require parsing fdt */ +if (acpi_os_get_root_pointer ()) +return ; + +/* Look for a device tree configuration table entry */ + fdt_pointer =efi_fdt_pointer (); +if (!fdt_pointer ||fdt_check_header (fdt_pointer)) +return ; + +early_init_dt_scan (fdt_pointer); +early_init_fdt_reserve_self (); +early_init_dt_scan_chosen_stdout (); + + max_low_pfn =PFN_PHYS (memblock_end_of_DRAM ()); +#endif +} +void __init setup_arch (char **cmdline_p) {cpu_probe (); - *cmdline_p = boot_command_line; +pagetable_init ();init_environ ();efi_init (); +fdt_setup ();memblock_init (); -pagetable_init ();
arch/loongarch/kernel/setup.c static void __init prefill_possible_map(void) · line 503
Quoted 10 lines
arch/loongarch/kernel/setup.c +2
-0+bootcmdline_init (cmdline_p);parse_early_param ();reserve_initrd_mem ();platform_init ();arch_mem_init (cmdline_p); +unflatten_and_copy_device_tree ();resource_init ();#ifdef CONFIG_SMP
I haven't reviewed as throughly as I'd like to though, and this is in part because I can't test the changes at all without an open-source LoongArch DT firmware available for QEMU. (Hint hint)
And, although we're already aware of the part-UEFI and part-FDT usage pattern, and the arch UEFI code already has consideration for such, it still makes me a bit wary because you risk losing standards compliance and creating maintenance burden for admins/users/devs alike by relying on this not-really-UEFI-but-advertising-as-such thing. I'd still suggest you try throwing together something fully DT, to at least experiment a little with. You already have to rewrite pretty much everything with all the boot protocol changes in the past few months, so this would probably not even hurt, and the burden on the LoongArch/generic UEFI infra could be lessened even further if this plays out. And you can always continue working on this change if it turns out infeasible to do so.
Signature · 3 lines
WANG "xen0n" Xuerui Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
Quoted 11 lines · WANG Xuerui
And, although we're already aware of the part-UEFI and part-FDT usage pattern, and the arch UEFI code already has consideration for such, it still makes me a bit wary because you risk losing standards compliance and creating maintenance burden for admins/users/devs alike by relying on this not-really-UEFI-but-advertising-as-such thing. I'd still suggest you try throwing together something fully DT, to at least experiment a little with. You already have to rewrite pretty much everything with all the boot protocol changes in the past few months, so this would probably not even hurt, and the burden on the LoongArch/generic UEFI infra could be lessened even further if this plays out. And you can always continue working on this change if it turns out infeasible to do so.
AFAIK using UEFI with FDT (instead of ACPI) is fully allowed and documented by the standard (section 4.6.1.3 of the UEFI spec). It may be not possible or not worthy to implement ACPI for 2K systems, then FDT will be the only choice.
In ARM64 ecosystem, SBBR (for server) demands UEFI+ACPI, EBBR (for embedded) allows UEFI+ACPI or UEFI+FDT.
Signature · 2 lines
Xi Ruoyao <[email protected]> School of Aerospace Science and Technology, Xidian University
Hi Ruoyao:
Quoted 13 lines · Xi Ruoyao
Quoted 11 lines · WANG Xuerui
And, although we're already aware of the part-UEFI and part-FDT usage pattern, and the arch UEFI code already has consideration for such, it still makes me a bit wary because you risk losing standards compliance and creating maintenance burden for admins/users/devs alike by relying on this not-really-UEFI-but-advertising-as-such thing. I'd still suggest you try throwing together something fully DT, to at least experiment a little with. You already have to rewrite pretty much everything with all the boot protocol changes in the past few months, so this would probably not even hurt, and the burden on the LoongArch/generic UEFI infra could be lessened even further if this plays out. And you can always continue working on this change if it turns out infeasible to do so.
Quoted 8 lines
AFAIK using UEFI with FDT (instead of ACPI) is fully allowed and documented by the standard (section 4.6.1.3 of the UEFI spec). It may be not possible or not worthy to implement ACPI for 2K systems, then FDT will be the only choice.
In ARM64 ecosystem, SBBR (for server) demands UEFI+ACPI, EBBR (for embedded) allows UEFI+ACPI or UEFI+FDT.
Yes, I agree with you.
Theoretically, we have four combinations: EFI+ACPI, EFI+FDT, non-EFI+ACPI,non-EFI+FDT.
Now, for LoongArch, EFI+ACPI has been used on Loongson-3, and Loongson-2K being an embedded product, EFI+FDT is a more suitable way. They are both relatively independent. So I don't see this as a violation of standards compliance, nor does it add to the maintenance burden.
Binbin
WANG Xuerui
reviewerQuoted 23 lines · Binbin Zhou
Hi Ruoyao:
Quoted 20 lines · Xi Ruoyao
Quoted 11 lines · WANG Xuerui
And, although we're already aware of the part-UEFI and part-FDT usage pattern, and the arch UEFI code already has consideration for such, it still makes me a bit wary because you risk losing standards compliance and creating maintenance burden for admins/users/devs alike by relying on this not-really-UEFI-but-advertising-as-such thing. I'd still suggest you try throwing together something fully DT, to at least experiment a little with. You already have to rewrite pretty much everything with all the boot protocol changes in the past few months, so this would probably not even hurt, and the burden on the LoongArch/generic UEFI infra could be lessened even further if this plays out. And you can always continue working on this change if it turns out infeasible to do so.
AFAIK using UEFI with FDT (instead of ACPI) is fully allowed and documented by the standard (section 4.6.1.3 of the UEFI spec). It may be not possible or not worthy to implement ACPI for 2K systems, then FDT will be the only choice.
In ARM64 ecosystem, SBBR (for server) demands UEFI+ACPI, EBBR (for embedded) allows UEFI+ACPI or UEFI+FDT.
Ah I see. My bad for not reading the spec in enough detail...
Quoted 7 lines
Quoted 1 line
Yes, I agree with you.
Theoretically, we have four combinations: EFI+ACPI, EFI+FDT, non-EFI+ACPI,non-EFI+FDT.
Now, for LoongArch, EFI+ACPI has been used on Loongson-3, and Loongson-2K being an embedded product, EFI+FDT is a more suitable way. They are both relatively independent. So I don't see this as a violation of standards compliance, nor does it add to the maintenance burden.
Yeah I now see the reason why it's acceptable. Then, I'm only suggesting you to try formulating the changes and commit message, in a way that doesn't leave people with the false impression that Loongson-3 is somehow strongly bound with EFI+ACPI and Loongson-2 with EFI+FDT, despite the typical capabilities of such systems.
Signature · 3 lines
WANG "xen0n" Xuerui Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
Ard Biesheuvel
maintainerQuoted 60 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
Signed-off-by Binbin Zhou <[email protected]>--- arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 + arch/loongarch/include/asm/setup.h | 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++- 6 files changed, 106 insertions(+), 3 deletions(-)arch/loongarch/Kconfig +2
-0@@ -111,6 +111,8 @@ config LOONGARCH select MODULES_USE_ELF_RELA if MODULES select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select OF + select OF_EARLY_FLATTREE select PCI select PCI_DOMAINS_GENERIC select PCI_ECAM if ACPIarch/loongarch/include/asm/efi.h +1
-0@@ -9,6 +9,7 @@void __init efi_init (void );void __init efi_runtime_init (void ); +void __init *efi_fdt_pointer (void );void efifb_setup_from_dmi (struct screen_info *si,const char *opt);#define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004/* Bit 2: CSR.CRMD.IE */ arch/loongarch/include/asm/setup.h +1
-0@@ -13,6 +13,7 @@extern unsigned long eentry;extern unsigned long tlbrentry; +extern char original_cmdline[COMMAND_LINE_SIZE ];extern void tlb_init (int cpu);extern void cpu_cache_init (void );extern void cache_error_setup (void );arch/loongarch/kernel/efi.c +0
-0
arch/loongarch/kernel/efi.c static efi_config_table_type_t arch_tables[] __initdata = { · line 40
Quoted 5 lines
arch/loongarch/kernel/efi.c +1
-1@@ -37,7 +37,7 @@ static efi_config_table_type_t arch_tables[] __initdata = {void __init efi_runtime_init (void ) { -if (!efi_enabled (EFI_BOOT )) +if (!efi_enabled (EFI_BOOT ) || !efi_systab->runtime)
How can this happen? Why would we ever set EFI_BOOT if efi_systab->runtime == NULL?
Quoted 22 lines
arch/loongarch/kernel/efi.c +15
-0return ;if (efi_runtime_disabled ()) {@@ -101,3 +101,28 @@ void __init efi_init(void)early_memunmap (tbl,sizeof (*tbl)); } } + +/* parse the fdt pointer from efi system table */ +void __init *efi_fdt_pointer (void ) +{ +int i; +void *fdt =NULL ; +efi_config_table_t *tables; + +if (!efi_systab) { +pr_err ("Can't find EFI system table.\n" ); +return NULL ; + } + + tables = (efi_config_table_t *) efi_systab->tables; +
arch/loongarch/kernel/efi.c void __init efi_init(void) · line 128
Quoted 10 lines
arch/loongarch/kernel/efi.c +10
-0+for (i =0 ; i < efi_systab->nr_tables; i++) +if (efi_guidcmp (tables[i].guid,DEVICE_TREE_GUID ) ==0 ) { + fdt = (void *)early_memremap_ro ( + (resource_size_t )tables[i].table, +sizeof (efi_config_table_t)); +break ; + } + +return fdt; +}
Please use the existing config table discovery mechanism for this.
Quoted 13 lines
arch/loongarch/kernel/env.c +1
-0@@ -11,6 +11,7 @@#include <asm/early_ioremap.h> #include <asm/bootinfo.h> #include <asm/loongson.h> +#include <asm/setup.h> u64 efi_system_table;struct loongson_system_configuration loongson_sysconf;
arch/loongarch/kernel/env.c void __init init_environ(void) · line 31
Quoted 4 lines
arch/loongarch/kernel/env.c +1
-0@@ -27,6 +28,8 @@ void __init init_environ(void)clear_bit (EFI_BOOT , &efi.flags);strscpy (boot_command_line, cmdline,COMMAND_LINE_SIZE ); +/* Save unparsed command line copy for FDT */
Why is this necessary?
Quoted 95 lines
arch/loongarch/kernel/env.c +1
-0+strscpy (original_cmdline, boot_command_line,COMMAND_LINE_SIZE );early_memunmap (cmdline,COMMAND_LINE_SIZE ); efi_system_table = fw_arg2;arch/loongarch/kernel/setup.c +55
-0@@ -29,6 +29,9 @@#include <linux/device.h> #include <linux/dma-map-ops.h> #include <linux/swiotlb.h> +#include <linux/of_fdt.h> +#include <linux/of_address.h> +#include <linux/libfdt.h> #include <asm/addrspace.h> #include <asm/bootinfo.h> @@ -67,6 +70,7 @@ static const char dmi_empty_string[] = " ";* * These are initialized so they are in the .data section */ +char original_cmdline[COMMAND_LINE_SIZE ]__initdata ;static int num_standard_resources;static struct resource *standard_resources;@@ -281,6 +285,47 @@ static void __init check_kernel_sections_mem(void) } } +static void __init bootcmdline_init (char **cmdline_p) +{ +/* +* If CONFIG_CMDLINE_FORCE is enabled then initializing the command line +* is trivial - we simply use the built-in command line unconditionally & +* unmodified. +*/ +if (IS_ENABLED (CONFIG_CMDLINE_FORCE )) { +strscpy (boot_command_line,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); +return ; + } + +#ifdef CONFIG_OF_FLATTREE +/* +* This is for CONFIG_CMDLINE_EXTEND or CONFIG_CMDLINE_BOOTLOADER. +* +* If CONFIG_CMDLINE_BOOTLOADER is enabled, we need to determine if the +* system is ACPI-based or FDT-based. +* +* For ACPI-based system: nothing need to do. +* +* For FDT-based system: the boot_command_line will be overwritten by +* early_init_dt_scan_chosen(), so we need to append original_cmdline(the +* original copy of boot_command_line) to boot_command_line. +* +* As for the built-in command line, if CONFIG_CMDLINE_EXTEND is enabled, +* both ACPI-based and FDT-based system will append the built-in command +* line to the boot_command_line themselves, and no additional processing +* is required here. +*/ +if (initial_boot_params) { +if (boot_command_line[0 ]) +strlcat (boot_command_line," " ,COMMAND_LINE_SIZE ); + +strlcat (boot_command_line, original_cmdline,COMMAND_LINE_SIZE ); + } +#endif + + *cmdline_p = boot_command_line; +} +/* * arch_mem_init - initialize memory management subsystem */ @@ -291,6 +336,8 @@ static void __init arch_mem_init(char **cmdline_p)check_kernel_sections_mem (); +early_init_fdt_scan_reserved_mem (); +/* * In order to reduce the possibility of kernel panic when failed to * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate @@ -413,20 +460,44 @@ static void __init prefill_possible_map(void) }#endif +static void __init fdt_setup (void ) +{ +#ifdef CONFIG_OF_EARLY_FLATTREE +void *fdt_pointer; + +/* ACPI-based systems do not require parsing fdt */ +if (acpi_os_get_root_pointer ()) +return ;
arch/loongarch/kernel/setup.c static void __init prefill_possible_map(void) · line 480
Quoted 10 lines
arch/loongarch/kernel/setup.c +10
-0+ +/* Look for a device tree configuration table entry */ + fdt_pointer =efi_fdt_pointer (); +if (!fdt_pointer ||fdt_check_header (fdt_pointer)) +return ; + +early_init_dt_scan (fdt_pointer); +early_init_fdt_reserve_self (); +early_init_dt_scan_chosen_stdout (); +
The FDT is only a hardware description, right? So why are we scanning /chosen here?
Quoted 28 lines
arch/loongarch/kernel/setup.c +8
-3+ max_low_pfn =PFN_PHYS (memblock_end_of_DRAM ()); +#endif +} +void __init setup_arch (char **cmdline_p) {cpu_probe (); - *cmdline_p = boot_command_line; +pagetable_init ();init_environ ();efi_init (); +fdt_setup ();memblock_init (); -pagetable_init (); +bootcmdline_init (cmdline_p);parse_early_param ();reserve_initrd_mem ();platform_init ();arch_mem_init (cmdline_p); +unflatten_and_copy_device_tree ();resource_init ();#ifdef CONFIG_SMP --2.31.1
Quoted 62 lines · Ard Biesheuvel
Quoted 61 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
Signed-off-by Binbin Zhou <[email protected]>--- arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 + arch/loongarch/include/asm/setup.h | 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++- 6 files changed, 106 insertions(+), 3 deletions(-)arch/loongarch/Kconfig +2
-0@@ -111,6 +111,8 @@ config LOONGARCH select MODULES_USE_ELF_RELA if MODULES select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select OF + select OF_EARLY_FLATTREE select PCI select PCI_DOMAINS_GENERIC select PCI_ECAM if ACPIarch/loongarch/include/asm/efi.h +1
-0@@ -9,6 +9,7 @@void __init efi_init (void );void __init efi_runtime_init (void ); +void __init *efi_fdt_pointer (void );void efifb_setup_from_dmi (struct screen_info *si,const char *opt);#define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004/* Bit 2: CSR.CRMD.IE */ arch/loongarch/include/asm/setup.h +1
-0@@ -13,6 +13,7 @@extern unsigned long eentry;extern unsigned long tlbrentry; +extern char original_cmdline[COMMAND_LINE_SIZE ];extern void tlb_init (int cpu);extern void cpu_cache_init (void );extern void cache_error_setup (void );arch/loongarch/kernel/efi.c +0
-0@@ -37,7 +37,7 @@ static efi_config_table_type_t arch_tables[] __initdata = {
Quoted 8 lines
arch/loongarch/kernel/efi.c static efi_config_table_type_t arch_tables[] __initdata = { · line 40
Quoted 4 lines
arch/loongarch/kernel/efi.c +1
-1void __init efi_runtime_init (void ) { -if (!efi_enabled (EFI_BOOT )) +if (!efi_enabled (EFI_BOOT ) || !efi_systab->runtime)How can this happen? Why would we ever set
EFI_BOOTifefi_systab->runtime== NULL?
Because some firmware (such as PMON) employed UEFI compatible implementaion without runtime (and set runtime null pointer).
Maybe *noefi* in command line is enough for this without CONFIG_CMDLINE_FORCE simillar stuff configured?
Quoted 192 lines
Quoted 22 lines
arch/loongarch/kernel/efi.c +15
-0return ;if (efi_runtime_disabled ()) {@@ -101,3 +101,28 @@ void __init efi_init(void)early_memunmap (tbl,sizeof (*tbl)); } } + +/* parse the fdt pointer from efi system table */ +void __init *efi_fdt_pointer (void ) +{ +int i; +void *fdt =NULL ; +efi_config_table_t *tables; + +if (!efi_systab) { +pr_err ("Can't find EFI system table.\n" ); +return NULL ; + } + + tables = (efi_config_table_t *) efi_systab->tables; +arch/loongarch/kernel/efi.c void __init efi_init(void) · line 128
Quoted 10 lines
arch/loongarch/kernel/efi.c +10
-0+for (i =0 ; i < efi_systab->nr_tables; i++) +if (efi_guidcmp (tables[i].guid,DEVICE_TREE_GUID ) ==0 ) { + fdt = (void *)early_memremap_ro ( + (resource_size_t )tables[i].table, +sizeof (efi_config_table_t)); +break ; + } + +return fdt; +}Please use the existing config table discovery mechanism for this.
Quoted 13 lines
arch/loongarch/kernel/env.c +1
-0@@ -11,6 +11,7 @@#include <asm/early_ioremap.h> #include <asm/bootinfo.h> #include <asm/loongson.h> +#include <asm/setup.h> u64 efi_system_table;struct loongson_system_configuration loongson_sysconf;arch/loongarch/kernel/env.c void __init init_environ(void) · line 31
Quoted 4 lines
arch/loongarch/kernel/env.c +1
-0@@ -27,6 +28,8 @@ void __init init_environ(void)clear_bit (EFI_BOOT , &efi.flags);strscpy (boot_command_line, cmdline,COMMAND_LINE_SIZE ); +/* Save unparsed command line copy for FDT */ Why is this necessary?
Quoted 95 lines
arch/loongarch/kernel/env.c +1
-0+strscpy (original_cmdline, boot_command_line,COMMAND_LINE_SIZE );early_memunmap (cmdline,COMMAND_LINE_SIZE ); efi_system_table = fw_arg2;arch/loongarch/kernel/setup.c +55
-0@@ -29,6 +29,9 @@#include <linux/device.h> #include <linux/dma-map-ops.h> #include <linux/swiotlb.h> +#include <linux/of_fdt.h> +#include <linux/of_address.h> +#include <linux/libfdt.h> #include <asm/addrspace.h> #include <asm/bootinfo.h> @@ -67,6 +70,7 @@ static const char dmi_empty_string[] = " ";* * These are initialized so they are in the .data section */ +char original_cmdline[COMMAND_LINE_SIZE ]__initdata ;static int num_standard_resources;static struct resource *standard_resources;@@ -281,6 +285,47 @@ static void __init check_kernel_sections_mem(void) } } +static void __init bootcmdline_init (char **cmdline_p) +{ +/* +* If CONFIG_CMDLINE_FORCE is enabled then initializing the command line +* is trivial - we simply use the built-in command line unconditionally & +* unmodified. +*/ +if (IS_ENABLED (CONFIG_CMDLINE_FORCE )) { +strscpy (boot_command_line,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); +return ; + } + +#ifdef CONFIG_OF_FLATTREE +/* +* This is for CONFIG_CMDLINE_EXTEND or CONFIG_CMDLINE_BOOTLOADER. +* +* If CONFIG_CMDLINE_BOOTLOADER is enabled, we need to determine if the +* system is ACPI-based or FDT-based. +* +* For ACPI-based system: nothing need to do. +* +* For FDT-based system: the boot_command_line will be overwritten by +* early_init_dt_scan_chosen(), so we need to append original_cmdline(the +* original copy of boot_command_line) to boot_command_line. +* +* As for the built-in command line, if CONFIG_CMDLINE_EXTEND is enabled, +* both ACPI-based and FDT-based system will append the built-in command +* line to the boot_command_line themselves, and no additional processing +* is required here. +*/ +if (initial_boot_params) { +if (boot_command_line[0 ]) +strlcat (boot_command_line," " ,COMMAND_LINE_SIZE ); + +strlcat (boot_command_line, original_cmdline,COMMAND_LINE_SIZE ); + } +#endif + + *cmdline_p = boot_command_line; +} +/* * arch_mem_init - initialize memory management subsystem */ @@ -291,6 +336,8 @@ static void __init arch_mem_init(char **cmdline_p)check_kernel_sections_mem (); +early_init_fdt_scan_reserved_mem (); +/* * In order to reduce the possibility of kernel panic when failed to * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate @@ -413,20 +460,44 @@ static void __init prefill_possible_map(void) }#endif +static void __init fdt_setup (void ) +{ +#ifdef CONFIG_OF_EARLY_FLATTREE +void *fdt_pointer; + +/* ACPI-based systems do not require parsing fdt */ +if (acpi_os_get_root_pointer ()) +return ;arch/loongarch/kernel/setup.c static void __init prefill_possible_map(void) · line 480
Quoted 10 lines
arch/loongarch/kernel/setup.c +10
-0+ +/* Look for a device tree configuration table entry */ + fdt_pointer =efi_fdt_pointer (); +if (!fdt_pointer ||fdt_check_header (fdt_pointer)) +return ; + +early_init_dt_scan (fdt_pointer); +early_init_fdt_reserve_self (); +early_init_dt_scan_chosen_stdout (); +The FDT is only a hardware description, right? So why are we scanning /chosen here?
Quoted 28 lines
arch/loongarch/kernel/setup.c +8
-3+ max_low_pfn =PFN_PHYS (memblock_end_of_DRAM ()); +#endif +} +void __init setup_arch (char **cmdline_p) {cpu_probe (); - *cmdline_p = boot_command_line; +pagetable_init ();init_environ ();efi_init (); +fdt_setup ();memblock_init (); -pagetable_init (); +bootcmdline_init (cmdline_p);parse_early_param ();reserve_initrd_mem ();platform_init ();arch_mem_init (cmdline_p); +unflatten_and_copy_device_tree ();resource_init ();#ifdef CONFIG_SMP --2.31.1
WANG Xuerui
reviewerQuoted 75 lines · Jianmin Lv
Quoted 63 lines · Ard Biesheuvel
Quoted 62 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
Signed-off-by Binbin Zhou <[email protected]>---
arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 +arch/loongarch/include/asm/setup.h| 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++-6 files changed, 106 insertions(+), 3 deletions(-)arch/loongarch/Kconfig +0
-0@@ -111,6 +111,8 @@ config LOONGARCHselect
MODULES_USE_ELF_RELAif MODULES
selectNEED_PER_CPU_EMBED_FIRST_CHUNK
selectNEED_PER_CPU_PAGE_FIRST_CHUNK
+ select OF
+ selectOF_EARLY_FLATTREE
select PCI
selectPCI_DOMAINS_GENERIC
selectPCI_ECAMif ACPIarch/loongarch/include/asm/efi.h +1
-0@@ -9,6 +9,7 @@ void __init efi_init(void); void __init efi_runtime_init(void); +void __init *efi_fdt_pointer (void ); void efifb_setup_from_dmi(struct screen_info *si, const char *opt); #define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004 /* Bit 2: CSR.CRMD.IE */arch/loongarch/include/asm/setup.h +1
-0@@ -13,6 +13,7 @@ extern unsigned long eentry; extern unsigned long tlbrentry; +extern char original_cmdline[COMMAND_LINE_SIZE ]; extern void tlb_init(int cpu); extern void cpu_cache_init(void); extern void cache_error_setup(void);arch/loongarch/kernel/efi.c +0
-0@@ -37,7 +37,7 @@ static efi_config_table_type_t arch_tables[] __initdata = {Quoted 8 lines
arch/loongarch/kernel/efi.c static efi_config_table_type_t arch_tables[] __initdata = { · line 40
Quoted 4 lines
arch/loongarch/kernel/efi.c +1
-1void __init efi_runtime_init(void) { - if (!efi_enabled(EFI_BOOT)) + if (!efi_enabled(EFI_BOOT) || !efi_systab->runtime)How can this happen? Why would we ever set
EFI_BOOTifefi_systab->runtime== NULL?
Quoted 1 line
Because some firmware (such as PMON) employed UEFI compatible implementaion without runtime (and set runtime null pointer).
Hmm, is it really "UEFI-compatible" when it's without a UEFI runtime? Anyway it's becoming increasingly difficult for community reviewers to check things without corresponding firmware sources available... (and I think, given the Loongson fork of PMON even back in the MIPS era is effectively GPL'd [1], the LoongArch port of PMON could probably be GPL as well, in which case it's totally fair for us to request the sources.)
(I know the similar usage pattern i.e. making use of various UEFI features but without a runtime was already widespread back in the MIPS days of Loongson, but personally I don't think it's enough to justify doing the same when it's 2022 and we're fully upstream.)
[1]: https://github.com/loongson-community/pmon/blob/master/LICENSE.md
Quoted 1 line
Maybe *noefi* in command line is enough for this without
CONFIG_CMDLINE_FORCEsimillar stuff configured?
I think having/forcing users to add "noefi" themselves wouldn't be good ergonomics? Manipulating the cmdline in the firmware could be more acceptable but I'm not sure.
Signature · 3 lines
WANG "xen0n" Xuerui Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
Quoted 77 lines · WANG Xuerui
Quoted 76 lines · Jianmin Lv
Quoted 72 lines · Ard Biesheuvel
Quoted 61 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
Signed-off-by Binbin Zhou <[email protected]>---
arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 +arch/loongarch/include/asm/setup.h| 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75
+++++++++++++++++++++++++++++-6 files changed, 106 insertions(+), 3 deletions(-)arch/loongarch/Kconfig +0
-0@@ -111,6 +111,8 @@ config LOONGARCHselect
MODULES_USE_ELF_RELAif MODULES
selectNEED_PER_CPU_EMBED_FIRST_CHUNK
selectNEED_PER_CPU_PAGE_FIRST_CHUNK
+ select OF
+ selectOF_EARLY_FLATTREE
select PCI
selectPCI_DOMAINS_GENERIC
selectPCI_ECAMif ACPIarch/loongarch/include/asm/efi.h +1
-0@@ -9,6 +9,7 @@ void __init efi_init(void); void __init efi_runtime_init(void); +void __init *efi_fdt_pointer (void ); void efifb_setup_from_dmi(struct screen_info *si, const char *opt); #define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004 /* Bit 2: CSR.CRMD.IE */arch/loongarch/include/asm/setup.h +1
-0@@ -13,6 +13,7 @@ extern unsigned long eentry; extern unsigned long tlbrentry; +extern char original_cmdline[COMMAND_LINE_SIZE ]; extern void tlb_init(int cpu); extern void cpu_cache_init(void); extern void cache_error_setup(void);arch/loongarch/kernel/efi.c +0
-0arch/loongarch/kernel/efi.c static efi_config_table_type_t arch_tables[] · line 41
Quoted 6 lines
arch/loongarch/kernel/efi.c +1
-1@@ -37,7 +37,7 @@ static efi_config_table_type_t arch_tables[] __initdata = { void __init efi_runtime_init(void) { - if (!efi_enabled(EFI_BOOT)) + if (!efi_enabled(EFI_BOOT) || !efi_systab->runtime)How can this happen? Why would we ever set
EFI_BOOTifefi_systab->runtime== NULL?
Quoted 3 lines
Quoted 1 line
Because some firmware (such as PMON) employed UEFI compatible implementaion without runtime (and set runtime null pointer).
Hmm, is it really "UEFI-compatible" when it's without a UEFI runtime?
To be frank, it seems that runtime should be always valid in UEFI complaint firmware (according to UEFI spec section 4.5, 8). Unfortunately, some machines shipped with *partially-compatible" (without runtime) firmware have been outside (maybe not many, I'm not sure). So, thinking about compatibility with them, the case have to be taken account, unless rather.
Quoted 10 lines
Anyway it's becoming increasingly difficult for community reviewers to check things without corresponding firmware sources available... (and I think, given the Loongson fork of PMON even back in the MIPS era is effectively GPL'd [1], the LoongArch port of PMON could probably be GPL as well, in which case it's totally fair for us to request the sources.)
(I know the similar usage pattern i.e. making use of various UEFI features but without a runtime was already widespread back in the MIPS days of Loongson, but personally I don't think it's enough to justify doing the same when it's 2022 and we're fully upstream.)
[1]: https://github.com/loongson-community/pmon/blob/master/LICENSE.md
Quoted 1 line
Maybe *noefi* in command line is enough for this without
CONFIG_CMDLINE_FORCEsimillar stuff configured?I think having/forcing users to add "noefi" themselves wouldn't be good ergonomics? Manipulating the cmdline in the firmware could be more acceptable but I'm not sure.
I think so, adding it in firmware internally (if using "noefi") maybe acceptable rather than adding it by users.
Huacai Chen
maintainerHi, Ard,
Quoted 111 lines · Jianmin Lv
Quoted 79 lines · WANG Xuerui
Quoted 78 lines · Jianmin Lv
Quoted 74 lines · Ard Biesheuvel
Quoted 63 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
Signed-off-by Binbin Zhou <[email protected]>--- arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 + arch/loongarch/include/asm/setup.h | 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++- 6 files changed, 106 insertions(+), 3 deletions(-)arch/loongarch/Kconfig +2
-0@@ -111,6 +111,8 @@ config LOONGARCH select MODULES_USE_ELF_RELA if MODULES select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select OF + select OF_EARLY_FLATTREE select PCI select PCI_DOMAINS_GENERIC select PCI_ECAM if ACPIarch/loongarch/include/asm/efi.h +1
-0@@ -9,6 +9,7 @@void __init efi_init (void );void __init efi_runtime_init (void ); +void __init *efi_fdt_pointer (void );void efifb_setup_from_dmi (struct screen_info *si,const char *opt);#define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004/* Bit 2: CSR.CRMD.IE */ arch/loongarch/include/asm/setup.h +1
-0@@ -13,6 +13,7 @@extern unsigned long eentry;extern unsigned long tlbrentry; +extern char original_cmdline[COMMAND_LINE_SIZE ];extern void tlb_init (int cpu);extern void cpu_cache_init (void );extern void cache_error_setup (void );arch/loongarch/kernel/efi.c +0
-0arch/loongarch/kernel/efi.c static efi_config_table_type_t arch_tables[] · line 41
Quoted 6 lines
arch/loongarch/kernel/efi.c +1
-1@@ -37,7 +37,7 @@ static efi_config_table_type_t arch_tables[] __initdata = {void __init efi_runtime_init (void ) { -if (!efi_enabled (EFI_BOOT )) +if (!efi_enabled (EFI_BOOT ) || !efi_systab->runtime)How can this happen? Why would we ever set
EFI_BOOTifefi_systab->runtime== NULL?Quoted 4 lines
Quoted 2 lines
Because some firmware (such as PMON) employed UEFI compatible implementaion without runtime (and set runtime null pointer).
Hmm, is it really "UEFI-compatible" when it's without a UEFI runtime?
To be frank, it seems that runtime should be always valid in UEFI complaint firmware (according to UEFI spec section 4.5, 8). Unfortunately, some machines shipped with *partially-compatible" (without runtime) firmware have been outside (maybe not many, I'm not sure). So, thinking about compatibility with them, the case have to be taken account, unless rather.
Quoted 16 lines
Anyway it's becoming increasingly difficult for community reviewers to check things without corresponding firmware sources available... (and I think, given the Loongson fork of PMON even back in the MIPS era is effectively GPL'd [1], the LoongArch port of PMON could probably be GPL as well, in which case it's totally fair for us to request the sources.)
(I know the similar usage pattern i.e. making use of various UEFI features but without a runtime was already widespread back in the MIPS days of Loongson, but personally I don't think it's enough to justify doing the same when it's 2022 and we're fully upstream.)
[1]: https://github.com/loongson-community/pmon/blob/master/LICENSE.md
Quoted 2 lines
Maybe *noefi* in command line is enough for this without
CONFIG_CMDLINE_FORCEsimillar stuff configured?
Quoted 7 lines
Quoted 4 lines
I think having/forcing users to add "noefi" themselves wouldn't be good ergonomics? Manipulating the cmdline in the firmware could be more acceptable but I'm not sure.
I think so, adding it in firmware internally (if using "noefi") maybe acceptable rather than adding it by users.
With Jianmin's explanation, do you think it is acceptable for PMON-like firmware (emulates a systemtable but doesn't provide runtime) to set efi boot flag to 1? Or the flag should be 0 unless firmware is fully efi-compatible (has systemtable and runtime service is available)?
Huacai
Quoted 1 line
Huacai Chen
maintainerHi, Ard,
Quoted 226 lines · Ard Biesheuvel
Quoted 60 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
Signed-off-by Binbin Zhou <[email protected]>--- arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 + arch/loongarch/include/asm/setup.h | 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++- 6 files changed, 106 insertions(+), 3 deletions(-)arch/loongarch/Kconfig +2
-0@@ -111,6 +111,8 @@ config LOONGARCH select MODULES_USE_ELF_RELA if MODULES select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select OF + select OF_EARLY_FLATTREE select PCI select PCI_DOMAINS_GENERIC select PCI_ECAM if ACPIarch/loongarch/include/asm/efi.h +1
-0@@ -9,6 +9,7 @@void __init efi_init (void );void __init efi_runtime_init (void ); +void __init *efi_fdt_pointer (void );void efifb_setup_from_dmi (struct screen_info *si,const char *opt);#define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004/* Bit 2: CSR.CRMD.IE */ arch/loongarch/include/asm/setup.h +1
-0@@ -13,6 +13,7 @@extern unsigned long eentry;extern unsigned long tlbrentry; +extern char original_cmdline[COMMAND_LINE_SIZE ];extern void tlb_init (int cpu);extern void cpu_cache_init (void );extern void cache_error_setup (void );arch/loongarch/kernel/efi.c +0
-0arch/loongarch/kernel/efi.c static efi_config_table_type_t arch_tables[] __initdata = { · line 40
Quoted 5 lines
arch/loongarch/kernel/efi.c +1
-1@@ -37,7 +37,7 @@ static efi_config_table_type_t arch_tables[] __initdata = {void __init efi_runtime_init (void ) { -if (!efi_enabled (EFI_BOOT )) +if (!efi_enabled (EFI_BOOT ) || !efi_systab->runtime)How can this happen? Why would we ever set
EFI_BOOTifefi_systab->runtime== NULL?Quoted 22 lines
arch/loongarch/kernel/efi.c +15
-0return ;if (efi_runtime_disabled ()) {@@ -101,3 +101,28 @@ void __init efi_init(void)early_memunmap (tbl,sizeof (*tbl)); } } + +/* parse the fdt pointer from efi system table */ +void __init *efi_fdt_pointer (void ) +{ +int i; +void *fdt =NULL ; +efi_config_table_t *tables; + +if (!efi_systab) { +pr_err ("Can't find EFI system table.\n" ); +return NULL ; + } + + tables = (efi_config_table_t *) efi_systab->tables; +arch/loongarch/kernel/efi.c void __init efi_init(void) · line 128
Quoted 10 lines
arch/loongarch/kernel/efi.c +10
-0+for (i =0 ; i < efi_systab->nr_tables; i++) +if (efi_guidcmp (tables[i].guid,DEVICE_TREE_GUID ) ==0 ) { + fdt = (void *)early_memremap_ro ( + (resource_size_t )tables[i].table, +sizeof (efi_config_table_t)); +break ; + } + +return fdt; +}Please use the existing config table discovery mechanism for this.
Quoted 13 lines
arch/loongarch/kernel/env.c +1
-0@@ -11,6 +11,7 @@#include <asm/early_ioremap.h> #include <asm/bootinfo.h> #include <asm/loongson.h> +#include <asm/setup.h> u64 efi_system_table;struct loongson_system_configuration loongson_sysconf;arch/loongarch/kernel/env.c void __init init_environ(void) · line 31
Quoted 4 lines
arch/loongarch/kernel/env.c +1
-0@@ -27,6 +28,8 @@ void __init init_environ(void)clear_bit (EFI_BOOT , &efi.flags);strscpy (boot_command_line, cmdline,COMMAND_LINE_SIZE ); +/* Save unparsed command line copy for FDT */ Why is this necessary?
Quoted 100 lines
arch/loongarch/kernel/env.c +1
-0+strscpy (original_cmdline, boot_command_line,COMMAND_LINE_SIZE );early_memunmap (cmdline,COMMAND_LINE_SIZE ); efi_system_table = fw_arg2;arch/loongarch/kernel/setup.c +60
-0@@ -29,6 +29,9 @@#include <linux/device.h> #include <linux/dma-map-ops.h> #include <linux/swiotlb.h> +#include <linux/of_fdt.h> +#include <linux/of_address.h> +#include <linux/libfdt.h> #include <asm/addrspace.h> #include <asm/bootinfo.h> @@ -67,6 +70,7 @@ static const char dmi_empty_string[] = " ";* * These are initialized so they are in the .data section */ +char original_cmdline[COMMAND_LINE_SIZE ]__initdata ;static int num_standard_resources;static struct resource *standard_resources;@@ -281,6 +285,47 @@ static void __init check_kernel_sections_mem(void) } } +static void __init bootcmdline_init (char **cmdline_p) +{ +/* +* If CONFIG_CMDLINE_FORCE is enabled then initializing the command line +* is trivial - we simply use the built-in command line unconditionally & +* unmodified. +*/ +if (IS_ENABLED (CONFIG_CMDLINE_FORCE )) { +strscpy (boot_command_line,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); +return ; + } + +#ifdef CONFIG_OF_FLATTREE +/* +* This is for CONFIG_CMDLINE_EXTEND or CONFIG_CMDLINE_BOOTLOADER. +* +* If CONFIG_CMDLINE_BOOTLOADER is enabled, we need to determine if the +* system is ACPI-based or FDT-based. +* +* For ACPI-based system: nothing need to do. +* +* For FDT-based system: the boot_command_line will be overwritten by +* early_init_dt_scan_chosen(), so we need to append original_cmdline(the +* original copy of boot_command_line) to boot_command_line. +* +* As for the built-in command line, if CONFIG_CMDLINE_EXTEND is enabled, +* both ACPI-based and FDT-based system will append the built-in command +* line to the boot_command_line themselves, and no additional processing +* is required here. +*/ +if (initial_boot_params) { +if (boot_command_line[0 ]) +strlcat (boot_command_line," " ,COMMAND_LINE_SIZE ); + +strlcat (boot_command_line, original_cmdline,COMMAND_LINE_SIZE ); + } +#endif + + *cmdline_p = boot_command_line; +} +/* * arch_mem_init - initialize memory management subsystem */ @@ -291,6 +336,8 @@ static void __init arch_mem_init(char **cmdline_p)check_kernel_sections_mem (); +early_init_fdt_scan_reserved_mem (); +/* * In order to reduce the possibility of kernel panic when failed to * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate @@ -413,20 +460,44 @@ static void __init prefill_possible_map(void) }#endif +static void __init fdt_setup (void ) +{ +#ifdef CONFIG_OF_EARLY_FLATTREE +void *fdt_pointer; + +/* ACPI-based systems do not require parsing fdt */ +if (acpi_os_get_root_pointer ()) +return ; + +/* Look for a device tree configuration table entry */ + fdt_pointer =efi_fdt_pointer (); +if (!fdt_pointer ||fdt_check_header (fdt_pointer)) +return ;
Quoted 8 lines
arch/loongarch/kernel/setup.c static void __init prefill_possible_map(void) · line 480
Quoted 5 lines
arch/loongarch/kernel/setup.c +5
-0+ +early_init_dt_scan (fdt_pointer); +early_init_fdt_reserve_self (); +early_init_dt_scan_chosen_stdout (); +The FDT is only a hardware description, right? So why are we scanning /chosen here?
We scan the chosen node here in order to configure earlycon as early as possible, this is very useful for debugging. ARM64 does similar things in acpi_boot_table_init(), but I think fdt_setup() is more suitable.
Huacai
Quoted 29 lines
Quoted 29 lines
arch/loongarch/kernel/setup.c +8
-3+ max_low_pfn =PFN_PHYS (memblock_end_of_DRAM ()); +#endif +} +void __init setup_arch (char **cmdline_p) {cpu_probe (); - *cmdline_p = boot_command_line; +pagetable_init ();init_environ ();efi_init (); +fdt_setup ();memblock_init (); -pagetable_init (); +bootcmdline_init (cmdline_p);parse_early_param ();reserve_initrd_mem ();platform_init ();arch_mem_init (cmdline_p); +unflatten_and_copy_device_tree ();resource_init ();#ifdef CONFIG_SMP --2.31.1
Ard Biesheuvel
maintainerQuoted 238 lines · Huacai Chen
Hi, Ard,
Quoted 226 lines · Ard Biesheuvel
Quoted 60 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
Signed-off-by Binbin Zhou <[email protected]>--- arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 + arch/loongarch/include/asm/setup.h | 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++- 6 files changed, 106 insertions(+), 3 deletions(-)arch/loongarch/Kconfig +2
-0@@ -111,6 +111,8 @@ config LOONGARCH select MODULES_USE_ELF_RELA if MODULES select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select OF + select OF_EARLY_FLATTREE select PCI select PCI_DOMAINS_GENERIC select PCI_ECAM if ACPIarch/loongarch/include/asm/efi.h +1
-0@@ -9,6 +9,7 @@void __init efi_init (void );void __init efi_runtime_init (void ); +void __init *efi_fdt_pointer (void );void efifb_setup_from_dmi (struct screen_info *si,const char *opt);#define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004/* Bit 2: CSR.CRMD.IE */ arch/loongarch/include/asm/setup.h +1
-0@@ -13,6 +13,7 @@extern unsigned long eentry;extern unsigned long tlbrentry; +extern char original_cmdline[COMMAND_LINE_SIZE ];extern void tlb_init (int cpu);extern void cpu_cache_init (void );extern void cache_error_setup (void );arch/loongarch/kernel/efi.c +0
-0arch/loongarch/kernel/efi.c static efi_config_table_type_t arch_tables[] __initdata = { · line 40
Quoted 5 lines
arch/loongarch/kernel/efi.c +1
-1@@ -37,7 +37,7 @@ static efi_config_table_type_t arch_tables[] __initdata = {void __init efi_runtime_init (void ) { -if (!efi_enabled (EFI_BOOT )) +if (!efi_enabled (EFI_BOOT ) || !efi_systab->runtime)How can this happen? Why would we ever set
EFI_BOOTifefi_systab->runtime== NULL?Quoted 22 lines
arch/loongarch/kernel/efi.c +15
-0return ;if (efi_runtime_disabled ()) {@@ -101,3 +101,28 @@ void __init efi_init(void)early_memunmap (tbl,sizeof (*tbl)); } } + +/* parse the fdt pointer from efi system table */ +void __init *efi_fdt_pointer (void ) +{ +int i; +void *fdt =NULL ; +efi_config_table_t *tables; + +if (!efi_systab) { +pr_err ("Can't find EFI system table.\n" ); +return NULL ; + } + + tables = (efi_config_table_t *) efi_systab->tables; +arch/loongarch/kernel/efi.c void __init efi_init(void) · line 128
Quoted 10 lines
arch/loongarch/kernel/efi.c +10
-0+for (i =0 ; i < efi_systab->nr_tables; i++) +if (efi_guidcmp (tables[i].guid,DEVICE_TREE_GUID ) ==0 ) { + fdt = (void *)early_memremap_ro ( + (resource_size_t )tables[i].table, +sizeof (efi_config_table_t)); +break ; + } + +return fdt; +}Please use the existing config table discovery mechanism for this.
Quoted 13 lines
arch/loongarch/kernel/env.c +1
-0@@ -11,6 +11,7 @@#include <asm/early_ioremap.h> #include <asm/bootinfo.h> #include <asm/loongson.h> +#include <asm/setup.h> u64 efi_system_table;struct loongson_system_configuration loongson_sysconf;arch/loongarch/kernel/env.c void __init init_environ(void) · line 31
Quoted 4 lines
arch/loongarch/kernel/env.c +1
-0@@ -27,6 +28,8 @@ void __init init_environ(void)clear_bit (EFI_BOOT , &efi.flags);strscpy (boot_command_line, cmdline,COMMAND_LINE_SIZE ); +/* Save unparsed command line copy for FDT */ Why is this necessary?
Quoted 100 lines
arch/loongarch/kernel/env.c +1
-0+strscpy (original_cmdline, boot_command_line,COMMAND_LINE_SIZE );early_memunmap (cmdline,COMMAND_LINE_SIZE ); efi_system_table = fw_arg2;arch/loongarch/kernel/setup.c +60
-0@@ -29,6 +29,9 @@#include <linux/device.h> #include <linux/dma-map-ops.h> #include <linux/swiotlb.h> +#include <linux/of_fdt.h> +#include <linux/of_address.h> +#include <linux/libfdt.h> #include <asm/addrspace.h> #include <asm/bootinfo.h> @@ -67,6 +70,7 @@ static const char dmi_empty_string[] = " ";* * These are initialized so they are in the .data section */ +char original_cmdline[COMMAND_LINE_SIZE ]__initdata ;static int num_standard_resources;static struct resource *standard_resources;@@ -281,6 +285,47 @@ static void __init check_kernel_sections_mem(void) } } +static void __init bootcmdline_init (char **cmdline_p) +{ +/* +* If CONFIG_CMDLINE_FORCE is enabled then initializing the command line +* is trivial - we simply use the built-in command line unconditionally & +* unmodified. +*/ +if (IS_ENABLED (CONFIG_CMDLINE_FORCE )) { +strscpy (boot_command_line,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); +return ; + } + +#ifdef CONFIG_OF_FLATTREE +/* +* This is for CONFIG_CMDLINE_EXTEND or CONFIG_CMDLINE_BOOTLOADER. +* +* If CONFIG_CMDLINE_BOOTLOADER is enabled, we need to determine if the +* system is ACPI-based or FDT-based. +* +* For ACPI-based system: nothing need to do. +* +* For FDT-based system: the boot_command_line will be overwritten by +* early_init_dt_scan_chosen(), so we need to append original_cmdline(the +* original copy of boot_command_line) to boot_command_line. +* +* As for the built-in command line, if CONFIG_CMDLINE_EXTEND is enabled, +* both ACPI-based and FDT-based system will append the built-in command +* line to the boot_command_line themselves, and no additional processing +* is required here. +*/ +if (initial_boot_params) { +if (boot_command_line[0 ]) +strlcat (boot_command_line," " ,COMMAND_LINE_SIZE ); + +strlcat (boot_command_line, original_cmdline,COMMAND_LINE_SIZE ); + } +#endif + + *cmdline_p = boot_command_line; +} +/* * arch_mem_init - initialize memory management subsystem */ @@ -291,6 +336,8 @@ static void __init arch_mem_init(char **cmdline_p)check_kernel_sections_mem (); +early_init_fdt_scan_reserved_mem (); +/* * In order to reduce the possibility of kernel panic when failed to * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate @@ -413,20 +460,44 @@ static void __init prefill_possible_map(void) }#endif +static void __init fdt_setup (void ) +{ +#ifdef CONFIG_OF_EARLY_FLATTREE +void *fdt_pointer; + +/* ACPI-based systems do not require parsing fdt */ +if (acpi_os_get_root_pointer ()) +return ; + +/* Look for a device tree configuration table entry */ + fdt_pointer =efi_fdt_pointer (); +if (!fdt_pointer ||fdt_check_header (fdt_pointer)) +return ;Quoted 8 lines
arch/loongarch/kernel/setup.c static void __init prefill_possible_map(void) · line 480
Quoted 5 lines
arch/loongarch/kernel/setup.c +5
-0+ +early_init_dt_scan (fdt_pointer); +early_init_fdt_reserve_self (); +early_init_dt_scan_chosen_stdout (); +The FDT is only a hardware description, right? So why are we scanning /chosen here?
Quoted 5 lines
We scan the chosen node here in order to configure earlycon as early as possible, this is very useful for debugging. ARM64 does similar things in
acpi_boot_table_init(), but I thinkfdt_setup()is more suitable.
Do you mean for the /chosen/stdout-path node?
Huacai Chen
maintainerQuoted 240 lines · Ard Biesheuvel
Quoted 238 lines · Huacai Chen
Hi, Ard,
Quoted 234 lines · Ard Biesheuvel
Quoted 60 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
Signed-off-by Binbin Zhou <[email protected]>--- arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 + arch/loongarch/include/asm/setup.h | 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++- 6 files changed, 106 insertions(+), 3 deletions(-)arch/loongarch/Kconfig +2
-0@@ -111,6 +111,8 @@ config LOONGARCH select MODULES_USE_ELF_RELA if MODULES select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select OF + select OF_EARLY_FLATTREE select PCI select PCI_DOMAINS_GENERIC select PCI_ECAM if ACPIarch/loongarch/include/asm/efi.h +1
-0@@ -9,6 +9,7 @@void __init efi_init (void );void __init efi_runtime_init (void ); +void __init *efi_fdt_pointer (void );void efifb_setup_from_dmi (struct screen_info *si,const char *opt);#define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004/* Bit 2: CSR.CRMD.IE */ arch/loongarch/include/asm/setup.h +1
-0@@ -13,6 +13,7 @@extern unsigned long eentry;extern unsigned long tlbrentry; +extern char original_cmdline[COMMAND_LINE_SIZE ];extern void tlb_init (int cpu);extern void cpu_cache_init (void );extern void cache_error_setup (void );arch/loongarch/kernel/efi.c +0
-0arch/loongarch/kernel/efi.c static efi_config_table_type_t arch_tables[] __initdata = { · line 40
Quoted 5 lines
arch/loongarch/kernel/efi.c +1
-1@@ -37,7 +37,7 @@ static efi_config_table_type_t arch_tables[] __initdata = {void __init efi_runtime_init (void ) { -if (!efi_enabled (EFI_BOOT )) +if (!efi_enabled (EFI_BOOT ) || !efi_systab->runtime)How can this happen? Why would we ever set
EFI_BOOTifefi_systab->runtime== NULL?Quoted 22 lines
arch/loongarch/kernel/efi.c +15
-0return ;if (efi_runtime_disabled ()) {@@ -101,3 +101,28 @@ void __init efi_init(void)early_memunmap (tbl,sizeof (*tbl)); } } + +/* parse the fdt pointer from efi system table */ +void __init *efi_fdt_pointer (void ) +{ +int i; +void *fdt =NULL ; +efi_config_table_t *tables; + +if (!efi_systab) { +pr_err ("Can't find EFI system table.\n" ); +return NULL ; + } + + tables = (efi_config_table_t *) efi_systab->tables; +arch/loongarch/kernel/efi.c void __init efi_init(void) · line 128
Quoted 10 lines
arch/loongarch/kernel/efi.c +10
-0+for (i =0 ; i < efi_systab->nr_tables; i++) +if (efi_guidcmp (tables[i].guid,DEVICE_TREE_GUID ) ==0 ) { + fdt = (void *)early_memremap_ro ( + (resource_size_t )tables[i].table, +sizeof (efi_config_table_t)); +break ; + } + +return fdt; +}Please use the existing config table discovery mechanism for this.
Quoted 13 lines
arch/loongarch/kernel/env.c +1
-0@@ -11,6 +11,7 @@#include <asm/early_ioremap.h> #include <asm/bootinfo.h> #include <asm/loongson.h> +#include <asm/setup.h> u64 efi_system_table;struct loongson_system_configuration loongson_sysconf;arch/loongarch/kernel/env.c void __init init_environ(void) · line 31
Quoted 4 lines
arch/loongarch/kernel/env.c +1
-0@@ -27,6 +28,8 @@ void __init init_environ(void)clear_bit (EFI_BOOT , &efi.flags);strscpy (boot_command_line, cmdline,COMMAND_LINE_SIZE ); +/* Save unparsed command line copy for FDT */ Why is this necessary?
Quoted 95 lines
arch/loongarch/kernel/env.c +1
-0+strscpy (original_cmdline, boot_command_line,COMMAND_LINE_SIZE );early_memunmap (cmdline,COMMAND_LINE_SIZE ); efi_system_table = fw_arg2;arch/loongarch/kernel/setup.c +55
-0@@ -29,6 +29,9 @@#include <linux/device.h> #include <linux/dma-map-ops.h> #include <linux/swiotlb.h> +#include <linux/of_fdt.h> +#include <linux/of_address.h> +#include <linux/libfdt.h> #include <asm/addrspace.h> #include <asm/bootinfo.h> @@ -67,6 +70,7 @@ static const char dmi_empty_string[] = " ";* * These are initialized so they are in the .data section */ +char original_cmdline[COMMAND_LINE_SIZE ]__initdata ;static int num_standard_resources;static struct resource *standard_resources;@@ -281,6 +285,47 @@ static void __init check_kernel_sections_mem(void) } } +static void __init bootcmdline_init (char **cmdline_p) +{ +/* +* If CONFIG_CMDLINE_FORCE is enabled then initializing the command line +* is trivial - we simply use the built-in command line unconditionally & +* unmodified. +*/ +if (IS_ENABLED (CONFIG_CMDLINE_FORCE )) { +strscpy (boot_command_line,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); +return ; + } + +#ifdef CONFIG_OF_FLATTREE +/* +* This is for CONFIG_CMDLINE_EXTEND or CONFIG_CMDLINE_BOOTLOADER. +* +* If CONFIG_CMDLINE_BOOTLOADER is enabled, we need to determine if the +* system is ACPI-based or FDT-based. +* +* For ACPI-based system: nothing need to do. +* +* For FDT-based system: the boot_command_line will be overwritten by +* early_init_dt_scan_chosen(), so we need to append original_cmdline(the +* original copy of boot_command_line) to boot_command_line. +* +* As for the built-in command line, if CONFIG_CMDLINE_EXTEND is enabled, +* both ACPI-based and FDT-based system will append the built-in command +* line to the boot_command_line themselves, and no additional processing +* is required here. +*/ +if (initial_boot_params) { +if (boot_command_line[0 ]) +strlcat (boot_command_line," " ,COMMAND_LINE_SIZE ); + +strlcat (boot_command_line, original_cmdline,COMMAND_LINE_SIZE ); + } +#endif + + *cmdline_p = boot_command_line; +} +/* * arch_mem_init - initialize memory management subsystem */ @@ -291,6 +336,8 @@ static void __init arch_mem_init(char **cmdline_p)check_kernel_sections_mem (); +early_init_fdt_scan_reserved_mem (); +/* * In order to reduce the possibility of kernel panic when failed to * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate @@ -413,20 +460,44 @@ static void __init prefill_possible_map(void) }#endif +static void __init fdt_setup (void ) +{ +#ifdef CONFIG_OF_EARLY_FLATTREE +void *fdt_pointer; + +/* ACPI-based systems do not require parsing fdt */ +if (acpi_os_get_root_pointer ()) +return ;arch/loongarch/kernel/setup.c static void __init prefill_possible_map(void) · line 480
Quoted 10 lines
arch/loongarch/kernel/setup.c +10
-0+ +/* Look for a device tree configuration table entry */ + fdt_pointer =efi_fdt_pointer (); +if (!fdt_pointer ||fdt_check_header (fdt_pointer)) +return ; + +early_init_dt_scan (fdt_pointer); +early_init_fdt_reserve_self (); +early_init_dt_scan_chosen_stdout (); +The FDT is only a hardware description, right? So why are we scanning /chosen here?
Quoted 7 lines
Quoted 5 lines
We scan the chosen node here in order to configure earlycon as early as possible, this is very useful for debugging. ARM64 does similar things in
acpi_boot_table_init(), but I thinkfdt_setup()is more suitable.Do you mean for the /chosen/stdout-path node?
Yes.
Quoted 94 lines · Ard Biesheuvel
Quoted 60 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
Signed-off-by Binbin Zhou <[email protected]>--- arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 + arch/loongarch/include/asm/setup.h | 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++- 6 files changed, 106 insertions(+), 3 deletions(-)arch/loongarch/Kconfig +2
-0@@ -111,6 +111,8 @@ config LOONGARCH select MODULES_USE_ELF_RELA if MODULES select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select OF + select OF_EARLY_FLATTREE select PCI select PCI_DOMAINS_GENERIC select PCI_ECAM if ACPIarch/loongarch/include/asm/efi.h +1
-0@@ -9,6 +9,7 @@void __init efi_init (void );void __init efi_runtime_init (void ); +void __init *efi_fdt_pointer (void );void efifb_setup_from_dmi (struct screen_info *si,const char *opt);#define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004/* Bit 2: CSR.CRMD.IE */ arch/loongarch/include/asm/setup.h +1
-0@@ -13,6 +13,7 @@extern unsigned long eentry;extern unsigned long tlbrentry; +extern char original_cmdline[COMMAND_LINE_SIZE ];extern void tlb_init (int cpu);extern void cpu_cache_init (void );extern void cache_error_setup (void );arch/loongarch/kernel/efi.c +0
-0arch/loongarch/kernel/efi.c static efi_config_table_type_t arch_tables[] __initdata = { · line 40
Quoted 5 lines
arch/loongarch/kernel/efi.c +1
-1@@ -37,7 +37,7 @@ static efi_config_table_type_t arch_tables[] __initdata = {void __init efi_runtime_init (void ) { -if (!efi_enabled (EFI_BOOT )) +if (!efi_enabled (EFI_BOOT ) || !efi_systab->runtime)How can this happen? Why would we ever set
EFI_BOOTifefi_systab->runtime== NULL?Quoted 24 lines
arch/loongarch/kernel/efi.c +17
-0return ;if (efi_runtime_disabled ()) {@@ -101,3 +101,28 @@ void __init efi_init(void)early_memunmap (tbl,sizeof (*tbl)); } } + +/* parse the fdt pointer from efi system table */ +void __init *efi_fdt_pointer (void ) +{ +int i; +void *fdt =NULL ; +efi_config_table_t *tables; + +if (!efi_systab) { +pr_err ("Can't find EFI system table.\n" ); +return NULL ; + } + + tables = (efi_config_table_t *) efi_systab->tables; + +for (i =0 ; i < efi_systab->nr_tables; i++) +if (efi_guidcmp (tables[i].guid,DEVICE_TREE_GUID ) ==0 ) {
Quoted 9 lines
arch/loongarch/kernel/efi.c void __init efi_init(void) · line 128
Quoted 8 lines
arch/loongarch/kernel/efi.c +8
-0+ fdt = (void *)early_memremap_ro ( + (resource_size_t )tables[i].table, +sizeof (efi_config_table_t)); +break ; + } + +return fdt; +}
Hi Ard:
Quoted 1 line
Please use the existing config table discovery mechanism for this.
Sorry, Regarding the mechanism related to config table discovery you mentioned, I only found the get_fdt() or get_efi_config_table() interfaces in driver/firmware/efi/libstub. Unfortunately, both of them cannot be referenced in our case.
So which mechanism are you referring to specifically?
Thanks.
Binbin
Quoted 158 lines
Quoted 14 lines
arch/loongarch/kernel/env.c +1
-0@@ -11,6 +11,7 @@#include <asm/early_ioremap.h> #include <asm/bootinfo.h> #include <asm/loongson.h> +#include <asm/setup.h> u64 efi_system_table;struct loongson_system_configuration loongson_sysconf;arch/loongarch/kernel/env.c void __init init_environ(void) · line 31
Quoted 4 lines
arch/loongarch/kernel/env.c +1
-0@@ -27,6 +28,8 @@ void __init init_environ(void)clear_bit (EFI_BOOT , &efi.flags);strscpy (boot_command_line, cmdline,COMMAND_LINE_SIZE ); +/* Save unparsed command line copy for FDT */ Why is this necessary?
Quoted 95 lines
arch/loongarch/kernel/env.c +1
-0+strscpy (original_cmdline, boot_command_line,COMMAND_LINE_SIZE );early_memunmap (cmdline,COMMAND_LINE_SIZE ); efi_system_table = fw_arg2;arch/loongarch/kernel/setup.c +55
-0@@ -29,6 +29,9 @@#include <linux/device.h> #include <linux/dma-map-ops.h> #include <linux/swiotlb.h> +#include <linux/of_fdt.h> +#include <linux/of_address.h> +#include <linux/libfdt.h> #include <asm/addrspace.h> #include <asm/bootinfo.h> @@ -67,6 +70,7 @@ static const char dmi_empty_string[] = " ";* * These are initialized so they are in the .data section */ +char original_cmdline[COMMAND_LINE_SIZE ]__initdata ;static int num_standard_resources;static struct resource *standard_resources;@@ -281,6 +285,47 @@ static void __init check_kernel_sections_mem(void) } } +static void __init bootcmdline_init (char **cmdline_p) +{ +/* +* If CONFIG_CMDLINE_FORCE is enabled then initializing the command line +* is trivial - we simply use the built-in command line unconditionally & +* unmodified. +*/ +if (IS_ENABLED (CONFIG_CMDLINE_FORCE )) { +strscpy (boot_command_line,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); +return ; + } + +#ifdef CONFIG_OF_FLATTREE +/* +* This is for CONFIG_CMDLINE_EXTEND or CONFIG_CMDLINE_BOOTLOADER. +* +* If CONFIG_CMDLINE_BOOTLOADER is enabled, we need to determine if the +* system is ACPI-based or FDT-based. +* +* For ACPI-based system: nothing need to do. +* +* For FDT-based system: the boot_command_line will be overwritten by +* early_init_dt_scan_chosen(), so we need to append original_cmdline(the +* original copy of boot_command_line) to boot_command_line. +* +* As for the built-in command line, if CONFIG_CMDLINE_EXTEND is enabled, +* both ACPI-based and FDT-based system will append the built-in command +* line to the boot_command_line themselves, and no additional processing +* is required here. +*/ +if (initial_boot_params) { +if (boot_command_line[0 ]) +strlcat (boot_command_line," " ,COMMAND_LINE_SIZE ); + +strlcat (boot_command_line, original_cmdline,COMMAND_LINE_SIZE ); + } +#endif + + *cmdline_p = boot_command_line; +} +/* * arch_mem_init - initialize memory management subsystem */ @@ -291,6 +336,8 @@ static void __init arch_mem_init(char **cmdline_p)check_kernel_sections_mem (); +early_init_fdt_scan_reserved_mem (); +/* * In order to reduce the possibility of kernel panic when failed to * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate @@ -413,20 +460,44 @@ static void __init prefill_possible_map(void) }#endif +static void __init fdt_setup (void ) +{ +#ifdef CONFIG_OF_EARLY_FLATTREE +void *fdt_pointer; + +/* ACPI-based systems do not require parsing fdt */ +if (acpi_os_get_root_pointer ()) +return ;arch/loongarch/kernel/setup.c static void __init prefill_possible_map(void) · line 480
Quoted 10 lines
arch/loongarch/kernel/setup.c +10
-0+ +/* Look for a device tree configuration table entry */ + fdt_pointer =efi_fdt_pointer (); +if (!fdt_pointer ||fdt_check_header (fdt_pointer)) +return ; + +early_init_dt_scan (fdt_pointer); +early_init_fdt_reserve_self (); +early_init_dt_scan_chosen_stdout (); +The FDT is only a hardware description, right? So why are we scanning /chosen here?
Quoted 28 lines
arch/loongarch/kernel/setup.c +8
-3+ max_low_pfn =PFN_PHYS (memblock_end_of_DRAM ()); +#endif +} +void __init setup_arch (char **cmdline_p) {cpu_probe (); - *cmdline_p = boot_command_line; +pagetable_init ();init_environ ();efi_init (); +fdt_setup ();memblock_init (); -pagetable_init (); +bootcmdline_init (cmdline_p);parse_early_param ();reserve_initrd_mem ();platform_init ();arch_mem_init (cmdline_p); +unflatten_and_copy_device_tree ();resource_init ();#ifdef CONFIG_SMP --2.31.1
Ard Biesheuvel
maintainerQuoted 109 lines · Binbin Zhou
Quoted 94 lines · Ard Biesheuvel
Quoted 60 lines · Binbin Zhou
Since commit 40cd01a9c324("efi/loongarch: libstub: remove dependency on flattened DT"), we can parse the FDT from efi system table.
And now, the Loongson-2K series cpus based on LoongArch support booting with FDT, so we adds the relevant booting support as well as parameter parsing.
Signed-off-by Binbin Zhou <[email protected]>--- arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 + arch/loongarch/include/asm/setup.h | 1 + arch/loongarch/kernel/efi.c | 27 ++++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/setup.c | 75 +++++++++++++++++++++++++++++- 6 files changed, 106 insertions(+), 3 deletions(-)arch/loongarch/Kconfig +2
-0@@ -111,6 +111,8 @@ config LOONGARCH select MODULES_USE_ELF_RELA if MODULES select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select OF + select OF_EARLY_FLATTREE select PCI select PCI_DOMAINS_GENERIC select PCI_ECAM if ACPIarch/loongarch/include/asm/efi.h +1
-0@@ -9,6 +9,7 @@void __init efi_init (void );void __init efi_runtime_init (void ); +void __init *efi_fdt_pointer (void );void efifb_setup_from_dmi (struct screen_info *si,const char *opt);#define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004/* Bit 2: CSR.CRMD.IE */ arch/loongarch/include/asm/setup.h +1
-0@@ -13,6 +13,7 @@extern unsigned long eentry;extern unsigned long tlbrentry; +extern char original_cmdline[COMMAND_LINE_SIZE ];extern void tlb_init (int cpu);extern void cpu_cache_init (void );extern void cache_error_setup (void );arch/loongarch/kernel/efi.c +0
-0arch/loongarch/kernel/efi.c static efi_config_table_type_t arch_tables[] __initdata = { · line 40
Quoted 5 lines
arch/loongarch/kernel/efi.c +1
-1@@ -37,7 +37,7 @@ static efi_config_table_type_t arch_tables[] __initdata = {void __init efi_runtime_init (void ) { -if (!efi_enabled (EFI_BOOT )) +if (!efi_enabled (EFI_BOOT ) || !efi_systab->runtime)How can this happen? Why would we ever set
EFI_BOOTifefi_systab->runtime== NULL?Quoted 24 lines
arch/loongarch/kernel/efi.c +17
-0return ;if (efi_runtime_disabled ()) {@@ -101,3 +101,28 @@ void __init efi_init(void)early_memunmap (tbl,sizeof (*tbl)); } } + +/* parse the fdt pointer from efi system table */ +void __init *efi_fdt_pointer (void ) +{ +int i; +void *fdt =NULL ; +efi_config_table_t *tables; + +if (!efi_systab) { +pr_err ("Can't find EFI system table.\n" ); +return NULL ; + } + + tables = (efi_config_table_t *) efi_systab->tables; + +for (i =0 ; i < efi_systab->nr_tables; i++) +if (efi_guidcmp (tables[i].guid,DEVICE_TREE_GUID ) ==0 ) {Quoted 9 lines
arch/loongarch/kernel/efi.c void __init efi_init(void) · line 128
Quoted 8 lines
arch/loongarch/kernel/efi.c +8
-0+ fdt = (void *)early_memremap_ro ( + (resource_size_t )tables[i].table, +sizeof (efi_config_table_t)); +break ; + } + +return fdt; +}Hi Ard:
Quoted 9 lines
Quoted 1 line
Please use the existing config table discovery mechanism for this.
Sorry, Regarding the mechanism related to config table discovery you mentioned, I only found the
get_fdt()orget_efi_config_table()interfaces in driver/firmware/efi/libstub. Unfortunately, both of them cannot be referenced in our case.So which mechanism are you referring to specifically?
Please look at how the existing LoongArch code uses efi_config_parse_tables()