cpukit/libmisc/rtems-fdt: Add shell read and write handler support

The handlers allow indirect access to FDT resources registered with the
shell.

Closes #5152
This commit is contained in:
Chris Johns
2024-11-12 16:53:33 +11:00
parent b3be636863
commit 133b335bae
2 changed files with 62 additions and 2 deletions

View File

@@ -54,6 +54,28 @@ void rtems_fdt_add_shell_command (void);
*/
rtems_fdt_handle* rtems_fdt_get_shell_handle (void);
/**
* Write handler call to write from the address property.
*/
typedef void (*rtems_fdt_write_handler)(uintptr_t address, uint32_t value);
/**
* Read handler call to read from the address property.
*/
typedef uint32_t (*rtems_fdt_read_handler)(uintptr_t address);
/**
* Set the write handler returning the current handler.
*/
rtems_fdt_write_handler
rtems_fdt_set_shell_write_handler (rtems_fdt_write_handler handler);
/**
* Set the read handler returning the current handler.
*/
rtems_fdt_read_handler
rtems_fdt_set_shell_read_handler (rtems_fdt_read_handler handler);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@@ -70,20 +70,42 @@ static long rtems_fdt_test_timeout = 5;
*/
static rtems_fdt_handle cmd_fdt_handle;
/**
* The write and read handlers.
*/
static void rtems_fdt_default_write (uintptr_t address, uint32_t value);
static uint32_t rtems_fdt_default_read (uintptr_t address);
static rtems_fdt_write_handler write_handler = rtems_fdt_default_write;;
static rtems_fdt_read_handler read_handler = rtems_fdt_default_read;
static void
rtems_fdt_write (uintptr_t address, uint32_t value)
rtems_fdt_default_write (uintptr_t address, uint32_t value)
{
volatile uint32_t* ap = (uint32_t*) address;
*ap = value;
}
static uint32_t
rtems_fdt_read (uintptr_t address)
rtems_fdt_default_read (uintptr_t address)
{
volatile uint32_t* ap = (uint32_t*) address;
return *ap;
}
static void
rtems_fdt_write (uintptr_t address, uint32_t value)
{
write_handler (address, value);
}
static uint32_t
rtems_fdt_read (uintptr_t address)
{
return read_handler (address);
}
static int
rtems_fdt_wrong_number_of_args (void)
{
@@ -785,3 +807,19 @@ rtems_fdt_get_shell_handle (void)
{
return &cmd_fdt_handle;
}
rtems_fdt_write_handler
rtems_fdt_set_shell_write_handler (rtems_fdt_write_handler handler)
{
rtems_fdt_write_handler tmp = write_handler;
write_handler = handler;
return tmp;
}
rtems_fdt_read_handler
rtems_fdt_set_shell_read_handler (rtems_fdt_read_handler handler)
{
rtems_fdt_read_handler tmp = read_handler;
read_handler = handler;
return tmp;
}