From patchwork Mon May 3 07:29:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Igor V. Kovalenko" X-Patchwork-Id: 51482 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 76B50B7BEE for ; Mon, 3 May 2010 18:06:31 +1000 (EST) Received: from localhost ([127.0.0.1]:33245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O8qa1-0005fV-1f for incoming@patchwork.ozlabs.org; Mon, 03 May 2010 04:00:41 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O8q6U-0006gi-BU for qemu-devel@nongnu.org; Mon, 03 May 2010 03:30:10 -0400 Received: from [140.186.70.92] (port=53492 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O8q6I-0006dV-Al for qemu-devel@nongnu.org; Mon, 03 May 2010 03:30:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O8q68-0003SX-MI for qemu-devel@nongnu.org; Mon, 03 May 2010 03:29:57 -0400 Received: from mail-fx0-f45.google.com ([209.85.161.45]:47992) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O8q61-0003O9-Nr for qemu-devel@nongnu.org; Mon, 03 May 2010 03:29:45 -0400 Received: by mail-fx0-f45.google.com with SMTP id 12so1871356fxm.4 for ; Mon, 03 May 2010 00:29:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:subject:to:from:date :message-id:in-reply-to:references:user-agent:mime-version :content-type:content-transfer-encoding; bh=jdcIQm6RESFb99soypmKCLmN8xprzr4b3snUPkKjNZM=; b=bv8rkLO4xxJBsgv9NYqfhbC8M2mvUVo4vYDCaXqVC+cPZIusNgXxZ7Ux1HeER2Wto2 TX1fc18SvGf3WXAqKOoBH1C4Uf5Z1OwQydXibqpU+nm4snxfFYoHwvHB3/TZ0zrJNgBX S94Q7ivulCBKuAn5VQG7o7ux/hK7ip6wtitiY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:to:from:date:message-id:in-reply-to:references:user-agent :mime-version:content-type:content-transfer-encoding; b=wyLjk/cS3hW3xO47SjMvDtmRhfoV5uKCcsEa3qiani/yFIErExshRTsGaGBo89GWJZ h82uk18ZrG+9yFz2oH7I50hb8AC/V5FraZVqvLEhA/qjPNRMUzxOQSLB5l6bnJcqeXlI JbAFVjxjKvRwqjFJ57dH3PEoCGaB/jzEK7DYQ= Received: by 10.102.170.16 with SMTP id s16mr8645834mue.16.1272871781254; Mon, 03 May 2010 00:29:41 -0700 (PDT) Received: from skyserv ([87.255.14.75]) by mx.google.com with ESMTPS id e10sm19169556muf.8.2010.05.03.00.29.40 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 03 May 2010 00:29:40 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=[192.168.1.2]) by skyserv with esmtp (Exim 4.71) (envelope-from ) id 1O8q5z-00008V-LU for qemu-devel@nongnu.org; Mon, 03 May 2010 11:29:39 +0400 To: qemu-devel@nongnu.org From: "Igor V. Kovalenko" Date: Mon, 03 May 2010 11:29:39 +0400 Message-ID: <20100503072939.367.3130.stgit@skyserv> In-Reply-To: <20100503072448.367.7010.stgit@skyserv> References: <20100503072448.367.7010.stgit@skyserv> User-Agent: StGit/0.15 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 2/3] sparc64: implement global translation table entries X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Igor V. Kovalenko - match global tte against any context - show global tte in MMU dump Signed-off-by: Igor V. Kovalenko --- target-sparc/cpu.h | 18 ++++++++++++++++ target-sparc/helper.c | 33 ++++++++++++----------------- target-sparc/op_helper.c | 52 ++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 75 insertions(+), 28 deletions(-) diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h index 0e7f390..b705728 100644 --- a/target-sparc/cpu.h +++ b/target-sparc/cpu.h @@ -513,6 +513,24 @@ static inline void cpu_set_cwp(CPUSPARCState *env1, int new_cwp) /* sun4m.c, sun4u.c */ void cpu_check_irqs(CPUSPARCState *env); +#if defined (TARGET_SPARC64) + +static inline int compare_masked(uint64_t x, uint64_t y, uint64_t mask) +{ + return (x & mask) == (y & mask); +} + +#define MMU_CONTEXT_BITS 13 +#define MMU_CONTEXT_MASK ((1 << MMU_CONTEXT_BITS) - 1) + +static inline int tlb_compare_context(const SparcTLBEntry *tlb, + uint64_t context) +{ + return compare_masked(context, tlb->tag, MMU_CONTEXT_MASK); +} + +#endif + static inline void PUT_PSR(CPUSPARCState *env1, target_ulong val) { env1->psr = val & PSR_ICC; diff --git a/target-sparc/helper.c b/target-sparc/helper.c index 1f0f7d4..4ece01b 100644 --- a/target-sparc/helper.c +++ b/target-sparc/helper.c @@ -381,17 +381,11 @@ static inline target_phys_addr_t ultrasparc_truncate_physical(uint64_t x) * UltraSparc IIi I/DMMUs */ -static inline int compare_masked(uint64_t x, uint64_t y, uint64_t mask) -{ - return (x & mask) == (y & mask); -} - // Returns true if TTE tag is valid and matches virtual address value in context // requires virtual address mask value calculated from TTE entry size static inline int ultrasparc_tag_match(SparcTLBEntry *tlb, uint64_t address, uint64_t context, - target_phys_addr_t *physical, - int is_nucleus) + target_phys_addr_t *physical) { uint64_t mask; @@ -413,8 +407,7 @@ static inline int ultrasparc_tag_match(SparcTLBEntry *tlb, // valid, context match, virtual address match? if (TTE_IS_VALID(tlb->tte) && - ((is_nucleus && compare_masked(0, tlb->tag, 0x1fff)) - || TTE_IS_GLOBAL(tlb->tte) || compare_masked(context, tlb->tag, 0x1fff)) + (TTE_IS_GLOBAL(tlb->tte) || tlb_compare_context(tlb, context)) && compare_masked(address, tlb->tag, mask)) { // decode physical address @@ -431,7 +424,6 @@ static int get_physical_address_data(CPUState *env, { unsigned int i; uint64_t context; - int is_nucleus; if ((env->lsu & DMMU_E) == 0) { /* DMMU disabled */ *physical = ultrasparc_truncate_physical(address); @@ -439,14 +431,16 @@ static int get_physical_address_data(CPUState *env, return 0; } - context = env->dmmu.mmu_primary_context & 0x1fff; - is_nucleus = env->tl > 0; + if (env->tl == 0) { + context = env->dmmu.mmu_primary_context & 0x1fff; + } else { + context = 0; + } for (i = 0; i < 64; i++) { // ctx match, vaddr match, valid? if (ultrasparc_tag_match(&env->dtlb[i], - address, context, physical, - is_nucleus)) { + address, context, physical)) { // access ok? if (((env->dtlb[i].tte & 0x4) && is_user) || (!(env->dtlb[i].tte & 0x2) && (rw == 1))) { @@ -492,7 +486,6 @@ static int get_physical_address_code(CPUState *env, { unsigned int i; uint64_t context; - int is_nucleus; if ((env->lsu & IMMU_E) == 0 || (env->pstate & PS_RED) != 0) { /* IMMU disabled */ @@ -501,14 +494,16 @@ static int get_physical_address_code(CPUState *env, return 0; } - context = env->dmmu.mmu_primary_context & 0x1fff; - is_nucleus = env->tl > 0; + if (env->tl == 0) { + context = env->dmmu.mmu_primary_context & 0x1fff; + } else { + context = 0; + } for (i = 0; i < 64; i++) { // ctx match, vaddr match, valid? if (ultrasparc_tag_match(&env->itlb[i], - address, context, physical, - is_nucleus)) { + address, context, physical)) { // access ok? if ((env->itlb[i].tte & 0x4) && is_user) { if (env->immu.sfsr) /* Fault status register */ diff --git a/target-sparc/op_helper.c b/target-sparc/op_helper.c index b27778b..e048845 100644 --- a/target-sparc/op_helper.c +++ b/target-sparc/op_helper.c @@ -129,24 +129,58 @@ static void demap_tlb(SparcTLBEntry *tlb, target_ulong demap_addr, { unsigned int i; target_ulong mask; + uint64_t context; + + int is_demap_context = (demap_addr >> 6) & 1; + + // demap context + switch ((demap_addr >> 4) & 3) { + case 0: // primary + context = env1->dmmu.mmu_primary_context; + break; + case 1: // secondary + context = env1->dmmu.mmu_secondary_context; + break; + case 2: // nucleus + context = 0; + break; + case 3: // reserved + return; + } for (i = 0; i < 64; i++) { if (TTE_IS_VALID(tlb[i].tte)) { - mask = 0xffffffffffffe000ULL; - mask <<= 3 * ((tlb[i].tte >> 61) & 3); + if (is_demap_context) { + // will remove non-global entries matching context value + if (TTE_IS_GLOBAL(tlb[i].tte) || + !tlb_compare_context(&tlb[i], context)) { + continue; + } + } else { + // demap page + // will remove any entry matching VA + mask = 0xffffffffffffe000ULL; + mask <<= 3 * ((tlb[i].tte >> 61) & 3); + + if (!compare_masked(demap_addr, tlb[i].tag, mask)) { + continue; + } + + // entry should be global or matching context value + if (!TTE_IS_GLOBAL(tlb[i].tte) && + !tlb_compare_context(&tlb[i], context)) { + continue; + } + } - if ((demap_addr & mask) == (tlb[i].tag & mask)) { - replace_tlb_entry(&tlb[i], 0, 0, env1); + replace_tlb_entry(&tlb[i], 0, 0, env1); #ifdef DEBUG_MMU - DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu, i); - dump_mmu(env1); + DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu, i); + dump_mmu(env1); #endif - } - //return; } } - } static void replace_tlb_1bit_lru(SparcTLBEntry *tlb,