iPXE
Data Structures | Macros | Typedefs | Functions | Variables
fdt.h File Reference

Flattened Device Tree. More...

#include <stdint.h>
#include <ipxe/image.h>

Go to the source code of this file.

Data Structures

struct  fdt_header
 Device tree header. More...
 
struct  fdt_prop
 Property fragment. More...
 
struct  fdt_reservation
 A memory reservation. More...
 
struct  fdt
 A device tree. More...
 
struct  fdt_descriptor
 A device tree token descriptor. More...
 
struct  fdt_reg_cells
 A device tree region cell size specification. More...
 

Macros

#define FDT_MAGIC   0xd00dfeed
 Magic signature. More...
 
#define FDT_VERSION   16
 Expected device tree version. More...
 
#define FDT_BEGIN_NODE   0x00000001
 Begin node token. More...
 
#define FDT_END_NODE   0x00000002
 End node token. More...
 
#define FDT_PROP   0x00000003
 Property token. More...
 
#define FDT_NOP   0x00000004
 NOP token. More...
 
#define FDT_END   0x00000009
 End of structure block. More...
 
#define FDT_STRUCTURE_ALIGN   ( sizeof ( fdt_token_t ) )
 Alignment of structure block. More...
 
#define FDT_MAX_ALIGN   8
 Maximum alignment of any block. More...
 
#define FDT_DEFAULT_ADDRESS_CELLS   2
 Default number of address cells, if not specified. More...
 
#define FDT_DEFAULT_SIZE_CELLS   1
 Default number of size cells, if not specified. More...
 
#define for_each_fdt_reservation(rsv, fdt)
 Iterate over memory reservations. More...
 

Typedefs

typedef uint32_t fdt_token_t
 Device tree token. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
static const struct fdt_reservationfdt_reservations (struct fdt *fdt)
 Get memory reservations. More...
 
int fdt_describe (struct fdt *fdt, unsigned int offset, struct fdt_descriptor *desc)
 Describe device tree token. More...
 
int fdt_parent (struct fdt *fdt, unsigned int offset, unsigned int *parent)
 Find parent node. More...
 
int fdt_path (struct fdt *fdt, const char *path, unsigned int *offset)
 Find node by path. More...
 
int fdt_alias (struct fdt *fdt, const char *name, unsigned int *offset)
 Find node by alias. More...
 
const char * fdt_strings (struct fdt *fdt, unsigned int offset, const char *name, unsigned int *count)
 Find strings property. More...
 
const char * fdt_string (struct fdt *fdt, unsigned int offset, const char *name)
 Find string property. More...
 
int fdt_cells (struct fdt *fdt, unsigned int offset, const char *name, unsigned int index, unsigned int count, uint64_t *value)
 Get integer property. More...
 
int fdt_u64 (struct fdt *fdt, unsigned int offset, const char *name, uint64_t *value)
 Get 64-bit integer property. More...
 
int fdt_u32 (struct fdt *fdt, unsigned int offset, const char *name, uint32_t *value)
 Get 32-bit integer property. More...
 
uint32_t fdt_phandle (struct fdt *fdt, unsigned int offset)
 Get package handle (phandle) property. More...
 
void fdt_reg_cells (struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs)
 Get region cell size specification. More...
 
int fdt_parent_reg_cells (struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs)
 Get parent region cell size specification. More...
 
int fdt_reg_count (struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs)
 Get number of regions. More...
 
int fdt_reg_address (struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs, unsigned int index, uint64_t *address)
 Get region address. More...
 
int fdt_reg_size (struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs, unsigned int index, uint64_t *size)
 Get region size. More...
 
int fdt_reg (struct fdt *fdt, unsigned int offset, uint64_t *region)
 Get unsized single-entry region address. More...
 
int fdt_mac (struct fdt *fdt, unsigned int offset, struct net_device *netdev)
 Get MAC address from property. More...
 
int fdt_parse (struct fdt *fdt, struct fdt_header *hdr, size_t max_len)
 Parse device tree. More...
 
int fdt_create (struct fdt_header **hdr, const char *cmdline, physaddr_t initrd, size_t initrd_len)
 Create device tree. More...
 
void fdt_remove (struct fdt_header *hdr)
 Remove device tree. More...
 

Variables

struct image_tag fdt_image __image_tag
 The downloaded flattened device tree tag. More...
 
struct fdt sysfdt
 The system flattened device tree (if present) More...
 

Detailed Description

Flattened Device Tree.

Definition in file fdt.h.

Macro Definition Documentation

◆ FDT_MAGIC

#define FDT_MAGIC   0xd00dfeed

Magic signature.

Definition at line 43 of file fdt.h.

◆ FDT_VERSION

#define FDT_VERSION   16

Expected device tree version.

Definition at line 46 of file fdt.h.

◆ FDT_BEGIN_NODE

#define FDT_BEGIN_NODE   0x00000001

Begin node token.

Definition at line 52 of file fdt.h.

◆ FDT_END_NODE

#define FDT_END_NODE   0x00000002

End node token.

Definition at line 55 of file fdt.h.

◆ FDT_PROP

#define FDT_PROP   0x00000003

Property token.

Definition at line 58 of file fdt.h.

◆ FDT_NOP

#define FDT_NOP   0x00000004

NOP token.

Definition at line 69 of file fdt.h.

◆ FDT_END

#define FDT_END   0x00000009

End of structure block.

Definition at line 72 of file fdt.h.

◆ FDT_STRUCTURE_ALIGN

#define FDT_STRUCTURE_ALIGN   ( sizeof ( fdt_token_t ) )

Alignment of structure block.

Definition at line 75 of file fdt.h.

◆ FDT_MAX_ALIGN

#define FDT_MAX_ALIGN   8

Maximum alignment of any block.

Definition at line 78 of file fdt.h.

◆ FDT_DEFAULT_ADDRESS_CELLS

#define FDT_DEFAULT_ADDRESS_CELLS   2

Default number of address cells, if not specified.

Definition at line 147 of file fdt.h.

◆ FDT_DEFAULT_SIZE_CELLS

#define FDT_DEFAULT_SIZE_CELLS   1

Default number of size cells, if not specified.

Definition at line 150 of file fdt.h.

◆ for_each_fdt_reservation

