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