From 380b81d0fb2f16c21552d894c76dd9d5bc950d61 Mon Sep 17 00:00:00 2001 From: Colin Rothwell Date: Mon, 16 May 2016 15:26:28 +0000 Subject: [PATCH] Search for io region correctly --- hw/pci/pci.c | 4 +++- ioport.c | 5 +++++ memory.c | 11 +++++++++-- test.c | 10 +++++++--- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index cf750df..5557b4b 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1122,7 +1122,8 @@ static void pci_update_mappings(PCIDevice *d) continue; } - /*PDBG("Updating mapping %d => 0x%lx.", i, new_addr);*/ + /*PDBG("Updating mapping %s in %s; %d => 0x%lx.", r->memory->name,*/ + /*r->address_space->name, i, new_addr);*/ /* now do the real mapping */ if (r->addr != PCI_BAR_UNMAPPED) { trace_pci_update_mappings_del(d, pci_bus_num(d->bus), @@ -1133,6 +1134,7 @@ static void pci_update_mappings(PCIDevice *d) } r->addr = new_addr; if (r->addr != PCI_BAR_UNMAPPED) { + /*PDBG("Adding mapping.");*/ trace_pci_update_mappings_add(d, pci_bus_num(d->bus), PCI_FUNC(d->devfn), PCI_SLOT(d->devfn), diff --git a/ioport.c b/ioport.c index 783a3ae..0868674 100644 --- a/ioport.c +++ b/ioport.c @@ -25,6 +25,8 @@ * splitted out ioport related stuffs from vl.c. */ +#include "pcie-debug.h" + #include "exec/ioport.h" #include "trace.h" #include "exec/memory.h" @@ -46,12 +48,14 @@ typedef struct MemoryRegionPortioList { static uint64_t unassigned_io_read(void *opaque, hwaddr addr, unsigned size) { + PDBG("Unassigned io read: 0x%lx", addr); return -1ULL; } static void unassigned_io_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { + PDBG("Unassigned io write: 0x%lx", addr, val); } const MemoryRegionOps unassigned_io_ops = { @@ -197,6 +201,7 @@ static uint64_t portio_read(void *opaque, hwaddr addr, unsigned size) static void portio_write(void *opaque, hwaddr addr, uint64_t data, unsigned size) { + PDBG("."); MemoryRegionPortioList *mrpio = opaque; const MemoryRegionPortio *mrp = find_portio(mrpio, addr, size, true); diff --git a/memory.c b/memory.c index 7424f8a..2d7ef8e 100644 --- a/memory.c +++ b/memory.c @@ -428,6 +428,7 @@ static void memory_region_write_accessor(MemoryRegion *mr, } tmp = (*value >> shift) & mask; trace_memory_region_ops_write(mr, addr, tmp, size); + /*PDBG("Write to %s, %lx", mr->name, addr);*/ mr->ops->write(mr->opaque, addr, tmp, size); } @@ -458,6 +459,8 @@ static void access_with_adjusted_size(hwaddr addr, /* FIXME: support unaligned access? */ access_size = MAX(MIN(size, access_size_max), access_size_min); access_mask = -1ULL >> (64 - access_size * 8); + /*PDBG("access_size: %d, access_mask: %lx, big_endian: %d",*/ + /*access_size, access_mask, memory_region_big_endian(mr));*/ if (memory_region_big_endian(mr)) { for (i = 0; i < size; i += access_size) { access(mr, addr + i, value, access_size, @@ -1050,8 +1053,9 @@ bool memory_region_access_valid(MemoryRegion *mr, for (i = 0; i < size; i += access_size) { if (!mr->ops->valid.accepts(mr->opaque, addr + i, access_size, is_write)) { - PDBG("Memory region does not accept %s access to addr 0x%lx of %d" - " bytes", is_write ? "write" : "read", addr + i, access_size); + PDBG("Memory region %s does not accept %s access to addr 0x%lx of %d" + " bytes", is_write ? "write" : "read", mr->name, addr + i, + access_size); return false; } } @@ -1098,7 +1102,10 @@ static bool memory_region_dispatch_write(MemoryRegion *mr, uint64_t data, unsigned size) { + /*PDBG(".");*/ if (!memory_region_access_valid(mr, addr, size, true)) { + PDBG("Write access to 0x%lx in %s invalid.", + addr, mr->name); unassigned_mem_write(mr, addr, data, size); return true; } diff --git a/test.c b/test.c index 922c10e..8d6ca85 100644 --- a/test.c +++ b/test.c @@ -929,7 +929,7 @@ main(int argc, char *argv[]) MemoryRegion *pci_memory; pci_memory = g_new(MemoryRegion, 1); - memory_region_init(pci_memory, NULL, "pci", UINT64_MAX); + memory_region_init(pci_memory, NULL, "my-pci-memory", UINT64_MAX); printf("Created pci memory region.\n"); @@ -945,6 +945,7 @@ main(int argc, char *argv[]) q35_host->mch.pci_address_space = pci_memory; q35_host->mch.system_memory = get_system_memory(); q35_host->mch.address_space_io = get_system_io(); + PDBG("System IO name: %s", get_system_io()->name); /*q35_host->mch.below_4g_mem_size = below_4g_mem_size;*/ /*q35_host->mch.above_4g_mem_size = above_4g_mem_size;*/ /*q35_host->mch.guest_info = guest_info;*/ @@ -1153,9 +1154,12 @@ main(int argc, char *argv[]) * */ + MemoryRegion *target_region = memory_region_find(get_system_io(), + tlp_in[2], 4).mr; + if (dir == TLPD_WRITE) { send_length = 12; - assert(io_mem_write(get_system_io(), tlp_in[2], tlp_in[3], 4) + assert(io_mem_write(target_region, tlp_in[2], tlp_in[3], 4) == false); if (card_reg == -1 && tlp_in[2] == io_region) { @@ -1168,7 +1172,7 @@ main(int argc, char *argv[]) } } else { send_length = 16; - assert(io_mem_read(get_system_io(), tlp_in[2], + assert(io_mem_read(target_region, tlp_in[2], (uint64_t *)tlp_out_body, 4) == false);