1 | /** @file
|
---|
2 | * Manage XenBus device path and I/O handles
|
---|
3 | *
|
---|
4 | * Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
|
---|
5 | *
|
---|
6 | * SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 | *
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include <Library/BaseLib.h>
|
---|
11 | #include <Library/UefiBootServicesTableLib.h>
|
---|
12 | #include <Library/DebugLib.h>
|
---|
13 | #include <Library/UefiLib.h>
|
---|
14 | #include <Library/BaseMemoryLib.h>
|
---|
15 | #include <Library/MemoryAllocationLib.h>
|
---|
16 | #include <Library/DevicePathLib.h>
|
---|
17 | #include <Library/XenIoMmioLib.h>
|
---|
18 |
|
---|
19 | #include <Protocol/XenIo.h>
|
---|
20 | #include <Guid/XenBusRootDevice.h>
|
---|
21 |
|
---|
22 | #pragma pack (1)
|
---|
23 | typedef struct {
|
---|
24 | VENDOR_DEVICE_PATH Vendor;
|
---|
25 | EFI_PHYSICAL_ADDRESS GrantTableAddress;
|
---|
26 | EFI_DEVICE_PATH_PROTOCOL End;
|
---|
27 | } XENBUS_ROOT_DEVICE_PATH;
|
---|
28 | #pragma pack ()
|
---|
29 |
|
---|
30 | STATIC CONST XENBUS_ROOT_DEVICE_PATH mXenBusRootDevicePathTemplate = {
|
---|
31 | {
|
---|
32 | {
|
---|
33 | HARDWARE_DEVICE_PATH,
|
---|
34 | HW_VENDOR_DP,
|
---|
35 | { sizeof (VENDOR_DEVICE_PATH) + sizeof (EFI_PHYSICAL_ADDRESS), 0 }
|
---|
36 | },
|
---|
37 | XENBUS_ROOT_DEVICE_GUID,
|
---|
38 | },
|
---|
39 | 0,
|
---|
40 | {
|
---|
41 | END_DEVICE_PATH_TYPE,
|
---|
42 | END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
---|
43 | { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }
|
---|
44 | }
|
---|
45 | };
|
---|
46 |
|
---|
47 | /**
|
---|
48 |
|
---|
49 | Install the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols on
|
---|
50 | the handle pointed to by @Handle, or on a new handle if it points to
|
---|
51 | NULL
|
---|
52 |
|
---|
53 | @param Handle Pointer to the handle to install the protocols
|
---|
54 | on, may point to a NULL handle.
|
---|
55 |
|
---|
56 | @param GrantTableAddress The address of the Xen grant table
|
---|
57 |
|
---|
58 | @retval EFI_SUCCESS Protocols were installed successfully
|
---|
59 |
|
---|
60 | @retval EFI_OUT_OF_RESOURCES The function failed to allocate memory required
|
---|
61 | by the XenIo MMIO and device path protocols
|
---|
62 |
|
---|
63 | @return Status code returned by the boot service
|
---|
64 | InstallMultipleProtocolInterfaces ()
|
---|
65 |
|
---|
66 | **/
|
---|
67 | EFI_STATUS
|
---|
68 | XenIoMmioInstall (
|
---|
69 | IN OUT EFI_HANDLE *Handle,
|
---|
70 | IN EFI_PHYSICAL_ADDRESS GrantTableAddress
|
---|
71 | )
|
---|
72 | {
|
---|
73 | EFI_STATUS Status;
|
---|
74 | XENIO_PROTOCOL *XenIo;
|
---|
75 | XENBUS_ROOT_DEVICE_PATH *XenBusDevicePath;
|
---|
76 | EFI_HANDLE OutHandle;
|
---|
77 |
|
---|
78 | ASSERT (Handle != NULL);
|
---|
79 |
|
---|
80 | OutHandle = *Handle;
|
---|
81 |
|
---|
82 | XenIo = AllocateZeroPool (sizeof *XenIo);
|
---|
83 | if (!XenIo) {
|
---|
84 | return EFI_OUT_OF_RESOURCES;
|
---|
85 | }
|
---|
86 | XenIo->GrantTableAddress = GrantTableAddress;
|
---|
87 |
|
---|
88 | XenBusDevicePath = AllocateCopyPool (sizeof *XenBusDevicePath,
|
---|
89 | &mXenBusRootDevicePathTemplate);
|
---|
90 | if (!XenBusDevicePath) {
|
---|
91 | DEBUG ((DEBUG_ERROR, "%a: Out of memory\n", __FUNCTION__));
|
---|
92 | Status = EFI_OUT_OF_RESOURCES;
|
---|
93 | goto FreeXenIo;
|
---|
94 | }
|
---|
95 | XenBusDevicePath->GrantTableAddress = GrantTableAddress;
|
---|
96 |
|
---|
97 | Status = gBS->InstallMultipleProtocolInterfaces (&OutHandle,
|
---|
98 | &gEfiDevicePathProtocolGuid, XenBusDevicePath,
|
---|
99 | &gXenIoProtocolGuid, XenIo,
|
---|
100 | NULL);
|
---|
101 | if (!EFI_ERROR (Status)) {
|
---|
102 | *Handle = OutHandle;
|
---|
103 | return EFI_SUCCESS;
|
---|
104 | }
|
---|
105 |
|
---|
106 | DEBUG ((DEBUG_ERROR, "%a: Failed to install the EFI_DEVICE_PATH and "
|
---|
107 | "XENIO_PROTOCOL protocols on handle %p (Status == %r)\n",
|
---|
108 | __FUNCTION__, OutHandle, Status));
|
---|
109 |
|
---|
110 | FreePool (XenBusDevicePath);
|
---|
111 |
|
---|
112 | FreeXenIo:
|
---|
113 | FreePool (XenIo);
|
---|
114 | return Status;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /**
|
---|
118 |
|
---|
119 | Uninstall the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols
|
---|
120 |
|
---|
121 | @param Handle Handle onto which the protocols have been installed
|
---|
122 | earlier by XenIoMmioInstall ()
|
---|
123 |
|
---|
124 | @retval EFI_SUCCESS Protocols were uninstalled successfully
|
---|
125 |
|
---|
126 | @return Status code returned by the boot service
|
---|
127 | UninstallMultipleProtocolInterfaces ()
|
---|
128 |
|
---|
129 | **/
|
---|
130 | EFI_STATUS
|
---|
131 | XenIoMmioUninstall (
|
---|
132 | IN EFI_HANDLE Handle
|
---|
133 | )
|
---|
134 | {
|
---|
135 | EFI_STATUS Status;
|
---|
136 | VOID *XenIo;
|
---|
137 | VOID *XenBusDevicePath;
|
---|
138 |
|
---|
139 | XenBusDevicePath = NULL;
|
---|
140 | gBS->OpenProtocol (Handle, &gEfiDevicePathProtocolGuid, &XenBusDevicePath,
|
---|
141 | NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
|
---|
142 |
|
---|
143 | XenIo = NULL;
|
---|
144 | gBS->OpenProtocol (Handle, &gXenIoProtocolGuid, &XenIo,
|
---|
145 | NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
|
---|
146 |
|
---|
147 | Status = gBS->UninstallMultipleProtocolInterfaces (Handle,
|
---|
148 | &gEfiDevicePathProtocolGuid, XenBusDevicePath,
|
---|
149 | &gXenIoProtocolGuid, XenIo,
|
---|
150 | NULL);
|
---|
151 |
|
---|
152 | if (EFI_ERROR (Status)) {
|
---|
153 | return Status;
|
---|
154 | }
|
---|
155 |
|
---|
156 | FreePool (XenBusDevicePath);
|
---|
157 | FreePool (XenIo);
|
---|
158 |
|
---|
159 | return EFI_SUCCESS;
|
---|
160 | }
|
---|