FlashBlockIoDxe.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include "FlashFvbDxe.h"
  17. //
  18. // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
  19. //
  20. EFI_STATUS
  21. EFIAPI
  22. FlashBlockIoReadBlocks (
  23. IN EFI_BLOCK_IO_PROTOCOL* This,
  24. IN UINT32 MediaId,
  25. IN EFI_LBA Lba,
  26. IN UINTN BufferSizeInBytes,
  27. OUT VOID* Buffer
  28. )
  29. {
  30. FLASH_INSTANCE* Instance;
  31. EFI_STATUS Status;
  32. Instance = INSTANCE_FROM_BLKIO_THIS(This);
  33. DEBUG ((EFI_D_INFO, "FlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
  34. if ( !This->Media->MediaPresent )
  35. {
  36. Status = EFI_NO_MEDIA;
  37. }
  38. else if ( This->Media->MediaId != MediaId )
  39. {
  40. Status = EFI_MEDIA_CHANGED;
  41. }
  42. else
  43. {
  44. Status = FlashReadBlocks (Instance, Lba, BufferSizeInBytes, Buffer);
  45. }
  46. return Status;
  47. }
  48. //
  49. // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
  50. //
  51. EFI_STATUS
  52. EFIAPI
  53. FlashBlockIoWriteBlocks (
  54. IN EFI_BLOCK_IO_PROTOCOL* This,
  55. IN UINT32 MediaId,
  56. IN EFI_LBA Lba,
  57. IN UINTN BufferSizeInBytes,
  58. IN VOID* Buffer
  59. )
  60. {
  61. FLASH_INSTANCE* Instance;
  62. EFI_STATUS Status;
  63. Instance = INSTANCE_FROM_BLKIO_THIS(This);
  64. DEBUG ((EFI_D_INFO, "FlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
  65. if ( !This->Media->MediaPresent )
  66. {
  67. Status = EFI_NO_MEDIA;
  68. }
  69. else if ( This->Media->MediaId != MediaId )
  70. {
  71. Status = EFI_MEDIA_CHANGED;
  72. }
  73. else if ( This->Media->ReadOnly )
  74. {
  75. Status = EFI_WRITE_PROTECTED;
  76. }
  77. else
  78. {
  79. Status = FlashWriteBlocks (Instance, Lba, BufferSizeInBytes, Buffer);
  80. }
  81. return Status;
  82. }
  83. //
  84. // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
  85. //
  86. EFI_STATUS
  87. EFIAPI
  88. FlashBlockIoFlushBlocks (
  89. IN EFI_BLOCK_IO_PROTOCOL* This
  90. )
  91. {
  92. // No Flush required for the NOR Flash driver
  93. // because cache operations are not permitted.
  94. // Nothing to do so just return without error
  95. return EFI_SUCCESS;
  96. }