History

virt: acrn: Introduce PCI configuration space PIO accesses combiner

A User VM can access its virtual PCI configuration spaces via port IO approach, which has two following steps: 1) writes address into port 0xCF8 2) put/get data in/from port 0xCFC To distribute a complete PCI configuration space access one time, HSM need to combine such two accesses together. Combine two paired PIO I/O requests into one PCI I/O request and continue the I/O request distribution.

Shuo Liu committed 5 years ago

Commit 3c4c3311 parent 72f293d3 files · +105 −0Browse files

Unified · Split

3 files
  1. drivers/virt/acrn/acrn_drv.h +2 −0
  2. drivers/virt/acrn/ioreq.c +76 −0
  3. include/uapi/linux/acrn.h +27 −0
drivers/virt/acrn/acrn_drv.h+2−0
@@ -154,6 +154,7 @@ extern rwlock_t acrn_vm_list_lock; · 153 unmodified lines
154154 * @default_client: The default I/O request client
155155 * @ioreq_buf: I/O request shared buffer
156156 * @ioreq_page: The page of the I/O request shared buffer
157+ * @pci_conf_addr: Address of a PCI configuration access emulation
157158 */
158159 struct acrn_vm {
159160 struct list_head list;
@@ -168,6 +169,7 @@ struct acrn_vm { · 8 unmodified lines
168169 struct acrn_ioreq_client *default_client;
169170 struct acrn_io_request_buffer *ioreq_buf;
170171 struct page *ioreq_page;
172+ u32 pci_conf_addr;
171173 };
172174
173175 struct acrn_vm *acrn_vm_create(struct acrn_vm *vm,
drivers/virt/acrn/ioreq.c+76−0
@@ -222,6 +222,80 @@ int acrn_ioreq_client_wait(struct acrn_ioreq_client *client) · 221 unmodified lines
222222 return 0;
223223 }
224224
225+static bool is_cfg_addr(struct acrn_io_request *req)
226+{
227+ return ((req->type == ACRN_IOREQ_TYPE_PORTIO) &&
228+ (req->reqs.pio_request.address == 0xcf8));
229+}
230+
231+static bool is_cfg_data(struct acrn_io_request *req)
232+{
233+ return ((req->type == ACRN_IOREQ_TYPE_PORTIO) &&
234+ ((req->reqs.pio_request.address >= 0xcfc) &&
235+ (req->reqs.pio_request.address < (0xcfc + 4))));
236+}
237+
238+/* The low 8-bit of supported pci_reg addr.*/
239+#define PCI_LOWREG_MASK 0xFC
240+/* The high 4-bit of supported pci_reg addr */
241+#define PCI_HIGHREG_MASK 0xF00
242+/* Max number of supported functions */
243+#define PCI_FUNCMAX 7
244+/* Max number of supported slots */
245+#define PCI_SLOTMAX 31
246+/* Max number of supported buses */
247+#define PCI_BUSMAX 255
248+#define CONF1_ENABLE 0x80000000UL
249+/*
250+ * A PCI configuration space access via PIO 0xCF8 and 0xCFC normally has two
251+ * following steps:
252+ * 1) writes address into 0xCF8 port
253+ * 2) accesses data in/from 0xCFC
254+ * This function combines such paired PCI configuration space I/O requests into
255+ * one ACRN_IOREQ_TYPE_PCICFG type I/O request and continues the processing.
256+ */
257+static bool handle_cf8cfc(struct acrn_vm *vm,
258+ struct acrn_io_request *req, u16 vcpu)
259+{
260+ int offset, pci_cfg_addr, pci_reg;
261+ bool is_handled = false;
262+
263+ if (is_cfg_addr(req)) {
264+ WARN_ON(req->reqs.pio_request.size != 4);
265+ if (req->reqs.pio_request.direction == ACRN_IOREQ_DIR_WRITE)
266+ vm->pci_conf_addr = req->reqs.pio_request.value;
267+ else
268+ req->reqs.pio_request.value = vm->pci_conf_addr;
269+ is_handled = true;
270+ } else if (is_cfg_data(req)) {
271+ if (!(vm->pci_conf_addr & CONF1_ENABLE)) {
272+ if (req->reqs.pio_request.direction ==
273+ ACRN_IOREQ_DIR_READ)
274+ req->reqs.pio_request.value = 0xffffffff;
275+ is_handled = true;
276+ } else {
277+ offset = req->reqs.pio_request.address - 0xcfc;
278+
279+ req->type = ACRN_IOREQ_TYPE_PCICFG;
280+ pci_cfg_addr = vm->pci_conf_addr;
281+ req->reqs.pci_request.bus =
282+ (pci_cfg_addr >> 16) & PCI_BUSMAX;
283+ req->reqs.pci_request.dev =
284+ (pci_cfg_addr >> 11) & PCI_SLOTMAX;
285+ req->reqs.pci_request.func =
286+ (pci_cfg_addr >> 8) & PCI_FUNCMAX;
287+ pci_reg = (pci_cfg_addr & PCI_LOWREG_MASK) +
288+ ((pci_cfg_addr >> 16) & PCI_HIGHREG_MASK);
289+ req->reqs.pci_request.reg = pci_reg + offset;
290+ }
291+ }
292+
293+ if (is_handled)
294+ ioreq_complete_request(vm, vcpu, req);
295+
296+ return is_handled;
297+}
298+
225299 static bool in_range(struct acrn_ioreq_range *range,
226300 struct acrn_io_request *req)
227301 {
@@ -382,6 +456,8 @@ static int acrn_ioreq_dispatch(struct acrn_vm *vm) · 154 unmodified lines
382456 ioreq_complete_request(vm, i, req);
383457 continue;
384458 }
459+ if (handle_cf8cfc(vm, req, i))
460+ continue;
385461
386462 spin_lock_bh(&vm->ioreq_clients_lock);
387463 client = find_ioreq_client(vm, req);
include/uapi/linux/acrn.h+27−0
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323
2424 #define ACRN_IOREQ_TYPE_PORTIO 0
2525 #define ACRN_IOREQ_TYPE_MMIO 1
26+#define ACRN_IOREQ_TYPE_PCICFG 2
2627
2728 #define ACRN_IOREQ_DIR_READ 0
2829 #define ACRN_IOREQ_DIR_WRITE 1
@@ -59,6 +60,30 @@ struct acrn_pio_request { · 30 unmodified lines
5960 __u32 value;
6061 };
6162
63+/**
64+ * struct acrn_pci_request - Info of a PCI I/O request
65+ * @direction: Access direction of this request (ACRN_IOREQ_DIR_*)
66+ * @reserved: Reserved for alignment and should be 0
67+ * @size: Access size of this PCI I/O request
68+ * @value: Read/write value of this PIO I/O request
69+ * @bus: PCI bus value of this PCI I/O request
70+ * @dev: PCI device value of this PCI I/O request
71+ * @func: PCI function value of this PCI I/O request
72+ * @reg: PCI config space offset of this PCI I/O request
73+ *
74+ * Need keep same header layout with &struct acrn_pio_request.
75+ */
76+struct acrn_pci_request {
77+ __u32 direction;
78+ __u32 reserved[3];
79+ __u64 size;
80+ __u32 value;
81+ __u32 bus;
82+ __u32 dev;
83+ __u32 func;
84+ __u32 reg;
85+};
86+
6287 /**
6388 * struct acrn_io_request - 256-byte ACRN I/O request
6489 * @type: Type of this request (ACRN_IOREQ_TYPE_*).
@@ -67,6 +92,7 @@ struct acrn_pio_request { · 2 unmodified lines
6792 * @reserved0: Reserved fields.
6893 * @reqs: Union of different types of request. Byte offset: 64.
6994 * @reqs.pio_request: PIO request data of the I/O request.
95+ * @reqs.pci_request: PCI configuration space request data of the I/O request.
7096 * @reqs.mmio_request: MMIO request data of the I/O request.
7197 * @reqs.data: Raw data of the I/O request.
7298 * @reserved1: Reserved fields.
@@ -126,6 +152,7 @@ struct acrn_io_request { · 53 unmodified lines
126152 __u32 reserved0[14];
127153 union {
128154 struct acrn_pio_request pio_request;
155+ struct acrn_pci_request pci_request;
129156 struct acrn_mmio_request mmio_request;
130157 __u64 data[8];
131158 } reqs;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t