XenioFdtDxe.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /** @file
  2. * Xenio FDT client protocol driver for xen,xen DT node
  3. *
  4. * Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause-Patent
  7. *
  8. **/
  9. #include <Library/BaseLib.h>
  10. #include <Library/DebugLib.h>
  11. #include <Library/UefiDriverEntryPoint.h>
  12. #include <Library/UefiBootServicesTableLib.h>
  13. #include <Library/XenIoMmioLib.h>
  14. #include <Protocol/FdtClient.h>
  15. EFI_STATUS
  16. EFIAPI
  17. InitializeXenioFdtDxe (
  18. IN EFI_HANDLE ImageHandle,
  19. IN EFI_SYSTEM_TABLE *SystemTable
  20. )
  21. {
  22. EFI_STATUS Status;
  23. FDT_CLIENT_PROTOCOL *FdtClient;
  24. CONST UINT64 *Reg;
  25. UINT32 RegSize;
  26. UINTN AddressCells, SizeCells;
  27. EFI_HANDLE Handle;
  28. UINT64 RegBase;
  29. Status = gBS->LocateProtocol (
  30. &gFdtClientProtocolGuid,
  31. NULL,
  32. (VOID **)&FdtClient
  33. );
  34. ASSERT_EFI_ERROR (Status);
  35. Status = FdtClient->FindCompatibleNodeReg (
  36. FdtClient,
  37. "xen,xen",
  38. (CONST VOID **)&Reg,
  39. &AddressCells,
  40. &SizeCells,
  41. &RegSize
  42. );
  43. if (EFI_ERROR (Status)) {
  44. DEBUG ((
  45. DEBUG_WARN,
  46. "%a: No 'xen,xen' compatible DT node found\n",
  47. __FUNCTION__
  48. ));
  49. return EFI_UNSUPPORTED;
  50. }
  51. ASSERT (AddressCells == 2);
  52. ASSERT (SizeCells == 2);
  53. ASSERT (RegSize == 2 * sizeof (UINT64));
  54. //
  55. // Retrieve the reg base from this node and wire it up to the
  56. // MMIO flavor of the XenBus root device I/O protocol
  57. //
  58. RegBase = SwapBytes64 (Reg[0]);
  59. Handle = NULL;
  60. Status = XenIoMmioInstall (&Handle, RegBase);
  61. if (EFI_ERROR (Status)) {
  62. DEBUG ((
  63. DEBUG_ERROR,
  64. "%a: XenIoMmioInstall () failed on a new handle "
  65. "(Status == %r)\n",
  66. __FUNCTION__,
  67. Status
  68. ));
  69. return Status;
  70. }
  71. DEBUG ((DEBUG_INFO, "Found Xen node with Grant table @ 0x%Lx\n", RegBase));
  72. return EFI_SUCCESS;
  73. }