diff mbox series

[RFC,13/23] hw/phb3: Add phb3_assert_perst()

Message ID 20190403090920.362-14-oohall@gmail.com
State RFC
Headers show
Series [RFC,01/23] platform/firenze-pci: Remove freset | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch warning Failed to apply on branch master (050d8165ab05b6d9cdf4bfee42d9776969c77029)
snowpatch_ozlabs/apply_patch fail Failed to apply to any branch

Commit Message

Oliver O'Halloran April 3, 2019, 9:09 a.m. UTC
Wire it up.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 hw/phb3.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/hw/phb3.c b/hw/phb3.c
index ee98fd51dd79..095fc3153378 100644
--- a/hw/phb3.c
+++ b/hw/phb3.c
@@ -2399,11 +2399,29 @@  static int64_t phb3_hreset(struct pci_slot *slot)
 	return OPAL_HARDWARE;
 }
 
+static int64_t phb3_assert_perst(struct pci_slot *slot, bool assert)
+{
+	struct phb3 *p = phb_to_phb3(slot->phb);
+	uint64_t reg;
+
+	/*
+	 * PPCBIT(2) of PHB_RESET drives PERST directly so we *clear*
+	 * it to assert PERST.
+	 */
+	reg = in_be64(p->regs + PHB_RESET);
+	if (assert)
+		reg &= ~0x2000000000000000ul;
+	else
+		reg |= 0x2000000000000000ul;
+	out_be64(p->regs + PHB_RESET, reg);
+
+	return OPAL_SUCCESS;
+}
+
 static int64_t phb3_freset(struct pci_slot *slot)
 {
 	struct phb3 *p = phb_to_phb3(slot->phb);
 	uint8_t presence = 1;
-	uint64_t reg;
 
 	switch(slot->state) {
 	case PHB3_SLOT_NORMAL:
@@ -2425,9 +2443,7 @@  static int64_t phb3_freset(struct pci_slot *slot)
 	case PHB3_SLOT_FRESET_START:
 		if (!p->skip_perst) {
 			PHBDBG(p, "FRESET: Assert\n");
-			reg = in_be64(p->regs + PHB_RESET);
-			reg &= ~0x2000000000000000ul;
-			out_be64(p->regs + PHB_RESET, reg);
+			phb3_assert_perst(slot, true);
 			pci_slot_set_state(slot,
 				PHB3_SLOT_FRESET_ASSERT_DELAY);
 			return pci_slot_set_sm_timeout(slot, secs_to_tb(1));
@@ -2440,9 +2456,7 @@  static int64_t phb3_freset(struct pci_slot *slot)
 		/* fall through */
 	case PHB3_SLOT_FRESET_ASSERT_DELAY:
 		PHBDBG(p, "FRESET: Deassert\n");
-		reg = in_be64(p->regs + PHB_RESET);
-		reg |= 0x2000000000000000ul;
-		out_be64(p->regs + PHB_RESET, reg);
+		phb3_assert_perst(slot, false);
 		pci_slot_set_state(slot,
 			PHB3_SLOT_FRESET_DEASSERT_DELAY);