Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 1 | /* |
| 2 | * PS3 pagetable management routines. |
| 3 | * |
| 4 | * Copyright (C) 2006 Sony Computer Entertainment Inc. |
Geert Uytterhoeven | 36dff96 | 2007-02-12 00:55:26 -0800 | [diff] [blame] | 5 | * Copyright 2006, 2007 Sony Corporation |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <linux/kernel.h> |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 22 | #include <linux/memblock.h> |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 23 | |
| 24 | #include <asm/machdep.h> |
David S. Miller | d9b2b2a | 2008-02-13 16:56:49 -0800 | [diff] [blame] | 25 | #include <asm/prom.h> |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 26 | #include <asm/udbg.h> |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 27 | #include <asm/lv1call.h> |
Geert Uytterhoeven | 36dff96 | 2007-02-12 00:55:26 -0800 | [diff] [blame] | 28 | #include <asm/ps3fb.h> |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 29 | |
Geoff Levand | 97db7f7 | 2013-02-13 17:03:16 +0000 | [diff] [blame] | 30 | #define PS3_VERBOSE_RESULT |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 31 | #include "platform.h" |
| 32 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 33 | /** |
| 34 | * enum lpar_vas_id - id of LPAR virtual address space. |
| 35 | * @lpar_vas_id_current: Current selected virtual address space |
| 36 | * |
| 37 | * Identify the target LPAR address space. |
| 38 | */ |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 39 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 40 | enum ps3_lpar_vas_id { |
| 41 | PS3_LPAR_VAS_ID_CURRENT = 0, |
| 42 | }; |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 43 | |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 44 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 45 | static DEFINE_SPINLOCK(ps3_htab_lock); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 46 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 47 | static long ps3_hpte_insert(unsigned long hpte_group, unsigned long vpn, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 48 | unsigned long pa, unsigned long rflags, unsigned long vflags, |
| 49 | int psize, int ssize) |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 50 | { |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 51 | int result; |
| 52 | u64 hpte_v, hpte_r; |
| 53 | u64 inserted_index; |
| 54 | u64 evicted_v, evicted_r; |
| 55 | u64 hpte_v_array[4], hpte_rs; |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 56 | unsigned long flags; |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 57 | long ret = -1; |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 58 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 59 | /* |
| 60 | * lv1_insert_htab_entry() will search for victim |
| 61 | * entry in both primary and secondary pte group |
| 62 | */ |
| 63 | vflags &= ~HPTE_V_SECONDARY; |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 64 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 65 | hpte_v = hpte_encode_v(vpn, psize, ssize) | vflags | HPTE_V_VALID; |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 66 | hpte_r = hpte_encode_r(ps3_mm_phys_to_lpar(pa), psize) | rflags; |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 67 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 68 | spin_lock_irqsave(&ps3_htab_lock, flags); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 69 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 70 | /* talk hvc to replace entries BOLTED == 0 */ |
| 71 | result = lv1_insert_htab_entry(PS3_LPAR_VAS_ID_CURRENT, hpte_group, |
| 72 | hpte_v, hpte_r, |
| 73 | HPTE_V_BOLTED, 0, |
| 74 | &inserted_index, |
| 75 | &evicted_v, &evicted_r); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 76 | |
| 77 | if (result) { |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 78 | /* all entries bolted !*/ |
Geoff Levand | 97db7f7 | 2013-02-13 17:03:16 +0000 | [diff] [blame] | 79 | pr_info("%s:result=%s vpn=%lx pa=%lx ix=%lx v=%llx r=%llx\n", |
| 80 | __func__, ps3_result(result), vpn, pa, hpte_group, |
| 81 | hpte_v, hpte_r); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 82 | BUG(); |
| 83 | } |
| 84 | |
| 85 | /* |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 86 | * see if the entry is inserted into secondary pteg |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 87 | */ |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 88 | result = lv1_read_htab_entries(PS3_LPAR_VAS_ID_CURRENT, |
| 89 | inserted_index & ~0x3UL, |
| 90 | &hpte_v_array[0], &hpte_v_array[1], |
| 91 | &hpte_v_array[2], &hpte_v_array[3], |
| 92 | &hpte_rs); |
| 93 | BUG_ON(result); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 94 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 95 | if (hpte_v_array[inserted_index % 4] & HPTE_V_SECONDARY) |
| 96 | ret = (inserted_index & 7) | (1 << 3); |
| 97 | else |
| 98 | ret = inserted_index & 7; |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 99 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 100 | spin_unlock_irqrestore(&ps3_htab_lock, flags); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 101 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 102 | return ret; |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static long ps3_hpte_remove(unsigned long hpte_group) |
| 106 | { |
| 107 | panic("ps3_hpte_remove() not implemented"); |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static long ps3_hpte_updatepp(unsigned long slot, unsigned long newpp, |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 112 | unsigned long vpn, int psize, int ssize, int local) |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 113 | { |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 114 | int result; |
| 115 | u64 hpte_v, want_v, hpte_rs; |
| 116 | u64 hpte_v_array[4]; |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 117 | unsigned long flags; |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 118 | long ret; |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 119 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 120 | want_v = hpte_encode_v(vpn, psize, ssize); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 121 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 122 | spin_lock_irqsave(&ps3_htab_lock, flags); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 123 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 124 | result = lv1_read_htab_entries(PS3_LPAR_VAS_ID_CURRENT, slot & ~0x3UL, |
| 125 | &hpte_v_array[0], &hpte_v_array[1], |
| 126 | &hpte_v_array[2], &hpte_v_array[3], |
| 127 | &hpte_rs); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 128 | |
| 129 | if (result) { |
Geoff Levand | 97db7f7 | 2013-02-13 17:03:16 +0000 | [diff] [blame] | 130 | pr_info("%s: result=%s read vpn=%lx slot=%lx psize=%d\n", |
| 131 | __func__, ps3_result(result), vpn, slot, psize); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 132 | BUG(); |
| 133 | } |
| 134 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 135 | hpte_v = hpte_v_array[slot % 4]; |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 136 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 137 | /* |
| 138 | * As lv1_read_htab_entries() does not give us the RPN, we can |
| 139 | * not synthesize the new hpte_r value here, and therefore can |
| 140 | * not update the hpte with lv1_insert_htab_entry(), so we |
Uwe Kleine-König | fd0961f | 2010-06-11 12:16:56 +0200 | [diff] [blame] | 141 | * instead invalidate it and ask the caller to update it via |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 142 | * ps3_hpte_insert() by returning a -1 value. |
| 143 | */ |
| 144 | if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) { |
| 145 | /* not found */ |
| 146 | ret = -1; |
| 147 | } else { |
| 148 | /* entry found, just invalidate it */ |
| 149 | result = lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, |
| 150 | slot, 0, 0); |
| 151 | ret = -1; |
| 152 | } |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 153 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 154 | spin_unlock_irqrestore(&ps3_htab_lock, flags); |
| 155 | return ret; |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static void ps3_hpte_updateboltedpp(unsigned long newpp, unsigned long ea, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 159 | int psize, int ssize) |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 160 | { |
| 161 | panic("ps3_hpte_updateboltedpp() not implemented"); |
| 162 | } |
| 163 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 164 | static void ps3_hpte_invalidate(unsigned long slot, unsigned long vpn, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 165 | int psize, int ssize, int local) |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 166 | { |
| 167 | unsigned long flags; |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 168 | int result; |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 169 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 170 | spin_lock_irqsave(&ps3_htab_lock, flags); |
| 171 | |
| 172 | result = lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, slot, 0, 0); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 173 | |
| 174 | if (result) { |
Geoff Levand | 97db7f7 | 2013-02-13 17:03:16 +0000 | [diff] [blame] | 175 | pr_info("%s: result=%s vpn=%lx slot=%lx psize=%d\n", |
| 176 | __func__, ps3_result(result), vpn, slot, psize); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 177 | BUG(); |
| 178 | } |
| 179 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 180 | spin_unlock_irqrestore(&ps3_htab_lock, flags); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static void ps3_hpte_clear(void) |
| 184 | { |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 185 | unsigned long hpte_count = (1UL << ppc64_pft_size) >> 4; |
| 186 | u64 i; |
Geert Uytterhoeven | 36dff96 | 2007-02-12 00:55:26 -0800 | [diff] [blame] | 187 | |
Masakazu Mokuno | 9cfeb74 | 2008-08-21 06:18:51 +1000 | [diff] [blame] | 188 | for (i = 0; i < hpte_count; i++) |
| 189 | lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, i, 0, 0); |
Geoff Levand | 9263e85 | 2007-06-16 07:19:32 +1000 | [diff] [blame] | 190 | |
| 191 | ps3_mm_shutdown(); |
| 192 | ps3_mm_vas_destroy(); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | void __init ps3_hpte_init(unsigned long htab_size) |
| 196 | { |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 197 | ppc_md.hpte_invalidate = ps3_hpte_invalidate; |
| 198 | ppc_md.hpte_updatepp = ps3_hpte_updatepp; |
| 199 | ppc_md.hpte_updateboltedpp = ps3_hpte_updateboltedpp; |
| 200 | ppc_md.hpte_insert = ps3_hpte_insert; |
| 201 | ppc_md.hpte_remove = ps3_hpte_remove; |
| 202 | ppc_md.hpte_clear_all = ps3_hpte_clear; |
| 203 | |
| 204 | ppc64_pft_size = __ilog2(htab_size); |
Geoff Levand | c6cec72 | 2006-11-23 00:46:54 +0100 | [diff] [blame] | 205 | } |
| 206 | |