xref: /kernel/liteos_a/arch/arm/include/gic_common.h (revision 0d163575)
10d163575Sopenharmony_ci/*
20d163575Sopenharmony_ci * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
30d163575Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
40d163575Sopenharmony_ci *
50d163575Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification,
60d163575Sopenharmony_ci * are permitted provided that the following conditions are met:
70d163575Sopenharmony_ci *
80d163575Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of
90d163575Sopenharmony_ci *    conditions and the following disclaimer.
100d163575Sopenharmony_ci *
110d163575Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list
120d163575Sopenharmony_ci *    of conditions and the following disclaimer in the documentation and/or other materials
130d163575Sopenharmony_ci *    provided with the distribution.
140d163575Sopenharmony_ci *
150d163575Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used
160d163575Sopenharmony_ci *    to endorse or promote products derived from this software without specific prior written
170d163575Sopenharmony_ci *    permission.
180d163575Sopenharmony_ci *
190d163575Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
200d163575Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
210d163575Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
220d163575Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
230d163575Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
240d163575Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
250d163575Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
260d163575Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
270d163575Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
280d163575Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
290d163575Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
300d163575Sopenharmony_ci */
310d163575Sopenharmony_ci
320d163575Sopenharmony_ci#ifndef _GIC_COMMON_H
330d163575Sopenharmony_ci#define _GIC_COMMON_H
340d163575Sopenharmony_ci
350d163575Sopenharmony_ci#include "stdint.h"
360d163575Sopenharmony_ci#include "target_config.h"
370d163575Sopenharmony_ci#include "los_config.h"
380d163575Sopenharmony_ci
390d163575Sopenharmony_ci/* gic arch revision */
400d163575Sopenharmony_cienum {
410d163575Sopenharmony_ci    GICV1 = 1,
420d163575Sopenharmony_ci    GICV2,
430d163575Sopenharmony_ci    GICV3,
440d163575Sopenharmony_ci    GICV4
450d163575Sopenharmony_ci};
460d163575Sopenharmony_ci
470d163575Sopenharmony_ci#define GIC_REV_MASK                    0xF0
480d163575Sopenharmony_ci#define GIC_REV_OFFSET                  0x4
490d163575Sopenharmony_ci
500d163575Sopenharmony_ci#ifdef LOSCFG_ARCH_GIC_V2
510d163575Sopenharmony_ci#define GICC_CTLR                       (GICC_OFFSET + 0x00)            /* CPU Interface Control Register */
520d163575Sopenharmony_ci#define GICC_PMR                        (GICC_OFFSET + 0x04)            /* Interrupt Priority Mask Register */
530d163575Sopenharmony_ci#define GICC_BPR                        (GICC_OFFSET + 0x08)            /* Binary Point Register */
540d163575Sopenharmony_ci#define GICC_IAR                        (GICC_OFFSET + 0x0c)            /* Interrupt Acknowledge Register */
550d163575Sopenharmony_ci#define GICC_EOIR                       (GICC_OFFSET + 0x10)            /* End of Interrupt Register */
560d163575Sopenharmony_ci#define GICC_RPR                        (GICC_OFFSET + 0x14)            /* Running Priority Register */
570d163575Sopenharmony_ci#define GICC_HPPIR                      (GICC_OFFSET + 0x18)            /* Highest Priority Pending Interrupt Register */
580d163575Sopenharmony_ci#endif
590d163575Sopenharmony_ci
600d163575Sopenharmony_ci#define GICD_CTLR                       (GICD_OFFSET + 0x000)           /* Distributor Control Register */
610d163575Sopenharmony_ci#define GICD_TYPER                      (GICD_OFFSET + 0x004)           /* Interrupt Controller Type Register */
620d163575Sopenharmony_ci#define GICD_IIDR                       (GICD_OFFSET + 0x008)           /* Distributor Implementer Identification Register */
630d163575Sopenharmony_ci#define GICD_IGROUPR(n)                 (GICD_OFFSET + 0x080 + (n) * 4) /* Interrupt Group Registers */
640d163575Sopenharmony_ci#define GICD_ISENABLER(n)               (GICD_OFFSET + 0x100 + (n) * 4) /* Interrupt Set-Enable Registers */
650d163575Sopenharmony_ci#define GICD_ICENABLER(n)               (GICD_OFFSET + 0x180 + (n) * 4) /* Interrupt Clear-Enable Registers */
660d163575Sopenharmony_ci#define GICD_ISPENDR(n)                 (GICD_OFFSET + 0x200 + (n) * 4) /* Interrupt Set-Pending Registers */
670d163575Sopenharmony_ci#define GICD_ICPENDR(n)                 (GICD_OFFSET + 0x280 + (n) * 4) /* Interrupt Clear-Pending Registers */
680d163575Sopenharmony_ci#define GICD_ISACTIVER(n)               (GICD_OFFSET + 0x300 + (n) * 4) /* GICv2 Interrupt Set-Active Registers */
690d163575Sopenharmony_ci#define GICD_ICACTIVER(n)               (GICD_OFFSET + 0x380 + (n) * 4) /* Interrupt Clear-Active Registers */
700d163575Sopenharmony_ci#define GICD_IPRIORITYR(n)              (GICD_OFFSET + 0x400 + (n) * 4) /* Interrupt Priority Registers */
710d163575Sopenharmony_ci#define GICD_ITARGETSR(n)               (GICD_OFFSET + 0x800 + (n) * 4) /* Interrupt Processor Targets Registers */
720d163575Sopenharmony_ci#define GICD_ICFGR(n)                   (GICD_OFFSET + 0xc00 + (n) * 4) /* Interrupt Configuration Registers */
730d163575Sopenharmony_ci#define GICD_SGIR                       (GICD_OFFSET + 0xf00)           /* Software Generated Interrupt Register */
740d163575Sopenharmony_ci#define GICD_CPENDSGIR(n)               (GICD_OFFSET + 0xf10 + (n) * 4) /* SGI Clear-Pending Registers; NOT available on cortex-a9 */
750d163575Sopenharmony_ci#define GICD_SPENDSGIR(n)               (GICD_OFFSET + 0xf20 + (n) * 4) /* SGI Set-Pending Registers; NOT available on cortex-a9 */
760d163575Sopenharmony_ci#define GICD_PIDR2V2                    (GICD_OFFSET + 0xfe8)
770d163575Sopenharmony_ci#define GICD_PIDR2V3                    (GICD_OFFSET + 0xffe8)
780d163575Sopenharmony_ci
790d163575Sopenharmony_ci#ifdef LOSCFG_ARCH_GIC_V3
800d163575Sopenharmony_ci#define GICD_IGRPMODR(n)                (GICD_OFFSET + 0x0d00 + (n) * 4) /* Interrupt Group Mode Registers */
810d163575Sopenharmony_ci#define GICD_IROUTER(n)                 (GICD_OFFSET + 0x6000 + (n) * 8) /* Interrupt Rounter Registers */
820d163575Sopenharmony_ci#endif
830d163575Sopenharmony_ci
840d163575Sopenharmony_ci#define GIC_REG_8(reg)                  (*(volatile UINT8 *)((UINTPTR)(GIC_BASE_ADDR + (reg))))
850d163575Sopenharmony_ci#define GIC_REG_32(reg)                 (*(volatile UINT32 *)((UINTPTR)(GIC_BASE_ADDR + (reg))))
860d163575Sopenharmony_ci#define GIC_REG_64(reg)                 (*(volatile UINT64 *)((UINTPTR)(GIC_BASE_ADDR + (reg))))
870d163575Sopenharmony_ci
880d163575Sopenharmony_ci#define GICD_INT_DEF_PRI                0xa0U
890d163575Sopenharmony_ci#define GICD_INT_DEF_PRI_X4             (((UINT32)GICD_INT_DEF_PRI << 24) | \
900d163575Sopenharmony_ci                                         ((UINT32)GICD_INT_DEF_PRI << 16) | \
910d163575Sopenharmony_ci                                         ((UINT32)GICD_INT_DEF_PRI << 8)  | \
920d163575Sopenharmony_ci                                         (UINT32)GICD_INT_DEF_PRI)
930d163575Sopenharmony_ci
940d163575Sopenharmony_ci#define GIC_MIN_SPI_NUM                 32
950d163575Sopenharmony_ci
960d163575Sopenharmony_ci/* Interrupt preemption config */
970d163575Sopenharmony_ci#define GIC_PRIORITY_MASK               0xFFU
980d163575Sopenharmony_ci#define GIC_PRIORITY_OFFSET             8
990d163575Sopenharmony_ci
1000d163575Sopenharmony_ci/*
1010d163575Sopenharmony_ci * The number of bits to shift for an interrupt priority is dependent
1020d163575Sopenharmony_ci * on the number of bits implemented by the interrupt controller.
1030d163575Sopenharmony_ci * If the MAX_BINARY_POINT_VALUE is 7,
1040d163575Sopenharmony_ci * it means that interrupt preemption is not supported.
1050d163575Sopenharmony_ci */
1060d163575Sopenharmony_ci#ifndef LOSCFG_ARCH_INTERRUPT_PREEMPTION
1070d163575Sopenharmony_ci#define MAX_BINARY_POINT_VALUE              7
1080d163575Sopenharmony_ci#define PRIORITY_SHIFT                      0
1090d163575Sopenharmony_ci#define GIC_MAX_INTERRUPT_PREEMPTION_LEVEL  0U
1100d163575Sopenharmony_ci#else
1110d163575Sopenharmony_ci#define PRIORITY_SHIFT                      ((MAX_BINARY_POINT_VALUE + 1) % GIC_PRIORITY_OFFSET)
1120d163575Sopenharmony_ci#define GIC_MAX_INTERRUPT_PREEMPTION_LEVEL  ((UINT8)((GIC_PRIORITY_MASK + 1) >> PRIORITY_SHIFT))
1130d163575Sopenharmony_ci#endif
1140d163575Sopenharmony_ci
1150d163575Sopenharmony_ci#define GIC_INTR_PRIO_MASK                  ((UINT8)(0xFFFFFFFFU << PRIORITY_SHIFT))
1160d163575Sopenharmony_ci
1170d163575Sopenharmony_ci/*
1180d163575Sopenharmony_ci * The preemption level is up to 128, and the maximum value corresponding to the interrupt priority is 254 [7:1].
1190d163575Sopenharmony_ci * If the GIC_MAX_INTERRUPT_PREEMPTION_LEVEL is 0, the minimum priority is 0xff.
1200d163575Sopenharmony_ci */
1210d163575Sopenharmony_ci#define MIN_INTERRUPT_PRIORITY              ((UINT8)((GIC_MAX_INTERRUPT_PREEMPTION_LEVEL - 1) << PRIORITY_SHIFT))
1220d163575Sopenharmony_ci
1230d163575Sopenharmony_ci#endif
124