From: Jan Dittmer <jdittmer@ppp0.net>
To: Greg KH <greg@kroah.com>
Cc: Rolf Eike Beer <eike-kernel@sf-tec.de>,
linux-kernel@vger.kernel.org,
Hotplug List <pcihpd-discuss@lists.sourceforge.net>
Subject: Re: Is there a user space pci rescan method?
Date: Sun, 10 Oct 2004 02:13:46 +0200 [thread overview]
Message-ID: <41687EBA.7050506@ppp0.net> (raw)
In-Reply-To: <20040924145542.GA17147@kroah.com>
[-- Attachment #1: Type: text/plain, Size: 785 bytes --]
Greg KH wrote:
> Please just add the "rescan" support to fakephp, and everyone will be
> happy...
Well, I started to work on this for fun. What I currently have is a
stand-alone module which rescans the pci bus on insert and enables
previously disabled devices. This works (at least with my ieee1394 port).
Problem is, that fakephp does not get notified about this new pci device
and no new file is created in /sys/bus/pci/slots. So I'm going to add
this rescan functionality directly to fakephp.
Question is: where? My current idea is a fake hotplug slot "rescan" in
/sys/bus/pci/slots , where you can write "1" into the "power" attribute.
FWIW I've attached the standalone module and a kernel patch which rips
out the pci_bus_add_device functionality from pci_bus_add_devices.
Jan
[-- Attachment #2: pci_bus_add_device.patch --]
[-- Type: text/x-patch, Size: 1692 bytes --]
--- linus/include/linux/pci.h 2004-10-06 19:58:35.000000000 +0200
+++ pcirescan/include/linux/pci.h 2004-10-10 01:55:41.000000000 +0200
@@ -704,6 +704,7 @@
int pci_scan_slot(struct pci_bus *bus, int devfn);
struct pci_dev * pci_scan_single_device(struct pci_bus *bus, int devfn);
unsigned int pci_scan_child_bus(struct pci_bus *bus);
+void pci_bus_add_device(struct pci_dev *dev);
void pci_bus_add_devices(struct pci_bus *bus);
void pci_name_device(struct pci_dev *dev);
char *pci_class_name(u32 class);
diff -ur linus/drivers/pci/bus.c pcirescan/drivers/pci/bus.c
--- linus/drivers/pci/bus.c 2004-05-10 10:06:44.000000000 +0200
+++ pcirescan/drivers/pci/bus.c 2004-10-10 01:29:50.000000000 +0200
@@ -69,6 +69,20 @@
}
/**
+ * add a single device
+ */
+void __devinit pci_bus_add_device(struct pci_dev *dev) {
+ device_add(&dev->dev);
+
+ spin_lock(&pci_bus_lock);
+ list_add_tail(&dev->global_list, &pci_devices);
+ spin_unlock(&pci_bus_lock);
+
+ pci_proc_attach_device(dev);
+ pci_create_sysfs_dev_files(dev);
+}
+
+/**
* pci_bus_add_devices - insert newly discovered PCI devices
* @bus: bus to check for new devices
*
@@ -91,16 +105,7 @@
*/
if (!list_empty(&dev->global_list))
continue;
-
- device_add(&dev->dev);
-
- spin_lock(&pci_bus_lock);
- list_add_tail(&dev->global_list, &pci_devices);
- spin_unlock(&pci_bus_lock);
-
- pci_proc_attach_device(dev);
- pci_create_sysfs_dev_files(dev);
-
+ pci_bus_add_device(dev);
}
list_for_each_entry(dev, &bus->devices, bus_list) {
@@ -136,5 +141,6 @@
}
EXPORT_SYMBOL(pci_bus_alloc_resource);
+EXPORT_SYMBOL(pci_bus_add_device);
EXPORT_SYMBOL(pci_bus_add_devices);
EXPORT_SYMBOL(pci_enable_bridges);
[-- Attachment #3: Makefile --]
[-- Type: text/plain, Size: 202 bytes --]
ifneq ($(KERNELRELEASE),)
obj-m := pcirescan.o
else
KDIR := /lib/modules/$(shell uname -r)/build
# KDIR := ../pcirescan
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
endif
[-- Attachment #4: pcirescan.c --]
[-- Type: text/x-csrc, Size: 3174 bytes --]
/**
* rescan the pci bus on insert
* Jan Dittmer <jdittmer@ppp0.net>
*
* heavily based on a similar module from
* Vladimir Kondratiev, vladimir.kondratiev@intel.com
*/
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/errno.h>
/**
* Rescan slot.
* First, determine whether card in the slot has changed. It is
* done by compare of old and actual devices for function 0.
* If change detected, old device(s) removed, other functions
* scanned if it is multi-function dev, new devices inserted.
*
* @param temp Device template. Should be set: bus and devfn.
* @return Device for function 0
*/
void pci_rescan_slot(struct pci_dev *temp)
{
struct pci_bus *bus = temp->bus;
struct pci_dev* old_dev = pci_find_slot(bus->number,temp->devfn);
struct pci_dev *dev = NULL;
int func = 0;
int new_multi = 0; /* new multifunction device */
u8 hdr_type;
/* function 0 */
if (!pci_read_config_byte(temp, PCI_HEADER_TYPE, &hdr_type)) {
temp->hdr_type = hdr_type & 0x7f;
new_multi=hdr_type & 0x80;
if (!old_dev) {
dev = pci_scan_single_device(bus, temp->devfn);
if (dev) {
printk("Found new device on %s function %x:%x %x\n",
bus->name, temp->devfn >> 3,
temp->devfn & 7,
hdr_type);
pci_bus_add_device(dev);
}
}
if (new_multi) { /* continue scanning for other functions */
/* printk("Scanning subfunctions\n"); */
for (func = 1, temp->devfn++; func < 8; func++, temp->devfn++) {
// printk("%x\n", func);
if (pci_read_config_byte(temp, PCI_HEADER_TYPE, &hdr_type))
continue;
temp->hdr_type = hdr_type & 0x7f;
old_dev = pci_find_slot(bus->number, temp->devfn);
if (!old_dev) {
dev = pci_scan_single_device(bus, temp->devfn);
if (dev) {
printk("Found new device on %s function %x:%x %x\n",
bus->name, temp->devfn >> 3,
temp->devfn & 7,
hdr_type);
printk("Prettyname %s\n", dev->pretty_name);
// from drivers/pci/bus.c, pci_bus_add_devices
pci_bus_add_device(dev);
}
}
}
}
}
}
/**
* Rescan PCI bus.
* Assumed, some slots may have changed its content.
* Find old information about each slot and the new one.
* If they match, do nothing. Otherwise,
* remove/insert proper devices.
*
* @param bus
*/
static void pci_rescan_bus(const struct pci_bus *bus)
{
unsigned int devfn;
struct pci_dev dev0;
memset(&dev0, 0, sizeof(dev0));
dev0.bus = (struct pci_bus*)bus;
dev0.sysdata = bus->sysdata;
for (devfn = 0; devfn < 0x100; devfn += 8) {
dev0.devfn = devfn;
pci_rescan_slot(&dev0);
}
}
static void pci_rescan_buses(const struct list_head *list)
{
const struct list_head *l;
list_for_each(l,list) {
const struct pci_bus *b = pci_bus_b(l);
/*
printk("Scanning Bus %d:%d:%d, %s\n", b->number,
b->primary, b->secondary, b->name);
*/
pci_rescan_bus(b);
pci_rescan_buses(&b->children);
}
}
static int pci_rescan_init(void)
{
pci_rescan_buses(&pci_root_buses);
return -ENODEV;
}
static void pci_rescan_exit(void)
{}
module_init(pci_rescan_init);
module_exit(pci_rescan_exit);
MODULE_DESCRIPTION("Do PCI bus rescan");
MODULE_AUTHOR("jdi");
next prev parent reply other threads:[~2004-10-10 0:14 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-22 22:00 Is there a user space pci rescan method? Dave Aubin
2004-09-22 23:58 ` Jan Dittmer
2004-09-23 0:26 ` Greg KH
2004-09-23 15:04 ` Jan Dittmer
2004-09-23 16:49 ` Rolf Eike Beer
2004-09-23 16:53 ` Jan Dittmer
2004-09-23 17:05 ` Rolf Eike Beer
2004-09-24 10:41 ` Rolf Eike Beer
2004-09-24 11:42 ` Jan Dittmer
2004-09-24 12:12 ` Rolf Eike Beer
2004-09-24 12:16 ` Jan Dittmer
2004-09-24 12:32 ` Rolf Eike Beer
2004-09-24 14:55 ` Greg KH
2004-09-27 9:14 ` Rolf Eike Beer
2004-10-10 0:13 ` Jan Dittmer [this message]
2004-10-10 0:59 ` Jan Dittmer
2004-10-10 13:45 ` Jan Dittmer
2004-10-30 4:16 ` Greg KH
2004-10-31 23:59 ` [patch 1/2] fakephp: introduce pci_bus_add_device Jan Dittmer
2004-11-01 9:35 ` Christoph Hellwig
2004-11-02 22:51 ` Jan Dittmer
2004-11-11 23:47 ` Greg KH
2004-11-12 0:13 ` Jan Dittmer
2004-11-12 18:59 ` Greg KH
2004-10-31 23:59 ` [patch 2/2] fakephp: add pci bus rescan ability Jan Dittmer
2004-11-12 18:59 ` Greg KH
2004-09-24 13:09 ` [Pcihpd-discuss] Re: Is there a user space pci rescan method? Matthew Wilcox
2004-09-24 13:18 ` Rolf Eike Beer
2004-09-24 12:40 ` Jan Dittmer
2004-09-24 12:59 ` Rolf Eike Beer
2004-09-23 23:31 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2004-09-22 21:58 Dave Aubin
2004-09-22 20:30 Dave Aubin
2004-09-22 20:04 ` Alan Cox
2004-09-22 20:42 ` Richard B. Johnson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=41687EBA.7050506@ppp0.net \
--to=jdittmer@ppp0.net \
--cc=eike-kernel@sf-tec.de \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pcihpd-discuss@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).