From patchwork Wed Mar 6 03:44:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 225279 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 0B53D2C0374 for ; Wed, 6 Mar 2013 14:56:58 +1100 (EST) Received: from localhost ([::1]:55633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD5TM-0005rS-9s for incoming@patchwork.ozlabs.org; Tue, 05 Mar 2013 22:56:56 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD5IH-0004Fs-3r for qemu-devel@nongnu.org; Tue, 05 Mar 2013 22:46:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UD5Hi-0007uS-GW for qemu-devel@nongnu.org; Tue, 05 Mar 2013 22:45:28 -0500 Received: from ozlabs.org ([203.10.76.45]:60671) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD5Hh-0007o3-Qj; Tue, 05 Mar 2013 22:44:54 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 861742C039E; Wed, 6 Mar 2013 14:44:43 +1100 (EST) From: David Gibson To: agraf@suse.de Date: Wed, 6 Mar 2013 14:44:21 +1100 Message-Id: <1362541473-4365-34-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1362541473-4365-1-git-send-email-david@gibson.dropbear.id.au> References: <1362541473-4365-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 33/45] mmu-hash32: Clean up BAT matching logic 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 The code to search for a matching BAT for a virtual address is somewhat longwinded and awkward. In particular, it relies on seperate size and validity information being returned from the hash32_bat_size() function (and 601 specific variant). We simplify this by having hash32_bat_size() return instead a mask of the virtual address bits to match, and 0 for invalid (since a BAT can never match the entire address space). Signed-off-by: David Gibson --- target-ppc/mmu-hash32.c | 74 +++++++++++++++++++---------------------------- target-ppc/mmu-hash32.h | 4 --- 2 files changed, 30 insertions(+), 48 deletions(-) diff --git a/target-ppc/mmu-hash32.c b/target-ppc/mmu-hash32.c index 6c71ebd..40d3564 100644 --- a/target-ppc/mmu-hash32.c +++ b/target-ppc/mmu-hash32.c @@ -113,20 +113,15 @@ static int ppc_hash32_check_prot(int prot, int rwx) return ret; } -static void hash32_bat_size(CPUPPCState *env, target_ulong *blp, int *validp, - target_ulong batu, target_ulong batl) +static target_ulong hash32_bat_size(CPUPPCState *env, + target_ulong batu, target_ulong batl) { - target_ulong bl; - int valid; - - bl = (batu & BATU32_BL) << 15; - valid = 0; - if (((msr_pr == 0) && (batu & BATU32_VS)) || - ((msr_pr != 0) && (batu & BATU32_VP))) { - valid = 1; + if ((msr_pr && !(batu & BATU32_VP)) + || (!msr_pr && !(batu & BATU32_VS))) { + return 0; } - *blp = bl; - *validp = valid; + + return BATU32_BEPI & ~((batu & BATU32_BL) << 15); } static int hash32_bat_prot(CPUPPCState *env, @@ -145,18 +140,14 @@ static int hash32_bat_prot(CPUPPCState *env, return prot; } -static void hash32_bat_601_size(CPUPPCState *env, target_ulong *blp, int *validp, +static target_ulong hash32_bat_601_size(CPUPPCState *env, target_ulong batu, target_ulong batl) { - target_ulong bl; - int valid; - - bl = (batl & BATL32_601_BL) << 17; - LOG_BATS("b %02x ==> bl " TARGET_FMT_lx " msk " TARGET_FMT_lx "\n", - (uint8_t)(batl & BATL32_601_BL), bl, ~bl); - valid = !!(batl & BATL32_601_V); - *blp = bl; - *validp = valid; + if (!(batl & BATL32_601_V)) { + return 0; + } + + return BATU32_BEPI & ~((batl & BATL32_601_BL) << 17); } static int hash32_bat_601_prot(CPUPPCState *env, @@ -177,8 +168,7 @@ static int ppc_hash32_get_bat(CPUPPCState *env, struct mmu_ctx_hash32 *ctx, target_ulong virtual, int rwx) { target_ulong *BATlt, *BATut; - target_ulong BEPIl, BEPIu, bl; - int i, valid, prot; + int i, prot; int ret = -1; LOG_BATS("%s: %cBAT v " TARGET_FMT_lx "\n", __func__, @@ -193,37 +183,33 @@ static int ppc_hash32_get_bat(CPUPPCState *env, struct mmu_ctx_hash32 *ctx, for (i = 0; i < env->nb_BATs; i++) { target_ulong batu = BATut[i]; target_ulong batl = BATlt[i]; + target_ulong mask; - BEPIu = batu & BATU32_BEPIU; - BEPIl = batu & BATU32_BEPIL; if (unlikely(env->mmu_model == POWERPC_MMU_601)) { - hash32_bat_601_size(env, &bl, &valid, batu, batl); + mask = hash32_bat_601_size(env, batu, batl); prot = hash32_bat_601_prot(env, batu, batl); } else { - hash32_bat_size(env, &bl, &valid, batu, batl); + mask = hash32_bat_size(env, batu, batl); prot = hash32_bat_prot(env, batu, batl); } LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx " BATl " TARGET_FMT_lx "\n", __func__, type == ACCESS_CODE ? 'I' : 'D', i, virtual, batu, batl); - if ((virtual & BATU32_BEPIU) == BEPIu && - ((virtual & BATU32_BEPIL) & ~bl) == BEPIl) { + + if (mask && ((virtual & mask) == (batu & BATU32_BEPI))) { /* BAT matches */ - if (valid != 0) { - /* Get physical address */ - ctx->raddr = (batl & BATL32_BRPNU) | - ((virtual & BATU32_BEPIL & bl) | (batl & BATL32_BRPNL)) | - (virtual & 0x0001F000); - /* Compute access rights */ - ctx->prot = prot; - ret = ppc_hash32_check_prot(ctx->prot, rwx); - if (ret == 0) { - LOG_BATS("BAT %d match: r " TARGET_FMT_plx " prot=%c%c\n", - i, ctx->raddr, ctx->prot & PAGE_READ ? 'R' : '-', - ctx->prot & PAGE_WRITE ? 'W' : '-'); - } - break; + /* Get physical address */ + ctx->raddr = (batl & mask) | (virtual & ~mask); + ctx->raddr &= TARGET_PAGE_MASK; + /* Compute access rights */ + ctx->prot = prot; + ret = ppc_hash32_check_prot(ctx->prot, rwx); + if (ret == 0) { + LOG_BATS("BAT %d match: r " TARGET_FMT_plx " prot=%c%c\n", + i, ctx->raddr, ctx->prot & PAGE_READ ? 'R' : '-', + ctx->prot & PAGE_WRITE ? 'W' : '-'); } + break; } } if (ret < 0) { diff --git a/target-ppc/mmu-hash32.h b/target-ppc/mmu-hash32.h index d6e9330..06cd0e6 100644 --- a/target-ppc/mmu-hash32.h +++ b/target-ppc/mmu-hash32.h @@ -20,16 +20,12 @@ int ppc_hash32_handle_mmu_fault(CPUPPCState *env, target_ulong address, int rw, * Block Address Translation (BAT) definitions */ -#define BATU32_BEPIU 0xf0000000 -#define BATU32_BEPIL 0x0ffe0000 #define BATU32_BEPI 0xfffe0000 #define BATU32_BL 0x00001ffc #define BATU32_VS 0x00000002 #define BATU32_VP 0x00000001 -#define BATL32_BRPNU 0xf0000000 -#define BATL32_BRPNL 0x0ffe0000 #define BATL32_BRPN 0xfffe0000 #define BATL32_WIMG 0x00000078 #define BATL32_PP 0x00000003