diff --git a/drivers/virtual_media/VirtioDevice.h b/drivers/virtual_media/VirtioDevice.h index 4ef5cb7..d7989c9 100755 --- a/drivers/virtual_media/VirtioDevice.h +++ b/drivers/virtual_media/VirtioDevice.h @@ -1,527 +1,201 @@ -/** @file - Virtio Device - - DISCLAIMER: the VIRTIO_DEVICE_PROTOCOL introduced here is a work in progress, - and should not be used outside of the EDK II tree. - - Copyright (c) 2013, ARM Ltd. All rights reserved.
- Copyright (c) 2017, AMD Inc, All rights reserved.
- - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License which accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __VIRTIO_DEVICE_H__ -#define __VIRTIO_DEVICE_H__ - -//#include -#include "Virtio.h" - -// -// VirtIo Specification Revision: Major[31:24].Minor[23:16].Revision[15:0] -// -#define VIRTIO_SPEC_REVISION(major,minor,revision) \ - ((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | ((revision) & 0xFFFF)) - -#define VIRTIO_DEVICE_PROTOCOL_GUID { \ - 0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a }\ - } - -typedef struct _VIRTIO_DEVICE_PROTOCOL VIRTIO_DEVICE_PROTOCOL; - -// -// VIRTIO Operation for VIRTIO_MAP_SHARED -// -typedef enum { - // - // A read operation from system memory by a bus master - // - VirtioOperationBusMasterRead, - // - // A write operation to system memory by a bus master - // - VirtioOperationBusMasterWrite, - // - // Provides both read and write access to system memory by both the - // processor and a bus master - // - VirtioOperationBusMasterCommonBuffer, -} VIRTIO_MAP_OPERATION; - -/** - - Read a word from the device-specific I/O region of the Virtio Header. - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[in] FieldOffset Source offset. - - @param[in] FieldSize Source field size in bytes, must be in {1, 2, 4, 8}. - - @param[in] BufferSize Number of bytes available in the target buffer. Must - equal FieldSize. - - @param[out] Buffer Target buffer. - - @retval EFI_SUCCESS The data was read successfully. - @retval EFI_UNSUPPORTED The underlying IO device doesn't support the - provided address offset and read size. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a - lack of resources. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_DEVICE_READ) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINTN FieldOffset, - IN UINTN FieldSize, - IN UINTN BufferSize, - OUT VOID *Buffer - ); - -/** - - Write a word to the device-specific I/O region of the Virtio Header. - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[in] FieldOffset Destination offset. - - @param[in] FieldSize Destination field size in bytes, - must be in {1, 2, 4, 8}. - - @param[out] Value Value to write. - - @retval EFI_SUCCESS The data was written successfully. - @retval EFI_UNSUPPORTED The underlying IO device doesn't support the - provided address offset and write size. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a - lack of resources. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_DEVICE_WRITE) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINTN FieldOffset, - IN UINTN FieldSize, - IN UINT64 Value - ); - -/** - Read the device features field from the Virtio Header. - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[out] DeviceFeatures The device features field. - - @retval EFI_SUCCESS The data was read successfully. - @retval EFI_UNSUPPORTED The underlying IO device doesn't support the - provided address offset and read size. - @retval EFI_INVALID_PARAMETER DeviceFeatures is NULL -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_GET_DEVICE_FEATURES) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT64 *DeviceFeatures - ); - -/** - Write the guest features field in the Virtio Header. - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[in] Features The guest features field - -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_SET_GUEST_FEATURES) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINT64 Features - ); - -/** - Write the queue address field(s) in the Virtio Header. - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[in] Ring The initialized VRING object to take the - addresses from. The caller is responsible for - ensuring that on input, all Ring->NumPages pages, - starting at Ring->Base, have been successfully - mapped with a single call to - This->MapSharedBuffer() for CommonBuffer bus - master operation. - - @param[in] RingBaseShift Adding this value using UINT64 arithmetic to the - addresses found in Ring translates them from - system memory to bus addresses. The caller shall - calculate RingBaseShift as - (DeviceAddress - (UINT64)(UINTN)HostAddress), - where DeviceAddress and HostAddress (i.e., - Ring->Base) were output and input parameters of - This->MapSharedBuffer(), respectively. - - @retval EFI_SUCCESS The data was written successfully. - @retval EFI_UNSUPPORTED The underlying IO device doesn't support the - provided address offset and write size. -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_SET_QUEUE_ADDRESS) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN VRING *Ring, - IN UINT64 RingBaseShift - ); - -/** - - Write the queue select field in the Virtio Header. - - Writing to the queue select field sets the index of the queue to which - operations such as SetQueueAlign and GetQueueNumMax apply. - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[in] Index The index of the queue to select - - @retval EFI_SUCCESS The data was written successfully. - @retval EFI_UNSUPPORTED The underlying IO device doesn't support the - provided address offset and write size. -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_SET_QUEUE_SEL) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINT16 Index - ); - -/** - - Write the queue notify field in the Virtio Header. - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[in] Address The 32-bit Queue Notify field - - @retval EFI_SUCCESS The data was written successfully. - @retval EFI_UNSUPPORTED The underlying IO device doesn't support the - provided address offset and write size. -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_SET_QUEUE_NOTIFY) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINT16 Index - ); - -/** - Write the queue alignment field in the Virtio Header. - - The queue to which the alignment applies is selected by the Queue Select - field. - - Note: This operation is not implemented by the VirtIo over PCI. The PCI - implementation of this protocol returns EFI_SUCCESS. - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[in] Alignment The alignment boundary of the Used Ring in bytes. - Must be a power of 2. - - @retval EFI_SUCCESS The data was written successfully. - @retval EFI_UNSUPPORTED The underlying IO device doesn't support the - provided address offset and write size. -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_SET_QUEUE_ALIGN) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINT32 Alignment - ); - -/** - Write the guest page size. - - Note: This operation is not implemented by the VirtIo over PCI. The PCI - implementation of this protocol returns EFI_SUCCESS. - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[in] PageSize Size of the Guest page in bytes. - Must be a power of 2. - - @retval EFI_SUCCESS The data was written successfully. - @retval EFI_UNSUPPORTED The underlying IO device doesn't support the - provided address offset and write size. -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_SET_PAGE_SIZE) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINT32 PageSize - ); - -/** - - Get the size of the virtqueue selected by the queue select field. - - See Virtio spec Section 2.3 - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[out] QueueNumMax The size of the virtqueue in bytes. - Always a power of 2. - - @retval EFI_SUCCESS The data was read successfully. - @retval EFI_UNSUPPORTED The underlying IO device doesn't support the - provided address offset and read size. - @retval EFI_INVALID_PARAMETER QueueNumMax is NULL -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_GET_QUEUE_NUM_MAX) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT16 *QueueNumMax - ); - -/** - - Write to the QueueNum field in the Virtio Header. - - This function only applies to Virtio-MMIO and may be a stub for other - implementations. See Virtio Spec appendix X. - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[in] QueueSize The number of elements in the queue. - - @retval EFI_SUCCESS The data was written successfully. - @retval EFI_UNSUPPORTED The underlying IO device doesn't support the - provided address offset and write size. -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_SET_QUEUE_NUM) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINT16 QueueSize - ); - -/** - - Get the DeviceStatus field from the Virtio Header. - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[out] DeviceStatus The 8-bit value for the Device status field - - @retval EFI_SUCCESS The data was read successfully. - @retval EFI_UNSUPPORTED The underlying IO device doesn't support the - provided address offset and read size. - @retval EFI_INVALID_PARAMETER DeviceStatus is NULL -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_GET_DEVICE_STATUS) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT8 *DeviceStatus - ); - -/** - - Write the DeviceStatus field in the Virtio Header. - - @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - - @param[in] DeviceStatus The 8-bit value for the Device status field - - @retval EFI_SUCCESS The data was written successfully. - @retval EFI_UNSUPPORTED The underlying IO device doesn't support the - provided address offset and write size. -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_SET_DEVICE_STATUS) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINT8 DeviceStatus - ); - -/** - - Allocates pages that are suitable for an VirtioOperationBusMasterCommonBuffer - mapping. This means that the buffer allocated by this function supports - simultaneous access by both the processor and the bus master. The device - address that the bus master uses to access the buffer must be retrieved with - a call to VIRTIO_MAP_SHARED. - - @param[in] This The protocol instance pointer. - - @param[in] Pages The number of pages to allocate. - - @param[in,out] HostAddress A pointer to store the system memory base - address of the allocated range. - - @retval EFI_SUCCESS The requested memory pages were allocated. - @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. - -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_ALLOCATE_SHARED)( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINTN Pages, - IN OUT VOID **HostAddress - ); - -/** - Frees memory that was allocated with VIRTIO_ALLOCATE_SHARED. - - @param[in] This The protocol instance pointer. - - @param[in] Pages The number of pages to free. - - @param[in] HostAddress The system memory base address of the allocated - range. - -**/ -typedef -VOID -(EFIAPI *VIRTIO_FREE_SHARED)( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINTN Pages, - IN VOID *HostAddress - ); - -/** - Provides the virtio device address required to access system memory from a - DMA bus master. - - The interface follows the same usage pattern as defined in UEFI spec 2.6 - (Section 13.2 PCI Root Bridge I/O Protocol) - - @param[in] This The protocol instance pointer. - - @param[in] Operation Indicates if the bus master is going to - read or write to system memory. - - @param[in] HostAddress The system memory address to map to shared - buffer address. - - @param[in,out] NumberOfBytes On input the number of bytes to map. - On output the number of bytes that were - mapped. - - @param[out] DeviceAddress The resulting shared map address for the - bus master to access the hosts HostAddress. - - @param[out] Mapping A resulting token to pass to - VIRTIO_UNMAP_SHARED. - - @retval EFI_SUCCESS The range was mapped for the returned - NumberOfBytes. - @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a - common buffer. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to - a lack of resources. - @retval EFI_DEVICE_ERROR The system hardware could not map the - requested address. -**/ - -typedef -EFI_STATUS -(EFIAPI *VIRTIO_MAP_SHARED) ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN VIRTIO_MAP_OPERATION Operation, - IN VOID *HostAddress, - IN OUT UINTN *NumberOfBytes, - OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, - OUT VOID **Mapping - ); - -/** - Completes the VIRTIO_MAP_SHARED operation and releases any corresponding - resources. - - @param[in] This The protocol instance pointer. - - @param[in] Mapping The mapping token returned from - VIRTIO_MAP_SHARED. - - @retval EFI_SUCCESS The range was unmapped. - @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by - VIRTIO_MAP_SHARED. Passing an invalid Mapping - token can cause undefined behavior. - @retval EFI_DEVICE_ERROR The data was not committed to the target - system memory. -**/ -typedef -EFI_STATUS -(EFIAPI *VIRTIO_UNMAP_SHARED)( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN VOID *Mapping - ); - -/// -/// This protocol provides an abstraction over the VirtIo transport layer -/// -/// DISCLAIMER: this protocol is a work in progress, and should not be used -/// outside of the EDK II tree. -/// -struct _VIRTIO_DEVICE_PROTOCOL { - // - // VirtIo Specification Revision encoded with VIRTIO_SPEC_REVISION() - // - UINT32 Revision; - // - // From the Virtio Spec - // - INT32 SubSystemDeviceId; - - VIRTIO_GET_DEVICE_FEATURES GetDeviceFeatures; - VIRTIO_SET_GUEST_FEATURES SetGuestFeatures; - - VIRTIO_SET_QUEUE_ADDRESS SetQueueAddress; - - VIRTIO_SET_QUEUE_SEL SetQueueSel; - - VIRTIO_SET_QUEUE_NOTIFY SetQueueNotify; - - VIRTIO_SET_QUEUE_ALIGN SetQueueAlign; - VIRTIO_SET_PAGE_SIZE SetPageSize; - - VIRTIO_GET_QUEUE_NUM_MAX GetQueueNumMax; - VIRTIO_SET_QUEUE_NUM SetQueueNum; - - VIRTIO_GET_DEVICE_STATUS GetDeviceStatus; - VIRTIO_SET_DEVICE_STATUS SetDeviceStatus; - - // - // Functions to read/write Device Specific headers - // - VIRTIO_DEVICE_WRITE WriteDevice; - VIRTIO_DEVICE_READ ReadDevice; - - // - // Functions to allocate, free, map and unmap shared buffer - // - VIRTIO_ALLOCATE_SHARED AllocateSharedPages; - VIRTIO_FREE_SHARED FreeSharedPages; - VIRTIO_MAP_SHARED MapSharedBuffer; - VIRTIO_UNMAP_SHARED UnmapSharedBuffer; -}; - -extern EFI_GUID gVirtioDeviceProtocolGuid; - -#endif +/** @file + + Copyright (c) 2018, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + + +#ifndef __VIRTIO_DEVICE_COMMON_H__ +#define __VIRTIO_DEVICE_COMMON_H__ + +#include + +#define VIRTUAL_MEDIA_DEBUG 0 +#if VIRTUAL_MEDIA_DEBUG +#define virtual_media_dbg(a,...) {printf(a);printf(__VA_ARGS__);} +#else +#define virtual_media_dbg(...) +#endif + +#ifdef DEBUG_INFO +#undef DEBUG_INFO +#endif +#define DEBUG_INFO "VIRTUAL MEDIA Debug: " + +#ifdef DEBUG +#undef DEBUG +#endif +#define DEBUG(a) virtual_media_dbg a + +#ifdef ASSERT +#undef ASSERT +#endif +#define ASSERT assert + +#define MemoryFence() __asm__ __volatile__("mfence": : :"memory") +/// +/// Maximum values for common UEFI Data Types +/// +#define MAX_INT8 ((INT8)0x7F) +#define MAX_UINT8 ((UINT8)0xFF) +#define MAX_INT16 ((INT16)0x7FFF) +#define MAX_UINT16 ((UINT16)0xFFFF) +#define MAX_INT32 ((INT32)0x7FFFFFFF) +#define MAX_UINT32 ((UINT32)0xFFFFFFFF) +#define MAX_INT64 ((INT64)0x7FFFFFFFFFFFFFFFULL) +#define MAX_UINT64 ((UINT64)0xFFFFFFFFFFFFFFFFULL) + +#define BIT0 0x00000001 +#define BIT1 0x00000002 +#define BIT2 0x00000004 +#define BIT3 0x00000008 +#define BIT4 0x00000010 +#define BIT5 0x00000020 +#define BIT6 0x00000040 +#define BIT7 0x00000080 +#define BIT8 0x00000100 +#define BIT9 0x00000200 +#define BIT10 0x00000400 +#define BIT11 0x00000800 +#define BIT12 0x00001000 +#define BIT13 0x00002000 +#define BIT14 0x00004000 +#define BIT15 0x00008000 +#define BIT16 0x00010000 +#define BIT17 0x00020000 +#define BIT18 0x00040000 +#define BIT19 0x00080000 +#define BIT20 0x00100000 +#define BIT21 0x00200000 +#define BIT22 0x00400000 +#define BIT23 0x00800000 +#define BIT24 0x01000000 +#define BIT25 0x02000000 +#define BIT26 0x04000000 +#define BIT27 0x08000000 +#define BIT28 0x10000000 +#define BIT29 0x20000000 +#define BIT30 0x40000000 +#define BIT31 0x80000000 +#define BIT32 0x0000000100000000ULL +#define BIT33 0x0000000200000000ULL +#define BIT34 0x0000000400000000ULL +#define BIT35 0x0000000800000000ULL +#define BIT36 0x0000001000000000ULL +#define BIT37 0x0000002000000000ULL +#define BIT38 0x0000004000000000ULL +#define BIT39 0x0000008000000000ULL +#define BIT40 0x0000010000000000ULL +#define BIT41 0x0000020000000000ULL +#define BIT42 0x0000040000000000ULL +#define BIT43 0x0000080000000000ULL +#define BIT44 0x0000100000000000ULL +#define BIT45 0x0000200000000000ULL +#define BIT46 0x0000400000000000ULL +#define BIT47 0x0000800000000000ULL +#define BIT48 0x0001000000000000ULL +#define BIT49 0x0002000000000000ULL +#define BIT50 0x0004000000000000ULL +#define BIT51 0x0008000000000000ULL +#define BIT52 0x0010000000000000ULL +#define BIT53 0x0020000000000000ULL +#define BIT54 0x0040000000000000ULL +#define BIT55 0x0080000000000000ULL +#define BIT56 0x0100000000000000ULL +#define BIT57 0x0200000000000000ULL +#define BIT58 0x0400000000000000ULL +#define BIT59 0x0800000000000000ULL +#define BIT60 0x1000000000000000ULL +#define BIT61 0x2000000000000000ULL +#define BIT62 0x4000000000000000ULL +#define BIT63 0x8000000000000000ULL + +/** + The macro that returns the byte offset of a field in a data structure. + + This function returns the offset, in bytes, of field specified by Field from the + beginning of the data structure specified by TYPE. If TYPE does not contain Field, + the module will not compile. + + @param TYPE The name of the data structure that contains the field specified by Field. + @param Field The name of the field in the data structure. + + @return Offset, in bytes, of field. + +**/ +#ifdef __GNUC__ +#if __GNUC__ >= 4 +#define OFFSET_OF(TYPE, Field) ((UINTN) __builtin_offsetof(TYPE, Field)) +#endif +#endif + +#ifndef OFFSET_OF +#define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field)) +#endif + +/** + Returns a 16-bit signature built from 2 ASCII characters. + + This macro returns a 16-bit value built from the two ASCII characters specified + by A and B. + + @param A The first ASCII character. + @param B The second ASCII character. + + @return A 16-bit value built from the two ASCII characters specified by A and B. + +**/ +#define SIGNATURE_16(A, B) ((A) | (B << 8)) + +/** + Returns a 32-bit signature built from 4 ASCII characters. + + This macro returns a 32-bit value built from the four ASCII characters specified + by A, B, C, and D. + + @param A The first ASCII character. + @param B The second ASCII character. + @param C The third ASCII character. + @param D The fourth ASCII character. + + @return A 32-bit value built from the two ASCII characters specified by A, B, + C and D. + +**/ +#define SIGNATURE_32(A, B, C, D) (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C, D) << 16)) + +/** + Returns a 64-bit signature built from 8 ASCII characters. + + This macro returns a 64-bit value built from the eight ASCII characters specified + by A, B, C, D, E, F, G,and H. + + @param A The first ASCII character. + @param B The second ASCII character. + @param C The third ASCII character. + @param D The fourth ASCII character. + @param E The fifth ASCII character. + @param F The sixth ASCII character. + @param G The seventh ASCII character. + @param H The eighth ASCII character. + + @return A 64-bit value built from the two ASCII characters specified by A, B, + C, D, E, F, G and H. + +**/ +#define SIGNATURE_64(A, B, C, D, E, F, G, H) \ + (SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32)) + +typedef struct { + UINT64 BlockNum; + UINT32 BlockSize; +} DEVICE_BLOCK_INFO; + +#endif diff --git a/drivers/virtual_media/VirtioDeviceCommon.h b/drivers/virtual_media/VirtioDeviceCommon.h deleted file mode 100755 index 6c803a2..0000000 --- a/drivers/virtual_media/VirtioDeviceCommon.h +++ /dev/null @@ -1,201 +0,0 @@ -/** @file - - Copyright (c) 2018, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - - -#ifndef __VIRTIO_DEVICE_COMMON_H__ -#define __VIRTIO_DEVICE_COMMON_H__ - -#include - -#define VIRTUAL_MEDIA_DEBUG 0 -#if VIRTUAL_MEDIA_DEBUG -#define virtual_media_dbg(a,...) {printf(a);printf(__VA_ARGS__);} -#else -#define virtual_media_dbg(...) -#endif - -#ifdef DEBUG_INFO -#undef DEBUG_INFO -#endif -#define DEBUG_INFO "VIRTUAL MEDIA Debug: " - -#ifdef DEBUG -#undef DEBUG -#endif -#define DEBUG(a) virtual_media_dbg a - -#ifdef ASSERT -#undef ASSERT -#endif -#define ASSERT assert - -#define MemoryFence() __asm__ __volatile__("": : :"memory") -/// -/// Maximum values for common UEFI Data Types -/// -#define MAX_INT8 ((INT8)0x7F) -#define MAX_UINT8 ((UINT8)0xFF) -#define MAX_INT16 ((INT16)0x7FFF) -#define MAX_UINT16 ((UINT16)0xFFFF) -#define MAX_INT32 ((INT32)0x7FFFFFFF) -#define MAX_UINT32 ((UINT32)0xFFFFFFFF) -#define MAX_INT64 ((INT64)0x7FFFFFFFFFFFFFFFULL) -#define MAX_UINT64 ((UINT64)0xFFFFFFFFFFFFFFFFULL) - -#define BIT0 0x00000001 -#define BIT1 0x00000002 -#define BIT2 0x00000004 -#define BIT3 0x00000008 -#define BIT4 0x00000010 -#define BIT5 0x00000020 -#define BIT6 0x00000040 -#define BIT7 0x00000080 -#define BIT8 0x00000100 -#define BIT9 0x00000200 -#define BIT10 0x00000400 -#define BIT11 0x00000800 -#define BIT12 0x00001000 -#define BIT13 0x00002000 -#define BIT14 0x00004000 -#define BIT15 0x00008000 -#define BIT16 0x00010000 -#define BIT17 0x00020000 -#define BIT18 0x00040000 -#define BIT19 0x00080000 -#define BIT20 0x00100000 -#define BIT21 0x00200000 -#define BIT22 0x00400000 -#define BIT23 0x00800000 -#define BIT24 0x01000000 -#define BIT25 0x02000000 -#define BIT26 0x04000000 -#define BIT27 0x08000000 -#define BIT28 0x10000000 -#define BIT29 0x20000000 -#define BIT30 0x40000000 -#define BIT31 0x80000000 -#define BIT32 0x0000000100000000ULL -#define BIT33 0x0000000200000000ULL -#define BIT34 0x0000000400000000ULL -#define BIT35 0x0000000800000000ULL -#define BIT36 0x0000001000000000ULL -#define BIT37 0x0000002000000000ULL -#define BIT38 0x0000004000000000ULL -#define BIT39 0x0000008000000000ULL -#define BIT40 0x0000010000000000ULL -#define BIT41 0x0000020000000000ULL -#define BIT42 0x0000040000000000ULL -#define BIT43 0x0000080000000000ULL -#define BIT44 0x0000100000000000ULL -#define BIT45 0x0000200000000000ULL -#define BIT46 0x0000400000000000ULL -#define BIT47 0x0000800000000000ULL -#define BIT48 0x0001000000000000ULL -#define BIT49 0x0002000000000000ULL -#define BIT50 0x0004000000000000ULL -#define BIT51 0x0008000000000000ULL -#define BIT52 0x0010000000000000ULL -#define BIT53 0x0020000000000000ULL -#define BIT54 0x0040000000000000ULL -#define BIT55 0x0080000000000000ULL -#define BIT56 0x0100000000000000ULL -#define BIT57 0x0200000000000000ULL -#define BIT58 0x0400000000000000ULL -#define BIT59 0x0800000000000000ULL -#define BIT60 0x1000000000000000ULL -#define BIT61 0x2000000000000000ULL -#define BIT62 0x4000000000000000ULL -#define BIT63 0x8000000000000000ULL - -/** - The macro that returns the byte offset of a field in a data structure. - - This function returns the offset, in bytes, of field specified by Field from the - beginning of the data structure specified by TYPE. If TYPE does not contain Field, - the module will not compile. - - @param TYPE The name of the data structure that contains the field specified by Field. - @param Field The name of the field in the data structure. - - @return Offset, in bytes, of field. - -**/ -#ifdef __GNUC__ -#if __GNUC__ >= 4 -#define OFFSET_OF(TYPE, Field) ((UINTN) __builtin_offsetof(TYPE, Field)) -#endif -#endif - -#ifndef OFFSET_OF -#define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field)) -#endif - -/** - Returns a 16-bit signature built from 2 ASCII characters. - - This macro returns a 16-bit value built from the two ASCII characters specified - by A and B. - - @param A The first ASCII character. - @param B The second ASCII character. - - @return A 16-bit value built from the two ASCII characters specified by A and B. - -**/ -#define SIGNATURE_16(A, B) ((A) | (B << 8)) - -/** - Returns a 32-bit signature built from 4 ASCII characters. - - This macro returns a 32-bit value built from the four ASCII characters specified - by A, B, C, and D. - - @param A The first ASCII character. - @param B The second ASCII character. - @param C The third ASCII character. - @param D The fourth ASCII character. - - @return A 32-bit value built from the two ASCII characters specified by A, B, - C and D. - -**/ -#define SIGNATURE_32(A, B, C, D) (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C, D) << 16)) - -/** - Returns a 64-bit signature built from 8 ASCII characters. - - This macro returns a 64-bit value built from the eight ASCII characters specified - by A, B, C, D, E, F, G,and H. - - @param A The first ASCII character. - @param B The second ASCII character. - @param C The third ASCII character. - @param D The fourth ASCII character. - @param E The fifth ASCII character. - @param F The sixth ASCII character. - @param G The seventh ASCII character. - @param H The eighth ASCII character. - - @return A 64-bit value built from the two ASCII characters specified by A, B, - C, D, E, F, G and H. - -**/ -#define SIGNATURE_64(A, B, C, D, E, F, G, H) \ - (SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32)) - -typedef struct { - UINT64 BlockNum; - UINT32 BlockSize; -} DEVICE_BLOCK_INFO; - -#endif