iPXE
efi_table.c File Reference

EFI configuration tables. More...

#include <assert.h>
#include <errno.h>
#include <string.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_table.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
void * efi_find_table (EFI_GUID *guid)
 Look up EFI configuration table.
int efi_install_table (struct efi_table *table, const void *data, void **backup)
 Install EFI configuration table.
int efi_uninstall_table (struct efi_table *table, void **backup)
 Uninstall EFI configuration table.

Detailed Description

EFI configuration tables.

Definition in file efi_table.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ efi_find_table()

void * efi_find_table ( EFI_GUID * guid)

Look up EFI configuration table.

Parameters
guidConfiguration table GUID
Return values
tableConfiguration table, or NULL

Definition at line 45 of file efi_table.c.

45 {
46 void *table;
47 unsigned int i;
48
49 /* Scan for installed table */
50 for ( i = 0 ; i < efi_systab->NumberOfTableEntries ; i++ ) {
51 if ( memcmp ( &efi_systab->ConfigurationTable[i].VendorGuid,
52 guid, sizeof ( *guid ) ) == 0 ) {
53 table = efi_systab->ConfigurationTable[i].VendorTable;
54 DBGC ( guid, "EFITAB %s is at %p\n",
55 efi_guid_ntoa ( guid ), table );
56 return table;
57 }
58 }
59
60 return NULL;
61}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
uint64_t guid
GUID.
Definition edd.h:1
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition efi_guid.c:726
#define DBGC(...)
Definition compiler.h:505
EFI_SYSTEM_TABLE * efi_systab
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115

References DBGC, efi_guid_ntoa(), efi_systab, guid, memcmp(), and NULL.

Referenced by efi_init(), and efi_install_table().

◆ efi_install_table()

int efi_install_table ( struct efi_table * table,
const void * data,
void ** backup )

Install EFI configuration table.

Parameters
tableConfiguration table type
dataConfiguration table data, or NULL to uninstall
backupTable backup, or NULL to not back up old table
Return values
rcReturn status code

Definition at line 71 of file efi_table.c.

72 {
73 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
74 EFI_GUID *guid = table->guid;
75 void *copy;
76 void *new;
77 void *old;
78 size_t old_len;
79 size_t new_len;
80 EFI_STATUS efirc;
81 int rc;
82
83 /* Get currently installed table, if any */
85 old_len = ( old ? table->len ( old ) : 0 );
86
87 /* Create backup copy, if applicable */
88 if ( old_len && backup ) {
89 if ( ( efirc = bs->AllocatePool ( EfiBootServicesData, old_len,
90 &copy ) ) != 0 ) {
91 rc = -EEFI ( efirc );
92 goto err_backup;
93 }
94 memcpy ( copy, old, old_len );
95 DBGC ( table, "EFITAB %s %p+%#zx backed up\n",
96 efi_guid_ntoa ( guid ), old, old_len );
97 } else {
98 copy = NULL;
99 }
100
101 /* Create installable runtime services data copy, if applicable */
102 new_len = ( data ? table->len ( data ) : 0 );
103 if ( new_len ) {
104 if ( ( efirc = bs->AllocatePool ( EfiRuntimeServicesData,
105 new_len, &new ) ) != 0 ) {
106 rc = -EEFI ( efirc );
107 goto err_allocate;
108 }
109 memcpy ( new, data, new_len );
110 } else {
111 new = NULL;
112 }
113
114 /* (Un)install configuration table, if applicable */
115 if ( new || old ) {
116 if ( ( efirc = bs->InstallConfigurationTable ( guid,
117 new ) ) != 0 ) {
118 rc = -EEFI ( efirc );
119 DBGC ( table, "EFITAB %s could not install: %s\n",
120 efi_guid_ntoa ( guid ), strerror ( rc ) );
121 goto err_install;
122 }
123 if ( old ) {
124 DBGC ( table, "EFITAB %s %p+%#zx uninstalled\n",
125 efi_guid_ntoa ( guid ), old, old_len );
126 }
127 if ( new ) {
128 DBGC ( table, "EFITAB %s %p+%#zx installed\n",
129 efi_guid_ntoa ( guid ), new, new_len );
130 }
131 }
132
133 /* Record backup copy, if applicable */
134 if ( backup ) {
135 if ( *backup )
136 bs->FreePool ( *backup );
137 *backup = copy;
138 }
139
140 /* Sanity check */
141 assert ( efi_find_table ( guid ) == new );
142
143 return 0;
144
145 err_install:
146 if ( new )
147 bs->FreePool ( new );
148 err_allocate:
149 if ( copy )
150 bs->FreePool ( copy );
151 err_backup:
152 return rc;
153}
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
GUID EFI_GUID
128-bit buffer containing a unique identifier value.
@ EfiBootServicesData
The data portions of a loaded Boot Serves Driver, and the default data allocation type used by a Boot...
@ EfiRuntimeServicesData
The data portions of a loaded Runtime Services Driver and the default data allocation type used by a ...
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
int old
Definition bitops.h:65
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
void * efi_find_table(EFI_GUID *guid)
Look up EFI configuration table.
Definition efi_table.c:45
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition efi.h:175
void * memcpy(void *dest, const void *src, size_t len) __nonnull
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
EFI Boot Services Table.
Definition UefiSpec.h:1931
EFI_INSTALL_CONFIGURATION_TABLE InstallConfigurationTable
Definition UefiSpec.h:1973
EFI_FREE_POOL FreePool
Definition UefiSpec.h:1950
EFI_ALLOCATE_POOL AllocatePool
Definition UefiSpec.h:1949
size_t(* len)(const void *data)
Determine length of table.
Definition efi_table.h:30
EFI_GUID * guid
Table GUID.
Definition efi_table.h:18

References EFI_BOOT_SERVICES::AllocatePool, assert, data, DBGC, EEFI, efi_find_table(), efi_guid_ntoa(), efi_systab, EfiBootServicesData, EfiRuntimeServicesData, EFI_BOOT_SERVICES::FreePool, efi_table::guid, guid, EFI_BOOT_SERVICES::InstallConfigurationTable, efi_table::len, memcpy(), NULL, old, rc, and strerror().

Referenced by efi_fdt_install(), and efi_uninstall_table().

◆ efi_uninstall_table()

int efi_uninstall_table ( struct efi_table * table,
void ** backup )

Uninstall EFI configuration table.

Parameters
tableConfiguration table type
backupTable backup (or NULL to not restore old table)
Return values
rcReturn status code

Definition at line 162 of file efi_table.c.

162 {
163 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
164 void *old;
165 int rc;
166
167 /* Uninstall or reinstall as applicable */
168 old = ( backup ? *backup : NULL );
169 if ( ( rc = efi_install_table ( table, old, NULL ) ) != 0 )
170 return rc;
171
172 /* Free backup copy, if applicable */
173 if ( backup && *backup ) {
174 bs->FreePool ( *backup );
175 *backup = NULL;
176 }
177
178 return 0;
179}
int efi_install_table(struct efi_table *table, const void *data, void **backup)
Install EFI configuration table.
Definition efi_table.c:71

References efi_install_table(), efi_systab, EFI_BOOT_SERVICES::FreePool, NULL, old, and rc.

Referenced by efi_fdt_install(), and efi_fdt_uninstall().