Skip to content

Commit b9d320f

Browse files
Yinghai Lujbarnes993
authored andcommitted
PCI: add rescan to /sys/.../pci_bus/.../
After remove the device from /sys, we have to rescan all or find out the bridge and access /sys../device/rescan there. this patch add /sys/.../pci_bus/.../rescan. So user can rescan more easy. that is more clean and easy to understand. like after remove 0000:c4:00.0, you can rescan 0000:c4 directly. -v2: According to Jesse, use function instead of exposing attr, so could hide #ifdef in header file. also add code to remove rescan file in remove path. -v3: GregKH pointed out that we should use dev_attrs to avoid racing. So add pcibus_attrs and make it to be member of pcibus_attrs. -v4: Change name to pcibus_dev_attrs according to GregKH Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Yinghai Lu <yinghai@kernel.org> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent da7822e commit b9d320f

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎Documentation/ABI/testing/sysfs-bus-pci‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ Description:
7474
hot-remove the PCI device and any of its children.
7575
Depends on CONFIG_HOTPLUG.
7676

77+
What: /sys/bus/pci/devices/.../pci_bus/.../rescan
78+
Date: May 2011
79+
Contact: Linux PCI developers <linux-pci@vger.kernel.org>
80+
Description:
81+
Writing a non-zero value to this attribute will
82+
force a rescan of the bus and all child buses,
83+
and re-discover devices removed earlier from this
84+
part of the device tree. Depends on CONFIG_HOTPLUG.
85+
7786
What: /sys/bus/pci/devices/.../rescan
7887
Date: January 2009
7988
Contact: Linux PCI developers <linux-pci@vger.kernel.org>

‎drivers/pci/pci-sysfs.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,25 @@ remove_store(struct device *dev, struct device_attribute *dummy,
318318
count = ret;
319319
return count;
320320
}
321+
322+
static ssize_t
323+
dev_bus_rescan_store(struct device *dev, struct device_attribute *attr,
324+
const char *buf, size_t count)
325+
{
326+
unsigned long val;
327+
struct pci_bus *bus = to_pci_bus(dev);
328+
329+
if (strict_strtoul(buf, 0, &val) < 0)
330+
return -EINVAL;
331+
332+
if (val) {
333+
mutex_lock(&pci_remove_rescan_mutex);
334+
pci_rescan_bus(bus);
335+
mutex_unlock(&pci_remove_rescan_mutex);
336+
}
337+
return count;
338+
}
339+
321340
#endif
322341

323342
struct device_attribute pci_dev_attrs[] = {
@@ -347,6 +366,13 @@ struct device_attribute pci_dev_attrs[] = {
347366
__ATTR_NULL,
348367
};
349368

369+
struct device_attribute pcibus_dev_attrs[] = {
370+
#ifdef CONFIG_HOTPLUG
371+
__ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_bus_rescan_store),
372+
#endif
373+
__ATTR_NULL,
374+
};
375+
350376
static ssize_t
351377
boot_vga_show(struct device *dev, struct device_attribute *attr, char *buf)
352378
{

‎drivers/pci/pci.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ static inline int pci_no_d1d2(struct pci_dev *dev)
156156

157157
}
158158
extern struct device_attribute pci_dev_attrs[];
159+
extern struct device_attribute pcibus_dev_attrs[];
159160
extern struct device_attribute dev_attr_cpuaffinity;
160161
extern struct device_attribute dev_attr_cpulistaffinity;
161162
#ifdef CONFIG_HOTPLUG

‎drivers/pci/probe.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static void release_pcibus_dev(struct device *dev)
9595
static struct class pcibus_class = {
9696
.name = "pci_bus",
9797
.dev_release = &release_pcibus_dev,
98+
.dev_attrs = pcibus_dev_attrs,
9899
};
99100

100101
static int __init pcibus_class_init(void)

0 commit comments

Comments
 (0)