iPXE
Data Structures | Functions
efi_table.h File Reference

EFI configuration tables. More...

#include <ipxe/efi/efi.h>

Go to the source code of this file.

Data Structures

struct  efi_table
 An installable EFI configuration table type. More...
 

Functions

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

Detailed Description

EFI configuration tables.

Definition in file efi_table.h.

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++ ) {
52  guid, sizeof ( *guid ) ) == 0 ) {
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 }
EFI_GUID VendorGuid
The 128-bit GUID value that uniquely identifies the system configuration table.
Definition: UefiSpec.h:2034
#define DBGC(...)
Definition: compiler.h:505
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_guid.c:726
uint64_t guid
GUID.
Definition: edd.h:31
UINTN NumberOfTableEntries
The number of system configuration tables in the buffer ConfigurationTable.
Definition: UefiSpec.h:2103
EFI_SYSTEM_TABLE * efi_systab
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:115
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
EFI_CONFIGURATION_TABLE * ConfigurationTable
A pointer to the system configuration tables.
Definition: UefiSpec.h:2108
VOID * VendorTable
A pointer to the table associated with VendorGuid.
Definition: UefiSpec.h:2038

References EFI_SYSTEM_TABLE::ConfigurationTable, DBGC, efi_guid_ntoa(), efi_systab, guid, memcmp(), NULL, EFI_SYSTEM_TABLE::NumberOfTableEntries, EFI_CONFIGURATION_TABLE::VendorGuid, and EFI_CONFIGURATION_TABLE::VendorTable.

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  {
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 */
84  old = efi_find_table ( guid );
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 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2099
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
128 bit buffer containing a unique identifier value.
Definition: Base.h:216
#define DBGC(...)
Definition: compiler.h:505
int old
Definition: bitops.h:65
size_t(* len)(const void *data)
Determine length of table.
Definition: efi_table.h:30
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
EFI Boot Services Table.
Definition: UefiSpec.h:1931
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_guid.c:726
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1950
uint64_t guid
GUID.
Definition: edd.h:31
The data portions of a loaded Runtime Services Driver and the default data allocation type used by a ...
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
uint8_t data[48]
Additional event data.
Definition: ena.h:22
EFI_SYSTEM_TABLE * efi_systab
The data portions of a loaded Boot Serves Driver, and the default data allocation type used by a Boot...
EFI_GUID * guid
Table GUID.
Definition: efi_table.h:18
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
void * efi_find_table(EFI_GUID *guid)
Look up EFI configuration table.
Definition: efi_table.c:45
EFI_INSTALL_CONFIGURATION_TABLE InstallConfigurationTable
Definition: UefiSpec.h:1973
EFI_ALLOCATE_POOL AllocatePool
Definition: UefiSpec.h:1949

References EFI_BOOT_SERVICES::AllocatePool, assert(), EFI_SYSTEM_TABLE::BootServices, 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  {
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 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2099
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int old
Definition: bitops.h:65
EFI Boot Services Table.
Definition: UefiSpec.h:1931
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1950
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
int efi_install_table(struct efi_table *table, const void *data, void **backup)
Install EFI configuration table.
Definition: efi_table.c:71

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

Referenced by efi_fdt_install(), and efi_fdt_uninstall().