From 67e0adad7143b089859e14bbba23301f8092a693 Mon Sep 17 00:00:00 2001 From: Marcin Wojtas Date: Fri, 8 Dec 2017 15:57:36 +0100 Subject: Marvell/Drivers: Modify location and rename the MvEeprom driver MvEeprom driver nesting into additional Devices directory under Silicon/Marvell/Drivers/I2c is redundant. Align its level with MvI2cDxe. Change MvEeprom to MvEepromDxe in order to be more consistent in Marvell drivers naming. On the occasion add sorting in the .inf file. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marcin Wojtas Reviewed-by: Ard Biesheuvel --- Platform/Marvell/Armada70x0Db/Armada70x0Db.fdf | 2 +- Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc | 2 +- .../Drivers/I2c/Devices/MvEeprom/MvEeprom.c | 292 --------------------- .../Drivers/I2c/Devices/MvEeprom/MvEeprom.h | 103 -------- .../Drivers/I2c/Devices/MvEeprom/MvEeprom.inf | 70 ----- .../Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.c | 292 +++++++++++++++++++++ .../Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.h | 103 ++++++++ .../Drivers/I2c/MvEepromDxe/MvEepromDxe.inf | 70 +++++ 8 files changed, 467 insertions(+), 467 deletions(-) delete mode 100644 Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.c delete mode 100644 Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.h delete mode 100644 Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.inf create mode 100644 Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.c create mode 100644 Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.h create mode 100644 Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.inf diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0Db.fdf b/Platform/Marvell/Armada70x0Db/Armada70x0Db.fdf index 24ee32e7c7..7fcb90a7c9 100644 --- a/Platform/Marvell/Armada70x0Db/Armada70x0Db.fdf +++ b/Platform/Marvell/Armada70x0Db/Armada70x0Db.fdf @@ -109,7 +109,7 @@ FvNameGuid = 5eda4200-2c5f-43cb-9da3-0baf74b1b30c INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf INF Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf INF MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.inf - INF Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.inf + INF Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.inf INF Silicon/Marvell/Drivers/Spi/MvSpiOrionDxe/MvSpiOrionDxe.inf INF Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.inf INF Silicon/Marvell/Armada7k8k/Drivers/Armada7k8kRngDxe/Armada7k8kRngDxe.inf diff --git a/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc b/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc index ed3dba609d..9450830793 100644 --- a/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc +++ b/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc @@ -410,7 +410,7 @@ # Platform drivers Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.inf - Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.inf + Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.inf Silicon/Marvell/Drivers/Spi/MvSpiOrionDxe/MvSpiOrionDxe.inf Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.inf Silicon/Marvell/Armada7k8k/Drivers/Armada7k8kRngDxe/Armada7k8kRngDxe.inf diff --git a/Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.c b/Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.c deleted file mode 100644 index d8fd1bfe62..0000000000 --- a/Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.c +++ /dev/null @@ -1,292 +0,0 @@ -/******************************************************************************** -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 -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "MvEeprom.h" - -#define I2C_DEVICE_INDEX(bus, address) (((address) & 0xffff) | (bus) << 16) - -STATIC CONST EFI_GUID I2cGuid = I2C_GUID; - -EFI_DRIVER_BINDING_PROTOCOL gDriverBindingProtocol = { - MvEepromSupported, - MvEepromStart, - MvEepromStop -}; - -EFI_STATUS -EFIAPI -MvEepromSupported ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL - ) -{ - EFI_STATUS Status = EFI_UNSUPPORTED; - EFI_I2C_IO_PROTOCOL *TmpI2cIo; - UINT8 *EepromAddresses; - UINT8 *EepromBuses; - UINTN i; - - Status = gBS->OpenProtocol ( - ControllerHandle, - &gEfiI2cIoProtocolGuid, - (VOID **) &TmpI2cIo, - gImageHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - if (EFI_ERROR(Status)) { - return EFI_UNSUPPORTED; - } - - /* get EEPROM devices' addresses from PCD */ - EepromAddresses = PcdGetPtr (PcdEepromI2cAddresses); - EepromBuses = PcdGetPtr (PcdEepromI2cBuses); - if (EepromAddresses == 0) { - Status = EFI_UNSUPPORTED; - DEBUG((DEBUG_INFO, "MvEepromSupported: I2C device found, but it's not EEPROM\n")); - goto out; - } - - Status = EFI_UNSUPPORTED; - for (i = 0; EepromAddresses[i] != '\0'; i++) { - /* I2C guid must fit and valid DeviceIndex must be provided */ - if (CompareGuid(TmpI2cIo->DeviceGuid, &I2cGuid) && - TmpI2cIo->DeviceIndex == I2C_DEVICE_INDEX(EepromBuses[i], - EepromAddresses[i])) { - DEBUG((DEBUG_INFO, "MvEepromSupported: attached to EEPROM device\n")); - Status = EFI_SUCCESS; - break; - } - } - -out: - gBS->CloseProtocol ( - ControllerHandle, - &gEfiI2cIoProtocolGuid, - gImageHandle, - ControllerHandle - ); - return Status; -} - -EFI_STATUS -EFIAPI -MvEepromTransfer ( - IN CONST MARVELL_EEPROM_PROTOCOL *This, - IN UINT16 Address, - IN UINT32 Length, - IN UINT8 *Buffer, - IN UINT8 Operation - ) -{ - EFI_I2C_REQUEST_PACKET *RequestPacket; - UINTN RequestPacketSize; - EFI_STATUS Status = EFI_SUCCESS; - EEPROM_CONTEXT *EepromContext = EEPROM_SC_FROM_EEPROM(This); - UINT32 BufferLength; - UINT32 Transmitted = 0; - UINT32 CurrentAddress = Address; - - ASSERT(EepromContext != NULL); - ASSERT(EepromContext->I2cIo != NULL); - - RequestPacketSize = sizeof(UINTN) + sizeof (EFI_I2C_OPERATION) * 2; - RequestPacket = AllocateZeroPool (RequestPacketSize); - if (RequestPacket == NULL) - return EFI_OUT_OF_RESOURCES; - /* First operation contains address, the second is buffer */ - RequestPacket->OperationCount = 2; - RequestPacket->Operation[0].LengthInBytes = 2; - RequestPacket->Operation[0].Buffer = AllocateZeroPool ( RequestPacket->Operation[0].LengthInBytes ); - if (RequestPacket->Operation[0].Buffer == NULL) { - FreePool(RequestPacket); - return EFI_OUT_OF_RESOURCES; - } - RequestPacket->Operation[1].Flags = (Operation == EEPROM_READ ? I2C_FLAG_READ : I2C_FLAG_NORESTART); - - while (Length > 0) { - CurrentAddress = Address + Transmitted; - BufferLength = (Length <= MAX_BUFFER_LENGTH ? Length : MAX_BUFFER_LENGTH); - RequestPacket->Operation[0].Buffer[0] = (CurrentAddress >> 8) & 0xff; - RequestPacket->Operation[0].Buffer[1] = CurrentAddress & 0xff; - RequestPacket->Operation[1].LengthInBytes = BufferLength; - RequestPacket->Operation[1].Buffer = Buffer + Transmitted; - Status = EepromContext->I2cIo->QueueRequest(EepromContext->I2cIo, 0, NULL, RequestPacket, NULL); - if (EFI_ERROR(Status)) { - DEBUG((DEBUG_ERROR, "MvEepromTransfer: error %d during transmission\n", Status)); - break; - } - Length -= BufferLength; - Transmitted += BufferLength; - } - - FreePool(RequestPacket->Operation[0].Buffer); - FreePool(RequestPacket); - return Status; -} - -EFI_STATUS -EFIAPI -MvEepromStart ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL - ) -{ - EFI_STATUS Status = EFI_SUCCESS; - EEPROM_CONTEXT *EepromContext; - - EepromContext = AllocateZeroPool (sizeof(EEPROM_CONTEXT)); - if (EepromContext == NULL) { - DEBUG((DEBUG_ERROR, "MvEeprom: allocation fail\n")); - return EFI_OUT_OF_RESOURCES; - } - - EepromContext->ControllerHandle = ControllerHandle; - EepromContext->Signature = EEPROM_SIGNATURE; - EepromContext->EepromProtocol.Transfer = MvEepromTransfer; - - Status = gBS->OpenProtocol ( - ControllerHandle, - &gEfiI2cIoProtocolGuid, - (VOID **) &EepromContext->I2cIo, - gImageHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - if (EFI_ERROR(Status)) { - DEBUG((DEBUG_ERROR, "MvEeprom: failed to open I2cIo\n")); - FreePool(EepromContext); - return EFI_UNSUPPORTED; - } - - EepromContext->EepromProtocol.Identifier = EepromContext->I2cIo->DeviceIndex; - Status = gBS->InstallMultipleProtocolInterfaces ( - &ControllerHandle, - &gMarvellEepromProtocolGuid, &EepromContext->EepromProtocol, - NULL - ); - if (EFI_ERROR(Status)) { - DEBUG((DEBUG_ERROR, "MvEeprom: failed to install EEPROM protocol\n")); - goto fail; - } - - return Status; - -fail: - FreePool(EepromContext); - gBS->CloseProtocol ( - ControllerHandle, - &gEfiI2cIoProtocolGuid, - gImageHandle, - ControllerHandle - ); - - return Status; -} - -EFI_STATUS -EFIAPI -MvEepromStop ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN UINTN NumberOfChildren, - IN EFI_HANDLE *ChildHandleBuffer OPTIONAL - ) -{ - MARVELL_EEPROM_PROTOCOL *EepromProtocol; - EFI_STATUS Status; - EEPROM_CONTEXT *EepromContext; - - Status = gBS->OpenProtocol ( - ControllerHandle, - &gMarvellEepromProtocolGuid, - (VOID **) &EepromProtocol, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - - if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; - } - EepromContext = EEPROM_SC_FROM_EEPROM(EepromProtocol); - - gBS->UninstallMultipleProtocolInterfaces ( - &ControllerHandle, - &gMarvellEepromProtocolGuid, &EepromContext->EepromProtocol, - &gEfiDriverBindingProtocolGuid, &gDriverBindingProtocol, - NULL - ); - gBS->CloseProtocol ( - ControllerHandle, - &gEfiI2cIoProtocolGuid, - gImageHandle, - ControllerHandle - ); - FreePool(EepromContext); - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -MvEepromInitialise ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - EFI_STATUS Status; - Status = gBS->InstallMultipleProtocolInterfaces ( - &ImageHandle, - &gEfiDriverBindingProtocolGuid, &gDriverBindingProtocol, - NULL - ); - return Status; -} diff --git a/Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.h b/Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.h deleted file mode 100644 index b1af645050..0000000000 --- a/Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.h +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************** -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. - -*******************************************************************************/ - -#ifndef __MV_EEPROM_H__ -#define __MV_EEPROM_H__ - -#include - -#define EEPROM_SIGNATURE SIGNATURE_32 ('E', 'E', 'P', 'R') - -#define MAX_BUFFER_LENGTH 64 - -/* - * I2C_FLAG_NORESTART is not part of PI spec, it allows to continue - * transmission without repeated start operation. - * FIXME: This flag is also defined in Drivers/I2c/MvI2cDxe/MvI2cDxe.h - * and it's important to have both version synced. This solution is - * temporary and shared flag should be used by both files. - * Situation is analogous with I2C_GUID, which also should be common, but is - * for now defined same way in two header files. - */ -#define I2C_FLAG_NORESTART 0x00000002 -#define I2C_GUID \ - { \ - 0xadc1901b, 0xb83c, 0x4831, { 0x8f, 0x59, 0x70, 0x89, 0x8f, 0x26, 0x57, 0x1e } \ - } - -typedef struct { - UINT32 Signature; - EFI_HANDLE ControllerHandle; - EFI_I2C_IO_PROTOCOL *I2cIo; - MARVELL_EEPROM_PROTOCOL EepromProtocol; -} EEPROM_CONTEXT; - -#define EEPROM_SC_FROM_IO(a) CR (a, EEPROM_CONTEXT, I2cIo, EEPROM_SIGNATURE) -#define EEPROM_SC_FROM_EEPROM(a) CR (a, EEPROM_CONTEXT, EepromProtocol, EEPROM_SIGNATURE) - -EFI_STATUS -EFIAPI -MvEepromSupported ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL - ); - -EFI_STATUS -EFIAPI -MvEepromStart ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL - ); - -EFI_STATUS -EFIAPI -MvEepromStop ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN UINTN NumberOfChildren, - IN EFI_HANDLE *ChildHandleBuffer OPTIONAL - ); - -EFI_STATUS -EFIAPI -MvEepromTransfer ( - IN CONST MARVELL_EEPROM_PROTOCOL *This, - IN UINT16 Address, - IN UINT32 Length, - IN UINT8 *Buffer, - IN UINT8 Operation - ); -#endif // __MV_EEPROM_H__ diff --git a/Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.inf b/Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.inf deleted file mode 100644 index 510b5502dc..0000000000 --- a/Silicon/Marvell/Drivers/I2c/Devices/MvEeprom/MvEeprom.inf +++ /dev/null @@ -1,70 +0,0 @@ -# -# 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 = 0x00010005 - BASE_NAME = MvEeprom - FILE_GUID = 59fc3843-d8d4-40aa-ae07-38967138509c - MODULE_TYPE = DXE_DRIVER - VERSION_STRING = 1.0 - ENTRY_POINT = MvEepromInitialise - -[Sources.common] - MvEeprom.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - ArmPlatformPkg/ArmPlatformPkg.dec - ArmPkg/ArmPkg.dec - Silicon/Marvell/Marvell.dec - -[LibraryClasses] - IoLib - PcdLib - BaseLib - BaseMemoryLib - DebugLib - UefiLib - UefiDriverEntryPoint - UefiBootServicesTableLib - -[Protocols] - gEfiI2cIoProtocolGuid - gEfiDriverBindingProtocolGuid - gMarvellEepromProtocolGuid - -[Pcd] - gMarvellTokenSpaceGuid.PcdEepromI2cAddresses - gMarvellTokenSpaceGuid.PcdEepromI2cBuses - -[Depex] - TRUE diff --git a/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.c b/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.c new file mode 100644 index 0000000000..9d2f650955 --- /dev/null +++ b/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.c @@ -0,0 +1,292 @@ +/******************************************************************************** +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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "MvEepromDxe.h" + +#define I2C_DEVICE_INDEX(bus, address) (((address) & 0xffff) | (bus) << 16) + +STATIC CONST EFI_GUID I2cGuid = I2C_GUID; + +EFI_DRIVER_BINDING_PROTOCOL gDriverBindingProtocol = { + MvEepromSupported, + MvEepromStart, + MvEepromStop +}; + +EFI_STATUS +EFIAPI +MvEepromSupported ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ) +{ + EFI_STATUS Status = EFI_UNSUPPORTED; + EFI_I2C_IO_PROTOCOL *TmpI2cIo; + UINT8 *EepromAddresses; + UINT8 *EepromBuses; + UINTN i; + + Status = gBS->OpenProtocol ( + ControllerHandle, + &gEfiI2cIoProtocolGuid, + (VOID **) &TmpI2cIo, + gImageHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + if (EFI_ERROR(Status)) { + return EFI_UNSUPPORTED; + } + + /* get EEPROM devices' addresses from PCD */ + EepromAddresses = PcdGetPtr (PcdEepromI2cAddresses); + EepromBuses = PcdGetPtr (PcdEepromI2cBuses); + if (EepromAddresses == 0) { + Status = EFI_UNSUPPORTED; + DEBUG((DEBUG_INFO, "MvEepromSupported: I2C device found, but it's not EEPROM\n")); + goto out; + } + + Status = EFI_UNSUPPORTED; + for (i = 0; EepromAddresses[i] != '\0'; i++) { + /* I2C guid must fit and valid DeviceIndex must be provided */ + if (CompareGuid(TmpI2cIo->DeviceGuid, &I2cGuid) && + TmpI2cIo->DeviceIndex == I2C_DEVICE_INDEX(EepromBuses[i], + EepromAddresses[i])) { + DEBUG((DEBUG_INFO, "MvEepromSupported: attached to EEPROM device\n")); + Status = EFI_SUCCESS; + break; + } + } + +out: + gBS->CloseProtocol ( + ControllerHandle, + &gEfiI2cIoProtocolGuid, + gImageHandle, + ControllerHandle + ); + return Status; +} + +EFI_STATUS +EFIAPI +MvEepromTransfer ( + IN CONST MARVELL_EEPROM_PROTOCOL *This, + IN UINT16 Address, + IN UINT32 Length, + IN UINT8 *Buffer, + IN UINT8 Operation + ) +{ + EFI_I2C_REQUEST_PACKET *RequestPacket; + UINTN RequestPacketSize; + EFI_STATUS Status = EFI_SUCCESS; + EEPROM_CONTEXT *EepromContext = EEPROM_SC_FROM_EEPROM(This); + UINT32 BufferLength; + UINT32 Transmitted = 0; + UINT32 CurrentAddress = Address; + + ASSERT(EepromContext != NULL); + ASSERT(EepromContext->I2cIo != NULL); + + RequestPacketSize = sizeof(UINTN) + sizeof (EFI_I2C_OPERATION) * 2; + RequestPacket = AllocateZeroPool (RequestPacketSize); + if (RequestPacket == NULL) + return EFI_OUT_OF_RESOURCES; + /* First operation contains address, the second is buffer */ + RequestPacket->OperationCount = 2; + RequestPacket->Operation[0].LengthInBytes = 2; + RequestPacket->Operation[0].Buffer = AllocateZeroPool ( RequestPacket->Operation[0].LengthInBytes ); + if (RequestPacket->Operation[0].Buffer == NULL) { + FreePool(RequestPacket); + return EFI_OUT_OF_RESOURCES; + } + RequestPacket->Operation[1].Flags = (Operation == EEPROM_READ ? I2C_FLAG_READ : I2C_FLAG_NORESTART); + + while (Length > 0) { + CurrentAddress = Address + Transmitted; + BufferLength = (Length <= MAX_BUFFER_LENGTH ? Length : MAX_BUFFER_LENGTH); + RequestPacket->Operation[0].Buffer[0] = (CurrentAddress >> 8) & 0xff; + RequestPacket->Operation[0].Buffer[1] = CurrentAddress & 0xff; + RequestPacket->Operation[1].LengthInBytes = BufferLength; + RequestPacket->Operation[1].Buffer = Buffer + Transmitted; + Status = EepromContext->I2cIo->QueueRequest(EepromContext->I2cIo, 0, NULL, RequestPacket, NULL); + if (EFI_ERROR(Status)) { + DEBUG((DEBUG_ERROR, "MvEepromTransfer: error %d during transmission\n", Status)); + break; + } + Length -= BufferLength; + Transmitted += BufferLength; + } + + FreePool(RequestPacket->Operation[0].Buffer); + FreePool(RequestPacket); + return Status; +} + +EFI_STATUS +EFIAPI +MvEepromStart ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ) +{ + EFI_STATUS Status = EFI_SUCCESS; + EEPROM_CONTEXT *EepromContext; + + EepromContext = AllocateZeroPool (sizeof(EEPROM_CONTEXT)); + if (EepromContext == NULL) { + DEBUG((DEBUG_ERROR, "MvEeprom: allocation fail\n")); + return EFI_OUT_OF_RESOURCES; + } + + EepromContext->ControllerHandle = ControllerHandle; + EepromContext->Signature = EEPROM_SIGNATURE; + EepromContext->EepromProtocol.Transfer = MvEepromTransfer; + + Status = gBS->OpenProtocol ( + ControllerHandle, + &gEfiI2cIoProtocolGuid, + (VOID **) &EepromContext->I2cIo, + gImageHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + if (EFI_ERROR(Status)) { + DEBUG((DEBUG_ERROR, "MvEeprom: failed to open I2cIo\n")); + FreePool(EepromContext); + return EFI_UNSUPPORTED; + } + + EepromContext->EepromProtocol.Identifier = EepromContext->I2cIo->DeviceIndex; + Status = gBS->InstallMultipleProtocolInterfaces ( + &ControllerHandle, + &gMarvellEepromProtocolGuid, &EepromContext->EepromProtocol, + NULL + ); + if (EFI_ERROR(Status)) { + DEBUG((DEBUG_ERROR, "MvEeprom: failed to install EEPROM protocol\n")); + goto fail; + } + + return Status; + +fail: + FreePool(EepromContext); + gBS->CloseProtocol ( + ControllerHandle, + &gEfiI2cIoProtocolGuid, + gImageHandle, + ControllerHandle + ); + + return Status; +} + +EFI_STATUS +EFIAPI +MvEepromStop ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer OPTIONAL + ) +{ + MARVELL_EEPROM_PROTOCOL *EepromProtocol; + EFI_STATUS Status; + EEPROM_CONTEXT *EepromContext; + + Status = gBS->OpenProtocol ( + ControllerHandle, + &gMarvellEepromProtocolGuid, + (VOID **) &EepromProtocol, + This->DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + EepromContext = EEPROM_SC_FROM_EEPROM(EepromProtocol); + + gBS->UninstallMultipleProtocolInterfaces ( + &ControllerHandle, + &gMarvellEepromProtocolGuid, &EepromContext->EepromProtocol, + &gEfiDriverBindingProtocolGuid, &gDriverBindingProtocol, + NULL + ); + gBS->CloseProtocol ( + ControllerHandle, + &gEfiI2cIoProtocolGuid, + gImageHandle, + ControllerHandle + ); + FreePool(EepromContext); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +MvEepromInitialise ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + Status = gBS->InstallMultipleProtocolInterfaces ( + &ImageHandle, + &gEfiDriverBindingProtocolGuid, &gDriverBindingProtocol, + NULL + ); + return Status; +} diff --git a/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.h b/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.h new file mode 100644 index 0000000000..b1af645050 --- /dev/null +++ b/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.h @@ -0,0 +1,103 @@ +/******************************************************************************** +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. + +*******************************************************************************/ + +#ifndef __MV_EEPROM_H__ +#define __MV_EEPROM_H__ + +#include + +#define EEPROM_SIGNATURE SIGNATURE_32 ('E', 'E', 'P', 'R') + +#define MAX_BUFFER_LENGTH 64 + +/* + * I2C_FLAG_NORESTART is not part of PI spec, it allows to continue + * transmission without repeated start operation. + * FIXME: This flag is also defined in Drivers/I2c/MvI2cDxe/MvI2cDxe.h + * and it's important to have both version synced. This solution is + * temporary and shared flag should be used by both files. + * Situation is analogous with I2C_GUID, which also should be common, but is + * for now defined same way in two header files. + */ +#define I2C_FLAG_NORESTART 0x00000002 +#define I2C_GUID \ + { \ + 0xadc1901b, 0xb83c, 0x4831, { 0x8f, 0x59, 0x70, 0x89, 0x8f, 0x26, 0x57, 0x1e } \ + } + +typedef struct { + UINT32 Signature; + EFI_HANDLE ControllerHandle; + EFI_I2C_IO_PROTOCOL *I2cIo; + MARVELL_EEPROM_PROTOCOL EepromProtocol; +} EEPROM_CONTEXT; + +#define EEPROM_SC_FROM_IO(a) CR (a, EEPROM_CONTEXT, I2cIo, EEPROM_SIGNATURE) +#define EEPROM_SC_FROM_EEPROM(a) CR (a, EEPROM_CONTEXT, EepromProtocol, EEPROM_SIGNATURE) + +EFI_STATUS +EFIAPI +MvEepromSupported ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ); + +EFI_STATUS +EFIAPI +MvEepromStart ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ); + +EFI_STATUS +EFIAPI +MvEepromStop ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer OPTIONAL + ); + +EFI_STATUS +EFIAPI +MvEepromTransfer ( + IN CONST MARVELL_EEPROM_PROTOCOL *This, + IN UINT16 Address, + IN UINT32 Length, + IN UINT8 *Buffer, + IN UINT8 Operation + ); +#endif // __MV_EEPROM_H__ diff --git a/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.inf b/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.inf new file mode 100644 index 0000000000..9b19db7fe4 --- /dev/null +++ b/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.inf @@ -0,0 +1,70 @@ +# +# 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 = 0x00010005 + BASE_NAME = MvEepromDxe + FILE_GUID = 59fc3843-d8d4-40aa-ae07-38967138509c + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = MvEepromInitialise + +[Sources.common] + MvEepromDxe.c + +[Packages] + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Marvell/Marvell.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + IoLib + PcdLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + +[Protocols] + gEfiDriverBindingProtocolGuid + gEfiI2cIoProtocolGuid + gMarvellEepromProtocolGuid + +[Pcd] + gMarvellTokenSpaceGuid.PcdEepromI2cAddresses + gMarvellTokenSpaceGuid.PcdEepromI2cBuses + +[Depex] + TRUE -- cgit v1.2.3