* [PATCH 1/2] PCI: Compile pci-sysfs.c only if CONFIG_SYSFS=y
@ 2023-10-30 12:32 Lukas Wunner
2023-10-30 12:33 ` [PATCH 2/2] PCI: Remove obsolete pci_cleanup_rom() declaration Lukas Wunner
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Lukas Wunner @ 2023-10-30 12:32 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci, Krzysztof Wilczynski, Alistair Francis
It is possible to enable CONFIG_PCI but disable CONFIG_SYSFS and for
space-constrained devices such as routers, such a configuration may
actually make sense.
However pci-sysfs.c is compiled even if CONFIG_SYSFS is disabled,
unnecessarily increasing the kernel's size.
To rectify that:
* Move pci_mmap_fits() to mmap.c. It is not only needed by
pci-sysfs.c, but also proc.c.
* Move pci_dev_type to probe.c and make it private. It references
pci_dev_attr_groups in pci-sysfs.c. Make that public instead for
consistency with pci_dev_groups, pcibus_groups and pci_bus_groups,
which are likewise public and referenced by struct definitions in
pci-driver.c and probe.c.
* Define pci_dev_groups, pci_dev_attr_groups, pcibus_groups and
pci_bus_groups to NULL if CONFIG_SYSFS is disabled. Provide empty
static inlines for pci_{create,remove}_legacy_files() and
pci_{create,remove}_sysfs_dev_files().
Result:
vmlinux size is reduced by 122996 bytes in my arm 32-bit test build.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
---
drivers/pci/Makefile | 4 ++--
drivers/pci/mmap.c | 29 +++++++++++++++++++++++++++++
drivers/pci/pci-sysfs.c | 29 +----------------------------
drivers/pci/pci.h | 18 ++++++++++++++----
drivers/pci/probe.c | 4 ++++
5 files changed, 50 insertions(+), 34 deletions(-)
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index cc8b4e01e29d..96f4759f2bd3 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -4,7 +4,7 @@
obj-$(CONFIG_PCI) += access.o bus.o probe.o host-bridge.o \
remove.o pci.o pci-driver.o search.o \
- pci-sysfs.o rom.o setup-res.o irq.o vpd.o \
+ rom.o setup-res.o irq.o vpd.o \
setup-bus.o vc.o mmap.o setup-irq.o
obj-$(CONFIG_PCI) += msi/
@@ -12,7 +12,7 @@ obj-$(CONFIG_PCI) += pcie/
ifdef CONFIG_PCI
obj-$(CONFIG_PROC_FS) += proc.o
-obj-$(CONFIG_SYSFS) += slot.o
+obj-$(CONFIG_SYSFS) += pci-sysfs.o slot.o
obj-$(CONFIG_ACPI) += pci-acpi.o
endif
diff --git a/drivers/pci/mmap.c b/drivers/pci/mmap.c
index 4504039056d1..8da3347a95c4 100644
--- a/drivers/pci/mmap.c
+++ b/drivers/pci/mmap.c
@@ -11,6 +11,8 @@
#include <linux/mm.h>
#include <linux/pci.h>
+#include "pci.h"
+
#ifdef ARCH_GENERIC_PCI_MMAP_RESOURCE
static const struct vm_operations_struct pci_phys_vm_ops = {
@@ -50,3 +52,30 @@ int pci_mmap_resource_range(struct pci_dev *pdev, int bar,
}
#endif
+
+#if (defined(CONFIG_SYSFS) || defined(CONFIG_PROC_FS)) && \
+ (defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE))
+
+int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
+ enum pci_mmap_api mmap_api)
+{
+ resource_size_t pci_start = 0, pci_end;
+ unsigned long nr, start, size;
+
+ if (pci_resource_len(pdev, resno) == 0)
+ return 0;
+ nr = vma_pages(vma);
+ start = vma->vm_pgoff;
+ size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
+ if (mmap_api == PCI_MMAP_PROCFS) {
+ pci_resource_to_user(pdev, resno, &pdev->resource[resno],
+ &pci_start, &pci_end);
+ pci_start >>= PAGE_SHIFT;
+ }
+ if (start >= pci_start && start < pci_start + size &&
+ start + nr <= pci_start + size)
+ return 1;
+ return 0;
+}
+
+#endif
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 2321fdfefd7d..44ed30df08c3 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1022,29 +1022,6 @@ void pci_remove_legacy_files(struct pci_bus *b)
#endif /* HAVE_PCI_LEGACY */
#if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)
-
-int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
- enum pci_mmap_api mmap_api)
-{
- unsigned long nr, start, size;
- resource_size_t pci_start = 0, pci_end;
-
- if (pci_resource_len(pdev, resno) == 0)
- return 0;
- nr = vma_pages(vma);
- start = vma->vm_pgoff;
- size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
- if (mmap_api == PCI_MMAP_PROCFS) {
- pci_resource_to_user(pdev, resno, &pdev->resource[resno],
- &pci_start, &pci_end);
- pci_start >>= PAGE_SHIFT;
- }
- if (start >= pci_start && start < pci_start + size &&
- start + nr <= pci_start + size)
- return 1;
- return 0;
-}
-
/**
* pci_mmap_resource - map a PCI resource into user memory space
* @kobj: kobject for mapping
@@ -1660,7 +1637,7 @@ static const struct attribute_group pcie_dev_attr_group = {
.is_visible = pcie_dev_attrs_are_visible,
};
-static const struct attribute_group *pci_dev_attr_groups[] = {
+const struct attribute_group *pci_dev_attr_groups[] = {
&pci_dev_attr_group,
&pci_dev_hp_attr_group,
#ifdef CONFIG_PCI_IOV
@@ -1677,7 +1654,3 @@ static const struct attribute_group *pci_dev_attr_groups[] = {
#endif
NULL,
};
-
-const struct device_type pci_dev_type = {
- .groups = pci_dev_attr_groups,
-};
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 5ecbcf041179..aedaf4e51146 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -31,8 +31,6 @@ bool pcie_cap_has_rtctl(const struct pci_dev *dev);
/* Functions internal to the PCI core code */
-int pci_create_sysfs_dev_files(struct pci_dev *pdev);
-void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
void pci_cleanup_rom(struct pci_dev *dev);
#ifdef CONFIG_DMI
extern const struct attribute_group pci_dev_smbios_attr_group;
@@ -152,7 +150,7 @@ static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
/* Functions for PCI Hotplug drivers to use */
int pci_hp_add_bridge(struct pci_dev *dev);
-#ifdef HAVE_PCI_LEGACY
+#if defined(CONFIG_SYSFS) && defined(HAVE_PCI_LEGACY)
void pci_create_legacy_files(struct pci_bus *bus);
void pci_remove_legacy_files(struct pci_bus *bus);
#else
@@ -185,10 +183,22 @@ static inline int pci_no_d1d2(struct pci_dev *dev)
return (dev->no_d1d2 || parent_dstates);
}
+
+#ifdef CONFIG_SYSFS
+int pci_create_sysfs_dev_files(struct pci_dev *pdev);
+void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
extern const struct attribute_group *pci_dev_groups[];
+extern const struct attribute_group *pci_dev_attr_groups[];
extern const struct attribute_group *pcibus_groups[];
-extern const struct device_type pci_dev_type;
extern const struct attribute_group *pci_bus_groups[];
+#else
+static inline int pci_create_sysfs_dev_files(struct pci_dev *pdev) { return 0; }
+static inline void pci_remove_sysfs_dev_files(struct pci_dev *pdev) { }
+#define pci_dev_groups NULL
+#define pci_dev_attr_groups NULL
+#define pcibus_groups NULL
+#define pci_bus_groups NULL
+#endif
extern unsigned long pci_hotplug_io_size;
extern unsigned long pci_hotplug_mmio_size;
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index ed6b7f48736a..500ac154fdfb 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2307,6 +2307,10 @@ static void pci_release_dev(struct device *dev)
kfree(pci_dev);
}
+static const struct device_type pci_dev_type = {
+ .groups = pci_dev_attr_groups,
+};
+
struct pci_dev *pci_alloc_dev(struct pci_bus *bus)
{
struct pci_dev *dev;
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/2] PCI: Remove obsolete pci_cleanup_rom() declaration
2023-10-30 12:32 [PATCH 1/2] PCI: Compile pci-sysfs.c only if CONFIG_SYSFS=y Lukas Wunner
@ 2023-10-30 12:33 ` Lukas Wunner
2023-11-02 3:36 ` Alistair Francis
2023-11-02 3:37 ` [PATCH 1/2] PCI: Compile pci-sysfs.c only if CONFIG_SYSFS=y Alistair Francis
2024-02-08 21:44 ` Bjorn Helgaas
2 siblings, 1 reply; 5+ messages in thread
From: Lukas Wunner @ 2023-10-30 12:33 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci, Krzysztof Wilczynski, Alistair Francis
Commit d9c8bea179a6 ("PCI: Remove unused IORESOURCE_ROM_COPY and
IORESOURCE_ROM_BIOS_COPY") removed pci_cleanup_rom(), but retained
its declaration in pci.h.
Remove it.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
---
drivers/pci/pci.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index aedaf4e51146..d865c4321e14 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -31,7 +31,6 @@ bool pcie_cap_has_rtctl(const struct pci_dev *dev);
/* Functions internal to the PCI core code */
-void pci_cleanup_rom(struct pci_dev *dev);
#ifdef CONFIG_DMI
extern const struct attribute_group pci_dev_smbios_attr_group;
#endif
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 2/2] PCI: Remove obsolete pci_cleanup_rom() declaration
2023-10-30 12:33 ` [PATCH 2/2] PCI: Remove obsolete pci_cleanup_rom() declaration Lukas Wunner
@ 2023-11-02 3:36 ` Alistair Francis
0 siblings, 0 replies; 5+ messages in thread
From: Alistair Francis @ 2023-11-02 3:36 UTC (permalink / raw)
To: Lukas Wunner; +Cc: Bjorn Helgaas, linux-pci, Krzysztof Wilczynski
On Mon, Oct 30, 2023 at 10:34 PM Lukas Wunner <lukas@wunner.de> wrote:
>
> Commit d9c8bea179a6 ("PCI: Remove unused IORESOURCE_ROM_COPY and
> IORESOURCE_ROM_BIOS_COPY") removed pci_cleanup_rom(), but retained
> its declaration in pci.h.
>
> Remove it.
>
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> drivers/pci/pci.h | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index aedaf4e51146..d865c4321e14 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -31,7 +31,6 @@ bool pcie_cap_has_rtctl(const struct pci_dev *dev);
>
> /* Functions internal to the PCI core code */
>
> -void pci_cleanup_rom(struct pci_dev *dev);
> #ifdef CONFIG_DMI
> extern const struct attribute_group pci_dev_smbios_attr_group;
> #endif
> --
> 2.40.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] PCI: Compile pci-sysfs.c only if CONFIG_SYSFS=y
2023-10-30 12:32 [PATCH 1/2] PCI: Compile pci-sysfs.c only if CONFIG_SYSFS=y Lukas Wunner
2023-10-30 12:33 ` [PATCH 2/2] PCI: Remove obsolete pci_cleanup_rom() declaration Lukas Wunner
@ 2023-11-02 3:37 ` Alistair Francis
2024-02-08 21:44 ` Bjorn Helgaas
2 siblings, 0 replies; 5+ messages in thread
From: Alistair Francis @ 2023-11-02 3:37 UTC (permalink / raw)
To: Lukas Wunner; +Cc: Bjorn Helgaas, linux-pci, Krzysztof Wilczynski
On Mon, Oct 30, 2023 at 10:32 PM Lukas Wunner <lukas@wunner.de> wrote:
>
> It is possible to enable CONFIG_PCI but disable CONFIG_SYSFS and for
> space-constrained devices such as routers, such a configuration may
> actually make sense.
>
> However pci-sysfs.c is compiled even if CONFIG_SYSFS is disabled,
> unnecessarily increasing the kernel's size.
>
> To rectify that:
>
> * Move pci_mmap_fits() to mmap.c. It is not only needed by
> pci-sysfs.c, but also proc.c.
>
> * Move pci_dev_type to probe.c and make it private. It references
> pci_dev_attr_groups in pci-sysfs.c. Make that public instead for
> consistency with pci_dev_groups, pcibus_groups and pci_bus_groups,
> which are likewise public and referenced by struct definitions in
> pci-driver.c and probe.c.
>
> * Define pci_dev_groups, pci_dev_attr_groups, pcibus_groups and
> pci_bus_groups to NULL if CONFIG_SYSFS is disabled. Provide empty
> static inlines for pci_{create,remove}_legacy_files() and
> pci_{create,remove}_sysfs_dev_files().
>
> Result:
>
> vmlinux size is reduced by 122996 bytes in my arm 32-bit test build.
>
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> drivers/pci/Makefile | 4 ++--
> drivers/pci/mmap.c | 29 +++++++++++++++++++++++++++++
> drivers/pci/pci-sysfs.c | 29 +----------------------------
> drivers/pci/pci.h | 18 ++++++++++++++----
> drivers/pci/probe.c | 4 ++++
> 5 files changed, 50 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
> index cc8b4e01e29d..96f4759f2bd3 100644
> --- a/drivers/pci/Makefile
> +++ b/drivers/pci/Makefile
> @@ -4,7 +4,7 @@
>
> obj-$(CONFIG_PCI) += access.o bus.o probe.o host-bridge.o \
> remove.o pci.o pci-driver.o search.o \
> - pci-sysfs.o rom.o setup-res.o irq.o vpd.o \
> + rom.o setup-res.o irq.o vpd.o \
> setup-bus.o vc.o mmap.o setup-irq.o
>
> obj-$(CONFIG_PCI) += msi/
> @@ -12,7 +12,7 @@ obj-$(CONFIG_PCI) += pcie/
>
> ifdef CONFIG_PCI
> obj-$(CONFIG_PROC_FS) += proc.o
> -obj-$(CONFIG_SYSFS) += slot.o
> +obj-$(CONFIG_SYSFS) += pci-sysfs.o slot.o
> obj-$(CONFIG_ACPI) += pci-acpi.o
> endif
>
> diff --git a/drivers/pci/mmap.c b/drivers/pci/mmap.c
> index 4504039056d1..8da3347a95c4 100644
> --- a/drivers/pci/mmap.c
> +++ b/drivers/pci/mmap.c
> @@ -11,6 +11,8 @@
> #include <linux/mm.h>
> #include <linux/pci.h>
>
> +#include "pci.h"
> +
> #ifdef ARCH_GENERIC_PCI_MMAP_RESOURCE
>
> static const struct vm_operations_struct pci_phys_vm_ops = {
> @@ -50,3 +52,30 @@ int pci_mmap_resource_range(struct pci_dev *pdev, int bar,
> }
>
> #endif
> +
> +#if (defined(CONFIG_SYSFS) || defined(CONFIG_PROC_FS)) && \
> + (defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE))
> +
> +int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
> + enum pci_mmap_api mmap_api)
> +{
> + resource_size_t pci_start = 0, pci_end;
> + unsigned long nr, start, size;
> +
> + if (pci_resource_len(pdev, resno) == 0)
> + return 0;
> + nr = vma_pages(vma);
> + start = vma->vm_pgoff;
> + size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
> + if (mmap_api == PCI_MMAP_PROCFS) {
> + pci_resource_to_user(pdev, resno, &pdev->resource[resno],
> + &pci_start, &pci_end);
> + pci_start >>= PAGE_SHIFT;
> + }
> + if (start >= pci_start && start < pci_start + size &&
> + start + nr <= pci_start + size)
> + return 1;
> + return 0;
> +}
> +
> +#endif
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index 2321fdfefd7d..44ed30df08c3 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -1022,29 +1022,6 @@ void pci_remove_legacy_files(struct pci_bus *b)
> #endif /* HAVE_PCI_LEGACY */
>
> #if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)
> -
> -int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
> - enum pci_mmap_api mmap_api)
> -{
> - unsigned long nr, start, size;
> - resource_size_t pci_start = 0, pci_end;
> -
> - if (pci_resource_len(pdev, resno) == 0)
> - return 0;
> - nr = vma_pages(vma);
> - start = vma->vm_pgoff;
> - size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
> - if (mmap_api == PCI_MMAP_PROCFS) {
> - pci_resource_to_user(pdev, resno, &pdev->resource[resno],
> - &pci_start, &pci_end);
> - pci_start >>= PAGE_SHIFT;
> - }
> - if (start >= pci_start && start < pci_start + size &&
> - start + nr <= pci_start + size)
> - return 1;
> - return 0;
> -}
> -
> /**
> * pci_mmap_resource - map a PCI resource into user memory space
> * @kobj: kobject for mapping
> @@ -1660,7 +1637,7 @@ static const struct attribute_group pcie_dev_attr_group = {
> .is_visible = pcie_dev_attrs_are_visible,
> };
>
> -static const struct attribute_group *pci_dev_attr_groups[] = {
> +const struct attribute_group *pci_dev_attr_groups[] = {
> &pci_dev_attr_group,
> &pci_dev_hp_attr_group,
> #ifdef CONFIG_PCI_IOV
> @@ -1677,7 +1654,3 @@ static const struct attribute_group *pci_dev_attr_groups[] = {
> #endif
> NULL,
> };
> -
> -const struct device_type pci_dev_type = {
> - .groups = pci_dev_attr_groups,
> -};
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index 5ecbcf041179..aedaf4e51146 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -31,8 +31,6 @@ bool pcie_cap_has_rtctl(const struct pci_dev *dev);
>
> /* Functions internal to the PCI core code */
>
> -int pci_create_sysfs_dev_files(struct pci_dev *pdev);
> -void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
> void pci_cleanup_rom(struct pci_dev *dev);
> #ifdef CONFIG_DMI
> extern const struct attribute_group pci_dev_smbios_attr_group;
> @@ -152,7 +150,7 @@ static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
> /* Functions for PCI Hotplug drivers to use */
> int pci_hp_add_bridge(struct pci_dev *dev);
>
> -#ifdef HAVE_PCI_LEGACY
> +#if defined(CONFIG_SYSFS) && defined(HAVE_PCI_LEGACY)
> void pci_create_legacy_files(struct pci_bus *bus);
> void pci_remove_legacy_files(struct pci_bus *bus);
> #else
> @@ -185,10 +183,22 @@ static inline int pci_no_d1d2(struct pci_dev *dev)
> return (dev->no_d1d2 || parent_dstates);
>
> }
> +
> +#ifdef CONFIG_SYSFS
> +int pci_create_sysfs_dev_files(struct pci_dev *pdev);
> +void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
> extern const struct attribute_group *pci_dev_groups[];
> +extern const struct attribute_group *pci_dev_attr_groups[];
> extern const struct attribute_group *pcibus_groups[];
> -extern const struct device_type pci_dev_type;
> extern const struct attribute_group *pci_bus_groups[];
> +#else
> +static inline int pci_create_sysfs_dev_files(struct pci_dev *pdev) { return 0; }
> +static inline void pci_remove_sysfs_dev_files(struct pci_dev *pdev) { }
> +#define pci_dev_groups NULL
> +#define pci_dev_attr_groups NULL
> +#define pcibus_groups NULL
> +#define pci_bus_groups NULL
> +#endif
>
> extern unsigned long pci_hotplug_io_size;
> extern unsigned long pci_hotplug_mmio_size;
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index ed6b7f48736a..500ac154fdfb 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -2307,6 +2307,10 @@ static void pci_release_dev(struct device *dev)
> kfree(pci_dev);
> }
>
> +static const struct device_type pci_dev_type = {
> + .groups = pci_dev_attr_groups,
> +};
> +
> struct pci_dev *pci_alloc_dev(struct pci_bus *bus)
> {
> struct pci_dev *dev;
> --
> 2.40.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 1/2] PCI: Compile pci-sysfs.c only if CONFIG_SYSFS=y
2023-10-30 12:32 [PATCH 1/2] PCI: Compile pci-sysfs.c only if CONFIG_SYSFS=y Lukas Wunner
2023-10-30 12:33 ` [PATCH 2/2] PCI: Remove obsolete pci_cleanup_rom() declaration Lukas Wunner
2023-11-02 3:37 ` [PATCH 1/2] PCI: Compile pci-sysfs.c only if CONFIG_SYSFS=y Alistair Francis
@ 2024-02-08 21:44 ` Bjorn Helgaas
2 siblings, 0 replies; 5+ messages in thread
From: Bjorn Helgaas @ 2024-02-08 21:44 UTC (permalink / raw)
To: Lukas Wunner; +Cc: linux-pci, Krzysztof Wilczynski, Alistair Francis
On Mon, Oct 30, 2023 at 01:32:12PM +0100, Lukas Wunner wrote:
> It is possible to enable CONFIG_PCI but disable CONFIG_SYSFS and for
> space-constrained devices such as routers, such a configuration may
> actually make sense.
>
> However pci-sysfs.c is compiled even if CONFIG_SYSFS is disabled,
> unnecessarily increasing the kernel's size.
>
> To rectify that:
>
> * Move pci_mmap_fits() to mmap.c. It is not only needed by
> pci-sysfs.c, but also proc.c.
>
> * Move pci_dev_type to probe.c and make it private. It references
> pci_dev_attr_groups in pci-sysfs.c. Make that public instead for
> consistency with pci_dev_groups, pcibus_groups and pci_bus_groups,
> which are likewise public and referenced by struct definitions in
> pci-driver.c and probe.c.
>
> * Define pci_dev_groups, pci_dev_attr_groups, pcibus_groups and
> pci_bus_groups to NULL if CONFIG_SYSFS is disabled. Provide empty
> static inlines for pci_{create,remove}_legacy_files() and
> pci_{create,remove}_sysfs_dev_files().
>
> Result:
>
> vmlinux size is reduced by 122996 bytes in my arm 32-bit test build.
>
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
Both applied to pci/sysfs with Alistair's Reviewed-by, thanks!
> ---
> drivers/pci/Makefile | 4 ++--
> drivers/pci/mmap.c | 29 +++++++++++++++++++++++++++++
> drivers/pci/pci-sysfs.c | 29 +----------------------------
> drivers/pci/pci.h | 18 ++++++++++++++----
> drivers/pci/probe.c | 4 ++++
> 5 files changed, 50 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
> index cc8b4e01e29d..96f4759f2bd3 100644
> --- a/drivers/pci/Makefile
> +++ b/drivers/pci/Makefile
> @@ -4,7 +4,7 @@
>
> obj-$(CONFIG_PCI) += access.o bus.o probe.o host-bridge.o \
> remove.o pci.o pci-driver.o search.o \
> - pci-sysfs.o rom.o setup-res.o irq.o vpd.o \
> + rom.o setup-res.o irq.o vpd.o \
> setup-bus.o vc.o mmap.o setup-irq.o
>
> obj-$(CONFIG_PCI) += msi/
> @@ -12,7 +12,7 @@ obj-$(CONFIG_PCI) += pcie/
>
> ifdef CONFIG_PCI
> obj-$(CONFIG_PROC_FS) += proc.o
> -obj-$(CONFIG_SYSFS) += slot.o
> +obj-$(CONFIG_SYSFS) += pci-sysfs.o slot.o
> obj-$(CONFIG_ACPI) += pci-acpi.o
> endif
>
> diff --git a/drivers/pci/mmap.c b/drivers/pci/mmap.c
> index 4504039056d1..8da3347a95c4 100644
> --- a/drivers/pci/mmap.c
> +++ b/drivers/pci/mmap.c
> @@ -11,6 +11,8 @@
> #include <linux/mm.h>
> #include <linux/pci.h>
>
> +#include "pci.h"
> +
> #ifdef ARCH_GENERIC_PCI_MMAP_RESOURCE
>
> static const struct vm_operations_struct pci_phys_vm_ops = {
> @@ -50,3 +52,30 @@ int pci_mmap_resource_range(struct pci_dev *pdev, int bar,
> }
>
> #endif
> +
> +#if (defined(CONFIG_SYSFS) || defined(CONFIG_PROC_FS)) && \
> + (defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE))
> +
> +int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
> + enum pci_mmap_api mmap_api)
> +{
> + resource_size_t pci_start = 0, pci_end;
> + unsigned long nr, start, size;
> +
> + if (pci_resource_len(pdev, resno) == 0)
> + return 0;
> + nr = vma_pages(vma);
> + start = vma->vm_pgoff;
> + size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
> + if (mmap_api == PCI_MMAP_PROCFS) {
> + pci_resource_to_user(pdev, resno, &pdev->resource[resno],
> + &pci_start, &pci_end);
> + pci_start >>= PAGE_SHIFT;
> + }
> + if (start >= pci_start && start < pci_start + size &&
> + start + nr <= pci_start + size)
> + return 1;
> + return 0;
> +}
> +
> +#endif
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index 2321fdfefd7d..44ed30df08c3 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -1022,29 +1022,6 @@ void pci_remove_legacy_files(struct pci_bus *b)
> #endif /* HAVE_PCI_LEGACY */
>
> #if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)
> -
> -int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
> - enum pci_mmap_api mmap_api)
> -{
> - unsigned long nr, start, size;
> - resource_size_t pci_start = 0, pci_end;
> -
> - if (pci_resource_len(pdev, resno) == 0)
> - return 0;
> - nr = vma_pages(vma);
> - start = vma->vm_pgoff;
> - size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
> - if (mmap_api == PCI_MMAP_PROCFS) {
> - pci_resource_to_user(pdev, resno, &pdev->resource[resno],
> - &pci_start, &pci_end);
> - pci_start >>= PAGE_SHIFT;
> - }
> - if (start >= pci_start && start < pci_start + size &&
> - start + nr <= pci_start + size)
> - return 1;
> - return 0;
> -}
> -
> /**
> * pci_mmap_resource - map a PCI resource into user memory space
> * @kobj: kobject for mapping
> @@ -1660,7 +1637,7 @@ static const struct attribute_group pcie_dev_attr_group = {
> .is_visible = pcie_dev_attrs_are_visible,
> };
>
> -static const struct attribute_group *pci_dev_attr_groups[] = {
> +const struct attribute_group *pci_dev_attr_groups[] = {
> &pci_dev_attr_group,
> &pci_dev_hp_attr_group,
> #ifdef CONFIG_PCI_IOV
> @@ -1677,7 +1654,3 @@ static const struct attribute_group *pci_dev_attr_groups[] = {
> #endif
> NULL,
> };
> -
> -const struct device_type pci_dev_type = {
> - .groups = pci_dev_attr_groups,
> -};
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index 5ecbcf041179..aedaf4e51146 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -31,8 +31,6 @@ bool pcie_cap_has_rtctl(const struct pci_dev *dev);
>
> /* Functions internal to the PCI core code */
>
> -int pci_create_sysfs_dev_files(struct pci_dev *pdev);
> -void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
> void pci_cleanup_rom(struct pci_dev *dev);
> #ifdef CONFIG_DMI
> extern const struct attribute_group pci_dev_smbios_attr_group;
> @@ -152,7 +150,7 @@ static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
> /* Functions for PCI Hotplug drivers to use */
> int pci_hp_add_bridge(struct pci_dev *dev);
>
> -#ifdef HAVE_PCI_LEGACY
> +#if defined(CONFIG_SYSFS) && defined(HAVE_PCI_LEGACY)
> void pci_create_legacy_files(struct pci_bus *bus);
> void pci_remove_legacy_files(struct pci_bus *bus);
> #else
> @@ -185,10 +183,22 @@ static inline int pci_no_d1d2(struct pci_dev *dev)
> return (dev->no_d1d2 || parent_dstates);
>
> }
> +
> +#ifdef CONFIG_SYSFS
> +int pci_create_sysfs_dev_files(struct pci_dev *pdev);
> +void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
> extern const struct attribute_group *pci_dev_groups[];
> +extern const struct attribute_group *pci_dev_attr_groups[];
> extern const struct attribute_group *pcibus_groups[];
> -extern const struct device_type pci_dev_type;
> extern const struct attribute_group *pci_bus_groups[];
> +#else
> +static inline int pci_create_sysfs_dev_files(struct pci_dev *pdev) { return 0; }
> +static inline void pci_remove_sysfs_dev_files(struct pci_dev *pdev) { }
> +#define pci_dev_groups NULL
> +#define pci_dev_attr_groups NULL
> +#define pcibus_groups NULL
> +#define pci_bus_groups NULL
> +#endif
>
> extern unsigned long pci_hotplug_io_size;
> extern unsigned long pci_hotplug_mmio_size;
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index ed6b7f48736a..500ac154fdfb 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -2307,6 +2307,10 @@ static void pci_release_dev(struct device *dev)
> kfree(pci_dev);
> }
>
> +static const struct device_type pci_dev_type = {
> + .groups = pci_dev_attr_groups,
> +};
> +
> struct pci_dev *pci_alloc_dev(struct pci_bus *bus)
> {
> struct pci_dev *dev;
> --
> 2.40.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-08 21:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-30 12:32 [PATCH 1/2] PCI: Compile pci-sysfs.c only if CONFIG_SYSFS=y Lukas Wunner
2023-10-30 12:33 ` [PATCH 2/2] PCI: Remove obsolete pci_cleanup_rom() declaration Lukas Wunner
2023-11-02 3:36 ` Alistair Francis
2023-11-02 3:37 ` [PATCH 1/2] PCI: Compile pci-sysfs.c only if CONFIG_SYSFS=y Alistair Francis
2024-02-08 21:44 ` Bjorn Helgaas
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).