xref: /openbmc/qemu/target/ppc/mmu-book3s-v3.c (revision 93b799fafd9170da3a79a533ea6f73a18de82e22)
1b2899495SSuraj Jitindar Singh /*
2b2899495SSuraj Jitindar Singh  *  PowerPC ISAV3 BookS emulation generic mmu helpers for qemu.
3b2899495SSuraj Jitindar Singh  *
4b2899495SSuraj Jitindar Singh  *  Copyright (c) 2017 Suraj Jitindar Singh, IBM Corporation
5b2899495SSuraj Jitindar Singh  *
6b2899495SSuraj Jitindar Singh  * This library is free software; you can redistribute it and/or
7b2899495SSuraj Jitindar Singh  * modify it under the terms of the GNU Lesser General Public
8b2899495SSuraj Jitindar Singh  * License as published by the Free Software Foundation; either
96bd039cdSChetan Pant  * version 2.1 of the License, or (at your option) any later version.
10b2899495SSuraj Jitindar Singh  *
11b2899495SSuraj Jitindar Singh  * This library is distributed in the hope that it will be useful,
12b2899495SSuraj Jitindar Singh  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13b2899495SSuraj Jitindar Singh  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14b2899495SSuraj Jitindar Singh  * Lesser General Public License for more details.
15b2899495SSuraj Jitindar Singh  *
16b2899495SSuraj Jitindar Singh  * You should have received a copy of the GNU Lesser General Public
17b2899495SSuraj Jitindar Singh  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18b2899495SSuraj Jitindar Singh  */
19b2899495SSuraj Jitindar Singh 
20b2899495SSuraj Jitindar Singh #include "qemu/osdep.h"
21b2899495SSuraj Jitindar Singh #include "cpu.h"
22b2899495SSuraj Jitindar Singh #include "mmu-hash64.h"
23b2899495SSuraj Jitindar Singh #include "mmu-book3s-v3.h"
24b2899495SSuraj Jitindar Singh 
ppc64_v3_get_pate(PowerPCCPU * cpu,target_ulong lpid,ppc_v3_pate_t * entry)253367c62fSBenjamin Herrenschmidt bool ppc64_v3_get_pate(PowerPCCPU *cpu, target_ulong lpid, ppc_v3_pate_t *entry)
263367c62fSBenjamin Herrenschmidt {
273367c62fSBenjamin Herrenschmidt     uint64_t patb = cpu->env.spr[SPR_PTCR] & PTCR_PATB;
283367c62fSBenjamin Herrenschmidt     uint64_t pats = cpu->env.spr[SPR_PTCR] & PTCR_PATS;
293367c62fSBenjamin Herrenschmidt 
30*3c2e80adSLeandro Lupori     /* Check if partition table is properly aligned */
31*3c2e80adSLeandro Lupori     if (patb & MAKE_64BIT_MASK(0, pats + 12)) {
32*3c2e80adSLeandro Lupori         return false;
33*3c2e80adSLeandro Lupori     }
34*3c2e80adSLeandro Lupori 
353367c62fSBenjamin Herrenschmidt     /* Calculate number of entries */
363367c62fSBenjamin Herrenschmidt     pats = 1ull << (pats + 12 - 4);
373367c62fSBenjamin Herrenschmidt     if (pats <= lpid) {
383367c62fSBenjamin Herrenschmidt         return false;
393367c62fSBenjamin Herrenschmidt     }
403367c62fSBenjamin Herrenschmidt 
413367c62fSBenjamin Herrenschmidt     /* Grab entry */
423367c62fSBenjamin Herrenschmidt     patb += 16 * lpid;
433367c62fSBenjamin Herrenschmidt     entry->dw0 = ldq_phys(CPU(cpu)->as, patb);
443367c62fSBenjamin Herrenschmidt     entry->dw1 = ldq_phys(CPU(cpu)->as, patb + 8);
453367c62fSBenjamin Herrenschmidt     return true;
463367c62fSBenjamin Herrenschmidt }
47