On Thu, Nov 17, 2016 at 05:33:04AM +0100, Marcin Wojtas wrote:
In order to use numerous UEFI drivers based on PCI bus, PciEmulation driver is implemented. It enables proper registration of platform devices as NonDiscoverableDevices and use generic EDK2 PciEmulation solution.
Used devices are enabled basing on PCD's and Armada 70x0 hardware description in a dedicated structure.
Happy with the functionality, a couple of cosmetic suggestions inline below.
Regards,
Leif
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Marcin Wojtas mw@semihalf.com Signed-off-by: Jan Dabros jsd@semihalf.com
.../Marvell/PortingGuide/PciEmulation.txt | 31 +++ Platforms/Marvell/Marvell.dec | 5 + Platforms/Marvell/PciEmulation/PciEmulation.c | 221 +++++++++++++++++++++ Platforms/Marvell/PciEmulation/PciEmulation.inf | 61 ++++++ 4 files changed, 318 insertions(+) create mode 100644 Documentation/Marvell/PortingGuide/PciEmulation.txt create mode 100644 Platforms/Marvell/PciEmulation/PciEmulation.c create mode 100644 Platforms/Marvell/PciEmulation/PciEmulation.inf
diff --git a/Documentation/Marvell/PortingGuide/PciEmulation.txt b/Documentation/Marvell/PortingGuide/PciEmulation.txt new file mode 100644 index 0000000..ec1afbc --- /dev/null +++ b/Documentation/Marvell/PortingGuide/PciEmulation.txt @@ -0,0 +1,31 @@ +PciEmulation configuration +-------------------------- +Installation of various NonDiscoverable devices via PciEmulation driver is performed +via set of PCDs. Following are available:
- gMarvellTokenSpaceGuid.PcdPciEXhci
+Indicates, which Xhci devices are used.
- gMarvellTokenSpaceGuid.PcdPciEAhci
+Indicates, which Ahci devices are used.
- gMarvellTokenSpaceGuid.PcdPciESdhci
+Indicates, which Sdhci devices are used.
+All above PCD's correspond to hardware description in a dedicated structure:
+STATIC PCI_E_PLATFORM_DESC A70x0PlatDescTemplate
+in Platforms/Marvell/PciEmulation/PciEmulation.c file. It comprises device +count, base addresses, register region size and DMA-coherency type.
+Examples +-------- +Assuming we want to enable second XHCI port and one SDHCI port on Armada +70x0 board, following needs to be declared:
- gMarvellTokenSpaceGuid.PcdPciEXhci|{ 0x0 0x1 }
- gMarvellTokenSpaceGuid.PcdPciESdhci|{ 0x1 }
diff --git a/Platforms/Marvell/Marvell.dec b/Platforms/Marvell/Marvell.dec index db99230..f1d2def 100644 --- a/Platforms/Marvell/Marvell.dec +++ b/Platforms/Marvell/Marvell.dec @@ -209,6 +209,11 @@ gMarvellTokenSpaceGuid.PcdPp2XlgBaseAddress|0|UINT64|0x3000031 gMarvellTokenSpaceGuid.PcdPp2XlgDevSize|0|UINT32|0x3000032 +#PciEmulation
- gMarvellTokenSpaceGuid.PcdPciEXhci|{ 0x0 }|VOID*|0x3000033
- gMarvellTokenSpaceGuid.PcdPciEAhci|{ 0x0 }|VOID*|0x3000034
- gMarvellTokenSpaceGuid.PcdPciESdhci|{ 0x0 }|VOID*|0x3000035
#ResetLib gMarvellTokenSpaceGuid.PcdResetRegAddress|0|UINT64|0x40000050 gMarvellTokenSpaceGuid.PcdResetRegMask|0|UINT32|0x4000051 diff --git a/Platforms/Marvell/PciEmulation/PciEmulation.c b/Platforms/Marvell/PciEmulation/PciEmulation.c new file mode 100644 index 0000000..56e66f5 --- /dev/null +++ b/Platforms/Marvell/PciEmulation/PciEmulation.c @@ -0,0 +1,221 @@ +/******************************************************************************** +Copyright (C) 2016 Marvell International Ltd.
+Marvell BSD License Option
+If you received this File from Marvell, you may opt to use, redistribute and/or +modify this File under the following licensing terms. +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- Neither the name of Marvell nor the names of its contributors may be
- used to endorse or promote products derived from this software without
- specific prior written permission.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+#include <PiDxe.h>
+#include <Library/DebugLib.h> +#include <Library/NonDiscoverableDeviceRegistrationLib.h> +#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/EmbeddedExternalDevice.h>
+typedef struct {
- // XHCI
- UINT8 XhciDevCount;
- UINTN XhciBaseAddresses[4];
- UINTN XhciMemSize[4];
- NON_DISCOVERABLE_DEVICE_DMA_TYPE XhciDmaType[4];
- // AHCI
- UINT8 AhciDevCount;
- UINTN AhciBaseAddresses[4];
- UINTN AhciMemSize[4];
- NON_DISCOVERABLE_DEVICE_DMA_TYPE AhciDmaType[4];
- // SDHCI
- UINT8 SdhciDevCount;
- UINTN SdhciBaseAddresses[4];
- UINTN SdhciMemSize[4];
- NON_DISCOVERABLE_DEVICE_DMA_TYPE SdhciDmaType[4];
+} PCI_E_PLATFORM_DESC;
(Most EDK2 sources use PCIE rather than PCI_E.)
+STATIC PCI_E_PLATFORM_DESC A70x0PlatDescTemplate = {
I think that should have an m-prefix?
- 2, // XHCI
- { 0xF2500000, 0xF2510000 },
- { SIZE_16KB, SIZE_16KB },
- { NonDiscoverableDeviceDmaTypeCoherent, NonDiscoverableDeviceDmaTypeCoherent },
- 1, // AHCI
- { 0xF2540000 },
- { SIZE_8KB },
- { NonDiscoverableDeviceDmaTypeCoherent },
- 1, // SDHCI
- { 0xF06E0000 },
- { SIZE_1KB },
- { NonDiscoverableDeviceDmaTypeCoherent }
+};
+STATIC UINT8 * CONST XhciDeviceTable = FixedPcdGetPtr (PcdPciEXhci); +STATIC UINT8 * CONST AhciDeviceTable = FixedPcdGetPtr (PcdPciEAhci); +STATIC UINT8 * CONST SdhciDeviceTable = FixedPcdGetPtr (PcdPciESdhci);
How about #define DEV_ENABLED(type, index) (type ## DeviceTable[index]) ...
+STATIC +EFI_STATUS +PciEmulationInitXhci (
- )
+{
- PCI_E_PLATFORM_DESC *Desc = &A70x0PlatDescTemplate;
- EFI_STATUS Status;
- UINT8 i;
- if (PcdGetSize (PcdPciEXhci) < Desc->XhciDevCount) {
- DEBUG((DEBUG_ERROR, "PciEmulation: Wrong PcdPciEXhci format\n"));
- return EFI_INVALID_PARAMETER;
- }
- for (i = 0; i < Desc->XhciDevCount; i++) {
- if (XhciDeviceTable[i] == 0) {
... if (DEV_ENABLED (Xhci, i)) { ?
And so on?
continue;
- }
- Status = RegisterNonDiscoverableMmioDevice (
NonDiscoverableDeviceTypeXhci,
Desc->XhciDmaType[i],
NULL,
NULL,
1,
Desc->XhciBaseAddresses[i], Desc->XhciMemSize[i]
);
- if (EFI_ERROR(Status)) {
DEBUG((DEBUG_ERROR, "PciEmulation: Cannot install Xhci device with ID=%d\n", i));
It's not really an ID. How about just "Cannot install Xhci device %d\n"? And same below.
return Status;
- }
- }
- return EFI_SUCCESS;
+}
+STATIC +EFI_STATUS +PciEmulationInitAhci (
- )
+{
- PCI_E_PLATFORM_DESC *Desc = &A70x0PlatDescTemplate;
- EFI_STATUS Status;
- UINT8 i;
- if (PcdGetSize (PcdPciEAhci) < Desc->AhciDevCount) {
- DEBUG((DEBUG_ERROR, "PciEmulation: Wrong PcdPciEAhci format\n"));
- return EFI_INVALID_PARAMETER;
- }
- for (i = 0; i < Desc->AhciDevCount; i++) {
- if (AhciDeviceTable[i] == 0) {
continue;
- }
- Status = RegisterNonDiscoverableMmioDevice (
NonDiscoverableDeviceTypeAhci,
Desc->AhciDmaType[i],
NULL,
NULL,
1,
Desc->AhciBaseAddresses[i], Desc->AhciMemSize[i]
);
- if (EFI_ERROR(Status)) {
DEBUG((DEBUG_ERROR, "PciEmulation: Cannot install Ahci device with ID=%d\n", i));
return Status;
- }
- }
- return EFI_SUCCESS;
+}
+STATIC +EFI_STATUS +PciEmulationInitSdhci (
- )
+{
- PCI_E_PLATFORM_DESC *Desc = &A70x0PlatDescTemplate;
- EFI_STATUS Status;
- UINT8 i;
- if (PcdGetSize (PcdPciESdhci) < Desc->SdhciDevCount) {
- DEBUG((DEBUG_ERROR, "PciEmulation: Wrong PcdPciESdhci format\n"));
- return EFI_INVALID_PARAMETER;
- }
- for (i = 0; i < Desc->SdhciDevCount; i++) {
- if (SdhciDeviceTable[i] == 0) {
continue;
- }
- Status = RegisterNonDiscoverableMmioDevice (
NonDiscoverableDeviceTypeSdhci,
Desc->SdhciDmaType[i],
NULL,
NULL,
1,
Desc->SdhciBaseAddresses[i], Desc->SdhciMemSize[i]
);
- if (EFI_ERROR(Status)) {
DEBUG((DEBUG_ERROR, "PciEmulation: Cannot install Sdhci device with ID=%d\n", i));
return Status;
- }
- }
- return EFI_SUCCESS;
+}
+// +// Below function is used to parse devices information from PCD strings. +// Once obtained, the resources are used for registration of +// NonDiscoverable devices. +// +EFI_STATUS +EFIAPI +PciEmulationEntryPoint (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- EFI_STATUS Status;
- Status = PciEmulationInitXhci();
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Status = PciEmulationInitAhci();
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Status = PciEmulationInitSdhci();
- if (EFI_ERROR(Status)) {
- return Status;
- }
- return EFI_SUCCESS;
+} diff --git a/Platforms/Marvell/PciEmulation/PciEmulation.inf b/Platforms/Marvell/PciEmulation/PciEmulation.inf new file mode 100644 index 0000000..5d569b9 --- /dev/null +++ b/Platforms/Marvell/PciEmulation/PciEmulation.inf @@ -0,0 +1,61 @@ +# Copyright (C) 2016 Marvell International Ltd. +# +# Marvell BSD License Option +# +# If you received this File from Marvell, you may opt to use, redistribute and/or +# modify this File under the following licensing terms. +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of Marvell nor the names of its contributors may be +# used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#
+[Defines]
- INF_VERSION = 0x00010019
- BASE_NAME = PciEmulation
- FILE_GUID = 3dfa08da-923b-4841-9435-c77a604d7493
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = PciEmulationEntryPoint
+[Sources.common]
- PciEmulation.c
+[Packages]
- EmbeddedPkg/EmbeddedPkg.dec
- MdeModulePkg/MdeModulePkg.dec
- MdePkg/MdePkg.dec
- OpenPlatformPkg/Platforms/Marvell/Marvell.dec
+[LibraryClasses]
- NonDiscoverableDeviceRegistrationLib
- UefiDriverEntryPoint
+[Pcd]
- gMarvellTokenSpaceGuid.PcdPciEXhci
- gMarvellTokenSpaceGuid.PcdPciEAhci
- gMarvellTokenSpaceGuid.PcdPciESdhci
+[Depex]
- TRUE
-- 1.8.3.1