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_60HZ_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_60HZ (1 << VIA1_IRQ_60HZ_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 OBJECT_DECLARE_SIMPLE_TYPE(MOS6522Q800VIA1State, MOS6522_Q800_VIA1) 36 37 struct MOS6522Q800VIA1State { 38 /*< private >*/ 39 MOS6522State parent_obj; 40 41 qemu_irq irqs[VIA1_IRQ_NB]; 42 uint8_t last_b; 43 44 /* RTC */ 45 uint8_t PRAM[256]; 46 BlockBackend *blk; 47 VMChangeStateEntry *vmstate; 48 49 uint32_t tick_offset; 50 51 uint8_t data_out; 52 int data_out_cnt; 53 uint8_t data_in; 54 uint8_t data_in_cnt; 55 uint8_t cmd; 56 int wprotect; 57 int alt; 58 59 /* ADB */ 60 ADBBusState adb_bus; 61 qemu_irq adb_data_ready; 62 int adb_data_in_size; 63 int adb_data_in_index; 64 int adb_data_out_index; 65 uint8_t adb_data_in[128]; 66 uint8_t adb_data_out[16]; 67 uint8_t adb_autopoll_cmd; 68 69 /* external timers */ 70 QEMUTimer *one_second_timer; 71 int64_t next_second; 72 QEMUTimer *sixty_hz_timer; 73 int64_t next_sixty_hz; 74 }; 75 76 77 /* VIA 2 */ 78 #define VIA2_IRQ_SCSI_DATA_BIT 0 79 #define VIA2_IRQ_SLOT_BIT 1 80 #define VIA2_IRQ_UNUSED_BIT 2 81 #define VIA2_IRQ_SCSI_BIT 3 82 #define VIA2_IRQ_ASC_BIT 4 83 84 #define VIA2_IRQ_NB 8 85 86 #define VIA2_IRQ_SCSI_DATA (1 << VIA2_IRQ_SCSI_DATA_BIT) 87 #define VIA2_IRQ_SLOT (1 << VIA2_IRQ_SLOT_BIT) 88 #define VIA2_IRQ_UNUSED (1 << VIA2_IRQ_SCSI_BIT) 89 #define VIA2_IRQ_SCSI (1 << VIA2_IRQ_UNUSED_BIT) 90 #define VIA2_IRQ_ASC (1 << VIA2_IRQ_ASC_BIT) 91 92 #define TYPE_MOS6522_Q800_VIA2 "mos6522-q800-via2" 93 OBJECT_DECLARE_SIMPLE_TYPE(MOS6522Q800VIA2State, MOS6522_Q800_VIA2) 94 95 struct MOS6522Q800VIA2State { 96 /*< private >*/ 97 MOS6522State parent_obj; 98 }; 99 100 101 #define TYPE_MAC_VIA "mac_via" 102 OBJECT_DECLARE_SIMPLE_TYPE(MacVIAState, MAC_VIA) 103 104 struct MacVIAState { 105 SysBusDevice busdev; 106 107 /* MMIO */ 108 MemoryRegion mmio; 109 MemoryRegion via1mem; 110 MemoryRegion via2mem; 111 112 /* VIAs */ 113 MOS6522Q800VIA1State mos6522_via1; 114 MOS6522Q800VIA2State mos6522_via2; 115 }; 116 117 #endif 118