From patchwork Tue Jun 10 18:51:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 31701 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f199.google.com (mail-vc0-f199.google.com [209.85.220.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DCE7D20675 for ; Tue, 10 Jun 2014 18:53:21 +0000 (UTC) Received: by mail-vc0-f199.google.com with SMTP id ij19sf17975332vcb.2 for ; Tue, 10 Jun 2014 11:53:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=C48FzMrksiHLmqEVbdcAfyEqr1GEGlLkcV7Cf6LHh6A=; b=W4TVkBtXLqTaOynwd3oRSMQe/4lGG8AIDLusm7ovvgU+trzxvyGkrlpDGMXotGcWqz YjTGJ8aUg9m2ONEJVPN3v1xTelui+LPz8ru4Hqoynm6ULsJIyyFDcygcLCPYEfSzfAoO 3TAckCMwYpPJYFoBHpFpQ0yLGOKaXjBBvQqC4zeBEmYrDbR9ZSk8nQlG5Wf22um9z8ln tzjYiR4g1cKkcbbjuaAcksZxPmS11IbLiFtud8xkn/NuXaZSfA2nDp0hvHg+pANkcfIG 6XUdI7WAQwi6DXGTxe9EpCgCG2Hkqhm2CutNDsxuDaHI5XABQysXGvCiFRky0cVOSz0G FC6g== X-Gm-Message-State: ALoCoQl2APHqd3FKjFw8uagIoWZyVkbwjkocjMekRLCXcSJPBzXlfXVXH+ZrC5Q8OfhH79zdCZPT X-Received: by 10.236.142.20 with SMTP id h20mr4813645yhj.12.1402426401602; Tue, 10 Jun 2014 11:53:21 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.115 with SMTP id c106ls2259977qge.55.gmail; Tue, 10 Jun 2014 11:53:21 -0700 (PDT) X-Received: by 10.221.42.135 with SMTP id ty7mr34096756vcb.14.1402426401468; Tue, 10 Jun 2014 11:53:21 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id yw19si5680966vcb.69.2014.06.10.11.53.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Jun 2014 11:53:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id id10so6569306vcb.38 for ; Tue, 10 Jun 2014 11:53:21 -0700 (PDT) X-Received: by 10.58.187.19 with SMTP id fo19mr18150051vec.45.1402426401145; Tue, 10 Jun 2014 11:53:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp247473vcb; Tue, 10 Jun 2014 11:53:20 -0700 (PDT) X-Received: by 10.66.190.167 with SMTP id gr7mr7167116pac.75.1402426400369; Tue, 10 Jun 2014 11:53:20 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id og1si35249077pbc.150.2014.06.10.11.53.19; Tue, 10 Jun 2014 11:53:19 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753006AbaFJSw5 (ORCPT + 27 others); Tue, 10 Jun 2014 14:52:57 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:59493 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752931AbaFJSwx (ORCPT ); Tue, 10 Jun 2014 14:52:53 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id s5AIpKo4021982; Tue, 10 Jun 2014 13:51:20 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s5AIpKBu029313; Tue, 10 Jun 2014 13:51:20 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Tue, 10 Jun 2014 13:51:20 -0500 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s5AIpGKn012701; Tue, 10 Jun 2014 13:51:19 -0500 From: Murali Karicheri To: , , , , CC: Murali Karicheri , Santosh Shilimkar , Russell King , Grant Likely , Rob Herring , Mohit Kumar , Jingoo Han , Bjorn Helgaas , Pratyush Anand , Richard Zhu , Kishon Vijay Abraham I , Marek Vasut , Arnd Bergmann , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Randy Dunlap Subject: [PATCH v2 2/8] PCI: designware: refactor host init code to re-use on v3.65 DW pci hw Date: Tue, 10 Jun 2014 14:51:21 -0400 Message-ID: <1402426287-31157-3-git-send-email-m-karicheri2@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1402426287-31157-1-git-send-email-m-karicheri2@ti.com> References: <1402426287-31157-1-git-send-email-m-karicheri2@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m-karicheri2@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Current DW PCI host init code has code specific to newer hw such as ATU port specific resource parsing and map. v3.65 DW PCI host has MSI controller in application space and requires different controller initialization code. So refactor the msi host controller code into a separate function. Other common functions across both hw versions are moved to dw_pcie_common_host_init() and called from the newer and v3.65 hw host initialization code. Signed-off-by: Murali Karicheri CC: Santosh Shilimkar CC: Russell King CC: Grant Likely CC: Rob Herring CC: Mohit Kumar CC: Jingoo Han CC: Bjorn Helgaas CC: Pratyush Anand CC: Richard Zhu CC: Kishon Vijay Abraham I CC: Marek Vasut CC: Arnd Bergmann CC: Pawel Moll CC: Mark Rutland CC: Ian Campbell CC: Kumar Gala CC: Randy Dunlap CC: Grant Likely --- drivers/pci/host/pcie-designware.c | 136 ++++++++++++++++++++++++++---------- 1 file changed, 101 insertions(+), 35 deletions(-) diff --git a/drivers/pci/host/pcie-designware.c b/drivers/pci/host/pcie-designware.c index e8f5d8d..e4bd19a 100644 --- a/drivers/pci/host/pcie-designware.c +++ b/drivers/pci/host/pcie-designware.c @@ -389,13 +389,19 @@ static const struct irq_domain_ops msi_domain_ops = { .map = dw_pcie_msi_map, }; -int __init dw_pcie_host_init(struct pcie_port *pp) +/* + * dw_pcie_parse_resource() - Function to parse common resources + * + * @pp: ptr to pcie port + * + * Parse the range property for MEM, IO and cfg resources, and map + * the cfg register space. + */ +int __init dw_pcie_parse_resource(struct pcie_port *pp) { struct device_node *np = pp->dev->of_node; struct of_pci_range range; struct of_pci_range_parser parser; - u32 val; - int i; if (of_pci_range_parser_init(&parser, np)) { dev_err(pp->dev, "missing ranges property\n"); @@ -431,41 +437,29 @@ int __init dw_pcie_host_init(struct pcie_port *pp) pp->config.cfg1_size = resource_size(&pp->cfg)/2; } } - - if (!pp->dbi_base) { - pp->dbi_base = devm_ioremap(pp->dev, pp->cfg.start, - resource_size(&pp->cfg)); - if (!pp->dbi_base) { - dev_err(pp->dev, "error with ioremap\n"); - return -ENOMEM; - } - } - - pp->cfg0_base = pp->cfg.start; - pp->cfg1_base = pp->cfg.start + pp->config.cfg0_size; pp->mem_base = pp->mem.start; - pp->va_cfg0_base = devm_ioremap(pp->dev, pp->cfg0_base, - pp->config.cfg0_size); - if (!pp->va_cfg0_base) { - dev_err(pp->dev, "error with ioremap in function\n"); - return -ENOMEM; - } - pp->va_cfg1_base = devm_ioremap(pp->dev, pp->cfg1_base, - pp->config.cfg1_size); - if (!pp->va_cfg1_base) { - dev_err(pp->dev, "error with ioremap\n"); - return -ENOMEM; - } + return 0; +} - if (of_property_read_u32(np, "num-lanes", &pp->lanes)) { - dev_err(pp->dev, "Failed to parse the number of lanes\n"); - return -EINVAL; - } +/* + * dw_pcie_msi_host_init() - Function to initialize msi host controller + * + * @pp: ptr to pcie port + * @np: device node ptr to msi irq controller + * @irq_msi_ops: ptr to MSI irq_domain_ops struct + * + * Function register irq domain for msi irq controller and create mappings + * for MSI irqs. + */ +int dw_pcie_msi_host_init(struct pcie_port *pp, struct device_node *np, + const struct irq_domain_ops *irq_msi_ops) +{ + int i; if (IS_ENABLED(CONFIG_PCI_MSI)) { pp->irq_domain = irq_domain_add_linear(pp->dev->of_node, - MAX_MSI_IRQS, &msi_domain_ops, + MAX_MSI_IRQS, irq_msi_ops, &dw_pcie_msi_chip); if (!pp->irq_domain) { dev_err(pp->dev, "irq domain init failed\n"); @@ -476,6 +470,29 @@ int __init dw_pcie_host_init(struct pcie_port *pp) irq_create_mapping(pp->irq_domain, i); } + return 0; +} + +/* + * dw_pcie_common_host_init() - common host init function across different + * versions of the designware PCI controller. + * @pp: ptr to pcie port + * @hw: ptr to hw_pci structure + * + * This functions parses common DT properties, call host_init() callback + * of the PCI controller driver. Also initialize the common RC configurations + * and call common pci core function to intialize the controller driver. + */ +int __init dw_pcie_common_host_init(struct pcie_port *pp, struct hw_pci *hw) +{ + struct device_node *np = pp->dev->of_node; + u32 val; + + if (of_property_read_u32(np, "num-lanes", &pp->lanes)) { + dev_err(pp->dev, "Failed to parse the number of lanes\n"); + return -EINVAL; + } + if (pp->ops->host_init) pp->ops->host_init(pp); @@ -488,10 +505,10 @@ int __init dw_pcie_host_init(struct pcie_port *pp) val |= PORT_LOGIC_SPEED_CHANGE; dw_pcie_wr_own_conf(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, 4, val); - dw_pci.nr_controllers = 1; - dw_pci.private_data = (void **)&pp; + hw->nr_controllers = 1; + hw->private_data = (void **)&pp; - pci_common_init_dev(pp->dev, &dw_pci); + pci_common_init_dev(pp->dev, hw); pci_assign_unassigned_resources(); #ifdef CONFIG_PCI_DOMAINS dw_pci.domain++; @@ -500,6 +517,55 @@ int __init dw_pcie_host_init(struct pcie_port *pp) return 0; } +/* + * dw_pcie_host_init() - Host init function for new designware h/w + * + * @pp: ptr to pcie port + * + * The function parse the PCI resurces for IO, Memory and map the config + * space addresses. Also initliaze the MSI irq controller and call + * dw_pcie_common_host_init() to initialize the PCI controller. + */ +int __init dw_pcie_host_init(struct pcie_port *pp) +{ + int ret; + + ret = dw_pcie_parse_resource(pp); + if (ret) + return ret; + + if (!pp->dbi_base) { + pp->dbi_base = devm_ioremap(pp->dev, pp->cfg.start, + resource_size(&pp->cfg)); + if (!pp->dbi_base) { + dev_err(pp->dev, "error with ioremap\n"); + return -ENOMEM; + } + } + + pp->cfg0_base = pp->cfg.start; + pp->cfg1_base = pp->cfg.start + pp->config.cfg0_size; + + pp->va_cfg0_base = devm_ioremap(pp->dev, pp->cfg0_base, + pp->config.cfg0_size); + if (!pp->va_cfg0_base) { + dev_err(pp->dev, "error with ioremap in function\n"); + return -ENOMEM; + } + pp->va_cfg1_base = devm_ioremap(pp->dev, pp->cfg1_base, + pp->config.cfg1_size); + if (!pp->va_cfg1_base) { + dev_err(pp->dev, "error with ioremap\n"); + return -ENOMEM; + } + + ret = dw_pcie_msi_host_init(pp, pp->dev->of_node, &msi_domain_ops); + if (ret < 0) + return ret; + + return dw_pcie_common_host_init(pp, &dw_pci); +} + static void dw_pcie_prog_viewport_cfg0(struct pcie_port *pp, u32 busdev) { /* Program viewport 0 : OUTBOUND : CFG0 */