Re: [Qemu-devel] [PATCH v4 26/39] pcnet: convert to memory API
Avi Kivity wrote: Also related chips. Reviewed-by: Richard Henderson r...@twiddle.net Reviewed-by: Anthony Liguori aligu...@us.ibm.com Signed-off-by: Avi Kivity a...@redhat.com --- hw/lance.c | 31 ++- hw/pcnet-pci.c | 74 +-- hw/pcnet.h |4 ++- 3 files changed, 61 insertions(+), 48 deletions(-) diff --git a/hw/lance.c b/hw/lance.c index ddb1cbb..8e20360 100644 --- a/hw/lance.c +++ b/hw/lance.c @@ -55,8 +55,8 @@ static void parent_lance_reset(void *opaque, int irq, int level) pcnet_h_reset(d-state); } -static void lance_mem_writew(void *opaque, target_phys_addr_t addr, - uint32_t val) +static void lance_mem_write(void *opaque, target_phys_addr_t addr, +uint64_t val, unsigned size) { SysBusPCNetState *d = opaque; @@ -64,7 +64,8 @@ static void lance_mem_writew(void *opaque, target_phys_addr_t addr, pcnet_ioport_writew(d-state, addr, val 0x); } -static uint32_t lance_mem_readw(void *opaque, target_phys_addr_t addr) +static uint64_t lance_mem_read(void *opaque, target_phys_addr_t addr, + unsigned size) { SysBusPCNetState *d = opaque; uint32_t val; @@ -74,16 +75,14 @@ static uint32_t lance_mem_readw(void *opaque, target_phys_addr_t addr) return val 0x; } -static CPUReadMemoryFunc * const lance_mem_read[3] = { -NULL, -lance_mem_readw, -NULL, -}; - -static CPUWriteMemoryFunc * const lance_mem_write[3] = { -NULL, -lance_mem_writew, -NULL, +static const MemoryRegionOps lance_mem_ops = { +.read = lance_mem_read, +.write = lance_mem_write, +.endianness = DEVICE_NATIVE_ENDIAN, +.valid = { +.min_access_size = 2, +.max_access_size = 2, +}, }; static void lance_cleanup(VLANClientState *nc) @@ -117,13 +116,11 @@ static int lance_init(SysBusDevice *dev) SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev); PCNetState *s = d-state; -s-mmio_index = -cpu_register_io_memory(lance_mem_read, lance_mem_write, d, - DEVICE_NATIVE_ENDIAN); +memory_region_init_io(s-mmio, lance_mem_ops, s, lance-mmio, 4); You've switched up d and s here, so anything that tries to talk to the ethernet, such as a sparc32 guest, will now cause Qemu to segfault. Bob
Re: [Qemu-devel] [PATCH v4 26/39] pcnet: convert to memory API
On 08/09/2011 09:55 AM, Bob Breuer wrote: static void lance_cleanup(VLANClientState *nc) @@ -117,13 +116,11 @@ static int lance_init(SysBusDevice *dev) SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev); PCNetState *s =d-state; -s-mmio_index = -cpu_register_io_memory(lance_mem_read, lance_mem_write, d, - DEVICE_NATIVE_ENDIAN); +memory_region_init_io(s-mmio,lance_mem_ops, s, lance-mmio, 4); You've switched up d and s here, so anything that tries to talk to the ethernet, such as a sparc32 guest, will now cause Qemu to segfault. Good catch; will post a fix. Maybe keeping the opaque wasn't such a good idea. -- I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Re: [Qemu-devel] [PATCH v4 26/39] pcnet: convert to memory API
On 08/09/2011 03:48 PM, Michael S. Tsirkin wrote: But in some cases, we can't, and the it's a pain having to wrap MemoryRegion in another structure containing an opaque. I guess, even though that wrapping structure would use a proper type, not an opaque. Yes, of course - that's what the first version did. Maybe a good compromise is to: - keep MemoryRegion::opaque - pass a MemoryRegion *mr to callbacks instead of opaque - use container_of() when possible - use mr-opaque otherwise Right. This even saves a memory dereference when opaque is unused. I'll put this on the TODO (as well as writing the TODO). -- error compiling committee.c: too many arguments to function
Re: [Qemu-devel] [PATCH v4 26/39] pcnet: convert to memory API
On Tue, Aug 09, 2011 at 09:52:17AM +0300, Avi Kivity wrote: On 08/09/2011 09:55 AM, Bob Breuer wrote: static void lance_cleanup(VLANClientState *nc) @@ -117,13 +116,11 @@ static int lance_init(SysBusDevice *dev) SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev); PCNetState *s =d-state; -s-mmio_index = -cpu_register_io_memory(lance_mem_read, lance_mem_write, d, - DEVICE_NATIVE_ENDIAN); +memory_region_init_io(s-mmio,lance_mem_ops, s, lance-mmio, 4); You've switched up d and s here, so anything that tries to talk to the ethernet, such as a sparc32 guest, will now cause Qemu to segfault. Good catch; will post a fix. Maybe keeping the opaque wasn't such a good idea. Yes, we typically can get from the mmio to the device state using container_of. -- I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Re: [Qemu-devel] [PATCH v4 26/39] pcnet: convert to memory API
On 08/09/2011 03:42 PM, Michael S. Tsirkin wrote: On Tue, Aug 09, 2011 at 09:52:17AM +0300, Avi Kivity wrote: On 08/09/2011 09:55 AM, Bob Breuer wrote: static void lance_cleanup(VLANClientState *nc) @@ -117,13 +116,11 @@ static int lance_init(SysBusDevice *dev) SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev); PCNetState *s =d-state; -s-mmio_index = -cpu_register_io_memory(lance_mem_read, lance_mem_write, d, - DEVICE_NATIVE_ENDIAN); +memory_region_init_io(s-mmio,lance_mem_ops, s, lance-mmio, 4); You've switched up d and s here, so anything that tries to talk to the ethernet, such as a sparc32 guest, will now cause Qemu to segfault. Good catch; will post a fix. Maybe keeping the opaque wasn't such a good idea. Yes, we typically can get from the mmio to the device state using container_of. But in some cases, we can't, and the it's a pain having to wrap MemoryRegion in another structure containing an opaque. Maybe a good compromise is to: - keep MemoryRegion::opaque - pass a MemoryRegion *mr to callbacks instead of opaque - use container_of() when possible - use mr-opaque otherwise -- error compiling committee.c: too many arguments to function
Re: [Qemu-devel] [PATCH v4 26/39] pcnet: convert to memory API
On Tue, Aug 09, 2011 at 03:44:35PM +0300, Avi Kivity wrote: On 08/09/2011 03:42 PM, Michael S. Tsirkin wrote: On Tue, Aug 09, 2011 at 09:52:17AM +0300, Avi Kivity wrote: On 08/09/2011 09:55 AM, Bob Breuer wrote: static void lance_cleanup(VLANClientState *nc) @@ -117,13 +116,11 @@ static int lance_init(SysBusDevice *dev) SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev); PCNetState *s =d-state; -s-mmio_index = -cpu_register_io_memory(lance_mem_read, lance_mem_write, d, - DEVICE_NATIVE_ENDIAN); +memory_region_init_io(s-mmio,lance_mem_ops, s, lance-mmio, 4); You've switched up d and s here, so anything that tries to talk to the ethernet, such as a sparc32 guest, will now cause Qemu to segfault. Good catch; will post a fix. Maybe keeping the opaque wasn't such a good idea. Yes, we typically can get from the mmio to the device state using container_of. But in some cases, we can't, and the it's a pain having to wrap MemoryRegion in another structure containing an opaque. I guess, even though that wrapping structure would use a proper type, not an opaque. Maybe a good compromise is to: - keep MemoryRegion::opaque - pass a MemoryRegion *mr to callbacks instead of opaque - use container_of() when possible - use mr-opaque otherwise Right. This even saves a memory dereference when opaque is unused. -- error compiling committee.c: too many arguments to function