qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Daniel Henrique Barboza" <danielhb413@gmail.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	qemu-ppc@nongnu.org, "Alexey Kardashevskiy" <aik@ozlabs.ru>,
	"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH v2 1/4] hw/ppc/spapr_nvdimm: Simplify LD/ST API uses
Date: Fri, 27 Sep 2024 23:50:37 +0200	[thread overview]
Message-ID: <20240927215040.20552-2-philmd@linaro.org> (raw)
In-Reply-To: <20240927215040.20552-1-philmd@linaro.org>

ldn/stn methods handle the access size, no need for the switch case.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/ppc/spapr_nvdimm.c | 47 ++++---------------------------------------
 1 file changed, 4 insertions(+), 43 deletions(-)

diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c
index 7d2dfe5e3d..5af0b13370 100644
--- a/hw/ppc/spapr_nvdimm.c
+++ b/hw/ppc/spapr_nvdimm.c
@@ -250,7 +250,6 @@ static target_ulong h_scm_read_metadata(PowerPCCPU *cpu,
     SpaprDrc *drc = spapr_drc_by_index(drc_index);
     NVDIMMDevice *nvdimm;
     NVDIMMClass *ddc;
-    uint64_t data = 0;
     uint8_t buf[8] = { 0 };
 
     if (!drc || !drc->dev ||
@@ -272,24 +271,7 @@ static target_ulong h_scm_read_metadata(PowerPCCPU *cpu,
     ddc = NVDIMM_GET_CLASS(nvdimm);
     ddc->read_label_data(nvdimm, buf, len, offset);
 
-    switch (len) {
-    case 1:
-        data = ldub_p(buf);
-        break;
-    case 2:
-        data = lduw_be_p(buf);
-        break;
-    case 4:
-        data = ldl_be_p(buf);
-        break;
-    case 8:
-        data = ldq_be_p(buf);
-        break;
-    default:
-        g_assert_not_reached();
-    }
-
-    args[0] = data;
+    args[0] = ldn_be_p(buf, len);
 
     return H_SUCCESS;
 }
@@ -325,31 +307,10 @@ static target_ulong h_scm_write_metadata(PowerPCCPU *cpu,
         return H_P2;
     }
 
-    switch (len) {
-    case 1:
-        if (data & 0xffffffffffffff00) {
-            return H_P2;
-        }
-        stb_p(buf, data);
-        break;
-    case 2:
-        if (data & 0xffffffffffff0000) {
-            return H_P2;
-        }
-        stw_be_p(buf, data);
-        break;
-    case 4:
-        if (data & 0xffffffff00000000) {
-            return H_P2;
-        }
-        stl_be_p(buf, data);
-        break;
-    case 8:
-        stq_be_p(buf, data);
-        break;
-    default:
-            g_assert_not_reached();
+    if (len < 8 && extract64(data, 8 * len, 64 - 8 * len)) {
+        return H_P2;
     }
+    stn_be_p(buf, data, len);
 
     ddc = NVDIMM_GET_CLASS(nvdimm);
     ddc->write_label_data(nvdimm, buf, len, offset);
-- 
2.45.2



  reply	other threads:[~2024-09-27 21:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-27 21:50 [PATCH v2 0/4] hw/ppc & net: Simplify LD/ST API uses Philippe Mathieu-Daudé
2024-09-27 21:50 ` Philippe Mathieu-Daudé [this message]
2024-10-03 22:18   ` [PATCH v2 1/4] hw/ppc/spapr_nvdimm: " Richard Henderson
2024-09-27 21:50 ` [PATCH v2 2/4] hw/ppc/spapr_vof: " Philippe Mathieu-Daudé
2024-10-03 22:21   ` Richard Henderson
2024-09-27 21:50 ` [PATCH v2 3/4] hw/ppc/vof: " Philippe Mathieu-Daudé
2024-09-27 21:50 ` [PATCH v2 4/4] net/l2tpv3: " Philippe Mathieu-Daudé
2024-10-03 22:34   ` Richard Henderson

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=20240927215040.20552-2-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=aik@ozlabs.ru \
    --cc=danielhb413@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=harshpb@linux.ibm.com \
    --cc=jasowang@redhat.com \
    --cc=npiggin@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).