Files
xen/tools/tests/vpci/emul.h
T
Oleksandr Andrushchenko ad3ac58a9d vpci: translate virtual PCI bus topology for guests
There are two originators for the PCI configuration space access:
1. The domain that owns physical host bridge: MMIO handlers are
there so we can update vPCI register handlers with the values
written by the hardware domain, e.g. physical view of the registers
vs guest's view on the configuration space.
2. Guest access to the passed through PCI devices: we need to properly
map virtual bus topology to the physical one, e.g. pass the configuration
space access to the corresponding physical devices.

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2025-05-09 13:58:43 -07:00

128 lines
2.9 KiB
C

/*
* Unit tests for the generic vPCI handler code.
*
* Copyright (C) 2017 Citrix Systems R&D
*
* This program is free software; you can redistribute it and/or
* modify it under the terms and conditions of the GNU General Public
* License, version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TEST_VPCI_
#define _TEST_VPCI_
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <xen-tools/common-macros.h>
#define smp_wmb()
#define prefetch(x) __builtin_prefetch(x)
#define ASSERT(x) assert(x)
#define __must_check __attribute__((__warn_unused_result__))
#define cf_check
#include "list.h"
typedef bool rwlock_t;
struct domain {
rwlock_t pci_lock;
};
struct pci_dev {
struct vpci *vpci;
};
struct vcpu
{
struct domain *domain;
};
extern const struct vcpu *current;
extern const struct pci_dev test_pdev;
typedef bool spinlock_t;
#define spin_lock_init(l) (*(l) = false)
#define spin_lock(l) (*(l) = true)
#define spin_unlock(l) (*(l) = false)
#define read_lock(l) (*(l) = true)
#define read_unlock(l) (*(l) = false)
#define write_lock(l) (*(l) = true)
#define write_unlock(l) (*(l) = false)
typedef union {
uint32_t sbdf;
struct {
union {
uint16_t bdf;
struct {
union {
struct {
uint8_t func : 3,
dev : 5;
};
uint8_t extfunc;
};
uint8_t bus;
};
};
uint16_t seg;
};
} pci_sbdf_t;
#define CONFIG_HAS_VPCI
#include "vpci.h"
#define __hwdom_init
#define is_hardware_domain(d) ((void)(d), true)
#define has_vpci(d) true
#define xzalloc(type) ((type *)calloc(1, sizeof(type)))
#define xmalloc(type) ((type *)malloc(sizeof(type)))
#define xfree(p) free(p)
#define pci_get_pdev(...) (&test_pdev)
#define pci_get_ro_map(...) NULL
#define test_bit(...) false
/* Dummy native helpers. Writes are ignored, reads return 1's. */
#define pci_conf_read8(...) 0xff
#define pci_conf_read16(...) 0xffff
#define pci_conf_read32(...) 0xffffffff
#define pci_conf_write8(...)
#define pci_conf_write16(...)
#define pci_conf_write32(...)
#define PCI_CFG_SPACE_EXP_SIZE 4096
#define BUG() assert(0)
#define ASSERT_UNREACHABLE() assert(0)
#endif
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/