From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2001:ba8:0:1d4::6950:5845; helo=duck.fensystems.co.uk; envelope-from=mcb30@ipxe.org; receiver=edk2-devel@lists.01.org Received: from duck.fensystems.co.uk (duck.fensystems.co.uk [IPv6:2001:ba8:0:1d4::6950:5845]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C698022497F56 for ; Mon, 16 Apr 2018 15:14:28 -0700 (PDT) Received: from pudding.home (cbs92326-cmbg19-2-0-cust10.5-4.cable.virginm.net [86.1.148.75]) by duck.fensystems.co.uk (Postfix) with ESMTPSA id B692FF515; Mon, 16 Apr 2018 23:14:26 +0100 (BST) To: Laszlo Ersek , "Kinney, Michael D" , Leif Lindholm Cc: "edk2-devel@lists.01.org" , "Gao, Liming" References: <20180413174211.858-1-leif.lindholm@linaro.org> <20180413193143.t45tua3yi7sopk4d@bivouac.eciton.net> <20180416100712.6v642ycksvmoffvt@bivouac.eciton.net> <52ea5684-380d-0519-2545-6ef7f62198ae@ipxe.org> <09cc135a-c3b7-bcbd-1a71-6454e3ba7623@redhat.com> From: Michael Brown Message-ID: <52f131ae-ed51-9276-ac91-e3dded7472e2@ipxe.org> Date: Mon, 16 Apr 2018 23:14:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <09cc135a-c3b7-bcbd-1a71-6454e3ba7623@redhat.com> Subject: Re: [PATCH] MdePkg: add big-endian MMIO BaseBeIoLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Apr 2018 22:14:29 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit On 16/04/18 21:42, Laszlo Ersek wrote: > On 04/16/18 16:34, Michael Brown wrote: >> On 16/04/18 15:10, Kinney, Michael D wrote: >>> I think we only need a single lib class and lib >>> Instance that does the byte swap and we should >>> not use Le or Be in any of the names of the class, >>> instance, or APIs.  Just "Swap". >> >> I may have misunderstood, but wouldn't using "Swap" within the API names >> effectively encode knowledge of the endianness of the _build_ platform >> into the source code?  This would prevent the same source code being >> built for both little-endian and big-endian CPUs. > > Under this scenario, all drivers meant to be portable to both byte > orders would have to: > - link against both IoLib and IoSwapLib, > - determine at device binding time, from CPU endianness and device > endianness combined, whether swapping was needed for that device, > - call the IoLib or IoSwapLib APIs through wrapper functions, or > function pointers. Given that "all drivers meant to be portable to both byte orders" would include almost the complete set of PCI device drivers, that sounds like an incredibly large amount of unnecessarily duplicated boilerplate code. Maybe we need some kind of wrapper library that provides an abstraction layer to automatically determine whether or not swapping is needed and then call the appropriate IoLib or IoSwapLib API function. For example, the wrapper library could provide a function SwapIfNeededForBigEndianDeviceMmioRead16() which would perform a runtime check on each call to determine the current CPU endianness and then call MmioRead16() or SwapMmioRead16() as appropriate. Michael