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.43; helo=eur03-am5-obe.outbound.protection.outlook.com; envelope-from=pankaj.bansal@nxp.com; receiver=edk2-devel@lists.01.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30043.outbound.protection.outlook.com [40.107.3.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 80A2022436939 for ; Fri, 23 Feb 2018 00:34:09 -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=H9QZ3zhOni8hCF3qY3dl193Oz9b3kmeaqKXDUMZ2nk8=; b=Cd5uJNq8//33el55Tj0lhHHPiKDGimCsTrcP2FpQpo5OgbEIX//oc7u6ZocQboJMeO7F2rdbEjSkvy8dpS08gzcZHsfiN2gkXmgeSc4dB+QS6tMvDJwZpMW1HHJwl9flPXZWfhHi435aZXaE65msnRu4pQ4YrLGCoSua+sL0LFc= Received: from AM0PR0402MB3940.eurprd04.prod.outlook.com (52.133.40.140) by AM0PR0402MB3426.eurprd04.prod.outlook.com (52.133.45.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.506.18; Fri, 23 Feb 2018 08:40:08 +0000 Received: from AM0PR0402MB3940.eurprd04.prod.outlook.com ([fe80::4815:8101:2a92:25ea]) by AM0PR0402MB3940.eurprd04.prod.outlook.com ([fe80::4815:8101:2a92:25ea%13]) with mapi id 15.20.0506.023; Fri, 23 Feb 2018 08:40:08 +0000 From: Pankaj Bansal 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: AQHTpwOBs6WgNXJNN0Obxj0PpJnLXaOvCB6AgAAFmACAADAhAIAA4+2AgAA3aICAACKogIABNlXQ Date: Fri, 23 Feb 2018 08:40:08 +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=pankaj.bansal@nxp.com; x-originating-ip: [192.88.169.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM0PR0402MB3426; 7:UMnFZFIt1ZGCWX0LRhh0dyzLZ/G6IDRjpsJTTxhrlUvwIGMZb38XZbOq8mO3+R/JnBdnQxdqzOXB0pTmoTFKxEt28FyoNqknEh2eTxgXF0BjMmFbQfB1pVcWoUidrBf0VPN7fQU72ERFRdrHXc5QkjM0GMAEdRKvQY3luJcm6VLF+yCtcX8AF4VV1Gs+9BwhqL32Eapt+Lf0GOc1oFWD6Js/CMOWkpeHm5EbrTiuet//jLvCa9vRECBLNwLj1LlW x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: daa6bcb7-d3e6-4fa1-8ee1-08d57a990b54 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7153060)(7193020); SRVR:AM0PR0402MB3426; x-ms-traffictypediagnostic: AM0PR0402MB3426: 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)(8121501046)(5005006)(3231101)(944501161)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041288)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011); SRVR:AM0PR0402MB3426; BCL:0; PCL:0; RULEID:; SRVR:AM0PR0402MB3426; x-forefront-prvs: 0592A9FDE6 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(346002)(366004)(376002)(39380400002)(396003)(13464003)(53754006)(189003)(199004)(3660700001)(105586002)(99286004)(2950100002)(106356001)(6116002)(7696005)(66066001)(6436002)(3846002)(966005)(5660300001)(6506007)(53546011)(97736004)(478600001)(59450400001)(25786009)(45080400002)(14454004)(229853002)(55016002)(26005)(3280700002)(4326008)(6306002)(102836004)(68736007)(9686003)(186003)(6246003)(7736002)(2906002)(53936002)(33656002)(76176011)(74316002)(86362001)(316002)(81156014)(5250100002)(54906003)(8936002)(81166006)(305945005)(93886005)(2900100001)(110136005)(8676002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0402MB3426; H:AM0PR0402MB3940.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: 7tnyVmKvR0tv6L2ckjTx7o1Qix6W6im+yKPbsIXJzNvCAd99sS+airDtWqMTN3JjXA3cK50yfBhHL4wU3njqI2S89Dfy6Bx6Zj9sSjG66xT2LAfFuUNUaLOLUE9GzazRa9/2eQvXSbepThsdE2d6Qw+jb/bcOgyRxoZ0X0OUkiY= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: daa6bcb7-d3e6-4fa1-8ee1-08d57a990b54 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Feb 2018 08:40:08.0844 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3426 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 08:34:11 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi All > -----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 yo= ur > 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 li= brary > 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 > // > } I suggest this approach : 1. Add BeMmio* functions in existing IoLib. BeMmio* functions will swap the= input before write and swap output after read and so on. Mmio* functions will not perform any byte swapping 2. create second instance (a copy) of this IoLib for CPUs that are Big Endi= an. We can call it BigEndianIoLib. In this library Mmio* functions will swap the input before write and s= wap output after read and so on. BeMmio* functions will not perform any byte swapping. 3. Include the instance of IoLib in dsc file based on cpu endianness that t= he platform wants to use. i.e. If BIG_ENDIAN =3D=3D FALSE IoLib | ..\..\..\IoLib Else IoLib | ..\..\..\BigEndianIoLib 4. The devices that are Big endian in platform will always call BeMmio* fun= ctions. They need not check CPU endianness. 5. The devices that are Little endian in platform will always call Mmio* fu= nctions. They need not check CPU endianness. >=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%7Cpankaj.bansal%40nxp.com%7C930d96bb226d4491 > df2d08d579fc1717%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6 > 36549046015230218&sdata=3DOtqNxwO10GcZw1GgvSdocBCwNFuuO2Am23eN > bj1xJ1g%3D&reserved=3D0