[PATCH] score: Use ISR lock for IO driver registration
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon Mar 14 09:25:38 UTC 2016
Create implementation header file.
Update #2555.
---
cpukit/libmisc/monitor/mon-driver.c | 1 +
cpukit/sapi/Makefile.am | 1 +
cpukit/sapi/include/confdefs.h | 1 +
cpukit/sapi/include/rtems/io.h | 13 -------
cpukit/sapi/include/rtems/ioimpl.h | 65 +++++++++++++++++++++++++++++++++++
cpukit/sapi/preinstall.am | 4 +++
cpukit/sapi/src/exinit.c | 2 +-
cpukit/sapi/src/io.c | 2 +-
cpukit/sapi/src/ioclose.c | 3 +-
cpukit/sapi/src/iocontrol.c | 3 +-
cpukit/sapi/src/ioinitialize.c | 3 +-
cpukit/sapi/src/ioopen.c | 3 +-
cpukit/sapi/src/ioread.c | 3 +-
cpukit/sapi/src/ioregisterdriver.c | 15 ++++----
cpukit/sapi/src/iounregisterdriver.c | 10 +++---
cpukit/sapi/src/iowrite.c | 3 +-
testsuites/sptests/sp40/init.c | 2 ++
testsuites/sptests/spsysinit01/init.c | 1 +
18 files changed, 96 insertions(+), 39 deletions(-)
create mode 100644 cpukit/sapi/include/rtems/ioimpl.h
diff --git a/cpukit/libmisc/monitor/mon-driver.c b/cpukit/libmisc/monitor/mon-driver.c
index ebbf0ec..504d509 100644
--- a/cpukit/libmisc/monitor/mon-driver.c
+++ b/cpukit/libmisc/monitor/mon-driver.c
@@ -22,6 +22,7 @@
#endif
#include <rtems.h>
+#include <rtems/ioimpl.h>
#include <rtems/monitor.h>
#include <stdio.h>
diff --git a/cpukit/sapi/Makefile.am b/cpukit/sapi/Makefile.am
index 7377177..edfdfc1 100644
--- a/cpukit/sapi/Makefile.am
+++ b/cpukit/sapi/Makefile.am
@@ -13,6 +13,7 @@ include_rtems_HEADERS += include/rtems/extensionimpl.h
include_rtems_HEADERS += include/rtems/fatal.h
include_rtems_HEADERS += include/rtems/init.h
include_rtems_HEADERS += include/rtems/io.h
+include_rtems_HEADERS += include/rtems/ioimpl.h
include_rtems_HEADERS += include/rtems/mptables.h
include_rtems_HEADERS += include/rtems/cbs.h
include_rtems_HEADERS += include/rtems/profiling.h
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index ee2558c..89beb23 100644
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -26,6 +26,7 @@
* Include the executive's configuration
*/
#include <rtems.h>
+#include <rtems/ioimpl.h>
#include <rtems/sysinit.h>
#include <rtems/score/apimutex.h>
#include <rtems/score/percpu.h>
diff --git a/cpukit/sapi/include/rtems/io.h b/cpukit/sapi/include/rtems/io.h
index f5876a0..760d412 100644
--- a/cpukit/sapi/include/rtems/io.h
+++ b/cpukit/sapi/include/rtems/io.h
@@ -246,19 +246,6 @@ rtems_status_code rtems_io_lookup_name(
rtems_driver_name_t *device_info
) RTEMS_DEPRECATED;
-extern const size_t _IO_Number_of_drivers;
-
-extern rtems_driver_address_table _IO_Driver_address_table[];
-
-extern bool _IO_All_drivers_initialized;
-
-/**
- * @brief Initialization of all device drivers.
- *
- * Initializes all device drivers.
- */
-void _IO_Initialize_all_drivers( void );
-
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/sapi/include/rtems/ioimpl.h b/cpukit/sapi/include/rtems/ioimpl.h
new file mode 100644
index 0000000..5c4a82e
--- /dev/null
+++ b/cpukit/sapi/include/rtems/ioimpl.h
@@ -0,0 +1,65 @@
+/**
+ * @file
+ *
+ * @brief Classic Input/Output Manager Implementation API
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifndef _RTEMS_IOIMPL_H
+#define _RTEMS_IOIMPL_H
+
+#include <rtems/io.h>
+#include <rtems/score/isrlock.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+extern const size_t _IO_Number_of_drivers;
+
+extern rtems_driver_address_table _IO_Driver_address_table[];
+
+extern bool _IO_All_drivers_initialized;
+
+/**
+ * @brief Initialization of all device drivers.
+ *
+ * Initializes all device drivers.
+ */
+void _IO_Initialize_all_drivers( void );
+
+ISR_LOCK_DECLARE( extern, _IO_Driver_registration_lock )
+
+RTEMS_INLINE_ROUTINE void _IO_Driver_registration_acquire(
+ ISR_lock_Context *lock_context
+)
+{
+ _ISR_lock_ISR_disable_and_acquire(
+ &_IO_Driver_registration_lock,
+ lock_context
+ );
+}
+
+RTEMS_INLINE_ROUTINE void _IO_Driver_registration_release(
+ ISR_lock_Context *lock_context
+)
+{
+ _ISR_lock_Release_and_ISR_enable(
+ &_IO_Driver_registration_lock,
+ lock_context
+ );
+}
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _RTEMS_IOIMPL_H */
diff --git a/cpukit/sapi/preinstall.am b/cpukit/sapi/preinstall.am
index 969edfe..b1bdf48 100644
--- a/cpukit/sapi/preinstall.am
+++ b/cpukit/sapi/preinstall.am
@@ -58,6 +58,10 @@ $(PROJECT_INCLUDE)/rtems/io.h: include/rtems/io.h $(PROJECT_INCLUDE)/rtems/$(dir
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/io.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/io.h
+$(PROJECT_INCLUDE)/rtems/ioimpl.h: include/rtems/ioimpl.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/ioimpl.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/ioimpl.h
+
$(PROJECT_INCLUDE)/rtems/mptables.h: include/rtems/mptables.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/mptables.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/mptables.h
diff --git a/cpukit/sapi/src/exinit.c b/cpukit/sapi/src/exinit.c
index 350c774..69db694 100644
--- a/cpukit/sapi/src/exinit.c
+++ b/cpukit/sapi/src/exinit.c
@@ -23,7 +23,7 @@
#include <rtems/config.h>
#include <rtems/extensionimpl.h>
#include <rtems/init.h>
-#include <rtems/io.h>
+#include <rtems/ioimpl.h>
#include <rtems/sysinit.h>
#include <rtems/score/sysstate.h>
diff --git a/cpukit/sapi/src/io.c b/cpukit/sapi/src/io.c
index c2698bc..6cda083 100644
--- a/cpukit/sapi/src/io.c
+++ b/cpukit/sapi/src/io.c
@@ -19,7 +19,7 @@
#include "config.h"
#endif
-#include <rtems/io.h>
+#include <rtems/ioimpl.h>
bool _IO_All_drivers_initialized;
diff --git a/cpukit/sapi/src/ioclose.c b/cpukit/sapi/src/ioclose.c
index 035c027..038c983 100644
--- a/cpukit/sapi/src/ioclose.c
+++ b/cpukit/sapi/src/ioclose.c
@@ -21,8 +21,7 @@
#include "config.h"
#endif
-#include <rtems/system.h>
-#include <rtems/io.h>
+#include <rtems/ioimpl.h>
rtems_status_code rtems_io_close(
rtems_device_major_number major,
diff --git a/cpukit/sapi/src/iocontrol.c b/cpukit/sapi/src/iocontrol.c
index 2aa7d62..8d6e0a1 100644
--- a/cpukit/sapi/src/iocontrol.c
+++ b/cpukit/sapi/src/iocontrol.c
@@ -19,8 +19,7 @@
#include "config.h"
#endif
-#include <rtems/system.h>
-#include <rtems/io.h>
+#include <rtems/ioimpl.h>
rtems_status_code rtems_io_control(
rtems_device_major_number major,
diff --git a/cpukit/sapi/src/ioinitialize.c b/cpukit/sapi/src/ioinitialize.c
index e1c2e05..7664644 100644
--- a/cpukit/sapi/src/ioinitialize.c
+++ b/cpukit/sapi/src/ioinitialize.c
@@ -19,8 +19,7 @@
#include "config.h"
#endif
-#include <rtems/system.h>
-#include <rtems/io.h>
+#include <rtems/ioimpl.h>
rtems_status_code rtems_io_initialize(
rtems_device_major_number major,
diff --git a/cpukit/sapi/src/ioopen.c b/cpukit/sapi/src/ioopen.c
index 7c5b0dc..5fcefe7 100644
--- a/cpukit/sapi/src/ioopen.c
+++ b/cpukit/sapi/src/ioopen.c
@@ -21,8 +21,7 @@
#include "config.h"
#endif
-#include <rtems/system.h>
-#include <rtems/io.h>
+#include <rtems/ioimpl.h>
rtems_status_code rtems_io_open(
rtems_device_major_number major,
diff --git a/cpukit/sapi/src/ioread.c b/cpukit/sapi/src/ioread.c
index 43bf053..2701cc9 100644
--- a/cpukit/sapi/src/ioread.c
+++ b/cpukit/sapi/src/ioread.c
@@ -19,8 +19,7 @@
#include "config.h"
#endif
-#include <rtems/system.h>
-#include <rtems/io.h>
+#include <rtems/ioimpl.h>
rtems_status_code rtems_io_read(
rtems_device_major_number major,
diff --git a/cpukit/sapi/src/ioregisterdriver.c b/cpukit/sapi/src/ioregisterdriver.c
index 33ee6b0..1d32320 100644
--- a/cpukit/sapi/src/ioregisterdriver.c
+++ b/cpukit/sapi/src/ioregisterdriver.c
@@ -21,9 +21,9 @@
#include "config.h"
#endif
-#include <rtems/io.h>
-#include <rtems/rtems/intr.h>
-#include <rtems/score/threaddispatch.h>
+#include <rtems/ioimpl.h>
+
+ISR_LOCK_DEFINE( , _IO_Driver_registration_lock, "IO Driver Registration" )
static inline bool rtems_io_is_empty_table(
const rtems_driver_address_table *table
@@ -64,6 +64,7 @@ rtems_status_code rtems_io_register_driver(
)
{
rtems_device_major_number major_limit = _IO_Number_of_drivers;
+ ISR_lock_Context lock_context;
if ( rtems_interrupt_is_in_progress() )
return RTEMS_CALLED_FROM_ISR;
@@ -83,13 +84,13 @@ rtems_status_code rtems_io_register_driver(
if ( major >= major_limit )
return RTEMS_INVALID_NUMBER;
- _Thread_Disable_dispatch();
+ _IO_Driver_registration_acquire( &lock_context );
if ( major == 0 ) {
rtems_status_code sc = rtems_io_obtain_major_number( registered_major );
if ( sc != RTEMS_SUCCESSFUL ) {
- _Thread_Enable_dispatch();
+ _IO_Driver_registration_release( &lock_context );
return sc;
}
major = *registered_major;
@@ -97,7 +98,7 @@ rtems_status_code rtems_io_register_driver(
rtems_driver_address_table *const table = _IO_Driver_address_table + major;
if ( !rtems_io_is_empty_table( table ) ) {
- _Thread_Enable_dispatch();
+ _IO_Driver_registration_release( &lock_context );
return RTEMS_RESOURCE_IN_USE;
}
@@ -106,7 +107,7 @@ rtems_status_code rtems_io_register_driver(
_IO_Driver_address_table [major] = *driver_table;
- _Thread_Enable_dispatch();
+ _IO_Driver_registration_release( &lock_context );
if ( _IO_All_drivers_initialized ) {
/* Other drivers have already been initialized, we initialize
diff --git a/cpukit/sapi/src/iounregisterdriver.c b/cpukit/sapi/src/iounregisterdriver.c
index 3748d34..fff4cd0 100644
--- a/cpukit/sapi/src/iounregisterdriver.c
+++ b/cpukit/sapi/src/iounregisterdriver.c
@@ -19,9 +19,7 @@
#include "config.h"
#endif
-#include <rtems/io.h>
-#include <rtems/rtems/intr.h>
-#include <rtems/score/threaddispatch.h>
+#include <rtems/ioimpl.h>
#include <string.h>
@@ -33,13 +31,15 @@ rtems_status_code rtems_io_unregister_driver(
return RTEMS_CALLED_FROM_ISR;
if ( major < _IO_Number_of_drivers ) {
- _Thread_Disable_dispatch();
+ ISR_lock_Context lock_context;
+
+ _IO_Driver_registration_acquire( &lock_context );
memset(
&_IO_Driver_address_table[major],
0,
sizeof( rtems_driver_address_table )
);
- _Thread_Enable_dispatch();
+ _IO_Driver_registration_release( &lock_context );
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/sapi/src/iowrite.c b/cpukit/sapi/src/iowrite.c
index 3e1608d..ba41851 100644
--- a/cpukit/sapi/src/iowrite.c
+++ b/cpukit/sapi/src/iowrite.c
@@ -19,8 +19,7 @@
#include "config.h"
#endif
-#include <rtems/system.h>
-#include <rtems/io.h>
+#include <rtems/ioimpl.h>
rtems_status_code rtems_io_write(
rtems_device_major_number major,
diff --git a/testsuites/sptests/sp40/init.c b/testsuites/sptests/sp40/init.c
index d3b547b..44e8d45 100644
--- a/testsuites/sptests/sp40/init.c
+++ b/testsuites/sptests/sp40/init.c
@@ -17,6 +17,8 @@
#include <tmacros.h>
+#include <rtems/ioimpl.h>
+
const char rtems_test_name[] = "SP 40";
/* forward declarations to avoid warnings */
diff --git a/testsuites/sptests/spsysinit01/init.c b/testsuites/sptests/spsysinit01/init.c
index 60e3747..f89ade6 100644
--- a/testsuites/sptests/spsysinit01/init.c
+++ b/testsuites/sptests/spsysinit01/init.c
@@ -26,6 +26,7 @@
#include <unistd.h>
#include <rtems.h>
+#include <rtems/ioimpl.h>
#include <rtems/libio_.h>
#include <rtems/sysinit.h>
#include <rtems/test.h>
--
1.8.4.5
More information about the devel
mailing list