iPXE
Data Structures | Defines | 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...

Defines

#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.

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.
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.


Define Documentation

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

Xen device driver table.

Definition at line 55 of file xenbus.h.

Referenced by xenbus_find_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 ( GPL2_OR_LATER_OR_UBDL  )
static void xen_set_drvdata ( struct xen_device xendev,
void *  priv 
) [inline, static]

Set Xen device driver-private data.

Parameters:
xendevXen device
privPrivate data

Definition at line 66 of file xenbus.h.

References xen_device::priv, and priv.

Referenced by netfront_probe().

                                                                             {
        xendev->priv = priv;
}
static void* xen_get_drvdata ( struct xen_device xendev) [inline, static]

Get Xen device driver-private data.

Parameters:
xendevXen device
Return values:
privPrivate data

Definition at line 76 of file xenbus.h.

References xen_device::priv.

Referenced by netfront_remove().

                                                                   {
        return xendev->priv;
}
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.

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

Referenced by netfront_open(), and netfront_reset().

                                                              {
        int rc;

        /* Attempt to set state */
        if ( ( rc = xenstore_write_num ( xendev->xen, state, xendev->key,
                                         "state", NULL ) ) != 0 ) {
                DBGC ( xendev, "XENBUS %s could not set state=\"%d\": %s\n",
                       xendev->key, state, strerror ( rc ) );
                return rc;
        }

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

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().

                                                       {
        unsigned long state;
        int rc;

        /* Attempt to get backend state */
        if ( ( rc = xenstore_read_num ( xendev->xen, &state, xendev->backend,
                                        "state", NULL ) ) != 0 ) {
                DBGC ( xendev, "XENBUS %s could not read %s/state: %s\n",
                       xendev->key, xendev->backend, strerror ( rc ) );
                return rc;
        }

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

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

Referenced by netfront_open(), and netfront_reset().

                                                                 {
        unsigned long started = currticks();
        unsigned long elapsed;
        unsigned int attempts = 0;
        int current_state;
        int rc;

        /* Wait for backend to reach this state */
        do {

                /* Get current backend state */
                current_state = xenbus_backend_state ( xendev );
                if ( current_state < 0 ) {
                        rc = current_state;
                        return rc;
                }
                if ( current_state == state )
                        return 0;

                /* Allow time for backend to react */
                cpu_nap();

                /* XenStore is a very slow interface; any fixed delay
                 * time would be dwarfed by the XenStore access time.
                 * We therefore use wall clock to time out this
                 * operation.
                 */
                elapsed = ( currticks() - started );
                attempts++;

        } while ( elapsed < XENBUS_BACKEND_TIMEOUT );

        /* Construct status code from current backend state */
        rc = -ETIMEDOUT_STATE ( current_state );
        DBGC ( xendev, "XENBUS %s timed out after %d attempts waiting for "
               "%s/state=\"%d\": %s\n", xendev->key, attempts, xendev->backend,
               state, strerror ( rc ) );

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

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

Referenced by hvm_probe().

                                                                       {
        char *types;
        char *type;
        size_t len;
        int rc;

        /* Get children of "device" key */
        if ( ( rc = xenstore_directory ( xen, &types, &len, "device",
                                         NULL ) ) != 0 ) {
                DBGC ( xen, "XENBUS could not list device types: %s\n",
                       strerror ( rc ) );
                goto err_directory;
        }

        /* Probe each child type */
        for ( type = types ; type < ( types + len ) ;
              type += ( strlen ( type ) + 1 /* NUL */ ) ) {
                if ( ( rc = xenbus_probe_type ( xen, parent, type ) ) != 0 )
                        goto err_probe_type;
        }

        free ( types );
        return 0;

        xenbus_remove ( xen, parent );
 err_probe_type:
        free ( types );
 err_directory:
        return rc;
}
void xenbus_remove ( struct xen_hypervisor xen,
struct device parent 
)