Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 1 | /* |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 2 | * Blackfin CPLB exception handling for when MPU in on |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 3 | * |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 4 | * Copyright 2008-2009 Analog Devices Inc. |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 5 | * |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 6 | * Licensed under the GPL-2 or later. |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 7 | */ |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 8 | |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 9 | #include <linux/module.h> |
| 10 | #include <linux/mm.h> |
| 11 | |
| 12 | #include <asm/blackfin.h> |
Mike Frysinger | a92946b | 2008-10-16 23:25:34 +0800 | [diff] [blame] | 13 | #include <asm/cacheflush.h> |
Yi Li | eb7bd9c | 2009-08-07 01:20:58 +0000 | [diff] [blame] | 14 | #include <asm/cplb.h> |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 15 | #include <asm/cplbinit.h> |
| 16 | #include <asm/mmu_context.h> |
| 17 | |
Bernd Schmidt | dbdf20d | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 18 | /* |
| 19 | * WARNING |
| 20 | * |
| 21 | * This file is compiled with certain -ffixed-reg options. We have to |
| 22 | * make sure not to call any functions here that could clobber these |
| 23 | * registers. |
| 24 | */ |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 25 | |
| 26 | int page_mask_nelts; |
| 27 | int page_mask_order; |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 28 | unsigned long *current_rwx_mask[NR_CPUS]; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 29 | |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 30 | int nr_dcplb_miss[NR_CPUS], nr_icplb_miss[NR_CPUS]; |
| 31 | int nr_icplb_supv_miss[NR_CPUS], nr_dcplb_prot[NR_CPUS]; |
| 32 | int nr_cplb_flush[NR_CPUS]; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 33 | |
Barry Song | 726e965 | 2010-01-20 07:25:31 +0000 | [diff] [blame] | 34 | #ifdef CONFIG_EXCPT_IRQ_SYSC_L1 |
| 35 | #define MGR_ATTR __attribute__((l1_text)) |
| 36 | #else |
| 37 | #define MGR_ATTR |
| 38 | #endif |
| 39 | |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 40 | /* |
| 41 | * Given the contents of the status register, return the index of the |
| 42 | * CPLB that caused the fault. |
| 43 | */ |
| 44 | static inline int faulting_cplb_index(int status) |
| 45 | { |
| 46 | int signbits = __builtin_bfin_norm_fr1x32(status & 0xFFFF); |
| 47 | return 30 - signbits; |
| 48 | } |
| 49 | |
| 50 | /* |
| 51 | * Given the contents of the status register and the DCPLB_DATA contents, |
| 52 | * return true if a write access should be permitted. |
| 53 | */ |
| 54 | static inline int write_permitted(int status, unsigned long data) |
| 55 | { |
| 56 | if (status & FAULT_USERSUPV) |
| 57 | return !!(data & CPLB_SUPV_WR); |
| 58 | else |
| 59 | return !!(data & CPLB_USER_WR); |
| 60 | } |
| 61 | |
| 62 | /* Counters to implement round-robin replacement. */ |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 63 | static int icplb_rr_index[NR_CPUS], dcplb_rr_index[NR_CPUS]; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Find an ICPLB entry to be evicted and return its index. |
| 67 | */ |
Barry Song | 726e965 | 2010-01-20 07:25:31 +0000 | [diff] [blame] | 68 | MGR_ATTR static int evict_one_icplb(unsigned int cpu) |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 69 | { |
| 70 | int i; |
| 71 | for (i = first_switched_icplb; i < MAX_CPLBS; i++) |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 72 | if ((icplb_tbl[cpu][i].data & CPLB_VALID) == 0) |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 73 | return i; |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 74 | i = first_switched_icplb + icplb_rr_index[cpu]; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 75 | if (i >= MAX_CPLBS) { |
| 76 | i -= MAX_CPLBS - first_switched_icplb; |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 77 | icplb_rr_index[cpu] -= MAX_CPLBS - first_switched_icplb; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 78 | } |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 79 | icplb_rr_index[cpu]++; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 80 | return i; |
| 81 | } |
| 82 | |
Barry Song | 726e965 | 2010-01-20 07:25:31 +0000 | [diff] [blame] | 83 | MGR_ATTR static int evict_one_dcplb(unsigned int cpu) |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 84 | { |
| 85 | int i; |
| 86 | for (i = first_switched_dcplb; i < MAX_CPLBS; i++) |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 87 | if ((dcplb_tbl[cpu][i].data & CPLB_VALID) == 0) |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 88 | return i; |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 89 | i = first_switched_dcplb + dcplb_rr_index[cpu]; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 90 | if (i >= MAX_CPLBS) { |
| 91 | i -= MAX_CPLBS - first_switched_dcplb; |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 92 | dcplb_rr_index[cpu] -= MAX_CPLBS - first_switched_dcplb; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 93 | } |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 94 | dcplb_rr_index[cpu]++; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 95 | return i; |
| 96 | } |
| 97 | |
Barry Song | 726e965 | 2010-01-20 07:25:31 +0000 | [diff] [blame] | 98 | MGR_ATTR static noinline int dcplb_miss(unsigned int cpu) |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 99 | { |
| 100 | unsigned long addr = bfin_read_DCPLB_FAULT_ADDR(); |
| 101 | int status = bfin_read_DCPLB_STATUS(); |
| 102 | unsigned long *mask; |
| 103 | int idx; |
| 104 | unsigned long d_data; |
| 105 | |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 106 | nr_dcplb_miss[cpu]++; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 107 | |
| 108 | d_data = CPLB_SUPV_WR | CPLB_VALID | CPLB_DIRTY | PAGE_SIZE_4KB; |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 109 | #ifdef CONFIG_BFIN_EXTMEM_DCACHEABLE |
Jie Zhang | 67834fa | 2009-06-10 06:26:26 +0000 | [diff] [blame] | 110 | if (bfin_addr_dcacheable(addr)) { |
Bernd Schmidt | b4bb68f | 2008-04-23 07:26:23 +0800 | [diff] [blame] | 111 | d_data |= CPLB_L1_CHBL | ANOMALY_05000158_WORKAROUND; |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 112 | # ifdef CONFIG_BFIN_EXTMEM_WRITETHROUGH |
Bernd Schmidt | b4bb68f | 2008-04-23 07:26:23 +0800 | [diff] [blame] | 113 | d_data |= CPLB_L1_AOW | CPLB_WT; |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 114 | # endif |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 115 | } |
Bernd Schmidt | b4bb68f | 2008-04-23 07:26:23 +0800 | [diff] [blame] | 116 | #endif |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 117 | |
| 118 | if (L2_LENGTH && addr >= L2_START && addr < L2_START + L2_LENGTH) { |
| 119 | addr = L2_START; |
| 120 | d_data = L2_DMEMORY; |
| 121 | } else if (addr >= physical_mem_end) { |
Barry Song | e187837 | 2009-12-02 02:50:43 +0000 | [diff] [blame] | 122 | if (addr >= ASYNC_BANK0_BASE && addr < ASYNC_BANK3_BASE + ASYNC_BANK3_SIZE) { |
Barry Song | e18e7dd | 2009-12-07 10:05:58 +0000 | [diff] [blame] | 123 | mask = current_rwx_mask[cpu]; |
| 124 | if (mask) { |
| 125 | int page = (addr - (ASYNC_BANK0_BASE - _ramend)) >> PAGE_SHIFT; |
| 126 | int idx = page >> 5; |
| 127 | int bit = 1 << (page & 31); |
| 128 | |
| 129 | if (mask[idx] & bit) |
| 130 | d_data |= CPLB_USER_RD; |
| 131 | } |
Mike Frysinger | 4e354b5 | 2008-04-24 05:44:32 +0800 | [diff] [blame] | 132 | } else if (addr >= BOOT_ROM_START && addr < BOOT_ROM_START + BOOT_ROM_LENGTH |
| 133 | && (status & (FAULT_RW | FAULT_USERSUPV)) == FAULT_USERSUPV) { |
| 134 | addr &= ~(1 * 1024 * 1024 - 1); |
| 135 | d_data &= ~PAGE_SIZE_4KB; |
Mike Frysinger | 4bea8b2 | 2008-04-24 07:23:36 +0800 | [diff] [blame] | 136 | d_data |= PAGE_SIZE_1MB; |
Bernd Schmidt | b4bb68f | 2008-04-23 07:26:23 +0800 | [diff] [blame] | 137 | } else |
| 138 | return CPLB_PROT_VIOL; |
Bernd Schmidt | 1ebc723 | 2008-04-24 02:58:26 +0800 | [diff] [blame] | 139 | } else if (addr >= _ramend) { |
Sonic Zhang | 5792ab2 | 2009-12-09 07:01:50 +0000 | [diff] [blame] | 140 | d_data |= CPLB_USER_RD | CPLB_USER_WR; |
| 141 | if (reserved_mem_dcache_on) |
| 142 | d_data |= CPLB_L1_CHBL; |
Bernd Schmidt | b4bb68f | 2008-04-23 07:26:23 +0800 | [diff] [blame] | 143 | } else { |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 144 | mask = current_rwx_mask[cpu]; |
Bernd Schmidt | b4bb68f | 2008-04-23 07:26:23 +0800 | [diff] [blame] | 145 | if (mask) { |
| 146 | int page = addr >> PAGE_SHIFT; |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 147 | int idx = page >> 5; |
Bernd Schmidt | b4bb68f | 2008-04-23 07:26:23 +0800 | [diff] [blame] | 148 | int bit = 1 << (page & 31); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 149 | |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 150 | if (mask[idx] & bit) |
Bernd Schmidt | b4bb68f | 2008-04-23 07:26:23 +0800 | [diff] [blame] | 151 | d_data |= CPLB_USER_RD; |
| 152 | |
| 153 | mask += page_mask_nelts; |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 154 | if (mask[idx] & bit) |
Bernd Schmidt | b4bb68f | 2008-04-23 07:26:23 +0800 | [diff] [blame] | 155 | d_data |= CPLB_USER_WR; |
| 156 | } |
| 157 | } |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 158 | idx = evict_one_dcplb(cpu); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 159 | |
| 160 | addr &= PAGE_MASK; |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 161 | dcplb_tbl[cpu][idx].addr = addr; |
| 162 | dcplb_tbl[cpu][idx].data = d_data; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 163 | |
Yi Li | eb7bd9c | 2009-08-07 01:20:58 +0000 | [diff] [blame] | 164 | _disable_dcplb(); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 165 | bfin_write32(DCPLB_DATA0 + idx * 4, d_data); |
| 166 | bfin_write32(DCPLB_ADDR0 + idx * 4, addr); |
Yi Li | eb7bd9c | 2009-08-07 01:20:58 +0000 | [diff] [blame] | 167 | _enable_dcplb(); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
Barry Song | 726e965 | 2010-01-20 07:25:31 +0000 | [diff] [blame] | 172 | MGR_ATTR static noinline int icplb_miss(unsigned int cpu) |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 173 | { |
| 174 | unsigned long addr = bfin_read_ICPLB_FAULT_ADDR(); |
| 175 | int status = bfin_read_ICPLB_STATUS(); |
| 176 | int idx; |
| 177 | unsigned long i_data; |
| 178 | |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 179 | nr_icplb_miss[cpu]++; |
Bernd Schmidt | 1ebc723 | 2008-04-24 02:58:26 +0800 | [diff] [blame] | 180 | |
| 181 | /* If inside the uncached DMA region, fault. */ |
| 182 | if (addr >= _ramend - DMA_UNCACHED_REGION && addr < _ramend) |
| 183 | return CPLB_PROT_VIOL; |
| 184 | |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 185 | if (status & FAULT_USERSUPV) |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 186 | nr_icplb_supv_miss[cpu]++; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 187 | |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 188 | /* |
| 189 | * First, try to find a CPLB that matches this address. If we |
| 190 | * find one, then the fact that we're in the miss handler means |
| 191 | * that the instruction crosses a page boundary. |
| 192 | */ |
| 193 | for (idx = first_switched_icplb; idx < MAX_CPLBS; idx++) { |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 194 | if (icplb_tbl[cpu][idx].data & CPLB_VALID) { |
| 195 | unsigned long this_addr = icplb_tbl[cpu][idx].addr; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 196 | if (this_addr <= addr && this_addr + PAGE_SIZE > addr) { |
| 197 | addr += PAGE_SIZE; |
| 198 | break; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | i_data = CPLB_VALID | CPLB_PORTPRIO | PAGE_SIZE_4KB; |
Bernd Schmidt | 1ebc723 | 2008-04-24 02:58:26 +0800 | [diff] [blame] | 204 | |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 205 | #ifdef CONFIG_BFIN_EXTMEM_ICACHEABLE |
Bernd Schmidt | 1ebc723 | 2008-04-24 02:58:26 +0800 | [diff] [blame] | 206 | /* |
| 207 | * Normal RAM, and possibly the reserved memory area, are |
| 208 | * cacheable. |
| 209 | */ |
| 210 | if (addr < _ramend || |
| 211 | (addr < physical_mem_end && reserved_mem_icache_on)) |
| 212 | i_data |= CPLB_L1_CHBL | ANOMALY_05000158_WORKAROUND; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 213 | #endif |
| 214 | |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 215 | if (L2_LENGTH && addr >= L2_START && addr < L2_START + L2_LENGTH) { |
| 216 | addr = L2_START; |
| 217 | i_data = L2_IMEMORY; |
| 218 | } else if (addr >= physical_mem_end) { |
Barry Song | e187837 | 2009-12-02 02:50:43 +0000 | [diff] [blame] | 219 | if (addr >= ASYNC_BANK0_BASE && addr < ASYNC_BANK3_BASE + ASYNC_BANK3_SIZE) { |
Barry Song | e18e7dd | 2009-12-07 10:05:58 +0000 | [diff] [blame] | 220 | if (!(status & FAULT_USERSUPV)) { |
| 221 | unsigned long *mask = current_rwx_mask[cpu]; |
| 222 | |
| 223 | if (mask) { |
| 224 | int page = (addr - (ASYNC_BANK0_BASE - _ramend)) >> PAGE_SHIFT; |
| 225 | int idx = page >> 5; |
| 226 | int bit = 1 << (page & 31); |
| 227 | |
| 228 | mask += 2 * page_mask_nelts; |
| 229 | if (mask[idx] & bit) |
| 230 | i_data |= CPLB_USER_RD; |
| 231 | } |
| 232 | } |
Barry Song | e187837 | 2009-12-02 02:50:43 +0000 | [diff] [blame] | 233 | } else if (addr >= BOOT_ROM_START && addr < BOOT_ROM_START + BOOT_ROM_LENGTH |
Mike Frysinger | 4bea8b2 | 2008-04-24 07:23:36 +0800 | [diff] [blame] | 234 | && (status & FAULT_USERSUPV)) { |
| 235 | addr &= ~(1 * 1024 * 1024 - 1); |
| 236 | i_data &= ~PAGE_SIZE_4KB; |
| 237 | i_data |= PAGE_SIZE_1MB; |
| 238 | } else |
| 239 | return CPLB_PROT_VIOL; |
Bernd Schmidt | 1ebc723 | 2008-04-24 02:58:26 +0800 | [diff] [blame] | 240 | } else if (addr >= _ramend) { |
| 241 | i_data |= CPLB_USER_RD; |
Sonic Zhang | 5792ab2 | 2009-12-09 07:01:50 +0000 | [diff] [blame] | 242 | if (reserved_mem_icache_on) |
| 243 | i_data |= CPLB_L1_CHBL; |
Bernd Schmidt | 1ebc723 | 2008-04-24 02:58:26 +0800 | [diff] [blame] | 244 | } else { |
| 245 | /* |
| 246 | * Two cases to distinguish - a supervisor access must |
| 247 | * necessarily be for a module page; we grant it |
| 248 | * unconditionally (could do better here in the future). |
| 249 | * Otherwise, check the x bitmap of the current process. |
| 250 | */ |
| 251 | if (!(status & FAULT_USERSUPV)) { |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 252 | unsigned long *mask = current_rwx_mask[cpu]; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 253 | |
Bernd Schmidt | 1ebc723 | 2008-04-24 02:58:26 +0800 | [diff] [blame] | 254 | if (mask) { |
| 255 | int page = addr >> PAGE_SHIFT; |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 256 | int idx = page >> 5; |
Bernd Schmidt | 1ebc723 | 2008-04-24 02:58:26 +0800 | [diff] [blame] | 257 | int bit = 1 << (page & 31); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 258 | |
Bernd Schmidt | 1ebc723 | 2008-04-24 02:58:26 +0800 | [diff] [blame] | 259 | mask += 2 * page_mask_nelts; |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 260 | if (mask[idx] & bit) |
Bernd Schmidt | 1ebc723 | 2008-04-24 02:58:26 +0800 | [diff] [blame] | 261 | i_data |= CPLB_USER_RD; |
| 262 | } |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 263 | } |
| 264 | } |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 265 | idx = evict_one_icplb(cpu); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 266 | addr &= PAGE_MASK; |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 267 | icplb_tbl[cpu][idx].addr = addr; |
| 268 | icplb_tbl[cpu][idx].data = i_data; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 269 | |
Yi Li | eb7bd9c | 2009-08-07 01:20:58 +0000 | [diff] [blame] | 270 | _disable_icplb(); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 271 | bfin_write32(ICPLB_DATA0 + idx * 4, i_data); |
| 272 | bfin_write32(ICPLB_ADDR0 + idx * 4, addr); |
Yi Li | eb7bd9c | 2009-08-07 01:20:58 +0000 | [diff] [blame] | 273 | _enable_icplb(); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
Barry Song | 726e965 | 2010-01-20 07:25:31 +0000 | [diff] [blame] | 278 | MGR_ATTR static noinline int dcplb_protection_fault(unsigned int cpu) |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 279 | { |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 280 | int status = bfin_read_DCPLB_STATUS(); |
| 281 | |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 282 | nr_dcplb_prot[cpu]++; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 283 | |
| 284 | if (status & FAULT_RW) { |
| 285 | int idx = faulting_cplb_index(status); |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 286 | unsigned long data = dcplb_tbl[cpu][idx].data; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 287 | if (!(data & CPLB_WT) && !(data & CPLB_DIRTY) && |
| 288 | write_permitted(status, data)) { |
| 289 | data |= CPLB_DIRTY; |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 290 | dcplb_tbl[cpu][idx].data = data; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 291 | bfin_write32(DCPLB_DATA0 + idx * 4, data); |
| 292 | return 0; |
| 293 | } |
| 294 | } |
| 295 | return CPLB_PROT_VIOL; |
| 296 | } |
| 297 | |
Barry Song | 726e965 | 2010-01-20 07:25:31 +0000 | [diff] [blame] | 298 | MGR_ATTR int cplb_hdr(int seqstat, struct pt_regs *regs) |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 299 | { |
| 300 | int cause = seqstat & 0x3f; |
Yi Li | b6dbde2 | 2009-08-20 04:17:47 +0000 | [diff] [blame] | 301 | unsigned int cpu = raw_smp_processor_id(); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 302 | switch (cause) { |
| 303 | case 0x23: |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 304 | return dcplb_protection_fault(cpu); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 305 | case 0x2C: |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 306 | return icplb_miss(cpu); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 307 | case 0x26: |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 308 | return dcplb_miss(cpu); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 309 | default: |
Bernd Schmidt | b4bb68f | 2008-04-23 07:26:23 +0800 | [diff] [blame] | 310 | return 1; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 314 | void flush_switched_cplbs(unsigned int cpu) |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 315 | { |
| 316 | int i; |
Bernd Schmidt | 5d2e321 | 2008-10-07 16:27:01 +0800 | [diff] [blame] | 317 | unsigned long flags; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 318 | |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 319 | nr_cplb_flush[cpu]++; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 320 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame] | 321 | flags = hard_local_irq_save(); |
Yi Li | eb7bd9c | 2009-08-07 01:20:58 +0000 | [diff] [blame] | 322 | _disable_icplb(); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 323 | for (i = first_switched_icplb; i < MAX_CPLBS; i++) { |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 324 | icplb_tbl[cpu][i].data = 0; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 325 | bfin_write32(ICPLB_DATA0 + i * 4, 0); |
| 326 | } |
Yi Li | eb7bd9c | 2009-08-07 01:20:58 +0000 | [diff] [blame] | 327 | _enable_icplb(); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 328 | |
Yi Li | eb7bd9c | 2009-08-07 01:20:58 +0000 | [diff] [blame] | 329 | _disable_dcplb(); |
Bernd Schmidt | d56daae | 2008-04-24 02:56:36 +0800 | [diff] [blame] | 330 | for (i = first_switched_dcplb; i < MAX_CPLBS; i++) { |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 331 | dcplb_tbl[cpu][i].data = 0; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 332 | bfin_write32(DCPLB_DATA0 + i * 4, 0); |
| 333 | } |
Yi Li | eb7bd9c | 2009-08-07 01:20:58 +0000 | [diff] [blame] | 334 | _enable_dcplb(); |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame] | 335 | hard_local_irq_restore(flags); |
Bernd Schmidt | 5d2e321 | 2008-10-07 16:27:01 +0800 | [diff] [blame] | 336 | |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 337 | } |
| 338 | |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 339 | void set_mask_dcplbs(unsigned long *masks, unsigned int cpu) |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 340 | { |
| 341 | int i; |
| 342 | unsigned long addr = (unsigned long)masks; |
| 343 | unsigned long d_data; |
Bernd Schmidt | 5d2e321 | 2008-10-07 16:27:01 +0800 | [diff] [blame] | 344 | unsigned long flags; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 345 | |
Bernd Schmidt | 5d2e321 | 2008-10-07 16:27:01 +0800 | [diff] [blame] | 346 | if (!masks) { |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 347 | current_rwx_mask[cpu] = masks; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 348 | return; |
Bernd Schmidt | 5d2e321 | 2008-10-07 16:27:01 +0800 | [diff] [blame] | 349 | } |
| 350 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame] | 351 | flags = hard_local_irq_save(); |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 352 | current_rwx_mask[cpu] = masks; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 353 | |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 354 | if (L2_LENGTH && addr >= L2_START && addr < L2_START + L2_LENGTH) { |
| 355 | addr = L2_START; |
| 356 | d_data = L2_DMEMORY; |
| 357 | } else { |
| 358 | d_data = CPLB_SUPV_WR | CPLB_VALID | CPLB_DIRTY | PAGE_SIZE_4KB; |
| 359 | #ifdef CONFIG_BFIN_EXTMEM_DCACHEABLE |
| 360 | d_data |= CPLB_L1_CHBL; |
| 361 | # ifdef CONFIG_BFIN_EXTMEM_WRITETHROUGH |
| 362 | d_data |= CPLB_L1_AOW | CPLB_WT; |
| 363 | # endif |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 364 | #endif |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 365 | } |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 366 | |
Yi Li | eb7bd9c | 2009-08-07 01:20:58 +0000 | [diff] [blame] | 367 | _disable_dcplb(); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 368 | for (i = first_mask_dcplb; i < first_switched_dcplb; i++) { |
Graf Yang | b8a9898 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 369 | dcplb_tbl[cpu][i].addr = addr; |
| 370 | dcplb_tbl[cpu][i].data = d_data; |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 371 | bfin_write32(DCPLB_DATA0 + i * 4, d_data); |
| 372 | bfin_write32(DCPLB_ADDR0 + i * 4, addr); |
| 373 | addr += PAGE_SIZE; |
| 374 | } |
Yi Li | eb7bd9c | 2009-08-07 01:20:58 +0000 | [diff] [blame] | 375 | _enable_dcplb(); |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame] | 376 | hard_local_irq_restore(flags); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 377 | } |