1 /* 2 * Unit tests for the generic vPCI handler code. 3 * 4 * Copyright (C) 2017 Citrix Systems R&D 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms and conditions of the GNU General Public 8 * License, version 2, as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public 16 * License along with this program; If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef _TEST_VPCI_ 20 #define _TEST_VPCI_ 21 22 #include <assert.h> 23 #include <errno.h> 24 #include <stdbool.h> 25 #include <stddef.h> 26 #include <stdint.h> 27 #include <stdio.h> 28 #include <stdlib.h> 29 30 #define container_of(ptr, type, member) ({ \ 31 typeof(((type *)0)->member) *mptr = (ptr); \ 32 \ 33 (type *)((char *)mptr - offsetof(type, member)); \ 34 }) 35 36 #define smp_wmb() 37 #define prefetch(x) __builtin_prefetch(x) 38 #define ASSERT(x) assert(x) 39 #define __must_check __attribute__((__warn_unused_result__)) 40 41 #include "list.h" 42 43 struct domain { 44 }; 45 46 struct pci_dev { 47 struct vpci *vpci; 48 }; 49 50 struct vcpu 51 { 52 const struct domain *domain; 53 }; 54 55 extern const struct vcpu *current; 56 extern const struct pci_dev test_pdev; 57 58 typedef bool spinlock_t; 59 #define spin_lock_init(l) (*(l) = false) 60 #define spin_lock(l) (*(l) = true) 61 #define spin_unlock(l) (*(l) = false) 62 63 typedef union { 64 uint32_t sbdf; 65 struct { 66 union { 67 uint16_t bdf; 68 struct { 69 union { 70 struct { 71 uint8_t func : 3, 72 dev : 5; 73 }; 74 uint8_t extfunc; 75 }; 76 uint8_t bus; 77 }; 78 }; 79 uint16_t seg; 80 }; 81 } pci_sbdf_t; 82 83 #define CONFIG_HAS_VPCI 84 #include "vpci.h" 85 86 #define __hwdom_init 87 88 #define has_vpci(d) true 89 90 #define xzalloc(type) ((type *)calloc(1, sizeof(type))) 91 #define xmalloc(type) ((type *)malloc(sizeof(type))) 92 #define xfree(p) free(p) 93 94 #define pci_get_pdev_by_domain(...) &test_pdev 95 #define pci_get_ro_map(...) NULL 96 97 #define test_bit(...) false 98 99 /* Dummy native helpers. Writes are ignored, reads return 1's. */ 100 #define pci_conf_read8(...) 0xff 101 #define pci_conf_read16(...) 0xffff 102 #define pci_conf_read32(...) 0xffffffff 103 #define pci_conf_write8(...) 104 #define pci_conf_write16(...) 105 #define pci_conf_write32(...) 106 107 #define PCI_CFG_SPACE_EXP_SIZE 4096 108 109 #define BUG() assert(0) 110 #define ASSERT_UNREACHABLE() assert(0) 111 112 #define min(x, y) ({ \ 113 const typeof(x) tx = (x); \ 114 const typeof(y) ty = (y); \ 115 \ 116 (void) (&tx == &ty); \ 117 tx < ty ? tx : ty; \ 118 }) 119 120 #define max(x, y) ({ \ 121 const typeof(x) tx = (x); \ 122 const typeof(y) ty = (y); \ 123 \ 124 (void) (&tx == &ty); \ 125 tx > ty ? tx : ty; \ 126 }) 127 128 #endif 129 130 /* 131 * Local variables: 132 * mode: C 133 * c-file-style: "BSD" 134 * c-basic-offset: 4 135 * indent-tabs-mode: nil 136 * End: 137 */ 138