From 133b335bae86bcbc9ef02eaea8caeeb624320751 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Tue, 12 Nov 2024 16:53:33 +1100 Subject: [PATCH] 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 --- cpukit/include/rtems/rtems-fdt-shell.h | 22 ++++++++++++ cpukit/libmisc/rtems-fdt/rtems-fdt-shell.c | 42 ++++++++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/cpukit/include/rtems/rtems-fdt-shell.h b/cpukit/include/rtems/rtems-fdt-shell.h index a4c87552b0..32fa738c4a 100644 --- a/cpukit/include/rtems/rtems-fdt-shell.h +++ b/cpukit/include/rtems/rtems-fdt-shell.h @@ -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 */ diff --git a/cpukit/libmisc/rtems-fdt/rtems-fdt-shell.c b/cpukit/libmisc/rtems-fdt/rtems-fdt-shell.c index 0bf6c84208..1ee2e357b8 100644 --- a/cpukit/libmisc/rtems-fdt/rtems-fdt-shell.c +++ b/cpukit/libmisc/rtems-fdt/rtems-fdt-shell.c @@ -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; +}