2004-01-05 01:09:06 +01:00
|
|
|
/*
|
2004-10-08 01:10:29 +02:00
|
|
|
* QEMU Floppy disk emulator (Intel 82078)
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2007-04-14 15:01:31 +02:00
|
|
|
* Copyright (c) 2003, 2007 Jocelyn Mayer
|
2011-12-02 10:30:41 +01:00
|
|
|
* Copyright (c) 2008 Hervé Poussineau
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2004-01-05 01:09:06 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2004-12-20 00:18:01 +01:00
|
|
|
/*
|
|
|
|
* The controller is used in Sun4m systems in a slightly different
|
|
|
|
* way. There are changes in DOR register and DMA is not available.
|
|
|
|
*/
|
2009-07-15 16:41:54 +02:00
|
|
|
|
2016-01-18 19:01:42 +01:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/block/fdc.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "qemu/timer.h"
|
2020-06-19 11:18:56 +02:00
|
|
|
#include "hw/acpi/aml-build.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/isa/isa.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2020-12-11 23:05:12 +01:00
|
|
|
#include "hw/qdev-properties-system.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/sysbus.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2016-10-27 22:29:13 +02:00
|
|
|
#include "hw/block/block.h"
|
2014-10-07 13:59:13 +02:00
|
|
|
#include "sysemu/block-backend.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/blockdev.h"
|
|
|
|
#include "sysemu/sysemu.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/log.h"
|
Include qemu/main-loop.h less
In my "build everything" tree, changing qemu/main-loop.h triggers a
recompile of some 5600 out of 6600 objects (not counting tests and
objects that don't depend on qemu/osdep.h). It includes block/aio.h,
which in turn includes qemu/event_notifier.h, qemu/notify.h,
qemu/processor.h, qemu/qsp.h, qemu/queue.h, qemu/thread-posix.h,
qemu/thread.h, qemu/timer.h, and a few more.
Include qemu/main-loop.h only where it's needed. Touching it now
recompiles only some 1700 objects. For block/aio.h and
qemu/event_notifier.h, these numbers drop from 5600 to 2800. For the
others, they shrink only slightly.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190812052359.30071-21-armbru@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2019-08-12 07:23:50 +02:00
|
|
|
#include "qemu/main-loop.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2018-06-21 19:12:56 +02:00
|
|
|
#include "trace.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2004-01-05 01:09:06 +01:00
|
|
|
|
|
|
|
/********************************************************/
|
|
|
|
/* debug Floppy devices */
|
|
|
|
|
2016-02-10 19:29:40 +01:00
|
|
|
#define DEBUG_FLOPPY 0
|
|
|
|
|
2009-05-13 19:53:17 +02:00
|
|
|
#define FLOPPY_DPRINTF(fmt, ...) \
|
2016-02-10 19:29:40 +01:00
|
|
|
do { \
|
|
|
|
if (DEBUG_FLOPPY) { \
|
|
|
|
fprintf(stderr, "FLOPPY: " fmt , ## __VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2004-01-05 01:09:06 +01:00
|
|
|
|
2016-10-27 22:29:13 +02:00
|
|
|
|
|
|
|
/********************************************************/
|
|
|
|
/* qdev floppy bus */
|
|
|
|
|
|
|
|
#define TYPE_FLOPPY_BUS "floppy-bus"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(FloppyBus, FLOPPY_BUS)
|
2016-10-27 22:29:13 +02:00
|
|
|
|
|
|
|
typedef struct FDCtrl FDCtrl;
|
2016-10-27 22:29:13 +02:00
|
|
|
typedef struct FDrive FDrive;
|
|
|
|
static FDrive *get_drv(FDCtrl *fdctrl, int unit);
|
2016-10-27 22:29:13 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct FloppyBus {
|
2016-10-27 22:29:13 +02:00
|
|
|
BusState bus;
|
|
|
|
FDCtrl *fdc;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2016-10-27 22:29:13 +02:00
|
|
|
|
|
|
|
static const TypeInfo floppy_bus_info = {
|
|
|
|
.name = TYPE_FLOPPY_BUS,
|
|
|
|
.parent = TYPE_BUS,
|
|
|
|
.instance_size = sizeof(FloppyBus),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void floppy_bus_create(FDCtrl *fdc, FloppyBus *bus, DeviceState *dev)
|
|
|
|
{
|
|
|
|
qbus_create_inplace(bus, sizeof(FloppyBus), TYPE_FLOPPY_BUS, dev, NULL);
|
|
|
|
bus->fdc = fdc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/********************************************************/
|
|
|
|
/* Floppy drive emulation */
|
|
|
|
|
2012-07-10 11:12:27 +02:00
|
|
|
typedef enum FDriveRate {
|
|
|
|
FDRIVE_RATE_500K = 0x00, /* 500 Kbps */
|
|
|
|
FDRIVE_RATE_300K = 0x01, /* 300 Kbps */
|
|
|
|
FDRIVE_RATE_250K = 0x02, /* 250 Kbps */
|
|
|
|
FDRIVE_RATE_1M = 0x03, /* 1 Mbps */
|
|
|
|
} FDriveRate;
|
|
|
|
|
2016-01-22 21:51:02 +01:00
|
|
|
typedef enum FDriveSize {
|
|
|
|
FDRIVE_SIZE_UNKNOWN,
|
|
|
|
FDRIVE_SIZE_350,
|
|
|
|
FDRIVE_SIZE_525,
|
|
|
|
} FDriveSize;
|
|
|
|
|
2012-07-10 11:12:27 +02:00
|
|
|
typedef struct FDFormat {
|
2016-01-22 21:50:56 +01:00
|
|
|
FloppyDriveType drive;
|
2012-07-10 11:12:27 +02:00
|
|
|
uint8_t last_sect;
|
|
|
|
uint8_t max_track;
|
|
|
|
uint8_t max_head;
|
|
|
|
FDriveRate rate;
|
|
|
|
} FDFormat;
|
|
|
|
|
2016-01-22 21:51:02 +01:00
|
|
|
/* In many cases, the total sector size of a format is enough to uniquely
|
|
|
|
* identify it. However, there are some total sector collisions between
|
|
|
|
* formats of different physical size, and these are noted below by
|
|
|
|
* highlighting the total sector size for entries with collisions. */
|
2012-07-10 11:12:27 +02:00
|
|
|
static const FDFormat fd_formats[] = {
|
|
|
|
/* First entry is default format */
|
|
|
|
/* 1.44 MB 3"1/2 floppy disks */
|
2016-01-22 21:51:02 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 18, 80, 1, FDRIVE_RATE_500K, }, /* 3.5" 2880 */
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 20, 80, 1, FDRIVE_RATE_500K, }, /* 3.5" 3200 */
|
2016-01-22 21:50:56 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 21, 80, 1, FDRIVE_RATE_500K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 21, 82, 1, FDRIVE_RATE_500K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 21, 83, 1, FDRIVE_RATE_500K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 22, 80, 1, FDRIVE_RATE_500K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 23, 80, 1, FDRIVE_RATE_500K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 24, 80, 1, FDRIVE_RATE_500K, },
|
2012-07-10 11:12:27 +02:00
|
|
|
/* 2.88 MB 3"1/2 floppy disks */
|
2016-01-22 21:50:56 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_288, 36, 80, 1, FDRIVE_RATE_1M, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_288, 39, 80, 1, FDRIVE_RATE_1M, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_288, 40, 80, 1, FDRIVE_RATE_1M, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_288, 44, 80, 1, FDRIVE_RATE_1M, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_288, 48, 80, 1, FDRIVE_RATE_1M, },
|
2012-07-10 11:12:27 +02:00
|
|
|
/* 720 kB 3"1/2 floppy disks */
|
2016-01-22 21:51:02 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 9, 80, 1, FDRIVE_RATE_250K, }, /* 3.5" 1440 */
|
2016-01-22 21:50:56 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 10, 80, 1, FDRIVE_RATE_250K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 10, 82, 1, FDRIVE_RATE_250K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 10, 83, 1, FDRIVE_RATE_250K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 13, 80, 1, FDRIVE_RATE_250K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 14, 80, 1, FDRIVE_RATE_250K, },
|
2012-07-10 11:12:27 +02:00
|
|
|
/* 1.2 MB 5"1/4 floppy disks */
|
2016-01-22 21:50:56 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 15, 80, 1, FDRIVE_RATE_500K, },
|
2016-01-22 21:51:02 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 18, 80, 1, FDRIVE_RATE_500K, }, /* 5.25" 2880 */
|
2016-01-22 21:50:56 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 18, 82, 1, FDRIVE_RATE_500K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 18, 83, 1, FDRIVE_RATE_500K, },
|
2016-01-22 21:51:02 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 20, 80, 1, FDRIVE_RATE_500K, }, /* 5.25" 3200 */
|
2012-07-10 11:12:27 +02:00
|
|
|
/* 720 kB 5"1/4 floppy disks */
|
2016-01-22 21:51:02 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 9, 80, 1, FDRIVE_RATE_250K, }, /* 5.25" 1440 */
|
2016-01-22 21:50:56 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 11, 80, 1, FDRIVE_RATE_250K, },
|
2012-07-10 11:12:27 +02:00
|
|
|
/* 360 kB 5"1/4 floppy disks */
|
2016-01-22 21:51:02 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 9, 40, 1, FDRIVE_RATE_300K, }, /* 5.25" 720 */
|
2016-01-22 21:50:56 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 9, 40, 0, FDRIVE_RATE_300K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 10, 41, 1, FDRIVE_RATE_300K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 10, 42, 1, FDRIVE_RATE_300K, },
|
2012-07-10 11:12:27 +02:00
|
|
|
/* 320 kB 5"1/4 floppy disks */
|
2016-01-22 21:50:56 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 8, 40, 1, FDRIVE_RATE_250K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 8, 40, 0, FDRIVE_RATE_250K, },
|
2012-07-10 11:12:27 +02:00
|
|
|
/* 360 kB must match 5"1/4 better than 3"1/2... */
|
2016-01-22 21:51:02 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 9, 80, 0, FDRIVE_RATE_250K, }, /* 3.5" 720 */
|
2012-07-10 11:12:27 +02:00
|
|
|
/* end */
|
2016-01-22 21:50:56 +01:00
|
|
|
{ FLOPPY_DRIVE_TYPE_NONE, -1, -1, 0, 0, },
|
2012-07-10 11:12:27 +02:00
|
|
|
};
|
|
|
|
|
2016-01-22 21:51:02 +01:00
|
|
|
static FDriveSize drive_size(FloppyDriveType drive)
|
|
|
|
{
|
|
|
|
switch (drive) {
|
|
|
|
case FLOPPY_DRIVE_TYPE_120:
|
|
|
|
return FDRIVE_SIZE_525;
|
|
|
|
case FLOPPY_DRIVE_TYPE_144:
|
|
|
|
case FLOPPY_DRIVE_TYPE_288:
|
|
|
|
return FDRIVE_SIZE_350;
|
|
|
|
default:
|
|
|
|
return FDRIVE_SIZE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-29 18:18:58 +02:00
|
|
|
#define GET_CUR_DRV(fdctrl) ((fdctrl)->cur_drv)
|
|
|
|
#define SET_CUR_DRV(fdctrl, drive) ((fdctrl)->cur_drv = (drive))
|
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Will always be a fixed parameter for us */
|
2009-01-24 13:09:52 +01:00
|
|
|
#define FD_SECTOR_LEN 512
|
|
|
|
#define FD_SECTOR_SC 2 /* Sector size code */
|
|
|
|
#define FD_RESET_SENSEI_COUNT 4 /* Number of sense interrupts on RESET */
|
2004-01-05 01:09:06 +01:00
|
|
|
|
|
|
|
/* Floppy disk drive emulation */
|
2010-02-07 10:01:18 +01:00
|
|
|
typedef enum FDiskFlags {
|
2004-03-20 00:05:34 +01:00
|
|
|
FDISK_DBL_SIDES = 0x01,
|
2010-02-07 10:01:18 +01:00
|
|
|
} FDiskFlags;
|
2004-03-20 00:05:34 +01:00
|
|
|
|
2016-10-27 22:29:13 +02:00
|
|
|
struct FDrive {
|
2012-02-06 22:29:10 +01:00
|
|
|
FDCtrl *fdctrl;
|
2014-10-07 13:59:18 +02:00
|
|
|
BlockBackend *blk;
|
2017-01-24 13:43:31 +01:00
|
|
|
BlockConf *conf;
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Drive status */
|
2016-01-22 21:50:56 +01:00
|
|
|
FloppyDriveType drive; /* CMOS drive type */
|
2004-01-05 01:09:06 +01:00
|
|
|
uint8_t perpendicular; /* 2.88 MB access mode */
|
|
|
|
/* Position */
|
|
|
|
uint8_t head;
|
|
|
|
uint8_t track;
|
|
|
|
uint8_t sect;
|
|
|
|
/* Media */
|
2016-01-22 21:50:57 +01:00
|
|
|
FloppyDriveType disk; /* Current disk type */
|
2010-02-07 10:01:18 +01:00
|
|
|
FDiskFlags flags;
|
2004-01-05 01:09:06 +01:00
|
|
|
uint8_t last_sect; /* Nb sector per track */
|
|
|
|
uint8_t max_track; /* Nb of tracks */
|
2004-03-20 00:05:34 +01:00
|
|
|
uint16_t bps; /* Bytes per sector */
|
2004-01-05 01:09:06 +01:00
|
|
|
uint8_t ro; /* Is read-only */
|
2011-04-06 12:34:31 +02:00
|
|
|
uint8_t media_changed; /* Is media changed */
|
2012-02-06 22:29:10 +01:00
|
|
|
uint8_t media_rate; /* Data rate of medium */
|
2015-10-19 17:53:16 +02:00
|
|
|
|
2016-01-22 21:50:59 +01:00
|
|
|
bool media_validated; /* Have we validated the media? */
|
2016-10-27 22:29:13 +02:00
|
|
|
};
|
2004-01-05 01:09:06 +01:00
|
|
|
|
2016-01-22 21:51:00 +01:00
|
|
|
|
|
|
|
static FloppyDriveType get_fallback_drive_type(FDrive *drv);
|
|
|
|
|
fdc: fix detection under Linux
Accidentally, I removed a "feature" where empty drives had geometry
values applied to them, which allows seek on empty drives to work
"by accident," as QEMU actually tries to disallow that.
Seeks on empty drives should work, though, but the easiest thing is to
restore the misfeature where empty drives have non-zero geometries
applied.
Document the hack accordingly.
[Maintainer edit]
This fix corrects a regression introduced in d5d47efc, where
pick_geometry was modified such that it would not operate on empty
drives, and as a result if there is no diskette inserted, QEMU
no longer populates it with geometry bounds. As a result, seek fails
when QEMU denies to move the current track, but reports success anyway.
This can confuse the guest, leading to kernel panics in the guest.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1454106932-17236-1-git-send-email-jsnow@redhat.com
2016-02-03 17:28:55 +01:00
|
|
|
/* Hack: FD_SEEK is expected to work on empty drives. However, QEMU
|
|
|
|
* currently goes through some pains to keep seeks within the bounds
|
|
|
|
* established by last_sect and max_track. Correcting this is difficult,
|
|
|
|
* as refactoring FDC code tends to expose nasty bugs in the Linux kernel.
|
|
|
|
*
|
|
|
|
* For now: allow empty drives to have large bounds so we can seek around,
|
|
|
|
* with the understanding that when a diskette is inserted, the bounds will
|
|
|
|
* properly tighten to match the geometry of that inserted medium.
|
|
|
|
*/
|
|
|
|
static void fd_empty_seek_hack(FDrive *drv)
|
|
|
|
{
|
|
|
|
drv->last_sect = 0xFF;
|
|
|
|
drv->max_track = 0xFF;
|
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fd_init(FDrive *drv)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
|
|
|
/* Drive */
|
|
|
|
drv->perpendicular = 0;
|
|
|
|
/* Disk */
|
2016-01-22 21:50:57 +01:00
|
|
|
drv->disk = FLOPPY_DRIVE_TYPE_NONE;
|
2004-03-20 00:05:34 +01:00
|
|
|
drv->last_sect = 0;
|
2004-01-05 01:09:06 +01:00
|
|
|
drv->max_track = 0;
|
2016-01-22 21:50:59 +01:00
|
|
|
drv->ro = true;
|
|
|
|
drv->media_changed = 1;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
2012-02-06 22:29:02 +01:00
|
|
|
#define NUM_SIDES(drv) ((drv)->flags & FDISK_DBL_SIDES ? 2 : 1)
|
|
|
|
|
2010-02-07 10:13:51 +01:00
|
|
|
static int fd_sector_calc(uint8_t head, uint8_t track, uint8_t sect,
|
2012-02-06 22:29:02 +01:00
|
|
|
uint8_t last_sect, uint8_t num_sides)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2012-02-06 22:29:02 +01:00
|
|
|
return (((track * num_sides) + head) * last_sect) + sect - 1;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns current position, in sectors, for given drive */
|
2010-02-07 10:01:18 +01:00
|
|
|
static int fd_sector(FDrive *drv)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2012-02-06 22:29:02 +01:00
|
|
|
return fd_sector_calc(drv->head, drv->track, drv->sect, drv->last_sect,
|
|
|
|
NUM_SIDES(drv));
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
2016-05-06 18:26:35 +02:00
|
|
|
/* Returns current position, in bytes, for given drive */
|
|
|
|
static int fd_offset(FDrive *drv)
|
|
|
|
{
|
|
|
|
g_assert(fd_sector(drv) < INT_MAX >> BDRV_SECTOR_BITS);
|
|
|
|
return fd_sector(drv) << BDRV_SECTOR_BITS;
|
|
|
|
}
|
|
|
|
|
2008-04-29 18:17:08 +02:00
|
|
|
/* Seek to a new position:
|
|
|
|
* returns 0 if already on right track
|
|
|
|
* returns 1 if track changed
|
|
|
|
* returns 2 if track is invalid
|
|
|
|
* returns 3 if sector is invalid
|
|
|
|
* returns 4 if seek is disabled
|
|
|
|
*/
|
2010-02-07 10:01:18 +01:00
|
|
|
static int fd_seek(FDrive *drv, uint8_t head, uint8_t track, uint8_t sect,
|
|
|
|
int enable_seek)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
|
|
|
uint32_t sector;
|
2004-03-20 00:05:34 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (track > drv->max_track ||
|
2007-11-05 04:11:37 +01:00
|
|
|
(head != 0 && (drv->flags & FDISK_DBL_SIDES) == 0)) {
|
2004-05-08 15:14:18 +02:00
|
|
|
FLOPPY_DPRINTF("try to read %d %02x %02x (max=%d %d %02x %02x)\n",
|
|
|
|
head, track, sect, 1,
|
|
|
|
(drv->flags & FDISK_DBL_SIDES) == 0 ? 0 : 1,
|
|
|
|
drv->max_track, drv->last_sect);
|
2004-01-05 01:09:06 +01:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (sect > drv->last_sect) {
|
2004-05-08 15:14:18 +02:00
|
|
|
FLOPPY_DPRINTF("try to read %d %02x %02x (max=%d %d %02x %02x)\n",
|
|
|
|
head, track, sect, 1,
|
|
|
|
(drv->flags & FDISK_DBL_SIDES) == 0 ? 0 : 1,
|
|
|
|
drv->max_track, drv->last_sect);
|
2004-01-05 01:09:06 +01:00
|
|
|
return 3;
|
|
|
|
}
|
2012-02-06 22:29:02 +01:00
|
|
|
sector = fd_sector_calc(head, track, sect, drv->last_sect, NUM_SIDES(drv));
|
2004-03-20 00:05:34 +01:00
|
|
|
ret = 0;
|
2004-01-05 01:09:06 +01:00
|
|
|
if (sector != fd_sector(drv)) {
|
|
|
|
#if 0
|
|
|
|
if (!enable_seek) {
|
2012-06-03 19:16:14 +02:00
|
|
|
FLOPPY_DPRINTF("error: no implicit seek %d %02x %02x"
|
|
|
|
" (max=%d %02x %02x)\n",
|
|
|
|
head, track, sect, 1, drv->max_track,
|
|
|
|
drv->last_sect);
|
2004-01-05 01:09:06 +01:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
drv->head = head;
|
2012-06-22 12:33:54 +02:00
|
|
|
if (drv->track != track) {
|
Revert "hw/block/fdc: Implement tray status"
This reverts the changes that commit
2e1280e8ff95b3145bc6262accc9d447718e5318 applied to hw/block/fdc.c;
also, an additional case of drv->media_inserted use has crept in since,
which is replaced by a call to blk_is_inserted().
That commit changed tests/fdc-test.c, too, because after it, one less
TRAY_MOVED event would be emitted when executing 'change' on an empty
drive. However, now, no TRAY_MOVED events will be emitted at all, and
the tray_open status returned by query-block will always be false,
necessitating (different) changes to tests/fdc-test.c and iotest 118,
which is why this patch is not a pure revert of said commit.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 1454096953-31773-4-git-send-email-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
2016-01-29 20:49:12 +01:00
|
|
|
if (drv->blk != NULL && blk_is_inserted(drv->blk)) {
|
2012-06-22 12:33:54 +02:00
|
|
|
drv->media_changed = 0;
|
|
|
|
}
|
2007-11-05 04:11:37 +01:00
|
|
|
ret = 1;
|
2012-06-22 12:33:54 +02:00
|
|
|
}
|
2004-01-05 01:09:06 +01:00
|
|
|
drv->track = track;
|
|
|
|
drv->sect = sect;
|
|
|
|
}
|
|
|
|
|
Revert "hw/block/fdc: Implement tray status"
This reverts the changes that commit
2e1280e8ff95b3145bc6262accc9d447718e5318 applied to hw/block/fdc.c;
also, an additional case of drv->media_inserted use has crept in since,
which is replaced by a call to blk_is_inserted().
That commit changed tests/fdc-test.c, too, because after it, one less
TRAY_MOVED event would be emitted when executing 'change' on an empty
drive. However, now, no TRAY_MOVED events will be emitted at all, and
the tray_open status returned by query-block will always be false,
necessitating (different) changes to tests/fdc-test.c and iotest 118,
which is why this patch is not a pure revert of said commit.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 1454096953-31773-4-git-send-email-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
2016-01-29 20:49:12 +01:00
|
|
|
if (drv->blk == NULL || !blk_is_inserted(drv->blk)) {
|
2012-06-13 15:43:11 +02:00
|
|
|
ret = 2;
|
|
|
|
}
|
|
|
|
|
2004-03-20 00:05:34 +01:00
|
|
|
return ret;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set drive back to track 0 */
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fd_recalibrate(FDrive *drv)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
|
|
|
FLOPPY_DPRINTF("recalibrate\n");
|
2012-06-22 12:33:54 +02:00
|
|
|
fd_seek(drv, 0, 0, 1, 1);
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
2016-01-22 21:50:59 +01:00
|
|
|
/**
|
|
|
|
* Determine geometry based on inserted diskette.
|
|
|
|
* Will not operate on an empty drive.
|
|
|
|
*
|
|
|
|
* @return: 0 on success, -1 if the drive is empty.
|
|
|
|
*/
|
|
|
|
static int pick_geometry(FDrive *drv)
|
2016-01-22 21:50:54 +01:00
|
|
|
{
|
2016-01-22 21:50:55 +01:00
|
|
|
BlockBackend *blk = drv->blk;
|
2016-01-22 21:50:54 +01:00
|
|
|
const FDFormat *parse;
|
|
|
|
uint64_t nb_sectors, size;
|
2016-01-22 21:51:03 +01:00
|
|
|
int i;
|
|
|
|
int match, size_match, type_match;
|
|
|
|
bool magic = drv->drive == FLOPPY_DRIVE_TYPE_AUTO;
|
2016-01-22 21:50:54 +01:00
|
|
|
|
2016-01-22 21:50:59 +01:00
|
|
|
/* We can only pick a geometry if we have a diskette. */
|
Revert "hw/block/fdc: Implement tray status"
This reverts the changes that commit
2e1280e8ff95b3145bc6262accc9d447718e5318 applied to hw/block/fdc.c;
also, an additional case of drv->media_inserted use has crept in since,
which is replaced by a call to blk_is_inserted().
That commit changed tests/fdc-test.c, too, because after it, one less
TRAY_MOVED event would be emitted when executing 'change' on an empty
drive. However, now, no TRAY_MOVED events will be emitted at all, and
the tray_open status returned by query-block will always be false,
necessitating (different) changes to tests/fdc-test.c and iotest 118,
which is why this patch is not a pure revert of said commit.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 1454096953-31773-4-git-send-email-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
2016-01-29 20:49:12 +01:00
|
|
|
if (!drv->blk || !blk_is_inserted(drv->blk) ||
|
|
|
|
drv->drive == FLOPPY_DRIVE_TYPE_NONE)
|
|
|
|
{
|
2016-01-22 21:50:59 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-01-22 21:51:03 +01:00
|
|
|
/* We need to determine the likely geometry of the inserted medium.
|
|
|
|
* In order of preference, we look for:
|
|
|
|
* (1) The same drive type and number of sectors,
|
|
|
|
* (2) The same diskette size and number of sectors,
|
|
|
|
* (3) The same drive type.
|
|
|
|
*
|
|
|
|
* In all cases, matches that occur higher in the drive table will take
|
|
|
|
* precedence over matches that occur later in the table.
|
|
|
|
*/
|
2016-01-22 21:50:54 +01:00
|
|
|
blk_get_geometry(blk, &nb_sectors);
|
2016-01-22 21:51:03 +01:00
|
|
|
match = size_match = type_match = -1;
|
2016-01-22 21:50:54 +01:00
|
|
|
for (i = 0; ; i++) {
|
|
|
|
parse = &fd_formats[i];
|
2016-01-22 21:50:56 +01:00
|
|
|
if (parse->drive == FLOPPY_DRIVE_TYPE_NONE) {
|
2016-01-22 21:50:54 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-01-22 21:51:03 +01:00
|
|
|
size = (parse->max_head + 1) * parse->max_track * parse->last_sect;
|
|
|
|
if (nb_sectors == size) {
|
|
|
|
if (magic || parse->drive == drv->drive) {
|
|
|
|
/* (1) perfect match -- nb_sectors and drive type */
|
|
|
|
goto out;
|
|
|
|
} else if (drive_size(parse->drive) == drive_size(drv->drive)) {
|
|
|
|
/* (2) size match -- nb_sectors and physical medium size */
|
|
|
|
match = (match == -1) ? i : match;
|
|
|
|
} else {
|
|
|
|
/* This is suspicious -- Did the user misconfigure? */
|
|
|
|
size_match = (size_match == -1) ? i : size_match;
|
2016-01-22 21:50:54 +01:00
|
|
|
}
|
2016-01-22 21:51:03 +01:00
|
|
|
} else if (type_match == -1) {
|
|
|
|
if ((parse->drive == drv->drive) ||
|
|
|
|
(magic && (parse->drive == get_fallback_drive_type(drv)))) {
|
|
|
|
/* (3) type match -- nb_sectors mismatch, but matches the type
|
|
|
|
* specified explicitly by the user, or matches the fallback
|
|
|
|
* default type when using the drive autodetect mechanism */
|
|
|
|
type_match = i;
|
2016-01-22 21:50:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-22 21:51:03 +01:00
|
|
|
|
|
|
|
/* No exact match found */
|
2016-01-22 21:50:54 +01:00
|
|
|
if (match == -1) {
|
2016-01-22 21:51:03 +01:00
|
|
|
if (size_match != -1) {
|
|
|
|
parse = &fd_formats[size_match];
|
|
|
|
FLOPPY_DPRINTF("User requested floppy drive type '%s', "
|
|
|
|
"but inserted medium appears to be a "
|
2016-02-10 19:29:40 +01:00
|
|
|
"%"PRId64" sector '%s' type\n",
|
2017-08-24 10:46:08 +02:00
|
|
|
FloppyDriveType_str(drv->drive),
|
2016-01-22 21:51:03 +01:00
|
|
|
nb_sectors,
|
2017-08-24 10:46:08 +02:00
|
|
|
FloppyDriveType_str(parse->drive));
|
2016-01-22 21:50:54 +01:00
|
|
|
}
|
2018-06-29 16:11:00 +02:00
|
|
|
assert(type_match != -1 && "misconfigured fd_format");
|
2016-01-22 21:51:03 +01:00
|
|
|
match = type_match;
|
2016-01-22 21:50:54 +01:00
|
|
|
}
|
2016-01-22 21:51:03 +01:00
|
|
|
parse = &(fd_formats[match]);
|
|
|
|
|
|
|
|
out:
|
2016-01-22 21:50:55 +01:00
|
|
|
if (parse->max_head == 0) {
|
|
|
|
drv->flags &= ~FDISK_DBL_SIDES;
|
|
|
|
} else {
|
|
|
|
drv->flags |= FDISK_DBL_SIDES;
|
|
|
|
}
|
|
|
|
drv->max_track = parse->max_track;
|
|
|
|
drv->last_sect = parse->last_sect;
|
2016-01-22 21:50:59 +01:00
|
|
|
drv->disk = parse->drive;
|
2016-01-22 21:50:55 +01:00
|
|
|
drv->media_rate = parse->rate;
|
2016-01-22 21:50:59 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pick_drive_type(FDrive *drv)
|
|
|
|
{
|
2016-01-22 21:51:01 +01:00
|
|
|
if (drv->drive != FLOPPY_DRIVE_TYPE_AUTO) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-22 21:50:59 +01:00
|
|
|
if (pick_geometry(drv) == 0) {
|
|
|
|
drv->drive = drv->disk;
|
|
|
|
} else {
|
2016-01-22 21:51:00 +01:00
|
|
|
drv->drive = get_fallback_drive_type(drv);
|
2016-01-22 21:50:59 +01:00
|
|
|
}
|
2016-01-22 21:51:01 +01:00
|
|
|
|
|
|
|
g_assert(drv->drive != FLOPPY_DRIVE_TYPE_AUTO);
|
2016-01-22 21:50:54 +01:00
|
|
|
}
|
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Revalidate a disk drive after a disk change */
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fd_revalidate(FDrive *drv)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2016-01-22 21:50:59 +01:00
|
|
|
int rc;
|
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
FLOPPY_DPRINTF("revalidate\n");
|
2014-10-07 13:59:18 +02:00
|
|
|
if (drv->blk != NULL) {
|
2021-01-18 13:34:47 +01:00
|
|
|
drv->ro = !blk_is_writable(drv->blk);
|
Revert "hw/block/fdc: Implement tray status"
This reverts the changes that commit
2e1280e8ff95b3145bc6262accc9d447718e5318 applied to hw/block/fdc.c;
also, an additional case of drv->media_inserted use has crept in since,
which is replaced by a call to blk_is_inserted().
That commit changed tests/fdc-test.c, too, because after it, one less
TRAY_MOVED event would be emitted when executing 'change' on an empty
drive. However, now, no TRAY_MOVED events will be emitted at all, and
the tray_open status returned by query-block will always be false,
necessitating (different) changes to tests/fdc-test.c and iotest 118,
which is why this patch is not a pure revert of said commit.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 1454096953-31773-4-git-send-email-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
2016-01-29 20:49:12 +01:00
|
|
|
if (!blk_is_inserted(drv->blk)) {
|
2012-05-24 11:02:29 +02:00
|
|
|
FLOPPY_DPRINTF("No disk in drive\n");
|
2016-01-22 21:50:59 +01:00
|
|
|
drv->disk = FLOPPY_DRIVE_TYPE_NONE;
|
fdc: fix detection under Linux
Accidentally, I removed a "feature" where empty drives had geometry
values applied to them, which allows seek on empty drives to work
"by accident," as QEMU actually tries to disallow that.
Seeks on empty drives should work, though, but the easiest thing is to
restore the misfeature where empty drives have non-zero geometries
applied.
Document the hack accordingly.
[Maintainer edit]
This fix corrects a regression introduced in d5d47efc, where
pick_geometry was modified such that it would not operate on empty
drives, and as a result if there is no diskette inserted, QEMU
no longer populates it with geometry bounds. As a result, seek fails
when QEMU denies to move the current track, but reports success anyway.
This can confuse the guest, leading to kernel panics in the guest.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1454106932-17236-1-git-send-email-jsnow@redhat.com
2016-02-03 17:28:55 +01:00
|
|
|
fd_empty_seek_hack(drv);
|
2016-01-22 21:50:59 +01:00
|
|
|
} else if (!drv->media_validated) {
|
|
|
|
rc = pick_geometry(drv);
|
|
|
|
if (rc) {
|
|
|
|
FLOPPY_DPRINTF("Could not validate floppy drive media");
|
|
|
|
} else {
|
|
|
|
drv->media_validated = true;
|
|
|
|
FLOPPY_DPRINTF("Floppy disk (%d h %d t %d s) %s\n",
|
|
|
|
(drv->flags & FDISK_DBL_SIDES) ? 2 : 1,
|
|
|
|
drv->max_track, drv->last_sect,
|
|
|
|
drv->ro ? "ro" : "rw");
|
|
|
|
}
|
2007-11-05 04:11:37 +01:00
|
|
|
}
|
2004-01-05 01:09:06 +01:00
|
|
|
} else {
|
2012-05-24 11:02:29 +02:00
|
|
|
FLOPPY_DPRINTF("No drive connected\n");
|
2004-03-20 00:05:34 +01:00
|
|
|
drv->last_sect = 0;
|
2007-11-05 04:11:37 +01:00
|
|
|
drv->max_track = 0;
|
|
|
|
drv->flags &= ~FDISK_DBL_SIDES;
|
2016-01-22 21:50:59 +01:00
|
|
|
drv->drive = FLOPPY_DRIVE_TYPE_NONE;
|
|
|
|
drv->disk = FLOPPY_DRIVE_TYPE_NONE;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
2004-03-14 22:40:43 +01:00
|
|
|
}
|
|
|
|
|
2017-01-24 14:21:41 +01:00
|
|
|
static void fd_change_cb(void *opaque, bool load, Error **errp)
|
2016-10-27 22:29:13 +02:00
|
|
|
{
|
|
|
|
FDrive *drive = opaque;
|
2017-01-24 13:43:31 +01:00
|
|
|
|
|
|
|
if (!load) {
|
|
|
|
blk_set_perm(drive->blk, 0, BLK_PERM_ALL, &error_abort);
|
|
|
|
} else {
|
2017-11-22 04:08:45 +01:00
|
|
|
if (!blkconf_apply_backend_options(drive->conf,
|
2021-01-18 13:34:47 +01:00
|
|
|
!blk_supports_write_perm(drive->blk),
|
|
|
|
false, errp)) {
|
2017-01-24 13:43:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-10-27 22:29:13 +02:00
|
|
|
|
|
|
|
drive->media_changed = 1;
|
|
|
|
drive->media_validated = false;
|
|
|
|
fd_revalidate(drive);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const BlockDevOps fd_block_ops = {
|
|
|
|
.change_media_cb = fd_change_cb,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define TYPE_FLOPPY_DRIVE "floppy"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(FloppyDrive, FLOPPY_DRIVE)
|
2016-10-27 22:29:13 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct FloppyDrive {
|
2016-10-27 22:29:13 +02:00
|
|
|
DeviceState qdev;
|
|
|
|
uint32_t unit;
|
|
|
|
BlockConf conf;
|
|
|
|
FloppyDriveType type;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2016-10-27 22:29:13 +02:00
|
|
|
|
|
|
|
static Property floppy_drive_properties[] = {
|
|
|
|
DEFINE_PROP_UINT32("unit", FloppyDrive, unit, -1),
|
2016-10-27 22:29:13 +02:00
|
|
|
DEFINE_BLOCK_PROPERTIES(FloppyDrive, conf),
|
2017-06-07 18:36:07 +02:00
|
|
|
DEFINE_PROP_SIGNED("drive-type", FloppyDrive, type,
|
2016-10-27 22:29:13 +02:00
|
|
|
FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type,
|
|
|
|
FloppyDriveType),
|
2016-10-27 22:29:13 +02:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2017-09-18 16:05:14 +02:00
|
|
|
static void floppy_drive_realize(DeviceState *qdev, Error **errp)
|
2016-10-27 22:29:13 +02:00
|
|
|
{
|
|
|
|
FloppyDrive *dev = FLOPPY_DRIVE(qdev);
|
|
|
|
FloppyBus *bus = FLOPPY_BUS(qdev->parent_bus);
|
|
|
|
FDrive *drive;
|
2019-07-30 15:37:08 +02:00
|
|
|
bool read_only;
|
2016-10-27 22:29:13 +02:00
|
|
|
int ret;
|
2016-10-27 22:29:13 +02:00
|
|
|
|
|
|
|
if (dev->unit == -1) {
|
|
|
|
for (dev->unit = 0; dev->unit < MAX_FD; dev->unit++) {
|
|
|
|
drive = get_drv(bus->fdc, dev->unit);
|
|
|
|
if (!drive->blk) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->unit >= MAX_FD) {
|
2017-09-18 16:05:14 +02:00
|
|
|
error_setg(errp, "Can't create floppy unit %d, bus supports "
|
|
|
|
"only %d units", dev->unit, MAX_FD);
|
|
|
|
return;
|
2016-10-27 22:29:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
drive = get_drv(bus->fdc, dev->unit);
|
|
|
|
if (drive->blk) {
|
2017-09-18 16:05:14 +02:00
|
|
|
error_setg(errp, "Floppy unit %d is in use", dev->unit);
|
|
|
|
return;
|
2016-10-27 22:29:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!dev->conf.blk) {
|
2016-10-27 22:29:13 +02:00
|
|
|
/* Anonymous BlockBackend for an empty drive */
|
2019-04-25 14:25:10 +02:00
|
|
|
dev->conf.blk = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL);
|
2016-10-27 22:29:13 +02:00
|
|
|
ret = blk_attach_dev(dev->conf.blk, qdev);
|
|
|
|
assert(ret == 0);
|
2019-07-30 15:37:08 +02:00
|
|
|
|
|
|
|
/* Don't take write permissions on an empty drive to allow attaching a
|
|
|
|
* read-only node later */
|
|
|
|
read_only = true;
|
|
|
|
} else {
|
2021-01-18 13:34:47 +01:00
|
|
|
read_only = !blk_bs(dev->conf.blk) ||
|
|
|
|
!blk_supports_write_perm(dev->conf.blk);
|
2016-10-27 22:29:13 +02:00
|
|
|
}
|
|
|
|
|
2020-05-29 00:55:10 +02:00
|
|
|
if (!blkconf_blocksizes(&dev->conf, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-27 22:29:13 +02:00
|
|
|
if (dev->conf.logical_block_size != 512 ||
|
|
|
|
dev->conf.physical_block_size != 512)
|
|
|
|
{
|
2017-09-18 16:05:14 +02:00
|
|
|
error_setg(errp, "Physical and logical block size must "
|
|
|
|
"be 512 for floppy");
|
|
|
|
return;
|
2016-10-27 22:29:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* rerror/werror aren't supported by fdc and therefore not even registered
|
|
|
|
* with qdev. So set the defaults manually before they are used in
|
|
|
|
* blkconf_apply_backend_options(). */
|
|
|
|
dev->conf.rerror = BLOCKDEV_ON_ERROR_AUTO;
|
|
|
|
dev->conf.werror = BLOCKDEV_ON_ERROR_AUTO;
|
2017-01-24 13:43:31 +01:00
|
|
|
|
2019-07-30 15:37:08 +02:00
|
|
|
if (!blkconf_apply_backend_options(&dev->conf, read_only, false, errp)) {
|
2017-09-18 16:05:14 +02:00
|
|
|
return;
|
2017-01-24 13:43:31 +01:00
|
|
|
}
|
2016-10-27 22:29:13 +02:00
|
|
|
|
|
|
|
/* 'enospc' is the default for -drive, 'report' is what blk_new() gives us
|
|
|
|
* for empty drives. */
|
|
|
|
if (blk_get_on_error(dev->conf.blk, 0) != BLOCKDEV_ON_ERROR_ENOSPC &&
|
|
|
|
blk_get_on_error(dev->conf.blk, 0) != BLOCKDEV_ON_ERROR_REPORT) {
|
2017-09-18 16:05:14 +02:00
|
|
|
error_setg(errp, "fdc doesn't support drive option werror");
|
|
|
|
return;
|
2016-10-27 22:29:13 +02:00
|
|
|
}
|
2016-10-27 22:29:13 +02:00
|
|
|
if (blk_get_on_error(dev->conf.blk, 1) != BLOCKDEV_ON_ERROR_REPORT) {
|
2017-09-18 16:05:14 +02:00
|
|
|
error_setg(errp, "fdc doesn't support drive option rerror");
|
|
|
|
return;
|
2016-10-27 22:29:13 +02:00
|
|
|
}
|
|
|
|
|
2017-01-24 13:43:31 +01:00
|
|
|
drive->conf = &dev->conf;
|
2016-10-27 22:29:13 +02:00
|
|
|
drive->blk = dev->conf.blk;
|
|
|
|
drive->fdctrl = bus->fdc;
|
|
|
|
|
|
|
|
fd_init(drive);
|
|
|
|
blk_set_dev_ops(drive->blk, &fd_block_ops, drive);
|
|
|
|
|
|
|
|
/* Keep 'type' qdev property and FDrive->drive in sync */
|
|
|
|
drive->drive = dev->type;
|
|
|
|
pick_drive_type(drive);
|
|
|
|
dev->type = drive->drive;
|
|
|
|
|
2016-10-27 22:29:13 +02:00
|
|
|
fd_revalidate(drive);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void floppy_drive_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *k = DEVICE_CLASS(klass);
|
2017-09-18 16:05:14 +02:00
|
|
|
k->realize = floppy_drive_realize;
|
2016-10-27 22:29:13 +02:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
|
|
|
|
k->bus_type = TYPE_FLOPPY_BUS;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(k, floppy_drive_properties);
|
2016-10-27 22:29:13 +02:00
|
|
|
k->desc = "virtual floppy drive";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo floppy_drive_info = {
|
|
|
|
.name = TYPE_FLOPPY_DRIVE,
|
|
|
|
.parent = TYPE_DEVICE,
|
|
|
|
.instance_size = sizeof(FloppyDrive),
|
|
|
|
.class_init = floppy_drive_class_init,
|
|
|
|
};
|
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/********************************************************/
|
2004-10-09 18:44:33 +02:00
|
|
|
/* Intel 82078 floppy disk controller emulation */
|
2004-01-05 01:09:06 +01:00
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_reset(FDCtrl *fdctrl, int do_irq);
|
2015-05-21 15:19:31 +02:00
|
|
|
static void fdctrl_to_command_phase(FDCtrl *fdctrl);
|
2004-11-07 19:04:02 +01:00
|
|
|
static int fdctrl_transfer_handler (void *opaque, int nchan,
|
2009-10-01 23:12:16 +02:00
|
|
|
int dma_pos, int dma_len);
|
2012-08-19 10:21:14 +02:00
|
|
|
static void fdctrl_raise_irq(FDCtrl *fdctrl);
|
2012-02-06 22:29:12 +01:00
|
|
|
static FDrive *get_cur_drv(FDCtrl *fdctrl);
|
2010-02-07 10:01:18 +01:00
|
|
|
|
|
|
|
static uint32_t fdctrl_read_statusA(FDCtrl *fdctrl);
|
|
|
|
static uint32_t fdctrl_read_statusB(FDCtrl *fdctrl);
|
|
|
|
static uint32_t fdctrl_read_dor(FDCtrl *fdctrl);
|
|
|
|
static void fdctrl_write_dor(FDCtrl *fdctrl, uint32_t value);
|
|
|
|
static uint32_t fdctrl_read_tape(FDCtrl *fdctrl);
|
|
|
|
static void fdctrl_write_tape(FDCtrl *fdctrl, uint32_t value);
|
|
|
|
static uint32_t fdctrl_read_main_status(FDCtrl *fdctrl);
|
|
|
|
static void fdctrl_write_rate(FDCtrl *fdctrl, uint32_t value);
|
|
|
|
static uint32_t fdctrl_read_data(FDCtrl *fdctrl);
|
|
|
|
static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value);
|
|
|
|
static uint32_t fdctrl_read_dir(FDCtrl *fdctrl);
|
2012-02-06 22:29:06 +01:00
|
|
|
static void fdctrl_write_ccr(FDCtrl *fdctrl, uint32_t value);
|
2004-01-05 01:09:06 +01:00
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_DIR_WRITE = 0,
|
|
|
|
FD_DIR_READ = 1,
|
|
|
|
FD_DIR_SCANE = 2,
|
|
|
|
FD_DIR_SCANL = 3,
|
|
|
|
FD_DIR_SCANH = 4,
|
2012-09-18 23:04:10 +02:00
|
|
|
FD_DIR_VERIFY = 5,
|
2004-01-05 01:09:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2008-04-29 18:16:30 +02:00
|
|
|
FD_STATE_MULTI = 0x01, /* multi track flag */
|
|
|
|
FD_STATE_FORMAT = 0x02, /* format flag */
|
2004-01-05 01:09:06 +01:00
|
|
|
};
|
|
|
|
|
2008-02-29 20:24:00 +01:00
|
|
|
enum {
|
2008-04-29 18:14:15 +02:00
|
|
|
FD_REG_SRA = 0x00,
|
|
|
|
FD_REG_SRB = 0x01,
|
2008-02-29 20:24:00 +01:00
|
|
|
FD_REG_DOR = 0x02,
|
|
|
|
FD_REG_TDR = 0x03,
|
|
|
|
FD_REG_MSR = 0x04,
|
|
|
|
FD_REG_DSR = 0x04,
|
|
|
|
FD_REG_FIFO = 0x05,
|
|
|
|
FD_REG_DIR = 0x07,
|
2012-02-06 22:29:06 +01:00
|
|
|
FD_REG_CCR = 0x07,
|
2008-02-29 20:24:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2008-04-08 19:18:53 +02:00
|
|
|
FD_CMD_READ_TRACK = 0x02,
|
2008-02-29 20:24:00 +01:00
|
|
|
FD_CMD_SPECIFY = 0x03,
|
|
|
|
FD_CMD_SENSE_DRIVE_STATUS = 0x04,
|
2008-04-08 19:18:53 +02:00
|
|
|
FD_CMD_WRITE = 0x05,
|
|
|
|
FD_CMD_READ = 0x06,
|
2008-02-29 20:24:00 +01:00
|
|
|
FD_CMD_RECALIBRATE = 0x07,
|
|
|
|
FD_CMD_SENSE_INTERRUPT_STATUS = 0x08,
|
2008-04-08 19:18:53 +02:00
|
|
|
FD_CMD_WRITE_DELETED = 0x09,
|
|
|
|
FD_CMD_READ_ID = 0x0a,
|
|
|
|
FD_CMD_READ_DELETED = 0x0c,
|
|
|
|
FD_CMD_FORMAT_TRACK = 0x0d,
|
2008-02-29 20:24:00 +01:00
|
|
|
FD_CMD_DUMPREG = 0x0e,
|
|
|
|
FD_CMD_SEEK = 0x0f,
|
|
|
|
FD_CMD_VERSION = 0x10,
|
2008-04-08 19:18:53 +02:00
|
|
|
FD_CMD_SCAN_EQUAL = 0x11,
|
2008-02-29 20:24:00 +01:00
|
|
|
FD_CMD_PERPENDICULAR_MODE = 0x12,
|
|
|
|
FD_CMD_CONFIGURE = 0x13,
|
2008-04-08 19:18:53 +02:00
|
|
|
FD_CMD_LOCK = 0x14,
|
|
|
|
FD_CMD_VERIFY = 0x16,
|
2008-02-29 20:24:00 +01:00
|
|
|
FD_CMD_POWERDOWN_MODE = 0x17,
|
|
|
|
FD_CMD_PART_ID = 0x18,
|
2008-04-08 19:18:53 +02:00
|
|
|
FD_CMD_SCAN_LOW_OR_EQUAL = 0x19,
|
|
|
|
FD_CMD_SCAN_HIGH_OR_EQUAL = 0x1d,
|
2010-06-11 16:02:34 +02:00
|
|
|
FD_CMD_SAVE = 0x2e,
|
2008-02-29 20:24:00 +01:00
|
|
|
FD_CMD_OPTION = 0x33,
|
2010-06-11 16:02:34 +02:00
|
|
|
FD_CMD_RESTORE = 0x4e,
|
2008-02-29 20:24:00 +01:00
|
|
|
FD_CMD_DRIVE_SPECIFICATION_COMMAND = 0x8e,
|
|
|
|
FD_CMD_RELATIVE_SEEK_OUT = 0x8f,
|
|
|
|
FD_CMD_FORMAT_AND_WRITE = 0xcd,
|
|
|
|
FD_CMD_RELATIVE_SEEK_IN = 0xcf,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_CONFIG_PRETRK = 0xff, /* Pre-compensation set to track 0 */
|
|
|
|
FD_CONFIG_FIFOTHR = 0x0f, /* FIFO threshold set to 1 byte */
|
|
|
|
FD_CONFIG_POLL = 0x10, /* Poll enabled */
|
|
|
|
FD_CONFIG_EFIFO = 0x20, /* FIFO disabled */
|
|
|
|
FD_CONFIG_EIS = 0x40, /* No implied seeks */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2012-06-22 12:33:55 +02:00
|
|
|
FD_SR0_DS0 = 0x01,
|
|
|
|
FD_SR0_DS1 = 0x02,
|
|
|
|
FD_SR0_HEAD = 0x04,
|
2008-02-29 20:24:00 +01:00
|
|
|
FD_SR0_EQPMT = 0x10,
|
|
|
|
FD_SR0_SEEK = 0x20,
|
|
|
|
FD_SR0_ABNTERM = 0x40,
|
|
|
|
FD_SR0_INVCMD = 0x80,
|
|
|
|
FD_SR0_RDYCHG = 0xc0,
|
|
|
|
};
|
|
|
|
|
2008-04-29 18:17:08 +02:00
|
|
|
enum {
|
2012-02-06 22:29:10 +01:00
|
|
|
FD_SR1_MA = 0x01, /* Missing address mark */
|
2012-02-06 22:29:05 +01:00
|
|
|
FD_SR1_NW = 0x02, /* Not writable */
|
2008-04-29 18:17:08 +02:00
|
|
|
FD_SR1_EC = 0x80, /* End of cylinder */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_SR2_SNS = 0x04, /* Scan not satisfied */
|
|
|
|
FD_SR2_SEH = 0x08, /* Scan equal hit */
|
|
|
|
};
|
|
|
|
|
2008-04-29 18:14:15 +02:00
|
|
|
enum {
|
|
|
|
FD_SRA_DIR = 0x01,
|
|
|
|
FD_SRA_nWP = 0x02,
|
|
|
|
FD_SRA_nINDX = 0x04,
|
|
|
|
FD_SRA_HDSEL = 0x08,
|
|
|
|
FD_SRA_nTRK0 = 0x10,
|
|
|
|
FD_SRA_STEP = 0x20,
|
|
|
|
FD_SRA_nDRV2 = 0x40,
|
|
|
|
FD_SRA_INTPEND = 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_SRB_MTR0 = 0x01,
|
|
|
|
FD_SRB_MTR1 = 0x02,
|
|
|
|
FD_SRB_WGATE = 0x04,
|
|
|
|
FD_SRB_RDATA = 0x08,
|
|
|
|
FD_SRB_WDATA = 0x10,
|
|
|
|
FD_SRB_DR0 = 0x20,
|
|
|
|
};
|
|
|
|
|
2008-02-29 20:24:00 +01:00
|
|
|
enum {
|
2008-04-29 18:18:26 +02:00
|
|
|
#if MAX_FD == 4
|
|
|
|
FD_DOR_SELMASK = 0x03,
|
|
|
|
#else
|
2008-02-29 20:24:00 +01:00
|
|
|
FD_DOR_SELMASK = 0x01,
|
2008-04-29 18:18:26 +02:00
|
|
|
#endif
|
2008-02-29 20:24:00 +01:00
|
|
|
FD_DOR_nRESET = 0x04,
|
|
|
|
FD_DOR_DMAEN = 0x08,
|
|
|
|
FD_DOR_MOTEN0 = 0x10,
|
|
|
|
FD_DOR_MOTEN1 = 0x20,
|
|
|
|
FD_DOR_MOTEN2 = 0x40,
|
|
|
|
FD_DOR_MOTEN3 = 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2008-04-29 18:18:26 +02:00
|
|
|
#if MAX_FD == 4
|
2008-02-29 20:24:00 +01:00
|
|
|
FD_TDR_BOOTSEL = 0x0c,
|
2008-04-29 18:18:26 +02:00
|
|
|
#else
|
|
|
|
FD_TDR_BOOTSEL = 0x04,
|
|
|
|
#endif
|
2008-02-29 20:24:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_DSR_DRATEMASK= 0x03,
|
|
|
|
FD_DSR_PWRDOWN = 0x40,
|
|
|
|
FD_DSR_SWRESET = 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_MSR_DRV0BUSY = 0x01,
|
|
|
|
FD_MSR_DRV1BUSY = 0x02,
|
|
|
|
FD_MSR_DRV2BUSY = 0x04,
|
|
|
|
FD_MSR_DRV3BUSY = 0x08,
|
|
|
|
FD_MSR_CMDBUSY = 0x10,
|
|
|
|
FD_MSR_NONDMA = 0x20,
|
|
|
|
FD_MSR_DIO = 0x40,
|
|
|
|
FD_MSR_RQM = 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_DIR_DSKCHG = 0x80,
|
|
|
|
};
|
|
|
|
|
2015-05-21 15:19:33 +02:00
|
|
|
/*
|
|
|
|
* See chapter 5.0 "Controller phases" of the spec:
|
|
|
|
*
|
|
|
|
* Command phase:
|
|
|
|
* The host writes a command and its parameters into the FIFO. The command
|
|
|
|
* phase is completed when all parameters for the command have been supplied,
|
|
|
|
* and execution phase is entered.
|
|
|
|
*
|
|
|
|
* Execution phase:
|
|
|
|
* Data transfers, either DMA or non-DMA. For non-DMA transfers, the FIFO
|
|
|
|
* contains the payload now, otherwise it's unused. When all bytes of the
|
|
|
|
* required data have been transferred, the state is switched to either result
|
|
|
|
* phase (if the command produces status bytes) or directly back into the
|
|
|
|
* command phase for the next command.
|
|
|
|
*
|
|
|
|
* Result phase:
|
|
|
|
* The host reads out the FIFO, which contains one or more result bytes now.
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
/* Only for migration: reconstruct phase from registers like qemu 2.3 */
|
|
|
|
FD_PHASE_RECONSTRUCT = 0,
|
|
|
|
|
|
|
|
FD_PHASE_COMMAND = 1,
|
|
|
|
FD_PHASE_EXECUTION = 2,
|
|
|
|
FD_PHASE_RESULT = 3,
|
|
|
|
};
|
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
#define FD_MULTI_TRACK(state) ((state) & FD_STATE_MULTI)
|
2004-03-20 00:05:34 +01:00
|
|
|
#define FD_FORMAT_CMD(state) ((state) & FD_STATE_FORMAT)
|
2004-01-05 01:09:06 +01:00
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
struct FDCtrl {
|
2011-10-11 15:52:48 +02:00
|
|
|
MemoryRegion iomem;
|
2007-04-07 20:14:41 +02:00
|
|
|
qemu_irq irq;
|
2004-10-09 18:44:33 +02:00
|
|
|
/* Controller state */
|
2004-05-08 15:14:18 +02:00
|
|
|
QEMUTimer *result_timer;
|
2011-08-07 21:43:38 +02:00
|
|
|
int dma_chann;
|
2015-05-21 15:19:33 +02:00
|
|
|
uint8_t phase;
|
2016-02-03 17:28:58 +01:00
|
|
|
IsaDma *dma;
|
2011-08-07 21:43:38 +02:00
|
|
|
/* Controller's identification */
|
|
|
|
uint8_t version;
|
|
|
|
/* HW */
|
2008-04-29 18:14:15 +02:00
|
|
|
uint8_t sra;
|
|
|
|
uint8_t srb;
|
2008-04-29 18:15:12 +02:00
|
|
|
uint8_t dor;
|
2009-09-10 03:04:37 +02:00
|
|
|
uint8_t dor_vmstate; /* only used as temp during vmstate */
|
2008-04-29 18:17:42 +02:00
|
|
|
uint8_t tdr;
|
2008-04-29 18:16:30 +02:00
|
|
|
uint8_t dsr;
|
2008-04-29 18:15:12 +02:00
|
|
|
uint8_t msr;
|
2004-01-05 01:09:06 +01:00
|
|
|
uint8_t cur_drv;
|
2008-04-29 18:17:08 +02:00
|
|
|
uint8_t status0;
|
|
|
|
uint8_t status1;
|
|
|
|
uint8_t status2;
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Command FIFO */
|
2007-12-24 15:33:24 +01:00
|
|
|
uint8_t *fifo;
|
2009-09-10 03:04:37 +02:00
|
|
|
int32_t fifo_size;
|
2004-01-05 01:09:06 +01:00
|
|
|
uint32_t data_pos;
|
|
|
|
uint32_t data_len;
|
|
|
|
uint8_t data_state;
|
|
|
|
uint8_t data_dir;
|
2004-10-08 01:10:29 +02:00
|
|
|
uint8_t eot; /* last wanted sector */
|
2004-01-05 01:09:06 +01:00
|
|
|
/* States kept only to be returned back */
|
|
|
|
/* precompensation */
|
|
|
|
uint8_t precomp_trk;
|
|
|
|
uint8_t config;
|
|
|
|
uint8_t lock;
|
|
|
|
/* Power down config (also with status regB access mode */
|
|
|
|
uint8_t pwrd;
|
|
|
|
/* Floppy drives */
|
2016-10-27 22:29:13 +02:00
|
|
|
FloppyBus bus;
|
2009-09-10 03:04:37 +02:00
|
|
|
uint8_t num_floppies;
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive drives[MAX_FD];
|
2016-10-27 22:29:13 +02:00
|
|
|
struct {
|
|
|
|
FloppyDriveType type;
|
|
|
|
} qdev_for_drives[MAX_FD];
|
2009-01-24 13:09:52 +01:00
|
|
|
int reset_sensei;
|
2016-01-22 21:51:00 +01:00
|
|
|
FloppyDriveType fallback; /* type=auto failure fallback */
|
2011-08-07 21:43:38 +02:00
|
|
|
/* Timers state */
|
|
|
|
uint8_t timer0;
|
|
|
|
uint8_t timer1;
|
2016-07-13 02:11:59 +02:00
|
|
|
PortioList portio_list;
|
2004-03-20 00:05:34 +01:00
|
|
|
};
|
|
|
|
|
2016-01-22 21:51:00 +01:00
|
|
|
static FloppyDriveType get_fallback_drive_type(FDrive *drv)
|
|
|
|
{
|
|
|
|
return drv->fdctrl->fallback;
|
|
|
|
}
|
|
|
|
|
2013-07-27 01:55:26 +02:00
|
|
|
#define TYPE_SYSBUS_FDC "base-sysbus-fdc"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(FDCtrlSysBus, SYSBUS_FDC)
|
2013-07-01 12:18:24 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct FDCtrlSysBus {
|
2013-07-01 12:18:24 +02:00
|
|
|
/*< private >*/
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
struct FDCtrl state;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2009-07-31 12:30:18 +02:00
|
|
|
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(FDCtrlISABus, ISA_FDC)
|
2013-04-27 22:18:38 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct FDCtrlISABus {
|
2013-04-27 22:18:38 +02:00
|
|
|
ISADevice parent_obj;
|
|
|
|
|
2012-03-17 15:39:44 +01:00
|
|
|
uint32_t iobase;
|
|
|
|
uint32_t irq;
|
|
|
|
uint32_t dma;
|
2010-02-07 10:01:18 +01:00
|
|
|
struct FDCtrl state;
|
2010-12-08 12:35:05 +01:00
|
|
|
int32_t bootindexA;
|
|
|
|
int32_t bootindexB;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2009-07-31 12:30:18 +02:00
|
|
|
|
2004-03-20 00:05:34 +01:00
|
|
|
static uint32_t fdctrl_read (void *opaque, uint32_t reg)
|
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrl *fdctrl = opaque;
|
2004-03-20 00:05:34 +01:00
|
|
|
uint32_t retval;
|
|
|
|
|
2011-10-18 16:41:45 +02:00
|
|
|
reg &= 7;
|
2008-12-02 18:47:02 +01:00
|
|
|
switch (reg) {
|
2008-04-29 18:14:15 +02:00
|
|
|
case FD_REG_SRA:
|
|
|
|
retval = fdctrl_read_statusA(fdctrl);
|
2007-11-05 04:11:37 +01:00
|
|
|
break;
|
2008-04-29 18:14:15 +02:00
|
|
|
case FD_REG_SRB:
|
2007-11-05 04:11:37 +01:00
|
|
|
retval = fdctrl_read_statusB(fdctrl);
|
|
|
|
break;
|
2008-02-29 20:24:00 +01:00
|
|
|
case FD_REG_DOR:
|
2007-11-05 04:11:37 +01:00
|
|
|
retval = fdctrl_read_dor(fdctrl);
|
|
|
|
break;
|
2008-02-29 20:24:00 +01:00
|
|
|
case FD_REG_TDR:
|
2004-03-20 00:05:34 +01:00
|
|
|
retval = fdctrl_read_tape(fdctrl);
|
2007-11-05 04:11:37 +01:00
|
|
|
break;
|
2008-02-29 20:24:00 +01:00
|
|
|
case FD_REG_MSR:
|
2004-03-20 00:05:34 +01:00
|
|
|
retval = fdctrl_read_main_status(fdctrl);
|
2007-11-05 04:11:37 +01:00
|
|
|
break;
|
2008-02-29 20:24:00 +01:00
|
|
|
case FD_REG_FIFO:
|
2004-03-20 00:05:34 +01:00
|
|
|
retval = fdctrl_read_data(fdctrl);
|
2007-11-05 04:11:37 +01:00
|
|
|
break;
|
2008-02-29 20:24:00 +01:00
|
|
|
case FD_REG_DIR:
|
2004-03-20 00:05:34 +01:00
|
|
|
retval = fdctrl_read_dir(fdctrl);
|
2007-11-05 04:11:37 +01:00
|
|
|
break;
|
2004-04-12 22:39:29 +02:00
|
|
|
default:
|
2007-11-05 04:11:37 +01:00
|
|
|
retval = (uint32_t)(-1);
|
|
|
|
break;
|
2004-04-12 22:39:29 +02:00
|
|
|
}
|
2018-06-21 19:12:56 +02:00
|
|
|
trace_fdc_ioport_read(reg, retval);
|
2004-03-20 00:05:34 +01:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fdctrl_write (void *opaque, uint32_t reg, uint32_t value)
|
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrl *fdctrl = opaque;
|
2004-03-20 00:05:34 +01:00
|
|
|
|
2011-10-18 16:41:45 +02:00
|
|
|
reg &= 7;
|
2018-06-21 19:12:56 +02:00
|
|
|
trace_fdc_ioport_write(reg, value);
|
2008-12-02 18:47:02 +01:00
|
|
|
switch (reg) {
|
2008-02-29 20:24:00 +01:00
|
|
|
case FD_REG_DOR:
|
2007-11-05 04:11:37 +01:00
|
|
|
fdctrl_write_dor(fdctrl, value);
|
|
|
|
break;
|
2008-02-29 20:24:00 +01:00
|
|
|
case FD_REG_TDR:
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl_write_tape(fdctrl, value);
|
2007-11-05 04:11:37 +01:00
|
|
|
break;
|
2008-02-29 20:24:00 +01:00
|
|
|
case FD_REG_DSR:
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl_write_rate(fdctrl, value);
|
2007-11-05 04:11:37 +01:00
|
|
|
break;
|
2008-02-29 20:24:00 +01:00
|
|
|
case FD_REG_FIFO:
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl_write_data(fdctrl, value);
|
2007-11-05 04:11:37 +01:00
|
|
|
break;
|
2012-02-06 22:29:06 +01:00
|
|
|
case FD_REG_CCR:
|
|
|
|
fdctrl_write_ccr(fdctrl, value);
|
|
|
|
break;
|
2004-04-12 22:39:29 +02:00
|
|
|
default:
|
2007-11-05 04:11:37 +01:00
|
|
|
break;
|
2004-04-12 22:39:29 +02:00
|
|
|
}
|
2004-03-20 00:05:34 +01:00
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t fdctrl_read_mem (void *opaque, hwaddr reg,
|
2011-10-11 15:52:48 +02:00
|
|
|
unsigned ize)
|
2005-01-04 00:28:27 +01:00
|
|
|
{
|
2007-05-19 14:58:30 +02:00
|
|
|
return fdctrl_read(opaque, (uint32_t)reg);
|
2005-01-04 00:28:27 +01:00
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void fdctrl_write_mem (void *opaque, hwaddr reg,
|
2011-10-11 15:52:48 +02:00
|
|
|
uint64_t value, unsigned size)
|
2005-01-04 00:28:27 +01:00
|
|
|
{
|
2007-05-19 14:58:30 +02:00
|
|
|
fdctrl_write(opaque, (uint32_t)reg, value);
|
2005-01-04 00:28:27 +01:00
|
|
|
}
|
|
|
|
|
2011-10-11 15:52:48 +02:00
|
|
|
static const MemoryRegionOps fdctrl_mem_ops = {
|
|
|
|
.read = fdctrl_read_mem,
|
|
|
|
.write = fdctrl_write_mem,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2004-12-20 00:18:01 +01:00
|
|
|
};
|
|
|
|
|
2011-10-11 15:52:48 +02:00
|
|
|
static const MemoryRegionOps fdctrl_mem_strict_ops = {
|
|
|
|
.read = fdctrl_read_mem,
|
|
|
|
.write = fdctrl_write_mem,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
.valid = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 1,
|
|
|
|
},
|
2008-01-01 18:06:38 +01:00
|
|
|
};
|
|
|
|
|
2011-04-06 12:34:31 +02:00
|
|
|
static bool fdrive_media_changed_needed(void *opaque)
|
|
|
|
{
|
|
|
|
FDrive *drive = opaque;
|
|
|
|
|
Revert "hw/block/fdc: Implement tray status"
This reverts the changes that commit
2e1280e8ff95b3145bc6262accc9d447718e5318 applied to hw/block/fdc.c;
also, an additional case of drv->media_inserted use has crept in since,
which is replaced by a call to blk_is_inserted().
That commit changed tests/fdc-test.c, too, because after it, one less
TRAY_MOVED event would be emitted when executing 'change' on an empty
drive. However, now, no TRAY_MOVED events will be emitted at all, and
the tray_open status returned by query-block will always be false,
necessitating (different) changes to tests/fdc-test.c and iotest 118,
which is why this patch is not a pure revert of said commit.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 1454096953-31773-4-git-send-email-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
2016-01-29 20:49:12 +01:00
|
|
|
return (drive->blk != NULL && drive->media_changed != 1);
|
2011-04-06 12:34:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_fdrive_media_changed = {
|
|
|
|
.name = "fdrive/media_changed",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 14:09:54 +02:00
|
|
|
.needed = fdrive_media_changed_needed,
|
2014-04-16 15:32:32 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2011-04-06 12:34:31 +02:00
|
|
|
VMSTATE_UINT8(media_changed, FDrive),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-06 22:29:10 +01:00
|
|
|
static const VMStateDescription vmstate_fdrive_media_rate = {
|
|
|
|
.name = "fdrive/media_rate",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-04-16 15:32:32 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2012-02-06 22:29:10 +01:00
|
|
|
VMSTATE_UINT8(media_rate, FDrive),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-28 13:18:41 +02:00
|
|
|
static bool fdrive_perpendicular_needed(void *opaque)
|
|
|
|
{
|
|
|
|
FDrive *drive = opaque;
|
|
|
|
|
|
|
|
return drive->perpendicular != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_fdrive_perpendicular = {
|
|
|
|
.name = "fdrive/perpendicular",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 14:09:54 +02:00
|
|
|
.needed = fdrive_perpendicular_needed,
|
2014-08-28 13:18:41 +02:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8(perpendicular, FDrive),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int fdrive_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
fd_revalidate(opaque);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-10 03:04:37 +02:00
|
|
|
static const VMStateDescription vmstate_fdrive = {
|
|
|
|
.name = "fdrive",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-08-28 13:18:41 +02:00
|
|
|
.post_load = fdrive_post_load,
|
2014-04-16 15:32:32 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2010-02-07 10:01:18 +01:00
|
|
|
VMSTATE_UINT8(head, FDrive),
|
|
|
|
VMSTATE_UINT8(track, FDrive),
|
|
|
|
VMSTATE_UINT8(sect, FDrive),
|
2009-09-10 03:04:37 +02:00
|
|
|
VMSTATE_END_OF_LIST()
|
2011-04-06 12:34:31 +02:00
|
|
|
},
|
2014-09-23 14:09:54 +02:00
|
|
|
.subsections = (const VMStateDescription*[]) {
|
|
|
|
&vmstate_fdrive_media_changed,
|
|
|
|
&vmstate_fdrive_media_rate,
|
|
|
|
&vmstate_fdrive_perpendicular,
|
|
|
|
NULL
|
2009-09-10 03:04:37 +02:00
|
|
|
}
|
|
|
|
};
|
2007-04-14 15:01:31 +02:00
|
|
|
|
2015-05-21 15:19:33 +02:00
|
|
|
/*
|
|
|
|
* Reconstructs the phase from register values according to the logic that was
|
|
|
|
* implemented in qemu 2.3. This is the default value that is used if the phase
|
|
|
|
* subsection is not present on migration.
|
|
|
|
*
|
|
|
|
* Don't change this function to reflect newer qemu versions, it is part of
|
|
|
|
* the migration ABI.
|
|
|
|
*/
|
|
|
|
static int reconstruct_phase(FDCtrl *fdctrl)
|
|
|
|
{
|
|
|
|
if (fdctrl->msr & FD_MSR_NONDMA) {
|
|
|
|
return FD_PHASE_EXECUTION;
|
|
|
|
} else if ((fdctrl->msr & FD_MSR_RQM) == 0) {
|
|
|
|
/* qemu 2.3 disabled RQM only during DMA transfers */
|
|
|
|
return FD_PHASE_EXECUTION;
|
|
|
|
} else if (fdctrl->msr & FD_MSR_DIO) {
|
|
|
|
return FD_PHASE_RESULT;
|
|
|
|
} else {
|
|
|
|
return FD_PHASE_COMMAND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-25 13:29:12 +02:00
|
|
|
static int fdc_pre_save(void *opaque)
|
2007-04-14 15:01:31 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrl *s = opaque;
|
2007-04-14 15:01:31 +02:00
|
|
|
|
2009-09-10 03:04:37 +02:00
|
|
|
s->dor_vmstate = s->dor | GET_CUR_DRV(s);
|
2017-09-25 13:29:12 +02:00
|
|
|
|
|
|
|
return 0;
|
2007-04-14 15:01:31 +02:00
|
|
|
}
|
|
|
|
|
2015-05-21 15:19:33 +02:00
|
|
|
static int fdc_pre_load(void *opaque)
|
|
|
|
{
|
|
|
|
FDCtrl *s = opaque;
|
|
|
|
s->phase = FD_PHASE_RECONSTRUCT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-29 22:48:21 +02:00
|
|
|
static int fdc_post_load(void *opaque, int version_id)
|
2007-04-14 15:01:31 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrl *s = opaque;
|
2007-04-14 15:01:31 +02:00
|
|
|
|
2009-09-10 03:04:37 +02:00
|
|
|
SET_CUR_DRV(s, s->dor_vmstate & FD_DOR_SELMASK);
|
|
|
|
s->dor = s->dor_vmstate & ~FD_DOR_SELMASK;
|
2015-05-21 15:19:33 +02:00
|
|
|
|
|
|
|
if (s->phase == FD_PHASE_RECONSTRUCT) {
|
|
|
|
s->phase = reconstruct_phase(s);
|
|
|
|
}
|
|
|
|
|
2007-04-14 15:01:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-28 13:18:41 +02:00
|
|
|
static bool fdc_reset_sensei_needed(void *opaque)
|
|
|
|
{
|
|
|
|
FDCtrl *s = opaque;
|
|
|
|
|
|
|
|
return s->reset_sensei != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_fdc_reset_sensei = {
|
|
|
|
.name = "fdc/reset_sensei",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 14:09:54 +02:00
|
|
|
.needed = fdc_reset_sensei_needed,
|
2014-08-28 13:18:41 +02:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_INT32(reset_sensei, FDCtrl),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool fdc_result_timer_needed(void *opaque)
|
|
|
|
{
|
|
|
|
FDCtrl *s = opaque;
|
|
|
|
|
|
|
|
return timer_pending(s->result_timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_fdc_result_timer = {
|
|
|
|
.name = "fdc/result_timer",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 14:09:54 +02:00
|
|
|
.needed = fdc_result_timer_needed,
|
2014-08-28 13:18:41 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2015-01-08 10:18:59 +01:00
|
|
|
VMSTATE_TIMER_PTR(result_timer, FDCtrl),
|
2014-08-28 13:18:41 +02:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-21 15:19:33 +02:00
|
|
|
static bool fdc_phase_needed(void *opaque)
|
|
|
|
{
|
|
|
|
FDCtrl *fdctrl = opaque;
|
|
|
|
|
|
|
|
return reconstruct_phase(fdctrl) != fdctrl->phase;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_fdc_phase = {
|
|
|
|
.name = "fdc/phase",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 14:09:54 +02:00
|
|
|
.needed = fdc_phase_needed,
|
2015-05-21 15:19:33 +02:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8(phase, FDCtrl),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-09-10 03:04:37 +02:00
|
|
|
static const VMStateDescription vmstate_fdc = {
|
2009-12-15 14:34:34 +01:00
|
|
|
.name = "fdc",
|
2009-09-10 03:04:37 +02:00
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
|
|
|
.pre_save = fdc_pre_save,
|
2015-05-21 15:19:33 +02:00
|
|
|
.pre_load = fdc_pre_load,
|
2009-09-10 03:04:37 +02:00
|
|
|
.post_load = fdc_post_load,
|
2014-04-16 15:32:32 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2009-09-10 03:04:37 +02:00
|
|
|
/* Controller State */
|
2010-02-07 10:01:18 +01:00
|
|
|
VMSTATE_UINT8(sra, FDCtrl),
|
|
|
|
VMSTATE_UINT8(srb, FDCtrl),
|
|
|
|
VMSTATE_UINT8(dor_vmstate, FDCtrl),
|
|
|
|
VMSTATE_UINT8(tdr, FDCtrl),
|
|
|
|
VMSTATE_UINT8(dsr, FDCtrl),
|
|
|
|
VMSTATE_UINT8(msr, FDCtrl),
|
|
|
|
VMSTATE_UINT8(status0, FDCtrl),
|
|
|
|
VMSTATE_UINT8(status1, FDCtrl),
|
|
|
|
VMSTATE_UINT8(status2, FDCtrl),
|
2009-09-10 03:04:37 +02:00
|
|
|
/* Command FIFO */
|
2010-03-21 13:30:46 +01:00
|
|
|
VMSTATE_VARRAY_INT32(fifo, FDCtrl, fifo_size, 0, vmstate_info_uint8,
|
|
|
|
uint8_t),
|
2010-02-07 10:01:18 +01:00
|
|
|
VMSTATE_UINT32(data_pos, FDCtrl),
|
|
|
|
VMSTATE_UINT32(data_len, FDCtrl),
|
|
|
|
VMSTATE_UINT8(data_state, FDCtrl),
|
|
|
|
VMSTATE_UINT8(data_dir, FDCtrl),
|
|
|
|
VMSTATE_UINT8(eot, FDCtrl),
|
2009-09-10 03:04:37 +02:00
|
|
|
/* States kept only to be returned back */
|
2010-02-07 10:01:18 +01:00
|
|
|
VMSTATE_UINT8(timer0, FDCtrl),
|
|
|
|
VMSTATE_UINT8(timer1, FDCtrl),
|
|
|
|
VMSTATE_UINT8(precomp_trk, FDCtrl),
|
|
|
|
VMSTATE_UINT8(config, FDCtrl),
|
|
|
|
VMSTATE_UINT8(lock, FDCtrl),
|
|
|
|
VMSTATE_UINT8(pwrd, FDCtrl),
|
2017-06-23 16:48:23 +02:00
|
|
|
VMSTATE_UINT8_EQUAL(num_floppies, FDCtrl, NULL),
|
2010-02-07 10:01:18 +01:00
|
|
|
VMSTATE_STRUCT_ARRAY(drives, FDCtrl, MAX_FD, 1,
|
|
|
|
vmstate_fdrive, FDrive),
|
2009-09-10 03:04:37 +02:00
|
|
|
VMSTATE_END_OF_LIST()
|
2014-08-28 13:18:41 +02:00
|
|
|
},
|
2014-09-23 14:09:54 +02:00
|
|
|
.subsections = (const VMStateDescription*[]) {
|
|
|
|
&vmstate_fdc_reset_sensei,
|
|
|
|
&vmstate_fdc_result_timer,
|
|
|
|
&vmstate_fdc_phase,
|
|
|
|
NULL
|
2008-04-29 18:18:26 +02:00
|
|
|
}
|
2009-09-10 03:04:37 +02:00
|
|
|
};
|
2007-04-14 15:01:31 +02:00
|
|
|
|
2009-10-24 18:56:20 +02:00
|
|
|
static void fdctrl_external_reset_sysbus(DeviceState *d)
|
2007-04-14 15:01:31 +02:00
|
|
|
{
|
2013-07-01 12:18:24 +02:00
|
|
|
FDCtrlSysBus *sys = SYSBUS_FDC(d);
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrl *s = &sys->state;
|
2009-10-24 18:56:20 +02:00
|
|
|
|
|
|
|
fdctrl_reset(s, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fdctrl_external_reset_isa(DeviceState *d)
|
|
|
|
{
|
2013-04-27 22:18:38 +02:00
|
|
|
FDCtrlISABus *isa = ISA_FDC(d);
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrl *s = &isa->state;
|
2007-04-14 15:01:31 +02:00
|
|
|
|
|
|
|
fdctrl_reset(s, 0);
|
|
|
|
}
|
|
|
|
|
2008-03-21 19:05:23 +01:00
|
|
|
static void fdctrl_handle_tc(void *opaque, int irq, int level)
|
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
//FDCtrl *s = opaque;
|
2008-03-21 19:05:23 +01:00
|
|
|
|
|
|
|
if (level) {
|
|
|
|
// XXX
|
|
|
|
FLOPPY_DPRINTF("TC pulsed\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Change IRQ state */
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_reset_irq(FDCtrl *fdctrl)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2012-08-19 10:21:14 +02:00
|
|
|
fdctrl->status0 = 0;
|
2008-04-29 18:14:15 +02:00
|
|
|
if (!(fdctrl->sra & FD_SRA_INTPEND))
|
|
|
|
return;
|
2004-05-08 15:14:18 +02:00
|
|
|
FLOPPY_DPRINTF("Reset interrupt\n");
|
2007-04-07 20:14:41 +02:00
|
|
|
qemu_set_irq(fdctrl->irq, 0);
|
2008-04-29 18:14:15 +02:00
|
|
|
fdctrl->sra &= ~FD_SRA_INTPEND;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
2012-08-19 10:21:14 +02:00
|
|
|
static void fdctrl_raise_irq(FDCtrl *fdctrl)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2008-04-29 18:14:15 +02:00
|
|
|
if (!(fdctrl->sra & FD_SRA_INTPEND)) {
|
2007-04-07 20:14:41 +02:00
|
|
|
qemu_set_irq(fdctrl->irq, 1);
|
2008-04-29 18:14:15 +02:00
|
|
|
fdctrl->sra |= FD_SRA_INTPEND;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
2012-05-05 19:43:28 +02:00
|
|
|
|
2009-01-24 13:09:52 +01:00
|
|
|
fdctrl->reset_sensei = 0;
|
2008-04-29 18:17:08 +02:00
|
|
|
FLOPPY_DPRINTF("Set interrupt status to 0x%02x\n", fdctrl->status0);
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
2004-10-09 18:44:33 +02:00
|
|
|
/* Reset controller */
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_reset(FDCtrl *fdctrl, int do_irq)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2004-10-09 18:44:33 +02:00
|
|
|
FLOPPY_DPRINTF("reset controller\n");
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl_reset_irq(fdctrl);
|
2004-10-09 18:44:33 +02:00
|
|
|
/* Initialise controller */
|
2008-04-29 18:14:15 +02:00
|
|
|
fdctrl->sra = 0;
|
|
|
|
fdctrl->srb = 0xc0;
|
2014-10-07 13:59:18 +02:00
|
|
|
if (!fdctrl->drives[1].blk) {
|
2008-04-29 18:14:15 +02:00
|
|
|
fdctrl->sra |= FD_SRA_nDRV2;
|
2014-10-07 13:59:18 +02:00
|
|
|
}
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->cur_drv = 0;
|
2008-04-29 18:15:53 +02:00
|
|
|
fdctrl->dor = FD_DOR_nRESET;
|
2008-04-29 18:15:12 +02:00
|
|
|
fdctrl->dor |= (fdctrl->dma_chann != -1) ? FD_DOR_DMAEN : 0;
|
2008-04-29 18:16:30 +02:00
|
|
|
fdctrl->msr = FD_MSR_RQM;
|
2014-08-28 13:18:41 +02:00
|
|
|
fdctrl->reset_sensei = 0;
|
|
|
|
timer_del(fdctrl->result_timer);
|
2004-01-05 01:09:06 +01:00
|
|
|
/* FIFO state */
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->data_pos = 0;
|
|
|
|
fdctrl->data_len = 0;
|
2008-04-29 18:16:30 +02:00
|
|
|
fdctrl->data_state = 0;
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->data_dir = FD_DIR_WRITE;
|
2004-01-05 01:09:06 +01:00
|
|
|
for (i = 0; i < MAX_FD; i++)
|
2008-04-29 18:15:53 +02:00
|
|
|
fd_recalibrate(&fdctrl->drives[i]);
|
2015-05-21 15:19:31 +02:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-29 18:17:08 +02:00
|
|
|
if (do_irq) {
|
2012-08-19 10:21:14 +02:00
|
|
|
fdctrl->status0 |= FD_SR0_RDYCHG;
|
|
|
|
fdctrl_raise_irq(fdctrl);
|
2009-01-24 13:09:52 +01:00
|
|
|
fdctrl->reset_sensei = FD_RESET_SENSEI_COUNT;
|
2008-04-29 18:17:08 +02:00
|
|
|
}
|
2004-03-20 00:05:34 +01:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static inline FDrive *drv0(FDCtrl *fdctrl)
|
2004-03-20 00:05:34 +01:00
|
|
|
{
|
2008-04-29 18:17:42 +02:00
|
|
|
return &fdctrl->drives[(fdctrl->tdr & FD_TDR_BOOTSEL) >> 2];
|
2004-03-20 00:05:34 +01:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static inline FDrive *drv1(FDCtrl *fdctrl)
|
2004-03-20 00:05:34 +01:00
|
|
|
{
|
2008-04-29 18:17:42 +02:00
|
|
|
if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (1 << 2))
|
|
|
|
return &fdctrl->drives[1];
|
|
|
|
else
|
|
|
|
return &fdctrl->drives[0];
|
2004-03-20 00:05:34 +01:00
|
|
|
}
|
|
|
|
|
2008-04-29 18:18:26 +02:00
|
|
|
#if MAX_FD == 4
|
2010-02-07 10:01:18 +01:00
|
|
|
static inline FDrive *drv2(FDCtrl *fdctrl)
|
2008-04-29 18:18:26 +02:00
|
|
|
{
|
|
|
|
if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (2 << 2))
|
|
|
|
return &fdctrl->drives[2];
|
|
|
|
else
|
|
|
|
return &fdctrl->drives[1];
|
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static inline FDrive *drv3(FDCtrl *fdctrl)
|
2008-04-29 18:18:26 +02:00
|
|
|
{
|
|
|
|
if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (3 << 2))
|
|
|
|
return &fdctrl->drives[3];
|
|
|
|
else
|
|
|
|
return &fdctrl->drives[2];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-10-27 22:29:13 +02:00
|
|
|
static FDrive *get_drv(FDCtrl *fdctrl, int unit)
|
2004-03-20 00:05:34 +01:00
|
|
|
{
|
2016-10-27 22:29:13 +02:00
|
|
|
switch (unit) {
|
2008-04-29 18:18:26 +02:00
|
|
|
case 0: return drv0(fdctrl);
|
|
|
|
case 1: return drv1(fdctrl);
|
|
|
|
#if MAX_FD == 4
|
|
|
|
case 2: return drv2(fdctrl);
|
|
|
|
case 3: return drv3(fdctrl);
|
|
|
|
#endif
|
|
|
|
default: return NULL;
|
|
|
|
}
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
2016-10-27 22:29:13 +02:00
|
|
|
static FDrive *get_cur_drv(FDCtrl *fdctrl)
|
|
|
|
{
|
|
|
|
return get_drv(fdctrl, fdctrl->cur_drv);
|
|
|
|
}
|
|
|
|
|
2008-04-29 18:14:15 +02:00
|
|
|
/* Status A register : 0x00 (read-only) */
|
2010-02-07 10:01:18 +01:00
|
|
|
static uint32_t fdctrl_read_statusA(FDCtrl *fdctrl)
|
2008-04-29 18:14:15 +02:00
|
|
|
{
|
|
|
|
uint32_t retval = fdctrl->sra;
|
|
|
|
|
|
|
|
FLOPPY_DPRINTF("status register A: 0x%02x\n", retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Status B register : 0x01 (read-only) */
|
2010-02-07 10:01:18 +01:00
|
|
|
static uint32_t fdctrl_read_statusB(FDCtrl *fdctrl)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2008-04-29 18:14:15 +02:00
|
|
|
uint32_t retval = fdctrl->srb;
|
|
|
|
|
|
|
|
FLOPPY_DPRINTF("status register B: 0x%02x\n", retval);
|
|
|
|
|
|
|
|
return retval;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Digital output register : 0x02 */
|
2010-02-07 10:01:18 +01:00
|
|
|
static uint32_t fdctrl_read_dor(FDCtrl *fdctrl)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2008-04-29 18:15:53 +02:00
|
|
|
uint32_t retval = fdctrl->dor;
|
2004-01-05 01:09:06 +01:00
|
|
|
|
|
|
|
/* Selected drive */
|
2004-03-20 00:05:34 +01:00
|
|
|
retval |= fdctrl->cur_drv;
|
2004-01-05 01:09:06 +01:00
|
|
|
FLOPPY_DPRINTF("digital output register: 0x%02x\n", retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_write_dor(FDCtrl *fdctrl, uint32_t value)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
|
|
|
FLOPPY_DPRINTF("digital output register set to 0x%02x\n", value);
|
2008-04-29 18:14:15 +02:00
|
|
|
|
|
|
|
/* Motors */
|
|
|
|
if (value & FD_DOR_MOTEN0)
|
|
|
|
fdctrl->srb |= FD_SRB_MTR0;
|
|
|
|
else
|
|
|
|
fdctrl->srb &= ~FD_SRB_MTR0;
|
|
|
|
if (value & FD_DOR_MOTEN1)
|
|
|
|
fdctrl->srb |= FD_SRB_MTR1;
|
|
|
|
else
|
|
|
|
fdctrl->srb &= ~FD_SRB_MTR1;
|
|
|
|
|
|
|
|
/* Drive */
|
|
|
|
if (value & 1)
|
|
|
|
fdctrl->srb |= FD_SRB_DR0;
|
|
|
|
else
|
|
|
|
fdctrl->srb &= ~FD_SRB_DR0;
|
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Reset */
|
2008-02-29 20:24:00 +01:00
|
|
|
if (!(value & FD_DOR_nRESET)) {
|
2008-04-29 18:15:53 +02:00
|
|
|
if (fdctrl->dor & FD_DOR_nRESET) {
|
2004-10-09 18:44:33 +02:00
|
|
|
FLOPPY_DPRINTF("controller enter RESET state\n");
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
2008-04-29 18:15:53 +02:00
|
|
|
if (!(fdctrl->dor & FD_DOR_nRESET)) {
|
2004-10-09 18:44:33 +02:00
|
|
|
FLOPPY_DPRINTF("controller out of RESET state\n");
|
2004-05-04 04:04:17 +02:00
|
|
|
fdctrl_reset(fdctrl, 1);
|
2008-04-29 18:16:30 +02:00
|
|
|
fdctrl->dsr &= ~FD_DSR_PWRDOWN;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Selected drive */
|
2008-02-29 20:24:00 +01:00
|
|
|
fdctrl->cur_drv = value & FD_DOR_SELMASK;
|
2008-04-29 18:15:12 +02:00
|
|
|
|
|
|
|
fdctrl->dor = value;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Tape drive register : 0x03 */
|
2010-02-07 10:01:18 +01:00
|
|
|
static uint32_t fdctrl_read_tape(FDCtrl *fdctrl)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2008-04-29 18:17:42 +02:00
|
|
|
uint32_t retval = fdctrl->tdr;
|
2004-01-05 01:09:06 +01:00
|
|
|
|
|
|
|
FLOPPY_DPRINTF("tape drive register: 0x%02x\n", retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_write_tape(FDCtrl *fdctrl, uint32_t value)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
|
|
|
/* Reset mode */
|
2008-04-29 18:15:53 +02:00
|
|
|
if (!(fdctrl->dor & FD_DOR_nRESET)) {
|
2004-10-09 18:44:33 +02:00
|
|
|
FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
|
2004-01-05 01:09:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
FLOPPY_DPRINTF("tape drive register set to 0x%02x\n", value);
|
|
|
|
/* Disk boot selection indicator */
|
2008-04-29 18:17:42 +02:00
|
|
|
fdctrl->tdr = value & FD_TDR_BOOTSEL;
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Tape indicators: never allow */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Main status register : 0x04 (read) */
|
2010-02-07 10:01:18 +01:00
|
|
|
static uint32_t fdctrl_read_main_status(FDCtrl *fdctrl)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2008-04-29 18:16:30 +02:00
|
|
|
uint32_t retval = fdctrl->msr;
|
2004-01-05 01:09:06 +01:00
|
|
|
|
2008-04-29 18:16:30 +02:00
|
|
|
fdctrl->dsr &= ~FD_DSR_PWRDOWN;
|
2008-04-29 18:15:53 +02:00
|
|
|
fdctrl->dor |= FD_DOR_nRESET;
|
2008-04-29 18:16:30 +02:00
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
FLOPPY_DPRINTF("main status register: 0x%02x\n", retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Data select rate register : 0x04 (write) */
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_write_rate(FDCtrl *fdctrl, uint32_t value)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
|
|
|
/* Reset mode */
|
2008-04-29 18:15:53 +02:00
|
|
|
if (!(fdctrl->dor & FD_DOR_nRESET)) {
|
2007-11-05 04:11:37 +01:00
|
|
|
FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
|
|
|
|
return;
|
|
|
|
}
|
2004-01-05 01:09:06 +01:00
|
|
|
FLOPPY_DPRINTF("select rate register set to 0x%02x\n", value);
|
|
|
|
/* Reset: autoclear */
|
2008-02-29 20:24:00 +01:00
|
|
|
if (value & FD_DSR_SWRESET) {
|
2008-04-29 18:15:53 +02:00
|
|
|
fdctrl->dor &= ~FD_DOR_nRESET;
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl_reset(fdctrl, 1);
|
2008-04-29 18:15:53 +02:00
|
|
|
fdctrl->dor |= FD_DOR_nRESET;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
2008-02-29 20:24:00 +01:00
|
|
|
if (value & FD_DSR_PWRDOWN) {
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl_reset(fdctrl, 1);
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
2008-04-29 18:16:30 +02:00
|
|
|
fdctrl->dsr = value;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
2012-02-06 22:29:06 +01:00
|
|
|
/* Configuration control register: 0x07 (write) */
|
|
|
|
static void fdctrl_write_ccr(FDCtrl *fdctrl, uint32_t value)
|
|
|
|
{
|
|
|
|
/* Reset mode */
|
|
|
|
if (!(fdctrl->dor & FD_DOR_nRESET)) {
|
|
|
|
FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FLOPPY_DPRINTF("configuration control register set to 0x%02x\n", value);
|
|
|
|
|
|
|
|
/* Only the rate selection bits used in AT mode, and we
|
|
|
|
* store those in the DSR.
|
|
|
|
*/
|
|
|
|
fdctrl->dsr = (fdctrl->dsr & ~FD_DSR_DRATEMASK) |
|
|
|
|
(value & FD_DSR_DRATEMASK);
|
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static int fdctrl_media_changed(FDrive *drv)
|
2006-08-19 13:43:22 +02:00
|
|
|
{
|
2012-05-05 19:43:28 +02:00
|
|
|
return drv->media_changed;
|
2006-08-19 13:43:22 +02:00
|
|
|
}
|
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Digital input register : 0x07 (read-only) */
|
2010-02-07 10:01:18 +01:00
|
|
|
static uint32_t fdctrl_read_dir(FDCtrl *fdctrl)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
|
|
|
uint32_t retval = 0;
|
|
|
|
|
2012-02-06 22:29:12 +01:00
|
|
|
if (fdctrl_media_changed(get_cur_drv(fdctrl))) {
|
2008-02-29 20:24:00 +01:00
|
|
|
retval |= FD_DIR_DSKCHG;
|
2012-02-06 22:29:12 +01:00
|
|
|
}
|
2010-04-18 10:45:03 +02:00
|
|
|
if (retval != 0) {
|
2004-03-20 00:05:34 +01:00
|
|
|
FLOPPY_DPRINTF("Floppy digital input register: 0x%02x\n", retval);
|
2010-04-18 10:45:03 +02:00
|
|
|
}
|
2004-01-05 01:09:06 +01:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-05-21 15:19:31 +02:00
|
|
|
/* Clear the FIFO and update the state for receiving the next command */
|
|
|
|
static void fdctrl_to_command_phase(FDCtrl *fdctrl)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2015-05-21 15:19:33 +02:00
|
|
|
fdctrl->phase = FD_PHASE_COMMAND;
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->data_dir = FD_DIR_WRITE;
|
|
|
|
fdctrl->data_pos = 0;
|
2015-05-21 15:19:37 +02:00
|
|
|
fdctrl->data_len = 1; /* Accept command byte, adjust for params later */
|
2008-04-29 18:16:30 +02:00
|
|
|
fdctrl->msr &= ~(FD_MSR_CMDBUSY | FD_MSR_DIO);
|
2015-05-21 15:19:37 +02:00
|
|
|
fdctrl->msr |= FD_MSR_RQM;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
2015-05-21 15:19:32 +02:00
|
|
|
/* Update the state to allow the guest to read out the command status.
|
|
|
|
* @fifo_len is the number of result bytes to be read out. */
|
|
|
|
static void fdctrl_to_result_phase(FDCtrl *fdctrl, int fifo_len)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2015-05-21 15:19:33 +02:00
|
|
|
fdctrl->phase = FD_PHASE_RESULT;
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->data_dir = FD_DIR_READ;
|
|
|
|
fdctrl->data_len = fifo_len;
|
|
|
|
fdctrl->data_pos = 0;
|
2008-04-29 18:16:30 +02:00
|
|
|
fdctrl->msr |= FD_MSR_CMDBUSY | FD_MSR_RQM | FD_MSR_DIO;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set an error: unimplemented/unknown command */
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_unimplemented(FDCtrl *fdctrl, int direction)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2012-06-03 19:16:14 +02:00
|
|
|
qemu_log_mask(LOG_UNIMP, "fdc: unimplemented command 0x%02x\n",
|
|
|
|
fdctrl->fifo[0]);
|
2008-02-29 20:24:00 +01:00
|
|
|
fdctrl->fifo[0] = FD_SR0_INVCMD;
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
2012-06-22 12:33:54 +02:00
|
|
|
/* Seek to next sector
|
|
|
|
* returns 0 when end of track reached (for DBL_SIDES on head 1)
|
|
|
|
* otherwise returns 1
|
|
|
|
*/
|
2010-02-07 10:01:18 +01:00
|
|
|
static int fdctrl_seek_to_next_sect(FDCtrl *fdctrl, FDrive *cur_drv)
|
2008-04-29 18:13:36 +02:00
|
|
|
{
|
|
|
|
FLOPPY_DPRINTF("seek to next sector (%d %02x %02x => %d)\n",
|
|
|
|
cur_drv->head, cur_drv->track, cur_drv->sect,
|
|
|
|
fd_sector(cur_drv));
|
|
|
|
/* XXX: cur_drv->sect >= cur_drv->last_sect should be an
|
|
|
|
error in fact */
|
2012-06-22 12:33:54 +02:00
|
|
|
uint8_t new_head = cur_drv->head;
|
|
|
|
uint8_t new_track = cur_drv->track;
|
|
|
|
uint8_t new_sect = cur_drv->sect;
|
|
|
|
|
|
|
|
int ret = 1;
|
|
|
|
|
|
|
|
if (new_sect >= cur_drv->last_sect ||
|
|
|
|
new_sect == fdctrl->eot) {
|
|
|
|
new_sect = 1;
|
2008-04-29 18:13:36 +02:00
|
|
|
if (FD_MULTI_TRACK(fdctrl->data_state)) {
|
2012-06-22 12:33:54 +02:00
|
|
|
if (new_head == 0 &&
|
2008-04-29 18:13:36 +02:00
|
|
|
(cur_drv->flags & FDISK_DBL_SIDES) != 0) {
|
2012-06-22 12:33:54 +02:00
|
|
|
new_head = 1;
|
2008-04-29 18:13:36 +02:00
|
|
|
} else {
|
2012-06-22 12:33:54 +02:00
|
|
|
new_head = 0;
|
|
|
|
new_track++;
|
2012-09-20 22:50:17 +02:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
2012-06-22 12:33:54 +02:00
|
|
|
if ((cur_drv->flags & FDISK_DBL_SIDES) == 0) {
|
|
|
|
ret = 0;
|
|
|
|
}
|
2008-04-29 18:13:36 +02:00
|
|
|
}
|
|
|
|
} else {
|
2012-09-20 22:50:17 +02:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
2012-06-22 12:33:54 +02:00
|
|
|
new_track++;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
if (ret == 1) {
|
|
|
|
FLOPPY_DPRINTF("seek to next track (%d %02x %02x => %d)\n",
|
|
|
|
new_head, new_track, new_sect, fd_sector(cur_drv));
|
2008-04-29 18:13:36 +02:00
|
|
|
}
|
|
|
|
} else {
|
2012-06-22 12:33:54 +02:00
|
|
|
new_sect++;
|
2008-04-29 18:13:36 +02:00
|
|
|
}
|
2012-06-22 12:33:54 +02:00
|
|
|
fd_seek(cur_drv, new_head, new_track, new_sect, 1);
|
|
|
|
return ret;
|
2008-04-29 18:13:36 +02:00
|
|
|
}
|
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Callback for transfer end (stop or abort) */
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_stop_transfer(FDCtrl *fdctrl, uint8_t status0,
|
|
|
|
uint8_t status1, uint8_t status2)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv;
|
2004-03-20 00:05:34 +01:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
2012-09-20 23:07:53 +02:00
|
|
|
|
|
|
|
fdctrl->status0 &= ~(FD_SR0_DS0 | FD_SR0_DS1 | FD_SR0_HEAD);
|
|
|
|
fdctrl->status0 |= GET_CUR_DRV(fdctrl);
|
|
|
|
if (cur_drv->head) {
|
|
|
|
fdctrl->status0 |= FD_SR0_HEAD;
|
|
|
|
}
|
|
|
|
fdctrl->status0 |= status0;
|
2012-06-22 12:33:55 +02:00
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
FLOPPY_DPRINTF("transfer status: %02x %02x %02x (%02x)\n",
|
2012-06-22 12:33:55 +02:00
|
|
|
status0, status1, status2, fdctrl->status0);
|
|
|
|
fdctrl->fifo[0] = fdctrl->status0;
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->fifo[1] = status1;
|
|
|
|
fdctrl->fifo[2] = status2;
|
|
|
|
fdctrl->fifo[3] = cur_drv->track;
|
|
|
|
fdctrl->fifo[4] = cur_drv->head;
|
|
|
|
fdctrl->fifo[5] = cur_drv->sect;
|
|
|
|
fdctrl->fifo[6] = FD_SECTOR_SC;
|
|
|
|
fdctrl->data_dir = FD_DIR_READ;
|
2018-11-11 10:40:23 +01:00
|
|
|
if (fdctrl->dma_chann != -1 && !(fdctrl->msr & FD_MSR_NONDMA)) {
|
2016-02-03 17:28:58 +01:00
|
|
|
IsaDmaClass *k = ISADMA_GET_CLASS(fdctrl->dma);
|
|
|
|
k->release_DREQ(fdctrl->dma, fdctrl->dma_chann);
|
2004-05-08 15:14:18 +02:00
|
|
|
}
|
2008-04-29 18:16:30 +02:00
|
|
|
fdctrl->msr |= FD_MSR_RQM | FD_MSR_DIO;
|
2008-04-29 18:15:12 +02:00
|
|
|
fdctrl->msr &= ~FD_MSR_NONDMA;
|
2012-09-04 01:46:54 +02:00
|
|
|
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 7);
|
2012-08-19 10:21:14 +02:00
|
|
|
fdctrl_raise_irq(fdctrl);
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare a data transfer (either DMA or FIFO) */
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_start_transfer(FDCtrl *fdctrl, int direction)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv;
|
2004-01-05 01:09:06 +01:00
|
|
|
uint8_t kh, kt, ks;
|
|
|
|
|
2008-04-29 18:18:58 +02:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2004-03-20 00:05:34 +01:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
kt = fdctrl->fifo[2];
|
|
|
|
kh = fdctrl->fifo[3];
|
|
|
|
ks = fdctrl->fifo[4];
|
2004-10-09 18:44:33 +02:00
|
|
|
FLOPPY_DPRINTF("Start transfer at %d %d %02x %02x (%d)\n",
|
2008-04-29 18:18:58 +02:00
|
|
|
GET_CUR_DRV(fdctrl), kh, kt, ks,
|
2012-02-06 22:29:02 +01:00
|
|
|
fd_sector_calc(kh, kt, ks, cur_drv->last_sect,
|
|
|
|
NUM_SIDES(cur_drv)));
|
2008-04-29 18:17:08 +02:00
|
|
|
switch (fd_seek(cur_drv, kh, kt, ks, fdctrl->config & FD_CONFIG_EIS)) {
|
2004-01-05 01:09:06 +01:00
|
|
|
case 2:
|
|
|
|
/* sect too big */
|
2008-02-29 20:24:00 +01:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
2004-01-05 01:09:06 +01:00
|
|
|
return;
|
|
|
|
case 3:
|
|
|
|
/* track too big */
|
2008-04-29 18:17:08 +02:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_EC, 0x00);
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
2004-01-05 01:09:06 +01:00
|
|
|
return;
|
|
|
|
case 4:
|
|
|
|
/* No seek enabled */
|
2008-02-29 20:24:00 +01:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
2004-01-05 01:09:06 +01:00
|
|
|
return;
|
|
|
|
case 1:
|
2012-09-20 23:01:58 +02:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
2004-01-05 01:09:06 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-04-29 18:16:30 +02:00
|
|
|
|
2012-02-06 22:29:10 +01:00
|
|
|
/* Check the data rate. If the programmed data rate does not match
|
|
|
|
* the currently inserted medium, the operation has to fail. */
|
2021-02-03 18:18:30 +01:00
|
|
|
if ((fdctrl->dsr & FD_DSR_DRATEMASK) != cur_drv->media_rate) {
|
2012-02-06 22:29:10 +01:00
|
|
|
FLOPPY_DPRINTF("data rate mismatch (fdc=%d, media=%d)\n",
|
|
|
|
fdctrl->dsr & FD_DSR_DRATEMASK, cur_drv->media_rate);
|
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_MA, 0x00);
|
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Set the FIFO state */
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->data_dir = direction;
|
|
|
|
fdctrl->data_pos = 0;
|
2012-08-19 22:04:43 +02:00
|
|
|
assert(fdctrl->msr & FD_MSR_CMDBUSY);
|
2004-03-20 00:05:34 +01:00
|
|
|
if (fdctrl->fifo[0] & 0x80)
|
|
|
|
fdctrl->data_state |= FD_STATE_MULTI;
|
|
|
|
else
|
|
|
|
fdctrl->data_state &= ~FD_STATE_MULTI;
|
2012-08-20 13:50:34 +02:00
|
|
|
if (fdctrl->fifo[5] == 0) {
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->data_len = fdctrl->fifo[8];
|
|
|
|
} else {
|
2007-11-05 04:11:37 +01:00
|
|
|
int tmp;
|
2006-12-11 00:07:39 +01:00
|
|
|
fdctrl->data_len = 128 << (fdctrl->fifo[5] > 7 ? 7 : fdctrl->fifo[5]);
|
2008-05-01 21:05:12 +02:00
|
|
|
tmp = (fdctrl->fifo[6] - ks + 1);
|
2004-03-20 00:05:34 +01:00
|
|
|
if (fdctrl->fifo[0] & 0x80)
|
2008-05-01 21:05:12 +02:00
|
|
|
tmp += fdctrl->fifo[6];
|
2007-11-05 04:11:37 +01:00
|
|
|
fdctrl->data_len *= tmp;
|
2004-03-20 00:05:34 +01:00
|
|
|
}
|
2004-10-08 01:10:29 +02:00
|
|
|
fdctrl->eot = fdctrl->fifo[6];
|
2008-04-29 18:15:12 +02:00
|
|
|
if (fdctrl->dor & FD_DOR_DMAEN) {
|
2019-11-01 17:55:13 +01:00
|
|
|
/* DMA transfer is enabled. */
|
2016-02-03 17:28:58 +01:00
|
|
|
IsaDmaClass *k = ISADMA_GET_CLASS(fdctrl->dma);
|
2019-11-01 17:55:13 +01:00
|
|
|
|
|
|
|
FLOPPY_DPRINTF("direction=%d (%d - %d)\n",
|
|
|
|
direction, (128 << fdctrl->fifo[5]) *
|
2007-11-05 04:11:37 +01:00
|
|
|
(cur_drv->last_sect - ks + 1), fdctrl->data_len);
|
2019-11-01 17:55:13 +01:00
|
|
|
|
|
|
|
/* No access is allowed until DMA transfer has completed */
|
|
|
|
fdctrl->msr &= ~FD_MSR_RQM;
|
|
|
|
if (direction != FD_DIR_VERIFY) {
|
|
|
|
/*
|
|
|
|
* Now, we just have to wait for the DMA controller to
|
|
|
|
* recall us...
|
|
|
|
*/
|
|
|
|
k->hold_DREQ(fdctrl->dma, fdctrl->dma_chann);
|
|
|
|
k->schedule(fdctrl->dma);
|
2004-03-20 00:05:34 +01:00
|
|
|
} else {
|
2019-11-01 17:55:13 +01:00
|
|
|
/* Start transfer */
|
|
|
|
fdctrl_transfer_handler(fdctrl, fdctrl->dma_chann, 0,
|
|
|
|
fdctrl->data_len);
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
2019-11-01 17:55:13 +01:00
|
|
|
return;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
FLOPPY_DPRINTF("start non-DMA transfer\n");
|
2015-05-21 15:19:37 +02:00
|
|
|
fdctrl->msr |= FD_MSR_NONDMA | FD_MSR_RQM;
|
2008-04-29 18:16:30 +02:00
|
|
|
if (direction != FD_DIR_WRITE)
|
|
|
|
fdctrl->msr |= FD_MSR_DIO;
|
2004-01-05 01:09:06 +01:00
|
|
|
/* IO based transfer: calculate len */
|
2012-08-19 10:21:14 +02:00
|
|
|
fdctrl_raise_irq(fdctrl);
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare a transfer of deleted data */
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_start_transfer_del(FDCtrl *fdctrl, int direction)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2012-06-03 19:16:14 +02:00
|
|
|
qemu_log_mask(LOG_UNIMP, "fdctrl_start_transfer_del() unimplemented\n");
|
2008-04-29 18:17:08 +02:00
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/* We don't handle deleted data,
|
|
|
|
* so we don't return *ANYTHING*
|
|
|
|
*/
|
2008-02-29 20:24:00 +01:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* handlers for DMA transfers */
|
2004-11-07 19:04:02 +01:00
|
|
|
static int fdctrl_transfer_handler (void *opaque, int nchan,
|
|
|
|
int dma_pos, int dma_len)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrl *fdctrl;
|
|
|
|
FDrive *cur_drv;
|
2004-03-20 00:05:34 +01:00
|
|
|
int len, start_pos, rel_pos;
|
2004-01-05 01:09:06 +01:00
|
|
|
uint8_t status0 = 0x00, status1 = 0x00, status2 = 0x00;
|
2016-02-03 17:28:58 +01:00
|
|
|
IsaDmaClass *k;
|
2004-01-05 01:09:06 +01:00
|
|
|
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl = opaque;
|
2008-04-29 18:16:30 +02:00
|
|
|
if (fdctrl->msr & FD_MSR_RQM) {
|
2004-01-05 01:09:06 +01:00
|
|
|
FLOPPY_DPRINTF("Not in DMA transfer mode !\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2016-02-03 17:28:58 +01:00
|
|
|
k = ISADMA_GET_CLASS(fdctrl->dma);
|
2004-03-20 00:05:34 +01:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
if (fdctrl->data_dir == FD_DIR_SCANE || fdctrl->data_dir == FD_DIR_SCANL ||
|
|
|
|
fdctrl->data_dir == FD_DIR_SCANH)
|
2008-04-29 18:17:08 +02:00
|
|
|
status2 = FD_SR2_SNS;
|
2004-11-07 19:04:02 +01:00
|
|
|
if (dma_len > fdctrl->data_len)
|
|
|
|
dma_len = fdctrl->data_len;
|
2014-10-07 13:59:18 +02:00
|
|
|
if (cur_drv->blk == NULL) {
|
2007-11-05 04:11:37 +01:00
|
|
|
if (fdctrl->data_dir == FD_DIR_WRITE)
|
2008-02-29 20:24:00 +01:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
|
2007-11-05 04:11:37 +01:00
|
|
|
else
|
2008-02-29 20:24:00 +01:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
|
2007-11-05 04:11:37 +01:00
|
|
|
len = 0;
|
2004-10-08 01:10:29 +02:00
|
|
|
goto transfer_error;
|
|
|
|
}
|
2004-03-20 00:05:34 +01:00
|
|
|
rel_pos = fdctrl->data_pos % FD_SECTOR_LEN;
|
2004-11-07 19:04:02 +01:00
|
|
|
for (start_pos = fdctrl->data_pos; fdctrl->data_pos < dma_len;) {
|
|
|
|
len = dma_len - fdctrl->data_pos;
|
2004-03-20 00:05:34 +01:00
|
|
|
if (len + rel_pos > FD_SECTOR_LEN)
|
|
|
|
len = FD_SECTOR_LEN - rel_pos;
|
2005-03-13 10:43:36 +01:00
|
|
|
FLOPPY_DPRINTF("copy %d bytes (%d %d %d) %d pos %d %02x "
|
|
|
|
"(%d-0x%08x 0x%08x)\n", len, dma_len, fdctrl->data_pos,
|
2008-04-29 18:18:58 +02:00
|
|
|
fdctrl->data_len, GET_CUR_DRV(fdctrl), cur_drv->head,
|
2004-03-20 00:05:34 +01:00
|
|
|
cur_drv->track, cur_drv->sect, fd_sector(cur_drv),
|
2008-02-29 20:24:00 +01:00
|
|
|
fd_sector(cur_drv) * FD_SECTOR_LEN);
|
2004-03-20 00:05:34 +01:00
|
|
|
if (fdctrl->data_dir != FD_DIR_WRITE ||
|
2007-11-05 04:11:37 +01:00
|
|
|
len < FD_SECTOR_LEN || rel_pos != 0) {
|
2004-03-20 00:05:34 +01:00
|
|
|
/* READ & SCAN commands and realign to a sector for WRITE */
|
2016-05-06 18:26:35 +02:00
|
|
|
if (blk_pread(cur_drv->blk, fd_offset(cur_drv),
|
|
|
|
fdctrl->fifo, BDRV_SECTOR_SIZE) < 0) {
|
2004-01-05 01:09:06 +01:00
|
|
|
FLOPPY_DPRINTF("Floppy: error getting sector %d\n",
|
|
|
|
fd_sector(cur_drv));
|
|
|
|
/* Sure, image size is too small... */
|
2004-03-20 00:05:34 +01:00
|
|
|
memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
2004-10-08 01:10:29 +02:00
|
|
|
}
|
2007-11-05 04:11:37 +01:00
|
|
|
switch (fdctrl->data_dir) {
|
|
|
|
case FD_DIR_READ:
|
|
|
|
/* READ commands */
|
2016-02-03 17:28:58 +01:00
|
|
|
k->write_memory(fdctrl->dma, nchan, fdctrl->fifo + rel_pos,
|
|
|
|
fdctrl->data_pos, len);
|
2007-11-05 04:11:37 +01:00
|
|
|
break;
|
|
|
|
case FD_DIR_WRITE:
|
2004-03-20 00:05:34 +01:00
|
|
|
/* WRITE commands */
|
2012-02-06 22:29:05 +01:00
|
|
|
if (cur_drv->ro) {
|
|
|
|
/* Handle readonly medium early, no need to do DMA, touch the
|
|
|
|
* LED or attempt any writes. A real floppy doesn't attempt
|
|
|
|
* to write to readonly media either. */
|
|
|
|
fdctrl_stop_transfer(fdctrl,
|
|
|
|
FD_SR0_ABNTERM | FD_SR0_SEEK, FD_SR1_NW,
|
|
|
|
0x00);
|
|
|
|
goto transfer_error;
|
|
|
|
}
|
|
|
|
|
2016-02-03 17:28:58 +01:00
|
|
|
k->read_memory(fdctrl->dma, nchan, fdctrl->fifo + rel_pos,
|
|
|
|
fdctrl->data_pos, len);
|
2016-05-06 18:26:35 +02:00
|
|
|
if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv),
|
|
|
|
fdctrl->fifo, BDRV_SECTOR_SIZE, 0) < 0) {
|
2012-06-03 19:16:14 +02:00
|
|
|
FLOPPY_DPRINTF("error writing sector %d\n",
|
|
|
|
fd_sector(cur_drv));
|
2008-02-29 20:24:00 +01:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
|
2004-03-20 00:05:34 +01:00
|
|
|
goto transfer_error;
|
2004-10-08 01:10:29 +02:00
|
|
|
}
|
2007-11-05 04:11:37 +01:00
|
|
|
break;
|
2012-09-18 23:04:10 +02:00
|
|
|
case FD_DIR_VERIFY:
|
|
|
|
/* VERIFY commands */
|
|
|
|
break;
|
2007-11-05 04:11:37 +01:00
|
|
|
default:
|
|
|
|
/* SCAN commands */
|
2004-03-20 00:05:34 +01:00
|
|
|
{
|
2007-11-05 04:11:37 +01:00
|
|
|
uint8_t tmpbuf[FD_SECTOR_LEN];
|
2004-03-20 00:05:34 +01:00
|
|
|
int ret;
|
2016-02-03 17:28:58 +01:00
|
|
|
k->read_memory(fdctrl->dma, nchan, tmpbuf, fdctrl->data_pos,
|
|
|
|
len);
|
2004-03-20 00:05:34 +01:00
|
|
|
ret = memcmp(tmpbuf, fdctrl->fifo + rel_pos, len);
|
2004-01-05 01:09:06 +01:00
|
|
|
if (ret == 0) {
|
2008-04-29 18:17:08 +02:00
|
|
|
status2 = FD_SR2_SEH;
|
2004-01-05 01:09:06 +01:00
|
|
|
goto end_transfer;
|
|
|
|
}
|
2004-03-20 00:05:34 +01:00
|
|
|
if ((ret < 0 && fdctrl->data_dir == FD_DIR_SCANL) ||
|
|
|
|
(ret > 0 && fdctrl->data_dir == FD_DIR_SCANH)) {
|
2004-01-05 01:09:06 +01:00
|
|
|
status2 = 0x00;
|
|
|
|
goto end_transfer;
|
|
|
|
}
|
|
|
|
}
|
2007-11-05 04:11:37 +01:00
|
|
|
break;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
2007-11-05 04:11:37 +01:00
|
|
|
fdctrl->data_pos += len;
|
|
|
|
rel_pos = fdctrl->data_pos % FD_SECTOR_LEN;
|
2004-03-20 00:05:34 +01:00
|
|
|
if (rel_pos == 0) {
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Seek to next sector */
|
2008-04-29 18:13:36 +02:00
|
|
|
if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv))
|
|
|
|
break;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
}
|
2007-11-05 04:11:37 +01:00
|
|
|
end_transfer:
|
2004-03-20 00:05:34 +01:00
|
|
|
len = fdctrl->data_pos - start_pos;
|
|
|
|
FLOPPY_DPRINTF("end transfer %d %d %d\n",
|
2007-11-05 04:11:37 +01:00
|
|
|
fdctrl->data_pos, len, fdctrl->data_len);
|
2004-03-20 00:05:34 +01:00
|
|
|
if (fdctrl->data_dir == FD_DIR_SCANE ||
|
|
|
|
fdctrl->data_dir == FD_DIR_SCANL ||
|
|
|
|
fdctrl->data_dir == FD_DIR_SCANH)
|
2008-04-29 18:17:08 +02:00
|
|
|
status2 = FD_SR2_SEH;
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->data_len -= len;
|
2004-10-08 01:10:29 +02:00
|
|
|
fdctrl_stop_transfer(fdctrl, status0, status1, status2);
|
2007-11-05 04:11:37 +01:00
|
|
|
transfer_error:
|
2004-01-05 01:09:06 +01:00
|
|
|
|
2004-03-20 00:05:34 +01:00
|
|
|
return len;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Data register : 0x05 */
|
2010-02-07 10:01:18 +01:00
|
|
|
static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv;
|
2004-01-05 01:09:06 +01:00
|
|
|
uint32_t retval = 0;
|
2015-05-06 09:48:59 +02:00
|
|
|
uint32_t pos;
|
2004-01-05 01:09:06 +01:00
|
|
|
|
2004-03-20 00:05:34 +01:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
2008-04-29 18:16:30 +02:00
|
|
|
fdctrl->dsr &= ~FD_DSR_PWRDOWN;
|
|
|
|
if (!(fdctrl->msr & FD_MSR_RQM) || !(fdctrl->msr & FD_MSR_DIO)) {
|
2012-06-03 19:16:14 +02:00
|
|
|
FLOPPY_DPRINTF("error: controller not ready for reading\n");
|
2004-01-05 01:09:06 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2015-05-21 15:19:36 +02:00
|
|
|
|
|
|
|
/* If data_len spans multiple sectors, the current position in the FIFO
|
|
|
|
* wraps around while fdctrl->data_pos is the real position in the whole
|
|
|
|
* request. */
|
2004-03-20 00:05:34 +01:00
|
|
|
pos = fdctrl->data_pos;
|
2015-05-06 09:48:59 +02:00
|
|
|
pos %= FD_SECTOR_LEN;
|
2015-05-21 15:19:36 +02:00
|
|
|
|
|
|
|
switch (fdctrl->phase) {
|
|
|
|
case FD_PHASE_EXECUTION:
|
|
|
|
assert(fdctrl->msr & FD_MSR_NONDMA);
|
2004-01-05 01:09:06 +01:00
|
|
|
if (pos == 0) {
|
2008-04-29 18:13:36 +02:00
|
|
|
if (fdctrl->data_pos != 0)
|
|
|
|
if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
|
|
|
|
FLOPPY_DPRINTF("error seeking to next sector %d\n",
|
|
|
|
fd_sector(cur_drv));
|
|
|
|
return 0;
|
|
|
|
}
|
2016-05-06 18:26:35 +02:00
|
|
|
if (blk_pread(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
|
|
|
|
BDRV_SECTOR_SIZE)
|
2014-10-07 13:59:18 +02:00
|
|
|
< 0) {
|
2008-04-29 18:17:08 +02:00
|
|
|
FLOPPY_DPRINTF("error getting sector %d\n",
|
|
|
|
fd_sector(cur_drv));
|
|
|
|
/* Sure, image size is too small... */
|
|
|
|
memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
|
|
|
|
}
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
2015-05-21 15:19:36 +02:00
|
|
|
|
|
|
|
if (++fdctrl->data_pos == fdctrl->data_len) {
|
2015-05-21 15:19:37 +02:00
|
|
|
fdctrl->msr &= ~FD_MSR_RQM;
|
2012-09-20 22:50:17 +02:00
|
|
|
fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
|
2015-05-21 15:19:36 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FD_PHASE_RESULT:
|
|
|
|
assert(!(fdctrl->msr & FD_MSR_NONDMA));
|
|
|
|
if (++fdctrl->data_pos == fdctrl->data_len) {
|
2015-05-21 15:19:37 +02:00
|
|
|
fdctrl->msr &= ~FD_MSR_RQM;
|
2015-05-21 15:19:31 +02:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2004-05-08 15:14:18 +02:00
|
|
|
fdctrl_reset_irq(fdctrl);
|
|
|
|
}
|
2015-05-21 15:19:36 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FD_PHASE_COMMAND:
|
|
|
|
default:
|
|
|
|
abort();
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
2015-05-21 15:19:36 +02:00
|
|
|
|
|
|
|
retval = fdctrl->fifo[pos];
|
2004-01-05 01:09:06 +01:00
|
|
|
FLOPPY_DPRINTF("data register: 0x%02x\n", retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_format_sector(FDCtrl *fdctrl)
|
2004-01-05 01:09:06 +01:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv;
|
2004-03-20 00:05:34 +01:00
|
|
|
uint8_t kh, kt, ks;
|
2004-01-05 01:09:06 +01:00
|
|
|
|
2008-04-29 18:18:58 +02:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2004-03-20 00:05:34 +01:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
kt = fdctrl->fifo[6];
|
|
|
|
kh = fdctrl->fifo[7];
|
|
|
|
ks = fdctrl->fifo[8];
|
|
|
|
FLOPPY_DPRINTF("format sector at %d %d %02x %02x (%d)\n",
|
2008-04-29 18:18:58 +02:00
|
|
|
GET_CUR_DRV(fdctrl), kh, kt, ks,
|
2012-02-06 22:29:02 +01:00
|
|
|
fd_sector_calc(kh, kt, ks, cur_drv->last_sect,
|
|
|
|
NUM_SIDES(cur_drv)));
|
2008-02-29 20:24:00 +01:00
|
|
|
switch (fd_seek(cur_drv, kh, kt, ks, fdctrl->config & FD_CONFIG_EIS)) {
|
2004-03-20 00:05:34 +01:00
|
|
|
case 2:
|
|
|
|
/* sect too big */
|
2008-02-29 20:24:00 +01:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
|
|
|
return;
|
|
|
|
case 3:
|
|
|
|
/* track too big */
|
2008-04-29 18:17:08 +02:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_EC, 0x00);
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
|
|
|
return;
|
|
|
|
case 4:
|
|
|
|
/* No seek enabled */
|
2008-02-29 20:24:00 +01:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
|
|
|
return;
|
|
|
|
case 1:
|
2012-09-20 23:11:58 +02:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
2004-03-20 00:05:34 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
|
2014-10-07 13:59:18 +02:00
|
|
|
if (cur_drv->blk == NULL ||
|
2016-05-06 18:26:35 +02:00
|
|
|
blk_pwrite(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
|
|
|
|
BDRV_SECTOR_SIZE, 0) < 0) {
|
2012-06-03 19:16:14 +02:00
|
|
|
FLOPPY_DPRINTF("error formatting sector %d\n", fd_sector(cur_drv));
|
2008-02-29 20:24:00 +01:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
|
2004-03-20 00:05:34 +01:00
|
|
|
} else {
|
2007-11-05 04:11:37 +01:00
|
|
|
if (cur_drv->sect == cur_drv->last_sect) {
|
|
|
|
fdctrl->data_state &= ~FD_STATE_FORMAT;
|
|
|
|
/* Last sector done */
|
2012-09-20 23:11:58 +02:00
|
|
|
fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
|
2007-11-05 04:11:37 +01:00
|
|
|
} else {
|
|
|
|
/* More to do */
|
|
|
|
fdctrl->data_pos = 0;
|
|
|
|
fdctrl->data_len = 4;
|
|
|
|
}
|
2004-03-20 00:05:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_lock(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
|
|
|
fdctrl->lock = (fdctrl->fifo[0] & 0x80) ? 1 : 0;
|
|
|
|
fdctrl->fifo[0] = fdctrl->lock << 4;
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_dumpreg(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
|
|
|
|
/* Drives position */
|
|
|
|
fdctrl->fifo[0] = drv0(fdctrl)->track;
|
|
|
|
fdctrl->fifo[1] = drv1(fdctrl)->track;
|
2008-04-29 18:18:26 +02:00
|
|
|
#if MAX_FD == 4
|
|
|
|
fdctrl->fifo[2] = drv2(fdctrl)->track;
|
|
|
|
fdctrl->fifo[3] = drv3(fdctrl)->track;
|
|
|
|
#else
|
2008-04-08 19:18:53 +02:00
|
|
|
fdctrl->fifo[2] = 0;
|
|
|
|
fdctrl->fifo[3] = 0;
|
2008-04-29 18:18:26 +02:00
|
|
|
#endif
|
2008-04-08 19:18:53 +02:00
|
|
|
/* timers */
|
|
|
|
fdctrl->fifo[4] = fdctrl->timer0;
|
2008-04-29 18:15:12 +02:00
|
|
|
fdctrl->fifo[5] = (fdctrl->timer1 << 1) | (fdctrl->dor & FD_DOR_DMAEN ? 1 : 0);
|
2008-04-08 19:18:53 +02:00
|
|
|
fdctrl->fifo[6] = cur_drv->last_sect;
|
|
|
|
fdctrl->fifo[7] = (fdctrl->lock << 7) |
|
|
|
|
(cur_drv->perpendicular << 2);
|
|
|
|
fdctrl->fifo[8] = fdctrl->config;
|
|
|
|
fdctrl->fifo[9] = fdctrl->precomp_trk;
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 10);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_version(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
|
|
|
/* Controller's version */
|
|
|
|
fdctrl->fifo[0] = fdctrl->version;
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_partid(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
|
|
|
fdctrl->fifo[0] = 0x41; /* Stepping 1 */
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_restore(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
|
|
|
|
/* Drives position */
|
|
|
|
drv0(fdctrl)->track = fdctrl->fifo[3];
|
|
|
|
drv1(fdctrl)->track = fdctrl->fifo[4];
|
2008-04-29 18:18:26 +02:00
|
|
|
#if MAX_FD == 4
|
|
|
|
drv2(fdctrl)->track = fdctrl->fifo[5];
|
|
|
|
drv3(fdctrl)->track = fdctrl->fifo[6];
|
|
|
|
#endif
|
2008-04-08 19:18:53 +02:00
|
|
|
/* timers */
|
|
|
|
fdctrl->timer0 = fdctrl->fifo[7];
|
|
|
|
fdctrl->timer1 = fdctrl->fifo[8];
|
|
|
|
cur_drv->last_sect = fdctrl->fifo[9];
|
|
|
|
fdctrl->lock = fdctrl->fifo[10] >> 7;
|
|
|
|
cur_drv->perpendicular = (fdctrl->fifo[10] >> 2) & 0xF;
|
|
|
|
fdctrl->config = fdctrl->fifo[11];
|
|
|
|
fdctrl->precomp_trk = fdctrl->fifo[12];
|
|
|
|
fdctrl->pwrd = fdctrl->fifo[13];
|
2015-05-21 15:19:31 +02:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_save(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
|
|
|
|
fdctrl->fifo[0] = 0;
|
|
|
|
fdctrl->fifo[1] = 0;
|
|
|
|
/* Drives position */
|
|
|
|
fdctrl->fifo[2] = drv0(fdctrl)->track;
|
|
|
|
fdctrl->fifo[3] = drv1(fdctrl)->track;
|
2008-04-29 18:18:26 +02:00
|
|
|
#if MAX_FD == 4
|
|
|
|
fdctrl->fifo[4] = drv2(fdctrl)->track;
|
|
|
|
fdctrl->fifo[5] = drv3(fdctrl)->track;
|
|
|
|
#else
|
2008-04-08 19:18:53 +02:00
|
|
|
fdctrl->fifo[4] = 0;
|
|
|
|
fdctrl->fifo[5] = 0;
|
2008-04-29 18:18:26 +02:00
|
|
|
#endif
|
2008-04-08 19:18:53 +02:00
|
|
|
/* timers */
|
|
|
|
fdctrl->fifo[6] = fdctrl->timer0;
|
|
|
|
fdctrl->fifo[7] = fdctrl->timer1;
|
|
|
|
fdctrl->fifo[8] = cur_drv->last_sect;
|
|
|
|
fdctrl->fifo[9] = (fdctrl->lock << 7) |
|
|
|
|
(cur_drv->perpendicular << 2);
|
|
|
|
fdctrl->fifo[10] = fdctrl->config;
|
|
|
|
fdctrl->fifo[11] = fdctrl->precomp_trk;
|
|
|
|
fdctrl->fifo[12] = fdctrl->pwrd;
|
|
|
|
fdctrl->fifo[13] = 0;
|
|
|
|
fdctrl->fifo[14] = 0;
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 15);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_readid(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
|
|
|
|
cur_drv->head = (fdctrl->fifo[1] >> 2) & 1;
|
2016-03-21 17:02:30 +01:00
|
|
|
timer_mod(fdctrl->result_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
|
|
|
|
(NANOSECONDS_PER_SECOND / 50));
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_format_track(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv;
|
2008-04-08 19:18:53 +02:00
|
|
|
|
2008-04-29 18:18:58 +02:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2008-04-08 19:18:53 +02:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
fdctrl->data_state |= FD_STATE_FORMAT;
|
|
|
|
if (fdctrl->fifo[0] & 0x80)
|
|
|
|
fdctrl->data_state |= FD_STATE_MULTI;
|
|
|
|
else
|
|
|
|
fdctrl->data_state &= ~FD_STATE_MULTI;
|
|
|
|
cur_drv->bps =
|
|
|
|
fdctrl->fifo[2] > 7 ? 16384 : 128 << fdctrl->fifo[2];
|
|
|
|
#if 0
|
|
|
|
cur_drv->last_sect =
|
|
|
|
cur_drv->flags & FDISK_DBL_SIDES ? fdctrl->fifo[3] :
|
|
|
|
fdctrl->fifo[3] / 2;
|
|
|
|
#else
|
|
|
|
cur_drv->last_sect = fdctrl->fifo[3];
|
|
|
|
#endif
|
|
|
|
/* TODO: implement format using DMA expected by the Bochs BIOS
|
|
|
|
* and Linux fdformat (read 3 bytes per sector via DMA and fill
|
|
|
|
* the sector with the specified fill byte
|
|
|
|
*/
|
|
|
|
fdctrl->data_state &= ~FD_STATE_FORMAT;
|
|
|
|
fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
|
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_specify(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
|
|
|
fdctrl->timer0 = (fdctrl->fifo[1] >> 4) & 0xF;
|
|
|
|
fdctrl->timer1 = fdctrl->fifo[2] >> 1;
|
2008-04-29 18:15:12 +02:00
|
|
|
if (fdctrl->fifo[2] & 1)
|
|
|
|
fdctrl->dor &= ~FD_DOR_DMAEN;
|
|
|
|
else
|
|
|
|
fdctrl->dor |= FD_DOR_DMAEN;
|
2008-04-08 19:18:53 +02:00
|
|
|
/* No result back */
|
2015-05-21 15:19:31 +02:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_sense_drive_status(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv;
|
2008-04-08 19:18:53 +02:00
|
|
|
|
2008-04-29 18:18:58 +02:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2008-04-08 19:18:53 +02:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
cur_drv->head = (fdctrl->fifo[1] >> 2) & 1;
|
|
|
|
/* 1 Byte status back */
|
|
|
|
fdctrl->fifo[0] = (cur_drv->ro << 6) |
|
|
|
|
(cur_drv->track == 0 ? 0x10 : 0x00) |
|
|
|
|
(cur_drv->head << 2) |
|
2008-04-29 18:18:58 +02:00
|
|
|
GET_CUR_DRV(fdctrl) |
|
2008-04-08 19:18:53 +02:00
|
|
|
0x28;
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_recalibrate(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv;
|
2008-04-08 19:18:53 +02:00
|
|
|
|
2008-04-29 18:18:58 +02:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2008-04-08 19:18:53 +02:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
fd_recalibrate(cur_drv);
|
2015-05-21 15:19:31 +02:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
/* Raise Interrupt */
|
2012-08-19 10:21:14 +02:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
|
|
|
fdctrl_raise_irq(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_sense_interrupt_status(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
|
2012-06-22 12:33:55 +02:00
|
|
|
if (fdctrl->reset_sensei > 0) {
|
2009-01-24 13:09:52 +01:00
|
|
|
fdctrl->fifo[0] =
|
|
|
|
FD_SR0_RDYCHG + FD_RESET_SENSEI_COUNT - fdctrl->reset_sensei;
|
|
|
|
fdctrl->reset_sensei--;
|
2012-06-22 12:33:55 +02:00
|
|
|
} else if (!(fdctrl->sra & FD_SRA_INTPEND)) {
|
|
|
|
fdctrl->fifo[0] = FD_SR0_INVCMD;
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2012-06-22 12:33:55 +02:00
|
|
|
return;
|
2009-01-24 13:09:52 +01:00
|
|
|
} else {
|
|
|
|
fdctrl->fifo[0] =
|
2012-06-22 12:33:55 +02:00
|
|
|
(fdctrl->status0 & ~(FD_SR0_HEAD | FD_SR0_DS1 | FD_SR0_DS0))
|
|
|
|
| GET_CUR_DRV(fdctrl);
|
2009-01-24 13:09:52 +01:00
|
|
|
}
|
|
|
|
|
2008-04-08 19:18:53 +02:00
|
|
|
fdctrl->fifo[1] = cur_drv->track;
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 2);
|
2008-04-08 19:18:53 +02:00
|
|
|
fdctrl_reset_irq(fdctrl);
|
2008-04-29 18:17:08 +02:00
|
|
|
fdctrl->status0 = FD_SR0_RDYCHG;
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_seek(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv;
|
2008-04-08 19:18:53 +02:00
|
|
|
|
2008-04-29 18:18:58 +02:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2008-04-08 19:18:53 +02:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
2015-05-21 15:19:31 +02:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2012-02-06 22:29:11 +01:00
|
|
|
/* The seek command just sends step pulses to the drive and doesn't care if
|
|
|
|
* there is a medium inserted of if it's banging the head against the drive.
|
|
|
|
*/
|
2012-06-22 12:33:54 +02:00
|
|
|
fd_seek(cur_drv, cur_drv->head, fdctrl->fifo[2], cur_drv->sect, 1);
|
2012-02-06 22:29:11 +01:00
|
|
|
/* Raise Interrupt */
|
2012-08-19 10:21:14 +02:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
|
|
|
fdctrl_raise_irq(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_perpendicular_mode(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
|
|
|
|
if (fdctrl->fifo[1] & 0x80)
|
|
|
|
cur_drv->perpendicular = fdctrl->fifo[1] & 0x7;
|
|
|
|
/* No result back */
|
2015-05-21 15:19:31 +02:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_configure(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
|
|
|
fdctrl->config = fdctrl->fifo[2];
|
|
|
|
fdctrl->precomp_trk = fdctrl->fifo[3];
|
|
|
|
/* No result back */
|
2015-05-21 15:19:31 +02:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_powerdown_mode(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
|
|
|
fdctrl->pwrd = fdctrl->fifo[1];
|
|
|
|
fdctrl->fifo[0] = fdctrl->fifo[1];
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_option(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
|
|
|
/* No result back */
|
2015-05-21 15:19:31 +02:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_handle_drive_specification_command(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2015-05-06 09:48:59 +02:00
|
|
|
uint32_t pos;
|
2008-04-08 19:18:53 +02:00
|
|
|
|
2015-05-06 09:48:59 +02:00
|
|
|
pos = fdctrl->data_pos - 1;
|
|
|
|
pos %= FD_SECTOR_LEN;
|
|
|
|
if (fdctrl->fifo[pos] & 0x80) {
|
2008-04-08 19:18:53 +02:00
|
|
|
/* Command parameters done */
|
2015-05-06 09:48:59 +02:00
|
|
|
if (fdctrl->fifo[pos] & 0x40) {
|
2008-04-08 19:18:53 +02:00
|
|
|
fdctrl->fifo[0] = fdctrl->fifo[1];
|
|
|
|
fdctrl->fifo[2] = 0;
|
|
|
|
fdctrl->fifo[3] = 0;
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 4);
|
2008-04-08 19:18:53 +02:00
|
|
|
} else {
|
2015-05-21 15:19:31 +02:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
} else if (fdctrl->data_len > 7) {
|
|
|
|
/* ERROR */
|
|
|
|
fdctrl->fifo[0] = 0x80 |
|
2008-04-29 18:18:58 +02:00
|
|
|
(cur_drv->head << 2) | GET_CUR_DRV(fdctrl);
|
2015-05-21 15:19:32 +02:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 15:48:26 +02:00
|
|
|
static void fdctrl_handle_relative_seek_in(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv;
|
2008-04-08 19:18:53 +02:00
|
|
|
|
2008-04-29 18:18:58 +02:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2008-04-08 19:18:53 +02:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
if (fdctrl->fifo[2] + cur_drv->track >= cur_drv->max_track) {
|
2012-06-22 12:33:54 +02:00
|
|
|
fd_seek(cur_drv, cur_drv->head, cur_drv->max_track - 1,
|
|
|
|
cur_drv->sect, 1);
|
2008-04-08 19:18:53 +02:00
|
|
|
} else {
|
2012-07-16 15:48:26 +02:00
|
|
|
fd_seek(cur_drv, cur_drv->head,
|
|
|
|
cur_drv->track + fdctrl->fifo[2], cur_drv->sect, 1);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
2015-05-21 15:19:31 +02:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-29 18:17:08 +02:00
|
|
|
/* Raise Interrupt */
|
2012-08-19 10:21:14 +02:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
|
|
|
fdctrl_raise_irq(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2012-07-16 15:48:26 +02:00
|
|
|
static void fdctrl_handle_relative_seek_out(FDCtrl *fdctrl, int direction)
|
2008-04-08 19:18:53 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv;
|
2008-04-08 19:18:53 +02:00
|
|
|
|
2008-04-29 18:18:58 +02:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2008-04-08 19:18:53 +02:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
if (fdctrl->fifo[2] > cur_drv->track) {
|
2012-06-22 12:33:54 +02:00
|
|
|
fd_seek(cur_drv, cur_drv->head, 0, cur_drv->sect, 1);
|
2008-04-08 19:18:53 +02:00
|
|
|
} else {
|
2012-07-16 15:48:26 +02:00
|
|
|
fd_seek(cur_drv, cur_drv->head,
|
|
|
|
cur_drv->track - fdctrl->fifo[2], cur_drv->sect, 1);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
2015-05-21 15:19:31 +02:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
/* Raise Interrupt */
|
2012-08-19 10:21:14 +02:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
|
|
|
fdctrl_raise_irq(fdctrl);
|
2008-04-08 19:18:53 +02:00
|
|
|
}
|
|
|
|
|
2015-05-21 15:19:33 +02:00
|
|
|
/*
|
|
|
|
* Handlers for the execution phase of each command
|
|
|
|
*/
|
2015-05-21 15:19:35 +02:00
|
|
|
typedef struct FDCtrlCommand {
|
2008-04-29 18:12:30 +02:00
|
|
|
uint8_t value;
|
|
|
|
uint8_t mask;
|
|
|
|
const char* name;
|
|
|
|
int parameters;
|
2010-02-07 10:01:18 +01:00
|
|
|
void (*handler)(FDCtrl *fdctrl, int direction);
|
2008-04-29 18:12:30 +02:00
|
|
|
int direction;
|
2015-05-21 15:19:35 +02:00
|
|
|
} FDCtrlCommand;
|
|
|
|
|
|
|
|
static const FDCtrlCommand handlers[] = {
|
2008-04-29 18:12:30 +02:00
|
|
|
{ FD_CMD_READ, 0x1f, "READ", 8, fdctrl_start_transfer, FD_DIR_READ },
|
|
|
|
{ FD_CMD_WRITE, 0x3f, "WRITE", 8, fdctrl_start_transfer, FD_DIR_WRITE },
|
|
|
|
{ FD_CMD_SEEK, 0xff, "SEEK", 2, fdctrl_handle_seek },
|
|
|
|
{ FD_CMD_SENSE_INTERRUPT_STATUS, 0xff, "SENSE INTERRUPT STATUS", 0, fdctrl_handle_sense_interrupt_status },
|
|
|
|
{ FD_CMD_RECALIBRATE, 0xff, "RECALIBRATE", 1, fdctrl_handle_recalibrate },
|
|
|
|
{ FD_CMD_FORMAT_TRACK, 0xbf, "FORMAT TRACK", 5, fdctrl_handle_format_track },
|
|
|
|
{ FD_CMD_READ_TRACK, 0xbf, "READ TRACK", 8, fdctrl_start_transfer, FD_DIR_READ },
|
|
|
|
{ FD_CMD_RESTORE, 0xff, "RESTORE", 17, fdctrl_handle_restore }, /* part of READ DELETED DATA */
|
|
|
|
{ FD_CMD_SAVE, 0xff, "SAVE", 0, fdctrl_handle_save }, /* part of READ DELETED DATA */
|
|
|
|
{ FD_CMD_READ_DELETED, 0x1f, "READ DELETED DATA", 8, fdctrl_start_transfer_del, FD_DIR_READ },
|
|
|
|
{ FD_CMD_SCAN_EQUAL, 0x1f, "SCAN EQUAL", 8, fdctrl_start_transfer, FD_DIR_SCANE },
|
2012-09-18 23:04:10 +02:00
|
|
|
{ FD_CMD_VERIFY, 0x1f, "VERIFY", 8, fdctrl_start_transfer, FD_DIR_VERIFY },
|
2008-04-29 18:12:30 +02:00
|
|
|
{ FD_CMD_SCAN_LOW_OR_EQUAL, 0x1f, "SCAN LOW OR EQUAL", 8, fdctrl_start_transfer, FD_DIR_SCANL },
|
|
|
|
{ FD_CMD_SCAN_HIGH_OR_EQUAL, 0x1f, "SCAN HIGH OR EQUAL", 8, fdctrl_start_transfer, FD_DIR_SCANH },
|
|
|
|
{ FD_CMD_WRITE_DELETED, 0x3f, "WRITE DELETED DATA", 8, fdctrl_start_transfer_del, FD_DIR_WRITE },
|
|
|
|
{ FD_CMD_READ_ID, 0xbf, "READ ID", 1, fdctrl_handle_readid },
|
|
|
|
{ FD_CMD_SPECIFY, 0xff, "SPECIFY", 2, fdctrl_handle_specify },
|
|
|
|
{ FD_CMD_SENSE_DRIVE_STATUS, 0xff, "SENSE DRIVE STATUS", 1, fdctrl_handle_sense_drive_status },
|
|
|
|
{ FD_CMD_PERPENDICULAR_MODE, 0xff, "PERPENDICULAR MODE", 1, fdctrl_handle_perpendicular_mode },
|
|
|
|
{ FD_CMD_CONFIGURE, 0xff, "CONFIGURE", 3, fdctrl_handle_configure },
|
|
|
|
{ FD_CMD_POWERDOWN_MODE, 0xff, "POWERDOWN MODE", 2, fdctrl_handle_powerdown_mode },
|
|
|
|
{ FD_CMD_OPTION, 0xff, "OPTION", 1, fdctrl_handle_option },
|
|
|
|
{ FD_CMD_DRIVE_SPECIFICATION_COMMAND, 0xff, "DRIVE SPECIFICATION COMMAND", 5, fdctrl_handle_drive_specification_command },
|
|
|
|
{ FD_CMD_RELATIVE_SEEK_OUT, 0xff, "RELATIVE SEEK OUT", 2, fdctrl_handle_relative_seek_out },
|
|
|
|
{ FD_CMD_FORMAT_AND_WRITE, 0xff, "FORMAT AND WRITE", 10, fdctrl_unimplemented },
|
|
|
|
{ FD_CMD_RELATIVE_SEEK_IN, 0xff, "RELATIVE SEEK IN", 2, fdctrl_handle_relative_seek_in },
|
|
|
|
{ FD_CMD_LOCK, 0x7f, "LOCK", 0, fdctrl_handle_lock },
|
|
|
|
{ FD_CMD_DUMPREG, 0xff, "DUMPREG", 0, fdctrl_handle_dumpreg },
|
|
|
|
{ FD_CMD_VERSION, 0xff, "VERSION", 0, fdctrl_handle_version },
|
|
|
|
{ FD_CMD_PART_ID, 0xff, "PART ID", 0, fdctrl_handle_partid },
|
|
|
|
{ FD_CMD_WRITE, 0x1f, "WRITE (BeOS)", 8, fdctrl_start_transfer, FD_DIR_WRITE }, /* not in specification ; BeOS 4.5 bug */
|
|
|
|
{ 0, 0, "unknown", 0, fdctrl_unimplemented }, /* default handler */
|
|
|
|
};
|
|
|
|
/* Associate command to an index in the 'handlers' array */
|
|
|
|
static uint8_t command_to_handler[256];
|
|
|
|
|
2015-05-21 15:19:35 +02:00
|
|
|
static const FDCtrlCommand *get_command(uint8_t cmd)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
idx = command_to_handler[cmd];
|
|
|
|
FLOPPY_DPRINTF("%s command\n", handlers[idx].name);
|
|
|
|
return &handlers[idx];
|
|
|
|
}
|
|
|
|
|
2010-02-07 10:01:18 +01:00
|
|
|
static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
|
2004-03-20 00:05:34 +01:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDrive *cur_drv;
|
2015-05-21 15:19:35 +02:00
|
|
|
const FDCtrlCommand *cmd;
|
2015-05-06 09:48:59 +02:00
|
|
|
uint32_t pos;
|
2004-03-20 00:05:34 +01:00
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/* Reset mode */
|
2008-04-29 18:15:53 +02:00
|
|
|
if (!(fdctrl->dor & FD_DOR_nRESET)) {
|
2004-10-09 18:44:33 +02:00
|
|
|
FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
|
2004-01-05 01:09:06 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-04-29 18:16:30 +02:00
|
|
|
if (!(fdctrl->msr & FD_MSR_RQM) || (fdctrl->msr & FD_MSR_DIO)) {
|
2012-06-03 19:16:14 +02:00
|
|
|
FLOPPY_DPRINTF("error: controller not ready for writing\n");
|
2004-01-05 01:09:06 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-04-29 18:16:30 +02:00
|
|
|
fdctrl->dsr &= ~FD_DSR_PWRDOWN;
|
2015-05-21 15:19:34 +02:00
|
|
|
|
2015-05-21 15:19:35 +02:00
|
|
|
FLOPPY_DPRINTF("%s: %02x\n", __func__, value);
|
|
|
|
|
|
|
|
/* If data_len spans multiple sectors, the current position in the FIFO
|
|
|
|
* wraps around while fdctrl->data_pos is the real position in the whole
|
|
|
|
* request. */
|
|
|
|
pos = fdctrl->data_pos++;
|
|
|
|
pos %= FD_SECTOR_LEN;
|
|
|
|
fdctrl->fifo[pos] = value;
|
|
|
|
|
2015-05-21 15:19:37 +02:00
|
|
|
if (fdctrl->data_pos == fdctrl->data_len) {
|
|
|
|
fdctrl->msr &= ~FD_MSR_RQM;
|
|
|
|
}
|
|
|
|
|
2015-05-21 15:19:34 +02:00
|
|
|
switch (fdctrl->phase) {
|
|
|
|
case FD_PHASE_EXECUTION:
|
|
|
|
/* For DMA requests, RQM should be cleared during execution phase, so
|
|
|
|
* we would have errored out above. */
|
|
|
|
assert(fdctrl->msr & FD_MSR_NONDMA);
|
2015-05-21 15:19:35 +02:00
|
|
|
|
2004-01-05 01:09:06 +01:00
|
|
|
/* FIFO data write */
|
2008-05-01 21:03:31 +02:00
|
|
|
if (pos == FD_SECTOR_LEN - 1 ||
|
2004-03-20 00:05:34 +01:00
|
|
|
fdctrl->data_pos == fdctrl->data_len) {
|
2008-04-29 18:17:08 +02:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
2016-05-06 18:26:35 +02:00
|
|
|
if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
|
|
|
|
BDRV_SECTOR_SIZE, 0) < 0) {
|
2012-06-03 19:16:14 +02:00
|
|
|
FLOPPY_DPRINTF("error writing sector %d\n",
|
|
|
|
fd_sector(cur_drv));
|
2015-05-21 15:19:34 +02:00
|
|
|
break;
|
2008-04-29 18:17:08 +02:00
|
|
|
}
|
2008-04-29 18:13:36 +02:00
|
|
|
if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
|
|
|
|
FLOPPY_DPRINTF("error seeking to next sector %d\n",
|
|
|
|
fd_sector(cur_drv));
|
2015-05-21 15:19:34 +02:00
|
|
|
break;
|
2008-04-29 18:13:36 +02:00
|
|
|
}
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
2015-05-21 15:19:35 +02:00
|
|
|
|
|
|
|
/* Switch to result phase when done with the transfer */
|
|
|
|
if (fdctrl->data_pos == fdctrl->data_len) {
|
2012-09-20 22:50:17 +02:00
|
|
|
fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
|
2015-05-21 15:19:35 +02:00
|
|
|
}
|
2015-05-21 15:19:34 +02:00
|
|
|
break;
|
2008-04-29 18:12:30 +02:00
|
|
|
|
2015-05-21 15:19:34 +02:00
|
|
|
case FD_PHASE_COMMAND:
|
|
|
|
assert(!(fdctrl->msr & FD_MSR_NONDMA));
|
2015-05-21 15:19:35 +02:00
|
|
|
assert(fdctrl->data_pos < FD_SECTOR_LEN);
|
2015-05-21 15:19:34 +02:00
|
|
|
|
2015-05-21 15:19:35 +02:00
|
|
|
if (pos == 0) {
|
|
|
|
/* The first byte specifies the command. Now we start reading
|
|
|
|
* as many parameters as this command requires. */
|
|
|
|
cmd = get_command(value);
|
|
|
|
fdctrl->data_len = cmd->parameters + 1;
|
2015-05-21 15:19:37 +02:00
|
|
|
if (cmd->parameters) {
|
|
|
|
fdctrl->msr |= FD_MSR_RQM;
|
|
|
|
}
|
2015-05-21 15:19:34 +02:00
|
|
|
fdctrl->msr |= FD_MSR_CMDBUSY;
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
2008-04-08 19:18:53 +02:00
|
|
|
|
2015-05-21 15:19:34 +02:00
|
|
|
if (fdctrl->data_pos == fdctrl->data_len) {
|
2015-05-21 15:19:35 +02:00
|
|
|
/* We have all parameters now, execute the command */
|
2015-05-21 15:19:34 +02:00
|
|
|
fdctrl->phase = FD_PHASE_EXECUTION;
|
2015-05-21 15:19:35 +02:00
|
|
|
|
2015-05-21 15:19:34 +02:00
|
|
|
if (fdctrl->data_state & FD_STATE_FORMAT) {
|
|
|
|
fdctrl_format_sector(fdctrl);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-05-21 15:19:35 +02:00
|
|
|
cmd = get_command(fdctrl->fifo[0]);
|
|
|
|
FLOPPY_DPRINTF("Calling handler for '%s'\n", cmd->name);
|
|
|
|
cmd->handler(fdctrl, cmd->direction);
|
2015-05-21 15:19:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FD_PHASE_RESULT:
|
|
|
|
default:
|
|
|
|
abort();
|
2004-01-05 01:09:06 +01:00
|
|
|
}
|
|
|
|
}
|
2004-05-08 15:14:18 +02:00
|
|
|
|
|
|
|
static void fdctrl_result_timer(void *opaque)
|
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrl *fdctrl = opaque;
|
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2007-11-05 04:11:37 +01:00
|
|
|
|
2007-09-13 14:40:37 +02:00
|
|
|
/* Pretend we are spinning.
|
|
|
|
* This is needed for Coherent, which uses READ ID to check for
|
|
|
|
* sector interleaving.
|
|
|
|
*/
|
|
|
|
if (cur_drv->last_sect != 0) {
|
|
|
|
cur_drv->sect = (cur_drv->sect % cur_drv->last_sect) + 1;
|
|
|
|
}
|
2012-02-06 22:29:10 +01:00
|
|
|
/* READ_ID can't automatically succeed! */
|
2021-02-03 18:18:30 +01:00
|
|
|
if ((fdctrl->dsr & FD_DSR_DRATEMASK) != cur_drv->media_rate) {
|
2012-02-06 22:29:10 +01:00
|
|
|
FLOPPY_DPRINTF("read id rate mismatch (fdc=%d, media=%d)\n",
|
|
|
|
fdctrl->dsr & FD_DSR_DRATEMASK, cur_drv->media_rate);
|
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_MA, 0x00);
|
|
|
|
} else {
|
|
|
|
fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
|
|
|
|
}
|
2004-05-08 15:14:18 +02:00
|
|
|
}
|
2008-04-29 18:12:30 +02:00
|
|
|
|
|
|
|
/* Init functions */
|
fdc: Reject clash between -drive if=floppy and -global isa-fdc
The floppy controller devices desugar their drive properties into
floppy devices (since commit a92bd191a4 "fdc: Move qdev properties to
FloppyDrive", v2.8.0). This involves some bad magic in
fdctrl_connect_drives(), and exists for backward compatibility.
The functions for boards to create floppy controller devices
fdctrl_init_isa(), fdctrl_init_sysbus(), and sun4m_fdctrl_init()
desugar -drive if=floppy to these floppy controller drive properties.
If you use both -drive if=floppy (or its -fda / -fdb sugar) and
-global isa-fdc for the same floppy device, -global silently loses the
conflict, and both backends involved end up with the floppy device
frontend attached, as demonstrated by iotest 172 (see commit before
previous). This is wrong.
Desugar -drive if=floppy straight to floppy devices instead, with
helper fdctrl_init_drives(). The conflict now gets rejected cleanly:
first, fdctrl_connect_drives() creates the floppy for the controller's
property, then fdctrl_init_drives() attempts to create the floppy for
-drive if=floppy, but fails because the unit is already in use.
Output of iotest 172 changes in three ways:
1. The clash gets rejected.
2. In one test case, "info qtree" has the floppy devices swapped, and
"info block" has their QOM paths swapped. This is because the
floppy device for -fda now gets created after the one for -global
isa-fdc.driveB.
3. The error message for -global floppy.drive=floppy0 changes. Before
the patch, we set isa-fdc.driveA to -fda's block backend, then
create the floppy device for it, then move the backend from
isa-fdc.driveA to floppy.drive. Floppy creation fails when
applying -global floppy.drive=floppy0, because floppy0 is still
attached to isa-fdc. After the patch, we create the floppy for
-fda, then set its drive property to floppy0. Now floppy creation
succeeds, but setting the drive property fails, because -global
already set it. Yes, this is exasperatingly complicated.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-5-armbru@redhat.com>
2020-06-22 11:42:15 +02:00
|
|
|
|
|
|
|
static void fdctrl_init_drives(FloppyBus *bus, DriveInfo **fds)
|
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_FD; i++) {
|
|
|
|
if (fds[i]) {
|
|
|
|
dev = qdev_new("floppy");
|
|
|
|
qdev_prop_set_uint32(dev, "unit", i);
|
|
|
|
qdev_prop_set_enum(dev, "drive-type", FLOPPY_DRIVE_TYPE_AUTO);
|
qdev: Make qdev_prop_set_drive() match the other helpers
qdev_prop_set_drive() can fail. None of the other qdev_prop_set_FOO()
can; they abort on error.
To clean up this inconsistency, rename qdev_prop_set_drive() to
qdev_prop_set_drive_err(), and create a qdev_prop_set_drive() that
aborts on error.
Coccinelle script to update callers:
@ depends on !(file in "hw/core/qdev-properties-system.c")@
expression dev, name, value;
symbol error_abort;
@@
- qdev_prop_set_drive(dev, name, value, &error_abort);
+ qdev_prop_set_drive(dev, name, value);
@@
expression dev, name, value, errp;
@@
- qdev_prop_set_drive(dev, name, value, errp);
+ qdev_prop_set_drive_err(dev, name, value, errp);
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200622094227.1271650-14-armbru@redhat.com>
2020-06-22 11:42:24 +02:00
|
|
|
qdev_prop_set_drive_err(dev, "drive", blk_by_legacy_dinfo(fds[i]),
|
|
|
|
&error_fatal);
|
fdc: Reject clash between -drive if=floppy and -global isa-fdc
The floppy controller devices desugar their drive properties into
floppy devices (since commit a92bd191a4 "fdc: Move qdev properties to
FloppyDrive", v2.8.0). This involves some bad magic in
fdctrl_connect_drives(), and exists for backward compatibility.
The functions for boards to create floppy controller devices
fdctrl_init_isa(), fdctrl_init_sysbus(), and sun4m_fdctrl_init()
desugar -drive if=floppy to these floppy controller drive properties.
If you use both -drive if=floppy (or its -fda / -fdb sugar) and
-global isa-fdc for the same floppy device, -global silently loses the
conflict, and both backends involved end up with the floppy device
frontend attached, as demonstrated by iotest 172 (see commit before
previous). This is wrong.
Desugar -drive if=floppy straight to floppy devices instead, with
helper fdctrl_init_drives(). The conflict now gets rejected cleanly:
first, fdctrl_connect_drives() creates the floppy for the controller's
property, then fdctrl_init_drives() attempts to create the floppy for
-drive if=floppy, but fails because the unit is already in use.
Output of iotest 172 changes in three ways:
1. The clash gets rejected.
2. In one test case, "info qtree" has the floppy devices swapped, and
"info block" has their QOM paths swapped. This is because the
floppy device for -fda now gets created after the one for -global
isa-fdc.driveB.
3. The error message for -global floppy.drive=floppy0 changes. Before
the patch, we set isa-fdc.driveA to -fda's block backend, then
create the floppy device for it, then move the backend from
isa-fdc.driveA to floppy.drive. Floppy creation fails when
applying -global floppy.drive=floppy0, because floppy0 is still
attached to isa-fdc. After the patch, we create the floppy for
-fda, then set its drive property to floppy0. Now floppy creation
succeeds, but setting the drive property fails, because -global
already set it. Yes, this is exasperatingly complicated.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-5-armbru@redhat.com>
2020-06-22 11:42:15 +02:00
|
|
|
qdev_realize_and_unref(dev, &bus->bus, &error_fatal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void isa_fdc_init_drives(ISADevice *fdc, DriveInfo **fds)
|
|
|
|
{
|
|
|
|
fdctrl_init_drives(&ISA_FDC(fdc)->state.bus, fds);
|
|
|
|
}
|
|
|
|
|
2017-04-21 14:27:06 +02:00
|
|
|
static void fdctrl_connect_drives(FDCtrl *fdctrl, DeviceState *fdc_dev,
|
|
|
|
Error **errp)
|
2008-04-29 18:12:30 +02:00
|
|
|
{
|
2009-07-20 08:56:23 +02:00
|
|
|
unsigned int i;
|
block: Fix virtual media change for if=none
BlockDriverState member removable controls whether virtual media
change (monitor commands change, eject) is allowed. It is set when
the "type hint" is BDRV_TYPE_CDROM or BDRV_TYPE_FLOPPY.
The type hint is only set by drive_init(). It sets BDRV_TYPE_FLOPPY
for if=floppy. It sets BDRV_TYPE_CDROM for media=cdrom and if=ide,
scsi, xen, or none.
if=ide and if=scsi work, because the type hint makes it a CD-ROM.
if=xen likewise, I think.
For the same reason, if=none works when it's used by ide-drive or
scsi-disk. For other guest devices, there are problems:
* fdc: you can't change virtual media
$ qemu [...] -drive if=none,id=foo,... -global isa-fdc.driveA=foo
QEMU 0.12.50 monitor - type 'help' for more information
(qemu) eject foo
Device 'foo' is not removable
unless you add media=cdrom, but that makes it readonly.
* virtio: if you add media=cdrom, you can change virtual media. If
you eject, the guest gets I/O errors. If you change, the guest sees
the drive's contents suddenly change.
* scsi-generic: if you add media=cdrom, you can change virtual media.
I didn't test what that does to the guest or the physical device,
but it can't be pretty.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-06-25 13:42:14 +02:00
|
|
|
FDrive *drive;
|
2008-04-29 18:12:30 +02:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_FD; i++) {
|
block: Fix virtual media change for if=none
BlockDriverState member removable controls whether virtual media
change (monitor commands change, eject) is allowed. It is set when
the "type hint" is BDRV_TYPE_CDROM or BDRV_TYPE_FLOPPY.
The type hint is only set by drive_init(). It sets BDRV_TYPE_FLOPPY
for if=floppy. It sets BDRV_TYPE_CDROM for media=cdrom and if=ide,
scsi, xen, or none.
if=ide and if=scsi work, because the type hint makes it a CD-ROM.
if=xen likewise, I think.
For the same reason, if=none works when it's used by ide-drive or
scsi-disk. For other guest devices, there are problems:
* fdc: you can't change virtual media
$ qemu [...] -drive if=none,id=foo,... -global isa-fdc.driveA=foo
QEMU 0.12.50 monitor - type 'help' for more information
(qemu) eject foo
Device 'foo' is not removable
unless you add media=cdrom, but that makes it readonly.
* virtio: if you add media=cdrom, you can change virtual media. If
you eject, the guest gets I/O errors. If you change, the guest sees
the drive's contents suddenly change.
* scsi-generic: if you add media=cdrom, you can change virtual media.
I didn't test what that does to the guest or the physical device,
but it can't be pretty.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-06-25 13:42:14 +02:00
|
|
|
drive = &fdctrl->drives[i];
|
2012-02-06 22:29:10 +01:00
|
|
|
drive->fdctrl = fdctrl;
|
2021-03-09 17:12:11 +01:00
|
|
|
fd_init(drive);
|
|
|
|
fd_revalidate(drive);
|
2008-04-29 18:12:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-05 17:32:23 +01:00
|
|
|
void fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr mmio_base, DriveInfo **fds)
|
2009-08-14 11:36:14 +02:00
|
|
|
{
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrl *fdctrl;
|
2009-08-14 11:36:14 +02:00
|
|
|
DeviceState *dev;
|
2013-07-01 12:18:24 +02:00
|
|
|
SysBusDevice *sbd;
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrlSysBus *sys;
|
2009-08-14 11:36:14 +02:00
|
|
|
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
dev = qdev_new("sysbus-fdc");
|
2013-07-01 12:18:24 +02:00
|
|
|
sys = SYSBUS_FDC(dev);
|
2009-09-22 13:53:19 +02:00
|
|
|
fdctrl = &sys->state;
|
|
|
|
fdctrl->dma_chann = dma_chann; /* FIXME */
|
2013-07-01 12:18:24 +02:00
|
|
|
sbd = SYS_BUS_DEVICE(dev);
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(sbd, &error_fatal);
|
2013-07-01 12:18:24 +02:00
|
|
|
sysbus_connect_irq(sbd, 0, irq);
|
|
|
|
sysbus_mmio_map(sbd, 0, mmio_base);
|
fdc: Reject clash between -drive if=floppy and -global isa-fdc
The floppy controller devices desugar their drive properties into
floppy devices (since commit a92bd191a4 "fdc: Move qdev properties to
FloppyDrive", v2.8.0). This involves some bad magic in
fdctrl_connect_drives(), and exists for backward compatibility.
The functions for boards to create floppy controller devices
fdctrl_init_isa(), fdctrl_init_sysbus(), and sun4m_fdctrl_init()
desugar -drive if=floppy to these floppy controller drive properties.
If you use both -drive if=floppy (or its -fda / -fdb sugar) and
-global isa-fdc for the same floppy device, -global silently loses the
conflict, and both backends involved end up with the floppy device
frontend attached, as demonstrated by iotest 172 (see commit before
previous). This is wrong.
Desugar -drive if=floppy straight to floppy devices instead, with
helper fdctrl_init_drives(). The conflict now gets rejected cleanly:
first, fdctrl_connect_drives() creates the floppy for the controller's
property, then fdctrl_init_drives() attempts to create the floppy for
-drive if=floppy, but fails because the unit is already in use.
Output of iotest 172 changes in three ways:
1. The clash gets rejected.
2. In one test case, "info qtree" has the floppy devices swapped, and
"info block" has their QOM paths swapped. This is because the
floppy device for -fda now gets created after the one for -global
isa-fdc.driveB.
3. The error message for -global floppy.drive=floppy0 changes. Before
the patch, we set isa-fdc.driveA to -fda's block backend, then
create the floppy device for it, then move the backend from
isa-fdc.driveA to floppy.drive. Floppy creation fails when
applying -global floppy.drive=floppy0, because floppy0 is still
attached to isa-fdc. After the patch, we create the floppy for
-fda, then set its drive property to floppy0. Now floppy creation
succeeds, but setting the drive property fails, because -global
already set it. Yes, this is exasperatingly complicated.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-5-armbru@redhat.com>
2020-06-22 11:42:15 +02:00
|
|
|
|
|
|
|
fdctrl_init_drives(&sys->state.bus, fds);
|
2008-04-29 18:12:30 +02:00
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
void sun4m_fdctrl_init(qemu_irq irq, hwaddr io_base,
|
2011-02-05 17:32:23 +01:00
|
|
|
DriveInfo **fds, qemu_irq *fdc_tc)
|
2008-04-29 18:12:30 +02:00
|
|
|
{
|
2009-07-15 16:41:54 +02:00
|
|
|
DeviceState *dev;
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrlSysBus *sys;
|
2008-04-29 18:12:30 +02:00
|
|
|
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
dev = qdev_new("SUNW,fdtwo");
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
|
2013-07-01 12:18:24 +02:00
|
|
|
sys = SYSBUS_FDC(dev);
|
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(sys), 0, irq);
|
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(sys), 0, io_base);
|
2009-07-15 16:41:54 +02:00
|
|
|
*fdc_tc = qdev_get_gpio_in(dev, 0);
|
fdc: Reject clash between -drive if=floppy and -global isa-fdc
The floppy controller devices desugar their drive properties into
floppy devices (since commit a92bd191a4 "fdc: Move qdev properties to
FloppyDrive", v2.8.0). This involves some bad magic in
fdctrl_connect_drives(), and exists for backward compatibility.
The functions for boards to create floppy controller devices
fdctrl_init_isa(), fdctrl_init_sysbus(), and sun4m_fdctrl_init()
desugar -drive if=floppy to these floppy controller drive properties.
If you use both -drive if=floppy (or its -fda / -fdb sugar) and
-global isa-fdc for the same floppy device, -global silently loses the
conflict, and both backends involved end up with the floppy device
frontend attached, as demonstrated by iotest 172 (see commit before
previous). This is wrong.
Desugar -drive if=floppy straight to floppy devices instead, with
helper fdctrl_init_drives(). The conflict now gets rejected cleanly:
first, fdctrl_connect_drives() creates the floppy for the controller's
property, then fdctrl_init_drives() attempts to create the floppy for
-drive if=floppy, but fails because the unit is already in use.
Output of iotest 172 changes in three ways:
1. The clash gets rejected.
2. In one test case, "info qtree" has the floppy devices swapped, and
"info block" has their QOM paths swapped. This is because the
floppy device for -fda now gets created after the one for -global
isa-fdc.driveB.
3. The error message for -global floppy.drive=floppy0 changes. Before
the patch, we set isa-fdc.driveA to -fda's block backend, then
create the floppy device for it, then move the backend from
isa-fdc.driveA to floppy.drive. Floppy creation fails when
applying -global floppy.drive=floppy0, because floppy0 is still
attached to isa-fdc. After the patch, we create the floppy for
-fda, then set its drive property to floppy0. Now floppy creation
succeeds, but setting the drive property fails, because -global
already set it. Yes, this is exasperatingly complicated.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-5-armbru@redhat.com>
2020-06-22 11:42:15 +02:00
|
|
|
|
|
|
|
fdctrl_init_drives(&sys->state.bus, fds);
|
2008-04-29 18:12:30 +02:00
|
|
|
}
|
2009-07-15 16:41:54 +02:00
|
|
|
|
2016-10-27 22:29:13 +02:00
|
|
|
static void fdctrl_realize_common(DeviceState *dev, FDCtrl *fdctrl,
|
|
|
|
Error **errp)
|
2009-07-15 16:41:54 +02:00
|
|
|
{
|
2009-07-20 08:56:23 +02:00
|
|
|
int i, j;
|
|
|
|
static int command_tables_inited = 0;
|
2009-07-15 16:41:54 +02:00
|
|
|
|
2016-01-22 21:51:00 +01:00
|
|
|
if (fdctrl->fallback == FLOPPY_DRIVE_TYPE_AUTO) {
|
|
|
|
error_setg(errp, "Cannot choose a fallback FDrive type of 'auto'");
|
2020-04-22 15:07:11 +02:00
|
|
|
return;
|
2016-01-22 21:51:00 +01:00
|
|
|
}
|
|
|
|
|
2009-07-20 08:56:23 +02:00
|
|
|
/* Fill 'command_to_handler' lookup table */
|
|
|
|
if (!command_tables_inited) {
|
|
|
|
command_tables_inited = 1;
|
|
|
|
for (i = ARRAY_SIZE(handlers) - 1; i >= 0; i--) {
|
|
|
|
for (j = 0; j < sizeof(command_to_handler); j++) {
|
|
|
|
if ((j & handlers[i].mask) == handlers[i].value) {
|
|
|
|
command_to_handler[j] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FLOPPY_DPRINTF("init controller\n");
|
|
|
|
fdctrl->fifo = qemu_memalign(512, FD_SECTOR_LEN);
|
2019-05-29 20:20:27 +02:00
|
|
|
memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
|
2009-09-10 03:04:37 +02:00
|
|
|
fdctrl->fifo_size = 512;
|
2013-08-21 17:03:08 +02:00
|
|
|
fdctrl->result_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
|
2013-07-17 14:14:41 +02:00
|
|
|
fdctrl_result_timer, fdctrl);
|
2009-07-20 08:56:23 +02:00
|
|
|
|
|
|
|
fdctrl->version = 0x90; /* Intel 82078 controller */
|
|
|
|
fdctrl->config = FD_CONFIG_EIS | FD_CONFIG_EFIFO; /* Implicit seek, polling & FIFO enabled */
|
2009-09-10 03:04:37 +02:00
|
|
|
fdctrl->num_floppies = MAX_FD;
|
2009-07-20 08:56:23 +02:00
|
|
|
|
2013-07-17 14:14:41 +02:00
|
|
|
if (fdctrl->dma_chann != -1) {
|
2016-02-03 17:28:58 +01:00
|
|
|
IsaDmaClass *k;
|
|
|
|
assert(fdctrl->dma);
|
|
|
|
k = ISADMA_GET_CLASS(fdctrl->dma);
|
|
|
|
k->register_channel(fdctrl->dma, fdctrl->dma_chann,
|
|
|
|
&fdctrl_transfer_handler, fdctrl);
|
2013-07-17 14:14:41 +02:00
|
|
|
}
|
2016-10-27 22:29:13 +02:00
|
|
|
|
|
|
|
floppy_bus_create(fdctrl, &fdctrl->bus, dev);
|
2017-04-21 14:27:06 +02:00
|
|
|
fdctrl_connect_drives(fdctrl, dev, errp);
|
2009-07-15 16:41:54 +02:00
|
|
|
}
|
|
|
|
|
2011-08-16 00:08:45 +02:00
|
|
|
static const MemoryRegionPortio fdc_portio_list[] = {
|
2011-08-11 00:28:20 +02:00
|
|
|
{ 1, 5, 1, .read = fdctrl_read, .write = fdctrl_write },
|
2011-08-16 00:08:45 +02:00
|
|
|
{ 7, 1, 1, .read = fdctrl_read, .write = fdctrl_write },
|
|
|
|
PORTIO_END_OF_LIST(),
|
2011-08-11 00:28:20 +02:00
|
|
|
};
|
|
|
|
|
2012-11-25 02:37:14 +01:00
|
|
|
static void isabus_fdc_realize(DeviceState *dev, Error **errp)
|
2009-07-31 12:30:18 +02:00
|
|
|
{
|
2012-11-25 02:37:14 +01:00
|
|
|
ISADevice *isadev = ISA_DEVICE(dev);
|
2013-04-27 22:18:38 +02:00
|
|
|
FDCtrlISABus *isa = ISA_FDC(dev);
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrl *fdctrl = &isa->state;
|
2013-07-17 14:14:41 +02:00
|
|
|
Error *err = NULL;
|
2009-07-31 12:30:18 +02:00
|
|
|
|
2016-07-13 02:11:59 +02:00
|
|
|
isa_register_portio_list(isadev, &fdctrl->portio_list,
|
|
|
|
isa->iobase, fdc_portio_list, fdctrl,
|
2012-11-25 02:37:14 +01:00
|
|
|
"fdc");
|
2010-12-08 12:34:56 +01:00
|
|
|
|
2012-11-25 02:37:14 +01:00
|
|
|
isa_init_irq(isadev, &fdctrl->irq, isa->irq);
|
2012-03-17 15:39:44 +01:00
|
|
|
fdctrl->dma_chann = isa->dma;
|
2016-02-03 17:28:58 +01:00
|
|
|
if (fdctrl->dma_chann != -1) {
|
|
|
|
fdctrl->dma = isa_get_dma(isa_bus_from_device(isadev), isa->dma);
|
2018-03-16 10:51:30 +01:00
|
|
|
if (!fdctrl->dma) {
|
|
|
|
error_setg(errp, "ISA controller does not support DMA");
|
|
|
|
return;
|
|
|
|
}
|
2016-02-03 17:28:58 +01:00
|
|
|
}
|
2009-07-31 12:30:18 +02:00
|
|
|
|
2012-11-25 02:37:14 +01:00
|
|
|
qdev_set_legacy_instance_id(dev, isa->iobase, 2);
|
2016-10-27 22:29:13 +02:00
|
|
|
fdctrl_realize_common(dev, fdctrl, &err);
|
2013-07-17 14:14:41 +02:00
|
|
|
if (err != NULL) {
|
|
|
|
error_propagate(errp, err);
|
2012-11-25 02:37:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2009-07-31 12:30:18 +02:00
|
|
|
}
|
|
|
|
|
2013-07-01 12:18:25 +02:00
|
|
|
static void sysbus_fdc_initfn(Object *obj)
|
2009-07-20 08:56:23 +02:00
|
|
|
{
|
2013-07-27 01:55:26 +02:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2013-07-01 12:18:25 +02:00
|
|
|
FDCtrlSysBus *sys = SYSBUS_FDC(obj);
|
2010-02-07 10:01:18 +01:00
|
|
|
FDCtrl *fdctrl = &sys->state;
|
2009-07-20 08:56:23 +02:00
|
|
|
|
2013-07-27 01:55:26 +02:00
|
|
|
fdctrl->dma_chann = -1;
|
|
|
|
|
2013-07-01 12:18:25 +02:00
|
|
|
memory_region_init_io(&fdctrl->iomem, obj, &fdctrl_mem_ops, fdctrl,
|
2013-06-07 03:25:08 +02:00
|
|
|
"fdc", 0x08);
|
2013-07-27 01:55:26 +02:00
|
|
|
sysbus_init_mmio(sbd, &fdctrl->iomem);
|
2013-07-01 12:18:25 +02:00
|
|
|
}
|
|
|
|
|
2013-07-27 01:55:26 +02:00
|
|
|
static void sun4m_fdc_initfn(Object *obj)
|
2013-07-01 12:18:25 +02:00
|
|
|
{
|
2013-07-27 01:55:26 +02:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
|
|
|
FDCtrlSysBus *sys = SYSBUS_FDC(obj);
|
2013-07-01 12:18:25 +02:00
|
|
|
FDCtrl *fdctrl = &sys->state;
|
|
|
|
|
2016-02-03 17:28:57 +01:00
|
|
|
fdctrl->dma_chann = -1;
|
|
|
|
|
2013-07-27 01:55:26 +02:00
|
|
|
memory_region_init_io(&fdctrl->iomem, obj, &fdctrl_mem_strict_ops,
|
|
|
|
fdctrl, "fdctrl", 0x08);
|
|
|
|
sysbus_init_mmio(sbd, &fdctrl->iomem);
|
2013-07-01 12:18:25 +02:00
|
|
|
}
|
2009-10-24 18:56:20 +02:00
|
|
|
|
2013-07-27 01:55:26 +02:00
|
|
|
static void sysbus_fdc_common_initfn(Object *obj)
|
2013-07-01 12:18:25 +02:00
|
|
|
{
|
2013-07-27 01:55:26 +02:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
2013-07-01 12:18:25 +02:00
|
|
|
FDCtrlSysBus *sys = SYSBUS_FDC(obj);
|
|
|
|
FDCtrl *fdctrl = &sys->state;
|
|
|
|
|
2013-07-27 01:55:26 +02:00
|
|
|
qdev_set_legacy_instance_id(dev, 0 /* io */, 2); /* FIXME */
|
|
|
|
|
|
|
|
sysbus_init_irq(sbd, &fdctrl->irq);
|
|
|
|
qdev_init_gpio_in(dev, fdctrl_handle_tc, 1);
|
2009-07-20 08:56:23 +02:00
|
|
|
}
|
|
|
|
|
2013-07-27 01:55:26 +02:00
|
|
|
static void sysbus_fdc_common_realize(DeviceState *dev, Error **errp)
|
2009-07-20 08:56:23 +02:00
|
|
|
{
|
2013-07-01 12:18:24 +02:00
|
|
|
FDCtrlSysBus *sys = SYSBUS_FDC(dev);
|
|
|
|
FDCtrl *fdctrl = &sys->state;
|
2009-07-20 08:56:23 +02:00
|
|
|
|
2016-10-27 22:29:13 +02:00
|
|
|
fdctrl_realize_common(dev, fdctrl, errp);
|
2009-07-20 08:56:23 +02:00
|
|
|
}
|
2009-07-15 16:41:54 +02:00
|
|
|
|
2016-01-22 21:50:56 +01:00
|
|
|
FloppyDriveType isa_fdc_get_drive_type(ISADevice *fdc, int i)
|
2011-10-20 16:37:26 +02:00
|
|
|
{
|
2013-04-27 22:18:38 +02:00
|
|
|
FDCtrlISABus *isa = ISA_FDC(fdc);
|
2011-10-20 16:37:26 +02:00
|
|
|
|
2012-07-10 11:12:27 +02:00
|
|
|
return isa->state.drives[i].drive;
|
2011-10-20 16:37:26 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 11:18:57 +02:00
|
|
|
static void isa_fdc_get_drive_max_chs(FloppyDriveType type, uint8_t *maxc,
|
|
|
|
uint8_t *maxh, uint8_t *maxs)
|
2016-02-17 19:25:32 +01:00
|
|
|
{
|
|
|
|
const FDFormat *fdf;
|
|
|
|
|
|
|
|
*maxc = *maxh = *maxs = 0;
|
|
|
|
for (fdf = fd_formats; fdf->drive != FLOPPY_DRIVE_TYPE_NONE; fdf++) {
|
|
|
|
if (fdf->drive != type) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*maxc < fdf->max_track) {
|
|
|
|
*maxc = fdf->max_track;
|
|
|
|
}
|
|
|
|
if (*maxh < fdf->max_head) {
|
|
|
|
*maxh = fdf->max_head;
|
|
|
|
}
|
|
|
|
if (*maxs < fdf->last_sect) {
|
|
|
|
*maxs = fdf->last_sect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(*maxc)--;
|
|
|
|
}
|
|
|
|
|
2020-06-19 11:18:56 +02:00
|
|
|
static Aml *build_fdinfo_aml(int idx, FloppyDriveType type)
|
|
|
|
{
|
|
|
|
Aml *dev, *fdi;
|
|
|
|
uint8_t maxc, maxh, maxs;
|
|
|
|
|
|
|
|
isa_fdc_get_drive_max_chs(type, &maxc, &maxh, &maxs);
|
|
|
|
|
|
|
|
dev = aml_device("FLP%c", 'A' + idx);
|
|
|
|
|
|
|
|
aml_append(dev, aml_name_decl("_ADR", aml_int(idx)));
|
|
|
|
|
|
|
|
fdi = aml_package(16);
|
|
|
|
aml_append(fdi, aml_int(idx)); /* Drive Number */
|
|
|
|
aml_append(fdi,
|
|
|
|
aml_int(cmos_get_fd_drive_type(type))); /* Device Type */
|
|
|
|
/*
|
|
|
|
* the values below are the limits of the drive, and are thus independent
|
|
|
|
* of the inserted media
|
|
|
|
*/
|
|
|
|
aml_append(fdi, aml_int(maxc)); /* Maximum Cylinder Number */
|
|
|
|
aml_append(fdi, aml_int(maxs)); /* Maximum Sector Number */
|
|
|
|
aml_append(fdi, aml_int(maxh)); /* Maximum Head Number */
|
|
|
|
/*
|
|
|
|
* SeaBIOS returns the below values for int 0x13 func 0x08 regardless of
|
|
|
|
* the drive type, so shall we
|
|
|
|
*/
|
|
|
|
aml_append(fdi, aml_int(0xAF)); /* disk_specify_1 */
|
|
|
|
aml_append(fdi, aml_int(0x02)); /* disk_specify_2 */
|
|
|
|
aml_append(fdi, aml_int(0x25)); /* disk_motor_wait */
|
|
|
|
aml_append(fdi, aml_int(0x02)); /* disk_sector_siz */
|
|
|
|
aml_append(fdi, aml_int(0x12)); /* disk_eot */
|
|
|
|
aml_append(fdi, aml_int(0x1B)); /* disk_rw_gap */
|
|
|
|
aml_append(fdi, aml_int(0xFF)); /* disk_dtl */
|
|
|
|
aml_append(fdi, aml_int(0x6C)); /* disk_formt_gap */
|
|
|
|
aml_append(fdi, aml_int(0xF6)); /* disk_fill */
|
|
|
|
aml_append(fdi, aml_int(0x0F)); /* disk_head_sttl */
|
|
|
|
aml_append(fdi, aml_int(0x08)); /* disk_motor_strt */
|
|
|
|
|
|
|
|
aml_append(dev, aml_name_decl("_FDI", fdi));
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2020-06-19 11:18:58 +02:00
|
|
|
int cmos_get_fd_drive_type(FloppyDriveType fd0)
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
switch (fd0) {
|
|
|
|
case FLOPPY_DRIVE_TYPE_144:
|
|
|
|
/* 1.44 Mb 3"5 drive */
|
|
|
|
val = 4;
|
|
|
|
break;
|
|
|
|
case FLOPPY_DRIVE_TYPE_288:
|
|
|
|
/* 2.88 Mb 3"5 drive */
|
|
|
|
val = 5;
|
|
|
|
break;
|
|
|
|
case FLOPPY_DRIVE_TYPE_120:
|
|
|
|
/* 1.2 Mb 5"5 drive */
|
|
|
|
val = 2;
|
|
|
|
break;
|
|
|
|
case FLOPPY_DRIVE_TYPE_NONE:
|
|
|
|
default:
|
|
|
|
val = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2020-06-19 11:18:56 +02:00
|
|
|
static void fdc_isa_build_aml(ISADevice *isadev, Aml *scope)
|
|
|
|
{
|
|
|
|
Aml *dev;
|
|
|
|
Aml *crs;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#define ACPI_FDE_MAX_FD 4
|
|
|
|
uint32_t fde_buf[5] = {
|
|
|
|
0, 0, 0, 0, /* presence of floppy drives #0 - #3 */
|
|
|
|
cpu_to_le32(2) /* tape presence (2 == never present) */
|
|
|
|
};
|
|
|
|
|
|
|
|
crs = aml_resource_template();
|
|
|
|
aml_append(crs, aml_io(AML_DECODE16, 0x03F2, 0x03F2, 0x00, 0x04));
|
|
|
|
aml_append(crs, aml_io(AML_DECODE16, 0x03F7, 0x03F7, 0x00, 0x01));
|
|
|
|
aml_append(crs, aml_irq_no_flags(6));
|
|
|
|
aml_append(crs,
|
|
|
|
aml_dma(AML_COMPATIBILITY, AML_NOTBUSMASTER, AML_TRANSFER8, 2));
|
|
|
|
|
|
|
|
dev = aml_device("FDC0");
|
|
|
|
aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0700")));
|
|
|
|
aml_append(dev, aml_name_decl("_CRS", crs));
|
|
|
|
|
|
|
|
for (i = 0; i < MIN(MAX_FD, ACPI_FDE_MAX_FD); i++) {
|
|
|
|
FloppyDriveType type = isa_fdc_get_drive_type(isadev, i);
|
|
|
|
|
|
|
|
if (type < FLOPPY_DRIVE_TYPE_NONE) {
|
|
|
|
fde_buf[i] = cpu_to_le32(1); /* drive present */
|
|
|
|
aml_append(dev, build_fdinfo_aml(i, type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aml_append(dev, aml_name_decl("_FDE",
|
|
|
|
aml_buffer(sizeof(fde_buf), (uint8_t *)fde_buf)));
|
|
|
|
|
|
|
|
aml_append(scope, dev);
|
|
|
|
}
|
|
|
|
|
2010-05-15 13:32:42 +02:00
|
|
|
static const VMStateDescription vmstate_isa_fdc ={
|
|
|
|
.name = "fdc",
|
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
2014-04-16 15:32:32 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2010-05-15 13:32:42 +02:00
|
|
|
VMSTATE_STRUCT(state, FDCtrlISABus, 0, vmstate_fdc, FDCtrl),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
static Property isa_fdc_properties[] = {
|
2014-02-08 11:01:53 +01:00
|
|
|
DEFINE_PROP_UINT32("iobase", FDCtrlISABus, iobase, 0x3f0),
|
2012-03-17 15:39:44 +01:00
|
|
|
DEFINE_PROP_UINT32("irq", FDCtrlISABus, irq, 6),
|
|
|
|
DEFINE_PROP_UINT32("dma", FDCtrlISABus, dma, 2),
|
2017-06-07 18:36:07 +02:00
|
|
|
DEFINE_PROP_SIGNED("fdtypeA", FDCtrlISABus, state.qdev_for_drives[0].type,
|
2016-01-22 21:51:01 +01:00
|
|
|
FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type,
|
|
|
|
FloppyDriveType),
|
2017-06-07 18:36:07 +02:00
|
|
|
DEFINE_PROP_SIGNED("fdtypeB", FDCtrlISABus, state.qdev_for_drives[1].type,
|
2016-01-22 21:51:01 +01:00
|
|
|
FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type,
|
|
|
|
FloppyDriveType),
|
2017-06-07 18:36:07 +02:00
|
|
|
DEFINE_PROP_SIGNED("fallback", FDCtrlISABus, state.fallback,
|
2016-01-22 21:51:05 +01:00
|
|
|
FLOPPY_DRIVE_TYPE_288, qdev_prop_fdc_drive_type,
|
2016-01-22 21:51:00 +01:00
|
|
|
FloppyDriveType),
|
2011-12-08 04:34:16 +01:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2013-04-27 22:18:38 +02:00
|
|
|
static void isabus_fdc_class_init(ObjectClass *klass, void *data)
|
2011-12-04 18:52:49 +01:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2020-06-19 11:18:56 +02:00
|
|
|
ISADeviceClass *isa = ISA_DEVICE_CLASS(klass);
|
2012-11-25 02:37:14 +01:00
|
|
|
|
|
|
|
dc->realize = isabus_fdc_realize;
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->fw_name = "fdc";
|
|
|
|
dc->reset = fdctrl_external_reset_isa;
|
|
|
|
dc->vmsd = &vmstate_isa_fdc;
|
2020-06-19 11:18:56 +02:00
|
|
|
isa->build_aml = fdc_isa_build_aml;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, isa_fdc_properties);
|
2013-07-29 16:17:45 +02:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2011-12-08 04:34:16 +01:00
|
|
|
}
|
|
|
|
|
2014-10-07 10:00:27 +02:00
|
|
|
static void isabus_fdc_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
FDCtrlISABus *isa = ISA_FDC(obj);
|
|
|
|
|
|
|
|
device_add_bootindex_property(obj, &isa->bootindexA,
|
|
|
|
"bootindexA", "/floppy@0",
|
2020-05-05 17:29:23 +02:00
|
|
|
DEVICE(obj));
|
2014-10-07 10:00:27 +02:00
|
|
|
device_add_bootindex_property(obj, &isa->bootindexB,
|
|
|
|
"bootindexB", "/floppy@1",
|
2020-05-05 17:29:23 +02:00
|
|
|
DEVICE(obj));
|
2014-10-07 10:00:27 +02:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo isa_fdc_info = {
|
2013-04-27 22:18:38 +02:00
|
|
|
.name = TYPE_ISA_FDC,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_ISA_DEVICE,
|
|
|
|
.instance_size = sizeof(FDCtrlISABus),
|
2013-04-27 22:18:38 +02:00
|
|
|
.class_init = isabus_fdc_class_init,
|
2014-10-07 10:00:27 +02:00
|
|
|
.instance_init = isabus_fdc_instance_init,
|
2009-07-31 12:30:18 +02:00
|
|
|
};
|
|
|
|
|
2010-05-15 13:32:42 +02:00
|
|
|
static const VMStateDescription vmstate_sysbus_fdc ={
|
|
|
|
.name = "fdc",
|
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
2014-04-16 15:32:32 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2010-05-15 13:32:42 +02:00
|
|
|
VMSTATE_STRUCT(state, FDCtrlSysBus, 0, vmstate_fdc, FDCtrl),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static Property sysbus_fdc_properties[] = {
|
2017-06-07 18:36:07 +02:00
|
|
|
DEFINE_PROP_SIGNED("fdtypeA", FDCtrlSysBus, state.qdev_for_drives[0].type,
|
2016-01-22 21:51:01 +01:00
|
|
|
FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type,
|
|
|
|
FloppyDriveType),
|
2017-06-07 18:36:07 +02:00
|
|
|
DEFINE_PROP_SIGNED("fdtypeB", FDCtrlSysBus, state.qdev_for_drives[1].type,
|
2016-01-22 21:51:01 +01:00
|
|
|
FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type,
|
|
|
|
FloppyDriveType),
|
2017-06-07 18:36:07 +02:00
|
|
|
DEFINE_PROP_SIGNED("fallback", FDCtrlISABus, state.fallback,
|
2016-01-22 21:51:00 +01:00
|
|
|
FLOPPY_DRIVE_TYPE_144, qdev_prop_fdc_drive_type,
|
|
|
|
FloppyDriveType),
|
2012-01-24 20:12:29 +01:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
2009-07-20 08:56:23 +02:00
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void sysbus_fdc_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, sysbus_fdc_properties);
|
2013-07-29 16:17:45 +02:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo sysbus_fdc_info = {
|
2013-07-27 01:55:26 +02:00
|
|
|
.name = "sysbus-fdc",
|
|
|
|
.parent = TYPE_SYSBUS_FDC,
|
2013-07-01 12:18:25 +02:00
|
|
|
.instance_init = sysbus_fdc_initfn,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = sysbus_fdc_class_init,
|
2012-01-24 20:12:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static Property sun4m_fdc_properties[] = {
|
2017-06-07 18:36:07 +02:00
|
|
|
DEFINE_PROP_SIGNED("fdtype", FDCtrlSysBus, state.qdev_for_drives[0].type,
|
2016-01-22 21:51:01 +01:00
|
|
|
FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type,
|
|
|
|
FloppyDriveType),
|
2017-06-07 18:36:07 +02:00
|
|
|
DEFINE_PROP_SIGNED("fallback", FDCtrlISABus, state.fallback,
|
2016-01-22 21:51:00 +01:00
|
|
|
FLOPPY_DRIVE_TYPE_144, qdev_prop_fdc_drive_type,
|
|
|
|
FloppyDriveType),
|
2012-01-24 20:12:29 +01:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sun4m_fdc_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, sun4m_fdc_properties);
|
2013-07-29 16:17:45 +02:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo sun4m_fdc_info = {
|
2011-12-08 04:34:16 +01:00
|
|
|
.name = "SUNW,fdtwo",
|
2013-07-27 01:55:26 +02:00
|
|
|
.parent = TYPE_SYSBUS_FDC,
|
2013-07-01 12:18:25 +02:00
|
|
|
.instance_init = sun4m_fdc_initfn,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = sun4m_fdc_class_init,
|
2009-07-15 16:41:54 +02:00
|
|
|
};
|
|
|
|
|
2013-07-27 01:55:26 +02:00
|
|
|
static void sysbus_fdc_common_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
dc->realize = sysbus_fdc_common_realize;
|
|
|
|
dc->reset = fdctrl_external_reset_sysbus;
|
|
|
|
dc->vmsd = &vmstate_sysbus_fdc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo sysbus_fdc_type_info = {
|
|
|
|
.name = TYPE_SYSBUS_FDC,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(FDCtrlSysBus),
|
|
|
|
.instance_init = sysbus_fdc_common_initfn,
|
|
|
|
.abstract = true,
|
|
|
|
.class_init = sysbus_fdc_common_class_init,
|
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void fdc_register_types(void)
|
2009-07-15 16:41:54 +02:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&isa_fdc_info);
|
2013-07-27 01:55:26 +02:00
|
|
|
type_register_static(&sysbus_fdc_type_info);
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&sysbus_fdc_info);
|
|
|
|
type_register_static(&sun4m_fdc_info);
|
2016-10-27 22:29:13 +02:00
|
|
|
type_register_static(&floppy_bus_info);
|
2016-10-27 22:29:13 +02:00
|
|
|
type_register_static(&floppy_drive_info);
|
2009-07-15 16:41:54 +02:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
type_init(fdc_register_types)
|