iPXE
Data Structures | Macros | Functions
xenbus.h File Reference

Xen device bus. More...

#include <ipxe/device.h>
#include <ipxe/tables.h>
#include <ipxe/xen.h>
#include <xen/io/xenbus.h>

Go to the source code of this file.

Data Structures

struct  xen_device
 A Xen device. More...
 
struct  xen_driver
 A Xen device driver. More...
 

Macros

#define XEN_DRIVERS   __table ( struct xen_driver, "xen_drivers" )
 Xen device driver table. More...
 
#define __xen_driver   __table_entry ( XEN_DRIVERS, 01 )
 Declare a Xen device driver. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void xen_set_drvdata (struct xen_device *xendev, void *priv)
 Set Xen device driver-private data. More...
 
static void * xen_get_drvdata (struct xen_device *xendev)
 Get Xen device driver-private data. More...
 
int xenbus_set_state (struct xen_device *xendev, int state)
 Set device state. More...
 
int xenbus_backend_state (struct xen_device *xendev)
 Get backend state. More...
 
int xenbus_backend_wait (struct xen_device *xendev, int state)
 Wait for backend to reach a given state. More...
 
int xenbus_probe (struct xen_hypervisor *xen, struct device *parent)
 Probe Xen bus. More...
 
void xenbus_remove (struct xen_hypervisor *xen, struct device *parent)
 

Detailed Description

Xen device bus.

Definition in file xenbus.h.

Macro Definition Documentation

◆ XEN_DRIVERS

#define XEN_DRIVERS   __table ( struct xen_driver, "xen_drivers" )

Xen device driver table.

Definition at line 55 of file xenbus.h.

◆ __xen_driver

#define __xen_driver   __table_entry ( XEN_DRIVERS, 01 )

Declare a Xen device driver.

Definition at line 58 of file xenbus.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ xen_set_drvdata()

static void xen_set_drvdata ( struct xen_device xendev,
void *  priv 
)
inlinestatic

Set Xen device driver-private data.

Parameters
xendevXen device
privPrivate data

Definition at line 66 of file xenbus.h.

66  {
67  xendev->priv = priv;
68 }
void * priv
Driver-private data.
Definition: xenbus.h:32
static struct tlan_private * priv
Definition: tlan.c:225

References xen_device::priv, and priv.

Referenced by netfront_probe().

◆ xen_get_drvdata()

static void* xen_get_drvdata ( struct xen_device xendev)
inlinestatic

Get Xen device driver-private data.

Parameters
xendevXen device
Return values
privPrivate data

Definition at line 76 of file xenbus.h.

76  {
77  return xendev->priv;
78 }
void * priv
Driver-private data.
Definition: xenbus.h:32

References xen_device::priv.

Referenced by netfront_remove().

◆ xenbus_set_state()

int xenbus_set_state ( struct xen_device xendev,
int  state 
)

Set device state.

Parameters
xendevXen device
stateNew state
Return values
rcReturn status code

Definition at line 106 of file xenbus.c.

