Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:08

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSBSPsSPARCLEON3
0007  *
0008  * @brief This header file provides interfaces used by the interrupt support
0009  *   implementation.
0010  */
0011 
0012 /*
0013  * Copyright (C) 2021 embedded brains GmbH & Co. KG
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #ifndef LIBBSP_SPARC_LEON3_BSP_IRQIMPL_H
0038 #define LIBBSP_SPARC_LEON3_BSP_IRQIMPL_H
0039 
0040 #include <rtems.h>
0041 #include <grlib/irqamp-regs.h>
0042 #include <grlib/io.h>
0043 
0044 #include <bspopts.h>
0045 
0046 struct ambapp_dev;
0047 
0048 #ifdef __cplusplus
0049 extern "C" {
0050 #endif
0051 
0052 /**
0053  * @addtogroup RTEMSBSPsSPARCLEON3
0054  *
0055  * @{
0056  */
0057 
0058 /**
0059  * @brief This object provides the index of the boot processor.
0060  *
0061  * This object should be read-only after initialization.
0062  */
0063 extern uint32_t LEON3_Cpu_Index;
0064 
0065 /**
0066  * @brief This lock serializes the interrupt controller access.
0067  */
0068 extern rtems_interrupt_lock LEON3_IrqCtrl_Lock;
0069 
0070 /**
0071  * @brief Acquires the interrupt controller lock.
0072  *
0073  * @param[out] _lock_context is the lock context.
0074  */
0075 #define LEON3_IRQCTRL_ACQUIRE( _lock_context ) \
0076   rtems_interrupt_lock_acquire( &LEON3_IrqCtrl_Lock, _lock_context )
0077 
0078 /**
0079  * @brief Releases the interrupt controller lock.
0080  *
0081  * @param[in, out] _lock_context is the lock context.
0082  */
0083 #define LEON3_IRQCTRL_RELEASE( _lock_context ) \
0084   rtems_interrupt_lock_release( &LEON3_IrqCtrl_Lock, _lock_context )
0085 
0086 /**
0087  * @brief This pointer provides the IRQ(A)MP register block address.
0088  */
0089 #if defined(LEON3_IRQAMP_BASE)
0090 #define LEON3_IrqCtrl_Regs ((irqamp *) LEON3_IRQAMP_BASE)
0091 #else
0092 extern irqamp *LEON3_IrqCtrl_Regs;
0093 
0094 /**
0095  * @brief This pointer provides the IRQ(A)MP device information block.
0096  */
0097 extern struct ambapp_dev *LEON3_IrqCtrl_Adev;
0098 #endif
0099 
0100 /**
0101  * @brief This object provides the interrupt number used to multiplex extended
0102  *   interrupts or is zero if no extended interrupts are available.
0103  *
0104  * This object should be read-only after initialization.
0105  */
0106 #if defined(LEON3_IRQAMP_EXTENDED_INTERRUPT)
0107 #define LEON3_IrqCtrl_EIrq LEON3_IRQAMP_EXTENDED_INTERRUPT
0108 #else
0109 extern uint32_t LEON3_IrqCtrl_EIrq;
0110 #endif
0111 
0112 /**
0113  * @brief Initializes the interrupt controller for the boot processor.
0114  *
0115  * @param[in, out] regs is the IRQ(A)MP register block address.
0116  */
0117 void leon3_ext_irq_init( irqamp *regs );
0118 
0119 /**
0120  * @brief Acknowledges and maps extended interrupts if this feature is
0121  * available and the interrupt for extended interrupts is present.
0122  *
0123  * @param irq is the standard interrupt number.
0124  */
0125 static inline uint32_t bsp_irq_fixup( uint32_t irq )
0126 {
0127   uint32_t eirq;
0128   uint32_t cpu_self;
0129 
0130   if ( irq != LEON3_IrqCtrl_EIrq ) {
0131     return irq;
0132   }
0133 
0134   cpu_self = _LEON3_Get_current_processor();
0135   eirq = grlib_load_32( &LEON3_IrqCtrl_Regs->pextack[ cpu_self ] );
0136   eirq = IRQAMP_PEXTACK_EID_4_0_GET( eirq );
0137 
0138   if ( eirq < 16 ) {
0139     return irq;
0140   }
0141 
0142   return eirq;
0143 }
0144 
0145 /** @} */
0146 
0147 #ifdef __cplusplus
0148 }
0149 #endif
0150 
0151 #endif /* LIBBSP_SPARC_LEON3_BSP_IRQIMPL_H */