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 static 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__);
68 * get_pci_adapter_status - get the status of a slot
71 * 1-- adapter is configured
72 * 2-- adapter is not configured
75 int rpaphp_get_pci_adapter_status(struct slot *slot, int is_init, u8 * value)
81 rc = rpaphp_get_sensor_state(slot, &state);
87 else if (state == PRESENT) {
89 /* at run-time slot->state can be changed by */
90 /* config/unconfig adapter */
93 bus = pcibios_find_pci_bus(slot->dn);
94 if (bus && !list_empty(&bus->devices))
97 *value = NOT_CONFIGURED;
104 static void print_slot_pci_funcs(struct pci_bus *bus)
106 struct device_node *dn;
109 dn = pci_bus_to_OF_node(bus);
113 dbg("%s: pci_devs of slot[%s]\n", __FUNCTION__, dn->full_name);
114 list_for_each_entry (dev, &bus->devices, bus_list)
115 dbg("\t%s\n", pci_name(dev));
119 int rpaphp_unconfig_pci_adapter(struct pci_bus *bus)
121 struct pci_dev *dev, *tmp;
123 list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) {
124 eeh_remove_bus_device(dev);
125 pci_remove_bus_device(dev);
129 EXPORT_SYMBOL_GPL(rpaphp_unconfig_pci_adapter);
131 static int setup_pci_hotplug_slot_info(struct slot *slot)
133 struct hotplug_slot_info *hotplug_slot_info = slot->hotplug_slot->info;
135 dbg("%s Initilize the PCI slot's hotplug->info structure ...\n",
137 rpaphp_get_power_status(slot, &hotplug_slot_info->power_status);
138 rpaphp_get_pci_adapter_status(slot, 1,
139 &hotplug_slot_info->adapter_status);
140 if (hotplug_slot_info->adapter_status == NOT_VALID) {
141 err("%s: NOT_VALID: skip dn->full_name=%s\n",
142 __FUNCTION__, slot->dn->full_name);
148 static void set_slot_name(struct slot *slot)
150 struct pci_bus *bus = slot->bus;
151 struct pci_dev *bridge;
155 strcpy(slot->name, pci_name(bridge));
157 sprintf(slot->name, "%04x:%02x:00.0", pci_domain_nr(bus),
161 static int setup_pci_slot(struct slot *slot)
163 struct device_node *dn = slot->dn;
167 bus = pcibios_find_pci_bus(dn);
169 err("%s: no pci_bus for dn %s\n", __FUNCTION__, dn->full_name);
174 slot->pci_devs = &bus->devices;
177 /* find slot's pci_dev if it's not empty */
178 if (slot->hotplug_slot->info->adapter_status == EMPTY) {
179 slot->state = EMPTY; /* slot is empty */
181 /* slot is occupied */
183 /* non-empty slot has to have child */
184 err("%s: slot[%s]'s device_node doesn't have child for adapter\n",
185 __FUNCTION__, slot->name);
189 if (slot->hotplug_slot->info->adapter_status == NOT_CONFIGURED) {
190 dbg("%s CONFIGURING pci adapter in slot[%s]\n",
191 __FUNCTION__, slot->name);
192 pcibios_add_pci_devices(slot->bus);
194 } else if (slot->hotplug_slot->info->adapter_status != CONFIGURED) {
195 err("%s: slot[%s]'s adapter_status is NOT_VALID.\n",
196 __FUNCTION__, slot->name);
199 print_slot_pci_funcs(slot->bus);
200 if (!list_empty(slot->pci_devs)) {
201 slot->state = CONFIGURED;
203 /* DLPAR add as opposed to
205 slot->state = NOT_CONFIGURED;
210 dealloc_slot_struct(slot);
214 int register_pci_slot(struct slot *slot)
218 if (setup_pci_hotplug_slot_info(slot))
220 if (setup_pci_slot(slot))
222 rc = register_slot(slot);
227 int rpaphp_enable_pci_slot(struct slot *slot)
229 int retval = 0, state;
231 retval = rpaphp_get_sensor_state(slot, &state);
234 dbg("%s: sensor state[%d]\n", __FUNCTION__, state);
235 /* if slot is not empty, enable the adapter */
236 if (state == PRESENT) {
237 dbg("%s : slot[%s] is occupied.\n", __FUNCTION__, slot->name);
238 pcibios_add_pci_devices(slot->bus);
239 slot->state = CONFIGURED;
240 info("%s: devices in slot[%s] configured\n",
241 __FUNCTION__, slot->name);
242 } else if (state == EMPTY) {
243 dbg("%s : slot[%s] is empty\n", __FUNCTION__, slot->name);
246 err("%s: slot[%s] is in invalid state\n", __FUNCTION__,
248 slot->state = NOT_VALID;
252 dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);