NorFlashBlockIoDxe.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /** @file NorFlashBlockIoDxe.c
  2. Copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. #include <Library/BaseMemoryLib.h>
  6. #include <Library/UefiBootServicesTableLib.h>
  7. #include "NorFlash.h"
  8. //
  9. // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
  10. //
  11. EFI_STATUS
  12. EFIAPI
  13. NorFlashBlockIoReset (
  14. IN EFI_BLOCK_IO_PROTOCOL *This,
  15. IN BOOLEAN ExtendedVerification
  16. )
  17. {
  18. NOR_FLASH_INSTANCE *Instance;
  19. Instance = INSTANCE_FROM_BLKIO_THIS (This);
  20. DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=0x%x)\n", This->Media->MediaId));
  21. return NorFlashReset (Instance);
  22. }
  23. //
  24. // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
  25. //
  26. EFI_STATUS
  27. EFIAPI
  28. NorFlashBlockIoReadBlocks (
  29. IN EFI_BLOCK_IO_PROTOCOL *This,
  30. IN UINT32 MediaId,
  31. IN EFI_LBA Lba,
  32. IN UINTN BufferSizeInBytes,
  33. OUT VOID *Buffer
  34. )
  35. {
  36. NOR_FLASH_INSTANCE *Instance;
  37. EFI_STATUS Status;
  38. EFI_BLOCK_IO_MEDIA *Media;
  39. if (This == NULL) {
  40. return EFI_INVALID_PARAMETER;
  41. }
  42. Instance = INSTANCE_FROM_BLKIO_THIS (This);
  43. Media = This->Media;
  44. DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, BufferSizeInBytes, Buffer));
  45. if (!Media) {
  46. Status = EFI_INVALID_PARAMETER;
  47. } else if (!Media->MediaPresent) {
  48. Status = EFI_NO_MEDIA;
  49. } else if (Media->MediaId != MediaId) {
  50. Status = EFI_MEDIA_CHANGED;
  51. } else if ((Media->IoAlign > 2) && (((UINTN)Buffer & (Media->IoAlign - 1)) != 0)) {
  52. Status = EFI_INVALID_PARAMETER;
  53. } else {
  54. Status = NorFlashReadBlocks (Instance, Lba, BufferSizeInBytes, Buffer);
  55. }
  56. return Status;
  57. }
  58. //
  59. // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
  60. //
  61. EFI_STATUS
  62. EFIAPI
  63. NorFlashBlockIoWriteBlocks (
  64. IN EFI_BLOCK_IO_PROTOCOL *This,
  65. IN UINT32 MediaId,
  66. IN EFI_LBA Lba,
  67. IN UINTN BufferSizeInBytes,
  68. IN VOID *Buffer
  69. )
  70. {
  71. NOR_FLASH_INSTANCE *Instance;
  72. EFI_STATUS Status;
  73. Instance = INSTANCE_FROM_BLKIO_THIS (This);
  74. DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes, BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
  75. if ( !This->Media->MediaPresent ) {
  76. Status = EFI_NO_MEDIA;
  77. } else if ( This->Media->MediaId != MediaId ) {
  78. Status = EFI_MEDIA_CHANGED;
  79. } else if ( This->Media->ReadOnly ) {
  80. Status = EFI_WRITE_PROTECTED;
  81. } else {
  82. Status = NorFlashWriteBlocks (Instance, Lba, BufferSizeInBytes, Buffer);
  83. }
  84. return Status;
  85. }
  86. //
  87. // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
  88. //
  89. EFI_STATUS
  90. EFIAPI
  91. NorFlashBlockIoFlushBlocks (
  92. IN EFI_BLOCK_IO_PROTOCOL *This
  93. )
  94. {
  95. // No Flush required for the NOR Flash driver
  96. // because cache operations are not permitted.
  97. DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));
  98. // Nothing to do so just return without error
  99. return EFI_SUCCESS;
  100. }