]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/XenioFdtDxe/XenioFdtDxe.c
ArmVirtPkg/ArmVirtXen: move from VirtFdtDxe to new XenioFdtDxe driver
[mirror_edk2.git] / ArmVirtPkg / XenioFdtDxe / XenioFdtDxe.c
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 * This program and the accompanying materials are
7 * licensed and made available under the terms and conditions of the BSD License
8 * which accompanies this distribution. The full text of the license may be found at
9 * http://opensource.org/licenses/bsd-license.php
10 *
11 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 *
14 **/
15
16 #include <Library/BaseLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/UefiDriverEntryPoint.h>
19 #include <Library/UefiBootServicesTableLib.h>
20 #include <Library/XenIoMmioLib.h>
21
22 #include <Protocol/FdtClient.h>
23
24 EFI_STATUS
25 EFIAPI
26 InitializeXenioFdtDxe (
27 IN EFI_HANDLE ImageHandle,
28 IN EFI_SYSTEM_TABLE *SystemTable
29 )
30 {
31 EFI_STATUS Status;
32 FDT_CLIENT_PROTOCOL *FdtClient;
33 CONST UINT64 *Reg;
34 UINT32 RegElemSize, RegSize;
35 EFI_HANDLE Handle;
36 UINT64 RegBase;
37
38 Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,
39 (VOID **)&FdtClient);
40 ASSERT_EFI_ERROR (Status);
41
42 Status = FdtClient->FindCompatibleNodeReg (FdtClient, "xen,xen",
43 (CONST VOID **)&Reg, &RegElemSize, &RegSize);
44 if (EFI_ERROR (Status)) {
45 DEBUG ((EFI_D_WARN, "%a: No 'xen,xen' compatible DT node found\n",
46 __FUNCTION__));
47 return EFI_UNSUPPORTED;
48 }
49
50 ASSERT (RegSize == 16);
51
52 //
53 // Retrieve the reg base from this node and wire it up to the
54 // MMIO flavor of the XenBus root device I/O protocol
55 //
56 RegBase = SwapBytes64 (Reg[0]);
57 Handle = NULL;
58 Status = XenIoMmioInstall (&Handle, RegBase);
59 if (EFI_ERROR (Status)) {
60 DEBUG ((EFI_D_ERROR, "%a: XenIoMmioInstall () failed on a new handle "
61 "(Status == %r)\n", __FUNCTION__, Status));
62 return Status;
63 }
64
65 DEBUG ((EFI_D_INFO, "Found Xen node with Grant table @ 0x%Lx\n", RegBase));
66
67 return EFI_SUCCESS;
68 }