blob: 736e19a510c196acd7851a8bc685af3d3e6b5f90 [file] [log] [blame]
Rusty Russelld7e28ff2007-07-19 01:49:23 -07001#ifndef _ASM_LGUEST_USER
2#define _ASM_LGUEST_USER
3/* Everything the "lguest" userspace program needs to know. */
Rusty Russellb45d8cb2007-10-22 10:56:24 +10004#include <linux/types.h>
Rusty Russelld7e28ff2007-07-19 01:49:23 -07005/* They can register up to 32 arrays of lguest_dma. */
6#define LGUEST_MAX_DMA 32
7/* At most we can dma 16 lguest_dma in one op. */
8#define LGUEST_MAX_DMA_SECTIONS 16
9
10/* How many devices? Assume each one wants up to two dma arrays per device. */
11#define LGUEST_MAX_DEVICES (LGUEST_MAX_DMA/2)
12
Rusty Russelle2c97842007-07-26 10:41:03 -070013/*D:200
14 * Lguest I/O
15 *
16 * The lguest I/O mechanism is the only way Guests can talk to devices. There
17 * are two hypercalls involved: SEND_DMA for output and BIND_DMA for input. In
18 * each case, "struct lguest_dma" describes the buffer: this contains 16
19 * addr/len pairs, and if there are fewer buffer elements the len array is
20 * terminated with a 0.
21 *
22 * I/O is organized by keys: BIND_DMA attaches buffers to a particular key, and
23 * SEND_DMA transfers to buffers bound to particular key. By convention, keys
24 * correspond to a physical address within the device's page. This means that
25 * devices will never accidentally end up with the same keys, and allows the
26 * Host use The Futex Trick (as we'll see later in our journey).
27 *
28 * SEND_DMA simply indicates a key to send to, and the physical address of the
29 * "struct lguest_dma" to send. The Host will write the number of bytes
30 * transferred into the "struct lguest_dma"'s used_len member.
31 *
32 * BIND_DMA indicates a key to bind to, a pointer to an array of "struct
33 * lguest_dma"s ready for receiving, the size of that array, and an interrupt
34 * to trigger when data is received. The Host will only allow transfers into
35 * buffers with a used_len of zero: it then sets used_len to the number of
36 * bytes transferred and triggers the interrupt for the Guest to process the
37 * new input. */
Rusty Russelld7e28ff2007-07-19 01:49:23 -070038struct lguest_dma
39{
Rusty Russelle2c97842007-07-26 10:41:03 -070040 /* 0 if free to be used, filled by the Host. */
Rusty Russellb45d8cb2007-10-22 10:56:24 +100041 __u32 used_len;
42 __u16 len[LGUEST_MAX_DMA_SECTIONS];
Rusty Russelld7e28ff2007-07-19 01:49:23 -070043 unsigned long addr[LGUEST_MAX_DMA_SECTIONS];
Rusty Russelld7e28ff2007-07-19 01:49:23 -070044};
Rusty Russelle2c97842007-07-26 10:41:03 -070045/*:*/
Rusty Russelld7e28ff2007-07-19 01:49:23 -070046
Rusty Russelle2c97842007-07-26 10:41:03 -070047/*D:460 This is the layout of a block device memory page. The Launcher sets up
48 * the num_sectors initially to tell the Guest the size of the disk. The Guest
49 * puts the type, sector and length of the request in the first three fields,
50 * then DMAs to the Host. The Host processes the request, sets up the result,
51 * then DMAs back to the Guest. */
Rusty Russelld7e28ff2007-07-19 01:49:23 -070052struct lguest_block_page
53{
54 /* 0 is a read, 1 is a write. */
55 int type;
Rusty Russellb45d8cb2007-10-22 10:56:24 +100056 __u32 sector; /* Offset in device = sector * 512. */
57 __u32 bytes; /* Length expected to be read/written in bytes */
Rusty Russelld7e28ff2007-07-19 01:49:23 -070058 /* 0 = pending, 1 = done, 2 = done, error */
59 int result;
Rusty Russellb45d8cb2007-10-22 10:56:24 +100060 __u32 num_sectors; /* Disk length = num_sectors * 512 */
Rusty Russelld7e28ff2007-07-19 01:49:23 -070061};
62
Rusty Russelle2c97842007-07-26 10:41:03 -070063/*D:520 The network device is basically a memory page where all the Guests on
64 * the network publish their MAC (ethernet) addresses: it's an array of "struct
65 * lguest_net": */
Rusty Russelld7e28ff2007-07-19 01:49:23 -070066struct lguest_net
67{
68 /* Simply the mac address (with multicast bit meaning promisc). */
69 unsigned char mac[6];
70};
Rusty Russelle2c97842007-07-26 10:41:03 -070071/*:*/
Rusty Russelld7e28ff2007-07-19 01:49:23 -070072
73/* Where the Host expects the Guest to SEND_DMA console output to. */
74#define LGUEST_CONSOLE_DMA_KEY 0
75
Rusty Russelle2c97842007-07-26 10:41:03 -070076/*D:010
77 * Drivers
78 *
79 * The Guest needs devices to do anything useful. Since we don't let it touch
80 * real devices (think of the damage it could do!) we provide virtual devices.
81 * We could emulate a PCI bus with various devices on it, but that is a fairly
82 * complex burden for the Host and suboptimal for the Guest, so we have our own
83 * "lguest" bus and simple drivers.
84 *
85 * Devices are described by an array of LGUEST_MAX_DEVICES of these structs,
86 * placed by the Launcher just above the top of physical memory:
87 */
Rusty Russelld7e28ff2007-07-19 01:49:23 -070088struct lguest_device_desc {
Rusty Russelle2c97842007-07-26 10:41:03 -070089 /* The device type: console, network, disk etc. */
Rusty Russellb45d8cb2007-10-22 10:56:24 +100090 __u16 type;
Rusty Russelld7e28ff2007-07-19 01:49:23 -070091#define LGUEST_DEVICE_T_CONSOLE 1
92#define LGUEST_DEVICE_T_NET 2
93#define LGUEST_DEVICE_T_BLOCK 3
94
Rusty Russelle2c97842007-07-26 10:41:03 -070095 /* The specific features of this device: these depends on device type
96 * except for LGUEST_DEVICE_F_RANDOMNESS. */
Rusty Russellb45d8cb2007-10-22 10:56:24 +100097 __u16 features;
Rusty Russelld7e28ff2007-07-19 01:49:23 -070098#define LGUEST_NET_F_NOCSUM 0x4000 /* Don't bother checksumming */
99#define LGUEST_DEVICE_F_RANDOMNESS 0x8000 /* IRQ is fairly random */
100
Rusty Russelle2c97842007-07-26 10:41:03 -0700101 /* This is how the Guest reports status of the device: the Host can set
102 * LGUEST_DEVICE_S_REMOVED to indicate removal, but the rest are only
103 * ever manipulated by the Guest, and only ever set. */
Rusty Russellb45d8cb2007-10-22 10:56:24 +1000104 __u16 status;
Rusty Russelld7e28ff2007-07-19 01:49:23 -0700105/* 256 and above are device specific. */
106#define LGUEST_DEVICE_S_ACKNOWLEDGE 1 /* We have seen device. */
107#define LGUEST_DEVICE_S_DRIVER 2 /* We have found a driver */
108#define LGUEST_DEVICE_S_DRIVER_OK 4 /* Driver says OK! */
109#define LGUEST_DEVICE_S_REMOVED 8 /* Device has gone away. */
110#define LGUEST_DEVICE_S_REMOVED_ACK 16 /* Driver has been told. */
111#define LGUEST_DEVICE_S_FAILED 128 /* Something actually failed */
112
Rusty Russelle2c97842007-07-26 10:41:03 -0700113 /* Each device exists somewhere in Guest physical memory, over some
114 * number of pages. */
Rusty Russellb45d8cb2007-10-22 10:56:24 +1000115 __u16 num_pages;
116 __u32 pfn;
Rusty Russelld7e28ff2007-07-19 01:49:23 -0700117};
Rusty Russelle2c97842007-07-26 10:41:03 -0700118/*:*/
Rusty Russelld7e28ff2007-07-19 01:49:23 -0700119
120/* Write command first word is a request. */
121enum lguest_req
122{
123 LHREQ_INITIALIZE, /* + pfnlimit, pgdir, start, pageoffset */
124 LHREQ_GETDMA, /* + addr (returns &lguest_dma, irq in ->used_len) */
125 LHREQ_IRQ, /* + irq */
126 LHREQ_BREAK, /* + on/off flag (on blocks until someone does off) */
127};
128#endif /* _ASM_LGUEST_USER */