1/*
2 * Copyright 2019, Data61, CSIRO (ABN 41 687 119 230)
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7/***
8 * @module vmm_pci_helper.h
9 * The interface presents a series of helpers for establishing VMM PCI support on x86 platforms.
10 */
11
12#include <sel4vm/guest_vm.h>
13#include <sel4vm/arch/ioports.h>
14#include <sel4vmmplatsupport/drivers/pci_helper.h>
15
16#include <pci/virtual_pci.h>
17#include <pci/helper.h>
18
19/***
20 * @function vmm_pci_helper_map_bars(vm, cfg, bars)
21 * Given a PCI device config, map the PCI device bars into the VM, effectively passing-through the
22 * PCI device. This will map MMIO and IO-based bars.
23 * @param {vm_t *} vm                       A handle to the VM
24 * @param {libpci_device_iocfg_t *} cfg     PCI device config
25 * @param {vmm_pci_bar_t *} bars            Resulting PCI bars mapped into the VM
26 * @return                                  -1 for error, otherwise the number of bars mapped into the VM (>=0)
27 */
28int vmm_pci_helper_map_bars(vm_t *vm, libpci_device_iocfg_t *cfg, vmm_pci_bar_t *bars);
29
30/* Functions for emulating PCI config spaces over IO ports */
31/***
32 * @function vmm_pci_io_port_in(vcpu, cookie, port_no, size, result)
33 * Emulates IOPort in access on the VMM Virtual PCI device
34 * @param {vm_vcpu_t *} vcpu            Faulting vcpu performing ioport access
35 * @param {unsigned int} port_no        Port address being accessed
36 * @param {unsigned int} size           Size of ioport access
37 * @param {unsigned int *} result       Pointer that will be populated with resulting data of io-in op
38 */
39ioport_fault_result_t vmm_pci_io_port_in(vm_vcpu_t *vcpu, void *cookie, unsigned int port_no, unsigned int size,
40                                         unsigned int *result);
41
42/***
43 * @function vmm_pci_io_port_out(vcpu, cookie, port_no, size, value)
44 * Emulates IOPort out access on the VMM Virtual PCI device
45 * @param {vm_vcpu_t *} vcpu            Faulting vcpu performing ioport access
46 * @param {unsigned int} port_no        Port address being accessed
47 * @param {unsigned int} size           Size of ioport access
48 * @param {unsigned int} value          Value being written in io-out op
49 */
50ioport_fault_result_t vmm_pci_io_port_out(vm_vcpu_t *vcpu, void *cookie, unsigned int port_no, unsigned int size,
51                                          unsigned int value);
52