RTEMS 6.1-rc4
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
ofw.h File Reference
#include <rtems.h>
#include <stdint.h>
#include <sys/types.h>

Go to the source code of this file.

Data Structures

struct  rtems_ofw_memory_area
 
struct  rtems_ofw_ranges
 

Typedefs

typedef uint32_t phandle_t
 
typedef uint32_t ihandle_t
 
typedef uint32_t pcell_t
 

Functions

phandle_t rtems_ofw_peer (phandle_t node)
 Gets the node that is next to node.
 
phandle_t rtems_ofw_child (phandle_t node)
 Gets the node that is the child of node.
 
phandle_t rtems_ofw_parent (phandle_t node)
 Gets the node that is the parent of node.
 
ssize_t rtems_ofw_get_prop_len (phandle_t node, const char *propname)
 Gets the length of the property mentioned in propname.
 
ssize_t rtems_ofw_get_prop (phandle_t node, const char *propname, void *buf, size_t len)
 Gets the value of property mentioned in propname.
 
ssize_t rtems_ofw_get_enc_prop (phandle_t node, const char *prop, pcell_t *buf, size_t len)
 Gets the value of property mentioned in prop.
 
int rtems_ofw_has_prop (phandle_t node, const char *propname)
 Checks if the property propname is present in node.
 
ssize_t rtems_ofw_search_prop (phandle_t node, const char *propname, void *buf, size_t len)
 Searches for property propname in node.
 
ssize_t rtems_ofw_search_enc_prop (phandle_t node, const char *propname, pcell_t *buf, size_t len)
 Searches for property propname in node.
 
ssize_t rtems_ofw_get_prop_alloc (phandle_t node, const char *propname, void **buf)
 Gets the value of property mentioned in propname.
 
ssize_t rtems_ofw_get_prop_alloc_multi (phandle_t node, const char *propname, int elsz, void **buf)
 Gets multiple values of the property propname.
 
ssize_t rtems_ofw_get_enc_prop_alloc (phandle_t node, const char *propname, void **buf)
 Gets the value of property mentioned in propname.
 
ssize_t rtems_ofw_get_enc_prop_alloc_multi (phandle_t node, const char *propname, int elsz, void **buf)
 Gets multiple values of the property propname.
 
void rtems_ofw_free (void *buf)
 Free's the buffers allocated by the rtems_ofw_*_alloc functions.
 
int rtems_ofw_next_prop (phandle_t node, const char *previous, char *buf, size_t len)
 Finds the next property of node.
 
of @a node to @a buf.

Sets the property

Parameters
[in]nodeNode offset
[in]nameProperty name
[in]bufBuffer contains the value to be set.
[in]lenLength of the buffer
Return values
-1node does not exist
0on success
libFDTerror codes on unsuccessful setting operation
int rtems_ofw_set_prop (phandle_t node, const char *name, const void *buf, size_t len)
 
ssize_t rtems_ofw_canon (const char *dev, char *buf, size_t len)
 Converts a device specifier to a fully qualified path name.
 
phandle_t rtems_ofw_find_device (const char *path)
 Finds the node at the given path.
 
phandle_t rtems_ofw_node_from_xref (phandle_t xref)
 This routine converts effective phandle xref to node offset.
 
phandle_t rtems_ofw_xref_from_node (phandle_t node)
 This routine converts node offset to effective phandle of node.
 
phandle_t rtems_ofw_instance_to_package (ihandle_t instance)
 Converts instance handle to phandle.
 
ssize_t rtems_ofw_package_to_path (phandle_t node, char *buf, size_t len)
 Find the node's path from phandle.
 
ssize_t rtems_ofw_instance_to_path (ihandle_t instance, char *buf, size_t len)
 Find the node's path from ihandle.
 
int rtems_ofw_get_reg (phandle_t node, rtems_ofw_memory_area *buf, size_t size)
 Queries the node's reg value.
 
int rtems_ofw_get_interrupts (phandle_t node, rtems_vector_number *buf, size_t size)
 Queries the node's interrupt value.
 
