From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9C80C433C1 for ; Tue, 23 Mar 2021 12:56:25 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1416B619C2 for ; Tue, 23 Mar 2021 12:56:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1416B619C2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=eik.bme.hu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOga7-0004Nx-W2 for qemu-devel@archiver.kernel.org; Tue, 23 Mar 2021 08:56:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOgYm-0002uk-5e; Tue, 23 Mar 2021 08:55:00 -0400 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:63657) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOgYj-00043S-3o; Tue, 23 Mar 2021 08:54:59 -0400 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id EE7F3746353; Tue, 23 Mar 2021 13:54:51 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id B3577746344; Tue, 23 Mar 2021 13:54:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id B16FC74632F; Tue, 23 Mar 2021 13:54:51 +0100 (CET) Date: Tue, 23 Mar 2021 13:54:51 +0100 (CET) From: BALATON Zoltan To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Subject: Re: [PATCH v7 1/8] vt82c686: Implement control of serial port io ranges via config regs In-Reply-To: <8cf90aad5a9fce1a20cbf49e4ef71c51ba04faed.1615345138.git.balaton@eik.bme.hu> Message-ID: References: <8cf90aad5a9fce1a20cbf49e4ef71c51ba04faed.1615345138.git.balaton@eik.bme.hu> MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII Received-SPF: pass client-ip=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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: Peter Maydell , David Gibson , Mark Cave-Ayland , f4bug@amsat.org, Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Wed, 10 Mar 2021, BALATON Zoltan wrote: > In VIA super south bridge the io ranges of superio components > (parallel and serial ports and FDC) can be controlled by superio > config registers to set their base address and enable/disable them. > This is not easy to implement in QEMU because ISA emulation is only > designed to set io base address once on creating the device and io > ranges are registered at creation and cannot easily be disabled or > moved later. > > In this patch we hack around that but only for serial ports because > those have a single io range at port base that's relatively easy to > handle and it's what guests actually use and set address different > than the default. > > We do not attempt to handle controlling the parallel and FDC regions > because those have multiple io ranges so handling them would be messy > and guests either don't change their deafult or don't care. We could > even get away with disabling and not emulating them, but since they > are already there, this patch leaves them mapped at their default > address just in case this could be useful for a guest in the future. > > Signed-off-by: BALATON Zoltan Could this patch be reviewed now please? I've dropped it from later versions to avoid this holding back the series but now that it won't be in 6.0 I'd like to go back to this. This is implementing the behaviour of the real hardware better than the unsettable default value we have as a replacement. That approach also works for the guests I've tried (MorphOS and Linux) but if we can do better than why not do it? Regards, BALATON Zoltan > --- > hw/isa/vt82c686.c | 84 +++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 82 insertions(+), 2 deletions(-) > > diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c > index 05d084f698..a3353ec5db 100644 > --- a/hw/isa/vt82c686.c > +++ b/hw/isa/vt82c686.c > @@ -252,8 +252,24 @@ static const TypeInfo vt8231_pm_info = { > typedef struct SuperIOConfig { > uint8_t regs[0x100]; > MemoryRegion io; > + ISASuperIODevice *superio; > + MemoryRegion *serial_io[SUPERIO_MAX_SERIAL_PORTS]; > } SuperIOConfig; > > +static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent, > + int offs) > +{ > + MemoryRegion *subregion, *mr = NULL; > + > + QTAILQ_FOREACH(subregion, &parent->subregions, subregions_link) { > + if (subregion->addr == offs) { > + mr = subregion; > + break; > + } > + } > + return mr; > +} > + > static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data, > unsigned size) > { > @@ -279,7 +295,53 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data, > case 0xfd ... 0xff: > /* ignore write to read only registers */ > return; > - /* case 0xe6 ... 0xe8: Should set base port of parallel and serial */ > + case 0xe2: > + { > + data &= 0x1f; > + if (data & BIT(2)) { /* Serial port 1 enable */ > + ISADevice *dev = sc->superio->serial[0]; > + if (!memory_region_is_mapped(sc->serial_io[0])) { > + memory_region_add_subregion(isa_address_space_io(dev), > + dev->ioport_id, sc->serial_io[0]); > + } > + } else { > + MemoryRegion *io = isa_address_space_io(sc->superio->serial[0]); > + if (memory_region_is_mapped(sc->serial_io[0])) { > + memory_region_del_subregion(io, sc->serial_io[0]); > + } > + } > + if (data & BIT(3)) { /* Serial port 2 enable */ > + ISADevice *dev = sc->superio->serial[1]; > + if (!memory_region_is_mapped(sc->serial_io[1])) { > + memory_region_add_subregion(isa_address_space_io(dev), > + dev->ioport_id, sc->serial_io[1]); > + } > + } else { > + MemoryRegion *io = isa_address_space_io(sc->superio->serial[1]); > + if (memory_region_is_mapped(sc->serial_io[1])) { > + memory_region_del_subregion(io, sc->serial_io[1]); > + } > + } > + break; > + } > + case 0xe7: /* Serial port 1 io base address */ > + { > + data &= 0xfe; > + sc->superio->serial[0]->ioport_id = data << 2; > + if (memory_region_is_mapped(sc->serial_io[0])) { > + memory_region_set_address(sc->serial_io[0], data << 2); > + } > + break; > + } > + case 0xe8: /* Serial port 2 io base address */ > + { > + data &= 0xfe; > + sc->superio->serial[1]->ioport_id = data << 2; > + if (memory_region_is_mapped(sc->serial_io[1])) { > + memory_region_set_address(sc->serial_io[1], data << 2); > + } > + break; > + } > default: > qemu_log_mask(LOG_UNIMP, > "via_superio_cfg: unimplemented register 0x%x\n", idx); > @@ -385,6 +447,7 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp) > DeviceState *dev = DEVICE(d); > ISABus *isa_bus; > qemu_irq *isa_irq; > + ISASuperIOClass *ic; > int i; > > qdev_init_gpio_out(dev, &s->cpu_intr, 1); > @@ -394,7 +457,9 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp) > isa_bus_irqs(isa_bus, i8259_init(isa_bus, *isa_irq)); > i8254_pit_init(isa_bus, 0x40, 0, NULL); > i8257_dma_init(isa_bus, 0); > - isa_create_simple(isa_bus, TYPE_VT82C686B_SUPERIO); > + s->superio_cfg.superio = ISA_SUPERIO(isa_create_simple(isa_bus, > + TYPE_VT82C686B_SUPERIO)); > + ic = ISA_SUPERIO_GET_CLASS(s->superio_cfg.superio); > mc146818_rtc_init(isa_bus, 2000, NULL); > > for (i = 0; i < PCI_CONFIG_HEADER_SIZE; i++) { > @@ -412,6 +477,21 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp) > */ > memory_region_add_subregion(isa_bus->address_space_io, 0x3f0, > &s->superio_cfg.io); > + > + /* Grab io regions of serial devices so we can control them */ > + for (i = 0; i < ic->serial.count; i++) { > + ISADevice *sd = s->superio_cfg.superio->serial[i]; > + MemoryRegion *io = isa_address_space_io(sd); > + MemoryRegion *mr = find_subregion(sd, io, sd->ioport_id); > + if (!mr) { > + error_setg(errp, "Could not get io region for serial %d", i); > + return; > + } > + s->superio_cfg.serial_io[i] = mr; > + if (memory_region_is_mapped(mr)) { > + memory_region_del_subregion(io, mr); > + } > + } > } > > static void via_class_init(ObjectClass *klass, void *data) >