git: 6366114c716f - main - efi: Use EDK2 EFI_GUID instead of sturct uuid
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 01 May 2025 18:06:39 UTC
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=6366114c716f9dca099a4090269a700b94a6173f commit 6366114c716f9dca099a4090269a700b94a6173f Author: Warner Losh <imp@FreeBSD.org> AuthorDate: 2025-05-01 17:53:28 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2025-05-01 17:53:28 +0000 efi: Use EDK2 EFI_GUID instead of sturct uuid So, while struct uuid and EFI_GUID are quite similar (they are the same size, they have the same binary representation, etc), they aren not identical. Speciifcally, the UUID and GUID defines are slightly different and can't be swapped one for the other. Start to use EFI_GUID for all EFI tables. This will allow increased sharing with the boot laoder that already uses EDK2 variants as well as using the possibility to use the EDK2 headers we've already imported more easily. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D50037 --- sys/dev/efidev/efidev.c | 2 +- sys/dev/efidev/efirt.c | 18 +++++++++--------- sys/dev/ipmi/ipmi_smbios.c | 3 +-- sys/dev/smbios/smbios.c | 4 ++-- sys/sys/efi.h | 36 ++++++++++++++++++++++++------------ usr.sbin/efitable/efitable.c | 2 -- 6 files changed, 37 insertions(+), 28 deletions(-) diff --git a/sys/dev/efidev/efidev.c b/sys/dev/efidev/efidev.c index 14712cf3c7bf..4c3570969e23 100644 --- a/sys/dev/efidev/efidev.c +++ b/sys/dev/efidev/efidev.c @@ -56,7 +56,7 @@ efidev_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t addr, (struct efi_get_table_ioc *)addr; void *buf = NULL; - error = efi_copy_table(&egtioc->uuid, egtioc->buf ? &buf : NULL, + error = efi_copy_table((efi_guid_t *)&egtioc->uuid, egtioc->buf ? &buf : NULL, egtioc->buf_len, &egtioc->table_len); if (error != 0 || egtioc->buf == NULL) diff --git a/sys/dev/efidev/efirt.c b/sys/dev/efidev/efirt.c index 9523ffc7f386..c5deb273c076 100644 --- a/sys/dev/efidev/efirt.c +++ b/sys/dev/efidev/efirt.c @@ -340,7 +340,7 @@ efi_leave(void) } static int -get_table(struct uuid *uuid, void **ptr) +get_table(efi_guid_t *guid, void **ptr) { struct efi_cfgtbl *ct; u_long count; @@ -354,7 +354,7 @@ get_table(struct uuid *uuid, void **ptr) count = efi_systbl->st_entries; ct = efi_cfgtbl; while (count--) { - if (!bcmp(&ct->ct_uuid, uuid, sizeof(*uuid))) { + if (!bcmp(&ct->ct_guid, guid, sizeof(*guid))) { *ptr = ct->ct_data; efi_leave(); return (0); @@ -373,13 +373,13 @@ get_table_length(enum efi_table_type type, size_t *table_len, void **taddr) case TYPE_ESRT: { struct efi_esrt_table *esrt = NULL; - struct uuid uuid = EFI_TABLE_ESRT; + efi_guid_t guid = EFI_TABLE_ESRT; uint32_t fw_resource_count = 0; size_t len = sizeof(*esrt); int error; void *buf; - error = efi_get_table(&uuid, (void **)&esrt); + error = efi_get_table(&guid, (void **)&esrt); if (error != 0) return (error); @@ -415,14 +415,14 @@ get_table_length(enum efi_table_type type, size_t *table_len, void **taddr) } case TYPE_PROP: { - struct uuid uuid = EFI_PROPERTIES_TABLE; + efi_guid_t guid = EFI_PROPERTIES_TABLE; struct efi_prop_table *prop; size_t len = sizeof(*prop); uint32_t prop_len; int error; void *buf; - error = efi_get_table(&uuid, (void **)&prop); + error = efi_get_table(&guid, (void **)&prop); if (error != 0) return (error); @@ -450,10 +450,10 @@ get_table_length(enum efi_table_type type, size_t *table_len, void **taddr) } static int -copy_table(struct uuid *uuid, void **buf, size_t buf_len, size_t *table_len) +copy_table(efi_guid_t *guid, void **buf, size_t buf_len, size_t *table_len) { static const struct known_table { - struct uuid uuid; + efi_guid_t guid; enum efi_table_type type; } tables[] = { { EFI_TABLE_ESRT, TYPE_ESRT }, @@ -464,7 +464,7 @@ copy_table(struct uuid *uuid, void **buf, size_t buf_len, size_t *table_len) int rc; for (table_idx = 0; table_idx < nitems(tables); table_idx++) { - if (!bcmp(&tables[table_idx].uuid, uuid, sizeof(*uuid))) + if (!bcmp(&tables[table_idx].guid, guid, sizeof(*guid))) break; } diff --git a/sys/dev/ipmi/ipmi_smbios.c b/sys/dev/ipmi/ipmi_smbios.c index f9fc958d9739..29aa74127041 100644 --- a/sys/dev/ipmi/ipmi_smbios.c +++ b/sys/dev/ipmi/ipmi_smbios.c @@ -150,7 +150,7 @@ static void ipmi_smbios_probe(struct ipmi_get_info *info) { #ifdef ARCH_MAY_USE_EFI - struct uuid efi_smbios; + efi_guid_t efi_smbios = EFI_TABLE_SMBIOS; void *addr_efi; #endif struct smbios_eps *header; @@ -161,7 +161,6 @@ ipmi_smbios_probe(struct ipmi_get_info *info) bzero(info, sizeof(struct ipmi_get_info)); #ifdef ARCH_MAY_USE_EFI - efi_smbios = (struct uuid)EFI_TABLE_SMBIOS; if (!efi_get_table(&efi_smbios, &addr_efi)) addr = (vm_paddr_t)addr_efi; #endif diff --git a/sys/dev/smbios/smbios.c b/sys/dev/smbios/smbios.c index 469e5ab649b6..8f2b4a56b37b 100644 --- a/sys/dev/smbios/smbios.c +++ b/sys/dev/smbios/smbios.c @@ -76,8 +76,8 @@ static void smbios_identify (driver_t *driver, device_t parent) { #ifdef ARCH_MAY_USE_EFI - struct uuid efi_smbios = EFI_TABLE_SMBIOS; - struct uuid efi_smbios3 = EFI_TABLE_SMBIOS3; + efi_guid_t efi_smbios = EFI_TABLE_SMBIOS; + efi_guid_t efi_smbios3 = EFI_TABLE_SMBIOS3; void *addr_efi; #endif struct smbios_eps *eps; diff --git a/sys/sys/efi.h b/sys/sys/efi.h index 4345b1636c2b..58e2c3b4df34 100644 --- a/sys/sys/efi.h +++ b/sys/sys/efi.h @@ -35,15 +35,15 @@ #define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1) #define EFI_TABLE_SMBIOS \ - {0xeb9d2d31,0x2d88,0x11d3,0x9a,0x16,{0x00,0x90,0x27,0x3f,0xc1,0x4d}} + {0xeb9d2d31,0x2d88,0x11d3,{0x9a,0x16,0x00,0x90,0x27,0x3f,0xc1,0x4d}} #define EFI_TABLE_SMBIOS3 \ - {0xf2fd1544,0x9794,0x4a2c,0x99,0x2e,{0xe5,0xbb,0xcf,0x20,0xe3,0x94}} + {0xf2fd1544,0x9794,0x4a2c,{0x99,0x2e,0xe5,0xbb,0xcf,0x20,0xe3,0x94}} #define EFI_TABLE_ESRT \ - {0xb122a263,0x3661,0x4f68,0x99,0x29,{0x78,0xf8,0xb0,0xd6,0x21,0x80}} + {0xb122a263,0x3661,0x4f68,{0x99,0x29,0x78,0xf8,0xb0,0xd6,0x21,0x80}} #define EFI_PROPERTIES_TABLE \ - {0x880aaca3,0x4adc,0x4a04,0x90,0x79,{0xb7,0x47,0x34,0x08,0x25,0xe5}} + {0x880aaca3,0x4adc,0x4a04,{0x90,0x79,0xb7,0x47,0x34,0x08,0x25,0xe5}} #define LINUX_EFI_MEMRESERVE_TABLE \ - {0x888eb0c6,0x8ede,0x4ff5,0xa8,0xf0,{0x9a,0xee,0x5c,0xb9,0x77,0xc2}} + {0x888eb0c6,0x8ede,0x4ff5,{0xa8,0xf0,0x9a,0xee,0x5c,0xb9,0x77,0xc2}} enum efi_reset { EFI_RESET_COLD = 0, @@ -54,8 +54,20 @@ enum efi_reset { typedef uint16_t efi_char; typedef unsigned long efi_status; +/* + * This type-puns to a struct uuid, but all the EDK2 headers use this variation, + * and we use it in the loader to specify GUIDs. We define it here so that we + * can use EDK2 definitions both places. + */ +typedef struct efi_guid { + uint32_t Data1; + uint16_t Data2; + uint16_t Data3; + uint8_t Data4[8]; +} efi_guid_t; /* Type puns with GUID and EFI_GUID */ + struct efi_cfgtbl { - struct uuid ct_uuid; + efi_guid_t ct_guid; void *ct_data; }; @@ -246,8 +258,8 @@ struct efi_ops { * access them. */ int (*rt_ok)(void); - int (*get_table)(struct uuid *, void **); - int (*copy_table)(struct uuid *, void **, size_t, size_t *); + int (*get_table)(efi_guid_t *, void **); + int (*copy_table)(efi_guid_t *, void **, size_t, size_t *); int (*get_time)(struct efi_tm *); int (*get_time_capabilities)(struct efi_tmcap *); int (*reset_system)(enum efi_reset); @@ -271,21 +283,21 @@ static inline int efi_rt_ok(void) return (active_efi_ops->rt_ok()); } -static inline int efi_get_table(struct uuid *uuid, void **ptr) +static inline int efi_get_table(efi_guid_t *guid, void **ptr) { if (active_efi_ops->get_table == NULL) return (ENXIO); - return (active_efi_ops->get_table(uuid, ptr)); + return (active_efi_ops->get_table(guid, ptr)); } -static inline int efi_copy_table(struct uuid *uuid, void **buf, +static inline int efi_copy_table(efi_guid_t *guid, void **buf, size_t buf_len, size_t *table_len) { if (active_efi_ops->copy_table == NULL) return (ENXIO); - return (active_efi_ops->copy_table(uuid, buf, buf_len, table_len)); + return (active_efi_ops->copy_table(guid, buf, buf_len, table_len)); } static inline int efi_get_time(struct efi_tm *tm) diff --git a/usr.sbin/efitable/efitable.c b/usr.sbin/efitable/efitable.c index f283d467b01d..0eee72801592 100644 --- a/usr.sbin/efitable/efitable.c +++ b/usr.sbin/efitable/efitable.c @@ -46,8 +46,6 @@ static void efi_table_print_esrt(const void *data); static void efi_table_print_prop(const void *data); static void usage(void) __dead2; -typedef uuid_t efi_guid_t; /* Typedef for future efi_guid_t */ - struct efi_table_op { char name[TABLE_MAX_LEN]; void (*parse) (const void *);