1 // SPDX-License-Identifier: GPL-2.0+
3 * CompactPCI Hot Plug Driver PCI functions
5 * Copyright (C) 2002,2005 by SOMA Networks, Inc.
9 * Send feedback to <scottm@somanetworks.com>
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/pci.h>
15 #include <linux/pci_hotplug.h>
16 #include <linux/proc_fs.h>
18 #include "cpci_hotplug.h"
20 #define MY_NAME "cpci_hotplug"
22 extern int cpci_debug
;
24 #define dbg(format, arg...) \
27 printk(KERN_DEBUG "%s: " format "\n", \
30 #define err(format, arg...) printk(KERN_ERR "%s: " format "\n", MY_NAME, ## arg)
31 #define info(format, arg...) printk(KERN_INFO "%s: " format "\n", MY_NAME, ## arg)
32 #define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", MY_NAME, ## arg)
35 u8
cpci_get_attention_status(struct slot
*slot
)
40 hs_cap
= pci_bus_find_capability(slot
->bus
,
46 if (pci_bus_read_config_word(slot
->bus
,
52 return hs_csr
& 0x0008 ? 1 : 0;
55 int cpci_set_attention_status(struct slot
*slot
, int status
)
60 hs_cap
= pci_bus_find_capability(slot
->bus
,
65 if (pci_bus_read_config_word(slot
->bus
,
73 hs_csr
&= ~HS_CSR_LOO
;
74 if (pci_bus_write_config_word(slot
->bus
,
82 u16
cpci_get_hs_csr(struct slot
*slot
)
87 hs_cap
= pci_bus_find_capability(slot
->bus
,
92 if (pci_bus_read_config_word(slot
->bus
,
100 int cpci_check_and_clear_ins(struct slot
*slot
)
106 hs_cap
= pci_bus_find_capability(slot
->bus
,
111 if (pci_bus_read_config_word(slot
->bus
,
116 if (hs_csr
& HS_CSR_INS
) {
117 /* Clear INS (by setting it) */
118 if (pci_bus_write_config_word(slot
->bus
,
129 int cpci_check_ext(struct slot
*slot
)
135 hs_cap
= pci_bus_find_capability(slot
->bus
,
140 if (pci_bus_read_config_word(slot
->bus
,
145 if (hs_csr
& HS_CSR_EXT
)
150 int cpci_clear_ext(struct slot
*slot
)
155 hs_cap
= pci_bus_find_capability(slot
->bus
,
160 if (pci_bus_read_config_word(slot
->bus
,
165 if (hs_csr
& HS_CSR_EXT
) {
166 /* Clear EXT (by setting it) */
167 if (pci_bus_write_config_word(slot
->bus
,
176 int cpci_led_on(struct slot
*slot
)
181 hs_cap
= pci_bus_find_capability(slot
->bus
,
186 if (pci_bus_read_config_word(slot
->bus
,
191 if ((hs_csr
& HS_CSR_LOO
) != HS_CSR_LOO
) {
192 hs_csr
|= HS_CSR_LOO
;
193 if (pci_bus_write_config_word(slot
->bus
,
197 err("Could not set LOO for slot %s",
198 hotplug_slot_name(slot
->hotplug_slot
));
205 int cpci_led_off(struct slot
*slot
)
210 hs_cap
= pci_bus_find_capability(slot
->bus
,
215 if (pci_bus_read_config_word(slot
->bus
,
220 if (hs_csr
& HS_CSR_LOO
) {
221 hs_csr
&= ~HS_CSR_LOO
;
222 if (pci_bus_write_config_word(slot
->bus
,
226 err("Could not clear LOO for slot %s",
227 hotplug_slot_name(slot
->hotplug_slot
));
236 * Device configuration functions
239 int cpci_configure_slot(struct slot
*slot
)
242 struct pci_bus
*parent
;
245 dbg("%s - enter", __func__
);
247 pci_lock_rescan_remove();
249 if (slot
->dev
== NULL
) {
250 dbg("pci_dev null, finding %02x:%02x:%x",
251 slot
->bus
->number
, PCI_SLOT(slot
->devfn
), PCI_FUNC(slot
->devfn
));
252 slot
->dev
= pci_get_slot(slot
->bus
, slot
->devfn
);
255 /* Still NULL? Well then scan for it! */
256 if (slot
->dev
== NULL
) {
258 dbg("pci_dev still null");
261 * This will generate pci_dev structures for all functions, but
262 * we will only call this case when lookup fails.
264 n
= pci_scan_slot(slot
->bus
, slot
->devfn
);
265 dbg("%s: pci_scan_slot returned %d", __func__
, n
);
266 slot
->dev
= pci_get_slot(slot
->bus
, slot
->devfn
);
267 if (slot
->dev
== NULL
) {
268 err("Could not find PCI device for slot %02x", slot
->number
);
273 parent
= slot
->dev
->bus
;
275 for_each_pci_bridge(dev
, parent
) {
276 if (PCI_SLOT(dev
->devfn
) == PCI_SLOT(slot
->devfn
))
277 pci_hp_add_bridge(dev
);
280 pci_assign_unassigned_bridge_resources(parent
->self
);
282 pci_bus_add_devices(parent
);
285 pci_unlock_rescan_remove();
286 dbg("%s - exit", __func__
);
290 int cpci_unconfigure_slot(struct slot
*slot
)
292 struct pci_dev
*dev
, *temp
;
294 dbg("%s - enter", __func__
);
296 err("No device for slot %02x\n", slot
->number
);
300 pci_lock_rescan_remove();
302 list_for_each_entry_safe(dev
, temp
, &slot
->bus
->devices
, bus_list
) {
303 if (PCI_SLOT(dev
->devfn
) != PCI_SLOT(slot
->devfn
))
306 pci_stop_and_remove_bus_device(dev
);
309 pci_dev_put(slot
->dev
);
312 pci_unlock_rescan_remove();
314 dbg("%s - exit", __func__
);