Skip to content

Commit 24e88ab

Browse files
committed
Merge tag 'efi-loongarch-for-v6.1-2' into HEAD
Second shared stable tag between EFI and LoongArch trees This is necessary because the EFI libstub refactoring patches are mostly directed at enabling LoongArch to wire up generic EFI boot support without being forced to consume DT properties that conflict with information that EFI also provides, e.g., memory map and reservations, etc.
2 parents a241d94 + 40cd01a commit 24e88ab

21 files changed

Lines changed: 411 additions & 384 deletions

File tree

Documentation/arm/uefi.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ linux,uefi-mmap-desc-size 32-bit Size in bytes of each entry in the UEFI
6565

6666
linux,uefi-mmap-desc-ver 32-bit Version of the mmap descriptor format.
6767

68-
linux,initrd-start 64-bit Physical start address of an initrd
69-
70-
linux,initrd-end 64-bit Physical end address of an initrd
71-
7268
kaslr-seed 64-bit Entropy used to randomize the kernel image
7369
base address location.
7470
========================== ====== ===========================================

arch/loongarch/Kconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ config LOONGARCH
104104
select MODULES_USE_ELF_RELA if MODULES
105105
select NEED_PER_CPU_EMBED_FIRST_CHUNK
106106
select NEED_PER_CPU_PAGE_FIRST_CHUNK
107-
select OF
108-
select OF_EARLY_FLATTREE
109107
select PCI
110108
select PCI_DOMAINS_GENERIC
111109
select PCI_ECAM if ACPI
@@ -311,7 +309,6 @@ config DMI
311309
config EFI
312310
bool "EFI runtime service support"
313311
select UCS2_STRING
314-
select EFI_PARAMS_FROM_FDT
315312
select EFI_RUNTIME_WRAPPERS
316313
help
317314
This enables the kernel to use EFI runtime services that are

arch/loongarch/include/asm/bootinfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct loongson_system_configuration {
3636
};
3737

3838
extern u64 efi_system_table;
39-
extern unsigned long fw_arg0, fw_arg1;
39+
extern unsigned long fw_arg0, fw_arg1, fw_arg2;
4040
extern struct loongson_board_info b_info;
4141
extern struct loongson_system_configuration loongson_sysconf;
4242

arch/loongarch/kernel/efi.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@
2727
static unsigned long efi_nr_tables;
2828
static unsigned long efi_config_table;
2929

30+
static unsigned long __initdata boot_memmap = EFI_INVALID_TABLE_ADDR;
31+
3032
static efi_system_table_t *efi_systab;
31-
static efi_config_table_type_t arch_tables[] __initdata = {{},};
33+
static efi_config_table_type_t arch_tables[] __initdata = {
34+
{LINUX_EFI_BOOT_MEMMAP_GUID, &boot_memmap, "MEMMAP" },
35+
{},
36+
};
3237

3338
void __init efi_runtime_init(void)
3439
{
@@ -51,6 +56,7 @@ void __init efi_init(void)
5156
{
5257
int size;
5358
void *config_tables;
59+
struct efi_boot_memmap *tbl;
5460

5561
if (!efi_system_table)
5662
return;
@@ -61,6 +67,8 @@ void __init efi_init(void)
6167
return;
6268
}
6369

70+
efi_systab_report_header(&efi_systab->hdr, efi_systab->fw_vendor);
71+
6472
set_bit(EFI_64BIT, &efi.flags);
6573
efi_nr_tables = efi_systab->nr_tables;
6674
efi_config_table = (unsigned long)efi_systab->tables;
@@ -70,6 +78,26 @@ void __init efi_init(void)
7078
efi_config_parse_tables(config_tables, efi_systab->nr_tables, arch_tables);
7179
early_memunmap(config_tables, efi_nr_tables * size);
7280

81+
set_bit(EFI_CONFIG_TABLES, &efi.flags);
82+
7383
if (screen_info.orig_video_isVGA == VIDEO_TYPE_EFI)
7484
memblock_reserve(screen_info.lfb_base, screen_info.lfb_size);
85+
86+
if (boot_memmap == EFI_INVALID_TABLE_ADDR)
87+
return;
88+
89+
tbl = early_memremap_ro(boot_memmap, sizeof(*tbl));
90+
if (tbl) {
91+
struct efi_memory_map_data data;
92+
93+
data.phys_map = boot_memmap + sizeof(*tbl);
94+
data.size = tbl->map_size;
95+
data.desc_size = tbl->desc_size;
96+
data.desc_version = tbl->desc_ver;
97+
98+
if (efi_memmap_init_early(&data) < 0)
99+
panic("Unable to map EFI memory map.\n");
100+
101+
early_memunmap(tbl, sizeof(*tbl));
102+
}
75103
}

