floppy: add drive properties.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Gerd Hoffmann 2009-09-22 13:53:18 +02:00 committed by Anthony Liguori
parent ef80b46623
commit fd8014e132
8 changed files with 55 additions and 46 deletions

View File

@ -81,6 +81,7 @@ typedef enum fdisk_flags_t {
} fdisk_flags_t;
typedef struct fdrive_t {
DriveInfo *dinfo;
BlockDriverState *bs;
/* Drive status */
fdrive_type_t drive;
@ -97,10 +98,10 @@ typedef struct fdrive_t {
uint8_t ro; /* Is read-only */
} fdrive_t;
static void fd_init (fdrive_t *drv, BlockDriverState *bs)
static void fd_init (fdrive_t *drv)
{
/* Drive */
drv->bs = bs;
drv->bs = drv->dinfo ? drv->dinfo->bdrv : NULL;
drv->drive = FDRIVE_DRV_NONE;
drv->perpendicular = 0;
/* Disk */
@ -1829,43 +1830,50 @@ static void fdctrl_result_timer(void *opaque)
}
/* Init functions */
static void fdctrl_connect_drives(fdctrl_t *fdctrl, BlockDriverState **fds)
static void fdctrl_connect_drives(fdctrl_t *fdctrl)
{
unsigned int i;
for (i = 0; i < MAX_FD; i++) {
fd_init(&fdctrl->drives[i], fds[i]);
fd_init(&fdctrl->drives[i]);
fd_revalidate(&fdctrl->drives[i]);
}
}
fdctrl_t *fdctrl_init_isa(BlockDriverState **fds)
fdctrl_t *fdctrl_init_isa(DriveInfo **fds)
{
fdctrl_t *fdctrl;
ISADevice *dev;
int dma_chann = 2;
dev = isa_create_simple("isa-fdc");
dev = isa_create("isa-fdc");
qdev_prop_set_drive(&dev->qdev, "driveA", fds[0]);
qdev_prop_set_drive(&dev->qdev, "driveB", fds[1]);
if (qdev_init(&dev->qdev) != 0)
return NULL;
fdctrl = &(DO_UPCAST(fdctrl_isabus_t, busdev, dev)->state);
fdctrl->dma_chann = dma_chann;
DMA_register_channel(dma_chann, &fdctrl_transfer_handler, fdctrl);
fdctrl_connect_drives(fdctrl, fds);
fdctrl_connect_drives(fdctrl);
return fdctrl;
}
fdctrl_t *fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
target_phys_addr_t mmio_base,
BlockDriverState **fds)
DriveInfo **fds)
{
fdctrl_t *fdctrl;
DeviceState *dev;
fdctrl_sysbus_t *sys;
dev = qdev_create(NULL, "sysbus-fdc");
qdev_init(dev);
qdev_prop_set_drive(dev, "driveA", fds[0]);
qdev_prop_set_drive(dev, "driveB", fds[1]);
if (qdev_init(dev) != 0)
return NULL;
sys = DO_UPCAST(fdctrl_sysbus_t, busdev.qdev, dev);
fdctrl = &sys->state;
sysbus_connect_irq(&sys->busdev, 0, irq);
@ -1873,20 +1881,22 @@ fdctrl_t *fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
fdctrl->dma_chann = dma_chann;
DMA_register_channel(dma_chann, &fdctrl_transfer_handler, fdctrl);
fdctrl_connect_drives(fdctrl, fds);
fdctrl_connect_drives(fdctrl);
return fdctrl;
}
fdctrl_t *sun4m_fdctrl_init (qemu_irq irq, target_phys_addr_t io_base,
BlockDriverState **fds, qemu_irq *fdc_tc)
DriveInfo **fds, qemu_irq *fdc_tc)
{
DeviceState *dev;
fdctrl_sysbus_t *sys;
fdctrl_t *fdctrl;
dev = qdev_create(NULL, "SUNW,fdtwo");
qdev_init(dev);
qdev_prop_set_drive(dev, "drive", fds[0]);
if (qdev_init(dev) != 0)
return NULL;
sys = DO_UPCAST(fdctrl_sysbus_t, busdev.qdev, dev);
fdctrl = &sys->state;
sysbus_connect_irq(&sys->busdev, 0, irq);
@ -1895,7 +1905,7 @@ fdctrl_t *sun4m_fdctrl_init (qemu_irq irq, target_phys_addr_t io_base,
fdctrl->dma_chann = -1;
fdctrl_connect_drives(fdctrl, fds);
fdctrl_connect_drives(fdctrl);
return fdctrl;
}
@ -1985,18 +1995,32 @@ static ISADeviceInfo isa_fdc_info = {
.init = isabus_fdc_init1,
.qdev.name = "isa-fdc",
.qdev.size = sizeof(fdctrl_isabus_t),
.qdev.props = (Property[]) {
DEFINE_PROP_DRIVE("driveA", fdctrl_isabus_t, state.drives[0].dinfo),
DEFINE_PROP_DRIVE("driveB", fdctrl_isabus_t, state.drives[1].dinfo),
DEFINE_PROP_END_OF_LIST(),
},
};
static SysBusDeviceInfo sysbus_fdc_info = {
.init = sysbus_fdc_init1,
.qdev.name = "sysbus-fdc",
.qdev.size = sizeof(fdctrl_sysbus_t),
.qdev.props = (Property[]) {
DEFINE_PROP_DRIVE("driveA", fdctrl_sysbus_t, state.drives[0].dinfo),
DEFINE_PROP_DRIVE("driveB", fdctrl_sysbus_t, state.drives[1].dinfo),
DEFINE_PROP_END_OF_LIST(),
},
};
static SysBusDeviceInfo sun4m_fdc_info = {
.init = sun4m_fdc_init1,
.qdev.name = "SUNW,fdtwo",
.qdev.size = sizeof(fdctrl_sysbus_t),
.qdev.props = (Property[]) {
DEFINE_PROP_DRIVE("drive", fdctrl_sysbus_t, state.drives[0].dinfo),
DEFINE_PROP_END_OF_LIST(),
},
};
static void fdc_register_devices(void)

View File

@ -1,12 +1,13 @@
/* fdc.c */
#include "sysemu.h"
#define MAX_FD 2
typedef struct fdctrl_t fdctrl_t;
fdctrl_t *fdctrl_init_isa(BlockDriverState **fds);
fdctrl_t *fdctrl_init_isa(DriveInfo **fds);
fdctrl_t *fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
target_phys_addr_t mmio_base,
BlockDriverState **fds);
DriveInfo **fds);
fdctrl_t *sun4m_fdctrl_init (qemu_irq irq, target_phys_addr_t io_base,
BlockDriverState **fds, qemu_irq *fdc_tc);
DriveInfo **fds, qemu_irq *fdc_tc);
int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num);

