* [PATCH 00/15] efi: loader preparatory patches
@ 2025-05-27 21:22 Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 01/15] lib: wchar: add wide char string comparison functions Ahmad Fatoum
` (14 more replies)
0 siblings, 15 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox
A random collection of patches in preparation for EFI loader support.
Ahmad Fatoum (15):
lib: wchar: add wide char string comparison functions
ARM: select HW_HAS_PCI architecture wide
efi: types: define efi_char16_t as wchar_t
efi: types: document efi_physical_addr_t being always 64-bit
efi: payload: early-mem: EFI_ALLOCATE_ANY_PAGES on non-x86
string: implement kmemdup_nul
efi: types: implement efi_phys_to_virt/efi_virt_to_phys helpers
efi: return pointer from efi_earlymem_alloc
efi: payload: image: use new efi_phys_to_virt helper
efi: payload: iomem: use virt_start if set
efi: use size_t for UINTN array sizes instead of unsigned long
efi: payload: unify duplicate code in ifdef
efi: payload: use efi_virt_to_phys instead of pointer to u64 casts
clocksource: efi: use DIV_ROUND_DOWN_ULL for 64-bit devision
efi: payload: use ktime_to_us to avoid plain 64-bit division
arch/arm/Kconfig | 5 +---
arch/arm/mach-imx/Kconfig | 3 ---
arch/arm/mach-rockchip/Kconfig | 2 --
commands/efi_handle_dump.c | 8 +++----
drivers/clocksource/efi.c | 2 +-
drivers/efi/efi-device.c | 17 +++++++-------
drivers/efi/efi-handle.c | 4 ++--
drivers/serial/serial_efi.c | 10 ++++----
drivers/video/efi_gop.c | 10 ++++----
efi/payload/early-mem.c | 17 +++++++++-----
efi/payload/entry-multi.c | 4 ++--
efi/payload/entry-single.c | 4 ++--
efi/payload/image.c | 38 ++++++++++++------------------
efi/payload/init.c | 7 +++---
efi/payload/iomem.c | 11 +++++----
fs/efi.c | 12 +++++-----
fs/efivarfs.c | 6 ++---
include/efi.h | 32 +++++++++++++-------------
include/efi/efi-device.h | 2 +-
include/efi/efi-payload.h | 5 ++--
include/efi/types.h | 21 +++++++++++++++--
include/linux/string.h | 6 +++++
include/wchar.h | 3 +++
lib/string.c | 42 +++++++++++++++++++++-------------
lib/wchar.c | 26 +++++++++++++++++++++
25 files changed, 173 insertions(+), 124 deletions(-)
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 01/15] lib: wchar: add wide char string comparison functions
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 02/15] ARM: select HW_HAS_PCI architecture wide Ahmad Fatoum
` (13 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
For use by the EFI code, implement string comparison for wide character
strings.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
include/wchar.h | 3 +++
lib/wchar.c | 26 ++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/include/wchar.h b/include/wchar.h
index 392211039a61..02818815e183 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -24,4 +24,7 @@ size_t wcsnlen(const wchar_t *s, size_t maxlen);
int mbtowc(wchar_t *pwc, const char *s, size_t n);
int wctomb(char *s, wchar_t wc);
+int wcscmp (const wchar_t *s1, const wchar_t *s2);
+int wcsncmp (const wchar_t *s1, const wchar_t *s2, size_t n);
+
#endif /* __WCHAR_H */
diff --git a/lib/wchar.c b/lib/wchar.c
index 49e946a09424..96db8116286a 100644
--- a/lib/wchar.c
+++ b/lib/wchar.c
@@ -124,3 +124,29 @@ char *strdup_wchar_to_char(const wchar_t *src)
return dst;
}
+
+int wcscmp(const wchar_t *s1, const wchar_t *s2)
+{
+ while (*s1 == *s2++) {
+ if (*s1++ == 0)
+ return 0;
+ }
+
+ return *s1 - *--s2;
+}
+
+int wcsncmp (const wchar_t *s1, const wchar_t *s2, size_t n)
+{
+ if (n == 0)
+ return 0;
+
+ do {
+ if (*s1 != *s2++)
+ return *s1 - *--s2;
+
+ if (*s1++ == 0)
+ break;
+ } while (--n != 0);
+
+ return 0;
+}
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 02/15] ARM: select HW_HAS_PCI architecture wide
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 01/15] lib: wchar: add wide char string comparison functions Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 03/15] efi: types: define efi_char16_t as wchar_t Ahmad Fatoum
` (12 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
HAVE_PCI mostly means that the architecture provides <asm/pci.h>.
There still needs to be a driver that actually makes use of this.
Instead of adding HW_HAS_PCI on a SoC by SoC basis and missing some
(e.g. ARM Virt 32-bit), let's just enable it architecture-wide as
<asm/pci.h> is available for all our ARM platforms too.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
arch/arm/Kconfig | 5 +----
arch/arm/mach-imx/Kconfig | 3 ---
arch/arm/mach-rockchip/Kconfig | 2 --
3 files changed, 1 insertion(+), 9 deletions(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 0800b15d784c..2bcd5862bdd1 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -14,6 +14,7 @@ config ARM
select PBL_RELOCATABLE
select USE_COMPRESSED_DTB
select HAVE_ARCH_BOARD_GENERIC_DT if OFDEVICE
+ select HW_HAS_PCI
default y
config ARCH_LINUX_NAME
@@ -88,7 +89,6 @@ config ARCH_MVEBU
select COMMON_CLK_OF_PROVIDER
select GPIOLIB
select HAS_DEBUG_LL
- select HW_HAS_PCI
select MVEBU_MBUS
select OFTREE
select OF_ADDRESS_PCI
@@ -120,7 +120,6 @@ config ARCH_TEGRA
depends on 32BIT
select CPU_V7
select HAS_DEBUG_LL
- select HW_HAS_PCI
select COMMON_CLK
select COMMON_CLK_OF_PROVIDER
select GPIOLIB
@@ -144,7 +143,6 @@ config ARCH_ARM64_VIRT
select CPU_V8
select ARM_AMBA
select BOARD_ARM_VIRT
- select HW_HAS_PCI
select HAS_DEBUG_LL
select COMMON_CLK
select COMMON_CLK_OF_PROVIDER
@@ -192,7 +190,6 @@ config ARCH_LAYERSCAPE
select HAS_DEBUG_LL
select COMMON_CLK
select COMMON_CLK_OF_PROVIDER
- select HW_HAS_PCI
select OF_DMA_COHERENCY
config ARCH_OMAP_MULTI
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 552e7227a022..abe44c846561 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -126,7 +126,6 @@ config ARCH_IMX6
select CPU_V7
select PINCTRL_IMX_IOMUX_V3
select COMMON_CLK_OF_PROVIDER
- select HW_HAS_PCI
select PBL_VERIFY_PIGGY if HABV4
config ARCH_IMX6SL
@@ -149,7 +148,6 @@ config ARCH_IMX7
select COMMON_CLK_OF_PROVIDER
select ARCH_HAS_FEC_IMX
select ARCH_HAS_IMX_GPT
- select HW_HAS_PCI
config ARCH_IMX8M
bool
@@ -157,7 +155,6 @@ config ARCH_IMX8M
select PINCTRL_IMX_IOMUX_V3
select COMMON_CLK_OF_PROVIDER
select ARCH_HAS_FEC_IMX
- select HW_HAS_PCI
select IMX8M_DRAM
select PBL_VERIFY_PIGGY if HABV4
select SOC_BUS
diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index 98dfd11c182b..7390ace41427 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -30,12 +30,10 @@ config ARCH_ROCKCHIP_V8
config ARCH_RK3568
bool
select ARCH_ROCKCHIP_V8
- select HW_HAS_PCI
config ARCH_RK3588
bool
select ARCH_ROCKCHIP_V8
- select HW_HAS_PCI
comment "select Rockchip boards:"
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 03/15] efi: types: define efi_char16_t as wchar_t
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 01/15] lib: wchar: add wide char string comparison functions Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 02/15] ARM: select HW_HAS_PCI architecture wide Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 04/15] efi: types: document efi_physical_addr_t being always 64-bit Ahmad Fatoum
` (11 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
We are using wchar_t internally for 16-bit wide strings, so let's align
efi_char16_t with that.
No functional change expected.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
include/efi/types.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/efi/types.h b/include/efi/types.h
index 3309820416be..ddd8dd7bcb62 100644
--- a/include/efi/types.h
+++ b/include/efi/types.h
@@ -7,7 +7,7 @@
#include <linux/uuid.h>
typedef unsigned long efi_status_t;
-typedef u16 efi_char16_t; /* UNICODE character */
+typedef wchar_t efi_char16_t; /* UNICODE character */
typedef u64 efi_physical_addr_t;
struct efi_object;
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 04/15] efi: types: document efi_physical_addr_t being always 64-bit
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
` (2 preceding siblings ...)
2025-05-27 21:22 ` [PATCH 03/15] efi: types: define efi_char16_t as wchar_t Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 05/15] efi: payload: early-mem: EFI_ALLOCATE_ANY_PAGES on non-x86 Ahmad Fatoum
` (10 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
Unlike UINTN (size_t), efi_physical_addr_t doesn't change size
depending on whether the system is 32- or 64-bit.
Add a comment to clarify this.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
include/efi/types.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/efi/types.h b/include/efi/types.h
index ddd8dd7bcb62..c845d08d62b6 100644
--- a/include/efi/types.h
+++ b/include/efi/types.h
@@ -8,7 +8,7 @@
typedef unsigned long efi_status_t;
typedef wchar_t efi_char16_t; /* UNICODE character */
-typedef u64 efi_physical_addr_t;
+typedef u64 efi_physical_addr_t; /* always, even on 32-bit systems */
struct efi_object;
typedef struct efi_object *efi_handle_t;
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 05/15] efi: payload: early-mem: EFI_ALLOCATE_ANY_PAGES on non-x86
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
` (3 preceding siblings ...)
2025-05-27 21:22 ` [PATCH 04/15] efi: types: document efi_physical_addr_t being always 64-bit Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 06/15] string: implement kmemdup_nul Ahmad Fatoum
` (9 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
Using EFI_ALLOCATE_MAX_ADDRESS with an address of ~0 means that the EFI
implementation is free to give us any region it sees fit, so let's use
EFI_ALLOCATE_ANY_PAGES explicitly instead to make this clearer.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
efi/payload/early-mem.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/efi/payload/early-mem.c b/efi/payload/early-mem.c
index b4e8790a39c4..52052f7ed128 100644
--- a/efi/payload/early-mem.c
+++ b/efi/payload/early-mem.c
@@ -9,13 +9,18 @@ efi_physical_addr_t efi_earlymem_alloc(const struct efi_system_table *sys_table,
size_t *memsize)
{
struct efi_boot_services *bs = sys_table->boottime;
+ enum efi_allocate_type alloc_type = EFI_ALLOCATE_ANY_PAGES;
efi_physical_addr_t mem;
efi_status_t efiret;
- mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
+ if (IS_ENABLED(CONFIG_X86)) {
+ /* Try to stay clear of memory mapped devices */
+ alloc_type = EFI_ALLOCATE_MAX_ADDRESS;
+ mem = SZ_1G - 1;
+ }
+
for (*memsize = SZ_256M; *memsize >= SZ_8M; *memsize /= 2) {
- efiret = bs->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
- EFI_LOADER_DATA,
+ efiret = bs->allocate_pages(alloc_type, EFI_LOADER_DATA,
*memsize / EFI_PAGE_SIZE, &mem);
if (!EFI_ERROR(efiret) || efiret != EFI_OUT_OF_RESOURCES)
break;
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 06/15] string: implement kmemdup_nul
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
` (4 preceding siblings ...)
2025-05-27 21:22 ` [PATCH 05/15] efi: payload: early-mem: EFI_ALLOCATE_ANY_PAGES on non-x86 Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 07/15] efi: types: implement efi_phys_to_virt/efi_virt_to_phys helpers Ahmad Fatoum
` (8 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
Unlike memdup and strdup, memdup_nul ensures that the output is NUL
terminated, while not expecting the input to be so.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
include/linux/string.h | 6 ++++++
lib/string.c | 42 ++++++++++++++++++++++++++----------------
2 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index 0fa84f095e02..953484ebc9f6 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -175,6 +175,12 @@ static inline void *memdup(const void *buf, size_t size)
}
#endif
+extern char *memdup_nul(const char *s, size_t len);
+static inline char *kmemdup_nul(const char *s, size_t len, gfp_t gfp)
+{
+ return memdup_nul(s, len);
+}
+
#define memdup_array(arr, count) memdup(arr, array_size(count, sizeof(*arr)));
static inline void *kmemdup(const void *src, size_t len, gfp_t gfp)
diff --git a/lib/string.c b/lib/string.c
index f2272be37e76..33d61add8189 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -423,42 +423,52 @@ size_t strnlen(const char * s, size_t count)
#endif
EXPORT_SYMBOL(strnlen);
-#ifndef __HAVE_ARCH_STRDUP
-char * strdup(const char *s)
+static __always_inline char *__memdup_nul(const char *s, size_t len)
{
char *new;
if ((s == NULL) ||
- ((new = malloc (strlen(s) + 1)) == NULL) ) {
+ ((new = malloc (len + 1)) == NULL) ) {
return NULL;
}
- strcpy (new, s);
+ memcpy (new, s, len);
+ /* Ensure the buf is always NUL-terminated, regardless of @s. */
+ new[len] = '\0';
return new;
}
+
+#ifndef __HAVE_ARCH_STRDUP
+char * strdup(const char *s)
+{
+ return s ? __memdup_nul(s, strlen(s)) : NULL;
+}
#endif
EXPORT_SYMBOL(strdup);
#ifndef __HAVE_ARCH_STRNDUP
char *strndup(const char *s, size_t n)
{
- char *new;
- size_t len = strnlen(s, n);
-
- if ((s == NULL) ||
- ((new = malloc(len + 1)) == NULL)) {
- return NULL;
- }
-
- memcpy(new, s, len);
- new[len] = '\0';
-
- return new;
+ return s ? __memdup_nul(s, strnlen(s, n)) : NULL;
}
#endif
EXPORT_SYMBOL(strndup);
+/**
+ * memdup_nul - Create a NUL-terminated string from @s, which might be unterminated.
+ * @s: The data to copy
+ * @len: The size of the data, not including the NUL terminator
+ *
+ * Return: newly allocated copy of @s with NUL-termination or %NULL in
+ * case of error
+ */
+char *memdup_nul(const char *s, size_t n)
+{
+ return s ? __memdup_nul(s, n) : NULL;
+}
+EXPORT_SYMBOL(memdup_nul);
+
#ifndef __HAVE_ARCH_STRSPN
/**
* strspn - Calculate the length of the initial substring of @s which only
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 07/15] efi: types: implement efi_phys_to_virt/efi_virt_to_phys helpers
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
` (5 preceding siblings ...)
2025-05-27 21:22 ` [PATCH 06/15] string: implement kmemdup_nul Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 08/15] efi: return pointer from efi_earlymem_alloc Ahmad Fatoum
` (7 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
From: Ahmad Fatoum <ahmad@a3f.at>
We shouldn't have any physical addresses exceeding 32-bit on 64-bit
systems, especially as barebox doesn't implement ARM32 LPAE.
Add helpers to convert between the types to be able to drop casts and
checks in the code.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
include/efi/types.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/include/efi/types.h b/include/efi/types.h
index c845d08d62b6..85aaf32f8f1d 100644
--- a/include/efi/types.h
+++ b/include/efi/types.h
@@ -2,7 +2,11 @@
#ifndef _EFI_TYPES_H_
#define _EFI_TYPES_H_
+#ifndef __ASSEMBLY__
+
#include <linux/types.h>
+#include <linux/limits.h>
+#include <linux/stddef.h>
#include <linux/compiler.h>
#include <linux/uuid.h>
@@ -65,4 +69,17 @@ union efi_ip_address {
struct efi_ipv6_address v6;
};
+static inline void *efi_phys_to_virt(efi_physical_addr_t addr)
+{
+ if (addr > UINTPTR_MAX)
+ __builtin_trap();
+
+ return (void *)(uintptr_t)addr;
+}
+
+static inline efi_physical_addr_t efi_virt_to_phys(const void *addr)
+{
+ return (uintptr_t)addr;
+}
+
#endif
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 08/15] efi: return pointer from efi_earlymem_alloc
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
` (6 preceding siblings ...)
2025-05-27 21:22 ` [PATCH 07/15] efi: types: implement efi_phys_to_virt/efi_virt_to_phys helpers Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 09/15] efi: payload: image: use new efi_phys_to_virt helper Ahmad Fatoum
` (6 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox
Returning a pointer for a memory allocation function makes more sense.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
efi/payload/early-mem.c | 6 +++---
efi/payload/entry-multi.c | 4 ++--
efi/payload/entry-single.c | 4 ++--
include/efi/efi-payload.h | 3 +--
4 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/efi/payload/early-mem.c b/efi/payload/early-mem.c
index 52052f7ed128..6229fd43a587 100644
--- a/efi/payload/early-mem.c
+++ b/efi/payload/early-mem.c
@@ -5,8 +5,8 @@
#include <efi.h>
#include <efi/efi-payload.h>
-efi_physical_addr_t efi_earlymem_alloc(const struct efi_system_table *sys_table,
- size_t *memsize)
+void *efi_earlymem_alloc(const struct efi_system_table *sys_table,
+ size_t *memsize)
{
struct efi_boot_services *bs = sys_table->boottime;
enum efi_allocate_type alloc_type = EFI_ALLOCATE_ANY_PAGES;
@@ -29,5 +29,5 @@ efi_physical_addr_t efi_earlymem_alloc(const struct efi_system_table *sys_table,
panic("failed to allocate %zu byte memory pool: 0x%lx\n",
*memsize, efiret);
- return mem;
+ return efi_phys_to_virt(mem);
}
diff --git a/efi/payload/entry-multi.c b/efi/payload/entry-multi.c
index 26cf2ebfa764..2eb9dccc08a0 100644
--- a/efi/payload/entry-multi.c
+++ b/efi/payload/entry-multi.c
@@ -24,7 +24,7 @@ static void efi_putc(void *ctx, int ch)
void __efistub_efi_pe_entry(void *image, struct efi_system_table *sys_table)
{
size_t memsize;
- efi_physical_addr_t mem;
+ void *mem;
static struct barebox_efi_data efidata;
#ifdef DEBUG
@@ -39,5 +39,5 @@ void __efistub_efi_pe_entry(void *image, struct efi_system_table *sys_table)
mem = efi_earlymem_alloc(sys_table, &memsize);
- barebox_pbl_entry(mem, memsize, NULL);
+ barebox_pbl_entry((uintptr_t)mem, memsize, NULL);
}
diff --git a/efi/payload/entry-single.c b/efi/payload/entry-single.c
index cb7981e03060..c95672b9fe66 100644
--- a/efi/payload/entry-single.c
+++ b/efi/payload/entry-single.c
@@ -18,7 +18,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
{
efi_status_t efiret;
size_t memsize;
- efi_physical_addr_t mem;
+ void *mem;
#ifdef DEBUG
sys_table->con_out->output_string(sys_table->con_out, L"barebox\n");
@@ -39,7 +39,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
mem = efi_earlymem_alloc(sys_table, &memsize);
- mem_malloc_init((void *)mem, (void *)mem + memsize - 1);
+ mem_malloc_init(mem, mem + memsize - 1);
start_barebox();
}
diff --git a/include/efi/efi-payload.h b/include/efi/efi-payload.h
index 73b1b9bd8e74..313ba7f4abc2 100644
--- a/include/efi/efi-payload.h
+++ b/include/efi/efi-payload.h
@@ -30,7 +30,6 @@ int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
void *buf, unsigned long size);
int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec);
-efi_physical_addr_t efi_earlymem_alloc(const struct efi_system_table *sys_table,
- size_t *memsize);
+void *efi_earlymem_alloc(const struct efi_system_table *sys_table, size_t *memsize);
#endif
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 09/15] efi: payload: image: use new efi_phys_to_virt helper
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
` (7 preceding siblings ...)
2025-05-27 21:22 ` [PATCH 08/15] efi: return pointer from efi_earlymem_alloc Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 10/15] efi: payload: iomem: use virt_start if set Ahmad Fatoum
` (5 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
efi/payload/image.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/efi/payload/image.c b/efi/payload/image.c
index 70b57360c99d..20ef2a878c11 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -101,7 +101,7 @@ static void *efi_read_file(const char *file, size_t *size)
return NULL;
}
- buf = (void *)mem;
+ buf = efi_phys_to_virt(mem);
ret = read_file_into_buf(file, buf, s.st_size);
if (ret < 0)
@@ -113,7 +113,7 @@ static void *efi_read_file(const char *file, size_t *size)
static void efi_free_file(void *_mem, size_t size)
{
- efi_physical_addr_t mem = (efi_physical_addr_t)_mem;
+ efi_physical_addr_t mem = efi_virt_to_phys(_mem);
if (mem_malloc_start() <= mem && mem < mem_malloc_end())
free(_mem);
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 10/15] efi: payload: iomem: use virt_start if set
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
` (8 preceding siblings ...)
2025-05-27 21:22 ` [PATCH 09/15] efi: payload: image: use new efi_phys_to_virt helper Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 11/15] efi: use size_t for UINTN array sizes instead of unsigned long Ahmad Fatoum
` (4 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
If the EFI firmware populates virt_start, we should use that in
preference to phys_start as not to assume a 1:1 mapping.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
efi/payload/iomem.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/efi/payload/iomem.c b/efi/payload/iomem.c
index 832f6db72b76..888aa8569ebb 100644
--- a/efi/payload/iomem.c
+++ b/efi/payload/iomem.c
@@ -25,9 +25,10 @@ static int efi_parse_mmap(struct efi_memory_desc *desc, bool verbose)
return 0;
/* XXX At least OVMF doesn't populate ->virt_start and leaves it at zero
- * for all mapping. Thus assume a 1:1 mapping and ignore virt_start
+ * for all mappings. Handles this by assume a 1:1 mapping and falling
+ * back to phys_start.
*/
- va_base = desc->phys_start;
+ va_base = (uintptr_t)desc->virt_start ?: desc->phys_start;
switch (desc->type) {
case EFI_RESERVED_TYPE:
@@ -124,9 +125,9 @@ static int efi_parse_mmap(struct efi_memory_desc *desc, bool verbose)
flags = IORESOURCE_MEM | IORESOURCE_ROM_BIOS_COPY;
}
- fullname = xasprintf("%s@%llx", name, desc->phys_start);
+ fullname = xasprintf("%s@%llx", name, (u64)va_base);
- pr_debug("%s: (0x%llx+0x%llx)\n", fullname, va_base, va_size);
+ pr_debug("%s: (%pad+%pad)\n", fullname, &va_base, &va_size);
res = request_iomem_region(fullname, va_base, va_base + va_size - 1);
if (IS_ERR(res)) {
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 11/15] efi: use size_t for UINTN array sizes instead of unsigned long
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
` (9 preceding siblings ...)
2025-05-27 21:22 ` [PATCH 10/15] efi: payload: iomem: use virt_start if set Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 12/15] efi: payload: unify duplicate code in ifdef Ahmad Fatoum
` (3 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
UINTN is the native register wide integer type. We don't have a specific
typedef for this in barebox, instead using size_t in places and unsigned
long in others.
The type confusion is no problem on 64-bit platforms, where size_t is
just a typedef for long. On 32-bit platforms, size_t is a typedef for
int, which while having the same size as long, is a different type,
which leads to compiler warning and errors regarding use of different
types for pointer arguments or in printf format strings.
The nice way out would have just define the size_t type as alias for
unsigned long everywhere, but this leads to false positive printf format
string warnings, so let's clean up the EFI UINTN type usage:
- Everywhere, where the UINTN is used for an array size or buffer
length, use size_t
- Everywhere else keep it as unsigned long. In future, these types may
be replaces by more specific typedefs.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
commands/efi_handle_dump.c | 8 ++++----
drivers/efi/efi-device.c | 17 ++++++++---------
drivers/efi/efi-handle.c | 4 ++--
drivers/serial/serial_efi.c | 10 +++++-----
drivers/video/efi_gop.c | 10 +++++-----
efi/payload/init.c | 4 ++--
efi/payload/iomem.c | 2 +-
fs/efi.c | 12 ++++++------
fs/efivarfs.c | 6 +++---
include/efi.h | 32 ++++++++++++++++----------------
include/efi/efi-device.h | 2 +-
include/efi/efi-payload.h | 2 +-
12 files changed, 54 insertions(+), 55 deletions(-)
diff --git a/commands/efi_handle_dump.c b/commands/efi_handle_dump.c
index a9db5eb75b69..30abf9000387 100644
--- a/commands/efi_handle_dump.c
+++ b/commands/efi_handle_dump.c
@@ -33,10 +33,10 @@ static void efi_devpath(struct efi_boot_services *bs,
}
}
-static void efi_dump(struct efi_boot_services *bs, efi_handle_t *handles, unsigned long handle_count)
+static void efi_dump(struct efi_boot_services *bs, efi_handle_t *handles, size_t handle_count)
{
int i, j;
- unsigned long num_guids;
+ size_t num_guids;
efi_guid_t **guids;
if (!handles || !handle_count)
@@ -61,7 +61,7 @@ static void efi_dump(struct efi_boot_services *bs, efi_handle_t *handles, unsign
static int do_efi_protocol_dump(struct efi_boot_services *bs, int argc, char **argv)
{
- unsigned long handle_count = 0;
+ size_t handle_count = 0;
efi_handle_t *handles = NULL;
int ret;
efi_guid_t guid;
@@ -110,7 +110,7 @@ static int do_efi_protocol_dump(struct efi_boot_services *bs, int argc, char **a
static int do_efi_handle_dump(int argc, char *argv[])
{
- unsigned long handle_count = 0;
+ size_t handle_count = 0;
efi_handle_t *handles = NULL;
struct efi_boot_services *bs;
int ret;
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 6dfcf22d3baf..d5eda66cd55a 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -23,7 +23,7 @@
static int efi_locate_handle(enum efi_locate_search_type search_type,
efi_guid_t *protocol,
void *search_key,
- unsigned long *no_handles,
+ size_t *no_handles,
efi_handle_t **buffer)
{
return __efi_locate_handle(BS, search_type, protocol, search_key, no_handles,
@@ -59,14 +59,14 @@ static void efi_devinfo(struct device *dev)
static efi_handle_t efi_find_parent(efi_handle_t handle)
{
- unsigned long handle_count = 0;
+ size_t i, handle_count = 0;
efi_handle_t *handles = NULL, parent;
- unsigned long num_guids;
+ size_t j, num_guids;
efi_guid_t **guids;
- int ret, i, j, k;
+ int ret;
efi_status_t efiret;
struct efi_open_protocol_information_entry *entry_buffer;
- unsigned long entry_count;
+ size_t k, entry_count;
ret = efi_locate_handle(BY_PROTOCOL, &efi_device_path_protocol_guid,
NULL, &handle_count, &handles);
@@ -215,9 +215,9 @@ static int efi_register_device(struct efi_device *efidev)
*/
void efi_register_devices(void)
{
- unsigned long handle_count = 0;
+ size_t handle_count = 0;
efi_handle_t *handles = NULL;
- unsigned long num_guids;
+ size_t num_guids;
efi_guid_t **guids;
int ret, i;
struct efi_device **efidevs;
@@ -264,9 +264,8 @@ void efi_register_devices(void)
int efi_connect_all(void)
{
efi_status_t efiret;
- unsigned long handle_count;
+ size_t i, handle_count;
efi_handle_t *handle_buffer;
- int i;
efiret = BS->locate_handle_buffer(ALL_HANDLES, NULL, NULL, &handle_count,
&handle_buffer);
diff --git a/drivers/efi/efi-handle.c b/drivers/efi/efi-handle.c
index be9013cb648f..6485e97ded3f 100644
--- a/drivers/efi/efi-handle.c
+++ b/drivers/efi/efi-handle.c
@@ -13,11 +13,11 @@ int __efi_locate_handle(struct efi_boot_services *bs,
enum efi_locate_search_type search_type,
efi_guid_t *protocol,
void *search_key,
- unsigned long *no_handles,
+ size_t *no_handles,
efi_handle_t **buffer)
{
efi_status_t efiret;
- unsigned long buffer_size = 0;
+ size_t buffer_size = 0;
efi_handle_t *buf;
efiret = bs->locate_handle(search_type, protocol, search_key, &buffer_size,
diff --git a/drivers/serial/serial_efi.c b/drivers/serial/serial_efi.c
index 6ed068f159f2..a0abbaf649d3 100644
--- a/drivers/serial/serial_efi.c
+++ b/drivers/serial/serial_efi.c
@@ -75,9 +75,9 @@ struct efi_serial_io_protocol {
efi_status_t (EFIAPI *getcontrol) (struct efi_serial_io_protocol *This,
uint32_t *control);
efi_status_t (EFIAPI *write) (struct efi_serial_io_protocol *This,
- unsigned long *buffersize, void *buffer);
+ size_t *buffersize, void *buffer);
efi_status_t (EFIAPI *read) (struct efi_serial_io_protocol *This,
- unsigned long *buffersize, void *buffer);
+ size_t *buffersize, void *buffer);
struct efi_serial_io_mode *mode;
};
@@ -117,7 +117,7 @@ static void efi_serial_putc(struct console_device *cdev, char c)
struct efi_serial_io_protocol *serial = uart->serial;
uint32_t control;
efi_status_t efiret;
- unsigned long buffersize = sizeof(char);
+ size_t buffersize = sizeof(char);
do {
efiret = serial->getcontrol(serial, &control);
@@ -136,7 +136,7 @@ static int efi_serial_puts(struct console_device *cdev, const char *s,
struct efi_serial_io_protocol *serial = uart->serial;
uint32_t control;
efi_status_t efiret;
- unsigned long buffersize = nbytes;
+ size_t buffersize = nbytes;
do {
efiret = serial->getcontrol(serial, &control);
@@ -156,7 +156,7 @@ static int efi_serial_getc(struct console_device *cdev)
struct efi_serial_io_protocol *serial = uart->serial;
uint32_t control;
efi_status_t efiret;
- unsigned long buffersize = sizeof(char);
+ size_t buffersize = sizeof(char);
char c;
do {
diff --git a/drivers/video/efi_gop.c b/drivers/video/efi_gop.c
index cd2506c04b24..f4f58d9271f5 100644
--- a/drivers/video/efi_gop.c
+++ b/drivers/video/efi_gop.c
@@ -41,14 +41,14 @@ struct efi_graphics_output_protocol_mode {
uint32_t max_mode;
uint32_t mode;
struct efi_graphics_output_mode_info *info;
- unsigned long size_of_info;
+ size_t size_of_info;
void *frame_buffer_base;
- unsigned long frame_buffer_size;
+ size_t frame_buffer_size;
};
struct efi_graphics_output_protocol {
efi_status_t (EFIAPI *query_mode) (struct efi_graphics_output_protocol *This,
- uint32_t mode_number, unsigned long *size_of_info,
+ uint32_t mode_number, size_t *size_of_info,
struct efi_graphics_output_mode_info **info);
efi_status_t (EFIAPI *set_mode) (struct efi_graphics_output_protocol *This,
uint32_t mode_number);
@@ -147,7 +147,7 @@ static int efi_gop_query(struct efi_gop_priv *priv)
struct efi_graphics_output_protocol_mode *mode;
struct efi_graphics_output_mode_info *info;
efi_status_t efiret;
- unsigned long size = 0;
+ size_t size = 0;
int i;
struct fb_videomode *vmode;
@@ -180,7 +180,7 @@ static int efi_gop_fb_activate_var(struct fb_info *fb_info)
struct efi_gop_priv *priv = fb_info->priv;
struct efi_graphics_output_mode_info *info;
int num;
- unsigned long size = 0;
+ size_t size = 0;
efi_status_t efiret;
num = simple_strtoul(fb_info->mode->name, NULL, 0);
diff --git a/efi/payload/init.c b/efi/payload/init.c
index ae8b9203737b..6a616161e884 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -51,7 +51,7 @@ void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size)
{
efi_status_t efiret;
void *buf;
- unsigned long size = 0;
+ size_t size = 0;
s16 *name16 = xstrdup_char_to_wchar(name);
efiret = RT->get_variable(name16, vendor, NULL, &size, NULL);
@@ -84,7 +84,7 @@ void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size)
}
int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
- void *buf, unsigned long size)
+ void *buf, size_t size)
{
efi_status_t efiret = EFI_SUCCESS;
s16 *name16 = xstrdup_char_to_wchar(name);
diff --git a/efi/payload/iomem.c b/efi/payload/iomem.c
index 888aa8569ebb..64f4b809e0c2 100644
--- a/efi/payload/iomem.c
+++ b/efi/payload/iomem.c
@@ -147,7 +147,7 @@ static int efi_barebox_populate_mmap(void)
void *mmap_buf = NULL, *desc;
efi_status_t efiret;
size_t mmap_size;
- size_t mapkey;
+ ulong mapkey;
size_t descsz;
u32 descver;
int ret = 0;
diff --git a/fs/efi.c b/fs/efi.c
index 40f71ff241d3..da15c9078051 100644
--- a/fs/efi.c
+++ b/fs/efi.c
@@ -149,7 +149,7 @@ static int efifs_open(struct device *dev, struct file *f, const char *filename)
struct efifs_file *ufile;
wchar_t *efi_path = path_to_efi(filename);
struct efi_file_info *info;
- unsigned long bufsize = 1024;
+ size_t bufsize = 1024;
uint64_t efimode = EFI_FILE_MODE_READ;
int ret;
@@ -205,7 +205,7 @@ static int efifs_read(struct device *_dev, struct file *f, void *buf, size_t ins
{
struct efifs_file *ufile = f->private_data;
efi_status_t efiret;
- unsigned long bufsize = insize;
+ size_t bufsize = insize;
efiret = ufile->entry->read(ufile->entry, &bufsize, buf);
if (EFI_ERROR(efiret)) {
@@ -220,7 +220,7 @@ static int efifs_write(struct device *_dev, struct file *f, const void *buf,
{
struct efifs_file *ufile = f->private_data;
efi_status_t efiret;
- unsigned long bufsize = insize;
+ size_t bufsize = insize;
efiret = ufile->entry->write(ufile->entry, &bufsize, (void *)buf);
if (EFI_ERROR(efiret)) {
@@ -249,7 +249,7 @@ static int efifs_truncate(struct device *dev, struct file *f, loff_t size)
struct efifs_file *ufile = f->private_data;
efi_status_t efiret;
struct efi_file_info *info;
- unsigned long bufsize = 1024;
+ size_t bufsize = 1024;
int ret;
info = xzalloc(1024);
@@ -302,7 +302,7 @@ static struct dirent *efifs_readdir(struct device *dev, DIR *dir)
{
struct efifs_dir *udir = container_of(dir, struct efifs_dir, dir);
efi_status_t efiret;
- unsigned long bufsize = 256;
+ size_t bufsize = 256;
s16 buf[256];
struct efi_file_info *f;
@@ -336,7 +336,7 @@ static int efifs_stat(struct device *dev, const char *filename,
efi_status_t efiret;
struct efi_file_handle *entry;
struct efi_file_info *info;
- unsigned long bufsize = 1024;
+ size_t bufsize = 1024;
int ret;
info = xzalloc(1024);
diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index f5217ae91eda..9717a6340676 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -119,7 +119,7 @@ static int efivars_unlink(struct device *dev, const char *pathname)
struct efivars_file {
void *buf;
- unsigned long size;
+ size_t size;
efi_guid_t vendor;
s16 *name;
u32 attributes;
@@ -273,7 +273,7 @@ static int efivarfs_stat(struct device *dev, const char *filename,
efi_guid_t vendor;
s16 *name;
efi_status_t efiret;
- unsigned long size = 0;
+ size_t size = 0;
int ret;
ret = efivarfs_parse_filename(filename, &vendor, &name);
@@ -299,7 +299,7 @@ static int efivarfs_probe(struct device *dev)
efi_guid_t vendor;
s16 name[1024];
char *name8;
- unsigned long size;
+ size_t size;
struct efivarfs_priv *priv;
name[0] = 0;
diff --git a/include/efi.h b/include/efi.h
index 217e3d9f56ff..9015aebaa50b 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -193,12 +193,12 @@ struct efi_boot_services {
struct efi_table_hdr hdr;
efi_status_t (EFIAPI *raise_tpl)(unsigned long new_tpl);
void (EFIAPI *restore_tpl)(unsigned long old_tpl);
- efi_status_t (EFIAPI *allocate_pages)(int, int, unsigned long,
+ efi_status_t (EFIAPI *allocate_pages)(int, int, size_t,
efi_physical_addr_t *);
- efi_status_t (EFIAPI *free_pages)(efi_physical_addr_t, unsigned long);
+ efi_status_t (EFIAPI *free_pages)(efi_physical_addr_t, size_t);
efi_status_t (EFIAPI *get_memory_map)(size_t *, struct efi_memory_desc *,
- size_t *, size_t *, u32 *);
- efi_status_t (EFIAPI *allocate_pool)(int, unsigned long, void **);
+ ulong *, size_t *, u32 *);
+ efi_status_t (EFIAPI *allocate_pool)(int, size_t, void **);
efi_status_t (EFIAPI *free_pool)(void *);
#define EFI_EVT_TIMER 0x80000000
#define EFI_EVT_RUNTIME 0x40000000
@@ -240,18 +240,18 @@ struct efi_boot_services {
efi_status_t (EFIAPI *install_configuration_table)(const efi_guid_t *guid, void *table);
efi_status_t (EFIAPI *load_image)(bool boot_policiy, efi_handle_t parent_image,
struct efi_device_path *file_path, void *source_buffer,
- unsigned long source_size, efi_handle_t *image);
+ size_t source_size, efi_handle_t *image);
efi_status_t (EFIAPI *start_image)(efi_handle_t handle,
size_t *exitdata_size, u16 **exitdata);
efi_status_t(EFIAPI *exit)(efi_handle_t handle, efi_status_t exit_status,
- unsigned long exitdata_size, u16 *exitdata);
+ size_t exitdata_size, u16 *exitdata);
efi_status_t (EFIAPI *unload_image)(efi_handle_t handle);
efi_status_t (EFIAPI *exit_boot_services)(efi_handle_t, unsigned long);
void *get_next_monotonic_count;
efi_status_t (EFIAPI *stall)(unsigned long usecs);
efi_status_t (EFIAPI *set_watchdog_timer)(unsigned long timeout,
uint64_t watchdog_code,
- unsigned long data_size,
+ size_t data_size,
u16 *watchdog_data);
efi_status_t(EFIAPI *connect_controller)(efi_handle_t controller_handle,
efi_handle_t *driver_image_handle,
@@ -272,22 +272,22 @@ struct efi_boot_services {
efi_handle_t agent, efi_handle_t controller);
efi_status_t(EFIAPI *open_protocol_information)(efi_handle_t handle, const efi_guid_t *Protocol,
struct efi_open_protocol_information_entry **entry_buffer,
- unsigned long *entry_count);
+ size_t *entry_count);
efi_status_t (EFIAPI *protocols_per_handle)(efi_handle_t handle,
efi_guid_t ***protocol_buffer,
- unsigned long *protocols_buffer_count);
+ size_t *protocols_buffer_count);
efi_status_t (EFIAPI *locate_handle_buffer) (
enum efi_locate_search_type search_type,
const efi_guid_t *protocol, void *search_key,
- unsigned long *no_handles, efi_handle_t **buffer);
+ size_t *no_handles, efi_handle_t **buffer);
efi_status_t (EFIAPI *locate_protocol)(const efi_guid_t *protocol,
void *registration, void **protocol_interface);
efi_status_t (EFIAPI *install_multiple_protocol_interfaces)(efi_handle_t *handle, ...);
efi_status_t (EFIAPI *uninstall_multiple_protocol_interfaces)(efi_handle_t handle, ...);
efi_status_t (EFIAPI *calculate_crc32)(const void *data,
- unsigned long data_size, uint32_t *crc32);
- void (EFIAPI *copy_mem)(void *destination, const void *source, unsigned long length);
- void (EFIAPI *set_mem)(void *buffer, unsigned long size, uint8_t value);
+ size_t data_size, uint32_t *crc32);
+ void (EFIAPI *copy_mem)(void *destination, const void *source, size_t length);
+ void (EFIAPI *set_mem)(void *buffer, size_t size, uint8_t value);
void *create_event_ex;
};
@@ -670,7 +670,7 @@ struct efi_system_table {
struct efi_simple_text_output_protocol *std_err;
struct efi_runtime_services *runtime;
struct efi_boot_services *boottime;
- unsigned long nr_tables;
+ size_t nr_tables;
struct efi_config_table *tables;
};
@@ -840,9 +840,9 @@ struct efi_block_io_protocol {
efi_status_t(EFIAPI *reset)(struct efi_block_io_protocol *this,
bool ExtendedVerification);
efi_status_t(EFIAPI *read)(struct efi_block_io_protocol *this, u32 media_id,
- u64 lba, unsigned long buffer_size, void *buf);
+ u64 lba, size_t buffer_size, void *buf);
efi_status_t(EFIAPI *write)(struct efi_block_io_protocol *this, u32 media_id,
- u64 lba, unsigned long buffer_size, void *buf);
+ u64 lba, size_t buffer_size, void *buf);
efi_status_t(EFIAPI *flush)(struct efi_block_io_protocol *this);
};
diff --git a/include/efi/efi-device.h b/include/efi/efi-device.h
index a8fc99a0e12b..06903f48da64 100644
--- a/include/efi/efi-device.h
+++ b/include/efi/efi-device.h
@@ -66,7 +66,7 @@ int __efi_locate_handle(struct efi_boot_services *bs,
enum efi_locate_search_type search_type,
efi_guid_t *protocol,
void *search_key,
- unsigned long *no_handles,
+ size_t *no_handles,
efi_handle_t **buffer);
#endif /* __EFI_EFI_DEVICE_H */
diff --git a/include/efi/efi-payload.h b/include/efi/efi-payload.h
index 313ba7f4abc2..22cdceb71fe2 100644
--- a/include/efi/efi-payload.h
+++ b/include/efi/efi-payload.h
@@ -27,7 +27,7 @@ static inline void *efi_get_global_var(char *name, int *var_size)
}
int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
- void *buf, unsigned long size);
+ void *buf, size_t size);
int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec);
void *efi_earlymem_alloc(const struct efi_system_table *sys_table, size_t *memsize);
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 12/15] efi: payload: unify duplicate code in ifdef
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
` (10 preceding siblings ...)
2025-05-27 21:22 ` [PATCH 11/15] efi: use size_t for UINTN array sizes instead of unsigned long Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 13/15] efi: payload: use efi_virt_to_phys instead of pointer to u64 casts Ahmad Fatoum
` (2 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The two branches only differ in the addition of 512 bytes, so move that
into an IS_ENABLED() clause and remove the #ifdef.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
efi/payload/image.c | 23 ++++++-----------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/efi/payload/image.c b/efi/payload/image.c
index 20ef2a878c11..fa9a3ee1026d 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -215,7 +215,6 @@ static int efi_execute_image(enum filetype filetype, const char *file)
return -efi_errno(efiret);
}
-#ifdef __x86_64__
typedef void(*handover_fn)(void *image, struct efi_system_table *table,
struct linux_kernel_header *header);
@@ -223,25 +222,15 @@ static inline void linux_efi_handover(efi_handle_t handle,
struct linux_kernel_header *header)
{
handover_fn handover;
+ uintptr_t addr;
- handover = (handover_fn)((long)header->code32_start + 512 +
- header->handover_offset);
+ addr = header->code32_start + header->handover_offset;
+ if (IS_ENABLED(CONFIG_X86_64))
+ addr += 512;
+
+ handover = efi_phys_to_virt(addr);
handover(handle, efi_sys_table, header);
}
-#else
-typedef void(*handover_fn)(void *image, struct efi_system_table *table,
- struct linux_kernel_header *setup);
-
-static inline void linux_efi_handover(efi_handle_t handle,
- struct linux_kernel_header *header)
-{
- handover_fn handover;
-
- handover = (handover_fn)((long)header->code32_start +
- header->handover_offset);
- handover(handle, efi_sys_table, header);
-}
-#endif
static int do_bootm_efi(struct image_data *data)
{
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 13/15] efi: payload: use efi_virt_to_phys instead of pointer to u64 casts
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
` (11 preceding siblings ...)
2025-05-27 21:22 ` [PATCH 12/15] efi: payload: unify duplicate code in ifdef Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 14/15] clocksource: efi: use DIV_ROUND_DOWN_ULL for 64-bit devision Ahmad Fatoum
2025-05-27 21:23 ` [PATCH 15/15] efi: payload: use ktime_to_us to avoid plain 64-bit division Ahmad Fatoum
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
From: Ahmad Fatoum <ahmad@a3f.at>
Instead of casting pointers directly to integers, let's make use of the
newly introduced efi_virt_to_phys helper.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
efi/payload/image.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/efi/payload/image.c b/efi/payload/image.c
index fa9a3ee1026d..f039b8a8d26a 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -273,18 +273,18 @@ static int do_bootm_efi(struct image_data *data)
memcpy(initrd, tmp, size);
memset(initrd + size, 0, PAGE_ALIGN(size) - size);
free(tmp);
- boot_header->ramdisk_image = (uint64_t)initrd;
+ boot_header->ramdisk_image = efi_virt_to_phys(initrd);
boot_header->ramdisk_size = PAGE_ALIGN(size);
}
options = linux_bootargs_get();
if (options) {
- boot_header->cmd_line_ptr = (uint64_t)options;
+ boot_header->cmd_line_ptr = efi_virt_to_phys(options);
boot_header->cmdline_size = strlen(options);
}
- boot_header->code32_start = (uint64_t)loaded_image->image_base +
- (image_header->setup_sects+1) * 512;
+ boot_header->code32_start = efi_virt_to_phys(loaded_image->image_base +
+ (image_header->setup_sects+1) * 512);
if (bootm_verbose(data)) {
printf("\nStarting kernel at 0x%p", loaded_image->image_base);
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 14/15] clocksource: efi: use DIV_ROUND_DOWN_ULL for 64-bit devision
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
` (12 preceding siblings ...)
2025-05-27 21:22 ` [PATCH 13/15] efi: payload: use efi_virt_to_phys instead of pointer to u64 casts Ahmad Fatoum
@ 2025-05-27 21:22 ` Ahmad Fatoum
2025-05-27 21:23 ` [PATCH 15/15] efi: payload: use ktime_to_us to avoid plain 64-bit division Ahmad Fatoum
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:22 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
From: Ahmad Fatoum <ahmad@a3f.at>
The denominator freq is 64-bit, but this worked out ok so far, because
the driver was only used on 64-bit systems. Now that we want to start
compiling it for 32-bit as well, make the division work there as well.
Note that nb_100ns is a valid result and will instruct the EFI firmware
to expire the timer at the next tick.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/clocksource/efi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
index 1ac587a715f2..2f8bfdec489a 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi.c
@@ -74,7 +74,7 @@ static int efi_cs_init(struct clocksource *cs)
BS->close_event(efi_cs_evt);
return -ENODEV;
}
- nb_100ns = 10 * 1000 * 1000 / freq;
+ nb_100ns = DIV_ROUND_DOWN_ULL(10 * 1000 * 1000, freq);
pr_warn("EFI Event timer too slow freq = %llu Hz\n", freq);
efiret = BS->set_timer(efi_cs_evt, EFI_TIMER_PERIODIC, nb_100ns);
if (EFI_ERROR(efiret)) {
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 15/15] efi: payload: use ktime_to_us to avoid plain 64-bit division
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
` (13 preceding siblings ...)
2025-05-27 21:22 ` [PATCH 14/15] clocksource: efi: use DIV_ROUND_DOWN_ULL for 64-bit devision Ahmad Fatoum
@ 2025-05-27 21:23 ` Ahmad Fatoum
14 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 21:23 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
From: Ahmad Fatoum <ahmad@a3f.at>
The nanosecond time is a 64-bit quantity and dividing them by 1000
worked out so far, because we only did EFI on 64-bit systems.
Now that we want to start compiling it for 32-bit as well, make
the division work there as well.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
efi/payload/image.c | 3 ++-
efi/payload/init.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/efi/payload/image.c b/efi/payload/image.c
index f039b8a8d26a..33c5e18dac27 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -8,6 +8,7 @@
#include <clock.h>
#include <common.h>
#include <linux/sizes.h>
+#include <linux/ktime.h>
#include <memory.h>
#include <command.h>
#include <magicvar.h>
@@ -302,7 +303,7 @@ static int do_bootm_efi(struct image_data *data)
}
efi_set_variable_usec("LoaderTimeExecUSec", &efi_systemd_vendor_guid,
- get_time_ns()/1000);
+ ktime_to_us(ktime_get()));
shutdown_barebox();
linux_efi_handover(handle, boot_header);
diff --git a/efi/payload/init.c b/efi/payload/init.c
index 6a616161e884..239c5ce9ec18 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -14,6 +14,7 @@
#include <linux/linkage.h>
#include <common.h>
#include <linux/sizes.h>
+#include <linux/ktime.h>
#include <memory.h>
#include <clock.h>
#include <command.h>
@@ -310,7 +311,7 @@ static int efi_postcore_init(void)
EFI_LOADER_FEATURE_DEVICETREE;
efi_set_variable_usec("LoaderTimeInitUSec", &efi_systemd_vendor_guid,
- get_time_ns()/1000);
+ ktime_to_us(ktime_get()));
efi_set_variable_printf("LoaderInfo", &efi_systemd_vendor_guid,
"barebox-" UTS_RELEASE);
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2025-05-27 21:32 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-27 21:22 [PATCH 00/15] efi: loader preparatory patches Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 01/15] lib: wchar: add wide char string comparison functions Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 02/15] ARM: select HW_HAS_PCI architecture wide Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 03/15] efi: types: define efi_char16_t as wchar_t Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 04/15] efi: types: document efi_physical_addr_t being always 64-bit Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 05/15] efi: payload: early-mem: EFI_ALLOCATE_ANY_PAGES on non-x86 Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 06/15] string: implement kmemdup_nul Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 07/15] efi: types: implement efi_phys_to_virt/efi_virt_to_phys helpers Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 08/15] efi: return pointer from efi_earlymem_alloc Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 09/15] efi: payload: image: use new efi_phys_to_virt helper Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 10/15] efi: payload: iomem: use virt_start if set Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 11/15] efi: use size_t for UINTN array sizes instead of unsigned long Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 12/15] efi: payload: unify duplicate code in ifdef Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 13/15] efi: payload: use efi_virt_to_phys instead of pointer to u64 casts Ahmad Fatoum
2025-05-27 21:22 ` [PATCH 14/15] clocksource: efi: use DIV_ROUND_DOWN_ULL for 64-bit devision Ahmad Fatoum
2025-05-27 21:23 ` [PATCH 15/15] efi: payload: use ktime_to_us to avoid plain 64-bit division Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox