TianoCore EDK2 master
Loading...
Searching...
No Matches
VirtioScsi.c File Reference

Go to the source code of this file.

Macros

#define VIRTIO_CFG_WRITE(Dev, Field, Value)
 
#define VIRTIO_CFG_READ(Dev, Field, Pointer)
 

Functions

STATIC EFI_STATUS EFIAPI PopulateRequest (IN CONST VSCSI_DEV *Dev, IN UINT16 Target, IN UINT64 Lun, IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet, OUT volatile VIRTIO_SCSI_REQ *Request)
 
STATIC EFI_STATUS EFIAPI ParseResponse (IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet, IN CONST volatile VIRTIO_SCSI_RESP *Response)
 
STATIC EFI_STATUS ReportHostAdapterError (OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet)
 
EFI_STATUS EFIAPI VirtioScsiPassThru (IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN UINT8 *Target, IN UINT64 Lun, IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet, IN EFI_EVENT Event OPTIONAL)
 
EFI_STATUS EFIAPI VirtioScsiGetNextTargetLun (IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN OUT UINT8 **TargetPointer, IN OUT UINT64 *Lun)
 
EFI_STATUS EFIAPI VirtioScsiBuildDevicePath (IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN UINT8 *Target, IN UINT64 Lun, IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
 
EFI_STATUS EFIAPI VirtioScsiGetTargetLun (IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT UINT8 **TargetPointer, OUT UINT64 *Lun)
 
EFI_STATUS EFIAPI VirtioScsiResetChannel (IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This)
 
EFI_STATUS EFIAPI VirtioScsiResetTargetLun (IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN UINT8 *Target, IN UINT64 Lun)
 
EFI_STATUS EFIAPI VirtioScsiGetNextTarget (IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN OUT UINT8 **TargetPointer)
 
STATIC EFI_STATUS EFIAPI VirtioScsiInit (IN OUT VSCSI_DEV *Dev)
 
STATIC VOID EFIAPI VirtioScsiUninit (IN OUT VSCSI_DEV *Dev)
 
STATIC VOID EFIAPI VirtioScsiExitBoot (IN EFI_EVENT Event, IN VOID *Context)
 
EFI_STATUS EFIAPI VirtioScsiDriverBindingSupported (IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE DeviceHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
 
EFI_STATUS EFIAPI VirtioScsiDriverBindingStart (IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE DeviceHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
 
EFI_STATUS EFIAPI VirtioScsiDriverBindingStop (IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE DeviceHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
 
EFI_STATUS EFIAPI VirtioScsiGetDriverName (IN EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName)
 
EFI_STATUS EFIAPI VirtioScsiGetDeviceName (IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE DeviceHandle, IN EFI_HANDLE ChildHandle, IN CHAR8 *Language, OUT CHAR16 **ControllerName)
 
EFI_STATUS EFIAPI VirtioScsiEntryPoint (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 

Variables

STATIC EFI_DRIVER_BINDING_PROTOCOL gDriverBinding
 
STATIC EFI_UNICODE_STRING_TABLE mDriverNameTable []
 
STATIC EFI_COMPONENT_NAME_PROTOCOL gComponentName
 
STATIC EFI_COMPONENT_NAME2_PROTOCOL gComponentName2
 

Detailed Description

This driver produces Extended SCSI Pass Thru Protocol instances for virtio-scsi devices.

The implementation is basic:

  • No hotplug / hot-unplug.
  • Although EFI_EXT_SCSI_PASS_THRU_PROTOCOL.PassThru() could be a good match for multiple in-flight virtio-scsi requests, we stick to synchronous requests for now.
  • Timeouts are not supported for EFI_EXT_SCSI_PASS_THRU_PROTOCOL.PassThru().
  • Only one channel is supported. (At the time of this writing, host-side virtio-scsi supports a single channel too.)
  • Only one request queue is used (for the one synchronous request).
  • The ResetChannel() and ResetTargetLun() functions of EFI_EXT_SCSI_PASS_THRU_PROTOCOL are not supported (which is allowed by the UEFI 2.3.1 Errata C specification), although VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET could be a good match. That would however require client code for the control queue, which is deemed unreasonable for now.

Copyright (C) 2012, Red Hat, Inc. Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.
Copyright (c) 2017, AMD Inc, All rights reserved.
Copyright (c) 2024, Arm Limited. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file VirtioScsi.c.

Macro Definition Documentation

◆ VIRTIO_CFG_READ

#define VIRTIO_CFG_READ (   Dev,
  Field,
  Pointer 
)
Value:
((Dev)->VirtIo->ReadDevice ( \
(Dev)->VirtIo, \
OFFSET_OF_VSCSI (Field), \
SIZE_OF_VSCSI (Field), \
sizeof *(Pointer), \
(Pointer) \
))

Definition at line 80 of file VirtioScsi.c.

◆ VIRTIO_CFG_WRITE

#define VIRTIO_CFG_WRITE (   Dev,
  Field,
  Value 
)
Value:
((Dev)->VirtIo->WriteDevice ( \
(Dev)->VirtIo, \
OFFSET_OF_VSCSI (Field), \
SIZE_OF_VSCSI (Field), \
(Value) \
))

Convenience macros to read and write configuration elements of the virtio-scsi VirtIo device.

The following macros make it possible to specify only the "core parameters" for such accesses and to derive the rest. By the time VIRTIO_CFG_WRITE() returns, the transaction will have been completed.

Parameters
[in]DevPointer to the VSCSI_DEV structure.
[in]FieldA field name from VSCSI_HDR, identifying the virtio-scsi configuration item to access.
[in]Value(VIRTIO_CFG_WRITE() only.) The value to write to the selected configuration item.
[out]Pointer(VIRTIO_CFG_READ() only.) The object to receive the value read from the configuration item. Its type must be one of UINT8, UINT16, UINT32, UINT64.
Returns
Status codes returned by Virtio->WriteDevice() / Virtio->ReadDevice().

Definition at line 73 of file VirtioScsi.c.

Function Documentation

◆ ParseResponse()

STATIC EFI_STATUS EFIAPI ParseResponse ( IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET Packet,
IN CONST volatile VIRTIO_SCSI_RESP Response 
)

Parse the virtio-scsi device's response, translate it to an EFI status code, and update the Extended SCSI Pass Thru Protocol packet, to be returned by the EFI_EXT_SCSI_PASS_THRU_PROTOCOL.PassThru() implementation.

Parameters
[in,out]PacketThe Extended SCSI Pass Thru Protocol packet that has been translated to a virtio-scsi request with PopulateRequest(), and processed by the host. On output this parameter is updated with response or error contents.
[in]ResponseThe virtio-scsi response structure to parse. We expect it to come from a virtio ring, thus it is qualified volatile.
Returns
PassThru() status codes mandated by UEFI Spec 2.3.1 + Errata C, 14.7 Extended SCSI Pass Thru Protocol.

Definition at line 290 of file VirtioScsi.c.

◆ PopulateRequest()

STATIC EFI_STATUS EFIAPI PopulateRequest ( IN CONST VSCSI_DEV Dev,
IN UINT16  Target,
IN UINT64  Lun,
IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET Packet,
OUT volatile VIRTIO_SCSI_REQ Request 
)

Populate a virtio-scsi request from the Extended SCSI Pass Thru Protocol packet.

The caller is responsible for pre-zeroing the virtio-scsi request. The Extended SCSI Pass Thru Protocol packet is modified, to be forwarded outwards by VirtioScsiPassThru(), if invalid or unsupported parameters are detected.

Parameters
[in]DevThe virtio-scsi host device the packet targets.
[in]TargetThe SCSI target controlled by the virtio-scsi host device.
[in]LunThe Logical Unit Number under the SCSI target.
[in,out]PacketThe Extended SCSI Pass Thru Protocol packet the function translates to a virtio-scsi request. On failure this parameter relays error contents.
[out]RequestThe pre-zeroed virtio-scsi request to populate. This parameter is volatile-qualified because we expect the caller to append it to a virtio ring, thus assignments to Request must be visible when the function returns.
Return values
EFI_SUCCESSThe Extended SCSI Pass Thru Protocol packet was valid, Request has been populated.
Returns
Otherwise, invalid or unsupported parameters were detected. Status codes are meant for direct forwarding by the EFI_EXT_SCSI_PASS_THRU_PROTOCOL.PassThru() implementation.

Definition at line 148 of file VirtioScsi.c.

◆ ReportHostAdapterError()

STATIC EFI_STATUS ReportHostAdapterError ( OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET Packet)

The function can be used to create a fake host adapter error.

When VirtioScsiPassThru() is failed due to some reasons then this function can be called to construct a host adapter error.

Parameters
[out]PacketThe Extended SCSI Pass Thru Protocol packet that the host adapter error shall be placed in.
Return values
EFI_DEVICE_ERRORThe function returns this status code unconditionally, to be propagated by VirtioScsiPassThru().

Definition at line 402 of file VirtioScsi.c.

◆ VirtioScsiBuildDevicePath()

EFI_STATUS EFIAPI VirtioScsiBuildDevicePath ( IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL This,
IN UINT8 *  Target,
IN UINT64  Lun,
IN OUT EFI_DEVICE_PATH_PROTOCOL **  DevicePath 
)

Definition at line 776 of file VirtioScsi.c.

◆ VirtioScsiDriverBindingStart()

EFI_STATUS EFIAPI VirtioScsiDriverBindingStart ( IN EFI_DRIVER_BINDING_PROTOCOL This,
IN EFI_HANDLE  DeviceHandle,
IN EFI_DEVICE_PATH_PROTOCOL RemainingDevicePath 
)

Definition at line 1322 of file VirtioScsi.c.

◆ VirtioScsiDriverBindingStop()

EFI_STATUS EFIAPI VirtioScsiDriverBindingStop ( IN EFI_DRIVER_BINDING_PROTOCOL This,
IN EFI_HANDLE  DeviceHandle,
IN UINTN  NumberOfChildren,
IN EFI_HANDLE ChildHandleBuffer 
)

Definition at line 1406 of file VirtioScsi.c.

◆ VirtioScsiDriverBindingSupported()

EFI_STATUS EFIAPI VirtioScsiDriverBindingSupported ( IN EFI_DRIVER_BINDING_PROTOCOL This,
IN EFI_HANDLE  DeviceHandle,
IN EFI_DEVICE_PATH_PROTOCOL RemainingDevicePath 
)

Definition at line 1275 of file VirtioScsi.c.

◆ VirtioScsiEntryPoint()

EFI_STATUS EFIAPI VirtioScsiEntryPoint ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

Definition at line 1544 of file VirtioScsi.c.

◆ VirtioScsiExitBoot()

STATIC VOID EFIAPI VirtioScsiExitBoot ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

Definition at line 1239 of file VirtioScsi.c.

◆ VirtioScsiGetDeviceName()

EFI_STATUS EFIAPI VirtioScsiGetDeviceName ( IN EFI_COMPONENT_NAME_PROTOCOL This,
IN EFI_HANDLE  DeviceHandle,
IN EFI_HANDLE  ChildHandle,
IN CHAR8 *  Language,
OUT CHAR16 **  ControllerName 
)

Definition at line 1514 of file VirtioScsi.c.

◆ VirtioScsiGetDriverName()

EFI_STATUS EFIAPI VirtioScsiGetDriverName ( IN EFI_COMPONENT_NAME_PROTOCOL This,
IN CHAR8 *  Language,
OUT CHAR16 **  DriverName 
)

Definition at line 1497 of file VirtioScsi.c.

◆ VirtioScsiGetNextTarget()

EFI_STATUS EFIAPI VirtioScsiGetNextTarget ( IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL This,
IN OUT UINT8 **  TargetPointer 
)

Definition at line 881 of file VirtioScsi.c.

◆ VirtioScsiGetNextTargetLun()

EFI_STATUS EFIAPI VirtioScsiGetNextTargetLun ( IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL This,
IN OUT UINT8 **  TargetPointer,
IN OUT UINT64 *  Lun 
)

Definition at line 718 of file VirtioScsi.c.

◆ VirtioScsiGetTargetLun()

EFI_STATUS EFIAPI VirtioScsiGetTargetLun ( IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL This,
IN EFI_DEVICE_PATH_PROTOCOL DevicePath,
OUT UINT8 **  TargetPointer,
OUT UINT64 *  Lun 
)

Definition at line 815 of file VirtioScsi.c.

◆ VirtioScsiInit()

STATIC EFI_STATUS EFIAPI VirtioScsiInit ( IN OUT VSCSI_DEV Dev)

Definition at line 932 of file VirtioScsi.c.

◆ VirtioScsiPassThru()

EFI_STATUS EFIAPI VirtioScsiPassThru ( IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL This,
IN UINT8 *  Target,
IN UINT64  Lun,
IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET Packet,
IN EFI_EVENT Event  OPTIONAL 
)

Definition at line 423 of file VirtioScsi.c.

◆ VirtioScsiResetChannel()

EFI_STATUS EFIAPI VirtioScsiResetChannel ( IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL This)

Definition at line 861 of file VirtioScsi.c.

◆ VirtioScsiResetTargetLun()

EFI_STATUS EFIAPI VirtioScsiResetTargetLun ( IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL This,
IN UINT8 *  Target,
IN UINT64  Lun 
)

Definition at line 870 of file VirtioScsi.c.

◆ VirtioScsiUninit()

STATIC VOID EFIAPI VirtioScsiUninit ( IN OUT VSCSI_DEV Dev)

Definition at line 1209 of file VirtioScsi.c.

Variable Documentation

◆ gComponentName

Initial value:
= {
&VirtioScsiGetDriverName,
&VirtioScsiGetDeviceName,
"eng"
}

Definition at line 1493 of file VirtioScsi.c.

◆ gComponentName2

Initial value:
= {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME)&VirtioScsiGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)&VirtioScsiGetDeviceName,
"en"
}
EFI_STATUS(EFIAPI * EFI_COMPONENT_NAME2_GET_DRIVER_NAME)(IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName)
EFI_STATUS(EFIAPI * EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)(IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName)

Definition at line 1533 of file VirtioScsi.c.

◆ gDriverBinding

Initial value:
= {
&VirtioScsiDriverBindingSupported,
&VirtioScsiDriverBindingStart,
&VirtioScsiDriverBindingStop,
0x10,
NULL,
}
#define NULL
Definition: Base.h:319

Definition at line 1464 of file VirtioScsi.c.

◆ mDriverNameTable

STATIC EFI_UNICODE_STRING_TABLE mDriverNameTable[]
Initial value:
= {
{ "eng;en", L"Virtio SCSI Host Driver" },
{ NULL, NULL }
}

Definition at line 1487 of file VirtioScsi.c.