diff options
Diffstat (limited to 'include/linux/lguest_launcher.h')
-rw-r--r-- | include/linux/lguest_launcher.h | 112 |
1 files changed, 22 insertions, 90 deletions
diff --git a/include/linux/lguest_launcher.h b/include/linux/lguest_launcher.h index 641670579446..61e1e3e6b1cc 100644 --- a/include/linux/lguest_launcher.h +++ b/include/linux/lguest_launcher.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _ASM_LGUEST_USER | 1 | #ifndef _ASM_LGUEST_USER |
2 | #define _ASM_LGUEST_USER | 2 | #define _ASM_LGUEST_USER |
3 | /* Everything the "lguest" userspace program needs to know. */ | 3 | /* Everything the "lguest" userspace program needs to know. */ |
4 | #include <linux/types.h> | ||
4 | /* They can register up to 32 arrays of lguest_dma. */ | 5 | /* They can register up to 32 arrays of lguest_dma. */ |
5 | #define LGUEST_MAX_DMA 32 | 6 | #define LGUEST_MAX_DMA 32 |
6 | /* At most we can dma 16 lguest_dma in one op. */ | 7 | /* At most we can dma 16 lguest_dma in one op. */ |
@@ -9,66 +10,6 @@ | |||
9 | /* How many devices? Assume each one wants up to two dma arrays per device. */ | 10 | /* How many devices? Assume each one wants up to two dma arrays per device. */ |
10 | #define LGUEST_MAX_DEVICES (LGUEST_MAX_DMA/2) | 11 | #define LGUEST_MAX_DEVICES (LGUEST_MAX_DMA/2) |
11 | 12 | ||
12 | /*D:200 | ||
13 | * Lguest I/O | ||
14 | * | ||
15 | * The lguest I/O mechanism is the only way Guests can talk to devices. There | ||
16 | * are two hypercalls involved: SEND_DMA for output and BIND_DMA for input. In | ||
17 | * each case, "struct lguest_dma" describes the buffer: this contains 16 | ||
18 | * addr/len pairs, and if there are fewer buffer elements the len array is | ||
19 | * terminated with a 0. | ||
20 | * | ||
21 | * I/O is organized by keys: BIND_DMA attaches buffers to a particular key, and | ||
22 | * SEND_DMA transfers to buffers bound to particular key. By convention, keys | ||
23 | * correspond to a physical address within the device's page. This means that | ||
24 | * devices will never accidentally end up with the same keys, and allows the | ||
25 | * Host use The Futex Trick (as we'll see later in our journey). | ||
26 | * | ||
27 | * SEND_DMA simply indicates a key to send to, and the physical address of the | ||
28 | * "struct lguest_dma" to send. The Host will write the number of bytes | ||
29 | * transferred into the "struct lguest_dma"'s used_len member. | ||
30 | * | ||
31 | * BIND_DMA indicates a key to bind to, a pointer to an array of "struct | ||
32 | * lguest_dma"s ready for receiving, the size of that array, and an interrupt | ||
33 | * to trigger when data is received. The Host will only allow transfers into | ||
34 | * buffers with a used_len of zero: it then sets used_len to the number of | ||
35 | * bytes transferred and triggers the interrupt for the Guest to process the | ||
36 | * new input. */ | ||
37 | struct lguest_dma | ||
38 | { | ||
39 | /* 0 if free to be used, filled by the Host. */ | ||
40 | u32 used_len; | ||
41 | unsigned long addr[LGUEST_MAX_DMA_SECTIONS]; | ||
42 | u16 len[LGUEST_MAX_DMA_SECTIONS]; | ||
43 | }; | ||
44 | /*:*/ | ||
45 | |||
46 | /*D:460 This is the layout of a block device memory page. The Launcher sets up | ||
47 | * the num_sectors initially to tell the Guest the size of the disk. The Guest | ||
48 | * puts the type, sector and length of the request in the first three fields, | ||
49 | * then DMAs to the Host. The Host processes the request, sets up the result, | ||
50 | * then DMAs back to the Guest. */ | ||
51 | struct lguest_block_page | ||
52 | { | ||
53 | /* 0 is a read, 1 is a write. */ | ||
54 | int type; | ||
55 | u32 sector; /* Offset in device = sector * 512. */ | ||
56 | u32 bytes; /* Length expected to be read/written in bytes */ | ||
57 | /* 0 = pending, 1 = done, 2 = done, error */ | ||
58 | int result; | ||
59 | u32 num_sectors; /* Disk length = num_sectors * 512 */ | ||
60 | }; | ||
61 | |||
62 | /*D:520 The network device is basically a memory page where all the Guests on | ||
63 | * the network publish their MAC (ethernet) addresses: it's an array of "struct | ||
64 | * lguest_net": */ | ||
65 | struct lguest_net | ||
66 | { | ||
67 | /* Simply the mac address (with multicast bit meaning promisc). */ | ||
68 | unsigned char mac[6]; | ||
69 | }; | ||
70 | /*:*/ | ||
71 | |||
72 | /* Where the Host expects the Guest to SEND_DMA console output to. */ | 13 | /* Where the Host expects the Guest to SEND_DMA console output to. */ |
73 | #define LGUEST_CONSOLE_DMA_KEY 0 | 14 | #define LGUEST_CONSOLE_DMA_KEY 0 |
74 | 15 | ||
@@ -81,38 +22,29 @@ struct lguest_net | |||
81 | * complex burden for the Host and suboptimal for the Guest, so we have our own | 22 | * complex burden for the Host and suboptimal for the Guest, so we have our own |
82 | * "lguest" bus and simple drivers. | 23 | * "lguest" bus and simple drivers. |
83 | * | 24 | * |
84 | * Devices are described by an array of LGUEST_MAX_DEVICES of these structs, | 25 | * Devices are described by a simplified ID, a status byte, and some "config" |
85 | * placed by the Launcher just above the top of physical memory: | 26 | * bytes which describe this device's configuration. This is placed by the |
27 | * Launcher just above the top of physical memory: | ||
86 | */ | 28 | */ |
87 | struct lguest_device_desc { | 29 | struct lguest_device_desc { |
88 | /* The device type: console, network, disk etc. */ | 30 | /* The device type: console, network, disk etc. Type 0 terminates. */ |
89 | u16 type; | 31 | __u8 type; |
90 | #define LGUEST_DEVICE_T_CONSOLE 1 | 32 | /* The number of bytes of the config array. */ |
91 | #define LGUEST_DEVICE_T_NET 2 | 33 | __u8 config_len; |
92 | #define LGUEST_DEVICE_T_BLOCK 3 | 34 | /* A status byte, written by the Guest. */ |
93 | 35 | __u8 status; | |
94 | /* The specific features of this device: these depends on device type | 36 | __u8 config[0]; |
95 | * except for LGUEST_DEVICE_F_RANDOMNESS. */ | 37 | }; |
96 | u16 features; | ||
97 | #define LGUEST_NET_F_NOCSUM 0x4000 /* Don't bother checksumming */ | ||
98 | #define LGUEST_DEVICE_F_RANDOMNESS 0x8000 /* IRQ is fairly random */ | ||
99 | |||
100 | /* This is how the Guest reports status of the device: the Host can set | ||
101 | * LGUEST_DEVICE_S_REMOVED to indicate removal, but the rest are only | ||
102 | * ever manipulated by the Guest, and only ever set. */ | ||
103 | u16 status; | ||
104 | /* 256 and above are device specific. */ | ||
105 | #define LGUEST_DEVICE_S_ACKNOWLEDGE 1 /* We have seen device. */ | ||
106 | #define LGUEST_DEVICE_S_DRIVER 2 /* We have found a driver */ | ||
107 | #define LGUEST_DEVICE_S_DRIVER_OK 4 /* Driver says OK! */ | ||
108 | #define LGUEST_DEVICE_S_REMOVED 8 /* Device has gone away. */ | ||
109 | #define LGUEST_DEVICE_S_REMOVED_ACK 16 /* Driver has been told. */ | ||
110 | #define LGUEST_DEVICE_S_FAILED 128 /* Something actually failed */ | ||
111 | 38 | ||
112 | /* Each device exists somewhere in Guest physical memory, over some | 39 | /*D:135 This is how we expect the device configuration field for a virtqueue |
113 | * number of pages. */ | 40 | * (type VIRTIO_CONFIG_F_VIRTQUEUE) to be laid out: */ |
114 | u16 num_pages; | 41 | struct lguest_vqconfig { |
115 | u32 pfn; | 42 | /* The number of entries in the virtio_ring */ |
43 | __u16 num; | ||
44 | /* The interrupt we get when something happens. */ | ||
45 | __u16 irq; | ||
46 | /* The page number of the virtio ring for this device. */ | ||
47 | __u32 pfn; | ||
116 | }; | 48 | }; |
117 | /*:*/ | 49 | /*:*/ |
118 | 50 | ||
@@ -120,7 +52,7 @@ struct lguest_device_desc { | |||
120 | enum lguest_req | 52 | enum lguest_req |
121 | { | 53 | { |
122 | LHREQ_INITIALIZE, /* + pfnlimit, pgdir, start, pageoffset */ | 54 | LHREQ_INITIALIZE, /* + pfnlimit, pgdir, start, pageoffset */ |
123 | LHREQ_GETDMA, /* + addr (returns &lguest_dma, irq in ->used_len) */ | 55 | LHREQ_GETDMA, /* No longer used */ |
124 | LHREQ_IRQ, /* + irq */ | 56 | LHREQ_IRQ, /* + irq */ |
125 | LHREQ_BREAK, /* + on/off flag (on blocks until someone does off) */ | 57 | LHREQ_BREAK, /* + on/off flag (on blocks until someone does off) */ |
126 | }; | 58 | }; |