Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp358521imu; Thu, 8 Nov 2018 09:15:24 -0800 (PST) X-Google-Smtp-Source: AJdET5fDerYoLxXBmpCTENBMYGi+Py9wNV025fhwNt5TxSdYfRUsq5rqW2NLvfOcVWc+cT+wdvMM X-Received: by 2002:a17:902:163:: with SMTP id 90-v6mr5393278plb.87.1541697324025; Thu, 08 Nov 2018 09:15:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541697323; cv=none; d=google.com; s=arc-20160816; b=S+47+gUWNncAjGD2e+FbEaQ+8NZT5R+z6gJyTkj73LnqmSyn1TCD6RN0/z2KDclyZ6 oedMeIKPH3COIfv1HpK7rwPT+R4VxX5Nyac6scYjtJLrCM300cXTUpubZmEYw4vJ1Hl9 0Vfu4T9taB69YfwjHIDme0okxtrOCvbPUcrhS94zXJe0LM/CnjMSE5aq0PG3S1hNN8Me qgIfMKmmZ43MFQXjtBUVpqKE531/FSR3sp09qxDlZXKfd/2yZVtT/rrdskh5mw+zz0HM 0jl7/FMgAXRCx7cMc7n6KBQz2nCCECTx0Bu7++NfAcY0pMBiS41HU3w2Zh1f0Np7m9vC YOQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/7QJD6QyN4a7tCGv0UAwEV35V+U7OQLpTdnOlwe/UIk=; b=mBYZar2mniXeslShMBKmXu4tbH1s2e4xL7+v2RtP8jlGyawdHBpuzP5PlgIVgD2dO3 rWDqB083bdcg0os7aCGxhHLdjh0r5QkrYDEbeciuDOLhls00wNUPLTewdyj/qC1BxMec uIXQc5+nVOmdVP2qo9LTeJuR7KrL25WnbWdyhWzw8cYRBmjL1iY1ARMAPVy5lTo1h9E5 lCdpJ86yOUPgmiYT8iXn1FbxckQXw4RzYdUcUFFQMUHKAEkbpbTTrDT9+Nk46GLWi7+X NaDQLdLsQDvwFVTG3GTS7cuZaxoVVeVwy/7yiCDGFr3b2t3MZIQVY+v+phtOu7CSlVh4 H5yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MF+Ux7k2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r3-v6si4844596plo.97.2018.11.08.09.15.04; Thu, 08 Nov 2018 09:15:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MF+Ux7k2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727029AbeKICrv (ORCPT + 99 others); Thu, 8 Nov 2018 21:47:51 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:42085 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726585AbeKICru (ORCPT ); Thu, 8 Nov 2018 21:47:50 -0500 Received: by mail-pf1-f194.google.com with SMTP id u10-v6so3829522pfn.9 for ; Thu, 08 Nov 2018 09:11:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/7QJD6QyN4a7tCGv0UAwEV35V+U7OQLpTdnOlwe/UIk=; b=MF+Ux7k2StOreuROdRCMWZIJI9kOkmgExm0GoIPapVQY/fph+Kh8mjLOGEGKFBvYzu qC7+HVHvZR8Ai990c/tL22zlIHNPRxh2R0uPBaOMv0fIQlbpuh8IZ1os9od/6MtAriiq rEM0b+/4pLKXIPSJv5wPjmz/U39XEIoRAV99U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/7QJD6QyN4a7tCGv0UAwEV35V+U7OQLpTdnOlwe/UIk=; b=scssYjfH+OUzQ6TKjxU6b1GX0hOXIZhgBzt1sXgvfXSmu69cvM66moEHuPotVoxFfH Q3Lkwe/eQxD9CckeJqF+rbHctiEIaOVNOHjNtOxwjKkzFItvUtkghc8ANgEmdhIS60AM BUh8h1LNoD4n35p8hxk6YDn+3WOpq+7DSUlqf2ZtrFbeqAcQ92qX42l3zHg0+BOSu+8q s3eVjYM46rFWCh5mQ0qSzAzqaTkZrRqPeSwLJitSMA6oTACwZqP3Dk35fHrsWh1bKPI2 r2TqUJAy22yALzuCRt9J1Nd7qRsOglp627fv8CDaAJnaIx1Dh3QqyaKqZKAbbRwupSgc j9lg== X-Gm-Message-State: AGRZ1gIBuwxktbWU6bJs/ONiEqR0HIYtgOk0xuWiHV84RVK1cZRVntsG ptF2AfB33tQ5yMA7BwfXjSCUzg== X-Received: by 2002:a65:664e:: with SMTP id z14-v6mr4250026pgv.347.1541697083998; Thu, 08 Nov 2018 09:11:23 -0800 (PST) Received: from zsm-linux.mtv.corp.google.com ([2620:15c:202:201:1b7c:8280:c835:b226]) by smtp.googlemail.com with ESMTPSA id s86-v6sm9586941pfa.137.2018.11.08.09.11.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 09:11:23 -0800 (PST) From: Zubin Mithra To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, hch@infradead.org, bhelgaas@google.com Cc: groeck@chromium.org, keescook@chromium.org, zsm@chromium.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [RFC] x86/pci: Mark pci_root_ops as const Date: Thu, 8 Nov 2018 09:11:15 -0800 Message-Id: <20181108171115.216060-1-zsm@chromium.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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(-) 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); -- 2.19.1.930.g4563a0d9d0-goog