18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * arch/arm64/include/asm/arch_gicv3.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2015 ARM Ltd. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci#ifndef __ASM_ARCH_GICV3_H 88c2ecf20Sopenharmony_ci#define __ASM_ARCH_GICV3_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <asm/sysreg.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/irqchip/arm-gic-common.h> 158c2ecf20Sopenharmony_ci#include <linux/stringify.h> 168c2ecf20Sopenharmony_ci#include <asm/barrier.h> 178c2ecf20Sopenharmony_ci#include <asm/cacheflush.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define read_gicreg(r) read_sysreg_s(SYS_ ## r) 208c2ecf20Sopenharmony_ci#define write_gicreg(v, r) write_sysreg_s(v, SYS_ ## r) 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* 238c2ecf20Sopenharmony_ci * Low-level accessors 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * These system registers are 32 bits, but we make sure that the compiler 268c2ecf20Sopenharmony_ci * sets the GP register's most significant bits to 0 with an explicit cast. 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic inline void gic_write_eoir(u32 irq) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci write_sysreg_s(irq, SYS_ICC_EOIR1_EL1); 328c2ecf20Sopenharmony_ci isb(); 338c2ecf20Sopenharmony_ci} 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cistatic __always_inline void gic_write_dir(u32 irq) 368c2ecf20Sopenharmony_ci{ 378c2ecf20Sopenharmony_ci write_sysreg_s(irq, SYS_ICC_DIR_EL1); 388c2ecf20Sopenharmony_ci isb(); 398c2ecf20Sopenharmony_ci} 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic inline u64 gic_read_iar_common(void) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci u64 irqstat; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci irqstat = read_sysreg_s(SYS_ICC_IAR1_EL1); 468c2ecf20Sopenharmony_ci dsb(sy); 478c2ecf20Sopenharmony_ci return irqstat; 488c2ecf20Sopenharmony_ci} 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* 518c2ecf20Sopenharmony_ci * Cavium ThunderX erratum 23154 528c2ecf20Sopenharmony_ci * 538c2ecf20Sopenharmony_ci * The gicv3 of ThunderX requires a modified version for reading the 548c2ecf20Sopenharmony_ci * IAR status to ensure data synchronization (access to icc_iar1_el1 558c2ecf20Sopenharmony_ci * is not sync'ed before and after). 568c2ecf20Sopenharmony_ci */ 578c2ecf20Sopenharmony_cistatic inline u64 gic_read_iar_cavium_thunderx(void) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci u64 irqstat; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci nops(8); 628c2ecf20Sopenharmony_ci irqstat = read_sysreg_s(SYS_ICC_IAR1_EL1); 638c2ecf20Sopenharmony_ci nops(4); 648c2ecf20Sopenharmony_ci mb(); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci return irqstat; 678c2ecf20Sopenharmony_ci} 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic inline void gic_write_ctlr(u32 val) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci write_sysreg_s(val, SYS_ICC_CTLR_EL1); 728c2ecf20Sopenharmony_ci isb(); 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic inline u32 gic_read_ctlr(void) 768c2ecf20Sopenharmony_ci{ 778c2ecf20Sopenharmony_ci return read_sysreg_s(SYS_ICC_CTLR_EL1); 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistatic inline void gic_write_grpen1(u32 val) 818c2ecf20Sopenharmony_ci{ 828c2ecf20Sopenharmony_ci write_sysreg_s(val, SYS_ICC_IGRPEN1_EL1); 838c2ecf20Sopenharmony_ci isb(); 848c2ecf20Sopenharmony_ci} 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cistatic inline void gic_write_sgi1r(u64 val) 878c2ecf20Sopenharmony_ci{ 888c2ecf20Sopenharmony_ci write_sysreg_s(val, SYS_ICC_SGI1R_EL1); 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic inline u32 gic_read_sre(void) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci return read_sysreg_s(SYS_ICC_SRE_EL1); 948c2ecf20Sopenharmony_ci} 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistatic inline void gic_write_sre(u32 val) 978c2ecf20Sopenharmony_ci{ 988c2ecf20Sopenharmony_ci write_sysreg_s(val, SYS_ICC_SRE_EL1); 998c2ecf20Sopenharmony_ci isb(); 1008c2ecf20Sopenharmony_ci} 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic inline void gic_write_bpr1(u32 val) 1038c2ecf20Sopenharmony_ci{ 1048c2ecf20Sopenharmony_ci write_sysreg_s(val, SYS_ICC_BPR1_EL1); 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic inline u32 gic_read_pmr(void) 1088c2ecf20Sopenharmony_ci{ 1098c2ecf20Sopenharmony_ci return read_sysreg_s(SYS_ICC_PMR_EL1); 1108c2ecf20Sopenharmony_ci} 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_cistatic __always_inline void gic_write_pmr(u32 val) 1138c2ecf20Sopenharmony_ci{ 1148c2ecf20Sopenharmony_ci write_sysreg_s(val, SYS_ICC_PMR_EL1); 1158c2ecf20Sopenharmony_ci} 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_cistatic inline u32 gic_read_rpr(void) 1188c2ecf20Sopenharmony_ci{ 1198c2ecf20Sopenharmony_ci return read_sysreg_s(SYS_ICC_RPR_EL1); 1208c2ecf20Sopenharmony_ci} 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci#define gic_read_typer(c) readq_relaxed(c) 1238c2ecf20Sopenharmony_ci#define gic_write_irouter(v, c) writeq_relaxed(v, c) 1248c2ecf20Sopenharmony_ci#define gic_read_lpir(c) readq_relaxed(c) 1258c2ecf20Sopenharmony_ci#define gic_write_lpir(v, c) writeq_relaxed(v, c) 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci#define gic_flush_dcache_to_poc(a,l) __flush_dcache_area((a), (l)) 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci#define gits_read_baser(c) readq_relaxed(c) 1308c2ecf20Sopenharmony_ci#define gits_write_baser(v, c) writeq_relaxed(v, c) 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci#define gits_read_cbaser(c) readq_relaxed(c) 1338c2ecf20Sopenharmony_ci#define gits_write_cbaser(v, c) writeq_relaxed(v, c) 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci#define gits_write_cwriter(v, c) writeq_relaxed(v, c) 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci#define gicr_read_propbaser(c) readq_relaxed(c) 1388c2ecf20Sopenharmony_ci#define gicr_write_propbaser(v, c) writeq_relaxed(v, c) 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci#define gicr_write_pendbaser(v, c) writeq_relaxed(v, c) 1418c2ecf20Sopenharmony_ci#define gicr_read_pendbaser(c) readq_relaxed(c) 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci#define gicr_write_vpropbaser(v, c) writeq_relaxed(v, c) 1448c2ecf20Sopenharmony_ci#define gicr_read_vpropbaser(c) readq_relaxed(c) 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci#define gicr_write_vpendbaser(v, c) writeq_relaxed(v, c) 1478c2ecf20Sopenharmony_ci#define gicr_read_vpendbaser(c) readq_relaxed(c) 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistatic inline bool gic_prio_masking_enabled(void) 1508c2ecf20Sopenharmony_ci{ 1518c2ecf20Sopenharmony_ci return system_uses_irq_prio_masking(); 1528c2ecf20Sopenharmony_ci} 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistatic inline void gic_pmr_mask_irqs(void) 1558c2ecf20Sopenharmony_ci{ 1568c2ecf20Sopenharmony_ci BUILD_BUG_ON(GICD_INT_DEF_PRI < (__GIC_PRIO_IRQOFF | 1578c2ecf20Sopenharmony_ci GIC_PRIO_PSR_I_SET)); 1588c2ecf20Sopenharmony_ci BUILD_BUG_ON(GICD_INT_DEF_PRI >= GIC_PRIO_IRQON); 1598c2ecf20Sopenharmony_ci /* 1608c2ecf20Sopenharmony_ci * Need to make sure IRQON allows IRQs when SCR_EL3.FIQ is cleared 1618c2ecf20Sopenharmony_ci * and non-secure PMR accesses are not subject to the shifts that 1628c2ecf20Sopenharmony_ci * are applied to IRQ priorities 1638c2ecf20Sopenharmony_ci */ 1648c2ecf20Sopenharmony_ci BUILD_BUG_ON((0x80 | (GICD_INT_DEF_PRI >> 1)) >= GIC_PRIO_IRQON); 1658c2ecf20Sopenharmony_ci /* 1668c2ecf20Sopenharmony_ci * Same situation as above, but now we make sure that we can mask 1678c2ecf20Sopenharmony_ci * regular interrupts. 1688c2ecf20Sopenharmony_ci */ 1698c2ecf20Sopenharmony_ci BUILD_BUG_ON((0x80 | (GICD_INT_DEF_PRI >> 1)) < (__GIC_PRIO_IRQOFF_NS | 1708c2ecf20Sopenharmony_ci GIC_PRIO_PSR_I_SET)); 1718c2ecf20Sopenharmony_ci gic_write_pmr(GIC_PRIO_IRQOFF); 1728c2ecf20Sopenharmony_ci} 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_cistatic inline void gic_arch_enable_irqs(void) 1758c2ecf20Sopenharmony_ci{ 1768c2ecf20Sopenharmony_ci asm volatile ("msr daifclr, #2" : : : "memory"); 1778c2ecf20Sopenharmony_ci} 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */ 1808c2ecf20Sopenharmony_ci#endif /* __ASM_ARCH_GICV3_H */ 181