[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [PULL 20/21] spapr: Clean up DRC set_allocation_state path
From: |
David Gibson |
Subject: |
[Qemu-ppc] [PULL 20/21] spapr: Clean up DRC set_allocation_state path |
Date: |
Fri, 30 Jun 2017 20:46:31 +1000 |
The allocation-state indicator should only actually be implemented for
"logical" DRCs, not physical ones. Factor a check for this, and also for
valid indicator state values into rtas_set_allocation_state(). Because
they don't exist for physical DRCs, there's no reason that we'd ever want
more than one method implementation, so it can just be a plain function.
In addition, the setting to USABLE and setting to UNUSABLE paths in
set_allocation_state() don't actually have much in common. So, split the
method separate functions for each parameter value (drc_set_usable()
and drc_set_unusable()).
Signed-off-by: David Gibson <address@hidden>
Reviewed-by: Greg Kurz <address@hidden>
Reviewed-by: Michael Roth <address@hidden>
---
hw/ppc/spapr_drc.c | 73 ++++++++++++++++++++++++++++------------------
include/hw/ppc/spapr_drc.h | 2 --
2 files changed, 45 insertions(+), 30 deletions(-)
diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
index 9a2511f..dbcd670 100644
--- a/hw/ppc/spapr_drc.c
+++ b/hw/ppc/spapr_drc.c
@@ -114,33 +114,42 @@ static uint32_t set_isolation_state(sPAPRDRConnector *drc,
return RTAS_OUT_SUCCESS;
}
-static uint32_t set_allocation_state(sPAPRDRConnector *drc,
- sPAPRDRAllocationState state)
+static uint32_t drc_set_usable(sPAPRDRConnector *drc)
{
- trace_spapr_drc_set_allocation_state(spapr_drc_index(drc), state);
-
- if (state == SPAPR_DR_ALLOCATION_STATE_USABLE) {
- /* if there's no resource/device associated with the DRC, there's
- * no way for us to put it in an allocation state consistent with
- * being 'USABLE'. PAPR 2.7, 13.5.3.4 documents that this should
- * result in an RTAS return code of -3 / "no such indicator"
+ /* if there's no resource/device associated with the DRC, there's
+ * no way for us to put it in an allocation state consistent with
+ * being 'USABLE'. PAPR 2.7, 13.5.3.4 documents that this should
+ * result in an RTAS return code of -3 / "no such indicator"
+ */
+ if (!drc->dev) {
+ return RTAS_OUT_NO_SUCH_INDICATOR;
+ }
+ if (drc->awaiting_release && drc->awaiting_allocation) {
+ /* kernel is acknowledging a previous hotplug event
+ * while we are already removing it.
+ * it's safe to ignore awaiting_allocation here since we know the
+ * situation is predicated on the guest either already having done
+ * so (boot-time hotplug), or never being able to acquire in the
+ * first place (hotplug followed by immediate unplug).
*/
- if (!drc->dev) {
- return RTAS_OUT_NO_SUCH_INDICATOR;
- }
+ return RTAS_OUT_NO_SUCH_INDICATOR;
}
- if (spapr_drc_type(drc) != SPAPR_DR_CONNECTOR_TYPE_PCI) {
- drc->allocation_state = state;
- if (drc->awaiting_release &&
- drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_UNUSABLE) {
- uint32_t drc_index = spapr_drc_index(drc);
- trace_spapr_drc_set_allocation_state_finalizing(drc_index);
- spapr_drc_detach(drc, DEVICE(drc->dev), NULL);
- } else if (drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_USABLE) {
- drc->awaiting_allocation = false;
- }
+ drc->allocation_state = SPAPR_DR_ALLOCATION_STATE_USABLE;
+ drc->awaiting_allocation = false;
+
+ return RTAS_OUT_SUCCESS;
+}
+
+static uint32_t drc_set_unusable(sPAPRDRConnector *drc)
+{
+ drc->allocation_state = SPAPR_DR_ALLOCATION_STATE_UNUSABLE;
+ if (drc->awaiting_release) {
+ uint32_t drc_index = spapr_drc_index(drc);
+ trace_spapr_drc_set_allocation_state_finalizing(drc_index);
+ spapr_drc_detach(drc, DEVICE(drc->dev), NULL);
}
+
return RTAS_OUT_SUCCESS;
}
@@ -547,7 +556,6 @@ static void spapr_dr_connector_class_init(ObjectClass *k,
void *data)
dk->realize = realize;
dk->unrealize = unrealize;
drck->set_isolation_state = set_isolation_state;
- drck->set_allocation_state = set_allocation_state;
drck->release_pending = release_pending;
/*
* Reason: it crashes FIXME find and document the real reason
@@ -817,14 +825,23 @@ static uint32_t rtas_set_isolation_state(uint32_t idx,
uint32_t state)
static uint32_t rtas_set_allocation_state(uint32_t idx, uint32_t state)
{
sPAPRDRConnector *drc = spapr_drc_by_index(idx);
- sPAPRDRConnectorClass *drck;
- if (!drc) {
- return RTAS_OUT_PARAM_ERROR;
+ if (!drc || !object_dynamic_cast(OBJECT(drc), TYPE_SPAPR_DRC_LOGICAL)) {
+ return RTAS_OUT_NO_SUCH_INDICATOR;
}
- drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
- return drck->set_allocation_state(drc, state);
+ trace_spapr_drc_set_allocation_state(spapr_drc_index(drc), state);
+
+ switch (state) {
+ case SPAPR_DR_ALLOCATION_STATE_USABLE:
+ return drc_set_usable(drc);
+
+ case SPAPR_DR_ALLOCATION_STATE_UNUSABLE:
+ return drc_set_unusable(drc);
+
+ default:
+ return RTAS_OUT_PARAM_ERROR;
+ }
}
static uint32_t rtas_set_dr_indicator(uint32_t idx, uint32_t state)
diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h
index 388e2a6..1674b66 100644
--- a/include/hw/ppc/spapr_drc.h
+++ b/include/hw/ppc/spapr_drc.h
@@ -219,8 +219,6 @@ typedef struct sPAPRDRConnectorClass {
/* accessors for guest-visible (generally via RTAS) DR state */
uint32_t (*set_isolation_state)(sPAPRDRConnector *drc,
sPAPRDRIsolationState state);
- uint32_t (*set_allocation_state)(sPAPRDRConnector *drc,
- sPAPRDRAllocationState state);
/* QEMU interfaces for managing hotplug operations */
bool (*release_pending)(sPAPRDRConnector *drc);
--
2.9.4
- [Qemu-ppc] [PULL 10/21] xics: directly register ICPState objects to vmstate, (continued)
- [Qemu-ppc] [PULL 10/21] xics: directly register ICPState objects to vmstate, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 04/21] pseries: Reset CPU compatibility mode, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 14/21] hw/ppc/spapr.c: consecutive 'spapr->patb_entry = 0' statements, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 05/21] ppc: Rework CPU compatibility testing across migration, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 18/21] spapr: Split DRC release from DRC detach, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 19/21] spapr: Make DRC reset force DRC into known state, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 15/21] target-ppc: Enable open-pic timers to count and generate interrupts, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 17/21] spapr: Eliminate DRC 'signalled' state variable, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 13/21] spapr: prevent QEMU crash when CPU realization fails, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 11/21] spapr: fix migration of ICPState objects from/to older QEMU, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 20/21] spapr: Clean up DRC set_allocation_state path,
David Gibson <=
- [Qemu-ppc] [PULL 16/21] spapr: Start hotplugged PCI devices in ISOLATED state, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 12/21] target/ppc: Proper cleanup when ppc_cpu_realizefn fails, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 03/21] pseries: Move CPU compatibility property to machine, David Gibson, 2017/06/30
- [Qemu-ppc] [PULL 21/21] spapr: Clean up DRC set_isolation_state() path, David Gibson, 2017/06/30
- Re: [Qemu-ppc] [Qemu-devel] [PULL 00/21] ppc-for-2.10 queue 20170730, Greg Kurz, 2017/06/30
- Re: [Qemu-ppc] [PULL 00/21] ppc-for-2.10 queue 20170730, Peter Maydell, 2017/06/30