2 * PCI Hot Plug Controller Driver for RPA-compliant PPC64 platform.
3 * Copyright (C) 2003 Linda Xie <lxie@us.ibm.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
15 * NON INFRINGEMENT. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Send feedback to <lxie@us.ibm.com>
25 #include <linux/pci.h>
26 #include <linux/string.h>
28 #include <asm/pci-bridge.h>
30 #include <asm/machdep.h>
32 #include "../pci.h" /* for pci_add_new_bus */
35 int rpaphp_get_sensor_state(struct slot *slot, int *state)
40 rc = rtas_get_sensor(DR_ENTITY_SENSE, slot->index, state);
43 if (rc == -EFAULT || rc == -EEXIST) {
44 dbg("%s: slot must be power up to get sensor-state\n",
47 /* some slots have to be powered up
48 * before get-sensor will succeed.
50 rc = rtas_set_power_level(slot->power_domain, POWER_ON,
53 dbg("%s: power on slot[%s] failed rc=%d.\n",
54 __FUNCTION__, slot->name, rc);
56 rc = rtas_get_sensor(DR_ENTITY_SENSE,
59 } else if (rc == -ENODEV)
60 info("%s: slot is unusable\n", __FUNCTION__);
62 err("%s failed to get sensor state\n", __FUNCTION__);
67 static void print_slot_pci_funcs(struct pci_bus *bus)
69 struct device_node *dn;
72 dn = pci_bus_to_OF_node(bus);
76 dbg("%s: pci_devs of slot[%s]\n", __FUNCTION__, dn->full_name);
77 list_for_each_entry (dev, &bus->devices, bus_list)
78 dbg("\t%s\n", pci_name(dev));
82 static void set_slot_name(struct slot *slot)
84 struct pci_bus *bus = slot->bus;
85 struct pci_dev *bridge;
89 strcpy(slot->name, pci_name(bridge));
91 sprintf(slot->name, "%04x:%02x:00.0", pci_domain_nr(bus),
95 static int setup_pci_slot(struct slot *slot)
97 struct device_node *dn = slot->dn;
101 bus = pcibios_find_pci_bus(dn);
103 err("%s: no pci_bus for dn %s\n", __FUNCTION__, dn->full_name);
108 slot->pci_devs = &bus->devices;
111 /* find slot's pci_dev if it's not empty */
112 if (slot->hotplug_slot->info->adapter_status == EMPTY) {
113 slot->state = EMPTY; /* slot is empty */
115 /* slot is occupied */
117 /* non-empty slot has to have child */
118 err("%s: slot[%s]'s device_node doesn't have child for adapter\n",
119 __FUNCTION__, slot->name);
123 if (slot->hotplug_slot->info->adapter_status == NOT_CONFIGURED) {
124 dbg("%s CONFIGURING pci adapter in slot[%s]\n",
125 __FUNCTION__, slot->name);
126 pcibios_add_pci_devices(slot->bus);
128 } else if (slot->hotplug_slot->info->adapter_status != CONFIGURED) {
129 err("%s: slot[%s]'s adapter_status is NOT_VALID.\n",
130 __FUNCTION__, slot->name);
133 print_slot_pci_funcs(slot->bus);
134 if (!list_empty(slot->pci_devs)) {
135 slot->state = CONFIGURED;
137 /* DLPAR add as opposed to
139 slot->state = NOT_CONFIGURED;
147 int rpaphp_register_pci_slot(struct slot *slot)
149 int rc, level, state;
151 struct hotplug_slot_info *info = slot->hotplug_slot->info;
153 /* Find out if the power is turned on for the slot */
154 rc = rtas_get_power_level(slot->power_domain, &level);
157 info->power_status = level;
159 /* Figure out if there is an adapter in the slot */
160 info->adapter_status = NOT_VALID;
161 rc = rpaphp_get_sensor_state(slot, &state);
166 info->adapter_status = EMPTY;
167 else if (state == PRESENT) {
168 bus = pcibios_find_pci_bus(slot->dn);
169 if (bus && !list_empty(&bus->devices))
170 info->adapter_status = CONFIGURED;
172 info->adapter_status = NOT_CONFIGURED;
175 if (setup_pci_slot(slot))
178 return rpaphp_register_slot(slot);