[PATCH 10] IO_MANAGER: early dynamic driver registration

Daniel Hellstrom daniel at gaisler.com
Thu Feb 2 14:46:31 UTC 2012


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.

Signed-off-by: Daniel Hellstrom <daniel at gaisler.com>
---
 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 6a752cd..c889899 100644
--- a/cpukit/sapi/src/io.c
+++ b/cpukit/sapi/src/io.c
@@ -24,6 +24,8 @@
 
 #include <string.h>
 
+int _IO_Manager_drivers_inititalized = 0;
+
 /*
  *  _IO_Manager_initialization
  *
@@ -96,6 +98,8 @@ 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 30d10eb..6e505a6 100644
--- a/cpukit/sapi/src/ioregisterdriver.c
+++ b/cpukit/sapi/src/ioregisterdriver.c
@@ -28,6 +28,8 @@
 #include <rtems/rtems/intr.h>
 #include <rtems/score/thread.h>
 
+extern int _IO_Manager_drivers_inititalized;
+
 static inline bool rtems_io_is_empty_table(
   const rtems_driver_address_table *table
 )
@@ -111,5 +113,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