xen_backend.h 4.2 KB
Newer Older
1 2 3
#ifndef QEMU_HW_XEN_BACKEND_H
#define QEMU_HW_XEN_BACKEND_H 1

P
Paolo Bonzini 已提交
4
#include "hw/xen/xen_common.h"
5
#include "sysemu/sysemu.h"
P
Paolo Bonzini 已提交
6
#include "net/net.h"
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

/* ------------------------------------------------------------- */

#define XEN_BUFSIZE 1024

struct XenDevice;

/* driver uses grant tables  ->  open gntdev device (xendev->gnttabdev) */
#define DEVOPS_FLAG_NEED_GNTDEV   1
/* don't expect frontend doing correct state transitions (aka console quirk) */
#define DEVOPS_FLAG_IGNORE_STATE  2

struct XenDevOps {
    size_t    size;
    uint32_t  flags;
    void      (*alloc)(struct XenDevice *xendev);
    int       (*init)(struct XenDevice *xendev);
24 25
    int       (*initialise)(struct XenDevice *xendev);
    void      (*connected)(struct XenDevice *xendev);
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    void      (*event)(struct XenDevice *xendev);
    void      (*disconnect)(struct XenDevice *xendev);
    int       (*free)(struct XenDevice *xendev);
    void      (*backend_changed)(struct XenDevice *xendev, const char *node);
    void      (*frontend_changed)(struct XenDevice *xendev, const char *node);
};

struct XenDevice {
    const char         *type;
    int                dom;
    int                dev;
    char               name[64];
    int                debug;

    enum xenbus_state  be_state;
    enum xenbus_state  fe_state;
    int                online;
    char               be[XEN_BUFSIZE];
    char               *fe;
    char               *protocol;
    int                remote_port;
    int                local_port;

49
    xenevtchn_handle   *evtchndev;
50
    xengnttab_handle   *gnttabdev;
51 52

    struct XenDevOps   *ops;
B
Blue Swirl 已提交
53
    QTAILQ_ENTRY(XenDevice) next;
54 55 56 57 58
};

/* ------------------------------------------------------------- */

/* variables */
59
extern xc_interface *xen_xc;
60
extern xenforeignmemory_handle *xen_fmem;
61
extern struct xs_handle *xenstore;
62
extern const char *xen_protocol;
63 64 65 66

/* xenstore helper functions */
int xenstore_write_str(const char *base, const char *node, const char *val);
int xenstore_write_int(const char *base, const char *node, int ival);
67
int xenstore_write_int64(const char *base, const char *node, int64_t ival);
68 69 70 71 72
char *xenstore_read_str(const char *base, const char *node);
int xenstore_read_int(const char *base, const char *node, int *ival);

int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val);
int xenstore_write_be_int(struct XenDevice *xendev, const char *node, int ival);
73
int xenstore_write_be_int64(struct XenDevice *xendev, const char *node, int64_t ival);
74 75 76 77
char *xenstore_read_be_str(struct XenDevice *xendev, const char *node);
int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival);
char *xenstore_read_fe_str(struct XenDevice *xendev, const char *node);
int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival);
78 79
int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval);
int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, uint64_t *uval);
80 81 82 83 84 85 86 87 88 89 90 91 92

const char *xenbus_strstate(enum xenbus_state state);
struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev);
void xen_be_check_state(struct XenDevice *xendev);

/* xen backend driver bits */
int xen_be_init(void);
int xen_be_register(const char *type, struct XenDevOps *ops);
int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state);
int xen_be_bind_evtchn(struct XenDevice *xendev);
void xen_be_unbind_evtchn(struct XenDevice *xendev);
int xen_be_send_notify(struct XenDevice *xendev);
void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...)
93
    GCC_FMT_ATTR(3, 4);
94

95 96
/* actual backend drivers */
extern struct XenDevOps xen_console_ops;      /* xen_console.c     */
97 98
extern struct XenDevOps xen_kbdmouse_ops;     /* xen_framebuffer.c */
extern struct XenDevOps xen_framebuffer_ops;  /* xen_framebuffer.c */
99
extern struct XenDevOps xen_blkdev_ops;       /* xen_disk.c        */
100
extern struct XenDevOps xen_netdev_ops;       /* xen_nic.c         */
101 102

void xen_init_display(int domid);
103

104
/* configuration (aka xenbus setup) */
105
void xen_config_cleanup(void);
106 107
int xen_config_dev_blk(DriveInfo *disk);
int xen_config_dev_nic(NICInfo *nic);
108 109 110
int xen_config_dev_vfb(int vdev, const char *type);
int xen_config_dev_vkbd(int vdev);
int xen_config_dev_console(int vdev);
111

112
#endif /* QEMU_HW_XEN_BACKEND_H */