xref: /freebsd/usr.sbin/bhyve/pci_passthru.h (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2020 Beckhoff Automation GmbH & Co. KG
5  * Author: Corvin Köhne <c.koehne@beckhoff.com>
6  */
7 
8 #pragma once
9 
10 #include <sys/linker_set.h>
11 
12 #include <vmmapi.h>
13 
14 #include "config.h"
15 #include "pci_emul.h"
16 
17 struct passthru_mmio_mapping {
18 	vm_paddr_t gpa; /* guest physical address */
19 	void *gva;	/* guest virtual address */
20 	vm_paddr_t hpa; /* host physical address */
21 	void *hva;	/* guest virtual address */
22 	vm_paddr_t len;
23 };
24 
25 struct passthru_softc;
26 
27 struct passthru_dev {
28     int (*probe)(struct pci_devinst *pi);
29     int (*init)(struct pci_devinst *pi, nvlist_t *nvl);
30     void (*deinit)(struct pci_devinst *pi);
31 };
32 #define PASSTHRU_DEV_SET(x) DATA_SET(passthru_dev_set, x)
33 
34 typedef int (*cfgread_handler)(struct passthru_softc *sc,
35     struct pci_devinst *pi, int coff, int bytes, uint32_t *rv);
36 typedef int (*cfgwrite_handler)(struct passthru_softc *sc,
37     struct pci_devinst *pi, int coff, int bytes, uint32_t val);
38 
39 uint32_t pci_host_read_config(const struct pcisel *sel, long reg, int width);
40 void pci_host_write_config(const struct pcisel *sel, long reg, int width,
41     uint32_t data);
42 
43 int passthru_cfgread_emulate(struct passthru_softc *sc, struct pci_devinst *pi,
44     int coff, int bytes, uint32_t *rv);
45 int passthru_cfgwrite_emulate(struct passthru_softc *sc, struct pci_devinst *pi,
46     int coff, int bytes, uint32_t val);
47 struct passthru_mmio_mapping *passthru_get_mmio(struct passthru_softc *sc,
48     int num);
49 struct pcisel *passthru_get_sel(struct passthru_softc *sc);
50 int set_pcir_handler(struct passthru_softc *sc, int reg, int len,
51     cfgread_handler rhandler, cfgwrite_handler whandler);
52