|
40 | 40 | #define L1_CACHE_SHIFT (6) |
41 | 41 | #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) |
42 | 42 |
|
| 43 | + |
| 44 | +#define CLIDR_LOUU_SHIFT 27 |
| 45 | +#define CLIDR_LOC_SHIFT 24 |
| 46 | +#define CLIDR_LOUIS_SHIFT 21 |
| 47 | + |
| 48 | +#define CLIDR_LOUU(clidr) (((clidr) >> CLIDR_LOUU_SHIFT) & 0x7) |
| 49 | +#define CLIDR_LOC(clidr) (((clidr) >> CLIDR_LOC_SHIFT) & 0x7) |
| 50 | +#define CLIDR_LOUIS(clidr) (((clidr) >> CLIDR_LOUIS_SHIFT) & 0x7) |
| 51 | + |
43 | 52 | /* |
44 | 53 | * Memory returned by kmalloc() may be used for DMA, so we must make |
45 | 54 | * sure that all such allocations are cache aligned. Otherwise, |
@@ -84,6 +93,37 @@ static inline int cache_line_size(void) |
84 | 93 | return cwg ? 4 << cwg : ARCH_DMA_MINALIGN; |
85 | 94 | } |
86 | 95 |
|
| 96 | +/* |
| 97 | + * Read the effective value of CTR_EL0. |
| 98 | + * |
| 99 | + * According to ARM ARM for ARMv8-A (ARM DDI 0487C.a), |
| 100 | + * section D10.2.33 "CTR_EL0, Cache Type Register" : |
| 101 | + * |
| 102 | + * CTR_EL0.IDC reports the data cache clean requirements for |
| 103 | + * instruction to data coherence. |
| 104 | + * |
| 105 | + * 0 - dcache clean to PoU is required unless : |
| 106 | + * (CLIDR_EL1.LoC == 0) || (CLIDR_EL1.LoUIS == 0 && CLIDR_EL1.LoUU == 0) |
| 107 | + * 1 - dcache clean to PoU is not required for i-to-d coherence. |
| 108 | + * |
| 109 | + * This routine provides the CTR_EL0 with the IDC field updated to the |
| 110 | + * effective state. |
| 111 | + */ |
| 112 | +static inline u32 __attribute_const__ read_cpuid_effective_cachetype(void) |
| 113 | +{ |
| 114 | + u32 ctr = read_cpuid_cachetype(); |
| 115 | + |
| 116 | + if (!(ctr & BIT(CTR_IDC_SHIFT))) { |
| 117 | + u64 clidr = read_sysreg(clidr_el1); |
| 118 | + |
| 119 | + if (CLIDR_LOC(clidr) == 0 || |
| 120 | + (CLIDR_LOUIS(clidr) == 0 && CLIDR_LOUU(clidr) == 0)) |
| 121 | + ctr |= BIT(CTR_IDC_SHIFT); |
| 122 | + } |
| 123 | + |
| 124 | + return ctr; |
| 125 | +} |
| 126 | + |
87 | 127 | #endif /* __ASSEMBLY__ */ |
88 | 128 |
|
89 | 129 | #endif |
0 commit comments