xref: /openbmc/qemu/target/ppc/mmu-book3s-v3.c (revision 3c2e80ad2fcf004fcf74bf690dc1c952320a5b52)
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"
24d5fee0bbSSuraj Jitindar Singh #include "mmu-radix64.h"
25b2899495SSuraj Jitindar Singh 
263367c62fSBenjamin Herrenschmidt bool ppc64_v3_get_pate(PowerPCCPU *cpu, target_ulong lpid, ppc_v3_pate_t *entry)
273367c62fSBenjamin Herrenschmidt {
283367c62fSBenjamin Herrenschmidt     uint64_t patb = cpu->env.spr[SPR_PTCR] & PTCR_PATB;
293367c62fSBenjamin Herrenschmidt     uint64_t pats = cpu->env.spr[SPR_PTCR] & PTCR_PATS;
303367c62fSBenjamin Herrenschmidt 
31*3c2e80adSLeandro Lupori     /* Check if partition table is properly aligned */
32*3c2e80adSLeandro Lupori     if (patb & MAKE_64BIT_MASK(0, pats + 12)) {
33*3c2e80adSLeandro Lupori         return false;
34*3c2e80adSLeandro Lupori     }
35*3c2e80adSLeandro Lupori 
363367c62fSBenjamin Herrenschmidt     /* Calculate number of entries */
373367c62fSBenjamin Herrenschmidt     pats = 1ull << (pats + 12 - 4);
383367c62fSBenjamin Herrenschmidt     if (pats <= lpid) {
393367c62fSBenjamin Herrenschmidt         return false;
403367c62fSBenjamin Herrenschmidt     }
413367c62fSBenjamin Herrenschmidt 
423367c62fSBenjamin Herrenschmidt     /* Grab entry */
433367c62fSBenjamin Herrenschmidt     patb += 16 * lpid;
443367c62fSBenjamin Herrenschmidt     entry->dw0 = ldq_phys(CPU(cpu)->as, patb);
453367c62fSBenjamin Herrenschmidt     entry->dw1 = ldq_phys(CPU(cpu)->as, patb + 8);
463367c62fSBenjamin Herrenschmidt     return true;
473367c62fSBenjamin Herrenschmidt }
48