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 __func__
, slot
->name
, rc
);
56 rc
= rtas_get_sensor(DR_ENTITY_SENSE
,
59 } else if (rc
== -ENODEV
)
60 info("%s: slot is unusable\n", __func__
);
62 err("%s failed to get sensor state\n", __func__
);
68 * rpaphp_enable_slot - record slot state, config pci device
71 * Initialize values in the slot, and the hotplug_slot info
72 * structures to indicate if there is a pci card plugged into
73 * the slot. If the slot is not empty, run the pcibios routine
74 * to get pcibios stuff correctly set up.
76 int rpaphp_enable_slot(struct slot
*slot
)
80 struct hotplug_slot_info
*info
= slot
->hotplug_slot
->info
;
82 info
->adapter_status
= NOT_VALID
;
85 /* Find out if the power is turned on for the slot */
86 rc
= rtas_get_power_level(slot
->power_domain
, &level
);
89 info
->power_status
= level
;
91 /* Figure out if there is an adapter in the slot */
92 rc
= rpaphp_get_sensor_state(slot
, &state
);
96 bus
= pci_find_bus_by_node(slot
->dn
);
98 err("%s: no pci_bus for dn %s\n", __func__
, slot
->dn
->full_name
);
102 info
->adapter_status
= EMPTY
;
104 slot
->pci_devs
= &bus
->devices
;
106 /* if there's an adapter in the slot, go add the pci devices */
107 if (state
== PRESENT
) {
108 info
->adapter_status
= NOT_CONFIGURED
;
109 slot
->state
= NOT_CONFIGURED
;
111 /* non-empty slot has to have child */
112 if (!slot
->dn
->child
) {
113 err("%s: slot[%s]'s device_node doesn't have child for adapter\n",
114 __func__
, slot
->name
);
118 if (list_empty(&bus
->devices
))
119 pci_hp_add_devices(bus
);
121 if (!list_empty(&bus
->devices
)) {
122 info
->adapter_status
= CONFIGURED
;
123 slot
->state
= CONFIGURED
;
128 dbg("%s: pci_devs of slot[%s]\n", __func__
, slot
->dn
->full_name
);
129 list_for_each_entry(dev
, &bus
->devices
, bus_list
)
130 dbg("\t%s\n", pci_name(dev
));