From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/4] Remove global floppy_controller
Date: Thu, 30 Apr 2009 18:03:46 +0200 [thread overview]
Message-ID: <9b44b171aa0919e1df03c7e7bcbbcf09168e0955.1241106809.git.armbru@redhat.com> (raw)
In-Reply-To: <cover.1241106809.git.armbru@redhat.com>
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 <armbru@redhat.com>
---
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
next prev parent reply other threads:[~2009-04-30 16:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1241106809.git.armbru@redhat.com>
2009-04-30 16:03 ` [Qemu-devel] [PATCH 1/4] Confine use of global rtc_state to PC CMOS functions Markus Armbruster
2009-05-01 17:27 ` Blue Swirl
2009-05-04 13:54 ` Markus Armbruster
2009-05-05 16:22 ` Blue Swirl
2009-05-19 6:56 ` Markus Armbruster
2009-05-19 16:51 ` Blue Swirl
2009-05-19 16:57 ` Avi Kivity
2009-04-30 16:03 ` Markus Armbruster [this message]
2009-05-01 17:31 ` [Qemu-devel] [PATCH 2/4] Remove global floppy_controller Blue Swirl
2009-04-30 16:03 ` [Qemu-devel] [PATCH 3/4] Give parse_macaddr() external linkage Markus Armbruster
2009-04-30 16:03 ` [Qemu-devel] [PATCH 4/4] Machine description as data Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9b44b171aa0919e1df03c7e7bcbbcf09168e0955.1241106809.git.armbru@redhat.com \
--to=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).