diff mbox series

[RFC] x86/pci: Mark pci_root_ops as const

Message ID 20181108171115.216060-1-zsm@chromium.org
State Changes Requested
Delegated to: Bjorn Helgaas
Headers show
Series [RFC] x86/pci: Mark pci_root_ops as const | expand

Commit Message

Zubin Mithra Nov. 8, 2018, 5:11 p.m. UTC
pci_root_ops is only written to from within intel_mid_pci_init. This
is linked in only when CONFIG_X86_INTEL_MID is set. If not for this,
pci_root_ops could be marked as const.

Fix this by replacing pci_root_ops usage with pci_root_ops_ptr. If
CONFIG_X86_INTEL_MID is set, pci_root_ops_ptr will be set to
intel_mid_pci_ops inside intel_mid_pci_init.

Introduce pci_acpi_set_ops for intel_mid_pci_init to set
acpi_pci_root_ops.pci_ops.

This also means that intel_mid_pci_ops cannot be freed after init, hence
remove __initconst.

Signed-off-by: Zubin Mithra <zsm@chromium.org>
---
 arch/x86/include/asm/pci_x86.h |  4 +++-
 arch/x86/pci/acpi.c            |  5 +++++
 arch/x86/pci/common.c          |  5 +++--
 arch/x86/pci/intel_mid_pci.c   |  5 +++--
 drivers/pci/access.c           |  4 ++--
 drivers/pci/probe.c            |  4 ++--
 include/linux/pci-acpi.h       |  2 +-
 include/linux/pci.h            | 11 ++++++-----
 8 files changed, 25 insertions(+), 15 deletions(-)

Comments

Bjorn Helgaas Nov. 8, 2018, 11:51 p.m. UTC | #1
Hi Zubin,

On Thu, Nov 08, 2018 at 09:11:15AM -0800, Zubin Mithra wrote:
> pci_root_ops is only written to from within intel_mid_pci_init. This
> is linked in only when CONFIG_X86_INTEL_MID is set. If not for this,
> pci_root_ops could be marked as const.
> 
> Fix this by replacing pci_root_ops usage with pci_root_ops_ptr. If
> CONFIG_X86_INTEL_MID is set, pci_root_ops_ptr will be set to
> intel_mid_pci_ops inside intel_mid_pci_init.
> 
> Introduce pci_acpi_set_ops for intel_mid_pci_init to set
> acpi_pci_root_ops.pci_ops.
> 
> This also means that intel_mid_pci_ops cannot be freed after init, hence
> remove __initconst.
> 
> Signed-off-by: Zubin Mithra <zsm@chromium.org>
> ---
>  arch/x86/include/asm/pci_x86.h |  4 +++-
>  arch/x86/pci/acpi.c            |  5 +++++
>  arch/x86/pci/common.c          |  5 +++--
>  arch/x86/pci/intel_mid_pci.c   |  5 +++--
>  drivers/pci/access.c           |  4 ++--
>  drivers/pci/probe.c            |  4 ++--
>  include/linux/pci-acpi.h       |  2 +-
>  include/linux/pci.h            | 11 ++++++-----
>  8 files changed, 25 insertions(+), 15 deletions(-)

Can you:

  - Split this into an x86 patch and a PCI core patch (if possible)?
  - Make the same fixes for other arches?

Bjorn
diff mbox series

Patch

diff --git a/arch/x86/include/asm/pci_x86.h b/arch/x86/include/asm/pci_x86.h
index 959d618dbb17..1e82ddaeb52f 100644
--- a/arch/x86/include/asm/pci_x86.h
+++ b/arch/x86/include/asm/pci_x86.h
@@ -58,7 +58,8 @@  void pcibios_set_cache_line_size(void);
 /* pci-pc.c */
 
 extern int pcibios_last_bus;
-extern struct pci_ops pci_root_ops;
+extern const struct pci_ops pci_root_ops;
+extern const struct pci_ops *pci_root_ops_ptr;
 
 void pcibios_scan_specific_bus(int busn);
 
@@ -122,6 +123,7 @@  extern void __init dmi_check_skip_isa_align(void);
 
 /* some common used subsys_initcalls */
 extern int __init pci_acpi_init(void);
+extern void __init pci_acpi_set_ops(const struct pci_ops *ops);
 extern void __init pcibios_irq_init(void);
 extern int __init pcibios_init(void);
 extern int pci_legacy_init(void);
diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index 948656069cdd..63ebac5fa212 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -397,6 +397,11 @@  int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
 	return 0;
 }
 
+void __init pci_acpi_set_ops(const struct pci_ops *ops)
+{
+	acpi_pci_root_ops.pci_ops = ops;
+}
+
 int __init pci_acpi_init(void)
 {
 	struct pci_dev *dev = NULL;
diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
index d4ec117c1142..747a8e9fd430 100644
--- a/arch/x86/pci/common.c
+++ b/arch/x86/pci/common.c
@@ -67,10 +67,11 @@  static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int siz
 				  devfn, where, size, value);
 }
 
