+ //\r
+ // Host status is bi-directional (we preset with a value and expect the\r
+ // device to update it). Allocate a host status buffer which can be mapped\r
+ // to access equally by both processor and the device.\r
+ //\r
+ Status = Dev->VirtIo->AllocateSharedPages (\r
+ Dev->VirtIo,\r
+ EFI_SIZE_TO_PAGES (sizeof *HostStatus),\r
+ &HostStatusBuffer\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ HostStatus = HostStatusBuffer;\r
+\r
+ //\r
+ // Map virtio-blk request header (must be done after request header is\r
+ // populated)\r
+ //\r
+ Status = VirtioMapAllBytesInSharedBuffer (\r
+ Dev->VirtIo,\r
+ VirtioOperationBusMasterRead,\r
+ (VOID *) &Request,\r
+ sizeof Request,\r
+ &RequestDeviceAddress,\r
+ &RequestMapping\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto FreeHostStatusBuffer;\r
+ }\r
+\r
+ //\r
+ // Map data buffer\r
+ //\r
+ if (BufferSize > 0) {\r
+ Status = VirtioMapAllBytesInSharedBuffer (\r
+ Dev->VirtIo,\r
+ (RequestIsWrite ?\r
+ VirtioOperationBusMasterRead :\r
+ VirtioOperationBusMasterWrite),\r
+ (VOID *) Buffer,\r
+ BufferSize,\r
+ &BufferDeviceAddress,\r
+ &BufferMapping\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto UnmapRequestBuffer;\r
+ }\r
+ }\r