Add test device
[qemu-kvm/amd-iommu.git] / hw / testdev.c
blob199731efe2a2d4637759ce6031c6855dd8c670a4
1 #include "hw.h"
2 #include "qdev.h"
3 #include "isa.h"
5 struct testdev {
6 ISADevice dev;
7 CharDriverState *chr;
8 };
10 static void test_device_serial_write(void *opaque, uint32_t addr, uint32_t data)
12 struct testdev *dev = opaque;
13 uint8_t buf[1] = { data };
15 if (dev->chr) {
16 qemu_chr_write(dev->chr, buf, 1);
20 static void test_device_exit(void *opaque, uint32_t addr, uint32_t data)
22 exit(data);
25 static uint32_t test_device_memsize_read(void *opaque, uint32_t addr)
27 return ram_size;
30 static int init_test_device(ISADevice *isa)
32 struct testdev *dev = DO_UPCAST(struct testdev, dev, isa);
34 register_ioport_write(0xf1, 1, 1, test_device_serial_write, dev);
35 register_ioport_write(0xf4, 1, 4, test_device_exit, dev);
36 register_ioport_read(0xd1, 1, 4, test_device_memsize_read, dev);
37 return 0;
40 static ISADeviceInfo testdev_info = {
41 .qdev.name = "testdev",
42 .qdev.size = sizeof(struct testdev),
43 .init = init_test_device,
44 .qdev.props = (Property[]) {
45 DEFINE_PROP_CHR("chardev", struct testdev, chr),
46 DEFINE_PROP_END_OF_LIST(),
50 static void testdev_register_devices(void)
52 isa_qdev_register(&testdev_info);
55 device_init(testdev_register_devices)