From patchwork Mon Nov 9 10:26:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Edworthy X-Patchwork-Id: 7582331 X-Patchwork-Delegate: horms@verge.net.au Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 19BEF9F2E9 for ; Mon, 9 Nov 2015 10:26:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B77F420667 for ; Mon, 9 Nov 2015 10:26:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D685205B8 for ; Mon, 9 Nov 2015 10:26:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752777AbbKIK0p (ORCPT ); Mon, 9 Nov 2015 05:26:45 -0500 Received: from relmlor2.renesas.com ([210.160.252.172]:25897 "EHLO relmlie1.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752771AbbKIK0o convert rfc822-to-8bit (ORCPT ); Mon, 9 Nov 2015 05:26:44 -0500 Received: from unknown (HELO relmlir3.idc.renesas.com) ([10.200.68.153]) by relmlie1.idc.renesas.com with ESMTP; 09 Nov 2015 19:26:42 +0900 Received: from relmlac3.idc.renesas.com (relmlac3.idc.renesas.com [10.200.69.23]) by relmlir3.idc.renesas.com (Postfix) with ESMTP id 3800B4DA7E; Mon, 9 Nov 2015 19:26:42 +0900 (JST) Received: by relmlac3.idc.renesas.com (Postfix, from userid 0) id 2B8B01806F; Mon, 9 Nov 2015 19:26:42 +0900 (JST) Received: from relmlac3.idc.renesas.com (localhost [127.0.0.1]) by relmlac3.idc.renesas.com (Postfix) with ESMTP id 265F31800A; Mon, 9 Nov 2015 19:26:42 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac3.idc.renesas.com with ESMTP id VBQ23142; Mon, 9 Nov 2015 19:26:42 +0900 X-IronPort-AV: E=Sophos;i="5.20,265,1444662000"; d="scan'208";a="199376251" Received: from mail-hk2apc01lp0207.outbound.protection.outlook.com (HELO APC01-HK2-obe.outbound.protection.outlook.com) ([65.55.88.207]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA; 09 Nov 2015 19:26:41 +0900 Received: from PS1PR06MB1180.apcprd06.prod.outlook.com (10.169.63.140) by PS1PR06MB1179.apcprd06.prod.outlook.com (10.169.63.139) with Microsoft SMTP Server (TLS) id 15.1.318.15; Mon, 9 Nov 2015 10:26:39 +0000 Received: from PS1PR06MB1180.apcprd06.prod.outlook.com ([10.169.63.140]) by PS1PR06MB1180.apcprd06.prod.outlook.com ([10.169.63.140]) with mapi id 15.01.0318.003; Mon, 9 Nov 2015 10:26:39 +0000 From: Phil Edworthy To: Bjorn Helgaas , Simon Horman CC: Geert Uytterhoeven , "linux-pci@vger.kernel.org" , "linux-sh@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Wolfram Sang Subject: [PATCH 1/3 v2] PCI: pcie-rcar: Convert to DT resource parsing API Thread-Topic: [PATCH 1/3 v2] PCI: pcie-rcar: Convert to DT resource parsing API Thread-Index: AdEa2N3tC0DT6qn3T7GoGc+dwq8KQQ== Date: Mon, 9 Nov 2015 10:26:39 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=phil.edworthy@renesas.com; x-originating-ip: [193.141.220.21] x-microsoft-exchange-diagnostics: 1; PS1PR06MB1179; 5:mWTCgy3+hywbDbQT/OU/+f+L5hj4KN/yMcnFu0+vDQNhllcZ0Y2KB+6MHLBGIB6CT2sjZcFvKX+qRaitfch0f063LenlBSParm7iTU6zeu1K5bvju9ZQo1LGyZ8vFRhXj3Lp+1LRzavQgaZLzY47gw==; 24:ilKB6YPGuKI+HGKqSgURNAsAhu2/y37r+Ez+mfU3rdkeCYdmi3tJWBL420BpdGCBYfrgX7V4ySMILkt+/MKoVy1ARaqqE0XnzQGIZAwamrE=; 20:Pwqr3JPr6+ulVKbwVCqagI85KCKrYwkMSv4+9aJgYwv4izjYi2rW3bHwHZhahc+euyy+wtFjZDBKVmFfXoPoXV2CygdEfZz24fOfwlpZBSjB1yoV7gCvxjagM/WLTisxCzmZZ9xUEBnpXMWN7T4+bUHQGzKThkDXc7Q3/1yWQlk= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:PS1PR06MB1179; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(85106069007906); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(520078)(3002001)(10201501046); SRVR:PS1PR06MB1179; BCL:0; PCL:0; RULEID:; SRVR:PS1PR06MB1179; x-forefront-prvs: 0755F54DD9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(199003)(189002)(189998001)(122556002)(76576001)(5008740100001)(5007970100001)(5001770100001)(19580395003)(81156007)(5001920100001)(11100500001)(101416001)(2900100001)(10400500002)(54356999)(74316001)(77096005)(5004730100002)(50986999)(102836002)(33656002)(5001960100002)(86362001)(87936001)(92566002)(5003600100002)(40100003)(105586002)(229853001)(66066001)(5002640100001)(97736004)(106356001)(19580405001); DIR:OUT; SFP:1102; SCL:1; SRVR:PS1PR06MB1179; H:PS1PR06MB1180.apcprd06.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Nov 2015 10:26:39.1728 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: PS1PR06MB1179 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.2 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 The main purpose of this change is to avoid calling pci_ioremap_io() as this is not available on arm64. However, instead of doing the range passing in this driver we can utilise of_pci_get_host_bridge_resources(). This is similar to changes made to the generic PCI host driver in commit dbf9826d "PCI: generic: Convert to DT resource parsing API". Signed-off-by: Phil Edworthy Reported-by: Wolfram Sang Tested-by: Wolfram Sang Acked-by: Simon Horman --- v2: - Remove incorrect res_valid check --- drivers/pci/host/pcie-rcar.c | 116 +++++++++++++++++++++++++++---------------- 1 file changed, 73 insertions(+), 43 deletions(-) diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c index 6a3a612..c977fa6 100644 --- a/drivers/pci/host/pcie-rcar.c +++ b/drivers/pci/host/pcie-rcar.c @@ -108,8 +108,6 @@ #define RCAR_PCI_MAX_RESOURCES 4 #define MAX_NR_INBOUND_MAPS 6 -static unsigned long global_io_offset; - struct rcar_msi { DECLARE_BITMAP(used, INT_PCI_MSI_NR); struct irq_domain *domain; @@ -138,8 +136,7 @@ struct rcar_pcie { #endif struct device *dev; void __iomem *base; - struct resource res[RCAR_PCI_MAX_RESOURCES]; - struct resource busn; + struct list_head resources; int root_bus_nr; struct clk *clk; struct clk *bus_clk; @@ -323,10 +320,9 @@ static struct pci_ops rcar_pcie_ops = { .write = rcar_pcie_write_conf, }; -static void rcar_pcie_setup_window(int win, struct rcar_pcie *pcie) +static void rcar_pcie_setup_window(int win, struct rcar_pcie *pcie, + struct resource *res) { - struct resource *res = &pcie->res[win]; - /* Setup PCIe address space mappings for each resource */ resource_size_t size; resource_size_t res_start; @@ -359,31 +355,33 @@ static void rcar_pcie_setup_window(int win, struct rcar_pcie *pcie) rcar_pci_write_reg(pcie, mask, PCIEPTCTLR(win)); } -static int rcar_pcie_setup(struct list_head *resource, struct rcar_pcie *pcie) +static int rcar_pcie_setup(struct list_head *resource, struct rcar_pcie *pci) { - struct resource *res; - int i; - - pcie->root_bus_nr = pcie->busn.start; + struct resource_entry *win; + int i = 0; /* Setup PCI resources */ - for (i = 0; i < RCAR_PCI_MAX_RESOURCES; i++) { + resource_list_for_each_entry(win, &pci->resources) { + struct resource *res = win->res; - res = &pcie->res[i]; if (!res->flags) continue; - rcar_pcie_setup_window(i, pcie); - - if (res->flags & IORESOURCE_IO) { - phys_addr_t io_start = pci_pio_to_address(res->start); - pci_ioremap_io(global_io_offset, io_start); - global_io_offset += SZ_64K; + switch (resource_type(res)) { + case IORESOURCE_IO: + case IORESOURCE_MEM: + rcar_pcie_setup_window(i, pci, res); + i++; + break; + case IORESOURCE_BUS: + pci->root_bus_nr = res->start; + break; + default: + continue; } pci_add_resource(resource, res); } - pci_add_resource(resource, &pcie->busn); return 1; } @@ -923,14 +921,63 @@ static const struct of_device_id rcar_pcie_of_match[] = { }; MODULE_DEVICE_TABLE(of, rcar_pcie_of_match); +static void rcar_pcie_release_of_pci_ranges(struct rcar_pcie *pci) +{ + pci_free_resource_list(&pci->resources); +} + +static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci) +{ + int err; + struct device *dev = pci->dev; + struct device_node *np = dev->of_node; + resource_size_t iobase; + struct resource_entry *win; + + err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pci->resources, &iobase); + if (err) + return err; + + resource_list_for_each_entry(win, &pci->resources) { + struct resource *parent, *res = win->res; + + switch (resource_type(res)) { + case IORESOURCE_IO: + parent = &ioport_resource; + err = pci_remap_iospace(res, iobase); + if (err) { + dev_warn(dev, "error %d: failed to map resource %pR\n", + err, res); + continue; + } + break; + case IORESOURCE_MEM: + parent = &iomem_resource; + break; + + case IORESOURCE_BUS: + default: + continue; + } + + err = devm_request_resource(dev, parent, res); + if (err) + goto out_release_res; + } + + return 0; + +out_release_res: + rcar_pcie_release_of_pci_ranges(pci); + return err; +} + static int rcar_pcie_probe(struct platform_device *pdev) { struct rcar_pcie *pcie; unsigned int data; - struct of_pci_range range; - struct of_pci_range_parser parser; const struct of_device_id *of_id; - int err, win = 0; + int err; int (*hw_init_fn)(struct rcar_pcie *); pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL); @@ -940,16 +987,9 @@ static int rcar_pcie_probe(struct platform_device *pdev) pcie->dev = &pdev->dev; platform_set_drvdata(pdev, pcie); - /* Get the bus range */ - if (of_pci_parse_bus_range(pdev->dev.of_node, &pcie->busn)) { - dev_err(&pdev->dev, "failed to parse bus-range property\n"); - return -EINVAL; - } + INIT_LIST_HEAD(&pcie->resources); - if (of_pci_range_parser_init(&parser, pdev->dev.of_node)) { - dev_err(&pdev->dev, "missing ranges property\n"); - return -EINVAL; - } + rcar_pcie_parse_request_of_pci_ranges(pcie); err = rcar_pcie_get_resources(pdev, pcie); if (err < 0) { @@ -957,16 +997,6 @@ static int rcar_pcie_probe(struct platform_device *pdev) return err; } - for_each_of_pci_range(&parser, &range) { - err = of_pci_range_to_resource(&range, pdev->dev.of_node, - &pcie->res[win++]); - if (err < 0) - return err; - - if (win > RCAR_PCI_MAX_RESOURCES) - break; - } - err = rcar_pcie_parse_map_dma_ranges(pcie, pdev->dev.of_node); if (err) return err;