From nobody Sat Oct 25 08:57:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520285794368582.991523566335; Mon, 5 Mar 2018 13:36:34 -0800 (PST) Received: from localhost ([::1]:51701 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esxmX-0002Iv-Jw for importer@patchew.org; Mon, 05 Mar 2018 16:36:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esxWV-0004QH-8x for qemu-devel@nongnu.org; Mon, 05 Mar 2018 16:19:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esxWT-0001aS-EB for qemu-devel@nongnu.org; Mon, 05 Mar 2018 16:19:55 -0500 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:38491) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1esxWT-0001aC-3A; Mon, 05 Mar 2018 16:19:53 -0500 Received: by mail-wr0-x243.google.com with SMTP id n7so18805892wrn.5; Mon, 05 Mar 2018 13:19:53 -0800 (PST) Received: from x1.local (ABayonne-654-1-79-224.w86-222.abo.wanadoo.fr. [86.222.222.224]) by smtp.gmail.com with ESMTPSA id g96sm12904808wrd.73.2018.03.05.13.19.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Mar 2018 13:19:51 -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=EDEfYwpMGrgR1nDYzLP0TFaSRPmSsCRkHo47/1+rh4Y=; b=k4LAw0hLXs0bcilWWfib2V9ZABDsFx6xfuVJbdeN+6XXge+jeJN+PL3pbxSe8b/NUl nisEFv6r9w+tjWwl3Iwe+kdAYAvAIp70RY0zPoEKJshrFXp6QHTR0KHvxzAK0BcDlq2e khfdxks5oCuZRWshZ5qPecMgLAezcNTJSCYukka13t2WSjEr7p13hleHGclxKl2dkovZ p9gTkNxcqpAreeDcy7RpGlisOS9Xic8t49odvEd8pgq+DAN2w+ohK4wwkdHw7XOIAB/W rBZOPcw9MO2fye8BukrgA6/49r5AjDlxtamaR3ucNpMkUetY+Z32UDAkm8RBMS2IO2ly Y11w== 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=EDEfYwpMGrgR1nDYzLP0TFaSRPmSsCRkHo47/1+rh4Y=; b=bAtB/XYYIYuLgLVfyZkiv7mZdtRJZuw21tFNvBWBI1iU+ftnrBP/MyO9GYMqw9ZfVJ Esi0frLM11E2EreE5e79Y7lRANxT2AgfWNIEocxWxdQ6yiXpuhru7T9Qxif5nNmvNsbY WJ3yd1VJkZum10L+dczfsd7FVXFSU7u83dTQWN3v74cRLub/8P5+fyxOTB2g/MbuziZJ zpoi7yAWBdXXkJATqZca4f2iTGN+Hu17au/cjthAi6Dn3U4Yd0hlBBkJwwczAOTxS2Qn ljfU66YVILCi5sjW59qvC4pRMu6xeuu9TmURPi3hyJhrRQofPVRYSRHrCxph8wL9mDZ5 /x/Q== X-Gm-Message-State: APf1xPDPZaRR2Hk8ZepfPGHY7HEOHfyY1FVZk+DQdr6BDZ+3lIBgQuL3 AsvYVrtsBs4JJMzYicusHg0= X-Google-Smtp-Source: AG47ELujfriU0at7Lum05KlGtFIgt6L9WwXqY08RTaaxnjzacHZ4dk6a2AKaCS8K0SjMFDfCqyiwgg== X-Received: by 10.223.160.157 with SMTP id m29mr13814101wrm.119.1520284791969; Mon, 05 Mar 2018 13:19:51 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: "Michael S . Tsirkin" , Paolo Bonzini , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Marcel Apfelbaum , Aurelien Jarno , Mark Cave-Ayland , Alexey Kardashevskiy , Thomas Huth Date: Mon, 5 Mar 2018 18:19:15 -0300 Message-Id: <20180305211928.466-10-f4bug@amsat.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180305211928.466-1-f4bug@amsat.org> References: <20180305211928.466-1-f4bug@amsat.org> 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:400c:c0c::243 Subject: [Qemu-devel] [RFC PATCH v2 09/22] hw/isa/superio: Factor out the parallel code from pc87312.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, "open list:PReP" , Guan Xuetao , Yongbok Kim , Artyom Tarasenko , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/isa/pc87312.h | 4 --- include/hw/isa/superio.h | 6 +++++ hw/isa/isa-superio.c | 63 ++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/isa/pc87312.c | 38 ++++++++++++----------------- hw/isa/trace-events | 4 ++- 5 files changed, 87 insertions(+), 28 deletions(-) diff --git a/include/hw/isa/pc87312.h b/include/hw/isa/pc87312.h index f3761d6fe1..bcc4578479 100644 --- a/include/hw/isa/pc87312.h +++ b/include/hw/isa/pc87312.h @@ -39,10 +39,6 @@ typedef struct PC87312State { uint16_t iobase; uint8_t config; /* initial configuration */ =20 - struct { - ISADevice *dev; - } parallel; - struct { ISADevice *dev; } uart[2]; diff --git a/include/hw/isa/superio.h b/include/hw/isa/superio.h index cff6ad6c08..e9879cfde1 100644 --- a/include/hw/isa/superio.h +++ b/include/hw/isa/superio.h @@ -23,7 +23,11 @@ OBJECT_CLASS_CHECK(ISASuperIOClass, (klass), TYPE_ISA_SUPERIO) =20 typedef struct ISASuperIODevice { + /*< private >*/ ISADevice parent_obj; + /*< public >*/ + + ISADevice *parallel[MAX_PARALLEL_PORTS]; } ISASuperIODevice; =20 typedef struct ISASuperIOFuncs { @@ -39,6 +43,8 @@ typedef struct ISASuperIOClass { ISADeviceClass parent_class; /*< public >*/ DeviceRealize parent_realize; + + ISASuperIOFuncs parallel; } ISASuperIOClass; =20 #endif /* HW_ISA_SUPERIO_H */ diff --git a/hw/isa/isa-superio.c b/hw/isa/isa-superio.c index 7777f8b9f0..4e0b1af633 100644 --- a/hw/isa/isa-superio.c +++ b/hw/isa/isa-superio.c @@ -10,13 +10,76 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "sysemu/sysemu.h" +#include "chardev/char.h" #include "hw/isa/superio.h" #include "trace.h" =20 +static void isa_superio_realize(DeviceState *dev, Error **errp) +{ + ISASuperIODevice *sio =3D ISA_SUPERIO(dev); + ISASuperIOClass *k =3D ISA_SUPERIO_GET_CLASS(sio); + ISABus *bus =3D isa_bus_from_device(ISA_DEVICE(dev)); + ISADevice *isa; + DeviceState *d; + Chardev *chr; + char *name; + int i; + + /* Parallel port */ + for (i =3D 0; i < k->parallel.count; i++) { + if (i >=3D ARRAY_SIZE(sio->parallel)) { + warn_report("superio: ignoring %ld parallel controllers", + k->parallel.count - ARRAY_SIZE(sio->parallel)); + break; + } + if (!k->parallel.is_enabled || k->parallel.is_enabled(sio, i)) { + name =3D g_strdup_printf("discarding-parallel%d", i); + /* FIXME use a qdev chardev prop instead of parallel_hds[] */ + chr =3D parallel_hds[i]; + if (chr =3D=3D NULL || chr->be) { + chr =3D qemu_chr_new(name, "null"); + } + isa =3D isa_create(bus, "isa-parallel"); + d =3D DEVICE(isa); + qdev_prop_set_uint32(d, "index", i); + if (k->parallel.get_iobase) { + qdev_prop_set_uint32(d, "iobase", + k->parallel.get_iobase(sio, i)); + } + if (k->parallel.get_irq) { + qdev_prop_set_uint32(d, "irq", k->parallel.get_irq(sio, i)= ); + } + qdev_prop_set_chr(d, "chardev", chr); + qdev_init_nofail(d); + sio->parallel[i] =3D isa; + trace_superio_create_parallel(i, + k->parallel.get_iobase ? + k->parallel.get_iobase(sio, i) := -1, + k->parallel.get_irq ? + k->parallel.get_irq(sio, i) : -1= ); + object_property_add_child(OBJECT(dev), name, + OBJECT(sio->parallel[i]), NULL); + g_free(name); + } + } +} + +static void isa_superio_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + dc->realize =3D isa_superio_realize; + /* Reason: Uses parallel_hds[0] in realize(), so it can't be used twic= e */ + dc->user_creatable =3D false; +} + static const TypeInfo isa_superio_type_info =3D { .name =3D TYPE_ISA_SUPERIO, .parent =3D TYPE_ISA_DEVICE, .abstract =3D true, + .class_init =3D isa_superio_class_init, }; =20 static void isa_superio_register_types(void) diff --git a/hw/isa/pc87312.c b/hw/isa/pc87312.c index 6b8100ff56..1c15715c69 100644 --- a/hw/isa/pc87312.c +++ b/hw/isa/pc87312.c @@ -64,22 +64,25 @@ =20 /* Parallel port */ =20 -static inline bool is_parallel_enabled(PC87312State *s) +static bool is_parallel_enabled(ISASuperIODevice *sio, uint8_t index) { - return s->regs[REG_FER] & FER_PARALLEL_EN; + PC87312State *s =3D PC87312(sio); + return index ? false : s->regs[REG_FER] & FER_PARALLEL_EN; } =20 static const uint16_t parallel_base[] =3D { 0x378, 0x3bc, 0x278, 0x00 }; =20 -static inline uint16_t get_parallel_iobase(PC87312State *s) +static uint16_t get_parallel_iobase(ISASuperIODevice *sio, uint8_t index) { + PC87312State *s =3D PC87312(sio); return parallel_base[s->regs[REG_FAR] & FAR_PARALLEL_ADDR]; } =20 static const unsigned int parallel_irq[] =3D { 5, 7, 5, 0 }; =20 -static inline unsigned int get_parallel_irq(PC87312State *s) +static unsigned int get_parallel_irq(ISASuperIODevice *sio, uint8_t index) { + PC87312State *s =3D PC87312(sio); int idx; idx =3D (s->regs[REG_FAR] & FAR_PARALLEL_ADDR); if (idx =3D=3D 0) { @@ -286,24 +289,6 @@ static void pc87312_realize(DeviceState *dev, Error **= errp) return; } =20 - if (is_parallel_enabled(s)) { - /* FIXME use a qdev chardev prop instead of parallel_hds[] */ - chr =3D parallel_hds[0]; - if (chr =3D=3D NULL) { - chr =3D qemu_chr_new("par0", "null"); - } - isa =3D isa_create(bus, "isa-parallel"); - d =3D DEVICE(isa); - qdev_prop_set_uint32(d, "index", 0); - qdev_prop_set_uint32(d, "iobase", get_parallel_iobase(s)); - qdev_prop_set_uint32(d, "irq", get_parallel_irq(s)); - qdev_prop_set_chr(d, "chardev", chr); - qdev_init_nofail(d); - s->parallel.dev =3D isa; - trace_pc87312_info_parallel(get_parallel_iobase(s), - get_parallel_irq(s)); - } - for (i =3D 0; i < 2; i++) { if (is_uart_enabled(s, i)) { /* FIXME use a qdev chardev prop instead of serial_hds[] */ @@ -395,8 +380,15 @@ static void pc87312_class_init(ObjectClass *klass, voi= d *data) dc->reset =3D pc87312_reset; dc->vmsd =3D &vmstate_pc87312; dc->props =3D pc87312_properties; - /* Reason: Uses parallel_hds[0] in realize(), so it can't be used twic= e */ + /* Reason: Uses serial_hds[0] in realize(), so it can't be used twice = */ dc->user_creatable =3D false; + + sc->parallel =3D (ISASuperIOFuncs){ + .count =3D 1, + .is_enabled =3D is_parallel_enabled, + .get_iobase =3D get_parallel_iobase, + .get_irq =3D get_parallel_irq, + }; } =20 static const TypeInfo pc87312_type_info =3D { diff --git a/hw/isa/trace-events b/hw/isa/trace-events index a4ab4e3634..97b1949981 100644 --- a/hw/isa/trace-events +++ b/hw/isa/trace-events @@ -1,9 +1,11 @@ # See docs/devel/tracing.txt for syntax documentation. =20 +# hw/isa/isa-superio.c +superio_create_parallel(int id, uint16_t base, unsigned int irq) "id=3D%d,= base 0x%03x, irq %u" + # hw/isa/pc87312.c pc87312_io_read(uint32_t addr, uint32_t val) "read addr=3D0x%x val=3D0x%x" pc87312_io_write(uint32_t addr, uint32_t val) "write addr=3D0x%x val=3D0x%= x" pc87312_info_floppy(uint32_t base) "base 0x%x" pc87312_info_ide(uint32_t base) "base 0x%x" -pc87312_info_parallel(uint32_t base, uint32_t irq) "base 0x%x, irq %u" pc87312_info_serial(int n, uint32_t base, uint32_t irq) "id=3D%d, base 0x%= x, irq %u" --=20 2.16.2