From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.82]) by mx.groups.io with SMTP id smtpd.web10.1954.1591642378219385625 for ; Mon, 08 Jun 2020 11:52:58 -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=km5hEDv+; spf=pass (domain: oss.nxp.com, ip: 40.107.20.82, mailfrom: wasim.khan@oss.nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WT2ux8PQHgczr3G2UDVynAPbd2T7GYiGXnIH9APcpvHKjYytVgdLMVnPXhLCrYSnilmrqkZh26tvAdlJUEiX82b6/3NZ3qZf2EqF3uvkzU6hGGcXlRdSpDD4rPCZPOIGERvySSqqmVh7arPFYZJLaAgP47kq8877SgMS3DBvb/azunPcKn0b0bKKkR+uBUt35p/Xl+JM16DCx/ZLKrpGgVBf8Gb+cJTHw24kknAvcJ8LbiPer7+1btX28+/ozRhPjfxK4LFFbI7R3qWsG+tP51LRcqjIwQaGPz4b1yy0BlHO7Q68aNgcmOD9H4nKQ4vDbh5E6KRb0h6mbCc0uiJPMA== 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=BTzIe+kbzUYv2sAV/1mzpxYHdJmvXvFNm9wowxfXLMk=; b=F0yj3GX82l2U4oGc9klTQ407YCaNs8DxUurZ9ceBf6IQL7EBk1fkp9QUvPv15PUHbosNtf5988eqyWAdeIxO1qwmjxFwK+6D5EHGJ9ewRtxZFvQcL1kpvrKGvJHcrWpIKhETh0wzRRjL9dWNr9OuX739z9RCaISa+R3GNwG9fbYwgdMuTNFZaKzOJewkSd28m173ks3qmLpxTo0sYtmAzbMLtLdbcnui4IDRniuz8ULvAEavJWTc82aePMrAqz9YOnTrjEmCSF+gV1QL5zP6fW93yvsx/Ms258726iHJoQwm3Az4e1fr3Jvg4jmQcL+Hogz28vdNo+/gnQHOxB8Xmw== 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=BTzIe+kbzUYv2sAV/1mzpxYHdJmvXvFNm9wowxfXLMk=; b=km5hEDv+3Jd/95MbuQkUnfdQl98GjfEOZzgn1Hc3sstpLHHU0LmiQ6qs4yH1Iox9oglFwEwSIDFVqRkY0Tgw9dm3p5oeL37NnaDt/4sRpBfd2EeBY+jucP7uXsP7JQonrWVKrp+XNz/HVupwOEkQw9ayVjGmwE/q3vKsUs9cCr8= 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 VE1PR04MB6606.eurprd04.prod.outlook.com (2603:10a6:803:127::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Mon, 8 Jun 2020 18:52:56 +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:52:56 +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 v5 1/3] Silicon/NXP/Library: Implement SerDesHelperLib Date: Tue, 9 Jun 2020 00:22:33 +0530 Message-ID: <1591642355-26470-2-git-send-email-wasim.khan@oss.nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1591642355-26470-1-git-send-email-wasim.khan@oss.nxp.com> References: <1591642355-26470-1-git-send-email-wasim.khan@oss.nxp.com> X-ClientProxiedBy: PN1PR01CA0078.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:1::18) 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 PN1PR01CA0078.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:1::18) 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:52:53 +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: 23434fd2-3553-4ca8-c094-08d80bdd27de X-MS-TrafficTypeDiagnostic: VE1PR04MB6606: 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: 3DiX+MjgBRO3Xs93m3FvwnUznT9gWEAhy3ltdDBu/2iojAxY2zyP+oxEoIooBfebBYzJ6+WlWV2FH8HwS2zcN5A6KijnU+wxHowpREu6rssj0aqcIea+LOh6s8VtUbdywZavwnrYTIcEkt8JDj9/d7ruVC6bWMnZEmwxOagmMsvE7YT578DopzSHZXGYLT/ZvBjPd0Uk2JMLEUUF3gOeSUaQ7Sb5Pzz5PvP9Yz6+A1DhZFqCwSemhDYNNQ9Ec7RSA+wx9SDMKQk6kHfIOLlT2HgfXWq/5Gn+nFt0itS5o9CbQ+D9GUr8pJYzlKReK7VXeGnKDsRgZToflXMFSAAaHQ== 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)(136003)(376002)(366004)(39860400002)(346002)(396003)(26005)(66946007)(8936002)(66476007)(4326008)(6486002)(5660300002)(66556008)(956004)(52116002)(2616005)(86362001)(6512007)(8676002)(316002)(478600001)(2906002)(83380400001)(6506007)(6666004)(186003)(16526019)(44832011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: O/6E2L3+Zidmt3kydShOg64bbsLRT/2D2ZUJgXmRma8ko18IgWgreiUVCb4tJJjRQxbedfvIDit/cM8sehxfflpJ5dD1KMaQ2R4qvHxi7cbNjMqxPzg9Wybb8xiIfHpfwwwk3XX0zW9kfLRv3AbG0ik0ycGWGBNotEyNJlOGyQ1y4JyV2uvIGtRJJ1f8ThMV88qxti9d2Gt0SM8xXK+SjsUF7mH7AuOfsCpDx21g4dE3LqQfVfvQuPdH6XT7lNdj5INs0hFULDl3CxYOUZBFlgT2d6CrbfEMAjsXNHPIHcxz540pIEbsR7CCIUH7goD9kLEinRstdXLwTmpFy3+RPkUMt74UnJVsw12g7qV+YV8H2Zcoux14JsLfmUVHV8tTb/+ELQUppZ0deWZF7ZfIr51ysyDtFRCqNKHZmbYWQtGFYMDURXGmAFGAH0rumj2aSOdQG3qw5tiBNn1E5bb317o8KlFGFPe6tasSHzHuJNU= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23434fd2-3553-4ca8-c094-08d80bdd27de X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2020 18:52:56.1780 (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: HrdVNlUQjRopGgYSDvVj2NChER5xgbcdtf5AjEPBG/HbDxXlikO0StBWFqhssxlzdQKD/t1X3qaDe7EoFTm+jQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6606 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 V5: - No Change =20 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