Home | History | Annotate | Download | only in NorFlashDxe
      1 /** @file  NorFlashBlockIoDxe.c
      2 
      3   Copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR>
      4 
      5   This program and the accompanying materials
      6   are licensed and made available under the terms and conditions of the BSD License
      7   which accompanies this distribution.  The full text of the license may be found at
      8   http://opensource.org/licenses/bsd-license.php
      9 
     10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 
     13 **/
     14 
     15 #include <Library/BaseMemoryLib.h>
     16 #include <Library/UefiBootServicesTableLib.h>
     17 
     18 #include "NorFlashDxe.h"
     19 
     20 //
     21 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
     22 //
     23 EFI_STATUS
     24 EFIAPI
     25 NorFlashBlockIoReset (
     26   IN EFI_BLOCK_IO_PROTOCOL  *This,
     27   IN BOOLEAN                ExtendedVerification
     28   )
     29 {
     30   NOR_FLASH_INSTANCE *Instance;
     31 
     32   Instance = INSTANCE_FROM_BLKIO_THIS(This);
     33 
     34   DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=0x%x)\n", This->Media->MediaId));
     35 
     36   return NorFlashReset (Instance);
     37 }
     38 
     39 //
     40 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
     41 //
     42 EFI_STATUS
     43 EFIAPI
     44 NorFlashBlockIoReadBlocks (
     45   IN  EFI_BLOCK_IO_PROTOCOL   *This,
     46   IN  UINT32                  MediaId,
     47   IN  EFI_LBA                 Lba,
     48   IN  UINTN                   BufferSizeInBytes,
     49   OUT VOID                    *Buffer
     50   )
     51 {
     52   NOR_FLASH_INSTANCE  *Instance;
     53   EFI_STATUS          Status;
     54   EFI_BLOCK_IO_MEDIA  *Media;
     55 
     56   if (This == NULL) {
     57     return EFI_INVALID_PARAMETER;
     58   }
     59 
     60   Instance = INSTANCE_FROM_BLKIO_THIS(This);
     61   Media = This->Media;
     62 
     63   DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
     64 
     65   if (!Media) {
     66     Status = EFI_INVALID_PARAMETER;
     67   } else if (!Media->MediaPresent) {
     68     Status = EFI_NO_MEDIA;
     69   } else if (Media->MediaId != MediaId) {
     70     Status = EFI_MEDIA_CHANGED;
     71   } else if ((Media->IoAlign > 2) && (((UINTN)Buffer & (Media->IoAlign - 1)) != 0)) {
     72     Status = EFI_INVALID_PARAMETER;
     73   } else {
     74     Status = NorFlashReadBlocks (Instance, Lba, BufferSizeInBytes, Buffer);
     75   }
     76 
     77   return Status;
     78 }
     79 
     80 //
     81 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
     82 //
     83 EFI_STATUS
     84 EFIAPI
     85 NorFlashBlockIoWriteBlocks (
     86   IN  EFI_BLOCK_IO_PROTOCOL   *This,
     87   IN  UINT32                  MediaId,
     88   IN  EFI_LBA                 Lba,
     89   IN  UINTN                   BufferSizeInBytes,
     90   IN  VOID                    *Buffer
     91   )
     92 {
     93   NOR_FLASH_INSTANCE  *Instance;
     94   EFI_STATUS          Status;
     95 
     96   Instance = INSTANCE_FROM_BLKIO_THIS(This);
     97 
     98   DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
     99 
    100   if( !This->Media->MediaPresent ) {
    101     Status = EFI_NO_MEDIA;
    102   } else if( This->Media->MediaId != MediaId ) {
    103     Status = EFI_MEDIA_CHANGED;
    104   } else if( This->Media->ReadOnly ) {
    105     Status = EFI_WRITE_PROTECTED;
    106   } else {
    107     Status = NorFlashWriteBlocks (Instance,Lba,BufferSizeInBytes,Buffer);
    108   }
    109 
    110   return Status;
    111 }
    112 
    113 //
    114 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
    115 //
    116 EFI_STATUS
    117 EFIAPI
    118 NorFlashBlockIoFlushBlocks (
    119   IN EFI_BLOCK_IO_PROTOCOL  *This
    120   )
    121 {
    122   // No Flush required for the NOR Flash driver
    123   // because cache operations are not permitted.
    124 
    125   DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));
    126 
    127   // Nothing to do so just return without error
    128   return EFI_SUCCESS;
    129 }
    130