From nobody Mon Feb 9 16:12:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621442108; cv=none; d=zohomail.com; s=zohoarc; b=ZJKM0JHSEVm7lqxBlw32ofcU2CVNStyXXpDjt143+qiAT0F1veKClxTOe0fX0eMLt8G5cnxIcATtB7kOjXMHR5mC6d4Z/e7/DmWHWDQpiDNr13Ou/M7mcxph8Is7zgL1Wv/mln0RbZJOd7dtxuPYZLMBmq7rec8i48g2NvO4h/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621442108; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ntuPDGRvSJUugCXT9BaH6p28w2jINXWjbJZ/rFQ7At4=; b=IA3EUzOdDFVLKda3/9ayGNLCV+q0k8dypWLxLAG95BGfRlR9pH7QrjFkNf+M+TfDD7ijh8J3yTBodPV4msvJBuzat4TMCaMyU8030cbww79iPVF3Us642FyS7YznzTypPdFAnGyRXa/hRoLQFXXhrY69ACl8KHtQkqvyZE23C50= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1621442108326123.09297393309726; Wed, 19 May 2021 09:35:08 -0700 (PDT) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-598-QnP0CTNpOqu8K3bzShNZMg-1; Wed, 19 May 2021 12:35:05 -0400 Received: by mail-wm1-f71.google.com with SMTP id b206-20020a1c1bd70000b02901713122405eso831652wmb.1 for ; Wed, 19 May 2021 09:35:05 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id n129sm1401wma.19.2021.05.19.09.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 09:35:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621442107; 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=ntuPDGRvSJUugCXT9BaH6p28w2jINXWjbJZ/rFQ7At4=; b=LoTQoueo+O8iU5Q9urAJgeOaw8dPzLD5Gj1fbRLTojOfvTyc9zTS4JIlugIjH5PTGQxHlx Oqo3uC96fiaKLe+QutmPu5okSGsnWO1yQEBWFlFeQx0VmOndIqDPQhXsu/PPx4EwAWUknL H9JkxFluYyccoit9sdDhIKHZwZxIhaE= X-MC-Unique: QnP0CTNpOqu8K3bzShNZMg-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=ntuPDGRvSJUugCXT9BaH6p28w2jINXWjbJZ/rFQ7At4=; b=nRP1gVrRFYeeoEMHGH40gX0cN9hXS30VT1Cn4vUX/INEWqHX/ltSlrJd5WCkSRpvwS RiDH1v1DaKbZfTNU+JhqQxyx61S5jcWJ3qPmGEpQhoTxQN3a+rC1KxdQCE/AXtq49RAn 6+e56kuVLR6EEi61kh//6fXnq+w9UaxfkIYu2Zv5DsNMWUdPQPLLtrg8n2HI0LJBEzIc /KSfDiMsUixlG26Lq/fXvBEAlycBJqkfz/tA8mGiOmVUPWwBfRjyKowfmXVh0boQz1E0 WfvqpFfbNPyC1gNiuzkHa3L6K6OSkIL895LV5Oed0c1/H6Zk6fhnnllljU7DGDKmR6qH VXZA== X-Gm-Message-State: AOAM531u8LrphZ2vO1Sh3AqU4kidB4hCTo7SPK5caD9DSkNTpjgs8MBN rVi1VDnP7L/jt4Js2s8Y87sfWzHN92rdZ73hqLIggOWuskWFBpURmYRD0Iri0qwY+xjDK7NkGac V5LLYKkg+j9Ai+w== X-Received: by 2002:adf:ffd2:: with SMTP id x18mr15750398wrs.144.1621442103884; Wed, 19 May 2021 09:35:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaoIhbBdx083mlCjCuEXvdrUx1jFwCg5fNYku2rm0+TLo5EKeLr2qml/Hawtsnb4zohjLd8g== X-Received: by 2002:adf:ffd2:: with SMTP id x18mr15750357wrs.144.1621442103623; Wed, 19 May 2021 09:35:03 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: John Snow , qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Mark Cave-Ayland Subject: [PATCH v6 3/5] hw/block/fdc: Declare shared prototypes in fdc-internal.h Date: Wed, 19 May 2021 18:34:46 +0200 Message-Id: <20210519163448.2154339-4-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210519163448.2154339-1-philmd@redhat.com> References: <20210519163448.2154339-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 X-ZohoMail-DKIM: pass (identity @redhat.com) We want to extract ISA/SysBus code from the generic fdc.c file. First, declare the prototypes we will access from the new units into a new local header: "fdc-internal.h". Acked-by: Mark Cave-Ayland Reviewed-by: Mark Cave-Ayland Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/fdc-internal.h | 158 ++++++++++++++++++++++++++++++++++++++++ hw/block/fdc.c | 131 +++------------------------------ MAINTAINERS | 1 + 3 files changed, 168 insertions(+), 122 deletions(-) create mode 100644 hw/block/fdc-internal.h diff --git a/hw/block/fdc-internal.h b/hw/block/fdc-internal.h new file mode 100644 index 00000000000..036392e9fc1 --- /dev/null +++ b/hw/block/fdc-internal.h @@ -0,0 +1,158 @@ +/* + * 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. + */ +#ifndef HW_BLOCK_FDC_INTERNAL_H +#define HW_BLOCK_FDC_INTERNAL_H + +#include "exec/memory.h" +#include "exec/ioport.h" +#include "hw/block/block.h" +#include "hw/block/fdc.h" +#include "qapi/qapi-types-block.h" + +typedef struct FDCtrl FDCtrl; + +/* Floppy bus emulation */ + +typedef struct FloppyBus { + BusState bus; + FDCtrl *fdc; +} FloppyBus; + +/* Floppy disk drive emulation */ + +typedef enum FDriveRate { + FDRIVE_RATE_500K =3D 0x00, /* 500 Kbps */ + FDRIVE_RATE_300K =3D 0x01, /* 300 Kbps */ + FDRIVE_RATE_250K =3D 0x02, /* 250 Kbps */ + FDRIVE_RATE_1M =3D 0x03, /* 1 Mbps */ +} FDriveRate; + +typedef enum FDriveSize { + FDRIVE_SIZE_UNKNOWN, + FDRIVE_SIZE_350, + FDRIVE_SIZE_525, +} FDriveSize; + +typedef struct FDFormat { + FloppyDriveType drive; + uint8_t last_sect; + uint8_t max_track; + uint8_t max_head; + FDriveRate rate; +} FDFormat; + +typedef enum FDiskFlags { + FDISK_DBL_SIDES =3D 0x01, +} FDiskFlags; + +typedef struct FDrive { + FDCtrl *fdctrl; + BlockBackend *blk; + BlockConf *conf; + /* Drive status */ + FloppyDriveType drive; /* CMOS drive type */ + uint8_t perpendicular; /* 2.88 MB access mode */ + /* Position */ + uint8_t head; + uint8_t track; + uint8_t sect; + /* Media */ + FloppyDriveType disk; /* Current disk type */ + FDiskFlags flags; + uint8_t last_sect; /* Nb sector per track */ + uint8_t max_track; /* Nb of tracks */ + uint16_t bps; /* Bytes per sector */ + uint8_t ro; /* Is read-only */ + uint8_t media_changed; /* Is media changed */ + uint8_t media_rate; /* Data rate of medium */ + + bool media_validated; /* Have we validated the media? */ +} FDrive; + +struct FDCtrl { + MemoryRegion iomem; + qemu_irq irq; + /* Controller state */ + QEMUTimer *result_timer; + int dma_chann; + uint8_t phase; + IsaDma *dma; + /* Controller's identification */ + uint8_t version; + /* HW */ + uint8_t sra; + uint8_t srb; + uint8_t dor; + uint8_t dor_vmstate; /* only used as temp during vmstate */ + uint8_t tdr; + uint8_t dsr; + uint8_t msr; + uint8_t cur_drv; + uint8_t status0; + uint8_t status1; + uint8_t status2; + /* Command FIFO */ + uint8_t *fifo; + int32_t fifo_size; + uint32_t data_pos; + uint32_t data_len; + uint8_t data_state; + uint8_t data_dir; + uint8_t eot; /* last wanted sector */ + /* States kept only to be returned back */ + /* precompensation */ + uint8_t precomp_trk; + uint8_t config; + uint8_t lock; + /* Power down config (also with status regB access mode */ + uint8_t pwrd; + /* Floppy drives */ + FloppyBus bus; + uint8_t num_floppies; + FDrive drives[MAX_FD]; + struct { + FloppyDriveType type; + } qdev_for_drives[MAX_FD]; + int reset_sensei; + FloppyDriveType fallback; /* type=3Dauto failure fallback */ + /* Timers state */ + uint8_t timer0; + uint8_t timer1; + PortioList portio_list; +}; + +extern const FDFormat fd_formats[]; +extern const VMStateDescription vmstate_fdc; + +uint32_t fdctrl_read(void *opaque, uint32_t reg); +void fdctrl_write(void *opaque, uint32_t reg, uint32_t value); +void fdctrl_reset(FDCtrl *fdctrl, int do_irq); +void fdctrl_realize_common(DeviceState *dev, FDCtrl *fdctrl, Error **errp); + +int fdctrl_transfer_handler(void *opaque, int nchan, int dma_pos, int dma_= len); + +void fdctrl_init_drives(FloppyBus *bus, DriveInfo **fds); + +#endif diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 1d3a0473678..20ddeb98d83 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -48,6 +48,7 @@ #include "qemu/module.h" #include "trace.h" #include "qom/object.h" +#include "fdc-internal.h" =20 /********************************************************/ /* debug Floppy devices */ @@ -68,15 +69,8 @@ #define TYPE_FLOPPY_BUS "floppy-bus" OBJECT_DECLARE_SIMPLE_TYPE(FloppyBus, FLOPPY_BUS) =20 -typedef struct FDCtrl FDCtrl; -typedef struct FDrive FDrive; static FDrive *get_drv(FDCtrl *fdctrl, int unit); =20 -struct FloppyBus { - BusState bus; - FDCtrl *fdc; -}; - static const TypeInfo floppy_bus_info =3D { .name =3D TYPE_FLOPPY_BUS, .parent =3D TYPE_BUS, @@ -93,32 +87,11 @@ static void floppy_bus_create(FDCtrl *fdc, FloppyBus *b= us, DeviceState *dev) /********************************************************/ /* Floppy drive emulation */ =20 -typedef enum FDriveRate { - FDRIVE_RATE_500K =3D 0x00, /* 500 Kbps */ - FDRIVE_RATE_300K =3D 0x01, /* 300 Kbps */ - FDRIVE_RATE_250K =3D 0x02, /* 250 Kbps */ - FDRIVE_RATE_1M =3D 0x03, /* 1 Mbps */ -} FDriveRate; - -typedef enum FDriveSize { - FDRIVE_SIZE_UNKNOWN, - FDRIVE_SIZE_350, - FDRIVE_SIZE_525, -} FDriveSize; - -typedef struct FDFormat { - FloppyDriveType drive; - uint8_t last_sect; - uint8_t max_track; - uint8_t max_head; - FDriveRate rate; -} FDFormat; - /* In many cases, the total sector size of a format is enough to uniquely * identify it. However, there are some total sector collisions between * formats of different physical size, and these are noted below by * highlighting the total sector size for entries with collisions. */ -static const FDFormat fd_formats[] =3D { +const FDFormat fd_formats[] =3D { /* First entry is default format */ /* 1.44 MB 3"1/2 floppy disks */ { FLOPPY_DRIVE_TYPE_144, 18, 80, 1, FDRIVE_RATE_500K, }, /* 3.5" 2880 = */ @@ -186,35 +159,6 @@ static FDriveSize drive_size(FloppyDriveType drive) #define FD_SECTOR_SC 2 /* Sector size code */ #define FD_RESET_SENSEI_COUNT 4 /* Number of sense interrupts on RESET = */ =20 -/* Floppy disk drive emulation */ -typedef enum FDiskFlags { - FDISK_DBL_SIDES =3D 0x01, -} FDiskFlags; - -struct FDrive { - FDCtrl *fdctrl; - BlockBackend *blk; - BlockConf *conf; - /* Drive status */ - FloppyDriveType drive; /* CMOS drive type */ - uint8_t perpendicular; /* 2.88 MB access mode */ - /* Position */ - uint8_t head; - uint8_t track; - uint8_t sect; - /* Media */ - FloppyDriveType disk; /* Current disk type */ - FDiskFlags flags; - uint8_t last_sect; /* Nb sector per track */ - uint8_t max_track; /* Nb of tracks */ - uint16_t bps; /* Bytes per sector */ - uint8_t ro; /* Is read-only */ - uint8_t media_changed; /* Is media changed */ - uint8_t media_rate; /* Data rate of medium */ - - bool media_validated; /* Have we validated the media? */ -}; - =20 static FloppyDriveType get_fallback_drive_type(FDrive *drv); =20 @@ -626,10 +570,7 @@ static const TypeInfo floppy_drive_info =3D { /********************************************************/ /* Intel 82078 floppy disk controller emulation */ =20 -static void fdctrl_reset(FDCtrl *fdctrl, int do_irq); static void fdctrl_to_command_phase(FDCtrl *fdctrl); -static int fdctrl_transfer_handler (void *opaque, int nchan, - int dma_pos, int dma_len); static void fdctrl_raise_irq(FDCtrl *fdctrl); static FDrive *get_cur_drv(FDCtrl *fdctrl); =20 @@ -828,58 +769,6 @@ enum { #define FD_MULTI_TRACK(state) ((state) & FD_STATE_MULTI) #define FD_FORMAT_CMD(state) ((state) & FD_STATE_FORMAT) =20 -struct FDCtrl { - MemoryRegion iomem; - qemu_irq irq; - /* Controller state */ - QEMUTimer *result_timer; - int dma_chann; - uint8_t phase; - IsaDma *dma; - /* Controller's identification */ - uint8_t version; - /* HW */ - uint8_t sra; - uint8_t srb; - uint8_t dor; - uint8_t dor_vmstate; /* only used as temp during vmstate */ - uint8_t tdr; - uint8_t dsr; - uint8_t msr; - uint8_t cur_drv; - uint8_t status0; - uint8_t status1; - uint8_t status2; - /* Command FIFO */ - uint8_t *fifo; - int32_t fifo_size; - uint32_t data_pos; - uint32_t data_len; - uint8_t data_state; - uint8_t data_dir; - uint8_t eot; /* last wanted sector */ - /* States kept only to be returned back */ - /* precompensation */ - uint8_t precomp_trk; - uint8_t config; - uint8_t lock; - /* Power down config (also with status regB access mode */ - uint8_t pwrd; - /* Floppy drives */ - FloppyBus bus; - uint8_t num_floppies; - FDrive drives[MAX_FD]; - struct { - FloppyDriveType type; - } qdev_for_drives[MAX_FD]; - int reset_sensei; - FloppyDriveType fallback; /* type=3Dauto failure fallback */ - /* Timers state */ - uint8_t timer0; - uint8_t timer1; - PortioList portio_list; -}; - static FloppyDriveType get_fallback_drive_type(FDrive *drv) { return drv->fdctrl->fallback; @@ -909,7 +798,7 @@ struct FDCtrlISABus { int32_t bootindexB; }; =20 -static uint32_t fdctrl_read (void *opaque, uint32_t reg) +uint32_t fdctrl_read(void *opaque, uint32_t reg) { FDCtrl *fdctrl =3D opaque; uint32_t retval; @@ -946,7 +835,7 @@ static uint32_t fdctrl_read (void *opaque, uint32_t reg) return retval; } =20 -static void fdctrl_write (void *opaque, uint32_t reg, uint32_t value) +void fdctrl_write(void *opaque, uint32_t reg, uint32_t value) { FDCtrl *fdctrl =3D opaque; =20 @@ -1178,7 +1067,7 @@ static const VMStateDescription vmstate_fdc_phase =3D= { } }; =20 -static const VMStateDescription vmstate_fdc =3D { +const VMStateDescription vmstate_fdc =3D { .name =3D "fdc", .version_id =3D 2, .minimum_version_id =3D 2, @@ -1268,7 +1157,7 @@ static void fdctrl_raise_irq(FDCtrl *fdctrl) } =20 /* Reset controller */ -static void fdctrl_reset(FDCtrl *fdctrl, int do_irq) +void fdctrl_reset(FDCtrl *fdctrl, int do_irq) { int i; =20 @@ -1747,8 +1636,7 @@ static void fdctrl_start_transfer_del(FDCtrl *fdctrl,= int direction) } =20 /* handlers for DMA transfers */ -static int fdctrl_transfer_handler (void *opaque, int nchan, - int dma_pos, int dma_len) +int fdctrl_transfer_handler(void *opaque, int nchan, int dma_pos, int dma_= len) { FDCtrl *fdctrl; FDrive *cur_drv; @@ -2484,7 +2372,7 @@ static void fdctrl_result_timer(void *opaque) =20 /* Init functions */ =20 -static void fdctrl_init_drives(FloppyBus *bus, DriveInfo **fds) +void fdctrl_init_drives(FloppyBus *bus, DriveInfo **fds) { DeviceState *dev; int i; @@ -2542,8 +2430,7 @@ void sun4m_fdctrl_init(qemu_irq irq, hwaddr io_base, fdctrl_init_drives(&sys->state.bus, fds); } =20 -static void fdctrl_realize_common(DeviceState *dev, FDCtrl *fdctrl, - Error **errp) +void fdctrl_realize_common(DeviceState *dev, FDCtrl *fdctrl, Error **errp) { int i, j; FDrive *drive; diff --git a/MAINTAINERS b/MAINTAINERS index 8fa85e40a52..153335e8a2e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1659,6 +1659,7 @@ M: John Snow L: qemu-block@nongnu.org S: Supported F: hw/block/fdc.c +F: hw/block/fdc-internal.h F: hw/block/fdc-isa-stubs.c F: include/hw/block/fdc.h F: tests/qtest/fdc-test.c --=20 2.26.3