xref: /qemu/include/hw/misc/mac_via.h (revision e3a6e0da)
1 /*
2  *
3  * Copyright (c) 2011-2018 Laurent Vivier
4  *
5  * This work is licensed under the terms of the GNU GPL, version 2 or later.
6  * See the COPYING file in the top-level directory.
7  */
8 
9 #ifndef HW_MISC_MAC_VIA_H
10 #define HW_MISC_MAC_VIA_H
11 
12 #include "exec/memory.h"
13 #include "hw/sysbus.h"
14 #include "hw/misc/mos6522.h"
15 #include "qom/object.h"
16 
17 
18 /* VIA 1 */
19 #define VIA1_IRQ_ONE_SECOND_BIT 0
20 #define VIA1_IRQ_VBLANK_BIT     1
21 #define VIA1_IRQ_ADB_READY_BIT  2
22 #define VIA1_IRQ_ADB_DATA_BIT   3
23 #define VIA1_IRQ_ADB_CLOCK_BIT  4
24 
25 #define VIA1_IRQ_NB             8
26 
27 #define VIA1_IRQ_ONE_SECOND (1 << VIA1_IRQ_ONE_SECOND_BIT)
28 #define VIA1_IRQ_VBLANK     (1 << VIA1_IRQ_VBLANK_BIT)
29 #define VIA1_IRQ_ADB_READY  (1 << VIA1_IRQ_ADB_READY_BIT)
30 #define VIA1_IRQ_ADB_DATA   (1 << VIA1_IRQ_ADB_DATA_BIT)
31 #define VIA1_IRQ_ADB_CLOCK  (1 << VIA1_IRQ_ADB_CLOCK_BIT)
32 
33 
34 #define TYPE_MOS6522_Q800_VIA1 "mos6522-q800-via1"
35 typedef struct MOS6522Q800VIA1State MOS6522Q800VIA1State;
36 DECLARE_INSTANCE_CHECKER(MOS6522Q800VIA1State, MOS6522_Q800_VIA1,
37                          TYPE_MOS6522_Q800_VIA1)
38 
39 struct MOS6522Q800VIA1State {
40     /*< private >*/
41     MOS6522State parent_obj;
42 
43     qemu_irq irqs[VIA1_IRQ_NB];
44     uint8_t last_b;
45     uint8_t PRAM[256];
46 
47     /* external timers */
48     QEMUTimer *one_second_timer;
49     int64_t next_second;
50     QEMUTimer *VBL_timer;
51     int64_t next_VBL;
52 };
53 
54 
55 /* VIA 2 */
56 #define VIA2_IRQ_SCSI_DATA_BIT  0
57 #define VIA2_IRQ_SLOT_BIT       1
58 #define VIA2_IRQ_UNUSED_BIT     2
59 #define VIA2_IRQ_SCSI_BIT       3
60 #define VIA2_IRQ_ASC_BIT        4
61 
62 #define VIA2_IRQ_NB             8
63 
64 #define VIA2_IRQ_SCSI_DATA  (1 << VIA2_IRQ_SCSI_DATA_BIT)
65 #define VIA2_IRQ_SLOT       (1 << VIA2_IRQ_SLOT_BIT)
66 #define VIA2_IRQ_UNUSED     (1 << VIA2_IRQ_SCSI_BIT)
67 #define VIA2_IRQ_SCSI       (1 << VIA2_IRQ_UNUSED_BIT)
68 #define VIA2_IRQ_ASC        (1 << VIA2_IRQ_ASC_BIT)
69 
70 #define TYPE_MOS6522_Q800_VIA2 "mos6522-q800-via2"
71 typedef struct MOS6522Q800VIA2State MOS6522Q800VIA2State;
72 DECLARE_INSTANCE_CHECKER(MOS6522Q800VIA2State, MOS6522_Q800_VIA2,
73                          TYPE_MOS6522_Q800_VIA2)
74 
75 struct MOS6522Q800VIA2State {
76     /*< private >*/
77     MOS6522State parent_obj;
78 };
79 
80 
81 #define TYPE_MAC_VIA "mac_via"
82 typedef struct MacVIAState MacVIAState;
83 DECLARE_INSTANCE_CHECKER(MacVIAState, MAC_VIA,
84                          TYPE_MAC_VIA)
85 
86 struct MacVIAState {
87     SysBusDevice busdev;
88 
89     VMChangeStateEntry *vmstate;
90 
91     /* MMIO */
92     MemoryRegion mmio;
93     MemoryRegion via1mem;
94     MemoryRegion via2mem;
95 
96     /* VIAs */
97     MOS6522Q800VIA1State mos6522_via1;
98     MOS6522Q800VIA2State mos6522_via2;
99 
100     /* RTC */
101     uint32_t tick_offset;
102 
103     uint8_t data_out;
104     int data_out_cnt;
105     uint8_t data_in;
106     uint8_t data_in_cnt;
107     uint8_t cmd;
108     int wprotect;
109     int alt;
110     BlockBackend *blk;
111 
112     /* ADB */
113     ADBBusState adb_bus;
114     qemu_irq adb_data_ready;
115     int adb_data_in_size;
116     int adb_data_in_index;
117     int adb_data_out_index;
118     uint8_t adb_data_in[128];
119     uint8_t adb_data_out[16];
120     uint8_t adb_autopoll_cmd;
121 };
122 
123 #endif
124