xref: /openbmc/qemu/hw/block/fdc-internal.h (revision 13b5ae94)
1 /*
2  * QEMU Floppy disk emulator (Intel 82078)
3  *
4  * Copyright (c) 2003, 2007 Jocelyn Mayer
5  * Copyright (c) 2008 Hervé Poussineau
6  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
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.
24  */
25 #ifndef HW_BLOCK_FDC_INTERNAL_H
26 #define HW_BLOCK_FDC_INTERNAL_H
27 
28 #include "hw/block/block.h"
29 #include "hw/block/fdc.h"
30 #include "qapi/qapi-types-block.h"
31 
32 typedef struct FDCtrl FDCtrl;
33 
34 /* Floppy bus emulation */
35 
36 typedef struct FloppyBus {
37     BusState bus;
38     FDCtrl *fdc;
39 } FloppyBus;
40 
41 /* Floppy disk drive emulation */
42 
43 typedef enum FDriveRate {
44     FDRIVE_RATE_500K = 0x00,  /* 500 Kbps */
45     FDRIVE_RATE_300K = 0x01,  /* 300 Kbps */
46     FDRIVE_RATE_250K = 0x02,  /* 250 Kbps */
47     FDRIVE_RATE_1M   = 0x03,  /*   1 Mbps */
48 } FDriveRate;
49 
50 typedef enum FDriveSize {
51     FDRIVE_SIZE_UNKNOWN,
52     FDRIVE_SIZE_350,
53     FDRIVE_SIZE_525,
54 } FDriveSize;
55 
56 typedef struct FDFormat {
57     FloppyDriveType drive;
58     uint8_t last_sect;
59     uint8_t max_track;
60     uint8_t max_head;
61     FDriveRate rate;
62 } FDFormat;
63 
64 typedef enum FDiskFlags {
65     FDISK_DBL_SIDES  = 0x01,
66 } FDiskFlags;
67 
68 typedef struct FDrive {
69     FDCtrl *fdctrl;
70     BlockBackend *blk;
71     BlockConf *conf;
72     /* Drive status */
73     FloppyDriveType drive;    /* CMOS drive type        */
74     uint8_t perpendicular;    /* 2.88 MB access mode    */
75     /* Position */
76     uint8_t head;
77     uint8_t track;
78     uint8_t sect;
79     /* Media */
80     FloppyDriveType disk;     /* Current disk type      */
81     FDiskFlags flags;
82     uint8_t last_sect;        /* Nb sector per track    */
83     uint8_t max_track;        /* Nb of tracks           */
84     uint16_t bps;             /* Bytes per sector       */
85     uint8_t ro;               /* Is read-only           */
86     uint8_t media_changed;    /* Is media changed       */
87     uint8_t media_rate;       /* Data rate of medium    */
88 
89     bool media_validated;     /* Have we validated the media? */
90 } FDrive;
91 
92 struct FDCtrl {
93     qemu_irq irq;
94     /* Controller state */
95     QEMUTimer *result_timer;
96     int dma_chann;
97     uint8_t phase;
98     IsaDma *dma;
99     /* Controller's identification */
100     uint8_t version;
101     /* HW */
102     uint8_t sra;
103     uint8_t srb;
104     uint8_t dor;
105     uint8_t dor_vmstate; /* only used as temp during vmstate */
106     uint8_t tdr;
107     uint8_t dsr;
108     uint8_t msr;
109     uint8_t cur_drv;
110     uint8_t status0;
111     uint8_t status1;
112     uint8_t status2;
113     /* Command FIFO */
114     uint8_t *fifo;
115     int32_t fifo_size;
116     uint32_t data_pos;
117     uint32_t data_len;
118     uint8_t data_state;
119     uint8_t data_dir;
120     uint8_t eot; /* last wanted sector */
121     /* States kept only to be returned back */
122     /* precompensation */
123     uint8_t precomp_trk;
124     uint8_t config;
125     uint8_t lock;
126     /* Power down config (also with status regB access mode */
127     uint8_t pwrd;
128     /* Floppy drives */
129     FloppyBus bus;
130     uint8_t num_floppies;
131     FDrive drives[MAX_FD];
132     struct {
133         FloppyDriveType type;
134     } qdev_for_drives[MAX_FD];
135     int reset_sensei;
136     FloppyDriveType fallback; /* type=auto failure fallback */
137     /* Timers state */
138     uint8_t timer0;
139     uint8_t timer1;
140 };
141 
142 extern const FDFormat fd_formats[];
143 extern const VMStateDescription vmstate_fdc;
144 
145 uint32_t fdctrl_read(void *opaque, uint32_t reg);
146 void fdctrl_write(void *opaque, uint32_t reg, uint32_t value);
147 void fdctrl_reset(FDCtrl *fdctrl, int do_irq);
148 void fdctrl_realize_common(DeviceState *dev, FDCtrl *fdctrl, Error **errp);
149 
150 int fdctrl_transfer_handler(void *opaque, int nchan, int dma_pos, int dma_len);
151 
152 void fdctrl_init_drives(FloppyBus *bus, DriveInfo **fds);
153 
154 #endif
155