OvmfPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the OvmfPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Andrew Fish <afish@apple.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:09 -08:00
committed by mergify[bot]
parent d1050b9dff
commit ac0a286f4d
445 changed files with 30894 additions and 26369 deletions

View File

@@ -34,23 +34,25 @@
STATIC
XENSTORE_STATUS
XenBusReadUint64 (
IN XENBUS_PROTOCOL *This,
IN CONST CHAR8 *Node,
IN BOOLEAN FromBackend,
OUT UINT64 *ValuePtr
IN XENBUS_PROTOCOL *This,
IN CONST CHAR8 *Node,
IN BOOLEAN FromBackend,
OUT UINT64 *ValuePtr
)
{
XENSTORE_STATUS Status;
CHAR8 *Ptr;
XENSTORE_STATUS Status;
CHAR8 *Ptr;
if (!FromBackend) {
Status = This->XsRead (This, XST_NIL, Node, (VOID**)&Ptr);
Status = This->XsRead (This, XST_NIL, Node, (VOID **)&Ptr);
} else {
Status = This->XsBackendRead (This, XST_NIL, Node, (VOID**)&Ptr);
Status = This->XsBackendRead (This, XST_NIL, Node, (VOID **)&Ptr);
}
if (Status != XENSTORE_STATUS_SUCCESS) {
return Status;
}
// AsciiStrDecimalToUint64 will ASSERT if Ptr overflow UINT64.
*ValuePtr = AsciiStrDecimalToUint64 (Ptr);
FreePool (Ptr);
@@ -65,20 +67,23 @@ XenBusReadUint64 (
STATIC
VOID
XenPvBlockFree (
IN XEN_BLOCK_FRONT_DEVICE *Dev
IN XEN_BLOCK_FRONT_DEVICE *Dev
)
{
XENBUS_PROTOCOL *XenBusIo = Dev->XenBusIo;
XENBUS_PROTOCOL *XenBusIo = Dev->XenBusIo;
if (Dev->RingRef != 0) {
XenBusIo->GrantEndAccess (XenBusIo, Dev->RingRef);
}
if (Dev->Ring.sring != NULL) {
FreePages (Dev->Ring.sring, 1);
}
if (Dev->EventChannel != 0) {
XenBusIo->EventChannelClose (XenBusIo, Dev->EventChannel);
}
FreePool (Dev);
}
@@ -95,27 +100,29 @@ XenPvBlockFree (
STATIC
XENSTORE_STATUS
XenPvBlkWaitForBackendState (
IN XEN_BLOCK_FRONT_DEVICE *Dev,
IN XenbusState ExpectedState,
OUT XenbusState *LastStatePtr OPTIONAL
IN XEN_BLOCK_FRONT_DEVICE *Dev,
IN XenbusState ExpectedState,
OUT XenbusState *LastStatePtr OPTIONAL
)
{
XENBUS_PROTOCOL *XenBusIo = Dev->XenBusIo;
XenbusState State;
UINT64 Value;
XENSTORE_STATUS Status = XENSTORE_STATUS_SUCCESS;
XENBUS_PROTOCOL *XenBusIo = Dev->XenBusIo;
XenbusState State;
UINT64 Value;
XENSTORE_STATUS Status = XENSTORE_STATUS_SUCCESS;
while (TRUE) {
Status = XenBusReadUint64 (XenBusIo, "state", TRUE, &Value);
if (Status != XENSTORE_STATUS_SUCCESS) {
return Status;
}
if (Value > XenbusStateReconfigured) {
//
// Value is not a State value.
//
return XENSTORE_STATUS_EIO;
}
State = Value;
if (State == ExpectedState) {
break;
@@ -123,9 +130,13 @@ XenPvBlkWaitForBackendState (
Status = XENSTORE_STATUS_FAIL;
break;
}
DEBUG ((DEBUG_INFO,
"XenPvBlk: waiting backend state %d, current: %d\n",
ExpectedState, State));
DEBUG ((
DEBUG_INFO,
"XenPvBlk: waiting backend state %d, current: %d\n",
ExpectedState,
State
));
XenBusIo->WaitForWatch (XenBusIo, Dev->StateWatchToken);
}
@@ -143,14 +154,14 @@ XenPvBlockFrontInitialization (
OUT XEN_BLOCK_FRONT_DEVICE **DevPtr
)
{
XENSTORE_TRANSACTION Transaction;
CHAR8 *DeviceType;
blkif_sring_t *SharedRing;
XENSTORE_STATUS Status;
XEN_BLOCK_FRONT_DEVICE *Dev;
XenbusState State;
UINT64 Value;
CHAR8 *Params;
XENSTORE_TRANSACTION Transaction;
CHAR8 *DeviceType;
blkif_sring_t *SharedRing;
XENSTORE_STATUS Status;
XEN_BLOCK_FRONT_DEVICE *Dev;
XenbusState State;
UINT64 Value;
CHAR8 *Params;
ASSERT (NodeName != NULL);
@@ -160,49 +171,58 @@ XenPvBlockFrontInitialization (
}
Dev->Signature = XEN_BLOCK_FRONT_SIGNATURE;
Dev->NodeName = NodeName;
Dev->XenBusIo = XenBusIo;
Dev->DeviceId = XenBusIo->DeviceId;
Dev->NodeName = NodeName;
Dev->XenBusIo = XenBusIo;
Dev->DeviceId = XenBusIo->DeviceId;
XenBusIo->XsRead (XenBusIo, XST_NIL, "device-type", (VOID**)&DeviceType);
XenBusIo->XsRead (XenBusIo, XST_NIL, "device-type", (VOID **)&DeviceType);
if (AsciiStrCmp (DeviceType, "cdrom") == 0) {
Dev->MediaInfo.CdRom = TRUE;
} else {
Dev->MediaInfo.CdRom = FALSE;
}
FreePool (DeviceType);
if (Dev->MediaInfo.CdRom) {
Status = XenBusIo->XsBackendRead (XenBusIo, XST_NIL, "params", (VOID**)&Params);
Status = XenBusIo->XsBackendRead (XenBusIo, XST_NIL, "params", (VOID **)&Params);
if (Status != XENSTORE_STATUS_SUCCESS) {
DEBUG ((DEBUG_ERROR, "%a: Failed to read params (%d)\n", __FUNCTION__, Status));
goto Error;
}
if (AsciiStrLen (Params) == 0 || AsciiStrCmp (Params, "aio:") == 0) {
if ((AsciiStrLen (Params) == 0) || (AsciiStrCmp (Params, "aio:") == 0)) {
FreePool (Params);
DEBUG ((DEBUG_INFO, "%a: Empty cdrom\n", __FUNCTION__));
goto Error;
}
FreePool (Params);
}
Status = XenBusReadUint64 (XenBusIo, "backend-id", FALSE, &Value);
if (Status != XENSTORE_STATUS_SUCCESS || Value > MAX_UINT16) {
DEBUG ((DEBUG_ERROR, "XenPvBlk: Failed to get backend-id (%d)\n",
Status));
if ((Status != XENSTORE_STATUS_SUCCESS) || (Value > MAX_UINT16)) {
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: Failed to get backend-id (%d)\n",
Status
));
goto Error;
}
Dev->DomainId = (domid_t)Value;
XenBusIo->EventChannelAllocate (XenBusIo, Dev->DomainId, &Dev->EventChannel);
SharedRing = (blkif_sring_t*) AllocatePages (1);
SharedRing = (blkif_sring_t *)AllocatePages (1);
SHARED_RING_INIT (SharedRing);
FRONT_RING_INIT (&Dev->Ring, SharedRing, EFI_PAGE_SIZE);
XenBusIo->GrantAccess (XenBusIo,
Dev->DomainId,
(INTN) SharedRing >> EFI_PAGE_SHIFT,
FALSE,
&Dev->RingRef);
XenBusIo->GrantAccess (
XenBusIo,
Dev->DomainId,
(INTN)SharedRing >> EFI_PAGE_SHIFT,
FALSE,
&Dev->RingRef
);
Again:
Status = XenBusIo->XsTransactionStart (XenBusIo, &Transaction);
@@ -211,20 +231,40 @@ Again:
goto Error;
}
Status = XenBusIo->XsPrintf (XenBusIo, &Transaction, NodeName, "ring-ref", "%d",
Dev->RingRef);
Status = XenBusIo->XsPrintf (
XenBusIo,
&Transaction,
NodeName,
"ring-ref",
"%d",
Dev->RingRef
);
if (Status != XENSTORE_STATUS_SUCCESS) {
DEBUG ((DEBUG_ERROR, "XenPvBlk: Failed to write ring-ref.\n"));
goto AbortTransaction;
}
Status = XenBusIo->XsPrintf (XenBusIo, &Transaction, NodeName,
"event-channel", "%d", Dev->EventChannel);
Status = XenBusIo->XsPrintf (
XenBusIo,
&Transaction,
NodeName,
"event-channel",
"%d",
Dev->EventChannel
);
if (Status != XENSTORE_STATUS_SUCCESS) {
DEBUG ((DEBUG_ERROR, "XenPvBlk: Failed to write event-channel.\n"));
goto AbortTransaction;
}
Status = XenBusIo->XsPrintf (XenBusIo, &Transaction, NodeName,
"protocol", "%a", XEN_IO_PROTO_ABI_NATIVE);
Status = XenBusIo->XsPrintf (
XenBusIo,
&Transaction,
NodeName,
"protocol",
"%a",
XEN_IO_PROTO_ABI_NATIVE
);
if (Status != XENSTORE_STATUS_SUCCESS) {
DEBUG ((DEBUG_ERROR, "XenPvBlk: Failed to write protocol.\n"));
goto AbortTransaction;
@@ -248,16 +288,22 @@ Again:
//
Status = XenPvBlkWaitForBackendState (Dev, XenbusStateConnected, &State);
if (Status != XENSTORE_STATUS_SUCCESS) {
DEBUG ((DEBUG_ERROR,
"XenPvBlk: backend for %a/%d not available, rc=%d state=%d\n",
XenBusIo->Type, XenBusIo->DeviceId, Status, State));
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: backend for %a/%d not available, rc=%d state=%d\n",
XenBusIo->Type,
XenBusIo->DeviceId,
Status,
State
));
goto Error2;
}
Status = XenBusReadUint64 (XenBusIo, "info", TRUE, &Value);
if (Status != XENSTORE_STATUS_SUCCESS || Value > MAX_UINT32) {
if ((Status != XENSTORE_STATUS_SUCCESS) || (Value > MAX_UINT32)) {
goto Error2;
}
Dev->MediaInfo.VDiskInfo = (UINT32)Value;
if (Dev->MediaInfo.VDiskInfo & VDISK_READONLY) {
Dev->MediaInfo.ReadWrite = FALSE;
@@ -271,17 +317,23 @@ Again:
}
Status = XenBusReadUint64 (XenBusIo, "sector-size", TRUE, &Value);
if (Status != XENSTORE_STATUS_SUCCESS || Value > MAX_UINT32) {
if ((Status != XENSTORE_STATUS_SUCCESS) || (Value > MAX_UINT32)) {
goto Error2;
}
if ((UINT32)Value % 512 != 0) {
//
// This is not supported by the driver.
//
DEBUG ((DEBUG_ERROR, "XenPvBlk: Unsupported sector-size value %Lu, "
"it must be a multiple of 512\n", Value));
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: Unsupported sector-size value %Lu, "
"it must be a multiple of 512\n",
Value
));
goto Error2;
}
Dev->MediaInfo.SectorSize = (UINT32)Value;
// Default value
@@ -302,8 +354,12 @@ Again:
Dev->MediaInfo.FeatureFlushCache = FALSE;
}
DEBUG ((DEBUG_INFO, "XenPvBlk: New disk with %ld sectors of %d bytes\n",
Dev->MediaInfo.Sectors, Dev->MediaInfo.SectorSize));
DEBUG ((
DEBUG_INFO,
"XenPvBlk: New disk with %ld sectors of %d bytes\n",
Dev->MediaInfo.Sectors,
Dev->MediaInfo.SectorSize
));
*DevPtr = Dev;
return EFI_SUCCESS;
@@ -323,69 +379,86 @@ Error:
VOID
XenPvBlockFrontShutdown (
IN XEN_BLOCK_FRONT_DEVICE *Dev
IN XEN_BLOCK_FRONT_DEVICE *Dev
)
{
XENBUS_PROTOCOL *XenBusIo = Dev->XenBusIo;
XENSTORE_STATUS Status;
UINT64 Value;
XENBUS_PROTOCOL *XenBusIo = Dev->XenBusIo;
XENSTORE_STATUS Status;
UINT64 Value;
XenPvBlockSync (Dev);
Status = XenBusIo->SetState (XenBusIo, XST_NIL, XenbusStateClosing);
if (Status != XENSTORE_STATUS_SUCCESS) {
DEBUG ((DEBUG_ERROR,
"XenPvBlk: error while changing state to Closing: %d\n",
Status));
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: error while changing state to Closing: %d\n",
Status
));
goto Close;
}
Status = XenPvBlkWaitForBackendState (Dev, XenbusStateClosing, NULL);
if (Status != XENSTORE_STATUS_SUCCESS) {
DEBUG ((DEBUG_ERROR,
"XenPvBlk: error while waiting for closing backend state: %d\n",
Status));
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: error while waiting for closing backend state: %d\n",
Status
));
goto Close;
}
Status = XenBusIo->SetState (XenBusIo, XST_NIL, XenbusStateClosed);
if (Status != XENSTORE_STATUS_SUCCESS) {
DEBUG ((DEBUG_ERROR,
"XenPvBlk: error while changing state to Closed: %d\n",
Status));
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: error while changing state to Closed: %d\n",
Status
));
goto Close;
}
Status = XenPvBlkWaitForBackendState (Dev, XenbusStateClosed, NULL);
if (Status != XENSTORE_STATUS_SUCCESS) {
DEBUG ((DEBUG_ERROR,
"XenPvBlk: error while waiting for closed backend state: %d\n",
Status));
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: error while waiting for closed backend state: %d\n",
Status
));
goto Close;
}
Status = XenBusIo->SetState (XenBusIo, XST_NIL, XenbusStateInitialising);
if (Status != XENSTORE_STATUS_SUCCESS) {
DEBUG ((DEBUG_ERROR,
"XenPvBlk: error while changing state to initialising: %d\n",
Status));
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: error while changing state to initialising: %d\n",
Status
));
goto Close;
}
while (TRUE) {
Status = XenBusReadUint64 (XenBusIo, "state", TRUE, &Value);
if (Status != XENSTORE_STATUS_SUCCESS) {
DEBUG ((DEBUG_ERROR,
"XenPvBlk: error while waiting for new backend state: %d\n",
Status));
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: error while waiting for new backend state: %d\n",
Status
));
goto Close;
}
if (Value <= XenbusStateInitWait || Value >= XenbusStateClosed) {
if ((Value <= XenbusStateInitWait) || (Value >= XenbusStateClosed)) {
break;
}
DEBUG ((DEBUG_INFO,
"XenPvBlk: waiting backend state %d, current: %Lu\n",
XenbusStateInitWait, Value));
DEBUG ((
DEBUG_INFO,
"XenPvBlk: waiting backend state %d, current: %Lu\n",
XenbusStateInitWait,
Value
));
XenBusIo->WaitForWatch (XenBusIo, Dev->StateWatchToken);
}
@@ -401,7 +474,7 @@ Close:
STATIC
VOID
XenPvBlockWaitSlot (
IN XEN_BLOCK_FRONT_DEVICE *Dev
IN XEN_BLOCK_FRONT_DEVICE *Dev
)
{
/* Wait for a slot */
@@ -411,6 +484,7 @@ XenPvBlockWaitSlot (
if (!RING_FULL (&Dev->Ring)) {
break;
}
/* Really no slot, could wait for an event on Dev->EventChannel. */
}
}
@@ -418,53 +492,58 @@ XenPvBlockWaitSlot (
VOID
XenPvBlockAsyncIo (
IN OUT XEN_BLOCK_FRONT_IO *IoData,
IN BOOLEAN IsWrite
IN OUT XEN_BLOCK_FRONT_IO *IoData,
IN BOOLEAN IsWrite
)
{
XEN_BLOCK_FRONT_DEVICE *Dev = IoData->Dev;
XENBUS_PROTOCOL *XenBusIo = Dev->XenBusIo;
blkif_request_t *Request;
RING_IDX RingIndex;
BOOLEAN Notify;
INT32 NumSegments, Index;
UINTN Start, End;
XEN_BLOCK_FRONT_DEVICE *Dev = IoData->Dev;
XENBUS_PROTOCOL *XenBusIo = Dev->XenBusIo;
blkif_request_t *Request;
RING_IDX RingIndex;
BOOLEAN Notify;
INT32 NumSegments, Index;
UINTN Start, End;
// Can't io at non-sector-aligned location
ASSERT(!(IoData->Sector & ((Dev->MediaInfo.SectorSize / 512) - 1)));
ASSERT (!(IoData->Sector & ((Dev->MediaInfo.SectorSize / 512) - 1)));
// Can't io non-sector-sized amounts
ASSERT(!(IoData->Size & (Dev->MediaInfo.SectorSize - 1)));
ASSERT (!(IoData->Size & (Dev->MediaInfo.SectorSize - 1)));
// Can't io non-sector-aligned buffer
ASSERT(!((UINTN) IoData->Buffer & (Dev->MediaInfo.SectorSize - 1)));
ASSERT (!((UINTN)IoData->Buffer & (Dev->MediaInfo.SectorSize - 1)));
Start = (UINTN) IoData->Buffer & ~EFI_PAGE_MASK;
End = ((UINTN) IoData->Buffer + IoData->Size + EFI_PAGE_SIZE - 1) & ~EFI_PAGE_MASK;
Start = (UINTN)IoData->Buffer & ~EFI_PAGE_MASK;
End = ((UINTN)IoData->Buffer + IoData->Size + EFI_PAGE_SIZE - 1) & ~EFI_PAGE_MASK;
IoData->NumRef = NumSegments = (INT32)((End - Start) / EFI_PAGE_SIZE);
ASSERT (NumSegments <= BLKIF_MAX_SEGMENTS_PER_REQUEST);
XenPvBlockWaitSlot (Dev);
RingIndex = Dev->Ring.req_prod_pvt;
Request = RING_GET_REQUEST (&Dev->Ring, RingIndex);
Request = RING_GET_REQUEST (&Dev->Ring, RingIndex);
Request->operation = IsWrite ? BLKIF_OP_WRITE : BLKIF_OP_READ;
Request->nr_segments = (UINT8)NumSegments;
Request->handle = Dev->DeviceId;
Request->id = (UINTN) IoData;
Request->operation = IsWrite ? BLKIF_OP_WRITE : BLKIF_OP_READ;
Request->nr_segments = (UINT8)NumSegments;
Request->handle = Dev->DeviceId;
Request->id = (UINTN)IoData;
Request->sector_number = IoData->Sector;
for (Index = 0; Index < NumSegments; Index++) {
Request->seg[Index].first_sect = 0;
Request->seg[Index].last_sect = EFI_PAGE_SIZE / 512 - 1;
Request->seg[Index].last_sect = EFI_PAGE_SIZE / 512 - 1;
}
Request->seg[0].first_sect = (UINT8)(((UINTN) IoData->Buffer & EFI_PAGE_MASK) / 512);
Request->seg[0].first_sect = (UINT8)(((UINTN)IoData->Buffer & EFI_PAGE_MASK) / 512);
Request->seg[NumSegments - 1].last_sect =
(UINT8)((((UINTN) IoData->Buffer + IoData->Size - 1) & EFI_PAGE_MASK) / 512);
(UINT8)((((UINTN)IoData->Buffer + IoData->Size - 1) & EFI_PAGE_MASK) / 512);
for (Index = 0; Index < NumSegments; Index++) {
UINTN Data = Start + Index * EFI_PAGE_SIZE;
XenBusIo->GrantAccess (XenBusIo, Dev->DomainId,
Data >> EFI_PAGE_SHIFT, IsWrite,
&Request->seg[Index].gref);
UINTN Data = Start + Index * EFI_PAGE_SIZE;
XenBusIo->GrantAccess (
XenBusIo,
Dev->DomainId,
Data >> EFI_PAGE_SHIFT,
IsWrite,
&Request->seg[Index].gref
);
IoData->GrantRef[Index] = Request->seg[Index].gref;
}
@@ -474,20 +553,22 @@ XenPvBlockAsyncIo (
RING_PUSH_REQUESTS_AND_CHECK_NOTIFY (&Dev->Ring, Notify);
if (Notify) {
UINT32 ReturnCode;
UINT32 ReturnCode;
ReturnCode = XenBusIo->EventChannelNotify (XenBusIo, Dev->EventChannel);
if (ReturnCode != 0) {
DEBUG ((DEBUG_ERROR,
"XenPvBlk: Unexpected return value from EventChannelNotify: %d\n",
ReturnCode));
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: Unexpected return value from EventChannelNotify: %d\n",
ReturnCode
));
}
}
}
EFI_STATUS
XenPvBlockIo (
IN OUT XEN_BLOCK_FRONT_IO *IoData,
IN BOOLEAN IsWrite
IN OUT XEN_BLOCK_FRONT_IO *IoData,
IN BOOLEAN IsWrite
)
{
//
@@ -506,42 +587,44 @@ XenPvBlockIo (
STATIC
VOID
XenPvBlockPushOperation (
IN XEN_BLOCK_FRONT_DEVICE *Dev,
IN UINT8 Operation,
IN UINT64 Id
IN XEN_BLOCK_FRONT_DEVICE *Dev,
IN UINT8 Operation,
IN UINT64 Id
)
{
INT32 Index;
blkif_request_t *Request;
BOOLEAN Notify;
INT32 Index;
blkif_request_t *Request;
BOOLEAN Notify;
XenPvBlockWaitSlot (Dev);
Index = Dev->Ring.req_prod_pvt;
Request = RING_GET_REQUEST(&Dev->Ring, Index);
Request->operation = Operation;
Index = Dev->Ring.req_prod_pvt;
Request = RING_GET_REQUEST (&Dev->Ring, Index);
Request->operation = Operation;
Request->nr_segments = 0;
Request->handle = Dev->DeviceId;
Request->id = Id;
Request->handle = Dev->DeviceId;
Request->id = Id;
/* Not needed anyway, but the backend will check it */
Request->sector_number = 0;
Dev->Ring.req_prod_pvt = Index + 1;
MemoryFence ();
RING_PUSH_REQUESTS_AND_CHECK_NOTIFY (&Dev->Ring, Notify);
if (Notify) {
XENBUS_PROTOCOL *XenBusIo = Dev->XenBusIo;
UINT32 ReturnCode;
XENBUS_PROTOCOL *XenBusIo = Dev->XenBusIo;
UINT32 ReturnCode;
ReturnCode = XenBusIo->EventChannelNotify (XenBusIo, Dev->EventChannel);
if (ReturnCode != 0) {
DEBUG ((DEBUG_ERROR,
"XenPvBlk: Unexpected return value from EventChannelNotify: %d\n",
ReturnCode));
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: Unexpected return value from EventChannelNotify: %d\n",
ReturnCode
));
}
}
}
VOID
XenPvBlockSync (
IN XEN_BLOCK_FRONT_DEVICE *Dev
IN XEN_BLOCK_FRONT_DEVICE *Dev
)
{
if (Dev->MediaInfo.ReadWrite) {
@@ -565,12 +648,12 @@ XenPvBlockSync (
VOID
XenPvBlockAsyncIoPoll (
IN XEN_BLOCK_FRONT_DEVICE *Dev
IN XEN_BLOCK_FRONT_DEVICE *Dev
)
{
RING_IDX ProducerIndex, ConsumerIndex;
blkif_response_t *Response;
INT32 More;
RING_IDX ProducerIndex, ConsumerIndex;
blkif_response_t *Response;
INT32 More;
do {
ProducerIndex = Dev->Ring.sring->rsp_prod;
@@ -579,28 +662,31 @@ XenPvBlockAsyncIoPoll (
ConsumerIndex = Dev->Ring.rsp_cons;
while (ConsumerIndex != ProducerIndex) {
XEN_BLOCK_FRONT_IO *IoData = NULL;
INT16 Status;
XEN_BLOCK_FRONT_IO *IoData = NULL;
INT16 Status;
Response = RING_GET_RESPONSE (&Dev->Ring, ConsumerIndex);
IoData = (VOID *) (UINTN) Response->id;
IoData = (VOID *)(UINTN)Response->id;
Status = Response->status;
switch (Response->operation) {
case BLKIF_OP_READ:
case BLKIF_OP_WRITE:
case BLKIF_OP_READ:
case BLKIF_OP_WRITE:
{
INT32 Index;
INT32 Index;
if (Status != BLKIF_RSP_OKAY) {
DEBUG ((DEBUG_ERROR,
"XenPvBlk: "
"%a error %d on %a at sector %Lx, num bytes %Lx\n",
Response->operation == BLKIF_OP_READ ? "read" : "write",
Status, IoData->Dev->NodeName,
(UINT64)IoData->Sector,
(UINT64)IoData->Size));
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: "
"%a error %d on %a at sector %Lx, num bytes %Lx\n",
Response->operation == BLKIF_OP_READ ? "read" : "write",
Status,
IoData->Dev->NodeName,
(UINT64)IoData->Sector,
(UINT64)IoData->Size
));
}
for (Index = 0; Index < IoData->NumRef; Index++) {
@@ -610,28 +696,34 @@ XenPvBlockAsyncIoPoll (
break;
}
case BLKIF_OP_WRITE_BARRIER:
if (Status != BLKIF_RSP_OKAY) {
DEBUG ((DEBUG_ERROR, "XenPvBlk: write barrier error %d\n", Status));
}
break;
case BLKIF_OP_FLUSH_DISKCACHE:
if (Status != BLKIF_RSP_OKAY) {
DEBUG ((DEBUG_ERROR, "XenPvBlk: flush error %d\n", Status));
}
break;
case BLKIF_OP_WRITE_BARRIER:
if (Status != BLKIF_RSP_OKAY) {
DEBUG ((DEBUG_ERROR, "XenPvBlk: write barrier error %d\n", Status));
}
default:
DEBUG ((DEBUG_ERROR,
"XenPvBlk: unrecognized block operation %d response (status %d)\n",
Response->operation, Status));
break;
break;
case BLKIF_OP_FLUSH_DISKCACHE:
if (Status != BLKIF_RSP_OKAY) {
DEBUG ((DEBUG_ERROR, "XenPvBlk: flush error %d\n", Status));
}
break;
default:
DEBUG ((
DEBUG_ERROR,
"XenPvBlk: unrecognized block operation %d response (status %d)\n",
Response->operation,
Status
));
break;
}
Dev->Ring.rsp_cons = ++ConsumerIndex;
if (IoData != NULL) {
IoData->Status = Status ? EFI_DEVICE_ERROR : EFI_SUCCESS;
}
if (Dev->Ring.rsp_cons != ConsumerIndex) {
/* We reentered, we must not continue here */
break;

View File

@@ -11,50 +11,48 @@
#include <IndustryStandard/Xen/event_channel.h>
#include <IndustryStandard/Xen/io/blkif.h>
typedef struct _XEN_BLOCK_FRONT_DEVICE XEN_BLOCK_FRONT_DEVICE;
typedef struct _XEN_BLOCK_FRONT_IO XEN_BLOCK_FRONT_IO;
typedef struct _XEN_BLOCK_FRONT_DEVICE XEN_BLOCK_FRONT_DEVICE;
typedef struct _XEN_BLOCK_FRONT_IO XEN_BLOCK_FRONT_IO;
struct _XEN_BLOCK_FRONT_IO
{
XEN_BLOCK_FRONT_DEVICE *Dev;
UINT8 *Buffer;
UINTN Size;
UINTN Sector; ///< 512 bytes sector.
struct _XEN_BLOCK_FRONT_IO {
XEN_BLOCK_FRONT_DEVICE *Dev;
UINT8 *Buffer;
UINTN Size;
UINTN Sector; ///< 512 bytes sector.
grant_ref_t GrantRef[BLKIF_MAX_SEGMENTS_PER_REQUEST];
INT32 NumRef;
grant_ref_t GrantRef[BLKIF_MAX_SEGMENTS_PER_REQUEST];
INT32 NumRef;
EFI_STATUS Status;
EFI_STATUS Status;
};
typedef struct
{
UINT64 Sectors;
UINT32 SectorSize;
UINT32 VDiskInfo;
BOOLEAN ReadWrite;
BOOLEAN CdRom;
BOOLEAN FeatureBarrier;
BOOLEAN FeatureFlushCache;
typedef struct {
UINT64 Sectors;
UINT32 SectorSize;
UINT32 VDiskInfo;
BOOLEAN ReadWrite;
BOOLEAN CdRom;
BOOLEAN FeatureBarrier;
BOOLEAN FeatureFlushCache;
} XEN_BLOCK_FRONT_MEDIA_INFO;
#define XEN_BLOCK_FRONT_SIGNATURE SIGNATURE_32 ('X', 'p', 'v', 'B')
#define XEN_BLOCK_FRONT_SIGNATURE SIGNATURE_32 ('X', 'p', 'v', 'B')
struct _XEN_BLOCK_FRONT_DEVICE {
UINT32 Signature;
EFI_BLOCK_IO_PROTOCOL BlockIo;
domid_t DomainId;
UINT32 Signature;
EFI_BLOCK_IO_PROTOCOL BlockIo;
domid_t DomainId;
blkif_front_ring_t Ring;
grant_ref_t RingRef;
evtchn_port_t EventChannel;
blkif_vdev_t DeviceId;
blkif_front_ring_t Ring;
grant_ref_t RingRef;
evtchn_port_t EventChannel;
blkif_vdev_t DeviceId;
CONST CHAR8 *NodeName;
XEN_BLOCK_FRONT_MEDIA_INFO MediaInfo;
CONST CHAR8 *NodeName;
XEN_BLOCK_FRONT_MEDIA_INFO MediaInfo;
VOID *StateWatchToken;
VOID *StateWatchToken;
XENBUS_PROTOCOL *XenBusIo;
XENBUS_PROTOCOL *XenBusIo;
};
#define XEN_BLOCK_FRONT_FROM_BLOCK_IO(b) \
@@ -62,34 +60,34 @@ struct _XEN_BLOCK_FRONT_DEVICE {
EFI_STATUS
XenPvBlockFrontInitialization (
IN XENBUS_PROTOCOL *XenBusIo,
IN CONST CHAR8 *NodeName,
OUT XEN_BLOCK_FRONT_DEVICE **DevPtr
IN XENBUS_PROTOCOL *XenBusIo,
IN CONST CHAR8 *NodeName,
OUT XEN_BLOCK_FRONT_DEVICE **DevPtr
);
VOID
XenPvBlockFrontShutdown (
IN XEN_BLOCK_FRONT_DEVICE *Dev
IN XEN_BLOCK_FRONT_DEVICE *Dev
);
VOID
XenPvBlockAsyncIo (
IN OUT XEN_BLOCK_FRONT_IO *IoData,
IN BOOLEAN IsWrite
IN OUT XEN_BLOCK_FRONT_IO *IoData,
IN BOOLEAN IsWrite
);
EFI_STATUS
XenPvBlockIo (
IN OUT XEN_BLOCK_FRONT_IO *IoData,
IN BOOLEAN IsWrite
IN OUT XEN_BLOCK_FRONT_IO *IoData,
IN BOOLEAN IsWrite
);
VOID
XenPvBlockAsyncIoPoll (
IN XEN_BLOCK_FRONT_DEVICE *Dev
IN XEN_BLOCK_FRONT_DEVICE *Dev
);
VOID
XenPvBlockSync (
IN XEN_BLOCK_FRONT_DEVICE *Dev
IN XEN_BLOCK_FRONT_DEVICE *Dev
);

View File

@@ -46,9 +46,6 @@ EFI_BLOCK_IO_PROTOCOL gXenPvBlkDxeBlockIo = {
XenPvBlkDxeBlockIoFlushBlocks // FlushBlocks
};
/**
Read/Write BufferSize bytes from Lba into Buffer.
@@ -76,29 +73,38 @@ XenPvBlkDxeBlockIoReadWriteBlocks (
IN BOOLEAN IsWrite
)
{
XEN_BLOCK_FRONT_IO IoData;
EFI_BLOCK_IO_MEDIA *Media = This->Media;
UINTN Sector;
EFI_STATUS Status;
XEN_BLOCK_FRONT_IO IoData;
EFI_BLOCK_IO_MEDIA *Media = This->Media;
UINTN Sector;
EFI_STATUS Status;
if (Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
if (BufferSize == 0) {
return EFI_SUCCESS;
}
if (BufferSize % Media->BlockSize != 0) {
DEBUG ((DEBUG_ERROR, "XenPvBlkDxe: Bad buffer size: 0x%Lx\n",
(UINT64)BufferSize));
DEBUG ((
DEBUG_ERROR,
"XenPvBlkDxe: Bad buffer size: 0x%Lx\n",
(UINT64)BufferSize
));
return EFI_BAD_BUFFER_SIZE;
}
if (Lba > Media->LastBlock ||
(BufferSize / Media->BlockSize) - 1 > Media->LastBlock - Lba) {
DEBUG ((DEBUG_ERROR,
if ((Lba > Media->LastBlock) ||
((BufferSize / Media->BlockSize) - 1 > Media->LastBlock - Lba))
{
DEBUG ((
DEBUG_ERROR,
"XenPvBlkDxe: %a with invalid LBA: 0x%Lx, size: 0x%Lx\n",
IsWrite ? "Write" : "Read", Lba, (UINT64)BufferSize));
IsWrite ? "Write" : "Read",
Lba,
(UINT64)BufferSize
));
return EFI_INVALID_PARAMETER;
}
@@ -111,54 +117,74 @@ XenPvBlkDxeBlockIoReadWriteBlocks (
// Grub2 does not appear to respect IoAlign of 512, so reallocate the
// buffer here.
//
VOID *NewBuffer;
VOID *NewBuffer;
//
// Try again with a properly aligned buffer.
//
NewBuffer = AllocateAlignedPages((BufferSize + EFI_PAGE_SIZE) / EFI_PAGE_SIZE,
Media->IoAlign);
NewBuffer = AllocateAlignedPages (
(BufferSize + EFI_PAGE_SIZE) / EFI_PAGE_SIZE,
Media->IoAlign
);
if (!IsWrite) {
Status = XenPvBlkDxeBlockIoReadBlocks (This, MediaId,
Lba, BufferSize, NewBuffer);
Status = XenPvBlkDxeBlockIoReadBlocks (
This,
MediaId,
Lba,
BufferSize,
NewBuffer
);
CopyMem (Buffer, NewBuffer, BufferSize);
} else {
CopyMem (NewBuffer, Buffer, BufferSize);
Status = XenPvBlkDxeBlockIoWriteBlocks (This, MediaId,
Lba, BufferSize, NewBuffer);
Status = XenPvBlkDxeBlockIoWriteBlocks (
This,
MediaId,
Lba,
BufferSize,
NewBuffer
);
}
FreeAlignedPages (NewBuffer, (BufferSize + EFI_PAGE_SIZE) / EFI_PAGE_SIZE);
return Status;
}
IoData.Dev = XEN_BLOCK_FRONT_FROM_BLOCK_IO (This);
Sector = (UINTN)MultU64x32 (Lba, Media->BlockSize / 512);
Sector = (UINTN)MultU64x32 (Lba, Media->BlockSize / 512);
while (BufferSize > 0) {
if (((UINTN)Buffer & EFI_PAGE_MASK) == 0) {
IoData.Size = MIN (BLKIF_MAX_SEGMENTS_PER_REQUEST * EFI_PAGE_SIZE,
BufferSize);
IoData.Size = MIN (
BLKIF_MAX_SEGMENTS_PER_REQUEST * EFI_PAGE_SIZE,
BufferSize
);
} else {
IoData.Size = MIN ((BLKIF_MAX_SEGMENTS_PER_REQUEST - 1) * EFI_PAGE_SIZE,
BufferSize);
IoData.Size = MIN (
(BLKIF_MAX_SEGMENTS_PER_REQUEST - 1) * EFI_PAGE_SIZE,
BufferSize
);
}
IoData.Buffer = Buffer;
IoData.Sector = Sector;
BufferSize -= IoData.Size;
Buffer = (VOID*) ((UINTN) Buffer + IoData.Size);
Sector += IoData.Size / 512;
Status = XenPvBlockIo (&IoData, IsWrite);
BufferSize -= IoData.Size;
Buffer = (VOID *)((UINTN)Buffer + IoData.Size);
Sector += IoData.Size / 512;
Status = XenPvBlockIo (&IoData, IsWrite);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "XenPvBlkDxe: Error during %a operation.\n",
IsWrite ? "write" : "read"));
DEBUG ((
DEBUG_ERROR,
"XenPvBlkDxe: Error during %a operation.\n",
IsWrite ? "write" : "read"
));
return Status;
}
}
return EFI_SUCCESS;
}
/**
Read BufferSize bytes from Lba into Buffer.
@@ -181,15 +207,21 @@ XenPvBlkDxeBlockIoReadWriteBlocks (
EFI_STATUS
EFIAPI
XenPvBlkDxeBlockIoReadBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
)
{
return XenPvBlkDxeBlockIoReadWriteBlocks (This,
MediaId, Lba, BufferSize, Buffer, FALSE);
return XenPvBlkDxeBlockIoReadWriteBlocks (
This,
MediaId,
Lba,
BufferSize,
Buffer,
FALSE
);
}
/**
@@ -215,15 +247,21 @@ XenPvBlkDxeBlockIoReadBlocks (
EFI_STATUS
EFIAPI
XenPvBlkDxeBlockIoWriteBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
return XenPvBlkDxeBlockIoReadWriteBlocks (This,
MediaId, Lba, BufferSize, Buffer, TRUE);
return XenPvBlkDxeBlockIoReadWriteBlocks (
This,
MediaId,
Lba,
BufferSize,
Buffer,
TRUE
);
}
/**
@@ -258,8 +296,8 @@ XenPvBlkDxeBlockIoFlushBlocks (
EFI_STATUS
EFIAPI
XenPvBlkDxeBlockIoReset (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
//

View File

@@ -29,11 +29,11 @@
EFI_STATUS
EFIAPI
XenPvBlkDxeBlockIoReadBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
);
/**
@@ -59,11 +59,11 @@ XenPvBlkDxeBlockIoReadBlocks (
EFI_STATUS
EFIAPI
XenPvBlkDxeBlockIoWriteBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
);
/**
@@ -94,9 +94,9 @@ XenPvBlkDxeBlockIoFlushBlocks (
EFI_STATUS
EFIAPI
XenPvBlkDxeBlockIoReset (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
extern EFI_BLOCK_IO_MEDIA gXenPvBlkDxeBlockIoMedia;
extern EFI_BLOCK_IO_MEDIA gXenPvBlkDxeBlockIoMedia;
extern EFI_BLOCK_IO_PROTOCOL gXenPvBlkDxeBlockIo;

View File

@@ -14,7 +14,7 @@
///
GLOBAL_REMOVE_IF_UNREFERENCED
EFI_COMPONENT_NAME_PROTOCOL gXenPvBlkDxeComponentName = {
(EFI_COMPONENT_NAME_GET_DRIVER_NAME) XenPvBlkDxeComponentNameGetDriverName,
(EFI_COMPONENT_NAME_GET_DRIVER_NAME)XenPvBlkDxeComponentNameGetDriverName,
(EFI_COMPONENT_NAME_GET_CONTROLLER_NAME)XenPvBlkDxeComponentNameGetControllerName,
"eng"
};
@@ -33,18 +33,18 @@ EFI_COMPONENT_NAME2_PROTOCOL gXenPvBlkDxeComponentName2 = {
/// Table of driver names
///
GLOBAL_REMOVE_IF_UNREFERENCED
EFI_UNICODE_STRING_TABLE mXenPvBlkDxeDriverNameTable[] = {
EFI_UNICODE_STRING_TABLE mXenPvBlkDxeDriverNameTable[] = {
{ "eng;en", (CHAR16 *)L"Xen PV Block Driver" },
{ NULL, NULL }
{ NULL, NULL }
};
///
/// Table of controller names
///
GLOBAL_REMOVE_IF_UNREFERENCED
EFI_UNICODE_STRING_TABLE mXenPvBlkDxeControllerNameTable[] = {
EFI_UNICODE_STRING_TABLE mXenPvBlkDxeControllerNameTable[] = {
{ "eng;en", (CHAR16 *)L"Xen PV Block Device" },
{ NULL, NULL }
{ NULL, NULL }
};
/**

View File

@@ -1,4 +1,3 @@
/** @file
Driver Binding functions declaration for XenPvBlk driver.

View File

@@ -16,11 +16,10 @@
#include "BlockFront.h"
///
/// Driver Binding Protocol instance
///
EFI_DRIVER_BINDING_PROTOCOL gXenPvBlkDxeDriverBinding = {
EFI_DRIVER_BINDING_PROTOCOL gXenPvBlkDxeDriverBinding = {
XenPvBlkDxeDriverBindingSupported,
XenPvBlkDxeDriverBindingStart,
XenPvBlkDxeDriverBindingStop,
@@ -29,7 +28,6 @@ EFI_DRIVER_BINDING_PROTOCOL gXenPvBlkDxeDriverBinding = {
NULL
};
/**
Unloads an image.
@@ -51,7 +49,6 @@ XenPvBlkDxeUnload (
UINTN HandleCount;
UINTN Index;
//
// Retrieve array of all handles in the handle database
//
@@ -78,15 +75,17 @@ XenPvBlkDxeUnload (
//
FreePool (HandleBuffer);
//
// Uninstall protocols installed in the driver entry point
//
Status = gBS->UninstallMultipleProtocolInterfaces (
ImageHandle,
&gEfiDriverBindingProtocolGuid, &gXenPvBlkDxeDriverBinding,
&gEfiComponentNameProtocolGuid, &gXenPvBlkDxeComponentName,
&gEfiComponentName2ProtocolGuid, &gXenPvBlkDxeComponentName2,
&gEfiDriverBindingProtocolGuid,
&gXenPvBlkDxeDriverBinding,
&gEfiComponentNameProtocolGuid,
&gXenPvBlkDxeComponentName,
&gEfiComponentName2ProtocolGuid,
&gXenPvBlkDxeComponentName2,
NULL
);
if (EFI_ERROR (Status)) {
@@ -132,7 +131,6 @@ XenPvBlkDxeDriverEntryPoint (
return Status;
}
/**
Tests to see if this driver supports a given controller. If a child device is provided,
it further tests to see if this driver supports creating a handle for the specified child device.
@@ -183,28 +181,33 @@ XenPvBlkDxeDriverBindingSupported (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
EFI_STATUS Status;
XENBUS_PROTOCOL *XenBusIo;
EFI_STATUS Status;
XENBUS_PROTOCOL *XenBusIo;
Status = gBS->OpenProtocol (
ControllerHandle,
&gXenBusProtocolGuid,
(VOID **)&XenBusIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
ControllerHandle,
&gXenBusProtocolGuid,
(VOID **)&XenBusIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
if (AsciiStrCmp (XenBusIo->Type, "vbd") == 0) {
Status = EFI_SUCCESS;
} else {
Status = EFI_UNSUPPORTED;
}
gBS->CloseProtocol (ControllerHandle, &gXenBusProtocolGuid,
This->DriverBindingHandle, ControllerHandle);
gBS->CloseProtocol (
ControllerHandle,
&gXenBusProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return Status;
}
@@ -252,19 +255,19 @@ XenPvBlkDxeDriverBindingStart (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
EFI_STATUS Status;
XENBUS_PROTOCOL *XenBusIo;
XEN_BLOCK_FRONT_DEVICE *Dev;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
XENBUS_PROTOCOL *XenBusIo;
XEN_BLOCK_FRONT_DEVICE *Dev;
EFI_BLOCK_IO_MEDIA *Media;
Status = gBS->OpenProtocol (
ControllerHandle,
&gXenBusProtocolGuid,
(VOID **)&XenBusIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
ControllerHandle,
&gXenBusProtocolGuid,
(VOID **)&XenBusIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -275,13 +278,16 @@ XenPvBlkDxeDriverBindingStart (
}
CopyMem (&Dev->BlockIo, &gXenPvBlkDxeBlockIo, sizeof (EFI_BLOCK_IO_PROTOCOL));
Media = AllocateCopyPool (sizeof (EFI_BLOCK_IO_MEDIA),
&gXenPvBlkDxeBlockIoMedia);
Media = AllocateCopyPool (
sizeof (EFI_BLOCK_IO_MEDIA),
&gXenPvBlkDxeBlockIoMedia
);
if (Dev->MediaInfo.VDiskInfo & VDISK_REMOVABLE) {
Media->RemovableMedia = TRUE;
}
Media->MediaPresent = TRUE;
Media->ReadOnly = !Dev->MediaInfo.ReadWrite;
Media->ReadOnly = !Dev->MediaInfo.ReadWrite;
if (Dev->MediaInfo.CdRom) {
//
// If it's a cdrom, the blocksize value need to be 2048 for OVMF to
@@ -289,20 +295,24 @@ XenPvBlkDxeDriverBindingStart (
// MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
//
Media->BlockSize = 2048;
Media->LastBlock = DivU64x32 (Dev->MediaInfo.Sectors,
Media->BlockSize / Dev->MediaInfo.SectorSize) - 1;
Media->LastBlock = DivU64x32 (
Dev->MediaInfo.Sectors,
Media->BlockSize / Dev->MediaInfo.SectorSize
) - 1;
} else {
Media->BlockSize = Dev->MediaInfo.SectorSize;
Media->LastBlock = Dev->MediaInfo.Sectors - 1;
}
ASSERT (Media->BlockSize % 512 == 0);
Dev->BlockIo.Media = Media;
Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiBlockIoProtocolGuid, &Dev->BlockIo,
NULL
);
&ControllerHandle,
&gEfiBlockIoProtocolGuid,
&Dev->BlockIo,
NULL
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "XenPvBlk: install protocol fail: %r\n", Status));
goto UninitBlockFront;
@@ -314,8 +324,12 @@ UninitBlockFront:
FreePool (Media);
XenPvBlockFrontShutdown (Dev);
CloseProtocol:
gBS->CloseProtocol (ControllerHandle, &gXenBusProtocolGuid,
This->DriverBindingHandle, ControllerHandle);
gBS->CloseProtocol (
ControllerHandle,
&gXenBusProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return Status;
}
@@ -354,35 +368,44 @@ XenPvBlkDxeDriverBindingStop (
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
)
{
EFI_BLOCK_IO_PROTOCOL *BlockIo;
XEN_BLOCK_FRONT_DEVICE *Dev;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
XEN_BLOCK_FRONT_DEVICE *Dev;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
Status = gBS->OpenProtocol (
ControllerHandle, &gEfiBlockIoProtocolGuid,
ControllerHandle,
&gEfiBlockIoProtocolGuid,
(VOID **)&BlockIo,
This->DriverBindingHandle, ControllerHandle,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->UninstallProtocolInterface (ControllerHandle,
&gEfiBlockIoProtocolGuid, BlockIo);
Status = gBS->UninstallProtocolInterface (
ControllerHandle,
&gEfiBlockIoProtocolGuid,
BlockIo
);
if (EFI_ERROR (Status)) {
return Status;
}
Media = BlockIo->Media;
Dev = XEN_BLOCK_FRONT_FROM_BLOCK_IO (BlockIo);
Dev = XEN_BLOCK_FRONT_FROM_BLOCK_IO (BlockIo);
XenPvBlockFrontShutdown (Dev);
FreePool (Media);
gBS->CloseProtocol (ControllerHandle, &gXenBusProtocolGuid,
This->DriverBindingHandle, ControllerHandle);
gBS->CloseProtocol (
ControllerHandle,
&gXenBusProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return EFI_SUCCESS;
}

View File

@@ -12,9 +12,9 @@
#include <Uefi.h>
#define xen_mb() MemoryFence()
#define xen_rmb() MemoryFence()
#define xen_wmb() MemoryFence()
#define xen_mb() MemoryFence()
#define xen_rmb() MemoryFence()
#define xen_wmb() MemoryFence()
//
// Libraries
@@ -27,7 +27,6 @@
#include <Library/DevicePathLib.h>
#include <Library/DebugLib.h>
//
// UEFI Driver Model Protocols
//
@@ -35,32 +34,27 @@
#include <Protocol/ComponentName2.h>
#include <Protocol/ComponentName.h>
//
// Consumed Protocols
//
#include <Protocol/XenBus.h>
//
// Produced Protocols
//
#include <Protocol/BlockIo.h>
//
// Driver Version
//
#define XEN_PV_BLK_DXE_VERSION 0x00000010
//
// Protocol instances
//
extern EFI_DRIVER_BINDING_PROTOCOL gXenPvBlkDxeDriverBinding;
extern EFI_DRIVER_BINDING_PROTOCOL gXenPvBlkDxeDriverBinding;
extern EFI_COMPONENT_NAME2_PROTOCOL gXenPvBlkDxeComponentName2;
extern EFI_COMPONENT_NAME_PROTOCOL gXenPvBlkDxeComponentName;
extern EFI_COMPONENT_NAME_PROTOCOL gXenPvBlkDxeComponentName;
//
// Include files with function prototypes
@@ -69,5 +63,4 @@ extern EFI_COMPONENT_NAME_PROTOCOL gXenPvBlkDxeComponentName;
#include "ComponentName.h"
#include "BlockIo.h"
#endif