From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR03-VE1-obe.outbound.protection.outlook.com (EUR03-VE1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.7254.1591535768843178203 for ; Sun, 07 Jun 2020 06:16:10 -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=AYqTteQv; 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=cLDRrO+eqhiKZTw5GxpjNlXohk08NbedA0FxKHfzAef2qxlr2/EVGf2e1ceHUhcHxrSXAFdXoFu5vZFA1LW43+TAikw58MzCIAvn2K/Vs2P3qTUQiRRy1K5n67zJ5hoR1QAA7HuGbd0VsywTUmfwt0miUeQJtpP0FEP4gdmm3o9/GsIsslQMiIGVSm/Mt0KJLlbPnjuO2wzpd0BKSTDY9gbGGsp9nGQ5MgKLizGLtLm27PAXI6OnTYZLMhs1fV0o0EHLMZPlMpYpgqNeSm6AZvadTKtG6a1paRPKHZE3CmzRddpRFDSC37j0DHjlsqxQFBfeAxxHuls/CnqBk6thkw== 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=rZ0MxJyL9d1edJXFVzhzpeCm2rjgwAbNaHD1JxfP1ak=; b=BLr5s/y5Z4/CEmabySqiBefdpqlSgg3Pu0InCZD7139WVN7rLa62e09BkYqGUx0+yzVfXEqy4tyRWSLc22vaAFmepiO1ih1e9g19h4i9mYxaTQPj/icwi0y46mo85yn4aW7it+0jSFO8EXgCDtVn93XqcHKS2FIvlniVNFPbHwjnV012R8Q9WRdRVg0nA0uc1rS3rA+Laql/quz2/wEvNMp8LisimFT2MTUh+4geRm/dlGzhQwqwzeaKvjrYplbg8n8ui34Q3H+Zom2XdaBGvlu3DynRk2PrkQp3LCH2FOWD+zP97DyzDlJL9/jiQfB0RxLxNc7DAMEcJdrxHphKjA== 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=rZ0MxJyL9d1edJXFVzhzpeCm2rjgwAbNaHD1JxfP1ak=; b=AYqTteQv4FIKMb0JE/4ItCYSy20dExxaaBwxN/HajHgG4vLBzvITFCwM88zlzz23CplZZ0CvJ5133FtWG5xhbkXm5zemTqYs/4s4uu6l54EZ8p1e45ECW7y5Qr22Ywluxo0dRwrLAEQBUVggyegSJEJWBlzTSc5J6MudO6SHVSU= 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 VE1PR04MB6493.eurprd04.prod.outlook.com (2603:10a6:803:11f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20; Sun, 7 Jun 2020 13:16:07 +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; Sun, 7 Jun 2020 13:16:07 +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 v2 1/3] Silicon/NXP/Library: Implement SerDesHelperLib Date: Sun, 7 Jun 2020 18:45:48 +0530 Message-ID: <1591535750-15743-2-git-send-email-wasim.khan@oss.nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1591535750-15743-1-git-send-email-wasim.khan@oss.nxp.com> References: <1591535750-15743-1-git-send-email-wasim.khan@oss.nxp.com> X-ClientProxiedBy: BM1PR01CA0153.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:68::23) 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.47.233.236) by BM1PR01CA0153.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:68::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3066.18 via Frontend Transport; Sun, 7 Jun 2020 13:16:05 +0000 X-Mailer: git-send-email 2.7.4 X-Originating-IP: [157.47.233.236] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 36afa131-50fa-4e29-cd66-08d80ae4f018 X-MS-TrafficTypeDiagnostic: VE1PR04MB6493: 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: 04270EF89C X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SZ7rdS/N28mMbbcK/iGhsBvwrWt1WA5Qtq0KJDx+1CJUQ3yg4UcWfcS+zXvEb/ZJHoLGJOoO9Ts4FWh1HrlIxZW9HphV1YXWlhuiPd7gLP1biJOmgdb9E2pDeHmSix1TfV77wFVUWan/a7db+BKzsK3tf9qYkF8/P7Wv2fPy+ZGdHPSE2X0w7y0UTN2XomWQMqtbsyEqdCM3R3ukXk8tHigxTfg28y0gDOD7f1ILQ3Pk8EWVyJqd5q6TQeICEIoX/PD+kPsr+oZKwmdTLhyche75qiYcfg7M0x7PF8rFfOdHK8ehGtAfiNprUEoQwvALrTSXCjxEkQOYW8zR5FdG3w== 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)(366004)(136003)(396003)(376002)(186003)(26005)(16526019)(86362001)(478600001)(83380400001)(4326008)(8936002)(8676002)(5660300002)(44832011)(6486002)(66946007)(6666004)(66556008)(6512007)(316002)(6506007)(2906002)(52116002)(2616005)(956004)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 1Ff9sLas3FrykQZ/1S4EEzrwqv/0MUnZOFGmGIsVSsX3v42I84iJaaaIGM8cEmX/rYRoJKwSOhAP7W+l3FuWlA9XxIdtQTgbRv9SxWW0AiRCej1kXrxawwC6/7BrIDvbemdDIGppGBe6+pWbSNmluwLjxlsjaQmMUJYPRK7g9vnIYQs3S7Gm+oFekaSnUPVcBrLL5LqdkZZUMAbCwmDAf5Qm4z+Xzoya3yQbnN7Es51yJC9AkqbW+cHvjyVGuXgF2f72+YnLczlm8tTUWgW/KRg7VaEZ2TAnjXFkKzhJT4mJyqminjD2szNxZPcwWpT2yVe1jMmZ3Uo0ydfTQ7NaQkaAW8lf7NxJlTOWgi6D/NLeqbxF/oCIQ0O6MNJbq1ii05hK/XnGsJ6vXEcemogGbNsD02oyr7wIhVSWnH7bKXlYwb6T2QGmQp+yOsQ/SwUMeeLvW3p4BBxIutunO6Qi7QQTiBRJuZS4b4UCtPmwnGN9aXk8T2eZyygh3hXyWgLv X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36afa131-50fa-4e29-cd66-08d80ae4f018 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2020 13:16:07.2522 (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: FdEaMbVChTOHkNdiTfeRK9VXvm/Hs6iZH6MLu8oWxpYFKSYovIOn5vo3A0t6OXQY9sDj1+I/EaB7rrquB0iyFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6493 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 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..52c27a0fd49d --- /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 LanePrtcl; + + 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++) { + LanePrtcl =3D GetSerDesProtocol (SerDes, SerDesProtocol, Lane, SerDesM= axProtocol, Config); + if (LanePrtcl >=3D SerDesMaxProtocol) { + DEBUG ((DEBUG_ERROR, "Unknown SerDes lane protocol %d\n", LanePrtcl)= ); + return EFI_NO_MAPPING; + } + *SerDesProtocolMap |=3D (BIT0 << (LanePrtcl)); + } + + return EFI_SUCCESS; +} --=20 2.7.4