bool rtems_ofw_node_status (phandle_t node)
 Queries the node's status.
 
phandle_t rtems_ofw_find_device_by_compat (const char *compat)
 Gets node phandle from compatible property.
 
bool rtems_ofw_is_node_compatible (phandle_t node, const char *compat)
 check a nodes compatible property.
 

Detailed Description

RTEMS FDT implementation of OpenFirmWare Interface.

RTEMS OFW is a FDT only implementation of the OpenFirmWare interface. This API is created to be compatible with FreeBSD OpenFirmWare interface. The main intention is to make porting of FreeBSD drivers to RTEMS easier.

Typedef Documentation

◆ ihandle_t

typedef uint32_t ihandle_t

Represents the effective phandle of the node.

◆ pcell_t

typedef uint32_t pcell_t

Represents the data type of the buffer.

◆ phandle_t

typedef uint32_t phandle_t

Represents a node in the device tree. The offset from fdtp to node is used instead of fdt offset to make sure this is compatible with OF interface in FreeBSD.

Function Documentation

◆ rtems_ofw_canon()

ssize_t rtems_ofw_canon ( const char *  dev,
char *  buf,
size_t  len 
)

Converts a device specifier to a fully qualified path name.

Parameters
[in]devdevice specifier
[out]bufThe path is filled into the buffer(Pre-allocated)
[in]lengthof the buffer
Return values
-1always. Unimplemented.

◆ rtems_ofw_child()

phandle_t rtems_ofw_child ( phandle_t  node)

Gets the node that is the child of node.

Parameters
[in]nodeNode offset
Return values
childnode offset Successful operation.
0No child node or invalid node handle

◆ rtems_ofw_find_device()

phandle_t rtems_ofw_find_device ( const char *  path)

Finds the node at the given path.

Parameters
[in]pathto the node from root
Return values
-1node does not exist
nodehandle on success

◆ rtems_ofw_find_device_by_compat()

phandle_t rtems_ofw_find_device_by_compat ( const char *  compat)

Gets node phandle from compatible property.

This routine is local to RTEMS OFW and does not have an corresponding FreeBSD OFW pair.

Parameters
[in]compatCompatible string
Return values
0Node with compat as compatible string not found
Nodephandle on success.

◆ rtems_ofw_free()

void rtems_ofw_free ( void *  buf)

Free's the buffers allocated by the rtems_ofw_*_alloc functions.

Parameters
[in]bufBuffer to be freed

◆ rtems_ofw_get_enc_prop()

ssize_t rtems_ofw_get_enc_prop ( phandle_t  node,
const char *  prop,
pcell_t buf,
size_t  len 
)

Gets the value of property mentioned in prop.

Gets the value of property of node and converts the value into the host's endianness.

Parameters
[in]nodeNode offset
[in]propProperty name
[out]bufThe property value gets stored in this buffer(Pre-allocated) after converted to the host's endianness
[in]lenLength of the buffer
Return values
-1Invalid node or property
Lengthof property on successful operation

◆ rtems_ofw_get_enc_prop_alloc()

ssize_t rtems_ofw_get_enc_prop_alloc ( phandle_t  node,
const char *  propname,
void **  buf 
)

Gets the value of property mentioned in propname.

Same as rtems_ofw_getprop_alloc but the value stored in the buffer is converted into the host's endianness.

Parameters
[in]nodeNode offset
[in]propnameProperty name
[out]bufThe buffer is allocated in this routine and user is responsible for freeing.
Return values
-1Property is not found.
Lengthof the property if property is found.

◆ rtems_ofw_get_enc_prop_alloc_multi()

ssize_t rtems_ofw_get_enc_prop_alloc_multi ( phandle_t  node,
const char *  propname,
int  elsz,
void **  buf 
)

Gets multiple values of the property propname.

Same as rtems_ofw_getprop_alloc_multi but the values stored in the buffer are converted to the host's endianness.

Parameters
[in]nodeNode offset
[in]propnameProperty name
[in]elszSize of the single value
[out]bufThe buffer is allocated in this routine and user is responsible for freeing.
Return values
-1Property is not found.
Numberof values read.

