blob: efc515eb3348c902844d165f42f12e6c55ce177e [file] [log] [blame]
Aneesh V960f5c02011-06-16 23:30:47 +00001/*
2 * (C) Copyright 2010
3 * Texas Instruments, <www.ti.com>
4 * Aneesh V <aneesh@ti.com>
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Aneesh V960f5c02011-06-16 23:30:47 +00007 */
8#ifndef ARMV7_H
9#define ARMV7_H
Aneesh V960f5c02011-06-16 23:30:47 +000010
Aneesh V162ced32011-07-21 09:10:04 -040011/* Cortex-A9 revisions */
12#define MIDR_CORTEX_A9_R0P1 0x410FC091
13#define MIDR_CORTEX_A9_R1P2 0x411FC092
14#define MIDR_CORTEX_A9_R1P3 0x411FC093
Aneesh V0b92f092011-07-21 09:29:23 -040015#define MIDR_CORTEX_A9_R2P10 0x412FC09A
Aneesh V162ced32011-07-21 09:10:04 -040016
Sricharan9310ff72011-11-15 09:49:55 -050017/* Cortex-A15 revisions */
18#define MIDR_CORTEX_A15_R0P0 0x410FC0F0
SRICHARAN Rcf850562013-02-12 01:33:41 +000019#define MIDR_CORTEX_A15_R2P2 0x412FC0F2
Sricharan9310ff72011-11-15 09:49:55 -050020
Andre Przywaradd5e8da2013-09-19 18:06:41 +020021/* Cortex-A7 revisions */
22#define MIDR_CORTEX_A7_R0P0 0x410FC070
23
24#define MIDR_PRIMARY_PART_MASK 0xFF0FFFF0
25
26/* ID_PFR1 feature fields */
27#define CPUID_ARM_SEC_SHIFT 4
28#define CPUID_ARM_SEC_MASK (0xF << CPUID_ARM_SEC_SHIFT)
29#define CPUID_ARM_VIRT_SHIFT 12
30#define CPUID_ARM_VIRT_MASK (0xF << CPUID_ARM_VIRT_SHIFT)
31#define CPUID_ARM_GENTIMER_SHIFT 16
32#define CPUID_ARM_GENTIMER_MASK (0xF << CPUID_ARM_GENTIMER_SHIFT)
33
34/* valid bits in CBAR register / PERIPHBASE value */
35#define CBAR_MASK 0xFFFF8000
36
Aneesh V960f5c02011-06-16 23:30:47 +000037/* CCSIDR */
38#define CCSIDR_LINE_SIZE_OFFSET 0
39#define CCSIDR_LINE_SIZE_MASK 0x7
40#define CCSIDR_ASSOCIATIVITY_OFFSET 3
41#define CCSIDR_ASSOCIATIVITY_MASK (0x3FF << 3)
42#define CCSIDR_NUM_SETS_OFFSET 13
43#define CCSIDR_NUM_SETS_MASK (0x7FFF << 13)
44
45/*
46 * Values for InD field in CSSELR
47 * Selects the type of cache
48 */
49#define ARMV7_CSSELR_IND_DATA_UNIFIED 0
50#define ARMV7_CSSELR_IND_INSTRUCTION 1
51
52/* Values for Ctype fields in CLIDR */
53#define ARMV7_CLIDR_CTYPE_NO_CACHE 0
54#define ARMV7_CLIDR_CTYPE_INSTRUCTION_ONLY 1
55#define ARMV7_CLIDR_CTYPE_DATA_ONLY 2
56#define ARMV7_CLIDR_CTYPE_INSTRUCTION_DATA 3
57#define ARMV7_CLIDR_CTYPE_UNIFIED 4
58
Andre Przywaraa6bb6682013-09-19 18:06:39 +020059#ifndef __ASSEMBLY__
60#include <linux/types.h>
Tom Rinie9689732015-03-02 08:24:45 -050061#include <asm/io.h>
Andre Przywarae996bc62016-05-12 12:14:41 +010062#include <asm/barriers.h>
Valentine Barshak689bfa22015-03-20 18:16:17 +030063
Jagan Teki71d71fe2017-09-27 23:03:10 +053064/* read L2 control register (L2CTLR) */
65static inline uint32_t read_l2ctlr(void)
66{
67 uint32_t val = 0;
68
69 asm volatile ("mrc p15, 1, %0, c9, c0, 2" : "=r" (val));
70
71 return val;
72}
73
74/* write L2 control register (L2CTLR) */
75static inline void write_l2ctlr(uint32_t val)
76{
77 /*
78 * Note: L2CTLR can only be written when the L2 memory system
79 * is idle, ie before the MMU is enabled.
80 */
81 asm volatile("mcr p15, 1, %0, c9, c0, 2" : : "r" (val) : "memory");
82 isb();
83}
84
Akshay Saraswate5be4132015-02-20 13:27:13 +053085/*
86 * Workaround for ARM errata # 798870
87 * Set L2ACTLR[7] to reissue any memory transaction in the L2 that has been
88 * stalled for 1024 cycles to verify that its hazard condition still exists.
89 */
90static inline void v7_enable_l2_hazard_detect(void)
91{
92 uint32_t val;
93
94 /* L2ACTLR[7]: Enable hazard detect timeout */
95 asm volatile ("mrc p15, 1, %0, c15, c0, 0\n\t" : "=r"(val));
96 val |= (1 << 7);
97 asm volatile ("mcr p15, 1, %0, c15, c0, 0\n\t" : : "r"(val));
98}
99
Akshay Saraswat57fd6392015-02-20 13:27:14 +0530100/*
101 * Workaround for ARM errata # 799270
102 * Ensure that the L2 logic has been used within the previous 256 cycles
103 * before modifying the ACTLR.SMP bit. This is required during boot before
104 * MMU has been enabled, or during a specified reset or power down sequence.
105 */
106static inline void v7_enable_smp(uint32_t address)
107{
108 uint32_t temp, val;
109
110 /* Read auxiliary control register */
111 asm volatile ("mrc p15, 0, %0, c1, c0, 1\n\t" : "=r"(val));
112
113 /* Enable SMP */
114 val |= (1 << 6);
115
116 /* Dummy read to assure L2 access */
117 temp = readl(address);
118 temp &= 0;
119 val |= temp;
120
121 /* Write auxiliary control register */
122 asm volatile ("mcr p15, 0, %0, c1, c0, 1\n\t" : : "r"(val));
123
124 CP15DSB;
125 CP15ISB;
126}
127
Akshay Saraswate5be4132015-02-20 13:27:13 +0530128void v7_en_l2_hazard_detect(void);
Aneesh V960f5c02011-06-16 23:30:47 +0000129void v7_outer_cache_enable(void);
130void v7_outer_cache_disable(void);
131void v7_outer_cache_flush_all(void);
132void v7_outer_cache_inval_all(void);
133void v7_outer_cache_flush_range(u32 start, u32 end);
134void v7_outer_cache_inval_range(u32 start, u32 end);
135
Jan Kiszkaac31b5a2015-04-21 07:18:24 +0200136#ifdef CONFIG_ARMV7_NONSEC
Andre Przywaraad5ad742013-09-19 18:06:42 +0200137
Marc Zyngier855ca662014-07-12 14:24:03 +0100138int armv7_init_nonsec(void);
Jan Kiszkacb334402015-04-21 07:18:32 +0200139int armv7_apply_memory_carveout(u64 *start, u64 *size);
Ian Campbell68bc8f52014-12-21 09:45:11 +0000140bool armv7_boot_nonsec(void);
Andre Przywaraad5ad742013-09-19 18:06:42 +0200141
Andre Przywaradd5e8da2013-09-19 18:06:41 +0200142/* defined in assembly file */
143unsigned int _nonsec_init(void);
Marc Zyngier855ca662014-07-12 14:24:03 +0100144void _do_nonsec_entry(void *target_pc, unsigned long r0,
145 unsigned long r1, unsigned long r2);
Andre Przywaradbbe1962013-09-19 18:06:44 +0200146void _smp_pen(void);
Marc Zyngier855ca662014-07-12 14:24:03 +0100147
148extern char __secure_start[];
149extern char __secure_end[];
Chen-Yu Tsaia00f85d2016-06-19 12:38:36 +0800150extern char __secure_stack_start[];
151extern char __secure_stack_end[];
Marc Zyngier855ca662014-07-12 14:24:03 +0100152
Jan Kiszkaac31b5a2015-04-21 07:18:24 +0200153#endif /* CONFIG_ARMV7_NONSEC */
Andre Przywaradd5e8da2013-09-19 18:06:41 +0200154
Nishanth Menonaa0294e2015-03-09 17:11:59 -0500155void v7_arch_cp15_set_l2aux_ctrl(u32 l2auxctrl, u32 cpu_midr,
156 u32 cpu_rev_comb, u32 cpu_variant,
157 u32 cpu_rev);
Nishanth Menon071d6ce2015-03-09 17:12:00 -0500158void v7_arch_cp15_set_acr(u32 acr, u32 cpu_midr, u32 cpu_rev_comb,
159 u32 cpu_variant, u32 cpu_rev);
Andre Przywaraa6bb6682013-09-19 18:06:39 +0200160#endif /* ! __ASSEMBLY__ */
161
Aneesh V960f5c02011-06-16 23:30:47 +0000162#endif