Kill old-style I/O dispatch
cover Kill old-style I/O dispatch
This patchset removes I/O dispatch through CPU{Read,Write}Func and replaces it with direct dispatch through MemoryRegions (except for MemoryRegionOps::old_mmio, of course).
Avi Kivity (16):
memory: move endianness compensation to memory core
exec: make phys_page_find() return a temporary
memory: move mmio access to functions
memory: remove MemoryRegion::backend_registered
Fix wrong region_offset when overlaying a page with another Avoid range comparisons on io index types
Uninline get_page_addr_code()
Convert IO_MEM_{RAM,ROM,UNASSIGNED,NOTDIRTY} to MemoryRegions Switch cpu_register_physical_memory_log() to use MemoryRegions Convert the subpage wrapper to be a MemoryRegion Convert IO_MEM_SUBPAGE_RAM to be a MemoryRegion Convert io_mem_watch to be a MemoryRegion
Direct dispatch through MemoryRegion
Remove IO_MEM_SUBPAGE
Drop IO_MEM_ROMD
Remove IO_MEM_SHIFT
cpu-all.h | 2 +- cpu-common.h | 15 +- exec-all.h | 33 +-- exec-obsolete.h | 29 +-- exec.c | 889 ++++++++++++++++++---------------------------------- memory.c | 188 +++++------- memory.h | 3 +- softmmu_template.h | 33 ++- 8 files changed, 418 insertions(+), 774 deletions(-)
Signature · 1 line
1.7.7.1
PATCH 1/16 memory: move endianness compensation to memory core
Instead of doing device endianness compensation in cpu_register_io_memory(), do it in the memory core.
--- exec-obsolete.h | 2 +- exec.c | 142 ++++--------------------------------------------------- memory.c | 37 ++++++++++++-- 3 files changed, 41 insertions(+), 140 deletions(-)
exec-obsolete.h +1 -1
@@ -33,7 +33,7 @@ void qemu_ram_free_from_ptr(ram_addr_t addr);int cpu_register_io_memory (CPUReadMemoryFunc *const *mem_read,CPUWriteMemoryFunc *const *mem_write, -void *opaque,enum device_endian endian); +void *opaque);void cpu_unregister_io_memory (int table_address); void cpu_register_physical_memory_log(target_phys_addr_t start_addr,
exec.c +9 -133
191 lines not on this page · raw message
memory.c +31 -6
@@ -857,6 +857,15 @@ static void memory_region_destructor_rom_device(MemoryRegion *mr)cpu_unregister_io_memory (mr->ram_addr & ~(TARGET_PAGE_MASK |IO_MEM_ROMD )); } +static bool memory_region_wrong_endianness (MemoryRegion *mr) +{ +#ifdef TARGET_BIG_ENDIAN +return mr->ops->endianness ==DEVICE_LITTLE_ENDIAN ; +#else +return mr->ops->endianness ==DEVICE_BIG_ENDIAN ; +#endif +} +void memory_region_init (MemoryRegion *mr,const char *name,uint64_t size)
@@ -967,12 +976,24 @@ static uint32_t memory_region_read_thunk_b(void *mr, target_phys_addr_t addr)static uint32_t memory_region_read_thunk_w (void *mr,target_phys_addr_t addr) { -return memory_region_read_thunk_n (mr, addr,2 ); +uint32_t data; + + data =memory_region_read_thunk_n (mr, addr,2 ); +if (memory_region_wrong_endianness (mr)) { + data =bswap16 (data); + } +return data; }static uint32_t memory_region_read_thunk_l (void *mr,target_phys_addr_t addr) { -return memory_region_read_thunk_n (mr, addr,4 ); +uint32_t data; + + data =memory_region_read_thunk_n (mr, addr,4 ); +if (memory_region_wrong_endianness (mr)) { + data =bswap32 (data); + } +return data; } static void memory_region_write_thunk_b(void *mr, target_phys_addr_t addr,
@@ -984,12 +1005,18 @@ static void memory_region_write_thunk_b(void *mr, target_phys_addr_t addr,static void memory_region_write_thunk_w (void *mr,target_phys_addr_t addr,uint32_t data) { +if (memory_region_wrong_endianness (mr)) { + data =bswap16 (data); + }memory_region_write_thunk_n (mr, addr,2 , data); }static void memory_region_write_thunk_l (void *mr,target_phys_addr_t addr,uint32_t data) { +if (memory_region_wrong_endianness (mr)) { + data =bswap32 (data); + }memory_region_write_thunk_n (mr, addr,4 , data); }
@@ -1014,8 +1041,7 @@ static void memory_region_prepare_ram_addr(MemoryRegion *mr) mr->destructor = memory_region_destructor_iomem; mr->ram_addr =cpu_register_io_memory (memory_region_read_thunk, memory_region_write_thunk, - mr, - mr->ops->endianness); + mr); mr->backend_registered = true; }
@@ -1082,8 +1108,7 @@ void memory_region_init_rom_device(MemoryRegion *mr, mr->ram_addr =qemu_ram_alloc (size, mr); mr->ram_addr |=cpu_register_io_memory (memory_region_read_thunk, memory_region_write_thunk, - mr, - mr->ops->endianness); + mr); mr->ram_addr |=IO_MEM_ROMD ; mr->backend_registered = true; }
Signature · 1 line
1.7.7.1
Re: [Qemu-devel] [PATCH 01/16] memory: move endianness compensation to memory core
Am 02.01.2012 17:33, schrieb Avi Kivity:
Quoted 4 lines
Instead of doing device endianness compensation in
cpu_register_io_memory(), do it in the memory core.Signed-off-by Avi Kivity <[email protected]>
This further broke PReP boot (Etch 2.4.x kernel):
be675c972088eba210e18dc125613e9f205a6bfb is the first bad commit commit be675c972088eba210e18dc125613e9f205a6bfb
Author: Avi Kivity <[email protected]> Date: Sun Nov 20 16:22:55 2011 +0200
memory: move endianness compensation to memory core
Instead of doing device endianness compensation incpu_register_io_memory(),
do it in the memory core.
:100644 100644 698d7fc4118edc71f00de6f87908bb4031df5b5a79f989c65469ad068448f334b692b7ed60f1704a M exec-obsolete.h
:100644 100644 28c057c08671a8b6bfa90d94e873460bda7afa69507d37c61761d71d8b39d0073724ceb0200ff6d4 M exec.c
:100644 100644 868ffd0bc5a1eea7a6f9deb9d6d39f689b89e0146f9fea15ad1890c63c285fd62e72b8614030dd4f M memory.c
My wild guess is that prep_pci.c is swapping too much or not enough now. The bswap calls in the native-endian PCIIO there look fishy.
Andreas
register PCI host 'pci-bridge' 'pci' '<null>' 'PREP Host PCI Bridge - Motorola Raven'
register 'pci-bridge' 'pci' '<null>' 'PREP Host PCI Bridge - Motorola Raven' 0x80000000 in 'device-tree' 0xffffffff
Done 582b000 582b880
PCI device '<null>' 0 11 0 has no reg properties:
PCI device '<null>' 0 11 0 has no assigned addresses properties:
register pci device 'Qemu VGA' 0000000c 'display' 'VGA' 'Qemu VGA' register 'Qemu VGA' 'display' 'VGA' 'Qemu VGA' 0x0000000c in 'pci-bridge' 0x80000000
Done 582b880 582b980
PCI device 'Qemu VGA' 0 12 0 reg properties:
addr: 82006010 00000000 f0000000 size: 00000000 00800000
PCI device 'Qemu VGA' 0 12 0 assigned addresses properties:
addr: 82006010 00000000 f0000000 size: 00000000 00800000
PPC Open Hack'Ware BIOS for qemu version 0.4.1
Build 2007-10-01 06:42:47
Copyright 2003-2005 Jocelyn Mayer
Memory size: 256 MB.
Booting from device m
ide0: drive 0: Hard Disk
ERROR: OF_property_copy cannot get property 'hd' for aliases
ERROR: WIN_READ_NATIVE_MAX : status 50 != 0x40
ide0: drive 1: none
ide1: drive 0: CD-ROM
ERROR: OF_property_copy cannot get property 'cd' for aliases
ERROR: ATAPI TEST_UNIT_READY : status 41 != 0x40
ide1: drive 1: none
Probe partitions for device m
ERROR: No MSDOS signature (38 0 0 0)
Use bloc device as raw partition
Boot partition: 0 9401fff8 9401fff8 0
ERROR: OF_property_copy cannot get property 'alias' for <null> boot device: 5832080 image 1000000 size 1266665
Probe filesystem on unknown PREP partition 'PREP boot' (bootable) 5832100 Fix bootfile
Partition is bootable (0)bd_set_boot_part: part 5832100 (0) 0
Boot partition: 5832100 582e400 582e400 0
boot device: 5832080
ERROR: Found boot partition : 5832100 582e400
ERROR: Not a MACH-O file
ERROR: Not an Apple CHRP boot file !
dest 100000 entry 00000200 => 100200
Load raw file into memory at 100000 1266665 (001353e9) 0 (00000000)
Boot: 00040000 e9531300 00000000 00000000
Bootinfos at : 300000
Now boot it... (0)
stack: 5bfff80 malloc_base: 0 0x05800000 0x06000000 PREP boot... 100200 100000
loaded at: 00100200 0023DDE8 relocated to: 00800000 0093DBE8 board data at: 05837000 0583DA0C relocated to: 0093414C 0093AB58 zimage at: 00805B9C 00933AC6 avail ram: 00400000 00800000
Linux/PPC load: ide0=0x1f0,0x3f6,13 ide1=0x170,0x376,13 netdev=9,0x300,eth0 console=ttyS0 console=tty0 root=/dev/hda3 ro Uncompressing Linux...done.
Now booting the kernel
Memory BAT mapping: BAT2=256Mb, BAT3=0Mb, residual: 0Mb Total memory = 256MB; using 512kB for hash table (at c0300000) Linux version 2.4.36.1 (root@debianppc) (gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)) #3 Thu Feb 21 10:14:55 CET 2008 PReP architecture
On node 0 totalpages: 65536
zone(0): 65536 pages.
zone(1): 0 pages.
zone(2): 0 pages.
Kernel command line: ide0=0x1f0,0x3f6,13 ide1=0x170,0x376,13 netdev=9,0x300,eth0 console=ttyS0 console=tty0 root=/dev/hda3 roide_setup: ide0=0x1f0,0x3f6,13
ide_setup: ide1=0x170,0x376,13
time_init: decrementer frequency = 28.252727 MHz
Warning: real time clock seems stuck!
Console: colour dummy device 80x25
Calibrating delay loop... 251.49 BogoMIPS
Memory: 255232k available (2052k kernel code, 816k data, 168k init, 0k highmem)
Dentry cache hash table entries: 32768 (order: 6, 262144 bytes) Inode cache hash table entries: 16384 (order: 5, 131072 bytes) Mount cache hash table entries: 512 (order: 0, 4096 bytes) Buffer cache hash table entries: 16384 (order: 4, 65536 bytes) Page-cache hash table entries: 65536 (order: 6, 262144 bytes) POSIX conformance testing by UNIFIX
PCI: Probing PCI hardware
Setting PCI interrupts for a "Mesquite cPCI (MCP750)"
PCI: Cannot allocate resource region 0 of device 00:0c.0
PCI: moved device 00:0c.0 resource 0 (1208) to 0
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039 Initializing RT netlink socket
Starting kswapd
Journalled Block Device driver loaded
Installing knfsd (copyright (C) 1996 [email protected]).
udf: registering filesystem
vga16fb: mapped to 0xf00a0000
Console: switching to colour frame buffer device 80x30
fb0: VGA16 VGA frame buffer device
pty: 256 Unix98 ptys configured
Serial driver version 5.05c (2001-07-08) with MANY_PORTS SHARE_IRQ SERIAL_PCI enabled
ttyS00 at 0x03f8 (irq = 4) is a 16550A
rtc: I/O resource 70 is not free.
Generic RTC Driver v1.07
Floppy drive(s): fd0 is 2.88M
FDC 0 is a S82078B
ne.c:v1.10 9/23/94 Donald Becker ([email protected])
Last modified Nov 1, 2000 by Paul Gortmaker
NE*000 ethercard probe at 0x300: 52 54 00 12 34 56
eth0: NE2000 found at 0x300, using IRQ 9.
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
loop: loaded (max 8 devices)
PPP generic driver version 2.4.2
PPP Deflate Compression module registered
PPP BSD Compression module registered
Universal TUN/TAP device driver 1.5 (C)1999-2002 Maxim Krasnyansky Uniform Multi-Platform E-IDE driver Revision: 7.00beta4-2.4
ide: Assuming 33MHz system bus speed for PIO modes; override with idebus=xx Probing IDE interface ide0...
hda: EQUMH RADDSI K, ATA DISK drive
Probing IDE interface ide1...
hdc: EQUMD DVR-MO, ATAPI cdrom or floppy?, assuming FLOPPY drive Probing IDE interface ide2...
ide2: Wait for ready failed before probe !
Probing IDE interface ide3...
ide3: Wait for ready failed before probe !
ide0 at 0x1f0-0x1f7,0x3f6 on irq 13
ide1 at 0x170-0x177,0x376 on irq 13 (shared with ide0)
hda: attached ide-disk driver.
hda: 0 sectors (0 MB) w/1KiB Cache, CHS=24856/0/0
hda: INVALID GEOMETRY: 0 PHYSICAL HEADS?
Partition check:
hdc:end_request: I/O error, dev 16:00 (hdc), sector 0end_request: I/O error, dev 16:00 (hdc), sector 2end_request: I/O error, dev 16:00 (hdc), sector 4end_request: I/O error, dev 16:00 (hdc), sector 6end_request: I/O error, dev 16:00 (hdc), sector 0end_request: I/O error, dev 16:00 (hdc), sector 2end_request: I/O error, dev 16:00 (hdc), sector 4end_request: I/O error, dev 16:00 (hdc), sector 6
unable to read partition table
Macintosh non-volatile memory driver v1.0
mice: PS/2 mouse device common for all mice
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP, IGMP
IP: routing cache hash table of 2048 buckets, 16Kbytes
TCP: Hash tables configured (established 16384 bind 32768)
NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.
hda3: bad access: block=2, count=2end_request: I/O error, dev 03:03 (hda), sector 2
EXT3-fs: unable to read superblock
hda3: bad access: block=2, count=2end_request: I/O error, dev 03:03 (hda), sector 2
EXT2-fs: unable to read superblock
hda3: bad access: block=0, count=8end_request: I/O error, dev 03:03 (hda), sector 0
hda3: bad access: block=2, count=6end_request: I/O error, dev 03:03 (hda), sector 2
hda3: bad access: block=4, count=4end_request: I/O error, dev 03:03 (hda), sector 4
hda3: bad access: block=6, count=2end_request: I/O error, dev 03:03 (hda), sector 6
hda3: bad access: block=0, count=16end_request: I/O error, dev 03:03 (hda), sector 0
hda3: bad access: block=2, count=14end_request: I/O error, dev 03:03 (hda), sector 2
hda3: bad access: block=4, count=12end_request: I/O error, dev 03:03 (hda), sector 4
hda3: bad access: block=6, count=10end_request: I/O error, dev 03:03 (hda), sector 6
hda3: bad access: block=8, count=8end_request: I/O error, dev 03:03 (hda), sector 8
hda3: bad access: block=10, count=6end_request: I/O error, dev 03:03 (hda), sector 10
hda3: bad access: block=12, count=4end_request: I/O error, dev 03:03 (hda), sector 12
hda3: bad access: block=14, count=2end_request: I/O error, dev 03:03 (hda), sector 14
hda3: bad access: block=8, count=16end_request: I/O error, dev 03:03 (hda), sector 8
hda3: bad access: block=10, count=14end_request: I/O error, dev 03:03 (hda), sector 10
hda3: bad access: block=12, count=12end_request: I/O error, dev 03:03 (hda), sector 12
hda3: bad access: block=14, count=10end_request: I/O error, dev 03:03 (hda), sector 14
hda3: bad access: block=16, count=8end_request: I/O error, dev 03:03 (hda), sector 16
hda3: bad access: block=18, count=6end_request: I/O error, dev 03:03 (hda), sector 18
hda3: bad access: block=20, count=4end_request: I/O error, dev 03:03 (hda), sector 20
hda3: bad access: block=22, count=2end_request: I/O error, dev 03:03 (hda), sector 22
hda3: bad access: block=16, count=16end_request: I/O error, dev 03:03 (hda), sector 16
hda3: bad access: block=18, count=14end_request: I/O error, dev 03:03 (hda), sector 18
hda3: bad access: block=20, count=12end_request: I/O error, dev 03:03 (hda), sector 20
hda3: bad access: block=22, count=10end_request: I/O error, dev 03:03 (hda), sector 22
hda3: bad access: block=24, count=8end_request: I/O error, dev 03:03 (hda), sector 24
hda3: bad access: block=26, count=6end_request: I/O error, dev 03:03 (hda), sector 26
hda3: bad access: block=28, count=4end_request: I/O error, dev 03:03 (hda), sector 28
hda3: bad access: block=30, count=2end_request: I/O error, dev 03:03 (hda), sector 30
hda3: bad access: block=24, count=8end_request: I/O error, dev 03:03 (hda), sector 24
hda3: bad access: block=26, count=6end_request: I/O error, dev 03:03 (hda), sector 26
hda3: bad access: block=28, count=4end_request: I/O error, dev 03:03 (hda), sector 28
hda3: bad access: block=30, count=2end_request: I/O error, dev 03:03 (hda), sector 30
cramfs: wrong magic
hda3: bad access: block=0, count=1end_request: I/O error, dev 03:03 (hda), sector 0
FAT: unable to read boot sector
hda3: bad access: block=0, count=1end_request: I/O error, dev 03:03 (hda), sector 0
FAT: unable to read boot sector
hda3: bad access: block=64, count=2end_request: I/O error, dev 03:03 (hda), sector 64isofs_read_super: bread failed, dev=03:03, iso_blknum=16, block=32
hda3: bad access: block=2, count=1end_request: I/O error, dev 03:03 (hda), sector 2
HFS+-fs: unable to read VHDR or MDB
hda3: bad access: block=2, count=1end_request: I/O error, dev 03:03 (hda), sector 2hfs_fs: unable to read block 0x00000002 from dev 03:03hfs_fs: Unable to read superblock
hda3: bad access: block=0, count=1end_request: I/O error, dev 03:03 (hda), sector 0hfs_fs: unable to read block 0x00000000 from dev 03:03hfs_fs: Unable to read block 0.
You didn't specify the type of your ufs filesystem
mount -t ufs -o ufstype=sun|sunx86|44bsd|old|hp|nextstep|netxstep-cd|openstep ...
Quoted 1 line
Quoted 1 line
Quoted 1 line
WARNING<<< Wrong ufstype may corrupt your filesystem, default is
ufstype=old
hda3: bad access: block=16, count=2end_request: I/O error, dev 03:03 (hda), sector 16
hda3: bad access: block=0, count=2end_request: I/O error, dev 03:03 (hda), sector 0
romfs: unable to read superblock
hda3: bad access: block=64, count=4end_request: I/O error, dev 03:03 (hda), sector 64
hda3: bad access: block=1248, count=4end_request: I/O error, dev 03:03 (hda), sector 1248
hda3: bad access: block=1024, count=4end_request: I/O error, dev 03:03 (hda), sector 1024
UDF-fs: No partition found (1)
Kernel panic: VFS: Unable to mount root fs on 03:03 <0>Rebooting in 180 seconds..
Quoted 306 lines
--- exec-obsolete.h | 2 +- exec.c | 142 ++++--------------------------------------------------- memory.c | 37 ++++++++++++-- 3 files changed, 41 insertions(+), 140 deletions(-)exec-obsolete.h +1
-1@@ -33,7 +33,7 @@ void qemu_ram_free_from_ptr(ram_addr_t addr);int cpu_register_io_memory (CPUReadMemoryFunc *const *mem_read,CPUWriteMemoryFunc *const *mem_write, -void *opaque,enum device_endian endian); +void *opaque);void cpu_unregister_io_memory (int table_address); void cpu_register_physical_memory_log(target_phys_addr_t start_addr,exec.c +9
-133@@ -3507,8 +3507,7 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end, mmio =g_malloc0 (sizeof (subpage_t)); mmio->base = base; - subpage_memory =cpu_register_io_memory (subpage_read, subpage_write, mmio, -DEVICE_NATIVE_ENDIAN ); + subpage_memory =cpu_register_io_memory (subpage_read, subpage_write, mmio);#if defined(DEBUG_SUBPAGE )printf ("%s: %p base " TARGET_FMT_plx" len %08x %d\n" , __func__, mmio, base,TARGET_PAGE_SIZE , subpage_memory);@@ -3532,106 +3531,6 @@ static int get_free_io_mem_idx(void)return -1 ; } -/* -* Usually, devices operate in little endian mode. There are devices out -* there that operate in big endian too. Each device gets byte swapped -* mmio if plugged onto a CPU that does the other endianness. -* -* CPU Device swap? -* -* little little no -* little big yes -* big little yes -* big big no -*/ - -typedef struct SwapEndianContainer { -CPUReadMemoryFunc *read[3 ]; -CPUWriteMemoryFunc *write[3 ]; -void *opaque; -}SwapEndianContainer ; - -static uint32_t swapendian_mem_readb (void *opaque,target_phys_addr_t addr) -{ -uint32_t val; -SwapEndianContainer *c = opaque; - val = c->read[0 ](c->opaque, addr); -return val; -} - -static uint32_t swapendian_mem_readw (void *opaque,target_phys_addr_t addr) -{ -uint32_t val; -SwapEndianContainer *c = opaque; - val =bswap16 (c->read[1 ](c->opaque, addr)); -return val; -} - -static uint32_t swapendian_mem_readl (void *opaque,target_phys_addr_t addr) -{ -uint32_t val; -SwapEndianContainer *c = opaque; - val =bswap32 (c->read[2 ](c->opaque, addr)); -return val; -} - -static CPUReadMemoryFunc *const swapendian_readfn[3 ]={ - swapendian_mem_readb, - swapendian_mem_readw, - swapendian_mem_readl -}; - -static void swapendian_mem_writeb (void *opaque,target_phys_addr_t addr, -uint32_t val) -{ -SwapEndianContainer *c = opaque; - c->write[0 ](c->opaque, addr, val); -} - -static void swapendian_mem_writew (void *opaque,target_phys_addr_t addr, -uint32_t val) -{ -SwapEndianContainer *c = opaque; - c->write[1 ](c->opaque, addr,bswap16 (val)); -} - -static void swapendian_mem_writel (void *opaque,target_phys_addr_t addr, -uint32_t val) -{ -SwapEndianContainer *c = opaque; - c->write[2 ](c->opaque, addr,bswap32 (val)); -} - -static CPUWriteMemoryFunc *const swapendian_writefn[3 ]={ - swapendian_mem_writeb, - swapendian_mem_writew, - swapendian_mem_writel -}; - -static void swapendian_init (int io_index) -{ -SwapEndianContainer *c =g_malloc (sizeof (SwapEndianContainer)); -int i; - -/* Swap mmio for big endian targets */ - c->opaque = io_mem_opaque[io_index]; -for (i =0 ; i <3 ; i++) { - c->read[i] = io_mem_read[io_index][i]; - c->write[i] = io_mem_write[io_index][i]; - - io_mem_read[io_index][i] = swapendian_readfn[i]; - io_mem_write[io_index][i] = swapendian_writefn[i]; - } - io_mem_opaque[io_index] = c; -} - -static void swapendian_del (int io_index) -{ -if (io_mem_read[io_index][0 ] == swapendian_readfn[0 ]) { -g_free (io_mem_opaque[io_index]); - } -} -/* mem_read and mem_write are arrays of functions containing the function to access byte (index 0), word (index 1) and dword (index 2). Functions can be omitted with a NULL function pointer. @@ -3642,7 +3541,7 @@ static void swapendian_del(int io_index)static int cpu_register_io_memory_fixed (int io_index,CPUReadMemoryFunc *const *mem_read,CPUWriteMemoryFunc *const *mem_write, -void *opaque,enum device_endian endian) +void *opaque) {int i;@@ -3666,30 +3565,14 @@ static int cpu_register_io_memory_fixed(int io_index, } io_mem_opaque[io_index] = opaque; -switch (endian) { -case DEVICE_BIG_ENDIAN : -#ifndef TARGET_WORDS_BIGENDIAN -swapendian_init (io_index); -#endif -break ; -case DEVICE_LITTLE_ENDIAN : -#ifdef TARGET_WORDS_BIGENDIAN -swapendian_init (io_index); -#endif -break ; -case DEVICE_NATIVE_ENDIAN : -default : -break ; - } -return (io_index <<IO_MEM_SHIFT ); }int cpu_register_io_memory (CPUReadMemoryFunc *const *mem_read,CPUWriteMemoryFunc *const *mem_write, -void *opaque,enum device_endian endian) +void *opaque) { -return cpu_register_io_memory_fixed (0 , mem_read, mem_write, opaque, endian); +return cpu_register_io_memory_fixed (0 , mem_read, mem_write, opaque); }void cpu_unregister_io_memory (int io_table_address)@@ -3697,8 +3580,6 @@ void cpu_unregister_io_memory(int io_table_address)int i;int io_index = io_table_address >>IO_MEM_SHIFT ; -swapendian_del (io_index); -for (i=0 ;i <3 ; i++) { io_mem_read[io_index][i] = unassigned_mem_read[i]; io_mem_write[io_index][i] = unassigned_mem_write[i];@@ -3712,23 +3593,18 @@ static void io_mem_init(void)int i;cpu_register_io_memory_fixed (IO_MEM_ROM , error_mem_read, - unassigned_mem_write,NULL , -DEVICE_NATIVE_ENDIAN ); + unassigned_mem_write,NULL );cpu_register_io_memory_fixed (IO_MEM_UNASSIGNED , unassigned_mem_read, - unassigned_mem_write,NULL , -DEVICE_NATIVE_ENDIAN ); + unassigned_mem_write,NULL );cpu_register_io_memory_fixed (IO_MEM_NOTDIRTY , error_mem_read, - notdirty_mem_write,NULL , -DEVICE_NATIVE_ENDIAN ); + notdirty_mem_write,NULL );cpu_register_io_memory_fixed (IO_MEM_SUBPAGE_RAM , subpage_ram_read, - subpage_ram_write,NULL , -DEVICE_NATIVE_ENDIAN ); + subpage_ram_write,NULL );for (i=0 ; i<5 ; i++) io_mem_used[i] =1 ; io_mem_watch =cpu_register_io_memory (watch_mem_read, - watch_mem_write,NULL , -DEVICE_NATIVE_ENDIAN ); + watch_mem_write,NULL ); }static void memory_map_init (void )memory.c +31
-6@@ -857,6 +857,15 @@ static void memory_region_destructor_rom_device(MemoryRegion *mr)cpu_unregister_io_memory (mr->ram_addr & ~(TARGET_PAGE_MASK |IO_MEM_ROMD )); } +static bool memory_region_wrong_endianness (MemoryRegion *mr) +{ +#ifdef TARGET_BIG_ENDIAN +return mr->ops->endianness ==DEVICE_LITTLE_ENDIAN ; +#else +return mr->ops->endianness ==DEVICE_BIG_ENDIAN ; +#endif +} +void memory_region_init (MemoryRegion *mr,const char *name,uint64_t size)@@ -967,12 +976,24 @@ static uint32_t memory_region_read_thunk_b(void *mr, target_phys_addr_t addr)static uint32_t memory_region_read_thunk_w (void *mr,target_phys_addr_t addr) { -return memory_region_read_thunk_n (mr, addr,2 ); +uint32_t data; + + data =memory_region_read_thunk_n (mr, addr,2 ); +if (memory_region_wrong_endianness (mr)) { + data =bswap16 (data); + } +return data; }static uint32_t memory_region_read_thunk_l (void *mr,target_phys_addr_t addr) { -return memory_region_read_thunk_n (mr, addr,4 ); +uint32_t data; + + data =memory_region_read_thunk_n (mr, addr,4 ); +if (memory_region_wrong_endianness (mr)) { + data =bswap32 (data); + } +return data; } static void memory_region_write_thunk_b(void *mr, target_phys_addr_t addr,@@ -984,12 +1005,18 @@ static void memory_region_write_thunk_b(void *mr, target_phys_addr_t addr,static void memory_region_write_thunk_w (void *mr,target_phys_addr_t addr,uint32_t data) { +if (memory_region_wrong_endianness (mr)) { + data =bswap16 (data); + }memory_region_write_thunk_n (mr, addr,2 , data); }static void memory_region_write_thunk_l (void *mr,target_phys_addr_t addr,uint32_t data) { +if (memory_region_wrong_endianness (mr)) { + data =bswap32 (data); + }memory_region_write_thunk_n (mr, addr,4 , data); }@@ -1014,8 +1041,7 @@ static void memory_region_prepare_ram_addr(MemoryRegion *mr) mr->destructor = memory_region_destructor_iomem; mr->ram_addr =cpu_register_io_memory (memory_region_read_thunk, memory_region_write_thunk, - mr, - mr->ops->endianness); + mr); mr->backend_registered = true; }@@ -1082,8 +1108,7 @@ void memory_region_init_rom_device(MemoryRegion *mr, mr->ram_addr =qemu_ram_alloc (size, mr); mr->ram_addr |=cpu_register_io_memory (memory_region_read_thunk, memory_region_write_thunk, - mr, - mr->ops->endianness); + mr); mr->ram_addr |=IO_MEM_ROMD ; mr->backend_registered = true; }
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 01/16] memory: move endianness compensation to memory core
In reply to Avi KivityAm 02.01.2012 17:33, schrieb Avi Kivity:
Quoted 38 lines
Instead of doing device endianness compensation in
cpu_register_io_memory(), do it in the memory core.Signed-off-by Avi Kivity <[email protected]>exec.c +0
-16@@ -3666,30 +3565,14 @@ static int cpu_register_io_memory_fixed(int io_index, } io_mem_opaque[io_index] = opaque; -switch (endian) { -case DEVICE_BIG_ENDIAN : -#ifndef TARGET_WORDS_BIGENDIAN -swapendian_init (io_index); -#endif -break ; -case DEVICE_LITTLE_ENDIAN : -#ifdef TARGET_WORDS_BIGENDIAN -swapendian_init (io_index); -#endif -break ; -case DEVICE_NATIVE_ENDIAN : -default : -break ; - } -return (io_index <<IO_MEM_SHIFT ); }memory.c +0
-0
memory.c static void memory_region_destructor_rom_device(MemoryRegion *mr) · line 862
Quoted 6 lines
memory.c +3
-0@@ -857,6 +857,15 @@ static void memory_region_destructor_rom_device(MemoryRegion *mr)cpu_unregister_io_memory (mr->ram_addr & ~(TARGET_PAGE_MASK |IO_MEM_ROMD )); } +static bool memory_region_wrong_endianness (MemoryRegion *mr) +{ +#ifdef TARGET_BIG_ENDIAN
This should've been TARGET_WORDS_BIGENDIAN. Patch coming up.
Andreas
Quoted 5 lines
memory.c +5
-0+return mr->ops->endianness ==DEVICE_LITTLE_ENDIAN ; +#else +return mr->ops->endianness ==DEVICE_BIG_ENDIAN ; +#endif +}
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
PATCH 2/16 exec: make phys_page_find() return a temporary
In reply to Avi KivityInstead of returning a PhysPageDesc pointer, return a temporary. This lets us move away from actually storing PhysPageDesc's, and instead sythesising them when needed.
--- exec.c | 148 +++++++++++++++++++++------------------------------------------- 1 files changed, 48 insertions(+), 100 deletions(-)
exec.c +48 -100
@@ -438,9 +438,18 @@ static void page_init(void)return pd + (index & (L2_SIZE -1 )); } -static inline PhysPageDesc *phys_page_find (target_phys_addr_t index) +static inline PhysPageDesc phys_page_find (target_phys_addr_t index) { -return phys_page_find_alloc (index,0 ); +PhysPageDesc *p =phys_page_find_alloc (index,0 ); + +if (p) { +return *p; + }else { +return (PhysPageDesc ) { + .phys_offset =IO_MEM_UNASSIGNED , + .region_offset = index <<TARGET_PAGE_BITS , + }; + } }static void tlb_protect_code (ram_addr_t ram_addr);
@@ -1402,15 +1411,11 @@ static void breakpoint_invalidate(CPUState *env, target_ulong pc)target_phys_addr_t addr;target_ulong pd;ram_addr_t ram_addr; -PhysPageDesc *p; +PhysPageDesc p; addr =cpu_get_phys_page_debug (env, pc); p =phys_page_find (addr >>TARGET_PAGE_BITS ); -if (!p) { - pd =IO_MEM_UNASSIGNED ; - }else { - pd = p->phys_offset; - } + pd = p.phys_offset; ram_addr = (pd &TARGET_PAGE_MASK ) | (pc & ~TARGET_PAGE_MASK );tb_invalidate_phys_page_range (ram_addr, ram_addr +1 ,0 ); }
@@ -2086,7 +2091,7 @@ void tlb_set_page(CPUState *env, target_ulong vaddr, target_phys_addr_t paddr, int prot, int mmu_idx, target_ulong size) { - PhysPageDesc *p; + PhysPageDesc p;unsigned long pd;unsigned int index;target_ulong address;
@@ -2101,11 +2106,7 @@ void tlb_set_page(CPUState *env, target_ulong vaddr,tlb_add_large_page (env, vaddr, size); } p =phys_page_find (paddr >>TARGET_PAGE_BITS ); -if (!p) { - pd =IO_MEM_UNASSIGNED ; - }else { - pd = p->phys_offset; - } + pd = p.phys_offset;#if defined(DEBUG_TLB ) printf("tlb_set_page: vaddr=" TARGET_FMT_lx " paddr=0x" TARGET_FMT_plx " prot=%x idx=%d pd=0x%08lx\n",
@@ -2133,11 +2134,7 @@ void tlb_set_page(CPUState *env, target_ulong vaddr,We can't use the high bits of pd for this because IO_MEM_ROMD uses these as a ram address. */ iotlb = (pd & ~TARGET_PAGE_MASK ); -if (p) { - iotlb += p->region_offset; - }else { - iotlb += paddr; - } + iotlb += p.region_offset; } code_address = address;
@@ -2523,7 +2520,7 @@ void cpu_register_physical_memory_log(target_phys_addr_t start_addr, addr = start_addr; do { - p = phys_page_find(addr >> TARGET_PAGE_BITS); + p = phys_page_find_alloc(addr >> TARGET_PAGE_BITS, 0); if (p && p->phys_offset != IO_MEM_UNASSIGNED) { ram_addr_t orig_memory = p->phys_offset; target_phys_addr_t start_addr2, end_addr2;
@@ -3680,7 +3677,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,uint32_t val;target_phys_addr_t page;ram_addr_t pd; -PhysPageDesc *p; +PhysPageDesc p;while (len >0 ) { page = addr &TARGET_PAGE_MASK ;
@@ -3688,18 +3685,13 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,if (l > len) l = len; p =phys_page_find (page >>TARGET_PAGE_BITS ); -if (!p) { - pd =IO_MEM_UNASSIGNED ; - }else { - pd = p->phys_offset; - } + pd = p.phys_offset;if (is_write) {if ((pd & ~TARGET_PAGE_MASK ) !=IO_MEM_RAM ) { -target_phys_addr_t addr1 = addr; +target_phys_addr_t addr1; io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); -if (p) - addr1 = (addr & ~TARGET_PAGE_MASK ) + p->region_offset; + addr1 = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;/* XXX: could force cpu_single_env to NULL to avoid potential bugs */ if (l >=4 && ((addr1 &3 ) ==0 )) {
@@ -3736,11 +3728,10 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, }else {if ((pd & ~TARGET_PAGE_MASK ) >IO_MEM_ROM && !(pd &IO_MEM_ROMD )) { -target_phys_addr_t addr1 = addr; +target_phys_addr_t addr1;/* I/O case */ io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); -if (p) - addr1 = (addr & ~TARGET_PAGE_MASK ) + p->region_offset; + addr1 = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;if (l >=4 && ((addr1 &3 ) ==0 )) {/* 32 bit read access */ val = io_mem_read[io_index][2 ](io_mem_opaque[io_index], addr1);
@@ -3778,7 +3769,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr,uint8_t *ptr;target_phys_addr_t page;unsigned long pd; -PhysPageDesc *p; +PhysPageDesc p;while (len >0 ) { page = addr &TARGET_PAGE_MASK ;
@@ -3786,11 +3777,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr,if (l > len) l = len; p =phys_page_find (page >>TARGET_PAGE_BITS ); -if (!p) { - pd =IO_MEM_UNASSIGNED ; - }else { - pd = p->phys_offset; - } + pd = p.phys_offset; if ((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM && (pd & ~TARGET_PAGE_MASK) != IO_MEM_ROM &&
@@ -3872,7 +3859,7 @@ static void cpu_notify_map_clients(void)int l;target_phys_addr_t page;unsigned long pd; -PhysPageDesc *p; +PhysPageDesc p;ram_addr_t raddr =RAM_ADDR_MAX ;ram_addr_t rlen;void *ret;
@@ -3883,11 +3870,7 @@ static void cpu_notify_map_clients(void)if (l > len) l = len; p =phys_page_find (page >>TARGET_PAGE_BITS ); -if (!p) { - pd =IO_MEM_UNASSIGNED ; - }else { - pd = p->phys_offset; - } + pd = p.phys_offset;if ((pd & ~TARGET_PAGE_MASK ) !=IO_MEM_RAM ) {if (todo || bounce.buffer) {
@@ -3964,21 +3947,16 @@ static inline uint32_t ldl_phys_internal(target_phys_addr_t addr,uint8_t *ptr;uint32_t val;unsigned long pd; -PhysPageDesc *p; +PhysPageDesc p; p =phys_page_find (addr >>TARGET_PAGE_BITS ); -if (!p) { - pd =IO_MEM_UNASSIGNED ; - }else { - pd = p->phys_offset; - } + pd = p.phys_offset;if ((pd & ~TARGET_PAGE_MASK ) >IO_MEM_ROM && !(pd &IO_MEM_ROMD )) {/* I/O case */ io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); -if (p) - addr = (addr & ~TARGET_PAGE_MASK ) + p->region_offset; + addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset; val = io_mem_read[io_index][2 ](io_mem_opaque[io_index], addr);#if defined(TARGET_WORDS_BIGENDIAN )if (endian ==DEVICE_LITTLE_ENDIAN ) {
@@ -4031,21 +4009,16 @@ static inline uint64_t ldq_phys_internal(target_phys_addr_t addr,uint8_t *ptr;uint64_t val;unsigned long pd; -PhysPageDesc *p; +PhysPageDesc p; p =phys_page_find (addr >>TARGET_PAGE_BITS ); -if (!p) { - pd =IO_MEM_UNASSIGNED ; - }else { - pd = p->phys_offset; - } + pd = p.phys_offset;if ((pd & ~TARGET_PAGE_MASK ) >IO_MEM_ROM && !(pd &IO_MEM_ROMD )) {/* I/O case */ io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); -if (p) - addr = (addr & ~TARGET_PAGE_MASK ) + p->region_offset; + addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;/* XXX This is broken when device endian != cpu endian. Fix and add "endian" variable check */
@@ -4106,21 +4079,16 @@ static inline uint32_t lduw_phys_internal(target_phys_addr_t addr,uint8_t *ptr;uint64_t val;unsigned long pd; -PhysPageDesc *p; +PhysPageDesc p; p =phys_page_find (addr >>TARGET_PAGE_BITS ); -if (!p) { - pd =IO_MEM_UNASSIGNED ; - }else { - pd = p->phys_offset; - } + pd = p.phys_offset;if ((pd & ~TARGET_PAGE_MASK ) >IO_MEM_ROM && !(pd &IO_MEM_ROMD )) {/* I/O case */ io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); -if (p) - addr = (addr & ~TARGET_PAGE_MASK ) + p->region_offset; + addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset; val = io_mem_read[io_index][1 ](io_mem_opaque[io_index], addr);#if defined(TARGET_WORDS_BIGENDIAN )if (endian ==DEVICE_LITTLE_ENDIAN ) {
@@ -4173,19 +4141,14 @@ void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val)int io_index;uint8_t *ptr;unsigned long pd; -PhysPageDesc *p; +PhysPageDesc p; p =phys_page_find (addr >>TARGET_PAGE_BITS ); -if (!p) { - pd =IO_MEM_UNASSIGNED ; - }else { - pd = p->phys_offset; - } + pd = p.phys_offset;if ((pd & ~TARGET_PAGE_MASK ) !=IO_MEM_RAM ) { io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); -if (p) - addr = (addr & ~TARGET_PAGE_MASK ) + p->region_offset; + addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset; io_mem_write[io_index][2 ](io_mem_opaque[io_index], addr, val); }else {unsigned long addr1 = (pd &TARGET_PAGE_MASK ) + (addr & ~TARGET_PAGE_MASK );
@@ -4209,19 +4172,14 @@ void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val)int io_index;uint8_t *ptr;unsigned long pd; -PhysPageDesc *p; +PhysPageDesc p; p =phys_page_find (addr >>TARGET_PAGE_BITS ); -if (!p) { - pd =IO_MEM_UNASSIGNED ; - }else { - pd = p->phys_offset; - } + pd = p.phys_offset;if ((pd & ~TARGET_PAGE_MASK ) !=IO_MEM_RAM ) { io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); -if (p) - addr = (addr & ~TARGET_PAGE_MASK ) + p->region_offset; + addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;#ifdef TARGET_WORDS_BIGENDIAN io_mem_write[io_index][2 ](io_mem_opaque[io_index], addr, val >>32 ); io_mem_write[io_index][2 ](io_mem_opaque[io_index], addr +4 , val);
@@ -4243,19 +4201,14 @@ static inline void stl_phys_internal(target_phys_addr_t addr, uint32_t val,int io_index;uint8_t *ptr;unsigned long pd; -PhysPageDesc *p; +PhysPageDesc p; p =phys_page_find (addr >>TARGET_PAGE_BITS ); -if (!p) { - pd =IO_MEM_UNASSIGNED ; - }else { - pd = p->phys_offset; - } + pd = p.phys_offset;if ((pd & ~TARGET_PAGE_MASK ) !=IO_MEM_RAM ) { io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); -if (p) - addr = (addr & ~TARGET_PAGE_MASK ) + p->region_offset; + addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;#if defined(TARGET_WORDS_BIGENDIAN )if (endian ==DEVICE_LITTLE_ENDIAN ) { val =bswap32 (val);
@@ -4321,19 +4274,14 @@ static inline void stw_phys_internal(target_phys_addr_t addr, uint32_t val,int io_index;uint8_t *ptr;unsigned long pd; -PhysPageDesc *p; +PhysPageDesc p; p =phys_page_find (addr >>TARGET_PAGE_BITS ); -if (!p) { - pd =IO_MEM_UNASSIGNED ; - }else { - pd = p->phys_offset; - } + pd = p.phys_offset;if ((pd & ~TARGET_PAGE_MASK ) !=IO_MEM_RAM ) { io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); -if (p) - addr = (addr & ~TARGET_PAGE_MASK ) + p->region_offset; + addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;#if defined(TARGET_WORDS_BIGENDIAN )if (endian ==DEVICE_LITTLE_ENDIAN ) { val =bswap16 (val);
Signature · 1 line
1.7.7.1
PATCH 3/16 memory: move mmio access to functions
In reply to Avi KivityCurrently mmio access goes directly to the io_mem_{read,write} arrays. In preparation for eliminating them, add indirection via a function.
--- exec-all.h | 7 ++++- exec.c | 54 ++++++++++++++++++++++++++-------------------------- memory.c | 13 ++++++++++++ softmmu_template.h | 20 +++++++++--------- 4 files changed, 55 insertions(+), 39 deletions(-)
exec-all.h +5 -2
@@ -299,8 +299,11 @@ extern void *tci_tb_ptr;#if !defined(CONFIG_USER_ONLY ) -extern CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES ][4 ]; -extern CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES ][4 ]; +uint64_t io_mem_read (int index,target_phys_addr_t addr,unsigned size); +void io_mem_write (int index,target_phys_addr_t addr,uint64_t value, +unsigned size); +extern CPUWriteMemoryFunc *_io_mem_write[IO_MEM_NB_ENTRIES ][4 ]; +extern CPUReadMemoryFunc *_io_mem_read[IO_MEM_NB_ENTRIES ][4 ];extern void *io_mem_opaque[IO_MEM_NB_ENTRIES ]; void tlb_fill(CPUState *env1, target_ulong addr, int is_write, int mmu_idx,
exec.c +27 -27
159 lines not on this page · raw message
memory.c +13 -0
@@ -1580,6 +1580,19 @@ void set_system_io_map(MemoryRegion *mr)memory_region_update_topology (NULL ); } +uint64_t io_mem_read (int io_index,target_phys_addr_t addr,unsigned size) +{ +return _io_mem_read[io_index][bitops_ffsl (size)](io_mem_opaque[io_index], + addr); +} + +void io_mem_write (int io_index,target_phys_addr_t addr, +uint64_t val,unsigned size) +{ + _io_mem_write[io_index][bitops_ffsl (size)](io_mem_opaque[io_index], + addr, val); +} +typedef struct MemoryRegionList MemoryRegionList ;struct MemoryRegionList {
softmmu_template.h +10 -10
@@ -72,14 +72,14 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr, env->mem_io_vaddr = addr;#if SHIFT <=2 - res = io_mem_read[index][SHIFT ](io_mem_opaque[index], physaddr); + res =io_mem_read (index, physaddr,1 <<SHIFT );#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 ); + res =io_mem_read (index, physaddr,4 ) <<32 ; + res |=io_mem_read (index, physaddr +4 ,4 );#else - 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 ; + res =io_mem_read (index, physaddr,4 ); + res |=io_mem_read (index, physaddr +4 ,4 ) <<32 ;#endif #endif /* SHIFT > 2 */ return res;
@@ -215,14 +215,14 @@ static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr, env->mem_io_vaddr = addr; env->mem_io_pc = (unsigned long )retaddr;#if SHIFT <=2 - io_mem_write[index][SHIFT ](io_mem_opaque[index], physaddr, val); +io_mem_write (index, physaddr, val,1 <<SHIFT );#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); +io_mem_write (index, physaddr, (val >>32 ),4 ); +io_mem_write (index, physaddr +4 , (uint32_t )val,4 );#else - io_mem_write[index][2 ](io_mem_opaque[index], physaddr, val); - io_mem_write[index][2 ](io_mem_opaque[index], physaddr +4 , val >>32 ); +io_mem_write (index, physaddr, (uint32_t )val,4 ); +io_mem_write (index, physaddr +4 , val >>32 ,4 );#endif #endif /* SHIFT > 2 */ }
Signature · 1 line
1.7.7.1
PATCH 4/16 memory: remove MemoryRegion::backend_registered
In reply to Avi Kivitybackend_registered was used to lazify the process of registering an mmio region, since the it is different for the I/O address space and the memory address space. However, it also makes registration dependent on the region being visible in the address space. This is not the case for "fake" regions, like watchpoints or IO_MEM_UNASSIGNED.
Remove backend_registered and always initialize the region. If it turns out to be part of the I/O address space, we've wasted an I/O slot, but that's not too bad. In any case this will be optimized later on.
--- memory.c | 26 ++++---------------------- memory.h | 1 - 2 files changed, 4 insertions(+), 23 deletions(-)
memory.c +4 -22
@@ -303,14 +303,10 @@ static void access_with_adjusted_size(target_phys_addr_t addr, } } -static void memory_region_prepare_ram_addr (MemoryRegion *mr); -static void as_memory_range_add (AddressSpace *as,FlatRange *fr) {ram_addr_t phys_offset, region_offset; -memory_region_prepare_ram_addr (fr->mr); - phys_offset = fr->mr->ram_addr; region_offset = fr->offset_in_region;/* cpu_register_physical_memory_log() wants region_offset for
@@ -1032,19 +1028,6 @@ static void memory_region_write_thunk_l(void *mr, target_phys_addr_t addr, memory_region_write_thunk_l, }; -static void memory_region_prepare_ram_addr (MemoryRegion *mr) -{ -if (mr->backend_registered) { -return ; - } - - mr->destructor = memory_region_destructor_iomem; - mr->ram_addr =cpu_register_io_memory (memory_region_read_thunk, - memory_region_write_thunk, - mr); - mr->backend_registered = true; -} - void memory_region_init_io(MemoryRegion *mr, const MemoryRegionOps *ops, void *opaque,
@@ -1055,7 +1038,10 @@ void memory_region_init_io(MemoryRegion *mr, mr->ops = ops; mr->opaque = opaque; mr->terminates = true; - mr->backend_registered = false; + mr->destructor = memory_region_destructor_iomem; + mr->ram_addr =cpu_register_io_memory (memory_region_read_thunk, + memory_region_write_thunk, + mr); } void memory_region_init_ram(MemoryRegion *mr,
@@ -1067,7 +1053,6 @@ void memory_region_init_ram(MemoryRegion *mr, mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->ram_addr =qemu_ram_alloc (size, mr); - mr->backend_registered = true; } void memory_region_init_ram_ptr(MemoryRegion *mr,
@@ -1080,7 +1065,6 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, mr->terminates = true; mr->destructor = memory_region_destructor_ram_from_ptr; mr->ram_addr =qemu_ram_alloc_from_ptr (size, ptr, mr); - mr->backend_registered = true; } void memory_region_init_alias(MemoryRegion *mr,
@@ -1110,7 +1094,6 @@ void memory_region_init_rom_device(MemoryRegion *mr, memory_region_write_thunk, mr); mr->ram_addr |=IO_MEM_ROMD ; - mr->backend_registered = true; }void memory_region_destroy (MemoryRegion *mr)
@@ -1453,7 +1436,6 @@ void memory_region_set_alias_offset(MemoryRegion *mr, target_phys_addr_t offset)ram_addr_t memory_region_get_ram_addr (MemoryRegion *mr) { -assert (mr->backend_registered);return mr->ram_addr; }
memory.h +0 -1
@@ -116,7 +116,6 @@ struct MemoryRegion {Int128 size;target_phys_addr_t addr;target_phys_addr_t offset; -bool backend_registered;void (*destructor)(MemoryRegion *mr);ram_addr_t ram_addr;IORange iorange;
Signature · 1 line
1.7.7.1
PATCH 5/16 Fix wrong region_offset when overlaying a page with another
In reply to Avi Kivitycpu_register_physical_memory_log() does not update region_offset if a page was previously registered for the same address. This could cause mmio accesses going to the wrong place, by using the old region_offset.
--- exec.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
exec.c +1 -0
@@ -2542,6 +2542,7 @@ void cpu_register_physical_memory_log(target_phys_addr_t start_addr, p->region_offset =0 ; }else { p->phys_offset = phys_offset; + p->region_offset = region_offset;if ((phys_offset & ~TARGET_PAGE_MASK ) <=IO_MEM_ROM || (phys_offset &IO_MEM_ROMD )) phys_offset +=TARGET_PAGE_SIZE ;
Signature · 1 line
1.7.7.1
PATCH 6/16 Avoid range comparisons on io index types
In reply to Avi KivityThe code sometimes uses range comparisons on io indexes (e.g. index =< IO_MEM_ROM). Avoid these as they make moving to objects harder.
--- exec-all.h | 2 +- exec.c | 37 ++++++++++++++++++++----------------- memory.c | 3 ++- softmmu_template.h | 6 ++++-- 4 files changed, 27 insertions(+), 21 deletions(-)
exec-all.h +1 -1
@@ -354,7 +354,7 @@ static inline tb_page_addr_t get_page_addr_code(CPUState *env1, target_ulong addldub_code (addr); } pd = env1->tlb_table[mmu_idx][page_index].addr_code & ~TARGET_PAGE_MASK ; -if (pd >IO_MEM_ROM && !(pd &IO_MEM_ROMD )) { +if (pd !=IO_MEM_RAM && pd !=IO_MEM_ROM && !(pd &IO_MEM_ROMD )) {#if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || defined(TARGET_SPARC )cpu_unassigned_access (env1, addr,0 ,1 ,0 ,4 );#else
exec.c +20 -17
@@ -2084,6 +2084,17 @@ static void tlb_add_large_page(CPUState *env, target_ulong vaddr, env->tlb_flush_mask = mask; } +static bool is_ram_rom (ram_addr_t pd) +{ + pd &= ~TARGET_PAGE_MASK ; +return pd ==IO_MEM_RAM || pd ==IO_MEM_ROM ; +} + +static bool is_ram_rom_romd (ram_addr_t pd) +{ +return is_ram_rom (pd) || (pd &IO_MEM_ROMD ); +} +/* Add a new TLB entry. At most one entry for a given virtual address is permitted. Only a single TARGET_PAGE_SIZE region is mapped, the supplied size is only used by tlb_flush_page. */
@@ -2114,12 +2125,12 @@ void tlb_set_page(CPUState *env, target_ulong vaddr,#endif address = vaddr; -if ((pd & ~TARGET_PAGE_MASK ) >IO_MEM_ROM && !(pd &IO_MEM_ROMD )) { +if (!is_ram_rom (pd) && !(pd &IO_MEM_ROMD )) {/* IO memory case (romd handled later) */ address |=TLB_MMIO ; } addend = (unsigned long )qemu_get_ram_ptr (pd &TARGET_PAGE_MASK ); -if ((pd & ~TARGET_PAGE_MASK ) <=IO_MEM_ROM ) { +if (is_ram_rom (pd)) {/* Normal RAM. */ iotlb = pd &TARGET_PAGE_MASK ;if ((pd & ~TARGET_PAGE_MASK ) ==IO_MEM_RAM )
@@ -2543,16 +2554,14 @@ void cpu_register_physical_memory_log(target_phys_addr_t start_addr, }else { p->phys_offset = phys_offset; p->region_offset = region_offset; -if ((phys_offset & ~TARGET_PAGE_MASK ) <=IO_MEM_ROM || - (phys_offset &IO_MEM_ROMD )) +if (is_ram_rom_romd (phys_offset)) phys_offset +=TARGET_PAGE_SIZE ; } }else { p =phys_page_find_alloc (addr >>TARGET_PAGE_BITS ,1 ); p->phys_offset = phys_offset; p->region_offset = region_offset; -if ((phys_offset & ~TARGET_PAGE_MASK ) <=IO_MEM_ROM || - (phys_offset &IO_MEM_ROMD )) { +if (is_ram_rom_romd (phys_offset)) { phys_offset +=TARGET_PAGE_SIZE ; }else {target_phys_addr_t start_addr2, end_addr2;
@@ -3727,8 +3736,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,qemu_put_ram_ptr (ptr); } }else { -if ((pd & ~TARGET_PAGE_MASK ) >IO_MEM_ROM && - !(pd &IO_MEM_ROMD )) { +if (!is_ram_rom_romd (pd)) {target_phys_addr_t addr1;/* I/O case */ io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 );
@@ -3780,9 +3788,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr, p =phys_page_find (page >>TARGET_PAGE_BITS ); pd = p.phys_offset; -if ((pd & ~TARGET_PAGE_MASK ) !=IO_MEM_RAM && - (pd & ~TARGET_PAGE_MASK ) !=IO_MEM_ROM && - !(pd &IO_MEM_ROMD )) { +if (!is_ram_rom_romd (pd)) {/* do nothing */ }else {unsigned long addr1;
@@ -3953,8 +3959,7 @@ static inline uint32_t ldl_phys_internal(target_phys_addr_t addr, p =phys_page_find (addr >>TARGET_PAGE_BITS ); pd = p.phys_offset; -if ((pd & ~TARGET_PAGE_MASK ) >IO_MEM_ROM && - !(pd &IO_MEM_ROMD )) { +if (!is_ram_rom_romd (pd)) {/* I/O case */ io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;
@@ -4015,8 +4020,7 @@ static inline uint64_t ldq_phys_internal(target_phys_addr_t addr, p =phys_page_find (addr >>TARGET_PAGE_BITS ); pd = p.phys_offset; -if ((pd & ~TARGET_PAGE_MASK ) >IO_MEM_ROM && - !(pd &IO_MEM_ROMD )) { +if (!is_ram_rom_romd (pd)) {/* I/O case */ io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;
@@ -4085,8 +4089,7 @@ static inline uint32_t lduw_phys_internal(target_phys_addr_t addr, p =phys_page_find (addr >>TARGET_PAGE_BITS ); pd = p.phys_offset; -if ((pd & ~TARGET_PAGE_MASK ) >IO_MEM_ROM && - !(pd &IO_MEM_ROMD )) { +if (is_ram_rom_romd (pd)) {/* I/O case */ io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;
memory.c +2 -1
@@ -312,7 +312,8 @@ static void as_memory_range_add(AddressSpace *as, FlatRange *fr)/* cpu_register_physical_memory_log() wants region_offset for * mmio, but prefers offseting phys_offset for RAM. Humour it. */ -if ((phys_offset & ~TARGET_PAGE_MASK ) <=IO_MEM_ROM ) { +if ((phys_offset & ~TARGET_PAGE_MASK ) ==IO_MEM_RAM + || (phys_offset & ~TARGET_PAGE_MASK ) ==IO_MEM_ROM ) { phys_offset += region_offset; region_offset =0 ; }
softmmu_template.h +4 -2
@@ -65,7 +65,8 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr, index = (physaddr >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); physaddr = (physaddr &TARGET_PAGE_MASK ) + addr; env->mem_io_pc = (unsigned long )retaddr; -if (index > (IO_MEM_NOTDIRTY >>IO_MEM_SHIFT ) +if (index !=IO_MEM_RAM && index !=IO_MEM_ROM + && index !=IO_MEM_UNASSIGNED && index !=IO_MEM_NOTDIRTY && !can_do_io (env)) {cpu_io_recompile (env, retaddr); }
@@ -207,7 +208,8 @@ static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr,int index; index = (physaddr >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); physaddr = (physaddr &TARGET_PAGE_MASK ) + addr; -if (index > (IO_MEM_NOTDIRTY >>IO_MEM_SHIFT ) +if (index !=IO_MEM_RAM && index !=IO_MEM_ROM + && index !=IO_MEM_UNASSIGNED && index !=IO_MEM_NOTDIRTY && !can_do_io (env)) {cpu_io_recompile (env, retaddr); }
Signature · 1 line
1.7.7.1
Re: [Qemu-devel] [PATCH 06/16] Avoid range comparisons on io index types
exec.c void tlb_set_page(CPUState *env, target_ulong vaddr, · line 2129
Quoted 3 lines · Avi Kivity
exec.c +1
-1-if ((pd & ~TARGET_PAGE_MASK ) >IO_MEM_ROM && !(pd &IO_MEM_ROMD )) { +if (!is_ram_rom (pd) && !(pd &IO_MEM_ROMD )) {/* IO memory case (romd handled later) */
Perhaps (!is_ram_rom_romd(pd))?
At least that's what I see from DeMorgan's, even though it doesn't quite seem to tally with the comment...
r~
Re: [Qemu-devel] [PATCH 06/16] Avoid range comparisons on io index types
Quoted 6 lines · Richard Henderson
exec.c void tlb_set_page(CPUState *env, target_ulong vaddr, · line 2129
Quoted 3 lines · Avi Kivity
exec.c +1
-1-if ((pd & ~TARGET_PAGE_MASK ) >IO_MEM_ROM && !(pd &IO_MEM_ROMD )) { +if (!is_ram_rom (pd) && !(pd &IO_MEM_ROMD )) {/* IO memory case (romd handled later) */ Perhaps (!is_ram_rom_romd(pd))?
Yeah, will change.
Quoted 2 lines
At least that's what I see from DeMorgan's, even though it doesn't quite seem to tally with the comment...
The comment actually fits both (!is_ram_rom && !is_romd()) and (!is_ram_rom && is_romd()), since romd acts like both rom and I/O memory. The code appears to be correct.
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH 7/16 Uninline get_page_addr_code()
In reply to Avi KivityIts use of IO_MEM_ROM and friends will later cause #include loops; and it is too large to merit inlining.
--- exec-all.h | 26 +------------------------- exec.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 25 deletions(-)
exec-all.h +1 -25
@@ -339,31 +339,7 @@ static inline tb_page_addr_t get_page_addr_code(CPUState *env1, target_ulong add return addr; }#else -/* NOTE: this function can trigger an exception */ -/* NOTE2: the returned address is not exactly the physical address: it -is the offset relative to phys_ram_base */ -static inline tb_page_addr_t get_page_addr_code (CPUState *env1,target_ulong addr) -{ -int mmu_idx, page_index, pd; -void *p; - - page_index = (addr >>TARGET_PAGE_BITS ) & (CPU_TLB_SIZE -1 ); - mmu_idx =cpu_mmu_index (env1); -if (unlikely (env1->tlb_table[mmu_idx][page_index].addr_code != - (addr &TARGET_PAGE_MASK ))) { -ldub_code (addr); - } - pd = env1->tlb_table[mmu_idx][page_index].addr_code & ~TARGET_PAGE_MASK ; -if (pd !=IO_MEM_RAM && pd !=IO_MEM_ROM && !(pd &IO_MEM_ROMD )) { -#if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || defined(TARGET_SPARC ) -cpu_unassigned_access (env1, addr,0 ,1 ,0 ,4 ); -#else -cpu_abort (env1,"Trying to execute code outside RAM or ROM at 0x" TARGET_FMT_lx"\n" , addr); -#endif - } - p = (void *)((uintptr_t )addr + env1->tlb_table[mmu_idx][page_index].addend); -return qemu_ram_addr_from_host_nofail (p); -} +tb_page_addr_t get_page_addr_code (CPUState *env1,target_ulong addr);#endif typedef void (CPUDebugExcpHandler )(CPUState *env);
exec.c +26 -0
@@ -4499,6 +4499,32 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf)tcg_dump_info (f, cpu_fprintf); } +/* NOTE: this function can trigger an exception */ +/* NOTE2: the returned address is not exactly the physical address: it +is the offset relative to phys_ram_base */ +tb_page_addr_t get_page_addr_code (CPUState *env1,target_ulong addr) +{ +int mmu_idx, page_index, pd; +void *p; + + page_index = (addr >>TARGET_PAGE_BITS ) & (CPU_TLB_SIZE -1 ); + mmu_idx =cpu_mmu_index (env1); +if (unlikely (env1->tlb_table[mmu_idx][page_index].addr_code != + (addr &TARGET_PAGE_MASK ))) { +ldub_code (addr); + } + pd = env1->tlb_table[mmu_idx][page_index].addr_code & ~TARGET_PAGE_MASK ; +if (pd !=IO_MEM_RAM && pd !=IO_MEM_ROM && !(pd &IO_MEM_ROMD )) { +#if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || defined(TARGET_SPARC ) +cpu_unassigned_access (env1, addr,0 ,1 ,0 ,4 ); +#else +cpu_abort (env1,"Trying to execute code outside RAM or ROM at 0x" TARGET_FMT_lx"\n" , addr); +#endif + } + p = (void *)((uintptr_t )addr + env1->tlb_table[mmu_idx][page_index].addend); +return qemu_ram_addr_from_host_nofail (p); +} +#define MMUSUFFIX _cmmu#undef GETPC#define GETPC () NULL
Signature · 1 line
1.7.7.1
PATCH 8/16 Convert IO_MEM_{RAM, ROM, UNASSIGNED, NOTDIRTY} to MemoryRegions
In reply to Avi KivityConvert the fixed-address IO_MEM_RAM, IO_MEM_ROM, IO_MEM_UNASSIGNED, and IO_MEM_NOTDIRTY io handlers to MemoryRegions. These aren't real regions, since they are never added to the memory hierarchy, but they allow reuse of the dispatch functionality.
--- cpu-common.h | 8 +- exec.c | 220 ++++++++++++++++++++-------------------------------- memory.c | 7 +- softmmu_template.h | 11 ++- 4 files changed, 99 insertions(+), 147 deletions(-)
cpu-common.h +4 -4
@@ -109,10 +109,10 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr,#define IO_MEM_SHIFT 3 -#define IO_MEM_RAM (0 << IO_MEM_SHIFT)/* hardcoded offset */ -#define IO_MEM_ROM (1 << IO_MEM_SHIFT)/* hardcoded offset */ -#define IO_MEM_UNASSIGNED (2 << IO_MEM_SHIFT) -#define IO_MEM_NOTDIRTY (3 << IO_MEM_SHIFT) +extern struct MemoryRegion io_mem_ram; +extern struct MemoryRegion io_mem_rom; +extern struct MemoryRegion io_mem_unassigned; +extern struct MemoryRegion io_mem_notdirty;#define IO_MEM_SUBPAGE_RAM (4 << IO_MEM_SHIFT)/* Acts like a ROM when read and like a device when written. */
exec.c +85 -135
412 lines not on this page · raw message
memory.c +3 -4
@@ -312,8 +312,7 @@ static void as_memory_range_add(AddressSpace *as, FlatRange *fr)/* cpu_register_physical_memory_log() wants region_offset for * mmio, but prefers offseting phys_offset for RAM. Humour it. */ -if ((phys_offset & ~TARGET_PAGE_MASK ) ==IO_MEM_RAM - || (phys_offset & ~TARGET_PAGE_MASK ) ==IO_MEM_ROM ) { +if (memory_region_is_ram (fr->mr)) { phys_offset += region_offset; region_offset =0 ; }
@@ -323,7 +322,7 @@ static void as_memory_range_add(AddressSpace *as, FlatRange *fr) }if (fr->readonly) { - phys_offset |=IO_MEM_ROM ; + phys_offset |= io_mem_rom.ram_addr; } cpu_register_physical_memory_log(int128_get64(fr->addr.start),
@@ -337,7 +336,7 @@ static void as_memory_range_del(AddressSpace *as, FlatRange *fr) {cpu_register_physical_memory (int128_get64 (fr->addr.start),int128_get64 (fr->addr.size), -IO_MEM_UNASSIGNED ); + io_mem_unassigned.ram_addr); }static void as_memory_log_start (AddressSpace *as,FlatRange *fr)
softmmu_template.h +7 -4
@@ -22,6 +22,7 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #include "qemu-timer.h" +#include "memory.h" #define DATA_SIZE (1 << SHIFT)
@@ -65,8 +66,9 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr, index = (physaddr >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); physaddr = (physaddr &TARGET_PAGE_MASK ) + addr; env->mem_io_pc = (unsigned long )retaddr; -if (index !=IO_MEM_RAM && index !=IO_MEM_ROM - && index !=IO_MEM_UNASSIGNED && index !=IO_MEM_NOTDIRTY +if (index != io_mem_ram.ram_addr && index != io_mem_rom.ram_addr + && index != io_mem_unassigned.ram_addr + && index != io_mem_notdirty.ram_addr && !can_do_io (env)) {cpu_io_recompile (env, retaddr); }
@@ -208,8 +210,9 @@ static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr,int index; index = (physaddr >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); physaddr = (physaddr &TARGET_PAGE_MASK ) + addr; -if (index !=IO_MEM_RAM && index !=IO_MEM_ROM - && index !=IO_MEM_UNASSIGNED && index !=IO_MEM_NOTDIRTY +if (index != io_mem_ram.ram_addr && index != io_mem_rom.ram_addr + && index != io_mem_unassigned.ram_addr + && index != io_mem_notdirty.ram_addr && !can_do_io (env)) {cpu_io_recompile (env, retaddr); }
Signature · 1 line
1.7.7.1
Re: [Qemu-devel] [PATCH 08/16] Convert IO_MEM_{RAM, ROM, UNASSIGNED, NOTDIRTY} to MemoryRegions
exec.c static inline uint32_t lduw_phys_internal(target_phys_addr_t addr, · line 4041
Quoted 2 lines · Avi Kivity
exec.c +1
-1-if (is_ram_rom_romd (pd)) { +if (!is_ram_rom_romd (pd)) {
Should be merged with a previous patch.
r~
Re: [Qemu-devel] [PATCH 08/16] Convert IO_MEM_{RAM, ROM, UNASSIGNED, NOTDIRTY} to MemoryRegions
Quoted 6 lines · Richard Henderson
exec.c static inline uint32_t lduw_phys_internal(target_phys_addr_t addr, · line 4041
Quoted 2 lines · Avi Kivity
exec.c +1
-1-if (is_ram_rom_romd (pd)) { +if (!is_ram_rom_romd (pd)) {Should be merged with a previous patch.
Fixed.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [Qemu-devel] [PATCH 08/16] Convert IO_MEM_{RAM, ROM, UNASSIGNED, NOTDIRTY} to MemoryRegions
In reply to Avi KivityQuoted 3 lines · Avi Kivity
These aren't real
regions, since they are never added to the memory hierarchy, but they allow reuse of the dispatch functionality.
This would be great as a comment...
cpu-common.h void cpu_physical_memory_write_rom(target_phys_addr_t addr, · line 115
Quoted 4 lines
cpu-common.h +4
-0+extern struct MemoryRegion io_mem_ram; +extern struct MemoryRegion io_mem_rom; +extern struct MemoryRegion io_mem_unassigned; +extern struct MemoryRegion io_mem_notdirty;
^^ here, so future readers will know their purpose without looking at git logs.
Stefan
PATCH 9/16 Switch cpu_register_physical_memory_log() to use MemoryRegions
In reply to Avi KivityStill internally using ram_addr.
--- exec-obsolete.h | 24 +++--------------------- exec.c | 24 +++++++++++++++++++----- memory.c | 44 ++++++++++++++++---------------------------- 3 files changed, 38 insertions(+), 54 deletions(-)
exec-obsolete.h +3 -21
@@ -36,27 +36,9 @@ int cpu_register_io_memory(CPUReadMemoryFunc * const *mem_read, void *opaque);void cpu_unregister_io_memory (int table_address); -void cpu_register_physical_memory_log (target_phys_addr_t start_addr, -ram_addr_t size, -ram_addr_t phys_offset, -ram_addr_t region_offset, -bool log_dirty); - -static inline void cpu_register_physical_memory_offset (target_phys_addr_t start_addr, -ram_addr_t size, -ram_addr_t phys_offset, -ram_addr_t region_offset) -{ -cpu_register_physical_memory_log (start_addr, size, phys_offset, - region_offset, false); -} - -static inline void cpu_register_physical_memory (target_phys_addr_t start_addr, -ram_addr_t size, -ram_addr_t phys_offset) -{ -cpu_register_physical_memory_offset (start_addr, size, phys_offset,0 ); -} +struct MemoryRegionSection ; +void cpu_register_physical_memory_log (struct MemoryRegionSection *section, +bool readable,bool readonly);void qemu_register_coalesced_mmio (target_phys_addr_t addr,ram_addr_t size);void qemu_unregister_coalesced_mmio (target_phys_addr_t addr,ram_addr_t size);
exec.c +19 -5
@@ -2510,18 +2510,32 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end,start_addr and region_offset are rounded down to a page boundary before calculating this offset. This should not be a problem unless the low bits of start_addr and region_offset differ. */ -void cpu_register_physical_memory_log (target_phys_addr_t start_addr, -ram_addr_t size, -ram_addr_t phys_offset, -ram_addr_t region_offset, -bool log_dirty) +void cpu_register_physical_memory_log (MemoryRegionSection *section, +bool readable,bool readonly) { +target_phys_addr_t start_addr = section->offset_within_address_space; +ram_addr_t size = section->size; +ram_addr_t phys_offset = section->mr->ram_addr; +ram_addr_t region_offset = section->offset_within_region;target_phys_addr_t addr, end_addr;PhysPageDesc *p;CPUState *env;ram_addr_t orig_size = size;subpage_t *subpage; +if (memory_region_is_ram (section->mr)) { + phys_offset += region_offset; + region_offset =0 ; + } + +if (!readable) { + phys_offset &= ~TARGET_PAGE_MASK & ~IO_MEM_ROMD ; + } + +if (readonly) { + phys_offset |= io_mem_rom.ram_addr; + } +assert (size);if (phys_offset == io_mem_unassigned.ram_addr) {
memory.c +15 -27
53 lines not on this page · raw message
Signature · 1 line
1.7.7.1
PATCH 10/16 Convert the subpage wrapper to be a MemoryRegion
In reply to Avi Kivity--- exec.c | 70 ++++++++++++++++----------------------------------------------- 1 files changed, 18 insertions(+), 52 deletions(-)
exec.c +18 -52
@@ -2472,6 +2472,7 @@ static inline void tlb_set_dirty(CPUState *env,#define SUBPAGE_IDX (addr) ((addr) & ~TARGET_PAGE_MASK) typedef struct subpage_t { + MemoryRegion iomem; target_phys_addr_t base; ram_addr_t sub_io_index[TARGET_PAGE_SIZE]; ram_addr_t region_offset[TARGET_PAGE_SIZE];
@@ -3309,10 +3310,10 @@ static void watch_mem_writel(void *opaque, target_phys_addr_t addr, watch_mem_writel, }; -static inline uint32_t subpage_readlen (subpage_t *mmio, -target_phys_addr_t addr, -unsigned int len) +static uint64_t subpage_read (void *opaque,target_phys_addr_t addr, +unsigned len) { +subpage_t *mmio = opaque;unsigned int idx =SUBPAGE_IDX (addr);#if defined(DEBUG_SUBPAGE ) printf("%s: subpage %p len %d addr " TARGET_FMT_plx " idx %d\n", __func__,
@@ -3321,66 +3322,29 @@ static inline uint32_t subpage_readlen (subpage_t *mmio, addr += mmio->region_offset[idx]; idx = mmio->sub_io_index[idx]; -return io_mem_read (idx, addr,1 <<len); +return io_mem_read (idx, addr, len); } -static inline void subpage_writelen (subpage_t *mmio,target_phys_addr_t addr, -uint32_t value,unsigned int len) +static void subpage_write (void *opaque,target_phys_addr_t addr, +uint64_t value,unsigned len) { +subpage_t *mmio = opaque;unsigned int idx =SUBPAGE_IDX (addr);#if defined(DEBUG_SUBPAGE ) -printf ("%s: subpage %p len %d addr " TARGET_FMT_plx" idx %d value %08x\n" , +printf ("%s: subpage %p len %d addr " TARGET_FMT_plx +" idx %d value %" PRIx64"\n" , __func__, mmio, len, addr, idx, value);#endif addr += mmio->region_offset[idx]; idx = mmio->sub_io_index[idx]; -io_mem_write (idx, addr, value,1 << len); +io_mem_write (idx, addr, value, len); } -static uint32_t subpage_readb (void *opaque,target_phys_addr_t addr) -{ -return subpage_readlen (opaque, addr,0 ); -} - -static void subpage_writeb (void *opaque,target_phys_addr_t addr, -uint32_t value) -{ -subpage_writelen (opaque, addr, value,0 ); -} - -static uint32_t subpage_readw (void *opaque,target_phys_addr_t addr) -{ -return subpage_readlen (opaque, addr,1 ); -} - -static void subpage_writew (void *opaque,target_phys_addr_t addr, -uint32_t value) -{ -subpage_writelen (opaque, addr, value,1 ); -} - -static uint32_t subpage_readl (void *opaque,target_phys_addr_t addr) -{ -return subpage_readlen (opaque, addr,2 ); -} - -static void subpage_writel (void *opaque,target_phys_addr_t addr, -uint32_t value) -{ -subpage_writelen (opaque, addr, value,2 ); -} - -static CPUReadMemoryFunc *const subpage_read[] = { - &subpage_readb, - &subpage_readw, - &subpage_readl, -}; - -static CPUWriteMemoryFunc *const subpage_write[] = { - &subpage_writeb, - &subpage_writew, - &subpage_writel, +static const MemoryRegionOps subpage_ops = { + .read = subpage_read, + .write = subpage_write, + .endianness =DEVICE_NATIVE_ENDIAN , };static uint32_t subpage_ram_readb (void *opaque,target_phys_addr_t addr)
@@ -3475,7 +3439,9 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end, mmio =g_malloc0 (sizeof (subpage_t)); mmio->base = base; - subpage_memory =cpu_register_io_memory (subpage_read, subpage_write, mmio); +memory_region_init_io (&mmio->iomem, &subpage_ops, mmio, +"subpage" ,TARGET_PAGE_SIZE ); + subpage_memory = mmio->iomem.ram_addr;#if defined(DEBUG_SUBPAGE )printf ("%s: %p base " TARGET_FMT_plx" len %08x %d\n" , __func__, mmio, base,TARGET_PAGE_SIZE , subpage_memory);
Signature · 1 line
1.7.7.1
PATCH 11/16 Convert IO_MEM_SUBPAGE_RAM to be a MemoryRegion
In reply to Avi Kivity--- cpu-common.h | 1 - exec.c | 72 +++++++++++++++++++-------------------------------------- 2 files changed, 24 insertions(+), 49 deletions(-)
cpu-common.h +0 -1
@@ -113,7 +113,6 @@ extern struct MemoryRegion io_mem_ram;extern struct MemoryRegion io_mem_rom;extern struct MemoryRegion io_mem_unassigned;extern struct MemoryRegion io_mem_notdirty; -#define IO_MEM_SUBPAGE_RAM (4 << IO_MEM_SHIFT)/* Acts like a ROM when read and like a device when written. */ #define IO_MEM_ROMD (1)
exec.c +24 -48
106 lines not on this page · raw message
Signature · 1 line
1.7.7.1
PATCH 12/16 Convert io_mem_watch to be a MemoryRegion
In reply to Avi Kivity--- exec.c | 73 ++++++++++++++++++++++----------------------------------------- 1 files changed, 26 insertions(+), 47 deletions(-)
exec.c +26 -47
@@ -212,7 +212,7 @@CPUReadMemoryFunc *_io_mem_read[IO_MEM_NB_ENTRIES ][4 ];void *io_mem_opaque[IO_MEM_NB_ENTRIES ];static char io_mem_used[IO_MEM_NB_ENTRIES ]; -static int io_mem_watch; +static MemoryRegion io_mem_watch;#endif /* log support */
@@ -2158,7 +2158,7 @@ void tlb_set_page(CPUState *env, target_ulong vaddr,if (vaddr == (wp->vaddr &TARGET_PAGE_MASK )) {/* Avoid trapping reads of pages with a write breakpoint. */ if ((prot &PAGE_WRITE ) || (wp->flags &BP_MEM_READ )) { - iotlb = io_mem_watch + paddr; + iotlb = io_mem_watch.ram_addr + paddr; address |=TLB_MMIO ;break ; }
@@ -3260,55 +3260,34 @@ static void check_watchpoint(int offset, int len_mask, int flags)/* Watchpoint access routines. Watchpoints are inserted using TLB tricks, so these check for a hit then pass through to the normal out-of-line phys routines. */ -static uint32_t watch_mem_readb (void *opaque,target_phys_addr_t addr) -{ -check_watchpoint (addr & ~TARGET_PAGE_MASK , ~0x0 ,BP_MEM_READ ); -return ldub_phys (addr); -} - -static uint32_t watch_mem_readw (void *opaque,target_phys_addr_t addr) -{ -check_watchpoint (addr & ~TARGET_PAGE_MASK , ~0x1 ,BP_MEM_READ ); -return lduw_phys (addr); -} - -static uint32_t watch_mem_readl (void *opaque,target_phys_addr_t addr) -{ -check_watchpoint (addr & ~TARGET_PAGE_MASK , ~0x3 ,BP_MEM_READ ); -return ldl_phys (addr); -} - -static void watch_mem_writeb (void *opaque,target_phys_addr_t addr, -uint32_t val) -{ -check_watchpoint (addr & ~TARGET_PAGE_MASK , ~0x0 ,BP_MEM_WRITE ); -stb_phys (addr, val); -} - -static void watch_mem_writew (void *opaque,target_phys_addr_t addr, -uint32_t val) +static uint64_t watch_mem_read (void *opaque,target_phys_addr_t addr, +unsigned size) { -check_watchpoint (addr & ~TARGET_PAGE_MASK , ~0x1 ,BP_MEM_WRITE ); -stw_phys (addr, val); +check_watchpoint (addr & ~TARGET_PAGE_MASK , ~(size -1 ),BP_MEM_READ ); +switch (size) { +case 1 :return ldub_phys (addr); +case 2 :return lduw_phys (addr); +case 4 :return ldl_phys (addr); +default :abort (); + } } -static void watch_mem_writel (void *opaque,target_phys_addr_t addr, -uint32_t val) +static void watch_mem_write (void *opaque,target_phys_addr_t addr, +uint64_t val,unsigned size) { -check_watchpoint (addr & ~TARGET_PAGE_MASK , ~0x3 ,BP_MEM_WRITE ); -stl_phys (addr, val); +check_watchpoint (addr & ~TARGET_PAGE_MASK , ~(size -1 ),BP_MEM_WRITE ); +switch (size) { +case 1 :stb_phys (addr, val); +case 2 :stw_phys (addr, val); +case 4 :stl_phys (addr, val); +default :abort (); + } } -static CPUReadMemoryFunc *const watch_mem_read[3 ] = { - watch_mem_readb, - watch_mem_readw, - watch_mem_readl, -}; - -static CPUWriteMemoryFunc *const watch_mem_write[3 ] = { - watch_mem_writeb, - watch_mem_writew, - watch_mem_writel, +static const MemoryRegionOps watch_mem_ops = { + .read = watch_mem_read, + .write = watch_mem_write, + .endianness =DEVICE_NATIVE_ENDIAN , }; static uint64_t subpage_read(void *opaque, target_phys_addr_t addr,
@@ -3515,8 +3494,8 @@ static void io_mem_init(void)for (i=0 ; i<5 ; i++) io_mem_used[i] =1 ; - io_mem_watch =cpu_register_io_memory (watch_mem_read, - watch_mem_write,NULL ); +memory_region_init_io (&io_mem_watch, &watch_mem_ops,NULL , +"watch" ,UINT64_MAX ); }static void memory_map_init (void )
Signature · 1 line
1.7.7.1
PATCH 13/16 Direct dispatch through MemoryRegion
In reply to Avi KivityNow that all mmio goes through MemoryRegions, we can convert io_mem_opaque to be a MemoryRegion pointer, and remove the thunks that convert from old-style CPU{Read,Write}MemoryFunc to MemoryRegionOps.
--- exec-all.h | 4 +- exec-obsolete.h | 5 +- exec.c | 40 +++++------------- memory.c | 122 ++++++++++++++++++------------------------------------- 4 files changed, 53 insertions(+), 118 deletions(-)
exec-all.h +1 -3
@@ -302,9 +302,7 @@ extern void *tci_tb_ptr;uint64_t io_mem_read (int index,target_phys_addr_t addr,unsigned size);void io_mem_write (int index,target_phys_addr_t addr,uint64_t value,unsigned size); -extern CPUWriteMemoryFunc *_io_mem_write[IO_MEM_NB_ENTRIES ][4 ]; -extern CPUReadMemoryFunc *_io_mem_read[IO_MEM_NB_ENTRIES ][4 ]; -extern void *io_mem_opaque[IO_MEM_NB_ENTRIES ]; +extern struct MemoryRegion *io_mem_region[IO_MEM_NB_ENTRIES ];void tlb_fill (CPUState *env1,target_ulong addr,int is_write,int mmu_idx,void *retaddr);
exec-obsolete.h +2 -3
@@ -31,9 +31,8 @@ ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr);void qemu_ram_free (ram_addr_t addr);void qemu_ram_free_from_ptr (ram_addr_t addr); -int cpu_register_io_memory (CPUReadMemoryFunc *const *mem_read, -CPUWriteMemoryFunc *const *mem_write, -void *opaque); +struct MemoryRegion ; +int cpu_register_io_memory (MemoryRegion *mr);void cpu_unregister_io_memory (int table_address);struct MemoryRegionSection ;
exec.c +10 -30
@@ -208,9 +208,7 @@static void memory_map_init (void );/* io memory support */ -CPUWriteMemoryFunc *_io_mem_write[IO_MEM_NB_ENTRIES ][4 ]; -CPUReadMemoryFunc *_io_mem_read[IO_MEM_NB_ENTRIES ][4 ]; -void *io_mem_opaque[IO_MEM_NB_ENTRIES ]; +MemoryRegion *io_mem_region[IO_MEM_NB_ENTRIES ];static char io_mem_used[IO_MEM_NB_ENTRIES ];static MemoryRegion io_mem_watch;#endif
@@ -2563,8 +2561,10 @@ void cpu_register_physical_memory_log(MemoryRegionSection *section, &p->phys_offset, orig_memory, p->region_offset); }else { - subpage = io_mem_opaque[(orig_memory & ~TARGET_PAGE_MASK ) - >>IO_MEM_SHIFT ]; +MemoryRegion *mr + = io_mem_region[(orig_memory & ~TARGET_PAGE_MASK ) + >>IO_MEM_SHIFT ]; + subpage =container_of (mr, subpage_t, iomem); }subpage_register (subpage, start_addr2, end_addr2, phys_offset, region_offset);
@@ -3427,13 +3427,8 @@ static int get_free_io_mem_idx(void)modified. If it is zero, a new io zone is allocated. The return value can be used with cpu_register_physical_memory(). (-1) is returned if error. */ -static int cpu_register_io_memory_fixed (int io_index, -CPUReadMemoryFunc *const *mem_read, -CPUWriteMemoryFunc *const *mem_write, -void *opaque) +static int cpu_register_io_memory_fixed (int io_index,MemoryRegion *mr) { -int i; -if (io_index <=0 ) { io_index =get_free_io_mem_idx ();if (io_index ==-1 )
@@ -3444,36 +3439,21 @@ static int cpu_register_io_memory_fixed(int io_index,return -1 ; } -for (i =0 ; i <3 ; ++i) { -assert (mem_read[i]); - _io_mem_read[io_index][i] = mem_read[i]; - } -for (i =0 ; i <3 ; ++i) { -assert (mem_write[i]); - _io_mem_write[io_index][i] = mem_write[i]; - } - io_mem_opaque[io_index] = opaque; + io_mem_region[io_index] = mr;return (io_index <<IO_MEM_SHIFT ); } -int cpu_register_io_memory (CPUReadMemoryFunc *const *mem_read, -CPUWriteMemoryFunc *const *mem_write, -void *opaque) +int cpu_register_io_memory (MemoryRegion *mr) { -return cpu_register_io_memory_fixed (0 , mem_read, mem_write, opaque); +return cpu_register_io_memory_fixed (0 , mr); }void cpu_unregister_io_memory (int io_table_address) { -int i;int io_index = io_table_address >>IO_MEM_SHIFT ; -for (i=0 ;i <3 ; i++) { - _io_mem_read[io_index][i] =NULL ; - _io_mem_write[io_index][i] =NULL ; - } - io_mem_opaque[io_index] =NULL ; + io_mem_region[io_index] =NULL ; io_mem_used[io_index] =0 ; }
memory.c +40 -82
170 lines not on this page · raw message
Signature · 1 line
1.7.7.1
Re: [Qemu-devel] [PATCH 13/16] Direct dispatch through MemoryRegion
Am 02.01.2012 17:33, schrieb Avi Kivity:
Quoted 13 lines
Now that all mmio goes through MemoryRegions, we can convert
io_mem_opaqueto be a MemoryRegion pointer, and remove the thunks that convert from old-style CPU{Read,Write}MemoryFunc to MemoryRegionOps.Signed-off-by Avi Kivity <[email protected]>memory.c +1
-0+static void adjust_endianness (MemoryRegion *mr,uint64_t *data,unsigned size) {
memory.c static uint32_t memory_region_read_thunk_n(void *_mr, · line 942
Quoted 10 lines
memory.c +9
-1-MemoryRegion *mr = _mr; +if (memory_region_wrong_endianness (mr)) { +switch (size) { +case 1 : +break ; +case 2 : + *data =bswap16 (*data); +break ; +case 4 : + *data =bswap32 (*data);
break; missing. Patch coming up.
Andreas
Quoted 5 lines
memory.c +5
-0+default : +abort (); + } + } +}
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
PATCH 14/16 Remove IO_MEM_SUBPAGE
In reply to Avi KivityReplace with a MemoryRegion flag.
--- cpu-common.h | 1 - exec.c | 10 +++++----- memory.c | 1 + memory.h | 1 + 4 files changed, 7 insertions(+), 6 deletions(-)
cpu-common.h +0 -1
@@ -116,7 +116,6 @@ extern struct MemoryRegion io_mem_notdirty;/* Acts like a ROM when read and like a device when written. */ #define IO_MEM_ROMD (1) -#define IO_MEM_SUBPAGE (2)#endif
exec.c +5 -5
@@ -2552,18 +2552,17 @@ void cpu_register_physical_memory_log(MemoryRegionSection *section,ram_addr_t orig_memory = p->phys_offset;target_phys_addr_t start_addr2, end_addr2;int need_subpage =0 ; +MemoryRegion *mr = io_mem_region[(orig_memory & ~TARGET_PAGE_MASK ) + >>IO_MEM_SHIFT ];CHECK_SUBPAGE (addr, start_addr, start_addr2, end_addr, end_addr2, need_subpage);if (need_subpage) { -if (!(orig_memory &IO_MEM_SUBPAGE )) { +if (!(mr->subpage)) { subpage =subpage_init ((addr &TARGET_PAGE_MASK ), &p->phys_offset, orig_memory, p->region_offset); }else { -MemoryRegion *mr - = io_mem_region[(orig_memory & ~TARGET_PAGE_MASK ) - >>IO_MEM_SHIFT ]; subpage =container_of (mr, subpage_t, iomem); } subpage_register(subpage, start_addr2, end_addr2, phys_offset,
@@ -3396,12 +3395,13 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end, mmio->base = base;memory_region_init_io (&mmio->iomem, &subpage_ops, mmio,"subpage" ,TARGET_PAGE_SIZE ); + mmio->iomem.subpage = true; subpage_memory = mmio->iomem.ram_addr;#if defined(DEBUG_SUBPAGE )printf ("%s: %p base " TARGET_FMT_plx" len %08x %d\n" , __func__, mmio, base,TARGET_PAGE_SIZE , subpage_memory);#endif - *phys = subpage_memory |IO_MEM_SUBPAGE ; + *phys = subpage_memory;subpage_register (mmio,0 ,TARGET_PAGE_SIZE -1 , orig_memory, region_offset);return mmio;
memory.c +1 -0
@@ -862,6 +862,7 @@ void memory_region_init(MemoryRegion *mr, } mr->addr =0 ; mr->offset =0 ; + mr->subpage = false; mr->enabled = true; mr->terminates = false; mr->ram = false;
memory.h +1 -0
@@ -119,6 +119,7 @@ struct MemoryRegion {void (*destructor)(MemoryRegion *mr);ram_addr_t ram_addr;IORange iorange; +bool subpage;bool terminates;bool readable;bool ram;
Signature · 1 line
1.7.7.1
PATCH 15/16 Drop IO_MEM_ROMD
In reply to Avi KivityUnlike ->readonly, ->readable is not inherited from aliase, so we can simply query the memory region.
--- cpu-common.h | 3 --- exec.c | 22 +++++++++++++--------- memory.c | 5 +++-- memory.h | 1 + 4 files changed, 17 insertions(+), 14 deletions(-)
cpu-common.h +0 -3
@@ -114,9 +114,6 @@ extern struct MemoryRegion io_mem_rom;extern struct MemoryRegion io_mem_unassigned;extern struct MemoryRegion io_mem_notdirty; -/* Acts like a ROM when read and like a device when written. */ -#define IO_MEM_ROMD (1) -#endif #endif /* !CPU_COMMON_H */
exec.c +13 -9
@@ -2091,9 +2091,18 @@ static bool is_ram_rom(ram_addr_t pd)return pd == io_mem_ram.ram_addr || pd == io_mem_rom.ram_addr; } +static bool is_romd (ram_addr_t pd) +{ +MemoryRegion *mr; + + pd &= ~TARGET_PAGE_MASK ; + mr = io_mem_region[pd >>IO_MEM_SHIFT ]; +return mr->rom_device && mr->readable; +} +static bool is_ram_rom_romd (ram_addr_t pd) { -return is_ram_rom (pd) || (pd &IO_MEM_ROMD ); +return is_ram_rom (pd) ||is_romd (pd); }/* Add a new TLB entry. At most one entry for a given virtual address
@@ -2126,7 +2135,7 @@ void tlb_set_page(CPUState *env, target_ulong vaddr,#endif address = vaddr; -if (!is_ram_rom (pd) && !(pd &IO_MEM_ROMD )) { +if (!is_ram_rom (pd) && !is_romd (pd)) {/* IO memory case (romd handled later) */ address |=TLB_MMIO ; }
@@ -2179,8 +2188,7 @@ void tlb_set_page(CPUState *env, target_ulong vaddr, te->addr_code =-1 ; }if (prot &PAGE_WRITE ) { -if ((pd & ~TARGET_PAGE_MASK ) == io_mem_rom.ram_addr || - (pd &IO_MEM_ROMD )) { +if ((pd & ~TARGET_PAGE_MASK ) == io_mem_rom.ram_addr ||is_romd (pd)) {/* Write access calls the I/O callback. */ te->addr_write = address |TLB_MMIO ; } else if ((pd & ~TARGET_PAGE_MASK) == io_mem_ram.ram_addr &&
@@ -2528,10 +2536,6 @@ void cpu_register_physical_memory_log(MemoryRegionSection *section, region_offset =0 ; } -if (!readable) { - phys_offset &= ~TARGET_PAGE_MASK & ~IO_MEM_ROMD ; - } -if (readonly) { phys_offset |= io_mem_rom.ram_addr; }
@@ -4379,7 +4383,7 @@ tb_page_addr_t get_page_addr_code(CPUState *env1, target_ulong addr) } pd = env1->tlb_table[mmu_idx][page_index].addr_code & ~TARGET_PAGE_MASK ;if (pd != io_mem_ram.ram_addr && pd != io_mem_rom.ram_addr - && !(pd &IO_MEM_ROMD )) { + && !is_romd (pd)) {#if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || defined(TARGET_SPARC )cpu_unassigned_access (env1, addr,0 ,1 ,0 ,4 );#else
memory.c +3 -2
@@ -838,7 +838,7 @@ static void memory_region_destructor_iomem(MemoryRegion *mr)static void memory_region_destructor_rom_device (MemoryRegion *mr) {qemu_ram_free (mr->ram_addr &TARGET_PAGE_MASK ); -cpu_unregister_io_memory (mr->ram_addr & ~(TARGET_PAGE_MASK |IO_MEM_ROMD )); +cpu_unregister_io_memory (mr->ram_addr & ~TARGET_PAGE_MASK ); }static bool memory_region_wrong_endianness (MemoryRegion *mr)
@@ -868,6 +868,7 @@ void memory_region_init(MemoryRegion *mr, mr->ram = false; mr->readable = true; mr->readonly = false; + mr->rom_device = false; mr->destructor = memory_region_destructor_none; mr->priority =0 ; mr->may_overlap = false;
@@ -1039,10 +1040,10 @@ void memory_region_init_rom_device(MemoryRegion *mr, mr->ops = ops; mr->opaque = opaque; mr->terminates = true; + mr->rom_device = true; mr->destructor = memory_region_destructor_rom_device; mr->ram_addr =qemu_ram_alloc (size, mr); mr->ram_addr |=cpu_register_io_memory (mr); - mr->ram_addr |=IO_MEM_ROMD ; }void memory_region_destroy (MemoryRegion *mr)
memory.h +1 -0
@@ -125,6 +125,7 @@ struct MemoryRegion {bool ram;bool readonly;/* For RAM regions */ bool enabled; +bool rom_device;MemoryRegion *alias;target_phys_addr_t alias_offset;unsigned priority;
Signature · 1 line
1.7.7.1
PATCH 16/16 Remove IO_MEM_SHIFT
In reply to Avi KivityWe no longer use any of the lower bits of a ram_addr, so we might as well use them for the io table index. This increases the number of potential I/O handlers by a factor of 8.
--- cpu-all.h | 2 +- cpu-common.h | 2 -- exec.c | 32 ++++++++++++++------------------ softmmu_template.h | 4 ++-- 4 files changed, 17 insertions(+), 23 deletions(-)
cpu-all.h +1 -1
@@ -503,7 +503,7 @@ extern int mem_prealloc;3 flags. The ROMD code stores the page ram offset in iotlb entry, so only a limited number of ids are avaiable. */ -#define IO_MEM_NB_ENTRIES (1 << (TARGET_PAGE_BITS - IO_MEM_SHIFT)) +#define IO_MEM_NB_ENTRIES (1 << TARGET_PAGE_BITS)/* Flags stored in the low bits of the TLB virtual address. These are defined so that fast path ram access is all zeros. */
cpu-common.h +0 -2
@@ -107,8 +107,6 @@ void stq_phys(target_phys_addr_t addr, uint64_t val);void cpu_physical_memory_write_rom (target_phys_addr_t addr,const uint8_t *buf,int len); -#define IO_MEM_SHIFT 3 -extern struct MemoryRegion io_mem_ram;extern struct MemoryRegion io_mem_rom;extern struct MemoryRegion io_mem_unassigned;
exec.c +14 -18
@@ -2096,7 +2096,7 @@ static bool is_romd(ram_addr_t pd)MemoryRegion *mr; pd &= ~TARGET_PAGE_MASK ; - mr = io_mem_region[pd >>IO_MEM_SHIFT ]; + mr = io_mem_region[pd];return mr->rom_device && mr->readable; }
@@ -2556,8 +2556,7 @@ void cpu_register_physical_memory_log(MemoryRegionSection *section,ram_addr_t orig_memory = p->phys_offset;target_phys_addr_t start_addr2, end_addr2;int need_subpage =0 ; -MemoryRegion *mr = io_mem_region[(orig_memory & ~TARGET_PAGE_MASK ) - >>IO_MEM_SHIFT ]; +MemoryRegion *mr = io_mem_region[orig_memory & ~TARGET_PAGE_MASK ];CHECK_SUBPAGE (addr, start_addr, start_addr2, end_addr, end_addr2, need_subpage);
@@ -3378,7 +3377,7 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end,if ((memory & ~TARGET_PAGE_MASK ) == io_mem_ram.ram_addr) { memory = io_mem_subpage_ram.ram_addr; } - memory = (memory >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); + memory &=IO_MEM_NB_ENTRIES -1 ;for (; idx <= eidx; idx++) { mmio->sub_io_index[idx] = memory; mmio->region_offset[idx] = region_offset;
@@ -3438,14 +3437,13 @@ static int cpu_register_io_memory_fixed(int io_index, MemoryRegion *mr)if (io_index ==-1 )return io_index; }else { - io_index >>=IO_MEM_SHIFT ;if (io_index >=IO_MEM_NB_ENTRIES )return -1 ; } io_mem_region[io_index] = mr; -return (io_index <<IO_MEM_SHIFT ); +return io_index; }int cpu_register_io_memory (MemoryRegion *mr)
@@ -3453,10 +3451,8 @@ int cpu_register_io_memory(MemoryRegion *mr)return cpu_register_io_memory_fixed (0 , mr); } -void cpu_unregister_io_memory (int io_table_address) +void cpu_unregister_io_memory (int io_index) { -int io_index = io_table_address >>IO_MEM_SHIFT ; - io_mem_region[io_index] =NULL ; io_mem_used[io_index] =0 ; }
@@ -3568,7 +3564,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,if (is_write) {if ((pd & ~TARGET_PAGE_MASK ) != io_mem_ram.ram_addr) {target_phys_addr_t addr1; - io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); + io_index = pd & (IO_MEM_NB_ENTRIES -1 ); addr1 = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;/* XXX: could force cpu_single_env to NULL to avoid potential bugs */
@@ -3607,7 +3603,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,if (!is_ram_rom_romd (pd)) {target_phys_addr_t addr1;/* I/O case */ - io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); + io_index = pd & (IO_MEM_NB_ENTRIES -1 ); addr1 = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;if (l >=4 && ((addr1 &3 ) ==0 )) {/* 32 bit read access */
@@ -3829,7 +3825,7 @@ static inline uint32_t ldl_phys_internal(target_phys_addr_t addr,if (!is_ram_rom_romd (pd)) {/* I/O case */ - io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); + io_index = pd & (IO_MEM_NB_ENTRIES -1 ); addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset; val =io_mem_read (io_index, addr,4 );#if defined(TARGET_WORDS_BIGENDIAN )
@@ -3890,7 +3886,7 @@ static inline uint64_t ldq_phys_internal(target_phys_addr_t addr,if (!is_ram_rom_romd (pd)) {/* I/O case */ - io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); + io_index = pd & (IO_MEM_NB_ENTRIES -1 ); addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;/* XXX This is broken when device endian != cpu endian.
@@ -3959,7 +3955,7 @@ static inline uint32_t lduw_phys_internal(target_phys_addr_t addr,if (!is_ram_rom_romd (pd)) {/* I/O case */ - io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); + io_index = pd & (IO_MEM_NB_ENTRIES -1 ); addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset; val =io_mem_read (io_index, addr,2 );#if defined(TARGET_WORDS_BIGENDIAN )
@@ -4019,7 +4015,7 @@ void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val) pd = p.phys_offset;if ((pd & ~TARGET_PAGE_MASK ) != io_mem_ram.ram_addr) { - io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); + io_index = pd & (IO_MEM_NB_ENTRIES -1 ); addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;io_mem_write (io_index, addr, val,4 ); }else {
@@ -4050,7 +4046,7 @@ void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val) pd = p.phys_offset;if ((pd & ~TARGET_PAGE_MASK ) != io_mem_ram.ram_addr) { - io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); + io_index = pd & (IO_MEM_NB_ENTRIES -1 ); addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;#ifdef TARGET_WORDS_BIGENDIAN io_mem_write (io_index, addr, val >>32 ,4 );
@@ -4079,7 +4075,7 @@ static inline void stl_phys_internal(target_phys_addr_t addr, uint32_t val, pd = p.phys_offset;if ((pd & ~TARGET_PAGE_MASK ) != io_mem_ram.ram_addr) { - io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); + io_index = pd & (IO_MEM_NB_ENTRIES -1 ); addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;#if defined(TARGET_WORDS_BIGENDIAN )if (endian ==DEVICE_LITTLE_ENDIAN ) {
@@ -4152,7 +4148,7 @@ static inline void stw_phys_internal(target_phys_addr_t addr, uint32_t val, pd = p.phys_offset;if ((pd & ~TARGET_PAGE_MASK ) != io_mem_ram.ram_addr) { - io_index = (pd >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); + io_index = pd & (IO_MEM_NB_ENTRIES -1 ); addr = (addr & ~TARGET_PAGE_MASK ) + p.region_offset;#if defined(TARGET_WORDS_BIGENDIAN )if (endian ==DEVICE_LITTLE_ENDIAN ) {
softmmu_template.h +2 -2
@@ -63,7 +63,7 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr, {DATA_TYPE res;int index; - index = (physaddr >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); + index = physaddr & (IO_MEM_NB_ENTRIES -1 ); physaddr = (physaddr &TARGET_PAGE_MASK ) + addr; env->mem_io_pc = (unsigned long )retaddr; if (index != io_mem_ram.ram_addr && index != io_mem_rom.ram_addr
@@ -208,7 +208,7 @@ static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr, void *retaddr) {int index; - index = (physaddr >>IO_MEM_SHIFT ) & (IO_MEM_NB_ENTRIES -1 ); + index = physaddr & (IO_MEM_NB_ENTRIES -1 ); physaddr = (physaddr &TARGET_PAGE_MASK ) + addr;if (index != io_mem_ram.ram_addr && index != io_mem_rom.ram_addr && index != io_mem_unassigned.ram_addr
Signature · 1 line
1.7.7.1
Quoted 9 lines · Avi Kivity
Avi Kivity (16):
memory: move endianness compensation to memory core
exec: makephys_page_find()return a temporary
memory: move mmio access to functions
memory: removeMemoryRegion::backend_registered
Fix wrongregion_offsetwhen overlaying a page with another Avoid range comparisons on io index types
Uninlineget_page_addr_code()
Convert IO_MEM_{RAM,ROM,UNASSIGNED,NOTDIRTY} to MemoryRegions
Quoted 8 lines
Switch
cpu_register_physical_memory_log()to use MemoryRegions Convert the subpage wrapper to be a MemoryRegion ConvertIO_MEM_SUBPAGE_RAMto be a MemoryRegion Convertio_mem_watchto be a MemoryRegion
Direct dispatch through MemoryRegion
RemoveIO_MEM_SUBPAGE
DropIO_MEM_ROMD
RemoveIO_MEM_SHIFT
Yaye! After this a relatively small patch will enable full 64-bit I/O.
r~