From patchwork Thu Mar 17 20:18:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jayachandran C." X-Patchwork-Id: 8614171 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F0F04C0553 for ; Thu, 17 Mar 2016 20:34:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0F0EB202F0 for ; Thu, 17 Mar 2016 20:34:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 223DC2034A for ; Thu, 17 Mar 2016 20:34:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935704AbcCQUeX (ORCPT ); Thu, 17 Mar 2016 16:34:23 -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" Received: from mail-irv-18.broadcom.com ([10.15.198.37]) by mail-gw3-out.broadcom.com with ESMTP; 17 Mar 2016 13:31:19 -0700 Received: from mail-irva-13.broadcom.com (mail-irva-13.broadcom.com [10.11.16.103]) by mail-irv-18.broadcom.com (Postfix) with ESMTP id 6055982025; Thu, 17 Mar 2016 13:24:38 -0700 (PDT) Received: from lc-blr-136.ban.broadcom.com (unknown [10.131.60.136]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id B91AE40FEA; Thu, 17 Mar 2016 13:24:08 -0700 (PDT) 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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); +}