iPXE
Functions | Variables
efi_fdt.c File Reference

EFI Flattened Device Tree. More...

#include <string.h>
#include <byteswap.h>
#include <ipxe/fdt.h>
#include <ipxe/init.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_table.h>
#include <ipxe/efi/efi_fdt.h>
#include <ipxe/efi/Guid/Fdt.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 EFI_USE_TABLE (FDT_TABLE, &efi_fdt, 0)
 
static void efi_fdt_init (void)
 Initialise EFI Flattened Device Tree. More...
 
struct init_fn efi_fdt_init_fn __init_fn (INIT_EARLY)
 EFI Flattened Device Tree initialisation function. More...
 
static size_t efi_fdt_len (const void *data)
 Determine length of EFI Flattened Device Tree. More...
 
int efi_fdt_install (const char *cmdline)
 Install EFI Flattened Device Tree table. More...
 
int efi_fdt_uninstall (void)
 Uninstall EFI Flattened Device Tree table. More...
 

Variables

static struct fdt_headerefi_fdt
 EFI Flattened Device Tree configuration table. More...
 
static struct efi_table efi_fdt_table
 EFI Flattened Device Tree table type. More...
 
static void * efi_fdt_backup
 EFI Flattened Device Tree table backup. More...
 
static struct fdt_headerefi_fdt_installed
 EFI Flattened Device Tree installed table. More...
 

Detailed Description

EFI Flattened Device Tree.

Definition in file efi_fdt.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ EFI_USE_TABLE()

EFI_USE_TABLE ( FDT_TABLE  ,
efi_fdt,
 
)

◆ efi_fdt_init()

static void efi_fdt_init ( void  )
static

Initialise EFI Flattened Device Tree.

Definition at line 49 of file efi_fdt.c.

49  {
51  EFI_STATUS efirc;
52  int rc;
53 
54  /* Do nothing if no configuration table is present */
55  if ( ! efi_fdt ) {
56  DBGC ( &efi_fdt, "EFIFDT has no configuration table\n" );
57  return;
58  }
59  DBGC ( &efi_fdt, "EFIFDT configuration table at %p\n", efi_fdt );
60 
61  /* Parse as system device tree */
62  if ( ( rc = fdt_parse ( &sysfdt, efi_fdt, -1UL ) ) != 0 ) {
63  DBGC ( &efi_fdt, "EFIFDT could not parse: %s\n",
64  strerror ( rc ) );
65  return;
66  }
67 
68  /* Create copy, since table may be removed at any time */
69  if ( ( efirc = bs->AllocatePool ( EfiBootServicesData, sysfdt.len,
70  &sysfdt.raw ) ) != 0 ) {
71  DBGC ( &efi_fdt, "EFIFDT could not create copy\n" );
72  sysfdt.len = 0;
73  return;
74  }
76 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
size_t len
Length of tree.
Definition: fdt.h:97
int fdt_parse(struct fdt *fdt, struct fdt_header *hdr, size_t max_len)
Parse device tree.
Definition: fdt.c:903
void * raw
Raw data.
Definition: fdt.h:94
#define DBGC(...)
Definition: compiler.h:505
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct fdt_header * efi_fdt
EFI Flattened Device Tree configuration table.
Definition: efi_fdt.c:42
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1930
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
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_ALLOCATE_POOL AllocatePool
Definition: UefiSpec.h:1948
struct fdt sysfdt
The system flattened device tree (if present)
Definition: fdt.c:44

References EFI_BOOT_SERVICES::AllocatePool, EFI_SYSTEM_TABLE::BootServices, DBGC, efi_fdt, efi_systab, EfiBootServicesData, fdt_parse(), fdt::len, memcpy(), fdt::raw, rc, strerror(), and sysfdt.

◆ __init_fn()

struct init_fn efi_fdt_init_fn __init_fn ( INIT_EARLY  )

EFI Flattened Device Tree initialisation function.

◆ efi_fdt_len()

static size_t efi_fdt_len ( const void *  data)
static

Determine length of EFI Flattened Device Tree.

Parameters
dataConfiguration table data (presumed valid)
Return values
lenLength of table

Definition at line 90 of file efi_fdt.c.

90  {
91  const struct fdt_header *hdr = data;
92 
93  return be32_to_cpu ( hdr->totalsize );
94 }
Device tree header.
Definition: fdt.h:18
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
#define be32_to_cpu(value)
Definition: byteswap.h:116
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References be32_to_cpu, data, and hdr.

◆ efi_fdt_install()

int efi_fdt_install ( const char *  cmdline)

Install EFI Flattened Device Tree table.

Parameters
cmdlineCommand line, or NULL
Return values
rcReturn status code

Definition at line 114 of file efi_fdt.c.

114  {
115  int rc;
116 
117  /* Create device tree */
118  if ( ( rc = fdt_create ( &efi_fdt_installed, cmdline, 0, 0 ) ) != 0 ) {
119  DBGC ( &efi_fdt, "EFI_FDT could not install: %s\n",
120  strerror ( rc ) );
121  goto err_create;
122  }
123 
124  /* Install table */
126  &efi_fdt_backup ) ) != 0 ) {
127  DBGC ( &efi_fdt, "EFIFDT could not install: %s\n",
128  strerror ( rc ) );
129  goto err_install;
130  }
131 
132  return 0;
133 
135  err_install:
137  err_create:
138  return rc;
139 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct efi_table efi_fdt_table
EFI Flattened Device Tree table type.
Definition: efi_fdt.c:97
#define DBGC(...)
Definition: compiler.h:505
static struct fdt_header * efi_fdt_installed
EFI Flattened Device Tree installed table.
Definition: efi_fdt.c:106
void fdt_remove(struct fdt_header *hdr)
Remove device tree.
Definition: fdt.c:1458
static struct fdt_header * efi_fdt
EFI Flattened Device Tree configuration table.
Definition: efi_fdt.c:42
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int efi_uninstall_table(struct efi_table *table, void **backup)
Uninstall EFI configuration table.
Definition: efi_table.c:161
uint32_t cmdline
Definition: multiboot.h:16
static void * efi_fdt_backup
EFI Flattened Device Tree table backup.
Definition: efi_fdt.c:103
int fdt_create(struct fdt_header **hdr, const char *cmdline, physaddr_t initrd, size_t initrd_len)
Create device tree.
Definition: fdt.c:1407
int efi_install_table(struct efi_table *table, const void *data, void **backup)
Install EFI configuration table.
Definition: efi_table.c:70

