[PATCH 001/111] IO_MANAGER: early dynamic driver registration

Daniel Hellstrom daniel at gaisler.com
Thu Feb 26 16:38:03 UTC 2015


Adds the possibility to register drivers before the IO Manager has
completed the initialization. Sometimes the BSP may want to register
a driver dynamically early in the boot process.
---
 cpukit/sapi/src/io.c               |    4 ++++
 cpukit/sapi/src/ioregisterdriver.c |   14 +++++++++++++-
 2 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/cpukit/sapi/src/io.c b/cpukit/sapi/src/io.c
index c14f5e7..b27bed9 100644
--- a/cpukit/sapi/src/io.c
+++ b/cpukit/sapi/src/io.c
@@ -21,10 +21,14 @@
 
 #include <rtems/io.h>
 
+int _IO_Manager_drivers_inititalized = 0;
+
 void _IO_Initialize_all_drivers( void )
 {
    rtems_device_major_number major;
 
+   _IO_Manager_drivers_inititalized = 1;
+
    for ( major=0 ; major < _IO_Number_of_drivers ; major ++ )
      (void) rtems_io_initialize( major, 0, NULL );
 }
diff --git a/cpukit/sapi/src/ioregisterdriver.c b/cpukit/sapi/src/ioregisterdriver.c
index 65cc56f..ca1ecb9 100644
--- a/cpukit/sapi/src/ioregisterdriver.c
+++ b/cpukit/sapi/src/ioregisterdriver.c
@@ -25,6 +25,8 @@
 #include <rtems/rtems/intr.h>
 #include <rtems/score/threaddispatch.h>
 
+extern int _IO_Manager_drivers_inititalized;
+
 static inline bool rtems_io_is_empty_table(
   const rtems_driver_address_table *table
 )
@@ -108,5 +110,15 @@ rtems_status_code rtems_io_register_driver(
 
   _Thread_Enable_dispatch();
 
-  return rtems_io_initialize( major, 0, NULL );
+  if ( _IO_Manager_drivers_inititalized ) {
+    /* Other drivers have already been initialized, we initialize
+     * the driver directly.
+     */
+    return rtems_io_initialize( major, 0, NULL );
+  } else {
+    /* The driver will be initialized together with all other drivers
+     * in a later stage by _IO_Initialize_all_drivers().
+     */
+    return RTEMS_SUCCESSFUL;
+  }
 }
-- 
1.7.0.4




More information about the devel mailing list