17334492b53706964eb055ed8e25e2e3315d7222aRusty Russell#ifndef _LINUX_LGUEST_LAUNCHER 27334492b53706964eb055ed8e25e2e3315d7222aRusty Russell#define _LINUX_LGUEST_LAUNCHER 3d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell/* Everything the "lguest" userspace program needs to know. */ 4b45d8cb054d7677d75176ae22a584fd84e4650e9Rusty Russell#include <linux/types.h> 5d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell 6e2c9784325490c878b7f69aeec1bed98b288bd97Rusty Russell/*D:010 7e2c9784325490c878b7f69aeec1bed98b288bd97Rusty Russell * Drivers 8e2c9784325490c878b7f69aeec1bed98b288bd97Rusty Russell * 9e2c9784325490c878b7f69aeec1bed98b288bd97Rusty Russell * The Guest needs devices to do anything useful. Since we don't let it touch 10e2c9784325490c878b7f69aeec1bed98b288bd97Rusty Russell * real devices (think of the damage it could do!) we provide virtual devices. 11e2c9784325490c878b7f69aeec1bed98b288bd97Rusty Russell * We could emulate a PCI bus with various devices on it, but that is a fairly 12e2c9784325490c878b7f69aeec1bed98b288bd97Rusty Russell * complex burden for the Host and suboptimal for the Guest, so we have our own 13e1e72965ec2c02db99b415cd06c17ea90767e3a4Rusty Russell * simple lguest bus and we use "virtio" drivers. These drivers need a set of 14e1e72965ec2c02db99b415cd06c17ea90767e3a4Rusty Russell * routines from us which will actually do the virtual I/O, but they handle all 15e1e72965ec2c02db99b415cd06c17ea90767e3a4Rusty Russell * the net/block/console stuff themselves. This means that if we want to add 16e1e72965ec2c02db99b415cd06c17ea90767e3a4Rusty Russell * a new device, we simply need to write a new virtio driver and create support 17e1e72965ec2c02db99b415cd06c17ea90767e3a4Rusty Russell * for it in the Launcher: this code won't need to change. 18e2c9784325490c878b7f69aeec1bed98b288bd97Rusty Russell * 19a6bd8e13034dd7d60b6f14217096efa192d0adc1Rusty Russell * Virtio devices are also used by kvm, so we can simply reuse their optimized 20a6bd8e13034dd7d60b6f14217096efa192d0adc1Rusty Russell * device drivers. And one day when everyone uses virtio, my plan will be 21a6bd8e13034dd7d60b6f14217096efa192d0adc1Rusty Russell * complete. Bwahahahah! 22a6bd8e13034dd7d60b6f14217096efa192d0adc1Rusty Russell * 2319f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell * Devices are described by a simplified ID, a status byte, and some "config" 2419f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell * bytes which describe this device's configuration. This is placed by the 2519f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell * Launcher just above the top of physical memory: 26e2c9784325490c878b7f69aeec1bed98b288bd97Rusty Russell */ 27d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellstruct lguest_device_desc { 2819f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell /* The device type: console, network, disk etc. Type 0 terminates. */ 2919f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell __u8 type; 30a586d4f6016f7139d8c26df0e6927131168d3b5bRusty Russell /* The number of virtqueues (first in config array) */ 31a586d4f6016f7139d8c26df0e6927131168d3b5bRusty Russell __u8 num_vq; 322e04ef76916d1e29a077ea9d0f2003c8fd86724dRusty Russell /* 332e04ef76916d1e29a077ea9d0f2003c8fd86724dRusty Russell * The number of bytes of feature bits. Multiply by 2: one for host 342e04ef76916d1e29a077ea9d0f2003c8fd86724dRusty Russell * features and one for Guest acknowledgements. 352e04ef76916d1e29a077ea9d0f2003c8fd86724dRusty Russell */ 36a586d4f6016f7139d8c26df0e6927131168d3b5bRusty Russell __u8 feature_len; 37a586d4f6016f7139d8c26df0e6927131168d3b5bRusty Russell /* The number of bytes of the config array after virtqueues. */ 3819f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell __u8 config_len; 3919f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell /* A status byte, written by the Guest. */ 4019f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell __u8 status; 4119f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell __u8 config[0]; 4219f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell}; 43d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell 442e04ef76916d1e29a077ea9d0f2003c8fd86724dRusty Russell/*D:135 452e04ef76916d1e29a077ea9d0f2003c8fd86724dRusty Russell * This is how we expect the device configuration field for a virtqueue 462e04ef76916d1e29a077ea9d0f2003c8fd86724dRusty Russell * to be laid out in config space. 472e04ef76916d1e29a077ea9d0f2003c8fd86724dRusty Russell */ 4819f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russellstruct lguest_vqconfig { 4919f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell /* The number of entries in the virtio_ring */ 5019f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell __u16 num; 5119f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell /* The interrupt we get when something happens. */ 5219f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell __u16 irq; 5319f1537b7b8a9a82665db3ad8210a9d954d13acdRusty Russell /* The page number of the virtio ring for this device. */ 54b45d8cb054d7677d75176ae22a584fd84e4650e9Rusty Russell __u32 pfn; 55d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell}; 56e2c9784325490c878b7f69aeec1bed98b288bd97Rusty Russell/*:*/ 57d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell 58d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell/* Write command first word is a request. */ 59d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellenum lguest_req 60d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell{ 6158a24566449892dda409b9ad92c2e56c76c5670cMatias Zabaljauregui LHREQ_INITIALIZE, /* + base, pfnlimit, start */ 6215045275c32bf6d15d32c2eca8157be9c0ba6e45Rusty Russell LHREQ_GETDMA, /* No longer used */ 63d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell LHREQ_IRQ, /* + irq */ 645dac051bc6030963181b69faddd9e0ad04f85fa8Rusty Russell LHREQ_BREAK, /* No longer used */ 65df60aeef4f4fe0645d9a195a7689005520422de5Rusty Russell LHREQ_EVENTFD, /* + address, fd. */ 66d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell}; 672966af73e70dee461c256b5eb877b2ff757f8c82Rusty Russell 682e04ef76916d1e29a077ea9d0f2003c8fd86724dRusty Russell/* 692e04ef76916d1e29a077ea9d0f2003c8fd86724dRusty Russell * The alignment to use between consumer and producer parts of vring. 702e04ef76916d1e29a077ea9d0f2003c8fd86724dRusty Russell * x86 pagesize for historical reasons. 712e04ef76916d1e29a077ea9d0f2003c8fd86724dRusty Russell */ 722966af73e70dee461c256b5eb877b2ff757f8c82Rusty Russell#define LGUEST_VRING_ALIGN 4096 737334492b53706964eb055ed8e25e2e3315d7222aRusty Russell#endif /* _LINUX_LGUEST_LAUNCHER */ 74