PlatformDxe.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /** @file
  2. LS1043 DXE platform driver.
  3. Copyright 2018-2020 NXP
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Library/BaseLib.h>
  7. #include <Library/BaseMemoryLib.h>
  8. #include <Library/DebugLib.h>
  9. #include <Library/MemoryAllocationLib.h>
  10. #include <Library/PcdLib.h>
  11. #include <Library/UefiBootServicesTableLib.h>
  12. #include <Library/UefiLib.h>
  13. #include <Soc.h>
  14. #include <Protocol/NonDiscoverableDevice.h>
  15. typedef struct {
  16. EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR StartDesc;
  17. UINT8 EndDesc;
  18. } ADDRESS_SPACE_DESCRIPTOR;
  19. STATIC ADDRESS_SPACE_DESCRIPTOR mI2cDesc[LS1043A_I2C_NUM_CONTROLLERS];
  20. STATIC
  21. EFI_STATUS
  22. RegisterDevice (
  23. IN EFI_GUID *TypeGuid,
  24. IN ADDRESS_SPACE_DESCRIPTOR *Desc,
  25. OUT EFI_HANDLE *Handle
  26. )
  27. {
  28. NON_DISCOVERABLE_DEVICE *Device;
  29. EFI_STATUS Status;
  30. Device = (NON_DISCOVERABLE_DEVICE *)AllocateZeroPool (sizeof (*Device));
  31. if (Device == NULL) {
  32. return EFI_OUT_OF_RESOURCES;
  33. }
  34. Device->Type = TypeGuid;
  35. Device->DmaType = NonDiscoverableDeviceDmaTypeNonCoherent;
  36. Device->Resources = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Desc;
  37. Status = gBS->InstallMultipleProtocolInterfaces (Handle,
  38. &gEdkiiNonDiscoverableDeviceProtocolGuid, Device,
  39. NULL);
  40. if (EFI_ERROR (Status)) {
  41. goto FreeDevice;
  42. }
  43. return EFI_SUCCESS;
  44. FreeDevice:
  45. FreePool (Device);
  46. return Status;
  47. }
  48. VOID
  49. PopulateI2cInformation (
  50. IN VOID
  51. )
  52. {
  53. UINT32 Index;
  54. for (Index = 0; Index < ARRAY_SIZE (mI2cDesc); Index++) {
  55. mI2cDesc[Index].StartDesc.Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR;
  56. mI2cDesc[Index].StartDesc.Len = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3;
  57. mI2cDesc[Index].StartDesc.ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;
  58. mI2cDesc[Index].StartDesc.GenFlag = 0;
  59. mI2cDesc[Index].StartDesc.SpecificFlag = 0;
  60. mI2cDesc[Index].StartDesc.AddrSpaceGranularity = 32;
  61. mI2cDesc[Index].StartDesc.AddrRangeMin = LS1043A_I2C0_PHYS_ADDRESS +
  62. (Index * LS1043A_I2C_SIZE);
  63. mI2cDesc[Index].StartDesc.AddrRangeMax = mI2cDesc[Index].StartDesc.AddrRangeMin +
  64. LS1043A_I2C_SIZE - 1;
  65. mI2cDesc[Index].StartDesc.AddrTranslationOffset = 0;
  66. mI2cDesc[Index].StartDesc.AddrLen = LS1043A_I2C_SIZE;
  67. mI2cDesc[Index].EndDesc = ACPI_END_TAG_DESCRIPTOR;
  68. }
  69. }
  70. EFI_STATUS
  71. EFIAPI
  72. PlatformDxeEntryPoint (
  73. IN EFI_HANDLE ImageHandle,
  74. IN EFI_SYSTEM_TABLE *SystemTable
  75. )
  76. {
  77. EFI_STATUS Status;
  78. EFI_HANDLE Handle;
  79. Handle = NULL;
  80. PopulateI2cInformation ();
  81. Status = RegisterDevice (&gNxpNonDiscoverableI2cMasterGuid,
  82. &mI2cDesc[0], &Handle);
  83. ASSERT_EFI_ERROR (Status);
  84. //
  85. // Install the DS1307 I2C Master protocol on this handle so the RTC driver
  86. // can identify it as the I2C master it can invoke directly.
  87. //
  88. Status = gBS->InstallProtocolInterface (&Handle,
  89. &gDs1307RealTimeClockLibI2cMasterProtocolGuid,
  90. EFI_NATIVE_INTERFACE, NULL);
  91. ASSERT_EFI_ERROR (Status);
  92. return EFI_SUCCESS;
  93. }