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/config.h>
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/pci.h>
30 #include <linux/proc_fs.h>
32 #include "pci_hotplug.h"
33 #include "cpci_hotplug.h"
35 #define MY_NAME "cpci_hotplug"
37 extern int cpci_debug;
39 #define dbg(format, arg...) \
42 printk (KERN_DEBUG "%s: " format "\n", \
45 #define err(format, arg...) printk(KERN_ERR "%s: " format "\n", MY_NAME , ## arg)
46 #define info(format, arg...) printk(KERN_INFO "%s: " format "\n", MY_NAME , ## arg)
47 #define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", MY_NAME , ## arg)
49 #define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1))
52 u8 cpci_get_attention_status(struct slot* slot)
57 hs_cap = pci_bus_find_capability(slot->bus,
63 if (pci_bus_read_config_word(slot->bus,
69 return hs_csr & 0x0008 ? 1 : 0;
72 int cpci_set_attention_status(struct slot* slot, int status)
77 hs_cap = pci_bus_find_capability(slot->bus,
82 if (pci_bus_read_config_word(slot->bus,
90 hs_csr &= ~HS_CSR_LOO;
91 if (pci_bus_write_config_word(slot->bus,
99 u16 cpci_get_hs_csr(struct slot* slot)
104 hs_cap = pci_bus_find_capability(slot->bus,
109 if (pci_bus_read_config_word(slot->bus,
117 int cpci_check_and_clear_ins(struct slot* slot)
123 hs_cap = pci_bus_find_capability(slot->bus,
128 if (pci_bus_read_config_word(slot->bus,
133 if (hs_csr & HS_CSR_INS) {
134 /* Clear INS (by setting it) */
135 if (pci_bus_write_config_word(slot->bus,
146 int cpci_check_ext(struct slot* slot)
152 hs_cap = pci_bus_find_capability(slot->bus,
157 if (pci_bus_read_config_word(slot->bus,
162 if (hs_csr & HS_CSR_EXT)
167 int cpci_clear_ext(struct slot* slot)
172 hs_cap = pci_bus_find_capability(slot->bus,
177 if (pci_bus_read_config_word(slot->bus,
182 if (hs_csr & HS_CSR_EXT) {
183 /* Clear EXT (by setting it) */
184 if (pci_bus_write_config_word(slot->bus,
193 int cpci_led_on(struct slot* slot)
198 hs_cap = pci_bus_find_capability(slot->bus,
203 if (pci_bus_read_config_word(slot->bus,
208 if ((hs_csr & HS_CSR_LOO) != HS_CSR_LOO) {
209 hs_csr |= HS_CSR_LOO;
210 if (pci_bus_write_config_word(slot->bus,
214 err("Could not set LOO for slot %s",
215 slot->hotplug_slot->name);
222 int cpci_led_off(struct slot* slot)
227 hs_cap = pci_bus_find_capability(slot->bus,
232 if (pci_bus_read_config_word(slot->bus,
237 if (hs_csr & HS_CSR_LOO) {
238 hs_csr &= ~HS_CSR_LOO;
239 if (pci_bus_write_config_word(slot->bus,
243 err("Could not clear LOO for slot %s",
244 slot->hotplug_slot->name);
253 * Device configuration functions
256 int cpci_configure_slot(struct slot* slot)
259 struct pci_bus *child;
261 dbg("%s - enter", __FUNCTION__);
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", __FUNCTION__, n);
281 pci_bus_add_devices(slot->bus);
282 slot->dev = pci_get_slot(slot->bus, slot->devfn);
283 if (slot->dev == NULL) {
284 err("Could not find PCI device for slot %02x", slot->number);
289 if (slot->dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
290 pci_read_config_byte(slot->dev, PCI_SECONDARY_BUS, &busnr);
291 child = pci_add_new_bus(slot->dev->bus, slot->dev, busnr);
292 pci_do_scan_bus(child);
293 pci_bus_size_bridges(child);
296 pci_bus_assign_resources(slot->dev->bus);
298 dbg("%s - exit", __FUNCTION__);
302 int cpci_unconfigure_slot(struct slot* slot)
307 dbg("%s - enter", __FUNCTION__);
309 err("No device for slot %02x\n", slot->number);
313 for (i = 0; i < 8; i++) {
314 dev = pci_get_slot(slot->bus,
315 PCI_DEVFN(PCI_SLOT(slot->devfn), i));
317 pci_remove_bus_device(dev);
321 dbg("%s - exit", __FUNCTION__);