1 /* 2 * Copyright (c) 2014 Travis Geiselbrecht 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files 6 * (the "Software"), to deal in the Software without restriction, 7 * including without limitation the rights to use, copy, modify, merge, 8 * publish, distribute, sublicense, and/or sell copies of the Software, 9 * and to permit persons to whom the Software is furnished to do so, 10 * subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 #pragma once 24 25 #include <compiler.h> 26 #include <stdint.h> 27 28 struct virtio_mmio_config { 29 /* 0x00 */ uint32_t magic; 30 uint32_t version; 31 uint32_t device_id; 32 uint32_t vendor_id; 33 /* 0x10 */ uint32_t host_features; 34 uint32_t host_features_sel; 35 uint32_t __reserved0[2]; 36 /* 0x20 */ uint32_t guest_features; 37 uint32_t guest_features_sel; 38 uint32_t guest_page_size; 39 uint32_t __reserved1[1]; 40 /* 0x30 */ uint32_t queue_sel; 41 uint32_t queue_num_max; 42 uint32_t queue_num; 43 uint32_t queue_align; 44 /* 0x40 */ uint32_t queue_pfn; 45 uint32_t __reserved2[3]; 46 /* 0x50 */ uint32_t queue_notify; 47 uint32_t __reserved3[3]; 48 /* 0x60 */ uint32_t interrupt_status; 49 uint32_t interrupt_ack; 50 uint32_t __reserved4[2]; 51 /* 0x70 */ uint32_t status; 52 uint8_t __reserved5[0x8c]; 53 /* 0x100 */ uint32_t config[0]; 54 }; 55 56 STATIC_ASSERT(sizeof(struct virtio_mmio_config) == 0x100); 57 58 #define VIRTIO_MMIO_MAGIC 0x74726976 // 'virt' 59 60 #define VIRTIO_STATUS_ACKNOWLEDGE (1<<0) 61 #define VIRTIO_STATUS_DRIVER (1<<1) 62 #define VIRTIO_STATUS_DRIVER_OK (1<<2) 63 #define VIRTIO_STATUS_FEATURES_OK (1<<3) 64 #define VIRTIO_STATUS_DEVICE_NEEDS_RESET (1<<6) 65 #define VIRTIO_STATUS_FAILED (1<<7) 66