◆ rtems_ofw_get_interrupts()

int rtems_ofw_get_interrupts ( phandle_t  node,
rtems_vector_number buf,
size_t  size 
)

Queries the node's interrupt value.

This routine fills the buffer buf with the interrupt number. In case of multiple numbers it fills the buffer to its full extent. This routine is local to RTEMS OFW and does not have an corresponding FreeBSD OFW pair.

Parameters
[in]nodeNode offset
[out]bufInterrupt values are stored in this buffer(Pre-allocated).
[in]sizeLength of the buffer.
Return values
-1If interrupts property is missing.
Thenumber of interrupt numbers read.

◆ rtems_ofw_get_prop()

ssize_t rtems_ofw_get_prop ( phandle_t  node,
const char *  propname,
void *  buf,
size_t  len 
)

Gets the value of property mentioned in propname.

Parameters
[in]nodeNode offset
[in]propProperty name
[out]bufThe property value gets stored in this buffer (Pre-allocated)
[in]lenLength of the buffer
Return values
-1Invalid node or property
Lengthof property on successful operation

◆ rtems_ofw_get_prop_alloc()

ssize_t rtems_ofw_get_prop_alloc ( phandle_t  node,
const char *  propname,
void **  buf 
)

Gets the value of property mentioned in propname.

Same as rtems_ofw_getprop, but the buf is allocated in this routine and the user is responsible for freeing it.

Parameters
[in]nodeNode offset
[in]propnameProperty name
[out]bufThe buffer is allocated in this routine and user is responsible for freeing.
Return values
-1Property is not found.
Lengthof the property if property is found.

◆ rtems_ofw_get_prop_alloc_multi()

ssize_t rtems_ofw_get_prop_alloc_multi ( phandle_t  node,
const char *  propname,
int  elsz,
void **  buf 
)

Gets multiple values of the property propname.

Same as rtems_ofw_getprop_alloc but it can read properties with multiple values. For eg: reg = <0x1000 0x10 0x2000 0x20>

Parameters
[in]nodeNode offset
[in]propnameProperty name
[in]elszSize of the single value
[out]bufThe buffer is allocated in this routine and user is responsible for freeing.
Return values
-1Property is not found.
Numberof values read.

◆ rtems_ofw_get_prop_len()

ssize_t rtems_ofw_get_prop_len ( phandle_t  node,
const char *  propname 
)

Gets the length of the property mentioned in propname.

Parameters
[in]nodeNode offset
[in]propProperty name
Return values
-1Invalid node or property
Lengthof property on successful operation

◆ rtems_ofw_get_reg()

int rtems_ofw_get_reg ( phandle_t  node,
rtems_ofw_memory_area buf,
size_t  size 
)

Queries the node's reg value.

This routine fills the buffer buf with the values in reg property of node node. It reads all the values of the property and fills the buffer to max size. This routine is local to RTEMS OFW and does not have an corresponding FreeBSD OFW pair.

Parameters
[in]nodeNode offset
[out]bufRegister values are stored in this buffer(Pre-allocated).
[in]sizeLength of the buffer.
Return values
-1If reg property is missing.
Lengthof the reg property in bytes.

