1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * io.h: HVM IO support
4  *
5  * Copyright (c) 2004, Intel Corporation.
6  */
7 
8 #ifndef __ASM_X86_HVM_IO_H__
9 #define __ASM_X86_HVM_IO_H__
10 
11 #include <xen/pci.h>
12 #include <public/hvm/ioreq.h>
13 
14 #define NR_IO_HANDLERS 32
15 
16 typedef int (*hvm_mmio_read_t)(struct vcpu *v,
17                                unsigned long addr,
18                                unsigned int length,
19                                unsigned long *val);
20 typedef int (*hvm_mmio_write_t)(struct vcpu *v,
21                                 unsigned long addr,
22                                 unsigned int length,
23                                 unsigned long val);
24 typedef int (*hvm_mmio_check_t)(struct vcpu *v, unsigned long addr);
25 
26 struct hvm_mmio_ops {
27     hvm_mmio_check_t check;
28     hvm_mmio_read_t  read;
29     hvm_mmio_write_t write;
30 };
31 
32 typedef int (*portio_action_t)(
33     int dir, unsigned int port, unsigned int bytes, uint32_t *val);
34 
35 struct hvm_io_handler {
36     union {
37         struct {
38             const struct hvm_mmio_ops *ops;
39         } mmio;
40         struct {
41             unsigned int port, size;
42             portio_action_t action;
43         } portio;
44     };
45     const struct hvm_io_ops *ops;
46     uint8_t type;
47 };
48 
49 typedef int (*hvm_io_read_t)(const struct hvm_io_handler *handler,
50                              uint64_t addr,
51                              uint32_t size,
52                              uint64_t *data);
53 typedef int (*hvm_io_write_t)(const struct hvm_io_handler *handler,
54                               uint64_t addr,
55                               uint32_t size,
56                               uint64_t data);
57 typedef bool (*hvm_io_accept_t)(const struct hvm_io_handler *handler,
58                                 const ioreq_t *p);
59 
60 struct hvm_io_ops {
61     hvm_io_accept_t   accept;
62     hvm_io_read_t     read;
63     hvm_io_write_t    write;
64 };
65 
66 int hvm_process_io_intercept(const struct hvm_io_handler *handler,
67                              ioreq_t *p);
68 
69 int hvm_io_intercept(ioreq_t *p);
70 
71 struct hvm_io_handler *hvm_next_io_handler(struct domain *d);
72 
73 bool hvm_mmio_internal(paddr_t gpa);
74 
75 void register_mmio_handler(struct domain *d,
76                            const struct hvm_mmio_ops *ops);
77 
78 void register_portio_handler(
79     struct domain *d, unsigned int port, unsigned int size,
80     portio_action_t action);
81 
82 bool relocate_portio_handler(
83     struct domain *d, unsigned int old_port, unsigned int new_port,
84     unsigned int size);
85 
86 void send_timeoffset_req(unsigned long timeoff);
87 bool handle_mmio_with_translation(unsigned long gla, unsigned long gpfn,
88                                   struct npfec access);
89 bool handle_pio(uint16_t port, unsigned int size, int dir);
90 void hvm_interrupt_post(struct vcpu *v, int vector, int type);
91 void hvm_dpci_eoi(struct domain *d, unsigned int guest_gsi);
92 void msix_write_completion(struct vcpu *v);
93 
94 #ifdef CONFIG_HVM
95 void msixtbl_init(struct domain *d);
96 #else
msixtbl_init(struct domain * d)97 static inline void msixtbl_init(struct domain *d) {}
98 #endif
99 
100 /* Arch-specific MSI data for vPCI. */
101 struct vpci_arch_msi {
102     int pirq;
103     bool bound;
104 };
105 
106 /* Arch-specific MSI-X entry data for vPCI. */
107 struct vpci_arch_msix_entry {
108     int pirq;
109 };
110 
111 void stdvga_init(struct domain *d);
112 
113 extern void hvm_dpci_msi_eoi(struct domain *d, int vector);
114 
115 /* Decode a PCI port IO access into a bus/slot/func/reg. */
116 unsigned int hvm_pci_decode_addr(unsigned int cf8, unsigned int addr,
117                                  pci_sbdf_t *sbdf);
118 
119 /*
120  * HVM port IO handler that performs forwarding of guest IO ports into machine
121  * IO ports.
122  */
123 void register_g2m_portio_handler(struct domain *d);
124 
125 /* HVM port IO handler for vPCI accesses. */
126 void register_vpci_portio_handler(struct domain *d);
127 
128 /* HVM MMIO handler for PCI MMCFG accesses. */
129 int register_vpci_mmcfg_handler(struct domain *d, paddr_t addr,
130                                 unsigned int start_bus, unsigned int end_bus,
131                                 unsigned int seg);
132 /* Destroy tracked MMCFG areas. */
133 void destroy_vpci_mmcfg(struct domain *d);
134 
135 /* Remove MMCFG regions from a domain ->iomem_caps. */
136 int vpci_mmcfg_deny_access(struct domain *d);
137 
138 /* r/o MMIO subpage access handler. */
139 void register_subpage_ro_handler(struct domain *d);
140 
141 #endif /* __ASM_X86_HVM_IO_H__ */
142 
143 
144 /*
145  * Local variables:
146  * mode: C
147  * c-file-style: "BSD"
148  * c-basic-offset: 4
149  * tab-width: 4
150  * indent-tabs-mode: nil
151  * End:
152  */
153