2 * CompactPCI Hot Plug Driver PCI functions
4 * Copyright (C) 2002,2005 by SOMA Networks, Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
16 * NON INFRINGEMENT. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Send feedback to <scottm@somanetworks.com>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/pci.h>
29 #include <linux/pci_hotplug.h>
30 #include <linux/proc_fs.h>
32 #include "cpci_hotplug.h"
34 #define MY_NAME "cpci_hotplug"
36 extern int cpci_debug
;
38 #define dbg(format, arg...) \
41 printk(KERN_DEBUG "%s: " format "\n", \
44 #define err(format, arg...) printk(KERN_ERR "%s: " format "\n", MY_NAME, ## arg)
45 #define info(format, arg...) printk(KERN_INFO "%s: " format "\n", MY_NAME, ## arg)
46 #define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", MY_NAME, ## arg)
49 u8
cpci_get_attention_status(struct slot
*slot
)
54 hs_cap
= pci_bus_find_capability(slot
->bus
,
60 if (pci_bus_read_config_word(slot
->bus
,
66 return hs_csr
& 0x0008 ? 1 : 0;
69 int cpci_set_attention_status(struct slot
*slot
, int status
)
74 hs_cap
= pci_bus_find_capability(slot
->bus
,
79 if (pci_bus_read_config_word(slot
->bus
,
87 hs_csr
&= ~HS_CSR_LOO
;
88 if (pci_bus_write_config_word(slot
->bus
,
96 u16
cpci_get_hs_csr(struct slot
*slot
)
101 hs_cap
= pci_bus_find_capability(slot
->bus
,
106 if (pci_bus_read_config_word(slot
->bus
,
114 int cpci_check_and_clear_ins(struct slot
*slot
)
120 hs_cap
= pci_bus_find_capability(slot
->bus
,
125 if (pci_bus_read_config_word(slot
->bus
,
130 if (hs_csr
& HS_CSR_INS
) {
131 /* Clear INS (by setting it) */
132 if (pci_bus_write_config_word(slot
->bus
,
143 int cpci_check_ext(struct slot
*slot
)
149 hs_cap
= pci_bus_find_capability(slot
->bus
,
154 if (pci_bus_read_config_word(slot
->bus
,
159 if (hs_csr
& HS_CSR_EXT
)
164 int cpci_clear_ext(struct slot
*slot
)
169 hs_cap
= pci_bus_find_capability(slot
->bus
,
174 if (pci_bus_read_config_word(slot
->bus
,
179 if (hs_csr
& HS_CSR_EXT
) {
180 /* Clear EXT (by setting it) */
181 if (pci_bus_write_config_word(slot
->bus
,
190 int cpci_led_on(struct slot
*slot
)
195 hs_cap
= pci_bus_find_capability(slot
->bus
,
200 if (pci_bus_read_config_word(slot
->bus
,
205 if ((hs_csr
& HS_CSR_LOO
) != HS_CSR_LOO
) {
206 hs_csr
|= HS_CSR_LOO
;
207 if (pci_bus_write_config_word(slot
->bus
,
211 err("Could not set LOO for slot %s",
212 hotplug_slot_name(slot
->hotplug_slot
));
219 int cpci_led_off(struct slot
*slot
)
224 hs_cap
= pci_bus_find_capability(slot
->bus
,
229 if (pci_bus_read_config_word(slot
->bus
,
234 if (hs_csr
& HS_CSR_LOO
) {
235 hs_csr
&= ~HS_CSR_LOO
;
236 if (pci_bus_write_config_word(slot
->bus
,
240 err("Could not clear LOO for slot %s",
241 hotplug_slot_name(slot
->hotplug_slot
));
250 * Device configuration functions
253 int cpci_configure_slot(struct slot
*slot
)
256 struct pci_bus
*parent
;
259 dbg("%s - enter", __func__
);
261 pci_lock_rescan_remove();
263 if (slot
->dev
== NULL
) {
264 dbg("pci_dev null, finding %02x:%02x:%x",
265 slot
->bus
->number
, PCI_SLOT(slot
->devfn
), PCI_FUNC(slot
->devfn
));
266 slot
->dev
= pci_get_slot(slot
->bus
, slot
->devfn
);
269 /* Still NULL? Well then scan for it! */
270 if (slot
->dev
== NULL
) {
272 dbg("pci_dev still null");
275 * This will generate pci_dev structures for all functions, but
276 * we will only call this case when lookup fails.
278 n
= pci_scan_slot(slot
->bus
, slot
->devfn
);
279 dbg("%s: pci_scan_slot returned %d", __func__
, n
);
280 slot
->dev
= pci_get_slot(slot
->bus
, slot
->devfn
);
281 if (slot
->dev
== NULL
) {
282 err("Could not find PCI device for slot %02x", slot
->number
);
287 parent
= slot
->dev
->bus
;
289 list_for_each_entry(dev
, &parent
->devices
, bus_list
) {
290 if (PCI_SLOT(dev
->devfn
) != PCI_SLOT(slot
->devfn
))
292 if (pci_is_bridge(dev
))
293 pci_hp_add_bridge(dev
);
297 pci_assign_unassigned_bridge_resources(parent
->self
);
299 pci_bus_add_devices(parent
);
302 pci_unlock_rescan_remove();
303 dbg("%s - exit", __func__
);
307 int cpci_unconfigure_slot(struct slot
*slot
)
309 struct pci_dev
*dev
, *temp
;
311 dbg("%s - enter", __func__
);
313 err("No device for slot %02x\n", slot
->number
);
317 pci_lock_rescan_remove();
319 list_for_each_entry_safe(dev
, temp
, &slot
->bus
->devices
, bus_list
) {
320 if (PCI_SLOT(dev
->devfn
) != PCI_SLOT(slot
->devfn
))
323 pci_stop_and_remove_bus_device(dev
);
326 pci_dev_put(slot
->dev
);
329 pci_unlock_rescan_remove();
331 dbg("%s - exit", __func__
);