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.
int nvs_write (struct nvs_device *nvs, unsigned int address, const void *data, size_t len)
 Write to non-volatile storage device.

Detailed Description

Non-volatile storage.

Definition in file nvs.h.


Function Documentation

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.

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.

References assert, 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().

                                        {
        size_t frag_len;
        int rc;

        /* We don't even attempt to handle buffer lengths that aren't
         * an integral number of words.
         */
        assert ( ( len & ( ( 1 << nvs->word_len_log2 ) - 1 ) ) == 0 );

        while ( len ) {

                /* Calculate length to read, stopping at block boundaries */
                frag_len = nvs_frag_len ( nvs, address, len );

                /* Read this portion of the buffer from the device */
                if ( ( rc = nvs->read ( nvs, address, data, frag_len ) ) != 0 )
                        return rc;

                /* Update parameters */
                data += frag_len;
                address += ( frag_len >> nvs->word_len_log2 );
                len -= frag_len;
        }

        return 0;
}
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.

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

Referenced by nvo_save().

                                               {
        size_t frag_len;
        int rc;

        /* We don't even attempt to handle buffer lengths that aren't
         * an integral number of words.
         */
        assert ( ( len & ( ( 1 << nvs->word_len_log2 ) - 1 ) ) == 0 );

        while ( len ) {

                /* Calculate length to write, stopping at block boundaries */
                frag_len = nvs_frag_len ( nvs, address, len );

                /* Write this portion of the buffer to the device */
                if ( ( rc = nvs->write ( nvs, address, data, frag_len ) ) != 0)
                        return rc;

                /* Read back and verify data */
                if ( ( rc = nvs_verify ( nvs, address, data, frag_len ) ) != 0)
                        return rc;

                /* Update parameters */
                data += frag_len;
                address += ( frag_len >> nvs->word_len_log2 );
                len -= frag_len;
        }

        return 0;
}