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)
 
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 42 of file fdt.h.

◆ FDT_VERSION

#define FDT_VERSION   16

Expected device tree version.

Definition at line 45 of file fdt.h.

◆ FDT_BEGIN_NODE

#define FDT_BEGIN_NODE   0x00000001

Begin node token.

Definition at line 51 of file fdt.h.

◆ FDT_END_NODE

#define FDT_END_NODE   0x00000002

End node token.

Definition at line 54 of file fdt.h.

◆ FDT_PROP

#define FDT_PROP   0x00000003

Property token.

Definition at line 57 of file fdt.h.

◆ FDT_NOP

#define FDT_NOP   0x00000004

NOP token.

Definition at line 68 of file fdt.h.

◆ FDT_END

#define FDT_END   0x00000009

End of structure block.

Definition at line 71 of file fdt.h.

◆ FDT_STRUCTURE_ALIGN

#define FDT_STRUCTURE_ALIGN   ( sizeof ( fdt_token_t ) )

Alignment of structure block.

Definition at line 74 of file fdt.h.

◆ FDT_MAX_ALIGN

#define FDT_MAX_ALIGN   8

Maximum alignment of any block.

Definition at line 77 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 146 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 149 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:161
uint32_t start
Starting offset.
Definition: netvsc.h:12
A device tree.
Definition: fdt.h:88

Iterate over memory reservations.

Definition at line 167 of file fdt.h.

Typedef Documentation

◆ fdt_token_t

Device tree token.

Definition at line 48 of file fdt.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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 161 of file fdt.h.

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

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 89 of file fdt.c.

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

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

