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:224

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 105 of file xenbus.c.

105  {
106  int rc;
107 
108  /* Attempt to set state */
109  if ( ( rc = xenstore_write_num ( xendev->xen, state, xendev->key,
110  "state", NULL ) ) != 0 ) {
111  DBGC ( xendev, "XENBUS %s could not set state=\"%d\": %s\n",
112  xendev->key, state, strerror ( rc ) );
113  return rc;
114  }
115 
116  return 0;
117 }
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 125 of file xenbus.c.

125  {
126  unsigned long state;
127  int rc;
128 
129  /* Attempt to get backend state */
130  if ( ( rc = xenstore_read_num ( xendev->xen, &state, xendev->backend,
131  "state", NULL ) ) != 0 ) {
132  DBGC ( xendev, "XENBUS %s could not read %s/state: %s\n",
133  xendev->key, xendev->backend, strerror ( rc ) );
134  return rc;
135  }
136 
137  return state;
138 }
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 147 of file xenbus.c.

147  {
148  unsigned long started = currticks();
149  unsigned long elapsed;
150  unsigned int attempts = 0;
151  int current_state;
152  int rc;
153 
154  /* Wait for backend to reach this state */
155  do {
156 
157  /* Get current backend state */
158  current_state = xenbus_backend_state ( xendev );
159  if ( current_state < 0 ) {
160  rc = current_state;
161  return rc;
162  }
163  if ( current_state == state )
164  return 0;
165 
166  /* Allow time for backend to react */
167  cpu_nap();
168 
169  /* XenStore is a very slow interface; any fixed delay
170  * time would be dwarfed by the XenStore access time.
171  * We therefore use wall clock to time out this
172  * operation.
173  */
174  elapsed = ( currticks() - started );
175  attempts++;
176 
177  } while ( elapsed < XENBUS_BACKEND_TIMEOUT );
178 
179  /* Construct status code from current backend state */
180  rc = -ETIMEDOUT_STATE ( current_state );
181  DBGC ( xendev, "XENBUS %s timed out after %d attempts waiting for "
182  "%s/state=\"%d\": %s\n", xendev->key, attempts, xendev->backend,
183  state, strerror ( rc ) );
184 
185  return rc;
186 }
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:88
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:96
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:125

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 353 of file xenbus.c.

353  {
354  char *types;
355  char *type;
356  size_t len;
357  int rc;
358 
359  /* Get children of "device" key */
360  if ( ( rc = xenstore_directory ( xen, &types, &len, "device",
361  NULL ) ) != 0 ) {
362  DBGC ( xen, "XENBUS could not list device types: %s\n",
363  strerror ( rc ) );
364  goto err_directory;
365  }
366 
367  /* Probe each child type */
368  for ( type = types ; type < ( types + len ) ;
369  type += ( strlen ( type ) + 1 /* NUL */ ) ) {
370  if ( ( rc = xenbus_probe_type ( xen, parent, type ) ) != 0 )
371  goto err_probe_type;
372  }
373 
374  free ( types );
375  return 0;
376 
377  xenbus_remove ( xen, parent );
378  err_probe_type:
379  free ( types );
380  err_directory:
381  return rc;
382 }
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:303
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:390
uint32_t len
Length.
Definition: ena.h:14
#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 
)