1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without 7 * restriction, including without limitation the rights to use, copy, 8 * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, 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 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 25 #pragma once 26 #include <sys/types.h> 27 28 /** 29 * struct virtio_mmio_config - VirtIO MMIO Register Layout 30 * @magic: Contains VIRTIO_MMIO_MAGIC, or this is invalid 31 * @version: MMIO Spec Version 32 * @device_id: Type of device. See VIRTIO_DEVICE_ID_* 33 * @vendor_id: Identifies the implementor of the device 34 * @host_features: 32-bits of which features the host supports. 35 * @host_features_sel: Selects which half of the feature vector @host_features 36 * exposes - 0 for low, 1 for high. 37 * @guest_features: 32-bits of which features the guest wants. 38 * @guest_features_sel: Selects which half of the feature vector 39 * @guest_features is writing to. 40 * @queue_sel: Which device queue the guest is configuring 41 * @queue_num_max: The maximum VirtIO queue size supported by the for the 42 * selected queue. 43 * @queue_num: The VirtIO queue size used by the guest for the 44 * selected queue. 45 * @queue_align: Specify the alignment of the queues. Using a value 46 * other than PAGE_SIZE may not be supported. 47 * Must be a power of 2. 48 * @queue_pfn: Page frame number of the virtq_raw struct to be used. 49 * @queue_ready: (Non-Legacy) Writing 1 to this enables the current 50 * queue. Should be poked after using @queue_desc_low and 51 * friends to define the queue. 52 * @queue_notify: Write a queue index here to tell the device to check it 53 * @interrupt_status: Why the most recent interrupt was fired. 54 * * Bit 0 - Used ring updated (device processed a buffer) 55 * * Bit 1 - Config updated 56 * @interrupt_ack: Tell the device an interrupt was handled. Format is the 57 * the same as @interrupt_status 58 * @status: Used to negotiate startup. See VIRTIO_STATUS_*. 59 * Write 0 to reset. 60 * @queue_desc_low: (Non-Legacy) Low 32-bits of descriptor table physaddr. 61 * @queue_desc_high: (Non-Legacy) High 32-bits of descriptor table physaddr. 62 * @queue_avail_low: (Non-Legacy) Low 32-bits of available ring physaddr. 63 * @queue_avail_high: (Non-Legacy) High 32-bits of available ring physaddr. 64 * @queue_used_low: (Non-Legacy) Low 32-bits of used ring physaddr. 65 * @queue_used_high: (Non-Legacy) High 32-bits of used ring physaddr. 66 * @config: Device specific configuration information. 67 */ 68 struct virtio_mmio_config { 69 /* 0x00 */ 70 uint32_t magic; 71 uint32_t version; 72 uint32_t device_id; 73 uint32_t vendor_id; 74 /* 0x10 */ 75 uint32_t host_features; 76 uint32_t host_features_sel; 77 uint32_t __reserved0[2]; 78 /* 0x20 */ 79 uint32_t guest_features; 80 uint32_t guest_features_sel; 81 uint32_t guest_page_size; 82 uint32_t __reserved1[1]; 83 /* 0x30 */ 84 uint32_t queue_sel; 85 uint32_t queue_num_max; 86 uint32_t queue_num; 87 uint32_t queue_align; 88 /* 0x40 */ 89 uint32_t queue_pfn; 90 uint32_t queue_ready; 91 uint32_t __reserved2[2]; 92 /* 0x50 */ 93 uint32_t queue_notify; 94 uint32_t __reserved3[3]; 95 /* 0x60 */ 96 uint32_t interrupt_status; 97 uint32_t interrupt_ack; 98 uint32_t __reserved4[2]; 99 /* 0x70 */ 100 uint32_t status; 101 uint32_t __reserved5[3]; 102 /* 0x80 */ 103 uint32_t queue_desc_low; 104 uint32_t queue_desc_high; 105 uint32_t __reserved6[2]; 106 /* 0x90 */ 107 uint32_t queue_avail_low; 108 uint32_t queue_avail_high; 109 uint32_t __reserved7[2]; 110 /* 0xa0 */ 111 uint32_t queue_used_low; 112 uint32_t queue_used_high; 113 uint8_t __reserved8[0x58]; 114 /* 0x100 */ 115 uint8_t config[0x100]; 116 }; 117 118 /* Magic value to identify a real VirtIO MMIO region */ 119 #define VIRTIO_MMIO_MAGIC (0x74726976) 120