From: deller@kernel.org
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
Helge Deller <deller@gmx.de>
Subject: [PATCH 6/6] target/hppa: Wire up diag instruction to support BTLB
Date: Wed, 13 Sep 2023 11:53:40 +0200 [thread overview]
Message-ID: <20230913095340.32951-7-deller@kernel.org> (raw)
In-Reply-To: <20230913095340.32951-1-deller@kernel.org>
From: Helge Deller <deller@gmx.de>
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 <deller@gmx.de>
---
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..da0f03aa4f 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%lx 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,
+ 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)
--
2.41.0
prev parent reply other threads:[~2023-09-13 9:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 9:53 [PATCH 0/6] Add Block-TLB support for hppa target deller
2023-09-13 9:53 ` [PATCH 1/6] target/hppa: Update to SeaBIOS-hppa version 9 deller
2023-09-13 9:53 ` [PATCH 2/6] target/hppa: Allow up to 16 BTLB entries deller
2023-09-13 9:53 ` [PATCH 3/6] target/hppa: Provide qemu version via fw_cfg to firmware deller
2023-09-13 9:53 ` [PATCH 4/6] target/hppa: Add BTLB support to hppa TLB functions deller
2023-09-13 9:53 ` [PATCH 5/6] target/hppa: Extract diagnose immediate value deller
2023-09-13 9:53 ` deller [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230913095340.32951-7-deller@kernel.org \
--to=deller@kernel.org \
--cc=deller@gmx.de \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.