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_V3_H_ 330d163575Sopenharmony_ci#define _GIC_V3_H_ 340d163575Sopenharmony_ci 350d163575Sopenharmony_ci#include "stdint.h" 360d163575Sopenharmony_ci#include "target_config.h" 370d163575Sopenharmony_ci#include "los_hw_cpu.h" 380d163575Sopenharmony_ci 390d163575Sopenharmony_ci#define BIT_32(bit) (1u << bit) 400d163575Sopenharmony_ci#define BIT_64(bit) (1ul << bit) 410d163575Sopenharmony_ci 420d163575Sopenharmony_ci#define ICC_CTLR_EL1 "S3_0_C12_C12_4" 430d163575Sopenharmony_ci#define ICC_PMR_EL1 "S3_0_C4_C6_0" 440d163575Sopenharmony_ci#define ICC_IAR1_EL1 "S3_0_C12_C12_0" 450d163575Sopenharmony_ci#define ICC_SRE_EL1 "S3_0_C12_C12_5" 460d163575Sopenharmony_ci#define ICC_BPR0_EL1 "S3_0_C12_C8_3" 470d163575Sopenharmony_ci#define ICC_BPR1_EL1 "S3_0_C12_C12_3" 480d163575Sopenharmony_ci#define ICC_IGRPEN0_EL1 "S3_0_C12_C12_6" 490d163575Sopenharmony_ci#define ICC_IGRPEN1_EL1 "S3_0_C12_C12_7" 500d163575Sopenharmony_ci#define ICC_EOIR1_EL1 "S3_0_C12_C12_1" 510d163575Sopenharmony_ci#define ICC_SGI1R_EL1 "S3_0_C12_C11_5" 520d163575Sopenharmony_ci#define ICC_EOIR0_EL1 "S3_0_c12_c8_1" 530d163575Sopenharmony_ci#define ICC_IAR0_EL1 "S3_0_C12_C8_0" 540d163575Sopenharmony_ci 550d163575Sopenharmony_ci#define ICC_CTLR_EL3 "S3_6_C12_C12_4" 560d163575Sopenharmony_ci#define ICC_SRE_EL3 "S3_6_C12_C12_5" 570d163575Sopenharmony_ci#define ICC_IGRPEN1_EL3 "S3_6_C12_C12_7" 580d163575Sopenharmony_ci 590d163575Sopenharmony_ci/* GICD_CTLR bit definitions */ 600d163575Sopenharmony_ci#define CTLR_ENALBE_G0 BIT_32(0) 610d163575Sopenharmony_ci#define CTLR_ENABLE_G1NS BIT_32(1) 620d163575Sopenharmony_ci#define CTLR_ENABLE_G1S BIT_32(2) 630d163575Sopenharmony_ci#define CTLR_RES0 BIT_32(3) 640d163575Sopenharmony_ci#define CTLR_ARE_S BIT_32(4) 650d163575Sopenharmony_ci#define CTLR_ARE_NS BIT_32(5) 660d163575Sopenharmony_ci#define CTLR_DS BIT_32(6) 670d163575Sopenharmony_ci#define CTLR_E1NWF BIT_32(7) 680d163575Sopenharmony_ci#define GICD_CTLR_RWP BIT_32(31) 690d163575Sopenharmony_ci 700d163575Sopenharmony_ci/* peripheral identification registers */ 710d163575Sopenharmony_ci#define GICD_CIDR0 (GICD_OFFSET + 0xfff0) 720d163575Sopenharmony_ci#define GICD_CIDR1 (GICD_OFFSET + 0xfff4) 730d163575Sopenharmony_ci#define GICD_CIDR2 (GICD_OFFSET + 0xfff8) 740d163575Sopenharmony_ci#define GICD_CIDR3 (GICD_OFFSET + 0xfffc) 750d163575Sopenharmony_ci#define GICD_PIDR0 (GICD_OFFSET + 0xffe0) 760d163575Sopenharmony_ci#define GICD_PIDR1 (GICD_OFFSET + 0xffe4) 770d163575Sopenharmony_ci#define GICD_PIDR2 (GICD_OFFSET + 0xffe8) 780d163575Sopenharmony_ci#define GICD_PIDR3 (GICD_OFFSET + 0xffec) 790d163575Sopenharmony_ci 800d163575Sopenharmony_ci/* GICD_PIDR bit definitions and masks */ 810d163575Sopenharmony_ci#define GICD_PIDR2_ARCHREV_SHIFT 4 820d163575Sopenharmony_ci#define GICD_PIDR2_ARCHREV_MASK 0xf 830d163575Sopenharmony_ci 840d163575Sopenharmony_ci/* redistributor registers */ 850d163575Sopenharmony_ci#define GICR_SGI_OFFSET (GICR_OFFSET + 0x10000) 860d163575Sopenharmony_ci 870d163575Sopenharmony_ci#define GICR_CTLR(i) (GICR_OFFSET + GICR_STRIDE * (i) + 0x0000) 880d163575Sopenharmony_ci#define GICR_IIDR(i) (GICR_OFFSET + GICR_STRIDE * (i) + 0x0004) 890d163575Sopenharmony_ci#define GICR_TYPER(i, n) (GICR_OFFSET + GICR_STRIDE * (i) + 0x0008 + (n)*4) 900d163575Sopenharmony_ci#define GICR_STATUSR(i) (GICR_OFFSET + GICR_STRIDE * (i) + 0x0010) 910d163575Sopenharmony_ci#define GICR_WAKER(i) (GICR_OFFSET + GICR_STRIDE * (i) + 0x0014) 920d163575Sopenharmony_ci#define GICR_IGROUPR0(i) (GICR_SGI_OFFSET + GICR_STRIDE * (i) + 0x0080) 930d163575Sopenharmony_ci#define GICR_IGRPMOD0(i) (GICR_SGI_OFFSET + GICR_STRIDE * (i) + 0x0d00) 940d163575Sopenharmony_ci#define GICR_ISENABLER0(i) (GICR_SGI_OFFSET + GICR_STRIDE * (i) + 0x0100) 950d163575Sopenharmony_ci#define GICR_ICENABLER0(i) (GICR_SGI_OFFSET + GICR_STRIDE * (i) + 0x0180) 960d163575Sopenharmony_ci#define GICR_ISPENDR0(i) (GICR_SGI_OFFSET + GICR_STRIDE * (i) + 0x0200) 970d163575Sopenharmony_ci#define GICR_ICPENDR0(i) (GICR_SGI_OFFSET + GICR_STRIDE * (i) + 0x0280) 980d163575Sopenharmony_ci#define GICR_ISACTIVER0(i) (GICR_SGI_OFFSET + GICR_STRIDE * (i) + 0x0300) 990d163575Sopenharmony_ci#define GICR_ICACTIVER0(i) (GICR_SGI_OFFSET + GICR_STRIDE * (i) + 0x0380) 1000d163575Sopenharmony_ci#define GICR_IPRIORITYR0(i) (GICR_SGI_OFFSET + GICR_STRIDE * (i) + 0x0400) 1010d163575Sopenharmony_ci#define GICR_ICFGR0(i) (GICR_SGI_OFFSET + GICR_STRIDE * (i) + 0x0c00) 1020d163575Sopenharmony_ci#define GICR_ICFGR1(i) (GICR_SGI_OFFSET + GICR_STRIDE * (i) + 0x0c04) 1030d163575Sopenharmony_ci#define GICR_NSACR(i) (GICR_SGI_OFFSET + GICR_STRIDE * (i) + 0x0e00) 1040d163575Sopenharmony_ci 1050d163575Sopenharmony_ci#define GICR_WAKER_PROCESSORSLEEP_LEN 1U 1060d163575Sopenharmony_ci#define GICR_WAKER_PROCESSORSLEEP_OFFSET 1 1070d163575Sopenharmony_ci#define GICR_WAKER_CHILDRENASLEEP_LEN 1U 1080d163575Sopenharmony_ci#define GICR_WAKER_CHILDRENASLEEP_OFFSET 2 1090d163575Sopenharmony_ci#define GICR_WAKER_PROCESSORSLEEP (GICR_WAKER_PROCESSORSLEEP_LEN << GICR_WAKER_PROCESSORSLEEP_OFFSET) 1100d163575Sopenharmony_ci#define GICR_WAKER_CHILDRENASLEEP (GICR_WAKER_CHILDRENASLEEP_LEN << GICR_WAKER_CHILDRENASLEEP_OFFSET) 1110d163575Sopenharmony_ci 1120d163575Sopenharmony_ciSTATIC INLINE VOID GiccSetCtlr(UINT32 val) 1130d163575Sopenharmony_ci{ 1140d163575Sopenharmony_ci#ifdef LOSCFG_ARCH_SECURE_MONITOR_MODE 1150d163575Sopenharmony_ci __asm__ volatile("msr " ICC_CTLR_EL3 ", %0" ::"r"(val)); 1160d163575Sopenharmony_ci#else 1170d163575Sopenharmony_ci __asm__ volatile("msr " ICC_CTLR_EL1 ", %0" ::"r"(val)); 1180d163575Sopenharmony_ci#endif 1190d163575Sopenharmony_ci ISB; 1200d163575Sopenharmony_ci} 1210d163575Sopenharmony_ci 1220d163575Sopenharmony_ciSTATIC INLINE VOID GiccSetPmr(UINT32 val) 1230d163575Sopenharmony_ci{ 1240d163575Sopenharmony_ci __asm__ volatile("msr " ICC_PMR_EL1 ", %0" ::"r"(val)); 1250d163575Sopenharmony_ci ISB; 1260d163575Sopenharmony_ci DSB; 1270d163575Sopenharmony_ci} 1280d163575Sopenharmony_ci 1290d163575Sopenharmony_ciSTATIC INLINE VOID GiccSetIgrpen0(UINT32 val) 1300d163575Sopenharmony_ci{ 1310d163575Sopenharmony_ci __asm__ volatile("msr " ICC_IGRPEN0_EL1 ", %0" ::"r"(val)); 1320d163575Sopenharmony_ci ISB; 1330d163575Sopenharmony_ci} 1340d163575Sopenharmony_ci 1350d163575Sopenharmony_ciSTATIC INLINE VOID GiccSetIgrpen1(UINT32 val) 1360d163575Sopenharmony_ci{ 1370d163575Sopenharmony_ci#ifdef LOSCFG_ARCH_SECURE_MONITOR_MODE 1380d163575Sopenharmony_ci __asm__ volatile("msr " ICC_IGRPEN1_EL3 ", %0" ::"r"(val)); 1390d163575Sopenharmony_ci#else 1400d163575Sopenharmony_ci __asm__ volatile("msr " ICC_IGRPEN1_EL1 ", %0" ::"r"(val)); 1410d163575Sopenharmony_ci#endif 1420d163575Sopenharmony_ci ISB; 1430d163575Sopenharmony_ci} 1440d163575Sopenharmony_ci 1450d163575Sopenharmony_ciSTATIC INLINE UINT32 GiccGetSre(VOID) 1460d163575Sopenharmony_ci{ 1470d163575Sopenharmony_ci UINT32 temp; 1480d163575Sopenharmony_ci#ifdef LOSCFG_ARCH_SECURE_MONITOR_MODE 1490d163575Sopenharmony_ci __asm__ volatile("mrs %0, " ICC_SRE_EL3 : "=r"(temp)); 1500d163575Sopenharmony_ci#else 1510d163575Sopenharmony_ci __asm__ volatile("mrs %0, " ICC_SRE_EL1 : "=r"(temp)); 1520d163575Sopenharmony_ci#endif 1530d163575Sopenharmony_ci return temp; 1540d163575Sopenharmony_ci} 1550d163575Sopenharmony_ci 1560d163575Sopenharmony_ciSTATIC INLINE VOID GiccSetSre(UINT32 val) 1570d163575Sopenharmony_ci{ 1580d163575Sopenharmony_ci#ifdef LOSCFG_ARCH_SECURE_MONITOR_MODE 1590d163575Sopenharmony_ci __asm__ volatile("msr " ICC_SRE_EL3 ", %0" ::"r"(val)); 1600d163575Sopenharmony_ci#else 1610d163575Sopenharmony_ci __asm__ volatile("msr " ICC_SRE_EL1 ", %0" ::"r"(val)); 1620d163575Sopenharmony_ci#endif 1630d163575Sopenharmony_ci ISB; 1640d163575Sopenharmony_ci} 1650d163575Sopenharmony_ci 1660d163575Sopenharmony_ciSTATIC INLINE VOID GiccSetEoir(UINT32 val) 1670d163575Sopenharmony_ci{ 1680d163575Sopenharmony_ci#ifdef LOSCFG_ARCH_SECURE_MONITOR_MODE 1690d163575Sopenharmony_ci __asm__ volatile("msr " ICC_EOIR0_EL1 ", %0" ::"r"(val)); 1700d163575Sopenharmony_ci#else 1710d163575Sopenharmony_ci __asm__ volatile("msr " ICC_EOIR1_EL1 ", %0" ::"r"(val)); 1720d163575Sopenharmony_ci#endif 1730d163575Sopenharmony_ci ISB; 1740d163575Sopenharmony_ci} 1750d163575Sopenharmony_ci 1760d163575Sopenharmony_ciSTATIC INLINE UINT32 GiccGetIar(VOID) 1770d163575Sopenharmony_ci{ 1780d163575Sopenharmony_ci UINT32 temp; 1790d163575Sopenharmony_ci 1800d163575Sopenharmony_ci#ifdef LOSCFG_ARCH_SECURE_MONITOR_MODE 1810d163575Sopenharmony_ci __asm__ volatile("mrs %0, " ICC_IAR0_EL1 : "=r"(temp)); 1820d163575Sopenharmony_ci#else 1830d163575Sopenharmony_ci __asm__ volatile("mrs %0, " ICC_IAR1_EL1 : "=r"(temp)); 1840d163575Sopenharmony_ci#endif 1850d163575Sopenharmony_ci DSB; 1860d163575Sopenharmony_ci 1870d163575Sopenharmony_ci return temp; 1880d163575Sopenharmony_ci} 1890d163575Sopenharmony_ci 1900d163575Sopenharmony_ciSTATIC INLINE VOID GiccSetSgi1r(UINT64 val) 1910d163575Sopenharmony_ci{ 1920d163575Sopenharmony_ci __asm__ volatile("msr " ICC_SGI1R_EL1 ", %0" ::"r"(val)); 1930d163575Sopenharmony_ci ISB; 1940d163575Sopenharmony_ci DSB; 1950d163575Sopenharmony_ci} 1960d163575Sopenharmony_ci 1970d163575Sopenharmony_ciSTATIC INLINE VOID GiccSetBpr0(UINT32 val) 1980d163575Sopenharmony_ci{ 1990d163575Sopenharmony_ci __asm__ volatile("msr " ICC_BPR0_EL1 ", %0" ::"r"(val)); 2000d163575Sopenharmony_ci ISB; 2010d163575Sopenharmony_ci DSB; 2020d163575Sopenharmony_ci} 2030d163575Sopenharmony_ci#endif 204