From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224378; cv=none; d=zohomail.com; s=zohoarc; b=DXm2DYt9JYrSWXx6kEWzybQD3yQSfWSCPh6EpBQeyO/MfbLyiAfJbJ8VOPM4Vv5hmqRIbtr9G+kiDi+75EHhDYs0KhnUAa7DfzTCvJ0+DT7MiKPz9DNvF2ERyAs7pXsKeL2IFJtwfeQtMvlK1X2dnISheKuqaWd6xpmBJjZWyaY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224378; 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=WHFOSMKWAhZPmpZAANPGNKP2hOQYBufdgR6yKnJMQxE=; b=m0rt3VdavJd3sX9+ny3qs84AGIByoMkshUibpfuehFgR2Nbl/++xgTzCtKPnGTAswcYBJOR4A25IqrNgT7mXN5NWRi5AiORyIk87M35wXZIEef0rsFt9q0Vt5R9wwfwXyaKt/4lpndRKUWdLRlifsAlPGF6wyhhx5yMbLBKHWZE= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1610224378394357.7459168075562; Sat, 9 Jan 2021 12:32:58 -0800 (PST) Received: from localhost ([::1]:42890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyKuu-0001rs-Bf for importer@patchew.org; Sat, 09 Jan 2021 15:32:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41942) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsB-0008O9-KO for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:09 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:33369) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKs5-00078Q-Od for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:07 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id D6DD2747611; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 4CE3F7470FC; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 01/13] vt82c686: Move superio memory region to SuperIOConfig struct Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The superio memory region holds the io space index/data registers used to access the superio config registers that are implemented in struct SuperIOConfig. To keep these related things together move the memory region to SuperIOConfig and rename it accordingly. Also remove the unused "data" member of SuperIOConfig which is not needed as we store actual data values in the regs array. Signed-off-by: BALATON Zoltan Reviewed-by: Jiaxun Yang Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/isa/vt82c686.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index a6f5a0843d..30fe02f4c6 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -29,12 +29,11 @@ typedef struct SuperIOConfig { uint8_t regs[0x100]; uint8_t index; - uint8_t data; + MemoryRegion io; } SuperIOConfig; =20 struct VT82C686BISAState { PCIDevice dev; - MemoryRegion superio; SuperIOConfig superio_cfg; }; =20 @@ -128,8 +127,9 @@ static void vt82c686b_write_config(PCIDevice *d, uint32= _t addr, =20 trace_via_isa_write(addr, val, len); pci_default_write_config(d, addr, val, len); - if (addr =3D=3D 0x85) { /* enable or disable super IO configure */ - memory_region_set_enabled(&s->superio, val & 0x2); + if (addr =3D=3D 0x85) { + /* BIT(1): enable or disable superio config io ports */ + memory_region_set_enabled(&s->superio_cfg.io, val & BIT(1)); } } =20 @@ -311,15 +311,15 @@ static void vt82c686b_realize(PCIDevice *d, Error **e= rrp) } } =20 - memory_region_init_io(&s->superio, OBJECT(d), &superio_cfg_ops, - &s->superio_cfg, "superio", 2); - memory_region_set_enabled(&s->superio, false); + memory_region_init_io(&s->superio_cfg.io, OBJECT(d), &superio_cfg_ops, + &s->superio_cfg, "superio_cfg", 2); + memory_region_set_enabled(&s->superio_cfg.io, false); /* * The floppy also uses 0x3f0 and 0x3f1. * But we do not emulate a floppy, so just set it here. */ memory_region_add_subregion(isa_bus->address_space_io, 0x3f0, - &s->superio); + &s->superio_cfg.io); } =20 static void via_class_init(ObjectClass *klass, void *data) --=20 2.21.3 From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224649; cv=none; d=zohomail.com; s=zohoarc; b=f3PZRoc2DLPYXdpHKQQeSk9guhsybXOqdtpJ8ZFaYd95KfsJwLmQBpxVhHxHJh2Uw8MLz2OC+83KrO0ixitmHC88xELP0/owpUSJ4tT97wOcJoItOZtDG+Wvjx8zRyIo80hc+NgDZaIQxOQlwtKhVDTe0XLAPmBMYkR7SkpTyy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224649; 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=gPWDh08iT4XBEmRqx6Pjbg3pZXFfcxpj+16nizWe2bQ=; b=esdS/10aUGcDAReZMaHSs57E8F8qNEAga9NKHTN+pLt/hma9ByJDSmgGlC4lyKNSRIoqzXWKpzaxq6KvUS8GmPCDtdA2LjjX3BUbx/oWadvdqcoraA2H5rQvjgZS/CEEGSF/87ezg+oYyefYuX90mlxDo/XoL7Ur8pWVfKUcn1A= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1610224649591794.8209998853796; Sat, 9 Jan 2021 12:37:29 -0800 (PST) Received: from localhost ([::1]:57004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyKzI-0007qK-CV for importer@patchew.org; Sat, 09 Jan 2021 15:37:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42020) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsL-0008Ra-CY for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:18 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:33367) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKs5-00078S-Of for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:16 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id EC984747637; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 534697475FE; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: <9f942989dba46fc1c23b881f6cb135948f818c2f.1610223397.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 02/13] vt82c686: Reorganise code Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=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=unavailable 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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Move lines around so that object definitions become consecutive and not scattered around. This brings functions belonging to an object together so it's clearer what is defined and what parts belong to which object. Signed-off-by: BALATON Zoltan Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/isa/vt82c686.c | 279 +++++++++++++++++++++++----------------------- 1 file changed, 140 insertions(+), 139 deletions(-) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index 30fe02f4c6..fe8961b057 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -26,112 +26,7 @@ #include "exec/address-spaces.h" #include "trace.h" =20 -typedef struct SuperIOConfig { - uint8_t regs[0x100]; - uint8_t index; - MemoryRegion io; -} SuperIOConfig; - -struct VT82C686BISAState { - PCIDevice dev; - SuperIOConfig superio_cfg; -}; - -OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686B_ISA) - -static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data, - unsigned size) -{ - SuperIOConfig *sc =3D opaque; - - if (addr =3D=3D 0x3f0) { /* config index register */ - sc->index =3D data & 0xff; - } else { - bool can_write =3D true; - /* 0x3f1, config data register */ - trace_via_superio_write(sc->index, data & 0xff); - switch (sc->index) { - case 0x00 ... 0xdf: - case 0xe4: - case 0xe5: - case 0xe9 ... 0xed: - case 0xf3: - case 0xf5: - case 0xf7: - case 0xf9 ... 0xfb: - case 0xfd ... 0xff: - can_write =3D false; - break; - /* case 0xe6 ... 0xe8: Should set base port of parallel and serial= */ - default: - break; - - } - if (can_write) { - sc->regs[sc->index] =3D data & 0xff; - } - } -} - -static uint64_t superio_cfg_read(void *opaque, hwaddr addr, unsigned size) -{ - SuperIOConfig *sc =3D opaque; - uint8_t val =3D sc->regs[sc->index]; - - trace_via_superio_read(sc->index, val); - return val; -} - -static const MemoryRegionOps superio_cfg_ops =3D { - .read =3D superio_cfg_read, - .write =3D superio_cfg_write, - .endianness =3D DEVICE_NATIVE_ENDIAN, - .impl =3D { - .min_access_size =3D 1, - .max_access_size =3D 1, - }, -}; - -static void vt82c686b_isa_reset(DeviceState *dev) -{ - VT82C686BISAState *s =3D VT82C686B_ISA(dev); - uint8_t *pci_conf =3D s->dev.config; - - pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x000000c0); - pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMO= RY | - PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL); - pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM); - - pci_conf[0x48] =3D 0x01; /* Miscellaneous Control 3 */ - pci_conf[0x4a] =3D 0x04; /* IDE interrupt Routing */ - pci_conf[0x4f] =3D 0x03; /* DMA/Master Mem Access Control 3 */ - pci_conf[0x50] =3D 0x2d; /* PnP DMA Request Control */ - pci_conf[0x59] =3D 0x04; - pci_conf[0x5a] =3D 0x04; /* KBC/RTC Control*/ - pci_conf[0x5f] =3D 0x04; - pci_conf[0x77] =3D 0x10; /* GPIO Control 1/2/3/4 */ - - s->superio_cfg.regs[0xe0] =3D 0x3c; /* Device ID */ - s->superio_cfg.regs[0xe2] =3D 0x03; /* Function select */ - s->superio_cfg.regs[0xe3] =3D 0xfc; /* Floppy ctrl base addr */ - s->superio_cfg.regs[0xe6] =3D 0xde; /* Parallel port base addr */ - s->superio_cfg.regs[0xe7] =3D 0xfe; /* Serial port 1 base addr */ - s->superio_cfg.regs[0xe8] =3D 0xbe; /* Serial port 2 base addr */ -} - -/* write config pci function0 registers. PCI-ISA bridge */ -static void vt82c686b_write_config(PCIDevice *d, uint32_t addr, - uint32_t val, int len) -{ - VT82C686BISAState *s =3D VT82C686B_ISA(d); - - trace_via_isa_write(addr, val, len); - pci_default_write_config(d, addr, val, len); - if (addr =3D=3D 0x85) { - /* BIT(1): enable or disable superio config io ports */ - memory_region_set_enabled(&s->superio_cfg.io, val & BIT(1)); - } -} +OBJECT_DECLARE_SIMPLE_TYPE(VT686PMState, VT82C686B_PM) =20 struct VT686PMState { PCIDevice dev; @@ -142,30 +37,6 @@ struct VT686PMState { uint32_t smb_io_base; }; =20 -OBJECT_DECLARE_SIMPLE_TYPE(VT686PMState, VT82C686B_PM) - -static void pm_update_sci(VT686PMState *s) -{ - int sci_level, pmsts; - - pmsts =3D acpi_pm1_evt_get_sts(&s->ar); - sci_level =3D (((pmsts & s->ar.pm1.evt.en) & - (ACPI_BITMASK_RT_CLOCK_ENABLE | - ACPI_BITMASK_POWER_BUTTON_ENABLE | - ACPI_BITMASK_GLOBAL_LOCK_ENABLE | - ACPI_BITMASK_TIMER_ENABLE)) !=3D 0); - pci_set_irq(&s->dev, sci_level); - /* schedule a timer interruption if needed */ - acpi_pm_tmr_update(&s->ar, (s->ar.pm1.evt.en & ACPI_BITMASK_TIMER_ENAB= LE) && - !(pmsts & ACPI_BITMASK_TIMER_STATUS)); -} - -static void pm_tmr_timer(ACPIREGS *ar) -{ - VT686PMState *s =3D container_of(ar, VT686PMState, ar); - pm_update_sci(s); -} - static void pm_io_space_update(VT686PMState *s) { uint32_t pm_io_base; @@ -179,12 +50,6 @@ static void pm_io_space_update(VT686PMState *s) memory_region_transaction_commit(); } =20 -static void pm_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int= len) -{ - trace_via_pm_write(addr, val, len); - pci_default_write_config(d, addr, val, len); -} - static int vmstate_acpi_post_load(void *opaque, int version_id) { VT686PMState *s =3D opaque; @@ -210,7 +75,34 @@ static const VMStateDescription vmstate_acpi =3D { } }; =20 -/* vt82c686 pm init */ +static void pm_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int= len) +{ + trace_via_pm_write(addr, val, len); + pci_default_write_config(d, addr, val, len); +} + +static void pm_update_sci(VT686PMState *s) +{ + int sci_level, pmsts; + + pmsts =3D acpi_pm1_evt_get_sts(&s->ar); + sci_level =3D (((pmsts & s->ar.pm1.evt.en) & + (ACPI_BITMASK_RT_CLOCK_ENABLE | + ACPI_BITMASK_POWER_BUTTON_ENABLE | + ACPI_BITMASK_GLOBAL_LOCK_ENABLE | + ACPI_BITMASK_TIMER_ENABLE)) !=3D 0); + pci_set_irq(&s->dev, sci_level); + /* schedule a timer interruption if needed */ + acpi_pm_tmr_update(&s->ar, (s->ar.pm1.evt.en & ACPI_BITMASK_TIMER_ENAB= LE) && + !(pmsts & ACPI_BITMASK_TIMER_STATUS)); +} + +static void pm_tmr_timer(ACPIREGS *ar) +{ + VT686PMState *s =3D container_of(ar, VT686PMState, ar); + pm_update_sci(s); +} + static void vt82c686b_pm_realize(PCIDevice *dev, Error **errp) { VT686PMState *s =3D VT82C686B_PM(dev); @@ -276,6 +168,87 @@ static const TypeInfo via_pm_info =3D { }, }; =20 + +typedef struct SuperIOConfig { + uint8_t regs[0x100]; + uint8_t index; + MemoryRegion io; +} SuperIOConfig; + +static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data, + unsigned size) +{ + SuperIOConfig *sc =3D opaque; + + if (addr =3D=3D 0x3f0) { /* config index register */ + sc->index =3D data & 0xff; + } else { + bool can_write =3D true; + /* 0x3f1, config data register */ + trace_via_superio_write(sc->index, data & 0xff); + switch (sc->index) { + case 0x00 ... 0xdf: + case 0xe4: + case 0xe5: + case 0xe9 ... 0xed: + case 0xf3: + case 0xf5: + case 0xf7: + case 0xf9 ... 0xfb: + case 0xfd ... 0xff: + can_write =3D false; + break; + /* case 0xe6 ... 0xe8: Should set base port of parallel and serial= */ + default: + break; + + } + if (can_write) { + sc->regs[sc->index] =3D data & 0xff; + } + } +} + +static uint64_t superio_cfg_read(void *opaque, hwaddr addr, unsigned size) +{ + SuperIOConfig *sc =3D opaque; + uint8_t val =3D sc->regs[sc->index]; + + trace_via_superio_read(sc->index, val); + return val; +} + +static const MemoryRegionOps superio_cfg_ops =3D { + .read =3D superio_cfg_read, + .write =3D superio_cfg_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl =3D { + .min_access_size =3D 1, + .max_access_size =3D 1, + }, +}; + + +OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686B_ISA) + +struct VT82C686BISAState { + PCIDevice dev; + SuperIOConfig superio_cfg; +}; + +static void vt82c686b_write_config(PCIDevice *d, uint32_t addr, + uint32_t val, int len) +{ + VT82C686BISAState *s =3D VT82C686B_ISA(d); + + trace_via_isa_write(addr, val, len); + pci_default_write_config(d, addr, val, len); + if (addr =3D=3D 0x85) { + /* BIT(1): enable or disable superio config io ports */ + memory_region_set_enabled(&s->superio_cfg.io, val & BIT(1)); + } +} + static const VMStateDescription vmstate_via =3D { .name =3D "vt82c686b", .version_id =3D 1, @@ -286,7 +259,33 @@ static const VMStateDescription vmstate_via =3D { } }; =20 -/* init the PCI-to-ISA bridge */ +static void vt82c686b_isa_reset(DeviceState *dev) +{ + VT82C686BISAState *s =3D VT82C686B_ISA(dev); + uint8_t *pci_conf =3D s->dev.config; + + pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x000000c0); + pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMO= RY | + PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL); + pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM); + + pci_conf[0x48] =3D 0x01; /* Miscellaneous Control 3 */ + pci_conf[0x4a] =3D 0x04; /* IDE interrupt Routing */ + pci_conf[0x4f] =3D 0x03; /* DMA/Master Mem Access Control 3 */ + pci_conf[0x50] =3D 0x2d; /* PnP DMA Request Control */ + pci_conf[0x59] =3D 0x04; + pci_conf[0x5a] =3D 0x04; /* KBC/RTC Control*/ + pci_conf[0x5f] =3D 0x04; + pci_conf[0x77] =3D 0x10; /* GPIO Control 1/2/3/4 */ + + s->superio_cfg.regs[0xe0] =3D 0x3c; /* Device ID */ + s->superio_cfg.regs[0xe2] =3D 0x03; /* Function select */ + s->superio_cfg.regs[0xe3] =3D 0xfc; /* Floppy ctrl base addr */ + s->superio_cfg.regs[0xe6] =3D 0xde; /* Parallel port base addr */ + s->superio_cfg.regs[0xe7] =3D 0xfe; /* Serial port 1 base addr */ + s->superio_cfg.regs[0xe8] =3D 0xbe; /* Serial port 2 base addr */ +} + static void vt82c686b_realize(PCIDevice *d, Error **errp) { VT82C686BISAState *s =3D VT82C686B_ISA(d); @@ -354,6 +353,7 @@ static const TypeInfo via_info =3D { }, }; =20 + static void vt82c686b_superio_class_init(ObjectClass *klass, void *data) { ISASuperIOClass *sc =3D ISA_SUPERIO_CLASS(klass); @@ -372,11 +372,12 @@ static const TypeInfo via_superio_info =3D { .class_init =3D vt82c686b_superio_class_init, }; =20 + static void vt82c686b_register_types(void) { type_register_static(&via_pm_info); - type_register_static(&via_superio_info); type_register_static(&via_info); + type_register_static(&via_superio_info); } =20 type_init(vt82c686b_register_types) --=20 2.21.3 From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224536; cv=none; d=zohomail.com; s=zohoarc; b=fMS7hy6b6UMXNwPhO+R+PYZNk3Bm9dzxKuSqGsf7jdbx7NSR3gme7HmbbomUg9ISTLmkFOBue9EGhVzrZVsptSHxhzFerOC3PZOeEMqZfF0Qu2NIBm3IVygz9nMLybQKERg1dJJ5XndlpSie2MD3nuRWOYocTHf4USRJBVOWfk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224536; 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=a3Fe0NdSmaEMIlLXaYRLeZTKW2qWkhFhNQ9pMp+4jN0=; b=RvSLNlasaIZavVvQnh8D5wd6P4mJoPP0BTOXar3mPMCmhGs79s2eN2DrpN8m00+ZUnHkBOHMJ9YU+6q3TLLs6xRvRcm7lFsdNBmx0ic14iSHmR5zyn46zRsgdOqO0RNYYZpwjQkSnHXInrVLpQv6hdYXr0O+v98FrXSmxJwOWdo= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1610224536205969.3866848400882; Sat, 9 Jan 2021 12:35:36 -0800 (PST) Received: from localhost ([::1]:50626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyKxS-00057R-Us for importer@patchew.org; Sat, 09 Jan 2021 15:35:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41980) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsJ-0008Pm-4O for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:15 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:33366) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKs5-00078R-Ol for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:14 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id E692A747636; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 5A2F1747601; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 03/13] vt82c686: Fix SMBus IO base and configuration registers Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The base address of the SMBus io ports and its enabled status is set by registers in the PCI config space but this was not correctly emulated. Instead the SMBus registers were mapped on realize to the base address set by a property to the address expected by fuloong2e firmware. Fix the base and config register handling to more closely model hardware which allows to remove the property and allows the guest to control this mapping. Do all this in reset instead of realize so it's correctly updated on reset. Signed-off-by: BALATON Zoltan Reviewed-by: Jiaxun Yang --- hw/isa/vt82c686.c | 49 +++++++++++++++++++++++++++++++++------------ hw/mips/fuloong2e.c | 4 +--- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index fe8961b057..9c4d153022 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -22,6 +22,7 @@ #include "hw/i2c/pm_smbus.h" #include "qapi/error.h" #include "qemu/module.h" +#include "qemu/range.h" #include "qemu/timer.h" #include "exec/address-spaces.h" #include "trace.h" @@ -34,7 +35,6 @@ struct VT686PMState { ACPIREGS ar; APMState apm; PMSMBus smb; - uint32_t smb_io_base; }; =20 static void pm_io_space_update(VT686PMState *s) @@ -50,11 +50,22 @@ static void pm_io_space_update(VT686PMState *s) memory_region_transaction_commit(); } =20 +static void smb_io_space_update(VT686PMState *s) +{ + uint32_t smbase =3D pci_get_long(s->dev.config + 0x90) & 0xfff0UL; + + memory_region_transaction_begin(); + memory_region_set_address(&s->smb.io, smbase); + memory_region_set_enabled(&s->smb.io, s->dev.config[0xd2] & BIT(0)); + memory_region_transaction_commit(); +} + static int vmstate_acpi_post_load(void *opaque, int version_id) { VT686PMState *s =3D opaque; =20 pm_io_space_update(s); + smb_io_space_update(s); return 0; } =20 @@ -77,8 +88,18 @@ static const VMStateDescription vmstate_acpi =3D { =20 static void pm_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int= len) { + VT686PMState *s =3D VT82C686B_PM(d); + trace_via_pm_write(addr, val, len); pci_default_write_config(d, addr, val, len); + if (ranges_overlap(addr, len, 0x90, 4)) { + uint32_t v =3D pci_get_long(s->dev.config + 0x90); + pci_set_long(s->dev.config + 0x90, (v & 0xfff0UL) | 1); + } + if (range_covers_byte(addr, len, 0xd2)) { + s->dev.config[0xd2] &=3D 0xf; + smb_io_space_update(s); + } } =20 static void pm_update_sci(VT686PMState *s) @@ -103,6 +124,17 @@ static void pm_tmr_timer(ACPIREGS *ar) pm_update_sci(s); } =20 +static void vt82c686b_pm_reset(DeviceState *d) +{ + VT686PMState *s =3D VT82C686B_PM(d); + + /* SMBus IO base */ + pci_set_long(s->dev.config + 0x90, 1); + s->dev.config[0xd2] =3D 0; + + smb_io_space_update(s); +} + static void vt82c686b_pm_realize(PCIDevice *dev, Error **errp) { VT686PMState *s =3D VT82C686B_PM(dev); @@ -116,13 +148,9 @@ static void vt82c686b_pm_realize(PCIDevice *dev, Error= **errp) /* 0x48-0x4B is Power Management I/O Base */ pci_set_long(pci_conf + 0x48, 0x00000001); =20 - /* SMB ports:0xeee0~0xeeef */ - s->smb_io_base =3D ((s->smb_io_base & 0xfff0) + 0x0); - pci_conf[0x90] =3D s->smb_io_base | 1; - pci_conf[0x91] =3D s->smb_io_base >> 8; - pci_conf[0xd2] =3D 0x90; pm_smbus_init(DEVICE(s), &s->smb, false); - memory_region_add_subregion(get_system_io(), s->smb_io_base, &s->smb.i= o); + memory_region_add_subregion(pci_address_space_io(dev), 0, &s->smb.io); + memory_region_set_enabled(&s->smb.io, false); =20 apm_init(dev, &s->apm, NULL, s); =20 @@ -135,11 +163,6 @@ static void vt82c686b_pm_realize(PCIDevice *dev, Error= **errp) acpi_pm1_cnt_init(&s->ar, &s->io, false, false, 2); } =20 -static Property via_pm_properties[] =3D { - DEFINE_PROP_UINT32("smb_io_base", VT686PMState, smb_io_base, 0), - DEFINE_PROP_END_OF_LIST(), -}; - static void via_pm_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -151,10 +174,10 @@ static void via_pm_class_init(ObjectClass *klass, voi= d *data) k->device_id =3D PCI_DEVICE_ID_VIA_ACPI; k->class_id =3D PCI_CLASS_BRIDGE_OTHER; k->revision =3D 0x40; + dc->reset =3D vt82c686b_pm_reset; dc->desc =3D "PM"; dc->vmsd =3D &vmstate_acpi; set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); - device_class_set_props(dc, via_pm_properties); } =20 static const TypeInfo via_pm_info =3D { diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c index 29805242ca..fbdd6122b3 100644 --- a/hw/mips/fuloong2e.c +++ b/hw/mips/fuloong2e.c @@ -251,9 +251,7 @@ static void vt82c686b_southbridge_init(PCIBus *pci_bus,= int slot, qemu_irq intc, pci_create_simple(pci_bus, PCI_DEVFN(slot, 2), "vt82c686b-usb-uhci"); pci_create_simple(pci_bus, PCI_DEVFN(slot, 3), "vt82c686b-usb-uhci"); =20 - dev =3D pci_new(PCI_DEVFN(slot, 4), TYPE_VT82C686B_PM); - qdev_prop_set_uint32(DEVICE(dev), "smb_io_base", 0xeee1); - pci_realize_and_unref(dev, pci_bus, &error_fatal); + dev =3D pci_create_simple(pci_bus, PCI_DEVFN(slot, 4), TYPE_VT82C686B_= PM); *i2c_bus =3D I2C_BUS(qdev_get_child_bus(DEVICE(dev), "i2c")); =20 /* Audio support */ --=20 2.21.3 From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224378; cv=none; d=zohomail.com; s=zohoarc; b=GiNL7bn0ZtsbTpgS1Vs5Cikl7qNIZEaoC3pnp+zJg9lGJv7jgGlONF0y+XQbx59pZ3TOsXdVyhmWoWMdcTM+5Fv+4bdchdqtWvsQung8QWsbKM2ZbjVs2lPgv5S2u0OO+yLS8tlFJV03lQgnJdSSwjd8un9tAicoFIz2WgtlEBk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224378; 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=uNu8OXLNePiQ8Sw00IA5D8oFwG7hZWujyS1q7C4qDMo=; b=e3/URWnUz6rs4NvUTTVLWfZpr3cc6EAPur31c00ziiVvu1nWeIE+furEWc/Tk1xzoBsxKYL/Eu+lrUtQM23upR+dIYXABSzO0JFfn3zeA1LrVtPGNHFB68cXirJ4olANTpT2UTBQhJ/L/DIejjo98TiGpgxtofMCmmmHRhigjyM= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 161022437838248.82550839374346; Sat, 9 Jan 2021 12:32:58 -0800 (PST) Received: from localhost ([::1]:42962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyKuu-0001th-SP for importer@patchew.org; Sat, 09 Jan 2021 15:32:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsF-0008OV-E2 for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:14 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:33365) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKs5-00078P-RB for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:11 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 1D45D747639; Sat, 9 Jan 2021 21:29:58 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 5F40F747603; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 04/13] vt82c686: Fix up power management io base and config Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Similar to the SMBus io registers there is a power management io range that is set via similar base address reg and enable bit. Some handling of this was already there but with several problems: using the wrong registers and bits, wrong size range, not acually updating mapping and handling reset correctly, nor emulating any of the actual io registers. Some of these errors are fixed up here. After this patch we use the correct base address register, enable bit and region size and allow guests to map/unmap this region and correctly reset all registers to default values on reset but we still don't emulate any of the registers in this range. Previously just an empty RAM region was mapped on realize, now we add an empty io range logging access instead. I think the pm timer should be hooked up here but not sure guests need it. PMON on fuloong2e sets a base address but does not seem to enable region; the pegasos2 firmware pokes some regs but continues anyway so don't know if anything would make use of these facilities. Therefore this is just a clean up of previous state for now and not intending to fully implement missing functionality which could be done later if some guests need it. Signed-off-by: BALATON Zoltan --- hw/isa/trace-events | 2 ++ hw/isa/vt82c686.c | 56 ++++++++++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/hw/isa/trace-events b/hw/isa/trace-events index d267d3e652..641d69eedf 100644 --- a/hw/isa/trace-events +++ b/hw/isa/trace-events @@ -17,5 +17,7 @@ apm_io_write(uint8_t addr, uint8_t val) "write addr=3D0x%= x val=3D0x%02x" # vt82c686.c via_isa_write(uint32_t addr, uint32_t val, int len) "addr 0x%x val 0x%x le= n 0x%x" via_pm_write(uint32_t addr, uint32_t val, int len) "addr 0x%x val 0x%x len= 0x%x" +via_pm_io_read(uint32_t addr, uint32_t val, int len) "addr 0x%x val 0x%x l= en 0x%x" +via_pm_io_write(uint32_t addr, uint32_t val, int len) "addr 0x%x val 0x%x = len 0x%x" via_superio_read(uint8_t addr, uint8_t val) "addr 0x%x val 0x%x" via_superio_write(uint8_t addr, uint32_t val) "addr 0x%x val 0x%x" diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index 9c4d153022..fc2a1f4430 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -39,14 +39,11 @@ struct VT686PMState { =20 static void pm_io_space_update(VT686PMState *s) { - uint32_t pm_io_base; - - pm_io_base =3D pci_get_long(s->dev.config + 0x40); - pm_io_base &=3D 0xffc0; + uint32_t pmbase =3D pci_get_long(s->dev.config + 0x48) & 0xff80UL; =20 memory_region_transaction_begin(); - memory_region_set_enabled(&s->io, s->dev.config[0x80] & 1); - memory_region_set_address(&s->io, pm_io_base); + memory_region_set_address(&s->io, pmbase); + memory_region_set_enabled(&s->io, s->dev.config[0x41] & BIT(7)); memory_region_transaction_commit(); } =20 @@ -92,6 +89,13 @@ static void pm_write_config(PCIDevice *d, uint32_t addr,= uint32_t val, int len) =20 trace_via_pm_write(addr, val, len); pci_default_write_config(d, addr, val, len); + if (ranges_overlap(addr, len, 0x48, 4)) { + uint32_t v =3D pci_get_long(s->dev.config + 0x48); + pci_set_long(s->dev.config + 0x48, (v & 0xff80UL) | 1); + } + if (range_covers_byte(addr, len, 0x41)) { + pm_io_space_update(s); + } if (ranges_overlap(addr, len, 0x90, 4)) { uint32_t v =3D pci_get_long(s->dev.config + 0x90); pci_set_long(s->dev.config + 0x90, (v & 0xfff0UL) | 1); @@ -102,6 +106,27 @@ static void pm_write_config(PCIDevice *d, uint32_t add= r, uint32_t val, int len) } } =20 +static void pm_io_write(void *op, hwaddr addr, uint64_t data, unsigned siz= e) +{ + trace_via_pm_io_write(addr, data, size); +} + +static uint64_t pm_io_read(void *op, hwaddr addr, unsigned size) +{ + trace_via_pm_io_read(addr, 0, size); + return 0; +} + +static const MemoryRegionOps pm_io_ops =3D { + .read =3D pm_io_read, + .write =3D pm_io_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl =3D { + .min_access_size =3D 1, + .max_access_size =3D 1, + }, +}; + static void pm_update_sci(VT686PMState *s) { int sci_level, pmsts; @@ -128,35 +153,34 @@ static void vt82c686b_pm_reset(DeviceState *d) { VT686PMState *s =3D VT82C686B_PM(d); =20 + memset(s->dev.config + PCI_CONFIG_HEADER_SIZE, 0, + PCI_CONFIG_SPACE_SIZE - PCI_CONFIG_HEADER_SIZE); + /* Power Management IO base */ + pci_set_long(s->dev.config + 0x48, 1); /* SMBus IO base */ pci_set_long(s->dev.config + 0x90, 1); - s->dev.config[0xd2] =3D 0; =20 + pm_io_space_update(s); smb_io_space_update(s); } =20 static void vt82c686b_pm_realize(PCIDevice *dev, Error **errp) { VT686PMState *s =3D VT82C686B_PM(dev); - uint8_t *pci_conf; =20 - pci_conf =3D s->dev.config; - pci_set_word(pci_conf + PCI_COMMAND, 0); - pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_FAST_BACK | + pci_set_word(dev->config + PCI_STATUS, PCI_STATUS_FAST_BACK | PCI_STATUS_DEVSEL_MEDIUM); =20 - /* 0x48-0x4B is Power Management I/O Base */ - pci_set_long(pci_conf + 0x48, 0x00000001); - pm_smbus_init(DEVICE(s), &s->smb, false); memory_region_add_subregion(pci_address_space_io(dev), 0, &s->smb.io); memory_region_set_enabled(&s->smb.io, false); =20 apm_init(dev, &s->apm, NULL, s); =20 - memory_region_init(&s->io, OBJECT(dev), "vt82c686-pm", 64); + memory_region_init_io(&s->io, OBJECT(dev), &pm_io_ops, s, + "vt82c686-pm", 0x100); + memory_region_add_subregion(pci_address_space_io(dev), 0, &s->io); memory_region_set_enabled(&s->io, false); - memory_region_add_subregion(get_system_io(), 0, &s->io); =20 acpi_pm_tmr_init(&s->ar, pm_tmr_timer, &s->io); acpi_pm1_evt_init(&s->ar, pm_tmr_timer, &s->io); --=20 2.21.3 From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224378; cv=none; d=zohomail.com; s=zohoarc; b=AYPgj82fyQgMRIovH89+dST0HtOhtIDLcf1ilcfNvbeTg1PPavyuOaj59u/RdxB1E5c81HKgY2o4oH1uuIEfPrkax4B8CkvsCtB4F+hu+IwyKySUaqM636s9uCScdIRrRaTy23QSh7Kp8GGaVbIxaiEHXC86rsgJCx8IobM97+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224378; 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=VZBhUFD7aCQTwetun/UkarIHMxMQb6ntQPopwGT4IC4=; b=hD1ZZUZdmHElUI7MV3PiIjkOWzQdwlb0S+PVAHBlGHRVnlt6vWNybOnBW/NXBz6VjaxCrvMJPJPVZRX1sFLo8/fMlM+9ZkAiuGvp6ipYzdGxteIteiTdDr1tf9Xdi9Yu9mEsOXUi67ajejiGi1KMGirR2+urC+6Eqmj0s4NIQpI= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1610224378354519.3774833069364; Sat, 9 Jan 2021 12:32:58 -0800 (PST) Received: from localhost ([::1]:42912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyKuu-0001sT-In for importer@patchew.org; Sat, 09 Jan 2021 15:32:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsL-0008Rb-Cy for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:18 -0500 Received: from zero.eik.bme.hu ([152.66.115.2]:33408) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsD-0007CO-22 for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:15 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 1577B747638; Sat, 9 Jan 2021 21:29:58 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 6634F7475FD; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 05/13] vt82c686: Set user_creatable=false for VT82C686B_PM Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, 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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This device is part of the multifunction VIA superio/south bridge chip so not useful in itself. Signed-off-by: BALATON Zoltan Reviewed-by: Jiaxun Yang Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/isa/vt82c686.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index fc2a1f4430..9b16660e9d 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -200,8 +200,9 @@ static void via_pm_class_init(ObjectClass *klass, void = *data) k->revision =3D 0x40; dc->reset =3D vt82c686b_pm_reset; dc->desc =3D "PM"; + /* Reason: part of VIA south bridge, does not exist stand alone */ + dc->user_creatable =3D false; dc->vmsd =3D &vmstate_acpi; - set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); } =20 static const TypeInfo via_pm_info =3D { --=20 2.21.3 From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224537; cv=none; d=zohomail.com; s=zohoarc; b=YeF8u7P0WJziyrUaXHTymrSxiKHn/OvA4rG1NJ9oX4X0xnqwVZSw6MKovguE1iNc/v/zb4sfn3XVJ2pE5kGSHO1m5YrO7HD8liQDok3yJnAKPnZa2EKZE6oQ2IcfdG70kYChL56oJ4119aiSW129gq4cI0LoxZrtJb7IHOvLPOQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224537; 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=oGWOaRSjW4IbODPMsZ6uKQo/rRzM7CBK9JMg4yCFT7s=; b=P0dwTT6hgID1R28CvS1gL2YABWTFUL1gaKyB3XSQf14OeQyK2fhn43WbTfizl5dbBAT5yfmzwuTPFc+TQc3xWNd4WHAWO1WNK8m5SXGVveEDrB0TwIR7o93RGUDky/wEWPb+C20PQLYHjs8grN50Pbh/H8+bw+vgQNjSZuAxjkQ= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1610224537081840.3599462044104; Sat, 9 Jan 2021 12:35:37 -0800 (PST) Received: from localhost ([::1]:50674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyKxT-00058a-QH for importer@patchew.org; Sat, 09 Jan 2021 15:35:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsJ-0008QP-Fa for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:17 -0500 Received: from zero.eik.bme.hu ([152.66.115.2]:33409) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsD-0007CN-2E for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:15 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 3BCAE747601; Sat, 9 Jan 2021 21:29:58 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 6C65C747608; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: <34969fc7be984fa070479bfb9f748993a0aef31b.1610223397.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 06/13] vt82c686: Make vt82c686b-pm an abstract base class and add vt8231-pm based on it Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 10% 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=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, 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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The vt82c686b-pm model can be shared between VT82C686B and VT8231. The only difference between the two is the device id in what we emulate so make an abstract via-pm model by renaming appropriately and add types for vt82c686b-pm and vt8231-pm based on it. Signed-off-by: BALATON Zoltan Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/isa/vt82c686.c | 84 ++++++++++++++++++++++++++------------- include/hw/isa/vt82c686.h | 1 + include/hw/pci/pci_ids.h | 3 +- 3 files changed, 59 insertions(+), 29 deletions(-) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index 9b16660e9d..c257926579 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -27,9 +27,10 @@ #include "exec/address-spaces.h" #include "trace.h" =20 -OBJECT_DECLARE_SIMPLE_TYPE(VT686PMState, VT82C686B_PM) +#define TYPE_VIA_PM "via-pm" +OBJECT_DECLARE_SIMPLE_TYPE(ViaPMState, VIA_PM) =20 -struct VT686PMState { +struct ViaPMState { PCIDevice dev; MemoryRegion io; ACPIREGS ar; @@ -37,7 +38,7 @@ struct VT686PMState { PMSMBus smb; }; =20 -static void pm_io_space_update(VT686PMState *s) +static void pm_io_space_update(ViaPMState *s) { uint32_t pmbase =3D pci_get_long(s->dev.config + 0x48) & 0xff80UL; =20 @@ -47,7 +48,7 @@ static void pm_io_space_update(VT686PMState *s) memory_region_transaction_commit(); } =20 -static void smb_io_space_update(VT686PMState *s) +static void smb_io_space_update(ViaPMState *s) { uint32_t smbase =3D pci_get_long(s->dev.config + 0x90) & 0xfff0UL; =20 @@ -59,7 +60,7 @@ static void smb_io_space_update(VT686PMState *s) =20 static int vmstate_acpi_post_load(void *opaque, int version_id) { - VT686PMState *s =3D opaque; + ViaPMState *s =3D opaque; =20 pm_io_space_update(s); smb_io_space_update(s); @@ -72,20 +73,20 @@ static const VMStateDescription vmstate_acpi =3D { .minimum_version_id =3D 1, .post_load =3D vmstate_acpi_post_load, .fields =3D (VMStateField[]) { - VMSTATE_PCI_DEVICE(dev, VT686PMState), - VMSTATE_UINT16(ar.pm1.evt.sts, VT686PMState), - VMSTATE_UINT16(ar.pm1.evt.en, VT686PMState), - VMSTATE_UINT16(ar.pm1.cnt.cnt, VT686PMState), - VMSTATE_STRUCT(apm, VT686PMState, 0, vmstate_apm, APMState), - VMSTATE_TIMER_PTR(ar.tmr.timer, VT686PMState), - VMSTATE_INT64(ar.tmr.overflow_time, VT686PMState), + VMSTATE_PCI_DEVICE(dev, ViaPMState), + VMSTATE_UINT16(ar.pm1.evt.sts, ViaPMState), + VMSTATE_UINT16(ar.pm1.evt.en, ViaPMState), + VMSTATE_UINT16(ar.pm1.cnt.cnt, ViaPMState), + VMSTATE_STRUCT(apm, ViaPMState, 0, vmstate_apm, APMState), + VMSTATE_TIMER_PTR(ar.tmr.timer, ViaPMState), + VMSTATE_INT64(ar.tmr.overflow_time, ViaPMState), VMSTATE_END_OF_LIST() } }; =20 static void pm_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int= len) { - VT686PMState *s =3D VT82C686B_PM(d); + ViaPMState *s =3D VIA_PM(d); =20 trace_via_pm_write(addr, val, len); pci_default_write_config(d, addr, val, len); @@ -127,7 +128,7 @@ static const MemoryRegionOps pm_io_ops =3D { }, }; =20 -static void pm_update_sci(VT686PMState *s) +static void pm_update_sci(ViaPMState *s) { int sci_level, pmsts; =20 @@ -145,13 +146,13 @@ static void pm_update_sci(VT686PMState *s) =20 static void pm_tmr_timer(ACPIREGS *ar) { - VT686PMState *s =3D container_of(ar, VT686PMState, ar); + ViaPMState *s =3D container_of(ar, ViaPMState, ar); pm_update_sci(s); } =20 -static void vt82c686b_pm_reset(DeviceState *d) +static void via_pm_reset(DeviceState *d) { - VT686PMState *s =3D VT82C686B_PM(d); + ViaPMState *s =3D VIA_PM(d); =20 memset(s->dev.config + PCI_CONFIG_HEADER_SIZE, 0, PCI_CONFIG_SPACE_SIZE - PCI_CONFIG_HEADER_SIZE); @@ -164,9 +165,9 @@ static void vt82c686b_pm_reset(DeviceState *d) smb_io_space_update(s); } =20 -static void vt82c686b_pm_realize(PCIDevice *dev, Error **errp) +static void via_pm_realize(PCIDevice *dev, Error **errp) { - VT686PMState *s =3D VT82C686B_PM(dev); + ViaPMState *s =3D VIA_PM(dev); =20 pci_set_word(dev->config + PCI_STATUS, PCI_STATUS_FAST_BACK | PCI_STATUS_DEVSEL_MEDIUM); @@ -177,8 +178,7 @@ static void vt82c686b_pm_realize(PCIDevice *dev, Error = **errp) =20 apm_init(dev, &s->apm, NULL, s); =20 - memory_region_init_io(&s->io, OBJECT(dev), &pm_io_ops, s, - "vt82c686-pm", 0x100); + memory_region_init_io(&s->io, OBJECT(dev), &pm_io_ops, s, "via-pm", 0x= 100); memory_region_add_subregion(pci_address_space_io(dev), 0, &s->io); memory_region_set_enabled(&s->io, false); =20 @@ -187,35 +187,61 @@ static void vt82c686b_pm_realize(PCIDevice *dev, Erro= r **errp) acpi_pm1_cnt_init(&s->ar, &s->io, false, false, 2); } =20 +typedef struct via_pm_init_info { + uint16_t device_id; +} ViaPMInitInfo; + static void via_pm_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); + ViaPMInitInfo *info =3D data; =20 - k->realize =3D vt82c686b_pm_realize; + k->realize =3D via_pm_realize; k->config_write =3D pm_write_config; k->vendor_id =3D PCI_VENDOR_ID_VIA; - k->device_id =3D PCI_DEVICE_ID_VIA_ACPI; + k->device_id =3D info->device_id; k->class_id =3D PCI_CLASS_BRIDGE_OTHER; k->revision =3D 0x40; - dc->reset =3D vt82c686b_pm_reset; - dc->desc =3D "PM"; + dc->reset =3D via_pm_reset; /* Reason: part of VIA south bridge, does not exist stand alone */ dc->user_creatable =3D false; dc->vmsd =3D &vmstate_acpi; } =20 static const TypeInfo via_pm_info =3D { - .name =3D TYPE_VT82C686B_PM, + .name =3D TYPE_VIA_PM, .parent =3D TYPE_PCI_DEVICE, - .instance_size =3D sizeof(VT686PMState), - .class_init =3D via_pm_class_init, + .instance_size =3D sizeof(ViaPMState), + .abstract =3D true, .interfaces =3D (InterfaceInfo[]) { { INTERFACE_CONVENTIONAL_PCI_DEVICE }, { }, }, }; =20 +static const ViaPMInitInfo vt82c686b_pm_init_info =3D { + .device_id =3D PCI_DEVICE_ID_VIA_82C686B_PM, +}; + +static const TypeInfo vt82c686b_pm_info =3D { + .name =3D TYPE_VT82C686B_PM, + .parent =3D TYPE_VIA_PM, + .class_init =3D via_pm_class_init, + .class_data =3D (void *)&vt82c686b_pm_init_info, +}; + +static const ViaPMInitInfo vt8231_pm_init_info =3D { + .device_id =3D PCI_DEVICE_ID_VIA_8231_PM, +}; + +static const TypeInfo vt8231_pm_info =3D { + .name =3D TYPE_VT8231_PM, + .parent =3D TYPE_VIA_PM, + .class_init =3D via_pm_class_init, + .class_data =3D (void *)&vt8231_pm_init_info, +}; + =20 typedef struct SuperIOConfig { uint8_t regs[0x100]; @@ -424,6 +450,8 @@ static const TypeInfo via_superio_info =3D { static void vt82c686b_register_types(void) { type_register_static(&via_pm_info); + type_register_static(&vt82c686b_pm_info); + type_register_static(&vt8231_pm_info); type_register_static(&via_info); type_register_static(&via_superio_info); } diff --git a/include/hw/isa/vt82c686.h b/include/hw/isa/vt82c686.h index 5b0a1ffe72..9b6d610e83 100644 --- a/include/hw/isa/vt82c686.h +++ b/include/hw/isa/vt82c686.h @@ -4,6 +4,7 @@ #define TYPE_VT82C686B_ISA "vt82c686b-isa" #define TYPE_VT82C686B_SUPERIO "vt82c686b-superio" #define TYPE_VT82C686B_PM "vt82c686b-pm" +#define TYPE_VT8231_PM "vt8231-pm" #define TYPE_VIA_AC97 "via-ac97" #define TYPE_VIA_MC97 "via-mc97" =20 diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h index 11f8ab7149..7c183d16f9 100644 --- a/include/hw/pci/pci_ids.h +++ b/include/hw/pci/pci_ids.h @@ -204,9 +204,10 @@ #define PCI_DEVICE_ID_VIA_ISA_BRIDGE 0x0686 #define PCI_DEVICE_ID_VIA_IDE 0x0571 #define PCI_DEVICE_ID_VIA_UHCI 0x3038 -#define PCI_DEVICE_ID_VIA_ACPI 0x3057 +#define PCI_DEVICE_ID_VIA_82C686B_PM 0x3057 #define PCI_DEVICE_ID_VIA_AC97 0x3058 #define PCI_DEVICE_ID_VIA_MC97 0x3068 +#define PCI_DEVICE_ID_VIA_8231_PM 0x8235 =20 #define PCI_VENDOR_ID_MARVELL 0x11ab =20 --=20 2.21.3 From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224535; cv=none; d=zohomail.com; s=zohoarc; b=JSboRGJRBXb5+6ah/FIAHcnkKa0GlatPHtukE2d5mLYbmvrz7qlZDjqEeFR1w1dJiaCcn+Eb4R8WJXuCbqWYkLZ4RUvhHEGezMBL3GR8nErMEk0Nn9latUb01/203i+5D62vs1hgLBQfAcNyEOYKwlmXrZfuThsMBN2vQgwleCg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224535; 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=L9tom7/nkf36H79A3BwCSvP2xIV7MmmqY7ZTbjet7YA=; b=dmamxTP7VZaIDSY4qESsMFpluHLoGGQVAJ5A4e9Ta/5+tuJxXlusCySvSf2ztRrDfut5ys41Y+PDLXx7fJSsLuPv3RlBDUBHwKnBQU7iplSp092SEUgtWSUXokw4cOVnD7a43ROFGBlSaxu2aZS3QCxXky+P1jNFipHPQpxjWbc= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1610224535709247.0302468211902; Sat, 9 Jan 2021 12:35:35 -0800 (PST) Received: from localhost ([::1]:50538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyKxS-00054D-CS for importer@patchew.org; Sat, 09 Jan 2021 15:35:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42070) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsR-0008Vj-Gy for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:23 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:33416) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsL-0007Ee-45 for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:21 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 5407A74760C; Sat, 9 Jan 2021 21:30:05 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 72BDE74760B; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 07/13] vt82c686: Simplify vt82c686b_realize() Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Remove unneeded variables and setting value to 0 on zero initialised data and replace check for error with error_fatal. Rationalise loop that sets PCI config header fields read only. Signed-off-by: BALATON Zoltan Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/isa/vt82c686.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index c257926579..58c0bba1d0 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -363,24 +363,16 @@ static void vt82c686b_isa_reset(DeviceState *dev) static void vt82c686b_realize(PCIDevice *d, Error **errp) { VT82C686BISAState *s =3D VT82C686B_ISA(d); - uint8_t *pci_conf; + DeviceState *dev =3D DEVICE(d); ISABus *isa_bus; - uint8_t *wmask; int i; =20 - isa_bus =3D isa_bus_new(DEVICE(d), get_system_memory(), - pci_address_space_io(d), errp); - if (!isa_bus) { - return; - } - - pci_conf =3D d->config; - pci_config_set_prog_interface(pci_conf, 0x0); + isa_bus =3D isa_bus_new(dev, get_system_memory(), pci_address_space_io= (d), + &error_fatal); =20 - wmask =3D d->wmask; - for (i =3D 0x00; i < 0xff; i++) { - if (i <=3D 0x03 || (i >=3D 0x08 && i <=3D 0x3f)) { - wmask[i] =3D 0x00; + for (i =3D 0; i < PCI_CONFIG_HEADER_SIZE; i++) { + if (i < PCI_COMMAND || i >=3D PCI_REVISION_ID) { + d->wmask[i] =3D 0; } } =20 --=20 2.21.3 From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224650; cv=none; d=zohomail.com; s=zohoarc; b=nT23ZyIapQR6R6VEfb75boawzXHZqLHKvHPQTwPtDuKYhmdQghpMIG6xlX8G/qoZUnNWdBy89tGA+Jp3svXFj5VX8rBKZZTEYh45LrNPBVcuhb1FKmnQ2v05V9Fy/rGkEvq+51feTKohtkOW8YMOXdZ2TAaw8qeXhbMGwZYcJCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224650; 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=S7xwCqEn6cGm2goHT/yz5P9xCYzYtJh1C4W+Uq1vXwg=; b=e+2YOjsCwlgF/GyNgaJjNMn4Awh2ilOfIFdMAtcPPFMcN9c5dB6d9f+gCF97UFr7vHiUq72xaPHc5XDw5ZqzjPhGLwTGaRu6e24XyINa6HY9m1gY/OWTL+/x5UPfAhddjLlOAxQkQI2AseQIA1UtAG0dBqQ072X0GYK54ncqZt8= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1610224650034697.7810409412259; Sat, 9 Jan 2021 12:37:30 -0800 (PST) Received: from localhost ([::1]:56876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyKzG-0007nD-Oo for importer@patchew.org; Sat, 09 Jan 2021 15:37:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsU-000062-PI for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:27 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:33411) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsF-0007DN-5A for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:26 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 57E4C74763B; Sat, 9 Jan 2021 21:29:58 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 77BF2747605; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 08/13] vt82c686: Move creation of ISA devices to the ISA bridge Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Currently the ISA devices that are part of the VIA south bridge, superio chip are wired up by board code. Move creation of these ISA devices to the VIA ISA bridge model so that board code does not need to access ISA bus. This also allows vt82c686b-superio to be made internal to vt82c686 which allows implementing its configuration via registers in subseqent commits. Signed-off-by: BALATON Zoltan Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/isa/vt82c686.c | 20 ++++++++++++++++++++ hw/mips/fuloong2e.c | 29 +++++------------------------ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index 58c0bba1d0..5df9be8ff4 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -16,6 +16,11 @@ #include "hw/qdev-properties.h" #include "hw/isa/isa.h" #include "hw/isa/superio.h" +#include "hw/intc/i8259.h" +#include "hw/irq.h" +#include "hw/dma/i8257.h" +#include "hw/timer/i8254.h" +#include "hw/rtc/mc146818rtc.h" #include "migration/vmstate.h" #include "hw/isa/apm.h" #include "hw/acpi/acpi.h" @@ -307,9 +312,16 @@ OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686= B_ISA) =20 struct VT82C686BISAState { PCIDevice dev; + qemu_irq cpu_intr; SuperIOConfig superio_cfg; }; =20 +static void via_isa_request_i8259_irq(void *opaque, int irq, int level) +{ + VT82C686BISAState *s =3D opaque; + qemu_set_irq(s->cpu_intr, level); +} + static void vt82c686b_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int len) { @@ -365,10 +377,18 @@ static void vt82c686b_realize(PCIDevice *d, Error **e= rrp) VT82C686BISAState *s =3D VT82C686B_ISA(d); DeviceState *dev =3D DEVICE(d); ISABus *isa_bus; + qemu_irq *isa_irq; int i; =20 + qdev_init_gpio_out(dev, &s->cpu_intr, 1); + isa_irq =3D qemu_allocate_irqs(via_isa_request_i8259_irq, s, 1); isa_bus =3D isa_bus_new(dev, get_system_memory(), pci_address_space_io= (d), &error_fatal); + 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); + mc146818_rtc_init(isa_bus, 2000, NULL); =20 for (i =3D 0; i < PCI_CONFIG_HEADER_SIZE; i++) { if (i < PCI_COMMAND || i >=3D PCI_REVISION_ID) { diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c index fbdd6122b3..0fc3288556 100644 --- a/hw/mips/fuloong2e.c +++ b/hw/mips/fuloong2e.c @@ -25,9 +25,6 @@ #include "qapi/error.h" #include "cpu.h" #include "hw/clock.h" -#include "hw/intc/i8259.h" -#include "hw/dma/i8257.h" -#include "hw/isa/superio.h" #include "net/net.h" #include "hw/boards.h" #include "hw/i2c/smbus_eeprom.h" @@ -38,13 +35,13 @@ #include "qemu/log.h" #include "hw/loader.h" #include "hw/ide/pci.h" +#include "hw/qdev-properties.h" #include "elf.h" #include "hw/isa/vt82c686.h" -#include "hw/rtc/mc146818rtc.h" -#include "hw/timer/i8254.h" #include "exec/address-spaces.h" #include "sysemu/qtest.h" #include "sysemu/reset.h" +#include "sysemu/sysemu.h" #include "qemu/error-report.h" =20 #define ENVP_PADDR 0x2000 @@ -224,26 +221,13 @@ static void main_cpu_reset(void *opaque) } =20 static void vt82c686b_southbridge_init(PCIBus *pci_bus, int slot, qemu_irq= intc, - I2CBus **i2c_bus, ISABus **p_isa_bu= s) + I2CBus **i2c_bus) { - qemu_irq *i8259; - ISABus *isa_bus; PCIDevice *dev; =20 dev =3D pci_create_simple_multifunction(pci_bus, PCI_DEVFN(slot, 0), t= rue, TYPE_VT82C686B_ISA); - isa_bus =3D ISA_BUS(qdev_get_child_bus(DEVICE(dev), "isa.0")); - assert(isa_bus); - *p_isa_bus =3D isa_bus; - /* Interrupt controller */ - /* The 8259 -> IP5 */ - i8259 =3D i8259_init(isa_bus, intc); - isa_bus_irqs(isa_bus, i8259); - /* init other devices */ - i8254_pit_init(isa_bus, 0x40, 0, NULL); - i8257_dma_init(isa_bus, 0); - /* Super I/O */ - isa_create_simple(isa_bus, TYPE_VT82C686B_SUPERIO); + qdev_connect_gpio_out(DEVICE(dev), 0, intc); =20 dev =3D pci_create_simple(pci_bus, PCI_DEVFN(slot, 1), "via-ide"); pci_ide_create_devs(dev); @@ -290,7 +274,6 @@ static void mips_fuloong2e_init(MachineState *machine) uint64_t kernel_entry; PCIDevice *pci_dev; PCIBus *pci_bus; - ISABus *isa_bus; I2CBus *smbus; Clock *cpuclk; MIPSCPU *cpu; @@ -357,7 +340,7 @@ static void mips_fuloong2e_init(MachineState *machine) =20 /* South bridge -> IP5 */ vt82c686b_southbridge_init(pci_bus, FULOONG2E_VIA_SLOT, env->irq[5], - &smbus, &isa_bus); + &smbus); =20 /* GPU */ if (vga_interface_type !=3D VGA_NONE) { @@ -372,8 +355,6 @@ static void mips_fuloong2e_init(MachineState *machine) spd_data =3D spd_data_generate(DDR, machine->ram_size); smbus_eeprom_init_one(smbus, 0x50, spd_data); =20 - mc146818_rtc_init(isa_bus, 2000, NULL); - /* Network card: RTL8139D */ network_init(pci_bus); } --=20 2.21.3 From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224760; cv=none; d=zohomail.com; s=zohoarc; b=BCwJstLfJEh2BSl9ZnXd19h2BSpwUc2QEMS2hRDI+ute/XflPbCaFh+4uYcg4vPEwqzHLqYHBEwbVQ9d2AXSLLhC44T62nn6gp/cwJypIcj0evbUiz2z1Fvh3rILFxWLDUurcCZvp8rnA7GPJLQ0yA/SYEux0oOPWDSY7AZNsco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224760; 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=BvaBKS/bdmpr9O+Uktpatnh/wNMqs6fVXf+BhynZs7c=; b=bnr+97hkCAOAK/YAFN9xnbMkwiDsbS9e71IXnsmSpLdUUYs88EULPvL+L/tsiwz/rLFeY2xZk5Q7IcAUA5UtODUnoscEcPezSL4K+ctjPz8TOUd7t4XTi2JHQ1HpDUfTuap5CQnQS8Hj1Gxb9LtrgHxs+a/3wubaKIygcP9K+q4= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1610224760160231.15691897584452; Sat, 9 Jan 2021 12:39:20 -0800 (PST) Received: from localhost ([::1]:34286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyL14-0001gK-Sn for importer@patchew.org; Sat, 09 Jan 2021 15:39:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42090) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsU-000061-HF for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:27 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:33410) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsF-0007DL-5J for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:26 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 5072B74763A; Sat, 9 Jan 2021 21:29:58 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 7EB16747602; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: <15b2968fd300a12d06b42368d084f6f80d3c3be5.1610223397.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 09/13] vt82c686: Fix superio_cfg_{read,write}() functions Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" These functions are memory region callbacks so we have to check against relative address not the mapped address. Also reduce indentation by returning early and log unimplemented accesses. Additionally we remove separate index value from SuperIOConfig and store the index at reg 0 which is reserved and returns 0 on read. This simplifies object state. Signed-off-by: BALATON Zoltan --- hw/isa/vt82c686.c | 63 ++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index 5df9be8ff4..2921d5c55c 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -26,6 +26,7 @@ #include "hw/acpi/acpi.h" #include "hw/i2c/pm_smbus.h" #include "qapi/error.h" +#include "qemu/log.h" #include "qemu/module.h" #include "qemu/range.h" #include "qemu/timer.h" @@ -250,7 +251,6 @@ static const TypeInfo vt8231_pm_info =3D { =20 typedef struct SuperIOConfig { uint8_t regs[0x100]; - uint8_t index; MemoryRegion io; } SuperIOConfig; =20 @@ -258,42 +258,49 @@ static void superio_cfg_write(void *opaque, hwaddr ad= dr, uint64_t data, unsigned size) { SuperIOConfig *sc =3D opaque; + uint8_t idx =3D sc->regs[0]; =20 - if (addr =3D=3D 0x3f0) { /* config index register */ - sc->index =3D data & 0xff; - } else { - bool can_write =3D true; - /* 0x3f1, config data register */ - trace_via_superio_write(sc->index, data & 0xff); - switch (sc->index) { - case 0x00 ... 0xdf: - case 0xe4: - case 0xe5: - case 0xe9 ... 0xed: - case 0xf3: - case 0xf5: - case 0xf7: - case 0xf9 ... 0xfb: - case 0xfd ... 0xff: - can_write =3D false; - break; - /* case 0xe6 ... 0xe8: Should set base port of parallel and serial= */ - default: - break; + if (addr =3D=3D 0) { /* config index register */ + sc->regs[0] =3D data; + return; + } =20 - } - if (can_write) { - sc->regs[sc->index] =3D data & 0xff; - } + /* config data register */ + trace_via_superio_write(idx, data); + switch (idx) { + case 0x00 ... 0xdf: + case 0xe4: + case 0xe5: + case 0xe9 ... 0xed: + case 0xf3: + case 0xf5: + case 0xf7: + case 0xf9 ... 0xfb: + case 0xfd ... 0xff: + /* ignore write to read only registers */ + return; + /* case 0xe6 ... 0xe8: Should set base port of parallel and serial */ + default: + qemu_log_mask(LOG_UNIMP, + "via_superio_cfg: unimplemented register 0x%x\n", id= x); + break; } + sc->regs[idx] =3D data; } =20 static uint64_t superio_cfg_read(void *opaque, hwaddr addr, unsigned size) { SuperIOConfig *sc =3D opaque; - uint8_t val =3D sc->regs[sc->index]; + uint8_t idx =3D sc->regs[0]; + uint8_t val =3D sc->regs[idx]; =20 - trace_via_superio_read(sc->index, val); + if (addr =3D=3D 0) { + return idx; + } + if (addr =3D=3D 1 && idx =3D=3D 0) { + val =3D 0; /* reading reg 0 where we store index value */ + } + trace_via_superio_read(idx, val); return val; } =20 --=20 2.21.3 From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224763; cv=none; d=zohomail.com; s=zohoarc; b=Ij2p8Z+AW5GytUrIBpK8e+nTpOL7WlAagsdeH4kIkJrEd5gfGHE54x8MD1SpCfAY9HzlCFmv67PMpSQV4yw7EGBs1n/+o3nxYVG+xHL9p4HdI+UW7rMe47NMBoZVIC3k9N/PpFFoz0FqR8/r6m7auin89rfK7bPOYwTXg6Jjejo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224763; 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=qNTuwF8ke9ganwLy2Cov9oHMc4F5lvwsOloSjqKXGKs=; b=UXh0N5fOAhtLWOr+TWn7R0wQffJTq2xpRfhTt3cUfi0nx0h9gWy6cuTrVDBLursSx9PmExRSsFN9veIaPRjIxVBZPI4o+It8l6h2O/WK/Sgx4ZczR3HH1z3FCnXa9Q9wtqtgiSaOo77Uj+R1kRIyhnH4ANJwl47lsUQMZuCNC44= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1610224763243421.49032180199845; Sat, 9 Jan 2021 12:39:23 -0800 (PST) Received: from localhost ([::1]:34482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyL17-0001lH-Q5 for importer@patchew.org; Sat, 09 Jan 2021 15:39:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsN-0008Sn-OL for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:20 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:33413) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsI-0007Da-Rq for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:19 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 70911747602; Sat, 9 Jan 2021 21:29:58 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 85D4A74760C; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: <3e07fafd50db50f965be877409a420c2693d7b29.1610223397.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 10/13] vt82c686: Implement control of serial port io ranges via config regs Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 --- 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 2921d5c55c..18bd86285b 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -252,8 +252,24 @@ static const TypeInfo vt8231_pm_info =3D { typedef struct SuperIOConfig { uint8_t regs[0x100]; MemoryRegion io; + ISASuperIODevice *superio; + MemoryRegion *serial_io[SUPERIO_MAX_SERIAL_PORTS]; } SuperIOConfig; =20 +static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent, + int offs) +{ + MemoryRegion *subregion, *mr =3D NULL; + + QTAILQ_FOREACH(subregion, &parent->subregions, subregions_link) { + if (subregion->addr =3D=3D offs) { + mr =3D 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 add= r, 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 &=3D 0x1f; + if (data & BIT(2)) { /* Serial port 1 enable */ + ISADevice *dev =3D 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 =3D 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 =3D 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 =3D 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 &=3D 0xfe; + sc->superio->serial[0]->ioport_id =3D 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 &=3D 0xfe; + sc->superio->serial[1]->ioport_id =3D 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", id= x); @@ -385,6 +447,7 @@ static void vt82c686b_realize(PCIDevice *d, Error **err= p) DeviceState *dev =3D DEVICE(d); ISABus *isa_bus; qemu_irq *isa_irq; + ISASuperIOClass *ic; int i; =20 qdev_init_gpio_out(dev, &s->cpu_intr, 1); @@ -394,7 +457,9 @@ static void vt82c686b_realize(PCIDevice *d, Error **err= p) 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 =3D ISA_SUPERIO(isa_create_simple(isa_bus, + TYPE_VT82C686B_SUPER= IO)); + ic =3D ISA_SUPERIO_GET_CLASS(s->superio_cfg.superio); mc146818_rtc_init(isa_bus, 2000, NULL); =20 for (i =3D 0; i < PCI_CONFIG_HEADER_SIZE; i++) { @@ -412,6 +477,21 @@ static void vt82c686b_realize(PCIDevice *d, Error **er= rp) */ 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 =3D 0; i < ic->serial.count; i++) { + ISADevice *sd =3D s->superio_cfg.superio->serial[i]; + MemoryRegion *io =3D isa_address_space_io(sd); + MemoryRegion *mr =3D 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] =3D mr; + if (memory_region_is_mapped(mr)) { + memory_region_del_subregion(io, mr); + } + } } =20 static void via_class_init(ObjectClass *klass, void *data) --=20 2.21.3 From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224968; cv=none; d=zohomail.com; s=zohoarc; b=jdRNb52Iss8NKru7RlLE0jlDHSey51ycXvOjYqhenOQgxxgPDzbbgAR8QlJQ5HcLWCgJUAQQqLPkE8pkdqfQ4dJX8H3Sd1l/sOdAVesPFcbw/oCEjYxDCXPiMxEmXdZ1PcnixcfGIF6tlDfecHLTrOVRMsPbHc3vKHr4z+eKwTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224968; 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=Mlm0xlNJUEofzTFAJDBwIMtmcoLPUeWxWKyFD1K93VU=; b=kdxrC5fq7xcD4ZU5A47ZquG1742xLNSxHywMqEnbVo3EVWvfz72b/1qTL+cHUoI3WXCst3j20Y6cMGS5ObbWInfm+RsT2guSrQCpQm+xCCfd36S7RIda5fyUKBYc7MaHK9XClMiWNDQWWTy12pykOQSYpI00qiVV1pywxXR5ds8= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1610224968383143.17771829820435; Sat, 9 Jan 2021 12:42:48 -0800 (PST) Received: from localhost ([::1]:39774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyL4R-00049R-1p for importer@patchew.org; Sat, 09 Jan 2021 15:42:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsX-000071-Mo for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:31 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:33415) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsV-0007Dr-4W for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:29 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 98C8A747605; Sat, 9 Jan 2021 21:29:58 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 8BACB74760E; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: <96befc6722bdc4808a973549c997919a8fad74a1.1610223397.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 11/13] vt82c686: QOM-ify superio related functionality Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Collect superio functionality and its controlling config registers handling in an abstract VIA_SUPERIO class that is a subclass of ISA_SUPERIO and put vt82c686b specific parts in a subclass of this abstract class. Signed-off-by: BALATON Zoltan --- hw/isa/vt82c686.c | 240 ++++++++++++++++++++++++-------------- include/hw/isa/vt82c686.h | 1 - 2 files changed, 150 insertions(+), 91 deletions(-) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index 18bd86285b..f23fb2ea25 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -249,12 +249,21 @@ static const TypeInfo vt8231_pm_info =3D { }; =20 =20 -typedef struct SuperIOConfig { +#define TYPE_VIA_SUPERIO "via-superio" +OBJECT_DECLARE_SIMPLE_TYPE(ViaSuperIOState, VIA_SUPERIO) + +struct ViaSuperIOState { + ISASuperIODevice superio; uint8_t regs[0x100]; + const MemoryRegionOps *io_ops; MemoryRegion io; - ISASuperIODevice *superio; MemoryRegion *serial_io[SUPERIO_MAX_SERIAL_PORTS]; -} SuperIOConfig; +}; + +static inline void via_superio_io_enable(ViaSuperIOState *s, bool enable) +{ + memory_region_set_enabled(&s->io, enable); +} =20 static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent, int offs) @@ -270,10 +279,76 @@ static MemoryRegion *find_subregion(ISADevice *d, Mem= oryRegion *parent, return mr; } =20 -static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data, - unsigned size) +static void via_superio_realize(DeviceState *d, Error **errp) +{ + ViaSuperIOState *s =3D VIA_SUPERIO(d); + ISASuperIOClass *ic =3D ISA_SUPERIO_GET_CLASS(s); + int i; + + assert(s->io_ops); + ic->parent_realize(d, errp); + if (*errp) { + return; + } + /* Grab io regions of serial devices so we can control them */ + for (i =3D 0; i < ic->serial.count; i++) { + ISADevice *sd =3D s->superio.serial[i]; + MemoryRegion *io =3D isa_address_space_io(sd); + MemoryRegion *mr =3D find_subregion(sd, io, sd->ioport_id); + if (!mr) { + error_setg(errp, "Could not get io region for serial %d", i); + return; + } + s->serial_io[i] =3D mr; + } + + memory_region_init_io(&s->io, OBJECT(d), s->io_ops, s, "via-superio", = 2); + memory_region_set_enabled(&s->io, false); + /* The floppy also uses 0x3f0 and 0x3f1 but this seems to work anyway = */ + memory_region_add_subregion(isa_address_space_io(ISA_DEVICE(s)), 0x3f0, + &s->io); +} + +static uint64_t via_superio_cfg_read(void *opaque, hwaddr addr, unsigned s= ize) +{ + ViaSuperIOState *sc =3D opaque; + uint8_t idx =3D sc->regs[0]; + uint8_t val =3D sc->regs[idx]; + + if (addr =3D=3D 0) { + return idx; + } + if (addr =3D=3D 1 && idx =3D=3D 0) { + val =3D 0; /* reading reg 0 where we store index value */ + } + trace_via_superio_read(idx, val); + return val; +} + +static void via_superio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ISASuperIOClass *sc =3D ISA_SUPERIO_CLASS(klass); + + sc->parent_realize =3D dc->realize; + dc->realize =3D via_superio_realize; +} + +static const TypeInfo via_superio_info =3D { + .name =3D TYPE_VIA_SUPERIO, + .parent =3D TYPE_ISA_SUPERIO, + .instance_size =3D sizeof(ViaSuperIOState), + .class_size =3D sizeof(ISASuperIOClass), + .class_init =3D via_superio_class_init, + .abstract =3D true, +}; + +#define TYPE_VT82C686B_SUPERIO "vt82c686b-superio" + +static void vt82c686b_superio_cfg_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size) { - SuperIOConfig *sc =3D opaque; + ViaSuperIOState *sc =3D opaque; uint8_t idx =3D sc->regs[0]; =20 if (addr =3D=3D 0) { /* config index register */ @@ -295,29 +370,29 @@ static void superio_cfg_write(void *opaque, hwaddr ad= dr, uint64_t data, case 0xfd ... 0xff: /* ignore write to read only registers */ return; - case 0xe2: + case 0xe2: /* Function select */ { data &=3D 0x1f; if (data & BIT(2)) { /* Serial port 1 enable */ - ISADevice *dev =3D sc->superio->serial[0]; + ISADevice *dev =3D 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 =3D isa_address_space_io(sc->superio->serial[= 0]); + MemoryRegion *io =3D 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 =3D sc->superio->serial[1]; + ISADevice *dev =3D 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 =3D isa_address_space_io(sc->superio->serial[= 1]); + MemoryRegion *io =3D 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]); } @@ -327,7 +402,7 @@ static void superio_cfg_write(void *opaque, hwaddr addr= , uint64_t data, case 0xe7: /* Serial port 1 io base address */ { data &=3D 0xfe; - sc->superio->serial[0]->ioport_id =3D data << 2; + sc->superio.serial[0]->ioport_id =3D data << 2; if (memory_region_is_mapped(sc->serial_io[0])) { memory_region_set_address(sc->serial_io[0], data << 2); } @@ -336,7 +411,7 @@ static void superio_cfg_write(void *opaque, hwaddr addr= , uint64_t data, case 0xe8: /* Serial port 2 io base address */ { data &=3D 0xfe; - sc->superio->serial[1]->ioport_id =3D data << 2; + sc->superio.serial[1]->ioport_id =3D data << 2; if (memory_region_is_mapped(sc->serial_io[1])) { memory_region_set_address(sc->serial_io[1], data << 2); } @@ -350,25 +425,9 @@ static void superio_cfg_write(void *opaque, hwaddr add= r, uint64_t data, sc->regs[idx] =3D data; } =20 -static uint64_t superio_cfg_read(void *opaque, hwaddr addr, unsigned size) -{ - SuperIOConfig *sc =3D opaque; - uint8_t idx =3D sc->regs[0]; - uint8_t val =3D sc->regs[idx]; - - if (addr =3D=3D 0) { - return idx; - } - if (addr =3D=3D 1 && idx =3D=3D 0) { - val =3D 0; /* reading reg 0 where we store index value */ - } - trace_via_superio_read(idx, val); - return val; -} - -static const MemoryRegionOps superio_cfg_ops =3D { - .read =3D superio_cfg_read, - .write =3D superio_cfg_write, +static const MemoryRegionOps vt82c686b_superio_cfg_ops =3D { + .read =3D via_superio_cfg_read, + .write =3D vt82c686b_superio_cfg_write, .endianness =3D DEVICE_NATIVE_ENDIAN, .impl =3D { .min_access_size =3D 1, @@ -376,13 +435,66 @@ static const MemoryRegionOps superio_cfg_ops =3D { }, }; =20 +static void vt82c686b_superio_reset(DeviceState *dev) +{ + ViaSuperIOState *s =3D VIA_SUPERIO(dev); + + memset(s->regs, 0, sizeof(s->regs)); + /* Device ID */ + vt82c686b_superio_cfg_write(s, 0, 0xe0, 1); + vt82c686b_superio_cfg_write(s, 1, 0x3c, 1); + /* Function select - all disabled */ + vt82c686b_superio_cfg_write(s, 0, 0xe2, 1); + vt82c686b_superio_cfg_write(s, 1, 0x03, 1); + /* Floppy ctrl base addr */ + vt82c686b_superio_cfg_write(s, 0, 0xe3, 1); + vt82c686b_superio_cfg_write(s, 1, 0xfc, 1); + /* Parallel port base addr */ + vt82c686b_superio_cfg_write(s, 0, 0xe6, 1); + vt82c686b_superio_cfg_write(s, 1, 0xde, 1); + /* Serial port 1 base addr */ + vt82c686b_superio_cfg_write(s, 0, 0xe7, 1); + vt82c686b_superio_cfg_write(s, 1, 0xfe, 1); + /* Serial port 2 base addr */ + vt82c686b_superio_cfg_write(s, 0, 0xe8, 1); + vt82c686b_superio_cfg_write(s, 1, 0xbe, 1); + + vt82c686b_superio_cfg_write(s, 0, 0, 1); +} + +static void vt82c686b_superio_init(Object *obj) +{ + VIA_SUPERIO(obj)->io_ops =3D &vt82c686b_superio_cfg_ops; +} + +static void vt82c686b_superio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ISASuperIOClass *sc =3D ISA_SUPERIO_CLASS(klass); + + dc->reset =3D vt82c686b_superio_reset; + sc->serial.count =3D 2; + sc->parallel.count =3D 1; + sc->ide.count =3D 0; /* emulated by via-ide */ + sc->floppy.count =3D 1; +} + +static const TypeInfo vt82c686b_superio_info =3D { + .name =3D TYPE_VT82C686B_SUPERIO, + .parent =3D TYPE_VIA_SUPERIO, + .instance_size =3D sizeof(ViaSuperIOState), + .instance_init =3D vt82c686b_superio_init, + .class_size =3D sizeof(ISASuperIOClass), + .class_init =3D vt82c686b_superio_class_init, +}; + =20 OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686B_ISA) =20 struct VT82C686BISAState { PCIDevice dev; qemu_irq cpu_intr; - SuperIOConfig superio_cfg; + ViaSuperIOState *via_sio; }; =20 static void via_isa_request_i8259_irq(void *opaque, int irq, int level) @@ -400,7 +512,7 @@ static void vt82c686b_write_config(PCIDevice *d, uint32= _t addr, pci_default_write_config(d, addr, val, len); if (addr =3D=3D 0x85) { /* BIT(1): enable or disable superio config io ports */ - memory_region_set_enabled(&s->superio_cfg.io, val & BIT(1)); + via_superio_io_enable(s->via_sio, val & BIT(1)); } } =20 @@ -432,13 +544,6 @@ static void vt82c686b_isa_reset(DeviceState *dev) pci_conf[0x5a] =3D 0x04; /* KBC/RTC Control*/ pci_conf[0x5f] =3D 0x04; pci_conf[0x77] =3D 0x10; /* GPIO Control 1/2/3/4 */ - - s->superio_cfg.regs[0xe0] =3D 0x3c; /* Device ID */ - s->superio_cfg.regs[0xe2] =3D 0x03; /* Function select */ - s->superio_cfg.regs[0xe3] =3D 0xfc; /* Floppy ctrl base addr */ - s->superio_cfg.regs[0xe6] =3D 0xde; /* Parallel port base addr */ - s->superio_cfg.regs[0xe7] =3D 0xfe; /* Serial port 1 base addr */ - s->superio_cfg.regs[0xe8] =3D 0xbe; /* Serial port 2 base addr */ } =20 static void vt82c686b_realize(PCIDevice *d, Error **errp) @@ -447,7 +552,6 @@ static void vt82c686b_realize(PCIDevice *d, Error **err= p) DeviceState *dev =3D DEVICE(d); ISABus *isa_bus; qemu_irq *isa_irq; - ISASuperIOClass *ic; int i; =20 qdev_init_gpio_out(dev, &s->cpu_intr, 1); @@ -457,9 +561,8 @@ static void vt82c686b_realize(PCIDevice *d, Error **err= p) 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); - s->superio_cfg.superio =3D ISA_SUPERIO(isa_create_simple(isa_bus, - TYPE_VT82C686B_SUPER= IO)); - ic =3D ISA_SUPERIO_GET_CLASS(s->superio_cfg.superio); + s->via_sio =3D VIA_SUPERIO(isa_create_simple(isa_bus, + TYPE_VT82C686B_SUPERIO)); mc146818_rtc_init(isa_bus, 2000, NULL); =20 for (i =3D 0; i < PCI_CONFIG_HEADER_SIZE; i++) { @@ -467,31 +570,6 @@ static void vt82c686b_realize(PCIDevice *d, Error **er= rp) d->wmask[i] =3D 0; } } - - memory_region_init_io(&s->superio_cfg.io, OBJECT(d), &superio_cfg_ops, - &s->superio_cfg, "superio_cfg", 2); - memory_region_set_enabled(&s->superio_cfg.io, false); - /* - * The floppy also uses 0x3f0 and 0x3f1. - * But we do not emulate a floppy, so just set it here. - */ - 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 =3D 0; i < ic->serial.count; i++) { - ISADevice *sd =3D s->superio_cfg.superio->serial[i]; - MemoryRegion *io =3D isa_address_space_io(sd); - MemoryRegion *mr =3D 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] =3D mr; - if (memory_region_is_mapped(mr)) { - memory_region_del_subregion(io, mr); - } - } } =20 static void via_class_init(ObjectClass *klass, void *data) @@ -527,32 +605,14 @@ static const TypeInfo via_info =3D { }; =20 =20 -static void vt82c686b_superio_class_init(ObjectClass *klass, void *data) -{ - ISASuperIOClass *sc =3D ISA_SUPERIO_CLASS(klass); - - sc->serial.count =3D 2; - sc->parallel.count =3D 1; - sc->ide.count =3D 0; - sc->floppy.count =3D 1; -} - -static const TypeInfo via_superio_info =3D { - .name =3D TYPE_VT82C686B_SUPERIO, - .parent =3D TYPE_ISA_SUPERIO, - .instance_size =3D sizeof(ISASuperIODevice), - .class_size =3D sizeof(ISASuperIOClass), - .class_init =3D vt82c686b_superio_class_init, -}; - - static void vt82c686b_register_types(void) { type_register_static(&via_pm_info); type_register_static(&vt82c686b_pm_info); type_register_static(&vt8231_pm_info); - type_register_static(&via_info); type_register_static(&via_superio_info); + type_register_static(&vt82c686b_superio_info); + type_register_static(&via_info); } =20 type_init(vt82c686b_register_types) diff --git a/include/hw/isa/vt82c686.h b/include/hw/isa/vt82c686.h index 9b6d610e83..0692b9a527 100644 --- a/include/hw/isa/vt82c686.h +++ b/include/hw/isa/vt82c686.h @@ -2,7 +2,6 @@ #define HW_VT82C686_H =20 #define TYPE_VT82C686B_ISA "vt82c686b-isa" -#define TYPE_VT82C686B_SUPERIO "vt82c686b-superio" #define TYPE_VT82C686B_PM "vt82c686b-pm" #define TYPE_VT8231_PM "vt8231-pm" #define TYPE_VIA_AC97 "via-ac97" --=20 2.21.3 From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224650; cv=none; d=zohomail.com; s=zohoarc; b=G0qU15djPFqnTeO3MhKuSDM2R282ou0prHGXv/P6wNiBLZBwv2ugBrwnK/so1wb3RBmUaLAYzuHgQ+8RUXAd1dJhjgnv+ZUE3iMIpjMebkewugJcG16ETogEVtBTSV4/BJR3wY4u4Nm7CJb1yOQyr5Rl+P1g9aYKOy46QEcHRhA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224650; 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=TwHgEdSZr+q+5M4vT5L7FrOADramA5e1QRcyuJkWk4Y=; b=RKkKG7yHINAr8y9wWSh5ERKzCdrC0xJjxwSr7We0OgGq/5uWIN+yhlYlWoMN1fI28OFbJmArhpFxMuLaTWW4FQGce8jyuQBgMkhK4M931oKt0mjAx+1RW/l3fWg0wa1RBLU44/zaFJDrKKmQqXH4lvqQvPXYvt6iRstxQaEhZIM= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1610224650913432.2585460659669; Sat, 9 Jan 2021 12:37:30 -0800 (PST) Received: from localhost ([::1]:57140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyKzJ-0007tm-Lz for importer@patchew.org; Sat, 09 Jan 2021 15:37:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsN-0008Sb-9q for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:19 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:33412) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsI-0007DZ-SD for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:19 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 896B4747603; Sat, 9 Jan 2021 21:29:58 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 923FF74760F; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: <882243e3f6d222d08f67a363d24c820e4431d4d5.1610223397.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 12/13] vt82c686: Add VT8231_SUPERIO based on VIA_SUPERIO Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The VT8231 south bridge is very similar to VT82C686B but there are some differences in register addresses and functionality, e.g. the VT8231 only has one serial port. This commit adds VT8231_SUPERIO subclass based on the abstract VIA_SUPERIO class to emulate the superio part of VT8231. Signed-off-by: BALATON Zoltan --- hw/isa/vt82c686.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index f23fb2ea25..f27aea1643 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -489,6 +489,126 @@ static const TypeInfo vt82c686b_superio_info =3D { }; =20 =20 +#define TYPE_VT8231_SUPERIO "vt8231-superio" + +static void vt8231_superio_cfg_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size) +{ + ViaSuperIOState *sc =3D opaque; + uint8_t idx =3D sc->regs[0]; + + if (addr =3D=3D 0) { /* config index register */ + sc->regs[0] =3D data; + return; + } + + /* config data register */ + trace_via_superio_write(idx, data); + switch (idx) { + case 0x00 ... 0xdf: + case 0xe7 ... 0xef: + case 0xf0 ... 0xf1: + case 0xf5: + case 0xf8: + case 0xfd: + /* ignore write to read only registers */ + return; + case 0xf2: /* Function select */ + { + data &=3D 0x17; + if (data & BIT(2)) { /* Serial port enable */ + ISADevice *dev =3D 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 =3D 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]); + } + } + break; + } + case 0xf4: /* Serial port io base address */ + { + data &=3D 0xfe; + sc->superio.serial[0]->ioport_id =3D data << 2; + if (memory_region_is_mapped(sc->serial_io[0])) { + memory_region_set_address(sc->serial_io[0], data << 2); + } + break; + } + default: + qemu_log_mask(LOG_UNIMP, + "via_superio_cfg: unimplemented register 0x%x\n", id= x); + break; + } + sc->regs[idx] =3D data; +} + +static const MemoryRegionOps vt8231_superio_cfg_ops =3D { + .read =3D via_superio_cfg_read, + .write =3D vt8231_superio_cfg_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl =3D { + .min_access_size =3D 1, + .max_access_size =3D 1, + }, +}; + +static void vt8231_superio_reset(DeviceState *dev) +{ + ViaSuperIOState *s =3D VIA_SUPERIO(dev); + + memset(s->regs, 0, sizeof(s->regs)); + /* Device ID */ + s->regs[0xf0] =3D 0x3c; + /* Device revision */ + s->regs[0xf1] =3D 0x01; + /* Function select - all disabled */ + vt8231_superio_cfg_write(s, 0, 0xf2, 1); + vt8231_superio_cfg_write(s, 1, 0x03, 1); + /* Serial port base addr */ + vt8231_superio_cfg_write(s, 0, 0xf4, 1); + vt8231_superio_cfg_write(s, 1, 0xfe, 1); + /* Parallel port base addr */ + vt8231_superio_cfg_write(s, 0, 0xf6, 1); + vt8231_superio_cfg_write(s, 1, 0xde, 1); + /* Floppy ctrl base addr */ + vt8231_superio_cfg_write(s, 0, 0xf7, 1); + vt8231_superio_cfg_write(s, 1, 0xfc, 1); + + vt8231_superio_cfg_write(s, 0, 0, 1); +} + +static void vt8231_superio_init(Object *obj) +{ + VIA_SUPERIO(obj)->io_ops =3D &vt8231_superio_cfg_ops; +} + +static void vt8231_superio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ISASuperIOClass *sc =3D ISA_SUPERIO_CLASS(klass); + + dc->reset =3D vt8231_superio_reset; + sc->serial.count =3D 1; + sc->parallel.count =3D 1; + sc->ide.count =3D 0; /* emulated by via-ide */ + sc->floppy.count =3D 1; +} + +static const TypeInfo vt8231_superio_info =3D { + .name =3D TYPE_VT8231_SUPERIO, + .parent =3D TYPE_VIA_SUPERIO, + .instance_size =3D sizeof(ViaSuperIOState), + .instance_init =3D vt8231_superio_init, + .class_size =3D sizeof(ISASuperIOClass), + .class_init =3D vt8231_superio_class_init, +}; + + OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686B_ISA) =20 struct VT82C686BISAState { @@ -612,6 +732,7 @@ static void vt82c686b_register_types(void) type_register_static(&vt8231_pm_info); type_register_static(&via_superio_info); type_register_static(&vt82c686b_superio_info); + type_register_static(&vt8231_superio_info); type_register_static(&via_info); } =20 --=20 2.21.3 From nobody Thu May 2 06:05:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=eik.bme.hu ARC-Seal: i=1; a=rsa-sha256; t=1610224891; cv=none; d=zohomail.com; s=zohoarc; b=Dy7JaOJcxXi/6dJSW6jOYUyxy5Ib9IjyL9tAKdVII2l34EiprN7QqsW7xwayvq0eWldoFdwlAihLD7kj0ZaGx427aKniVfiMYcWB7knyyLvg9cODducLNhFRsomKhpadbOv1koIOY+TK0WD9iFlUkImEjAX7SD1bhNUfuE9kw4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610224891; 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=0TMQD89+Obiujsd96YQaaVYTwy5CN3htptlrYcUfGxc=; b=mK4dPKG4191n50zPirAaBjdwFfKoDDgXYYLcIVOxXLrxNtUHST1LfzGBAYssLiPU20lO9LugusHSB3DKPB9iS1RsjZLE1/OYApjHQl/ZOFw+dxc+sPBdmp8JThZLWuwi/rrldDENL23NuzdMcma5MO+hy9DnL7RK7S0dSv4wC7A= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1610224891093101.03165307403958; Sat, 9 Jan 2021 12:41:31 -0800 (PST) Received: from localhost ([::1]:37714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyL3B-0003Fp-Tu for importer@patchew.org; Sat, 09 Jan 2021 15:41:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsT-00005V-Mc for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:27 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:33414) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyKsL-0007Dq-3l for qemu-devel@nongnu.org; Sat, 09 Jan 2021 15:30:25 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id AD6A8747608; Sat, 9 Jan 2021 21:29:58 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 98A7C747610; Sat, 9 Jan 2021 21:29:57 +0100 (CET) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 13/13] vt82c686: Add emulation of VT8231 south bridge Date: Sat, 09 Jan 2021 21:16:36 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 10% 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=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: Huacai Chen , f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add emulation of VT8231 south bridge ISA part based on the similar VT82C686B but implemented in a separate subclass that holds the differences while reusing parts that can be shared. Signed-off-by: BALATON Zoltan --- hw/isa/vt82c686.c | 154 ++++++++++++++++++++++++++++++-------- include/hw/isa/vt82c686.h | 1 + include/hw/pci/pci_ids.h | 3 +- 3 files changed, 126 insertions(+), 32 deletions(-) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index f27aea1643..50181e22dd 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -8,6 +8,9 @@ * * Contributions after 2012-01-13 are licensed under the terms of the * GNU GPL, version 2 or (at your option) any later version. + * + * VT8231 south bridge support and general clean up to allow it + * Copyright (c) 2018-2020 BALATON Zoltan */ =20 #include "qemu/osdep.h" @@ -609,24 +612,48 @@ static const TypeInfo vt8231_superio_info =3D { }; =20 =20 -OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686B_ISA) +#define TYPE_VIA_ISA "via-isa" +OBJECT_DECLARE_SIMPLE_TYPE(ViaISAState, VIA_ISA) =20 -struct VT82C686BISAState { +struct ViaISAState { PCIDevice dev; qemu_irq cpu_intr; ViaSuperIOState *via_sio; }; =20 +static const VMStateDescription vmstate_via =3D { + .name =3D "via-isa", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_PCI_DEVICE(dev, ViaISAState), + VMSTATE_END_OF_LIST() + } +}; + +static const TypeInfo via_isa_info =3D { + .name =3D TYPE_VIA_ISA, + .parent =3D TYPE_PCI_DEVICE, + .instance_size =3D sizeof(ViaISAState), + .abstract =3D true, + .interfaces =3D (InterfaceInfo[]) { + { INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { }, + }, +}; + static void via_isa_request_i8259_irq(void *opaque, int irq, int level) { - VT82C686BISAState *s =3D opaque; + ViaISAState *s =3D opaque; qemu_set_irq(s->cpu_intr, level); } =20 +/* TYPE_VT82C686B_ISA */ + static void vt82c686b_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int len) { - VT82C686BISAState *s =3D VT82C686B_ISA(d); + ViaISAState *s =3D VIA_ISA(d); =20 trace_via_isa_write(addr, val, len); pci_default_write_config(d, addr, val, len); @@ -636,19 +663,9 @@ static void vt82c686b_write_config(PCIDevice *d, uint3= 2_t addr, } } =20 -static const VMStateDescription vmstate_via =3D { - .name =3D "vt82c686b", - .version_id =3D 1, - .minimum_version_id =3D 1, - .fields =3D (VMStateField[]) { - VMSTATE_PCI_DEVICE(dev, VT82C686BISAState), - VMSTATE_END_OF_LIST() - } -}; - static void vt82c686b_isa_reset(DeviceState *dev) { - VT82C686BISAState *s =3D VT82C686B_ISA(dev); + ViaISAState *s =3D VIA_ISA(dev); uint8_t *pci_conf =3D s->dev.config; =20 pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x000000c0); @@ -668,7 +685,7 @@ static void vt82c686b_isa_reset(DeviceState *dev) =20 static void vt82c686b_realize(PCIDevice *d, Error **errp) { - VT82C686BISAState *s =3D VT82C686B_ISA(d); + ViaISAState *s =3D VIA_ISA(d); DeviceState *dev =3D DEVICE(d); ISABus *isa_bus; qemu_irq *isa_irq; @@ -692,7 +709,7 @@ static void vt82c686b_realize(PCIDevice *d, Error **err= p) } } =20 -static void via_class_init(ObjectClass *klass, void *data) +static void vt82c686b_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); @@ -700,28 +717,101 @@ static void via_class_init(ObjectClass *klass, void = *data) k->realize =3D vt82c686b_realize; k->config_write =3D vt82c686b_write_config; k->vendor_id =3D PCI_VENDOR_ID_VIA; - k->device_id =3D PCI_DEVICE_ID_VIA_ISA_BRIDGE; + k->device_id =3D PCI_DEVICE_ID_VIA_82C686B_ISA; k->class_id =3D PCI_CLASS_BRIDGE_ISA; k->revision =3D 0x40; dc->reset =3D vt82c686b_isa_reset; dc->desc =3D "ISA bridge"; dc->vmsd =3D &vmstate_via; - /* - * Reason: part of VIA VT82C686 southbridge, needs to be wired up, - * e.g. by mips_fuloong2e_init() - */ + /* Reason: part of VIA VT82C686 southbridge, needs to be wired up */ dc->user_creatable =3D false; } =20 -static const TypeInfo via_info =3D { +static const TypeInfo vt82c686b_isa_info =3D { .name =3D TYPE_VT82C686B_ISA, - .parent =3D TYPE_PCI_DEVICE, - .instance_size =3D sizeof(VT82C686BISAState), - .class_init =3D via_class_init, - .interfaces =3D (InterfaceInfo[]) { - { INTERFACE_CONVENTIONAL_PCI_DEVICE }, - { }, - }, + .parent =3D TYPE_VIA_ISA, + .instance_size =3D sizeof(ViaISAState), + .class_init =3D vt82c686b_class_init, +}; + +/* TYPE_VT8231_ISA */ + +static void vt8231_write_config(PCIDevice *d, uint32_t addr, + uint32_t val, int len) +{ + ViaISAState *s =3D VIA_ISA(d); + + trace_via_isa_write(addr, val, len); + pci_default_write_config(d, addr, val, len); + if (addr =3D=3D 0x50) { + /* BIT(2): enable or disable superio config io ports */ + via_superio_io_enable(s->via_sio, val & BIT(2)); + } +} + +static void vt8231_isa_reset(DeviceState *dev) +{ + ViaISAState *s =3D VIA_ISA(dev); + uint8_t *pci_conf =3D s->dev.config; + + pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x000000c0); + pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMO= RY | + PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL); + pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM); + + pci_conf[0x58] =3D 0x40; /* Miscellaneous Control 0 */ + pci_conf[0x67] =3D 0x08; /* Fast IR Config */ + pci_conf[0x6b] =3D 0x01; /* Fast IR I/O Base */ +} + +static void vt8231_realize(PCIDevice *d, Error **errp) +{ + ViaISAState *s =3D VIA_ISA(d); + DeviceState *dev =3D DEVICE(d); + ISABus *isa_bus; + qemu_irq *isa_irq; + int i; + + qdev_init_gpio_out(dev, &s->cpu_intr, 1); + isa_irq =3D qemu_allocate_irqs(via_isa_request_i8259_irq, s, 1); + isa_bus =3D isa_bus_new(dev, get_system_memory(), pci_address_space_io= (d), + &error_fatal); + 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); + s->via_sio =3D VIA_SUPERIO(isa_create_simple(isa_bus, TYPE_VT8231_SUPE= RIO)); + mc146818_rtc_init(isa_bus, 2000, NULL); + + for (i =3D 0; i < PCI_CONFIG_HEADER_SIZE; i++) { + if (i < PCI_COMMAND || i >=3D PCI_REVISION_ID) { + d->wmask[i] =3D 0; + } + } +} + +static void vt8231_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); + + k->realize =3D vt8231_realize; + k->config_write =3D vt8231_write_config; + k->vendor_id =3D PCI_VENDOR_ID_VIA; + k->device_id =3D PCI_DEVICE_ID_VIA_8231_ISA; + k->class_id =3D PCI_CLASS_BRIDGE_ISA; + k->revision =3D 0x10; + dc->reset =3D vt8231_isa_reset; + dc->desc =3D "ISA bridge"; + dc->vmsd =3D &vmstate_via; + /* Reason: part of VIA VT8231 southbridge, needs to be wired up */ + dc->user_creatable =3D false; +} + +static const TypeInfo vt8231_isa_info =3D { + .name =3D TYPE_VT8231_ISA, + .parent =3D TYPE_VIA_ISA, + .instance_size =3D sizeof(ViaISAState), + .class_init =3D vt8231_class_init, }; =20 =20 @@ -733,7 +823,9 @@ static void vt82c686b_register_types(void) type_register_static(&via_superio_info); type_register_static(&vt82c686b_superio_info); type_register_static(&vt8231_superio_info); - type_register_static(&via_info); + type_register_static(&via_isa_info); + type_register_static(&vt82c686b_isa_info); + type_register_static(&vt8231_isa_info); } =20 type_init(vt82c686b_register_types) diff --git a/include/hw/isa/vt82c686.h b/include/hw/isa/vt82c686.h index 0692b9a527..0f01aaa471 100644 --- a/include/hw/isa/vt82c686.h +++ b/include/hw/isa/vt82c686.h @@ -3,6 +3,7 @@ =20 #define TYPE_VT82C686B_ISA "vt82c686b-isa" #define TYPE_VT82C686B_PM "vt82c686b-pm" +#define TYPE_VT8231_ISA "vt8231-isa" #define TYPE_VT8231_PM "vt8231-pm" #define TYPE_VIA_AC97 "via-ac97" #define TYPE_VIA_MC97 "via-mc97" diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h index 7c183d16f9..463ffa054e 100644 --- a/include/hw/pci/pci_ids.h +++ b/include/hw/pci/pci_ids.h @@ -201,12 +201,13 @@ #define PCI_VENDOR_ID_XILINX 0x10ee =20 #define PCI_VENDOR_ID_VIA 0x1106 -#define PCI_DEVICE_ID_VIA_ISA_BRIDGE 0x0686 +#define PCI_DEVICE_ID_VIA_82C686B_ISA 0x0686 #define PCI_DEVICE_ID_VIA_IDE 0x0571 #define PCI_DEVICE_ID_VIA_UHCI 0x3038 #define PCI_DEVICE_ID_VIA_82C686B_PM 0x3057 #define PCI_DEVICE_ID_VIA_AC97 0x3058 #define PCI_DEVICE_ID_VIA_MC97 0x3068 +#define PCI_DEVICE_ID_VIA_8231_ISA 0x8231 #define PCI_DEVICE_ID_VIA_8231_PM 0x8235 =20 #define PCI_VENDOR_ID_MARVELL 0x11ab --=20 2.21.3