| 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 |
#include <xen-tools/common-macros.h> |
| 31 |
|
| 32 |
#define smp_wmb() |
| 33 |
#define prefetch(x) __builtin_prefetch(x) |
| 34 |
#define ASSERT(x) assert(x) |
| 35 |
#define __must_check __attribute__((__warn_unused_result__)) |
| 36 |
#define cf_check |
| 37 |
|
| 38 |
#include "list.h" |
| 39 |
|
| 40 |
typedef bool rwlock_t; |
| 41 |
|
| 42 |
struct domain { |
| 43 |
rwlock_t pci_lock; |
| 44 |
}; |
| 45 |
|
| 46 |
struct pci_dev { |
| 47 |
struct vpci *vpci; |
| 48 |
}; |
| 49 |
|
| 50 |
struct vcpu |
| 51 |
{ |
| 52 |
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 |
#define read_lock(l) (*(l) = true) |
| 63 |
#define read_unlock(l) (*(l) = false) |
| 64 |
#define write_lock(l) (*(l) = true) |
| 65 |
#define write_unlock(l) (*(l) = false) |
| 66 |
|
| 67 |
typedef union { |
| 68 |
uint32_t sbdf; |
| 69 |
struct { |
| 70 |
union { |
| 71 |
uint16_t bdf; |
| 72 |
struct { |
| 73 |
union { |
| 74 |
struct { |
| 75 |
uint8_t func : 3, |
| 76 |
dev : 5; |
| 77 |
}; |
| 78 |
uint8_t extfunc; |
| 79 |
}; |
| 80 |
uint8_t bus; |
| 81 |
}; |
| 82 |
}; |
| 83 |
uint16_t seg; |
| 84 |
}; |
| 85 |
} pci_sbdf_t; |
| 86 |
|
| 87 |
#define CONFIG_HAS_VPCI |
| 88 |
#include "vpci.h" |
| 89 |
|
| 90 |
#define __hwdom_init |
| 91 |
|
| 92 |
#define is_hardware_domain(d) ((void)(d), false) |
| 93 |
|
| 94 |
#define has_vpci(d) true |
| 95 |
|
| 96 |
#define xzalloc(type) ((type *)calloc(1, sizeof(type))) |
| 97 |
#define xmalloc(type) ((type *)malloc(sizeof(type))) |
| 98 |
#define xfree(p) free(p) |
| 99 |
|
| 100 |
#define pci_get_pdev(...) (&test_pdev) |
| 101 |
#define pci_get_ro_map(...) NULL |
| 102 |
|
| 103 |
#define test_bit(...) false |
| 104 |
|
| 105 |
/* Dummy native helpers. Writes are ignored, reads return 1's. */ |
| 106 |
#define pci_conf_read8(...) 0xff |
| 107 |
#define pci_conf_read16(...) 0xffff |
| 108 |
#define pci_conf_read32(...) 0xffffffff |
| 109 |
#define pci_conf_write8(...) |
| 110 |
#define pci_conf_write16(...) |
| 111 |
#define pci_conf_write32(...) |
| 112 |
|
| 113 |
#define PCI_CFG_SPACE_EXP_SIZE 4096 |
| 114 |
|
| 115 |
#define BUG() assert(0) |
| 116 |
#define ASSERT_UNREACHABLE() assert(0) |
| 117 |
|
| 118 |
#endif |
| 119 |
|
| 120 |
/* |
| 121 |
* Local variables: |
| 122 |
* mode: C |
| 123 |
* c-file-style: "BSD" |
| 124 |
* c-basic-offset: 4 |
| 125 |
* indent-tabs-mode: nil |
| 126 |
* End: |
| 127 |
*/ |