LoongArch: Support booting with FDT
v2 cover LoongArch: Support booting with FDT
Hi all:
Since LoongArch will soon support FDT booting, such as the Loongson-2K series, this patchset adds relevant booting support and parameter parsing.
Changes in V2:
patch(1/2)
- Update comments and commit messages (setup.c);
- Give the general method to get the FDT Pointer from EFI (efi.c);
- Add SMP support based on FDT (smp.c);
- Call early_init_dt_scan_chosen_stdout() only when
earlycon_acpi_spcr_enable is true (kernel/acpi.c);
- Fix illegal access during pci root bridge registration (pci/acpi.c).
patch(2/2)
- Newly added.
Thanks.
Binbin Zhou (2):
LoongArch: Support booting with FDT from efi system table
LoongArch: Process ISA Node in DeviceTree
arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/efi.h | 1 + arch/loongarch/include/asm/setup.h | 1 + arch/loongarch/kernel/acpi.c | 11 ++- arch/loongarch/kernel/efi.c | 19 +++- arch/loongarch/kernel/env.c | 3 + arch/loongarch/kernel/reset.c | 3 +- arch/loongarch/kernel/setup.c | 137 ++++++++++++++++++++++++++++- arch/loongarch/kernel/smp.c | 32 +++++++ arch/loongarch/pci/acpi.c | 5 +- 10 files changed, 207 insertions(+), 7 deletions(-)
Signature · 1 line
2.31.1
PATCH v2 1/2 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, LoongArch is coming to 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/acpi.c | 11 +++++- arch/loongarch/kernel/efi.c | 19 +++++++++- arch/loongarch/kernel/env.c | 3 ++ arch/loongarch/kernel/reset.c | 3 +- arch/loongarch/kernel/setup.c | 61 +++++++++++++++++++++++++++++- arch/loongarch/kernel/smp.c | 32 ++++++++++++++++ arch/loongarch/pci/acpi.c | 5 ++- 10 files changed, 131 insertions(+), 7 deletions(-)
arch/loongarch/Kconfig +2 -0
@@ -120,6 +120,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/acpi.c +9 -2
@@ -13,6 +13,7 @@#include <linux/irqdomain.h> #include <linux/memblock.h> #include <linux/serial_core.h> +#include <linux/of_fdt.h> #include <asm/io.h> #include <asm/numa.h> #include <asm/loongson.h>
@@ -151,14 +152,14 @@ void __init acpi_boot_table_init(void)* If acpi_disabled, bail out */ if (acpi_disabled) -return ; + goto fdt_earlycon;/* * Initialize the ACPI boot-time table parser. */ if (acpi_table_init ()) {disable_acpi (); -return ; + goto fdt_earlycon; } loongson_sysconf.boot_cpu_id =read_csr_cpuid ();
@@ -170,6 +171,12 @@ void __init acpi_boot_table_init(void)/* Do not enable ACPI SPCR console by default */ acpi_parse_spcr (earlycon_acpi_spcr_enable, false); + +return ; + +fdt_earlycon: +if (earlycon_acpi_spcr_enable) +early_init_dt_scan_chosen_stdout (); }#ifdef CONFIG_ACPI_NUMA
arch/loongarch/kernel/efi.c +17 -2
@@ -27,17 +27,19 @@static unsigned long efi_nr_tables;static unsigned long efi_config_table; -static unsigned long __initdata boot_memmap =EFI_INVALID_TABLE_ADDR ; +static unsigned long boot_memmap__initdata =EFI_INVALID_TABLE_ADDR ; +static unsigned long efi_fdt__initdata =EFI_INVALID_TABLE_ADDR ;static efi_system_table_t *efi_systab;static efi_config_table_type_t arch_tables[]__initdata = { {LINUX_EFI_BOOT_MEMMAP_GUID , &boot_memmap,"MEMMAP" }, + {DEVICE_TREE_GUID , &efi_fdt,"EFIFDT" }, {}, };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 +103,16 @@ void __init efi_init(void)early_memunmap (tbl,sizeof (*tbl)); } } + +void __init *efi_fdt_pointer (void ) +{ +if (!efi_systab) { +pr_err ("Can't find EFI system table.\n" ); +return NULL ; + } + +if (efi_fdt ==EFI_INVALID_TABLE_ADDR ) +return NULL ; + +return (void *)early_memremap_ro (efi_fdt,sizeof (efi_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/reset.c +2 -1
@@ -44,7 +44,8 @@ void machine_power_off(void)smp_send_stop ();#endif #ifdef CONFIG_PM -enable_pci_wakeup (); +if (!acpi_disabled) +enable_pci_wakeup ();#endif do_kernel_power_off ();#ifdef CONFIG_EFI
arch/loongarch/kernel/setup.c +60 -1
104 lines not on this page · raw message
arch/loongarch/kernel/smp.c +32 -0
@@ -170,8 +170,40 @@ irqreturn_t loongson_ipi_interrupt(int irq, void *dev)return IRQ_HANDLED ; } +static void __init fdt_smp_setup (void ) +{ +#ifdef CONFIG_OF +struct device_node *node =NULL ; +unsigned int cpu, cpuid; + +for_each_of_cpu_node (node) { +if (!of_device_is_available (node)) +continue ; + + cpuid =of_get_cpu_hwid (node,0 ); +if (cpuid >= nr_cpu_ids) +continue ; + +if (cpuid == loongson_sysconf.boot_cpu_id) + cpu =0 ; +else + cpu =cpumask_next_zero (-1 , cpu_present_mask); + + num_processors++; +set_cpu_possible (cpu, true); +set_cpu_present (cpu, true); + __cpu_number_map[cpuid] = cpu; + __cpu_logical_map[cpu] = cpuid; + } + + loongson_sysconf.nr_cpus = num_processors; +#endif +} +void __init loongson_smp_setup (void ) { +fdt_smp_setup (); + cpu_data[0 ].core =cpu_logical_map (0 ) % loongson_sysconf.cores_per_package; cpu_data[0 ].package =cpu_logical_map (0 ) / loongson_sysconf.cores_per_package;
arch/loongarch/pci/acpi.c +4 -1
@@ -27,9 +27,12 @@ void pcibios_add_bus(struct pci_bus *bus)int pcibios_root_bridge_prepare (struct pci_host_bridge *bridge) {struct pci_config_window *cfg = bridge->bus->sysdata; -struct acpi_device *adev =to_acpi_device (cfg->parent); +struct acpi_device *adev =NULL ;struct device *bus_dev = &bridge->bus->dev; +if (!acpi_disabled) + adev =to_acpi_device (cfg->parent); +ACPI_COMPANION_SET (&bridge->dev, adev);set_dev_node (bus_dev,pa_to_nid (cfg->res.start));
Signature · 1 line
2.31.1
PATCH v2 2/2 LoongArch: Process ISA Node in DeviceTree
In reply to Binbin ZhouPreviously, we are hardcoding reserved ISA I/O Space in, now we are processing it I/O via DeviceTree directly.
The ranges property if ISA node is used to determine the size and address of reserved I/O space.
--- arch/loongarch/kernel/setup.c | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)
arch/loongarch/kernel/setup.c +76 -0
@@ -258,6 +258,82 @@ static void __init arch_parse_crashkernel(void)#endif } +static int __init add_legacy_isa_io (struct fwnode_handle *fwnode,resource_size_t hw_start, +resource_size_t size) +{ +int ret =0 ; +struct logic_pio_hwaddr *range; +unsigned long vaddr; + + range =kzalloc (sizeof (*range),GFP_ATOMIC ); +if (!range) +return -ENOMEM ; + + range->fwnode = fwnode; + range->size = size =round_up (size,PAGE_SIZE ); + range->hw_start = hw_start; + range->flags =LOGIC_PIO_CPU_MMIO ; + + ret =logic_pio_register_range (range); +if (ret) { +kfree (range); +return ret; + } + +/* Legacy ISA must placed at the start of PCI_IOBASE */ +if (range->io_start !=0 ) { +logic_pio_unregister_range (range); +kfree (range); +return -EINVAL ; + } + + vaddr = (unsigned long ) (PCI_IOBASE + range->io_start); + +ioremap_page_range (vaddr, vaddr + size, hw_start,pgprot_device (PAGE_KERNEL )); + +return 0 ; +} + +static __init int arch_reserve_pio_range (void ) +{ +struct device_node *np; + +for_each_node_by_name (np,"isa" ) { +struct of_range range; +struct of_range_parser parser; + +pr_info ("ISA Bridge: %pOF\n" , np); + +if (of_range_parser_init (&parser, np)) { +pr_info ("Failed to parse resources.\n" ); +of_node_put (np); +break ; + } + +for_each_of_range (&parser, &range) { +switch (range.flags &IORESOURCE_TYPE_BITS ) { +case IORESOURCE_IO : +pr_info (" IO 0x%016llx..0x%016llx -> 0x%016llx\n" , + range.cpu_addr, + range.cpu_addr + range.size -1 , + range.bus_addr); +if (add_legacy_isa_io (&np->fwnode, range.cpu_addr, range.size)) +pr_warn ("Failed to reserve legacy IO in Logic PIO\n" ); +break ; +case IORESOURCE_MEM : +pr_info (" MEM 0x%016llx..0x%016llx -> 0x%016llx\n" , + range.cpu_addr, + range.cpu_addr + range.size -1 , + range.bus_addr); +break ; + } + } + } + +return 0 ; +} +arch_initcall (arch_reserve_pio_range); +void __init platform_init (void ) {arch_reserve_vmcore ();
Signature · 1 line
2.31.1