[PATCH 2/3] bsps/irq: Add bsp_interrupt_get_dispatch_table_slot()

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Dec 1 12:10:57 UTC 2022


Update #4769.
---
 bsps/include/bsp/irq-generic.h        | 11 +++++++++++
 bsps/shared/irq/irq-entry-remove.c    |  2 +-
 bsps/shared/irq/irq-generic.c         | 19 +++++++++++++------
 bsps/shared/irq/irq-handler-iterate.c |  2 +-
 4 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/bsps/include/bsp/irq-generic.h b/bsps/include/bsp/irq-generic.h
index 4a3dd75e7d..1ff84ee7cd 100644
--- a/bsps/include/bsp/irq-generic.h
+++ b/bsps/include/bsp/irq-generic.h
@@ -663,6 +663,17 @@ static inline bool bsp_interrupt_is_initialized( void )
   return bsp_interrupt_is_handler_unique( BSP_INTERRUPT_DISPATCH_TABLE_SIZE );
 }
 
+/**
+ * @brief Gets a reference to the interrupt handler table slot associated with
+ *   the index.
+ *
+ * @return Returns a reference to the interrupt handler table slot associated
+ *   with the index.
+ */
+rtems_interrupt_entry **bsp_interrupt_get_dispatch_table_slot(
+  rtems_vector_number index
+);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/bsps/shared/irq/irq-entry-remove.c b/bsps/shared/irq/irq-entry-remove.c
index e970b80455..6b43134a0c 100644
--- a/bsps/shared/irq/irq-entry-remove.c
+++ b/bsps/shared/irq/irq-entry-remove.c
@@ -47,7 +47,7 @@ void bsp_interrupt_entry_remove(
   rtems_interrupt_entry *entry_next;
 
   index = bsp_interrupt_dispatch_index( vector );
-  first = bsp_interrupt_dispatch_table[ index ];
+  first = *bsp_interrupt_get_dispatch_table_slot( index );
   entry_next = entry->next;
 
   if ( entry == first && entry_next == NULL ) {
diff --git a/bsps/shared/irq/irq-generic.c b/bsps/shared/irq/irq-generic.c
index ffd820730e..e899731a54 100644
--- a/bsps/shared/irq/irq-generic.c
+++ b/bsps/shared/irq/irq-generic.c
@@ -49,6 +49,13 @@
 rtems_interrupt_entry *
 bsp_interrupt_dispatch_table[ BSP_INTERRUPT_DISPATCH_TABLE_SIZE ];
 
+RTEMS_WEAK rtems_interrupt_entry **bsp_interrupt_get_dispatch_table_slot(
+  rtems_vector_number index
+)
+{
+  return &bsp_interrupt_dispatch_table[ index ];
+}
+
 /* The last entry indicates if everything is initialized */
 uint8_t bsp_interrupt_handler_unique_table
   [ ( BSP_INTERRUPT_DISPATCH_TABLE_SIZE + 7 + 1 ) / 8 ];
@@ -91,9 +98,9 @@ void bsp_interrupt_spurious( rtems_vector_number vector )
    * In order to get the last written pointer value to the first entry, we have
    * to carry out an atomic read-modify-write operation.
    */
-  ptr = (Atomic_Uintptr *) &bsp_interrupt_dispatch_table[
+  ptr = (Atomic_Uintptr *) bsp_interrupt_get_dispatch_table_slot(
     bsp_interrupt_dispatch_index( vector )
-  ];
+  );
   first = (rtems_interrupt_entry *)
     _Atomic_Fetch_add_uintptr( ptr, 0, ATOMIC_ORDER_ACQUIRE );
 
@@ -143,8 +150,8 @@ rtems_interrupt_entry *bsp_interrupt_entry_find(
 
   bsp_interrupt_assert( bsp_interrupt_is_valid_vector( vector ) );
   index = bsp_interrupt_dispatch_index( vector );
-  *previous_next = &bsp_interrupt_dispatch_table[ index ];
-  entry = bsp_interrupt_dispatch_table[ index ];
+  *previous_next = bsp_interrupt_get_dispatch_table_slot( index );
+  entry = **previous_next;
 
   while ( entry != NULL ) {
     if ( entry->handler == routine && entry->arg == arg ) {
@@ -187,7 +194,7 @@ static rtems_status_code bsp_interrupt_entry_install_first(
   bsp_interrupt_dispatch_index_table[ vector ] = index;
 #endif
   bsp_interrupt_entry_store_release(
-    &bsp_interrupt_dispatch_table[ index ],
+    bsp_interrupt_get_dispatch_table_slot( index ),
     entry
   );
 
@@ -220,7 +227,7 @@ static rtems_status_code bsp_interrupt_entry_install(
   }
 
   index = bsp_interrupt_dispatch_index( vector );
-  first = bsp_interrupt_dispatch_table[ index ];
+  first = *bsp_interrupt_get_dispatch_table_slot( index );
 
   if ( first == NULL ) {
     return bsp_interrupt_entry_install_first( vector, options, entry );
diff --git a/bsps/shared/irq/irq-handler-iterate.c b/bsps/shared/irq/irq-handler-iterate.c
index 0aa890e6fd..7437e8a43e 100644
--- a/bsps/shared/irq/irq-handler-iterate.c
+++ b/bsps/shared/irq/irq-handler-iterate.c
@@ -57,9 +57,9 @@ rtems_status_code rtems_interrupt_handler_iterate(
   }
 
   index = bsp_interrupt_dispatch_index( vector );
+  entry = *bsp_interrupt_get_dispatch_table_slot( index );
   options = bsp_interrupt_is_handler_unique( index ) ?
     RTEMS_INTERRUPT_UNIQUE : RTEMS_INTERRUPT_SHARED;
-  entry = bsp_interrupt_dispatch_table[ index ];
 
   while ( entry != NULL ) {
     ( *routine )( arg, entry->info, options, entry->handler, entry->arg );
-- 
2.35.3



More information about the devel mailing list