All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, david@gibson.dropbear.id.au, clg@kaod.org,
	fbarrat@linux.ibm.com,
	Daniel Henrique Barboza <danielhb413@gmail.com>
Subject: [PATCH 13/17] ppc/pnv: add pnv_phb_get_current_machine()
Date: Sat,  7 May 2022 16:06:20 -0300	[thread overview]
Message-ID: <20220507190624.507419-14-danielhb413@gmail.com> (raw)
In-Reply-To: <20220507190624.507419-1-danielhb413@gmail.com>

Add a simple helper to avoid hardcoding strcmp() comparisons all around
pnv_phb.c.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/pci-host/pnv_phb.c | 40 +++++++++++++++++++++++++++++++---------
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/hw/pci-host/pnv_phb.c b/hw/pci-host/pnv_phb.c
index cef6a57d50..e03062a494 100644
--- a/hw/pci-host/pnv_phb.c
+++ b/hw/pci-host/pnv_phb.c
@@ -20,6 +20,10 @@
 #include "sysemu/sysemu.h"
 
 
+#define PNV_MACHINE_POWER8    1
+#define PNV_MACHINE_POWER9    2
+#define PNV_MACHINE_POWER10   3
+
 static char *pnv_phb_get_chip_typename(void)
 {
     Object *qdev_machine = qdev_get_machine();
@@ -39,7 +43,7 @@ static char *pnv_phb_get_chip_typename(void)
     return g_steal_pointer(&chip_typename);
 }
 
-static void pnv_phb_instance_init(Object *obj)
+static int pnv_phb_get_current_machine(void)
 {
     g_autofree char *chip_typename = pnv_phb_get_chip_typename();
 
@@ -48,12 +52,31 @@ static void pnv_phb_instance_init(Object *obj)
      * a valid machine->cpu_type value.
      */
     if (!chip_typename) {
-        return;
+        return 0;
     }
 
     if (!strcmp(chip_typename, TYPE_PNV_CHIP_POWER8) ||
         !strcmp(chip_typename, TYPE_PNV_CHIP_POWER8E) ||
         !strcmp(chip_typename, TYPE_PNV_CHIP_POWER8NVL)) {
+        return PNV_MACHINE_POWER8;
+    } else if (!strcmp(chip_typename, TYPE_PNV_CHIP_POWER9)) {
+        return PNV_MACHINE_POWER9;
+    } else if (!strcmp(chip_typename, TYPE_PNV_CHIP_POWER10)) {
+        return PNV_MACHINE_POWER10;
+    }
+
+    return 0;
+}
+
+static void pnv_phb_instance_init(Object *obj)
+{
+    int pnv_current_machine = pnv_phb_get_current_machine();
+
+    if (pnv_current_machine == 0) {
+        return;
+    }
+
+    if (pnv_current_machine == PNV_MACHINE_POWER8) {
         pnv_phb3_instance_init(obj);
         return;
     }
@@ -63,25 +86,24 @@ static void pnv_phb_instance_init(Object *obj)
 
 static void pnv_phb_realize(DeviceState *dev, Error **errp)
 {
+    int pnv_current_machine = pnv_phb_get_current_machine();
     PnvPHB *phb = PNV_PHB(dev);
-    g_autofree char *chip_typename = pnv_phb_get_chip_typename();
 
-    g_assert(chip_typename != NULL);
+    g_assert(pnv_current_machine != 0);
 
-    if (!strcmp(chip_typename, TYPE_PNV_CHIP_POWER8) ||
-        !strcmp(chip_typename, TYPE_PNV_CHIP_POWER8E) ||
-        !strcmp(chip_typename, TYPE_PNV_CHIP_POWER8NVL)) {
+    if (pnv_current_machine == PNV_MACHINE_POWER8) {
         /* PnvPHB3 */
         phb->version = PHB_VERSION_3;
         pnv_phb3_realize(dev, errp);
         return;
     }
 
-    if (!strcmp(chip_typename, TYPE_PNV_CHIP_POWER9)) {
+    if (pnv_current_machine == PNV_MACHINE_POWER9) {
         phb->version = PHB_VERSION_4;
-    } else if (!strcmp(chip_typename, TYPE_PNV_CHIP_POWER10)) {
+    } else if (pnv_current_machine == PNV_MACHINE_POWER10) {
         phb->version = PHB_VERSION_5;
     } else {
+        g_autofree char *chip_typename = pnv_phb_get_chip_typename();
         error_setg(errp, "unknown PNV chip: %s", chip_typename);
         return;
     }
-- 
2.32.0



  parent reply	other threads:[~2022-05-07 19:21 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-07 19:06 [PATCH 00/17] powernv: introduce pnv-phb unified devices Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 01/17] ppc/pnv: rename PnvPHB3.ioda* to PnvPHB3.ioda2* Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 02/17] ppc/pnv: rename PnvPHB3.regs[] to PnvPHB3.regs3[] Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 03/17] ppc/pnv: rename PnvPHB3.dma_spaces to PnvPHB3.v3_dma_spaces Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 04/17] ppc/pnv: add unified pnv-phb header Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 05/17] ppc/pnv: add pnv-phb device Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 06/17] ppc/pnv: remove PnvPHB3 Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 07/17] ppc/pnv: user created pnv-phb for powernv8 Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 08/17] ppc/pnv: remove PnvPHB4 Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 09/17] ppc/pnv: user creatable pnv-phb for powernv9 Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 10/17] ppc/pnv: use PnvPHB.version Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 11/17] ppc/pnv: change pnv_phb4_get_pec() to also retrieve chip10->pecs Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 12/17] ppc/pnv: user creatable pnv-phb for powernv10 Daniel Henrique Barboza
2022-05-07 19:06 ` Daniel Henrique Barboza [this message]
2022-05-07 19:06 ` [PATCH 14/17] ppc/pnv: add pnv-phb-root-port device Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 15/17] ppc/pnv: remove pnv-phb3-root-port Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 16/17] ppc/pnv: remove pnv-phb4-root-port Daniel Henrique Barboza
2022-05-07 19:06 ` [PATCH 17/17] ppc/pnv: remove pecc->rp_model Daniel Henrique Barboza
2022-05-09 21:17 ` [PATCH 00/17] powernv: introduce pnv-phb unified devices Mark Cave-Ayland
2022-05-09 22:30   ` Daniel Henrique Barboza
2022-05-10  7:57     ` Mark Cave-Ayland
2022-05-11 18:30       ` Daniel Henrique Barboza
2022-05-12 15:03       ` Cédric Le Goater
2022-05-10  9:07 ` Frederic Barrat

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=20220507190624.507419-14-danielhb413@gmail.com \
    --to=danielhb413@gmail.com \
    --cc=clg@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=fbarrat@linux.ibm.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 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.