target/riscv/cpu.c: restrict 'mimpid' value
[qemu/ar7.git] / hw / block / fdc-internal.h
blob036392e9fc10d94c9db500a521ce8b18d83cfd65
1 /*
2 * QEMU Floppy disk emulator (Intel 82078)
4 * Copyright (c) 2003, 2007 Jocelyn Mayer
5 * Copyright (c) 2008 Hervé Poussineau
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
25 #ifndef HW_BLOCK_FDC_INTERNAL_H
26 #define HW_BLOCK_FDC_INTERNAL_H
28 #include "exec/memory.h"
29 #include "exec/ioport.h"
30 #include "hw/block/block.h"
31 #include "hw/block/fdc.h"
32 #include "qapi/qapi-types-block.h"
34 typedef struct FDCtrl FDCtrl;
36 /* Floppy bus emulation */
38 typedef struct FloppyBus {
39 BusState bus;
40 FDCtrl *fdc;
41 } FloppyBus;
43 /* Floppy disk drive emulation */
45 typedef enum FDriveRate {
46 FDRIVE_RATE_500K = 0x00, /* 500 Kbps */
47 FDRIVE_RATE_300K = 0x01, /* 300 Kbps */
48 FDRIVE_RATE_250K = 0x02, /* 250 Kbps */
49 FDRIVE_RATE_1M = 0x03, /* 1 Mbps */
50 } FDriveRate;
52 typedef enum FDriveSize {
53 FDRIVE_SIZE_UNKNOWN,
54 FDRIVE_SIZE_350,
55 FDRIVE_SIZE_525,
56 } FDriveSize;
58 typedef struct FDFormat {
59 FloppyDriveType drive;
60 uint8_t last_sect;
61 uint8_t max_track;
62 uint8_t max_head;
63 FDriveRate rate;
64 } FDFormat;
66 typedef enum FDiskFlags {
67 FDISK_DBL_SIDES = 0x01,
68 } FDiskFlags;
70 typedef struct FDrive {
71 FDCtrl *fdctrl;
72 BlockBackend *blk;
73 BlockConf *conf;
74 /* Drive status */
75 FloppyDriveType drive; /* CMOS drive type */
76 uint8_t perpendicular; /* 2.88 MB access mode */
77 /* Position */
78 uint8_t head;
79 uint8_t track;
80 uint8_t sect;
81 /* Media */
82 FloppyDriveType disk; /* Current disk type */
83 FDiskFlags flags;
84 uint8_t last_sect; /* Nb sector per track */
85 uint8_t max_track; /* Nb of tracks */
86 uint16_t bps; /* Bytes per sector */
87 uint8_t ro; /* Is read-only */
88 uint8_t media_changed; /* Is media changed */
89 uint8_t media_rate; /* Data rate of medium */
91 bool media_validated; /* Have we validated the media? */
92 } FDrive;
94 struct FDCtrl {
95 MemoryRegion iomem;
96 qemu_irq irq;
97 /* Controller state */
98 QEMUTimer *result_timer;
99 int dma_chann;
100 uint8_t phase;
101 IsaDma *dma;
102 /* Controller's identification */
103 uint8_t version;
104 /* HW */
105 uint8_t sra;
106 uint8_t srb;
107 uint8_t dor;
108 uint8_t dor_vmstate; /* only used as temp during vmstate */
109 uint8_t tdr;
110 uint8_t dsr;
111 uint8_t msr;
112 uint8_t cur_drv;
113 uint8_t status0;
114 uint8_t status1;
115 uint8_t status2;
116 /* Command FIFO */
117 uint8_t *fifo;
118 int32_t fifo_size;
119 uint32_t data_pos;
120 uint32_t data_len;
121 uint8_t data_state;
122 uint8_t data_dir;
123 uint8_t eot; /* last wanted sector */
124 /* States kept only to be returned back */
125 /* precompensation */
126 uint8_t precomp_trk;
127 uint8_t config;
128 uint8_t lock;
129 /* Power down config (also with status regB access mode */
130 uint8_t pwrd;
131 /* Floppy drives */
132 FloppyBus bus;
133 uint8_t num_floppies;
134 FDrive drives[MAX_FD];
135 struct {
136 FloppyDriveType type;
137 } qdev_for_drives[MAX_FD];
138 int reset_sensei;
139 FloppyDriveType fallback; /* type=auto failure fallback */
140 /* Timers state */
141 uint8_t timer0;
142 uint8_t timer1;
143 PortioList portio_list;
146 extern const FDFormat fd_formats[];
147 extern const VMStateDescription vmstate_fdc;
149 uint32_t fdctrl_read(void *opaque, uint32_t reg);
150 void fdctrl_write(void *opaque, uint32_t reg, uint32_t value);
151 void fdctrl_reset(FDCtrl *fdctrl, int do_irq);
152 void fdctrl_realize_common(DeviceState *dev, FDCtrl *fdctrl, Error **errp);
154 int fdctrl_transfer_handler(void *opaque, int nchan, int dma_pos, int dma_len);
156 void fdctrl_init_drives(FloppyBus *bus, DriveInfo **fds);
158 #endif