Skip to content

Commit

Permalink
Search for io region correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin Rothwell committed May 16, 2016
1 parent 67a796c commit 380b81d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 3 additions & 1 deletion hw/pci/pci.c
Expand Up @@ -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),
Expand All @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions ioport.c
Expand Up @@ -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"
Expand All @@ -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 = {
Expand Down Expand Up @@ -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);

Expand Down
11 changes: 9 additions & 2 deletions memory.c
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 7 additions & 3 deletions test.c
Expand Up @@ -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");

Expand All @@ -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;*/
Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand Down

0 comments on commit 380b81d

Please sign in to comment.