From patchwork Tue Mar 12 10:31:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 226919 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E025B2C02A4 for ; Tue, 12 Mar 2013 21:57:01 +1100 (EST) Received: from localhost ([::1]:45726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFMtA-0001Yz-47 for incoming@patchwork.ozlabs.org; Tue, 12 Mar 2013 06:57:00 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFMVm-0000Ly-K6 for qemu-devel@nongnu.org; Tue, 12 Mar 2013 06:33:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UFMV8-0004ox-0D for qemu-devel@nongnu.org; Tue, 12 Mar 2013 06:32:50 -0400 Received: from ozlabs.org ([203.10.76.45]:51599) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFMV7-0004jz-A3; Tue, 12 Mar 2013 06:32:09 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4F19F2C02CF; Tue, 12 Mar 2013 21:32:02 +1100 (EST) From: David Gibson To: agraf@suse.de Date: Tue, 12 Mar 2013 21:31:43 +1100 Message-Id: <1363084310-4115-42-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1363084310-4115-1-git-send-email-david@gibson.dropbear.id.au> References: <1363084310-4115-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 203.10.76.45 Cc: David Gibson , qemu-ppc@nongnu.org, afaerber@suse.de, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 41/48] mmu-hash*: Clean up real address calculation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org More recent 64-bit hash MMUs support multiple page sizes, and PTEs for large pages only include the offset of the whole large page. But the qemu tlb only handles pages of the base size (4k) so we need to break up the large pages into 4k pieces for the qemu tlb. To do that we have a somewhat awkward piece of code that adds the folds address bits 4k and the page size from the virtual address into the real address from the pte. This patch simplifies this redefining the raddr output of ppc_hash64_translate() to be the full real address of the faulting address, rather than just the (4k) page offset. Computing that turns out to be simpler, and is fine for the caller, since it already masks with TARGET_PAGE_MASK before inserting into the qemu tlb. The multiple page size complication doesn't exist for 32-bit hash mmus, but we make an analogous cleanup there for consistency. Signed-off-by: David Gibson --- target-ppc/mmu-hash32.c | 14 ++++++++++++-- target-ppc/mmu-hash64.c | 26 +++++++++++++++----------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/target-ppc/mmu-hash32.c b/target-ppc/mmu-hash32.c index 314b7d1..e5ee29b 100644 --- a/target-ppc/mmu-hash32.c +++ b/target-ppc/mmu-hash32.c @@ -343,6 +343,15 @@ static hwaddr ppc_hash32_htab_lookup(CPUPPCState *env, return pte_offset; } +static hwaddr ppc_hash32_pte_raddr(target_ulong sr, ppc_hash_pte32_t pte, + target_ulong eaddr) +{ + hwaddr rpn = pte.pte1; + hwaddr mask = ~TARGET_PAGE_MASK; + + return (rpn & ~mask) | (eaddr & mask); +} + static int ppc_hash32_translate(CPUPPCState *env, struct mmu_ctx_hash32 *ctx, target_ulong eaddr, int rwx) { @@ -421,8 +430,9 @@ static int ppc_hash32_translate(CPUPPCState *env, struct mmu_ctx_hash32 *ctx, ppc_hash32_store_hpte1(env, pte_offset, new_pte1); } - /* Keep the matching PTE informations */ - ctx->raddr = pte.pte1; + /* 9. Determine the real address from the PTE */ + + ctx->raddr = ppc_hash32_pte_raddr(sr, pte, eaddr); return 0; } diff --git a/target-ppc/mmu-hash64.c b/target-ppc/mmu-hash64.c index c76abb7..5e168d5 100644 --- a/target-ppc/mmu-hash64.c +++ b/target-ppc/mmu-hash64.c @@ -362,6 +362,18 @@ static hwaddr ppc_hash64_htab_lookup(CPUPPCState *env, return pte_offset; } +static hwaddr ppc_hash64_pte_raddr(ppc_slb_t *slb, ppc_hash_pte64_t pte, + target_ulong eaddr) +{ + hwaddr rpn = pte.pte1; + /* FIXME: Add support for SLLP extended page sizes */ + int target_page_bits = (slb->vsid & SLB_VSID_L) + ? TARGET_PAGE_BITS_16M : TARGET_PAGE_BITS; + hwaddr mask = (1ULL << target_page_bits) - 1; + + return (rpn & ~mask) | (eaddr & mask); +} + static int ppc_hash64_translate(CPUPPCState *env, struct mmu_ctx_hash64 *ctx, target_ulong eaddr, int rwx) { @@ -369,7 +381,6 @@ static int ppc_hash64_translate(CPUPPCState *env, struct mmu_ctx_hash64 *ctx, hwaddr pte_offset; ppc_hash_pte64_t pte; uint64_t new_pte1; - int target_page_bits; const int need_prot[] = {PAGE_READ, PAGE_WRITE, PAGE_EXEC}; assert((rwx == 0) || (rwx == 1) || (rwx == 2)); @@ -429,17 +440,10 @@ static int ppc_hash64_translate(CPUPPCState *env, struct mmu_ctx_hash64 *ctx, ppc_hash64_store_hpte1(env, pte_offset, new_pte1); } - /* Keep the matching PTE informations */ - ctx->raddr = pte.pte1; + /* 7. Determine the real address from the PTE */ + + ctx->raddr = ppc_hash64_pte_raddr(slb, pte, eaddr); - /* We have a TLB that saves 4K pages, so let's - * split a huge page to 4k chunks */ - target_page_bits = (slb->vsid & SLB_VSID_L) - ? TARGET_PAGE_BITS_16M : TARGET_PAGE_BITS; - if (target_page_bits != TARGET_PAGE_BITS) { - ctx->raddr |= (eaddr & ((1 << target_page_bits) - 1)) - & TARGET_PAGE_MASK; - } return 0; }