425  {
426  const char *tmp = path;
427  int rc;
428 
429  /* Initialise offset */
430  *offset = 0;
431 
432  /* Traverse tree one path segment at a time */
433  while ( 1 ) {
434 
435  /* Skip any leading '/' */
436  while ( *tmp == '/' )
437  tmp++;
438 
439  /* Terminate if there are no more path components */
440  if ( ! *tmp )
441  break;
442 
443  /* Find child */
444  if ( ( rc = fdt_child ( fdt, *offset, tmp, offset ) ) != 0 )
445  return rc;
446 
447  /* Move to next path component, if any */
448  tmp = strchr ( tmp, '/' );
449  if ( ! tmp )
450  break;
451  }
452 
453  DBGC2 ( fdt, "FDT found path \"%s\" at +%#04x\n", path, *offset );
454  return 0;
455 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned long tmp
Definition: linux_pci.h:64
static int fdt_child(struct fdt *fdt, unsigned int offset, const char *name, unsigned int *child)
Find child node.
Definition: fdt.c:346
char * strchr(const char *src, int character)
Find character within a string.
Definition: string.c:271
A device tree.
Definition: fdt.h:88
#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 465 of file fdt.c.

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

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 539 of file fdt.c.

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

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 578 of file fdt.c.

579  {
580  unsigned int count;
581 
582  /* Find strings property */
583  return fdt_strings ( fdt, offset, name, &count );
584 }
const char * name
Definition: ath9k_hw.c:1984
const char * fdt_strings(struct fdt *fdt, unsigned int offset, const char *name, unsigned int *count)
Find strings property.
Definition: fdt.c:539
static unsigned int count
Number of entries.
Definition: dwmac.h:225
A device tree.
Definition: fdt.h:88
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 597 of file fdt.c.

598  {
599  struct fdt_descriptor desc;
600  const uint32_t *cell;
601  unsigned int total;
602  int rc;
603 
604  /* Clear value */
605  *value = 0;
606 
607  /* Find property */
608  if ( ( rc = fdt_property ( fdt, offset, name, &desc ) ) != 0 )
609  return rc;
610  cell = desc.data;
611 
612  /* Determine number of cells */
613  total = ( desc.len / sizeof ( *cell ) );
614  if ( ( index > total ) || ( count > ( total - index ) ) ) {
615  DBGC ( fdt, "FDT truncated integer \"%s\"\n", name );
616  return -ERANGE;
617  }
618  if ( ! count )
619  count = ( total - index );
620  if ( count > ( sizeof ( *value ) / sizeof ( *cell ) ) ) {
621  DBGC ( fdt, "FDT overlength integer \"%s\"\n", name );
622  return -ERANGE;
623  }
624 
625  /* Read value */
626  for ( cell += index ; count ; cell++, count-- ) {
627  *value <<= 32;
628  *value |= be32_to_cpu ( *cell );
629  }
630 
631  return 0;
632 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:62
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
#define be32_to_cpu(value)
Definition: byteswap.h:116
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:494
static unsigned int count
Number of entries.
Definition: dwmac.h:225
#define ERANGE
Result too large.
Definition: errno.h:639
unsigned int uint32_t
Definition: stdint.h:12
A device tree.
Definition: fdt.h:88
A device tree token descriptor.
Definition: fdt.h:120
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 643 of file fdt.c.

644  {
645  int rc;
646 
647  /* Read value */
648  if ( ( rc = fdt_cells ( fdt, offset, name, 0, 0, value ) ) != 0 )
649  return rc;
650 
651  return 0;
652 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A device tree.
Definition: fdt.h:88
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:597

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 663 of file fdt.c.

664  {
665  uint64_t value64;
666  int rc;
667 
668  /* Read value */
669  if ( ( rc = fdt_u64 ( fdt, offset, name, &value64 ) ) != 0 )
670  return rc;
671 
672  /* Check range */
673  *value = value64;
674  if ( *value != value64 ) {
675  DBGC ( fdt, "FDT overlength 32-bit integer \"%s\"\n", name );
676  return -ERANGE;
677  }
678 
679  return 0;
680 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
#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:639
A device tree.
Definition: fdt.h:88
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:643

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 689 of file fdt.c.

689  {
690  uint32_t phandle;
691  int rc;
692 
693  /* Get "phandle" or "linux,phandle" property */
694  if ( ( ( rc = fdt_u32 ( fdt, offset, "phandle", &phandle ) ) == 0 ) ||
695  ( ( rc = fdt_u32 ( fdt, offset, "linux,phandle",
696  &phandle ) ) == 0 ) ) {
697  assert ( phandle != 0 );
698  return phandle;
699  }
700 
701  return 0;
702 }
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:663
unsigned int uint32_t
Definition: stdint.h:12
A device tree.
Definition: fdt.h:88
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 715 of file fdt.c.

716  {
717  int rc;
718 
719  /* Read #address-cells, if present */
720  if ( ( rc = fdt_u32 ( fdt, offset, "#address-cells",
721  &regs->address_cells ) ) != 0 ) {
722  regs->address_cells = FDT_DEFAULT_ADDRESS_CELLS;
723  }
724 
725  /* Read #size-cells, if present */
726  if ( ( rc = fdt_u32 ( fdt, offset, "#size-cells",
727  &regs->size_cells ) ) != 0 ) {
728  regs->size_cells = FDT_DEFAULT_SIZE_CELLS;
729  }
730 
731  /* Calculate stride */
732  regs->stride = ( regs->address_cells + regs->size_cells );
733 }
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:663
struct i386_regs regs
Definition: registers.h:15
A device tree.
Definition: fdt.h:88
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:149
#define FDT_DEFAULT_ADDRESS_CELLS
Default number of address cells, if not specified.
Definition: fdt.h:146

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 743 of file fdt.c.

744  {
745  unsigned int parent;
746  int rc;
747 
748  /* Get parent node */
749  if ( ( rc = fdt_parent ( fdt, offset, &parent ) ) != 0 )
750  return rc;
751 
752  /* Read #address-cells and #size-cells, if present */
753  fdt_reg_cells ( fdt, parent, regs );
754 
755  return 0;
756 }
int fdt_parent(struct fdt *fdt, unsigned int offset, unsigned int *parent)
Find parent node.
Definition: fdt.c:292
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:715
struct i386_regs regs
Definition: registers.h:15
A device tree.
Definition: fdt.h:88
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 766 of file fdt.c.

767  {
768  struct fdt_descriptor desc;
769  const uint32_t *cell;
770  unsigned int count;
771  int rc;
772 
773  /* Find property */
774  if ( ( rc = fdt_property ( fdt, offset, "reg", &desc ) ) != 0 )
775  return rc;
776 
777  /* Determine number of regions */
778  count = ( desc.len / ( regs->stride * sizeof ( *cell ) ) );
779  return count;
780 }
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:494
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:88
A device tree token descriptor.
Definition: fdt.h:120
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 792 of file fdt.c.

794  {
795  unsigned int cell = ( index * regs->stride );
796  int rc;
797 
798  /* Read relevant portion of region array */
799  if ( ( rc = fdt_cells ( fdt, offset, "reg", cell, regs->address_cells,
800  address ) ) != 0 ) {
801  return rc;
802  }
803 
804  return 0;
805 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t address
Base address.
Definition: ena.h:24
long index
Definition: bigint.h:62
struct i386_regs regs
Definition: registers.h:15
A device tree.
Definition: fdt.h:88
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:597

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 817 of file fdt.c.

819  {
820  unsigned int cell = ( ( index * regs->stride ) + regs->address_cells );
821  int rc;
822 
823  /* Read relevant portion of region array */
824  if ( ( rc = fdt_cells ( fdt, offset, "reg", cell, regs->size_cells,
825  size ) ) != 0 ) {
826  return rc;
827  }
828 
829  return 0;
830 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint16_t size
Buffer size.
Definition: dwmac.h:14
long index
Definition: bigint.h:62
struct i386_regs regs
Definition: registers.h:15
A device tree.
Definition: fdt.h:88
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:597

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 843 of file fdt.c.

843  {
844  struct fdt_reg_cells regs;
845  int rc;
846 
847  /* Get parent region cell size specification */
848  if ( ( rc = fdt_parent_reg_cells ( fdt, offset, &regs ) ) != 0 )
849  return rc;
850 
851  /* Get first region address */
852  if ( ( rc = fdt_reg_address ( fdt, offset, &regs, 0, region ) ) != 0 )
853  return rc;
854 
855  return 0;
856 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A device tree region cell size specification.
Definition: fdt.h:136
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:792
struct i386_regs regs
Definition: registers.h:15
A device tree.
Definition: fdt.h:88
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:743
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 866 of file fdt.c.

867  {
868  struct fdt_descriptor desc;
869  size_t len;
870  int rc;
871 
872  /* Find applicable MAC address property */
873  if ( ( ( rc = fdt_property ( fdt, offset, "mac-address",
874  &desc ) ) != 0 ) &&
875  ( ( rc = fdt_property ( fdt, offset, "local-mac-address",
876  &desc ) ) != 0 ) ) {
877  return rc;
878  }
879 
880  /* Check length */
882  if ( len != desc.len ) {
883  DBGC ( fdt, "FDT malformed MAC address \"%s\":\n",
884  desc.name );
885  DBGC_HDA ( fdt, 0, desc.data, desc.len );
886  return -ERANGE;
887  }
888 
889  /* Fill in MAC address */
890  memcpy ( netdev->hw_addr, desc.data, len );
891 
892  return 0;
893 }
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:196
#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:494
ring len
Length.
Definition: dwmac.h:231
static struct net_device * netdev
Definition: gdbudp.c:52
#define ERANGE
Result too large.
Definition: errno.h:639
A device tree.
Definition: fdt.h:88
A device tree token descriptor.
Definition: fdt.h:120
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

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 903 of file fdt.c.

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

1408  {
1409  struct image *image;
1410  struct fdt fdt;
1411  void *copy;
1412  int rc;
1413 
1414  /* Use system FDT as the base by default */
1415  memcpy ( &fdt, &sysfdt, sizeof ( fdt ) );
1416 
1417  /* If an FDT image exists, use this instead */
1418  image = find_image_tag ( &fdt_image );
1419  if ( image && ( ( rc = fdt_parse_image ( &fdt, image ) ) != 0 ) )
1420  goto err_image;
1421 
1422  /* Exit successfully if we have no base FDT */
1423  if ( ! fdt.len ) {
1424  DBGC ( &fdt, "FDT has no base tree\n" );
1425  goto no_fdt;
1426  }
1427 
1428  /* Create modifiable copy */
1429  copy = umalloc ( fdt.len );
1430  if ( ! copy ) {
1431  rc = -ENOMEM;
1432  goto err_alloc;
1433  }
1434  memcpy ( copy, fdt.raw, fdt.len );
1435  fdt.raw = copy;
1437 
1438  /* Populate boot arguments */
1439  if ( ( rc = fdt_bootargs ( &fdt, cmdline, initrd, initrd_len ) ) != 0 )
1440  goto err_bootargs;
1441 
1442  no_fdt:
1443  *hdr = fdt.raw;
1444  return 0;
1445 
1446  err_bootargs:
1447  ufree ( fdt.raw );
1448  err_alloc:
1449  err_image:
1450  return rc;
1451 }
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:67
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int(* realloc)(struct fdt *fdt, size_t len)
Reallocate device tree.
Definition: fdt.h:116
static int fdt_urealloc(struct fdt *fdt, size_t len)
Reallocate device tree via urealloc()
Definition: fdt.c:1329
size_t len
Length of tree.
Definition: fdt.h:97
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
void * raw
Raw data.
Definition: fdt.h:94
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
struct image * find_image_tag(struct image_tag *tag)
Find image by tag.
Definition: image.c:392
#define ENOMEM
Not enough space.
Definition: errno.h:534
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:1362
A device tree.
Definition: fdt.h:88
static __always_inline void * umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:56
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:1026
#define initrd_len
Definition: runtime.c:63
struct fdt sysfdt
The system flattened device tree (if present)
Definition: fdt.c:44

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 1458 of file fdt.c.

1458  {
1459 
1460  /* Free modifiable copy */
1461  ufree ( hdr );
1462 }
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:67
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 47 of file fdt.c.

◆ sysfdt

struct fdt sysfdt