1 // SPDX-License-Identifier: GPL-2.0+
3 * PCI Hot Plug Controller Driver for RPA-compliant PPC64 platform.
12 #include <linux/pci.h>
13 #include <linux/string.h>
15 #include <asm/pci-bridge.h>
17 #include <asm/machdep.h>
19 #include "../pci.h" /* for pci_add_new_bus */
22 int rpaphp_get_sensor_state(struct slot *slot, int *state)
27 rc = rtas_get_sensor(DR_ENTITY_SENSE, slot->index, state);
30 if (rc == -EFAULT || rc == -EEXIST) {
31 dbg("%s: slot must be power up to get sensor-state\n",
34 /* some slots have to be powered up
35 * before get-sensor will succeed.
37 rc = rtas_set_power_level(slot->power_domain, POWER_ON,
40 dbg("%s: power on slot[%s] failed rc=%d.\n",
41 __func__, slot->name, rc);
43 rc = rtas_get_sensor(DR_ENTITY_SENSE,
46 } else if (rc == -ENODEV)
47 info("%s: slot is unusable\n", __func__);
49 err("%s failed to get sensor state\n", __func__);
55 * rpaphp_enable_slot - record slot state, config pci device
58 * Initialize values in the slot structure to indicate if there is a pci card
59 * plugged into the slot. If the slot is not empty, run the pcibios routine
60 * to get pcibios stuff correctly set up.
62 int rpaphp_enable_slot(struct slot *slot)
69 /* Find out if the power is turned on for the slot */
70 rc = rtas_get_power_level(slot->power_domain, &level);
74 /* Figure out if there is an adapter in the slot */
75 rc = rpaphp_get_sensor_state(slot, &state);
79 bus = pci_find_bus_by_node(slot->dn);
81 err("%s: no pci_bus for dn %pOF\n", __func__, slot->dn);
86 slot->pci_devs = &bus->devices;
88 /* if there's an adapter in the slot, go add the pci devices */
89 if (state == PRESENT) {
90 slot->state = NOT_CONFIGURED;
92 /* non-empty slot has to have child */
93 if (!slot->dn->child) {
94 err("%s: slot[%s]'s device_node doesn't have child for adapter\n",
95 __func__, slot->name);
99 if (list_empty(&bus->devices)) {
100 pseries_eeh_init_edev_recursive(PCI_DN(slot->dn));
101 pci_hp_add_devices(bus);
104 if (!list_empty(&bus->devices)) {
105 slot->state = CONFIGURED;
110 dbg("%s: pci_devs of slot[%pOF]\n", __func__, slot->dn);
111 list_for_each_entry(dev, &bus->devices, bus_list)
112 dbg("\t%s\n", pci_name(dev));