From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (EUR01-HE1-obe.outbound.protection.outlook.com [40.107.13.52]) by mx.groups.io with SMTP id smtpd.web12.45543.1591039685813629470 for ; Mon, 01 Jun 2020 12:28:06 -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=fygrHxAL; spf=pass (domain: oss.nxp.com, ip: 40.107.13.52, mailfrom: wasim.khan@oss.nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UGHvG1spBG3SfXwyNeeUCy6uwn9qFTBnwsRkuaDk2jB78K5U+HHidBz90LzJHEwwPRvhyWT+OzqD2OT29cyG3reXhTAbaN5BfBgBTBLYlTiucbNR+WWjUtCjK8hLgT40YI90d/wYy/D8gNraHr09CCJphyr6HF8p09cn4DrXcCNvY5b9rqeKEp6O5X5wEvo6/sSKvssTOCtniJFhhwIl94vumqBS0FojfCq0hAbl7cO/2risBXSMjdFq2WLX04cknpc/kU+/BiNdSqtTWM49+GZWw2lv88E3E4RkMInQN3NcNv06gylWfFHbDJPDflNs85UX/bhyKP8sPBLvOuEjmA== 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=Y0NModUSriHG8MR3R2BhfYyrhSkY6/lg+nATrg4ZU7c=; b=jMahcO0kShLp2SgmMLLHUBMkL0Tbf9ZhRQxh3fEwwXR/WJHEvVQ9me8X3YCvT2TkyaMaE4e5zZU0DvFjNa+C321fcvWyr9Wz67YU4zYmaR2dkYgrS4na5+gr0nm756NQCAZxeHsN5mF9JHmqWSjpbLCjTUw2mX8mhZacBwXHJQXFeyM/ySaEE0Tg/jC6O3t6l0T87EDlGtZjlPikzfmn48znWiPlpw11LTjES4i9K30bCU0PutpOOKJfyr+U7L0IIAIjDxRVeJSewGOLGt9k060AIAoF1L4YK/N7/+KMZSZPXYY3Ti4U270PJzK3gjPkrxgCQv0gknsGknD1LCWSRQ== 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=Y0NModUSriHG8MR3R2BhfYyrhSkY6/lg+nATrg4ZU7c=; b=fygrHxALDQKSkoYSgbOcuSA3jt0Lon/nsVcgduuPGsOcYG9Z1Eigu30Bwi600q3F9jHuZja+jBNMrDlto4Kzmhiw/8EV3Q6DYlcPDZ1p8RP9Wdk/+hrs8w8Z66+75phdfu8pJxhgXNVYINgtT3CGXa13cMemu7x9NVzTFhXnAsg= 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 VE1PR04MB6768.eurprd04.prod.outlook.com (2603:10a6:803:129::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.22; Mon, 1 Jun 2020 19:28:03 +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.3045.024; Mon, 1 Jun 2020 19:28:03 +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 1/3] Silicon/NXP/Library: Implement SerDesHelperLib Date: Tue, 2 Jun 2020 00:57:36 +0530 Message-ID: <1591039658-18541-2-git-send-email-wasim.khan@oss.nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1591039658-18541-1-git-send-email-wasim.khan@oss.nxp.com> References: <1591039658-18541-1-git-send-email-wasim.khan@oss.nxp.com> X-ClientProxiedBy: PN1PR01CA0082.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:1::22) 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.140.9) by PN1PR01CA0082.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3045.18 via Frontend Transport; Mon, 1 Jun 2020 19:28:01 +0000 X-Mailer: git-send-email 2.7.4 X-Originating-IP: [157.37.140.9] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 41f99134-d401-4084-b438-08d80661e6f7 X-MS-TrafficTypeDiagnostic: VE1PR04MB6768: 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: 0421BF7135 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aLYdsQROhv4XRafQHcRW/gd+yeHSgv3hFqgZZGOpb5yh6I8FBuK+R7JFeljupzxqQ/+frIcCGmFg3iDQ+KlzUj+J2JbUHhZvfGi8v1eSgzvZHW2F56Ij4GDfagCXgvHvOEg68HIo4E+yLGdhHFiWsGaNsTsVwJzFuOBp675p8fWBzfh+/avWzzO++8Owqs6tjDoxoU9/zZxO3lLXopT/DBxg/mUolxl4MqdXQoLxdD90sulkl9/cAYgmE4glntAj6kKY9QoteW56QncIFrJcahbBv/X0yeJoPLyFcO/uwzEJGywlyjcQKa2aFQ+2jpcqMJdhKQ2MqSVskhfabhPJWQ== 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)(396003)(39860400002)(376002)(366004)(136003)(346002)(83380400001)(6512007)(6486002)(66946007)(66556008)(8676002)(2616005)(44832011)(66476007)(26005)(186003)(16526019)(956004)(2906002)(6506007)(86362001)(316002)(52116002)(6666004)(478600001)(4326008)(5660300002)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ZnSNzx8U8Vxcixs8favDSe+DIiQkpOi6FxZtsniggPoUOLNCbfyHBqov1jE32ATCKQ356KG2IkszgkQ9N9Q7HqLD1ltwrGtT3mbKS7oQvKj5l6WoKQfphjZ8Ulqnq3f3p3TJbdFatW3Hph16vp555+iEH9+WfXOAbUO8198Hoot3UjE+ofhHwUfxExxBM93oEhXa+1XMLRtnnHNt0Nkof9SfX/lEGNSymbbT7x1UH2vaDz/35DtY3qhMRQzPJsXLyMUd17vE/Dg3+JH1QVrNXBSBoBWgRU/ZFLEPoBEGkyxax0xWqYBhNoWnl3uKriBNUJVvUbys+GbmUi8IM2rC1xO4OOGdNNtK44hG3Jh9uGjuGqk9EcklC7dtBXSPfeyLwbNOR4Mb9C9QWg/zoGlJ9nXnJE1TnQgZYhc9gmvE8E7LYAQakiwGeVmo5D/eYnuhH7RnrX2cYSHt6jV+KRAU4U8xpEiSv1qjobVrRE8pUgo= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41f99134-d401-4084-b438-08d80661e6f7 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2020 19:28:03.4330 (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: H3vPT2O4vtptP63FlJpCQfVe5Db1faLsta9TWeQofth0Mid2/yvMVKO3g9VpArqNg91/bULL5rgMvDz0FR7LmQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6768 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 --- 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 | 165 ++++++++++++= ++++++++ 4 files changed, 258 insertions(+) diff --git a/Silicon/NXP/NxpQoriqLs.dec b/Silicon/NXP/NxpQoriqLs.dec index d4d3057af509..720bb5794960 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..05814c986393 --- /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 SocHelperLib + 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..ef08c3edc30a --- /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 SrdsLane[FixedPcdGet8 (PcdSerdesLanes)]; +} SERDES_CONFIG; + +typedef enum { + SRDS_1 =3D 0, + SRDS_2, + SRDS_3, + SRDS_MAX_NUM +} SERDES_NUMBER; + +UINT32 +GetSerDesPrtcl ( + IN INTN SerDes, + IN INTN Cfg, + IN INTN Lane, + IN UINT32 SerdesMaxProtocol, + IN SERDES_CONFIG *Config + ); + +EFI_STATUS +CheckSerDesPrtclValid ( + IN INTN SerDes, + IN UINT32 Prtcl, + IN UINT8 SerdesLanes, + IN SERDES_CONFIG *Config + ); + +EFI_STATUS +GetSerDesMap ( + IN UINT32 Srds, + IN UINT32 SrdsProt, + IN UINT8 SerdesLanes, + IN UINT32 SerdesMaxProtocol, + IN SERDES_CONFIG *Config, + OUT UINT64 *SerDesPrtclMap + ); + +VOID +SerDesInstanceProbeLanes ( + IN UINT32 Srds, + IN UINT32 SrdsProt, + IN UINT8 SerdesLanes, + 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..54d0a6181707 --- /dev/null +++ b/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c @@ -0,0 +1,165 @@ +/** 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 Cfg Serdes Protocol. + @param Lane Serdes Lane number. + @param SerdesMaxProtocol Max Serdes protocol number. + @param Config Serdes Configuration. + + @return Serdes Lane protocol. + +**/ +UINT32 +GetSerDesPrtcl ( + IN INTN SerDes, + IN INTN Cfg, + IN INTN Lane, + IN UINT32 SerdesMaxProtocol, + IN SERDES_CONFIG *Config + ) +{ + while (Config->Protocol) { + if (Config->Protocol =3D=3D Cfg) { + return Config->SrdsLane[Lane]; + } + Config++; + } + + return SerdesMaxProtocol; +} + +/** + Function to validate input serdes protocol. + + @param SerDes Serdes number. + @param Prtcl Serdes Protocol to be verified. + @param SerdesLanes 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 +CheckSerDesPrtclValid ( + IN INTN SerDes, + IN UINT32 Prtcl, + IN UINT8 SerdesLanes, + IN SERDES_CONFIG *Config + ) +{ + UINT8 Cnt; + + while (Config->Protocol) { + if (Config->Protocol =3D=3D Prtcl) { + DEBUG ((DEBUG_INFO, "Protocol: %x Matched with the one in Table\n", = Prtcl)); + break; + } + Config++; + } + + if (!Config->Protocol) { + return EFI_NOT_FOUND; + } + + for (Cnt =3D 0; Cnt < SerdesLanes; Cnt++) { + if (Config->SrdsLane[Cnt] !=3D 0) { + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +/** + Get lane protocol on provided serdes lane and execute callback function. + + @param Srds Serdes number. + @param SrdsProt Serdes protocol number. + @param SerdesLanes 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 Srds, + IN UINT32 SrdsProt, + IN UINT8 SerdesLanes, + IN UINT32 SerdesMaxProtocol, + IN SERDES_CONFIG *Config, + IN SERDES_PROBE_LANES_CALLBACK SerDesLaneProbeCallback, + IN VOID *Arg + ) +{ + INT8 Lane; + UINT32 LanePrtcl; + + // Invoke callback for all lanes in the SerDes instance: + for (Lane =3D 0; Lane < SerdesLanes; Lane++) { + LanePrtcl =3D GetSerDesPrtcl (Srds, SrdsProt, Lane, SerdesMaxProtocol,= Config); + ASSERT (LanePrtcl < SerdesMaxProtocol); + if (LanePrtcl !=3D 0x0) { + SerDesLaneProbeCallback (LanePrtcl, Arg); + } + } +} + +/** + Function to fill serdes map information. + + @param Srds Serdes number. + @param SrdsProt Serdes protocol number. + @param SerdesLanes Number of Serdes Lanes. + @param SerdesMaxProtocol Max Serdes protocol number. + @param Config Serdes Configuration. + @param SerDesPrtclMap Output Serdes protocol map of enabled device= s. + +**/ +EFI_STATUS +GetSerDesMap ( + IN UINT32 Srds, + IN UINT32 SrdsProt, + IN UINT8 SerdesLanes, + IN UINT32 SerdesMaxProtocol, + IN SERDES_CONFIG *Config, + OUT UINT64 *SerDesPrtclMap + ) +{ + INTN Lane; + EFI_STATUS Status; + UINT32 LanePrtcl; + + Status =3D CheckSerDesPrtclValid (Srds, SrdsProt, SerdesLanes, Config); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: SERDES%d[PRTCL] =3D 0x%x is not valid, Statu= s =3D %r \n", + __FUNCTION__, Srds + 1, SrdsProt, Status)); + return Status; + } + + for (Lane =3D 0; Lane < SerdesLanes; Lane++) { + LanePrtcl =3D GetSerDesPrtcl (Srds, SrdsProt, Lane, SerdesMaxProtocol,= Config); + if (LanePrtcl >=3D SerdesMaxProtocol) { + DEBUG ((DEBUG_ERROR, "Unknown SerDes lane protocol %d\n", LanePrtcl)= ); + return EFI_NO_MAPPING; + } + *SerDesPrtclMap |=3D (0x1u << (LanePrtcl)); + } + + return EFI_SUCCESS; +} --=20 2.7.4