From patchwork Tue Sep 19 19:17:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13391792 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9FCFCE79A8 for ; Tue, 19 Sep 2023 19:19:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qigEn-00061Y-Qz; Tue, 19 Sep 2023 15:18:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qigEi-0005xW-GL for qemu-devel@nongnu.org; Tue, 19 Sep 2023 15:18:16 -0400 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qigEg-00088x-6F for qemu-devel@nongnu.org; Tue, 19 Sep 2023 15:18:15 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E2D496176E; Tue, 19 Sep 2023 19:18:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37C4EC433C7; Tue, 19 Sep 2023 19:18:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695151091; bh=/H5WrOm9NmWrjgzLH7fGS4ghoO2YKyjvHFdIzwk4AJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OvmcGmTG9vgUR525Bq+2wDmbiX2uk9lhNwwOanrBcSrP/t/+Wn3pyZpFJeI/NdIdk PNF/VFNM8w+VQDunHXqjmY49m2S2AxMoNKwL+ZEzCiIJm/hqhfdH45BbuEalLTKEQ6 A2alYXRvw4NiDRCLIF+HmlbCRcWATHTD02sOmGCmgiLKO9Paexw7AIj0Bwd8gxyOCY OfJRjuZueTslvegNuNjKvJBFAcnoXf/BHfiMDlWsX7ELd3DYm3/2kr6JGJH5KRNRUi NZcOOfBpa9uI81dlm9g27mlStqgVU9yIW3MNLV1+SHmuK75cafwGQu9r6EPkIjZz0G dEOo7jCjGgGYQ== From: deller@kernel.org To: qemu-devel@nongnu.org Cc: Helge Deller , Richard Henderson , Laurent Vivier Subject: [PULL v2 6/8] target/hppa: Wire up diag instruction to support BTLB Date: Tue, 19 Sep 2023 21:17:54 +0200 Message-ID: <20230919191757.98889-7-deller@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919191757.98889-1-deller@kernel.org> References: <20230919191757.98889-1-deller@kernel.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2604:1380:4641:c500::1; envelope-from=deller@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Helge Deller Wire up the hppa diag instruction to support Block-TLBs when called with the 0x100 value. The diag_btlb() helper function does all necessary steps to emulate the PDC BTLB firmware function, which includes providing BTLB info, adding a new BTLB, deleting a BTLB and removing all BTLBs. Signed-off-by: Helge Deller --- target/hppa/helper.h | 1 + target/hppa/mem_helper.c | 92 ++++++++++++++++++++++++++++++++++++++++ target/hppa/translate.c | 15 +++++-- 3 files changed, 105 insertions(+), 3 deletions(-) diff --git a/target/hppa/helper.h b/target/hppa/helper.h index c7e35ce8c7..647f043c85 100644 --- a/target/hppa/helper.h +++ b/target/hppa/helper.h @@ -95,4 +95,5 @@ DEF_HELPER_FLAGS_2(ptlb, TCG_CALL_NO_RWG, void, env, tl) DEF_HELPER_FLAGS_1(ptlbe, TCG_CALL_NO_RWG, void, env) DEF_HELPER_FLAGS_2(lpa, TCG_CALL_NO_WG, tr, env, tl) DEF_HELPER_FLAGS_1(change_prot_id, TCG_CALL_NO_RWG, void, env) +DEF_HELPER_1(diag_btlb, void, env) #endif diff --git a/target/hppa/mem_helper.c b/target/hppa/mem_helper.c index ea33b58ddd..520fd311f8 100644 --- a/target/hppa/mem_helper.c +++ b/target/hppa/mem_helper.c @@ -412,3 +412,95 @@ int hppa_artype_for_page(CPUHPPAState *env, target_ulong vaddr) hppa_tlb_entry *ent = hppa_find_tlb(env, vaddr); return ent ? ent->ar_type : -1; } + +/* + * diag_btlb() emulates the PDC PDC_BLOCK_TLB firmware call to + * allow operating systems to modify the Block TLB (BTLB) entries. + * For implementation details see page 1-13 in + * https://parisc.wiki.kernel.org/images-parisc/e/ef/Pdc11-v0.96-Ch1-procs.pdf + */ +void HELPER(diag_btlb)(CPUHPPAState *env) +{ + unsigned int phys_page, len, slot; + int mmu_idx = cpu_mmu_index(env, 0); + uintptr_t ra = GETPC(); + hppa_tlb_entry *btlb; + uint64_t virt_page; + uint32_t *vaddr; + +#ifdef TARGET_HPPA64 + /* BTLBs are not supported on 64-bit CPUs */ + env->gr[28] = -1; /* nonexistent procedure */ + return; +#endif + env->gr[28] = 0; /* PDC_OK */ + + switch (env->gr[25]) { + case 0: + /* return BTLB parameters */ + qemu_log_mask(CPU_LOG_MMU, "PDC_BLOCK_TLB: PDC_BTLB_INFO\n"); + vaddr = probe_access(env, env->gr[24], 4 * sizeof(target_ulong), + MMU_DATA_STORE, mmu_idx, ra); + if (vaddr == NULL) { + env->gr[28] = -10; /* invalid argument */ + } else { + vaddr[0] = cpu_to_be32(1); + vaddr[1] = cpu_to_be32(16 * 1024); + vaddr[2] = cpu_to_be32(HPPA_BTLB_FIXED); + vaddr[3] = cpu_to_be32(HPPA_BTLB_VARIABLE); + } + break; + case 1: + /* insert BTLB entry */ + virt_page = env->gr[24]; /* upper 32 bits */ + virt_page <<= 32; + virt_page |= env->gr[23]; /* lower 32 bits */ + phys_page = env->gr[22]; + len = env->gr[21]; + slot = env->gr[19]; + qemu_log_mask(CPU_LOG_MMU, "PDC_BLOCK_TLB: PDC_BTLB_INSERT " + "0x%08llx-0x%08llx: vpage 0x%llx for phys page 0x%04x len %d " + "into slot %d\n", + (long long) virt_page << TARGET_PAGE_BITS, + (long long) (virt_page + len) << TARGET_PAGE_BITS, + (long long) virt_page, phys_page, len, slot); + if (slot < HPPA_BTLB_ENTRIES) { + btlb = &env->tlb[slot]; + /* force flush of possibly existing BTLB entry */ + hppa_flush_tlb_ent(env, btlb, true); + /* create new BTLB entry */ + btlb->va_b = virt_page << TARGET_PAGE_BITS; + btlb->va_e = btlb->va_b + len * TARGET_PAGE_SIZE - 1; + btlb->pa = phys_page << TARGET_PAGE_BITS; + set_access_bits(env, btlb, env->gr[20]); + btlb->t = 0; + btlb->d = 1; + } else { + env->gr[28] = -10; /* invalid argument */ + } + break; + case 2: + /* Purge BTLB entry */ + slot = env->gr[22]; + qemu_log_mask(CPU_LOG_MMU, "PDC_BLOCK_TLB: PDC_BTLB_PURGE slot %d\n", + slot); + if (slot < HPPA_BTLB_ENTRIES) { + btlb = &env->tlb[slot]; + hppa_flush_tlb_ent(env, btlb, true); + } else { + env->gr[28] = -10; /* invalid argument */ + } + break; + case 3: + /* Purge all BTLB entries */ + qemu_log_mask(CPU_LOG_MMU, "PDC_BLOCK_TLB: PDC_BTLB_PURGE_ALL\n"); + for (slot = 0; slot < HPPA_BTLB_ENTRIES; slot++) { + btlb = &env->tlb[slot]; + hppa_flush_tlb_ent(env, btlb, true); + } + break; + default: + env->gr[28] = -2; /* nonexistent option */ + break; + } +} diff --git a/target/hppa/translate.c b/target/hppa/translate.c index c04dc15228..650bbcfe95 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -4042,9 +4042,18 @@ static bool trans_fmpyfadd_d(DisasContext *ctx, arg_fmpyfadd_d *a) static bool trans_diag(DisasContext *ctx, arg_diag *a) { - qemu_log_mask(LOG_UNIMP, "DIAG opcode ignored\n"); - cond_free(&ctx->null_cond); - return true; + nullify_over(ctx); + CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); +#ifndef CONFIG_USER_ONLY + if (a->i == 0x100) { + /* emulate PDC BTLB, called by SeaBIOS-hppa */ + gen_helper_diag_btlb(cpu_env); + } else +#endif + { + qemu_log_mask(LOG_UNIMP, "DIAG opcode 0x%04x ignored\n", a->i); + } + return nullify_end(ctx); } static void hppa_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)