arch/loongarch/kernel/env.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <linux/efi.h>
99
#include <linux/export.h>
1010
#include <linux/memblock.h>
11-
#include <linux/of_fdt.h>
1211
#include <asm/early_ioremap.h>
1312
#include <asm/bootinfo.h>
1413
#include <asm/loongson.h>
@@ -20,21 +19,17 @@ EXPORT_SYMBOL(loongson_sysconf);
2019
void __init init_environ(void)
2120
{
2221
int efi_boot = fw_arg0;
23-
struct efi_memory_map_data data;
24-
void *fdt_ptr = early_memremap_ro(fw_arg1, SZ_64K);
22+
char *cmdline = early_memremap_ro(fw_arg1, COMMAND_LINE_SIZE);
2523

2624
if (efi_boot)
2725
set_bit(EFI_BOOT, &efi.flags);
2826
else
2927
clear_bit(EFI_BOOT, &efi.flags);
3028

31-
early_init_dt_scan(fdt_ptr);
32-
early_init_fdt_reserve_self();
33-
efi_system_table = efi_get_fdt_params(&data);
29+
strscpy(boot_command_line, cmdline, COMMAND_LINE_SIZE);
30+
early_memunmap(cmdline, COMMAND_LINE_SIZE);
3431

35-
efi_memmap_init_early(&data);
36-
memblock_reserve(data.phys_map & PAGE_MASK,
37-
PAGE_ALIGN(data.size + (data.phys_map & ~PAGE_MASK)));
32+
efi_system_table = fw_arg2;
3833
}
3934

4035
static int __init init_cpu_fullname(void)

arch/loongarch/kernel/head.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ SYM_CODE_START(kernel_entry) # kernel entry point
6767
st.d a0, t0, 0 # firmware arguments
6868
la t0, fw_arg1
6969
st.d a1, t0, 0
70+
la t0, fw_arg2
71+
st.d a2, t0, 0
7072

7173
/* KSave3 used for percpu base, initialized as 0 */
7274
csrwr zero, PERCPU_BASE_KS

arch/loongarch/kernel/setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
struct screen_info screen_info __section(".data");
5353

54-
unsigned long fw_arg0, fw_arg1;
54+
unsigned long fw_arg0, fw_arg1, fw_arg2;
5555
DEFINE_PER_CPU(unsigned long, kernelsp);
5656
struct cpuinfo_loongarch cpu_data[NR_CPUS] __read_mostly;
5757

@@ -187,7 +187,6 @@ early_param("mem", early_parse_mem);
187187

188188
void __init platform_init(void)
189189
{
190-
efi_init();
191190
#ifdef CONFIG_ACPI_TABLE_UPGRADE
192191
acpi_table_upgrade();
193192
#endif
@@ -347,6 +346,7 @@ void __init setup_arch(char **cmdline_p)
347346
*cmdline_p = boot_command_line;
348347

349348
init_environ();
349+
efi_init();
350350
memblock_init();
351351
parse_early_param();
352352

drivers/firmware/efi/efi.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/device.h>
2222
#include <linux/efi.h>
2323
#include <linux/of.h>
24+
#include <linux/initrd.h>
2425
#include <linux/io.h>
2526
#include <linux/kexec.h>
2627
#include <linux/platform_device.h>
@@ -55,6 +56,7 @@ EXPORT_SYMBOL(efi);
5556
unsigned long __ro_after_init efi_rng_seed = EFI_INVALID_TABLE_ADDR;
5657
static unsigned long __initdata mem_reserve = EFI_INVALID_TABLE_ADDR;
5758
static unsigned long __initdata rt_prop = EFI_INVALID_TABLE_ADDR;
59+
static unsigned long __initdata initrd = EFI_INVALID_TABLE_ADDR;
5860

5961
struct mm_struct efi_mm = {
6062
.mm_rb = RB_ROOT,
@@ -532,6 +534,7 @@ static const efi_config_table_type_t common_tables[] __initconst = {
532534
{LINUX_EFI_TPM_EVENT_LOG_GUID, &efi.tpm_log, "TPMEventLog" },
533535
{LINUX_EFI_TPM_FINAL_LOG_GUID, &efi.tpm_final_log, "TPMFinalLog" },
534536
{LINUX_EFI_MEMRESERVE_TABLE_GUID, &mem_reserve, "MEMRESERVE" },
537+
{LINUX_EFI_INITRD_MEDIA_GUID, &initrd, "INITRD" },
535538
{EFI_RT_PROPERTIES_TABLE_GUID, &rt_prop, "RTPROP" },
536539
#ifdef CONFIG_EFI_RCI2_TABLE
537540
{DELLEMC_EFI_RCI2_TABLE_GUID, &rci2_table_phys },
@@ -674,6 +677,18 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables,
674677
}
675678
}
676679

680+
if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) &&
681+
initrd != EFI_INVALID_TABLE_ADDR && phys_initrd_size == 0) {
682+
struct linux_efi_initrd *tbl;
683+
684+
tbl = early_memremap(initrd, sizeof(*tbl));
685+
if (tbl) {
686+
phys_initrd_start = tbl->base;
687+
phys_initrd_size = tbl->size;
688+
early_memunmap(tbl, sizeof(*tbl));
689+
}
690+
}
691+
677692
return 0;
678693
}
679694

