Home | History | Annotate | Download | only in FlashFvbDxe
      1 /** @file
      2 *
      3 *  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
      4 *  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
      5 *  Copyright (c) 2015, Linaro Limited. All rights reserved.
      6 *
      7 *  This program and the accompanying materials
      8 *  are licensed and made available under the terms and conditions of the BSD License
      9 *  which accompanies this distribution.  The 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 #include "FlashFvbDxe.h"
     18 
     19 //
     20 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
     21 //
     22 EFI_STATUS
     23 EFIAPI
     24 FlashBlockIoReadBlocks (
     25     IN  EFI_BLOCK_IO_PROTOCOL*     This,
     26     IN  UINT32                  MediaId,
     27     IN  EFI_LBA                     Lba,
     28     IN  UINTN         BufferSizeInBytes,
     29     OUT VOID*                     Buffer
     30 )
     31 {
     32     FLASH_INSTANCE*   Instance;
     33     EFI_STATUS          Status;
     34 
     35     Instance = INSTANCE_FROM_BLKIO_THIS(This);
     36 
     37     DEBUG ((EFI_D_INFO, "FlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
     38 
     39     if ( !This->Media->MediaPresent )
     40     {
     41         Status = EFI_NO_MEDIA;
     42     }
     43     else if ( This->Media->MediaId != MediaId )
     44     {
     45         Status = EFI_MEDIA_CHANGED;
     46     }
     47     else
     48     {
     49         Status = FlashReadBlocks (Instance, Lba, BufferSizeInBytes, Buffer);
     50     }
     51 
     52     return Status;
     53 }
     54 
     55 //
     56 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
     57 //
     58 EFI_STATUS
     59 EFIAPI
     60 FlashBlockIoWriteBlocks (
     61     IN  EFI_BLOCK_IO_PROTOCOL*     This,
     62     IN  UINT32                  MediaId,
     63     IN  EFI_LBA                     Lba,
     64     IN  UINTN         BufferSizeInBytes,
     65     IN  VOID*                     Buffer
     66 )
     67 {
     68     FLASH_INSTANCE*   Instance;
     69     EFI_STATUS          Status;
     70 
     71     Instance = INSTANCE_FROM_BLKIO_THIS(This);
     72 
     73     DEBUG ((EFI_D_INFO, "FlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
     74 
     75     if ( !This->Media->MediaPresent )
     76     {
     77         Status = EFI_NO_MEDIA;
     78     }
     79     else if ( This->Media->MediaId != MediaId )
     80     {
     81         Status = EFI_MEDIA_CHANGED;
     82     }
     83     else if ( This->Media->ReadOnly )
     84     {
     85         Status = EFI_WRITE_PROTECTED;
     86     }
     87     else
     88     {
     89         Status = FlashWriteBlocks (Instance, Lba, BufferSizeInBytes, Buffer);
     90     }
     91 
     92     return Status;
     93 }
     94 
     95 //
     96 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
     97 //
     98 EFI_STATUS
     99 EFIAPI
    100 FlashBlockIoFlushBlocks (
    101     IN EFI_BLOCK_IO_PROTOCOL*  This
    102 )
    103 {
    104     // No Flush required for the NOR Flash driver
    105     // because cache operations are not permitted.
    106 
    107     // Nothing to do so just return without error
    108     return EFI_SUCCESS;
    109 }
    110