iPXE
Data Structures | Functions
nvs.h File Reference

Non-volatile storage. More...

#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  nvs_device
 A non-volatile storage device. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int nvs_read (struct nvs_device *nvs, unsigned int address, void *data, size_t len)
 Read from non-volatile storage device. More...
 
int nvs_write (struct nvs_device *nvs, unsigned int address, const void *data, size_t len)
 Write to non-volatile storage device. More...
 

Detailed Description

Non-volatile storage.

Definition in file nvs.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ nvs_read()

int nvs_read ( struct nvs_device nvs,
unsigned int  address,
void *  data,
size_t  len 
)

Read from non-volatile storage device.

Parameters
nvsNVS device
addressAddress from which to read
dataData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 75 of file nvs.c.

76  {
77  size_t frag_len;
78  int rc;
79 
80  /* We don't even attempt to handle buffer lengths that aren't
81  * an integral number of words.
82  */
83  assert ( ( len & ( ( 1 << nvs->word_len_log2 ) - 1 ) ) == 0 );
84 
85  while ( len ) {
86 
87  /* Calculate length to read, stopping at block boundaries */
88  frag_len = nvs_frag_len ( nvs, address, len );
89 
90  /* Read this portion of the buffer from the device */
91  if ( ( rc = nvs->read ( nvs, address, data, frag_len ) ) != 0 )
92  return rc;
93 
94  /* Update parameters */
95  data += frag_len;
96  address += ( frag_len >> nvs->word_len_log2 );
97  len -= frag_len;
98  }
99 
100  return 0;
101 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int word_len_log2
Word length.
Definition: nvs.h:22
uint64_t address
Base address.
Definition: ena.h:24
static size_t nvs_frag_len(struct nvs_device *nvs, unsigned int address, size_t max_len)
Calculate length up to next block boundary.
Definition: nvs.c:46
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int(* read)(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read data from device.
Definition: nvs.h:47
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References address, assert(), data, len, nvs_frag_len(), rc, nvs_device::read, and nvs_device::word_len_log2.

Referenced by a3c90x_internal_ReadEepromContents(), falcon_probe_nvram(), icplus_probe(), ifec_pci_probe(), intel_fetch_mac_eeprom(), natsemi_hwaddr(), nvo_load(), nvs_verify(), realtek_init_eeprom(), realtek_probe(), and rtl818x_probe().

◆ nvs_write()

int nvs_write ( struct nvs_device nvs,
unsigned int  address,
const void *  data,
size_t  len 
)

Write to non-volatile storage device.

Parameters
nvsNVS device
addressAddress to which to write
dataData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 140 of file nvs.c.

141  {
142  size_t frag_len;
143  int rc;
144 
145  /* We don't even attempt to handle buffer lengths that aren't
146  * an integral number of words.
147  */
148  assert ( ( len & ( ( 1 << nvs->word_len_log2 ) - 1 ) ) == 0 );
149 
150  while ( len ) {
151 
152  /* Calculate length to write, stopping at block boundaries */
153  frag_len = nvs_frag_len ( nvs, address, len );
154 
155  /* Write this portion of the buffer to the device */
156  if ( ( rc = nvs->write ( nvs, address, data, frag_len ) ) != 0)
157  return rc;
158 
159  /* Read back and verify data */
160  if ( ( rc = nvs_verify ( nvs, address, data, frag_len ) ) != 0)
161  return rc;
162 
163  /* Update parameters */
164  data += frag_len;
165  address += ( frag_len >> nvs->word_len_log2 );
166  len -= frag_len;
167  }
168 
169  return 0;
170 }
int(* write)(struct nvs_device *nvs, unsigned int address, const void *data, size_t len)
Write data to device.
Definition: nvs.h:59
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int word_len_log2
Word length.
Definition: nvs.h:22
uint64_t address
Base address.
Definition: ena.h:24
static size_t nvs_frag_len(struct nvs_device *nvs, unsigned int address, size_t max_len)
Calculate length up to next block boundary.
Definition: nvs.c:46
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
static int nvs_verify(struct nvs_device *nvs, unsigned int address, const void *data, size_t len)
Verify content of non-volatile storage device.
Definition: nvs.c:112

References address, assert(), data, len, nvs_frag_len(), nvs_verify(), rc, nvs_device::word_len_log2, and nvs_device::write.

Referenced by nvo_save().