hv:io: wrap mmio read/write
When guest traps and wants to access a mmio region, the ACRN hypervisor doesn't know the mmio size the guest wants to access until the trap happens. In this case, ACRN should switch the mmio size and then call mmio_read8/16/32/64 or mmio_write8/16/32/64 in each trap place. This patch wrap the mmio read/write with a parameter to assign the mmio size. Tracked-On: #8255 Signed-off-by: Fei Li <fei1.li@intel.com>
This commit is contained in:
parent
c76f26bdad
commit
65454730de
|
@ -166,4 +166,42 @@ static inline uint8_t mmio_read8(const void *addr)
|
|||
return *((volatile const uint8_t *)addr);
|
||||
}
|
||||
|
||||
static inline uint64_t mmio_read(const void *addr, uint64_t sz)
|
||||
{
|
||||
uint64_t val;
|
||||
switch (sz) {
|
||||
case 1U:
|
||||
val = (uint64_t)mmio_read8(addr);
|
||||
break;
|
||||
case 2U:
|
||||
val = (uint64_t)mmio_read16(addr);
|
||||
break;
|
||||
case 4U:
|
||||
val = (uint64_t)mmio_read32(addr);
|
||||
break;
|
||||
default:
|
||||
val = mmio_read64(addr);
|
||||
break;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline void mmio_write(void *addr, uint64_t sz, uint64_t val)
|
||||
{
|
||||
switch (sz) {
|
||||
case 1U:
|
||||
mmio_write8((uint8_t)val, addr);
|
||||
break;
|
||||
case 2U:
|
||||
mmio_write16((uint16_t)val, addr);
|
||||
break;
|
||||
case 4U:
|
||||
mmio_write32((uint32_t)val, addr);
|
||||
break;
|
||||
default:
|
||||
mmio_write64(val, addr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _IO_H defined */
|
||||
|
|
Loading…
Reference in New Issue