<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 17, 2020 at 1:24 PM Jeff Kubascik <<a href="mailto:jeff.kubascik@dornerworks.com">jeff.kubascik@dornerworks.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
Have there been any updates on this patch? I do not see it in mainline.<br></blockquote><div><br></div><div>I was hoping someone would comment. :)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I am currently using it for work on the arm/xen BSP to add support for platforms<br>
with a GICv3 interrupt controller. With a few minor changes, I have confirm that<br>
it works with the Xen hypervisor on qemu. Before I can submit these patches,<br>
though, this patch would need to be accepted first.<br></blockquote><div><br></div><div>Thank you for using it and reporting back. I just pushed it and look forward to your</div><div>patch. </div><div><br></div><div>CC'ing Kinsey so he is on the lookout for your patch and verifies it still works</div><div>on HPSC Qemu.</div><div><br></div><div>--joel</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
On 8/16/2019 3:14 PM, Kinsey Moore wrote:<br>
> This adds support for the GICv3 interrupt controller along with the<br>
> redistributor to control SGIs and PPIs which wasn't present in GICv2<br>
> implementations. GICv3 implementations only optionally support<br>
> memory-mapped GICC interface interaction and require system register<br>
> access be implemented, so the GICC interface is accessed only<br>
> through system registers.<br>
> ---<br>
> bsps/arm/include/bsp/arm-gic-irq.h | 15 +-<br>
> bsps/arm/include/bsp/arm-gic-regs.h | 76 ++++++++-<br>
> bsps/arm/shared/irq/irq-gic.c | 16 ++<br>
> bsps/arm/shared/irq/irq-gicv3.c | 329 ++++++++++++++++++++++++++++++++++++<br>
> 4 files changed, 427 insertions(+), 9 deletions(-)<br>
> create mode 100644 bsps/arm/shared/irq/irq-gicv3.c<br>
> <br>
> diff --git a/bsps/arm/include/bsp/arm-gic-irq.h b/bsps/arm/include/bsp/arm-gic-irq.h<br>
> index b3e893de72..219c3c7189 100644<br>
> --- a/bsps/arm/include/bsp/arm-gic-irq.h<br>
> +++ b/bsps/arm/include/bsp/arm-gic-irq.h<br>
> @@ -85,6 +85,12 @@ typedef enum {<br>
> ARM_GIC_IRQ_SOFTWARE_IRQ_TO_SELF<br>
> } arm_gic_irq_software_irq_target_filter;<br>
> <br>
> +void arm_gic_trigger_sgi(<br>
> + rtems_vector_number vector,<br>
> + arm_gic_irq_software_irq_target_filter filter,<br>
> + uint8_t targets<br>
> +);<br>
> +<br>
> static inline rtems_status_code arm_gic_irq_generate_software_irq(<br>
> rtems_vector_number vector,<br>
> arm_gic_irq_software_irq_target_filter filter,<br>
> @@ -94,14 +100,7 @@ static inline rtems_status_code arm_gic_irq_generate_software_irq(<br>
> rtems_status_code sc = RTEMS_SUCCESSFUL;<br>
> <br>
> if (vector <= ARM_GIC_IRQ_SGI_15) {<br>
> - volatile gic_dist *dist = ARM_GIC_DIST;<br>
> -<br>
> - dist->icdsgir = GIC_DIST_ICDSGIR_TARGET_LIST_FILTER(filter)<br>
> - | GIC_DIST_ICDSGIR_CPU_TARGET_LIST(targets)<br>
> -#ifdef BSP_ARM_GIC_ENABLE_FIQ_FOR_GROUP_0<br>
> - | GIC_DIST_ICDSGIR_NSATT<br>
> -#endif<br>
> - | GIC_DIST_ICDSGIR_SGIINTID(vector);<br>
> + arm_gic_trigger_sgi(vector, filter, targets);<br>
> } else {<br>
> sc = RTEMS_INVALID_ID;<br>
> }<br>
> diff --git a/bsps/arm/include/bsp/arm-gic-regs.h b/bsps/arm/include/bsp/arm-gic-regs.h<br>
> index 2915313b71..8a65294b6f 100644<br>
> --- a/bsps/arm/include/bsp/arm-gic-regs.h<br>
> +++ b/bsps/arm/include/bsp/arm-gic-regs.h<br>
> @@ -86,7 +86,18 @@ typedef struct {<br>
> } gic_cpuif;<br>
> <br>
> typedef struct {<br>
> + /* GICD_CTLR */<br>
> uint32_t icddcr;<br>
> +/* GICv3 only */<br>
> +#define GIC_DIST_ICDDCR_RWP BSP_BIT32(31)<br>
> +#define GIC_DIST_ICDDCR_E1NWF BSP_BIT32(7)<br>
> +#define GIC_DIST_ICDDCR_DS BSP_BIT32(6)<br>
> +#define GIC_DIST_ICDDCR_ARE_NS BSP_BIT32(5)<br>
> +#define GIC_DIST_ICDDCR_ARE_S BSP_BIT32(4)<br>
> +#define GIC_DIST_ICDDCR_ENABLE_GRP1S BSP_BIT32(2)<br>
> +#define GIC_DIST_ICDDCR_ENABLE_GRP1NS BSP_BIT32(1)<br>
> +#define GIC_DIST_ICDDCR_ENABLE_GRP0 BSP_BIT32(0)<br>
> +/* GICv1/GICv2 */<br>
> #define GIC_DIST_ICDDCR_ENABLE_GRP_1 BSP_BIT32(1)<br>
> #define GIC_DIST_ICDDCR_ENABLE BSP_BIT32(0)<br>
> uint32_t icdictr;<br>
> @@ -126,7 +137,9 @@ typedef struct {<br>
> uint8_t icdiptr[256];<br>
> uint32_t reserved_900[192];<br>
> uint32_t icdicfr[64];<br>
> - uint32_t reserved_d00[128];<br>
> + /* GICD_IGRPMODR GICv3 only, reserved in GICv1/GICv2 */<br>
> + uint32_t icdigmr[32];<br>
> + uint32_t reserved_d80[96];<br>
> uint32_t icdsgir;<br>
> #define GIC_DIST_ICDSGIR_TARGET_LIST_FILTER(val) BSP_FLD32(val, 24, 25)<br>
> #define GIC_DIST_ICDSGIR_TARGET_LIST_FILTER_GET(reg) BSP_FLD32GET(reg, 24, 25)<br>
> @@ -140,4 +153,65 @@ typedef struct {<br>
> #define GIC_DIST_ICDSGIR_SGIINTID_SET(reg, val) BSP_FLD32SET(reg, val, 0, 3)<br>
> } gic_dist;<br>
> <br>
> +/* GICv3 only */<br>
> +typedef struct {<br>
> + /* GICR_CTLR */<br>
> + uint32_t icrrcr;<br>
> +#define GIC_REDIST_ICRRCR_UWP BSP_BIT32(31)<br>
> +#define GIC_REDIST_ICRRCR_DPG1S BSP_BIT32(26)<br>
> +#define GIC_REDIST_ICRRCR_DPG1NS BSP_BIT32(25)<br>
> +#define GIC_REDIST_ICRRCR_DPG0 BSP_BIT32(24)<br>
> +#define GIC_REDIST_ICRRCR_RWP BSP_BIT32(4)<br>
> +#define GIC_REDIST_ICRRCR_ENABLE_LPI BSP_BIT32(0)<br>
> + uint32_t icriidr;<br>
> + uint64_t icrtyper;<br>
> +#define GIC_REDIST_ICRTYPER_AFFINITY_VALUE(val) BSP_FLD64(val, 32, 63)<br>
> +#define GIC_REDIST_ICRTYPER_AFFINITY_VALUE_GET(reg) BSP_FLD64GET(reg, 32, 63)<br>
> +#define GIC_REDIST_ICRTYPER_AFFINITY_VALUE_SET(reg, val) BSP_FLD64SET(reg, val, 32, 63)<br>
> +#define GIC_REDIST_ICRTYPER_COMMON_LPI_AFFINITY(val) BSP_FLD64(val, 24, 25)<br>
> +#define GIC_REDIST_ICRTYPER_COMMON_LPI_AFFINITY_GET(reg) BSP_FLD64GET(reg, 24, 25)<br>
> +#define GIC_REDIST_ICRTYPER_COMMON_LPI_AFFINITY_SET(reg, val) BSP_FLD64SET(reg, val, 24, 25)<br>
> +#define GIC_REDIST_ICRTYPER_CPU_NUMBER(val) BSP_FLD64(val, 8, 23)<br>
> +#define GIC_REDIST_ICRTYPER_CPU_NUMBER_GET(reg) BSP_FLD64GET(reg, 8, 23)<br>
> +#define GIC_REDIST_ICRTYPER_CPU_NUMBER_SET(reg, val) BSP_FLD64SET(reg, val, 8, 23)<br>
> +#define GIC_REDIST_ICRTYPER_DPGS BSP_BIT64(5)<br>
> +#define GIC_REDIST_ICRTYPER_LAST BSP_BIT64(4)<br>
> +#define GIC_REDIST_ICRTYPER_DIRECT_LPI BSP_BIT64(3)<br>
> +#define GIC_REDIST_ICRTYPER_VLPIS BSP_BIT64(1)<br>
> +#define GIC_REDIST_ICRTYPER_PLPIS BSP_BIT64(0)<br>
> + uint32_t unused_10;<br>
> + uint32_t icrwaker;<br>
> +#define GIC_REDIST_ICRWAKER_CHILDREN_ASLEEP BSP_BIT32(2)<br>
> +#define GIC_REDIST_ICRWAKER_PROCESSOR_SLEEP BSP_BIT32(1)<br>
> +} gic_redist;<br>
> +<br>
> +/* GICv3 only */<br>
> +typedef struct {<br>
> + uint32_t reserved_0_80[32];<br>
> + /* GICR_IGROUPR0 */<br>
> + uint32_t icspigrpr[32];<br>
> + /* GICR_ISENABLER0 */<br>
> + uint32_t icspiser[32];<br>
> + /* GICR_ICENABLER0 */<br>
> + uint32_t icspicer[32];<br>
> + /* GICR_ISPENDR0 */<br>
> + uint32_t icspispendr[32];<br>
> + /* GICR_ICPENDR0 */<br>
> + uint32_t icspicpendr[32];<br>
> + /* GICR_ISACTIVER0 */<br>
> + uint32_t icspisar[32];<br>
> + /* GICR_ICACTIVER0 */<br>
> + uint32_t icspicar[32];<br>
> + /* GICR_IPRIORITYR */<br>
> + uint8_t icspiprior[32];<br>
> + uint32_t reserved_420_bfc[504];<br>
> + /* GICR_ICFGR0 */<br>
> + uint32_t icspicfgr0;<br>
> + /* GICR_ICFGR1 */<br>
> + uint32_t icspicfgr1;<br>
> + uint32_t reserved_c08_cfc[62];<br>
> + /* GICR_IGRPMODR0 */<br>
> + uint32_t icspigrpmodr[64];<br>
> +} gic_sgi_ppi;<br>
> +<br>
> #endif /* LIBBSP_ARM_SHARED_ARM_GIC_REGS_H */<br>
> diff --git a/bsps/arm/shared/irq/irq-gic.c b/bsps/arm/shared/irq/irq-gic.c<br>
> index 65a7e6f653..7cf469d0f7 100644<br>
> --- a/bsps/arm/shared/irq/irq-gic.c<br>
> +++ b/bsps/arm/shared/irq/irq-gic.c<br>
> @@ -262,3 +262,19 @@ void bsp_interrupt_get_affinity(<br>
> <br>
> _Processor_mask_From_uint32_t(affinity, targets, 0);<br>
> }<br>
> +<br>
> +void arm_gic_trigger_sgi(<br>
> + rtems_vector_number vector,<br>
> + arm_gic_irq_software_irq_target_filter filter,<br>
> + uint8_t targets<br>
> +)<br>
> +{<br>
> + volatile gic_dist *dist = ARM_GIC_DIST;<br>
> +<br>
> + dist->icdsgir = GIC_DIST_ICDSGIR_TARGET_LIST_FILTER(filter)<br>
> + | GIC_DIST_ICDSGIR_CPU_TARGET_LIST(targets)<br>
> +#ifdef BSP_ARM_GIC_ENABLE_FIQ_FOR_GROUP_0<br>
> + | GIC_DIST_ICDSGIR_NSATT<br>
> +#endif<br>
> + | GIC_DIST_ICDSGIR_SGIINTID(vector);<br>
> +}<br>
> diff --git a/bsps/arm/shared/irq/irq-gicv3.c b/bsps/arm/shared/irq/irq-gicv3.c<br>
> new file mode 100644<br>
> index 0000000000..138b565b9b<br>
> --- /dev/null<br>
> +++ b/bsps/arm/shared/irq/irq-gicv3.c<br>
> @@ -0,0 +1,329 @@<br>
> +/*<br>
> + * SPDX-License-Identifier: BSD-2-Clause<br>
> + *<br>
> + * Copyright (C) 2019 On-Line Applications Research Corporation (OAR)<br>
> + *<br>
> + * Redistribution and use in source and binary forms, with or without<br>
> + * modification, are permitted provided that the following conditions<br>
> + * are met:<br>
> + * 1. Redistributions of source code must retain the above copyright<br>
> + * notice, this list of conditions and the following disclaimer.<br>
> + * 2. Redistributions in binary form must reproduce the above copyright<br>
> + * notice, this list of conditions and the following disclaimer in the<br>
> + * documentation and/or other materials provided with the distribution.<br>
> + *<br>
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
> + * POSSIBILITY OF SUCH DAMAGE.<br>
> + */<br>
> +<br>
> +#include <bsp/arm-gic.h><br>
> +<br>
> +#include <rtems/score/armv4.h><br>
> +<br>
> +#include <libcpu/arm-cp15.h><br>
> +<br>
> +#include <bsp/irq.h><br>
> +#include <bsp/irq-generic.h><br>
> +#include <bsp/start.h><br>
> +<br>
> +#define PRIORITY_DEFAULT 127<br>
> +<br>
> +/* cpuif->iccicr */<br>
> +#define ICC_CTLR "p15, 0, %0, c12, c12, 4"<br>
> +<br>
> +/* cpuif->iccpmr */<br>
> +#define ICC_PMR "p15, 0, %0, c4, c6, 0"<br>
> +<br>
> +/* cpuif->iccbpr */<br>
> +#define ICC_BPR0 "p15, 0, %0, c12, c8, 3"<br>
> +#define ICC_BPR1 "p15, 0, %0, c12, c12, 3"<br>
> +<br>
> +/* cpuif->icciar */<br>
> +#define ICC_IAR0 "p15, 0, %0, c12, c8, 0"<br>
> +#define ICC_IAR1 "p15, 0, %0, c12, c12, 0"<br>
> +<br>
> +/* cpuif->icceoir */<br>
> +#define ICC_EOIR0 "p15, 0, %0, c12, c8, 1"<br>
> +#define ICC_EOIR1 "p15, 0, %0, c12, c12, 1"<br>
> +<br>
> +#define ICC_SRE "p15, 0, %0, c12, c12, 5"<br>
> +<br>
> +#define ICC_IGRPEN0 "p15, 0, %0, c12, c12, 6"<br>
> +#define ICC_IGRPEN1 "p15, 0, %0, c12, c12, 7"<br>
> +<br>
> +#define ICC_SGI1 "p15, 0, %Q0, %R0, c12"<br>
> +<br>
> +#define ICC_SGIR_AFFINITY3(val) BSP_FLD64(val, 48, 55)<br>
> +#define ICC_SGIR_AFFINITY3_GET(reg) BSP_FLD64GET(reg, 48, 55)<br>
> +#define ICC_SGIR_AFFINITY3_SET(reg, val) BSP_FLD64SET(reg, val, 48, 55)<br>
> +#define ICC_SGIR_IRM BSP_BIT32(40)<br>
> +#define ICC_SGIR_AFFINITY2(val) BSP_FLD64(val, 32, 39)<br>
> +#define ICC_SGIR_AFFINITY2_GET(reg) BSP_FLD64GET(reg, 32, 39)<br>
> +#define ICC_SGIR_AFFINITY2_SET(reg, val) BSP_FLD64SET(reg, val, 32, 39)<br>
> +#define ICC_SGIR_INTID(val) BSP_FLD64(val, 24, 27)<br>
> +#define ICC_SGIR_INTID_GET(reg) BSP_FLD64GET(reg, 24, 27)<br>
> +#define ICC_SGIR_INTID_SET(reg, val) BSP_FLD64SET(reg, val, 24, 27)<br>
> +#define ICC_SGIR_AFFINITY1(val) BSP_FLD64(val, 16, 23)<br>
> +#define ICC_SGIR_AFFINITY1_GET(reg) BSP_FLD64GET(reg, 16, 23)<br>
> +#define ICC_SGIR_AFFINITY1_SET(reg, val) BSP_FLD64SET(reg, val, 16, 23)<br>
> +#define ICC_SGIR_CPU_TARGET_LIST(val) BSP_FLD64(val, 0, 15)<br>
> +#define ICC_SGIR_CPU_TARGET_LIST_GET(reg) BSP_FLD64GET(reg, 0, 15)<br>
> +#define ICC_SGIR_CPU_TARGET_LIST_SET(reg, val) BSP_FLD64SET(reg, val, 0, 15)<br>
> +<br>
> +#define MPIDR "p15, 0, %0, c0, c0, 5"<br>
> +<br>
> +#define MPIDR_AFFINITY3(val) BSP_FLD64(val, 25, 29)<br>
> +#define MPIDR_AFFINITY3_GET(reg) BSP_FLD64GET(reg, 25, 29)<br>
> +#define MPIDR_AFFINITY3_SET(reg, val) BSP_FLD64SET(reg, val, 25, 29)<br>
> +#define MPIDR_AFFINITY2(val) BSP_FLD64(val, 16, 23)<br>
> +#define MPIDR_AFFINITY2_GET(reg) BSP_FLD64GET(reg, 16, 23)<br>
> +#define MPIDR_AFFINITY2_SET(reg, val) BSP_FLD64SET(reg, val, 16, 23)<br>
> +#define MPIDR_AFFINITY1(val) BSP_FLD64(val, 8, 15)<br>
> +#define MPIDR_AFFINITY1_GET(reg) BSP_FLD64GET(reg, 8, 15)<br>
> +#define MPIDR_AFFINITY1_SET(reg, val) BSP_FLD64SET(reg, val, 8, 15)<br>
> +#define MPIDR_AFFINITY0(val) BSP_FLD64(val, 0, 7)<br>
> +#define MPIDR_AFFINITY0_GET(reg) BSP_FLD64GET(reg, 0, 7)<br>
> +#define MPIDR_AFFINITY0_SET(reg, val) BSP_FLD64SET(reg, val, 0, 7)<br>
> +<br>
> +#define READ_SR(SR_NAME) \<br>
> +({ \<br>
> + uint32_t value; \<br>
> + __asm__ volatile("mrc " SR_NAME : "=r" (value) ); \<br>
> + value; \<br>
> +})<br>
> +<br>
> +#define WRITE_SR(SR_NAME, VALUE) \<br>
> + __asm__ volatile("mcr " SR_NAME " \n" : : "r" (VALUE) );<br>
> +<br>
> +#define WRITE64_SR(SR_NAME, VALUE) \<br>
> + __asm__ volatile("mcrr " SR_NAME " \n" : : "r" (VALUE) );<br>
> +<br>
> +#define ARM_GIC_REDIST ((volatile gic_redist *) BSP_ARM_GIC_REDIST_BASE)<br>
> +#define ARM_GIC_SGI_PPI (((volatile gic_sgi_ppi *) ((char*)BSP_ARM_GIC_REDIST_BASE + (1 << 16))))<br>
> +<br>
> +void bsp_interrupt_dispatch(void)<br>
> +{<br>
> + uint32_t icciar = READ_SR(ICC_IAR1);<br>
> + rtems_vector_number vector = GIC_CPUIF_ICCIAR_ACKINTID_GET(icciar);<br>
> + rtems_vector_number spurious = 1023;<br>
> +<br>
> + if (vector != spurious) {<br>
> + uint32_t psr = _ARMV4_Status_irq_enable();<br>
> + bsp_interrupt_handler_dispatch(vector);<br>
> +<br>
> + _ARMV4_Status_restore(psr);<br>
> +<br>
> + WRITE_SR(ICC_EOIR1, icciar);<br>
> + }<br>
> +}<br>
> +<br>
> +void bsp_interrupt_vector_enable(rtems_vector_number vector)<br>
> +{<br>
> + volatile gic_dist *dist = ARM_GIC_DIST;<br>
> + volatile gic_sgi_ppi *sgi_ppi = ARM_GIC_SGI_PPI;<br>
> +<br>
> + bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector));<br>
> +<br>
> + /* TODO(kmoore) This could use some cleanup and integration<br>
> + * Vectors below 32 are currently routed through the redistributor */<br>
> + if (vector >= 32) {<br>
> + gic_id_enable(dist, vector);<br>
> + } else {<br>
> + sgi_ppi->icspiser[0] = 1 << (vector % 32);<br>
> + }<br>
> +}<br>
> +<br>
> +void bsp_interrupt_vector_disable(rtems_vector_number vector)<br>
> +{<br>
> + volatile gic_dist *dist = ARM_GIC_DIST;<br>
> + volatile gic_sgi_ppi *sgi_ppi = ARM_GIC_SGI_PPI;<br>
> +<br>
> + bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector));<br>
> +<br>
> + if (vector >= 32) {<br>
> + gic_id_disable(dist, vector);<br>
> + } else {<br>
> + sgi_ppi->icspicer[0] = 1 << (vector % 32);<br>
> + }<br>
> +}<br>
> +<br>
> +static inline uint32_t get_id_count(volatile gic_dist *dist)<br>
> +{<br>
> + uint32_t id_count = GIC_DIST_ICDICTR_IT_LINES_NUMBER_GET(dist->icdictr);<br>
> +<br>
> + id_count = 32 * (id_count + 1);<br>
> + id_count = id_count <= 1020 ? id_count : 1020;<br>
> +<br>
> + return id_count;<br>
> +}<br>
> +<br>
> +static void init_cpu_interface(void)<br>
> +{<br>
> + uint32_t sre_value = 0x7;<br>
> + WRITE_SR(ICC_SRE, sre_value);<br>
> + WRITE_SR(ICC_PMR, GIC_CPUIF_ICCPMR_PRIORITY(0xff));<br>
> + WRITE_SR(ICC_BPR0, GIC_CPUIF_ICCBPR_BINARY_POINT(0x0));<br>
> +<br>
> + volatile gic_redist *redist = ARM_GIC_REDIST;<br>
> + uint32_t waker = redist->icrwaker;<br>
> + uint32_t waker_mask = GIC_REDIST_ICRWAKER_PROCESSOR_SLEEP;<br>
> + waker &= ~waker_mask;<br>
> + redist->icrwaker = waker;<br>
> +<br>
> + /* Set interrupt group to 1NS for SGI/PPI interrupts routed through the redistributor */<br>
> + volatile gic_sgi_ppi *sgi_ppi = ARM_GIC_SGI_PPI;<br>
> + sgi_ppi->icspigrpr[0] = 0xffffffff;<br>
> + sgi_ppi->icspigrpmodr[0] = 0;<br>
> + for (int id = 0; id < 32; id++) {<br>
> + sgi_ppi->icspiprior[id] = PRIORITY_DEFAULT;<br>
> + }<br>
> +<br>
> + /* Enable interrupt groups 0 and 1 */<br>
> + WRITE_SR(ICC_IGRPEN0, 0x1);<br>
> + WRITE_SR(ICC_IGRPEN1, 0x1);<br>
> + WRITE_SR(ICC_CTLR, 0x0);<br>
> +}<br>
> +<br>
> +rtems_status_code bsp_interrupt_facility_initialize(void)<br>
> +{<br>
> + volatile gic_dist *dist = ARM_GIC_DIST;<br>
> + uint32_t id_count = get_id_count(dist);<br>
> + uint32_t id;<br>
> +<br>
> + arm_cp15_set_exception_handler(<br>
> + ARM_EXCEPTION_IRQ,<br>
> + _ARMV4_Exception_interrupt<br>
> + );<br>
> +<br>
> + dist->icddcr = GIC_DIST_ICDDCR_ARE_NS | GIC_DIST_ICDDCR_ARE_S<br>
> + | GIC_DIST_ICDDCR_ENABLE_GRP1S | GIC_DIST_ICDDCR_ENABLE_GRP1NS<br>
> + | GIC_DIST_ICDDCR_ENABLE_GRP0;<br>
> +<br>
> + for (id = 0; id < id_count; id += 32) {<br>
> + /* Disable all interrupts */<br>
> + dist->icdicer[id / 32] = 0xffffffff;<br>
> +<br>
> + /* Set interrupt group to 1NS for all interrupts */<br>
> + dist->icdigr[id / 32] = 0xffffffff;<br>
> + dist->icdigmr[id / 32] = 0;<br>
> + }<br>
> +<br>
> + for (id = 0; id < id_count; ++id) {<br>
> + gic_id_set_priority(dist, id, PRIORITY_DEFAULT);<br>
> + }<br>
> +<br>
> + for (id = 32; id < id_count; ++id) {<br>
> + gic_id_set_targets(dist, id, 0x01);<br>
> + }<br>
> +<br>
> + init_cpu_interface();<br>
> + return RTEMS_SUCCESSFUL;<br>
> +}<br>
> +<br>
> +#ifdef RTEMS_SMP<br>
> +BSP_START_TEXT_SECTION void arm_gic_irq_initialize_secondary_cpu(void)<br>
> +{<br>
> + volatile gic_dist *dist = ARM_GIC_DIST;<br>
> +<br>
> + while ((dist->icddcr & GIC_DIST_ICDDCR_ENABLE) == 0) {<br>
> + /* Wait */<br>
> + }<br>
> +<br>
> +#error modify init_cpu_interface to use correct offsets for each CPU<br>
> + init_cpu_interface();<br>
> +}<br>
> +#endif<br>
> +<br>
> +rtems_status_code arm_gic_irq_set_priority(<br>
> + rtems_vector_number vector,<br>
> + uint8_t priority<br>
> +)<br>
> +{<br>
> + rtems_status_code sc = RTEMS_SUCCESSFUL;<br>
> +<br>
> + if (bsp_interrupt_is_valid_vector(vector)) {<br>
> + if (vector < 32) {<br>
> + volatile gic_sgi_ppi *sgi_ppi = ARM_GIC_SGI_PPI;<br>
> + sgi_ppi->icspiprior[vector] = priority;<br>
> + } else {<br>
> + volatile gic_dist *dist = ARM_GIC_DIST;<br>
> + gic_id_set_priority(dist, vector, priority);<br>
> + }<br>
> + } else {<br>
> + sc = RTEMS_INVALID_ID;<br>
> + }<br>
> +<br>
> + return sc;<br>
> +}<br>
> +<br>
> +rtems_status_code arm_gic_irq_get_priority(<br>
> + rtems_vector_number vector,<br>
> + uint8_t *priority<br>
> +)<br>
> +{<br>
> + rtems_status_code sc = RTEMS_SUCCESSFUL;<br>
> +<br>
> + if (bsp_interrupt_is_valid_vector(vector)) {<br>
> + if (vector < 32) {<br>
> + volatile gic_sgi_ppi *sgi_ppi = ARM_GIC_SGI_PPI;<br>
> + *priority = sgi_ppi->icspiprior[vector];<br>
> + } else {<br>
> + volatile gic_dist *dist = ARM_GIC_DIST;<br>
> + *priority = gic_id_get_priority(dist, vector);<br>
> + }<br>
> + } else {<br>
> + sc = RTEMS_INVALID_ID;<br>
> + }<br>
> +<br>
> + return sc;<br>
> +}<br>
> +<br>
> +void bsp_interrupt_set_affinity(<br>
> + rtems_vector_number vector,<br>
> + const Processor_mask *affinity<br>
> +)<br>
> +{<br>
> + volatile gic_dist *dist = ARM_GIC_DIST;<br>
> + uint8_t targets = (uint8_t) _Processor_mask_To_uint32_t(affinity, 0);<br>
> +<br>
> + gic_id_set_targets(dist, vector, targets);<br>
> +}<br>
> +<br>
> +void bsp_interrupt_get_affinity(<br>
> + rtems_vector_number vector,<br>
> + Processor_mask *affinity<br>
> +)<br>
> +{<br>
> + volatile gic_dist *dist = ARM_GIC_DIST;<br>
> + uint8_t targets = gic_id_get_targets(dist, vector);<br>
> +<br>
> + _Processor_mask_From_uint32_t(affinity, targets, 0);<br>
> +}<br>
> +<br>
> +void arm_gic_trigger_sgi(<br>
> + rtems_vector_number vector,<br>
> + arm_gic_irq_software_irq_target_filter filter,<br>
> + uint8_t targets<br>
> +)<br>
> +{<br>
> + /* TODO(kmoore) Handle filter:<br>
> + * ARM_GIC_IRQ_SOFTWARE_IRQ_TO_ALL_IN_LIST,<br>
> + * ARM_GIC_IRQ_SOFTWARE_IRQ_TO_ALL_EXCEPT_SELF,<br>
> + * ARM_GIC_IRQ_SOFTWARE_IRQ_TO_SELF */<br>
> + uint32_t mpidr = READ_SR(MPIDR);<br>
> + uint64_t value = ICC_SGIR_AFFINITY3(MPIDR_AFFINITY3_GET(mpidr))<br>
> + | ICC_SGIR_AFFINITY2(MPIDR_AFFINITY2_GET(mpidr))<br>
> + | ICC_SGIR_INTID(vector)<br>
> + | ICC_SGIR_AFFINITY1(MPIDR_AFFINITY1_GET(mpidr))<br>
> + | ICC_SGIR_CPU_TARGET_LIST(1);<br>
> + WRITE64_SR(ICC_SGI1, value);<br>
> +}<br>
> <br>
<br>
Thanks,<br>
Jeff Kubascik<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div>