lguest_launcher.h 5.0 KB

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