From nobody Sun Feb 8 23:20:27 2026 Delivered-To: importer@patchew.org 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; 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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576672438; cv=none; d=zohomail.com; s=zohoarc; b=U5StymMVlL8Hy21Nhq3lSboKI6eY9P8hwLz4PhzSOtGS8KwkaVB9fODhjFBS84/aKTSdZkdCgr99m0oxWXvFXUCqfiOIdI2a2vZxPt+hUUIvRtYPqxpwaZnoRFLtpvO9OXbs5fOMwi5o1oeVVm4xwwoc1A4cJJv+qP+OrmX6+Po= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576672438; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rDif3jIy3NQWrPrWp+OG7Re6McoAeV4H/8rGZ5nE6Ss=; b=iCp4ePM5fwz2MNBiIraOsHIkVnYX7S+O87w/q7Fkz+0iWydmm3JpziZndnl7WzR6vYMAOESTFPWNoNws8WoIs0loobddEs6foPFzoA5WiZvrL8byOXbpxshFLY7IzzYosG8q/7f37GKnkbdND4k1jot5LGnC5Fv/PyiiPy8jGls= ARC-Authentication-Results: i=1; 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+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576672438835877.3413501127798; Wed, 18 Dec 2019 04:33:58 -0800 (PST) Received: from localhost ([::1]:53532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihYWb-0005cl-4j for importer@patchew.org; Wed, 18 Dec 2019 07:33:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54294) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihY3h-00076L-8K for qemu-devel@nongnu.org; Wed, 18 Dec 2019 07:04:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihY3f-0002dK-Ex for qemu-devel@nongnu.org; Wed, 18 Dec 2019 07:04:05 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:39898) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ihY3f-0002XT-5M for qemu-devel@nongnu.org; Wed, 18 Dec 2019 07:04:03 -0500 Received: by mail-wm1-x344.google.com with SMTP id 20so1484074wmj.4 for ; Wed, 18 Dec 2019 04:04:03 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id n67sm2236838wmf.46.2019.12.18.04.04.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Dec 2019 04:04:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rDif3jIy3NQWrPrWp+OG7Re6McoAeV4H/8rGZ5nE6Ss=; b=OBzDOfj9RfWITy9p4YQA6RTKYI6Fxw9CapJ2CCN5wsUyLKZcCVUxf12hjExF6q9E93 2UtLbVruCIUs+AD03oog+vxuvuXUv0Xz/HlEy2QVS+zdFJyceaoh5A+ZRid4rM1+2Wea ZGp7BAMtLV/ibYnuWFcztwUB4gJB2FgAav27jEZYfa0tcb4SuCbW29ySIhF5Adh58xd5 nYPFVXqrNyBWrtjbZlkLX1wP5u8p2cnhi1aIuQ9ZzTaz7oUd7SdSNOLKQJpeQMVEvKUn ASPiGSqAIxlCg1hl1XGg8kDSfVkpJjkj2AVryduF1DQdEuw9vn4WkZDWT1LSIYcBSy0X aDLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=rDif3jIy3NQWrPrWp+OG7Re6McoAeV4H/8rGZ5nE6Ss=; b=tMPZpAAOMoPd9UPG7hfbFmowwuytMGXSPZNHy2E+6JAkSTdGJauGJw86LRx4msu6Dv 26T15Xmx7pqf8WSpZXk8DfizJt+mZuW0sp5tVd5NyWjTPDtcm3mbhts717rdQjoaYHE9 wYqbT5/haB8uw2GMS+diuwqWvac8MehOmy1kG+lnxSaoMk1t6rWyZy6w4xT6ByphNymI 1StXH7Y/R58+0WmljxGDruwmcQLgMlrIyj8Y4TMIT0GfRz/yQwdZxVunkzE/ONdzKJsg ltt6msfv3R4akdf1iPxEqfR+YAt5fZvsHWL1ot0yfdEChXJHVlTE9ZVqGqcdQARj79jj 3pMA== X-Gm-Message-State: APjAAAVPcIoqCniWTGzVy+DPOX7735RCS6qOd3FP9OskRHncyQFhMq9e 4GIh71rM5+v//e5oJbMcWcc+T+Rb X-Google-Smtp-Source: APXvYqw0UiYshy3Tu1qaEpr79/rkDbueK2ncAWYeC+eE1BiRIJ55nPdWWAw6bITv8tfJB1Y5a+ZUDQ== X-Received: by 2002:a1c:9e4c:: with SMTP id h73mr2799982wme.177.1576670641580; Wed, 18 Dec 2019 04:04:01 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 58/87] hw/i386/pc: Extract the port92 device Date: Wed, 18 Dec 2019 13:02:24 +0100 Message-Id: <1576670573-48048-59-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1576670573-48048-1-git-send-email-pbonzini@redhat.com> References: <1576670573-48048-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 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?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Philippe Mathieu-Daud=C3=A9 This device is only used by the PC machines. The pc.c file is already big enough, with 2255 lines. By removing 113 lines of it, we reduced it by 5%. It is now a bit easier to navigate the file. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Paolo Bonzini --- hw/i386/Makefile.objs | 1 + hw/i386/pc.c | 113 -------------------------------------------- hw/i386/port92.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/i386/trace-events | 2 +- include/hw/i386/pc.h | 3 ++ 5 files changed, 131 insertions(+), 114 deletions(-) create mode 100644 hw/i386/port92.c diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs index 1236c3b..8ce1b26 100644 --- a/hw/i386/Makefile.objs +++ b/hw/i386/Makefile.objs @@ -13,6 +13,7 @@ obj-$(CONFIG_AMD_IOMMU) +=3D amd_iommu.o obj-$(CONFIG_XEN) +=3D ../xenpv/ xen/ obj-$(CONFIG_VMPORT) +=3D vmport.o obj-$(CONFIG_VMMOUSE) +=3D vmmouse.o +obj-$(CONFIG_PC) +=3D port92.o =20 obj-y +=3D kvmvapic.o obj-$(CONFIG_PC) +=3D acpi-build.o diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e36053f..42014b0 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -673,119 +673,6 @@ void pc_cmos_init(PCMachineState *pcms, qemu_register_reset(pc_cmos_init_late, &arg); } =20 -#define TYPE_PORT92 "port92" -#define PORT92(obj) OBJECT_CHECK(Port92State, (obj), TYPE_PORT92) - -/* port 92 stuff: could be split off */ -typedef struct Port92State { - ISADevice parent_obj; - - MemoryRegion io; - uint8_t outport; - qemu_irq a20_out; -} Port92State; - -static void port92_write(void *opaque, hwaddr addr, uint64_t val, - unsigned size) -{ - Port92State *s =3D opaque; - int oldval =3D s->outport; - - trace_port92_write(val); - s->outport =3D val; - qemu_set_irq(s->a20_out, (val >> 1) & 1); - if ((val & 1) && !(oldval & 1)) { - qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); - } -} - -static uint64_t port92_read(void *opaque, hwaddr addr, - unsigned size) -{ - Port92State *s =3D opaque; - uint32_t ret; - - ret =3D s->outport; - trace_port92_read(ret); - return ret; -} - -static const VMStateDescription vmstate_port92_isa =3D { - .name =3D "port92", - .version_id =3D 1, - .minimum_version_id =3D 1, - .fields =3D (VMStateField[]) { - VMSTATE_UINT8(outport, Port92State), - VMSTATE_END_OF_LIST() - } -}; - -static void port92_reset(DeviceState *d) -{ - Port92State *s =3D PORT92(d); - - s->outport &=3D ~1; -} - -static const MemoryRegionOps port92_ops =3D { - .read =3D port92_read, - .write =3D port92_write, - .impl =3D { - .min_access_size =3D 1, - .max_access_size =3D 1, - }, - .endianness =3D DEVICE_LITTLE_ENDIAN, -}; - -static void port92_initfn(Object *obj) -{ - Port92State *s =3D PORT92(obj); - - memory_region_init_io(&s->io, OBJECT(s), &port92_ops, s, "port92", 1); - - s->outport =3D 0; - - qdev_init_gpio_out_named(DEVICE(obj), &s->a20_out, PORT92_A20_LINE, 1); -} - -static void port92_realizefn(DeviceState *dev, Error **errp) -{ - ISADevice *isadev =3D ISA_DEVICE(dev); - Port92State *s =3D PORT92(dev); - - isa_register_ioport(isadev, &s->io, 0x92); -} - -static void port92_class_initfn(ObjectClass *klass, void *data) -{ - DeviceClass *dc =3D DEVICE_CLASS(klass); - - dc->realize =3D port92_realizefn; - dc->reset =3D port92_reset; - dc->vmsd =3D &vmstate_port92_isa; - /* - * Reason: unlike ordinary ISA devices, this one needs additional - * wiring: its A20 output line needs to be wired up with - * qdev_connect_gpio_out_named(). - */ - dc->user_creatable =3D false; -} - -static const TypeInfo port92_info =3D { - .name =3D TYPE_PORT92, - .parent =3D TYPE_ISA_DEVICE, - .instance_size =3D sizeof(Port92State), - .instance_init =3D port92_initfn, - .class_init =3D port92_class_initfn, -}; - -static void port92_register_types(void) -{ - type_register_static(&port92_info); -} - -type_init(port92_register_types) - static void handle_a20_line_change(void *opaque, int irq, int level) { X86CPU *cpu =3D opaque; diff --git a/hw/i386/port92.c b/hw/i386/port92.c new file mode 100644 index 0000000..19866c4 --- /dev/null +++ b/hw/i386/port92.c @@ -0,0 +1,126 @@ +/* + * QEMU I/O port 0x92 (System Control Port A, to handle Fast Gate A20) + * + * Copyright (c) 2003-2004 Fabrice Bellard + * + * SPDX-License-Identifier: MIT + */ + +#include "qemu/osdep.h" +#include "sysemu/runstate.h" +#include "migration/vmstate.h" +#include "hw/irq.h" +#include "hw/i386/pc.h" +#include "trace.h" + +#define PORT92(obj) OBJECT_CHECK(Port92State, (obj), TYPE_PORT92) + +typedef struct Port92State { + ISADevice parent_obj; + + MemoryRegion io; + uint8_t outport; + qemu_irq a20_out; +} Port92State; + +static void port92_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size) +{ + Port92State *s =3D opaque; + int oldval =3D s->outport; + + trace_port92_write(val); + s->outport =3D val; + qemu_set_irq(s->a20_out, (val >> 1) & 1); + if ((val & 1) && !(oldval & 1)) { + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); + } +} + +static uint64_t port92_read(void *opaque, hwaddr addr, + unsigned size) +{ + Port92State *s =3D opaque; + uint32_t ret; + + ret =3D s->outport; + trace_port92_read(ret); + + return ret; +} + +static const VMStateDescription vmstate_port92_isa =3D { + .name =3D "port92", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8(outport, Port92State), + VMSTATE_END_OF_LIST() + } +}; + +static void port92_reset(DeviceState *d) +{ + Port92State *s =3D PORT92(d); + + s->outport &=3D ~1; +} + +static const MemoryRegionOps port92_ops =3D { + .read =3D port92_read, + .write =3D port92_write, + .impl =3D { + .min_access_size =3D 1, + .max_access_size =3D 1, + }, + .endianness =3D DEVICE_LITTLE_ENDIAN, +}; + +static void port92_initfn(Object *obj) +{ + Port92State *s =3D PORT92(obj); + + memory_region_init_io(&s->io, OBJECT(s), &port92_ops, s, "port92", 1); + + s->outport =3D 0; + + qdev_init_gpio_out_named(DEVICE(obj), &s->a20_out, PORT92_A20_LINE, 1); +} + +static void port92_realizefn(DeviceState *dev, Error **errp) +{ + ISADevice *isadev =3D ISA_DEVICE(dev); + Port92State *s =3D PORT92(dev); + + isa_register_ioport(isadev, &s->io, 0x92); +} + +static void port92_class_initfn(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->realize =3D port92_realizefn; + dc->reset =3D port92_reset; + dc->vmsd =3D &vmstate_port92_isa; + /* + * Reason: unlike ordinary ISA devices, this one needs additional + * wiring: its A20 output line needs to be wired up with + * qdev_connect_gpio_out_named(). + */ + dc->user_creatable =3D false; +} + +static const TypeInfo port92_info =3D { + .name =3D TYPE_PORT92, + .parent =3D TYPE_ISA_DEVICE, + .instance_size =3D sizeof(Port92State), + .instance_init =3D port92_initfn, + .class_init =3D port92_class_initfn, +}; + +static void port92_register_types(void) +{ + type_register_static(&port92_info); +} + +type_init(port92_register_types) diff --git a/hw/i386/trace-events b/hw/i386/trace-events index a9b6437..e48bef2 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -116,6 +116,6 @@ vmport_command(unsigned char command) "command: 0x%02x" x86_gsi_interrupt(int irqn, int level) "GSI interrupt #%d level:%d" x86_pic_interrupt(int irqn, int level) "PIC interrupt #%d level:%d" =20 -# pc.c +# port92.c port92_read(uint8_t val) "port92: read 0x%02x" port92_write(uint8_t val) "port92: write 0x%02x" diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 58aaa23..d5ac76d 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -196,8 +196,11 @@ void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_= irqs); ISADevice *pc_find_fdc0(void); int cmos_get_fd_drive_type(FloppyDriveType fd0); =20 +/* port92.c */ #define PORT92_A20_LINE "a20" =20 +#define TYPE_PORT92 "port92" + /* pc_sysfw.c */ void pc_system_flash_create(PCMachineState *pcms); void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memor= y); --=20 1.8.3.1