VirtioScsi.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /** @file
  2. Internal definitions for the virtio-scsi driver, which produces Extended SCSI
  3. Pass Thru Protocol instances for virtio-scsi devices.
  4. Copyright (C) 2012, Red Hat, Inc.
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #ifndef _VIRTIO_SCSI_DXE_H_
  8. #define _VIRTIO_SCSI_DXE_H_
  9. #include <Protocol/ComponentName.h>
  10. #include <Protocol/DriverBinding.h>
  11. #include <Protocol/ScsiPassThruExt.h>
  12. #include <IndustryStandard/Virtio.h>
  13. //
  14. // This driver supports 2-byte target identifiers and 4-byte LUN identifiers.
  15. //
  16. // EFI_EXT_SCSI_PASS_THRU_PROTOCOL provides TARGET_MAX_BYTES bytes for target
  17. // identification, and 8 bytes for LUN identification.
  18. //
  19. // EFI_EXT_SCSI_PASS_THRU_MODE.AdapterId is also a target identifier,
  20. // consisting of 4 bytes. Make sure TARGET_MAX_BYTES can accommodate both
  21. // AdapterId and our target identifiers.
  22. //
  23. #if TARGET_MAX_BYTES < 4
  24. #error "virtio-scsi requires TARGET_MAX_BYTES >= 4"
  25. #endif
  26. #define VSCSI_SIG SIGNATURE_32 ('V', 'S', 'C', 'S')
  27. typedef struct {
  28. //
  29. // Parts of this structure are initialized / torn down in various functions
  30. // at various call depths. The table to the right should make it easier to
  31. // track them.
  32. //
  33. // field init function init depth
  34. // ---------------- ------------------ ----------
  35. UINT32 Signature; // DriverBindingStart 0
  36. VIRTIO_DEVICE_PROTOCOL *VirtIo; // DriverBindingStart 0
  37. EFI_EVENT ExitBoot; // DriverBindingStart 0
  38. BOOLEAN InOutSupported; // VirtioScsiInit 1
  39. UINT16 MaxTarget; // VirtioScsiInit 1
  40. UINT32 MaxLun; // VirtioScsiInit 1
  41. UINT32 MaxSectors; // VirtioScsiInit 1
  42. VRING Ring; // VirtioRingInit 2
  43. EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru; // VirtioScsiInit 1
  44. EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode; // VirtioScsiInit 1
  45. VOID *RingMap; // VirtioRingMap 2
  46. } VSCSI_DEV;
  47. #define VIRTIO_SCSI_FROM_PASS_THRU(PassThruPointer) \
  48. CR (PassThruPointer, VSCSI_DEV, PassThru, VSCSI_SIG)
  49. //
  50. // Probe, start and stop functions of this driver, called by the DXE core for
  51. // specific devices.
  52. //
  53. // The following specifications document these interfaces:
  54. // - Driver Writer's Guide for UEFI 2.3.1 v1.01, 9 Driver Binding Protocol
  55. // - UEFI Spec 2.3.1 + Errata C, 10.1 EFI Driver Binding Protocol
  56. //
  57. EFI_STATUS
  58. EFIAPI
  59. VirtioScsiDriverBindingSupported (
  60. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  61. IN EFI_HANDLE DeviceHandle,
  62. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  63. );
  64. EFI_STATUS
  65. EFIAPI
  66. VirtioScsiDriverBindingStart (
  67. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  68. IN EFI_HANDLE DeviceHandle,
  69. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  70. );
  71. EFI_STATUS
  72. EFIAPI
  73. VirtioScsiDriverBindingStop (
  74. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  75. IN EFI_HANDLE DeviceHandle,
  76. IN UINTN NumberOfChildren,
  77. IN EFI_HANDLE *ChildHandleBuffer
  78. );
  79. //
  80. // The next seven functions implement EFI_EXT_SCSI_PASS_THRU_PROTOCOL
  81. // for the virtio-scsi HBA. Refer to UEFI Spec 2.3.1 + Errata C, sections
  82. // - 14.1 SCSI Driver Model Overview,
  83. // - 14.7 Extended SCSI Pass Thru Protocol.
  84. //
  85. EFI_STATUS
  86. EFIAPI
  87. VirtioScsiPassThru (
  88. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
  89. IN UINT8 *Target,
  90. IN UINT64 Lun,
  91. IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
  92. IN EFI_EVENT Event OPTIONAL
  93. );
  94. EFI_STATUS
  95. EFIAPI
  96. VirtioScsiGetNextTargetLun (
  97. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
  98. IN OUT UINT8 **Target,
  99. IN OUT UINT64 *Lun
  100. );
  101. EFI_STATUS
  102. EFIAPI
  103. VirtioScsiBuildDevicePath (
  104. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
  105. IN UINT8 *Target,
  106. IN UINT64 Lun,
  107. IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
  108. );
  109. EFI_STATUS
  110. EFIAPI
  111. VirtioScsiGetTargetLun (
  112. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
  113. IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  114. OUT UINT8 **Target,
  115. OUT UINT64 *Lun
  116. );
  117. EFI_STATUS
  118. EFIAPI
  119. VirtioScsiResetChannel (
  120. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This
  121. );
  122. EFI_STATUS
  123. EFIAPI
  124. VirtioScsiResetTargetLun (
  125. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
  126. IN UINT8 *Target,
  127. IN UINT64 Lun
  128. );
  129. EFI_STATUS
  130. EFIAPI
  131. VirtioScsiGetNextTarget (
  132. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
  133. IN OUT UINT8 **Target
  134. );
  135. //
  136. // The purpose of the following scaffolding (EFI_COMPONENT_NAME_PROTOCOL and
  137. // EFI_COMPONENT_NAME2_PROTOCOL implementation) is to format the driver's name
  138. // in English, for display on standard console devices. This is recommended for
  139. // UEFI drivers that follow the UEFI Driver Model. Refer to the Driver Writer's
  140. // Guide for UEFI 2.3.1 v1.01, 11 UEFI Driver and Controller Names.
  141. //
  142. // Device type names ("Virtio SCSI Host Device") are not formatted because the
  143. // driver supports only that device type. Therefore the driver name suffices
  144. // for unambiguous identification.
  145. //
  146. EFI_STATUS
  147. EFIAPI
  148. VirtioScsiGetDriverName (
  149. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  150. IN CHAR8 *Language,
  151. OUT CHAR16 **DriverName
  152. );
  153. EFI_STATUS
  154. EFIAPI
  155. VirtioScsiGetDeviceName (
  156. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  157. IN EFI_HANDLE DeviceHandle,
  158. IN EFI_HANDLE ChildHandle,
  159. IN CHAR8 *Language,
  160. OUT CHAR16 **ControllerName
  161. );
  162. #endif // _VIRTIO_SCSI_DXE_H_