#define for_each_fdt_reservation (   rsv,
  fdt 
)
Value:
for ( rsv = fdt_reservations ( (fdt) ) ; \
( (rsv)->start || (rsv)->size ) ; rsv++ )
static const struct fdt_reservation * fdt_reservations(struct fdt *fdt)
Get memory reservations.
Definition: fdt.h:162
uint32_t start
Starting offset.
Definition: netvsc.h:12
A device tree.
Definition: fdt.h:89

Iterate over memory reservations.

Definition at line 168 of file fdt.h.

Typedef Documentation

◆ fdt_token_t

Device tree token.

Definition at line 49 of file fdt.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ fdt_reservations()

static const struct fdt_reservation* fdt_reservations ( struct fdt fdt)
inlinestatic

Get memory reservations.

Parameters
fdtDevice tree
Return values
rsvMemory reservations

Definition at line 162 of file fdt.h.

162  {
163 
164  return ( fdt->raw + fdt->reservations );
165 }
unsigned int reservations
Offset to memory reservation block.
Definition: fdt.h:110
void * raw
Raw data.
Definition: fdt.h:95
A device tree.
Definition: fdt.h:89

References fdt::raw, and fdt::reservations.

◆ fdt_describe()

int fdt_describe ( struct fdt fdt,
unsigned int  offset,
struct fdt_descriptor desc 
)

Describe device tree token.

Parameters
fdtDevice tree
offsetOffset within structure block
descToken descriptor to fill in
Return values
rcReturn status code

Definition at line 90 of file fdt.c.

91  {
92  const fdt_token_t *token;
93  const void *data;
94  const struct fdt_prop *prop;
95  unsigned int name_off;
96  size_t remaining;
97  size_t len;
98 
99  /* Sanity checks */
100  assert ( offset <= fdt->len );
101  assert ( ( offset & ( FDT_STRUCTURE_ALIGN - 1 ) ) == 0 );
102 
103  /* Initialise descriptor */
104  memset ( desc, 0, sizeof ( *desc ) );
105  desc->offset = offset;
106 
107  /* Locate token and calculate remaining space */
108  token = ( fdt->raw + fdt->structure + offset );
109  remaining = ( fdt->len - offset );
110  if ( remaining < sizeof ( *token ) ) {
111  DBGC ( fdt, "FDT truncated tree at +%#04x\n", offset );
112  return -EINVAL;
113  }
114  remaining -= sizeof ( *token );
115  data = ( ( ( const void * ) token ) + sizeof ( *token ) );
116  len = 0;
117 
118  /* Handle token */
119  switch ( *token ) {
120 
121  case cpu_to_be32 ( FDT_BEGIN_NODE ):
122 
123  /* Start of node */
124  desc->name = data;
125  len = ( strnlen ( desc->name, remaining ) + 1 /* NUL */ );
126  if ( remaining < len ) {
127  DBGC ( fdt, "FDT unterminated node name at +%#04x\n",
128  offset );
129  return -EINVAL;
130  }
131  desc->depth = +1;
132  break;
133 
134  case cpu_to_be32 ( FDT_END_NODE ):
135 
136  /* End of node */
137  desc->depth = -1;
138  break;
139 
140  case cpu_to_be32 ( FDT_PROP ):
141 
142  /* Property */
143  prop = data;
144  if ( remaining < sizeof ( *prop ) ) {
145  DBGC ( fdt, "FDT truncated property at +%#04x\n",
146  offset );
147  return -EINVAL;
148  }
149  desc->data = ( ( ( const void * ) prop ) + sizeof ( *prop ) );
150  desc->len = be32_to_cpu ( prop->len );
151  len = ( sizeof ( *prop ) + desc->len );
152  if ( remaining < len ) {
153  DBGC ( fdt, "FDT overlength property at +%#04x\n",
154  offset );
155  return -EINVAL;
156  }
157  name_off = be32_to_cpu ( prop->name_off );
158  if ( name_off > fdt->strings_len ) {
159  DBGC ( fdt, "FDT property name outside strings "
160  "block at +%#04x\n", offset );
161  return -EINVAL;
162  }
163  desc->name = ( fdt->raw + fdt->strings + name_off );
164  break;
165 
166  case cpu_to_be32 ( FDT_NOP ):
167 
168  /* Do nothing */
169  break;
170 
171  default:
172 
173  /* Unrecognised or unexpected token */
174  DBGC ( fdt, "FDT unexpected token %#08x at +%#04x\n",
175  be32_to_cpu ( *token ), offset );
176  return -EINVAL;
177  }
178 
179  /* Calculate offset to next token */
180  len = ( ( len + FDT_STRUCTURE_ALIGN - 1 ) &
181  ~( FDT_STRUCTURE_ALIGN - 1 ) );
182  offset += ( sizeof ( *token ) + len );
183  desc->next = offset;
184 
185  /* Sanity checks */
186  assert ( offset <= fdt->len );
187 
188  return 0;
189 }
#define EINVAL
Invalid argument.
Definition: errno.h:429
const char * name
Definition: ath9k_hw.c:1986
#define FDT_STRUCTURE_ALIGN
Alignment of structure block.
Definition: fdt.h:75
#define FDT_NOP
NOP token.
Definition: fdt.h:69
size_t len
Length of tree.
Definition: fdt.h:98
void * raw
Raw data.
Definition: fdt.h:95
#define DBGC(...)
Definition: compiler.h:505
size_t strings_len
Length of strings block.
Definition: fdt.h:108
uint32_t fdt_token_t
Device tree token.
Definition: fdt.h:49
uint32_t len
Data length.
Definition: fdt.h:63
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
#define be32_to_cpu(value)
Definition: byteswap.h:117
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
unsigned int structure
Offset to structure block.
Definition: fdt.h:102
Property fragment.
Definition: fdt.h:61
size_t strnlen(const char *src, size_t max)
Get length of string.
Definition: string.c:256
u8 token
Definition: CIB_PRM.h:42
#define FDT_PROP
Property token.
Definition: fdt.h:58
#define cpu_to_be32(value)
Definition: byteswap.h:111
A device tree.
Definition: fdt.h:89
uint32_t name_off
Name offset.
Definition: fdt.h:65
#define FDT_END_NODE
End node token.
Definition: fdt.h:55
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define FDT_BEGIN_NODE
Begin node token.
Definition: fdt.h:52
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
unsigned int strings
Offset to strings block.
Definition: fdt.h:106
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), be32_to_cpu, cpu_to_be32, data, DBGC, desc, EINVAL, FDT_BEGIN_NODE, FDT_END_NODE, FDT_NOP, FDT_PROP, FDT_STRUCTURE_ALIGN, fdt_prop::len, fdt::len, len, memset(), fdt_prop::name_off, offset, fdt::raw, fdt::strings, fdt::strings_len, strnlen(), fdt::structure, and token.