-struct pci_ops pci_root_ops = {
+const struct pci_ops pci_root_ops = {
 	.read = pci_read,
 	.write = pci_write,
 };
+const struct pci_ops *pci_root_ops_ptr = &pci_root_ops;
 
 /*
  * This interrupt-safe spinlock protects all accesses to PCI configuration
@@ -467,7 +468,7 @@  void pcibios_scan_root(int busnum)
 	sd->node = x86_pci_root_bus_node(busnum);
 	x86_pci_root_bus_resources(busnum, &resources);
 	printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
-	bus = pci_scan_root_bus(NULL, busnum, &pci_root_ops, sd, &resources);
+	bus = pci_scan_root_bus(NULL, busnum, pci_root_ops_ptr, sd, &resources);
 	if (!bus) {
 		pci_free_resource_list(&resources);
 		kfree(sd);
diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
index 43867bc85368..b79c469afd57 100644
--- a/arch/x86/pci/intel_mid_pci.c
+++ b/arch/x86/pci/intel_mid_pci.c
@@ -280,7 +280,7 @@  static void intel_mid_pci_irq_disable(struct pci_dev *dev)
 	}
 }
 
-static const struct pci_ops intel_mid_pci_ops __initconst = {
+static const struct pci_ops intel_mid_pci_ops = {
 	.read = pci_read,
 	.write = pci_write,
 };
@@ -297,7 +297,8 @@  int __init intel_mid_pci_init(void)
 	pci_mmcfg_late_init();
 	pcibios_enable_irq = intel_mid_pci_irq_enable;
 	pcibios_disable_irq = intel_mid_pci_irq_disable;
-	pci_root_ops = intel_mid_pci_ops;
+	pci_root_ops_ptr = &intel_mid_pci_ops;
+	pci_acpi_set_ops(&intel_mid_pci_ops);
 	pci_soc_mode = 1;
 	/* Continue with standard init */
 	acpi_noirq_set();
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index 544922f097c0..ca9d3cbc5541 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -180,9 +180,9 @@  EXPORT_SYMBOL_GPL(pci_generic_config_write32);
  *
  * Return previous raw operations
  */
-struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops)
+const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, const struct pci_ops *ops)
 {
-	struct pci_ops *old_ops;
+	const struct pci_ops *old_ops;
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&pci_lock, flags);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index b1c05b5054a0..c66c84ef070a 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2915,7 +2915,7 @@  void __weak pcibios_remove_bus(struct pci_bus *bus)
 }
 
 struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
-		struct pci_ops *ops, void *sysdata, struct list_head *resources)
+		const struct pci_ops *ops, void *sysdata, struct list_head *resources)
 {
 	int error;
 	struct pci_host_bridge *bridge;
@@ -3079,7 +3079,7 @@  int pci_scan_root_bus_bridge(struct pci_host_bridge *bridge)
 EXPORT_SYMBOL(pci_scan_root_bus_bridge);
 
 struct pci_bus *pci_scan_root_bus(struct device *parent, int bus,
-		struct pci_ops *ops, void *sysdata, struct list_head *resources)
+		const struct pci_ops *ops, void *sysdata, struct list_head *resources)
 {
 	struct resource_entry *window;
 	bool found = false;
diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h
index 8082b612f561..e2c80f2edbe8 100644
--- a/include/linux/pci-acpi.h
+++ b/include/linux/pci-acpi.h
@@ -69,7 +69,7 @@  struct acpi_pci_root_info {
 };
 
 struct acpi_pci_root_ops {
-	struct pci_ops *pci_ops;
+	const struct pci_ops *pci_ops;
 	int (*init_info)(struct acpi_pci_root_info *info);
 	void (*release_info)(struct acpi_pci_root_info *info);
 	int (*prepare_resources)(struct acpi_pci_root_info *info);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 11c71c4ecf75..994a4418a3c4 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -474,7 +474,7 @@  static inline int pci_channel_offline(struct pci_dev *pdev)
 struct pci_host_bridge {
 	struct device	dev;
 	struct pci_bus	*bus;		/* Root bus */
-	struct pci_ops	*ops;
+	const struct pci_ops	*ops;
 	void		*sysdata;
 	int		busnr;
 	struct list_head windows;	/* resource_entry */
@@ -558,7 +558,7 @@  struct pci_bus {
 	struct list_head resources;	/* Address space routed to this bus */
 	struct resource busn_res;	/* Bus numbers routed to this bus */
 
-	struct pci_ops	*ops;		/* Configuration access functions */
+	const struct pci_ops	*ops;	/* Configuration access functions */
 	struct msi_controller *msi;	/* MSI controller */
 	void		*sysdata;	/* Hook for sys-specific extension */
 	struct proc_dir_entry *procdir;	/* Directory entry in /proc/bus/pci */
@@ -913,14 +913,14 @@  struct pci_bus *pci_find_bus(int domain, int busnr);
 void pci_bus_add_devices(const struct pci_bus *bus);
 struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata);
 struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
-				    struct pci_ops *ops, void *sysdata,
+				    const struct pci_ops *ops, void *sysdata,
 				    struct list_head *resources);
 int pci_host_probe(struct pci_host_bridge *bridge);
 int pci_bus_insert_busn_res(struct pci_bus *b, int bus, int busmax);
 int pci_bus_update_busn_res_end(struct pci_bus *b, int busmax);
 void pci_bus_release_busn_res(struct pci_bus *b);
 struct pci_bus *pci_scan_root_bus(struct device *parent, int bus,
-				  struct pci_ops *ops, void *sysdata,
+				  const struct pci_ops *ops, void *sysdata,
 				  struct list_head *resources);
 int pci_scan_root_bus_bridge(struct pci_host_bridge *bridge);
 struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev,
@@ -1010,7 +1010,8 @@  int pci_generic_config_read32(struct pci_bus *bus, unsigned int devfn,
 int pci_generic_config_write32(struct pci_bus *bus, unsigned int devfn,
 			       int where, int size, u32 val);
 
-struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops);
+const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus,
+				      const struct pci_ops *ops);
 
 int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val);
 int pci_read_config_word(const struct pci_dev *dev, int where, u16 *val);