From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.107.3.63; helo=eur03-am5-obe.outbound.protection.outlook.com; envelope-from=udit.kumar@nxp.com; receiver=edk2-devel@lists.01.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30063.outbound.protection.outlook.com [40.107.3.63]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0A38B22436929 for ; Fri, 23 Feb 2018 02:19:16 -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=fvSJpqanGYUO/t/NRPRBZECPAtzpysAZasP1wqNJ7EA=; b=ZJ/mYbFJwLn9k1ywYuCkJVbNPE55a7EG6An+XJVerg8/Cvn7jxMs4slrmU+gpzkNJ1tGmq4WDIAiwwAqCVLUuabP5HBq7vRjkId3pGmmxB9oyZ49ILsjs4tR+f9V2dLGZvcCzmduGYaFjNN8n8msVUhlgv+K0slj5Qp3VXK6Js8= Received: from AM0PR0402MB3330.eurprd04.prod.outlook.com (52.133.44.151) by AM0PR0402MB3380.eurprd04.prod.outlook.com (52.133.45.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.527.15; Fri, 23 Feb 2018 10:25:15 +0000 Received: from AM0PR0402MB3330.eurprd04.prod.outlook.com ([fe80::8d12:f6b0:d25c:a8de]) by AM0PR0402MB3330.eurprd04.prod.outlook.com ([fe80::8d12:f6b0:d25c:a8de%13]) with mapi id 15.20.0527.017; Fri, 23 Feb 2018 10:25:15 +0000 From: Udit Kumar To: Laszlo Ersek , Leif Lindholm CC: "michael.d.kinney@intel.com" , "edk2-devel@lists.01.org" , "ard.biesheuvel@linaro.org" Thread-Topic: [edk2] [PATCH edk2-platforms 01/39] Silicon/NXP: Add support for Big Endian Mmio APIs Thread-Index: AQHTqysWhBWg9HbkxE6P6Sgrl/jTxKOwc5jEgAFW8oA= Date: Fri, 23 Feb 2018 10:25:15 +0000 Message-ID: References: <1518771035-6733-1-git-send-email-meenakshi.aggarwal@nxp.com> <1518771035-6733-2-git-send-email-meenakshi.aggarwal@nxp.com> <20180221154601.nkbp2xmy3zb2xolm@bivouac.eciton.net> <20180221185818.arwfhombntutnt23@bivouac.eciton.net> <20180222115223.xtfpc7du22drfkju@bivouac.eciton.net> <2a1fa56f-98db-a1c1-d973-7e84cc7dc1fa@redhat.com> In-Reply-To: <2a1fa56f-98db-a1c1-d973-7e84cc7dc1fa@redhat.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=udit.kumar@nxp.com; x-originating-ip: [192.88.169.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM0PR0402MB3380; 7:eGaB0Jk8xCfA8mVnxUjKrtUIlTA0tPuuSJFdBW0OhCxgcYeAt68rL94vpCmvN/tTGBLsMmDxqn18eHLIAp1XpnN8ADstCsxQYGthAXfk19aRCgAhrCtIdcxPKwNGHLiZNRgKSqupjoReFjHhaZsZhHuwltBVm2LhP8PL+DKaPhwW3ZYyM05mLr6vQbzSqWCR1AanR1oLJApzhiLT3VYWsHT+afPrOuWMM7GrAXJ7b4xZetJag7U/6756wRY/u4aC x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 41ba3dc1-a4da-463b-be36-08d57aa7bafd x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7153060)(7193020); SRVR:AM0PR0402MB3380; x-ms-traffictypediagnostic: AM0PR0402MB3380: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(189930954265078)(162533806227266)(45079756050767)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040501)(2401047)(5005006)(8121501046)(3231101)(944501161)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041288)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(6072148)(201708071742011); SRVR:AM0PR0402MB3380; BCL:0; PCL:0; RULEID:; SRVR:AM0PR0402MB3380; x-forefront-prvs: 0592A9FDE6 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39380400002)(39860400002)(396003)(376002)(346002)(366004)(189003)(199004)(13464003)(8936002)(102836004)(45080400002)(478600001)(53546011)(6506007)(59450400001)(26005)(25786009)(186003)(8676002)(81156014)(81166006)(4326008)(55016002)(6306002)(229853002)(6436002)(66066001)(6246003)(2950100002)(53936002)(9686003)(5250100002)(5660300001)(33656002)(106356001)(966005)(3846002)(14454004)(54906003)(2906002)(110136005)(6116002)(316002)(68736007)(93886005)(74316002)(86362001)(2900100001)(7736002)(305945005)(3660700001)(99286004)(7696005)(76176011)(97736004)(105586002)(3280700002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0402MB3380; H:AM0PR0402MB3330.eurprd04.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: WPHpbBP4JErI753RDcTNkqTcSHZhJVhP9PVefQol/N3p6kYmG/7OOPwRkaQSYqQr+azJD7binSzlX39O34rGsROz4a6i8i0kZodONRoBJuT1eR6nd00JbhIOykimio/laJD7vPub15n32YYrE73mk50rzj3GymZbNEIVX1yuprA= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41ba3dc1-a4da-463b-be36-08d57aa7bafd X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Feb 2018 10:25:15.6861 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3380 Subject: Re: [PATCH edk2-platforms 01/39] Silicon/NXP: Add support for Big Endian Mmio APIs X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Feb 2018 10:19:17 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Laszlo Ersek > Sent: Thursday, February 22, 2018 7:26 PM > To: Leif Lindholm > Cc: michael.d.kinney@intel.com; edk2-devel@lists.01.org; > ard.biesheuvel@linaro.org > Subject: Re: [edk2] [PATCH edk2-platforms 01/39] Silicon/NXP: Add support > for Big Endian Mmio APIs >=20 > On 02/22/18 12:52, Leif Lindholm wrote: > > On Thu, Feb 22, 2018 at 09:34:05AM +0100, Laszlo Ersek wrote: >=20 > >>> But that brings back the complication as to how we have a driver > >>> that needs an LE IO library to write output, and a BE IO library to > >>> manipulate the hardware. > >> > >> Can you please explain the "write output" use case more precisely? > >> > >> My thinking would be this: > >> > >> - Use the IoLib class directly for "writing output" in little endian > >> byte order (which is still unclear to me sorry). > > > > If the IoLib class is mapped to a an instance that byte-swaps (hereto > > referred to as BeIoLib if IoLibSwap is unsuitable), would we not then > > end up mapping the non-swapping, currently implemented in > > BaseLibIoIntrinsic, variant as BeIoLib? Or if not, do we end up > > needing to duplicated all IoLib implementation .infs to provide an > > IoLib and a BeIoLib for each? > > > > It's at that point I burst an aneurysm. > > Am I overthinking/underthinking this? >=20 > We need two library classes, one for talking to LE devices and another to= BE > devices. These should be usable in a given module at the same time, as Ar= d > says. >=20 > Both library classes need to work on both LE and BE CPUs (working from > your suggestion that UEFI might grow BE CPU support at some point). > Whether that is implemented by dumb, separate library instances (yielding > in total 2*2=3D4 library instances), or by smart, CPU-endianness-agnostic > library instances (in total, 2), is a different question. >=20 > Note that such "smarts" could be less than trivial to implement: > - check CPU endianness in each library API? > - or check in the lib constructor only, and flip some function pointers? > - use a dynamic PCD for caching CPU endianness? > - use a HOB for the same? > - use a lib global variable (for caching only on the module level)? >=20 > I think the solution that saves the most on the *source* code size is: > - introduce the BeIoLib class > - duplicate the MMIO functions from BaseIoLibIntrinsic to the one > BeIoLib instance that we introduce > - modify the MMIO functions in *both* lib instances (original LE, and > new BE), like this: >=20 > - If the CPU architecture is known to be bound to a single endianness, > then hardcode the appropriate operation. This can be done with > preprocessor macros, or with the architecture support of INF files / > separate source files. For example, on IA32 and X64, the IoLib > instance should work transparently, unconditionally, and the BeIoLib > instance should byte-swap, unconditionally. >=20 > - On other CPU arches, all the wider-than-byte MMIO functions, in > *both* lib instances should do something like this: >=20 > // > // at file scope > // > STATIC CONST UINT16 mOne =3D 1; >=20 > // > // at function scope > // > if (*(CONST UINT8 *)&mOne =3D=3D 1) { > // > // CPU in LE mode: > // - work transparently in the IoLib instance > // - byte-swap in the BeIoLib instance > // > } else { > // > // CPU in BE mode: > // - byte-swap in the IoLib instance > // - work transparently in the BeIoLib instance > // > } You meant, sort of cpu_to_le and cpu_to_be sort of APIs=20 Thanks Udit =20 > Thanks, > Laszlo > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://emea01.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Flist= s. > 01.org%2Fmailman%2Flistinfo%2Fedk2- > devel&data=3D02%7C01%7Cudit.kumar%40nxp.com%7C930d96bb226d4491df2 > d08d579fc1717%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63654 > 9046016636482&sdata=3D0uPLjiDP60oNVSdbh44gostMx2id%2BzdLYjk8t%2BLwJ > tU%3D&reserved=3D0