From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.1.55; helo=eur01-ve1-obe.outbound.protection.outlook.com; envelope-from=meenakshi.aggarwal@nxp.com; receiver=edk2-devel@lists.01.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0055.outbound.protection.outlook.com [104.47.1.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 902F9202E5E66 for ; Mon, 13 Nov 2017 21:48:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=KiC9vHGKj2N/XTHWeEAVMlFvf6crjRB4oT0Mb49GHPc=; b=Ogt7hj9BeMnw6JYBptriPDEd32p4e7132A33aKjoaktiS0C4hyLKkSYZzfnzu0+ybFL+mW41b2B/nJAA/aaLnZIJAIwCHd0wIMePp12HWxWpRIRdNrg9zo3G0y1v6shzoERE3Em5obiWAD/Wb/2k3WCAy4rwq8gGC6Zh68rmfwE= Received: from DB5PR04MB0998.eurprd04.prod.outlook.com (10.161.199.12) by DB6PR04MB3000.eurprd04.prod.outlook.com (10.170.213.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.218.12; Tue, 14 Nov 2017 05:52:15 +0000 Received: from DB5PR04MB0998.eurprd04.prod.outlook.com ([fe80::7964:3b7:763b:63ba]) by DB5PR04MB0998.eurprd04.prod.outlook.com ([fe80::7964:3b7:763b:63ba%13]) with mapi id 15.20.0197.017; Tue, 14 Nov 2017 05:52:14 +0000 From: Meenakshi Aggarwal To: Leif Lindholm CC: "ard.biesheuvel@linaro.org" , "michael.d.kinney@intel.com" , "edk2-devel@lists.01.org" , Udit Kumar , Varun Sethi Thread-Topic: [PATCH 01/10] Platform/NXP: Library to provide helper functions. Thread-Index: AQHTV6X/r/ydUb1wdkqMw9N+JFczfqMSU02AgADu10A= Date: Tue, 14 Nov 2017 05:52:14 +0000 Message-ID: References: <1510065736-9394-1-git-send-email-meenakshi.aggarwal@nxp.com> <1510065736-9394-2-git-send-email-meenakshi.aggarwal@nxp.com> <20171113131413.cfx622huibkturcm@bivouac.eciton.net> In-Reply-To: <20171113131413.cfx622huibkturcm@bivouac.eciton.net> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=meenakshi.aggarwal@nxp.com; x-originating-ip: [192.88.169.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR04MB3000; 6:g3qijAYLkg0vP70ClGk/1OWebjb+sbn6f1RuFA6f+5HbBBbINDeluXW3Bm0nT215g1ZkLVFcadS+1c8E1QIvePQSjL80qa/9pPK5CE/4YrB0iIP45O3GsIQSxFxTCR68YQIz8nd8xjQahXg8YYxYTeBfImuKApJq1Hn6Hag6l6cQ0+UdOapoKh3EPLT+GRVIBzHDeHXo5h3nvsAJUb6eXFO28aDYFxUBD09KY6ud6fizRjhsmGPTC0KFcz8HTFd/BFNSJsfEXuUvMYSCdznzYrKfNGpWwug5uGhOnM32omVrhaegUgFpIy/OiAYN1c2A/3STqYnPyJI6/sNjh9MjSb/r2Snky8zRFxwDLah1Ofk=; 5:TWClNXOLaMNzJpE3HORYhhCmYYuZOJ0joG6HBTfoApROCdrlHJhvCom71HcmIh3VHupszZejjPDOmtWkAnA3aNQsFMAKbsWqSZROGprxfbyUs0DF+lYfCExtoaDPcSVJhkryKDHAa5O9G33iZ7RF1nvfiGLsoGzjg/yLn/+aA2w=; 24:WGTLxgT6wqv+19wE+/4tTPRiJfOcXQLZBPWaWEmP0DTkNmr3ohtzzju+TXT3Ch0wgelS1sfk04GzS0tX4I53gsoiJHkPHsQXoasxN0aFuJ0=; 7:YU6Mv35wBS+IPdS1oPXXkOSF0X67VwEB23jO5U454Hi1AcxslhW9N0hmT/QLFS00Qfa7W/AlbG7NuwLfnychCv9gUW9rPPJV/5AZ1l0YzMJD5QG95DNpdXRK8a6tlX4hV/RJsyoqXW2YAqcOtghlf7FiNLfxVGYG2TAJnZiFaZDlJqrm73OXLSIa0TO8ok8IQurcZw7/m393BjMNZnzqBxOLC9M0/WYc5h2Ofje+AXgs+OH2CUNH/53IfiiXsMx7 x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI; SCL:-1; SFV:NSPM; SFS:(10009020)(6009001)(346002)(39860400002)(376002)(13464003)(189002)(24454002)(199003)(102836003)(8676002)(53546010)(81156014)(8936002)(25786009)(14454004)(16799955002)(53936002)(33656002)(81166006)(4326008)(189998001)(3846002)(6246003)(101416001)(7736002)(305945005)(2900100001)(105586002)(6116002)(66066001)(45080400002)(68736007)(54356999)(55016002)(2906002)(50986999)(9686003)(3660700001)(3280700002)(6306002)(76176999)(106356001)(74316002)(97736004)(316002)(5660300001)(7696004)(966005)(478600001)(6436002)(575784001)(5250100002)(6506006)(6916009)(2950100002)(229853002)(86362001)(54906003)(99286004)(21314002)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR04MB3000; H:DB5PR04MB0998.eurprd04.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; x-ms-office365-filtering-correlation-id: 253eeec9-13e0-458e-dab6-08d52b23db4d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603199); SRVR:DB6PR04MB3000; x-ms-traffictypediagnostic: DB6PR04MB3000: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(189930954265078)(185117386973197)(162533806227266)(45079756050767)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(3231022)(3002001)(10201501046)(6055026)(6041248)(20161123564025)(20161123558100)(20161123555025)(20161123560025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR04MB3000; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR04MB3000; x-forefront-prvs: 04916EA04C received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 253eeec9-13e0-458e-dab6-08d52b23db4d X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Nov 2017 05:52:14.4393 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR04MB3000 Subject: Re: [PATCH 01/10] Platform/NXP: Library to provide helper functions. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Nov 2017 05:48:11 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Leif Lindholm [mailto:leif.lindholm@linaro.org] > Sent: Monday, November 13, 2017 6:44 PM > To: Meenakshi Aggarwal > Cc: ard.biesheuvel@linaro.org; michael.d.kinney@intel.com; edk2- > devel@lists.01.org; Udit Kumar ; Varun Sethi > > Subject: Re: [PATCH 01/10] Platform/NXP: Library to provide helper > functions. >=20 > On Tue, Nov 07, 2017 at 08:12:07PM +0530, Meenakshi Aggarwal wrote: > > UtilsLib provide helper functions which will be needed by NXP SoCs > > Library and Drivers. > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Meenakshi Aggarwal > > --- > > Platform/NXP/Include/Library/Utils.h | 137 > ++++++++++++++++++++++++++++++++ > > Platform/NXP/Library/UtilsLib/Utils.c | 97 ++++++++++++++++++++++ > > Platform/NXP/Library/UtilsLib/Utils.inf | 30 +++++++ > > 3 files changed, 264 insertions(+) > > create mode 100644 Platform/NXP/Include/Library/Utils.h > > create mode 100644 Platform/NXP/Library/UtilsLib/Utils.c > > create mode 100644 Platform/NXP/Library/UtilsLib/Utils.inf > > > > diff --git a/Platform/NXP/Include/Library/Utils.h > > b/Platform/NXP/Include/Library/Utils.h > > new file mode 100644 > > index 0000000..8920e4d > > --- /dev/null > > +++ b/Platform/NXP/Include/Library/Utils.h > > @@ -0,0 +1,137 @@ > > +/** Utils.h > > + Header defining the General Purpose Utilities > > + > > + Copyright 2017 NXP > > + > > + This program and the accompanying materials are licensed and made > > + available under the terms and conditions of the BSD License which > > + accompanies this distribution. The full text of the license may be > > + found at > > + > > + > https://emea01.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fop > > + ensource.org%2Flicenses%2Fbsd- > license.php&data=3D02%7C01%7Cmeenakshi.a > > + > ggarwal%40nxp.com%7C6e1f439b12994a95303208d52a987203%7C686ea1d3b > c2b4 > > + > c6fa92cd99c5c301635%7C0%7C0%7C636461756611410167&sdata=3D6p6jnHOrzd > eMT > > + mSED4ktCktqavpmbIfZpPGGa2TyM0g%3D&reserved=3D0 > > + > > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > + BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, > EITHER EXPRESS OR IMPLIED. > > + > > +**/ > > + > > +#ifndef __UTILS_H__ > > +#define __UTILS_H__ > > + > > +/* > > + * Divide positive or negative dividend by positive divisor and round > > + * to closest UINTNeger. Result is undefined for negative divisors > > +and > > + * for negative dividends if the divisor variable type is unsigned. > > + */ > > +#define DIV_ROUND_CLOSEST(X, Divisor)( \ > > +{ \ > > + typeof(X) __X =3D X; \ > > + typeof(Divisor) __D =3D Divisor; \ > > + (((typeof(X))-1) > 0 || \ > > + ((typeof(Divisor))-1) > 0 || (__X) > 0) ? \ > > + (((__X) + ((__D) / 2)) / (__D)) : \ > > + (((__X) - ((__D) / 2)) / (__D)); \ > > +} \ > > +) >=20 > This function has been lifted verbatim from the Linux kernel, with the in= puts > converted to upper case, at a date before commit 4f5901f5a6724 went in. > include/linux/kernel.h does not contain an explicit license, so falls und= er the > Linux kernel default of GPLv2, which is not compatible with the specified= BSD > license. >=20 > Please have a _very_ _close_ look at any other potential license infelici= ties in > the code. >=20 OK, I will check all functions in this file. =20 > > + > > +/* > > + * HammingWeight32: returns the hamming weight (i.e. the number > > + * of bits set) of a 32-bit word > > + */ > > +STATIC > > +inline > > +UINTN > > +HammingWeight32 ( > > + IN UINTN W > > + ) > > +{ > > + UINTN Res; > > + > > + Res =3D (W & 0x55555555) + ((W >> 1) & 0x55555555); Res =3D (Res & > > + 0x33333333) + ((Res >> 2) & 0x33333333); Res =3D (Res & 0x0F0F0F0F) = + > > + ((Res >> 4) & 0x0F0F0F0F); Res =3D (Res & 0x00FF00FF) + ((Res >> 8) = & > > + 0x00FF00FF); > > + > > + return (Res & 0x0000FFFF) + ((Res >> 16) & 0x0000FFFF); } >=20 > This looks near-identical to an old version from linux lib/hweight.c. >=20 > / > Leif >=20 > > + > > +STATIC > > +inline > > +UINTN > > +CpuMaskNext ( > > + IN UINTN Cpu, > > + IN UINTN Mask > > + ) > > +{ > > + for (Cpu++; !((1 << Cpu) & Mask); Cpu++) > > + ; > > + > > + return Cpu; > > +} > > + > > +#define ForEachCpu(Iter, Cpu, NumCpus, Mask) \ > > + for (Iter =3D 0, Cpu =3D CpuMaskNext(-1, Mask); \ > > + Iter < NumCpus; \ > > + Iter++, Cpu =3D CpuMaskNext(Cpu, Mask)) \ > > + > > +/** > > + Find last (most-significant) bit set > > + > > + @param X : the word to search > > + > > + Note Fls(0) =3D 0, Fls(1) =3D 1, Fls(0x80000000) =3D 32. > > + > > +**/ > > +STATIC > > +inline > > +INT32 > > +GenericFls ( > > + IN INT32 X > > + ) > > +{ > > + INT32 R =3D 32; > > + > > + if (!X) > > + return 0; > > + > > + if (!(X & 0xffff0000u)) { > > + X <<=3D 16; > > + R -=3D 16; > > + } > > + if (!(X & 0xff000000u)) { > > + X <<=3D 8; > > + R -=3D 8; > > + } > > + if (!(X & 0xf0000000u)) { > > + X <<=3D 4; > > + R -=3D 4; > > + } > > + if (!(X & 0xc0000000u)) { > > + X <<=3D 2; > > + R -=3D 2; > > + } > > + if (!(X & 0x80000000u)) { > > + X <<=3D 1; > > + R -=3D 1; > > + } > > + > > + return R; > > +} >=20 > include/asm-generic/bitops/fls.h >=20 > / > Leif >=20 > > + > > +/* > > + * PrINT32 Sizes As "Xxx KiB", "Xxx.Y KiB", "Xxx MiB", "Xxx.Y MiB", > > + * Xxx GiB, Xxx.Y GiB, Etc As Needed; Allow for Optional Trailing > > +String > > + * (Like "\n") > > + */ > > +VOID > > +PrintSize ( > > + IN UINT64 Size, > > + IN CONST INT8 *S > > + ); > > + > > +/* Function to convert a frequency to MHz */ > > +CHAR8 *StringToMHz ( > > + CHAR8 *Buf, > > + UINT32 Size, > > + UINT64 Hz > > + ); > > + > > +#endif > > diff --git a/Platform/NXP/Library/UtilsLib/Utils.c > > b/Platform/NXP/Library/UtilsLib/Utils.c > > new file mode 100644 > > index 0000000..4f5a15c > > --- /dev/null > > +++ b/Platform/NXP/Library/UtilsLib/Utils.c > > @@ -0,0 +1,97 @@ > > +/** Utils.c > > + > > + Copyright 2017 NXP > > + > > + This program and the accompanying materials are licensed and made > > + available under the terms and conditions of the BSD License which > > + accompanies this distribution. The full text of the license may be > > + found at > > + > > + > https://emea01.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fop > > + ensource.org%2Flicenses%2Fbsd- > license.php&data=3D02%7C01%7Cmeenakshi.a > > + > ggarwal%40nxp.com%7C6e1f439b12994a95303208d52a987203%7C686ea1d3b > c2b4 > > + > c6fa92cd99c5c301635%7C0%7C0%7C636461756611410167&sdata=3D6p6jnHOrzd > eMT > > + mSED4ktCktqavpmbIfZpPGGa2TyM0g%3D&reserved=3D0 > > + > > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > + BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, > EITHER EXPRESS OR IMPLIED. > > + > > +**/ > > + > > +#include > > +#include > > +#include > > + > > +/* Function to convert a frequency to MHz */ > > +CHAR8 * > > +StringToMHz ( > > + IN CHAR8 *Buf, > > + IN UINT32 Size, > > + IN UINT64 Hz > > + ) > > +{ > > + UINT64 L; > > + UINT64 M; > > + UINT64 N; > > + > > + N =3D DIV_ROUND_CLOSEST(Hz, 1000) / 1000L; L =3D AsciiSPrint (Buf, > > + Size, "%ld", N); > > + > > + Hz -=3D N * 1000000L; > > + M =3D DIV_ROUND_CLOSEST(Hz, 1000L); > > + > > + if (M !=3D 0) { > > + AsciiSPrint (Buf + L, Size, ".%03ld", M); } > > + > > + return (Buf); > > +} > > + > > +/* > > + * PrINT32 Sizes As "Xxx KiB", "Xxx.Y KiB", "Xxx MiB", "Xxx.Y MiB", > > + * Xxx GiB, Xxx.Y GiB, Etc As Needed; Allow for Optional Trailing > > +String > > + * (Like "\n") > > + */ > > +VOID > > +PrintSize ( > > + IN UINT64 Size, > > + IN CONST INT8 *S > > + ) > > +{ > > + UINT64 M; > > + UINT64 N; > > + UINT64 F; > > + UINT64 D; > > + CHAR8 C; > > + UINT32 I; > > + INT8 Names[6] =3D {'E', 'P', 'T', 'G', 'M', 'K'}; > > + > > + M =3D 0; > > + D =3D 10 * ARRAY_SIZE(Names); > > + C =3D 0; > > + > > + for (I =3D 0; I < ARRAY_SIZE(Names); I++, D -=3D 10) { > > + if (Size >> D) { > > + C =3D Names[I]; > > + break; > > + } > > + } > > + > > + if (!C) { > > + DEBUG((DEBUG_ERROR, "%Ld Bytes,\n %a", Size, S)); > > + return; > > + } > > + > > + N =3D Size >> D; > > + F =3D Size & ((1ULL << D) - 1); > > + > > + /* if There'S A Remainder, Deal With It */ if (F) { > > + M =3D (10ULL * F + (1ULL << (D - 1))) >> D; > > + > > + if (M >=3D 10) { > > + M -=3D 10; > > + N +=3D 1; > > + } > > + } > > + > > + DEBUG((DEBUG_ERROR, "%Ld", N)); > > + if (M) { > > + DEBUG((DEBUG_ERROR, ".%Ld", M)); > > + } > > + DEBUG((DEBUG_ERROR, " %ciB, %a ", C, S)); } > > diff --git a/Platform/NXP/Library/UtilsLib/Utils.inf > > b/Platform/NXP/Library/UtilsLib/Utils.inf > > new file mode 100644 > > index 0000000..9901445 > > --- /dev/null > > +++ b/Platform/NXP/Library/UtilsLib/Utils.inf > > @@ -0,0 +1,30 @@ > > +# @Utils.inf > > + > > +# Copyright 2017 NXP > > +# > > +# This program and the accompanying materials # are licensed and > > +made available under the terms and conditions of the BSD License # > > +which accompanies this distribution. The full text of the license > > +may be found at # > > > +https://emea01.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fop > e > > +nsource.org%2Flicenses%2Fbsd- > license.php&data=3D02%7C01%7Cmeenakshi.agg > > > +arwal%40nxp.com%7C6e1f439b12994a95303208d52a987203%7C686ea1d3bc > 2b4c6f > > > +a92cd99c5c301635%7C0%7C0%7C636461756611410167&sdata=3D6p6jnHOrzde > MTmSED > > +4ktCktqavpmbIfZpPGGa2TyM0g%3D&reserved=3D0 > > +# > > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, > EITHER EXPRESS OR IMPLIED. > > +# > > + > > +[Defines] > > + INF_VERSION =3D 0x00010005 > > + BASE_NAME =3D UtilsLib > > + FILE_GUID =3D 0985d4e8-5a41-40cf-ad12-2ad5d35e8= 17f > > + MODULE_TYPE =3D BASE > > + VERSION_STRING =3D 1.0 > > + LIBRARY_CLASS =3D UtilsLib > > + > > +[Packages] > > + MdePkg/MdePkg.dec > > + edk2-platforms/Platform/NXP/NxpQoriqLs.dec > > + > > +[LibraryClasses] > > + PrintLib > > + > > +[Sources.common] > > + Utils.c > > -- > > 1.9.1 > >