From nobody Thu Nov 14 17:50:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1708339781; cv=none; d=zohomail.com; s=zohoarc; b=BdBTwpRIdmY/ci3ZvMJbQiBMjPOl1R3B+Jpj6A+X8Y2d29hfIhESRCCAXv83283ImonVhzCwt9rEMK1FsjT1eRGwA8r3ynKyU0L2KN0qh6D0Oz6aeVBUJvQCEkBozCS/l3A7TrXp6eUK+iMuhgRHuE3p6Ip+ZOpjSQeWzGttahI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708339781; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=frInq5lYNhgswM3qhuQ1Q1cEDEC6RAK86KLi0mpbFYU=; b=hUA/gjOV32ST4XrPpM9PnewfStvzrGDHBLexfAMJW0dY/t5GV+F6WJfv68RxP5AMyVa5y0TWOHhb7IqvDBu4jhPn7bry2WpKGtUDULAGCNMk9KBWGCm4ZkHROqVNh1zk9aW3c40CS2rHdHVfO5K4t5dvK/PscKIkORvieRH7u+M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708339781603630.8495231497858; Mon, 19 Feb 2024 02:49:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rc1DG-0003tP-Kb; Mon, 19 Feb 2024 05:49:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rc1DC-0003sz-Nf for qemu-devel@nongnu.org; Mon, 19 Feb 2024 05:49:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rc1DA-00017H-Gw for qemu-devel@nongnu.org; Mon, 19 Feb 2024 05:49:26 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-257-JWktU7JGOpyDQXZDTc1XRQ-1; Mon, 19 Feb 2024 05:49:20 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C20C81C41A0A; Mon, 19 Feb 2024 10:49:19 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47B321C10C19; Mon, 19 Feb 2024 10:49:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708339763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=frInq5lYNhgswM3qhuQ1Q1cEDEC6RAK86KLi0mpbFYU=; b=GD+9WHAH++Rp4oH7xj87EFHmUX5WqmkFvCJnC96M7dmuhnZvP42TWrXF55tMuKNEYAGKrL QKoVH5SE9uun+uipzTMuLSOjOVwfXix2tQcQxX6hxIJ2XGWJavBvZDs/1VUJEgFVrnQw5W DHA/OtXQ3uS3la7ahK0JSkvoNjfVOT8= X-MC-Unique: JWktU7JGOpyDQXZDTc1XRQ-1 From: Thomas Huth To: John Snow , qemu-devel@nongnu.org Cc: BALATON Zoltan , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org Subject: [PATCH 2/7] hw/ide: Split qdev.c into ide-bus.c and ide-dev.c Date: Mon, 19 Feb 2024 11:49:07 +0100 Message-ID: <20240219104912.378211-3-thuth@redhat.com> In-Reply-To: <20240219104912.378211-1-thuth@redhat.com> References: <20240219104912.378211-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.077, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1708339782530100001 Content-Type: text/plain; charset="utf-8" qdev.c is a mixture between IDE bus specific functions and IDE device functions. Let's split it up to make it more obvious which part is related to bus handling and which part is related to device handling. Signed-off-by: Thomas Huth --- hw/ide/ide-bus.c | 111 +++++++++++++++++++++++++++++++++++ hw/ide/{qdev.c =3D> ide-dev.c} | 87 +-------------------------- hw/arm/Kconfig | 2 + hw/ide/Kconfig | 30 ++++++---- hw/ide/meson.build | 3 +- 5 files changed, 134 insertions(+), 99 deletions(-) create mode 100644 hw/ide/ide-bus.c rename hw/ide/{qdev.c =3D> ide-dev.c} (78%) diff --git a/hw/ide/ide-bus.c b/hw/ide/ide-bus.c new file mode 100644 index 0000000000..57fe67b29c --- /dev/null +++ b/hw/ide/ide-bus.c @@ -0,0 +1,111 @@ +/* + * ide bus support for qdev. + * + * Copyright (c) 2009 Gerd Hoffmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/module.h" +#include "hw/ide/internal.h" +#include "sysemu/block-backend.h" +#include "sysemu/blockdev.h" +#include "sysemu/runstate.h" + +static char *idebus_get_fw_dev_path(DeviceState *dev); +static void idebus_unrealize(BusState *qdev); + +static void ide_bus_class_init(ObjectClass *klass, void *data) +{ + BusClass *k =3D BUS_CLASS(klass); + + k->get_fw_dev_path =3D idebus_get_fw_dev_path; + k->unrealize =3D idebus_unrealize; +} + +static void idebus_unrealize(BusState *bus) +{ + IDEBus *ibus =3D IDE_BUS(bus); + + if (ibus->vmstate) { + qemu_del_vm_change_state_handler(ibus->vmstate); + } +} + +static const TypeInfo ide_bus_info =3D { + .name =3D TYPE_IDE_BUS, + .parent =3D TYPE_BUS, + .instance_size =3D sizeof(IDEBus), + .class_init =3D ide_bus_class_init, +}; + +void ide_bus_init(IDEBus *idebus, size_t idebus_size, DeviceState *dev, + int bus_id, int max_units) +{ + qbus_init(idebus, idebus_size, TYPE_IDE_BUS, dev, NULL); + idebus->bus_id =3D bus_id; + idebus->max_units =3D max_units; +} + +static char *idebus_get_fw_dev_path(DeviceState *dev) +{ + char path[30]; + + snprintf(path, sizeof(path), "%s@%x", qdev_fw_name(dev), + ((IDEBus *)dev->parent_bus)->bus_id); + + return g_strdup(path); +} + +IDEDevice *ide_bus_create_drive(IDEBus *bus, int unit, DriveInfo *drive) +{ + DeviceState *dev; + + dev =3D qdev_new(drive->media_cd ? "ide-cd" : "ide-hd"); + qdev_prop_set_uint32(dev, "unit", unit); + qdev_prop_set_drive_err(dev, "drive", blk_by_legacy_dinfo(drive), + &error_fatal); + qdev_realize_and_unref(dev, &bus->qbus, &error_fatal); + return DO_UPCAST(IDEDevice, qdev, dev); +} + +int ide_get_geometry(BusState *bus, int unit, + int16_t *cyls, int8_t *heads, int8_t *secs) +{ + IDEState *s =3D &DO_UPCAST(IDEBus, qbus, bus)->ifs[unit]; + + if (s->drive_kind !=3D IDE_HD || !s->blk) { + return -1; + } + + *cyls =3D s->cylinders; + *heads =3D s->heads; + *secs =3D s->sectors; + return 0; +} + +int ide_get_bios_chs_trans(BusState *bus, int unit) +{ + return DO_UPCAST(IDEBus, qbus, bus)->ifs[unit].chs_trans; +} + +static void ide_bus_register_type(void) +{ + type_register_static(&ide_bus_info); +} + +type_init(ide_bus_register_type) diff --git a/hw/ide/qdev.c b/hw/ide/ide-dev.c similarity index 78% rename from hw/ide/qdev.c rename to hw/ide/ide-dev.c index 4189313d30..15d088fd06 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/ide-dev.c @@ -1,5 +1,5 @@ /* - * ide bus support for qdev. + * IDE device functions * * Copyright (c) 2009 Gerd Hoffmann * @@ -18,71 +18,21 @@ */ =20 #include "qemu/osdep.h" -#include "sysemu/dma.h" #include "qapi/error.h" #include "qapi/qapi-types-block.h" #include "qemu/error-report.h" -#include "qemu/main-loop.h" #include "qemu/module.h" #include "hw/ide/ide-dev.h" #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "sysemu/sysemu.h" -#include "sysemu/runstate.h" #include "qapi/visitor.h" =20 -/* --------------------------------- */ - -static char *idebus_get_fw_dev_path(DeviceState *dev); -static void idebus_unrealize(BusState *qdev); - static Property ide_props[] =3D { DEFINE_PROP_UINT32("unit", IDEDevice, unit, -1), DEFINE_PROP_END_OF_LIST(), }; =20 -static void ide_bus_class_init(ObjectClass *klass, void *data) -{ - BusClass *k =3D BUS_CLASS(klass); - - k->get_fw_dev_path =3D idebus_get_fw_dev_path; - k->unrealize =3D idebus_unrealize; -} - -static void idebus_unrealize(BusState *bus) -{ - IDEBus *ibus =3D IDE_BUS(bus); - - if (ibus->vmstate) { - qemu_del_vm_change_state_handler(ibus->vmstate); - } -} - -static const TypeInfo ide_bus_info =3D { - .name =3D TYPE_IDE_BUS, - .parent =3D TYPE_BUS, - .instance_size =3D sizeof(IDEBus), - .class_init =3D ide_bus_class_init, -}; - -void ide_bus_init(IDEBus *idebus, size_t idebus_size, DeviceState *dev, - int bus_id, int max_units) -{ - qbus_init(idebus, idebus_size, TYPE_IDE_BUS, dev, NULL); - idebus->bus_id =3D bus_id; - idebus->max_units =3D max_units; -} - -static char *idebus_get_fw_dev_path(DeviceState *dev) -{ - char path[30]; - - snprintf(path, sizeof(path), "%s@%x", qdev_fw_name(dev), - ((IDEBus*)dev->parent_bus)->bus_id); - - return g_strdup(path); -} - static void ide_qdev_realize(DeviceState *qdev, Error **errp) { IDEDevice *dev =3D IDE_DEVICE(qdev); @@ -121,40 +71,6 @@ static void ide_qdev_realize(DeviceState *qdev, Error *= *errp) dc->realize(dev, errp); } =20 -IDEDevice *ide_bus_create_drive(IDEBus *bus, int unit, DriveInfo *drive) -{ - DeviceState *dev; - - dev =3D qdev_new(drive->media_cd ? "ide-cd" : "ide-hd"); - qdev_prop_set_uint32(dev, "unit", unit); - qdev_prop_set_drive_err(dev, "drive", blk_by_legacy_dinfo(drive), - &error_fatal); - qdev_realize_and_unref(dev, &bus->qbus, &error_fatal); - return DO_UPCAST(IDEDevice, qdev, dev); -} - -int ide_get_geometry(BusState *bus, int unit, - int16_t *cyls, int8_t *heads, int8_t *secs) -{ - IDEState *s =3D &DO_UPCAST(IDEBus, qbus, bus)->ifs[unit]; - - if (s->drive_kind !=3D IDE_HD || !s->blk) { - return -1; - } - - *cyls =3D s->cylinders; - *heads =3D s->heads; - *secs =3D s->sectors; - return 0; -} - -int ide_get_bios_chs_trans(BusState *bus, int unit) -{ - return DO_UPCAST(IDEBus, qbus, bus)->ifs[unit].chs_trans; -} - -/* --------------------------------- */ - void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp) { IDEBus *bus =3D DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus); @@ -347,7 +263,6 @@ static const TypeInfo ide_device_type_info =3D { =20 static void ide_register_types(void) { - type_register_static(&ide_bus_info); type_register_static(&ide_hd_info); type_register_static(&ide_cd_info); type_register_static(&ide_device_type_info); diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 29abe1da29..b372b819a4 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -275,6 +275,8 @@ config SBSA_REF select USB_XHCI_SYSBUS select WDT_SBSA select BOCHS_DISPLAY + select IDE_BUS + select IDE_DEV =20 config SABRELITE bool diff --git a/hw/ide/Kconfig b/hw/ide/Kconfig index b93d6743d5..6dfc5a2129 100644 --- a/hw/ide/Kconfig +++ b/hw/ide/Kconfig @@ -1,51 +1,58 @@ config IDE_CORE bool =20 -config IDE_QDEV +config IDE_BUS bool select IDE_CORE =20 +config IDE_DEV + bool + depends on IDE_BUS + config IDE_PCI bool depends on PCI - select IDE_QDEV + select IDE_BUS + select IDE_DEV =20 config IDE_ISA bool depends on ISA_BUS - select IDE_QDEV + select IDE_BUS + select IDE_DEV =20 config IDE_PIIX bool select IDE_PCI - select IDE_QDEV =20 config IDE_CMD646 bool select IDE_PCI - select IDE_QDEV =20 config IDE_MACIO bool - select IDE_QDEV + select IDE_BUS + select IDE_DEV =20 config IDE_MMIO bool - select IDE_QDEV + select IDE_BUS + select IDE_DEV =20 config IDE_VIA bool select IDE_PCI - select IDE_QDEV =20 config MICRODRIVE bool - select IDE_QDEV + select IDE_BUS + select IDE_DEV depends on PCMCIA =20 config AHCI bool - select IDE_QDEV + select IDE_BUS + select IDE_DEV =20 config AHCI_ICH9 bool @@ -56,8 +63,7 @@ config AHCI_ICH9 config IDE_SII3112 bool select IDE_PCI - select IDE_QDEV =20 config IDE_CF bool - default y if IDE_QDEV + default y if IDE_BUS diff --git a/hw/ide/meson.build b/hw/ide/meson.build index d2e5b45c9e..d09705cac0 100644 --- a/hw/ide/meson.build +++ b/hw/ide/meson.build @@ -1,15 +1,16 @@ system_ss.add(when: 'CONFIG_AHCI', if_true: files('ahci.c')) system_ss.add(when: 'CONFIG_AHCI_ICH9', if_true: files('ich.c')) system_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('ahci-allwinner= .c')) +system_ss.add(when: 'CONFIG_IDE_BUS', if_true: files('ide-bus.c')) system_ss.add(when: 'CONFIG_IDE_CF', if_true: files('cf.c')) system_ss.add(when: 'CONFIG_IDE_CMD646', if_true: files('cmd646.c')) system_ss.add(when: 'CONFIG_IDE_CORE', if_true: files('core.c', 'atapi.c')) +system_ss.add(when: 'CONFIG_IDE_DEV', if_true: files('ide-dev.c')) system_ss.add(when: 'CONFIG_IDE_ISA', if_true: files('isa.c', 'ioport.c')) system_ss.add(when: 'CONFIG_IDE_MACIO', if_true: files('macio.c')) system_ss.add(when: 'CONFIG_IDE_MMIO', if_true: files('mmio.c')) system_ss.add(when: 'CONFIG_IDE_PCI', if_true: files('pci.c')) system_ss.add(when: 'CONFIG_IDE_PIIX', if_true: files('piix.c', 'ioport.c'= )) -system_ss.add(when: 'CONFIG_IDE_QDEV', if_true: files('qdev.c')) system_ss.add(when: 'CONFIG_IDE_SII3112', if_true: files('sii3112.c')) system_ss.add(when: 'CONFIG_IDE_VIA', if_true: files('via.c')) system_ss.add(when: 'CONFIG_MICRODRIVE', if_true: files('microdrive.c')) --=20 2.43.2