3 The implementation of USB mass storage class device driver.
5 Copyright (c) 2007 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _EFI_USBMASS_IMPL_H_
17 #define _EFI_USBMASS_IMPL_H_
19 typedef struct _USB_MASS_DEVICE USB_MASS_DEVICE
;
22 #include "UsbMassBot.h"
23 #include "UsbMassCbi.h"
24 #include "UsbMassBoot.h"
26 #define USB_MASS_SIGNATURE SIGNATURE_32 ('U', 's', 'b', 'M')
28 struct _USB_MASS_DEVICE
{
30 EFI_HANDLE Controller
;
31 EFI_USB_IO_PROTOCOL
*UsbIo
;
32 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
33 EFI_BLOCK_IO_PROTOCOL BlockIo
;
34 EFI_BLOCK_IO_MEDIA BlockIoMedia
;
35 BOOLEAN OpticalStorage
;
36 UINT8 Lun
; // Logical Unit Number
37 UINT8 Pdt
; // Peripheral Device Type
38 USB_MASS_TRANSPORT
*Transport
; // USB mass storage transport protocol
39 VOID
*Context
; // Opaque storage for mass transport
42 #define USB_MASS_DEVICE_FROM_BLOCK_IO(a) \
43 CR (a, USB_MASS_DEVICE, BlockIo, USB_MASS_SIGNATURE)
45 extern EFI_COMPONENT_NAME_PROTOCOL gUsbMassStorageComponentName
;
46 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbMassStorageComponentName2
;
49 // Functions for Driver Binding Protocol
53 Check whether the controller is a supported USB mass storage.
55 @param This The USB mass storage driver binding protocol.
56 @param Controller The controller handle to check.
57 @param RemainingDevicePath The remaining device path.
59 @retval EFI_SUCCESS The driver supports this controller.
60 @retval other This device isn't supported.
65 USBMassDriverBindingSupported (
66 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
67 IN EFI_HANDLE Controller
,
68 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
72 Starts the USB mass storage device with this driver.
74 This function consumes USB I/O Portocol, intializes USB mass storage device,
75 installs Block I/O Protocol, and submits Asynchronous Interrupt
76 Transfer to manage the USB mass storage device.
78 @param This The USB mass storage driver binding protocol.
79 @param Controller The USB mass storage device to start on
80 @param RemainingDevicePath The remaining device path.
82 @retval EFI_SUCCESS This driver supports this device.
83 @retval EFI_UNSUPPORTED This driver does not support this device.
84 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
85 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
86 @retval EFI_ALREADY_STARTED This driver has been started.
91 USBMassDriverBindingStart (
92 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
93 IN EFI_HANDLE Controller
,
94 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
98 Stop controlling the device.
100 @param This The USB mass storage driver binding
101 @param Controller The device controller controlled by the driver.
102 @param NumberOfChildren The number of children of this device
103 @param ChildHandleBuffer The buffer of children handle.
105 @retval EFI_SUCCESS The driver stopped from controlling the device.
106 @retval Others Failed to stop the driver
111 USBMassDriverBindingStop (
112 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
113 IN EFI_HANDLE Controller
,
114 IN UINTN NumberOfChildren
,
115 IN EFI_HANDLE
*ChildHandleBuffer
119 // Functions for Block I/O Protocol
123 Reset the block device.
125 This function implements EFI_BLOCK_IO_PROTOCOL.Reset().
126 It resets the block device hardware.
127 ExtendedVerification is ignored in this implementation.
129 @param This Indicates a pointer to the calling context.
130 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
131 verification operation of the device during reset.
133 @retval EFI_SUCCESS The block device was reset.
134 @retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be reset.
140 IN EFI_BLOCK_IO_PROTOCOL
*This
,
141 IN BOOLEAN ExtendedVerification
145 Reads the requested number of blocks from the device.
147 This function implements EFI_BLOCK_IO_PROTOCOL.ReadBlocks().
148 It reads the requested number of blocks from the device.
149 All the blocks are read, or an error is returned.
151 @param This Indicates a pointer to the calling context.
152 @param MediaId The media ID that the read request is for.
153 @param Lba The starting logical block address to read from on the device.
154 @param BufferSize The size of the Buffer in bytes.
155 This must be a multiple of the intrinsic block size of the device.
156 @param Buffer A pointer to the destination buffer for the data. The caller is
157 responsible for either having implicit or explicit ownership of the buffer.
159 @retval EFI_SUCCESS The data was read correctly from the device.
160 @retval EFI_DEVICE_ERROR The device reported an error while attempting to perform the read operation.
161 @retval EFI_NO_MEDIA There is no media in the device.
162 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
163 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the intrinsic block size of the device.
164 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
165 or the buffer is not on proper alignment.
171 IN EFI_BLOCK_IO_PROTOCOL
*This
,
179 Writes a specified number of blocks to the device.
181 This function implements EFI_BLOCK_IO_PROTOCOL.WriteBlocks().
182 It writes a specified number of blocks to the device.
183 All blocks are written, or an error is returned.
185 @param This Indicates a pointer to the calling context.
186 @param MediaId The media ID that the write request is for.
187 @param Lba The starting logical block address to be written.
188 @param BufferSize The size of the Buffer in bytes.
189 This must be a multiple of the intrinsic block size of the device.
190 @param Buffer Pointer to the source buffer for the data.
192 @retval EFI_SUCCESS The data were written correctly to the device.
193 @retval EFI_WRITE_PROTECTED The device cannot be written to.
194 @retval EFI_NO_MEDIA There is no media in the device.
195 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
196 @retval EFI_DEVICE_ERROR The device reported an error while attempting to perform the write operation.
197 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the intrinsic
198 block size of the device.
199 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
200 or the buffer is not on proper alignment.
206 IN EFI_BLOCK_IO_PROTOCOL
*This
,
214 Flushes all modified data to a physical block device.
216 This function implements EFI_BLOCK_IO_PROTOCOL.FlushBlocks().
217 USB mass storage device doesn't support write cache,
218 so return EFI_SUCCESS directly.
220 @param This Indicates a pointer to the calling context.
222 @retval EFI_SUCCESS All outstanding data were written correctly to the device.
223 @retval EFI_DEVICE_ERROR The device reported an error while attempting to write data.
224 @retval EFI_NO_MEDIA There is no media in the device.
230 IN EFI_BLOCK_IO_PROTOCOL
*This