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)
 
 FILE_SECBOOT (PERMITTED)
 
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  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ 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 76 of file nvs.c.

77  {
78  size_t frag_len;
79  int rc;
80 
81  /* We don't even attempt to handle buffer lengths that aren't
82  * an integral number of words.
83  */
84  assert ( ( len & ( ( 1 << nvs->word_len_log2 ) - 1 ) ) == 0 );
85 
86  while ( len ) {
87 
88  /* Calculate length to read, stopping at block boundaries */
89  frag_len = nvs_frag_len ( nvs, address, len );
90 
91  /* Read this portion of the buffer from the device */
92  if ( ( rc = nvs->read ( nvs, address, data, frag_len ) ) != 0 )
93  return rc;
94 
95  /* Update parameters */
96  data += frag_len;
97  address += ( frag_len >> nvs->word_len_log2 );
98  len -= frag_len;
99  }
100 
101  return 0;
102 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int word_len_log2
Word length.
Definition: nvs.h:23
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:47
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
int(* read)(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read data from device.
Definition: nvs.h:48
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 141 of file nvs.c.

142  {
143  size_t frag_len;
144  int rc;
145 
146  /* We don't even attempt to handle buffer lengths that aren't
147  * an integral number of words.
148  */
149  assert ( ( len & ( ( 1 << nvs->word_len_log2 ) - 1 ) ) == 0 );
150 
151  while ( len ) {
152 
153  /* Calculate length to write, stopping at block boundaries */
154  frag_len = nvs_frag_len ( nvs, address, len );
155 
156  /* Write this portion of the buffer to the device */
157  if ( ( rc = nvs->write ( nvs, address, data, frag_len ) ) != 0)
158  return rc;
159 
160  /* Read back and verify data */
161  if ( ( rc = nvs_verify ( nvs, address, data, frag_len ) ) != 0)
162  return rc;
163 
164  /* Update parameters */
165  data += frag_len;
166  address += ( frag_len >> nvs->word_len_log2 );
167  len -= frag_len;
168  }
169 
170  return 0;
171 }
int(* write)(struct nvs_device *nvs, unsigned int address, const void *data, size_t len)
Write data to device.
Definition: nvs.h:60
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int word_len_log2
Word length.
Definition: nvs.h:23
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:47
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
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:113

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

Referenced by nvo_save().