xref: /freebsd/usr.sbin/bhyve/pci_passthru.h (revision 90c3a1b6629c80a7e4c3fa86d6b794596fdf06b4)
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 read_config(const struct pcisel *sel, long reg, int width);
40 void write_config(const struct pcisel *sel, long reg, int width, uint32_t data);
41 int passthru_cfgread_emulate(struct passthru_softc *sc, struct pci_devinst *pi,
42     int coff, int bytes, uint32_t *rv);
43 int passthru_cfgwrite_emulate(struct passthru_softc *sc, struct pci_devinst *pi,
44     int coff, int bytes, uint32_t val);
45 struct passthru_mmio_mapping *passthru_get_mmio(struct passthru_softc *sc,
46     int num);
47 struct pcisel *passthru_get_sel(struct passthru_softc *sc);
48 int set_pcir_handler(struct passthru_softc *sc, int reg, int len,
49     cfgread_handler rhandler, cfgwrite_handler whandler);
50