2014-07-24 13:14:42 +00:00
|
|
|
/*
|
|
|
|
* Macros for accessing system registers with older binutils.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 ARM Ltd.
|
|
|
|
* Author: Catalin Marinas <catalin.marinas@arm.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ASM_SYSREG_H
|
|
|
|
#define __ASM_SYSREG_H
|
|
|
|
|
2015-11-05 15:09:17 +00:00
|
|
|
#include <linux/stringify.h>
|
|
|
|
|
2015-07-22 18:05:54 +00:00
|
|
|
#include <asm/opcodes.h>
|
|
|
|
|
2015-07-22 10:38:14 +00:00
|
|
|
/*
|
|
|
|
* ARMv8 ARM reserves the following encoding for system registers:
|
|
|
|
* (Ref: ARMv8 ARM, Section: "System instruction class encoding overview",
|
|
|
|
* C5.2, version:ARM DDI 0487A.f)
|
|
|
|
* [20-19] : Op0
|
|
|
|
* [18-16] : Op1
|
|
|
|
* [15-12] : CRn
|
|
|
|
* [11-8] : CRm
|
|
|
|
* [7-5] : Op2
|
|
|
|
*/
|
2014-07-24 13:14:42 +00:00
|
|
|
#define sys_reg(op0, op1, crn, crm, op2) \
|
2015-07-22 10:38:14 +00:00
|
|
|
((((op0)&3)<<19)|((op1)<<16)|((crn)<<12)|((crm)<<8)|((op2)<<5))
|
2014-07-24 13:14:42 +00:00
|
|
|
|
2015-10-19 13:24:45 +00:00
|
|
|
#define SYS_MIDR_EL1 sys_reg(3, 0, 0, 0, 0)
|
|
|
|
#define SYS_MPIDR_EL1 sys_reg(3, 0, 0, 0, 5)
|
|
|
|
#define SYS_REVIDR_EL1 sys_reg(3, 0, 0, 0, 6)
|
|
|
|
|
|
|
|
#define SYS_ID_PFR0_EL1 sys_reg(3, 0, 0, 1, 0)
|
|
|
|
#define SYS_ID_PFR1_EL1 sys_reg(3, 0, 0, 1, 1)
|
|
|
|
#define SYS_ID_DFR0_EL1 sys_reg(3, 0, 0, 1, 2)
|
|
|
|
#define SYS_ID_MMFR0_EL1 sys_reg(3, 0, 0, 1, 4)
|
|
|
|
#define SYS_ID_MMFR1_EL1 sys_reg(3, 0, 0, 1, 5)
|
|
|
|
#define SYS_ID_MMFR2_EL1 sys_reg(3, 0, 0, 1, 6)
|
|
|
|
#define SYS_ID_MMFR3_EL1 sys_reg(3, 0, 0, 1, 7)
|
|
|
|
|
|
|
|
#define SYS_ID_ISAR0_EL1 sys_reg(3, 0, 0, 2, 0)
|
|
|
|
#define SYS_ID_ISAR1_EL1 sys_reg(3, 0, 0, 2, 1)
|
|
|
|
#define SYS_ID_ISAR2_EL1 sys_reg(3, 0, 0, 2, 2)
|
|
|
|
#define SYS_ID_ISAR3_EL1 sys_reg(3, 0, 0, 2, 3)
|
|
|
|
#define SYS_ID_ISAR4_EL1 sys_reg(3, 0, 0, 2, 4)
|
|
|
|
#define SYS_ID_ISAR5_EL1 sys_reg(3, 0, 0, 2, 5)
|
|
|
|
#define SYS_ID_MMFR4_EL1 sys_reg(3, 0, 0, 2, 6)
|
|
|
|
|
|
|
|
#define SYS_MVFR0_EL1 sys_reg(3, 0, 0, 3, 0)
|
|
|
|
#define SYS_MVFR1_EL1 sys_reg(3, 0, 0, 3, 1)
|
|
|
|
#define SYS_MVFR2_EL1 sys_reg(3, 0, 0, 3, 2)
|
|
|
|
|
|
|
|
#define SYS_ID_AA64PFR0_EL1 sys_reg(3, 0, 0, 4, 0)
|
|
|
|
#define SYS_ID_AA64PFR1_EL1 sys_reg(3, 0, 0, 4, 1)
|
|
|
|
|
|
|
|
#define SYS_ID_AA64DFR0_EL1 sys_reg(3, 0, 0, 5, 0)
|
|
|
|
#define SYS_ID_AA64DFR1_EL1 sys_reg(3, 0, 0, 5, 1)
|
|
|
|
|
|
|
|
#define SYS_ID_AA64ISAR0_EL1 sys_reg(3, 0, 0, 6, 0)
|
|
|
|
#define SYS_ID_AA64ISAR1_EL1 sys_reg(3, 0, 0, 6, 1)
|
|
|
|
|
|
|
|
#define SYS_ID_AA64MMFR0_EL1 sys_reg(3, 0, 0, 7, 0)
|
|
|
|
#define SYS_ID_AA64MMFR1_EL1 sys_reg(3, 0, 0, 7, 1)
|
2016-02-05 14:58:47 +00:00
|
|
|
#define SYS_ID_AA64MMFR2_EL1 sys_reg(3, 0, 0, 7, 2)
|
2015-10-19 13:24:45 +00:00
|
|
|
|
|
|
|
#define SYS_CNTFRQ_EL0 sys_reg(3, 3, 14, 0, 0)
|
|
|
|
#define SYS_CTR_EL0 sys_reg(3, 3, 0, 0, 1)
|
|
|
|
#define SYS_DCZID_EL0 sys_reg(3, 3, 0, 0, 7)
|
|
|
|
|
|
|
|
#define REG_PSTATE_PAN_IMM sys_reg(0, 0, 4, 0, 4)
|
2016-02-05 14:58:48 +00:00
|
|
|
#define REG_PSTATE_UAO_IMM sys_reg(0, 0, 4, 0, 3)
|
2015-07-22 18:05:54 +00:00
|
|
|
|
|
|
|
#define SET_PSTATE_PAN(x) __inst_arm(0xd5000000 | REG_PSTATE_PAN_IMM |\
|
|
|
|
(!!x)<<8 | 0x1f)
|
2016-02-05 14:58:48 +00:00
|
|
|
#define SET_PSTATE_UAO(x) __inst_arm(0xd5000000 | REG_PSTATE_UAO_IMM |\
|
|
|
|
(!!x)<<8 | 0x1f)
|
2015-07-22 18:05:54 +00:00
|
|
|
|
2016-04-27 16:47:01 +00:00
|
|
|
/* Common SCTLR_ELx flags. */
|
|
|
|
#define SCTLR_ELx_EE (1 << 25)
|
|
|
|
#define SCTLR_ELx_I (1 << 12)
|
|
|
|
#define SCTLR_ELx_SA (1 << 3)
|
|
|
|
#define SCTLR_ELx_C (1 << 2)
|
|
|
|
#define SCTLR_ELx_A (1 << 1)
|
|
|
|
#define SCTLR_ELx_M 1
|
|
|
|
|
|
|
|
#define SCTLR_ELx_FLAGS (SCTLR_ELx_M | SCTLR_ELx_A | SCTLR_ELx_C | \
|
|
|
|
SCTLR_ELx_SA | SCTLR_ELx_I)
|
|
|
|
|
|
|
|
/* SCTLR_EL1 specific flags. */
|
2016-06-28 17:07:32 +00:00
|
|
|
#define SCTLR_EL1_UCI (1 << 26)
|
2016-04-27 16:47:01 +00:00
|
|
|
#define SCTLR_EL1_SPAN (1 << 23)
|
2016-09-09 13:07:16 +00:00
|
|
|
#define SCTLR_EL1_UCT (1 << 15)
|
2016-04-27 16:47:01 +00:00
|
|
|
#define SCTLR_EL1_SED (1 << 8)
|
|
|
|
#define SCTLR_EL1_CP15BEN (1 << 5)
|
2015-10-19 13:24:45 +00:00
|
|
|
|
|
|
|
/* id_aa64isar0 */
|
|
|
|
#define ID_AA64ISAR0_RDM_SHIFT 28
|
|
|
|
#define ID_AA64ISAR0_ATOMICS_SHIFT 20
|
|
|
|
#define ID_AA64ISAR0_CRC32_SHIFT 16
|
|
|
|
#define ID_AA64ISAR0_SHA2_SHIFT 12
|
|
|
|
#define ID_AA64ISAR0_SHA1_SHIFT 8
|
|
|
|
#define ID_AA64ISAR0_AES_SHIFT 4
|
|
|
|
|
|
|
|
/* id_aa64pfr0 */
|
|
|
|
#define ID_AA64PFR0_GIC_SHIFT 24
|
|
|
|
#define ID_AA64PFR0_ASIMD_SHIFT 20
|
|
|
|
#define ID_AA64PFR0_FP_SHIFT 16
|
|
|
|
#define ID_AA64PFR0_EL3_SHIFT 12
|
|
|
|
#define ID_AA64PFR0_EL2_SHIFT 8
|
|
|
|
#define ID_AA64PFR0_EL1_SHIFT 4
|
|
|
|
#define ID_AA64PFR0_EL0_SHIFT 0
|
|
|
|
|
|
|
|
#define ID_AA64PFR0_FP_NI 0xf
|
|
|
|
#define ID_AA64PFR0_FP_SUPPORTED 0x0
|
|
|
|
#define ID_AA64PFR0_ASIMD_NI 0xf
|
|
|
|
#define ID_AA64PFR0_ASIMD_SUPPORTED 0x0
|
|
|
|
#define ID_AA64PFR0_EL1_64BIT_ONLY 0x1
|
|
|
|
#define ID_AA64PFR0_EL0_64BIT_ONLY 0x1
|
2016-04-18 09:28:34 +00:00
|
|
|
#define ID_AA64PFR0_EL0_32BIT_64BIT 0x2
|
2015-10-19 13:24:45 +00:00
|
|
|
|
|
|
|
/* id_aa64mmfr0 */
|
|
|
|
#define ID_AA64MMFR0_TGRAN4_SHIFT 28
|
|
|
|
#define ID_AA64MMFR0_TGRAN64_SHIFT 24
|
|
|
|
#define ID_AA64MMFR0_TGRAN16_SHIFT 20
|
2015-10-19 13:24:42 +00:00
|
|
|
#define ID_AA64MMFR0_BIGENDEL0_SHIFT 16
|
2015-10-19 13:24:45 +00:00
|
|
|
#define ID_AA64MMFR0_SNSMEM_SHIFT 12
|
2015-10-19 13:24:42 +00:00
|
|
|
#define ID_AA64MMFR0_BIGENDEL_SHIFT 8
|
2015-10-19 13:24:45 +00:00
|
|
|
#define ID_AA64MMFR0_ASID_SHIFT 4
|
|
|
|
#define ID_AA64MMFR0_PARANGE_SHIFT 0
|
|
|
|
|
|
|
|
#define ID_AA64MMFR0_TGRAN4_NI 0xf
|
|
|
|
#define ID_AA64MMFR0_TGRAN4_SUPPORTED 0x0
|
|
|
|
#define ID_AA64MMFR0_TGRAN64_NI 0xf
|
|
|
|
#define ID_AA64MMFR0_TGRAN64_SUPPORTED 0x0
|
|
|
|
#define ID_AA64MMFR0_TGRAN16_NI 0x0
|
|
|
|
#define ID_AA64MMFR0_TGRAN16_SUPPORTED 0x1
|
|
|
|
|
|
|
|
/* id_aa64mmfr1 */
|
|
|
|
#define ID_AA64MMFR1_PAN_SHIFT 20
|
|
|
|
#define ID_AA64MMFR1_LOR_SHIFT 16
|
|
|
|
#define ID_AA64MMFR1_HPD_SHIFT 12
|
|
|
|
#define ID_AA64MMFR1_VHE_SHIFT 8
|
|
|
|
#define ID_AA64MMFR1_VMIDBITS_SHIFT 4
|
|
|
|
#define ID_AA64MMFR1_HADBS_SHIFT 0
|
|
|
|
|
2016-03-30 13:33:59 +00:00
|
|
|
#define ID_AA64MMFR1_VMIDBITS_8 0
|
|
|
|
#define ID_AA64MMFR1_VMIDBITS_16 2
|
|
|
|
|
2016-02-05 14:58:47 +00:00
|
|
|
/* id_aa64mmfr2 */
|
2016-03-25 09:30:07 +00:00
|
|
|
#define ID_AA64MMFR2_LVA_SHIFT 16
|
|
|
|
#define ID_AA64MMFR2_IESB_SHIFT 12
|
|
|
|
#define ID_AA64MMFR2_LSM_SHIFT 8
|
2016-02-05 14:58:47 +00:00
|
|
|
#define ID_AA64MMFR2_UAO_SHIFT 4
|
2016-03-25 09:30:07 +00:00
|
|
|
#define ID_AA64MMFR2_CNP_SHIFT 0
|
2016-02-05 14:58:47 +00:00
|
|
|
|
2015-10-19 13:24:45 +00:00
|
|
|
/* id_aa64dfr0 */
|
|
|
|
#define ID_AA64DFR0_CTX_CMPS_SHIFT 28
|
|
|
|
#define ID_AA64DFR0_WRPS_SHIFT 20
|
|
|
|
#define ID_AA64DFR0_BRPS_SHIFT 12
|
|
|
|
#define ID_AA64DFR0_PMUVER_SHIFT 8
|
|
|
|
#define ID_AA64DFR0_TRACEVER_SHIFT 4
|
|
|
|
#define ID_AA64DFR0_DEBUGVER_SHIFT 0
|
|
|
|
|
|
|
|
#define ID_ISAR5_RDM_SHIFT 24
|
|
|
|
#define ID_ISAR5_CRC32_SHIFT 16
|
|
|
|
#define ID_ISAR5_SHA2_SHIFT 12
|
|
|
|
#define ID_ISAR5_SHA1_SHIFT 8
|
|
|
|
#define ID_ISAR5_AES_SHIFT 4
|
|
|
|
#define ID_ISAR5_SEVL_SHIFT 0
|
|
|
|
|
|
|
|
#define MVFR0_FPROUND_SHIFT 28
|
|
|
|
#define MVFR0_FPSHVEC_SHIFT 24
|
|
|
|
#define MVFR0_FPSQRT_SHIFT 20
|
|
|
|
#define MVFR0_FPDIVIDE_SHIFT 16
|
|
|
|
#define MVFR0_FPTRAP_SHIFT 12
|
|
|
|
#define MVFR0_FPDP_SHIFT 8
|
|
|
|
#define MVFR0_FPSP_SHIFT 4
|
|
|
|
#define MVFR0_SIMD_SHIFT 0
|
|
|
|
|
|
|
|
#define MVFR1_SIMDFMAC_SHIFT 28
|
|
|
|
#define MVFR1_FPHP_SHIFT 24
|
|
|
|
#define MVFR1_SIMDHP_SHIFT 20
|
|
|
|
#define MVFR1_SIMDSP_SHIFT 16
|
|
|
|
#define MVFR1_SIMDINT_SHIFT 12
|
|
|
|
#define MVFR1_SIMDLS_SHIFT 8
|
|
|
|
#define MVFR1_FPDNAN_SHIFT 4
|
|
|
|
#define MVFR1_FPFTZ_SHIFT 0
|
|
|
|
|
2015-10-19 13:19:35 +00:00
|
|
|
|
|
|
|
#define ID_AA64MMFR0_TGRAN4_SHIFT 28
|
|
|
|
#define ID_AA64MMFR0_TGRAN64_SHIFT 24
|
|
|
|
#define ID_AA64MMFR0_TGRAN16_SHIFT 20
|
|
|
|
|
|
|
|
#define ID_AA64MMFR0_TGRAN4_NI 0xf
|
|
|
|
#define ID_AA64MMFR0_TGRAN4_SUPPORTED 0x0
|
|
|
|
#define ID_AA64MMFR0_TGRAN64_NI 0xf
|
|
|
|
#define ID_AA64MMFR0_TGRAN64_SUPPORTED 0x0
|
|
|
|
#define ID_AA64MMFR0_TGRAN16_NI 0x0
|
|
|
|
#define ID_AA64MMFR0_TGRAN16_SUPPORTED 0x1
|
|
|
|
|
|
|
|
#if defined(CONFIG_ARM64_4K_PAGES)
|
|
|
|
#define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN4_SHIFT
|
|
|
|
#define ID_AA64MMFR0_TGRAN_SUPPORTED ID_AA64MMFR0_TGRAN4_SUPPORTED
|
2015-10-19 13:19:37 +00:00
|
|
|
#elif defined(CONFIG_ARM64_16K_PAGES)
|
|
|
|
#define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN16_SHIFT
|
|
|
|
#define ID_AA64MMFR0_TGRAN_SUPPORTED ID_AA64MMFR0_TGRAN16_SUPPORTED
|
2015-10-19 13:19:35 +00:00
|
|
|
#elif defined(CONFIG_ARM64_64K_PAGES)
|
|
|
|
#define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN64_SHIFT
|
|
|
|
#define ID_AA64MMFR0_TGRAN_SUPPORTED ID_AA64MMFR0_TGRAN64_SUPPORTED
|
|
|
|
#endif
|
|
|
|
|
2014-07-24 13:14:42 +00:00
|
|
|
#ifdef __ASSEMBLY__
|
|
|
|
|
|
|
|
.irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
|
2016-02-15 08:51:49 +00:00
|
|
|
.equ .L__reg_num_x\num, \num
|
2014-07-24 13:14:42 +00:00
|
|
|
.endr
|
2016-02-15 08:51:49 +00:00
|
|
|
.equ .L__reg_num_xzr, 31
|
2014-07-24 13:14:42 +00:00
|
|
|
|
|
|
|
.macro mrs_s, rt, sreg
|
2016-02-15 08:51:49 +00:00
|
|
|
.inst 0xd5200000|(\sreg)|(.L__reg_num_\rt)
|
2014-07-24 13:14:42 +00:00
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro msr_s, sreg, rt
|
2016-02-15 08:51:49 +00:00
|
|
|
.inst 0xd5000000|(\sreg)|(.L__reg_num_\rt)
|
2014-07-24 13:14:42 +00:00
|
|
|
.endm
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2015-11-05 15:09:17 +00:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
2014-07-24 13:14:42 +00:00
|
|
|
asm(
|
|
|
|
" .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n"
|
2016-02-15 08:51:49 +00:00
|
|
|
" .equ .L__reg_num_x\\num, \\num\n"
|
2014-07-24 13:14:42 +00:00
|
|
|
" .endr\n"
|
2016-02-15 08:51:49 +00:00
|
|
|
" .equ .L__reg_num_xzr, 31\n"
|
2014-07-24 13:14:42 +00:00
|
|
|
"\n"
|
|
|
|
" .macro mrs_s, rt, sreg\n"
|
2016-02-15 08:51:49 +00:00
|
|
|
" .inst 0xd5200000|(\\sreg)|(.L__reg_num_\\rt)\n"
|
2014-07-24 13:14:42 +00:00
|
|
|
" .endm\n"
|
|
|
|
"\n"
|
|
|
|
" .macro msr_s, sreg, rt\n"
|
2016-02-15 08:51:49 +00:00
|
|
|
" .inst 0xd5000000|(\\sreg)|(.L__reg_num_\\rt)\n"
|
2014-07-24 13:14:42 +00:00
|
|
|
" .endm\n"
|
|
|
|
);
|
|
|
|
|
2015-11-05 15:09:17 +00:00
|
|
|
/*
|
|
|
|
* Unlike read_cpuid, calls to read_sysreg are never expected to be
|
|
|
|
* optimized away or replaced with synthetic values.
|
|
|
|
*/
|
|
|
|
#define read_sysreg(r) ({ \
|
|
|
|
u64 __val; \
|
|
|
|
asm volatile("mrs %0, " __stringify(r) : "=r" (__val)); \
|
|
|
|
__val; \
|
|
|
|
})
|
|
|
|
|
2016-09-08 12:55:34 +00:00
|
|
|
/*
|
|
|
|
* The "Z" constraint normally means a zero immediate, but when combined with
|
|
|
|
* the "%x0" template means XZR.
|
|
|
|
*/
|
2015-11-05 15:09:17 +00:00
|
|
|
#define write_sysreg(v, r) do { \
|
|
|
|
u64 __val = (u64)v; \
|
2016-09-08 12:55:34 +00:00
|
|
|
asm volatile("msr " __stringify(r) ", %x0" \
|
|
|
|
: : "rZ" (__val)); \
|
2015-11-05 15:09:17 +00:00
|
|
|
} while (0)
|
|
|
|
|
2016-09-06 13:04:45 +00:00
|
|
|
/*
|
|
|
|
* For registers without architectural names, or simply unsupported by
|
|
|
|
* GAS.
|
|
|
|
*/
|
|
|
|
#define read_sysreg_s(r) ({ \
|
|
|
|
u64 __val; \
|
|
|
|
asm volatile("mrs_s %0, " __stringify(r) : "=r" (__val)); \
|
|
|
|
__val; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define write_sysreg_s(v, r) do { \
|
|
|
|
u64 __val = (u64)v; \
|
2016-10-17 12:38:14 +00:00
|
|
|
asm volatile("msr_s " __stringify(r) ", %x0" : : "rZ" (__val)); \
|
2016-09-06 13:04:45 +00:00
|
|
|
} while (0)
|
|
|
|
|
2016-09-08 12:55:38 +00:00
|
|
|
static inline void config_sctlr_el1(u32 clear, u32 set)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = read_sysreg(sctlr_el1);
|
|
|
|
val &= ~clear;
|
|
|
|
val |= set;
|
|
|
|
write_sysreg(val, sctlr_el1);
|
|
|
|
}
|
|
|
|
|
2014-07-24 13:14:42 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __ASM_SYSREG_H */
|