| 1 | /* |
| 2 | * PowerPC ISAV3 BookS emulation generic mmu helpers for qemu. |
| 3 | * |
| 4 | * Copyright (c) 2017 Suraj Jitindar Singh, IBM Corporation |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library 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 GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "qemu/osdep.h" |
| 21 | #include "system/memory.h" |
| 22 | #include "cpu.h" |
| 23 | #include "mmu-hash64.h" |
| 24 | #include "mmu-book3s-v3.h" |
| 25 | |
| 26 | #define PPC64_V3_PATE_SIZE 16 /* two 64-bit words */ |
| 27 | |
| 28 | bool ppc64_v3_get_pate(PowerPCCPU *cpu, target_ulong lpid, ppc_v3_pate_t *entry) |
| 29 | { |
| 30 | uint64_t patb = cpu->env.spr[SPR_PTCR] & PTCR_PATB; |
| 31 | uint64_t pats = cpu->env.spr[SPR_PTCR] & PTCR_PATS; |
| 32 | uint64_t table_size; |
| 33 | uint64_t entries; |
| 34 | |
| 35 | /* |
| 36 | * The POWER9 Processor User's Manual, section 4.9.4, specifies that |
| 37 | * POWER9 ignores PTCR[PATS] and only supports a 64 KiB partition table. |
| 38 | */ |
| 39 | if (cpu->env.excp_model == POWERPC_EXCP_POWER9) { |
| 40 | pats = 4; |
| 41 | } |
| 42 | table_size = 1ULL << (pats + 12); |
| 43 | |
| 44 | /* Check if partition table is properly aligned */ |
| 45 | if (patb & (table_size - 1)) { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | /* Calculate number of entries */ |
| 50 | entries = table_size / PPC64_V3_PATE_SIZE; |
| 51 | if (entries <= lpid) { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | /* Grab entry */ |
| 56 | patb += PPC64_V3_PATE_SIZE * lpid; |
| 57 | entry->dw0 = ldq_phys(CPU(cpu)->as, patb); |
| 58 | entry->dw1 = ldq_phys(CPU(cpu)->as, patb + 8); |
| 59 | return true; |
| 60 | } |