iPXE
Functions
nvsvpd.c File Reference

Non-Volatile Storage using Vital Product Data. More...

#include <stdio.h>
#include <errno.h>
#include <ipxe/nvs.h>
#include <ipxe/pci.h>
#include <ipxe/pcivpd.h>
#include <ipxe/nvo.h>
#include <ipxe/nvsvpd.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int nvs_vpd_read (struct nvs_device *nvs, unsigned int field, void *data, size_t len)
 Read from VPD field. More...
 
static int nvs_vpd_write (struct nvs_device *nvs, unsigned int field, const void *data, size_t len)
 Write to VPD field. More...
 
static int nvs_vpd_resize (struct nvs_device *nvs, unsigned int field, size_t len)
 Resize VPD field. More...
 
int nvs_vpd_init (struct nvs_vpd_device *nvsvpd, struct pci_device *pci)
 Initialise NVS VPD device. More...
 
static int nvs_vpd_nvo_resize (struct nvo_block *nvo, size_t len)
 Resize non-volatile option storage within NVS VPD device. More...
 
void nvs_vpd_nvo_init (struct nvs_vpd_device *nvsvpd, unsigned int field, struct nvo_block *nvo, struct refcnt *refcnt)
 Initialise non-volatile option storage within NVS VPD device. More...
 

Detailed Description

Non-Volatile Storage using Vital Product Data.

Definition in file nvsvpd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ nvs_vpd_read()

static int nvs_vpd_read ( struct nvs_device nvs,
unsigned int  field,
void *  data,
size_t  len 
)
static

Read from VPD field.

Parameters
nvsNVS device
fieldVPD field descriptor
dataData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 49 of file nvsvpd.c.

50  {
51  struct nvs_vpd_device *nvsvpd =
52  container_of ( nvs, struct nvs_vpd_device, nvs );
53  struct pci_device *pci = nvsvpd->vpd.pci;
54  unsigned int address;
55  size_t max_len;
56  int rc;
57 
58  /* Allow reading non-existent field */
59  if ( len == 0 )
60  return 0;
61 
62  /* Locate VPD field */
63  if ( ( rc = pci_vpd_find ( &nvsvpd->vpd, field, &address,
64  &max_len ) ) != 0 ) {
65  DBGC ( pci, PCI_FMT " NVS VPD could not locate field "
66  PCI_VPD_FIELD_FMT ": %s\n", PCI_ARGS ( pci ),
67  PCI_VPD_FIELD_ARGS ( field ), strerror ( rc ) );
68  return rc;
69  }
70 
71  /* Sanity check */
72  if ( len > max_len ) {
73  DBGC ( pci, PCI_FMT " NVS VPD cannot read %#02zx bytes "
74  "beyond field " PCI_VPD_FIELD_FMT " at [%04x,%04zx)\n",
75  PCI_ARGS ( pci ), len, PCI_VPD_FIELD_ARGS ( field ),
76  address, ( address + max_len ) );
77  return -ENXIO;
78  }
79 
80  /* Read from VPD field */
81  if ( ( rc = pci_vpd_read ( &nvsvpd->vpd, address, data, len ) ) != 0 ) {
82  DBGC ( pci, PCI_FMT " NVS VPD could not read field "
83  PCI_VPD_FIELD_FMT " at [%04x,%04zx): %s\n",
84  PCI_ARGS ( pci ), PCI_VPD_FIELD_ARGS ( field ),
85  address, ( address + len ), strerror ( rc ) );
86  return rc;
87  }
88 
89  return 0;
90 }
int pci_vpd_find(struct pci_vpd *vpd, unsigned int field, unsigned int *address, size_t *len)
Locate PCI VPD field.
Definition: pcivpd.c:353
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int pci_vpd_read(struct pci_vpd *vpd, unsigned int address, void *buf, size_t len)
Read PCI VPD.
Definition: pcivpd.c:183
An NVS VPD device.
Definition: nvsvpd.h:20
static void size_t size_t max_len
Definition: entropy.h:153
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct nvs_device nvs
NVS device.
Definition: nvsvpd.h:22
#define PCI_VPD_FIELD_FMT
PCI VPD field debug message format.
Definition: pcivpd.h:70
struct pci_vpd vpd
PCI VPD device.
Definition: nvsvpd.h:24
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
A PCI device.
Definition: pci.h:187
#define PCI_VPD_FIELD_ARGS(field)
PCI VPD field debug message arguments.
Definition: pcivpd.h:73
#define ENXIO
No such device or address.
Definition: errno.h:599
uint32_t len
Length.
Definition: ena.h:14
struct pci_device * pci
PCI device.
Definition: pcivpd.h:132
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:290
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References address, container_of, data, DBGC, ENXIO, len, max_len, nvs_vpd_device::nvs, pci_vpd::pci, PCI_ARGS, PCI_FMT, PCI_VPD_FIELD_ARGS, PCI_VPD_FIELD_FMT, pci_vpd_find(), pci_vpd_read(), rc, strerror(), and nvs_vpd_device::vpd.

