From nobody Wed Dec 25 14:32:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1510044858526289.9039165357293; Tue, 7 Nov 2017 00:54:18 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EF0C62034D833; Tue, 7 Nov 2017 00:50:17 -0800 (PST) Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0051.outbound.protection.outlook.com [104.47.34.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 93F922034D825 for ; Tue, 7 Nov 2017 00:50:16 -0800 (PST) Received: from BN3PR03CA0080.namprd03.prod.outlook.com (10.167.1.168) by DM5PR03MB2697.namprd03.prod.outlook.com (10.168.197.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.218.12; Tue, 7 Nov 2017 08:54:15 +0000 Received: from BN1BFFO11FD004.protection.gbl (2a01:111:f400:7c10::1:163) by BN3PR03CA0080.outlook.office365.com (2a01:111:e400:7a4d::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.197.13 via Frontend Transport; Tue, 7 Nov 2017 08:54:14 +0000 Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1BFFO11FD004.mail.protection.outlook.com (10.58.144.67) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.178.5 via Frontend Transport; Tue, 7 Nov 2017 08:54:14 +0000 Received: from uefi-OptiPlex-790.ap.freescale.net (uefi-OptiPlex-790.ap.freescale.net [10.232.132.78]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id vA78s4DY009319; Tue, 7 Nov 2017 01:54:11 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.34.51; helo=nam01-by2-obe.outbound.protection.outlook.com; envelope-from=meenakshi.aggarwal@nxp.com; receiver=edk2-devel@lists.01.org Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; From: Meenakshi Aggarwal To: , , , Date: Tue, 7 Nov 2017 20:12:07 +0530 Message-ID: <1510065736-9394-2-git-send-email-meenakshi.aggarwal@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1510065736-9394-1-git-send-email-meenakshi.aggarwal@nxp.com> References: <1510065736-9394-1-git-send-email-meenakshi.aggarwal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131545184547706598; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(39860400002)(346002)(39380400002)(376002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(50466002)(48376002)(305945005)(104016004)(77096006)(54906003)(110136005)(2950100002)(2201001)(33646002)(36756003)(356003)(50986999)(97736004)(189998001)(2906002)(76176999)(85426001)(47776003)(105606002)(316002)(81166006)(81156014)(8936002)(5003940100001)(106466001)(498600001)(8656006)(8676002)(6306002)(6666003)(50226002)(5660300001)(4326008)(53936002)(68736007)(16586007)(966005)(16799955002)(575784001)(86362001)(53376002)(15188155005)(21314002)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB2697; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD004; 1:nm8+g2RxGrD1JZSuo6MlAhB227/nxbfqV8Bq1jBk5M0sA87oAPCrvAGSWIe9dYfMnYeqrcwitujqrb75ceC4TCdudswL0U5638YKgR7s0QmCL1VL+UI0+VaZlpkWH7i1 MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: a917a745-5598-4b12-00d6-08d525bd1f32 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4628075)(201703131517081)(2017052603199); SRVR:DM5PR03MB2697; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2697; 3:IE1Q6W5aQ/IbpTlhhupiR4X0GVyb8AIGyvRkpM6Pn+NpxRuQf4ncJX2Qmxhzriui5hEX3AYgoXvBOsxKBc17zLVBEvzhkDxZEgZ284nn9QyfR76dU7VigkiViyvBMIBq2Aa+35S0yHL7wjxcE86Kpj/C0LC2iablw98nVqNDDHRBkZnmNaywCQO714pHqzEv3+4aLkjp1/wmNQNreMd39KKVlDCO5tx7iQJ1pYDH3cPJRQmJF29ckMOJEbD2q0boouWjphdFOQTqYv8Yuhn1my1sYji0OTVzxazpbS3ns1pSCE7VFHDtgVMBcBIC+5OkulMoAcrob3InrJot+Y0LlxkvoUzgYhZVj1sGDYAkSos=; 25:CUzy933gHU/ZeOygo2Wm/OGUsIpnjIXz9/m5ilU3sDez3E95Djfl2ddQWtT34VJWkdKwSaY7AAlVkyk9HyXlU0c9Akrug9ikFJt81sEpzRrq07LdrStfADiwFOseTzuU0I3kZPDBNO/3phxJwY6BKBgsS6jrWesPAXZNdwPVvcYuHeJ2LJ4MzWPjccxoGCV7R93Xv/nkXfRgcvpQ5RM8572NAZcBcJuSHVr8t8dqwRvUDO/WjkSn5lGS1B7b/nXxpYaxILQjygSbKY4/mjt0nnDalV47nSqZj1+qfQUwOEGvMSEi9v5CSnumtoyPrVUamIIQnTsLQ+G27DeA0Mbhow== X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR03MB2697: X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2697; 31:RIxLQ2t0toYh9fBTbNoyjGKNRjcH8bXKCCttDH/iOJoGpOmZa8OdnXdmZKjqfyHM0e8joodyEFZ7rmSSW/Ww8j0Jp33mFqjPOqj8Q6UySWeEdIdx1AegOK5N4RSrjLXHeAXGkCFrq8GYfX/tFs8OSrd77bSH0Fmc8VnJAMpy9QikCFIWcdCLcU5c9HCM6yt5+eYnVZWl5A80z82dL7HmEKDcJR/Kh+aCxg7nSD2QEW4=; 4:Ab8rPSNwJ8atyLsZWDq3VOTEVNpF/4NQaZKWZLC/QWAJDsQy1Gf5JtRoqjAUNsaN8AovLRf/5mBXgIOA9xwhe469NzDCzkQ6z0q2wn8CAYzwCf9GFSFA+oB7X7rfiDM02NDT1moF4uxxLAPAjDcvikNScnN3BEoF2nCFefyzAgXSGoWqQn3rXA28W5Flnd9BDjtfaohbaJY5SCj0cSqhrWWf0kSnIf+3tm142yB463KAoI3/ZQHY2ALkdEKsOuyxGRHxiKoonVHaxiTPEaTFTC1dk3BvejLnr4eWx6iUgZe9fPkIPXlR9ztgUsLN/NEn X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(2401047)(8121501046)(5005006)(3231021)(93006095)(93001095)(3002001)(100000703101)(100105400095)(10201501046)(6055026)(2017110403001)(6096035)(20161123565025)(20161123559100)(20161123561025)(201703131430075)(201703131433075)(201703131448075)(201703161259150)(201703151042153)(20161123563025)(20161123556025)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM5PR03MB2697; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM5PR03MB2697; X-Forefront-PRVS: 0484063412 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR03MB2697; 23:MRqVCaxhmT3VidKfqcAwFtqs6qIEnja3cUitaEkUg?= =?us-ascii?Q?xc05pqfjxSHQXo4rF2pw4Xm6aHZ6In3LXpbDd3sHMuz59pkH18cJYYV+hF5D?= =?us-ascii?Q?xGk7D077hcvbIUzfdBVaNJYV8IoNUv1l8ZVdV9HuSmo5ErjI2rzquvlJQno+?= =?us-ascii?Q?YHQfU/2Vy+UffWiQV8Mt7JOcQRyd4AhwQUPO58zA8fzlVkay3yYwFap8PyKv?= =?us-ascii?Q?Wsrek8EyFEFTAB1WEf2MyMt5BMdPeSQqrIRA+WxywbiJj+5w+lJ5Yi/B1c45?= =?us-ascii?Q?C9szjEisie1HPuWW8+trdu6lINow+qVpE/TU1k9xs1cpqyYLUfpVI+E1Ir0g?= =?us-ascii?Q?IvdSdMhygx0mcXvc5zz8AJg2MWOSSmWoonPbtELPndsxTIuP5V4ryNTN55Lp?= =?us-ascii?Q?ExlvI8VNn4Bv3b5LNMn+m/GA+Z+LjmuY8GDBCIT3A18xHNwy2iGH2QHlrzrH?= =?us-ascii?Q?uqXasKFf5HsmMEjcqoKHCUPZd90NK+lQa3/y2Fen0f4NAHAvz8IkEHVp6Ree?= =?us-ascii?Q?FCTTfUu/KMqqqQyFesfpIkgrJbbzVXznAvF7RDrWg5mCQJ0seh/IPNtFFFXL?= =?us-ascii?Q?JYFSaES6zOG6Maxjt8njtZK2dAuc2OuvzGjTJ8uO/D1EBP6I9ieqB47H3nyP?= =?us-ascii?Q?SS+qeV1rMiG2tE3W4+DAHyeIXW7pgjl6G4daKPwGMn2ptdysdQItScvR0JlU?= =?us-ascii?Q?sK9tH7tn7bG8NjGuOR8Y8VDqVSbpjzLZN+2T+3lf4c1HveHZDuDCQhKcEsup?= =?us-ascii?Q?JyQssD6uvjQtNqenFjrHqVuqk3GTc4DAhEoANAHuVa92pCIN0jGoz9n2jVjg?= =?us-ascii?Q?TeTG0ML1sRKEhE+bjcty7aTr9Gi7ehnpcsvszZczXDS7eoQ3/ObtBWorCuB5?= =?us-ascii?Q?Mgt57OgSxkWfEUiSlrt0W3UlyAgDatxjXxXqPRGImU4QKISajhz3lq7vXAlM?= =?us-ascii?Q?DIi+Xhwgl1QHUDtU68gLFIZ/hmhSlvcm82Xj/PP6OXTNpzuywyUM2dzfDFW4?= =?us-ascii?Q?B/8L59k8rKMVKbbh7xzCS95DCygQgSjmqK9a8pmXXKIm/u4fLS5PR+Fu9db6?= =?us-ascii?Q?thfkh5rwUtNMw7be8KnsFV2FN4ezv2/0cilp5xxITPIp5+aqd/e9a1PuJR96?= =?us-ascii?Q?O8+iPZzYjf7fV5BWkL+c8zkK632e+8cU1b+1QwfFJD0kAKTKCL3fvxkBQZsH?= =?us-ascii?Q?FrZKOhH68C2mGZXnlYihieewUwBmZMUbm3No2Wrf2am7MwFACUR4PTfIzJZ3?= =?us-ascii?Q?fqozWD35GzdYjZy1e+jmV8c84iDPVHcMp+2s+r8qFasqKn5CzxOueunBWBHE?= =?us-ascii?Q?eHxj1Vnp3pq0mGH8N8s+3eZ4f8pIHwZ7H6uy/2z+3TnzYII0waU+Mfb7DqxV?= =?us-ascii?Q?LkmWg=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2697; 6:7iC55XlQIVYm5xtPJyM2ywFh2yzR8siG/2c76XKW5cpFKXmAzoF1xngMdbulckkkJ8L1nlskzx2dx4svW7FinMfoWNT5rnr9lxQmkxyUR2mohfY4zgmM/zDNrGnBIhTW0BJMEtQo9OXMzgPKU3bsxMJT9YzP76JYsWgqCGRV3SQY5JNGI7fvLjRmBdDQaP3ICFFj0cejay2GhX4onGMxBod3FI7wEHkffAy7PSW+DEKjsaAlrC6OfzCa3lYQEk4ZsNsSG5e9m0N2aEjWopD6X+2quQIZCnSgkkHKt2ZXAOLY9lwpUDHa4SgY0BEegFCy56wqoKIUm2rmUT+ui7246DvqAyJC3txnYJ9Rna49oYQ=; 5:tU4TNM8QZnLExYqyxANGMQJfm5RZOuXAP6roKTiQczG8SDrZT+qSj2Ff7mpskO6Mu24K3msoqmjKcvvoYwQyDMSrNOkFyMJ9K9N8CbMJoZ1wYtKKLLBnOZQAocvcn4VdWSYkQRDC/jv4n/TXjgmZ7R5ltwWnNfivkKUIW7u84f4=; 24:8qJFVn1IN9VMNdCCUyjXi+Gz5uATeAqXjFwWJx/gzwqasKKXfUWJsXwLySEYShwEooLGBl3/ilf2sw99BEL7dXaqUMDuvQpyzU1eVen4rW4=; 7:QIDtsipRdXUgmPDTpR0CFSpYQd7kNstNJnkhUXovTdpqiSfxaTMGfFpla+4E7tsZlza8B8PQSX34XEvveoanaBilwEKNH7Hf0mpVk/qBn3s8/rHl8TRK7yOpluKYGjgfLrxk579Q4qHHTYPlqibzHfYOns9CQAYNLoIG2x6liGuUkfThnepnYbPep+HeJPIVikyp6/2Cu1zRVjcFFp7bNP02Op0igvmDkxrUK0JSMTMfrAJoFLnMbdSoBxdvGJk5 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2017 08:54:14.3494 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a917a745-5598-4b12-00d6-08d525bd1f32 X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2697 Subject: [edk2] [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: , Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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/Li= brary/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 BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#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)); \ +} \ +) + +/* + * 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); +} + +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; +} + +/* + * 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/U= tilsLib/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 BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#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 B= SD License +# which accompanies this distribution. The full text of the license may = be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D UtilsLib + FILE_GUID =3D 0985d4e8-5a41-40cf-ad12-2ad5d35e817f + 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 --=20 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel