aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2007-07-26 13:41:03 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-26 14:35:17 -0400
commite2c9784325490c878b7f69aeec1bed98b288bd97 (patch)
treed474007607c713a30db818107ca0581269f059a2 /include/linux
parentb2b47c214f4e85ce3968120d42e8b18eccb4f4e3 (diff)
lguest: documentation III: Drivers
Documentation: The Drivers Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/lguest_bus.h5
-rw-r--r--include/linux/lguest_launcher.h60
2 files changed, 61 insertions, 4 deletions
diff --git a/include/linux/lguest_bus.h b/include/linux/lguest_bus.h
index c9b4e05fee49..d27853ddc644 100644
--- a/include/linux/lguest_bus.h
+++ b/include/linux/lguest_bus.h
@@ -15,11 +15,14 @@ struct lguest_device {
15 void *private; 15 void *private;
16}; 16};
17 17
18/* By convention, each device can use irq index+1 if it wants to. */ 18/*D:380 Since interrupt numbers are arbitrary, we use a convention: each device
19 * can use the interrupt number corresponding to its index. The +1 is because
20 * interrupt 0 is not usable (it's actually the timer interrupt). */
19static inline int lgdev_irq(const struct lguest_device *dev) 21static inline int lgdev_irq(const struct lguest_device *dev)
20{ 22{
21 return dev->index + 1; 23 return dev->index + 1;
22} 24}
25/*:*/
23 26
24/* dma args must not be vmalloced! */ 27/* dma args must not be vmalloced! */
25void lguest_send_dma(unsigned long key, struct lguest_dma *dma); 28void lguest_send_dma(unsigned long key, struct lguest_dma *dma);
diff --git a/include/linux/lguest_launcher.h b/include/linux/lguest_launcher.h
index 0ba414a40c80..641670579446 100644
--- a/include/linux/lguest_launcher.h
+++ b/include/linux/lguest_launcher.h
@@ -9,14 +9,45 @@
9/* How many devices? Assume each one wants up to two dma arrays per device. */ 9/* How many devices? Assume each one wants up to two dma arrays per device. */
10#define LGUEST_MAX_DEVICES (LGUEST_MAX_DMA/2) 10#define LGUEST_MAX_DEVICES (LGUEST_MAX_DMA/2)
11 11
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. */
12struct lguest_dma 37struct lguest_dma
13{ 38{
14 /* 0 if free to be used, filled by hypervisor. */ 39 /* 0 if free to be used, filled by the Host. */
15 u32 used_len; 40 u32 used_len;
16 unsigned long addr[LGUEST_MAX_DMA_SECTIONS]; 41 unsigned long addr[LGUEST_MAX_DMA_SECTIONS];
17 u16 len[LGUEST_MAX_DMA_SECTIONS]; 42 u16 len[LGUEST_MAX_DMA_SECTIONS];
18}; 43};
44/*:*/
19 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. */
20struct lguest_block_page 51struct lguest_block_page
21{ 52{
22 /* 0 is a read, 1 is a write. */ 53 /* 0 is a read, 1 is a write. */
@@ -28,27 +59,47 @@ struct lguest_block_page
28 u32 num_sectors; /* Disk length = num_sectors * 512 */ 59 u32 num_sectors; /* Disk length = num_sectors * 512 */
29}; 60};
30 61
31/* There is a shared page of these. */ 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": */
32struct lguest_net 65struct lguest_net
33{ 66{
34 /* Simply the mac address (with multicast bit meaning promisc). */ 67 /* Simply the mac address (with multicast bit meaning promisc). */
35 unsigned char mac[6]; 68 unsigned char mac[6];
36}; 69};
70/*:*/
37 71
38/* Where the Host expects the Guest to SEND_DMA console output to. */ 72/* Where the Host expects the Guest to SEND_DMA console output to. */
39#define LGUEST_CONSOLE_DMA_KEY 0 73#define LGUEST_CONSOLE_DMA_KEY 0
40 74
41/* We have a page of these descriptors in the lguest_device page. */ 75/*D:010
76 * Drivers
77 *
78 * The Guest needs devices to do anything useful. Since we don't let it touch
79 * real devices (think of the damage it could do!) we provide virtual devices.
80 * We could emulate a PCI bus with various devices on it, but that is a fairly
81 * complex burden for the Host and suboptimal for the Guest, so we have our own
82 * "lguest" bus and simple drivers.
83 *
84 * Devices are described by an array of LGUEST_MAX_DEVICES of these structs,
85 * placed by the Launcher just above the top of physical memory:
86 */
42struct lguest_device_desc { 87struct lguest_device_desc {
88 /* The device type: console, network, disk etc. */
43 u16 type; 89 u16 type;
44#define LGUEST_DEVICE_T_CONSOLE 1 90#define LGUEST_DEVICE_T_CONSOLE 1
45#define LGUEST_DEVICE_T_NET 2 91#define LGUEST_DEVICE_T_NET 2
46#define LGUEST_DEVICE_T_BLOCK 3 92#define LGUEST_DEVICE_T_BLOCK 3
47 93
94 /* The specific features of this device: these depends on device type
95 * except for LGUEST_DEVICE_F_RANDOMNESS. */
48 u16 features; 96 u16 features;
49#define LGUEST_NET_F_NOCSUM 0x4000 /* Don't bother checksumming */ 97#define LGUEST_NET_F_NOCSUM 0x4000 /* Don't bother checksumming */
50#define LGUEST_DEVICE_F_RANDOMNESS 0x8000 /* IRQ is fairly random */ 98#define LGUEST_DEVICE_F_RANDOMNESS 0x8000 /* IRQ is fairly random */
51 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. */
52 u16 status; 103 u16 status;
53/* 256 and above are device specific. */ 104/* 256 and above are device specific. */
54#define LGUEST_DEVICE_S_ACKNOWLEDGE 1 /* We have seen device. */ 105#define LGUEST_DEVICE_S_ACKNOWLEDGE 1 /* We have seen device. */
@@ -58,9 +109,12 @@ struct lguest_device_desc {
58#define LGUEST_DEVICE_S_REMOVED_ACK 16 /* Driver has been told. */ 109#define LGUEST_DEVICE_S_REMOVED_ACK 16 /* Driver has been told. */
59#define LGUEST_DEVICE_S_FAILED 128 /* Something actually failed */ 110#define LGUEST_DEVICE_S_FAILED 128 /* Something actually failed */
60 111
112 /* Each device exists somewhere in Guest physical memory, over some
113 * number of pages. */
61 u16 num_pages; 114 u16 num_pages;
62 u32 pfn; 115 u32 pfn;
63}; 116};
117/*:*/
64 118
65/* Write command first word is a request. */ 119/* Write command first word is a request. */
66enum lguest_req 120enum lguest_req