diff mbox series

[for-7.1,1/9] hw/ppc/spapr_drc.c: add drc->index

Message ID 20220318173320.320541-2-danielhb413@gmail.com
State Deferred
Headers show
Series spapr: add drc->index, remove spapr_drc_index() | expand

Commit Message

Daniel Henrique Barboza March 18, 2022, 5:33 p.m. UTC
The DRC index is an unique identifier that is used across all spapr
code. Its value is given by spapr_drc_index() as follows:

    return (drck->typeshift << DRC_INDEX_TYPE_SHIFT)
        | (drc->id & DRC_INDEX_ID_MASK);

We see that there is nothing that varies with the machine/device state
on spapr_drc_index(). drc->id is defined in spapr_dr_connector_new() and
it's read only, drck->typeshift relies on the DRC class type and it
doesn't change as well and the two macros. Nevertheless,
spapr_drc_index() is called multiple times across spapr files, meaning
that we're always recalculating this value.

This patch adds a new SpaprDrc attribute called 'index'. drc->index will
be initialized with spapr_drc_index() and it's going to be a replacement
for the repetitive spapr_drc_index() usage we have today.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 hw/ppc/spapr_drc.c         | 1 +
 include/hw/ppc/spapr_drc.h | 1 +
 2 files changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
index 76bc5d42a0..1b8c797192 100644
--- a/hw/ppc/spapr_drc.c
+++ b/hw/ppc/spapr_drc.c
@@ -561,6 +561,7 @@  SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type,
 
     drc->id = id;
     drc->owner = owner;
+    drc->index = spapr_drc_index(drc);
     prop_name = g_strdup_printf("dr-connector[%"PRIu32"]",
                                 spapr_drc_index(drc));
     object_property_add_child(owner, prop_name, OBJECT(drc));
diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h
index 02a63b3666..93825e47a6 100644
--- a/include/hw/ppc/spapr_drc.h
+++ b/include/hw/ppc/spapr_drc.h
@@ -173,6 +173,7 @@  typedef struct SpaprDrc {
     DeviceState parent;
 
     uint32_t id;
+    uint32_t index;
     Object *owner;
 
     uint32_t state;