Skip to content

Commit 1915eec

Browse files
junjiemao1lijinxia
authored andcommitted
HV: io: separate I/O emulation interface declarations
Currently the I/O emulation structures and interfaces are scattered among mmu.h, io.h and guest.h, and tangled with other interfaces there. This patch moves the former to a separate header ioreq.h. Signed-off-by: Junjie Mao <junjie.mao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 3cab926 commit 1915eec

File tree

5 files changed

+136
-125
lines changed

5 files changed

+136
-125
lines changed

hypervisor/include/arch/x86/guest/guest.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
#define IDX_PAT (IDX_TSC + 1U)
3333
#define IDX_MAX_MSR (IDX_PAT + 1U)
3434

35-
struct vhm_request;
36-
37-
int32_t acrn_insert_request_wait(struct vcpu *vcpu, struct vhm_request *req);
38-
3935
/*
4036
* VCPU related APIs
4137
*/

hypervisor/include/arch/x86/hv_arch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <lapic.h>
1616
#include <msr.h>
1717
#include <io.h>
18+
#include <ioreq.h>
1819
#include <mtrr.h>
1920
#include <vcpu.h>
2021
#include <trusty.h>

hypervisor/include/arch/x86/io.h

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99

1010
#include <types.h>
1111

12-
/* Definition of a IO port range */
13-
struct vm_io_range {
14-
uint16_t base; /* IO port base */
15-
uint16_t len; /* IO port range */
16-
uint32_t flags; /* IO port attributes */
17-
};
18-
1912
/* Write 1 byte to specified I/O port */
2013
static inline void io_write_byte(uint8_t value, uint16_t port)
2114
{
@@ -83,80 +76,6 @@ static inline uint32_t io_read(uint16_t addr, size_t sz)
8376
return io_read_long(addr);
8477
}
8578

86-
struct vm_io_handler;
87-
struct vm;
88-
struct vcpu;
89-
90-
typedef
91-
uint32_t (*io_read_fn_t)(struct vm_io_handler *, struct vm *,
92-
uint16_t, size_t);
93-
94-
typedef
95-
void (*io_write_fn_t)(struct vm_io_handler *, struct vm *,
96-
uint16_t, size_t, uint32_t);
97-
98-
/* Describes a single IO handler description entry. */
99-
struct vm_io_handler_desc {
100-
101-
/** The base address of the IO range for this description. */
102-
uint16_t addr;
103-
/** The number of bytes covered by this description. */
104-
size_t len;
105-
106-
/** A pointer to the "read" function.
107-
*
108-
* The read function is called from the hypervisor whenever
109-
* a read access to a range described in "ranges" occur.
110-
* The arguments to the callback are:
111-
*
112-
* - The address of the port to read from.
113-
* - The width of the read operation (1,2 or 4).
114-
*
115-
* The implementation must return the ports content as
116-
* byte, word or doubleword (depending on the width).
117-
*
118-
* If the pointer is null, a read of 1's is assumed.
119-
*/
120-
121-
io_read_fn_t io_read;
122-
/** A pointer to the "write" function.
123-
*
124-
* The write function is called from the hypervisor code
125-
* whenever a write access to a range described in "ranges"
126-
* occur. The arguments to the callback are:
127-
*
128-
* - The address of the port to write to.
129-
* - The width of the write operation (1,2 or 4).
130-
* - The value to write as byte, word or doubleword
131-
* (depending on the width)
132-
*
133-
* The implementation must write the value to the port.
134-
*
135-
* If the pointer is null, the write access is ignored.
136-
*/
137-
138-
io_write_fn_t io_write;
139-
};
140-
141-
struct vm_io_handler {
142-
struct vm_io_handler *next;
143-
struct vm_io_handler_desc desc;
144-
};
145-
146-
#define IO_ATTR_R 0U
147-
#define IO_ATTR_RW 1U
148-
#define IO_ATTR_NO_ACCESS 2U
149-
150-
/* External Interfaces */
151-
int io_instr_vmexit_handler(struct vcpu *vcpu);
152-
void setup_io_bitmap(struct vm *vm);
153-
void free_io_emulation_resource(struct vm *vm);
154-
void allow_guest_io_access(struct vm *vm, uint32_t address, uint32_t nbytes);
155-
void register_io_emulation_handler(struct vm *vm, struct vm_io_range *range,
156-
io_read_fn_t io_read_fn_ptr,
157-
io_write_fn_t io_write_fn_ptr);
158-
int dm_emulate_pio_post(struct vcpu *vcpu);
159-
16079
/** Writes a 32 bit value to a memory mapped IO device.
16180
*
16281
* @param value The 32 bit value to write.
@@ -327,24 +246,4 @@ static inline void setb(void *addr, uint8_t mask, uint8_t value)
327246
mmio_write_byte((mmio_read_byte(addr) & ~mask) | value, addr);
328247
}
329248

330-
/* MMIO memory access types */
331-
enum mem_io_type {
332-
HV_MEM_IO_READ = 0,
333-
HV_MEM_IO_WRITE,
334-
};
335-
336-
/* MMIO emulation related structures */
337-
#define MMIO_TRANS_VALID 1U
338-
#define MMIO_TRANS_INVALID 0U
339-
struct mem_io {
340-
uint64_t paddr; /* Physical address being accessed */
341-
enum mem_io_type read_write; /* 0 = read / 1 = write operation */
342-
uint8_t access_size; /* Access size being emulated */
343-
uint8_t sign_extend_read; /* 1 if sign extension required for read */
344-
uint64_t value; /* Value read or value to write */
345-
uint8_t mmio_status; /* Indicates if this MMIO transaction is valid */
346-
/* Used to store emulation context for this mmio transaction */
347-
void *private_data;
348-
};
349-
350249
#endif /* _IO_H defined */

