00001 #ifndef _GPXE_NVS_H 00002 #define _GPXE_NVS_H 00003 00004 /** @file 00005 * 00006 * Non-volatile storage 00007 * 00008 */ 00009 00010 FILE_LICENCE ( GPL2_OR_LATER ); 00011 00012 #include <stdint.h> 00013 00014 /** A non-volatile storage device */ 00015 struct nvs_device { 00016 /** Word length 00017 * 00018 * This is expressed as the base-2 logarithm of the word 00019 * length in bytes. A value of 0 therefore translates as 00020 * 8-bit words, and a value of 1 translates as 16-bit words. 00021 */ 00022 unsigned int word_len_log2; 00023 /** Device size (in words) */ 00024 unsigned int size; 00025 /** Data block size (in words) 00026 * 00027 * This is the block size used by the device. It must be a 00028 * power of two. Data reads and writes must not cross a block 00029 * boundary. 00030 * 00031 * Many devices allow reads to cross a block boundary, and 00032 * restrict only writes. For the sake of simplicity, we 00033 * assume that the same restriction applies to both reads and 00034 * writes. 00035 */ 00036 unsigned int block_size; 00037 /** Read data from device 00038 * 00039 * @v nvs NVS device 00040 * @v address Address from which to read 00041 * @v data Data buffer 00042 * @v len Length of data buffer 00043 * @ret rc Return status code 00044 * 00045 * Reads may not cross a block boundary. 00046 */ 00047 int ( * read ) ( struct nvs_device *nvs, unsigned int address, 00048 void *data, size_t len ); 00049 /** Write data to device 00050 * 00051 * @v nvs NVS device 00052 * @v address Address to which to write 00053 * @v data Data buffer 00054 * @v len Length of data buffer 00055 * @ret rc Return status code 00056 * 00057 * Writes may not cross a block boundary. 00058 */ 00059 int ( * write ) ( struct nvs_device *nvs, unsigned int address, 00060 const void *data, size_t len ); 00061 }; 00062 00063 extern int nvs_read ( struct nvs_device *nvs, unsigned int address, 00064 void *data, size_t len ); 00065 extern int nvs_write ( struct nvs_device *nvs, unsigned int address, 00066 const void *data, size_t len ); 00067 00068 #endif /* _GPXE_NVS_H */
1.5.7.1