Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * native hashtable management. |
| 3 | * |
| 4 | * SMP scalability work: |
| 5 | * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 12 | |
| 13 | #undef DEBUG_LOW |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/spinlock.h> |
| 16 | #include <linux/bitops.h> |
Michael Ellerman | beacc6d | 2012-07-25 21:20:03 +0000 | [diff] [blame] | 17 | #include <linux/of.h> |
Nicholas Piggin | 4e287e6 | 2017-06-06 23:08:32 +1000 | [diff] [blame] | 18 | #include <linux/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/threads.h> |
| 20 | #include <linux/smp.h> |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/machdep.h> |
| 23 | #include <asm/mmu.h> |
| 24 | #include <asm/mmu_context.h> |
| 25 | #include <asm/pgtable.h> |
| 26 | #include <asm/tlbflush.h> |
Balbir Singh | 0428491 | 2017-04-11 15:23:25 +1000 | [diff] [blame] | 27 | #include <asm/trace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/tlb.h> |
| 29 | #include <asm/cputable.h> |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 30 | #include <asm/udbg.h> |
Luke Browning | 71bf08b | 2007-05-03 00:19:11 +1000 | [diff] [blame] | 31 | #include <asm/kexec.h> |
Milton Miller | 60dbf43 | 2009-04-29 20:58:01 +0000 | [diff] [blame] | 32 | #include <asm/ppc-opcode.h> |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 33 | |
Michael Neuling | ec249dd | 2015-05-27 16:07:16 +1000 | [diff] [blame] | 34 | #include <misc/cxl-base.h> |
Ian Munsie | 4c6d9ac | 2014-10-08 19:55:00 +1100 | [diff] [blame] | 35 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 36 | #ifdef DEBUG_LOW |
| 37 | #define DBG_LOW(fmt...) udbg_printf(fmt) |
| 38 | #else |
| 39 | #define DBG_LOW(fmt...) |
| 40 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 42 | #ifdef __BIG_ENDIAN__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #define HPTE_LOCK_BIT 3 |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 44 | #else |
| 45 | #define HPTE_LOCK_BIT (56+3) |
| 46 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 48 | DEFINE_RAW_SPINLOCK(native_tlbie_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Mahesh Salgaonkar | a3961f8 | 2017-11-22 23:02:07 +0530 | [diff] [blame] | 50 | static inline unsigned long ___tlbie(unsigned long vpn, int psize, |
| 51 | int apsize, int ssize) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 52 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 53 | unsigned long va; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 54 | unsigned int penc; |
Aneesh Kumar K.V | de64095 | 2013-07-04 10:34:45 +0530 | [diff] [blame] | 55 | unsigned long sllp; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 56 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 57 | /* |
| 58 | * We need 14 to 65 bits of va for a tlibe of 4K page |
| 59 | * With vpn we ignore the lower VPN_SHIFT bits already. |
| 60 | * And top two bits are already ignored because we can |
Michael Ellerman | 027dfac | 2016-06-01 16:34:37 +1000 | [diff] [blame] | 61 | * only accomodate 76 bits in a 64 bit vpn with a VPN_SHIFT |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 62 | * of 12. |
| 63 | */ |
| 64 | va = vpn << VPN_SHIFT; |
| 65 | /* |
| 66 | * clear top 16 bits of 64bit va, non SLS segment |
| 67 | * Older versions of the architecture (2.02 and earler) require the |
| 68 | * masking of the top 16 bits. |
| 69 | */ |
Aneesh Kumar K.V | accfad7 | 2016-07-13 15:05:24 +0530 | [diff] [blame] | 70 | if (mmu_has_feature(MMU_FTR_TLBIE_CROP_VA)) |
| 71 | va &= ~(0xffffULL << 48); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 72 | |
| 73 | switch (psize) { |
| 74 | case MMU_PAGE_4K: |
Aneesh Kumar K.V | 1f6aaac | 2013-04-28 09:37:39 +0000 | [diff] [blame] | 75 | /* clear out bits after (52) [0....52.....63] */ |
| 76 | va &= ~((1ul << (64 - 52)) - 1); |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 77 | va |= ssize << 8; |
Aneesh Kumar K.V | 138ee7e | 2016-07-13 15:06:37 +0530 | [diff] [blame] | 78 | sllp = get_sllp_encoding(apsize); |
Aneesh Kumar K.V | de64095 | 2013-07-04 10:34:45 +0530 | [diff] [blame] | 79 | va |= sllp << 5; |
Michael Neuling | a32e252 | 2011-04-06 18:23:29 +0000 | [diff] [blame] | 80 | asm volatile(ASM_FTR_IFCLR("tlbie %0,0", PPC_TLBIE(%1,%0), %2) |
Paul Mackerras | 969391c | 2011-06-29 00:26:11 +0000 | [diff] [blame] | 81 | : : "r" (va), "r"(0), "i" (CPU_FTR_ARCH_206) |
Milton Miller | 60dbf43 | 2009-04-29 20:58:01 +0000 | [diff] [blame] | 82 | : "memory"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 83 | break; |
| 84 | default: |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 85 | /* We need 14 to 14 + i bits of va */ |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 86 | penc = mmu_psize_defs[psize].penc[apsize]; |
Aneesh Kumar K.V | 1f6aaac | 2013-04-28 09:37:39 +0000 | [diff] [blame] | 87 | va &= ~((1ul << mmu_psize_defs[apsize].shift) - 1); |
Arnd Bergmann | 19242b2 | 2006-06-15 21:15:44 +1000 | [diff] [blame] | 88 | va |= penc << 12; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 89 | va |= ssize << 8; |
Aneesh Kumar K.V | 29ef7a3 | 2014-04-21 10:37:36 +0530 | [diff] [blame] | 90 | /* |
| 91 | * AVAL bits: |
| 92 | * We don't need all the bits, but rest of the bits |
| 93 | * must be ignored by the processor. |
| 94 | * vpn cover upto 65 bits of va. (0...65) and we need |
| 95 | * 58..64 bits of va. |
| 96 | */ |
| 97 | va |= (vpn & 0xfe); /* AVAL */ |
Milton Miller | 60dbf43 | 2009-04-29 20:58:01 +0000 | [diff] [blame] | 98 | va |= 1; /* L */ |
Michael Neuling | a32e252 | 2011-04-06 18:23:29 +0000 | [diff] [blame] | 99 | asm volatile(ASM_FTR_IFCLR("tlbie %0,1", PPC_TLBIE(%1,%0), %2) |
Paul Mackerras | 969391c | 2011-06-29 00:26:11 +0000 | [diff] [blame] | 100 | : : "r" (va), "r"(0), "i" (CPU_FTR_ARCH_206) |
Milton Miller | 60dbf43 | 2009-04-29 20:58:01 +0000 | [diff] [blame] | 101 | : "memory"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 102 | break; |
| 103 | } |
Mahesh Salgaonkar | a3961f8 | 2017-11-22 23:02:07 +0530 | [diff] [blame] | 104 | return va; |
| 105 | } |
| 106 | |
| 107 | static inline void __tlbie(unsigned long vpn, int psize, int apsize, int ssize) |
| 108 | { |
| 109 | unsigned long rb; |
| 110 | |
| 111 | rb = ___tlbie(vpn, psize, apsize, ssize); |
| 112 | trace_tlbie(0, 0, rb, 0, 0, 0, 0); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 113 | } |
| 114 | |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 115 | static inline void __tlbiel(unsigned long vpn, int psize, int apsize, int ssize) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 116 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 117 | unsigned long va; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 118 | unsigned int penc; |
Aneesh Kumar K.V | de64095 | 2013-07-04 10:34:45 +0530 | [diff] [blame] | 119 | unsigned long sllp; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 120 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 121 | /* VPN_SHIFT can be atmost 12 */ |
| 122 | va = vpn << VPN_SHIFT; |
| 123 | /* |
| 124 | * clear top 16 bits of 64 bit va, non SLS segment |
| 125 | * Older versions of the architecture (2.02 and earler) require the |
| 126 | * masking of the top 16 bits. |
| 127 | */ |
Aneesh Kumar K.V | accfad7 | 2016-07-13 15:05:24 +0530 | [diff] [blame] | 128 | if (mmu_has_feature(MMU_FTR_TLBIE_CROP_VA)) |
| 129 | va &= ~(0xffffULL << 48); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 130 | |
| 131 | switch (psize) { |
| 132 | case MMU_PAGE_4K: |
Aneesh Kumar K.V | 1f6aaac | 2013-04-28 09:37:39 +0000 | [diff] [blame] | 133 | /* clear out bits after(52) [0....52.....63] */ |
| 134 | va &= ~((1ul << (64 - 52)) - 1); |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 135 | va |= ssize << 8; |
Aneesh Kumar K.V | 138ee7e | 2016-07-13 15:06:37 +0530 | [diff] [blame] | 136 | sllp = get_sllp_encoding(apsize); |
Aneesh Kumar K.V | de64095 | 2013-07-04 10:34:45 +0530 | [diff] [blame] | 137 | va |= sllp << 5; |
Balbir Singh | f923efb | 2016-09-28 17:25:52 +1000 | [diff] [blame] | 138 | asm volatile(ASM_FTR_IFSET("tlbiel %0", "tlbiel %0,0", %1) |
| 139 | : : "r" (va), "i" (CPU_FTR_ARCH_206) |
| 140 | : "memory"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 141 | break; |
| 142 | default: |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 143 | /* We need 14 to 14 + i bits of va */ |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 144 | penc = mmu_psize_defs[psize].penc[apsize]; |
Aneesh Kumar K.V | 1f6aaac | 2013-04-28 09:37:39 +0000 | [diff] [blame] | 145 | va &= ~((1ul << mmu_psize_defs[apsize].shift) - 1); |
Arnd Bergmann | 19242b2 | 2006-06-15 21:15:44 +1000 | [diff] [blame] | 146 | va |= penc << 12; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 147 | va |= ssize << 8; |
Aneesh Kumar K.V | 29ef7a3 | 2014-04-21 10:37:36 +0530 | [diff] [blame] | 148 | /* |
| 149 | * AVAL bits: |
| 150 | * We don't need all the bits, but rest of the bits |
| 151 | * must be ignored by the processor. |
| 152 | * vpn cover upto 65 bits of va. (0...65) and we need |
| 153 | * 58..64 bits of va. |
| 154 | */ |
| 155 | va |= (vpn & 0xfe); |
Milton Miller | 60dbf43 | 2009-04-29 20:58:01 +0000 | [diff] [blame] | 156 | va |= 1; /* L */ |
Balbir Singh | f923efb | 2016-09-28 17:25:52 +1000 | [diff] [blame] | 157 | asm volatile(ASM_FTR_IFSET("tlbiel %0", "tlbiel %0,1", %1) |
| 158 | : : "r" (va), "i" (CPU_FTR_ARCH_206) |
| 159 | : "memory"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 160 | break; |
| 161 | } |
Balbir Singh | 0428491 | 2017-04-11 15:23:25 +1000 | [diff] [blame] | 162 | trace_tlbie(0, 1, va, 0, 0, 0, 0); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 163 | |
| 164 | } |
| 165 | |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 166 | static inline void tlbie(unsigned long vpn, int psize, int apsize, |
| 167 | int ssize, int local) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 168 | { |
Ian Munsie | 4c6d9ac | 2014-10-08 19:55:00 +1100 | [diff] [blame] | 169 | unsigned int use_local; |
Matt Evans | 44ae3ab | 2011-04-06 19:48:50 +0000 | [diff] [blame] | 170 | int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 171 | |
Ian Munsie | 4c6d9ac | 2014-10-08 19:55:00 +1100 | [diff] [blame] | 172 | use_local = local && mmu_has_feature(MMU_FTR_TLBIEL) && !cxl_ctx_in_use(); |
| 173 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 174 | if (use_local) |
| 175 | use_local = mmu_psize_defs[psize].tlbiel; |
| 176 | if (lock_tlbie && !use_local) |
Thomas Gleixner | 6b9c9b8 | 2010-02-18 02:22:35 +0000 | [diff] [blame] | 177 | raw_spin_lock(&native_tlbie_lock); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 178 | asm volatile("ptesync": : :"memory"); |
| 179 | if (use_local) { |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 180 | __tlbiel(vpn, psize, apsize, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 181 | asm volatile("ptesync": : :"memory"); |
| 182 | } else { |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 183 | __tlbie(vpn, psize, apsize, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 184 | asm volatile("eieio; tlbsync; ptesync": : :"memory"); |
| 185 | } |
| 186 | if (lock_tlbie && !use_local) |
Thomas Gleixner | 6b9c9b8 | 2010-02-18 02:22:35 +0000 | [diff] [blame] | 187 | raw_spin_unlock(&native_tlbie_lock); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 188 | } |
| 189 | |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 190 | static inline void native_lock_hpte(struct hash_pte *hptep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 192 | unsigned long *word = (unsigned long *)&hptep->v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | while (1) { |
Anton Blanchard | 66d99b8 | 2010-02-10 01:03:06 +0000 | [diff] [blame] | 195 | if (!test_and_set_bit_lock(HPTE_LOCK_BIT, word)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | break; |
Nicholas Piggin | 4e287e6 | 2017-06-06 23:08:32 +1000 | [diff] [blame] | 197 | spin_begin(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | while(test_bit(HPTE_LOCK_BIT, word)) |
Nicholas Piggin | 4e287e6 | 2017-06-06 23:08:32 +1000 | [diff] [blame] | 199 | spin_cpu_relax(); |
| 200 | spin_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 204 | static inline void native_unlock_hpte(struct hash_pte *hptep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 206 | unsigned long *word = (unsigned long *)&hptep->v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Anton Blanchard | 66d99b8 | 2010-02-10 01:03:06 +0000 | [diff] [blame] | 208 | clear_bit_unlock(HPTE_LOCK_BIT, word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 211 | static long native_hpte_insert(unsigned long hpte_group, unsigned long vpn, |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 212 | unsigned long pa, unsigned long rflags, |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 213 | unsigned long vflags, int psize, int apsize, int ssize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 215 | struct hash_pte *hptep = htab_address + hpte_group; |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 216 | unsigned long hpte_v, hpte_r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | int i; |
| 218 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 219 | if (!(vflags & HPTE_V_BOLTED)) { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 220 | DBG_LOW(" insert(group=%lx, vpn=%016lx, pa=%016lx," |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 221 | " rflags=%lx, vflags=%lx, psize=%d)\n", |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 222 | hpte_group, vpn, pa, rflags, vflags, psize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 223 | } |
| 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | for (i = 0; i < HPTES_PER_GROUP; i++) { |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 226 | if (! (be64_to_cpu(hptep->v) & HPTE_V_VALID)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* retry with lock held */ |
| 228 | native_lock_hpte(hptep); |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 229 | if (! (be64_to_cpu(hptep->v) & HPTE_V_VALID)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | break; |
| 231 | native_unlock_hpte(hptep); |
| 232 | } |
| 233 | |
| 234 | hptep++; |
| 235 | } |
| 236 | |
| 237 | if (i == HPTES_PER_GROUP) |
| 238 | return -1; |
| 239 | |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 240 | hpte_v = hpte_encode_v(vpn, psize, apsize, ssize) | vflags | HPTE_V_VALID; |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 241 | hpte_r = hpte_encode_r(pa, psize, apsize) | rflags; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 242 | |
| 243 | if (!(vflags & HPTE_V_BOLTED)) { |
| 244 | DBG_LOW(" i=%x hpte_v=%016lx, hpte_r=%016lx\n", |
| 245 | i, hpte_v, hpte_r); |
| 246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 248 | if (cpu_has_feature(CPU_FTR_ARCH_300)) { |
| 249 | hpte_r = hpte_old_to_new_r(hpte_v, hpte_r); |
| 250 | hpte_v = hpte_old_to_new_v(hpte_v); |
| 251 | } |
| 252 | |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 253 | hptep->r = cpu_to_be64(hpte_r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | /* Guarantee the second dword is visible before the valid bit */ |
Kumar Gala | 74a0ba6 | 2007-07-09 23:49:09 -0500 | [diff] [blame] | 255 | eieio(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | /* |
| 257 | * Now set the first dword including the valid bit |
| 258 | * NOTE: this also unlocks the hpte |
| 259 | */ |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 260 | hptep->v = cpu_to_be64(hpte_v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | __asm__ __volatile__ ("ptesync" : : : "memory"); |
| 263 | |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 264 | return i | (!!(vflags & HPTE_V_SECONDARY) << 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static long native_hpte_remove(unsigned long hpte_group) |
| 268 | { |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 269 | struct hash_pte *hptep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | int i; |
| 271 | int slot_offset; |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 272 | unsigned long hpte_v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 274 | DBG_LOW(" remove(group=%lx)\n", hpte_group); |
| 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* pick a random entry to start at */ |
| 277 | slot_offset = mftb() & 0x7; |
| 278 | |
| 279 | for (i = 0; i < HPTES_PER_GROUP; i++) { |
| 280 | hptep = htab_address + hpte_group + slot_offset; |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 281 | hpte_v = be64_to_cpu(hptep->v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 283 | if ((hpte_v & HPTE_V_VALID) && !(hpte_v & HPTE_V_BOLTED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | /* retry with lock held */ |
| 285 | native_lock_hpte(hptep); |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 286 | hpte_v = be64_to_cpu(hptep->v); |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 287 | if ((hpte_v & HPTE_V_VALID) |
| 288 | && !(hpte_v & HPTE_V_BOLTED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | break; |
| 290 | native_unlock_hpte(hptep); |
| 291 | } |
| 292 | |
| 293 | slot_offset++; |
| 294 | slot_offset &= 0x7; |
| 295 | } |
| 296 | |
| 297 | if (i == HPTES_PER_GROUP) |
| 298 | return -1; |
| 299 | |
| 300 | /* Invalidate the hpte. NOTE: this also unlocks it */ |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 301 | hptep->v = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
| 303 | return i; |
| 304 | } |
| 305 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 306 | static long native_hpte_updatepp(unsigned long slot, unsigned long newpp, |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 307 | unsigned long vpn, int bpsize, |
Aneesh Kumar K.V | aefa568 | 2014-12-04 11:00:14 +0530 | [diff] [blame] | 308 | int apsize, int ssize, unsigned long flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 310 | struct hash_pte *hptep = htab_address + slot; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 311 | unsigned long hpte_v, want_v; |
Aneesh Kumar K.V | aefa568 | 2014-12-04 11:00:14 +0530 | [diff] [blame] | 312 | int ret = 0, local = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 314 | want_v = hpte_encode_avpn(vpn, bpsize, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 315 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 316 | DBG_LOW(" update(vpn=%016lx, avpnv=%016lx, group=%lx, newpp=%lx)", |
| 317 | vpn, want_v & HPTE_V_AVPN, slot, newpp); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 318 | |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 319 | hpte_v = be64_to_cpu(hptep->v); |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 320 | if (cpu_has_feature(CPU_FTR_ARCH_300)) |
| 321 | hpte_v = hpte_new_to_old_v(hpte_v, be64_to_cpu(hptep->r)); |
Aneesh Kumar K.V | 0608d69 | 2013-05-31 01:03:24 +0000 | [diff] [blame] | 322 | /* |
| 323 | * We need to invalidate the TLB always because hpte_remove doesn't do |
| 324 | * a tlb invalidate. If a hash bucket gets full, we "evict" a more/less |
| 325 | * random entry from it. When we do that we don't invalidate the TLB |
| 326 | * (hpte_remove) because we assume the old translation is still |
| 327 | * technically "valid". |
| 328 | */ |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 329 | if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 330 | DBG_LOW(" -> miss\n"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 331 | ret = -1; |
| 332 | } else { |
Aneesh Kumar K.V | 0ec2698 | 2014-11-03 20:21:34 +0530 | [diff] [blame] | 333 | native_lock_hpte(hptep); |
| 334 | /* recheck with locks held */ |
| 335 | hpte_v = be64_to_cpu(hptep->v); |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 336 | if (cpu_has_feature(CPU_FTR_ARCH_300)) |
| 337 | hpte_v = hpte_new_to_old_v(hpte_v, be64_to_cpu(hptep->r)); |
Aneesh Kumar K.V | 0ec2698 | 2014-11-03 20:21:34 +0530 | [diff] [blame] | 338 | if (unlikely(!HPTE_V_COMPARE(hpte_v, want_v) || |
| 339 | !(hpte_v & HPTE_V_VALID))) { |
| 340 | ret = -1; |
| 341 | } else { |
| 342 | DBG_LOW(" -> hit\n"); |
| 343 | /* Update the HPTE */ |
| 344 | hptep->r = cpu_to_be64((be64_to_cpu(hptep->r) & |
Aneesh Kumar K.V | 8550e2f | 2016-06-08 19:55:55 +0530 | [diff] [blame] | 345 | ~(HPTE_R_PPP | HPTE_R_N)) | |
| 346 | (newpp & (HPTE_R_PPP | HPTE_R_N | |
Aneesh Kumar K.V | 0ec2698 | 2014-11-03 20:21:34 +0530 | [diff] [blame] | 347 | HPTE_R_C))); |
| 348 | } |
| 349 | native_unlock_hpte(hptep); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 350 | } |
Aneesh Kumar K.V | aefa568 | 2014-12-04 11:00:14 +0530 | [diff] [blame] | 351 | |
| 352 | if (flags & HPTE_LOCAL_UPDATE) |
| 353 | local = 1; |
| 354 | /* |
| 355 | * Ensure it is out of the tlb too if it is not a nohpte fault |
| 356 | */ |
| 357 | if (!(flags & HPTE_NOHPTE_UPDATE)) |
| 358 | tlbie(vpn, bpsize, apsize, ssize, local); |
| 359 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 360 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 363 | static long native_hpte_find(unsigned long vpn, int psize, int ssize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | { |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 365 | struct hash_pte *hptep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | unsigned long hash; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 367 | unsigned long i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | long slot; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 369 | unsigned long want_v, hpte_v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 371 | hash = hpt_hash(vpn, mmu_psize_defs[psize].shift, ssize); |
Aneesh Kumar K.V | 74f227b | 2013-04-28 09:37:34 +0000 | [diff] [blame] | 372 | want_v = hpte_encode_avpn(vpn, psize, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 374 | /* Bolted mappings are only ever in the primary group */ |
| 375 | slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 376 | for (i = 0; i < HPTES_PER_GROUP; i++) { |
| 377 | hptep = htab_address + slot; |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 378 | hpte_v = be64_to_cpu(hptep->v); |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 379 | if (cpu_has_feature(CPU_FTR_ARCH_300)) |
| 380 | hpte_v = hpte_new_to_old_v(hpte_v, be64_to_cpu(hptep->r)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 382 | if (HPTE_V_COMPARE(hpte_v, want_v) && (hpte_v & HPTE_V_VALID)) |
| 383 | /* HPTE matches */ |
| 384 | return slot; |
| 385 | ++slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | return -1; |
| 389 | } |
| 390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | /* |
| 392 | * Update the page protection bits. Intended to be used to create |
| 393 | * guard pages for kernel data structures on pages which are bolted |
| 394 | * in the HPT. Assumes pages being operated on will not be stolen. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | * |
| 396 | * No need to lock here because we should be the only user. |
| 397 | */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 398 | static void native_hpte_updateboltedpp(unsigned long newpp, unsigned long ea, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 399 | int psize, int ssize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 401 | unsigned long vpn; |
| 402 | unsigned long vsid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | long slot; |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 404 | struct hash_pte *hptep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 406 | vsid = get_kernel_vsid(ea, ssize); |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 407 | vpn = hpt_vpn(ea, vsid, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 409 | slot = native_hpte_find(vpn, psize, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | if (slot == -1) |
| 411 | panic("could not find page to bolt\n"); |
| 412 | hptep = htab_address + slot; |
| 413 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 414 | /* Update the HPTE */ |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 415 | hptep->r = cpu_to_be64((be64_to_cpu(hptep->r) & |
Aneesh Kumar K.V | 8550e2f | 2016-06-08 19:55:55 +0530 | [diff] [blame] | 416 | ~(HPTE_R_PPP | HPTE_R_N)) | |
| 417 | (newpp & (HPTE_R_PPP | HPTE_R_N))); |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 418 | /* |
| 419 | * Ensure it is out of the tlb too. Bolted entries base and |
| 420 | * actual page size will be same. |
| 421 | */ |
| 422 | tlbie(vpn, psize, psize, ssize, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Anton Blanchard | 1b644f5 | 2017-06-28 11:32:35 +1000 | [diff] [blame] | 425 | /* |
| 426 | * Remove a bolted kernel entry. Memory hotplug uses this. |
| 427 | * |
| 428 | * No need to lock here because we should be the only user. |
| 429 | */ |
| 430 | static int native_hpte_removebolted(unsigned long ea, int psize, int ssize) |
| 431 | { |
| 432 | unsigned long vpn; |
| 433 | unsigned long vsid; |
| 434 | long slot; |
| 435 | struct hash_pte *hptep; |
| 436 | |
| 437 | vsid = get_kernel_vsid(ea, ssize); |
| 438 | vpn = hpt_vpn(ea, vsid, ssize); |
| 439 | |
| 440 | slot = native_hpte_find(vpn, psize, ssize); |
| 441 | if (slot == -1) |
| 442 | return -ENOENT; |
| 443 | |
| 444 | hptep = htab_address + slot; |
| 445 | |
| 446 | VM_WARN_ON(!(be64_to_cpu(hptep->v) & HPTE_V_BOLTED)); |
| 447 | |
| 448 | /* Invalidate the hpte */ |
| 449 | hptep->v = 0; |
| 450 | |
| 451 | /* Invalidate the TLB */ |
| 452 | tlbie(vpn, psize, psize, ssize, 0); |
| 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 457 | static void native_hpte_invalidate(unsigned long slot, unsigned long vpn, |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 458 | int bpsize, int apsize, int ssize, int local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | { |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 460 | struct hash_pte *hptep = htab_address + slot; |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 461 | unsigned long hpte_v; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 462 | unsigned long want_v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
| 465 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 467 | DBG_LOW(" invalidate(vpn=%016lx, hash: %lx)\n", vpn, slot); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 468 | |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 469 | want_v = hpte_encode_avpn(vpn, bpsize, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 470 | native_lock_hpte(hptep); |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 471 | hpte_v = be64_to_cpu(hptep->v); |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 472 | if (cpu_has_feature(CPU_FTR_ARCH_300)) |
| 473 | hpte_v = hpte_new_to_old_v(hpte_v, be64_to_cpu(hptep->r)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Aneesh Kumar K.V | 0608d69 | 2013-05-31 01:03:24 +0000 | [diff] [blame] | 475 | /* |
| 476 | * We need to invalidate the TLB always because hpte_remove doesn't do |
| 477 | * a tlb invalidate. If a hash bucket gets full, we "evict" a more/less |
| 478 | * random entry from it. When we do that we don't invalidate the TLB |
| 479 | * (hpte_remove) because we assume the old translation is still |
| 480 | * technically "valid". |
| 481 | */ |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 482 | if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | native_unlock_hpte(hptep); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 484 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | /* Invalidate the hpte. NOTE: this also unlocks it */ |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 486 | hptep->v = 0; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 487 | |
| 488 | /* Invalidate the TLB */ |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 489 | tlbie(vpn, bpsize, apsize, ssize, local); |
| 490 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 491 | local_irq_restore(flags); |
| 492 | } |
| 493 | |
Aneesh Kumar K.V | e34aa03 | 2015-12-01 09:06:53 +0530 | [diff] [blame] | 494 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
Aneesh Kumar K.V | fa1f8ae | 2014-08-13 12:31:58 +0530 | [diff] [blame] | 495 | static void native_hugepage_invalidate(unsigned long vsid, |
| 496 | unsigned long addr, |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 497 | unsigned char *hpte_slot_array, |
Aneesh Kumar K.V | d557b09 | 2014-11-02 21:15:28 +0530 | [diff] [blame] | 498 | int psize, int ssize, int local) |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 499 | { |
Aneesh Kumar K.V | 969b7b2 | 2014-08-13 12:32:01 +0530 | [diff] [blame] | 500 | int i; |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 501 | struct hash_pte *hptep; |
| 502 | int actual_psize = MMU_PAGE_16M; |
| 503 | unsigned int max_hpte_count, valid; |
| 504 | unsigned long flags, s_addr = addr; |
| 505 | unsigned long hpte_v, want_v, shift; |
Aneesh Kumar K.V | fa1f8ae | 2014-08-13 12:31:58 +0530 | [diff] [blame] | 506 | unsigned long hidx, vpn = 0, hash, slot; |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 507 | |
| 508 | shift = mmu_psize_defs[psize].shift; |
| 509 | max_hpte_count = 1U << (PMD_SHIFT - shift); |
| 510 | |
| 511 | local_irq_save(flags); |
| 512 | for (i = 0; i < max_hpte_count; i++) { |
| 513 | valid = hpte_valid(hpte_slot_array, i); |
| 514 | if (!valid) |
| 515 | continue; |
| 516 | hidx = hpte_hash_index(hpte_slot_array, i); |
| 517 | |
| 518 | /* get the vpn */ |
| 519 | addr = s_addr + (i * (1ul << shift)); |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 520 | vpn = hpt_vpn(addr, vsid, ssize); |
| 521 | hash = hpt_hash(vpn, shift, ssize); |
| 522 | if (hidx & _PTEIDX_SECONDARY) |
| 523 | hash = ~hash; |
| 524 | |
| 525 | slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 526 | slot += hidx & _PTEIDX_GROUP_IX; |
| 527 | |
| 528 | hptep = htab_address + slot; |
| 529 | want_v = hpte_encode_avpn(vpn, psize, ssize); |
| 530 | native_lock_hpte(hptep); |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 531 | hpte_v = be64_to_cpu(hptep->v); |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 532 | if (cpu_has_feature(CPU_FTR_ARCH_300)) |
| 533 | hpte_v = hpte_new_to_old_v(hpte_v, be64_to_cpu(hptep->r)); |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 534 | |
| 535 | /* Even if we miss, we need to invalidate the TLB */ |
| 536 | if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) |
| 537 | native_unlock_hpte(hptep); |
| 538 | else |
| 539 | /* Invalidate the hpte. NOTE: this also unlocks it */ |
| 540 | hptep->v = 0; |
Aneesh Kumar K.V | 969b7b2 | 2014-08-13 12:32:01 +0530 | [diff] [blame] | 541 | /* |
| 542 | * We need to do tlb invalidate for all the address, tlbie |
| 543 | * instruction compares entry_VA in tlb with the VA specified |
| 544 | * here |
| 545 | */ |
Aneesh Kumar K.V | d557b09 | 2014-11-02 21:15:28 +0530 | [diff] [blame] | 546 | tlbie(vpn, psize, actual_psize, ssize, local); |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 547 | } |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 548 | local_irq_restore(flags); |
| 549 | } |
Aneesh Kumar K.V | e34aa03 | 2015-12-01 09:06:53 +0530 | [diff] [blame] | 550 | #else |
| 551 | static void native_hugepage_invalidate(unsigned long vsid, |
| 552 | unsigned long addr, |
| 553 | unsigned char *hpte_slot_array, |
| 554 | int psize, int ssize, int local) |
| 555 | { |
| 556 | WARN(1, "%s called without THP support\n", __func__); |
| 557 | } |
| 558 | #endif |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 559 | |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 560 | static void hpte_decode(struct hash_pte *hpte, unsigned long slot, |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 561 | int *psize, int *apsize, int *ssize, unsigned long *vpn) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 562 | { |
Aneesh Kumar K.V | dcda287 | 2012-09-10 02:52:49 +0000 | [diff] [blame] | 563 | unsigned long avpn, pteg, vpi; |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 564 | unsigned long hpte_v = be64_to_cpu(hpte->v); |
| 565 | unsigned long hpte_r = be64_to_cpu(hpte->r); |
Aneesh Kumar K.V | dcda287 | 2012-09-10 02:52:49 +0000 | [diff] [blame] | 566 | unsigned long vsid, seg_off; |
Aneesh Kumar K.V | 7e74c39 | 2013-04-28 09:37:36 +0000 | [diff] [blame] | 567 | int size, a_size, shift; |
| 568 | /* Look at the 8 bit LP value */ |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 569 | unsigned int lp = (hpte_r >> LP_SHIFT) & ((1 << LP_BITS) - 1); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 570 | |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 571 | if (cpu_has_feature(CPU_FTR_ARCH_300)) { |
| 572 | hpte_v = hpte_new_to_old_v(hpte_v, hpte_r); |
| 573 | hpte_r = hpte_new_to_old_r(hpte_r); |
| 574 | } |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 575 | if (!(hpte_v & HPTE_V_LARGE)) { |
| 576 | size = MMU_PAGE_4K; |
| 577 | a_size = MMU_PAGE_4K; |
| 578 | } else { |
Paul Mackerras | 0eeede0 | 2016-09-02 17:20:43 +1000 | [diff] [blame] | 579 | size = hpte_page_sizes[lp] & 0xf; |
| 580 | a_size = hpte_page_sizes[lp] >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | } |
Paul Mackerras | 2454c7e | 2007-05-10 15:28:44 +1000 | [diff] [blame] | 582 | /* This works for all page sizes, and for 256M and 1T segments */ |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 583 | *ssize = hpte_v >> HPTE_V_SSIZE_SHIFT; |
Aneesh Kumar K.V | dcda287 | 2012-09-10 02:52:49 +0000 | [diff] [blame] | 584 | shift = mmu_psize_defs[size].shift; |
| 585 | |
| 586 | avpn = (HPTE_V_AVPN_VAL(hpte_v) & ~mmu_psize_defs[size].avpnm); |
| 587 | pteg = slot / HPTES_PER_GROUP; |
| 588 | if (hpte_v & HPTE_V_SECONDARY) |
| 589 | pteg = ~pteg; |
| 590 | |
| 591 | switch (*ssize) { |
| 592 | case MMU_SEGSIZE_256M: |
| 593 | /* We only have 28 - 23 bits of seg_off in avpn */ |
| 594 | seg_off = (avpn & 0x1f) << 23; |
| 595 | vsid = avpn >> 5; |
| 596 | /* We can find more bits from the pteg value */ |
| 597 | if (shift < 23) { |
| 598 | vpi = (vsid ^ pteg) & htab_hash_mask; |
| 599 | seg_off |= vpi << shift; |
| 600 | } |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 601 | *vpn = vsid << (SID_SHIFT - VPN_SHIFT) | seg_off >> VPN_SHIFT; |
Aneesh Kumar K.V | 83383b7 | 2013-07-03 13:50:03 +0530 | [diff] [blame] | 602 | break; |
Aneesh Kumar K.V | dcda287 | 2012-09-10 02:52:49 +0000 | [diff] [blame] | 603 | case MMU_SEGSIZE_1T: |
| 604 | /* We only have 40 - 23 bits of seg_off in avpn */ |
| 605 | seg_off = (avpn & 0x1ffff) << 23; |
| 606 | vsid = avpn >> 17; |
| 607 | if (shift < 23) { |
| 608 | vpi = (vsid ^ (vsid << 25) ^ pteg) & htab_hash_mask; |
| 609 | seg_off |= vpi << shift; |
| 610 | } |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 611 | *vpn = vsid << (SID_SHIFT_1T - VPN_SHIFT) | seg_off >> VPN_SHIFT; |
Aneesh Kumar K.V | 83383b7 | 2013-07-03 13:50:03 +0530 | [diff] [blame] | 612 | break; |
Aneesh Kumar K.V | dcda287 | 2012-09-10 02:52:49 +0000 | [diff] [blame] | 613 | default: |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 614 | *vpn = size = 0; |
Aneesh Kumar K.V | dcda287 | 2012-09-10 02:52:49 +0000 | [diff] [blame] | 615 | } |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 616 | *psize = size; |
| 617 | *apsize = a_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | } |
| 619 | |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 620 | /* |
| 621 | * clear all mappings on kexec. All cpus are in real mode (or they will |
| 622 | * be when they isi), and we are the only one left. We rely on our kernel |
| 623 | * mapping being 0xC0's and the hardware ignoring those two real bits. |
| 624 | * |
Cyril Bur | fdf880a | 2015-10-08 11:04:26 +1100 | [diff] [blame] | 625 | * This must be called with interrupts disabled. |
| 626 | * |
| 627 | * Taking the native_tlbie_lock is unsafe here due to the possibility of |
| 628 | * lockdep being on. On pre POWER5 hardware, not taking the lock could |
| 629 | * cause deadlock. POWER5 and newer not taking the lock is fine. This only |
| 630 | * gets called during boot before secondary CPUs have come up and during |
| 631 | * crashdump and all bets are off anyway. |
| 632 | * |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 633 | * TODO: add batching support when enabled. remember, no dynamic memory here, |
Michael Ellerman | 027dfac | 2016-06-01 16:34:37 +1000 | [diff] [blame] | 634 | * although there is the control page available... |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 635 | */ |
| 636 | static void native_hpte_clear(void) |
| 637 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 638 | unsigned long vpn = 0; |
Cyril Bur | fdf880a | 2015-10-08 11:04:26 +1100 | [diff] [blame] | 639 | unsigned long slot, slots; |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 640 | struct hash_pte *hptep = htab_address; |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 641 | unsigned long hpte_v; |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 642 | unsigned long pteg_count; |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 643 | int psize, apsize, ssize; |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 644 | |
| 645 | pteg_count = htab_hash_mask + 1; |
| 646 | |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 647 | slots = pteg_count * HPTES_PER_GROUP; |
| 648 | |
| 649 | for (slot = 0; slot < slots; slot++, hptep++) { |
| 650 | /* |
| 651 | * we could lock the pte here, but we are the only cpu |
| 652 | * running, right? and for crash dump, we probably |
| 653 | * don't want to wait for a maybe bad cpu. |
| 654 | */ |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 655 | hpte_v = be64_to_cpu(hptep->v); |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 656 | |
R Sharada | 47f78a4 | 2006-02-22 21:43:08 +0530 | [diff] [blame] | 657 | /* |
Cyril Bur | fdf880a | 2015-10-08 11:04:26 +1100 | [diff] [blame] | 658 | * Call __tlbie() here rather than tlbie() since we can't take the |
| 659 | * native_tlbie_lock. |
R Sharada | 47f78a4 | 2006-02-22 21:43:08 +0530 | [diff] [blame] | 660 | */ |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 661 | if (hpte_v & HPTE_V_VALID) { |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 662 | hpte_decode(hptep, slot, &psize, &apsize, &ssize, &vpn); |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 663 | hptep->v = 0; |
Mahesh Salgaonkar | a3961f8 | 2017-11-22 23:02:07 +0530 | [diff] [blame] | 664 | ___tlbie(vpn, psize, apsize, ssize); |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 665 | } |
| 666 | } |
| 667 | |
R Sharada | 47f78a4 | 2006-02-22 21:43:08 +0530 | [diff] [blame] | 668 | asm volatile("eieio; tlbsync; ptesync":::"memory"); |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 671 | /* |
| 672 | * Batched hash table flush, we batch the tlbie's to avoid taking/releasing |
| 673 | * the lock all the time |
| 674 | */ |
Benjamin Herrenschmidt | 61b1a94 | 2005-09-20 13:52:50 +1000 | [diff] [blame] | 675 | static void native_flush_hash_range(unsigned long number, int local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 677 | unsigned long vpn; |
| 678 | unsigned long hash, index, hidx, shift, slot; |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 679 | struct hash_pte *hptep; |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 680 | unsigned long hpte_v; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 681 | unsigned long want_v; |
| 682 | unsigned long flags; |
| 683 | real_pte_t pte; |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 684 | struct ppc64_tlb_batch *batch = this_cpu_ptr(&ppc64_tlb_batch); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 685 | unsigned long psize = batch->psize; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 686 | int ssize = batch->ssize; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 687 | int i; |
Frederic Barrat | 88b1bf72 | 2017-03-29 19:19:42 +0200 | [diff] [blame] | 688 | unsigned int use_local; |
| 689 | |
| 690 | use_local = local && mmu_has_feature(MMU_FTR_TLBIEL) && |
| 691 | mmu_psize_defs[psize].tlbiel && !cxl_ctx_in_use(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
| 693 | local_irq_save(flags); |
| 694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | for (i = 0; i < number; i++) { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 696 | vpn = batch->vpn[i]; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 697 | pte = batch->pte[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 699 | pte_iterate_hashed_subpages(pte, psize, vpn, index, shift) { |
| 700 | hash = hpt_hash(vpn, shift, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 701 | hidx = __rpte_to_hidx(pte, index); |
| 702 | if (hidx & _PTEIDX_SECONDARY) |
| 703 | hash = ~hash; |
| 704 | slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 705 | slot += hidx & _PTEIDX_GROUP_IX; |
| 706 | hptep = htab_address + slot; |
Aneesh Kumar K.V | 74f227b | 2013-04-28 09:37:34 +0000 | [diff] [blame] | 707 | want_v = hpte_encode_avpn(vpn, psize, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 708 | native_lock_hpte(hptep); |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 709 | hpte_v = be64_to_cpu(hptep->v); |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 710 | if (cpu_has_feature(CPU_FTR_ARCH_300)) |
| 711 | hpte_v = hpte_new_to_old_v(hpte_v, |
| 712 | be64_to_cpu(hptep->r)); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 713 | if (!HPTE_V_COMPARE(hpte_v, want_v) || |
| 714 | !(hpte_v & HPTE_V_VALID)) |
| 715 | native_unlock_hpte(hptep); |
| 716 | else |
| 717 | hptep->v = 0; |
| 718 | } pte_iterate_hashed_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Frederic Barrat | 88b1bf72 | 2017-03-29 19:19:42 +0200 | [diff] [blame] | 721 | if (use_local) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | asm volatile("ptesync":::"memory"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 723 | for (i = 0; i < number; i++) { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 724 | vpn = batch->vpn[i]; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 725 | pte = batch->pte[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 727 | pte_iterate_hashed_subpages(pte, psize, |
| 728 | vpn, index, shift) { |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 729 | __tlbiel(vpn, psize, psize, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 730 | } pte_iterate_hashed_end(); |
| 731 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | asm volatile("ptesync":::"memory"); |
| 733 | } else { |
Matt Evans | 44ae3ab | 2011-04-06 19:48:50 +0000 | [diff] [blame] | 734 | int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
| 736 | if (lock_tlbie) |
Thomas Gleixner | 6b9c9b8 | 2010-02-18 02:22:35 +0000 | [diff] [blame] | 737 | raw_spin_lock(&native_tlbie_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
| 739 | asm volatile("ptesync":::"memory"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 740 | for (i = 0; i < number; i++) { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 741 | vpn = batch->vpn[i]; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 742 | pte = batch->pte[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 744 | pte_iterate_hashed_subpages(pte, psize, |
| 745 | vpn, index, shift) { |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 746 | __tlbie(vpn, psize, psize, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 747 | } pte_iterate_hashed_end(); |
| 748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | asm volatile("eieio; tlbsync; ptesync":::"memory"); |
| 750 | |
| 751 | if (lock_tlbie) |
Thomas Gleixner | 6b9c9b8 | 2010-02-18 02:22:35 +0000 | [diff] [blame] | 752 | raw_spin_unlock(&native_tlbie_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | local_irq_restore(flags); |
| 756 | } |
| 757 | |
Aneesh Kumar K.V | 83209bc | 2016-07-13 15:05:28 +0530 | [diff] [blame] | 758 | static int native_register_proc_table(unsigned long base, unsigned long page_size, |
| 759 | unsigned long table_size) |
Aneesh Kumar K.V | 50de596 | 2016-04-29 23:25:43 +1000 | [diff] [blame] | 760 | { |
Aneesh Kumar K.V | 83209bc | 2016-07-13 15:05:28 +0530 | [diff] [blame] | 761 | unsigned long patb1 = base << 25; /* VSID */ |
| 762 | |
| 763 | patb1 |= (page_size << 5); /* sllp */ |
| 764 | patb1 |= table_size; |
| 765 | |
Aneesh Kumar K.V | 50de596 | 2016-04-29 23:25:43 +1000 | [diff] [blame] | 766 | partition_tb->patb1 = cpu_to_be64(patb1); |
| 767 | return 0; |
| 768 | } |
| 769 | |
Michael Ellerman | 7d0daae | 2006-06-23 18:16:38 +1000 | [diff] [blame] | 770 | void __init hpte_init_native(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | { |
Benjamin Herrenschmidt | 7025776 | 2016-07-05 15:03:58 +1000 | [diff] [blame] | 772 | mmu_hash_ops.hpte_invalidate = native_hpte_invalidate; |
| 773 | mmu_hash_ops.hpte_updatepp = native_hpte_updatepp; |
| 774 | mmu_hash_ops.hpte_updateboltedpp = native_hpte_updateboltedpp; |
Anton Blanchard | 1b644f5 | 2017-06-28 11:32:35 +1000 | [diff] [blame] | 775 | mmu_hash_ops.hpte_removebolted = native_hpte_removebolted; |
Benjamin Herrenschmidt | 7025776 | 2016-07-05 15:03:58 +1000 | [diff] [blame] | 776 | mmu_hash_ops.hpte_insert = native_hpte_insert; |
| 777 | mmu_hash_ops.hpte_remove = native_hpte_remove; |
| 778 | mmu_hash_ops.hpte_clear_all = native_hpte_clear; |
| 779 | mmu_hash_ops.flush_hash_range = native_flush_hash_range; |
| 780 | mmu_hash_ops.hugepage_invalidate = native_hugepage_invalidate; |
Aneesh Kumar K.V | 50de596 | 2016-04-29 23:25:43 +1000 | [diff] [blame] | 781 | |
| 782 | if (cpu_has_feature(CPU_FTR_ARCH_300)) |
Michael Ellerman | eea8148 | 2016-08-04 15:32:06 +1000 | [diff] [blame] | 783 | register_process_table = native_register_proc_table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | } |