Skip to content

Commit

Permalink
pc-testdev: add I/O port to test memory.c auto split/combine
Browse files Browse the repository at this point in the history
The ports at 0xe8..0xeb have impl.min/max_access_size == 1, so
that memory accesses are split and combined by the memory core.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Message-id: 1374501278-31549-29-git-send-email-pbonzini@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
  • Loading branch information
bonzini authored and Anthony Liguori committed Jul 25, 2013
1 parent e7342aa commit d2f5ea9
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
15 changes: 15 additions & 0 deletions hw/misc/pc-testdev.c
Expand Up @@ -49,6 +49,7 @@ typedef struct PCTestdev {
ISADevice parent_obj;

MemoryRegion ioport;
MemoryRegion ioport_byte;
MemoryRegion flush;
MemoryRegion irq;
MemoryRegion iomem;
Expand Down Expand Up @@ -102,6 +103,16 @@ static const MemoryRegionOps test_ioport_ops = {
.endianness = DEVICE_LITTLE_ENDIAN,
};

static const MemoryRegionOps test_ioport_byte_ops = {
.read = test_ioport_read,
.write = test_ioport_write,
.valid.min_access_size = 1,
.valid.max_access_size = 4,
.impl.min_access_size = 1,
.impl.max_access_size = 1,
.endianness = DEVICE_LITTLE_ENDIAN,
};

static void test_flush_page(void *opaque, hwaddr addr, uint64_t data,
unsigned len)
{
Expand Down Expand Up @@ -156,6 +167,9 @@ static void testdev_realizefn(DeviceState *d, Error **errp)

memory_region_init_io(&dev->ioport, OBJECT(dev), &test_ioport_ops, dev,
"pc-testdev-ioport", 4);
memory_region_init_io(&dev->ioport_byte, OBJECT(dev),
&test_ioport_byte_ops, dev,
"pc-testdev-ioport-byte", 4);
memory_region_init_io(&dev->flush, OBJECT(dev), &test_flush_ops, dev,
"pc-testdev-flush-page", 4);
memory_region_init_io(&dev->irq, OBJECT(dev), &test_irq_ops, dev,
Expand All @@ -165,6 +179,7 @@ static void testdev_realizefn(DeviceState *d, Error **errp)

memory_region_add_subregion(io, 0xe0, &dev->ioport);
memory_region_add_subregion(io, 0xe4, &dev->flush);
memory_region_add_subregion(io, 0xe8, &dev->ioport_byte);
memory_region_add_subregion(io, 0x2000, &dev->irq);
memory_region_add_subregion(mem, 0xff000000, &dev->iomem);
}
Expand Down
102 changes: 102 additions & 0 deletions tests/endianness-test.c
Expand Up @@ -190,6 +190,100 @@ static void test_endianness(gconstpointer data)
g_free(args);
}

static void test_endianness_split(gconstpointer data)
{
const TestCase *test = data;
char *args;

args = g_strdup_printf("-display none -M %s%s%s -device pc-testdev",
test->machine,
test->superio ? " -device " : "",
test->superio ?: "");
qtest_start(args);
isa_outl(test, 0xe8, 0x87654321);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4321);

isa_outw(test, 0xea, 0x8866);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x88664321);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8866);
g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4321);

isa_outw(test, 0xe8, 0x4422);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x88664422);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8866);
g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4422);

isa_outb(test, 0xeb, 0x87);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87664422);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8766);

isa_outb(test, 0xea, 0x65);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654422);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4422);

isa_outb(test, 0xe9, 0x43);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654322);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4322);

isa_outb(test, 0xe8, 0x21);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4321);
qtest_quit(global_qtest);
g_free(args);
}

static void test_endianness_combine(gconstpointer data)
{
const TestCase *test = data;
char *args;

args = g_strdup_printf("-display none -M %s%s%s -device pc-testdev",
test->machine,
test->superio ? " -device " : "",
test->superio ?: "");
qtest_start(args);
isa_outl(test, 0xe0, 0x87654321);
g_assert_cmphex(isa_inl(test, 0xe8), ==, 0x87654321);
g_assert_cmphex(isa_inw(test, 0xea), ==, 0x8765);
g_assert_cmphex(isa_inw(test, 0xe8), ==, 0x4321);

isa_outw(test, 0xe2, 0x8866);
g_assert_cmphex(isa_inl(test, 0xe8), ==, 0x88664321);
g_assert_cmphex(isa_inw(test, 0xea), ==, 0x8866);
g_assert_cmphex(isa_inw(test, 0xe8), ==, 0x4321);

isa_outw(test, 0xe0, 0x4422);
g_assert_cmphex(isa_inl(test, 0xe8), ==, 0x88664422);
g_assert_cmphex(isa_inw(test, 0xea), ==, 0x8866);
g_assert_cmphex(isa_inw(test, 0xe8), ==, 0x4422);

isa_outb(test, 0xe3, 0x87);
g_assert_cmphex(isa_inl(test, 0xe8), ==, 0x87664422);
g_assert_cmphex(isa_inw(test, 0xea), ==, 0x8766);

isa_outb(test, 0xe2, 0x65);
g_assert_cmphex(isa_inl(test, 0xe8), ==, 0x87654422);
g_assert_cmphex(isa_inw(test, 0xea), ==, 0x8765);
g_assert_cmphex(isa_inw(test, 0xe8), ==, 0x4422);

isa_outb(test, 0xe1, 0x43);
g_assert_cmphex(isa_inl(test, 0xe8), ==, 0x87654322);
g_assert_cmphex(isa_inw(test, 0xea), ==, 0x8765);
g_assert_cmphex(isa_inw(test, 0xe8), ==, 0x4322);

isa_outb(test, 0xe0, 0x21);
g_assert_cmphex(isa_inl(test, 0xe8), ==, 0x87654321);
g_assert_cmphex(isa_inw(test, 0xea), ==, 0x8765);
g_assert_cmphex(isa_inw(test, 0xe8), ==, 0x4321);
qtest_quit(global_qtest);
g_free(args);
}

int main(int argc, char **argv)
{
const char *arch = qtest_get_arch();
Expand All @@ -206,6 +300,14 @@ int main(int argc, char **argv)
path = g_strdup_printf("/%s/endianness/%s",
arch, test_cases[i].machine);
g_test_add_data_func(path, &test_cases[i], test_endianness);

path = g_strdup_printf("/%s/endianness/split/%s",
arch, test_cases[i].machine);
g_test_add_data_func(path, &test_cases[i], test_endianness_split);

path = g_strdup_printf("/%s/endianness/combine/%s",
arch, test_cases[i].machine);
g_test_add_data_func(path, &test_cases[i], test_endianness_combine);
}

ret = g_test_run();
Expand Down

0 comments on commit d2f5ea9

Please sign in to comment.