• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 
3   Internal definitions for the virtio-scsi driver, which produces Extended SCSI
4   Pass Thru Protocol instances for virtio-scsi devices.
5 
6   Copyright (C) 2012, Red Hat, Inc.
7 
8   This program and the accompanying materials are licensed and made available
9   under the terms and conditions of the BSD License which accompanies this
10   distribution. The full text of the license may be found at
11   http://opensource.org/licenses/bsd-license.php
12 
13   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14   WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 
16 **/
17 
18 #ifndef _VIRTIO_SCSI_DXE_H_
19 #define _VIRTIO_SCSI_DXE_H_
20 
21 #include <Protocol/ComponentName.h>
22 #include <Protocol/DriverBinding.h>
23 #include <Protocol/ScsiPassThruExt.h>
24 
25 #include <IndustryStandard/Virtio.h>
26 
27 
28 //
29 // This driver supports 2-byte target identifiers and 4-byte LUN identifiers.
30 //
31 // EFI_EXT_SCSI_PASS_THRU_PROTOCOL provides TARGET_MAX_BYTES bytes for target
32 // identification, and 8 bytes for LUN identification.
33 //
34 // EFI_EXT_SCSI_PASS_THRU_MODE.AdapterId is also a target identifier,
35 // consisting of 4 bytes. Make sure TARGET_MAX_BYTES can accommodate both
36 // AdapterId and our target identifiers.
37 //
38 #if TARGET_MAX_BYTES < 4
39 #  error "virtio-scsi requires TARGET_MAX_BYTES >= 4"
40 #endif
41 
42 
43 #define VSCSI_SIG SIGNATURE_32 ('V', 'S', 'C', 'S')
44 
45 typedef struct {
46   //
47   // Parts of this structure are initialized / torn down in various functions
48   // at various call depths. The table to the right should make it easier to
49   // track them.
50   //
51   //                              field              init function       init depth
52   //                              ----------------   ------------------  ----------
53   UINT32                          Signature;      // DriverBindingStart  0
54   VIRTIO_DEVICE_PROTOCOL          *VirtIo;        // DriverBindingStart  0
55   EFI_EVENT                       ExitBoot;       // DriverBindingStart  0
56   BOOLEAN                         InOutSupported; // VirtioScsiInit      1
57   UINT16                          MaxTarget;      // VirtioScsiInit      1
58   UINT32                          MaxLun;         // VirtioScsiInit      1
59   UINT32                          MaxSectors;     // VirtioScsiInit      1
60   VRING                           Ring;           // VirtioRingInit      2
61   EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru;       // VirtioScsiInit      1
62   EFI_EXT_SCSI_PASS_THRU_MODE     PassThruMode;   // VirtioScsiInit      1
63 } VSCSI_DEV;
64 
65 #define VIRTIO_SCSI_FROM_PASS_THRU(PassThruPointer) \
66         CR (PassThruPointer, VSCSI_DEV, PassThru, VSCSI_SIG)
67 
68 
69 //
70 // Probe, start and stop functions of this driver, called by the DXE core for
71 // specific devices.
72 //
73 // The following specifications document these interfaces:
74 // - Driver Writer's Guide for UEFI 2.3.1 v1.01, 9 Driver Binding Protocol
75 // - UEFI Spec 2.3.1 + Errata C, 10.1 EFI Driver Binding Protocol
76 //
77 
78 EFI_STATUS
79 EFIAPI
80 VirtioScsiDriverBindingSupported (
81   IN EFI_DRIVER_BINDING_PROTOCOL *This,
82   IN EFI_HANDLE                  DeviceHandle,
83   IN EFI_DEVICE_PATH_PROTOCOL    *RemainingDevicePath
84   );
85 
86 
87 EFI_STATUS
88 EFIAPI
89 VirtioScsiDriverBindingStart (
90   IN EFI_DRIVER_BINDING_PROTOCOL *This,
91   IN EFI_HANDLE                  DeviceHandle,
92   IN EFI_DEVICE_PATH_PROTOCOL    *RemainingDevicePath
93   );
94 
95 
96 EFI_STATUS
97 EFIAPI
98 VirtioScsiDriverBindingStop (
99   IN EFI_DRIVER_BINDING_PROTOCOL *This,
100   IN EFI_HANDLE                  DeviceHandle,
101   IN UINTN                       NumberOfChildren,
102   IN EFI_HANDLE                  *ChildHandleBuffer
103   );
104 
105 
106 //
107 // The next seven functions implement EFI_EXT_SCSI_PASS_THRU_PROTOCOL
108 // for the virtio-scsi HBA. Refer to UEFI Spec 2.3.1 + Errata C, sections
109 // - 14.1 SCSI Driver Model Overview,
110 // - 14.7 Extended SCSI Pass Thru Protocol.
111 //
112 
113 EFI_STATUS
114 EFIAPI
115 VirtioScsiPassThru (
116   IN     EFI_EXT_SCSI_PASS_THRU_PROTOCOL            *This,
117   IN     UINT8                                      *Target,
118   IN     UINT64                                     Lun,
119   IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
120   IN     EFI_EVENT                                  Event   OPTIONAL
121   );
122 
123 
124 EFI_STATUS
125 EFIAPI
126 VirtioScsiGetNextTargetLun (
127   IN     EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
128   IN OUT UINT8                           **Target,
129   IN OUT UINT64                          *Lun
130   );
131 
132 
133 EFI_STATUS
134 EFIAPI
135 VirtioScsiBuildDevicePath (
136   IN     EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
137   IN     UINT8                           *Target,
138   IN     UINT64                          Lun,
139   IN OUT EFI_DEVICE_PATH_PROTOCOL        **DevicePath
140   );
141 
142 
143 EFI_STATUS
144 EFIAPI
145 VirtioScsiGetTargetLun (
146   IN  EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
147   IN  EFI_DEVICE_PATH_PROTOCOL        *DevicePath,
148   OUT UINT8                           **Target,
149   OUT UINT64                          *Lun
150   );
151 
152 
153 EFI_STATUS
154 EFIAPI
155 VirtioScsiResetChannel (
156   IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This
157   );
158 
159 
160 EFI_STATUS
161 EFIAPI
162 VirtioScsiResetTargetLun (
163   IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
164   IN UINT8                           *Target,
165   IN UINT64                          Lun
166   );
167 
168 
169 EFI_STATUS
170 EFIAPI
171 VirtioScsiGetNextTarget (
172   IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
173   IN OUT UINT8                       **Target
174   );
175 
176 
177 //
178 // The purpose of the following scaffolding (EFI_COMPONENT_NAME_PROTOCOL and
179 // EFI_COMPONENT_NAME2_PROTOCOL implementation) is to format the driver's name
180 // in English, for display on standard console devices. This is recommended for
181 // UEFI drivers that follow the UEFI Driver Model. Refer to the Driver Writer's
182 // Guide for UEFI 2.3.1 v1.01, 11 UEFI Driver and Controller Names.
183 //
184 // Device type names ("Virtio SCSI Host Device") are not formatted because the
185 // driver supports only that device type. Therefore the driver name suffices
186 // for unambiguous identification.
187 //
188 
189 EFI_STATUS
190 EFIAPI
191 VirtioScsiGetDriverName (
192   IN  EFI_COMPONENT_NAME_PROTOCOL *This,
193   IN  CHAR8                       *Language,
194   OUT CHAR16                      **DriverName
195   );
196 
197 
198 EFI_STATUS
199 EFIAPI
200 VirtioScsiGetDeviceName (
201   IN  EFI_COMPONENT_NAME_PROTOCOL *This,
202   IN  EFI_HANDLE                  DeviceHandle,
203   IN  EFI_HANDLE                  ChildHandle,
204   IN  CHAR8                       *Language,
205   OUT CHAR16                      **ControllerName
206   );
207 
208 #endif // _VIRTIO_SCSI_DXE_H_
209