aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorBlue Swirl <blauwirbel@gmail.com>2011-02-05 16:32:23 +0000
committerBlue Swirl <blauwirbel@gmail.com>2011-02-20 09:33:46 +0000
commit63ffb564dca94f8bda01ed6d209784104630a4d2 (patch)
tree4804b4a3feea7e6854e9fe869901f4a964391e06 /hw
parentd288c7ba7beb7975fe4bc15b0b14b9fd14da0a03 (diff)
downloadqemu-63ffb564dca94f8bda01ed6d209784104630a4d2.zip
qemu-63ffb564dca94f8bda01ed6d209784104630a4d2.tar.gz
qemu-63ffb564dca94f8bda01ed6d209784104630a4d2.tar.bz2
fdc: refactor device creation
Turn fdc_init_isa into an inline function. Get floppy geometry directly from the drives. Don't expose FDCtrl. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/fdc.c37
-rw-r--r--hw/fdc.h24
-rw-r--r--hw/pc.c31
-rw-r--r--hw/pc.h3
-rw-r--r--hw/pc_piix.c5
5 files changed, 45 insertions, 55 deletions
diff --git a/hw/fdc.c b/hw/fdc.c
index c130cba..9f4779c 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -201,6 +201,8 @@ static void fd_revalidate(FDrive *drv)
/********************************************************/
/* Intel 82078 floppy disk controller emulation */
+typedef struct FDCtrl FDCtrl;
+
static void fdctrl_reset(FDCtrl *fdctrl, int do_irq);
static void fdctrl_reset_fifo(FDCtrl *fdctrl);
static int fdctrl_transfer_handler (void *opaque, int nchan,
@@ -626,12 +628,6 @@ static void fdctrl_handle_tc(void *opaque, int irq, int level)
}
}
-/* XXX: may change if moved to bdrv */
-FDriveType fdctrl_get_drive_type(FDCtrl *fdctrl, int drive_num)
-{
- return fdctrl->drives[drive_num].drive;
-}
-
/* Change IRQ state */
static void fdctrl_reset_irq(FDCtrl *fdctrl)
{
@@ -1775,23 +1771,8 @@ static int fdctrl_connect_drives(FDCtrl *fdctrl)
return 0;
}
-FDCtrl *fdctrl_init_isa(DriveInfo **fds)
-{
- ISADevice *dev;
-
- dev = isa_create("isa-fdc");
- if (fds[0]) {
- qdev_prop_set_drive_nofail(&dev->qdev, "driveA", fds[0]->bdrv);
- }
- if (fds[1]) {
- qdev_prop_set_drive_nofail(&dev->qdev, "driveB", fds[1]->bdrv);
- }
- qdev_init_nofail(&dev->qdev);
- return &(DO_UPCAST(FDCtrlISABus, busdev, dev)->state);
-}
-
-FDCtrl *fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
- target_phys_addr_t mmio_base, DriveInfo **fds)
+void fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
+ target_phys_addr_t mmio_base, DriveInfo **fds)
{
FDCtrl *fdctrl;
DeviceState *dev;
@@ -1810,16 +1791,13 @@ FDCtrl *fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
qdev_init_nofail(dev);
sysbus_connect_irq(&sys->busdev, 0, irq);
sysbus_mmio_map(&sys->busdev, 0, mmio_base);
-
- return fdctrl;
}
-FDCtrl *sun4m_fdctrl_init(qemu_irq irq, target_phys_addr_t io_base,
- DriveInfo **fds, qemu_irq *fdc_tc)
+void sun4m_fdctrl_init(qemu_irq irq, target_phys_addr_t io_base,
+ DriveInfo **fds, qemu_irq *fdc_tc)
{
DeviceState *dev;
FDCtrlSysBus *sys;
- FDCtrl *fdctrl;
dev = qdev_create(NULL, "SUNW,fdtwo");
if (fds[0]) {
@@ -1827,12 +1805,9 @@ FDCtrl *sun4m_fdctrl_init(qemu_irq irq, target_phys_addr_t io_base,
}
qdev_init_nofail(dev);
sys = DO_UPCAST(FDCtrlSysBus, busdev.qdev, dev);
- fdctrl = &sys->state;
sysbus_connect_irq(&sys->busdev, 0, irq);
sysbus_mmio_map(&sys->busdev, 0, io_base);
*fdc_tc = qdev_get_gpio_in(dev, 0);
-
- return fdctrl;
}
static int fdctrl_init_common(FDCtrl *fdctrl)
diff --git a/hw/fdc.h b/hw/fdc.h
index 30ac970..3b2fb3b 100644
--- a/hw/fdc.h
+++ b/hw/fdc.h
@@ -1,18 +1,28 @@
#ifndef HW_FDC_H
#define HW_FDC_H
+#include "isa.h"
#include "blockdev.h"
/* fdc.c */
#define MAX_FD 2
-typedef struct FDCtrl FDCtrl;
+static inline void fdctrl_init_isa(DriveInfo **fds)
+{
+ ISADevice *dev;
-FDCtrl *fdctrl_init_isa(DriveInfo **fds);
-FDCtrl *fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
- target_phys_addr_t mmio_base, DriveInfo **fds);
-FDCtrl *sun4m_fdctrl_init(qemu_irq irq, target_phys_addr_t io_base,
- DriveInfo **fds, qemu_irq *fdc_tc);
-FDriveType fdctrl_get_drive_type(FDCtrl *fdctrl, int drive_num);
+ dev = isa_create("isa-fdc");
+ if (fds[0]) {
+ qdev_prop_set_drive_nofail(&dev->qdev, "driveA", fds[0]->bdrv);
+ }
+ if (fds[1]) {
+ qdev_prop_set_drive_nofail(&dev->qdev, "driveB", fds[1]->bdrv);
+ }
+ qdev_init_nofail(&dev->qdev);
+}
+void fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
+ target_phys_addr_t mmio_base, DriveInfo **fds);
+void sun4m_fdctrl_init(qemu_irq irq, target_phys_addr_t io_base,
+ DriveInfo **fds, qemu_irq *fdc_tc);
#endif
diff --git a/hw/pc.c b/hw/pc.c
index 4e4e2eb..36641b3 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -334,10 +334,11 @@ static void pc_cmos_init_late(void *opaque)
void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
const char *boot_device,
BusState *idebus0, BusState *idebus1,
- FDCtrl *floppy_controller, ISADevice *s)
+ ISADevice *s)
{
- int val, nb;
- FDriveType fd0, fd1;
+ int val, nb, nb_heads, max_track, last_sect, i;
+ FDriveType fd_type[2];
+ DriveInfo *fd[2];
static pc_cmos_init_late_arg arg;
/* various important CMOS locations needed by PC/Bochs bios */
@@ -379,19 +380,26 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
}
/* floppy type */
-
- fd0 = fdctrl_get_drive_type(floppy_controller, 0);
- fd1 = fdctrl_get_drive_type(floppy_controller, 1);
-
- val = (cmos_get_fd_drive_type(fd0) << 4) | cmos_get_fd_drive_type(fd1);
+ for (i = 0; i < 2; i++) {
+ fd[i] = drive_get(IF_FLOPPY, 0, i);
+ if (fd[i]) {
+ bdrv_get_floppy_geometry_hint(fd[i]->bdrv, &nb_heads, &max_track,
+ &last_sect, FDRIVE_DRV_NONE,
+ &fd_type[i]);
+ } else {
+ fd_type[i] = FDRIVE_DRV_NONE;
+ }
+ }
+ val = (cmos_get_fd_drive_type(fd_type[0]) << 4) |
+ cmos_get_fd_drive_type(fd_type[1]);
rtc_set_memory(s, 0x10, val);
val = 0;
nb = 0;
- if (fd0 < FDRIVE_DRV_NONE) {
+ if (fd_type[0] < FDRIVE_DRV_NONE) {
nb++;
}
- if (fd1 < FDRIVE_DRV_NONE) {
+ if (fd_type[1] < FDRIVE_DRV_NONE) {
nb++;
}
switch (nb) {
@@ -1092,7 +1100,6 @@ static void cpu_request_exit(void *opaque, int irq, int level)
}
void pc_basic_device_init(qemu_irq *isa_irq,
- FDCtrl **floppy_controller,
ISADevice **rtc_state)
{
int i;
@@ -1153,7 +1160,7 @@ void pc_basic_device_init(qemu_irq *isa_irq,
for(i = 0; i < MAX_FD; i++) {
fd[i] = drive_get(IF_FLOPPY, 0, i);
}
- *floppy_controller = fdctrl_init_isa(fd);
+ fdctrl_init_isa(fd);
}
void pc_pci_device_init(PCIBus *pci_bus)
diff --git a/hw/pc.h b/hw/pc.h
index 89b43ea..64a3a22 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -129,13 +129,12 @@ void pc_memory_init(ram_addr_t ram_size,
qemu_irq *pc_allocate_cpu_irq(void);
void pc_vga_init(PCIBus *pci_bus);
void pc_basic_device_init(qemu_irq *isa_irq,
- FDCtrl **floppy_controller,
ISADevice **rtc_state);
void pc_init_ne2k_isa(NICInfo *nd);
void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
const char *boot_device,
BusState *ide0, BusState *ide1,
- FDCtrl *floppy_controller, ISADevice *s);
+ ISADevice *s);
void pc_pci_device_init(PCIBus *pci_bus);
typedef void (*cpu_set_smm_t)(int smm, void *arg);
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 2918454..b4ca9ec 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -82,7 +82,6 @@ static void pc_init1(ram_addr_t ram_size,
qemu_irq *smi_irq;
IsaIrqState *isa_irq_state;
DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
- FDCtrl *floppy_controller;
BusState *idebus[MAX_IDE_BUS];
ISADevice *rtc_state;
@@ -119,7 +118,7 @@ static void pc_init1(ram_addr_t ram_size,
pc_vga_init(pci_enabled? pci_bus: NULL);
/* init basic PC hardware */
- pc_basic_device_init(isa_irq, &floppy_controller, &rtc_state);
+ pc_basic_device_init(isa_irq, &rtc_state);
for(i = 0; i < nb_nics; i++) {
NICInfo *nd = &nd_table[i];
@@ -156,7 +155,7 @@ static void pc_init1(ram_addr_t ram_size,
audio_init(isa_irq, pci_enabled ? pci_bus : NULL);
pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
- idebus[0], idebus[1], floppy_controller, rtc_state);
+ idebus[0], idebus[1], rtc_state);
if (pci_enabled && usb_enabled) {
usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);