From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (EUR05-AM6-obe.outbound.protection.outlook.com [40.107.22.75]) by mx.groups.io with SMTP id smtpd.web11.46901.1590482340152576770 for ; Tue, 26 May 2020 01:39:00 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nxp1.onmicrosoft.com header.s=selector2-nxp1-onmicrosoft-com header.b=H1iJxApu; spf=pass (domain: oss.nxp.com, ip: 40.107.22.75, mailfrom: wasim.khan@oss.nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VfemPEyIv0cPuB027iElpwFWK7HwxHM4+ccAC9M/i7DE3+2TCO3sBfUJoumMAbfJC4P9LuPtlxMecBYxUJsSp3+vligMe/dGxtkvxlP1MkyO+vt/5gBFYUFnfvs2h1hBCi2QuAEAmf2HbcQkq58/TFv93H7erMd4jXikjaOgYuw49nv4YASrHFejVN1iBc/8B5U3wG2qAH3/dP2w3B3YCsFw+tpETzYHNjrMwTwodml8yLjpo+kQtoCu3TxFwt4803DPjvDA4VAkNOY625KBwd73qPjU8g4yOjPBVT/VudVVCeSisvsvUTgZoyhfMCnTf5DIi05YtQDrOrJO2Oj8ww== 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=YeQvg6iRXtmLRHX/acIwCqdoTTpuP2FoAo/SpvzVAHg=; b=EpznSlPVs+XYKDoBkp7bCy+i/b/5b8LLMGdjweSzqpynZpKoitgOvsY1zj5CcmVKh9X66oZF2FljeOXj1vCdqoLrR2R8ISfTdAXzLfBlNk4FgDnlCCd65p9dCMfoHa4q6/SP5nJt6EN9yMPKlaB0WvqA3Cyu0H3I2KEt5feuYk8h9lkVLheB1u0NR5BTsrOuDAZ1dW8opRcX+UY+FqJb56LFkqaQGq71Rh23cJiOP3860fHQ0/qZZBy/0KYoR7MCYl/ESV97qtPKo7MXxzHNAF6aYgpeGy/TnbUh8h48iZKyrQqVwyzGn94mN3wNCiPT3soAMmbMl4MUNX/E30Hzwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YeQvg6iRXtmLRHX/acIwCqdoTTpuP2FoAo/SpvzVAHg=; b=H1iJxApu7VyyYbsywx05jt03ixChZV3E89Dw8iRxTQuTiCRQGGqveuM5QnGwp7ffiOcNFCt31RUMM+6p4TsaaZQp3C+07h0rwJXqnkAc1sIRSmxZS2cUOvEgxpsWfS6W30bB0Ss3GAn3ltkFHaelXqLXtiiwkoMAIx//fVBoNIk= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=oss.nxp.com; Received: from VE1PR04MB6702.eurprd04.prod.outlook.com (2603:10a6:803:123::13) by VE1PR04MB6367.eurprd04.prod.outlook.com (2603:10a6:803:11a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.27; Tue, 26 May 2020 08:38:58 +0000 Received: from VE1PR04MB6702.eurprd04.prod.outlook.com ([fe80::81c4:97a6:7592:f225]) by VE1PR04MB6702.eurprd04.prod.outlook.com ([fe80::81c4:97a6:7592:f225%7]) with mapi id 15.20.3021.029; Tue, 26 May 2020 08:38:58 +0000 From: Wasim Khan To: devel@edk2.groups.io, meenakshi.aggarwal@nxp.com, vabhav.sharma@nxp.com, V.Sethi@nxp.com, ard.biesheuvel@arm.com, leif@nuviainc.com, jon@solid-run.com CC: Wasim Khan Subject: [PATCH edk2-platforms v2 11/16] Silicon/NXP: PciSegmentLib: Add support PCIe LsGen4 Controller Date: Tue, 26 May 2020 14:07:16 +0530 Message-ID: <1590482241-13132-12-git-send-email-wasim.khan@oss.nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1590482241-13132-1-git-send-email-wasim.khan@oss.nxp.com> References: <1590482241-13132-1-git-send-email-wasim.khan@oss.nxp.com> X-ClientProxiedBy: BM1PR0101CA0015.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:18::25) To VE1PR04MB6702.eurprd04.prod.outlook.com (2603:10a6:803:123::13) Return-Path: wasim.khan@oss.nxp.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wasimk-VirtualBox.nxp.com (171.79.147.152) by BM1PR0101CA0015.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:18::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3021.23 via Frontend Transport; Tue, 26 May 2020 08:38:52 +0000 X-Mailer: git-send-email 2.7.4 X-Originating-IP: [171.79.147.152] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 28b8c129-2c7a-40cb-4c1e-08d801503a21 X-MS-TrafficTypeDiagnostic: VE1PR04MB6367: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:407; X-Forefront-PRVS: 041517DFAB X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wxhnKSMN5Fj22o204k031Szrt8zbxmGClIg/TiCekswYK1dnJUnPJujcx0LTNy+YyqlpxY/0LL0BdgPmcFyVjRJvnlSCcwkq07dfncStftp1W1GJNoH4ksmGdjlwnE/FSKxgAm3DqxrlkbgS8xgCvTLyWzbTlKTo9M7/p8gCTzZD9z6RFkB9aKNEg0NaX4m0xw83I6zGTCjjFJH0OGevMun7SP7maAw/tYjrKOYoZpDuf/cv0tBJsLsZTgQpFhmXJ82+8/fEfAIG61dvVAne979D6ZQmdqqjBNl3YkBPstm+1WJ0MW5u0RD078Zl3obNPSgJEeP2cA8af9yLIuhHaA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6702.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(6029001)(4636009)(376002)(396003)(346002)(39860400002)(366004)(136003)(478600001)(6666004)(66946007)(86362001)(956004)(66476007)(44832011)(5660300002)(19627235002)(66556008)(316002)(2616005)(8936002)(2906002)(8676002)(6506007)(4326008)(16526019)(6486002)(52116002)(26005)(186003)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ocuwINbr0YGpBMxBLm5sGbqqudWFn+KR4uqNGfJfldTZ8Kfx/AWIc/rEgwZS52BYgtTQPUJnp6zafMaK1laZqyTYb9vLOqxI1tAYE5jYjxljOktZfhlgpJIRATd3vEFLNGSMo0L2EC0/ufjGmuuYcK8o/TpfQ4tqTX3iNViPB2UGCr0idt2X4hZWHgE0b+zoCdWQBsqRzHJJbdd9IVvxIBBKYXC6Sy5dhiIbgHPlpDVoMo/fIhcz2/saGZXxDofsrlQkro/eAgUjiggy7eZrcAoJsQlKKoaV3qxWbVxrUJXAroi5V7PaVIGEWrgwCO2SmbVqFMr3hM9LXR5jgw9EvyYuqQnw2cFGsBM9h1c4nU0VGDNZXElFKJiMYIpSDr9eg17WtvUpgORkI9Moo+M5zRUB70xl0LzK91b3Lhqa1uhYSQtvqs3u227k0R/qTZv6V1DHCdETSB9hoYGFmpVCYDPf+4pieIQ5NJrZYQn8UHA= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28b8c129-2c7a-40cb-4c1e-08d801503a21 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2020 08:38:57.8635 (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: 87AhZNKhBdAXtfY/foMSNWdxGEl34VWmFjuL9Wzl5nOaNDKSR7jJEkKUZ2sMwZiYZ/bL0lTBQGcI1SHEH8MtlA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6367 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Wasim Khan PCIe Layerscape Gen4 controller is not ECAM compliant and have different PCI config space region for bus 0 (Controller space) and bus[0x1-0xff] on NXP SoCs. For config transactions for Bus0: - Config transaction address =3D PCIe controller address + offset For config transactions for Bus[0x1-0xff]: - PCIe IP requires target BDF to be written at bit[31:16] of PCIe outbound configuration window. PCIe LsGen4 controller uses paging mechanism to access registers. To access PCIe CCSR registers which are above 3KB offset, page number must be set in Bridge Control Register. Co-authored-by: Vabhav Sharma Co-authored-by: Wasim Khan Signed-off-by: Wasim Khan --- Notes: V2: - fix typo in commit message - Removed Signed-off and added Co-authored-by for co-author - Addressed review comments to: - Drop outer () while calulating Target - Use (Bus > 0) instead of (Bus) Silicon/NXP/Library/PciSegmentLib/PciSegmentLib.inf | 1 + Silicon/NXP/Library/PciSegmentLib/PciSegmentLib.c | 60 +++++++++++++++++= ++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Silicon/NXP/Library/PciSegmentLib/PciSegmentLib.inf b/Silicon/= NXP/Library/PciSegmentLib/PciSegmentLib.inf index 936213dc8a9d..d6d7ea6e3b6b 100755 --- a/Silicon/NXP/Library/PciSegmentLib/PciSegmentLib.inf +++ b/Silicon/NXP/Library/PciSegmentLib/PciSegmentLib.inf @@ -33,3 +33,4 @@ [FixedPcd] =20 [Pcd] gNxpQoriqLsTokenSpaceGuid.PcdPciCfgShiftEnable + gNxpQoriqLsTokenSpaceGuid.PcdPciLsGen4Ctrl diff --git a/Silicon/NXP/Library/PciSegmentLib/PciSegmentLib.c b/Silicon/NX= P/Library/PciSegmentLib/PciSegmentLib.c index e5251ecf0dd8..09ce620ef988 100755 --- a/Silicon/NXP/Library/PciSegmentLib/PciSegmentLib.c +++ b/Silicon/NXP/Library/PciSegmentLib/PciSegmentLib.c @@ -35,6 +35,58 @@ typedef enum { ASSERT (((A) & (0xffff0000f0000000ULL | (M))) =3D=3D 0) =20 static BOOLEAN CfgShiftEnable; +static BOOLEAN PciLsGen4Ctrl; + +STATIC +VOID +PcieCfgSetTarget ( + IN EFI_PHYSICAL_ADDRESS Dbi, + IN UINT32 Target) +{ + PciLsGen4Write32 ((UINTN)Dbi, PAB_AXI_AMAP_PEX_WIN_L(0), Target); + PciLsGen4Write32 ((UINTN)Dbi, PAB_AXI_AMAP_PEX_WIN_H(0), 0); +} + +/** + Function to return PCIe Physical Address(PCIe view) or Controller + Address(CPU view) for NXP Layerscape Gen4 SoC + + @param Address Address passed from bus layer. + @param Segment Segment number for Root Complex. + @param Offset Config space register offset. + @param Bus PCIe Bus number. + + @return Return PCIe CPU or Controller address. + +**/ +STATIC +UINT64 +PciLsGen4GetConfigBase ( + IN UINT64 Address, + IN UINT16 Segment, + IN UINT16 Offset, + IN UINT8 Bus + ) +{ + UINT32 Target; + + if (Bus > 0) { + Target =3D (((Address >> 20) & 0xFF) << 24) | + (((Address >> 15) & 0x1F) << 19) | + (((Address >> 12) & 0x7) << 16); + + PcieCfgSetTarget ((PCI_SEG0_DBI_BASE + PCI_DBI_SIZE_DIFF* Segment), Ta= rget); + return PCI_SEG0_MMIO_MEMBASE + Offset + PCI_BASE_DIFF * Segment; + } else { + if (Offset < INDIRECT_ADDR_BNDRY) { + PciLsGen4SetPg (PCI_SEG0_DBI_BASE + PCI_DBI_SIZE_DIFF * Segment, 0= ); + return (PCI_SEG0_DBI_BASE + PCI_DBI_SIZE_DIFF * Segment + Offset); + } + PciLsGen4SetPg (PCI_SEG0_DBI_BASE + PCI_DBI_SIZE_DIFF * Segment, OFF= SET_TO_PAGE_IDX (Offset)); + Offset =3D OFFSET_TO_PAGE_ADDR (Offset); + return (PCI_SEG0_DBI_BASE + PCI_DBI_SIZE_DIFF * Segment + Offset); + } +} =20 STATIC UINT64 @@ -129,7 +181,12 @@ PciSegmentLibGetConfigBase ( UINT8 Bus; =20 Bus =3D ((UINT32)Address >> 20) & 0xff; - return PciLsGetConfigBase (Address, Segment, Offset, Bus); + + if (PciLsGen4Ctrl) { + return PciLsGen4GetConfigBase (Address, Segment, Offset, Bus); + } else { + return PciLsGetConfigBase (Address, Segment, Offset, Bus); + } } =20 /** @@ -620,5 +677,6 @@ PciSegLibInit ( ) { CfgShiftEnable =3D CFG_SHIFT_ENABLE; + PciLsGen4Ctrl =3D PCI_LS_GEN4_CTRL; return EFI_SUCCESS; } --=20 2.7.4