Home | History | Annotate | Download | only in UsbBotPei
      1 /** @file
      2 BOT Transportation implementation.
      3 
      4 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
      5 
      6 This program and the accompanying materials
      7 are licensed and made available under the terms and conditions
      8 of the BSD License which accompanies this distribution.  The
      9 full text of the license may be found at
     10 http://opensource.org/licenses/bsd-license.php
     11 
     12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     14 
     15 **/
     16 
     17 #ifndef _PEI_BOT_PEIM_H_
     18 #define _PEI_BOT_PEIM_H_
     19 
     20 
     21 #include <PiPei.h>
     22 
     23 #include <Ppi/UsbIo.h>
     24 #include <Ppi/UsbHostController.h>
     25 #include <Ppi/BlockIo.h>
     26 
     27 //#include <Library/DebugLib.h>
     28 #include <Library/PeimEntryPoint.h>
     29 #include <Library/PeiServicesLib.h>
     30 #include <Library/BaseMemoryLib.h>
     31 
     32 #include <IndustryStandard/Atapi.h>
     33 
     34 #pragma pack(1)
     35 //
     36 // Bulk Only device protocol
     37 //
     38 typedef struct {
     39   UINT32  Signature;
     40   UINT32  Tag;
     41   UINT32  DataTransferLength;
     42   UINT8   Flags;
     43   UINT8   Lun;
     44   UINT8   CmdLen;
     45   UINT8   CmdBlock[16];
     46 } CBW;
     47 
     48 typedef struct {
     49   UINT32  Signature;
     50   UINT32  Tag;
     51   UINT32  DataResidue;
     52   UINT8   Status;
     53 } CSW;
     54 
     55 #pragma pack()
     56 //
     57 // Status code, see Usb Bot device spec
     58 //
     59 #define CSWSIG  0x53425355
     60 #define CBWSIG  0x43425355
     61 
     62 /**
     63   Sends out ATAPI Inquiry Packet Command to the specified device. This command will
     64   return INQUIRY data of the device.
     65 
     66   @param PeiServices    The pointer of EFI_PEI_SERVICES.
     67   @param PeiBotDevice   The pointer to PEI_BOT_DEVICE instance.
     68 
     69   @retval EFI_SUCCESS       Inquiry command completes successfully.
     70   @retval EFI_DEVICE_ERROR  Inquiry command failed.
     71 
     72 **/
     73 EFI_STATUS
     74 PeiUsbInquiry (
     75   IN  EFI_PEI_SERVICES  **PeiServices,
     76   IN  PEI_BOT_DEVICE    *PeiBotDevice
     77   );
     78 
     79 /**
     80   Sends out ATAPI Test Unit Ready Packet Command to the specified device
     81   to find out whether device is accessible.
     82 
     83   @param PeiServices    The pointer of EFI_PEI_SERVICES.
     84   @param PeiBotDevice   The pointer to PEI_BOT_DEVICE instance.
     85 
     86   @retval EFI_SUCCESS        TestUnit command executed successfully.
     87   @retval EFI_DEVICE_ERROR   Device cannot be executed TestUnit command successfully.
     88 
     89 **/
     90 EFI_STATUS
     91 PeiUsbTestUnitReady (
     92   IN  EFI_PEI_SERVICES  **PeiServices,
     93   IN  PEI_BOT_DEVICE    *PeiBotDevice
     94   );
     95 
     96 /**
     97   Sends out ATAPI Request Sense Packet Command to the specified device.
     98 
     99   @param PeiServices    The pointer of EFI_PEI_SERVICES.
    100   @param PeiBotDevice   The pointer to PEI_BOT_DEVICE instance.
    101   @param SenseCounts    Length of sense buffer.
    102   @param SenseKeyBuffer Pointer to sense buffer.
    103 
    104   @retval EFI_SUCCESS           Command executed successfully.
    105   @retval EFI_DEVICE_ERROR      Some device errors happen.
    106 
    107 **/
    108 EFI_STATUS
    109 PeiUsbRequestSense (
    110   IN  EFI_PEI_SERVICES  **PeiServices,
    111   IN  PEI_BOT_DEVICE    *PeiBotDevice,
    112   OUT UINTN             *SenseCounts,
    113   IN  UINT8             *SenseKeyBuffer
    114   );
    115 
    116 /**
    117   Sends out ATAPI Read Capacity Packet Command to the specified device.
    118   This command will return the information regarding the capacity of the
    119   media in the device.
    120 
    121   @param PeiServices    The pointer of EFI_PEI_SERVICES.
    122   @param PeiBotDevice   The pointer to PEI_BOT_DEVICE instance.
    123 
    124   @retval EFI_SUCCESS           Command executed successfully.
    125   @retval EFI_DEVICE_ERROR      Some device errors happen.
    126 
    127 **/
    128 EFI_STATUS
    129 PeiUsbReadCapacity (
    130   IN  EFI_PEI_SERVICES  **PeiServices,
    131   IN  PEI_BOT_DEVICE    *PeiBotDevice
    132   );
    133 
    134 /**
    135   Sends out ATAPI Read Format Capacity Data Command to the specified device.
    136   This command will return the information regarding the capacity of the
    137   media in the device.
    138 
    139   @param PeiServices    The pointer of EFI_PEI_SERVICES.
    140   @param PeiBotDevice   The pointer to PEI_BOT_DEVICE instance.
    141 
    142   @retval EFI_SUCCESS           Command executed successfully.
    143   @retval EFI_DEVICE_ERROR      Some device errors happen.
    144 
    145 **/
    146 EFI_STATUS
    147 PeiUsbReadFormattedCapacity (
    148   IN  EFI_PEI_SERVICES  **PeiServices,
    149   IN  PEI_BOT_DEVICE    *PeiBotDevice
    150   );
    151 
    152 /**
    153   Execute Read(10) ATAPI command on a specific SCSI target.
    154 
    155   Executes the ATAPI Read(10) command on the ATAPI target specified by PeiBotDevice.
    156 
    157   @param PeiServices       The pointer of EFI_PEI_SERVICES.
    158   @param PeiBotDevice      The pointer to PEI_BOT_DEVICE instance.
    159   @param Buffer            The pointer to data buffer.
    160   @param Lba               The start logic block address of reading.
    161   @param NumberOfBlocks    The block number of reading.
    162 
    163   @retval EFI_SUCCESS           Command executed successfully.
    164   @retval EFI_DEVICE_ERROR      Some device errors happen.
    165 
    166 **/
    167 EFI_STATUS
    168 PeiUsbRead10 (
    169   IN  EFI_PEI_SERVICES  **PeiServices,
    170   IN  PEI_BOT_DEVICE    *PeiBotDevice,
    171   IN  VOID              *Buffer,
    172   IN  EFI_PEI_LBA       Lba,
    173   IN  UINTN             NumberOfBlocks
    174   );
    175 
    176 /**
    177   Check if there is media according to sense data.
    178 
    179   @param  SenseData   Pointer to sense data.
    180   @param  SenseCounts Count of sense data.
    181 
    182   @retval TRUE    No media
    183   @retval FALSE   Media exists
    184 
    185 **/
    186 BOOLEAN
    187 IsNoMedia (
    188   IN  ATAPI_REQUEST_SENSE_DATA    *SenseData,
    189   IN  UINTN                 SenseCounts
    190   );
    191 
    192 /**
    193   Check if there is media error according to sense data.
    194 
    195   @param  SenseData   Pointer to sense data.
    196   @param  SenseCounts Count of sense data.
    197 
    198   @retval TRUE    Media error
    199   @retval FALSE   No media error
    200 
    201 **/
    202 BOOLEAN
    203 IsMediaError (
    204   IN  ATAPI_REQUEST_SENSE_DATA    *SenseData,
    205   IN  UINTN                 SenseCounts
    206   );
    207 
    208 /**
    209   Check if media is changed according to sense data.
    210 
    211   @param  SenseData   Pointer to sense data.
    212   @param  SenseCounts Count of sense data.
    213 
    214   @retval TRUE    There is media change event.
    215   @retval FALSE   media is NOT changed.
    216 
    217 **/
    218 BOOLEAN
    219 IsMediaChange (
    220   IN  ATAPI_REQUEST_SENSE_DATA    *SenseData,
    221   IN  UINTN                 SenseCounts
    222   );
    223 
    224 #endif
    225