References cmdline, DBGC, efi_fdt, efi_fdt_backup, efi_fdt_installed, efi_fdt_table, efi_install_table(), efi_uninstall_table(), fdt_create(), fdt_remove(), rc, and strerror().

◆ efi_fdt_uninstall()

int efi_fdt_uninstall ( void  )

Uninstall EFI Flattened Device Tree table.

Uninstall EFI Flattened Device Tree table (when no FDT support is present)

Return values
rcReturn status code

Definition at line 146 of file efi_fdt.c.

146  {
147  int rc;
148 
149  /* Uninstall table */
151  &efi_fdt_backup ) ) != 0 ) {
152  DBGC ( &efi_fdt, "EFIFDT could not %sinstall: %s\n",
153  ( efi_fdt_backup ? "re" : "un" ), strerror ( rc ) );
154  /* Leak memory: there is nothing else we can do */
155  return rc;
156  }
157 
158  /* Remove table */
160 
161  return 0;
162 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct efi_table efi_fdt_table
EFI Flattened Device Tree table type.
Definition: efi_fdt.c:97
#define DBGC(...)
Definition: compiler.h:505
static struct fdt_header * efi_fdt_installed
EFI Flattened Device Tree installed table.
Definition: efi_fdt.c:106
void fdt_remove(struct fdt_header *hdr)
Remove device tree.
Definition: fdt.c:1458
static struct fdt_header * efi_fdt
EFI Flattened Device Tree configuration table.
Definition: efi_fdt.c:42
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int efi_uninstall_table(struct efi_table *table, void **backup)
Uninstall EFI configuration table.
Definition: efi_table.c:161
static void * efi_fdt_backup
EFI Flattened Device Tree table backup.
Definition: efi_fdt.c:103

References DBGC, efi_fdt, efi_fdt_backup, efi_fdt_installed, efi_fdt_table, efi_uninstall_table(), fdt_remove(), rc, and strerror().

Variable Documentation

◆ efi_fdt

struct fdt_header* efi_fdt
static

EFI Flattened Device Tree configuration table.

Definition at line 42 of file efi_fdt.c.

Referenced by efi_fdt_init(), efi_fdt_install(), and efi_fdt_uninstall().

◆ efi_fdt_table

struct efi_table efi_fdt_table
static
Initial value:
= {
.len = efi_fdt_len,
}
EFI_GUID efi_fdt_table_guid
FDT table GUID.
Definition: efi_guid.c:448
static size_t efi_fdt_len(const void *data)
Determine length of EFI Flattened Device Tree.
Definition: efi_fdt.c:90

EFI Flattened Device Tree table type.

Definition at line 97 of file efi_fdt.c.

Referenced by efi_fdt_install(), and efi_fdt_uninstall().

◆ efi_fdt_backup

void* efi_fdt_backup
static

EFI Flattened Device Tree table backup.

Definition at line 103 of file efi_fdt.c.

Referenced by efi_fdt_install(), and efi_fdt_uninstall().

◆ efi_fdt_installed

struct fdt_header* efi_fdt_installed
static

EFI Flattened Device Tree installed table.

Definition at line 106 of file efi_fdt.c.

Referenced by efi_fdt_install(), and efi_fdt_uninstall().