From patchwork Thu Sep 10 09:42:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurentiu Tudor X-Patchwork-Id: 1361382 X-Patchwork-Delegate: priyanka.jain@nxp.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector2 header.b=PBqX5nAK; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BnDT72qsqz9sTM for ; Thu, 10 Sep 2020 19:42:51 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 81F8282316; Thu, 10 Sep 2020 11:42:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="PBqX5nAK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3B1CC822FB; Thu, 10 Sep 2020 11:42:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-db5eur03on0621.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0a::621]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A0C80822F2 for ; Thu, 10 Sep 2020 11:42:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=laurentiu.tudor@nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BRgLPEL11sHnhLRTeRmMebxCFFlf42gQbAaRHzu11Px2/jlFjEVf/D00lB0NkYERB+G/u3gRpOpJFatlhGIHr4BaBJ3kiQFTqY9CpxEF/M0xUSSCsAJKxfTrEZGwVkxBSpqTBJhn/vcwct7/kfas/Dur14e0JbMhlSBK7OS1UpQWLZuCNmFx93n5Ae42AXnVZ70kUZ53yjC0eodDHBWxCcYwiwJtQME5OVUkWf2DoFDQUrD8qoYlOHREcol5PWBUhE6L+5wc/Jy1ZHn5+tDmtsZruWoJrgbOHz+tTABWKvvwDBPF0GoU1EI1wquevW634tpI+lJ28Qq9dKAG3GTfLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mvwh00WoKHncE4VD+0tKRCk0wmSQ0K9WtZzDXtJlwxc=; b=Uk/mVRM4ir55xatrfyXvWkrkL0VPpH8Pva4ObfwcdUf7UYJF2QVaeDYVUAndgQNdc846tNQucQxmRtz94iIbZD0HIVdvzvvVEAsDzxngq28AZ5jIjs2YynTq4Bllbvfv/9oDwlk//f4+evSObFrJdiiibw36l7F4TpbK1O8o+I/0Lt//2/daVbqRAZMkrkl902ePQ1yzsf1LFmhp52FlWHI7H1IeazaC+CNjXbtnPX8t81vKmo9/trA+qh0Ih37wXCH5PIeIY35dmXvPSU0HIdlcjCPlr+1vDgKtXRNwR1AB3zt8Sgl8J9t7cz8kNIC7RV5YFgH9P9WgcPrLCECELA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mvwh00WoKHncE4VD+0tKRCk0wmSQ0K9WtZzDXtJlwxc=; b=PBqX5nAKZ6ELPoWGc+SQtljvgOV6aWQI25Y5+2t5aRj3GzqVBB1xfYueeL+wz32mmWPexM28SAJ3gZ6BmLBM9itCntAqPtLCad99N16LlfBI7t/aflTboEp8G/KFpf4UcFDs4KitVeGqu73xhZWKHvMxYCqvonVLiddalUFsdfE= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=nxp.com; Received: from VI1PR0402MB3405.eurprd04.prod.outlook.com (2603:10a6:803:3::26) by VI1PR04MB7182.eurprd04.prod.outlook.com (2603:10a6:800:121::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Thu, 10 Sep 2020 09:42:29 +0000 Received: from VI1PR0402MB3405.eurprd04.prod.outlook.com ([fe80::f960:c16d:16a5:6e7b]) by VI1PR0402MB3405.eurprd04.prod.outlook.com ([fe80::f960:c16d:16a5:6e7b%7]) with mapi id 15.20.3348.019; Thu, 10 Sep 2020 09:42:29 +0000 From: laurentiu.tudor@nxp.com To: u-boot@lists.denx.de, priyanka.jain@nxp.com Cc: zhiqiang.hou@nxp.com, Laurentiu Tudor Subject: [PATCH v5 1/4] pci: layerscape: move per-pci device fdt fixup in a function Date: Thu, 10 Sep 2020 12:42:16 +0300 Message-Id: <20200910094219.32592-2-laurentiu.tudor@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910094219.32592-1-laurentiu.tudor@nxp.com> References: <20200910094219.32592-1-laurentiu.tudor@nxp.com> X-ClientProxiedBy: AM3PR05CA0145.eurprd05.prod.outlook.com (2603:10a6:207:3::23) To VI1PR0402MB3405.eurprd04.prod.outlook.com (2603:10a6:803:3::26) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from fsr-ub1864-101.ea.freescale.net (83.217.231.2) by AM3PR05CA0145.eurprd05.prod.outlook.com (2603:10a6:207:3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Thu, 10 Sep 2020 09:42:29 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [83.217.231.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: da0acc54-fefd-4abe-dff9-08d8556dd598 X-MS-TrafficTypeDiagnostic: VI1PR04MB7182: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sk1aFp7c/+KONMsqPkh8QXKw4tkFxuDdTKRZiPXwRQxc3EtOA5t+BBGA5OuHp661n+g4cJVklo4JJ9OziBRFx/mvwOrdOuCY+ih0gYgmFq7OsGIRNVYZ0vuBd3xIU8BelVtey5r500LOywzJbH5Od5cwd/HWMl72q6H9n0albbXAt9bjdAoCiqi+kkvhtmQOF5mbcMbv6BX82YoXUZ8HKIy8bLdRXZbcqb1A4RIPf0Oz9OuZpKX8zFqjnamQ/F1z8FsX/tbxEPh1p54qCCAS0X5gJUSQKcH8BxBG1i9SgHLnNLeTJ53foX6iGUpi6+Hk7mDo0Yp4G5MRsFgIL5vh6Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR0402MB3405.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(366004)(376002)(396003)(6506007)(66556008)(66946007)(66476007)(16526019)(316002)(2616005)(186003)(8676002)(4326008)(8936002)(83380400001)(2906002)(5660300002)(52116002)(956004)(26005)(6486002)(6512007)(478600001)(9686003)(86362001)(36756003)(1076003)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: M/ny7EDBJUtBX4y4LmNRBx+/iXCU6jhHlJnPesOPi4g3K+8/SIq5qBpGmtkxRU5qNi3C4MPhHZ2AKdYrxEugDnZ2L/qD/6beN7wzu7u7cYWQNy+YBivUki0NwP7HVq7/TXez/tpUi54dsrwcz2wcpjMyT3pWWT71UYcMPGFrx4PdLG75/KcDFHVxTXCKuTFE2rkIopciNZTZGBo/zMM1Ths1vgfaii7ID+jbJscgtgkZJxJugNoeCCek96gNz3Fdi5oQyWJgxSpPg+aEStXpECcKGaTc2bDxenDj0Qvku0QfBnoYhD7F/itvKzoGNGVzaPW/adqr5XCXHn5/AhU2lFq/6d3exR21YRstBBpMATBeG/ZKTGWE1TwKboOZta8l7Lbudm6XbOR5nYBWK7qRH04LNHTLiWvzAtHFd8a5Cuvki/tMh8OW9ytdbrp/gix9dmW8gjRtZuIx2Nv5m775s9jYw3Gh5zcVrQ0kXsHUOHx4tMrX5g7OBSPKhywQ7BMTqJdzrHDQsTbjOWMU4BECW6fVz0NVHqzmAKwEKcPsKwJoH0mVV/ta9dDD3pPua4uYw+wIsLYmE+BKvbO49PApciASGvTe7tfTUSETUpR8hY7F9fklj2PtxhWAZdYGuEhJL/udTeB+xWcAX6uBFlyPYg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: da0acc54-fefd-4abe-dff9-08d8556dd598 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3405.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2020 09:42:29.7906 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Vcq59/k7gwiJbOKliP+NSFQM8hhUvBv1vg9y/jYnPAtEIunQ8CSiIJNHKVEUYRjFXIfe4Z15pul3DoM0VQ9H2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7182 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Laurentiu Tudor Move the pci device related fdt fixup in a function in order to re-use it in a following patch. While at it, improve the error handling. Signed-off-by: Laurentiu Tudor --- drivers/pci/pcie_layerscape_fixup.c | 60 ++++++++++++++++------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/drivers/pci/pcie_layerscape_fixup.c b/drivers/pci/pcie_layerscape_fixup.c index 8315b0b590..7c55e3d249 100644 --- a/drivers/pci/pcie_layerscape_fixup.c +++ b/drivers/pci/pcie_layerscape_fixup.c @@ -174,12 +174,41 @@ static void fdt_pcie_set_iommu_map_entry_ls(void *blob, } } +static int fdt_fixup_pcie_device_ls(void *blob, pci_dev_t bdf, + struct ls_pcie_rc *pcie_rc) +{ + int streamid, index; + + streamid = pcie_next_streamid(pcie_rc->stream_id_cur, + pcie_rc->pcie->idx); + if (streamid < 0) { + printf("ERROR: out of stream ids for BDF %d.%d.%d\n", + PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf)); + return -ENOENT; + } + pcie_rc->stream_id_cur++; + + index = ls_pcie_next_lut_index(pcie_rc); + if (index < 0) { + printf("ERROR: out of LUT indexes for BDF %d.%d.%d\n", + PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf)); + return -ENOENT; + } + + /* map PCI b.d.f to streamID in LUT */ + ls_pcie_lut_set_mapping(pcie_rc, index, bdf >> 8, streamid); + /* update msi-map in device tree */ + fdt_pcie_set_msi_map_entry_ls(blob, pcie_rc, bdf >> 8, streamid); + /* update iommu-map in device tree */ + fdt_pcie_set_iommu_map_entry_ls(blob, pcie_rc, bdf >> 8, streamid); + + return 0; +} + static void fdt_fixup_pcie_ls(void *blob) { struct udevice *dev, *bus; struct ls_pcie_rc *pcie_rc; - int streamid; - int index; pci_dev_t bdf; /* Scan all known buses */ @@ -190,32 +219,11 @@ static void fdt_fixup_pcie_ls(void *blob) bus = bus->parent; pcie_rc = dev_get_priv(bus); - streamid = pcie_next_streamid(pcie_rc->stream_id_cur, - pcie_rc->pcie->idx); - if (streamid < 0) { - debug("ERROR: no stream ids free\n"); - continue; - } else { - pcie_rc->stream_id_cur++; - } - - index = ls_pcie_next_lut_index(pcie_rc); - if (index < 0) { - debug("ERROR: no LUT indexes free\n"); - continue; - } - /* the DT fixup must be relative to the hose first_busno */ bdf = dm_pci_get_bdf(dev) - PCI_BDF(bus->seq, 0, 0); - /* map PCI b.d.f to streamID in LUT */ - ls_pcie_lut_set_mapping(pcie_rc, index, bdf >> 8, - streamid); - /* update msi-map in device tree */ - fdt_pcie_set_msi_map_entry_ls(blob, pcie_rc, bdf >> 8, - streamid); - /* update iommu-map in device tree */ - fdt_pcie_set_iommu_map_entry_ls(blob, pcie_rc, bdf >> 8, - streamid); + + if (fdt_fixup_pcie_device_ls(blob, bdf, pcie_rc) < 0) + break; } pcie_board_fix_fdt(blob); } From patchwork Thu Sep 10 09:42:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurentiu Tudor X-Patchwork-Id: 1361383 X-Patchwork-Delegate: priyanka.jain@nxp.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector2 header.b=EhrXYzl5; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BnDTM1Zcwz9sTq for ; Thu, 10 Sep 2020 19:43:03 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6AAD782324; Thu, 10 Sep 2020 11:42:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="EhrXYzl5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 68A3382314; Thu, 10 Sep 2020 11:42:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-db5eur03on0610.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0a::610]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id AE3F8822F5 for ; Thu, 10 Sep 2020 11:42:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=laurentiu.tudor@nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VJLJsJq3OD1cwp7uBWZVbuA0W4vrSKGqKt2R6nh4fKiVUf/gJGwO32/Evc1jOaxitLfFX2gX2ON5yhY+L9NKS+yZK8vjJ7mDVb+3X+7jrqBxRwIKI5WLWEalQiJgarDWIQNTR/TcUAsLD+XPnNMOQe7mustKKxymMpl4EDIX1cIH3PJuDIabaxmYcNsTqkWl6SN/I9Lp40biFETBZ+LCf2k2BQC0vycknlEOgWumTHYbt5aq2Dha0m6Ija7ZvaYmh5Pr7/XjezP25oxhBd0qubymLEPVCj0Bnmm3pQ1WXymOrK1OC+bIcXyhg9prUq/lIOwTEmDEOv4DDH6AK9ul+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=c2be2gnv8PR5QHkpg2aSWVzvage/QFfVPklaFB44QKU=; b=clB+qGD3LecUMS7uLSM46jDvUJQDNNWaERE/YdZMLM53cpj4LnKFuiPM+aNZsUxz8n9A1L+LflNSWtE8tPsClNMpnSaunDGFlo8L2pBzOwgsDejYW1gXT62a1rba9ZqFxM1ktt1ixb7ZfX3iPP0111wzjt3z97mWGytV9OXqcuz+tXR1A7F6JJvImqbhhBl209m9VF3x+YqY4i6BtJuyKvPuHmk9YotF8oIyQf/SPHNX2iSnYADo/pY0QDgUynivv+FAMQAdqnlMEsg4QrHFqwGOwpV0B9b0hKtBBbVJlBsU8lnbZmDoaKwfRY35PgzpmJ17MbpJX0/x+xqe2QZrXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=c2be2gnv8PR5QHkpg2aSWVzvage/QFfVPklaFB44QKU=; b=EhrXYzl5n9LlnMN5QTApRvLo4NpoeTpCF213mxAqTwzOV64Ikak18ES9Pgja3uo9TEPVts3SNhCIowmheh32eA3lXCUBb+tReYV3ib+9DvABeM9rlaA4NoDTrW5bo7TWkeA3YQTxsBD4afsHP5R4VTgjBtcRsa/2lx7QPlAq/cU= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=nxp.com; Received: from VI1PR0402MB3405.eurprd04.prod.outlook.com (2603:10a6:803:3::26) by VI1PR04MB7182.eurprd04.prod.outlook.com (2603:10a6:800:121::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Thu, 10 Sep 2020 09:42:30 +0000 Received: from VI1PR0402MB3405.eurprd04.prod.outlook.com ([fe80::f960:c16d:16a5:6e7b]) by VI1PR0402MB3405.eurprd04.prod.outlook.com ([fe80::f960:c16d:16a5:6e7b%7]) with mapi id 15.20.3348.019; Thu, 10 Sep 2020 09:42:30 +0000 From: laurentiu.tudor@nxp.com To: u-boot@lists.denx.de, priyanka.jain@nxp.com Cc: zhiqiang.hou@nxp.com, Laurentiu Tudor Subject: [PATCH v5 2/4] pci: layerscape: move pci node search in a common function Date: Thu, 10 Sep 2020 12:42:17 +0300 Message-Id: <20200910094219.32592-3-laurentiu.tudor@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910094219.32592-1-laurentiu.tudor@nxp.com> References: <20200910094219.32592-1-laurentiu.tudor@nxp.com> X-ClientProxiedBy: AM3PR05CA0145.eurprd05.prod.outlook.com (2603:10a6:207:3::23) To VI1PR0402MB3405.eurprd04.prod.outlook.com (2603:10a6:803:3::26) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from fsr-ub1864-101.ea.freescale.net (83.217.231.2) by AM3PR05CA0145.eurprd05.prod.outlook.com (2603:10a6:207:3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Thu, 10 Sep 2020 09:42:29 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [83.217.231.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4e053a0e-8d9d-434a-0fd1-08d8556dd618 X-MS-TrafficTypeDiagnostic: VI1PR04MB7182: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4uQ0zCB9N+cSHTYXQiCvLi/9soRdLSPtFo6Fq+/5y9swY9hic7DR4Qj/0waMjRxGbyyAXNrt86ahzhYhgcDhQS7KuqebaXmkWC/51DVU3sEMFaOA4w1jCMNh7eoWBC7aaQGWElDPLNY6FddREQ/PT/qxUvVEBdvJ05XsUYuELdrm8Iw7ShX19m986hP5nc98/38My0CzNhTkjvD/oLJhLM1gXojOYyVxaH7r3PesD829GW4KARDg5g+4CaBJN41CEIluYy2V0noNFT1NBnbr/7smrJfUO3KocXSTBYFacC8EdpGv2ciIFtf+4JeqSKFpX3I0Qi/PuP4re1UlukhW3g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR0402MB3405.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(366004)(376002)(396003)(6506007)(66556008)(66946007)(66476007)(16526019)(316002)(2616005)(186003)(8676002)(4326008)(8936002)(83380400001)(2906002)(5660300002)(52116002)(956004)(26005)(6486002)(6512007)(478600001)(9686003)(86362001)(36756003)(1076003)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: nBYHvPprX68+5jZeArgiT6pI2R6m6ARAkna4V62AmiZI23UZRSmVsDHECn8Cf8wfTsYCsfy17fDjrIoO0q07QuI8Csw+lVuEd0VmHCSnbjCL8eCc9MVyNBLeqoiHco/ciIlKH7f6iBakaKfEvGNAFH8BLfJbgO3nBPdnyQPgjfTfAXEaELoY4bENG+eRg6eNJsh/AA9X+JKVR+m/oVrPCCIUWSxhoJPkuzmzHOMJpX5Us1qcxuhJC4VnpinL7zHMxK77LJiVHiwPhB0Zoe4Yiy5hTYSmhovSt4CkrxZhuovG5udswyZ0I8gHfCpQwb0sxs7nYb9+A2tYmFCHlaMpEj3ywcBUjDShFbhN6r6NGCQi2R8ve6ykeRpf9obx4uYvqXOT/US2XZibJp/p7aGTzgfMZWmicL7Lvn5RwxJOkCL1iY5DlUdPJLa5/SBn1gxX9OLoH6mFE82oh4OZqEZFqdUL4FMXmG8EIzkCJYzWhPVwyfhj8oKWLys9p8iU1XjRM8U9HO4zjlho68Wx8xEcnGNQmsm0B/LUf8waGOTecj5CvdxDymkbzIeB3sUYibRBsE41X4Qu5vWU2kcOjLGdj/U2h4T5EiJKP3l82GU0NueBOLz/0wQOGENnm8nsWrDmnAjvfj2wLd9JU7oLIiO77A== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e053a0e-8d9d-434a-0fd1-08d8556dd618 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3405.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2020 09:42:30.6151 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8rypYwWyua7fTbRHulghN1K/3cnyQRoVGr6lzr+lqpm0yjIaT0hkX1bq4sbePZMqa2SBpobmfb72Wl2aj20WEg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7182 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Laurentiu Tudor Fix duplication of this code by placing it in a common function. Furthermore, the resulting function will be re-used in upcoming patches. Signed-off-by: Laurentiu Tudor --- drivers/pci/pcie_layerscape_fixup.c | 76 +++++++++++++---------------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/drivers/pci/pcie_layerscape_fixup.c b/drivers/pci/pcie_layerscape_fixup.c index 7c55e3d249..fdbfd82740 100644 --- a/drivers/pci/pcie_layerscape_fixup.c +++ b/drivers/pci/pcie_layerscape_fixup.c @@ -22,6 +22,34 @@ #include "pcie_layerscape.h" #include "pcie_layerscape_fixup_common.h" +static int fdt_pcie_get_nodeoffset(void *blob, struct ls_pcie_rc *pcie_rc) +{ + int nodeoffset; + uint svr; + char *compat = NULL; + + /* find pci controller node */ + nodeoffset = fdt_node_offset_by_compat_reg(blob, "fsl,ls-pcie", + pcie_rc->dbi_res.start); + if (nodeoffset < 0) { +#ifdef CONFIG_FSL_PCIE_COMPAT /* Compatible with older version of dts node */ + svr = (get_svr() >> SVR_VAR_PER_SHIFT) & 0xFFFFFE; + if (svr == SVR_LS2088A || svr == SVR_LS2084A || + svr == SVR_LS2048A || svr == SVR_LS2044A || + svr == SVR_LS2081A || svr == SVR_LS2041A) + compat = "fsl,ls2088a-pcie"; + else + compat = CONFIG_FSL_PCIE_COMPAT; + + nodeoffset = + fdt_node_offset_by_compat_reg(blob, compat, + pcie_rc->dbi_res.start); +#endif + } + + return nodeoffset; +} + #if defined(CONFIG_FSL_LSCH3) || defined(CONFIG_FSL_LSCH2) /* * Return next available LUT index. @@ -127,30 +155,11 @@ static void fdt_pcie_set_iommu_map_entry_ls(void *blob, u32 iommu_map[4]; int nodeoffset; int lenp; - uint svr; - char *compat = NULL; struct ls_pcie *pcie = pcie_rc->pcie; - /* find pci controller node */ - nodeoffset = fdt_node_offset_by_compat_reg(blob, "fsl,ls-pcie", - pcie_rc->dbi_res.start); - if (nodeoffset < 0) { -#ifdef CONFIG_FSL_PCIE_COMPAT /* Compatible with older version of dts node */ - svr = (get_svr() >> SVR_VAR_PER_SHIFT) & 0xFFFFFE; - if (svr == SVR_LS2088A || svr == SVR_LS2084A || - svr == SVR_LS2048A || svr == SVR_LS2044A || - svr == SVR_LS2081A || svr == SVR_LS2041A) - compat = "fsl,ls2088a-pcie"; - else - compat = CONFIG_FSL_PCIE_COMPAT; - - if (compat) - nodeoffset = fdt_node_offset_by_compat_reg(blob, - compat, pcie_rc->dbi_res.start); -#endif - if (nodeoffset < 0) - return; - } + nodeoffset = fdt_pcie_get_nodeoffset(blob, pcie_rc); + if (nodeoffset < 0) + return; /* get phandle to iommu controller */ prop = fdt_getprop_w(blob, nodeoffset, "iommu-map", &lenp); @@ -232,28 +241,11 @@ static void fdt_fixup_pcie_ls(void *blob) static void ft_pcie_rc_fix(void *blob, struct ls_pcie_rc *pcie_rc) { int off; - uint svr; - char *compat = NULL; struct ls_pcie *pcie = pcie_rc->pcie; - off = fdt_node_offset_by_compat_reg(blob, "fsl,ls-pcie", - pcie_rc->dbi_res.start); - if (off < 0) { -#ifdef CONFIG_FSL_PCIE_COMPAT /* Compatible with older version of dts node */ - svr = (get_svr() >> SVR_VAR_PER_SHIFT) & 0xFFFFFE; - if (svr == SVR_LS2088A || svr == SVR_LS2084A || - svr == SVR_LS2048A || svr == SVR_LS2044A || - svr == SVR_LS2081A || svr == SVR_LS2041A) - compat = "fsl,ls2088a-pcie"; - else - compat = CONFIG_FSL_PCIE_COMPAT; - if (compat) - off = fdt_node_offset_by_compat_reg(blob, - compat, pcie_rc->dbi_res.start); -#endif - if (off < 0) - return; - } + off = fdt_pcie_get_nodeoffset(blob, pcie_rc); + if (off < 0) + return; if (pcie_rc->enabled && pcie->mode == PCI_HEADER_TYPE_BRIDGE) fdt_set_node_status(blob, off, FDT_STATUS_OKAY, 0); From patchwork Thu Sep 10 09:42:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurentiu Tudor X-Patchwork-Id: 1361384 X-Patchwork-Delegate: priyanka.jain@nxp.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector2 header.b=OLNydatd; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BnDTb0G5Yz9sTN for ; Thu, 10 Sep 2020 19:43:15 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5BB4E82339; Thu, 10 Sep 2020 11:42:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="OLNydatd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7D5A982311; Thu, 10 Sep 2020 11:42:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-db5eur03on0628.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0a::628]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B1BC0822F8 for ; Thu, 10 Sep 2020 11:42:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=laurentiu.tudor@nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NoKi8qBbuAltdIxtkYxYjbKtiNwHe08Ex1zCH12FZaPjW/3moLIDil3QlLMR2+Z6GiePMcSogLUp4R7tyCM9EpTXihS0z6lFtsrr8uwE6vTTPb5LRf6jiENjsGhnwp+PvxGozh0sH8jBZR82Ul3o7qgJYK27tsCG+y08cjp3mUx1YCQhY7W/cKACOWsI3UcOlkJQV/Yw1b+t2+HgplKrSkaObh027xP52F/uYC8UbLuvpNGecnJKREe5OBQcXoP4UHoQlTiGQop0MUHERQ+amivKhoY3vcv0dA2U0a9gJF3osCpk/iWpS4Z9modfIXj9EtLusMGsleZmsrJQ9yvlFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4UshfzmIrvrMGHgd8YJjgH+3pIrrG3PanBd8hBPIxpA=; b=Yk0f2ddvEFJ3r7dlxVZEohLxPp1TYsVux5YnGog3waTrdJZNH2I/1jiEOdeyANr7oQ6y2nDevOABm7DMfzL91chxxyb5+Uv+7l/9z8leOjtx2dHx38lXZz1PCexF0smbyqh+auWiOORt4qs1J7achwTRNDcC9BPsznhBliuAHUZqwz/bvZ6PcV3Zc1bW4rNBPGFBB+51NZKQlGE0QOKvW7NVLAF54hvuHiNLdXZVoPHysZuZr15UacktuumX7jL1JklJe5ji/jbDTlutg1OO7PKpftJ04PCbwZBU+QhloPUz5dMfDbWyMuye9DH/fwQlBI4XwG2qfh8oODxgVUZ3/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4UshfzmIrvrMGHgd8YJjgH+3pIrrG3PanBd8hBPIxpA=; b=OLNydatdbS0o9uIyLNLZOFzF4U/nzm6gyBM1wU7AtsgtOsmCVpaMqEc+z2yKup02doet0vmgCEIsY59Ci6U9thajs2Dcox9IYewLg4h/ezpwfGdkHbEK25nSEjnCKhSajK5Q59CUDhsJyjy9ScD8wCoev7TsPeXnTUnM5+PO5Yc= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=nxp.com; Received: from VI1PR0402MB3405.eurprd04.prod.outlook.com (2603:10a6:803:3::26) by VI1PR04MB7182.eurprd04.prod.outlook.com (2603:10a6:800:121::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Thu, 10 Sep 2020 09:42:31 +0000 Received: from VI1PR0402MB3405.eurprd04.prod.outlook.com ([fe80::f960:c16d:16a5:6e7b]) by VI1PR0402MB3405.eurprd04.prod.outlook.com ([fe80::f960:c16d:16a5:6e7b%7]) with mapi id 15.20.3348.019; Thu, 10 Sep 2020 09:42:31 +0000 From: laurentiu.tudor@nxp.com To: u-boot@lists.denx.de, priyanka.jain@nxp.com Cc: zhiqiang.hou@nxp.com, Laurentiu Tudor Subject: [PATCH v5 3/4] pci: add a few ARI related defines Date: Thu, 10 Sep 2020 12:42:18 +0300 Message-Id: <20200910094219.32592-4-laurentiu.tudor@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910094219.32592-1-laurentiu.tudor@nxp.com> References: <20200910094219.32592-1-laurentiu.tudor@nxp.com> X-ClientProxiedBy: AM3PR05CA0145.eurprd05.prod.outlook.com (2603:10a6:207:3::23) To VI1PR0402MB3405.eurprd04.prod.outlook.com (2603:10a6:803:3::26) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from fsr-ub1864-101.ea.freescale.net (83.217.231.2) by AM3PR05CA0145.eurprd05.prod.outlook.com (2603:10a6:207:3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Thu, 10 Sep 2020 09:42:30 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [83.217.231.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d504ec35-6bb9-48eb-5567-08d8556dd696 X-MS-TrafficTypeDiagnostic: VI1PR04MB7182: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:415; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fEnLPTUEJP2EeVzdCR8CharP6eiCOmtPDTI8DPs3C6iFoOhTI4sSthD8yQAxZviCclI/2AoGHhYRXTh8cDPJ2amv5HpbTQ6XgEsLmsE/GL8XKpD+PTj9KQQwGE6gCflIrGHuydgDpijvAoR5iEO2NYw2f9AvyIxe0pO4ROyZLHQC2F8c3kEfoXt5JRgM4Z7bZF06THOXPt+KIyfSfKuw5aqh1zxv7cZu3LH5x9A4cec+JNtVMg+eXdD9IcmXVD9JPOmklcJFGKla82ZlC++pSHWFUtnJmZg5bRbqLJ/9j+G1btMrfIiKGXHQGzWPtf/BlAT0auktf6yL7w/VcQxIFEnCEv5UrixXDfA/rXOyx/45bV5JFboK0NaFy6JHm0Dc X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR0402MB3405.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(366004)(376002)(396003)(6506007)(66556008)(66946007)(66476007)(16526019)(316002)(2616005)(186003)(8676002)(4326008)(8936002)(2906002)(5660300002)(52116002)(956004)(26005)(6486002)(6512007)(478600001)(9686003)(86362001)(36756003)(1076003)(6666004)(334744003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: QxvTGf7FIi/NuZQyzpTkngjUtcjb9nd7leLjESkLlTvqlmC7eTDfSylFeV/qI2p4YF6L1AgY02NMabVnKJXcqtH05kXCIKnccJUDRRgoKx6xp3fb0LLN8/bHIjMiLHrB3wPXnoaUO8fpUIYCqidBm9lniye9ek48X2SUEh9H37YAOOaLhPshjizV+jC0u9SrLQu11NMzwh/OKg8TlyRN2EHhDin137Mm52WPPn0vnpMMVqJjYToaao3KlLwo2CL8s1WvgK01kP648+wZ8e6HzwFCYe/OdupfZrX/ZKmb3S76I44DkvHLRWqoHMELsbPbCa8pgtoPkAhz2YgxrD0FRGyUZR+63tFWf9eWiVJXcMieYc9jIM369X7VwcJUh6tslRMeD0xkJl+R2Wea2F54XxVoEvpyLt2ShkEF28h6mlGz01882m2A2Q5jUXDV+vq0U3HQCpneq7fvXHqS2Es3UeTT3dmE8RS5hccXLxwnhb900Dvgsy9wSPMU3T+SJAt1+Tl+GL/Xy8urbBiAkraA5ynKy7MrglDofR2S4cljREAAGxrjtx3VaN70v6DhA2yEpphzvY52G8QmG0ceNtyPh4/VsX1jzih4x5eP9QRbATBhSeoA9cmjWZpYtw6ttpwuog54IsmvQJRStNZpwxOj4g== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d504ec35-6bb9-48eb-5567-08d8556dd696 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3405.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2020 09:42:31.4367 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /eKtYD6hTKABY8ct0YGIU6og6Cg2iEODZDs1p+T1TcgQqzUUkt2RZhyWsizfYPXuX/i/2PumiVVDJFMlsAtlfA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7182 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Laurentiu Tudor Add a few defines related to PCI ARI configuration. Signed-off-by: Laurentiu Tudor --- include/pci.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/pci.h b/include/pci.h index 1c5b36617e..d1ccf6c963 100644 --- a/include/pci.h +++ b/include/pci.h @@ -495,12 +495,18 @@ #define PCI_EXP_LNKSTA_DLLLA 0x2000 /* Data Link Layer Link Active */ #define PCI_EXP_SLTCAP 20 /* Slot Capabilities */ #define PCI_EXP_SLTCAP_PSN 0xfff80000 /* Physical Slot Number */ +#define PCI_EXP_DEVCAP2 36 /* Device Capabilities 2 */ +#define PCI_EXP_DEVCAP2_ARI 0x00000020 /* ARI Forwarding Supported */ +#define PCI_EXP_DEVCTL2 40 /* Device Control 2 */ +#define PCI_EXP_DEVCTL2_ARI 0x0020 /* Alternative Routing-ID */ + #define PCI_EXP_LNKCTL2 48 /* Link Control 2 */ /* Single Root I/O Virtualization Registers */ #define PCI_SRIOV_CAP 0x04 /* SR-IOV Capabilities */ #define PCI_SRIOV_CTRL 0x08 /* SR-IOV Control */ #define PCI_SRIOV_CTRL_VFE 0x01 /* VF Enable */ #define PCI_SRIOV_CTRL_MSE 0x08 /* VF Memory Space Enable */ +#define PCI_SRIOV_CTRL_ARI 0x10 /* ARI Capable Hierarchy */ #define PCI_SRIOV_INITIAL_VF 0x0c /* Initial VFs */ #define PCI_SRIOV_TOTAL_VF 0x0e /* Total VFs */ #define PCI_SRIOV_NUM_VF 0x10 /* Number of VFs */ From patchwork Thu Sep 10 09:42:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurentiu Tudor X-Patchwork-Id: 1361385 X-Patchwork-Delegate: priyanka.jain@nxp.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector2 header.b=YaYYE3rb; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BnDTq3kDLz9sTN for ; Thu, 10 Sep 2020 19:43:27 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B07A482311; Thu, 10 Sep 2020 11:42:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="YaYYE3rb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 936EE82311; Thu, 10 Sep 2020 11:42:36 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-db5eur03on0629.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0a::629]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6DA17822F2 for ; Thu, 10 Sep 2020 11:42:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=laurentiu.tudor@nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WuKDZotvvT1lHxxofP9T0J/RDTAQBxXsXKfvYppX6H//8ki6CzuB1coLfPzEB+6Psqqd9+lseDwyUVu00O/sxknyIqpXe0Jxfew4Kay3NogMHH9Io15bBe0U/sTD63X+DLLX9yJm98I2qVt8CYXbRMa5dlr3napX97zvuYpmktlGAb8t5OYgiL51ZM73Ca9F0Q6EnRYzpQS3GuZ8iZMHEjq20Sg1NBZSJi6FIynRFlbY8kmidVtoTX+qEuGJQQp3ZUu1dIKrW3JfkCxQ0KWJ+09MwlKrQnOEkHWZcf4MJo17a2gHZ7bOYO6bZdVYakNrWP12mRXTHhD2sIzqOEHo0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QcposLGMW3Dpf3N0EvIg75RRFAP1igKqT8KY8JKbxIc=; b=VpLaMD+l0rO7+QgtuzwyASuOqjJsAh/xXptkOMvdiXAaiGkUnLEqrx7GIjnuMQPl45UM6bCCt6NkDxCcui5oxTh3YUtA/JSQx8YqAodA/1ZWg/MTgu9kPede95aGvsI+ckByfWpYntHLDURowHn8QjGFlwvGoT4oz0RatwognDg8m0IiRWPGfWQxOoKkx16ikelku6kTl2u5zHQ7hSMRKEcOk6a4OvYpyCdgnScMm4T2khrKFn9y/+bdXGMIeigiC2n4IU7xdNdJ3pelT5azRV5PwBT1o5LYQNiQM52VVmHTR4auvZsQ7kFsEaU7gdIEMGlML0V7qW+q8Q7ZDLeJrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QcposLGMW3Dpf3N0EvIg75RRFAP1igKqT8KY8JKbxIc=; b=YaYYE3rb4goZVL9sI6fx3U08krFOF1CXfMWt/kTYsfxrfbRe5vO6TIU27o70/5Q1m0oGgVMY7o92SPSoa7VzEnpm4ag5LWfcUf5qIL32nJSI8vleY6xZgiCd8nvgttip/qstFdbzSE2ZC4jwdEFhtOLMi9ELbZOHWpn+4l7mXFE= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=nxp.com; Received: from VI1PR0402MB3405.eurprd04.prod.outlook.com (2603:10a6:803:3::26) by VI1PR04MB7182.eurprd04.prod.outlook.com (2603:10a6:800:121::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Thu, 10 Sep 2020 09:42:32 +0000 Received: from VI1PR0402MB3405.eurprd04.prod.outlook.com ([fe80::f960:c16d:16a5:6e7b]) by VI1PR0402MB3405.eurprd04.prod.outlook.com ([fe80::f960:c16d:16a5:6e7b%7]) with mapi id 15.20.3348.019; Thu, 10 Sep 2020 09:42:32 +0000 From: laurentiu.tudor@nxp.com To: u-boot@lists.denx.de, priyanka.jain@nxp.com Cc: zhiqiang.hou@nxp.com, Laurentiu Tudor Subject: [PATCH v5 4/4] pci: layerscape: add a way of specifying additional iommu mappings Date: Thu, 10 Sep 2020 12:42:19 +0300 Message-Id: <20200910094219.32592-5-laurentiu.tudor@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910094219.32592-1-laurentiu.tudor@nxp.com> References: <20200910094219.32592-1-laurentiu.tudor@nxp.com> X-ClientProxiedBy: AM3PR05CA0145.eurprd05.prod.outlook.com (2603:10a6:207:3::23) To VI1PR0402MB3405.eurprd04.prod.outlook.com (2603:10a6:803:3::26) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from fsr-ub1864-101.ea.freescale.net (83.217.231.2) by AM3PR05CA0145.eurprd05.prod.outlook.com (2603:10a6:207:3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Thu, 10 Sep 2020 09:42:31 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [83.217.231.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3b0c4229-9913-471f-5167-08d8556dd712 X-MS-TrafficTypeDiagnostic: VI1PR04MB7182: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1923; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cFm7ldRSNQ3Zm25L41IUT+ZQF2Xh/Qmbl7sAqq12MkUgwj/6yfoKPJY+dpaggxtBPgmuxhURE7fTUaOzWu9CbC6kovmfghN+SU+5e2tD5DPGeXhJJJJua95AaYicOeaGDdRTqtBbqs3lQEmYuYhAtcBGXy81Mu8Q4sEN9uzoZBjhvx8qtcntDaGq/nDdo8O89+wVCTS1DTJZ6t564JnD7V0Or4yYyJxyY9PsJUFLS81KTVMTu4zEzQm8XS2by6nlDlLoUnmbDH276NnI+VQ+JVnX0XNg6zPgKUFvjr/9st4zNR0h2kiHpK0/9juwStmcqEIlUvJFrXlWONJfp2n42w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR0402MB3405.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(366004)(376002)(396003)(6506007)(66556008)(30864003)(66946007)(66476007)(16526019)(316002)(2616005)(186003)(8676002)(4326008)(8936002)(83380400001)(2906002)(5660300002)(52116002)(956004)(26005)(6486002)(6512007)(478600001)(9686003)(86362001)(36756003)(1076003)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: KkDUJbdFuPf4jgneNvLvzfAWBu+fYVq1RTnzLcOMYs/IjSnsHEoB6yVyPUt9fBafiEp36tWEqpRCmlhyt0PCNt0PBIMxKOQ7bLQ5nezBA+ox0Xa3sBYJdxDl01BJxGgDsV1yXGfBA4f87NCLRpad5pGo1XTponwz6Ze4DAtdwhaQIGkdUzY2nvyPD7rlhxC3/I5rvONtsC0R2Ylg2vgbzvZTWgrQHsJ/3iy2xnMMFoXcnAmPrPIChFecac6MFfYkDNRCceMBife1itrU3fOAvqzBFGUf859tpokD4uJCybFDjXzRc1VwmVlF7YXZMZleSArj2W8H0/YaZKGwyzMF1Bx0/nB9xfCrOny2Uwu6pEG75eif5SdrE3Jrra2cihJOcx8nLFEGwXK2TPTERbHLitDSmdpgN4dUhBg1Rzdm9I8T2eZ6e7LKTqrR40LTPRx/9ZsI2o0Td6j0gSf1jvaTwTgMczIZ4di0mm7b491gaHiyfTD4X6MzfmRTsvudh2ma73xk5ehUMUuqdGwEsVzhZ9x3N+er4RZE9Gy/g9iAQEjdzQ5p6frKOWQ5YU8o9FaxLK95lS0LnN19Hn/0T3zhkDtCKDU9jCjHhv6Vb2EG67H0gvyX6WDrIbT3vfQO7zqwi6+BsZi9gscnPmuAY8dQkA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3b0c4229-9913-471f-5167-08d8556dd712 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3405.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2020 09:42:32.3401 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 76oDM8KzXZNtA0zNqMBzKetESqAGzfV3vE39K2L4XTqtNRpk9uzpYqOXKesos61emn1BtBOmRaCGzxMXpQa0IA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7182 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Laurentiu Tudor In the current implementation, u-boot creates iommu mappings only for PCI devices enumarated at boot time thus does not take into account more dynamic scenarios such as SR-IOV or PCI hot-plug. Add an u-boot env var and a device tree property (to be used for example in more static scenarios such as hardwired PCI endpoints that get initialized later in the system setup) that would allow two things: - for a SRIOV capable PCI EP identified by its B.D.F specify the maximum number of VFs that will ever be created for it - for hot-plug case, specify the B.D.F with which the device will show up on the PCI bus More details can be found in the included documentation: arch/arm/cpu/armv8/fsl-layerscape/doc/README.pci_iommu_extra Signed-off-by: Laurentiu Tudor --- .../fsl-layerscape/doc/README.pci_iommu_extra | 67 ++++ drivers/pci/Kconfig | 12 + drivers/pci/pcie_layerscape_fixup.c | 328 ++++++++++++++++++ 3 files changed, 407 insertions(+) create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/doc/README.pci_iommu_extra diff --git a/arch/arm/cpu/armv8/fsl-layerscape/doc/README.pci_iommu_extra b/arch/arm/cpu/armv8/fsl-layerscape/doc/README.pci_iommu_extra new file mode 100644 index 0000000000..43db4d8e94 --- /dev/null +++ b/arch/arm/cpu/armv8/fsl-layerscape/doc/README.pci_iommu_extra @@ -0,0 +1,67 @@ +# +# Copyright 2020 NXP +# +# SPDX-License-Identifier: GPL-2.0+ +# + +Specifying extra IOMMU mappings for PCI controllers + +This feature can be enabled through the PCI_IOMMU_EXTRA_MAPPINGS Kconfig option. + +The "pci_iommu_extra" env var or "pci-iommu-extra" device tree property (to be +used for example in more static scenarios such as hardwired PCI endpoints that +get initialized later in the system setup) allows two things: + - for a SRIOV capable PCI EP identified by its B.D.F specify the maximum number + of VFs that will ever be created for it + - for hot-plug case, specify the B.D.F with which the device will show up on + the PCI bus + +The env var consists of a list of , pairs for a certain pci bus +identified by its controller's base register address, as defined in the "reg" +property in the device tree. + +pci_iommu_extra = pci@,,,,, + pci@,,,,,... + +where: + is the base register address of the pci controller for which the + subsequent , pairs apply + identifies to which B.D.F the action applies to + can be: + - "vfs=" to specify that for the PCI EP identified previously by + the to include mappings for of VFs. + The variant "noari_vfs=" is available to disable taking ARI into + account. + - "hp" to specify that on this there will be a hot-plugged device so + it needs a mapping +The device tree property must be placed under the correct pci controller node +and only the bdf and action pairs need to be specified, like this: + +pci-iommu-extra = ",,,,..."; + +Note: the env var has priority over the device tree property. + +For example, given this configuration on bus 6: + +=> pci 6 +Scanning PCI devices on bus 6 +BusDevFun VendorId DeviceId Device Class Sub-Class +_____________________________________________________________ +06.00.00 0x8086 0x1572 Network controller 0x00 +06.00.01 0x8086 0x1572 Network controller 0x00 + +The following u-boot env var will create iommu mappings for 3 VFs for each PF: + +=> setenv pci_iommu_extra pci@0x3800000,6.0.0,vfs=3,6.0.1,vfs=3 + +For the device tree case, this would be specified like this: + +pci-iommu-extra = "6.0.0,vfs=3,6.0.1,vfs=3"; + +To add an iommu mapping for a hot-plugged device, please see following example: + +=> setenv pci_iommu_extra pci@0x3800000,2.16.0,hp + +For the device tree case, this would be specified like this: + +pci-iommu-extra = "2.16.0,hp"; diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index dd1cc65229..af92784950 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -179,6 +179,18 @@ config PCIE_LAYERSCAPE_RC configured to Root Complex mode by clearing the corresponding bit of RCW[HOST_AGT_PEX]. +config PCI_IOMMU_EXTRA_MAPPINGS + bool "Support for specifying extra IOMMU mappings for PCI" + depends on PCIE_LAYERSCAPE_RC + help + Enable support for specifying extra IOMMU mappings for PCI + controllers through a special env var called "pci_iommu_extra" or + through a device tree property named "pci-iommu-extra" placed in + the node describing the PCI controller. + The intent is to cover SR-IOV scenarios which need mappings for VFs + and PCI hot-plug scenarios. More documentation can be found under: + arch/arm/cpu/armv8/fsl-layerscape/doc/README.pci_iommu_extra + config PCIE_LAYERSCAPE_EP bool "Layerscape PCIe Endpoint mode support" depends on DM_PCI diff --git a/drivers/pci/pcie_layerscape_fixup.c b/drivers/pci/pcie_layerscape_fixup.c index fdbfd82740..8db7c6a4c4 100644 --- a/drivers/pci/pcie_layerscape_fixup.c +++ b/drivers/pci/pcie_layerscape_fixup.c @@ -19,6 +19,8 @@ #ifdef CONFIG_ARM #include #endif +#include +#include #include "pcie_layerscape.h" #include "pcie_layerscape_fixup_common.h" @@ -214,11 +216,292 @@ static int fdt_fixup_pcie_device_ls(void *blob, pci_dev_t bdf, return 0; } +struct extra_iommu_entry { + int action; + pci_dev_t bdf; + int num_vfs; + bool noari; +}; + +#define EXTRA_IOMMU_ENTRY_HOTPLUG 1 +#define EXTRA_IOMMU_ENTRY_VFS 2 + +static struct extra_iommu_entry *get_extra_iommu_ents(void *blob, + int nodeoffset, + phys_addr_t addr, + int *cnt) +{ + const char *s, *p, *tok; + struct extra_iommu_entry *entries; + int i = 0, b, d, f; + + /* + * Retrieve extra IOMMU configuration from env var or from device tree. + * Env var is given priority. + */ + s = env_get("pci_iommu_extra"); + if (!s) { + s = fdt_getprop(blob, nodeoffset, "pci-iommu-extra", NULL); + } else { + phys_addr_t pci_base; + char *endp; + + /* + * In env var case the config string has "pci@0x..." in + * addition. Parse this part and match it by address against + * the input pci controller's registers base address. + */ + tok = s; + p = strchrnul(s + 1, ','); + s = NULL; + do { + if (!strncmp(tok, "pci", 3)) { + pci_base = simple_strtoul(tok + 4, &endp, 0); + if (pci_base == addr) { + s = endp + 1; + break; + } + } + p = strchrnul(p + 1, ','); + tok = p + 1; + } while (*p); + } + + /* + * If no env var or device tree property found or pci register base + * address mismatches, bail out + */ + if (!s) + return NULL; + + /* + * In order to find how many action entries to allocate, count number + * of actions by interating through the pairs of bdfs and actions. + */ + *cnt = 0; + p = s; + while (*p && strncmp(p, "pci", 3)) { + if (*p == ',') + (*cnt)++; + p++; + } + if (!(*p)) + (*cnt)++; + + if (!(*cnt) || (*cnt) % 2) { + printf("ERROR: invalid or odd extra iommu token count %d\n", + *cnt); + return NULL; + } + *cnt = (*cnt) / 2; + + entries = malloc((*cnt) * sizeof(*entries)); + if (!entries) { + printf("ERROR: fail to allocate extra iommu entries\n"); + return NULL; + } + + /* + * Parse action entries one by one and store the information in the + * newly allocated actions array. + */ + p = s; + while (p) { + /* Extract BDF */ + b = simple_strtoul(p, (char **)&p, 0); p++; + d = simple_strtoul(p, (char **)&p, 0); p++; + f = simple_strtoul(p, (char **)&p, 0); p++; + entries[i].bdf = PCI_BDF(b, d, f); + + /* Parse action */ + if (!strncmp(p, "hp", 2)) { + /* Hot-plug entry */ + entries[i].action = EXTRA_IOMMU_ENTRY_HOTPLUG; + p += 2; + } else if (!strncmp(p, "vfs", 3) || + !strncmp(p, "noari_vfs", 9)) { + /* VFs or VFs with ARI disabled entry */ + entries[i].action = EXTRA_IOMMU_ENTRY_VFS; + entries[i].noari = !strncmp(p, "noari_vfs", 9); + + /* + * Parse and store total number of VFs to allocate + * IOMMU entries for. + */ + p = strchr(p, '='); + entries[i].num_vfs = simple_strtoul(p + 1, (char **)&p, + 0); + if (*p) + p++; + } else { + printf("ERROR: invalid action in extra iommu entry\n"); + free(entries); + + return NULL; + } + + if (!(*p) || !strncmp(p, "pci", 3)) + break; + + i++; + } + + return entries; +} + +static void get_vf_offset_and_stride(struct udevice *dev, int sriov_pos, + struct extra_iommu_entry *entry, + u16 *offset, u16 *stride) +{ + u16 tmp16; + u32 tmp32; + bool have_ari = false; + int pos; + struct udevice *pf_dev; + + dm_pci_read_config16(dev, sriov_pos + PCI_SRIOV_TOTAL_VF, &tmp16); + if (entry->num_vfs > tmp16) { + printf("WARN: requested no. of VFs %d exceeds total of %d\n", + entry->num_vfs, tmp16); + } + + /* + * The code below implements the VF Discovery recomandations specified + * in PCIe base spec "9.2.1.2 VF Discovery", quoted below: + * + * VF Discovery + * + * The First VF Offset and VF Stride fields in the SR-IOV extended + * capability are 16-bit Routing ID offsets. These offsets are used to + * compute the Routing IDs for the VFs with the following restrictions: + * - The value in NumVFs in a PF (Section 9.3.3.7) may affect the + * values in First VF Offset (Section 9.3.3.9) and VF Stride + * (Section 9.3.3.10) of that PF. + * - The value in ARI Capable Hierarchy (Section 9.3.3.3.5) in the + * lowest-numbered PF of the Device (for example PF0) may affect + * the values in First VF Offset and VF Stride in all PFs of the + * Device. + * - NumVFs of a PF may only be changed when VF Enable + * (Section 9.3.3.3.1) of that PF is Clear. + * - ARI Capable Hierarchy (Section 9.3.3.3.5) may only be changed + * when VF Enable is Clear in all PFs of a Device. + */ + + /* Clear VF enable for all PFs */ + device_foreach_child(pf_dev, dev->parent) { + dm_pci_read_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL, + &tmp16); + tmp16 &= ~PCI_SRIOV_CTRL_VFE; + dm_pci_write_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL, + tmp16); + } + + /* Obtain a reference to PF0 device */ + if (dm_pci_bus_find_bdf(PCI_BDF(PCI_BUS(entry->bdf), + PCI_DEV(entry->bdf), 0), &pf_dev)) { + printf("WARN: failed to get PF0\n"); + } + + if (entry->noari) + goto skip_ari; + + /* Check that connected downstream port supports ARI Forwarding */ + pos = dm_pci_find_capability(dev->parent, PCI_CAP_ID_EXP); + dm_pci_read_config32(dev->parent, pos + PCI_EXP_DEVCAP2, &tmp32); + if (!(tmp32 & PCI_EXP_DEVCAP2_ARI)) + goto skip_ari; + + /* Check that PF supports Alternate Routing ID */ + if (!dm_pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI)) + goto skip_ari; + + /* Set ARI Capable Hierarcy for PF0 */ + dm_pci_read_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL, &tmp16); + tmp16 |= PCI_SRIOV_CTRL_ARI; + dm_pci_write_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL, tmp16); + have_ari = true; + +skip_ari: + if (!have_ari) { + /* + * No ARI support or disabled so clear ARI Capable Hierarcy + * for PF0 + */ + dm_pci_read_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL, + &tmp16); + tmp16 &= ~PCI_SRIOV_CTRL_ARI; + dm_pci_write_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL, + tmp16); + } + + /* Set requested number of VFs */ + dm_pci_write_config16(dev, sriov_pos + PCI_SRIOV_NUM_VF, + entry->num_vfs); + + /* Read VF stride and offset with the configs just made */ + dm_pci_read_config16(dev, sriov_pos + PCI_SRIOV_VF_OFFSET, offset); + dm_pci_read_config16(dev, sriov_pos + PCI_SRIOV_VF_STRIDE, stride); + + if (have_ari) { + /* Reset to default ARI Capable Hierarcy bit for PF0 */ + dm_pci_read_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL, + &tmp16); + tmp16 &= ~PCI_SRIOV_CTRL_ARI; + dm_pci_write_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL, + tmp16); + } + /* Reset to default the number of VFs */ + dm_pci_write_config16(dev, sriov_pos + PCI_SRIOV_NUM_VF, 0); +} + +static int fdt_fixup_pci_vfs(void *blob, struct extra_iommu_entry *entry, + struct ls_pcie_rc *pcie_rc) +{ + struct udevice *dev, *bus; + u16 vf_offset, vf_stride; + int i, sriov_pos; + pci_dev_t bdf; + + if (dm_pci_bus_find_bdf(entry->bdf, &dev)) { + printf("ERROR: BDF %d.%d.%d not found\n", PCI_BUS(entry->bdf), + PCI_DEV(entry->bdf), PCI_FUNC(entry->bdf)); + return 0; + } + + sriov_pos = dm_pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV); + if (!sriov_pos) { + printf("WARN: trying to set VFs on non-SRIOV dev\n"); + return 0; + } + + get_vf_offset_and_stride(dev, sriov_pos, entry, &vf_offset, &vf_stride); + + for (bus = dev; device_is_on_pci_bus(bus);) + bus = bus->parent; + + bdf = entry->bdf - PCI_BDF(bus->seq, 0, 0) + (vf_offset << 8); + + for (i = 0; i < entry->num_vfs; i++) { + if (fdt_fixup_pcie_device_ls(blob, bdf, pcie_rc) < 0) + return -1; + bdf += vf_stride << 8; + } + + printf("Added %d iommu VF mappings for PF %d.%d.%d\n", + entry->num_vfs, PCI_BUS(entry->bdf), + PCI_DEV(entry->bdf), PCI_FUNC(entry->bdf)); + + return 0; +} + static void fdt_fixup_pcie_ls(void *blob) { struct udevice *dev, *bus; struct ls_pcie_rc *pcie_rc; pci_dev_t bdf; + struct extra_iommu_entry *entries; + int i, cnt, nodeoffset; + /* Scan all known buses */ for (pci_find_first_device(&dev); @@ -234,6 +517,51 @@ static void fdt_fixup_pcie_ls(void *blob) if (fdt_fixup_pcie_device_ls(blob, bdf, pcie_rc) < 0) break; } + + if (!IS_ENABLED(CONFIG_PCI_IOMMU_EXTRA_MAPPINGS)) + goto skip; + + list_for_each_entry(pcie_rc, &ls_pcie_list, list) { + nodeoffset = fdt_pcie_get_nodeoffset(blob, pcie_rc); + if (nodeoffset < 0) { + printf("ERROR: couldn't find pci node\n"); + continue; + } + + entries = get_extra_iommu_ents(blob, nodeoffset, + pcie_rc->dbi_res.start, &cnt); + if (!entries) + continue; + + for (i = 0; i < cnt; i++) { + if (entries[i].action == EXTRA_IOMMU_ENTRY_HOTPLUG) { + bdf = entries[i].bdf; + printf("Added iommu map for hotplug %d.%d.%d\n", + PCI_BUS(bdf), PCI_DEV(bdf), + PCI_FUNC(bdf)); + if (fdt_fixup_pcie_device_ls(blob, bdf, + pcie_rc) < 0) { + free(entries); + return; + } + } else if (entries[i].action == EXTRA_IOMMU_ENTRY_VFS) { + if (fdt_fixup_pci_vfs(blob, &entries[i], + pcie_rc) < 0) { + free(entries); + return; + } + } else { + printf("Invalid action %d for BDF %d.%d.%d\n", + entries[i].action, + PCI_BUS(entries[i].bdf), + PCI_DEV(entries[i].bdf), + PCI_FUNC(entries[i].bdf)); + } + } + free(entries); + } + +skip: pcie_board_fix_fdt(blob); } #endif