hypervisor/include/arch/x86/ioreq.h

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright (C) 2018 Intel Corporation. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef IOREQ_H
8+
#define IOREQ_H
9+
10+
#include <types.h>
11+
12+
/* Definition of a IO port range */
13+
struct vm_io_range {
14+
uint16_t base; /* IO port base */
15+
uint16_t len; /* IO port range */
16+
uint32_t flags; /* IO port attributes */
17+
};
18+
19+
struct vm_io_handler;
20+
struct vm;
21+
struct vcpu;
22+
23+
typedef
24+
uint32_t (*io_read_fn_t)(struct vm_io_handler *, struct vm *,
25+
uint16_t, size_t);
26+
27+
typedef
28+
void (*io_write_fn_t)(struct vm_io_handler *, struct vm *,
29+
uint16_t, size_t, uint32_t);
30+
31+
/* Describes a single IO handler description entry. */
32+
struct vm_io_handler_desc {
33+
34+
/** The base address of the IO range for this description. */
35+
uint16_t addr;
36+
/** The number of bytes covered by this description. */
37+
size_t len;
38+
39+
/** A pointer to the "read" function.
40+
*
41+
* The read function is called from the hypervisor whenever
42+
* a read access to a range described in "ranges" occur.
43+
* The arguments to the callback are:
44+
*
45+
* - The address of the port to read from.
46+
* - The width of the read operation (1,2 or 4).
47+
*
48+
* The implementation must return the ports content as
49+
* byte, word or doubleword (depending on the width).
50+
*
51+
* If the pointer is null, a read of 1's is assumed.
52+
*/
53+
54+
io_read_fn_t io_read;
55+
/** A pointer to the "write" function.
56+
*
57+
* The write function is called from the hypervisor code
58+
* whenever a write access to a range described in "ranges"
59+
* occur. The arguments to the callback are:
60+
*
61+
* - The address of the port to write to.
62+
* - The width of the write operation (1,2 or 4).
63+
* - The value to write as byte, word or doubleword
64+
* (depending on the width)
65+
*
66+
* The implementation must write the value to the port.
67+
*
68+
* If the pointer is null, the write access is ignored.
69+
*/
70+
71+
io_write_fn_t io_write;
72+
};
73+
74+
struct vm_io_handler {
75+
struct vm_io_handler *next;
76+
struct vm_io_handler_desc desc;
77+
};
78+
79+
#define IO_ATTR_R 0U
80+
#define IO_ATTR_RW 1U
81+
#define IO_ATTR_NO_ACCESS 2U
82+
83+
/* MMIO memory access types */
84+
enum mem_io_type {
85+
HV_MEM_IO_READ = 0,
86+
HV_MEM_IO_WRITE,
87+
};
88+
89+
/* MMIO emulation related structures */
90+
#define MMIO_TRANS_VALID 1U
91+
#define MMIO_TRANS_INVALID 0U
92+
struct mem_io {
93+
uint64_t paddr; /* Physical address being accessed */
94+
enum mem_io_type read_write; /* 0 = read / 1 = write operation */
95+
uint8_t access_size; /* Access size being emulated */
96+
uint8_t sign_extend_read; /* 1 if sign extension required for read */
97+
uint64_t value; /* Value read or value to write */
98+
uint8_t mmio_status; /* Indicates if this MMIO transaction is valid */
99+
/* Used to store emulation context for this mmio transaction */
100+
void *private_data;
101+
};
102+
103+
/* Typedef for MMIO handler and range check routine */
104+
struct mmio_request;
105+
typedef int (*hv_mem_io_handler_t)(struct vcpu *, struct mem_io *, void *);
106+
107+
/* Structure for MMIO handler node */
108+
struct mem_io_node {
109+
hv_mem_io_handler_t read_write;
110+
void *handler_private_data;
111+
struct list_head list;
112+
uint64_t range_start;
113+
uint64_t range_end;
114+
};
115+
116+
/* External Interfaces */
117+
int io_instr_vmexit_handler(struct vcpu *vcpu);
118+
void setup_io_bitmap(struct vm *vm);
119+
void free_io_emulation_resource(struct vm *vm);
120+
void allow_guest_io_access(struct vm *vm, uint32_t address, uint32_t nbytes);
121+
void register_io_emulation_handler(struct vm *vm, struct vm_io_range *range,
122+
io_read_fn_t io_read_fn_ptr,
123+
io_write_fn_t io_write_fn_ptr);
124+
int dm_emulate_pio_post(struct vcpu *vcpu);
125+
126+
int register_mmio_emulation_handler(struct vm *vm,
127+
hv_mem_io_handler_t read_write, uint64_t start,
128+
uint64_t end, void *handler_private_data);
129+
void unregister_mmio_emulation_handler(struct vm *vm, uint64_t start,
130+
uint64_t end);
131+
int dm_emulate_mmio_post(struct vcpu *vcpu);
132+
133+
int32_t acrn_insert_request_wait(struct vcpu *vcpu, struct vhm_request *req);
134+
135+
#endif /* IOREQ_H */