Referenced by nvs_vpd_init().

◆ nvs_vpd_write()

static int nvs_vpd_write ( struct nvs_device nvs,
unsigned int  field,
const void *  data,
size_t  len 
)
static

Write to VPD field.

Parameters
nvsNVS device
fieldVPD field descriptor
dataData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 101 of file nvsvpd.c.

102  {
103  struct nvs_vpd_device *nvsvpd =
104  container_of ( nvs, struct nvs_vpd_device, nvs );
105  struct pci_device *pci = nvsvpd->vpd.pci;
106  unsigned int address;
107  size_t max_len;
108  int rc;
109 
110  /* Locate VPD field */
111  if ( ( rc = pci_vpd_find ( &nvsvpd->vpd, field, &address,
112  &max_len ) ) != 0 ) {
113  DBGC ( pci, PCI_FMT " NVS VPD could not locate field "
114  PCI_VPD_FIELD_FMT ": %s\n", PCI_ARGS ( pci ),
115  PCI_VPD_FIELD_ARGS ( field ), strerror ( rc ) );
116  return rc;
117  }
118 
119  /* Sanity check */
120  if ( len > max_len ) {
121  DBGC ( pci, PCI_FMT " NVS VPD cannot write %#02zx bytes "
122  "beyond field " PCI_VPD_FIELD_FMT " at [%04x,%04zx)\n",
123  PCI_ARGS ( pci ), len, PCI_VPD_FIELD_ARGS ( field ),
124  address, ( address + max_len ) );
125  return -ENXIO;
126  }
127 
128  /* Write field */
129  if ( ( rc = pci_vpd_write ( &nvsvpd->vpd, address, data,
130  len ) ) != 0 ) {
131  DBGC ( pci, PCI_FMT " NVS VPD could not write field "
132  PCI_VPD_FIELD_FMT " at [%04x,%04zx): %s\n",
133  PCI_ARGS ( pci ), PCI_VPD_FIELD_ARGS ( field ),
134  address, ( address + len ), strerror ( rc ) );
135  return rc;
136  }
137 
138  return 0;
139 }
int pci_vpd_find(struct pci_vpd *vpd, unsigned int field, unsigned int *address, size_t *len)
Locate PCI VPD field.
Definition: pcivpd.c:353
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An NVS VPD device.
Definition: nvsvpd.h:20
static void size_t size_t max_len
Definition: entropy.h:153
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct nvs_device nvs
NVS device.
Definition: nvsvpd.h:22
#define PCI_VPD_FIELD_FMT
PCI VPD field debug message format.
Definition: pcivpd.h:70
struct pci_vpd vpd
PCI VPD device.
Definition: nvsvpd.h:24
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
int pci_vpd_write(struct pci_vpd *vpd, unsigned int address, const void *buf, size_t len)
Write PCI VPD.
Definition: pcivpd.c:225
A PCI device.
Definition: pci.h:187
#define PCI_VPD_FIELD_ARGS(field)
PCI VPD field debug message arguments.
Definition: pcivpd.h:73
#define ENXIO
No such device or address.
Definition: errno.h:599
uint32_t len
Length.
Definition: ena.h:14
struct pci_device * pci
PCI device.
Definition: pcivpd.h:132
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:290
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References address, container_of, data, DBGC, ENXIO, len, max_len, nvs_vpd_device::nvs, pci_vpd::pci, PCI_ARGS, PCI_FMT, PCI_VPD_FIELD_ARGS, PCI_VPD_FIELD_FMT, pci_vpd_find(), pci_vpd_write(), rc, strerror(), and nvs_vpd_device::vpd.

