1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright 2018, Christophe Leroy CS S.I. 4 * <christophe.leroy@c-s.fr> 5 * 6 * This dumps the content of BATS 7 */ 8 9 #include <asm/debugfs.h> 10 #include <asm/pgtable.h> 11 #include <asm/cpu_has_feature.h> 12 13 #include "ptdump.h" 14 15 static char *pp_601(int k, int pp) 16 { 17 if (pp == 0) 18 return k ? "NA" : "RWX"; 19 if (pp == 1) 20 return k ? "ROX" : "RWX"; 21 if (pp == 2) 22 return k ? "RWX" : "RWX"; 23 return k ? "ROX" : "ROX"; 24 } 25 26 static void bat_show_601(struct seq_file *m, int idx, u32 lower, u32 upper) 27 { 28 u32 blpi = upper & 0xfffe0000; 29 u32 k = (upper >> 2) & 3; 30 u32 pp = upper & 3; 31 phys_addr_t pbn = PHYS_BAT_ADDR(lower); 32 u32 bsm = lower & 0x3ff; 33 u32 size = (bsm + 1) << 17; 34 35 seq_printf(m, "%d: ", idx); 36 if (!(lower & 0x40)) { 37 seq_puts(m, " -\n"); 38 return; 39 } 40 41 seq_printf(m, "0x%08x-0x%08x ", blpi, blpi + size - 1); 42 #ifdef CONFIG_PHYS_64BIT 43 seq_printf(m, "0x%016llx ", pbn); 44 #else 45 seq_printf(m, "0x%08x ", pbn); 46 #endif 47 pt_dump_size(m, size); 48 49 seq_printf(m, "Kernel %s User %s", pp_601(k & 2, pp), pp_601(k & 1, pp)); 50 51 if (lower & _PAGE_WRITETHRU) 52 seq_puts(m, "write through "); 53 if (lower & _PAGE_NO_CACHE) 54 seq_puts(m, "no cache "); 55 if (lower & _PAGE_COHERENT) 56 seq_puts(m, "coherent "); 57 seq_puts(m, "\n"); 58 } 59 60 #define BAT_SHOW_601(_m, _n, _l, _u) bat_show_601(_m, _n, mfspr(_l), mfspr(_u)) 61 62 static int bats_show_601(struct seq_file *m, void *v) 63 { 64 seq_puts(m, "---[ Block Address Translation ]---\n"); 65 66 BAT_SHOW_601(m, 0, SPRN_IBAT0L, SPRN_IBAT0U); 67 BAT_SHOW_601(m, 1, SPRN_IBAT1L, SPRN_IBAT1U); 68 BAT_SHOW_601(m, 2, SPRN_IBAT2L, SPRN_IBAT2U); 69 BAT_SHOW_601(m, 3, SPRN_IBAT3L, SPRN_IBAT3U); 70 71 return 0; 72 } 73 74 static void bat_show_603(struct seq_file *m, int idx, u32 lower, u32 upper, bool is_d) 75 { 76 u32 bepi = upper & 0xfffe0000; 77 u32 bl = (upper >> 2) & 0x7ff; 78 u32 k = upper & 3; 79 phys_addr_t brpn = PHYS_BAT_ADDR(lower); 80 u32 size = (bl + 1) << 17; 81 82 seq_printf(m, "%d: ", idx); 83 if (k == 0) { 84 seq_puts(m, " -\n"); 85 return; 86 } 87 88 seq_printf(m, "0x%08x-0x%08x ", bepi, bepi + size - 1); 89 #ifdef CONFIG_PHYS_64BIT 90 seq_printf(m, "0x%016llx ", brpn); 91 #else 92 seq_printf(m, "0x%08x ", brpn); 93 #endif 94 pt_dump_size(m, size); 95 96 if (k == 1) 97 seq_puts(m, "User "); 98 else if (k == 2) 99 seq_puts(m, "Kernel "); 100 else 101 seq_puts(m, "Kernel/User "); 102 103 if (lower & BPP_RX) 104 seq_puts(m, is_d ? "RO " : "EXEC "); 105 else if (lower & BPP_RW) 106 seq_puts(m, is_d ? "RW " : "EXEC "); 107 else 108 seq_puts(m, is_d ? "NA " : "NX "); 109 110 if (lower & _PAGE_WRITETHRU) 111 seq_puts(m, "write through "); 112 if (lower & _PAGE_NO_CACHE) 113 seq_puts(m, "no cache "); 114 if (lower & _PAGE_COHERENT) 115 seq_puts(m, "coherent "); 116 if (lower & _PAGE_GUARDED) 117 seq_puts(m, "guarded "); 118 seq_puts(m, "\n"); 119 } 120 121 #define BAT_SHOW_603(_m, _n, _l, _u, _d) bat_show_603(_m, _n, mfspr(_l), mfspr(_u), _d) 122 123 static int bats_show_603(struct seq_file *m, void *v) 124 { 125 seq_puts(m, "---[ Instruction Block Address Translation ]---\n"); 126 127 BAT_SHOW_603(m, 0, SPRN_IBAT0L, SPRN_IBAT0U, false); 128 BAT_SHOW_603(m, 1, SPRN_IBAT1L, SPRN_IBAT1U, false); 129 BAT_SHOW_603(m, 2, SPRN_IBAT2L, SPRN_IBAT2U, false); 130 BAT_SHOW_603(m, 3, SPRN_IBAT3L, SPRN_IBAT3U, false); 131 if (mmu_has_feature(MMU_FTR_USE_HIGH_BATS)) { 132 BAT_SHOW_603(m, 4, SPRN_IBAT4L, SPRN_IBAT4U, false); 133 BAT_SHOW_603(m, 5, SPRN_IBAT5L, SPRN_IBAT5U, false); 134 BAT_SHOW_603(m, 6, SPRN_IBAT6L, SPRN_IBAT6U, false); 135 BAT_SHOW_603(m, 7, SPRN_IBAT7L, SPRN_IBAT7U, false); 136 } 137 138 seq_puts(m, "\n---[ Data Block Address Translation ]---\n"); 139 140 BAT_SHOW_603(m, 0, SPRN_DBAT0L, SPRN_DBAT0U, true); 141 BAT_SHOW_603(m, 1, SPRN_DBAT1L, SPRN_DBAT1U, true); 142 BAT_SHOW_603(m, 2, SPRN_DBAT2L, SPRN_DBAT2U, true); 143 BAT_SHOW_603(m, 3, SPRN_DBAT3L, SPRN_DBAT3U, true); 144 if (mmu_has_feature(MMU_FTR_USE_HIGH_BATS)) { 145 BAT_SHOW_603(m, 4, SPRN_DBAT4L, SPRN_DBAT4U, true); 146 BAT_SHOW_603(m, 5, SPRN_DBAT5L, SPRN_DBAT5U, true); 147 BAT_SHOW_603(m, 6, SPRN_DBAT6L, SPRN_DBAT6U, true); 148 BAT_SHOW_603(m, 7, SPRN_DBAT7L, SPRN_DBAT7U, true); 149 } 150 151 return 0; 152 } 153 154 static int bats_open(struct inode *inode, struct file *file) 155 { 156 if (IS_ENABLED(CONFIG_PPC_BOOK3S_601)) 157 return single_open(file, bats_show_601, NULL); 158 159 return single_open(file, bats_show_603, NULL); 160 } 161 162 static const struct file_operations bats_fops = { 163 .open = bats_open, 164 .read = seq_read, 165 .llseek = seq_lseek, 166 .release = single_release, 167 }; 168 169 static int __init bats_init(void) 170 { 171 debugfs_create_file("block_address_translation", 0400, 172 powerpc_debugfs_root, NULL, &bats_fops); 173 return 0; 174 } 175 device_initcall(bats_init); 176