]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/blob - hw/apohw.c
apohw: Added VM state descriptions.
[lisovros/qemu_apohw.git] / hw / apohw.c
1 /*
2  *  Virtual I/O PCI card + simple terminal connected
3  *  to this card via 8bit parallel bus.
4  *  Hardware used for teaching A0b36APO:
5  *  https://edux.feld.cvut.cz/courses/A0B36APO/tutorials/10/start
6  *
7  *  Copyright (C) 2012 Rostislav Lisovy (lisovy@gmail.com)
8  *
9  *  Licensed under GPLv3 license
10 */
11
12 #include "hw.h"
13 #include "pci.h"
14 #include <unistd.h>
15
16 #define PCI_VENDOR_ID_ALTERA                            0x1172
17 #define PCI_DEVICE_ID_ALTERA_CORPORATION_DEVICE         0x1f32
18
19 typedef struct apohw_state_t {
20         uint8_t emul_bus_ctrl;
21         uint8_t emul_bus_data_out;
22         uint8_t emul_bus_data_in;
23 } apohw_state_t;
24
25 typedef struct {
26         PCIDevice dev;
27         apohw_state_t apohw;
28 } apohw_pci_state_t;
29
30 /* ------------------------------------------------------------------------- */
31
32 static int pci_apohw_init(PCIDevice *pci_dev)
33 {
34         printf("apohw started\n");
35         return 0;
36 }
37
38 static int pci_apohw_exit(PCIDevice *pci_dev)
39 {
40         return 0;
41 }
42
43 const VMStateDescription apohw_vmsd = {
44         .name = "apohw",
45         .version_id = 2, // Wut?
46         .minimum_version_id = 0,
47         .minimum_version_id_old = 0,
48         .fields = (VMStateField []) {
49                 VMSTATE_UNUSED(0x8040),
50                 VMSTATE_UINT8(emul_bus_ctrl, apohw_state_t),
51                 VMSTATE_UNUSED(0x20),
52                 VMSTATE_UINT8(emul_bus_data_out, apohw_state_t),
53                 VMSTATE_UNUSED(0x20),
54                 VMSTATE_UINT8(emul_bus_data_in, apohw_state_t),
55                 VMSTATE_END_OF_LIST()
56         }
57 };
58
59 static const VMStateDescription apohw_pci_vmsd = {
60         .name = "apohw",
61         .version_id = 3, // Wat?
62         .minimum_version_id = 3,
63         .minimum_version_id_old = 3,
64         .fields = (VMStateField[]) {
65             VMSTATE_PCI_DEVICE(dev, apohw_pci_state_t),
66             VMSTATE_STRUCT(apohw, apohw_pci_state_t, 0, apohw_vmsd, apohw_state_t),
67             VMSTATE_END_OF_LIST()
68         }
69 };
70
71 static void apohw_class_init(ObjectClass *klass, void *data)
72 {
73         PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
74
75         k->init = pci_apohw_init;
76         k->exit = pci_apohw_exit;
77         k->vendor_id = PCI_VENDOR_ID_ALTERA;
78         k->device_id = PCI_DEVICE_ID_ALTERA_CORPORATION_DEVICE;
79         k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
80 }
81
82 static DeviceInfo apohw_info = {
83         .name = "apohw",
84         .size = sizeof(apohw_pci_state_t),
85         .vmsd = &apohw_pci_vmsd,
86         .class_init = apohw_class_init,
87 };
88
89 static void apohw_register_device(void)
90 {
91         pci_qdev_register(&apohw_info);
92 }
93
94 device_init(apohw_register_device)