You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nvs.h 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef _IPXE_NVS_H
  2. #define _IPXE_NVS_H
  3. /** @file
  4. *
  5. * Non-volatile storage
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. /** A non-volatile storage device */
  11. struct nvs_device {
  12. /** Word length
  13. *
  14. * This is expressed as the base-2 logarithm of the word
  15. * length in bytes. A value of 0 therefore translates as
  16. * 8-bit words, and a value of 1 translates as 16-bit words.
  17. */
  18. unsigned int word_len_log2;
  19. /** Device size (in words) */
  20. unsigned int size;
  21. /** Data block size (in words)
  22. *
  23. * This is the block size used by the device. It must be a
  24. * power of two. Data reads and writes must not cross a block
  25. * boundary.
  26. *
  27. * Many devices allow reads to cross a block boundary, and
  28. * restrict only writes. For the sake of simplicity, we
  29. * assume that the same restriction applies to both reads and
  30. * writes.
  31. */
  32. unsigned int block_size;
  33. /** Read data from device
  34. *
  35. * @v nvs NVS device
  36. * @v address Address from which to read
  37. * @v data Data buffer
  38. * @v len Length of data buffer
  39. * @ret rc Return status code
  40. *
  41. * Reads may not cross a block boundary.
  42. */
  43. int ( * read ) ( struct nvs_device *nvs, unsigned int address,
  44. void *data, size_t len );
  45. /** Write data to device
  46. *
  47. * @v nvs NVS device
  48. * @v address Address to which to write
  49. * @v data Data buffer
  50. * @v len Length of data buffer
  51. * @ret rc Return status code
  52. *
  53. * Writes may not cross a block boundary.
  54. */
  55. int ( * write ) ( struct nvs_device *nvs, unsigned int address,
  56. const void *data, size_t len );
  57. };
  58. extern int nvs_read ( struct nvs_device *nvs, unsigned int address,
  59. void *data, size_t len );
  60. extern int nvs_write ( struct nvs_device *nvs, unsigned int address,
  61. const void *data, size_t len );
  62. #endif /* _IPXE_NVS_H */