SpiFlashCommonLib.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /** @file
  2. The header file includes the common header files, defines
  3. internal structure and functions used by SpiFlashCommonLib.
  4. Copyright (c) 2019 Intel Corporation. All rights reserved. <BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #ifndef __SPI_FLASH_COMMON_LIB_H__
  8. #define __SPI_FLASH_COMMON_LIB_H__
  9. #include <Uefi.h>
  10. #include <Library/BaseLib.h>
  11. #include <Library/PcdLib.h>
  12. #include <Library/DebugLib.h>
  13. #include <Library/BaseMemoryLib.h>
  14. #include <Library/MemoryAllocationLib.h>
  15. #include <Library/UefiDriverEntryPoint.h>
  16. #include <Library/UefiBootServicesTableLib.h>
  17. #define SECTOR_SIZE_4KB 0x1000 // Common 4kBytes sector size
  18. /**
  19. Enable block protection on the Serial Flash device.
  20. @retval EFI_SUCCESS Opertion is successful.
  21. @retval EFI_DEVICE_ERROR If there is any device errors.
  22. **/
  23. EFI_STATUS
  24. EFIAPI
  25. SpiFlashLock (
  26. VOID
  27. );
  28. /**
  29. Read NumBytes bytes of data from the address specified by
  30. PAddress into Buffer.
  31. @param[in] Address The starting physical address of the read.
  32. @param[in,out] NumBytes On input, the number of bytes to read. On output, the number
  33. of bytes actually read.
  34. @param[out] Buffer The destination data buffer for the read.
  35. @retval EFI_SUCCESS Opertion is successful.
  36. @retval EFI_DEVICE_ERROR If there is any device errors.
  37. **/
  38. EFI_STATUS
  39. EFIAPI
  40. SpiFlashRead (
  41. IN UINTN Address,
  42. IN OUT UINT32 *NumBytes,
  43. OUT UINT8 *Buffer
  44. );
  45. /**
  46. Write NumBytes bytes of data from Buffer to the address specified by
  47. PAddresss.
  48. @param[in] Address The starting physical address of the write.
  49. @param[in,out] NumBytes On input, the number of bytes to write. On output,
  50. the actual number of bytes written.
  51. @param[in] Buffer The source data buffer for the write.
  52. @retval EFI_SUCCESS Opertion is successful.
  53. @retval EFI_DEVICE_ERROR If there is any device errors.
  54. **/
  55. EFI_STATUS
  56. EFIAPI
  57. SpiFlashWrite (
  58. IN UINTN Address,
  59. IN OUT UINT32 *NumBytes,
  60. IN UINT8 *Buffer
  61. );
  62. /**
  63. Erase the block starting at Address.
  64. @param[in] Address The starting physical address of the block to be erased.
  65. This library assume that caller garantee that the PAddress
  66. is at the starting address of this block.
  67. @param[in] NumBytes On input, the number of bytes of the logical block to be erased.
  68. On output, the actual number of bytes erased.
  69. @retval EFI_SUCCESS. Opertion is successful.
  70. @retval EFI_DEVICE_ERROR If there is any device errors.
  71. **/
  72. EFI_STATUS
  73. EFIAPI
  74. SpiFlashBlockErase (
  75. IN UINTN Address,
  76. IN UINTN *NumBytes
  77. );
  78. #endif