Skip to content

Commit

Permalink
Silicon/Marvell/MvI2cDxe: connect all I2C masters at EndOfDxe
Browse files Browse the repository at this point in the history
To ensure that platforms incorporating MvI2cDxe will keep working
as intended once the platform BDS code stops calling ConnectAll(),
connect the I2C masters explicitly at EndOfDxe.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
  • Loading branch information
Ard Biesheuvel authored and wojtas-marcin committed Jun 5, 2020
1 parent c8000ec commit 99b5775
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
60 changes: 57 additions & 3 deletions Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ STATIC MV_I2C_DEVICE_PATH MvI2cDevicePathProtocol = {
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
{
(UINT8) (sizeof(VENDOR_DEVICE_PATH)),
(UINT8) (sizeof(VENDOR_DEVICE_PATH) >> 8),
(UINT8)(OFFSET_OF (MV_I2C_DEVICE_PATH, End)),
(UINT8)(OFFSET_OF (MV_I2C_DEVICE_PATH, End) >> 8),
},
},
EFI_CALLER_ID_GUID
},
0, // Instance
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
Expand Down Expand Up @@ -86,7 +87,7 @@ MvI2cInitialiseController (
DEBUG((DEBUG_ERROR, "MvI2cDxe: I2C device path allocation failed\n"));
return EFI_OUT_OF_RESOURCES;
}
DevicePath->Guid.Guid.Data4[0] = Bus;
DevicePath->Instance = Bus;

/* if attachment succeeds, this gets freed at ExitBootServices */
I2cMasterContext = AllocateZeroPool (sizeof (I2C_MASTER_CONTEXT));
Expand Down Expand Up @@ -139,6 +140,50 @@ MvI2cInitialiseController (
return Status;
}

STATIC
VOID
EFIAPI
OnEndOfDxe (
IN EFI_EVENT Event,
IN VOID *Context
)
{
MV_I2C_DEVICE_PATH *DevicePath;
EFI_DEVICE_PATH_PROTOCOL *DevicePathPointer;
EFI_HANDLE DeviceHandle;
EFI_STATUS Status;

gBS->CloseEvent (Event);

DevicePath = AllocateCopyPool (sizeof (MvI2cDevicePathProtocol),
&MvI2cDevicePathProtocol);
if (DevicePath == NULL) {
DEBUG ((DEBUG_ERROR, "MvI2cDxe: I2C device path allocation failed\n"));
return;
}

do {
DevicePathPointer = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;
Status = gBS->LocateDevicePath (&gEfiI2cMasterProtocolGuid,
&DevicePathPointer,
&DeviceHandle);
if (EFI_ERROR (Status)) {
break;
}

Status = gBS->ConnectController (DeviceHandle, NULL, NULL, TRUE);
DEBUG ((DEBUG_INFO,
"%a: ConnectController () returned %r\n",
__FUNCTION__,
Status));

DevicePath->Instance++;
} while (TRUE);

gBS->FreePool (DevicePath);
}


EFI_STATUS
EFIAPI
MvI2cInitialise (
Expand All @@ -147,6 +192,7 @@ MvI2cInitialise (
)
{
MARVELL_BOARD_DESC_PROTOCOL *BoardDescProtocol;
EFI_EVENT EndOfDxeEvent;
MV_BOARD_I2C_DESC *Desc;
EFI_STATUS Status;
UINTN Index;
Expand Down Expand Up @@ -177,6 +223,14 @@ MvI2cInitialise (

BoardDescProtocol->BoardDescFree (Desc);

Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
OnEndOfDxe,
NULL,
&gEfiEndOfDxeEventGroupGuid,
&EndOfDxeEvent);
ASSERT_EFI_ERROR (Status);

return EFI_SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef struct {

typedef struct {
VENDOR_DEVICE_PATH Guid;
UINTN Instance;
EFI_DEVICE_PATH_PROTOCOL End;
} MV_I2C_DEVICE_PATH;

Expand Down
3 changes: 3 additions & 0 deletions Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@
gMarvellTokenSpaceGuid.PcdI2cBaudRate
gMarvellTokenSpaceGuid.PcdI2cBusCount

[Guids]
gEfiEndOfDxeEventGroupGuid

[Depex]
TRUE

0 comments on commit 99b5775

Please sign in to comment.