From b485419c8ef2c66c3b44b1e701d5519a77b8fbfe Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Wed, 8 Jul 2015 19:41:22 +0200 Subject: [PATCH 08/23] hw/i386/pc: factor out pc_cmos_init_floppy() Message-id: <1436384484-21640-6-git-send-email-lersek@redhat.com> Patchwork-id: 66876 O-Subject: [RHEV-7.2 qemu-kvm-rhev PATCH v2 5/7] hw/i386/pc: factor out pc_cmos_init_floppy() Bugzilla: 1227282 RH-Acked-by: Dr. David Alan Gilbert RH-Acked-by: John Snow RH-Acked-by: Michael S. Tsirkin Extract the pc_cmos_init_floppy() function from pc_cmos_init(). The function sets two RTC registers: floppy drive types (0x10), overwriting the earlier value in there), and REG_EQUIPMENT_BYTE (0x14), setting bits in the prior value. Cc: Jan Tomko Cc: John Snow Cc: Markus Armbruster Cc: Paolo Bonzini Signed-off-by: Laszlo Ersek Reviewed-by: John Snow Reviewed-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin (cherry picked from commit 7444ca4ee2382170774ae201c473270d65620d75) Signed-off-by: Miroslav Rezanina --- hw/i386/pc.c | 67 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 2c71f85..32d9c34 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -315,6 +315,42 @@ static void pc_boot_set(void *opaque, const char *boot_device, Error **errp) set_boot_dev(opaque, boot_device, errp); } +static void pc_cmos_init_floppy(ISADevice *rtc_state, ISADevice *floppy) +{ + int val, nb, i; + FDriveType fd_type[2] = { FDRIVE_DRV_NONE, FDRIVE_DRV_NONE }; + + /* floppy type */ + if (floppy) { + for (i = 0; i < 2; i++) { + fd_type[i] = isa_fdc_get_drive_type(floppy, i); + } + } + val = (cmos_get_fd_drive_type(fd_type[0]) << 4) | + cmos_get_fd_drive_type(fd_type[1]); + rtc_set_memory(rtc_state, 0x10, val); + + val = rtc_get_memory(rtc_state, REG_EQUIPMENT_BYTE); + nb = 0; + if (fd_type[0] < FDRIVE_DRV_NONE) { + nb++; + } + if (fd_type[1] < FDRIVE_DRV_NONE) { + nb++; + } + switch (nb) { + case 0: + break; + case 1: + val |= 0x01; /* 1 drive, ready for boot */ + break; + case 2: + val |= 0x41; /* 2 drives, ready for boot */ + break; + } + rtc_set_memory(rtc_state, REG_EQUIPMENT_BYTE, val); +} + typedef struct pc_cmos_init_late_arg { ISADevice *rtc_state; BusState *idebus[2]; @@ -365,8 +401,7 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, ISADevice *floppy, BusState *idebus0, BusState *idebus1, ISADevice *s) { - int val, nb, i; - FDriveType fd_type[2] = { FDRIVE_DRV_NONE, FDRIVE_DRV_NONE }; + int val; static pc_cmos_init_late_arg arg; PCMachineState *pc_machine = PC_MACHINE(machine); Error *local_err = NULL; @@ -424,37 +459,11 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, exit(1); } - /* floppy type */ - if (floppy) { - for (i = 0; i < 2; i++) { - fd_type[i] = isa_fdc_get_drive_type(floppy, i); - } - } - 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 (fd_type[0] < FDRIVE_DRV_NONE) { - nb++; - } - if (fd_type[1] < FDRIVE_DRV_NONE) { - nb++; - } - switch (nb) { - case 0: - break; - case 1: - val |= 0x01; /* 1 drive, ready for boot */ - break; - case 2: - val |= 0x41; /* 2 drives, ready for boot */ - break; - } val |= 0x02; /* FPU is there */ val |= 0x04; /* PS/2 mouse installed */ rtc_set_memory(s, REG_EQUIPMENT_BYTE, val); + pc_cmos_init_floppy(s, floppy); /* hard drives */ arg.rtc_state = s; -- 1.8.3.1