Home | History | Annotate | Download | only in BlockIoDxe
      1 /** @file
      2 
      3 Copyright (c) 1999 - 2011, Intel Corporation. All rights reserved.<BR>
      4 
      5 This program and the accompanying materials
      6 are licensed and made available under the terms and conditions
      7 of the BSD License which accompanies this distribution.  The
      8 full text of the license may be found at
      9 http://opensource.org/licenses/bsd-license.php
     10 
     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.
     13 
     14 **/
     15 
     16 #ifndef _BIOS_BLOCK_IO_H_
     17 #define _BIOS_BLOCK_IO_H_
     18 
     19 #include <Uefi.h>
     20 
     21 #include <Protocol/BlockIo.h>
     22 #include <Protocol/PciIo.h>
     23 #include <Protocol/LegacyBios.h>
     24 #include <Protocol/DevicePath.h>
     25 #include <Guid/LegacyBios.h>
     26 #include <Guid/BlockIoVendor.h>
     27 
     28 #include <Library/UefiDriverEntryPoint.h>
     29 #include <Library/DebugLib.h>
     30 #include <Library/BaseMemoryLib.h>
     31 #include <Library/UefiBootServicesTableLib.h>
     32 #include <Library/UefiLib.h>
     33 #include <Library/DevicePathLib.h>
     34 #include <Library/MemoryAllocationLib.h>
     35 
     36 #include <IndustryStandard/Pci.h>
     37 
     38 #include "Edd.h"
     39 
     40 //
     41 // Global Variables
     42 //
     43 extern EFI_COMPONENT_NAME_PROTOCOL   gBiosBlockIoComponentName;
     44 extern EFI_COMPONENT_NAME2_PROTOCOL  gBiosBlockIoComponentName2;
     45 
     46 
     47 //
     48 // Define the I2O class code
     49 //
     50 #define PCI_BASE_CLASS_INTELLIGENT  0x0e
     51 #define PCI_SUB_CLASS_INTELLIGENT   0x00
     52 
     53 //
     54 // Number of pages needed for our buffer under 1MB
     55 //
     56 #define BLOCK_IO_BUFFER_PAGE_SIZE (((sizeof (EDD_DEVICE_ADDRESS_PACKET) + sizeof (BIOS_LEGACY_DRIVE) + MAX_EDD11_XFER) / EFI_PAGE_SIZE) + 1 \
     57         )
     58 
     59 //
     60 // Driver Binding Protocol functions
     61 //
     62 
     63 /**
     64   Check whether the driver supports this device.
     65 
     66   @param  This                   The Udriver binding protocol.
     67   @param  Controller             The controller handle to check.
     68   @param  RemainingDevicePath    The remaining device path.
     69 
     70   @retval EFI_SUCCESS            The driver supports this controller.
     71   @retval other                  This device isn't supported.
     72 
     73 **/
     74 EFI_STATUS
     75 EFIAPI
     76 BiosBlockIoDriverBindingSupported (
     77   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
     78   IN EFI_HANDLE                   Controller,
     79   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath
     80   );
     81 
     82 
     83 /**
     84   Starts the device with this driver.
     85 
     86   @param  This                   The driver binding instance.
     87   @param  Controller             Handle of device to bind driver to.
     88   @param  RemainingDevicePath    Optional parameter use to pick a specific child
     89                                  device to start.
     90 
     91   @retval EFI_SUCCESS            The controller is controlled by the driver.
     92   @retval Other                  This controller cannot be started.
     93 
     94 **/
     95 EFI_STATUS
     96 EFIAPI
     97 BiosBlockIoDriverBindingStart (
     98   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
     99   IN EFI_HANDLE                   Controller,
    100   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath
    101   );
    102 
    103 /**
    104   Stop the device handled by this driver.
    105 
    106   @param  This                   The driver binding protocol.
    107   @param  Controller             The controller to release.
    108   @param  NumberOfChildren       The number of handles in ChildHandleBuffer.
    109   @param  ChildHandleBuffer      The array of child handle.
    110 
    111   @retval EFI_SUCCESS            The device was stopped.
    112   @retval EFI_DEVICE_ERROR       The device could not be stopped due to a device error.
    113   @retval Others                 Fail to uninstall protocols attached on the device.
    114 
    115 **/
    116 EFI_STATUS
    117 EFIAPI
    118 BiosBlockIoDriverBindingStop (
    119   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,
    120   IN  EFI_HANDLE                   Controller,
    121   IN  UINTN                        NumberOfChildren,
    122   IN  EFI_HANDLE                   *ChildHandleBuffer
    123   );
    124 
    125 //
    126 // Other internal functions
    127 //
    128 
    129 /**
    130   Build device path for EDD 3.0.
    131 
    132   @param  BaseDevicePath         Base device path.
    133   @param  Drive                  Legacy drive.
    134   @param  DevicePath             Device path for output.
    135 
    136   @retval EFI_SUCCESS            The device path is built successfully.
    137   @retval EFI_UNSUPPORTED        It is failed to built device path.
    138 
    139 **/
    140 EFI_STATUS
    141 BuildEdd30DevicePath (
    142   IN  EFI_DEVICE_PATH_PROTOCOL  *BaseDevicePath,
    143   IN  BIOS_LEGACY_DRIVE         *Drive,
    144   IN  EFI_DEVICE_PATH_PROTOCOL  **DevicePath
    145   );
    146 
    147 /**
    148   Initialize block I/O device instance
    149 
    150   @param  Dev   Instance of block I/O device instance
    151 
    152   @retval TRUE  Initialization succeeds.
    153   @retval FALSE Initialization fails.
    154 
    155 **/
    156 BOOLEAN
    157 BiosInitBlockIo (
    158   IN  BIOS_BLOCK_IO_DEV     *Dev
    159   );
    160 
    161 /**
    162   Read BufferSize bytes from Lba into Buffer.
    163 
    164   @param  This       Indicates a pointer to the calling context.
    165   @param  MediaId    Id of the media, changes every time the media is replaced.
    166   @param  Lba        The starting Logical Block Address to read from
    167   @param  BufferSize Size of Buffer, must be a multiple of device block size.
    168   @param  Buffer     A pointer to the destination buffer for the data. The caller is
    169                      responsible for either having implicit or explicit ownership of the buffer.
    170 
    171   @retval EFI_SUCCESS           The data was read correctly from the device.
    172   @retval EFI_DEVICE_ERROR      The device reported an error while performing the read.
    173   @retval EFI_NO_MEDIA          There is no media in the device.
    174   @retval EFI_MEDIA_CHANGED     The MediaId does not matched the current device.
    175   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.
    176   @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
    177                                 or the buffer is not on proper alignment.
    178 
    179 **/
    180 EFI_STATUS
    181 EFIAPI
    182 Edd30BiosReadBlocks (
    183   IN  EFI_BLOCK_IO_PROTOCOL *This,
    184   IN  UINT32                MediaId,
    185   IN  EFI_LBA               Lba,
    186   IN  UINTN                 BufferSize,
    187   OUT VOID                  *Buffer
    188   );
    189 
    190 /**
    191   Write BufferSize bytes from Lba into Buffer.
    192 
    193   @param  This       Indicates a pointer to the calling context.
    194   @param  MediaId    The media ID that the write request is for.
    195   @param  Lba        The starting logical block address to be written. The caller is
    196                      responsible for writing to only legitimate locations.
    197   @param  BufferSize Size of Buffer, must be a multiple of device block size.
    198   @param  Buffer     A pointer to the source buffer for the data.
    199 
    200   @retval EFI_SUCCESS           The data was written correctly to the device.
    201   @retval EFI_WRITE_PROTECTED   The device can not be written to.
    202   @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.
    203   @retval EFI_NO_MEDIA          There is no media in the device.
    204   @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.
    205   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.
    206   @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
    207                                 or the buffer is not on proper alignment.
    208 
    209 **/
    210 EFI_STATUS
    211 EFIAPI
    212 Edd30BiosWriteBlocks (
    213   IN  EFI_BLOCK_IO_PROTOCOL  *This,
    214   IN  UINT32                 MediaId,
    215   IN  EFI_LBA                Lba,
    216   IN  UINTN                  BufferSize,
    217   OUT VOID                   *Buffer
    218   );
    219 
    220 /**
    221   Flush the Block Device.
    222 
    223   @param  This              Indicates a pointer to the calling context.
    224 
    225   @retval EFI_SUCCESS       All outstanding data was written to the device
    226   @retval EFI_DEVICE_ERROR  The device reported an error while writting back the data
    227   @retval EFI_NO_MEDIA      There is no media in the device.
    228 
    229 **/
    230 EFI_STATUS
    231 EFIAPI
    232 BiosBlockIoFlushBlocks (
    233   IN  EFI_BLOCK_IO_PROTOCOL  *This
    234   );
    235 
    236 /**
    237   Reset the Block Device.
    238 
    239   @param  This                 Indicates a pointer to the calling context.
    240   @param  ExtendedVerification Driver may perform diagnostics on reset.
    241 
    242   @retval EFI_SUCCESS          The device was reset.
    243   @retval EFI_DEVICE_ERROR     The device is not functioning properly and could
    244                                not be reset.
    245 
    246 **/
    247 EFI_STATUS
    248 EFIAPI
    249 BiosBlockIoReset (
    250   IN  EFI_BLOCK_IO_PROTOCOL  *This,
    251   IN  BOOLEAN                ExtendedVerification
    252   );
    253 
    254 /**
    255   Read BufferSize bytes from Lba into Buffer.
    256 
    257   @param  This       Indicates a pointer to the calling context.
    258   @param  MediaId    Id of the media, changes every time the media is replaced.
    259   @param  Lba        The starting Logical Block Address to read from
    260   @param  BufferSize Size of Buffer, must be a multiple of device block size.
    261   @param  Buffer     A pointer to the destination buffer for the data. The caller is
    262                      responsible for either having implicit or explicit ownership of the buffer.
    263 
    264   @retval EFI_SUCCESS           The data was read correctly from the device.
    265   @retval EFI_DEVICE_ERROR      The device reported an error while performing the read.
    266   @retval EFI_NO_MEDIA          There is no media in the device.
    267   @retval EFI_MEDIA_CHANGED     The MediaId does not matched the current device.
    268   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.
    269   @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
    270                                 or the buffer is not on proper alignment.
    271 
    272 **/
    273 EFI_STATUS
    274 EFIAPI
    275 Edd11BiosReadBlocks (
    276   IN  EFI_BLOCK_IO_PROTOCOL *This,
    277   IN  UINT32                MediaId,
    278   IN  EFI_LBA               Lba,
    279   IN  UINTN                 BufferSize,
    280   OUT VOID                  *Buffer
    281   );
    282 
    283 /**
    284   Write BufferSize bytes from Lba into Buffer.
    285 
    286   @param  This       Indicates a pointer to the calling context.
    287   @param  MediaId    The media ID that the write request is for.
    288   @param  Lba        The starting logical block address to be written. The caller is
    289                      responsible for writing to only legitimate locations.
    290   @param  BufferSize Size of Buffer, must be a multiple of device block size.
    291   @param  Buffer     A pointer to the source buffer for the data.
    292 
    293   @retval EFI_SUCCESS           The data was written correctly to the device.
    294   @retval EFI_WRITE_PROTECTED   The device can not be written to.
    295   @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.
    296   @retval EFI_NO_MEDIA          There is no media in the device.
    297   @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.
    298   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.
    299   @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
    300                                 or the buffer is not on proper alignment.
    301 
    302 **/
    303 EFI_STATUS
    304 EFIAPI
    305 Edd11BiosWriteBlocks (
    306   IN  EFI_BLOCK_IO_PROTOCOL *This,
    307   IN  UINT32                MediaId,
    308   IN  EFI_LBA               Lba,
    309   IN  UINTN                 BufferSize,
    310   OUT VOID                  *Buffer
    311   );
    312 
    313 /**
    314   Read BufferSize bytes from Lba into Buffer.
    315 
    316   @param  This       Indicates a pointer to the calling context.
    317   @param  MediaId    Id of the media, changes every time the media is replaced.
    318   @param  Lba        The starting Logical Block Address to read from
    319   @param  BufferSize Size of Buffer, must be a multiple of device block size.
    320   @param  Buffer     A pointer to the destination buffer for the data. The caller is
    321                      responsible for either having implicit or explicit ownership of the buffer.
    322 
    323   @retval EFI_SUCCESS           The data was read correctly from the device.
    324   @retval EFI_DEVICE_ERROR      The device reported an error while performing the read.
    325   @retval EFI_NO_MEDIA          There is no media in the device.
    326   @retval EFI_MEDIA_CHANGED     The MediaId does not matched the current device.
    327   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.
    328   @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
    329                                 or the buffer is not on proper alignment.
    330 
    331 **/
    332 EFI_STATUS
    333 EFIAPI
    334 BiosReadLegacyDrive (
    335   IN  EFI_BLOCK_IO_PROTOCOL *This,
    336   IN  UINT32                MediaId,
    337   IN  EFI_LBA               Lba,
    338   IN  UINTN                 BufferSize,
    339   OUT VOID                  *Buffer
    340   );
    341 
    342 /**
    343   Write BufferSize bytes from Lba into Buffer.
    344 
    345   @param  This       Indicates a pointer to the calling context.
    346   @param  MediaId    The media ID that the write request is for.
    347   @param  Lba        The starting logical block address to be written. The caller is
    348                      responsible for writing to only legitimate locations.
    349   @param  BufferSize Size of Buffer, must be a multiple of device block size.
    350   @param  Buffer     A pointer to the source buffer for the data.
    351 
    352   @retval EFI_SUCCESS           The data was written correctly to the device.
    353   @retval EFI_WRITE_PROTECTED   The device can not be written to.
    354   @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.
    355   @retval EFI_NO_MEDIA          There is no media in the device.
    356   @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.
    357   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.
    358   @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
    359                                 or the buffer is not on proper alignment.
    360 
    361 **/
    362 EFI_STATUS
    363 EFIAPI
    364 BiosWriteLegacyDrive (
    365   IN  EFI_BLOCK_IO_PROTOCOL *This,
    366   IN  UINT32                MediaId,
    367   IN  EFI_LBA               Lba,
    368   IN  UINTN                 BufferSize,
    369   OUT VOID                  *Buffer
    370   );
    371 
    372 /**
    373   Gets parameters of block I/O device.
    374 
    375   @param  BiosBlockIoDev Instance of block I/O device.
    376   @param  Drive          Legacy drive.
    377 
    378   @return  Result of device parameter retrieval.
    379 
    380 **/
    381 UINTN
    382 Int13GetDeviceParameters (
    383   IN BIOS_BLOCK_IO_DEV    *BiosBlockIoDev,
    384   IN BIOS_LEGACY_DRIVE    *Drive
    385   );
    386 
    387 /**
    388   Extension of INT13 call.
    389 
    390   @param  BiosBlockIoDev Instance of block I/O device.
    391   @param  Drive          Legacy drive.
    392 
    393   @return  Result of this extension.
    394 
    395 **/
    396 UINTN
    397 Int13Extensions (
    398   IN BIOS_BLOCK_IO_DEV    *BiosBlockIoDev,
    399   IN BIOS_LEGACY_DRIVE    *Drive
    400   );
    401 
    402 /**
    403   Gets parameters of legacy drive.
    404 
    405   @param  BiosBlockIoDev Instance of block I/O device.
    406   @param  Drive          Legacy drive.
    407 
    408   @return  Result of drive parameter retrieval.
    409 
    410 **/
    411 UINTN
    412 GetDriveParameters (
    413   IN BIOS_BLOCK_IO_DEV    *BiosBlockIoDev,
    414   IN  BIOS_LEGACY_DRIVE   *Drive
    415   );
    416 
    417 /**
    418   Build device path for device.
    419 
    420   @param  BaseDevicePath         Base device path.
    421   @param  Drive                  Legacy drive.
    422   @param  DevicePath             Device path for output.
    423 
    424 **/
    425 VOID
    426 SetBiosInitBlockIoDevicePath (
    427   IN  EFI_DEVICE_PATH_PROTOCOL  *BaseDevicePath,
    428   IN  BIOS_LEGACY_DRIVE         *Drive,
    429   OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePath
    430   );
    431 
    432 #endif
    433