[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [PULL 11/20] spapr: Rework DRC name handling
From: |
David Gibson |
Subject: |
[Qemu-ppc] [PULL 11/20] spapr: Rework DRC name handling |
Date: |
Fri, 9 Jun 2017 15:26:43 +1000 |
DRC objects have a get_name method which returns the DRC name generated
when the DRC is created. Replace that with a fixed spapr_drc_name()
function which generates the name on the fly from other information. This
means:
* We get rid of a method with only one implementation, and only local
callers
* We don't have to carry the name string around for the lifetime of the
DRC
* We use information added to the class structure to generate the name
in standard format, so we don't need an explicit switch on drc type
any more
We also eliminate the 'name' property; it's basically useless since the
only information in it can easily be deduced from other things.
Signed-off-by: David Gibson <address@hidden>
Reviewed-by: Michael Roth <address@hidden>
Acked-by: Michael Roth <address@hidden>
---
hw/ppc/spapr_drc.c | 80 +++++++++++++++++-----------------------------
include/hw/ppc/spapr_drc.h | 3 +-
2 files changed, 30 insertions(+), 53 deletions(-)
diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
index 82c0b94..15ef67d 100644
--- a/hw/ppc/spapr_drc.c
+++ b/hw/ppc/spapr_drc.c
@@ -155,9 +155,32 @@ static uint32_t set_allocation_state(sPAPRDRConnector *drc,
return RTAS_OUT_SUCCESS;
}
-static const char *get_name(sPAPRDRConnector *drc)
+static const char *spapr_drc_name(sPAPRDRConnector *drc)
{
- return drc->name;
+ sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
+
+ /* human-readable name for a DRC to encode into the DT
+ * description. this is mainly only used within a guest in place
+ * of the unique DRC index.
+ *
+ * in the case of VIO/PCI devices, it corresponds to a "location
+ * code" that maps a logical device/function (DRC index) to a
+ * physical (or virtual in the case of VIO) location in the system
+ * by chaining together the "location label" for each
+ * encapsulating component.
+ *
+ * since this is more to do with diagnosing physical hardware
+ * issues than guest compatibility, we choose location codes/DRC
+ * names that adhere to the documented format, but avoid encoding
+ * the entire topology information into the label/code, instead
+ * just using the location codes based on the labels for the
+ * endpoints (VIO/PCI adaptor connectors), which is basically just
+ * "C" followed by an integer ID.
+ *
+ * DRC names as documented by PAPR+ v2.7, 13.5.2.4
+ * location codes as documented by PAPR+ v2.7, 12.3.1.5
+ */
+ return g_strdup_printf("%s%d", drck->drc_name_prefix, drc->id);
}
/* has the guest been notified of device attachment? */
@@ -202,13 +225,6 @@ static void prop_get_index(Object *obj, Visitor *v, const
char *name,
visit_type_uint32(v, name, &value, errp);
}
-static char *prop_get_name(Object *obj, Error **errp)
-{
- sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj);
- sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
- return g_strdup(drck->get_name(drc));
-}
-
static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
@@ -567,45 +583,6 @@ sPAPRDRConnector *spapr_dr_connector_new(Object *owner,
const char *type,
object_property_set_bool(OBJECT(drc), true, "realized", NULL);
g_free(prop_name);
- /* human-readable name for a DRC to encode into the DT
- * description. this is mainly only used within a guest in place
- * of the unique DRC index.
- *
- * in the case of VIO/PCI devices, it corresponds to a
- * "location code" that maps a logical device/function (DRC index)
- * to a physical (or virtual in the case of VIO) location in the
- * system by chaining together the "location label" for each
- * encapsulating component.
- *
- * since this is more to do with diagnosing physical hardware
- * issues than guest compatibility, we choose location codes/DRC
- * names that adhere to the documented format, but avoid encoding
- * the entire topology information into the label/code, instead
- * just using the location codes based on the labels for the
- * endpoints (VIO/PCI adaptor connectors), which is basically
- * just "C" followed by an integer ID.
- *
- * DRC names as documented by PAPR+ v2.7, 13.5.2.4
- * location codes as documented by PAPR+ v2.7, 12.3.1.5
- */
- switch (spapr_drc_type(drc)) {
- case SPAPR_DR_CONNECTOR_TYPE_CPU:
- drc->name = g_strdup_printf("CPU %d", id);
- break;
- case SPAPR_DR_CONNECTOR_TYPE_PHB:
- drc->name = g_strdup_printf("PHB %d", id);
- break;
- case SPAPR_DR_CONNECTOR_TYPE_VIO:
- case SPAPR_DR_CONNECTOR_TYPE_PCI:
- drc->name = g_strdup_printf("C%d", id);
- break;
- case SPAPR_DR_CONNECTOR_TYPE_LMB:
- drc->name = g_strdup_printf("LMB %d", id);
- break;
- default:
- g_assert(false);
- }
-
/* PCI slot always start in a USABLE state, and stay there */
if (spapr_drc_type(drc) == SPAPR_DR_CONNECTOR_TYPE_PCI) {
drc->allocation_state = SPAPR_DR_ALLOCATION_STATE_USABLE;
@@ -621,7 +598,6 @@ static void spapr_dr_connector_instance_init(Object *obj)
object_property_add_uint32_ptr(obj, "id", &drc->id, NULL);
object_property_add(obj, "index", "uint32", prop_get_index,
NULL, NULL, NULL, NULL);
- object_property_add_str(obj, "name", prop_get_name, NULL, NULL);
object_property_add(obj, "fdt", "struct", prop_get_fdt,
NULL, NULL, NULL, NULL);
}
@@ -636,7 +612,6 @@ static void spapr_dr_connector_class_init(ObjectClass *k,
void *data)
dk->unrealize = unrealize;
drck->set_isolation_state = set_isolation_state;
drck->set_allocation_state = set_allocation_state;
- drck->get_name = get_name;
drck->release_pending = release_pending;
drck->set_signalled = set_signalled;
/*
@@ -665,6 +640,7 @@ static void spapr_drc_cpu_class_init(ObjectClass *k, void
*data)
drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU;
drck->typename = "CPU";
+ drck->drc_name_prefix = "CPU ";
}
static void spapr_drc_pci_class_init(ObjectClass *k, void *data)
@@ -673,6 +649,7 @@ static void spapr_drc_pci_class_init(ObjectClass *k, void
*data)
drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI;
drck->typename = "28";
+ drck->drc_name_prefix = "C";
}
static void spapr_drc_lmb_class_init(ObjectClass *k, void *data)
@@ -681,6 +658,7 @@ static void spapr_drc_lmb_class_init(ObjectClass *k, void
*data)
drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB;
drck->typename = "MEM";
+ drck->drc_name_prefix = "LMB ";
}
static const TypeInfo spapr_dr_connector_info = {
@@ -829,7 +807,7 @@ int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object
*owner,
g_array_append_val(drc_power_domains, drc_power_domain);
/* ibm,drc-names */
- drc_names = g_string_append(drc_names, drck->get_name(drc));
+ drc_names = g_string_append(drc_names, spapr_drc_name(drc));
drc_names = g_string_insert_len(drc_names, -1, "\0", 1);
/* ibm,drc-types */
diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h
index 4f82001..c487123 100644
--- a/include/hw/ppc/spapr_drc.h
+++ b/include/hw/ppc/spapr_drc.h
@@ -184,7 +184,6 @@ typedef struct sPAPRDRConnector {
uint32_t id;
Object *owner;
- const char *name;
/* DR-indicator */
uint32_t dr_indicator;
@@ -215,6 +214,7 @@ typedef struct sPAPRDRConnectorClass {
/*< public >*/
sPAPRDRConnectorTypeShift typeshift;
const char *typename; /* used in device tree, PAPR 13.5.2.6 & C.6.1 */
+ const char *drc_name_prefix; /* used other places in device tree */
sPAPRDREntitySense (*dr_entity_sense)(sPAPRDRConnector *drc);
@@ -223,7 +223,6 @@ typedef struct sPAPRDRConnectorClass {
sPAPRDRIsolationState state);
uint32_t (*set_allocation_state)(sPAPRDRConnector *drc,
sPAPRDRAllocationState state);
- const char *(*get_name)(sPAPRDRConnector *drc);
/* QEMU interfaces for managing hotplug operations */
bool (*release_pending)(sPAPRDRConnector *drc);
--
2.9.4
- [Qemu-ppc] [PULL 00/20] ppc-for-2.10 queue 20170609, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 02/20] target/ppc: fix memory leak in kvmppc_is_mem_backend_page_size_ok(), David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 03/20] spapr: fix memory leak in spapr_memory_pre_plug(), David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 06/20] spapr: Don't misuse DR-indicator in spapr_recover_pending_dimm_state(), David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 10/20] spapr: Fold spapr_phb_{add, remove}_pci_device() into their only callers, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 01/20] target/ppc: pass const string to kvmppc_is_mem_backend_page_size_ok(), David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 14/20] hw/ppc/spapr: Adjust firmware name for PCI bridges, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 04/20] pseries: Correct panic behaviour for pseries machine type, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 07/20] spapr: Clean up RTAS set-indicator, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 19/20] xics: drop ICPStateClass::cpu_setup() handler, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 11/20] spapr: Rework DRC name handling,
David Gibson <=
- [Qemu-ppc] [PULL 15/20] hw/cpu: core.c can be compiled as common object, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 08/20] spapr: Clean up handling of DR-indicator, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 09/20] spapr: Change DRC attach & detach methods to functions, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 17/20] xics: pass appropriate types to realize() handlers., David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 12/20] pnv_core: drop reference on ICPState object during CPU realization, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 13/20] xics: add reset() handler to ICPStateClass, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 20/20] Revert "spapr: fix memory hot-unplugging", David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 18/20] xics: setup cpu at realize time, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 05/20] spapr: Clean up DR entity sense handling, David Gibson, 2017/06/09
- [Qemu-ppc] [PULL 16/20] xics: introduce macros for ICP/ICS link properties, David Gibson, 2017/06/09