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
154 * @default_client: The default I/O request client154 * @default_client: The default I/O request client
155 * @ioreq_buf: I/O request shared buffer155 * @ioreq_buf: I/O request shared buffer
156 * @ioreq_page: The page of the I/O request shared buffer156 * @ioreq_page: The page of the I/O request shared buffer
157 * @pci_conf_addr: Address of a PCI configuration access emulation
157 */158 */
158struct acrn_vm {159struct acrn_vm {
159 struct list_head list;160 struct list_head list;
@@ -168,6 +169,7 @@ struct acrn_vm { · 8 unmodified lines
168 struct acrn_ioreq_client *default_client;169 struct acrn_ioreq_client *default_client;
169 struct acrn_io_request_buffer *ioreq_buf;170 struct acrn_io_request_buffer *ioreq_buf;
170 struct page *ioreq_page;171 struct page *ioreq_page;
172 u32 pci_conf_addr;
171};173};
172 174
173struct acrn_vm *acrn_vm_create(struct acrn_vm *vm,175struct 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
222 return 0;222 return 0;
223}223}
224 224
225static 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
231static 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 */
257static 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
225static bool in_range(struct acrn_ioreq_range *range,299static bool in_range(struct acrn_ioreq_range *range,
226 struct acrn_io_request *req)300 struct acrn_io_request *req)
227{301{
@@ -382,6 +456,8 @@ static int acrn_ioreq_dispatch(struct acrn_vm *vm) · 154 unmodified lines
382 ioreq_complete_request(vm, i, req);456 ioreq_complete_request(vm, i, req);
383 continue;457 continue;
384 }458 }
459 if (handle_cf8cfc(vm, req, i))
460 continue;
385 461
386 spin_lock_bh(&vm->ioreq_clients_lock);462 spin_lock_bh(&vm->ioreq_clients_lock);
387 client = find_ioreq_client(vm, req);463 client = find_ioreq_client(vm, req);
include/uapi/linux/acrn.h+27−0
@@ -23,6 +23,7 @@ · 22 unmodified lines
23 23
24#define ACRN_IOREQ_TYPE_PORTIO 024#define ACRN_IOREQ_TYPE_PORTIO 0
25#define ACRN_IOREQ_TYPE_MMIO 125#define ACRN_IOREQ_TYPE_MMIO 1
26#define ACRN_IOREQ_TYPE_PCICFG 2
26 27
27#define ACRN_IOREQ_DIR_READ 028#define ACRN_IOREQ_DIR_READ 0
28#define ACRN_IOREQ_DIR_WRITE 129#define ACRN_IOREQ_DIR_WRITE 1
@@ -59,6 +60,30 @@ struct acrn_pio_request { · 30 unmodified lines
59 __u32 value;60 __u32 value;
60};61};
61 62
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 */
76struct 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
62/**87/**
63 * struct acrn_io_request - 256-byte ACRN I/O request88 * struct acrn_io_request - 256-byte ACRN I/O request
64 * @type: Type of this request (ACRN_IOREQ_TYPE_*).89 * @type: Type of this request (ACRN_IOREQ_TYPE_*).
@@ -67,6 +92,7 @@ struct acrn_pio_request { · 2 unmodified lines
67 * @reserved0: Reserved fields.92 * @reserved0: Reserved fields.
68 * @reqs: Union of different types of request. Byte offset: 64.93 * @reqs: Union of different types of request. Byte offset: 64.
69 * @reqs.pio_request: PIO request data of the I/O request.94 * @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.
70 * @reqs.mmio_request: MMIO request data of the I/O request.96 * @reqs.mmio_request: MMIO request data of the I/O request.
71 * @reqs.data: Raw data of the I/O request.97 * @reqs.data: Raw data of the I/O request.
72 * @reserved1: Reserved fields.98 * @reserved1: Reserved fields.
@@ -126,6 +152,7 @@ struct acrn_io_request { · 53 unmodified lines
126 __u32 reserved0[14];152 __u32 reserved0[14];
127 union {153 union {
128 struct acrn_pio_request pio_request;154 struct acrn_pio_request pio_request;
155 struct acrn_pci_request pci_request;
129 struct acrn_mmio_request mmio_request;156 struct acrn_mmio_request mmio_request;
130 __u64 data[8];157 __u64 data[8];
131 } reqs;158 } 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