Referenced by nvs_vpd_init().

◆ nvs_vpd_resize()

static int nvs_vpd_resize ( struct nvs_device nvs,
unsigned int  field,
size_t  len 
)
static

Resize VPD field.

Parameters
nvsNVS device
fieldVPD field descriptor
dataData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 150 of file nvsvpd.c.

151  {
152  struct nvs_vpd_device *nvsvpd =
153  container_of ( nvs, struct nvs_vpd_device, nvs );
154  struct pci_device *pci = nvsvpd->vpd.pci;
155  unsigned int address;
156  int rc;
157 
158  /* Resize field */
159  if ( ( rc = pci_vpd_resize ( &nvsvpd->vpd, field, len,
160  &address ) ) != 0 ) {
161  DBGC ( pci, PCI_FMT " NVS VPD could not resize field "
162  PCI_VPD_FIELD_FMT " to %#02zx bytes: %s\n",
163  PCI_ARGS ( pci ), PCI_VPD_FIELD_ARGS ( field ),
164  len, strerror ( rc ) );
165  return rc;
166  }
167 
168  return 0;
169 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An NVS VPD device.
Definition: nvsvpd.h:20
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
int pci_vpd_resize(struct pci_vpd *vpd, unsigned int field, size_t len, unsigned int *address)
Resize VPD field.
Definition: pcivpd.c:411
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct nvs_device nvs
NVS device.
Definition: nvsvpd.h:22
#define PCI_VPD_FIELD_FMT
PCI VPD field debug message format.
Definition: pcivpd.h:70
struct pci_vpd vpd
PCI VPD device.
Definition: nvsvpd.h:24
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
A PCI device.
Definition: pci.h:187
#define PCI_VPD_FIELD_ARGS(field)
PCI VPD field debug message arguments.
Definition: pcivpd.h:73
uint32_t len
Length.
Definition: ena.h:14
struct pci_device * pci
PCI device.
Definition: pcivpd.h:132
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:290

References address, container_of, DBGC, len, nvs_vpd_device::nvs, pci_vpd::pci, PCI_ARGS, PCI_FMT, PCI_VPD_FIELD_ARGS, PCI_VPD_FIELD_FMT, pci_vpd_resize(), rc, strerror(), and nvs_vpd_device::vpd.

Referenced by nvs_vpd_nvo_resize().

◆ nvs_vpd_init()

int nvs_vpd_init ( struct nvs_vpd_device nvsvpd,
struct pci_device pci 
)

Initialise NVS VPD device.

Parameters
nvsvpdNVS VPD device
pciPCI device
Return values
rcReturn status code

Definition at line 178 of file nvsvpd.c.

178  {
179  int rc;
180 
181  /* Initialise VPD device */
182  if ( ( rc = pci_vpd_init ( &nvsvpd->vpd, pci ) ) != 0 ) {
183  DBGC ( pci, PCI_FMT " NVS could not initialise "
184  "VPD: %s\n", PCI_ARGS ( pci ), strerror ( rc ) );
185  return rc;
186  }
187 
188  /* Initialise NVS device */
189  nvsvpd->nvs.read = nvs_vpd_read;
190  nvsvpd->nvs.write = nvs_vpd_write;
191 
192  return 0;
193 }
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
#define DBGC(...)
Definition: compiler.h:505
struct nvs_device nvs
NVS device.
Definition: nvsvpd.h:22
struct pci_vpd vpd
PCI VPD device.
Definition: nvsvpd.h:24
int(* read)(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read data from device.
Definition: nvs.h:47
static int nvs_vpd_read(struct nvs_device *nvs, unsigned int field, void *data, size_t len)
Read from VPD field.
Definition: nvsvpd.c:49
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
static int nvs_vpd_write(struct nvs_device *nvs, unsigned int field, const void *data, size_t len)
Write to VPD field.
Definition: nvsvpd.c:101
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:290
int pci_vpd_init(struct pci_vpd *vpd, struct pci_device *pci)
Initialise PCI Vital Product Data.
Definition: pcivpd.c:48

References DBGC, nvs_vpd_device::nvs, nvs_vpd_read(), nvs_vpd_write(), PCI_ARGS, PCI_FMT, pci_vpd_init(), rc, nvs_device::read, strerror(), nvs_vpd_device::vpd, and nvs_device::write.

Referenced by hermon_probe().

◆ nvs_vpd_nvo_resize()

static int nvs_vpd_nvo_resize ( struct nvo_block nvo,
size_t  len 
)
static

Resize non-volatile option storage within NVS VPD device.

Parameters
nvoNon-volatile options block
lenNew length
Return values
rcReturn status code

Definition at line 202 of file nvsvpd.c.

202  {
203  int rc;
204 
205  /* Resize VPD field */
206  if ( ( rc = nvs_vpd_resize ( nvo->nvs, nvo->address, len ) ) != 0 )
207  return rc;
208 
209  return 0;
210 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int nvs_vpd_resize(struct nvs_device *nvs, unsigned int field, size_t len)
Resize VPD field.
Definition: nvsvpd.c:150
struct nvs_device * nvs
Underlying non-volatile storage device.
Definition: nvo.h:26
unsigned int address
Address within NVS device.
Definition: nvo.h:28
uint32_t len
Length.
Definition: ena.h:14

References nvo_block::address, len, nvo_block::nvs, nvs_vpd_resize(), and rc.

Referenced by nvs_vpd_nvo_init().

◆ nvs_vpd_nvo_init()

void nvs_vpd_nvo_init ( struct nvs_vpd_device nvsvpd,
unsigned int  field,
struct nvo_block nvo,
struct refcnt refcnt 
)

Initialise non-volatile option storage within NVS VPD device.

Parameters
nvsvpdNVS VPD device
fieldVPD field descriptor
nvoNon-volatile options block
refcntContaining object reference counter, or NULL

Definition at line 220 of file nvsvpd.c.

221  {
222  struct pci_device *pci = nvsvpd->vpd.pci;
223  unsigned int address;
224  size_t len;
225  int rc;
226 
227  /* Locate VPD field, if present */
228  if ( ( rc = pci_vpd_find ( &nvsvpd->vpd, field, &address,
229  &len ) ) != 0 ) {
230  DBGC ( pci, PCI_FMT " NVS VPD field " PCI_VPD_FIELD_FMT
231  " not present; assuming empty\n",
232  PCI_ARGS ( pci ), PCI_VPD_FIELD_ARGS ( field ) );
233  len = 0;
234  }
235 
236  /* Initialise non-volatile options block */
237  nvo_init ( nvo, &nvsvpd->nvs, field, len, nvs_vpd_nvo_resize, refcnt );
238 }
int pci_vpd_find(struct pci_vpd *vpd, unsigned int field, unsigned int *address, size_t *len)
Locate PCI VPD field.
Definition: pcivpd.c:353
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
A reference counter.
Definition: refcnt.h:26
struct nvs_device nvs
NVS device.
Definition: nvsvpd.h:22
#define PCI_VPD_FIELD_FMT
PCI VPD field debug message format.
Definition: pcivpd.h:70
struct pci_vpd vpd
PCI VPD device.
Definition: nvsvpd.h:24
void nvo_init(struct nvo_block *nvo, struct nvs_device *nvs, size_t address, size_t len, int(*resize)(struct nvo_block *nvo, size_t len), struct refcnt *refcnt)
Initialise non-volatile stored options.
Definition: nvo.c:273
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
A PCI device.
Definition: pci.h:187
#define PCI_VPD_FIELD_ARGS(field)
PCI VPD field debug message arguments.
Definition: pcivpd.h:73
static int nvs_vpd_nvo_resize(struct nvo_block *nvo, size_t len)
Resize non-volatile option storage within NVS VPD device.
Definition: nvsvpd.c:202
uint32_t len
Length.
Definition: ena.h:14
struct pci_device * pci
PCI device.
Definition: pcivpd.h:132
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:290

References address, DBGC, len, nvo_init(), nvs_vpd_device::nvs, nvs_vpd_nvo_resize(), pci_vpd::pci, PCI_ARGS, PCI_FMT, PCI_VPD_FIELD_ARGS, PCI_VPD_FIELD_FMT, pci_vpd_find(), rc, and nvs_vpd_device::vpd.

Referenced by hermon_probe().