View File

@ -126,7 +126,7 @@ void mips_jazz_init (ram_addr_t ram_size,
int s_rtc, s_dma_dummy;
NICInfo *nd;
PITState *pit;
BlockDriverState *fds[MAX_FD];
DriveInfo *fds[MAX_FD];
qemu_irq esp_reset;
ram_addr_t ram_offset;
ram_addr_t bios_offset;
@ -234,8 +234,7 @@ void mips_jazz_init (ram_addr_t ram_size,
exit(1);
}
for (n = 0; n < MAX_FD; n++) {
DriveInfo *dinfo = drive_get(IF_FLOPPY, 0, n);
fds[n] = dinfo ? dinfo->bdrv : NULL;
fds[n] = drive_get(IF_FLOPPY, 0, n);
}
fdctrl_init_sysbus(rc4030[1], 0, 0x80003000, fds);

View File

@ -786,7 +786,7 @@ void mips_malta_init (ram_addr_t ram_size,
int i;
DriveInfo *dinfo;
DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
BlockDriverState *fd[MAX_FD];
DriveInfo *fd[MAX_FD];
int fl_idx = 0;
int fl_sectors = 0;
@ -947,8 +947,7 @@ void mips_malta_init (ram_addr_t ram_size,
if (parallel_hds[0])
parallel_init(0, parallel_hds[0]);
for(i = 0; i < MAX_FD; i++) {
dinfo = drive_get(IF_FLOPPY, 0, i);
fd[i] = dinfo ? dinfo->bdrv : NULL;
fd[i] = drive_get(IF_FLOPPY, 0, i);
}
floppy_controller = fdctrl_init_isa(fd);

View File

@ -1133,9 +1133,8 @@ static void pc_init1(ram_addr_t ram_size,
qemu_irq *isa_irq;
qemu_irq *i8259;
IsaIrqState *isa_irq_state;
DriveInfo *dinfo;
DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
BlockDriverState *fd[MAX_FD];
DriveInfo *fd[MAX_FD];
int using_vga = cirrus_vga_enabled || std_vga_enabled || vmsvga_enabled;
void *fw_cfg;
@ -1378,8 +1377,7 @@ static void pc_init1(ram_addr_t ram_size,
#endif
for(i = 0; i < MAX_FD; i++) {
dinfo = drive_get(IF_FLOPPY, 0, i);
fd[i] = dinfo ? dinfo->bdrv : NULL;
fd[i] = drive_get(IF_FLOPPY, 0, i);
}
floppy_controller = fdctrl_init_isa(fd);

View File

@ -563,9 +563,8 @@ static void ppc_prep_init (ram_addr_t ram_size,
PCIBus *pci_bus;
qemu_irq *i8259;
int ppc_boot_device;
DriveInfo *dinfo;
DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
BlockDriverState *fd[MAX_FD];
DriveInfo *fd[MAX_FD];
sysctrl = qemu_mallocz(sizeof(sysctrl_t));
@ -720,8 +719,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
// SB16_init();
for(i = 0; i < MAX_FD; i++) {
dinfo = drive_get(IF_FLOPPY, 0, i);
fd[i] = dinfo ? dinfo->bdrv : NULL;
fd[i] = drive_get(IF_FLOPPY, 0, i);
}
fdctrl_init_isa(fd);

View File

@ -758,9 +758,8 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
qemu_irq fdc_tc;
qemu_irq *cpu_halt;
unsigned long kernel_size;
BlockDriverState *fd[MAX_FD];
DriveInfo *fd[MAX_FD];
void *fw_cfg;
DriveInfo *dinfo;
/* init CPUs */
if (!cpu_model)
@ -834,10 +833,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
if (hwdef->fd_base) {
/* there is zero or one floppy drive */
memset(fd, 0, sizeof(fd));
dinfo = drive_get(IF_FLOPPY, 0, 0);
if (dinfo)
fd[0] = dinfo->bdrv;
fd[0] = drive_get(IF_FLOPPY, 0, 0);
sun4m_fdctrl_init(slavio_irq[22], hwdef->fd_base, fd,
&fdc_tc);
}
@ -1562,11 +1558,10 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
qemu_irq esp_reset;
qemu_irq fdc_tc;
unsigned long kernel_size;
BlockDriverState *fd[MAX_FD];
DriveInfo *fd[MAX_FD];
void *fw_cfg;
DeviceState *dev;
unsigned int i;
DriveInfo *dinfo;
/* init CPU */
if (!cpu_model)
@ -1618,10 +1613,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
if (hwdef->fd_base != (target_phys_addr_t)-1) {
/* there is zero or one floppy drive */
memset(fd, 0, sizeof(fd));
dinfo = drive_get(IF_FLOPPY, 0, 0);
if (dinfo)
fd[0] = dinfo->bdrv;
fd[0] = drive_get(IF_FLOPPY, 0, 0);
sun4m_fdctrl_init(slavio_irq[1], hwdef->fd_base, fd,
&fdc_tc);
}

View File

@ -573,9 +573,8 @@ static void sun4uv_init(ram_addr_t RAM_size,
PCIBus *pci_bus, *pci_bus2, *pci_bus3;
qemu_irq *irq;
DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
BlockDriverState *fd[MAX_FD];
DriveInfo *fd[MAX_FD];
void *fw_cfg;
DriveInfo *dinfo;
/* init CPUs */
env = cpu_devinit(cpu_model, hwdef);
@ -630,8 +629,7 @@ static void sun4uv_init(ram_addr_t RAM_size,
isa_create_simple("i8042");
for(i = 0; i < MAX_FD; i++) {
dinfo = drive_get(IF_FLOPPY, 0, i);
fd[i] = dinfo ? dinfo->bdrv : NULL;
fd[i] = drive_get(IF_FLOPPY, 0, i);
}
fdctrl_init_isa(fd);
nvram = m48t59_init_isa(0x0074, NVRAM_SIZE, 59);