106  {
107  int rc;
108 
109  /* Attempt to set state */
110  if ( ( rc = xenstore_write_num ( xendev->xen, state, xendev->key,
111  "state", NULL ) ) != 0 ) {
112  DBGC ( xendev, "XENBUS %s could not set state=\"%d\": %s\n",
113  xendev->key, state, strerror ( rc ) );
114  return rc;
115  }
116 
117  return 0;
118 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t state
State.
Definition: eth_slow.h:47
#define DBGC(...)
Definition: compiler.h:505
int xenstore_write_num(struct xen_hypervisor *xen, unsigned long num,...)
Write XenStore numeric value.
Definition: xenstore.c:460
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
char * key
XenStore key.
Definition: xenbus.h:24
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct xen_hypervisor * xen
Xen hypervisor.
Definition: xenbus.h:22

References DBGC, xen_device::key, NULL, rc, state, strerror(), xen_device::xen, and xenstore_write_num().

Referenced by netfront_open(), and netfront_reset().

◆ xenbus_backend_state()

int xenbus_backend_state ( struct xen_device xendev)

Get backend state.

Parameters
xendevXen device
Return values
stateBackend state, or negative error

Definition at line 126 of file xenbus.c.

126  {
127  unsigned long state;
128  int rc;
129 
130  /* Attempt to get backend state */
131  if ( ( rc = xenstore_read_num ( xendev->xen, &state, xendev->backend,
132  "state", NULL ) ) != 0 ) {
133  DBGC ( xendev, "XENBUS %s could not read %s/state: %s\n",
134  xendev->key, xendev->backend, strerror ( rc ) );
135  return rc;
136  }
137 
138  return state;
139 }
char * backend
Backend XenStore key.
Definition: xenbus.h:26
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t state
State.
Definition: eth_slow.h:47
#define DBGC(...)
Definition: compiler.h:505
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int xenstore_read_num(struct xen_hypervisor *xen, unsigned long *num,...)
Read XenStore numeric value.
Definition: xenstore.c:390
char * key
XenStore key.
Definition: xenbus.h:24
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct xen_hypervisor * xen
Xen hypervisor.
Definition: xenbus.h:22

References xen_device::backend, DBGC, xen_device::key, NULL, rc, state, strerror(), xen_device::xen, and xenstore_read_num().

Referenced by netfront_reset(), and xenbus_backend_wait().

◆ xenbus_backend_wait()

int xenbus_backend_wait ( struct xen_device xendev,
int  state 
)

Wait for backend to reach a given state.

Parameters
xendevXen device
stateDesired backend state
Return values
rcReturn status code

Definition at line 148 of file xenbus.c.

148  {
149  unsigned long started = currticks();
150  unsigned long elapsed;
151  unsigned int attempts = 0;
152  int current_state;
153  int rc;
154 
155  /* Wait for backend to reach this state */
156  do {
157 
158  /* Get current backend state */
159  current_state = xenbus_backend_state ( xendev );
160  if ( current_state < 0 ) {
161  rc = current_state;
162  return rc;
163  }
164  if ( current_state == state )
165  return 0;
166 
167  /* Allow time for backend to react */
168  cpu_nap();
169 
170  /* XenStore is a very slow interface; any fixed delay
171  * time would be dwarfed by the XenStore access time.
172  * We therefore use wall clock to time out this
173  * operation.
174  */
175  elapsed = ( currticks() - started );
176  attempts++;
177 
178  } while ( elapsed < XENBUS_BACKEND_TIMEOUT );
179 
180  /* Construct status code from current backend state */
181  rc = -ETIMEDOUT_STATE ( current_state );
182  DBGC ( xendev, "XENBUS %s timed out after %d attempts waiting for "
183  "%s/state=\"%d\": %s\n", xendev->key, attempts, xendev->backend,
184  state, strerror ( rc ) );
185 
186  return rc;
187 }
char * backend
Backend XenStore key.
Definition: xenbus.h:26
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t state
State.
Definition: eth_slow.h:47
#define DBGC(...)
Definition: compiler.h:505
static int started
"startup() has been called" flag
Definition: init.c:37
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define ETIMEDOUT_STATE(state)
Definition: xenbus.c:89
void cpu_nap(void)
Sleep with interrupts enabled until next CPU interrupt.
#define XENBUS_BACKEND_TIMEOUT
Maximum time to wait for backend to reach a given state, in ticks.
Definition: xenbus.c:97
char * key
XenStore key.
Definition: xenbus.h:24
unsigned long currticks(void)
Get current system time in ticks.
Definition: timer.c:42
int xenbus_backend_state(struct xen_device *xendev)
Get backend state.
Definition: xenbus.c:126

References xen_device::backend, cpu_nap(), currticks(), DBGC, ETIMEDOUT_STATE, xen_device::key, rc, started, state, strerror(), xenbus_backend_state(), and XENBUS_BACKEND_TIMEOUT.

Referenced by netfront_open(), and netfront_reset().

◆ xenbus_probe()

int xenbus_probe ( struct xen_hypervisor xen,
struct device parent 
)

Probe Xen bus.

Parameters
xenXen hypervisor
parentParent device
Return values
rcReturn status code

Definition at line 354 of file xenbus.c.

354  {
355  char *types;
356  char *type;
357  size_t len;
358  int rc;
359 
360  /* Get children of "device" key */
361  if ( ( rc = xenstore_directory ( xen, &types, &len, "device",
362  NULL ) ) != 0 ) {
363  DBGC ( xen, "XENBUS could not list device types: %s\n",
364  strerror ( rc ) );
365  goto err_directory;
366  }
367 
368  /* Probe each child type */
369  for ( type = types ; type < ( types + len ) ;
370  type += ( strlen ( type ) + 1 /* NUL */ ) ) {
371  if ( ( rc = xenbus_probe_type ( xen, parent, type ) ) != 0 )
372  goto err_probe_type;
373  }
374 
375  free ( types );
376  return 0;
377 
378  xenbus_remove ( xen, parent );
379  err_probe_type:
380  free ( types );
381  err_directory:
382  return rc;
383 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t type
Operating system type.
Definition: ena.h:12
#define DBGC(...)
Definition: compiler.h:505
static int xenbus_probe_type(struct xen_hypervisor *xen, struct device *parent, const char *type)
Probe Xen devices of a given type.
Definition: xenbus.c:304
ring len
Length.
Definition: dwmac.h:231
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
int xenstore_directory(struct xen_hypervisor *xen, char **children, size_t *len,...)
Read XenStore directory.
Definition: xenstore.c:503
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
void xenbus_remove(struct xen_hypervisor *xen __unused, struct device *parent)
Remove Xen bus.
Definition: xenbus.c:391
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References DBGC, free, len, NULL, rc, strerror(), strlen(), type, xenbus_probe_type(), xenbus_remove(), and xenstore_directory().

Referenced by hvm_probe().

◆ xenbus_remove()

void xenbus_remove ( struct xen_hypervisor xen,
struct device parent 
)