xref: /qemu/include/hw/ipack/ipack.h (revision 6ff5da16000f908140723e164d33a0b51a6c4162)
1 /*
2  * QEMU IndustryPack emulation
3  *
4  * Copyright (C) 2012 Igalia, S.L.
5  * Author: Alberto Garcia <berto@igalia.com>
6  *
7  * This code is licensed under the GNU GPL v2 or (at your option) any
8  * later version.
9  */
10 
11 #ifndef QEMU_IPACK_H
12 #define QEMU_IPACK_H
13 
14 #include "hw/qdev-core.h"
15 #include "hw/irq.h"
16 #include "qom/object.h"
17 
18 
19 #define TYPE_IPACK_BUS "IndustryPack"
20 OBJECT_DECLARE_SIMPLE_TYPE(IPackBus, IPACK_BUS)
21 
22 struct IPackBus {
23     BusState parent_obj;
24 
25     uint8_t n_slots;
26     uint8_t free_slot;
27     qemu_irq_handler set_irq;
28 };
29 
30 
31 #define TYPE_IPACK_DEVICE "ipack-device"
32 OBJECT_DECLARE_TYPE(IPackDevice, IPackDeviceClass,
33                     IPACK_DEVICE)
34 
35 struct IPackDeviceClass {
36     /*< private >*/
37     DeviceClass parent_class;
38     /*< public >*/
39 
40     DeviceRealize realize;
41     DeviceUnrealize unrealize;
42 
43     uint16_t (*io_read)(IPackDevice *dev, uint8_t addr);
44     void (*io_write)(IPackDevice *dev, uint8_t addr, uint16_t val);
45 
46     uint16_t (*id_read)(IPackDevice *dev, uint8_t addr);
47     void (*id_write)(IPackDevice *dev, uint8_t addr, uint16_t val);
48 
49     uint16_t (*int_read)(IPackDevice *dev, uint8_t addr);
50     void (*int_write)(IPackDevice *dev, uint8_t addr, uint16_t val);
51 
52     uint16_t (*mem_read16)(IPackDevice *dev, uint32_t addr);
53     void (*mem_write16)(IPackDevice *dev, uint32_t addr, uint16_t val);
54 
55     uint8_t (*mem_read8)(IPackDevice *dev, uint32_t addr);
56     void (*mem_write8)(IPackDevice *dev, uint32_t addr, uint8_t val);
57 };
58 
59 struct IPackDevice {
60     DeviceState parent_obj;
61 
62     int32_t slot;
63     /* IRQ objects for the IndustryPack INT0# and INT1# */
64     IRQState irq[2];
65 };
66 
67 extern const VMStateDescription vmstate_ipack_device;
68 
69 #define VMSTATE_IPACK_DEVICE(_field, _state)                            \
70     VMSTATE_STRUCT(_field, _state, 1, vmstate_ipack_device, IPackDevice)
71 
72 IPackDevice *ipack_device_find(IPackBus *bus, int32_t slot);
73 void ipack_bus_init(IPackBus *bus, size_t bus_size,
74                     DeviceState *parent,
75                     uint8_t n_slots,
76                     qemu_irq_handler handler);
77 
78 #endif
79