pci: Add generic pcibios_{fixup_bus,align_resource}
While upstreaming the RISC-V port, it was pointed out that multiple architectures have copied the mostly empty versions of at least one of these functions. This defines weakly bound versions of the common functions and removes the now obselete functions from other ports.
This has been split out from the RISC-V submission so we can decouple all these generic changes from our port review process. There's some discussion on an earlier version of the patch here
https://lkml.org/lkml/2017/6/6/998
but I'm afraid a lot of this is really out of my wheelhouse (and I'm pretty slammed trying to get the RISC-V port in better shape), so I'm afraid I'm not going to be able to perform the full cleanup suggested.
PATCH 1/3 pci: Add a generic, weakly-linked pcibios_fixup_bus
Multiple architectures define this as an empty function, and I'm adding another one as part of the RISC-V port. This adds a __weak version of pci_fixup_bios and deletes the now obselete ones in a handful of ports.
The only functional change should be that microblaze used to export pcibios_fixup_bus. None of the other architectures export this, so I just dropped it.
--- arch/arc/kernel/pcibios.c | 4 ---- arch/arm64/kernel/pci.c | 8 -------- arch/cris/arch-v32/drivers/pci/bios.c | 4 ---- arch/microblaze/pci/pci-common.c | 6 ------ arch/s390/pci/pci.c | 4 ---- arch/sh/drivers/pci/pci.c | 8 -------- arch/sparc/kernel/pci.c | 4 ---- arch/tile/kernel/pci.c | 8 -------- arch/tile/kernel/pci_gx.c | 5 ----- drivers/pci/probe.c | 10 ++++++++++ 10 files changed, 10 insertions(+), 51 deletions(-)
arch/arc/kernel/pcibios.c +0 -4
@@ -16,7 +16,3 @@ resource_size_t pcibios_align_resource(void *data, const struct resource *res, {return res->start; } - -void pcibios_fixup_bus (struct pci_bus *bus) -{ -}
arch/arm64/kernel/pci.c +0 -8
@@ -23,14 +23,6 @@#include <linux/slab.h> /* -* Called after each bus is probed, but before its children are examined -*/ -void pcibios_fixup_bus (struct pci_bus *bus) -{ -/* nothing to do, expected to be removed in the future */ -} - -/* * We don't have to worry about legacy ISA devices, so nothing to do here */ resource_size_t pcibios_align_resource(void *data, const struct resource *res,
arch/cris/arch-v32/drivers/pci/bios.c +0 -4
@@ -2,10 +2,6 @@#include <linux/kernel.h> #include <hwregs/intr_vect.h> -void pcibios_fixup_bus (struct pci_bus *b) -{ -} -void pcibios_set_master (struct pci_dev *dev) {u8 lat;
arch/microblaze/pci/pci-common.c +0 -6
@@ -810,12 +810,6 @@ void pcibios_setup_bus_devices(struct pci_bus *bus) } } -void pcibios_fixup_bus (struct pci_bus *bus) -{ -/* nothing to do */ -} -EXPORT_SYMBOL (pcibios_fixup_bus); -/* * We need to avoid collisions with `mirrored' VGA ports * and other strange ISA hardware, so we always want the
arch/s390/pci/pci.c +0 -4
@@ -234,10 +234,6 @@ static int zpci_cfg_store(struct zpci_dev *zdev, int offset, u32 val, u8 len)return rc; } -void pcibios_fixup_bus (struct pci_bus *bus) -{ -} -resource_size_t pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align)
arch/sh/drivers/pci/pci.c +0 -8
@@ -155,14 +155,6 @@ static int __init pcibios_init(void)subsys_initcall (pcibios_init);/* -* Called after each bus is probed, but before its children -* are examined. -*/ -void pcibios_fixup_bus (struct pci_bus *bus) -{ -} - -/* * We need to avoid collisions with `mirrored' VGA ports * and other strange ISA hardware, so we always want the * addresses to be allocated in the 0x000-0x0ff region
arch/sparc/kernel/pci.c +0 -4
@@ -690,10 +690,6 @@ struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm,return bus; } -void pcibios_fixup_bus (struct pci_bus *pbus) -{ -} -resource_size_t pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {
arch/tile/kernel/pci.c +0 -8
@@ -369,14 +369,6 @@ int __init pcibios_init(void) }subsys_initcall (pcibios_init); -/* -* No bus fixups needed. -*/ -void pcibios_fixup_bus (struct pci_bus *bus) -{ -/* Nothing needs to be done. */ -} -void pcibios_set_master (struct pci_dev *dev) {/* No special bus mastering setup handling. */
arch/tile/kernel/pci_gx.c +0 -5
@@ -1038,11 +1038,6 @@ int __init pcibios_init(void) }subsys_initcall (pcibios_init); -/* No bus fixups needed. */ -void pcibios_fixup_bus (struct pci_bus *bus) -{ -} -/* Process any "pci=" kernel boot arguments. */ char *__init pcibios_setup (char *str) {
drivers/pci/probe.c +10 -0
@@ -2227,6 +2227,16 @@ void pcie_bus_configure_settings(struct pci_bus *bus) }EXPORT_SYMBOL_GPL (pcie_bus_configure_settings); +/* +* Called after each bus is probed, but before its children are examined. This +* is marked as __weak because multiple architectures define it +*/ +__attribute__ ((weak)) +void pcibios_fixup_bus (struct pci_bus *bus) +{ +/* nothing to do, expected to be removed in the future */ +} +unsigned int pci_scan_child_bus (struct pci_bus *bus) {unsigned int devfn, pass, max = bus->busn_res.start;
Signature · 1 line
2.13.0
Re: [PATCH 1/3] pci: Add a generic, weakly-linked pcibios_fixup_bus
Hi Palmer,
Quoted 9 lines · Palmer Dabbelt
Multiple architectures define this as an empty function, and I'm adding another one as part of the RISC-V port. This adds a
__weakversion ofpci_fixup_biosand deletes the now obselete ones in a handful of ports.The only functional change should be that microblaze used to export
pcibios_fixup_bus. None of the other architectures export this, so I just dropped it.Signed-off-by Palmer Dabbelt <[email protected]>
Given this is an empty function, wouldn't it make more sense to have a static inline in asm-generic, protected by #ifndef pcibios_fixup_bus?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH 1/3] pci: Add a generic, weakly-linked pcibios_fixup_bus
Quoted 7 lines · On Sat, 24 Jun 2017 02:34:06 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 4 lines · Palmer Dabbelt
Multiple architectures define this as an empty function, and I'm adding another one as part of the RISC-V port. This adds a
__weakversion ofpci_fixup_biosand deletes the now obselete ones in a handful of ports.
Quoted 8 lines
Quoted 5 lines
The only functional change should be that microblaze used to export
pcibios_fixup_bus. None of the other architectures export this, so I just dropped it.Signed-off-by Palmer Dabbelt <[email protected]>Given this is an empty function, wouldn't it make more sense to have a static inline in asm-generic, protected by #ifndef
pcibios_fixup_bus?
I think the PCI people were considering changing this from a per-arch function to a per-controller function, so I think the inline won't help any there. I think since they hope to eventually clean up all the __weak functions it fits a bit better this way, but I'm really fine with anything here.
PATCH 2/3 pci: Add a generic, weakly-linked pcibios_align_resource
In reply to Palmer DabbeltMultiple architectures define this as trivial function, and I'm adding another one as part of the RISC-V port. This adds a __weak version of pcibios_align_resource and deletes the now obselete ones in a handful of ports.
The only functional change should be that a handful of ports used to export pcibios_fixup_bus. Only some architectures export this, so I just dropped it.
--- arch/arc/kernel/pcibios.c | 9 --------- arch/arm64/kernel/pci.c | 9 --------- arch/ia64/pci/pci.c | 7 ------- arch/microblaze/pci/pci-common.c | 7 ------- arch/sparc/kernel/leon_pci.c | 6 ------ arch/sparc/kernel/pci.c | 6 ------ arch/sparc/kernel/pcic.c | 6 ------ arch/tile/kernel/pci.c | 10 ---------- arch/tile/kernel/pci_gx.c | 9 --------- drivers/pci/setup-res.c | 12 ++++++++++++ 10 files changed, 12 insertions(+), 69 deletions(-)
arch/arc/kernel/pcibios.c +0 -9
@@ -7,12 +7,3 @@*/ #include <linux/pci.h> - -/* -* We don't have to worry about legacy ISA devices, so nothing to do here -*/ -resource_size_t pcibios_align_resource (void *data,const struct resource *res, -resource_size_t size,resource_size_t align) -{ -return res->start; -}
arch/arm64/kernel/pci.c +0 -9
@@ -23,15 +23,6 @@#include <linux/slab.h> /* -* We don't have to worry about legacy ISA devices, so nothing to do here -*/ -resource_size_t pcibios_align_resource (void *data,const struct resource *res, -resource_size_t size,resource_size_t align) -{ -return res->start; -} - -/* * Try to assign the IRQ number when probing a new device */ int pcibios_alloc_irq (struct pci_dev *dev)
arch/ia64/pci/pci.c +0 -7
@@ -411,13 +411,6 @@ pcibios_disable_device (struct pci_dev *dev)acpi_pci_irq_disable (dev); } -resource_size_t -pcibios_align_resource (void *data,const struct resource *res, -resource_size_t size,resource_size_t align) -{ -return res->start; -} -/** * ia64_pci_get_legacy_mem - generic legacy mem routine * @bus: bus to get legacy memory base address for
arch/microblaze/pci/pci-common.c +0 -7
@@ -823,13 +823,6 @@ void pcibios_setup_bus_devices(struct pci_bus *bus)* but we want to try to avoid allocating at 0x2900-0x2bff * which might have be mirrored at 0x0100-0x03ff.. */ -resource_size_t pcibios_align_resource (void *data,const struct resource *res, -resource_size_t size,resource_size_t align) -{ -return res->start; -} -EXPORT_SYMBOL (pcibios_align_resource); -int pcibios_add_device (struct pci_dev *dev) { dev->irq =of_irq_parse_and_map_pci (dev,0 ,0 );
arch/sparc/kernel/leon_pci.c +0 -6
@@ -94,9 +94,3 @@ void pcibios_fixup_bus(struct pci_bus *pbus) } } } - -resource_size_t pcibios_align_resource (void *data,const struct resource *res, -resource_size_t size,resource_size_t align) -{ -return res->start; -}
arch/sparc/kernel/pci.c +0 -6
@@ -690,12 +690,6 @@ struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm,return bus; } -resource_size_t pcibios_align_resource (void *data,const struct resource *res, -resource_size_t size,resource_size_t align) -{ -return res->start; -} -int pcibios_enable_device (struct pci_dev *dev,int mask) {u16 cmd, oldcmd;
arch/sparc/kernel/pcic.c +0 -6
@@ -746,12 +746,6 @@ static void watchdog_reset() { }#endif -resource_size_t pcibios_align_resource (void *data,const struct resource *res, -resource_size_t size,resource_size_t align) -{ -return res->start; -} -int pcibios_enable_device (struct pci_dev *pdev,int mask) {return 0 ;
arch/tile/kernel/pci.c +0 -10
@@ -67,16 +67,6 @@ static struct pci_ops tile_cfg_ops;/* -* We don't need to worry about the alignment of resources. -*/ -resource_size_t pcibios_align_resource (void *data,const struct resource *res, -resource_size_t size,resource_size_t align) -{ -return res->start; -} -EXPORT_SYMBOL (pcibios_align_resource); - -/* * Open a FD to the hypervisor PCI device. * * controller_id is the controller number, config type is 0 or 1 for
arch/tile/kernel/pci_gx.c +0 -9
@@ -108,15 +108,6 @@ static struct pci_ops tile_cfg_ops;/* Mask of CPUs that should receive PCIe interrupts. */ static struct cpumask intr_cpus_map; -/* We don't need to worry about the alignment of resources. */ -resource_size_t pcibios_align_resource (void *data,const struct resource *res, -resource_size_t size, -resource_size_t align) -{ -return res->start; -} -EXPORT_SYMBOL (pcibios_align_resource); -/* * Pick a CPU to receive and handle the PCIe interrupts, based on the IRQ #. * For now, we simply send interrupts to non-dataplane CPUs.
drivers/pci/setup-res.c +12 -0
@@ -234,6 +234,18 @@ static int pci_revert_fw_address(struct resource *res, struct pci_dev *dev,return 0 ; } +/* +* We don't have to worry about legacy ISA devices, so nothing to do here. +* This is marked as __weak because multiple architectures define it, it should +* eventually go away. +*/ +__attribute__ ((weak)) +resource_size_t pcibios_align_resource (void *data,const struct resource *res, +resource_size_t size,resource_size_t align) +{ +return res->start; +} +static int __pci_assign_resource (struct pci_bus *bus,struct pci_dev *dev,int resno,resource_size_t size,resource_size_t align) {
Signature · 1 line
2.13.0
Re: [PATCH 2/3] pci: Add a generic, weakly-linked pcibios_align_resource
Hi Palmer,
Quoted 10 lines · Palmer Dabbelt
Multiple architectures define this as trivial function, and I'm adding another one as part of the RISC-V port. This adds a
__weakversion ofpcibios_align_resourceand deletes the now obselete ones in a handful of ports.The only functional change should be that a handful of ports used to export
pcibios_fixup_bus. Only some architectures export this, so I just dropped it.Signed-off-by Palmer Dabbelt <[email protected]>
This function is only ever used as a pointer passed to pci_bus_alloc_resource()?
What about having
#ifndef pcibios_fixup_bus
#define pcibios_fixup_bus NULL
#endifin asm-generic/pci.h, letting the architecture with a non-trivial implementation predefine the preprocessor symbol, and teaching pci_bus_alloc_resource() to handle NULL?
[...]
Oh, the latter eventually calls into allocate_resource(), which already falls back to simple_align_resource() if the alignment function is NULL, which does the same thing.
So NULL should already work.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH 2/3] pci: Add a generic, weakly-linked pcibios_align_resource
Quoted 27 lines · On Sat, 24 Jun 2017 02:41:42 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 10 lines · Palmer Dabbelt
Multiple architectures define this as trivial function, and I'm adding another one as part of the RISC-V port. This adds a
__weakversion ofpcibios_align_resourceand deletes the now obselete ones in a handful of ports.The only functional change should be that a handful of ports used to export
pcibios_fixup_bus. Only some architectures export this, so I just dropped it.Signed-off-by Palmer Dabbelt <[email protected]>This function is only ever used as a pointer passed to
pci_bus_alloc_resource()?What about having
#ifndef pcibios_fixup_bus #define pcibios_fixup_bus NULL #endifin
asm-generic/pci.h, letting the architecture with a non-trivial implementation predefine the preprocessor symbol, and teachingpci_bus_alloc_resource()to handle NULL?
Quoted 6 lines
[...]
Oh, the latter eventually calls into
allocate_resource(), which already falls back tosimple_align_resource()if the alignment function is NULL, which does the same thing.
So NULL should already work.
I'm OK with that, but like your comments on the last one I think it might fit better as a __weak function. I think there were also some questions as to whether these should actually be empty functions or not. I'm really happy with either way.
Since this is all out of my wheelhouse, can one of the PCI maintainers chime in as to what I should do here?
PATCH 3/3 arc: kernel/pcibios.c is empty, delete it
In reply to Palmer Dabbelt--- arch/arc/kernel/Makefile | 1 - arch/arc/kernel/pcibios.c | 9 --------- 2 files changed, 10 deletions(-) delete mode 100644 arch/arc/kernel/pcibios.c
arch/arc/kernel/Makefile +0 -1
@@ -12,7 +12,6 @@ obj-y := arcksyms.o setup.o irq.o reset.o ptrace.o process.o devtree.o obj-y += signal.o traps.o sys.o troubleshoot.o stacktrace.o disasm.o obj-$(CONFIG_ISA_ARCOMPACT) += entry-compact.o intc-compact.o obj-$(CONFIG_ISA_ARCV2) += entry-arcv2.o intc-arcv2.o -obj-$(CONFIG_PCI) += pcibios.o obj-$(CONFIG_MODULES) += arcksyms.o module.o obj-$(CONFIG_SMP) += smp.o
arch/arc/kernel/pcibios.c deleted +0 -9
@@ -1,9 +0,0 @@ -/* -* Copyright (C) 2014-2015 Synopsys, Inc. (www.synopsys.com) -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -*/ - -#include <linux/pci.h>
Signature · 1 line
2.13.0
Bjorn Helgaas
AppliedQuoted 9 lines · Palmer Dabbelt
While upstreaming the RISC-V port, it was pointed out that multiple architectures have copied the mostly empty versions of at least one of these functions. This defines weakly bound versions of the common functions and removes the now obselete functions from other ports.
This has been split out from the RISC-V submission so we can decouple all these generic changes from our port review process. There's some discussion on an earlier version of the patch here
Quoted 5 lines
https://lkml.org/lkml/2017/6/6/998
but I'm afraid a lot of this is really out of my wheelhouse (and I'm pretty slammed trying to get the RISC-V port in better shape), so I'm afraid I'm not going to be able to perform the full cleanup suggested.
Applied to pci/resource for v4.14, thanks!
There's room for future improvement, e.g., using per-host callbacks, etc., but I think this is a clear improvement as-is.
There's some folklore about the evils of weak symbols, but I don't know the details. It would be useful to have them codified somewhere in Documentation/ or near the __weak definition.