iPXE
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.
#define __xen_driver   __table_entry ( XEN_DRIVERS, 01 )
 Declare a Xen device driver.
#define XEN_ROM(_name, _desc)
 Define build rules for a Xen device driver.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static void xen_set_drvdata (struct xen_device *xendev, void *priv)
 Set Xen device driver-private data.
static void * xen_get_drvdata (struct xen_device *xendev)
 Get Xen device driver-private data.
int xenbus_set_state (struct xen_device *xendev, int state)
 Set device state.
int xenbus_backend_state (struct xen_device *xendev)
 Get backend state.
int xenbus_backend_wait (struct xen_device *xendev, int state)
 Wait for backend to reach a given state.
int xenbus_probe (struct xen_hypervisor *xen, struct device *parent)
 Probe Xen bus.
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 56 of file xenbus.h.

Referenced by xenbus_find_driver().

◆ __xen_driver

#define __xen_driver   __table_entry ( XEN_DRIVERS, 01 )

Declare a Xen device driver.

Definition at line 59 of file xenbus.h.

◆ XEN_ROM

#define XEN_ROM ( _name,
_desc )

Define build rules for a Xen device driver.

Definition at line 62 of file xenbus.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ xen_set_drvdata()

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 70 of file xenbus.h.

70 {
71 xendev->priv = priv;
72}
void * priv
Driver-private data.
Definition xenbus.h:33
static struct tlan_private * priv
Definition tlan.c:225

References priv, and xen_device::priv.

Referenced by netfront_probe().

◆ xen_get_drvdata()

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 80 of file xenbus.h.

80 {
81 return xendev->priv;
82}

References xen_device::priv.

Referenced by netfront_remove().

◆ xenbus_set_state()

int xenbus_set_state ( struct xen_device * xendev,
int state )
extern

Set device state.

Parameters
xendevXen device
stateNew state
Return values
rcReturn status code

Definition at line 107 of file xenbus.c.

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

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

Referenced by netfront_open(), netfront_reset(), and REQUIRING_SYMBOL().

◆ xenbus_backend_state()

int xenbus_backend_state ( struct xen_device * xendev)
extern

Get backend state.

Parameters
xendevXen device
Return values
stateBackend state, or negative error

Definition at line 127 of file xenbus.c.

127 {
128 unsigned long state;
129 int rc;
130
131 /* Attempt to get backend state */
132 if ( ( rc = xenstore_read_num ( xendev->xen, &state, xendev->backend,
133 "state", NULL ) ) != 0 ) {
134 DBGC ( xendev, "XENBUS %s could not read %s/state: %s\n",
135 xendev->key, xendev->backend, strerror ( rc ) );
136 return rc;
137 }
138
139 return state;
140}
char * backend
Backend XenStore key.
Definition xenbus.h:27
int xenstore_read_num(struct xen_hypervisor *xen, unsigned long *num,...)
Read XenStore numeric value.
Definition xenstore.c:391

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 )
extern

Wait for backend to reach a given state.

Parameters
xendevXen device
stateDesired backend state
Return values
rcReturn status code

Definition at line 149 of file xenbus.c.

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

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 )
extern

Probe Xen bus.

Parameters
xenXen hypervisor
parentParent device
Return values
rcReturn status code

Definition at line 355 of file xenbus.c.

355 {
356 char *types;
357 char *type;
358 size_t len;
359 int rc;
360
361 /* Get children of "device" key */
362 if ( ( rc = xenstore_directory ( xen, &types, &len, "device",
363 NULL ) ) != 0 ) {
364 DBGC ( xen, "XENBUS could not list device types: %s\n",
365 strerror ( rc ) );
366 goto err_directory;
367 }
368
369 /* Probe each child type */
370 for ( type = types ; type < ( types + len ) ;
371 type += ( strlen ( type ) + 1 /* NUL */ ) ) {
372 if ( ( rc = xenbus_probe_type ( xen, parent, type ) ) != 0 )
373 goto err_probe_type;
374 }
375
376 free ( types );
377 return 0;
378
379 xenbus_remove ( xen, parent );
380 err_probe_type:
381 free ( types );
382 err_directory:
383 return rc;
384}
ring len
Length.
Definition dwmac.h:226
uint32_t type
Operating system type.
Definition ena.h:1
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
size_t strlen(const char *src)
Get length of string.
Definition string.c:244
void xenbus_remove(struct xen_hypervisor *xen __unused, struct device *parent)
Remove Xen bus.
Definition xenbus.c:392
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:305
int xenstore_directory(struct xen_hypervisor *xen, char **children, size_t *len,...)
Read XenStore directory.
Definition xenstore.c:504

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 )
extern