(buf + size - (sizeof(buf[0]) - 1) is the last valid address for buf[i]. If buf[i] points to any address larger than this, it will be an out of bound access

◆ rtems_ofw_has_prop()

int rtems_ofw_has_prop ( phandle_t  node,
const char *  propname 
)

Checks if the property propname is present in node.

Parameters
[in]nodeNode offset
[in]propnameProperty name
Return values
0Property not present.
1Property is present.

◆ rtems_ofw_instance_to_package()

phandle_t rtems_ofw_instance_to_package ( ihandle_t  instance)

Converts instance handle to phandle.

instance are same as node offsets in FDT.

Parameters
[in]instanceNode offset
Return values
phandleof node on success.
instanceof node on failure.

◆ rtems_ofw_instance_to_path()

ssize_t rtems_ofw_instance_to_path ( ihandle_t  instance,
char *  buf,
size_t  len 
)

Find the node's path from ihandle.

Parameters
[in]instanceNode offset
[out]bufPath is filled into this buffer(Pre-allocated).
[in]lenLength of the buffer.
Return values
-1always. Unimplemented.

◆ rtems_ofw_is_node_compatible()

bool rtems_ofw_is_node_compatible ( phandle_t  node,
const char *  compat 
)

check a nodes compatible property.

This routine is local to RTEMS OFW and does not have an corresponding FreeBSD OFW pair.

Return true if compat equals node compatible property

Parameters
[in]nodephandle of node
[in]compatCompatible string
Return values
1If node contains the compat as a element in compatible property.
0Otherwise.

◆ rtems_ofw_next_prop()

int rtems_ofw_next_prop ( phandle_t  node,
const char *  previous,
char *  buf,
size_t  len 
)

Finds the next property of node.

Finds the next property of the node and when propname is NULL it returns the value in the first property.

Parameters
[in]nodeNode offset
[in]previousPrevious property name
[out]bufThe value of the next property gets stored in this buffer (Pre-allocated)
[in]lenLength of the buffer
Return values
-1node or previous property does not exist
0no more properties
1success

◆ rtems_ofw_node_from_xref()

phandle_t rtems_ofw_node_from_xref ( phandle_t  xref)

This routine converts effective phandle xref to node offset.

Parameters
[in]xrefNode phandle
Return values
Nodeoffset on success
Nodephandle on failure

◆ rtems_ofw_node_status()

bool rtems_ofw_node_status ( phandle_t  node)

Queries the node's status.

This routine is local to RTEMS OFW and does not have an corresponding FreeBSD OFW pair.

Parameters
[in]nodeNode offset
Return values
trueStatus is OK or empty.
falseStatus is not OK or missing.

◆ rtems_ofw_package_to_path()

ssize_t rtems_ofw_package_to_path ( phandle_t  node,
char *  buf,
size_t  len 
)

Find the node's path from phandle.

Parameters
[in]nodeNode offset
[out]bufPath is filled into this buffer(Pre-allocated).
[in]lenLength of the buffer.
Return values
-1always. Unimplemented.

◆ rtems_ofw_parent()

phandle_t rtems_ofw_parent ( phandle_t  node)

Gets the node that is the parent of node.

Parameters
[in]nodeNode offset
Return values
childnode offset Successful operation.
0No child node or invalid node handle

◆ rtems_ofw_peer()

phandle_t rtems_ofw_peer ( phandle_t  node)

Gets the node that is next to node.

Parameters
[in]nodeNode offset
Return values
Peernode offset Successful operation.
0No peer node or invalid node handle

◆ rtems_ofw_search_enc_prop()

ssize_t rtems_ofw_search_enc_prop ( phandle_t  node,
const char *  propname,
pcell_t buf,
size_t  len 
)

Searches for property propname in node.

Searches the node and its parent recursively for the property and fills the buffer with the first value found after converting it to the endianness of the host.

Parameters
[in]nodeNode offset
[in]propnameProperty name
[out]bufThe property value gets stored in this buffer(Pre-allocated) after converted to the host's endianness
[in]lenLength of the buffer
Return values
Lengthof the property if property is found.
-1Property is not found.

◆ rtems_ofw_search_prop()

ssize_t rtems_ofw_search_prop ( phandle_t  node,
const char *  propname,
void *  buf,
size_t  len 
)

Searches for property propname in node.

Searches the node and its parent recursively for the property and fills the buffer with the first found value.

Parameters
[in]nodeNode offset
[in]propnameProperty name
[out]bufThe property value gets stored in this buffer (Pre-allocated)
[in]lenLength of the buffer
Return values
Lengthof the property if property is found.
-1Property is not found.

◆ rtems_ofw_xref_from_node()

phandle_t rtems_ofw_xref_from_node ( phandle_t  node)

This routine converts node offset to effective phandle of node.

Return values
Nodephandle on success
Nodeoffset on failure