From patchwork Wed Mar 6 03:44:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 225299 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 282D22C0336 for ; Wed, 6 Mar 2013 15:28:41 +1100 (EST) Received: from localhost ([::1]:59169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD5UL-0007mV-Od for incoming@patchwork.ozlabs.org; Tue, 05 Mar 2013 22:57:57 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51638) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD5II-0004J1-IB for qemu-devel@nongnu.org; Tue, 05 Mar 2013 22:46:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UD5Hi-0007vO-Vy for qemu-devel@nongnu.org; Tue, 05 Mar 2013 22:45:30 -0500 Received: from ozlabs.org ([2402:b800:7003:1:1::1]:36091) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD5Hi-0007nx-75; Tue, 05 Mar 2013 22:44:54 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 907B22C03A0; Wed, 6 Mar 2013 14:44:43 +1100 (EST) From: David Gibson To: agraf@suse.de Date: Wed, 6 Mar 2013 14:44:22 +1100 Message-Id: <1362541473-4365-35-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: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2402:b800:7003:1:1::1 Cc: David Gibson , qemu-ppc@nongnu.org, afaerber@suse.de, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 34/45] mmu-hash32: Cleanup BAT lookup 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 This patch makes a general cleanup of the ppc_hash32_get_bat() function, renaming it to ppc_hash32_bat_lookup(). In particular, the new function only looks for a matching BAT, with the permissions check from the old function moved to the caller. Signed-off-by: David Gibson --- target-ppc/mmu-hash32.c | 82 ++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/target-ppc/mmu-hash32.c b/target-ppc/mmu-hash32.c index 40d3564..d4d91dd 100644 --- a/target-ppc/mmu-hash32.c +++ b/target-ppc/mmu-hash32.c @@ -164,15 +164,14 @@ static int hash32_bat_601_prot(CPUPPCState *env, return ppc_hash32_pp_check(key, pp, 0); } -static int ppc_hash32_get_bat(CPUPPCState *env, struct mmu_ctx_hash32 *ctx, - target_ulong virtual, int rwx) +static hwaddr ppc_hash32_bat_lookup(CPUPPCState *env, target_ulong ea, int rwx, + int *prot) { target_ulong *BATlt, *BATut; - int i, prot; - int ret = -1; + int i; LOG_BATS("%s: %cBAT v " TARGET_FMT_lx "\n", __func__, - rwx == 2 ? 'I' : 'D', virtual); + rwx == 2 ? 'I' : 'D', ea); if (rwx == 2) { BATlt = env->IBAT[1]; BATut = env->IBAT[0]; @@ -187,52 +186,46 @@ static int ppc_hash32_get_bat(CPUPPCState *env, struct mmu_ctx_hash32 *ctx, if (unlikely(env->mmu_model == POWERPC_MMU_601)) { mask = hash32_bat_601_size(env, batu, batl); - prot = hash32_bat_601_prot(env, batu, batl); } else { 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 (mask && ((virtual & mask) == (batu & BATU32_BEPI))) { - /* BAT matches */ - /* 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' : '-'); + type == ACCESS_CODE ? 'I' : 'D', i, ea, batu, batl); + + if (mask && ((ea & mask) == (batu & BATU32_BEPI))) { + hwaddr raddr = (batl & mask) | (ea & ~mask); + + if (unlikely(env->mmu_model == POWERPC_MMU_601)) { + *prot = hash32_bat_601_prot(env, batu, batl); + } else { + *prot = hash32_bat_prot(env, batu, batl); } - break; + + return raddr & TARGET_PAGE_MASK; } } - if (ret < 0) { + + /* No hit */ #if defined(DEBUG_BATS) - if (qemu_log_enabled()) { - LOG_BATS("no BAT match for " TARGET_FMT_lx ":\n", virtual); - for (i = 0; i < 4; i++) { - BATu = &BATut[i]; - BATl = &BATlt[i]; - BEPIu = *BATu & BATU32_BEPIU; - BEPIl = *BATu & BATU32_BEPIL; - bl = (*BATu & 0x00001FFC) << 15; - LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx - " BATl " TARGET_FMT_lx "\n\t" TARGET_FMT_lx " " - TARGET_FMT_lx " " TARGET_FMT_lx "\n", - __func__, type == ACCESS_CODE ? 'I' : 'D', i, virtual, - *BATu, *BATl, BEPIu, BEPIl, bl); - } + if (qemu_log_enabled()) { + LOG_BATS("no BAT match for " TARGET_FMT_lx ":\n", ea); + for (i = 0; i < 4; i++) { + BATu = &BATut[i]; + BATl = &BATlt[i]; + BEPIu = *BATu & BATU32_BEPIU; + BEPIl = *BATu & BATU32_BEPIL; + bl = (*BATu & 0x00001FFC) << 15; + LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx + " BATl " TARGET_FMT_lx "\n\t" TARGET_FMT_lx " " + TARGET_FMT_lx " " TARGET_FMT_lx "\n", + __func__, type == ACCESS_CODE ? 'I' : 'D', i, ea, + *BATu, *BATl, BEPIu, BEPIl, bl); } -#endif } - /* No hit */ - return ret; +#endif + + return -1; } static int ppc_hash32_direct_store(CPUPPCState *env, target_ulong sr, @@ -405,9 +398,12 @@ static int ppc_hash32_translate(CPUPPCState *env, struct mmu_ctx_hash32 *ctx, /* 2. Check Block Address Translation entries (BATs) */ if (env->nb_BATs != 0) { - ret = ppc_hash32_get_bat(env, ctx, eaddr, rwx); - if (ret == 0) { - return 0; + ctx->raddr = ppc_hash32_bat_lookup(env, eaddr, rwx, &ctx->prot); + if (ctx->raddr != -1) { + ret = ppc_hash32_check_prot(ctx->prot, rwx); + if (ret == 0) { + return 0; + } } }