Implement qword CPU access to device MMIO regions
RFC 1/1 Implement qword CPU access to device MMIO regions
From: Max Filippov <[email protected]>
For newly developed device verification we need to be able to distinguish qword and dword access to its MMIO regions from CPU.
This goal is achieved with the following steps:
- io_mem_read[3] and io_mem_write[3] are used for the ldq/stq callbacks;
- softmmu io_read and io_write templates invoke these callbacks for 64 bit wide access if they are defined;
- new registration method (cpu_register_io_memory2) is defined for the devices that provide 64 bit wide MMIO access.
This implementation maintains backwards compatibility for the devices that provide only 8-16-32 bit io memory access callbacks, allowing wider access callbacks to be registered via cpu_register_io_memory2.
Legacy behavior of emulating 64 bit access via two adjacent 32 bit accesses holds both for devices registered via cpu_register_io_memory and for those registered via cpu_register_io_memory2 that do not provide 64 bit callbacks.
This implementation is developed for pre-memory API QEMU version. If this approach proves to be useful I will port it to the new memory API.
--- cpu-common.h | 23 +++++++++- exec.c | 132 ++++++++++++++++++++++++++++++++++++++++------------ softmmu_template.h | 10 ++++ 3 files changed, 134 insertions(+), 31 deletions(-)
cpu-common.h +22 -1
@@ -35,8 +35,26 @@ typedef unsigned long ram_addr_t;/* memory API */ -typedef void CPUWriteMemoryFunc (void *opaque,target_phys_addr_t addr,uint32_t value); +typedef void CPUWriteMemoryFunc (void *opaque,target_phys_addr_t addr, +uint32_t value); +typedef void CPUWriteMemoryFunc64 (void *opaque,target_phys_addr_t addr, +uint64_t value);typedef uint32_t CPUReadMemoryFunc (void *opaque,target_phys_addr_t addr); +typedef uint64_t CPUReadMemoryFunc64 (void *opaque,target_phys_addr_t addr); + +enum { +IO_MEM_FUNC32_NUM =3 , +IO_MEM_FUNC_NUM =4 , +}; +typedef struct CPUWriteMemoryFuncs { +CPUWriteMemoryFunc * func32[IO_MEM_FUNC32_NUM ]; +CPUWriteMemoryFunc64 *func64; +}CPUWriteMemoryFuncs ; + +typedef struct CPUReadMemoryFuncs { +CPUReadMemoryFunc * func32[IO_MEM_FUNC32_NUM ]; +CPUReadMemoryFunc64 *func64; +}CPUReadMemoryFuncs ; void cpu_register_physical_memory_log(target_phys_addr_t start_addr, ram_addr_t size,
@@ -81,6 +99,9 @@ ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr);int cpu_register_io_memory (CPUReadMemoryFunc *const *mem_read,CPUWriteMemoryFunc *const *mem_write,void *opaque,enum device_endian endian); +int cpu_register_io_memory2 (const CPUReadMemoryFuncs *mem_read, +const CPUWriteMemoryFuncs *mem_write, +void *opaque,enum device_endian endian);void cpu_unregister_io_memory (int table_address); void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
exec.c +102 -30
248 lines not on this page · raw message
softmmu_template.h +10 -0
@@ -74,6 +74,10 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr,#if SHIFT <=2 res = io_mem_read[index][SHIFT ](io_mem_opaque[index], physaddr);#else +if (io_mem_read[index][3 ]) { + res = ((CPUReadMemoryFunc64 *) + io_mem_read[index][3 ])(io_mem_opaque[index], physaddr); + }else {#ifdef TARGET_WORDS_BIGENDIAN res = (uint64_t )io_mem_read[index][2 ](io_mem_opaque[index], physaddr) <<32 ; res |= io_mem_read[index][2 ](io_mem_opaque[index], physaddr +4 );
@@ -81,6 +85,7 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr, res = io_mem_read[index][2 ](io_mem_opaque[index], physaddr); res |= (uint64_t )io_mem_read[index][2 ](io_mem_opaque[index], physaddr +4 ) <<32 ; #endif + }#endif /* SHIFT > 2 */ return res; }
@@ -217,6 +222,10 @@ static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr,#if SHIFT <=2 io_mem_write[index][SHIFT ](io_mem_opaque[index], physaddr, val);#else +if (io_mem_write[index][3 ]) { + ((CPUWriteMemoryFunc64 *) + io_mem_write[index][3 ])(io_mem_opaque[index], physaddr, val); + }else {#ifdef TARGET_WORDS_BIGENDIAN io_mem_write[index][2 ](io_mem_opaque[index], physaddr, val >>32 ); io_mem_write[index][2 ](io_mem_opaque[index], physaddr +4 , val);
@@ -224,6 +233,7 @@ static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr, io_mem_write[index][2 ](io_mem_opaque[index], physaddr, val); io_mem_write[index][2 ](io_mem_opaque[index], physaddr +4 , val >>32 ); #endif + }#endif /* SHIFT > 2 */ }
Signature · 1 line
1.7.2.5