From nobody Tue Jul 1 10:08:13 2025 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162369940335770.55687619129492; Mon, 14 Jun 2021 12:36:43 -0700 (PDT) Received: from localhost ([::1]:53888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lssO2-0004R6-6O for importer2@patchew.org; Mon, 14 Jun 2021 15:36:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lssKH-00055M-HF for qemu-devel@nongnu.org; Mon, 14 Jun 2021 15:32:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46483) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lssKE-0004yR-8p for qemu-devel@nongnu.org; Mon, 14 Jun 2021 15:32:49 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-89-OHvRzK7OOU2Dnp2jNcIdcw-1; Mon, 14 Jun 2021 15:32:41 -0400 Received: by mail-wr1-f69.google.com with SMTP id h104-20020adf90710000b029010de8455a3aso7463535wrh.12 for ; Mon, 14 Jun 2021 12:32:41 -0700 (PDT) Received: from x1w.. (93.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.93]) by smtp.gmail.com with ESMTPSA id a1sm18614717wrg.92.2021.06.14.12.32.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 12:32:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623699165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2ppgJSQX88zXRnD5SIV3IiQWkIiXWUtCAHzPOoYK6kc=; b=RYWbXYyEnQI/ptKuIhok7z3cZeDXotfKl2wl10ShIaNn3/9+wHjunt9SDQnw1xa5Y6nUyF tAJ6t1XARxQ5mfozk+bl+BCQf8EKokSzIXZBssTYL45KuxAGPQZjqmV7hsOEgEx+/JbwbC 0UDCnka+IzWby5/Yv8JoS7o8LBpWlYw= X-MC-Unique: OHvRzK7OOU2Dnp2jNcIdcw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2ppgJSQX88zXRnD5SIV3IiQWkIiXWUtCAHzPOoYK6kc=; b=Qzn0q51vZiNPz4jS1+GM5mmgVMGSS6CNDOJRHxBsLMLR/L7LN6efjNMx9oiL0Rwn5+ Ck3Gxdvge68l0j2g1ugO8PQqGSry882xZ9JsgOjR1dMupPTIoealoRBJ5zfiWFQdirUf PcxxNiyZs2XE6OFwK8S+ye970cEcKGozQDqB4yPuCMZ0L2/nVfCj2RT2yC3P5EDiMl// Aus3/5pISD1EXW0srReryiGi+VexfwnvR83FCvS7WxEJRmwgLp1xYrBp5+UlP8vTy3jx gJNlKjubpQr4l76TZg0igXitGpIM58904TIkmcZUTPgk7edK6NBtRcs3dyUH8MglpOWz W9Dg== X-Gm-Message-State: AOAM5338oinD1zlZhOzGmn1m+wzCRquvdSV7TJZQcVwrJl9UrdXZsjbx 9V4HrtPAZCgSe0GPaq/i/3mJxXORKyf1gZ7+xGz0trt65p3VruPYbjOmL7hOVvXYHwlTlXYu3G3 Dl32AYwmSQo0eHivJJVCiGknhliqq6PUPDa2VsfgY4xWmjFyBUMJqZ7xapIFCe8nm X-Received: by 2002:a05:600c:3b13:: with SMTP id m19mr18175055wms.53.1623699160012; Mon, 14 Jun 2021 12:32:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyq09mqh6cazIM0atvJpxN2ysS1dgA2FMGmP2FcR6PYZRSvMitrk+ZCwsmpZBrdIKJBO3l7gw== X-Received: by 2002:a05:600c:3b13:: with SMTP id m19mr18175026wms.53.1623699159668; Mon, 14 Jun 2021 12:32:39 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 4/6] hw/block/fdc: Extract ISA floppy controllers to fdc-isa.c Date: Mon, 14 Jun 2021 21:32:18 +0200 Message-Id: <20210614193220.2007159-5-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210614193220.2007159-1-philmd@redhat.com> References: <20210614193220.2007159-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.2, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , John Snow , Mark Cave-Ayland , Paolo Bonzini Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Some machines use floppy controllers via the SysBus interface, and don't need to pull in all the ISA code. Extract the ISA specific code to a new unit: fdc-isa.c, and add a new Kconfig symbol: "FDC_ISA". This allows us to remove the FIXME from commit dd0ff8191ab ("isa: express SuperIO dependencies with Kconfig"). Reviewed-by: John Snow Acked-by: Mark Cave-Ayland Reviewed-by: Mark Cave-Ayland Acked-by: Paolo Bonzini Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/fdc-isa.c | 319 +++++++++++++++++++++++++++++++++++++++++++ hw/block/fdc.c | 265 ----------------------------------- MAINTAINERS | 1 + hw/block/Kconfig | 8 +- hw/block/meson.build | 1 + hw/i386/Kconfig | 2 +- hw/isa/Kconfig | 8 +- hw/sparc64/Kconfig | 2 +- 8 files changed, 332 insertions(+), 274 deletions(-) create mode 100644 hw/block/fdc-isa.c diff --git a/hw/block/fdc-isa.c b/hw/block/fdc-isa.c new file mode 100644 index 00000000000..0e22a10732d --- /dev/null +++ b/hw/block/fdc-isa.c @@ -0,0 +1,319 @@ +/* + * QEMU Floppy disk emulator (Intel 82078) + * + * Copyright (c) 2003, 2007 Jocelyn Mayer + * Copyright (c) 2008 Herv=C3=A9 Poussineau + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ +/* + * The controller is used in Sun4m systems in a slightly different + * way. There are changes in DOR register and DMA is not available. + */ + +#include "qemu/osdep.h" +#include "hw/block/fdc.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/timer.h" +#include "hw/acpi/aml-build.h" +#include "hw/irq.h" +#include "hw/isa/isa.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" +#include "migration/vmstate.h" +#include "hw/block/block.h" +#include "sysemu/block-backend.h" +#include "sysemu/blockdev.h" +#include "sysemu/sysemu.h" +#include "qemu/log.h" +#include "qemu/main-loop.h" +#include "qemu/module.h" +#include "trace.h" +#include "qom/object.h" +#include "fdc-internal.h" + +OBJECT_DECLARE_SIMPLE_TYPE(FDCtrlISABus, ISA_FDC) + +struct FDCtrlISABus { + /*< private >*/ + ISADevice parent_obj; + /*< public >*/ + + uint32_t iobase; + uint32_t irq; + uint32_t dma; + struct FDCtrl state; + int32_t bootindexA; + int32_t bootindexB; +}; + +static void fdctrl_external_reset_isa(DeviceState *d) +{ + FDCtrlISABus *isa =3D ISA_FDC(d); + FDCtrl *s =3D &isa->state; + + fdctrl_reset(s, 0); +} + +void isa_fdc_init_drives(ISADevice *fdc, DriveInfo **fds) +{ + fdctrl_init_drives(&ISA_FDC(fdc)->state.bus, fds); +} + +static const MemoryRegionPortio fdc_portio_list[] =3D { + { 1, 5, 1, .read =3D fdctrl_read, .write =3D fdctrl_write }, + { 7, 1, 1, .read =3D fdctrl_read, .write =3D fdctrl_write }, + PORTIO_END_OF_LIST(), +}; + +static void isabus_fdc_realize(DeviceState *dev, Error **errp) +{ + ISADevice *isadev =3D ISA_DEVICE(dev); + FDCtrlISABus *isa =3D ISA_FDC(dev); + FDCtrl *fdctrl =3D &isa->state; + Error *err =3D NULL; + + isa_register_portio_list(isadev, &fdctrl->portio_list, + isa->iobase, fdc_portio_list, fdctrl, + "fdc"); + + isa_init_irq(isadev, &fdctrl->irq, isa->irq); + fdctrl->dma_chann =3D isa->dma; + if (fdctrl->dma_chann !=3D -1) { + IsaDmaClass *k; + fdctrl->dma =3D isa_get_dma(isa_bus_from_device(isadev), isa->dma); + if (!fdctrl->dma) { + error_setg(errp, "ISA controller does not support DMA"); + return; + } + k =3D ISADMA_GET_CLASS(fdctrl->dma); + k->register_channel(fdctrl->dma, fdctrl->dma_chann, + &fdctrl_transfer_handler, fdctrl); + } + + qdev_set_legacy_instance_id(dev, isa->iobase, 2); + + fdctrl_realize_common(dev, fdctrl, &err); + if (err !=3D NULL) { + error_propagate(errp, err); + return; + } +} + +FloppyDriveType isa_fdc_get_drive_type(ISADevice *fdc, int i) +{ + FDCtrlISABus *isa =3D ISA_FDC(fdc); + + return isa->state.drives[i].drive; +} + +static void isa_fdc_get_drive_max_chs(FloppyDriveType type, uint8_t *maxc, + uint8_t *maxh, uint8_t *maxs) +{ + const FDFormat *fdf; + + *maxc =3D *maxh =3D *maxs =3D 0; + for (fdf =3D fd_formats; fdf->drive !=3D FLOPPY_DRIVE_TYPE_NONE; fdf++= ) { + if (fdf->drive !=3D type) { + continue; + } + if (*maxc < fdf->max_track) { + *maxc =3D fdf->max_track; + } + if (*maxh < fdf->max_head) { + *maxh =3D fdf->max_head; + } + if (*maxs < fdf->last_sect) { + *maxs =3D fdf->last_sect; + } + } + (*maxc)--; +} + +static Aml *build_fdinfo_aml(int idx, FloppyDriveType type) +{ + Aml *dev, *fdi; + uint8_t maxc, maxh, maxs; + + isa_fdc_get_drive_max_chs(type, &maxc, &maxh, &maxs); + + dev =3D aml_device("FLP%c", 'A' + idx); + + aml_append(dev, aml_name_decl("_ADR", aml_int(idx))); + + fdi =3D aml_package(16); + aml_append(fdi, aml_int(idx)); /* Drive Number */ + aml_append(fdi, + aml_int(cmos_get_fd_drive_type(type))); /* Device Type */ + /* + * the values below are the limits of the drive, and are thus independ= ent + * of the inserted media + */ + aml_append(fdi, aml_int(maxc)); /* Maximum Cylinder Number */ + aml_append(fdi, aml_int(maxs)); /* Maximum Sector Number */ + aml_append(fdi, aml_int(maxh)); /* Maximum Head Number */ + /* + * SeaBIOS returns the below values for int 0x13 func 0x08 regardless = of + * the drive type, so shall we + */ + aml_append(fdi, aml_int(0xAF)); /* disk_specify_1 */ + aml_append(fdi, aml_int(0x02)); /* disk_specify_2 */ + aml_append(fdi, aml_int(0x25)); /* disk_motor_wait */ + aml_append(fdi, aml_int(0x02)); /* disk_sector_siz */ + aml_append(fdi, aml_int(0x12)); /* disk_eot */ + aml_append(fdi, aml_int(0x1B)); /* disk_rw_gap */ + aml_append(fdi, aml_int(0xFF)); /* disk_dtl */ + aml_append(fdi, aml_int(0x6C)); /* disk_formt_gap */ + aml_append(fdi, aml_int(0xF6)); /* disk_fill */ + aml_append(fdi, aml_int(0x0F)); /* disk_head_sttl */ + aml_append(fdi, aml_int(0x08)); /* disk_motor_strt */ + + aml_append(dev, aml_name_decl("_FDI", fdi)); + return dev; +} + +int cmos_get_fd_drive_type(FloppyDriveType fd0) +{ + int val; + + switch (fd0) { + case FLOPPY_DRIVE_TYPE_144: + /* 1.44 Mb 3"5 drive */ + val =3D 4; + break; + case FLOPPY_DRIVE_TYPE_288: + /* 2.88 Mb 3"5 drive */ + val =3D 5; + break; + case FLOPPY_DRIVE_TYPE_120: + /* 1.2 Mb 5"5 drive */ + val =3D 2; + break; + case FLOPPY_DRIVE_TYPE_NONE: + default: + val =3D 0; + break; + } + return val; +} + +static void fdc_isa_build_aml(ISADevice *isadev, Aml *scope) +{ + Aml *dev; + Aml *crs; + int i; + +#define ACPI_FDE_MAX_FD 4 + uint32_t fde_buf[5] =3D { + 0, 0, 0, 0, /* presence of floppy drives #0 - #3 */ + cpu_to_le32(2) /* tape presence (2 =3D=3D never present) */ + }; + + crs =3D aml_resource_template(); + aml_append(crs, aml_io(AML_DECODE16, 0x03F2, 0x03F2, 0x00, 0x04)); + aml_append(crs, aml_io(AML_DECODE16, 0x03F7, 0x03F7, 0x00, 0x01)); + aml_append(crs, aml_irq_no_flags(6)); + aml_append(crs, + aml_dma(AML_COMPATIBILITY, AML_NOTBUSMASTER, AML_TRANSFER8, 2)); + + dev =3D aml_device("FDC0"); + aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0700"))); + aml_append(dev, aml_name_decl("_CRS", crs)); + + for (i =3D 0; i < MIN(MAX_FD, ACPI_FDE_MAX_FD); i++) { + FloppyDriveType type =3D isa_fdc_get_drive_type(isadev, i); + + if (type < FLOPPY_DRIVE_TYPE_NONE) { + fde_buf[i] =3D cpu_to_le32(1); /* drive present */ + aml_append(dev, build_fdinfo_aml(i, type)); + } + } + aml_append(dev, aml_name_decl("_FDE", + aml_buffer(sizeof(fde_buf), (uint8_t *)fde_buf))); + + aml_append(scope, dev); +} + +static const VMStateDescription vmstate_isa_fdc =3D { + .name =3D "fdc", + .version_id =3D 2, + .minimum_version_id =3D 2, + .fields =3D (VMStateField[]) { + VMSTATE_STRUCT(state, FDCtrlISABus, 0, vmstate_fdc, FDCtrl), + VMSTATE_END_OF_LIST() + } +}; + +static Property isa_fdc_properties[] =3D { + DEFINE_PROP_UINT32("iobase", FDCtrlISABus, iobase, 0x3f0), + DEFINE_PROP_UINT32("irq", FDCtrlISABus, irq, 6), + DEFINE_PROP_UINT32("dma", FDCtrlISABus, dma, 2), + DEFINE_PROP_SIGNED("fdtypeA", FDCtrlISABus, state.qdev_for_drives[0].t= ype, + FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, + FloppyDriveType), + DEFINE_PROP_SIGNED("fdtypeB", FDCtrlISABus, state.qdev_for_drives[1].t= ype, + FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, + FloppyDriveType), + DEFINE_PROP_SIGNED("fallback", FDCtrlISABus, state.fallback, + FLOPPY_DRIVE_TYPE_288, qdev_prop_fdc_drive_type, + FloppyDriveType), + DEFINE_PROP_END_OF_LIST(), +}; + +static void isabus_fdc_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ISADeviceClass *isa =3D ISA_DEVICE_CLASS(klass); + + dc->realize =3D isabus_fdc_realize; + dc->fw_name =3D "fdc"; + dc->reset =3D fdctrl_external_reset_isa; + dc->vmsd =3D &vmstate_isa_fdc; + isa->build_aml =3D fdc_isa_build_aml; + device_class_set_props(dc, isa_fdc_properties); + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); +} + +static void isabus_fdc_instance_init(Object *obj) +{ + FDCtrlISABus *isa =3D ISA_FDC(obj); + + device_add_bootindex_property(obj, &isa->bootindexA, + "bootindexA", "/floppy@0", + DEVICE(obj)); + device_add_bootindex_property(obj, &isa->bootindexB, + "bootindexB", "/floppy@1", + DEVICE(obj)); +} + +static const TypeInfo isa_fdc_info =3D { + .name =3D TYPE_ISA_FDC, + .parent =3D TYPE_ISA_DEVICE, + .instance_size =3D sizeof(FDCtrlISABus), + .class_init =3D isabus_fdc_class_init, + .instance_init =3D isabus_fdc_instance_init, +}; + +static void isa_fdc_register_types(void) +{ + type_register_static(&isa_fdc_info); +} + +type_init(isa_fdc_register_types) diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 20ddeb98d83..aa70eb97c6a 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -32,7 +32,6 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/timer.h" -#include "hw/acpi/aml-build.h" #include "hw/irq.h" #include "hw/isa/isa.h" #include "hw/qdev-properties.h" @@ -785,19 +784,6 @@ struct FDCtrlSysBus { struct FDCtrl state; }; =20 -OBJECT_DECLARE_SIMPLE_TYPE(FDCtrlISABus, ISA_FDC) - -struct FDCtrlISABus { - ISADevice parent_obj; - - uint32_t iobase; - uint32_t irq; - uint32_t dma; - struct FDCtrl state; - int32_t bootindexA; - int32_t bootindexB; -}; - uint32_t fdctrl_read(void *opaque, uint32_t reg) { FDCtrl *fdctrl =3D opaque; @@ -1121,14 +1107,6 @@ static void fdctrl_external_reset_sysbus(DeviceState= *d) fdctrl_reset(s, 0); } =20 -static void fdctrl_external_reset_isa(DeviceState *d) -{ - FDCtrlISABus *isa =3D ISA_FDC(d); - FDCtrl *s =3D &isa->state; - - fdctrl_reset(s, 0); -} - static void fdctrl_handle_tc(void *opaque, int irq, int level) { trace_fdctrl_tc_pulse(level); @@ -2389,11 +2367,6 @@ void fdctrl_init_drives(FloppyBus *bus, DriveInfo **= fds) } } =20 -void isa_fdc_init_drives(ISADevice *fdc, DriveInfo **fds) -{ - fdctrl_init_drives(&ISA_FDC(fdc)->state.bus, fds); -} - void fdctrl_init_sysbus(qemu_irq irq, int dma_chann, hwaddr mmio_base, DriveInfo **fds) { @@ -2464,14 +2437,6 @@ void fdctrl_realize_common(DeviceState *dev, FDCtrl = *fdctrl, Error **errp) fdctrl->config =3D FD_CONFIG_EIS | FD_CONFIG_EFIFO; /* Implicit seek, = polling & FIFO enabled */ fdctrl->num_floppies =3D MAX_FD; =20 - if (fdctrl->dma_chann !=3D -1) { - IsaDmaClass *k; - assert(fdctrl->dma); - k =3D ISADMA_GET_CLASS(fdctrl->dma); - k->register_channel(fdctrl->dma, fdctrl->dma_chann, - &fdctrl_transfer_handler, fdctrl); - } - floppy_bus_create(fdctrl, &fdctrl->bus, dev); =20 for (i =3D 0; i < MAX_FD; i++) { @@ -2482,41 +2447,6 @@ void fdctrl_realize_common(DeviceState *dev, FDCtrl = *fdctrl, Error **errp) } } =20 -static const MemoryRegionPortio fdc_portio_list[] =3D { - { 1, 5, 1, .read =3D fdctrl_read, .write =3D fdctrl_write }, - { 7, 1, 1, .read =3D fdctrl_read, .write =3D fdctrl_write }, - PORTIO_END_OF_LIST(), -}; - -static void isabus_fdc_realize(DeviceState *dev, Error **errp) -{ - ISADevice *isadev =3D ISA_DEVICE(dev); - FDCtrlISABus *isa =3D ISA_FDC(dev); - FDCtrl *fdctrl =3D &isa->state; - Error *err =3D NULL; - - isa_register_portio_list(isadev, &fdctrl->portio_list, - isa->iobase, fdc_portio_list, fdctrl, - "fdc"); - - isa_init_irq(isadev, &fdctrl->irq, isa->irq); - fdctrl->dma_chann =3D isa->dma; - if (fdctrl->dma_chann !=3D -1) { - fdctrl->dma =3D isa_get_dma(isa_bus_from_device(isadev), isa->dma); - if (!fdctrl->dma) { - error_setg(errp, "ISA controller does not support DMA"); - return; - } - } - - qdev_set_legacy_instance_id(dev, isa->iobase, 2); - fdctrl_realize_common(dev, fdctrl, &err); - if (err !=3D NULL) { - error_propagate(errp, err); - return; - } -} - static void sysbus_fdc_initfn(Object *obj) { SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); @@ -2564,200 +2494,6 @@ static void sysbus_fdc_common_realize(DeviceState *= dev, Error **errp) fdctrl_realize_common(dev, fdctrl, errp); } =20 -FloppyDriveType isa_fdc_get_drive_type(ISADevice *fdc, int i) -{ - FDCtrlISABus *isa =3D ISA_FDC(fdc); - - return isa->state.drives[i].drive; -} - -static void isa_fdc_get_drive_max_chs(FloppyDriveType type, uint8_t *maxc, - uint8_t *maxh, uint8_t *maxs) -{ - const FDFormat *fdf; - - *maxc =3D *maxh =3D *maxs =3D 0; - for (fdf =3D fd_formats; fdf->drive !=3D FLOPPY_DRIVE_TYPE_NONE; fdf++= ) { - if (fdf->drive !=3D type) { - continue; - } - if (*maxc < fdf->max_track) { - *maxc =3D fdf->max_track; - } - if (*maxh < fdf->max_head) { - *maxh =3D fdf->max_head; - } - if (*maxs < fdf->last_sect) { - *maxs =3D fdf->last_sect; - } - } - (*maxc)--; -} - -static Aml *build_fdinfo_aml(int idx, FloppyDriveType type) -{ - Aml *dev, *fdi; - uint8_t maxc, maxh, maxs; - - isa_fdc_get_drive_max_chs(type, &maxc, &maxh, &maxs); - - dev =3D aml_device("FLP%c", 'A' + idx); - - aml_append(dev, aml_name_decl("_ADR", aml_int(idx))); - - fdi =3D aml_package(16); - aml_append(fdi, aml_int(idx)); /* Drive Number */ - aml_append(fdi, - aml_int(cmos_get_fd_drive_type(type))); /* Device Type */ - /* - * the values below are the limits of the drive, and are thus independ= ent - * of the inserted media - */ - aml_append(fdi, aml_int(maxc)); /* Maximum Cylinder Number */ - aml_append(fdi, aml_int(maxs)); /* Maximum Sector Number */ - aml_append(fdi, aml_int(maxh)); /* Maximum Head Number */ - /* - * SeaBIOS returns the below values for int 0x13 func 0x08 regardless = of - * the drive type, so shall we - */ - aml_append(fdi, aml_int(0xAF)); /* disk_specify_1 */ - aml_append(fdi, aml_int(0x02)); /* disk_specify_2 */ - aml_append(fdi, aml_int(0x25)); /* disk_motor_wait */ - aml_append(fdi, aml_int(0x02)); /* disk_sector_siz */ - aml_append(fdi, aml_int(0x12)); /* disk_eot */ - aml_append(fdi, aml_int(0x1B)); /* disk_rw_gap */ - aml_append(fdi, aml_int(0xFF)); /* disk_dtl */ - aml_append(fdi, aml_int(0x6C)); /* disk_formt_gap */ - aml_append(fdi, aml_int(0xF6)); /* disk_fill */ - aml_append(fdi, aml_int(0x0F)); /* disk_head_sttl */ - aml_append(fdi, aml_int(0x08)); /* disk_motor_strt */ - - aml_append(dev, aml_name_decl("_FDI", fdi)); - return dev; -} - -int cmos_get_fd_drive_type(FloppyDriveType fd0) -{ - int val; - - switch (fd0) { - case FLOPPY_DRIVE_TYPE_144: - /* 1.44 Mb 3"5 drive */ - val =3D 4; - break; - case FLOPPY_DRIVE_TYPE_288: - /* 2.88 Mb 3"5 drive */ - val =3D 5; - break; - case FLOPPY_DRIVE_TYPE_120: - /* 1.2 Mb 5"5 drive */ - val =3D 2; - break; - case FLOPPY_DRIVE_TYPE_NONE: - default: - val =3D 0; - break; - } - return val; -} - -static void fdc_isa_build_aml(ISADevice *isadev, Aml *scope) -{ - Aml *dev; - Aml *crs; - int i; - -#define ACPI_FDE_MAX_FD 4 - uint32_t fde_buf[5] =3D { - 0, 0, 0, 0, /* presence of floppy drives #0 - #3 */ - cpu_to_le32(2) /* tape presence (2 =3D=3D never present) */ - }; - - crs =3D aml_resource_template(); - aml_append(crs, aml_io(AML_DECODE16, 0x03F2, 0x03F2, 0x00, 0x04)); - aml_append(crs, aml_io(AML_DECODE16, 0x03F7, 0x03F7, 0x00, 0x01)); - aml_append(crs, aml_irq_no_flags(6)); - aml_append(crs, - aml_dma(AML_COMPATIBILITY, AML_NOTBUSMASTER, AML_TRANSFER8, 2)); - - dev =3D aml_device("FDC0"); - aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0700"))); - aml_append(dev, aml_name_decl("_CRS", crs)); - - for (i =3D 0; i < MIN(MAX_FD, ACPI_FDE_MAX_FD); i++) { - FloppyDriveType type =3D isa_fdc_get_drive_type(isadev, i); - - if (type < FLOPPY_DRIVE_TYPE_NONE) { - fde_buf[i] =3D cpu_to_le32(1); /* drive present */ - aml_append(dev, build_fdinfo_aml(i, type)); - } - } - aml_append(dev, aml_name_decl("_FDE", - aml_buffer(sizeof(fde_buf), (uint8_t *)fde_buf))); - - aml_append(scope, dev); -} - -static const VMStateDescription vmstate_isa_fdc =3D{ - .name =3D "fdc", - .version_id =3D 2, - .minimum_version_id =3D 2, - .fields =3D (VMStateField[]) { - VMSTATE_STRUCT(state, FDCtrlISABus, 0, vmstate_fdc, FDCtrl), - VMSTATE_END_OF_LIST() - } -}; - -static Property isa_fdc_properties[] =3D { - DEFINE_PROP_UINT32("iobase", FDCtrlISABus, iobase, 0x3f0), - DEFINE_PROP_UINT32("irq", FDCtrlISABus, irq, 6), - DEFINE_PROP_UINT32("dma", FDCtrlISABus, dma, 2), - DEFINE_PROP_SIGNED("fdtypeA", FDCtrlISABus, state.qdev_for_drives[0].t= ype, - FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, - FloppyDriveType), - DEFINE_PROP_SIGNED("fdtypeB", FDCtrlISABus, state.qdev_for_drives[1].t= ype, - FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, - FloppyDriveType), - DEFINE_PROP_SIGNED("fallback", FDCtrlISABus, state.fallback, - FLOPPY_DRIVE_TYPE_288, qdev_prop_fdc_drive_type, - FloppyDriveType), - DEFINE_PROP_END_OF_LIST(), -}; - -static void isabus_fdc_class_init(ObjectClass *klass, void *data) -{ - DeviceClass *dc =3D DEVICE_CLASS(klass); - ISADeviceClass *isa =3D ISA_DEVICE_CLASS(klass); - - dc->realize =3D isabus_fdc_realize; - dc->fw_name =3D "fdc"; - dc->reset =3D fdctrl_external_reset_isa; - dc->vmsd =3D &vmstate_isa_fdc; - isa->build_aml =3D fdc_isa_build_aml; - device_class_set_props(dc, isa_fdc_properties); - set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); -} - -static void isabus_fdc_instance_init(Object *obj) -{ - FDCtrlISABus *isa =3D ISA_FDC(obj); - - device_add_bootindex_property(obj, &isa->bootindexA, - "bootindexA", "/floppy@0", - DEVICE(obj)); - device_add_bootindex_property(obj, &isa->bootindexB, - "bootindexB", "/floppy@1", - DEVICE(obj)); -} - -static const TypeInfo isa_fdc_info =3D { - .name =3D TYPE_ISA_FDC, - .parent =3D TYPE_ISA_DEVICE, - .instance_size =3D sizeof(FDCtrlISABus), - .class_init =3D isabus_fdc_class_init, - .instance_init =3D isabus_fdc_instance_init, -}; - static const VMStateDescription vmstate_sysbus_fdc =3D{ .name =3D "fdc", .version_id =3D 2, @@ -2841,7 +2577,6 @@ static const TypeInfo sysbus_fdc_type_info =3D { =20 static void fdc_register_types(void) { - type_register_static(&isa_fdc_info); type_register_static(&sysbus_fdc_type_info); type_register_static(&sysbus_fdc_info); type_register_static(&sun4m_fdc_info); diff --git a/MAINTAINERS b/MAINTAINERS index fd83cfb2ad6..f2fb24ef7e7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1670,6 +1670,7 @@ L: qemu-block@nongnu.org S: Supported F: hw/block/fdc.c F: hw/block/fdc-internal.h +F: hw/block/fdc-isa.c F: include/hw/block/fdc.h F: tests/qtest/fdc-test.c T: git https://gitlab.com/jsnow/qemu.git ide diff --git a/hw/block/Kconfig b/hw/block/Kconfig index 295441e64ab..8c3be60a197 100644 --- a/hw/block/Kconfig +++ b/hw/block/Kconfig @@ -1,8 +1,10 @@ config FDC bool - # FIXME: there is no separate file for the MMIO floppy disk controller= , so - # select ISA_BUS here instead of polluting each board that requires one - select ISA_BUS + +config FDC_ISA + bool + depends on ISA_BUS + select FDC =20 config SSI_M25P80 bool diff --git a/hw/block/meson.build b/hw/block/meson.build index 8b0de54db1f..8cc79b5fcb4 100644 --- a/hw/block/meson.build +++ b/hw/block/meson.build @@ -5,6 +5,7 @@ )) softmmu_ss.add(when: 'CONFIG_ECC', if_true: files('ecc.c')) softmmu_ss.add(when: 'CONFIG_FDC', if_true: files('fdc.c')) +softmmu_ss.add(when: 'CONFIG_FDC_ISA', if_true: files('fdc-isa.c')) softmmu_ss.add(when: 'CONFIG_NAND', if_true: files('nand.c')) softmmu_ss.add(when: 'CONFIG_ONENAND', if_true: files('onenand.c')) softmmu_ss.add(when: 'CONFIG_PFLASH_CFI01', if_true: files('pflash_cfi01.c= ')) diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index 66838fa397b..aacb6f6d964 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -24,7 +24,7 @@ config PC imply VGA_PCI imply VIRTIO_VGA imply NVDIMM - select FDC + select FDC_ISA select I8259 select I8254 select PCKBD diff --git a/hw/isa/Kconfig b/hw/isa/Kconfig index 7216f66a54a..96db170eff3 100644 --- a/hw/isa/Kconfig +++ b/hw/isa/Kconfig @@ -17,7 +17,7 @@ config ISA_SUPERIO bool select ISA_BUS select PCKBD - select FDC + select FDC_ISA =20 config PC87312 bool @@ -28,7 +28,7 @@ config PC87312 select MC146818RTC select SERIAL_ISA select PARALLEL - select FDC + select FDC_ISA select IDE_ISA =20 config PIIX3 @@ -47,7 +47,7 @@ config VT82C686 select ISA_SUPERIO select ACPI_SMBUS select SERIAL_ISA - select FDC + select FDC_ISA select USB_UHCI select APM =20 @@ -56,7 +56,7 @@ config SMC37C669 select ISA_SUPERIO select SERIAL_ISA select PARALLEL - select FDC + select FDC_ISA =20 config LPC_ICH9 bool diff --git a/hw/sparc64/Kconfig b/hw/sparc64/Kconfig index 980a201bb73..7e557ad17b0 100644 --- a/hw/sparc64/Kconfig +++ b/hw/sparc64/Kconfig @@ -6,7 +6,7 @@ config SUN4U imply PARALLEL select M48T59 select ISA_BUS - select FDC + select FDC_ISA select SERIAL_ISA select PCI_SABRE select IDE_CMD646 --=20 2.31.1