From patchwork Fri Nov 10 03:48:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaowei Bao X-Patchwork-Id: 10052357 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 043A56035D for ; Fri, 10 Nov 2017 04:21:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8E8A28F8E for ; Fri, 10 Nov 2017 04:21:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCF7B2AC12; Fri, 10 Nov 2017 04:21:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 62FCA28F8E for ; Fri, 10 Nov 2017 04:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mN0AG75sN38dOw4JZUcAXDRWHvqMhZ3gsx8naLWzzfg=; b=Drns5auT0ApTRg dwqFpK22n1ayOvoTx32e1AV06h5oNREbOeS80Ibr3La0EH/KFwq5K9W1dsvEKCXciGdUF6HUgola+ RRdzxV5oPo7xoLAI5YsbOtjlSO/bHhS/JgTAI6Vkoqig5RlpShIfmXwUpYZSnpCCXsDbGCdKHZA1s IVF7Oscpyqp/fVhQ0rkC0oZCk45SjynKJ3Lp303GlaMyC66BEfdSrJxFOoqEIXRZoWmVFp4zBWV04 m41ralX3dGlbTPAeO4sbKVSIEA3hCdPEet5XmSJdd4be9w9yRPxqUA2JGyHtXFKGULlJxupeW9+9k nKmhu6nW7P5s6QTgp/+w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eD0pC-0004Hc-P1; Fri, 10 Nov 2017 04:21:50 +0000 Received: from mail-co1nam03on0046.outbound.protection.outlook.com ([104.47.40.46] helo=NAM03-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eD0bR-0004Dd-Ux for linux-arm-kernel@lists.infradead.org; Fri, 10 Nov 2017 04:07:39 +0000 Received: from MWHPR03CA0046.namprd03.prod.outlook.com (10.174.173.163) by CY1PR03MB2364.namprd03.prod.outlook.com (10.166.207.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.197.13; Fri, 10 Nov 2017 04:07:36 +0000 Received: from BY2FFO11FD045.protection.gbl (2a01:111:f400:7c0c::146) by MWHPR03CA0046.outlook.office365.com (2603:10b6:301:3b::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.218.12 via Frontend Transport; Fri, 10 Nov 2017 04:07:36 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD045.mail.protection.outlook.com (10.1.15.177) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.178.5 via Frontend Transport; Fri, 10 Nov 2017 04:07:36 +0000 Received: from titan.ap.freescale.net ([10.192.208.233]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id vAA47169007480; Thu, 9 Nov 2017 21:07:28 -0700 From: Bao Xiaowei To: , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCHv4 2/3] ARMv8: layerscape: add the pcie ep function support Date: Fri, 10 Nov 2017 11:48:46 +0800 Message-ID: <20171110034847.17891-3-xiaowei.bao@nxp.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171110034847.17891-1-xiaowei.bao@nxp.com> References: <20171110034847.17891-1-xiaowei.bao@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131547604565968233; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(346002)(39380400002)(39860400002)(376002)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(39060400002)(86362001)(5660300001)(8656006)(5003940100001)(7416002)(53936002)(81156014)(81166006)(8676002)(77096006)(50466002)(189998001)(305945005)(48376002)(356003)(4326008)(2950100002)(6666003)(6636002)(8936002)(105606002)(97736004)(106466001)(33646002)(104016004)(110136005)(16586007)(316002)(2201001)(47776003)(50986999)(76176999)(1076002)(498600001)(85426001)(50226002)(68736007)(36756003)(2906002)(921003)(83996005)(2101003)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR03MB2364; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD045; 1:+PLwKKEMbaIme6yZLBXj4DDoB45PhmlNXfSEGk1mlG8PDdrCAPIGZJr49SL3empsfBRv1tvzrt6oZrJm7NLG6U2xLsbHFQNNRXu7jB/OyRS2YcVf08i3k0KGsUd/2g0h MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e7891ae7-022b-4c69-3a71-08d527f09399 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4628075)(201703131517081)(2017052603256); SRVR:CY1PR03MB2364; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2364; 3:bXnsCct7FfWD5ChChKo/1OV5cYndco+BYPusYiyhCrdD1O+2nNjNvaz6N1ujXi0CilGooq//jpiN7xWau/BIuAKzUfPcP8zlO8N2xHcd181qiw7TkuNoTtWYE5rmzL+VYdn04S87XiORNwlOjp6avk7YhBl5X0Z8XoVWO9gr6cygu7AcLyBFLnX8FI5ucPBjWliEo7ogCXOVeiPILzdv/e6D5BACnMeLHn/W159fPNOxw4Fk9J3sPq9Irx45CrMEOeDS0nC8nbDT/RJgX2IhNZFHJJjBrrLPtXICMjphw3J40lmZWyJRmdv9XjT4G6eEGKf8ZZRCOmZvBI0ztHJ3QHkz8tgI2+lWOo5cb2ysAKc=; 25:tbFrBp58qVxJGdAmQH9q0L3iCtSiY1NlW2NiDh+kv1hzHt+OF/9ZHPpgUxGLBe+6+vcE6GrWDwUglRo+H7GOCk/VEgRHLkZbFc120VGTnSCqBgh1ZhVDTVNFcF6r2LUuc4PFKL3qK900xJ8m6lLvWPgegZ6OdHpG/tklI/zA5d/Sc7SfO86hFOPruwSBtH/RHaUVVnMY/0lEKT8F+UNjzZ0Km2wKGV+JgvHG/HLYtimgkV5qXR8Hu53D35fB8FX30YU6pWbLc8ykKVVQUgp5t5QXkuCqobNBAQrd/xSKTurNUJL2gGHxtsPxaNmCEqMwPN1ONtnku1A26v7QMWWhwA== X-MS-TrafficTypeDiagnostic: CY1PR03MB2364: X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2364; 31:zdnj8kF+DCv8LyaFWNtv4WbgQ7YbN3HzdzibQITinSb13bYWuYIw8JlUlkh5hwVnVkWm0bEi2adr9t/gm7bjVNSEygblNVfdh0mPtuqvpoP7x0BOexaarrsbFWGN4JnuW0z9qEc0ed7Q7IPWX7GrRB5WojJNPg6epAisa5niP7LsjlLbsSqDkQMfPJ1bbyPia5bY+V7OidCxt4ZqaclYi0IlRze58i/JgBEM26SN9bw=; 4:lEz0oeSko9T7tSI3oOU3WAp3hOoGXhgnaqYZnmBv0t6/3c3k1M0tU0pomQIvjc3DVKslnLtUuaCk2hpQTAZt/2gFPo+rJ9jCvSE/aqOvfw+VsxzH+G+IUo1QQrNOaWWt67b0G7qHvLwpewaJ5saqX/vSwEzCBQHIHAb7kEhw8pa+pmt6Xa12HD/Bfx9drupbOU3R26G0P1bE7o5cv7epZhXdn8JWX7NKXH5ulSoq+XxHPakBFgy0S2AaCHkr6AQKK95nO34I7thBVG5ACa44H1T/RgHC6xuUF5hB3IZjv1wLDfKDLkulNOktO6CdIjtT X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231021)(100000703101)(100105400095)(6055026)(6096035)(201703131430075)(201703131448075)(201703131433075)(201703161259150)(201703151042153)(20161123563025)(20161123561025)(20161123565025)(20161123556025)(20161123559100)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:CY1PR03MB2364; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:CY1PR03MB2364; X-Forefront-PRVS: 0487C0DB7E X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR03MB2364; 23:4uSxmspKjRcZRjO7y4ELEKPDZNFSJULVuKDvoXepI?= =?us-ascii?Q?5rXb7szSJQ2G4n7RBxZQHQedIxmSF3H7o/5ebAgZJigWHrEp8FydObH12Htj?= =?us-ascii?Q?ivVPZ7jw/T7K9ppuqENAI4J+oMTe/M0lW1PcrHY3wlou0xWw5Xu3i78kzyKz?= =?us-ascii?Q?2OVFNu1LbyReluqNFehx3ai1v0oGKURth+RhLv5Hmh3u+HmGa85NpX2rb31e?= =?us-ascii?Q?Wi2MUEYY21MxfXktIm+i6dbIHMljV+WYin25H8xiiUxJERPmGlys7xEWL4h3?= =?us-ascii?Q?4gAGCRAcjXDO6aHYXvXHiOcWM+w3j7rCwPDI8TKKmFrPpeyuYRgde3rNV13i?= =?us-ascii?Q?yFmK/Sq/eCbWTwyrdjFuH/mHIQbaTDHOqsOXj0a+4z7EMOlnz7pj46F5HBuz?= =?us-ascii?Q?o5t1lv055cqdr1JyIZbPSIvydPkogwwnToeFkps4q5QK0fIigtaJY4LIxbZI?= =?us-ascii?Q?acCw48GEKnpy52UvrFK6xM6u3ojOQEgKj6WsA9K16dGZZ41UbnXu/GAiYVzK?= =?us-ascii?Q?qQfY6q6pBmsjD8lMwlDYwnJKWf1bsH3zQIfNCFDGBatCv+4HQt4TZL6z8P/n?= =?us-ascii?Q?tkWx6Z7ijS0DK/KOKW3VwaUZZQgWalQppl0WapJjw0Hv8zwH62RncZiqIDvM?= =?us-ascii?Q?9FbacvOPs2XkslWRuRBRV2DplamMdqKsJ2UyEVQIXwFXf3Pdz5XPSeDORR21?= =?us-ascii?Q?iyBqoSggPuoqOR97Uvbci2W7l2ERNwOr7HKE0gwnJ+FYgS73KhL95sQcwPY6?= =?us-ascii?Q?oFBW1ZyX8A3dEtT8Lvypu+1WABjc3uUalNB9gGip/fNqI5OM8b93phT7qjHI?= =?us-ascii?Q?+BSt1nTEFDM/9316ES4VJAWIR80/vLMlh91tWHcjxHCHM2yUakIb24LeqodI?= =?us-ascii?Q?tSr3uEaNuphkEE9+/XmKpQQb+/IHpYoD/v5wsO6xs6mpJEkEkbP3tNJzNPyF?= =?us-ascii?Q?gvV/HcKDOdJlH24AdRiWHkg2Rw5KvMumqsYU6F30bQUD2pQM+WL9JZQ33w7+?= =?us-ascii?Q?Etk50IhME6Eqq+3SDFGZw1YG2c9IxZw4VQPTjHFnJlqPFfTUvV/8LdVeBlyY?= =?us-ascii?Q?+fIR2/2WLdn/e+ewuQ7oXVfW3djmFEaBb6SSF+bcOmfrqFB1H879iOhkZAL/?= =?us-ascii?Q?vD8dgEqx0NcHTEyOJGXyOhsfDKDghi/LjfFKcOVRL8zcZPrRcoSu9SJfc2gt?= =?us-ascii?Q?BZPLqoGWb4BTa5XywvV3mYxJYsC0oDbX3GfzOu4zOu34dHTkZhg0yStMbQHX?= =?us-ascii?Q?v+R6Lqufhy1zzw0MZfGWuuX8+TKFquWM+LHtM/y8w7FYWQaOIn4vSldFhLCS?= =?us-ascii?B?UT09?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2364; 6:lwRxjQHNpFeAyxhcXMLSm5GvdL+o74w4U6ngzu7HUWpuZXu4MjRT0PHS1ma13OgIK+BX1nqPetQ8ZzXM6li5ewrVArLMQtnWx1Wo2jXo9Hnrh+yS7kteNzqYp0lYWVB1d+Jj4b+hUeiSQiOZJY3acwI/gpi6NLJ39VqpgO+/R5kymiH6BtGjImYVmgDX0RH5SFHGbsyeluKqPxahQUZ4IAtMbOhrF1Px3P0s4JIyTEEOGjEtQNEPhZkuyFwUwkD+DfFYY4VGTlyx4ut4/kitzt77gpizfyIaHYbOQcUCs3TWAm/5PNfBKIR9Ubsy88IbmgyWOoKitObh+d3Z4WaZqt7KOFOh95Iv7ift4mQYQDo=; 5:D1me8ZBWN2EL5xgWjpMrOyjRfjDJxEon5gye3RPgNiDSG1ZkdGiH1wTF8sp1ItpGNNMznicShaZKQCHlYsYvHFsULjdjUUU8E2yfVSswVrgiestrrJyXnj/omQahlRsQ3P0gfbMf+60HIVAjtULErIzlnrcwUrUdysdRyUoUFgc=; 24:hNl91LyMF1duB8bEx0JtyDRT0AZm5vkAQIh77PIZk0OM1agihigs7zy7oJBuh14s+qzpAqoM9Nr6br2wZ4B6zKpXtbyLpmyzxXdWfQqOEak=; 7:HefCaBtef4fJwFi91CPGTD688PyxZfBOJVXvdq+nnw9EUmYLxxjP4RJGUwrGuIImw0YDmajW3yrZT46MDw2br6CZ01szwVGuNEMbXN1A/7XfwWVvDIhzauO9wk5PKDrWb9s17cHjLp6rqmIeEcCPFq3M31B81PZEkOikydsPTrzPO9TGksWZicSbU/KbxG4kOle7DJJzz57upWdGCimAGO9AXyY8mDBrfKu7jD/SzZyKqAjOfkAS16mWckxHU72X SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2017 04:07:36.1600 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e7891ae7-022b-4c69-3a71-08d527f09399 X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB2364 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171109_200738_048359_67A13DD3 X-CRM114-Status: GOOD ( 20.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bao Xiaowei Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add the pcie controller ep function support of layerscape base on pcie ep framework. Signed-off-by: Bao Xiaowei --- v2: - fix the ioremap function used but no ioumap issue - optimize the code structure - add code comments v3: - fix the msi outband window request failed issue v4: - optimize the code, adjust the format drivers/pci/dwc/pci-layerscape.c | 120 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 113 insertions(+), 7 deletions(-) diff --git a/drivers/pci/dwc/pci-layerscape.c b/drivers/pci/dwc/pci-layerscape.c index 87fa486bee2c..6f3e434599e0 100644 --- a/drivers/pci/dwc/pci-layerscape.c +++ b/drivers/pci/dwc/pci-layerscape.c @@ -34,7 +34,12 @@ /* PEX Internal Configuration Registers */ #define PCIE_STRFMR1 0x71c /* Symbol Timer & Filter Mask Register1 */ +#define PCIE_DBI2_BASE 0x1000 /* DBI2 base address*/ +#define PCIE_MSI_MSG_DATA_OFF 0x5c /* MSI Data register address*/ +#define PCIE_MSI_OB_SIZE 4096 +#define PCIE_MSI_ADDR_OFFSET (1024 * 1024) #define PCIE_IATU_NUM 6 +#define PCIE_EP_ADDR_SPACE_SIZE 0x100000000 struct ls_pcie_drvdata { u32 lut_offset; @@ -44,12 +49,20 @@ struct ls_pcie_drvdata { const struct dw_pcie_ops *dw_pcie_ops; }; +struct ls_pcie_ep { + dma_addr_t msi_phys_addr; + void __iomem *msi_virt_addr; + u64 msi_msg_addr; + u16 msi_msg_data; +}; + struct ls_pcie { struct dw_pcie *pci; void __iomem *lut; struct regmap *scfg; const struct ls_pcie_drvdata *drvdata; int index; + struct ls_pcie_ep *pcie_ep; }; #define to_ls_pcie(x) dev_get_drvdata((x)->dev) @@ -263,6 +276,99 @@ static const struct of_device_id ls_pcie_of_match[] = { { }, }; +static void ls_pcie_raise_msi_irq(struct ls_pcie_ep *pcie_ep) +{ + iowrite32(pcie_ep->msi_msg_data, pcie_ep->msi_virt_addr); +} + +static int ls_pcie_raise_irq(struct dw_pcie_ep *ep, + enum pci_epc_irq_type type, u8 interrupt_num) +{ + struct dw_pcie *pci = to_dw_pcie_from_ep(ep); + struct ls_pcie *pcie = to_ls_pcie(pci); + struct ls_pcie_ep *pcie_ep = pcie->pcie_ep; + u32 free_win; + + /* get the msi message address and msi message data */ + pcie_ep->msi_msg_addr = ioread32(pci->dbi_base + MSI_MESSAGE_ADDR_L32) | + (((u64)ioread32(pci->dbi_base + MSI_MESSAGE_ADDR_U32)) << 32); + pcie_ep->msi_msg_data = ioread16(pci->dbi_base + PCIE_MSI_MSG_DATA_OFF); + + /* request and config the outband window for msi */ + free_win = find_first_zero_bit(&ep->ob_window_map, + sizeof(ep->ob_window_map)); + if (free_win >= ep->num_ob_windows) { + dev_err(pci->dev, "no free outbound window\n"); + return -ENOMEM; + } + + dw_pcie_prog_outbound_atu(pci, free_win, PCIE_ATU_TYPE_MEM, + pcie_ep->msi_phys_addr, + pcie_ep->msi_msg_addr, + PCIE_MSI_OB_SIZE); + + set_bit(free_win, &ep->ob_window_map); + + /* generate the msi interrupt */ + ls_pcie_raise_msi_irq(pcie_ep); + + /* release the outband window of msi */ + dw_pcie_disable_atu(pci, free_win, DW_PCIE_REGION_OUTBOUND); + clear_bit(free_win, &ep->ob_window_map); + + return 0; +} + +static struct dw_pcie_ep_ops pcie_ep_ops = { + .raise_irq = ls_pcie_raise_irq, +}; + +static int __init ls_add_pcie_ep(struct ls_pcie *pcie, + struct platform_device *pdev) +{ + struct dw_pcie *pci = pcie->pci; + struct device *dev = pci->dev; + struct dw_pcie_ep *ep; + struct ls_pcie_ep *pcie_ep; + struct resource *cfg_res; + int ret; + + ep = &pci->ep; + ep->ops = &pcie_ep_ops; + + pcie_ep = devm_kzalloc(dev, sizeof(*pcie_ep), GFP_KERNEL); + if (!pcie_ep) + return -ENOMEM; + + pcie->pcie_ep = pcie_ep; + + cfg_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "config"); + if (cfg_res) { + ep->phys_base = cfg_res->start; + ep->addr_size = PCIE_EP_ADDR_SPACE_SIZE; + } else { + dev_err(dev, "missing *config* space\n"); + return -ENODEV; + } + + pcie_ep->msi_phys_addr = ep->phys_base + PCIE_MSI_ADDR_OFFSET; + + pcie_ep->msi_virt_addr = ioremap(pcie_ep->msi_phys_addr, + PCIE_MSI_OB_SIZE); + if (!pcie_ep->msi_virt_addr) { + dev_err(dev, "failed to map MSI outbound region\n"); + return -ENOMEM; + } + + ret = dw_pcie_ep_init(ep); + if (ret) { + dev_err(dev, "failed to initialize endpoint\n"); + return ret; + } + + return 0; +} + static int __init ls_add_pcie_port(struct ls_pcie *pcie) { struct dw_pcie *pci = pcie->pci; @@ -309,18 +415,18 @@ static int __init ls_pcie_probe(struct platform_device *pdev) if (IS_ERR(pci->dbi_base)) return PTR_ERR(pci->dbi_base); - pcie->lut = pci->dbi_base + pcie->drvdata->lut_offset; + pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_BASE; - if (!ls_pcie_is_bridge(pcie)) - return -ENODEV; + pcie->lut = pci->dbi_base + pcie->drvdata->lut_offset; platform_set_drvdata(pdev, pcie); - ret = ls_add_pcie_port(pcie); - if (ret < 0) - return ret; + if (!ls_pcie_is_bridge(pcie)) + ret = ls_add_pcie_ep(pcie, pdev); + else + ret = ls_add_pcie_port(pcie); - return 0; + return ret; } static struct platform_driver ls_pcie_driver = {