Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936761AbcCQUeZ (ORCPT ); Thu, 17 Mar 2016 16:34:25 -0400 Received: from mail-gw3-out.broadcom.com ([216.31.210.64]:44234 "EHLO mail-gw3-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751547AbcCQUeU (ORCPT ); Thu, 17 Mar 2016 16:34:20 -0400 X-IronPort-AV: E=Sophos;i="5.24,351,1455004800"; d="scan'208";a="90327993" From: Jayachandran C To: Bjorn Helgaas , Tomasz Nowicki , rafael@kernel.org Cc: Jayachandran C , Arnd Bergmann , Will Deacon , Catalin Marinas , Hanjun Guo , Lorenzo Pieralisi , okaya@codeaurora.org, jiang.liu@linux.intel.com, Stefano Stabellini , robert.richter@caviumnetworks.com, Marcin Wojtas , Liviu.Dudau@arm.com, David Daney , wangyijing@huawei.com, Suravee.Suthikulpanit@amd.com, msalter@redhat.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linaro-acpi@lists.linaro.org, Jon Masters Subject: [RFC PATCH 4/4] ACPI: PCI: Add raw_pci_read/write operations Date: Fri, 18 Mar 2016 01:48:33 +0530 Message-Id: <1458245913-17211-5-git-send-email-jchandra@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1458245913-17211-1-git-send-email-jchandra@broadcom.com> References: <1458245913-17211-1-git-send-email-jchandra@broadcom.com> In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2888 Lines: 114 Provide implementations of raw_pci_read and raw_pci_write needed by ACPI. We already maintain a gen_acpi_pci_roots list with all the ACPI PCI controllers, so we walk thru this list to see if there is an existing mapping. If there is one, we can use the generic config space access. If there is no existing mapping, create a temporary mapping with information available in the saved MCFG table and use it to do raw config space access. Signed-off-by: Jayachandran C --- drivers/acpi/pci_gen_host.c | 87 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/drivers/acpi/pci_gen_host.c b/drivers/acpi/pci_gen_host.c index a43f2cee..b5472f0 100644 --- a/drivers/acpi/pci_gen_host.c +++ b/drivers/acpi/pci_gen_host.c @@ -245,3 +245,90 @@ void __init pci_mmcfg_late_init(void) mcfgsav.cfg, mcfgsav.size); } } + +/* + * First walk thru the root infos of all the known ACPI PCI + * controllers to see if there is an existing mapping and + * use it if we find one. + * Otherwise check the MCFG table and setup a temporary mapping + */ +static int raw_pci_op(int domain, unsigned int busn, unsigned int devfn, + int reg, int len, u32 *val, bool write) +{ + void __iomem *m; + struct acpi_pci_generic_root_info *ri; + struct acpi_pci_root *root; + bool tmpmap = false; + int i, ret = PCIBIOS_DEVICE_NOT_FOUND; + + mutex_lock(&gen_acpi_pci_lock); + list_for_each_entry(ri, &gen_acpi_pci_roots, node) { + root = ri->common.root; + if (domain == root->segment && + busn >= (u8)root->secondary.start && + busn <= (u8)root->secondary.end) { + m = pci_generic_map_bus(ri->cfg, busn, devfn, reg); + if (m) + goto found; + else + goto err_out; + } + } + + /* not found in existing root buses, check in mcfg */ + i = mcfg_lookup(domain, busn, busn); + if (i < 0) + goto err_out; + + /* get a temporary mapping */ + busn -= mcfgsav.cfg[i].bus_start; + m = ioremap(mcfgsav.cfg[i].addr + (busn << 20 | devfn << 12), 1 << 12); + if (!m) + goto err_out; + tmpmap = true; + m += reg; +found: + if (write) { + switch (len) { + case 1: + writeb(*val, m); + break; + case 2: + writew(*val, m); + break; + case 4: + writel(*val, m); + break; + } + } else { + switch (len) { + case 1: + *val = readb(m); + break; + case 2: + *val = readw(m); + break; + case 4: + *val = readl(m); + break; + } + } + if (tmpmap) + iounmap(m); + ret = 0; +err_out: + mutex_unlock(&gen_acpi_pci_lock); + return ret; +} + +int raw_pci_read(unsigned int domain, unsigned int busn, unsigned int devfn, + int reg, int len, u32 *val) +{ + return raw_pci_op(domain, busn, devfn, reg, len, val, false); +} + +int raw_pci_write(unsigned int domain, unsigned int busn, unsigned int devfn, + int reg, int len, u32 val) +{ + return raw_pci_op(domain, busn, devfn, reg, len, &val, true); +} -- 1.9.1