Skip to content

Commit 1c0d7f7

Browse files
KaigeFuacrnsi
authored andcommitted
HV: HV: make io_read_fn_t return true or false
This patch makes io_read_fn_t return true or false instead of void. Returning true means that the handler in HV process the request completely. Returning false means that we need to re-inject the request to DM after processing it in HV. Tracked-On: #2865 Signed-off-by: Kaige Fu <kaige.fu@intel.com>
1 parent 3b2ad67 commit 1c0d7f7

File tree

7 files changed

+54
-31
lines changed

7 files changed

+54
-31
lines changed

hypervisor/arch/x86/guest/io_emul.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static void dm_emulate_io_complete(struct acrn_vcpu *vcpu)
196196
* @retval -EIO The request spans multiple devices and cannot be emulated.
197197
*/
198198
static int32_t
199-
hv_emulate_pio(const struct acrn_vcpu *vcpu, struct io_request *io_req)
199+
hv_emulate_pio(struct acrn_vcpu *vcpu, struct io_request *io_req)
200200
{
201201
int32_t status = -ENODEV;
202202
uint16_t port, size;
@@ -215,6 +215,8 @@ hv_emulate_pio(const struct acrn_vcpu *vcpu, struct io_request *io_req)
215215
continue;
216216
}
217217

218+
status = 0;
219+
218220
if (pio_req->direction == REQUEST_WRITE) {
219221
if (handler->io_write != NULL) {
220222
if (!(handler->io_write(vm, port, size, pio_req->value))) {
@@ -228,11 +230,16 @@ hv_emulate_pio(const struct acrn_vcpu *vcpu, struct io_request *io_req)
228230
pr_dbg("IO write on port %04x, data %08x", port, pio_req->value);
229231
} else {
230232
if (handler->io_read != NULL) {
231-
pio_req->value = handler->io_read(vm, port, size);
233+
if (!(handler->io_read(vm, vcpu, port, size))) {
234+
/*
235+
* If io_read return false, it indicates that we need continue
236+
* to emulate in DM.
237+
*/
238+
status = -ENODEV;
239+
}
232240
}
233241
pr_dbg("IO read on port %04x, data %08x", port, pio_req->value);
234242
}
235-
status = 0;
236243
break;
237244
}
238245

hypervisor/arch/x86/guest/pm.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,13 @@ static inline uint8_t get_slp_typx(uint32_t pm1_cnt)
121121
return (uint8_t)((pm1_cnt & 0x1fffU) >> BIT_SLP_TYPx);
122122
}
123123

124-
static uint32_t pm1ab_io_read(__unused struct acrn_vm *vm, uint16_t addr, size_t width)
124+
static bool pm1ab_io_read(__unused struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t addr, size_t width)
125125
{
126-
return pio_read(addr, width);
126+
struct pio_request *pio_req = &vcpu->req.reqs.pio;
127+
128+
pio_req->value = pio_read(addr, width);
129+
130+
return true;
127131
}
128132

129133
static inline void enter_s3(struct acrn_vm *vm, uint32_t pm1a_cnt_val, uint32_t pm1b_cnt_val)

hypervisor/debug/vuart.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,13 @@ static bool vuart_write(struct acrn_vm *vm, uint16_t offset_arg,
248248
return true;
249249
}
250250

251-
static uint32_t vuart_read(struct acrn_vm *vm, uint16_t offset_arg,
251+
static bool vuart_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t offset_arg,
252252
__unused size_t width)
253253
{
254254
uint16_t offset = offset_arg;
255255
uint8_t iir, reg, intr_reason;
256256
struct acrn_vuart *vu = vm_vuart(vm);
257+
struct pio_request *pio_req = &vcpu->req.reqs.pio;
257258

258259
offset -= vu->base;
259260
vuart_lock(vu);
@@ -323,8 +324,10 @@ static uint32_t vuart_read(struct acrn_vm *vm, uint16_t offset_arg,
323324
}
324325
done:
325326
vuart_toggle_intr(vu);
327+
pio_req->value = (uint32_t)reg;
326328
vuart_unlock(vu);
327-
return (uint32_t)reg;
329+
330+
return true;
328331
}
329332

330333
static void vuart_register_io_handler(struct acrn_vm *vm)

hypervisor/dm/vpci/vpci.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ static void pci_cfg_clear_cache(struct pci_addr_info *pi)
4343
}
4444

4545
/**
46-
* @pre vm != NULL
46+
* @pre vm != NULL && vcpu != NULL
4747
*/
48-
static uint32_t pci_cfgaddr_io_read(struct acrn_vm *vm, uint16_t addr, size_t bytes)
48+
static bool pci_cfgaddr_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t addr, size_t bytes)
4949
{
5050
uint32_t val = ~0U;
5151
struct acrn_vpci *vpci = &vm->vpci;
5252
struct pci_addr_info *pi = &vpci->addr_info;
53+
struct pio_request *pio_req = &vcpu->req.reqs.pio;
5354

5455
if ((addr == (uint16_t)PCI_CONFIG_ADDR) && (bytes == 4U)) {
5556
val = (uint32_t)pi->cached_bdf.value;
@@ -60,7 +61,9 @@ static uint32_t pci_cfgaddr_io_read(struct acrn_vm *vm, uint16_t addr, size_t by
6061
}
6162
}
6263

63-
return val;
64+
pio_req->value = val;
65+
66+
return true;
6467
}
6568

