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.7KB

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