This macro is designed to bind C functions into Forth words during creation of the device tree, but only into an existing node and without attempting to create any missing parent nodes.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- include/libopenbios/bindings.h | 8 ++++++++ libopenbios/bindings.c | 10 ++++++++++ 2 files changed, 18 insertions(+)
diff --git a/include/libopenbios/bindings.h b/include/libopenbios/bindings.h index 4ec9789..6360a4f 100644 --- a/include/libopenbios/bindings.h +++ b/include/libopenbios/bindings.h @@ -127,6 +127,11 @@ typedef struct { paths, 1, name##_m, sizeof(name##_m)/sizeof(method_t)); \ } while(0)
+#define BIND_NODE_METHODS(ph, name) do { \ + bind_node_methods(ph, name##_flags_, name##_size_, \ + name##_m, sizeof(name##_m)/sizeof(method_t)); \ +} while(0) + #define DECLARE_UNNAMED_NODE( name, flags, size ) \ static const int name##_flags_ = flags; \ static const int name##_size_ = size; @@ -144,6 +149,9 @@ static const method_t name##_m[] name##_m, sizeof(name##_m)/sizeof(method_t) ); \ } while(0)
+extern void +bind_node_methods(phandle_t ph, int flags, int size, const method_t *methods, int nmet); + extern void bind_node( int flags, int size, const char * const *paths, int npaths, const method_t *methods, int nmethods );
diff --git a/libopenbios/bindings.c b/libopenbios/bindings.c index 926944d..9b4308b 100644 --- a/libopenbios/bindings.c +++ b/libopenbios/bindings.c @@ -484,6 +484,16 @@ add_methods( int flags, int size, const method_t *methods, int nmet ) make_openable(0); }
+void +bind_node_methods(phandle_t ph, int flags, int size, const method_t *methods, int nmet) +{ + phandle_t save_ph = get_cur_dev(); + + activate_dev(ph); + add_methods(flags, size, methods, nmet); + activate_dev( save_ph ); +} + void bind_node( int flags, int size, const char * const *paths, int npaths, const method_t *methods, int nmet )