From 02e73b88c8f47827615ff501e0c4f4d2bf89d98d Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 16 Jul 2021 14:35:59 +0200 Subject: bsp/leon3: Untangle interrupt controller support Separate the probing of the interrupt controller from the initialization. --- bsps/sparc/leon3/include/bsp/leon3.h | 82 ++++++++++++++++++++++++++++++++++++ bsps/sparc/leon3/include/leon.h | 10 +---- bsps/sparc/leon3/start/amba.c | 9 ---- bsps/sparc/leon3/start/eirq.c | 15 +++++-- 4 files changed, 95 insertions(+), 21 deletions(-) create mode 100644 bsps/sparc/leon3/include/bsp/leon3.h diff --git a/bsps/sparc/leon3/include/bsp/leon3.h b/bsps/sparc/leon3/include/bsp/leon3.h new file mode 100644 index 0000000000..ff1ef261e6 --- /dev/null +++ b/bsps/sparc/leon3/include/bsp/leon3.h @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup sparc_leon3 + * + * @brief This header file provides interfaces used by the BSP implementation. + */ + +/* + * Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _BSP_LEON3_H +#define _BSP_LEON3_H + +#include +#include + +struct ambapp_dev; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup sparc_leon3 + * + * @{ + */ + +/** + * @brief This lock serializes the interrupt controller access. + */ +extern rtems_interrupt_lock LEON3_IrqCtrl_Lock; + +/** + * @brief This pointer provides the IRQ(A)MP register block address. + */ +extern volatile struct irqmp_regs *LEON3_IrqCtrl_Regs; + +/** + * @brief This pointer provides the IRQ(A)MP device information block. + */ +extern struct ambapp_dev *LEON3_IrqCtrl_Adev; + +/** + * @brief Initializes the interrupt controller for the boot processor. + * + * @param[in, out] regs is the IRQ(A)MP register block address. + */ +void leon3_ext_irq_init( volatile struct irqmp_regs *regs ); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* _BSP_LEON3_H */ diff --git a/bsps/sparc/leon3/include/leon.h b/bsps/sparc/leon3/include/leon.h index 5fadb08052..8cee0972d4 100644 --- a/bsps/sparc/leon3/include/leon.h +++ b/bsps/sparc/leon3/include/leon.h @@ -25,6 +25,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -127,10 +128,6 @@ extern "C" { #define LEON3_REG_CACHE_CTRL_FI 0x00200000 /* Flush instruction cache */ #define LEON3_REG_CACHE_CTRL_DS 0x00800000 /* Data cache snooping */ -/* LEON3 Interrupt Controller */ -extern volatile struct irqmp_regs *LEON3_IrqCtrl_Regs; -extern struct ambapp_dev *LEON3_IrqCtrl_Adev; - /* LEON3 GP Timer */ extern volatile struct gptimer_regs *LEON3_Timer_Regs; extern struct ambapp_dev *LEON3_Timer_Adev; @@ -174,8 +171,6 @@ static __inline__ int bsp_irq_fixup(int irq) * store the result back are vulnerable. */ -extern rtems_interrupt_lock LEON3_IrqCtrl_Lock; - #define LEON3_IRQCTRL_ACQUIRE( _lock_context ) \ rtems_interrupt_lock_acquire( &LEON3_IrqCtrl_Lock, _lock_context ) @@ -391,9 +386,6 @@ extern int leon3_timer_core_index; */ extern unsigned int leon3_timer_prescaler; -/* GRLIB extended IRQ controller register */ -void leon3_ext_irq_init(void); - RTEMS_NO_RETURN void leon3_power_down_loop(void); static inline uint32_t leon3_get_cpu_count( diff --git a/bsps/sparc/leon3/start/amba.c b/bsps/sparc/leon3/start/amba.c index 4801916825..e13d07e85d 100644 --- a/bsps/sparc/leon3/start/amba.c +++ b/bsps/sparc/leon3/start/amba.c @@ -96,9 +96,6 @@ RTEMS_SYSINIT_ITEM( ); #endif -rtems_interrupt_lock LEON3_IrqCtrl_Lock = - RTEMS_INTERRUPT_LOCK_INITIALIZER("LEON3 IrqCtrl"); - /* Pointers to Interrupt Controller configuration registers */ volatile struct irqmp_regs *LEON3_IrqCtrl_Regs; struct ambapp_dev *LEON3_IrqCtrl_Adev; @@ -147,12 +144,6 @@ static void amba_initialize(void) icsel = (icsel >> ((7 - (LEON3_Cpu_Index & 0x7)) * 4)) & 0xf; LEON3_IrqCtrl_Regs += icsel; } - LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index] = 0; - LEON3_IrqCtrl_Regs->force[LEON3_Cpu_Index] = 0; - LEON3_IrqCtrl_Regs->iclear = 0xffffffff; - - /* Init Extended IRQ controller if available */ - leon3_ext_irq_init(); /* find GP Timer */ adev = (void *)ambapp_for_each(plb, (OPTIONS_ALL|OPTIONS_APB_SLVS), diff --git a/bsps/sparc/leon3/start/eirq.c b/bsps/sparc/leon3/start/eirq.c index 2b69b68a13..fdfa9a80dd 100644 --- a/bsps/sparc/leon3/start/eirq.c +++ b/bsps/sparc/leon3/start/eirq.c @@ -19,12 +19,19 @@ /* GRLIB extended IRQ controller IRQ number */ int LEON3_IrqCtrl_EIrq = -1; +rtems_interrupt_lock LEON3_IrqCtrl_Lock = + RTEMS_INTERRUPT_LOCK_INITIALIZER("LEON3 IrqCtrl"); + /* Initialize Extended Interrupt controller */ -void leon3_ext_irq_init(void) +void leon3_ext_irq_init(volatile struct irqmp_regs *regs) { - if ( (LEON3_IrqCtrl_Regs->mpstat >> 16) & 0xf ) { + regs->mask[LEON3_Cpu_Index] = 0; + regs->force[LEON3_Cpu_Index] = 0; + regs->iclear = 0xffffffff; + + if ( (regs->mpstat >> 16) & 0xf ) { /* Extended IRQ controller available */ - LEON3_IrqCtrl_EIrq = (LEON3_IrqCtrl_Regs->mpstat >> 16) & 0xf; + LEON3_IrqCtrl_EIrq = (regs->mpstat >> 16) & 0xf; } } @@ -57,6 +64,8 @@ void bsp_interrupt_facility_initialize(void) leon3_interrupt_affinities[i] = affinity; } #endif + + leon3_ext_irq_init(LEON3_IrqCtrl_Regs); } rtems_status_code bsp_interrupt_get_attributes( -- cgit v1.2.3