drivers/firmware/efi/libstub/Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ cflags-$(CONFIG_RISCV) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \
2929
cflags-$(CONFIG_LOONGARCH) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \
3030
-fpie
3131

32-
cflags-$(CONFIG_EFI_GENERIC_STUB) += -I$(srctree)/scripts/dtc/libfdt
32+
cflags-$(CONFIG_EFI_PARAMS_FROM_FDT) += -I$(srctree)/scripts/dtc/libfdt
3333

3434
KBUILD_CFLAGS := $(cflags-y) -Os -DDISABLE_BRANCH_PROFILING \
3535
-include $(srctree)/include/linux/hidden.h \
@@ -59,15 +59,17 @@ lib-y := efi-stub-helper.o gop.o secureboot.o tpm.o \
5959
skip_spaces.o lib-cmdline.o lib-ctype.o \
6060
alignedmem.o relocate.o vsprintf.o
6161

62-
# include the stub's generic dependencies from lib/ when building for ARM/arm64
63-
efi-deps-y := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c
62+
# include the stub's libfdt dependencies from lib/ when needed
63+
libfdt-deps := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c \
64+
fdt_empty_tree.c fdt_sw.c
65+
66+
lib-$(CONFIG_EFI_PARAMS_FROM_FDT) += fdt.o \
67+
$(patsubst %.c,lib-%.o,$(libfdt-deps))
6468

6569
$(obj)/lib-%.o: $(srctree)/lib/%.c FORCE
6670
$(call if_changed_rule,cc_o_c)
6771

68-
lib-$(CONFIG_EFI_GENERIC_STUB) += efi-stub.o fdt.o string.o intrinsics.o \
69-
$(patsubst %.c,lib-%.o,$(efi-deps-y)) \
70-
systable.o
72+
lib-$(CONFIG_EFI_GENERIC_STUB) += efi-stub.o string.o intrinsics.o systable.o
7173

7274
lib-$(CONFIG_ARM) += arm32-stub.o
7375
lib-$(CONFIG_ARM64) += arm64-stub.o

drivers/firmware/efi/libstub/arm64-stub.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,17 @@ efi_status_t check_platform_features(void)
4242
*/
4343
static bool check_image_region(u64 base, u64 size)
4444
{
45-
unsigned long map_size, desc_size, buff_size;
46-
efi_memory_desc_t *memory_map;
47-
struct efi_boot_memmap map;
45+
struct efi_boot_memmap *map;
4846
efi_status_t status;
4947
bool ret = false;
5048
int map_offset;
5149

52-
map.map = &memory_map;
53-
map.map_size = &map_size;
54-
map.desc_size = &desc_size;
55-
map.desc_ver = NULL;
56-
map.key_ptr = NULL;
57-
map.buff_size = &buff_size;
58-
59-
status = efi_get_memory_map(&map);
50+
status = efi_get_memory_map(&map, false);
6051
if (status != EFI_SUCCESS)
6152
return false;
6253

63-
for (map_offset = 0; map_offset < map_size; map_offset += desc_size) {
64-
efi_memory_desc_t *md = (void *)memory_map + map_offset;
54+
for (map_offset = 0; map_offset < map->map_size; map_offset += map->desc_size) {
55+
efi_memory_desc_t *md = (void *)map->map + map_offset;
6556
u64 end = md->phys_addr + md->num_pages * EFI_PAGE_SIZE;
6657

6758
/*
@@ -74,7 +65,7 @@ static bool check_image_region(u64 base, u64 size)
7465
}
7566
}
7667

77-
efi_bs_call(free_pool, memory_map);
68+
efi_bs_call(free_pool, map);
7869

7970
return ret;
8071
}

0 commit comments

Comments
 (0)