Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: Add and use watch register field definitions

The files watch.c and ptrace.c contain various magic masks for
WatchLo/WatchHi register fields. Add some definitions to mipsregs.h for
these registers and make use of them in both watch.c and ptrace.c,
hopefully making them more readable.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Reviewed-by: David Daney <david.daney@cavium.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/12729/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

James Hogan and committed by
Ralf Baechle
50af501c e233c733

+63 -36
+18
arch/mips/include/asm/mipsregs.h
··· 648 648 /* FTLB probability bits for R6 */ 649 649 #define MIPS_CONF7_FTLBP_SHIFT (18) 650 650 651 + /* WatchLo* register definitions */ 652 + #define MIPS_WATCHLO_IRW (_ULCAST_(0x7) << 0) 653 + 654 + /* WatchHi* register definitions */ 655 + #define MIPS_WATCHHI_M (_ULCAST_(1) << 31) 656 + #define MIPS_WATCHHI_G (_ULCAST_(1) << 30) 657 + #define MIPS_WATCHHI_WM (_ULCAST_(0x3) << 28) 658 + #define MIPS_WATCHHI_WM_R_RVA (_ULCAST_(0) << 28) 659 + #define MIPS_WATCHHI_WM_R_GPA (_ULCAST_(1) << 28) 660 + #define MIPS_WATCHHI_WM_G_GVA (_ULCAST_(2) << 28) 661 + #define MIPS_WATCHHI_EAS (_ULCAST_(0x3) << 24) 662 + #define MIPS_WATCHHI_ASID (_ULCAST_(0xff) << 16) 663 + #define MIPS_WATCHHI_MASK (_ULCAST_(0x1ff) << 3) 664 + #define MIPS_WATCHHI_I (_ULCAST_(1) << 2) 665 + #define MIPS_WATCHHI_R (_ULCAST_(1) << 1) 666 + #define MIPS_WATCHHI_W (_ULCAST_(1) << 0) 667 + #define MIPS_WATCHHI_IRW (_ULCAST_(0x7) << 0) 668 + 651 669 /* MAAR bit definitions */ 652 670 #define MIPS_MAAR_ADDR ((BIT_ULL(BITS_PER_LONG - 12) - 1) << 12) 653 671 #define MIPS_MAAR_ADDR_SHIFT 12
+4 -3
arch/mips/kernel/ptrace.c
··· 210 210 for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) { 211 211 __put_user(child->thread.watch.mips3264.watchlo[i], 212 212 &addr->WATCH_STYLE.watchlo[i]); 213 - __put_user(child->thread.watch.mips3264.watchhi[i] & 0xfff, 213 + __put_user(child->thread.watch.mips3264.watchhi[i] & 214 + (MIPS_WATCHHI_MASK | MIPS_WATCHHI_IRW), 214 215 &addr->WATCH_STYLE.watchhi[i]); 215 216 __put_user(boot_cpu_data.watch_reg_masks[i], 216 217 &addr->WATCH_STYLE.watch_masks[i]); ··· 253 252 } 254 253 #endif 255 254 __get_user(ht[i], &addr->WATCH_STYLE.watchhi[i]); 256 - if (ht[i] & ~0xff8) 255 + if (ht[i] & ~MIPS_WATCHHI_MASK) 257 256 return -EINVAL; 258 257 } 259 258 /* Install them. */ 260 259 for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) { 261 - if (lt[i] & 7) 260 + if (lt[i] & MIPS_WATCHLO_IRW) 262 261 watch_active = 1; 263 262 child->thread.watch.mips3264.watchlo[i] = lt[i]; 264 263 /* Set the G bit. */
+41 -33
arch/mips/kernel/watch.c
··· 25 25 write_c0_watchlo3(watches->watchlo[3]); 26 26 /* Write 1 to the I, R, and W bits to clear them, and 27 27 1 to G so all ASIDs are trapped. */ 28 - write_c0_watchhi3(0x40000007 | watches->watchhi[3]); 28 + write_c0_watchhi3(MIPS_WATCHHI_G | MIPS_WATCHHI_IRW | 29 + watches->watchhi[3]); 29 30 case 3: 30 31 write_c0_watchlo2(watches->watchlo[2]); 31 - write_c0_watchhi2(0x40000007 | watches->watchhi[2]); 32 + write_c0_watchhi2(MIPS_WATCHHI_G | MIPS_WATCHHI_IRW | 33 + watches->watchhi[2]); 32 34 case 2: 33 35 write_c0_watchlo1(watches->watchlo[1]); 34 - write_c0_watchhi1(0x40000007 | watches->watchhi[1]); 36 + write_c0_watchhi1(MIPS_WATCHHI_G | MIPS_WATCHHI_IRW | 37 + watches->watchhi[1]); 35 38 case 1: 36 39 write_c0_watchlo0(watches->watchlo[0]); 37 - write_c0_watchhi0(0x40000007 | watches->watchhi[0]); 40 + write_c0_watchhi0(MIPS_WATCHHI_G | MIPS_WATCHHI_IRW | 41 + watches->watchhi[0]); 38 42 } 39 43 } 40 44 ··· 55 51 default: 56 52 BUG(); 57 53 case 4: 58 - watches->watchhi[3] = (read_c0_watchhi3() & 0x0fff); 54 + watches->watchhi[3] = (read_c0_watchhi3() & 55 + (MIPS_WATCHHI_MASK | MIPS_WATCHHI_IRW)); 59 56 case 3: 60 - watches->watchhi[2] = (read_c0_watchhi2() & 0x0fff); 57 + watches->watchhi[2] = (read_c0_watchhi2() & 58 + (MIPS_WATCHHI_MASK | MIPS_WATCHHI_IRW)); 61 59 case 2: 62 - watches->watchhi[1] = (read_c0_watchhi1() & 0x0fff); 60 + watches->watchhi[1] = (read_c0_watchhi1() & 61 + (MIPS_WATCHHI_MASK | MIPS_WATCHHI_IRW)); 63 62 case 1: 64 - watches->watchhi[0] = (read_c0_watchhi0() & 0x0fff); 63 + watches->watchhi[0] = (read_c0_watchhi0() & 64 + (MIPS_WATCHHI_MASK | MIPS_WATCHHI_IRW)); 65 65 } 66 66 if (current_cpu_data.watch_reg_use_cnt == 1 && 67 - (watches->watchhi[0] & 7) == 0) { 67 + (watches->watchhi[0] & MIPS_WATCHHI_IRW) == 0) { 68 68 /* Pathological case of release 1 architecture that 69 69 * doesn't set the condition bits. We assume that 70 70 * since we got here, the watch condition was met and 71 71 * signal that the conditions requested in watchlo 72 72 * were met. */ 73 - watches->watchhi[0] |= (watches->watchlo[0] & 7); 73 + watches->watchhi[0] |= (watches->watchlo[0] & MIPS_WATCHHI_IRW); 74 74 } 75 75 } 76 76 ··· 117 109 * Check which of the I,R and W bits are supported, then 118 110 * disable the register. 119 111 */ 120 - write_c0_watchlo0(7); 112 + write_c0_watchlo0(MIPS_WATCHLO_IRW); 121 113 back_to_back_c0_hazard(); 122 114 t = read_c0_watchlo0(); 123 115 write_c0_watchlo0(0); 124 - c->watch_reg_masks[0] = t & 7; 116 + c->watch_reg_masks[0] = t & MIPS_WATCHLO_IRW; 125 117 126 118 /* Write the mask bits and read them back to determine which 127 119 * can be used. */ 128 120 c->watch_reg_count = 1; 129 121 c->watch_reg_use_cnt = 1; 130 122 t = read_c0_watchhi0(); 131 - write_c0_watchhi0(t | 0xff8); 123 + write_c0_watchhi0(t | MIPS_WATCHHI_MASK); 132 124 back_to_back_c0_hazard(); 133 125 t = read_c0_watchhi0(); 134 - c->watch_reg_masks[0] |= (t & 0xff8); 135 - if ((t & 0x80000000) == 0) 126 + c->watch_reg_masks[0] |= (t & MIPS_WATCHHI_MASK); 127 + if ((t & MIPS_WATCHHI_M) == 0) 136 128 return; 137 129 138 - write_c0_watchlo1(7); 130 + write_c0_watchlo1(MIPS_WATCHLO_IRW); 139 131 back_to_back_c0_hazard(); 140 132 t = read_c0_watchlo1(); 141 133 write_c0_watchlo1(0); 142 - c->watch_reg_masks[1] = t & 7; 134 + c->watch_reg_masks[1] = t & MIPS_WATCHLO_IRW; 143 135 144 136 c->watch_reg_count = 2; 145 137 c->watch_reg_use_cnt = 2; 146 138 t = read_c0_watchhi1(); 147 - write_c0_watchhi1(t | 0xff8); 139 + write_c0_watchhi1(t | MIPS_WATCHHI_MASK); 148 140 back_to_back_c0_hazard(); 149 141 t = read_c0_watchhi1(); 150 - c->watch_reg_masks[1] |= (t & 0xff8); 151 - if ((t & 0x80000000) == 0) 142 + c->watch_reg_masks[1] |= (t & MIPS_WATCHHI_MASK); 143 + if ((t & MIPS_WATCHHI_M) == 0) 152 144 return; 153 145 154 - write_c0_watchlo2(7); 146 + write_c0_watchlo2(MIPS_WATCHLO_IRW); 155 147 back_to_back_c0_hazard(); 156 148 t = read_c0_watchlo2(); 157 149 write_c0_watchlo2(0); 158 - c->watch_reg_masks[2] = t & 7; 150 + c->watch_reg_masks[2] = t & MIPS_WATCHLO_IRW; 159 151 160 152 c->watch_reg_count = 3; 161 153 c->watch_reg_use_cnt = 3; 162 154 t = read_c0_watchhi2(); 163 - write_c0_watchhi2(t | 0xff8); 155 + write_c0_watchhi2(t | MIPS_WATCHHI_MASK); 164 156 back_to_back_c0_hazard(); 165 157 t = read_c0_watchhi2(); 166 - c->watch_reg_masks[2] |= (t & 0xff8); 167 - if ((t & 0x80000000) == 0) 158 + c->watch_reg_masks[2] |= (t & MIPS_WATCHHI_MASK); 159 + if ((t & MIPS_WATCHHI_M) == 0) 168 160 return; 169 161 170 - write_c0_watchlo3(7); 162 + write_c0_watchlo3(MIPS_WATCHLO_IRW); 171 163 back_to_back_c0_hazard(); 172 164 t = read_c0_watchlo3(); 173 165 write_c0_watchlo3(0); 174 - c->watch_reg_masks[3] = t & 7; 166 + c->watch_reg_masks[3] = t & MIPS_WATCHLO_IRW; 175 167 176 168 c->watch_reg_count = 4; 177 169 c->watch_reg_use_cnt = 4; 178 170 t = read_c0_watchhi3(); 179 - write_c0_watchhi3(t | 0xff8); 171 + write_c0_watchhi3(t | MIPS_WATCHHI_MASK); 180 172 back_to_back_c0_hazard(); 181 173 t = read_c0_watchhi3(); 182 - c->watch_reg_masks[3] |= (t & 0xff8); 183 - if ((t & 0x80000000) == 0) 174 + c->watch_reg_masks[3] |= (t & MIPS_WATCHHI_MASK); 175 + if ((t & MIPS_WATCHHI_M) == 0) 184 176 return; 185 177 186 178 /* We use at most 4, but probe and report up to 8. */ 187 179 c->watch_reg_count = 5; 188 180 t = read_c0_watchhi4(); 189 - if ((t & 0x80000000) == 0) 181 + if ((t & MIPS_WATCHHI_M) == 0) 190 182 return; 191 183 192 184 c->watch_reg_count = 6; 193 185 t = read_c0_watchhi5(); 194 - if ((t & 0x80000000) == 0) 186 + if ((t & MIPS_WATCHHI_M) == 0) 195 187 return; 196 188 197 189 c->watch_reg_count = 7; 198 190 t = read_c0_watchhi6(); 199 - if ((t & 0x80000000) == 0) 191 + if ((t & MIPS_WATCHHI_M) == 0) 200 192 return; 201 193 202 194 c->watch_reg_count = 8;