hypervisor/include/arch/x86/mmu.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,6 @@ static inline void mem_write64(void *addr, uint64_t data)
303303
*addr64 = data;
304304
}
305305

306-
/* Typedef for MMIO handler and range check routine */
307-
typedef int(*hv_mem_io_handler_t)(struct vcpu *, struct mem_io *, void *);
308-
309-
/* Structure for MMIO handler node */
310-
struct mem_io_node {
311-
hv_mem_io_handler_t read_write;
312-
void *handler_private_data;
313-
struct list_head list;
314-
uint64_t range_start;
315-
uint64_t range_end;
316-
};
317-
318306
uint64_t get_paging_pml4(void);
319307
bool check_mmu_1gb_support(enum _page_table_type page_table_type);
320308
void *alloc_paging_struct(void);
@@ -342,13 +330,6 @@ int obtain_last_page_table_entry(struct map_params *map_params,
342330
uint64_t *lookup_address(uint64_t *pml4_page, uint64_t addr,
343331
uint64_t *pg_size, enum _page_table_type ptt);
344332

345-
int register_mmio_emulation_handler(struct vm *vm,
346-
hv_mem_io_handler_t read_write, uint64_t start,
347-
uint64_t end, void *handler_private_data);
348-
349-
void unregister_mmio_emulation_handler(struct vm *vm, uint64_t start,
350-
uint64_t end);
351-
352333
#pragma pack(1)
353334

354335
/** Defines a single entry in an E820 memory map. */
@@ -411,7 +392,6 @@ int ept_mr_del(struct vm *vm, uint64_t *pml4_page,
411392

412393
int ept_violation_vmexit_handler(struct vcpu *vcpu);
413394
int ept_misconfig_vmexit_handler(struct vcpu *vcpu);
414-
int dm_emulate_mmio_post(struct vcpu *vcpu);
415395

416396
#endif /* ASSEMBLER not defined */
417397

0 commit comments

Comments
 (0)