6669
/**
@@ -96,17 +99,18 @@ static inline bool vpci_is_valid_access(uint32_t offset, uint32_t bytes)
9699
}
97100

98101
/**
99-
* @pre vm != NULL
102+
* @pre vm != NULL && vcpu != NULL
100103
* @pre vm->vm_id < CONFIG_MAX_VM_NUM
101104
* @pre (get_vm_config(vm->vm_id)->type == PRE_LAUNCHED_VM) || (get_vm_config(vm->vm_id)->type == SOS_VM)
102105
*/
103-
static uint32_t pci_cfgdata_io_read(struct acrn_vm *vm, uint16_t addr, size_t bytes)
106+
static bool pci_cfgdata_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t addr, size_t bytes)
104107
{
105108
struct acrn_vpci *vpci = &vm->vpci;
106109
struct pci_addr_info *pi = &vpci->addr_info;
107110
uint16_t offset = addr - PCI_CONFIG_DATA;
108111
uint32_t val = ~0U;
109112
struct acrn_vm_config *vm_config;
113+
struct pio_request *pio_req = &vcpu->req.reqs.pio;
110114

111115
if (pi->cached_enable) {
112116
if (vpci_is_valid_access(pi->cached_reg + offset, bytes)) {
@@ -129,7 +133,9 @@ static uint32_t pci_cfgdata_io_read(struct acrn_vm *vm, uint16_t addr, size_t by
129133
pci_cfg_clear_cache(pi);
130134
}
131135

132-
return val;
136+
pio_req->value = val;
137+
138+
return true;
133139
}
134140

135141
/**

hypervisor/dm/vpic.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -728,15 +728,16 @@ static int32_t vpic_master_handler(struct acrn_vm *vm, bool in, uint16_t port,
728728
return ret;
729729
}
730730

731-
static uint32_t vpic_master_io_read(struct acrn_vm *vm, uint16_t addr, size_t width)
731+
static bool vpic_master_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t addr, size_t width)
732732
{
733-
uint32_t val = 0U;
733+
struct pio_request *pio_req = &vcpu->req.reqs.pio;
734734

735-
if (vpic_master_handler(vm, true, addr, width, &val) < 0) {
735+
if (vpic_master_handler(vm, true, addr, width, &pio_req->value) < 0) {
736736
pr_err("pic master read port 0x%x width=%d failed\n",
737737
addr, width);
738738
}
739-
return val;
739+
740+
return true;
740741
}
741742

742743
static bool vpic_master_io_write(struct acrn_vm *vm, uint16_t addr, size_t width,
@@ -773,15 +774,15 @@ static int32_t vpic_slave_handler(struct acrn_vm *vm, bool in, uint16_t port,
773774
return ret;
774775
}
775776

776-
static uint32_t vpic_slave_io_read(struct acrn_vm *vm, uint16_t addr, size_t width)
777+
static bool vpic_slave_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t addr, size_t width)
777778
{
778-
uint32_t val = 0U;
779+
struct pio_request *pio_req = &vcpu->req.reqs.pio;
779780

780-
if (vpic_slave_handler(vm, true, addr, width, &val) < 0) {
781+
if (vpic_slave_handler(vm, true, addr, width, &pio_req->value) < 0) {
781782
pr_err("pic slave read port 0x%x width=%d failed\n",
782783
addr, width);
783784
}
784-
return val;
785+
return true;
785786
}
786787

787788
static bool vpic_slave_io_write(struct acrn_vm *vm, uint16_t addr, size_t width,
@@ -843,14 +844,15 @@ static int32_t vpic_elc_handler(struct acrn_vm *vm, bool in, uint16_t port, size
843844
return ret;
844845
}
845846

846-
static uint32_t vpic_elc_io_read(struct acrn_vm *vm, uint16_t addr, size_t width)
847+
static bool vpic_elc_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t addr, size_t width)
847848
{
848-
uint32_t val = 0U;
849+
struct pio_request *pio_req = &vcpu->req.reqs.pio;
849850

850-
if (vpic_elc_handler(vm, true, addr, width, &val) < 0) {
851+
if (vpic_elc_handler(vm, true, addr, width, &pio_req->value) < 0) {
851852
pr_err("pic elc read port 0x%x width=%d failed", addr, width);
852853
}
853-
return val;
854+
855+
return true;
854856
}
855857

856858
static bool vpic_elc_io_write(struct acrn_vm *vm, uint16_t addr, size_t width,

hypervisor/dm/vrtc.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@ static uint8_t cmos_get_reg_val(uint8_t addr)
4343
return reg;
4444
}
4545

46-
static uint32_t vrtc_read(struct acrn_vm *vm, uint16_t addr, __unused size_t width)
46+
static bool vrtc_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t addr, __unused size_t width)
4747
{
48-
uint8_t reg;
4948
uint8_t offset;
49+
struct pio_request *pio_req = &vcpu->req.reqs.pio;
5050

5151
offset = vm->vrtc_offset;
5252

5353
if (addr == CMOS_ADDR_PORT) {
54-
return vm->vrtc_offset;
54+
pio_req->value = vm->vrtc_offset;
55+
} else {
56+
pio_req->value = cmos_get_reg_val(offset);
5557
}
5658

57-
reg = cmos_get_reg_val(offset);
58-
return reg;
59+
return true;
5960
}
6061

6162
static bool vrtc_write(struct acrn_vm *vm, uint16_t addr, size_t width,

hypervisor/include/arch/x86/io_req.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct acrn_vm;
4949
struct acrn_vcpu;
5050

5151
typedef
52-
uint32_t (*io_read_fn_t)(struct acrn_vm *vm, uint16_t port, size_t size);
52+
bool (*io_read_fn_t)(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t port, size_t size);
5353

5454
typedef
5555
bool (*io_write_fn_t)(struct acrn_vm *vm, uint16_t port, size_t size, uint32_t val);

0 commit comments

Comments
 (0)