1 // SPDX-License-Identifier: GPL-2.0+
3 * PCI Hot Plug Controller Driver for RPA-compliant PPC64 platform.
4 * Copyright (C) 2003 Linda Xie <lxie@us.ibm.com>
8 * Send feedback to <lxie@us.ibm.com>
11 #include <linux/pci.h>
12 #include <linux/string.h>
14 #include <asm/pci-bridge.h>
16 #include <asm/machdep.h>
18 #include "../pci.h" /* for pci_add_new_bus */
21 int rpaphp_get_sensor_state(struct slot *slot, int *state)
26 rc = rtas_get_sensor(DR_ENTITY_SENSE, slot->index, state);
29 if (rc == -EFAULT || rc == -EEXIST) {
30 dbg("%s: slot must be power up to get sensor-state\n",
33 /* some slots have to be powered up
34 * before get-sensor will succeed.
36 rc = rtas_set_power_level(slot->power_domain, POWER_ON,
39 dbg("%s: power on slot[%s] failed rc=%d.\n",
40 __func__, slot->name, rc);
42 rc = rtas_get_sensor(DR_ENTITY_SENSE,
45 } else if (rc == -ENODEV)
46 info("%s: slot is unusable\n", __func__);
48 err("%s failed to get sensor state\n", __func__);
54 * rpaphp_enable_slot - record slot state, config pci device
57 * Initialize values in the slot, and the hotplug_slot info
58 * structures to indicate if there is a pci card plugged into
59 * 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)
66 struct hotplug_slot_info *info = slot->hotplug_slot->info;
68 info->adapter_status = NOT_VALID;
71 /* Find out if the power is turned on for the slot */
72 rc = rtas_get_power_level(slot->power_domain, &level);
75 info->power_status = level;
77 /* Figure out if there is an adapter in the slot */
78 rc = rpaphp_get_sensor_state(slot, &state);
82 bus = pci_find_bus_by_node(slot->dn);
84 err("%s: no pci_bus for dn %pOF\n", __func__, slot->dn);
88 info->adapter_status = EMPTY;
90 slot->pci_devs = &bus->devices;
92 /* if there's an adapter in the slot, go add the pci devices */
93 if (state == PRESENT) {
94 info->adapter_status = NOT_CONFIGURED;
95 slot->state = NOT_CONFIGURED;
97 /* non-empty slot has to have child */
98 if (!slot->dn->child) {
99 err("%s: slot[%s]'s device_node doesn't have child for adapter\n",
100 __func__, slot->name);
104 if (list_empty(&bus->devices))
105 pci_hp_add_devices(bus);
107 if (!list_empty(&bus->devices)) {
108 info->adapter_status = CONFIGURED;
109 slot->state = CONFIGURED;
114 dbg("%s: pci_devs of slot[%pOF]\n", __func__, slot->dn);
115 list_for_each_entry(dev, &bus->devices, bus_list)
116 dbg("\t%s\n", pci_name(dev));