Referenced by dt_probe_children(), dt_probe_node(), fdt_enter(), fdt_next(), fdt_test_exec(), and fdtmem_update_node().

◆ fdt_parent()

int fdt_parent ( struct fdt fdt,
unsigned int  offset,
unsigned int *  parent 
)

Find parent node.

Parameters
fdtDevice tree
offsetStarting node offset
parentParent node offset to fill in
Return values
rcReturn status code

Definition at line 293 of file fdt.c.

293  {
294  struct fdt_descriptor desc;
295  int pdepth;
296  int depth;
297  int rc;
298 
299  /* Find depth from root of tree */
300  depth = fdt_depth ( fdt, 0, offset );
301  if ( depth < 0 ) {
302  rc = depth;
303  return rc;
304  }
305  pdepth = ( depth - 1 );
306 
307  /* Enter root node */
308  if ( ( rc = fdt_enter ( fdt, 0, &desc ) ) != 0 )
309  return rc;
310  *parent = desc.offset;
311 
312  /* Find parent node */
313  for ( depth = 0 ; depth >= 0 ; depth += desc.depth ) {
314 
315  /* Describe token */
316  if ( ( rc = fdt_next ( fdt, &desc ) ) != 0 ) {
317  DBGC ( fdt, "FDT +%#04x has malformed node: %s\n",
318  offset, strerror ( rc ) );
319  return rc;
320  }
321 
322  /* Record possible parent node */
323  if ( ( depth == pdepth ) && desc.name && ( ! desc.data ) )
324  *parent = desc.offset;
325 
326  /* Check for target node */
327  if ( desc.offset == offset ) {
328  DBGC2 ( fdt, "FDT +%#04x has parent node at +%#04x\n",
329  offset, *parent );
330  return 0;
331  }
332  }
333 
334  DBGC ( fdt, "FDT +#%04x has no parent node\n", offset );
335  return -ENOENT;
336 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int depth
Depth change.
Definition: fdt.h:133
static int fdt_enter(struct fdt *fdt, unsigned int offset, struct fdt_descriptor *desc)
Enter node.
Definition: fdt.c:212
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:515
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static int fdt_next(struct fdt *fdt, struct fdt_descriptor *desc)
Describe next device tree token.
Definition: fdt.c:198
static int fdt_depth(struct fdt *fdt, unsigned int offset, unsigned int target)
Find node relative depth.
Definition: fdt.c:252
A device tree.
Definition: fdt.h:89
#define DBGC2(...)
Definition: compiler.h:522
A device tree token descriptor.
Definition: fdt.h:121
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

References DBGC, DBGC2, fdt_descriptor::depth, desc, ENOENT, fdt_depth(), fdt_enter(), fdt_next(), offset, rc, and strerror().

Referenced by fdt_parent_reg_cells(), and fdt_test_exec().

◆ fdt_path()

int fdt_path ( struct fdt fdt,
const char *  path,
unsigned int *  offset 
)

Find node by path.

Parameters
fdtDevice tree
pathNode path
offsetOffset to fill in
Return values
rcReturn status code

Definition at line 426 of file fdt.c.

426  {
427  const char *tmp = path;
428  int rc;
429 
430  /* Initialise offset */
431  *offset = 0;
432 
433  /* Traverse tree one path segment at a time */
434  while ( 1 ) {
435 
436  /* Skip any leading '/' */
437  while ( *tmp == '/' )
438  tmp++;
439 
440  /* Terminate if there are no more path components */
441  if ( ! *tmp )
442  break;
443 
444  /* Find child */
445  if ( ( rc = fdt_child ( fdt, *offset, tmp, offset ) ) != 0 )
446  return rc;
447 
448  /* Move to next path component, if any */
449  tmp = strchr ( tmp, '/' );
450  if ( ! tmp )
451  break;
452  }
453 
454  DBGC2 ( fdt, "FDT found path \"%s\" at +%#04x\n", path, *offset );
455  return 0;
456 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned long tmp
Definition: linux_pci.h:65
static int fdt_child(struct fdt *fdt, unsigned int offset, const char *name, unsigned int *child)
Find child node.
Definition: fdt.c:347
char * strchr(const char *src, int character)
Find character within a string.
Definition: string.c:272
A device tree.
Definition: fdt.h:89
#define DBGC2(...)
Definition: compiler.h:522
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

References DBGC2, fdt_child(), offset, rc, strchr(), and tmp.

Referenced by fdt_alias(), fdt_test_exec(), fdtcon_default(), and fdtmem_update_tree().

◆ fdt_alias()

int fdt_alias ( struct fdt fdt,
const char *  name,
unsigned int *  offset 
)

Find node by alias.

Parameters
fdtDevice tree
nameAlias name
offsetOffset to fill in
Return values
rcReturn status code

Definition at line 466 of file fdt.c.

466  {
467  const char *alias;
468  int rc;
469 
470  /* Locate "/aliases" node */
471  if ( ( rc = fdt_child ( fdt, 0, "aliases", offset ) ) != 0 )
472  return rc;
473 
474  /* Locate alias property */
475  if ( ( alias = fdt_string ( fdt, *offset, name ) ) == NULL )
476  return -ENOENT;
477  DBGC ( fdt, "FDT alias \"%s\" is \"%s\"\n", name, alias );
478 
479  /* Locate aliased node */
480  if ( ( rc = fdt_path ( fdt, alias, offset ) ) != 0 )
481  return rc;
482 
483  return 0;
484 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1986
int fdt_path(struct fdt *fdt, const char *path, unsigned int *offset)
Find node by path.
Definition: fdt.c:426
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:515
const char * fdt_string(struct fdt *fdt, unsigned int offset, const char *name)
Find string property.
Definition: fdt.c:579
static int fdt_child(struct fdt *fdt, unsigned int offset, const char *name, unsigned int *child)
Find child node.
Definition: fdt.c:347
A device tree.
Definition: fdt.h:89
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References DBGC, ENOENT, fdt_child(), fdt_path(), fdt_string(), name, NULL, offset, and rc.

Referenced by fdt_test_exec(), fdtcon_default(), and smscusb_fdt_fetch_mac().

◆ fdt_strings()

const char* fdt_strings ( struct fdt fdt,
unsigned int  offset,
const char *  name,
unsigned int *  count 
)

Find strings property.

Parameters
fdtDevice tree
offsetStarting node offset
nameProperty name
countString count to fill in
Return values
stringString property, or NULL on error

Definition at line 540 of file fdt.c.

541  {
542  struct fdt_descriptor desc;
543  const char *data;
544  size_t len;
545  int rc;
546 
547  /* Return a zero count on error */
548  *count = 0;
549 
550  /* Find property */
551  if ( ( rc = fdt_property ( fdt, offset, name, &desc ) ) != 0 )
552  return NULL;
553 
554  /* Check NUL termination */
555  data = desc.data;
556  if ( desc.len && ( data[ desc.len - 1 ] != '\0' ) ) {
557  DBGC ( fdt, "FDT unterminated string property \"%s\"\n",
558  name );
559  return NULL;
560  }
561 
562  /* Count number of strings */
563  for ( len = desc.len ; len-- ; ) {
564  if ( data[len] == '\0' )
565  (*count)++;
566  }
567 
568  return data;
569 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1986
#define DBGC(...)
Definition: compiler.h:505
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
static int fdt_property(struct fdt *fdt, unsigned int offset, const char *name, struct fdt_descriptor *desc)
Find property.
Definition: fdt.c:495
ring len
Length.
Definition: dwmac.h:231
static unsigned int count
Number of entries.
Definition: dwmac.h:225
A device tree.
Definition: fdt.h:89
uint8_t data[48]
Additional event data.
Definition: ena.h:22
A device tree token descriptor.
Definition: fdt.h:121
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References count, data, DBGC, desc, fdt_property(), len, name, NULL, offset, and rc.

Referenced by dt_find_driver(), fdt_string(), and fdt_test_exec().

◆ fdt_string()

const char* fdt_string ( struct fdt fdt,
unsigned int  offset,
const char *  name 
)

Find string property.

Parameters
fdtDevice tree
offsetStarting node offset
nameProperty name
Return values
stringString property, or NULL on error

Definition at line 579 of file fdt.c.

580  {
581  unsigned int count;
582 
583  /* Find strings property */
584  return fdt_strings ( fdt, offset, name, &count );
585 }
const char * name
Definition: ath9k_hw.c:1986
const char * fdt_strings(struct fdt *fdt, unsigned int offset, const char *name, unsigned int *count)
Find strings property.
Definition: fdt.c:540
static unsigned int count
Number of entries.
Definition: dwmac.h:225
A device tree.
Definition: fdt.h:89
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

References count, fdt_strings(), name, and offset.

Referenced by fdt_alias(), fdt_parse(), fdt_test_exec(), fdtcon_default(), and fdtmem_update_node().

◆ fdt_cells()

int fdt_cells ( struct fdt fdt,
unsigned int  offset,
const char *  name,
unsigned int  index,
unsigned int  count,
uint64_t value 
)

Get integer property.

Parameters
fdtDevice tree
offsetStarting node offset
nameProperty name
indexStarting cell index
countNumber of cells (or 0 to read all remaining cells)
valueInteger value to fill in
Return values
rcReturn status code

Definition at line 598 of file fdt.c.

599  {
600  struct fdt_descriptor desc;
601  const uint32_t *cell;
602  unsigned int total;
603  int rc;
604 
605  /* Clear value */
606  *value = 0;
607 
608  /* Find property */
609  if ( ( rc = fdt_property ( fdt, offset, name, &desc ) ) != 0 )
610  return rc;
611  cell = desc.data;
612 
613  /* Determine number of cells */
614  total = ( desc.len / sizeof ( *cell ) );
615  if ( ( index > total ) || ( count > ( total - index ) ) ) {
616  DBGC ( fdt, "FDT truncated integer \"%s\"\n", name );
617  return -ERANGE;
618  }
619  if ( ! count )
620  count = ( total - index );
621  if ( count > ( sizeof ( *value ) / sizeof ( *cell ) ) ) {
622  DBGC ( fdt, "FDT overlength integer \"%s\"\n", name );
623  return -ERANGE;
624  }
625 
626  /* Read value */
627  for ( cell += index ; count ; cell++, count-- ) {
628  *value <<= 32;
629  *value |= be32_to_cpu ( *cell );
630  }
631 
632  return 0;
633 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1986
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:65
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
#define be32_to_cpu(value)
Definition: byteswap.h:117
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static int fdt_property(struct fdt *fdt, unsigned int offset, const char *name, struct fdt_descriptor *desc)
Find property.
Definition: fdt.c:495
static unsigned int count
Number of entries.
Definition: dwmac.h:225
#define ERANGE
Result too large.
Definition: errno.h:640
unsigned int uint32_t
Definition: stdint.h:12
A device tree.
Definition: fdt.h:89
A device tree token descriptor.
Definition: fdt.h:121
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

References be32_to_cpu, count, DBGC, desc, ERANGE, fdt_property(), index, name, offset, rc, and value.

Referenced by fdt_reg_address(), fdt_reg_size(), fdt_test_exec(), and fdt_u64().

◆ fdt_u64()

int fdt_u64 ( struct fdt fdt,
unsigned int  offset,
const char *  name,
uint64_t value 
)

Get 64-bit integer property.

Parameters
fdtDevice tree
offsetStarting node offset
nameProperty name
valueInteger value to fill in
Return values
rcReturn status code

Definition at line 644 of file fdt.c.

645  {
646  int rc;
647 
648  /* Read value */
649  if ( ( rc = fdt_cells ( fdt, offset, name, 0, 0, value ) ) != 0 )
650  return rc;
651 
652  return 0;
653 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1986
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A device tree.
Definition: fdt.h:89
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
int fdt_cells(struct fdt *fdt, unsigned int offset, const char *name, unsigned int index, unsigned int count, uint64_t *value)
Get integer property.
Definition: fdt.c:598

References fdt_cells(), name, offset, rc, and value.

Referenced by fdt_test_exec(), and fdt_u32().

◆ fdt_u32()

int fdt_u32 ( struct fdt fdt,
unsigned int  offset,
const char *  name,
uint32_t value 
)

Get 32-bit integer property.

Parameters
fdtDevice tree
offsetStarting node offset
nameProperty name
valueInteger value to fill in
Return values
rcReturn status code

Definition at line 664 of file fdt.c.

665  {
666  uint64_t value64;
667  int rc;
668 
669  /* Read value */
670  if ( ( rc = fdt_u64 ( fdt, offset, name, &value64 ) ) != 0 )
671  return rc;
672 
673  /* Check range */
674  *value = value64;
675  if ( *value != value64 ) {
676  DBGC ( fdt, "FDT overlength 32-bit integer \"%s\"\n", name );
677  return -ERANGE;
678  }
679 
680  return 0;
681 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1986
#define DBGC(...)
Definition: compiler.h:505
unsigned long long uint64_t
Definition: stdint.h:13
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define ERANGE
Result too large.
Definition: errno.h:640
A device tree.
Definition: fdt.h:89
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
int fdt_u64(struct fdt *fdt, unsigned int offset, const char *name, uint64_t *value)
Get 64-bit integer property.
Definition: fdt.c:644

References DBGC, ERANGE, fdt_u64(), name, offset, rc, and value.

Referenced by dwgpio_probe(), dwuart_probe(), fdt_phandle(), fdt_reg_cells(), and fdt_test_exec().

◆ fdt_phandle()

uint32_t fdt_phandle ( struct fdt fdt,
unsigned int  offset 
)

Get package handle (phandle) property.

Parameters
fdtDevice tree
offsetStarting node offset
Return values
phandlePackage handle, or 0 on error

Definition at line 690 of file fdt.c.

690  {
691  uint32_t phandle;
692  int rc;
693 
694  /* Get "phandle" or "linux,phandle" property */
695  if ( ( ( rc = fdt_u32 ( fdt, offset, "phandle", &phandle ) ) == 0 ) ||
696  ( ( rc = fdt_u32 ( fdt, offset, "linux,phandle",
697  &phandle ) ) == 0 ) ) {
698  assert ( phandle != 0 );
699  return phandle;
700  }
701 
702  return 0;
703 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int fdt_u32(struct fdt *fdt, unsigned int offset, const char *name, uint32_t *value)
Get 32-bit integer property.
Definition: fdt.c:664
unsigned int uint32_t
Definition: stdint.h:12
A device tree.
Definition: fdt.h:89
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

References assert(), fdt_u32(), offset, and rc.

Referenced by dt_probe_node(), and fdt_test_exec().

◆ fdt_reg_cells()

void fdt_reg_cells ( struct fdt fdt,
unsigned int  offset,
struct fdt_reg_cells regs 
)

Get region cell size specification.

Parameters
fdtDevice tree
offsetStarting (parent) node offset
regsRegion cell size specification to fill in

Note that address-cells and size-cells are defined on the immediate parent node, rather than on the node with the "reg" property itself.

Definition at line 716 of file fdt.c.

717  {
718  int rc;
719 
720  /* Read #address-cells, if present */
721  if ( ( rc = fdt_u32 ( fdt, offset, "#address-cells",
722  &regs->address_cells ) ) != 0 ) {
723  regs->address_cells = FDT_DEFAULT_ADDRESS_CELLS;
724  }
725 
726  /* Read #size-cells, if present */
727  if ( ( rc = fdt_u32 ( fdt, offset, "#size-cells",
728  &regs->size_cells ) ) != 0 ) {
729  regs->size_cells = FDT_DEFAULT_SIZE_CELLS;
730  }
731 
732  /* Calculate stride */
733  regs->stride = ( regs->address_cells + regs->size_cells );
734 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int fdt_u32(struct fdt *fdt, unsigned int offset, const char *name, uint32_t *value)
Get 32-bit integer property.
Definition: fdt.c:664
struct i386_regs regs
Definition: registers.h:15
A device tree.
Definition: fdt.h:89
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
#define FDT_DEFAULT_SIZE_CELLS
Default number of size cells, if not specified.
Definition: fdt.h:150
#define FDT_DEFAULT_ADDRESS_CELLS
Default number of address cells, if not specified.
Definition: fdt.h:147

References FDT_DEFAULT_ADDRESS_CELLS, FDT_DEFAULT_SIZE_CELLS, fdt_u32(), offset, rc, and regs.

Referenced by fdt_parent_reg_cells(), and fdtmem_update_node().

◆ fdt_parent_reg_cells()

int fdt_parent_reg_cells ( struct fdt fdt,
unsigned int  offset,
struct fdt_reg_cells regs 
)

Get parent region cell size specification.

Parameters
fdtDevice tree
offsetStarting node offset
regsRegion cell size specification to fill in
Return values
rcReturn status code

Definition at line 744 of file fdt.c.

745  {
746  unsigned int parent;
747  int rc;
748 
749  /* Get parent node */
750  if ( ( rc = fdt_parent ( fdt, offset, &parent ) ) != 0 )
751  return rc;
752 
753  /* Read #address-cells and #size-cells, if present */
754  fdt_reg_cells ( fdt, parent, regs );
755 
756  return 0;
757 }
int fdt_parent(struct fdt *fdt, unsigned int offset, unsigned int *parent)
Find parent node.
Definition: fdt.c:293
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void fdt_reg_cells(struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs)
Get region cell size specification.
Definition: fdt.c:716
struct i386_regs regs
Definition: registers.h:15
A device tree.
Definition: fdt.h:89
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

References fdt_parent(), fdt_reg_cells(), offset, rc, and regs.

Referenced by dt_ioremap(), and fdt_reg().

◆ fdt_reg_count()

int fdt_reg_count ( struct fdt fdt,
unsigned int  offset,
struct fdt_reg_cells regs 
)

Get number of regions.

Parameters
fdtDevice tree
offsetStarting node offset
regsRegion cell size specification
Return values
countNumber of regions, or negative error

Definition at line 767 of file fdt.c.

768  {
769  struct fdt_descriptor desc;
770  const uint32_t *cell;
771  unsigned int count;
772  int rc;
773 
774  /* Find property */
775  if ( ( rc = fdt_property ( fdt, offset, "reg", &desc ) ) != 0 )
776  return rc;
777 
778  /* Determine number of regions */
779  count = ( desc.len / ( regs->stride * sizeof ( *cell ) ) );
780  return count;
781 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
static int fdt_property(struct fdt *fdt, unsigned int offset, const char *name, struct fdt_descriptor *desc)
Find property.
Definition: fdt.c:495
static unsigned int count
Number of entries.
Definition: dwmac.h:225
unsigned int uint32_t
Definition: stdint.h:12
struct i386_regs regs
Definition: registers.h:15
A device tree.
Definition: fdt.h:89
A device tree token descriptor.
Definition: fdt.h:121
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

References count, desc, fdt_property(), offset, rc, and regs.

Referenced by fdtmem_update_node().

◆ fdt_reg_address()

int fdt_reg_address ( struct fdt fdt,
unsigned int  offset,
struct fdt_reg_cells regs,
unsigned int  index,
uint64_t address 
)

Get region address.

Parameters
fdtDevice tree
offsetStarting node offset
regsRegion cell size specification
indexRegion index
addressRegion starting address to fill in
Return values
rcReturn status code

Definition at line 793 of file fdt.c.

795  {
796  unsigned int cell = ( index * regs->stride );
797  int rc;
798 
799  /* Read relevant portion of region array */
800  if ( ( rc = fdt_cells ( fdt, offset, "reg", cell, regs->address_cells,
801  address ) ) != 0 ) {
802  return rc;
803  }
804 
805  return 0;
806 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t address
Base address.
Definition: ena.h:24
long index
Definition: bigint.h:65
struct i386_regs regs
Definition: registers.h:15
A device tree.
Definition: fdt.h:89
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
int fdt_cells(struct fdt *fdt, unsigned int offset, const char *name, unsigned int index, unsigned int count, uint64_t *value)
Get integer property.
Definition: fdt.c:598

References address, fdt_cells(), index, offset, rc, and regs.

Referenced by dt_ioremap(), fdt_reg(), and fdtmem_update_node().

◆ fdt_reg_size()

int fdt_reg_size ( struct fdt fdt,
unsigned int  offset,
struct fdt_reg_cells regs,
unsigned int  index,
uint64_t size 
)

Get region size.

Parameters
fdtDevice tree
offsetStarting node offset
regsRegion cell size specification
indexRegion index
sizeRegion size to fill in
Return values
rcReturn status code

Definition at line 818 of file fdt.c.

820  {
821  unsigned int cell = ( ( index * regs->stride ) + regs->address_cells );
822  int rc;
823 
824  /* Read relevant portion of region array */
825  if ( ( rc = fdt_cells ( fdt, offset, "reg", cell, regs->size_cells,
826  size ) ) != 0 ) {
827  return rc;
828  }
829 
830  return 0;
831 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint16_t size
Buffer size.
Definition: dwmac.h:14
long index
Definition: bigint.h:65
struct i386_regs regs
Definition: registers.h:15
A device tree.
Definition: fdt.h:89
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
int fdt_cells(struct fdt *fdt, unsigned int offset, const char *name, unsigned int index, unsigned int count, uint64_t *value)
Get integer property.
Definition: fdt.c:598

References fdt_cells(), index, offset, rc, regs, and size.

Referenced by dt_ioremap(), and fdtmem_update_node().

◆ fdt_reg()

int fdt_reg ( struct fdt fdt,
unsigned int  offset,
uint64_t region 
)

Get unsized single-entry region address.

Parameters
fdtDevice tree
offsetStarting node offset
addressRegion address to fill in
Return values
rcReturn status code

Many region types (e.g. I2C bus addresses) can only ever contain a single region with no size cells specified.

Definition at line 844 of file fdt.c.

844  {
845  struct fdt_reg_cells regs;
846  int rc;
847 
848  /* Get parent region cell size specification */
849  if ( ( rc = fdt_parent_reg_cells ( fdt, offset, &regs ) ) != 0 )
850  return rc;
851 
852  /* Get first region address */
853  if ( ( rc = fdt_reg_address ( fdt, offset, &regs, 0, region ) ) != 0 )
854  return rc;
855 
856  return 0;
857 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A device tree region cell size specification.
Definition: fdt.h:137
int fdt_reg_address(struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs, unsigned int index, uint64_t *address)
Get region address.
Definition: fdt.c:793
struct i386_regs regs
Definition: registers.h:15
A device tree.
Definition: fdt.h:89
int fdt_parent_reg_cells(struct fdt *fdt, unsigned int offset, struct fdt_reg_cells *regs)
Get parent region cell size specification.
Definition: fdt.c:744
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

References fdt_parent_reg_cells(), fdt_reg_address(), offset, rc, and regs.

Referenced by dwgpio_probe().

◆ fdt_mac()

int fdt_mac ( struct fdt fdt,
unsigned int  offset,
struct net_device netdev 
)

Get MAC address from property.

Parameters
fdtDevice tree
offsetStarting node offset
netdevNetwork device
Return values
rcReturn status code

Definition at line 867 of file fdt.c.

868  {
869  struct fdt_descriptor desc;
870  size_t len;
871  int rc;
872 
873  /* Find applicable MAC address property */
874  if ( ( ( rc = fdt_property ( fdt, offset, "mac-address",
875  &desc ) ) != 0 ) &&
876  ( ( rc = fdt_property ( fdt, offset, "local-mac-address",
877  &desc ) ) != 0 ) ) {
878  return rc;
879  }
880 
881  /* Check length */
883  if ( len != desc.len ) {
884  DBGC ( fdt, "FDT malformed MAC address \"%s\":\n",
885  desc.name );
886  DBGC_HDA ( fdt, 0, desc.data, desc.len );
887  return -ERANGE;
888  }
889 
890  /* Fill in MAC address */
891  memcpy ( netdev->hw_addr, desc.data, len );
892 
893  return 0;
894 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint8_t hw_addr_len
Hardware address length.
Definition: netdevice.h:197
#define DBGC_HDA(...)
Definition: compiler.h:506
static int fdt_property(struct fdt *fdt, unsigned int offset, const char *name, struct fdt_descriptor *desc)
Find property.
Definition: fdt.c:495
ring len
Length.
Definition: dwmac.h:231
static struct net_device * netdev
Definition: gdbudp.c:53
#define ERANGE
Result too large.
Definition: errno.h:640
A device tree.
Definition: fdt.h:89
A device tree token descriptor.
Definition: fdt.h:121
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:382
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:373

References DBGC, DBGC_HDA, desc, ERANGE, fdt_property(), net_device::hw_addr, ll_protocol::hw_addr_len, len, net_device::ll_protocol, memcpy(), netdev, offset, and rc.

Referenced by cgem_probe(), dwmac_probe(), and smscusb_fdt_fetch_mac().

◆ fdt_parse()

int fdt_parse ( struct fdt fdt,
struct fdt_header hdr,
size_t  max_len 
)

Parse device tree.

Parameters
fdtDevice tree
hdrDevice tree header
max_lenMaximum device tree length
Return values
rcReturn status code

Definition at line 904 of file fdt.c.

904  {
905  const uint8_t *nul;
906  unsigned int chosen;
907  size_t end;
908 
909  /* Sanity check */
910  if ( sizeof ( *hdr ) > max_len ) {
911  DBGC ( fdt, "FDT length %#zx too short for header\n",
912  max_len );
913  goto err;
914  }
915 
916  /* Record device tree location */
917  fdt->hdr = hdr;
918  fdt->len = be32_to_cpu ( hdr->totalsize );
919  fdt->used = sizeof ( *hdr );
920  if ( fdt->len > max_len ) {
921  DBGC ( fdt, "FDT has invalid length %#zx / %#zx\n",
922  fdt->len, max_len );
923  goto err;
924  }
925  DBGC ( fdt, "FDT version %d at %p+%#04zx (phys %#08lx)\n",
926  be32_to_cpu ( hdr->version ), fdt->hdr, fdt->len,
927  virt_to_phys ( hdr ) );
928 
929  /* Check signature */
930  if ( hdr->magic != cpu_to_be32 ( FDT_MAGIC ) ) {
931  DBGC ( fdt, "FDT has invalid magic value %#08x\n",
932  be32_to_cpu ( hdr->magic ) );
933  goto err;
934  }
935 
936  /* Check version */
937  if ( hdr->last_comp_version != cpu_to_be32 ( FDT_VERSION ) ) {
938  DBGC ( fdt, "FDT unsupported version %d\n",
939  be32_to_cpu ( hdr->last_comp_version ) );
940  goto err;
941  }
942 
943  /* Record structure block location */
944  fdt->structure = be32_to_cpu ( hdr->off_dt_struct );
945  fdt->structure_len = be32_to_cpu ( hdr->size_dt_struct );
946  DBGC ( fdt, "FDT structure block at +[%#04x,%#04zx)\n",
948  if ( ( fdt->structure > fdt->len ) ||
949  ( fdt->structure_len > ( fdt->len - fdt->structure ) ) ) {
950  DBGC ( fdt, "FDT structure block exceeds table\n" );
951  goto err;
952  }
953  if ( ( fdt->structure | fdt->structure_len ) &
954  ( FDT_STRUCTURE_ALIGN - 1 ) ) {
955  DBGC ( fdt, "FDT structure block is misaligned\n" );
956  goto err;
957  }
958  end = ( fdt->structure + fdt->structure_len );
959  if ( fdt->used < end )
960  fdt->used = end;
961 
962  /* Record strings block location */
963  fdt->strings = be32_to_cpu ( hdr->off_dt_strings );
964  fdt->strings_len = be32_to_cpu ( hdr->size_dt_strings );
965  DBGC ( fdt, "FDT strings block at +[%#04x,%#04zx)\n",
966  fdt->strings, ( fdt->strings + fdt->strings_len ) );
967  if ( ( fdt->strings > fdt->len ) ||
968  ( fdt->strings_len > ( fdt->len - fdt->strings ) ) ) {
969  DBGC ( fdt, "FDT strings block exceeds table\n" );
970  goto err;
971  }
972  end = ( fdt->strings + fdt->strings_len );
973  if ( fdt->used < end )
974  fdt->used = end;
975 
976  /* Shrink strings block to ensure NUL termination safety */
977  nul = ( fdt->raw + fdt->strings + fdt->strings_len );
978  for ( ; fdt->strings_len ; fdt->strings_len-- ) {
979  if ( *(--nul) == '\0' )
980  break;
981  }
982  if ( fdt->strings_len != be32_to_cpu ( hdr->size_dt_strings ) ) {
983  DBGC ( fdt, "FDT strings block shrunk to +[%#04x,%#04zx)\n",
984  fdt->strings, ( fdt->strings + fdt->strings_len ) );
985  }
986 
987  /* Record memory reservation block location */
988  fdt->reservations = be32_to_cpu ( hdr->off_mem_rsvmap );
989  DBGC ( fdt, "FDT memory reservations at +[%#04x,...)\n",
990  fdt->reservations );
991  if ( fdt->used <= fdt->reservations ) {
992  /* No size field exists: assume whole table is used */
993  fdt->used = fdt->len;
994  }
995 
996  /* Identify free space (if any) */
997  if ( fdt->used < fdt->len ) {
998  DBGC ( fdt, "FDT free space at +[%#04zx,%#04zx)\n",
999  fdt->used, fdt->len );
1000  }
1001 
1002  /* Print model name and boot arguments (for debugging) */
1003  if ( DBG_LOG ) {
1004  DBGC ( fdt, "FDT model is \"%s\"\n",
1005  fdt_string ( fdt, 0, "model" ) );
1006  if ( fdt_child ( fdt, 0, "chosen", &chosen ) == 0 ) {
1007  DBGC ( fdt, "FDT boot arguments \"%s\"\n",
1008  fdt_string ( fdt, chosen, "bootargs" ) );
1009  }
1010  }
1011 
1012  return 0;
1013 
1014  err:
1015  DBGC_HDA ( fdt, 0, hdr, sizeof ( *hdr ) );
1016  memset ( fdt, 0, sizeof ( *fdt ) );
1017  return -EINVAL;
1018 }
#define EINVAL
Invalid argument.
Definition: errno.h:429
#define FDT_STRUCTURE_ALIGN
Alignment of structure block.
Definition: fdt.h:75
unsigned int reservations
Offset to memory reservation block.
Definition: fdt.h:110
size_t len
Length of tree.
Definition: fdt.h:98
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
void * raw
Raw data.
Definition: fdt.h:95
#define DBGC(...)
Definition: compiler.h:505
size_t strings_len
Length of strings block.
Definition: fdt.h:108
struct fdt_header * hdr
Tree header.
Definition: fdt.h:93
#define be32_to_cpu(value)
Definition: byteswap.h:117
#define FDT_MAGIC
Magic signature.
Definition: fdt.h:43
#define DBGC_HDA(...)
Definition: compiler.h:506
const char * fdt_string(struct fdt *fdt, unsigned int offset, const char *name)
Find string property.
Definition: fdt.c:579
unsigned int structure
Offset to structure block.
Definition: fdt.h:102
#define FDT_VERSION
Expected device tree version.
Definition: fdt.h:46
static int fdt_child(struct fdt *fdt, unsigned int offset, const char *name, unsigned int *child)
Find child node.
Definition: fdt.c:347
unsigned char uint8_t
Definition: stdint.h:10
size_t used
Used length of tree.
Definition: fdt.h:100
size_t structure_len
Length of structure block.
Definition: fdt.h:104
#define cpu_to_be32(value)
Definition: byteswap.h:111
A device tree.
Definition: fdt.h:89
uint32_t end
Ending offset.
Definition: netvsc.h:18
#define DBG_LOG
Definition: compiler.h:317
unsigned int strings
Offset to strings block.
Definition: fdt.h:106
void * memset(void *dest, int character, size_t len) __nonnull

References be32_to_cpu, cpu_to_be32, DBG_LOG, DBGC, DBGC_HDA, EINVAL, end, fdt_child(), FDT_MAGIC, fdt_string(), FDT_STRUCTURE_ALIGN, FDT_VERSION, fdt::hdr, hdr, fdt::len, memset(), fdt::raw, fdt::reservations, fdt::strings, fdt::strings_len, fdt::structure, fdt::structure_len, and fdt::used.

Referenced by efi_fdt_init(), fdt_parse_image(), fdt_test_exec(), fdtmem_register(), and fdtmem_relocate().

◆ fdt_create()

int fdt_create ( struct fdt_header **  hdr,
const char *  cmdline,
physaddr_t  initrd,
size_t  initrd_len 
)

Create device tree.

Parameters
hdrDevice tree header to fill in (may be set to NULL)
cmdlineCommand line, or NULL
initrdInitial ramdisk address (or 0 for no initrd)
initrd_lenInitial ramdisk length (or 0 for no initrd)
Return values
rcReturn status code

Definition at line 1408 of file fdt.c.

1409  {
1410  struct image *image;
1411  struct fdt fdt;
1412  void *copy;
1413  int rc;
1414 
1415  /* Use system FDT as the base by default */
1416  memcpy ( &fdt, &sysfdt, sizeof ( fdt ) );
1417 
1418  /* If an FDT image exists, use this instead */
1419  image = find_image_tag ( &fdt_image );
1420  if ( image && ( ( rc = fdt_parse_image ( &fdt, image ) ) != 0 ) )
1421  goto err_image;
1422 
1423  /* Exit successfully if we have no base FDT */
1424  if ( ! fdt.len ) {
1425  DBGC ( &fdt, "FDT has no base tree\n" );
1426  goto no_fdt;
1427  }
1428 
1429  /* Create modifiable copy */
1430  copy = umalloc ( fdt.len );
1431  if ( ! copy ) {
1432  rc = -ENOMEM;
1433  goto err_alloc;
1434  }
1435  memcpy ( copy, fdt.raw, fdt.len );
1436  fdt.raw = copy;
1438 
1439  /* Populate boot arguments */
1440  if ( ( rc = fdt_bootargs ( &fdt, cmdline, initrd, initrd_len ) ) != 0 )
1441  goto err_bootargs;
1442 
1443  no_fdt:
1444  *hdr = fdt.raw;
1445  return 0;
1446 
1447  err_bootargs:
1448  ufree ( fdt.raw );
1449  err_alloc:
1450  err_image:
1451  return rc;
1452 }
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:68
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int(* realloc)(struct fdt *fdt, size_t len)
Reallocate device tree.
Definition: fdt.h:117
static int fdt_urealloc(struct fdt *fdt, size_t len)
Reallocate device tree via urealloc()
Definition: fdt.c:1330
size_t len
Length of tree.
Definition: fdt.h:98
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
void * raw
Raw data.
Definition: fdt.h:95
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
struct image * find_image_tag(struct image_tag *tag)
Find image by tag.
Definition: image.c:393
#define ENOMEM
Not enough space.
Definition: errno.h:535
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static int fdt_bootargs(struct fdt *fdt, const char *cmdline, physaddr_t initrd, size_t initrd_len)
Populate device tree with boot arguments.
Definition: fdt.c:1363
A device tree.
Definition: fdt.h:89
static __always_inline void * umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:57
uint32_t cmdline
Definition: multiboot.h:16
static int fdt_parse_image(struct fdt *fdt, struct image *image)
Parse device tree image.
Definition: fdt.c:1027
#define initrd_len
Definition: runtime.c:63
struct fdt sysfdt
The system flattened device tree (if present)
Definition: fdt.c:45

References cmdline, DBGC, ENOMEM, fdt_bootargs(), fdt_parse_image(), fdt_urealloc(), find_image_tag(), hdr, initrd_len, fdt::len, memcpy(), fdt::raw, rc, fdt::realloc, sysfdt, ufree(), and umalloc().

Referenced by efi_fdt_install(), fdt_test_exec(), and lkrn_exec().

◆ fdt_remove()

void fdt_remove ( struct fdt_header hdr)

Remove device tree.

Parameters
hdrDevice tree header, or NULL

Definition at line 1459 of file fdt.c.

1459  {
1460 
1461  /* Free modifiable copy */
1462  ufree ( hdr );
1463 }
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:68
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28

References hdr, and ufree().

Referenced by efi_fdt_install(), efi_fdt_uninstall(), fdt_test_exec(), and lkrn_exec().

Variable Documentation

◆ __image_tag

struct image_tag fdt_image __image_tag

The downloaded flattened device tree tag.

The downloaded flattened device tree tag.

Currently-executing image.

The downloaded flattened device tree tag.

Definition at line 48 of file fdt.c.

◆ sysfdt

struct fdt sysfdt