PCI: rpaphp: remove a function that does nothing but wrap debug printks
[linux-2.6/mini2440.git] / drivers / pci / hotplug / rpaphp_pci.c
blob881e8073c807b018cb58f1e90ccb048a61f3a975
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 /**
68 * get_pci_adapter_status - get the status of a slot
70 * 0-- slot is empty
71 * 1-- adapter is configured
72 * 2-- adapter is not configured
73 * 3-- not valid
75 int rpaphp_get_pci_adapter_status(struct slot *slot, int is_init, u8 * value)
77 struct pci_bus *bus;
78 int state, rc;
80 *value = NOT_VALID;
81 rc = rpaphp_get_sensor_state(slot, &state);
82 if (rc)
83 goto exit;
85 if (state == EMPTY)
86 *value = EMPTY;
87 else if (state == PRESENT) {
88 if (!is_init) {
89 /* at run-time slot->state can be changed by */
90 /* config/unconfig adapter */
91 *value = slot->state;
92 } else {
93 bus = pcibios_find_pci_bus(slot->dn);
94 if (bus && !list_empty(&bus->devices))
95 *value = CONFIGURED;
96 else
97 *value = NOT_CONFIGURED;
100 exit:
101 return rc;
104 static void print_slot_pci_funcs(struct pci_bus *bus)
106 struct device_node *dn;
107 struct pci_dev *dev;
109 dn = pci_bus_to_OF_node(bus);
110 if (!dn)
111 return;
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));
116 return;
119 static void set_slot_name(struct slot *slot)
121 struct pci_bus *bus = slot->bus;
122 struct pci_dev *bridge;
124 bridge = bus->self;
125 if (bridge)
126 strcpy(slot->name, pci_name(bridge));
127 else
128 sprintf(slot->name, "%04x:%02x:00.0", pci_domain_nr(bus),
129 bus->number);
132 static int setup_pci_slot(struct slot *slot)
134 struct device_node *dn = slot->dn;
135 struct pci_bus *bus;
137 BUG_ON(!dn);
138 bus = pcibios_find_pci_bus(dn);
139 if (!bus) {
140 err("%s: no pci_bus for dn %s\n", __FUNCTION__, dn->full_name);
141 goto exit_rc;
144 slot->bus = bus;
145 slot->pci_devs = &bus->devices;
146 set_slot_name(slot);
148 /* find slot's pci_dev if it's not empty */
149 if (slot->hotplug_slot->info->adapter_status == EMPTY) {
150 slot->state = EMPTY; /* slot is empty */
151 } else {
152 /* slot is occupied */
153 if (!dn->child) {
154 /* non-empty slot has to have child */
155 err("%s: slot[%s]'s device_node doesn't have child for adapter\n",
156 __FUNCTION__, slot->name);
157 goto exit_rc;
160 if (slot->hotplug_slot->info->adapter_status == NOT_CONFIGURED) {
161 dbg("%s CONFIGURING pci adapter in slot[%s]\n",
162 __FUNCTION__, slot->name);
163 pcibios_add_pci_devices(slot->bus);
165 } else if (slot->hotplug_slot->info->adapter_status != CONFIGURED) {
166 err("%s: slot[%s]'s adapter_status is NOT_VALID.\n",
167 __FUNCTION__, slot->name);
168 goto exit_rc;
170 print_slot_pci_funcs(slot->bus);
171 if (!list_empty(slot->pci_devs)) {
172 slot->state = CONFIGURED;
173 } else {
174 /* DLPAR add as opposed to
175 * boot time */
176 slot->state = NOT_CONFIGURED;
179 return 0;
180 exit_rc:
181 return -EINVAL;
184 int rpaphp_register_pci_slot(struct slot *slot)
186 struct hotplug_slot_info *info = slot->hotplug_slot->info;
188 rpaphp_get_power_status(slot, &info->power_status);
189 rpaphp_get_pci_adapter_status(slot, 1, &info->adapter_status);
191 if (info->adapter_status == NOT_VALID) {
192 err("%s: NOT_VALID: skip dn->full_name=%s\n",
193 __FUNCTION__, slot->dn->full_name);
194 return -EINVAL;
197 if (setup_pci_slot(slot))
198 return -EINVAL;
200 return rpaphp_register_slot(slot);