From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.1244.1591640562976755607 for ; Mon, 08 Jun 2020 11:22:44 -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=PIACm25C; spf=fail (domain: oss.nxp.com, ip: , mailfrom: wasim.khan@oss.nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c/rFTADCWu79W294MB2AOecUUUCZZnY3Ok75XXDirLgMzGe4PtarCDPyHmQq0m9eM/mE6iHIdUXWn/gqBw5PoA6hssIEzeomztwqpj5BIon6zXVYPbB/adojysxTVDikksBlHcKJyb+e6btqtyQDB3exZQKmLLoioIc8y7HXtcPIbEvtoXeGUlCuI69PjE8pmBXjcsE2j1O4fsREZzcasCqTDYrv0AEECnOnHjlnEwVEF7SoPEVqHLygGTMBa83+3IYkygmtaDKsKLghk47wRHHg31rRozgxbfOEYCflgpAZwdpayWeuXYSArys0olE7rMwmmuEbGD8fgAHHWXPPXg== 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=BqmmNKd/stB5XIDcv3zNbRIoBgw3b6T9XdeGuNphMPQ=; b=m22EdzVc+XvT9ZnBxg+ejDPDCigybbIGOZb5bsmi280395a/MjmdIOauGabNfkAIrcqWE9+TjT4Lsezkd/6rYXGQqGy3v+Q4YWFK4h3StMeab3q8wOcpbjz3VwYgQLkxSHtw/TcxhNVNHds8mvZQaav/ml1UZMcFLM+PkkqkgUr1q0rf5/M0JJxWi/lGHpCnw/ygzdAU5/4DNE7rxCx+SjYbaXWEcJvebJhwJV1yY9jD6uMd3emUMu8dBmi1At29u8axStq/Ezsov0cx0w6FGXMgJd5wCSbe0J7mA1LzCvEM8RG8/b/NQ1A4CqzkrlZA6mWUYL/1O4aoed6HG/VAEQ== 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=BqmmNKd/stB5XIDcv3zNbRIoBgw3b6T9XdeGuNphMPQ=; b=PIACm25CxMd4Ok6jFv35pDF8FnKjteXqjoUBo2W1nwsPSES146poumHvmMUZTlxHNL8NVd82v6gYigwar7cNkeP+sonhOcNUA/RU+z8rHWcZyR3sQ0Q1BQiSHtygyIckspGqrfJWZzWwS9SmMdArlhd3CTmt8X+wCeygxekp2z4= 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 VE1PR04MB6525.eurprd04.prod.outlook.com (2603:10a6:803:120::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20; Mon, 8 Jun 2020 18:22:43 +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.3066.023; Mon, 8 Jun 2020 18:22:43 +0000 From: Wasim Khan To: devel@edk2.groups.io, meenakshi.aggarwal@nxp.com, V.Sethi@nxp.com, ard.biesheuvel@arm.com, leif@nuviainc.com CC: Wasim Khan Subject: [PATCH edk2-platforms v4 1/3] Silicon/NXP/Library: Implement SerDesHelperLib Date: Mon, 8 Jun 2020 23:52:16 +0530 Message-ID: <1591640538-24751-2-git-send-email-wasim.khan@oss.nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1591640538-24751-1-git-send-email-wasim.khan@oss.nxp.com> References: <1591640538-24751-1-git-send-email-wasim.khan@oss.nxp.com> X-ClientProxiedBy: PN1PR0101CA0065.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:d::27) 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 (157.37.163.9) by PN1PR0101CA0065.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:d::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3066.18 via Frontend Transport; Mon, 8 Jun 2020 18:22:40 +0000 X-Mailer: git-send-email 2.7.4 X-Originating-IP: [157.37.163.9] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: acbaa998-fab0-4600-0b8c-08d80bd8ef29 X-MS-TrafficTypeDiagnostic: VE1PR04MB6525: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 042857DBB5 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DBXO63EXEfN3qqSSwpxvJbAqk59R2xRH4IjuLMTbQ66SympHbX9wU1PlNMfsXz9gZUgA3S2LNrMXGUXBDQclnX3O/zwdQJJaibmfyZA6y8LB03+tUNaElyqMt9NtrKksCF9Pkp4CPqk2Kcsezv/6+7A78QS4M3UMMJV36c4ciYWEH02THB0VhI+KoxjzsqtA+rjvb/rOYzkDyehybUB0mEGLBGFa3JMlANwSKKt3sE8zpMPk5YFLp8CuBc5tbtB6hfip+zybMUWRkiKcYsiP9R3GEgRrabrCeCBwg8RR5FHtc+Dp7Gz4nXcVaoBJPIKnW8WqKg0iZoUAoChWBggxUA== 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:(4636009)(346002)(39860400002)(376002)(366004)(136003)(396003)(186003)(26005)(16526019)(8936002)(8676002)(4326008)(83380400001)(86362001)(478600001)(66946007)(6666004)(5660300002)(66556008)(956004)(316002)(6486002)(6512007)(52116002)(66476007)(6506007)(2616005)(44832011)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 6ND9ygvv/oV+26sUFdXh70e8S2pKP5OzKKsuH8siVm7TywpBLlASl3YSVGg5kSerUjCxdEU1J+W69pYE30hM9HSQG/Phtqi9m5ErYxTcUn24XOOHOR7JkCvSn+/m8LY5sv/+FB7YIAoiTHWH6+CepOgSfdNoe5JLNMcLWxvrUhOLWGTkTzR6Taar+65tY1TY9vY07Pmf0ybjEPUfdZwMBWxDHPuFluNcd7RdIy6jWSmO27EuYGM4d6W9hH8s/PPFkK/JktD5ZpyghygKEA3dFXGrZW3PBxPBzTtreEjMui9je00DY/8Kh/VQJ/pR5Hg/m+f/lb/vueJigvbGSWUORYE2r66pZTjQNYUp8yiWuKDUC72jTsSD7aYFyLiBTxG0PPGyNo0YdDxTZoVO3TRIVPj1YoGZABPUa54/AXk5h/CJHDxEohH2+EZtnSS6Lxk00A1bcaFkyHx+x/vMIR3Rg3LINvTdlJdg9CTuM/+8u7c= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: acbaa998-fab0-4600-0b8c-08d80bd8ef29 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2020 18:22:43.1897 (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: 5CNaTmprrwevNeCrMGguOVaLvNwtUyCDEy7GOT91ZzkOGrNd8Gn+hRP95DqMBryKN6XLBCqcpU+yujopkiZtGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6525 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Wasim Khan Implement SerDesHelperLib to provide helper functions which can be used for SoC specific SerDes configuration. Signed-off-by: Wasim Khan --- Notes: Changes in V4: - No Change =20 Changes in V3: - Change variable name LanePrtc to LaneProtocol =20 Changes in V2: - Addressed review comments for structure, variable and function names - Using BIT0 instead of 0x1u Silicon/NXP/NxpQoriqLs.dec | 1 + Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.inf | 28 ++++ Silicon/NXP/Include/Library/SerDesHelperLib.h | 64 ++++++++ Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c | 164 ++++++++++++= ++++++++ 4 files changed, 257 insertions(+) diff --git a/Silicon/NXP/NxpQoriqLs.dec b/Silicon/NXP/NxpQoriqLs.dec index d4d3057af509..d09a1ae194be 100644 --- a/Silicon/NXP/NxpQoriqLs.dec +++ b/Silicon/NXP/NxpQoriqLs.dec @@ -35,6 +35,7 @@ [PcdsFixedAtBuild.common] gNxpQoriqLsTokenSpaceGuid.PcdNumPciController|0|UINT32|0x00000501 gNxpQoriqLsTokenSpaceGuid.PcdPcieLutBase|0x0|UINT32|0x00000502 gNxpQoriqLsTokenSpaceGuid.PcdPcieLutDbg|0x0|UINT32|0x00000503 + gNxpQoriqLsTokenSpaceGuid.PcdSerDesLanes|0x0|UINT8|0x00000504 =20 [PcdsDynamic.common] gNxpQoriqLsTokenSpaceGuid.PcdPciCfgShiftEnable|FALSE|BOOLEAN|0x00000600 diff --git a/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.inf b/Sili= con/NXP/Library/SerDesHelperLib/SerDesHelperLib.inf new file mode 100644 index 000000000000..7a781620e449 --- /dev/null +++ b/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.inf @@ -0,0 +1,28 @@ +## @file +# +# Copyright 2020 NXP +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D SerDesHelperLib + FILE_GUID =3D 2930e932-a700-41e8-80f9-f1a2dedd2c4f + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SerDesHelperLib + +[Packages] + MdePkg/MdePkg.dec + Silicon/NXP/NxpQoriqLs.dec + +[LibraryClasses] + DebugLib + PcdLib + +[Sources.common] + SerDesHelperLib.c + +[FixedPcd] + gNxpQoriqLsTokenSpaceGuid.PcdSerDesLanes diff --git a/Silicon/NXP/Include/Library/SerDesHelperLib.h b/Silicon/NXP/In= clude/Library/SerDesHelperLib.h new file mode 100644 index 000000000000..377f020e0b3a --- /dev/null +++ b/Silicon/NXP/Include/Library/SerDesHelperLib.h @@ -0,0 +1,64 @@ +/** SerDesHelperLib.h + The Header file for SerDesHelperLib + + Copyright 2020 NXP + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef SERDES_HELPER_LIB_H +#define SERDES_HELPER_LIB_H + +#include +#include + +typedef struct { + UINT16 Protocol; + UINT8 SerDesLane[FixedPcdGet8 (PcdSerDesLanes)]; +} SERDES_CONFIG; + +typedef enum { + SERDES_1 =3D 0, + SERDES_2, + SERDES_3, + SERDES_MAX +} SERDES_NUMBER; + +UINT32 +GetSerDesProtocol ( + IN INTN SerDes, + IN INTN SerDesProtocol, + IN INTN Lane, + IN UINT32 SerDesMaxProtocol, + IN SERDES_CONFIG *Config + ); + +EFI_STATUS +IsSerDesProtocolValid ( + IN INTN SerDes, + IN UINT32 SerDesProtocol, + IN UINT8 SerDesNumLanes, + IN SERDES_CONFIG *Config + ); + +EFI_STATUS +GetSerDesMap ( + IN UINT32 SerDes, + IN UINT32 SerDesProtocol, + IN UINT8 SerDesNumLanes, + IN UINT32 SerDesMaxProtocol, + IN SERDES_CONFIG *Config, + OUT UINT64 *SerDesProtocolMap + ); + +VOID +SerDesInstanceProbeLanes ( + IN UINT32 SerDes, + IN UINT32 SerDesProtocol, + IN UINT8 SerDesNumLanes, + IN UINT32 SerDesMaxProtocol, + IN SERDES_CONFIG *Config, + IN SERDES_PROBE_LANES_CALLBACK SerDesLaneProbeCallback, + IN VOID *Arg + ); +#endif diff --git a/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c b/Silico= n/NXP/Library/SerDesHelperLib/SerDesHelperLib.c new file mode 100644 index 000000000000..ddefcc2fac98 --- /dev/null +++ b/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c @@ -0,0 +1,164 @@ +/** SerDes.c + Provides SoC specific SerDes interface + + Copyright 2020 NXP + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include + +/** + Function to get SerDes Lane protocol corresponding to + SerDes protocol. + + @param SerDes SerDes number. + @param SerDesProtocol SerDes protocol number. + @param Lane SerDes Lane number. + @param SerDesMaxProtocol Max SerDes protocol number. + @param Config SerDes Configuration. + + @return SerDes Lane protocol. + +**/ +UINT32 +GetSerDesProtocol ( + IN INTN SerDes, + IN INTN SerDesProtocol, + IN INTN Lane, + IN UINT32 SerDesMaxProtocol, + IN SERDES_CONFIG *Config + ) +{ + while (Config->Protocol) { + if (Config->Protocol =3D=3D SerDesProtocol) { + return Config->SerDesLane[Lane]; + } + Config++; + } + + return SerDesMaxProtocol; +} + +/** + Function to validate input SerDes protocol. + + @param SerDes SerDes number. + @param SerDesProtocol SerDes protocol number. + @param SerDesNumLanes Number of SerDes Lanes. + @param Config SerDes Configuration. + + @return EFI_NOT_FOUND SerDes Protocol not a valid protocol. + @return EFI_SUCCESS SerDes Protocol is a valid protocol. + +**/ +EFI_STATUS +IsSerDesProtocolValid ( + IN INTN SerDes, + IN UINT32 SerDesProtocol, + IN UINT8 SerDesNumLanes, + IN SERDES_CONFIG *Config + ) +{ + UINT8 Count; + + while (Config->Protocol) { + if (Config->Protocol =3D=3D SerDesProtocol) { + DEBUG ((DEBUG_INFO, "Protocol: %x Matched with the one in Table\n", = SerDesProtocol)); + break; + } + Config++; + } + + if (!Config->Protocol) { + return EFI_NOT_FOUND; + } + + for (Count =3D 0; Count < SerDesNumLanes; Count++) { + if (Config->SerDesLane[Count] !=3D 0) { + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +/** + Get Lane protocol on provided SerDes Lane and execute callback function. + + @param SerDes SerDes number. + @param SerDesProtocol SerDes protocol number. + @param SerDesNumLanes Number of SerDes Lanes. + @param SerDesMaxProtocol Max SerDes protocol number. + @param Config SerDes Configuration. + @param SerDesLaneProbeCallback Pointer Callback function to be called f= or Lane protocol + @param Arg Pointer to Arguments to be passed to cal= lback function. +**/ +VOID +SerDesInstanceProbeLanes ( + IN UINT32 SerDes, + IN UINT32 SerDesProtocol, + IN UINT8 SerDesNumLanes, + IN UINT32 SerDesMaxProtocol, + IN SERDES_CONFIG *Config, + IN SERDES_PROBE_LANES_CALLBACK SerDesLaneProbeCallback, + IN VOID *Arg + ) +{ + INT8 Lane; + UINT32 LaneProtocol; + + // Invoke callback for all lanes in the SerDes instance: + for (Lane =3D 0; Lane < SerDesNumLanes; Lane++) { + LaneProtocol =3D GetSerDesProtocol (SerDes, SerDesProtocol, Lane, SerD= esMaxProtocol, Config); + ASSERT (LaneProtocol < SerDesMaxProtocol); + if (LaneProtocol !=3D 0x0) { + SerDesLaneProbeCallback (LaneProtocol, Arg); + } + } +} + +/** + Function to fill SerDes map information. + + @param SerDes SerDes number. + @param SerDesProtocol SerDes protocol number. + @param SerDesNumLanes Number of SerDes Lanes. + @param SerDesMaxProtocol Max SerDes protocol number. + @param Config SerDes Configuration. + @param SerDesProtocolMap Output SerDes protocol map of enabled device= s. + +**/ +EFI_STATUS +GetSerDesMap ( + IN UINT32 SerDes, + IN UINT32 SerDesProtocol, + IN UINT8 SerDesNumLanes, + IN UINT32 SerDesMaxProtocol, + IN SERDES_CONFIG *Config, + OUT UINT64 *SerDesProtocolMap + ) +{ + INTN Lane; + EFI_STATUS Status; + UINT32 LaneProtocol; + + Status =3D IsSerDesProtocolValid (SerDes, SerDesProtocol, SerDesNumLanes= , Config); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: SERDES%d[PRTCL] =3D 0x%x is not valid, Statu= s =3D %r \n", + __FUNCTION__, SerDes + 1, SerDesProtocol, Status)); + return Status; + } + + for (Lane =3D 0; Lane < SerDesNumLanes; Lane++) { + LaneProtocol =3D GetSerDesProtocol (SerDes, SerDesProtocol, Lane, SerD= esMaxProtocol, Config); + if (LaneProtocol >=3D SerDesMaxProtocol) { + DEBUG ((DEBUG_ERROR, "Unknown SerDes lane protocol %d\n", LaneProtoc= ol)); + return EFI_NO_MAPPING; + } + *SerDesProtocolMap |=3D (BIT0 << (LaneProtocol)); + } + + return EFI_SUCCESS; +} --=20 2.7.4