[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/4] Remove global floppy_controller
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH 2/4] Remove global floppy_controller |
Date: |
Thu, 30 Apr 2009 18:03:46 +0200 |
Change cmos_init() to take the floppy drive types as arguments instead
of getting them through global floppy_controller.
Change fdctrl_get_drive_type() to take a BlockDriverState argument.
Factor fd_format() out of fd_revalidate() to make that possible.
Use it to compute the new arguments for cmos_init().
Signed-off-by: Markus Armbruster <address@hidden>
---
hw/fdc.c | 76 ++++++++++++++++++++++++++++++++++---------------------------
hw/fdc.h | 2 +-
hw/pc.c | 15 +++++------
3 files changed, 50 insertions(+), 43 deletions(-)
diff --git a/hw/fdc.c b/hw/fdc.c
index b00a4ec..1e09d52 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -231,12 +231,51 @@ static const fd_format_t fd_formats[] = {
{ FDRIVE_DRV_NONE, FDRIVE_DISK_NONE, -1, -1, 0, NULL, },
};
-/* Revalidate a disk drive after a disk change */
-static void fd_revalidate (fdrive_t *drv)
+static const fd_format_t *fd_format(BlockDriverState *bs,
+ fdrive_type_t prev_type)
{
const fd_format_t *parse;
uint64_t nb_sectors, size;
int i, first_match, match;
+
+ bdrv_get_geometry(bs, &nb_sectors);
+ match = -1;
+ first_match = -1;
+ for (i = 0;; i++) {
+ parse = &fd_formats[i];
+ if (parse->drive == FDRIVE_DRV_NONE)
+ break;
+ if (prev_type == parse->drive ||
+ prev_type == FDRIVE_DRV_NONE) {
+ size = (parse->max_head + 1) * parse->max_track *
+ parse->last_sect;
+ if (nb_sectors == size) {
+ match = i;
+ break;
+ }
+ if (first_match == -1)
+ first_match = i;
+ }
+ }
+ if (match == -1) {
+ if (first_match == -1)
+ match = 1;
+ else
+ match = first_match;
+ parse = &fd_formats[match];
+ }
+ return parse;
+}
+
+int fdctrl_get_drive_type(BlockDriverState *bs)
+{
+ return bs ? fd_format(bs, FDRIVE_DRV_NONE)->drive : FDRIVE_DRV_NONE;
+}
+
+/* Revalidate a disk drive after a disk change */
+static void fd_revalidate (fdrive_t *drv)
+{
+ const fd_format_t *parse;
int nb_heads, max_track, last_sect, ro;
FLOPPY_DPRINTF("revalidate\n");
@@ -247,32 +286,7 @@ static void fd_revalidate (fdrive_t *drv)
FLOPPY_DPRINTF("User defined disk (%d %d %d)",
nb_heads - 1, max_track, last_sect);
} else {
- bdrv_get_geometry(drv->bs, &nb_sectors);
- match = -1;
- first_match = -1;
- for (i = 0;; i++) {
- parse = &fd_formats[i];
- if (parse->drive == FDRIVE_DRV_NONE)
- break;
- if (drv->drive == parse->drive ||
- drv->drive == FDRIVE_DRV_NONE) {
- size = (parse->max_head + 1) * parse->max_track *
- parse->last_sect;
- if (nb_sectors == size) {
- match = i;
- break;
- }
- if (first_match == -1)
- first_match = i;
- }
- }
- if (match == -1) {
- if (first_match == -1)
- match = 1;
- else
- match = first_match;
- parse = &fd_formats[match];
- }
+ parse = fd_format(drv->bs, drv->drive);
nb_heads = parse->max_head + 1;
max_track = parse->max_track;
last_sect = parse->last_sect;
@@ -735,12 +749,6 @@ static void fdctrl_handle_tc(void *opaque, int irq, int
level)
}
}
-/* XXX: may change if moved to bdrv */
-int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num)
-{
- return fdctrl->drives[drive_num].drive;
-}
-
/* Change IRQ state */
static void fdctrl_reset_irq (fdctrl_t *fdctrl)
{
diff --git a/hw/fdc.h b/hw/fdc.h
index 7b6a9de..91fad1f 100644
--- a/hw/fdc.h
+++ b/hw/fdc.h
@@ -8,4 +8,4 @@ fdctrl_t *fdctrl_init (qemu_irq irq, int dma_chann, int
mem_mapped,
BlockDriverState **fds);
fdctrl_t *sun4m_fdctrl_init (qemu_irq irq, target_phys_addr_t io_base,
BlockDriverState **fds, qemu_irq *fdc_tc);
-int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num);
+int fdctrl_get_drive_type(BlockDriverState *bs);
diff --git a/hw/pc.c b/hw/pc.c
index 0e861ab..a9a39a9 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -56,7 +56,6 @@
#define MAX_IDE_BUS 2
-static fdctrl_t *floppy_controller;
static RTCState *rtc_state;
static PITState *pit;
static IOAPICState *ioapic;
@@ -234,11 +233,12 @@ static int pc_boot_set(void *opaque, const char
*boot_device)
/* hd_table must contain 4 block drivers */
static void cmos_init(RTCState *s,
ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
- const char *boot_device, BlockDriverState **hd_table)
+ const char *boot_device, BlockDriverState **hd_table,
+ int fd0, int fd1)
{
int nbds, bds[3] = { 0, };
int val;
- int fd0, fd1, nb;
+ int nb;
int i;
/* various important CMOS locations needed by PC/Bochs bios */
@@ -294,9 +294,6 @@ static void cmos_init(RTCState *s,
/* 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);
rtc_set_memory(s, 0x10, val);
@@ -1071,9 +1068,11 @@ static void pc_init1(ram_addr_t ram_size, int
vga_ram_size,
else
fd[i] = NULL;
}
- floppy_controller = fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
+ fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
- cmos_init(rtc, below_4g_mem_size, above_4g_mem_size, boot_device, hd);
+ cmos_init(rtc, below_4g_mem_size, above_4g_mem_size, boot_device, hd,
+ fdctrl_get_drive_type(fd[0]),
+ fdctrl_get_drive_type(fd[1]));
if (pci_enabled && usb_enabled) {
usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
--
1.6.0.6
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] [PATCH 2/4] Remove global floppy_controller,
Markus Armbruster <=