PCI: rpaphp: Remove setup_pci_slot()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / pci / hotplug / rpaphp_pci.c
blob6417b7074ed49ac66c947838ab60c4faa1d2f148
1 /*
2 * PCI Hot Plug Controller Driver for RPA-compliant PPC64 platform.
3 * Copyright (C) 2003 Linda Xie <lxie@us.ibm.com>
5 * All rights reserved.
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
16 * details.
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>
29 #include <asm/rtas.h>
30 #include <asm/machdep.h>
32 #include "../pci.h" /* for pci_add_new_bus */
33 #include "rpaphp.h"
35 int rpaphp_get_sensor_state(struct slot *slot, int *state)
37 int rc;
38 int setlevel;
40 rc = rtas_get_sensor(DR_ENTITY_SENSE, slot->index, state);
42 if (rc < 0) {
43 if (rc == -EFAULT || rc == -EEXIST) {
44 dbg("%s: slot must be power up to get sensor-state\n",
45 __FUNCTION__);
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,
51 &setlevel);
52 if (rc < 0) {
53 dbg("%s: power on slot[%s] failed rc=%d.\n",
54 __FUNCTION__, slot->name, rc);
55 } else {
56 rc = rtas_get_sensor(DR_ENTITY_SENSE,
57 slot->index, state);
59 } else if (rc == -ENODEV)
60 info("%s: slot is unusable\n", __FUNCTION__);
61 else
62 err("%s failed to get sensor state\n", __FUNCTION__);
64 return rc;
67 static void print_slot_pci_funcs(struct pci_bus *bus)
69 struct device_node *dn;
70 struct pci_dev *dev;
72 dn = pci_bus_to_OF_node(bus);
73 if (!dn)
74 return;
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));
79 return;
82 static void set_slot_name(struct slot *slot)
84 struct pci_bus *bus = slot->bus;
85 struct pci_dev *bridge;
87 bridge = bus->self;
88 if (bridge)
89 strcpy(slot->name, pci_name(bridge));
90 else
91 sprintf(slot->name, "%04x:%02x:00.0", pci_domain_nr(bus),
92 bus->number);
95 int rpaphp_register_pci_slot(struct slot *slot)
97 int rc, level, state;
98 struct pci_bus *bus;
99 struct hotplug_slot_info *info = slot->hotplug_slot->info;
101 info->adapter_status = NOT_VALID;
102 slot->state = EMPTY;
104 /* Find out if the power is turned on for the slot */
105 rc = rtas_get_power_level(slot->power_domain, &level);
106 if (rc)
107 return rc;
108 info->power_status = level;
110 /* Figure out if there is an adapter in the slot */
111 rc = rpaphp_get_sensor_state(slot, &state);
112 if (rc)
113 return rc;
115 bus = pcibios_find_pci_bus(slot->dn);
116 if (!bus) {
117 err("%s: no pci_bus for dn %s\n", __FUNCTION__, slot->dn->full_name);
118 return -EINVAL;
121 info->adapter_status = EMPTY;
122 slot->bus = bus;
123 slot->pci_devs = &bus->devices;
124 set_slot_name(slot);
126 /* if there's an adapter in the slot, go add the pci devices */
127 if (state == PRESENT) {
128 info->adapter_status = NOT_CONFIGURED;
129 slot->state = NOT_CONFIGURED;
131 /* non-empty slot has to have child */
132 if (!slot->dn->child) {
133 err("%s: slot[%s]'s device_node doesn't have child for adapter\n",
134 __FUNCTION__, slot->name);
135 return -EINVAL;
138 if (list_empty(&bus->devices))
139 pcibios_add_pci_devices(bus);
141 print_slot_pci_funcs(bus);
142 if (!list_empty(&bus->devices)) {
143 info->adapter_status = CONFIGURED;
144 slot->state = CONFIGURED;
148 return rpaphp_register_slot(slot);