From nobody Wed Feb 11 01:00:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.43 as permitted sender) client-ip=209.85.221.43; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f43.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1613918220; cv=none; d=zohomail.com; s=zohoarc; b=lkDOY1qUrx8Bpy6W6OqDlrQZWWfbEHqBLe9jDbXzJ4dwsYEotfGmK3Iqhp/yWtf0sBpcAatEJ4xHvXuj5ktPg4vWiKp1DhE4hqqiayR7HA5TSrHaUKmByshDK7Tn1PhlrKhz6Qz0trtCbALtxPLWfoVXlrW6p7PbAc+WjX82jWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613918220; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0W6aGfZKIKjWp3v6QqcMHHh44Y6g4mIdHgaCTPn7oN8=; b=bsZiXSD025q2tZSrP30raoAkfEVlu2G/+6ptS6SkSyswucqJzeKirDNJZwoY7ejVpCj7PUdeRg/d8xoO4G4neKsxk7XUPl/Gx8ZqakC5uKCMFqp6zOvBWw7KBVcOBuFfnf+pfgwg52vzAcL6IU7QpHIGUEoiOf8zUaZJg6vEXJk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by mx.zohomail.com with SMTPS id 161391822054463.91254892899997; Sun, 21 Feb 2021 06:37:00 -0800 (PST) Received: by mail-wr1-f43.google.com with SMTP id v15so16351467wrx.4 for ; Sun, 21 Feb 2021 06:36:59 -0800 (PST) Return-Path: Return-Path: Received: from localhost.localdomain (68.red-83-57-175.dynamicip.rima-tde.net. [83.57.175.68]) by smtp.gmail.com with ESMTPSA id p12sm20502064wmq.1.2021.02.21.06.36.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Feb 2021 06:36:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0W6aGfZKIKjWp3v6QqcMHHh44Y6g4mIdHgaCTPn7oN8=; b=icwcfoVRsVI5ttGpGg7pl0YLfKZUWdyKx+lxy392TGkLgom3f7I5UKQOD2PhzfxGaM Qwn38F37J2f7zvYXWMN4sYx4v507VHM1Fze5YMvrq4jjO5TIsXK7LTKRFlXFMaf84Cy9 3zDpwmZ+U106Tg0lVSDfGffGTa72Ix9vLjSet+ARzOtMefkoHjca+c8IbCdpbVOuGow7 FQB/nTqI0je+/k6P/tnomLGsLmfsK85tVJJhQyOdxFwnUyQMUVHuUXYDhJ2B+yAucuz9 XDEpRnjyjhe3Cm7wzL+HUY2mZ9ggJNZ9Vi/tijhg6Vgnf21EbiVFyQU44H27Q+5Li+a2 yiMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=0W6aGfZKIKjWp3v6QqcMHHh44Y6g4mIdHgaCTPn7oN8=; b=eo5pYWaZ89LZoR/FRAoPEe0hvaChIVES3yz6lF4jQytK7HJCfKcBjXp5GSNmjcwyh7 cnlsd78rqK1weeKbd/aBKBYnXOlMy/UcNtL6pM50IIzwSx5VOr75aCSfqUhpmP+3HRUf egaO4XrRXxxQpbtFN6fd5mdFhSJf8Q7BEkj0I4Fu/0J8M/4ueCxi5+0gWbpOZ+yPlgjs pfFuhGuDoMvtRWfh/Aj5VtioaoMlWQZcs4FVFST8HXsMKt+ABxeEJiJPmMKP6dFm9Nfc d3/SN9rZR3mxbZTElXMuqjYWZtgihsokucSSsRNZ2Fj0pj9dWJEewV1rzd7nB2WVVHg1 xVLA== X-Gm-Message-State: AOAM532ov5vlk2qDn/AXvebIr45NnzNNp6mmbtj9MyFSvPoLQuA4JCuv PMdU++GlXxAi7qvp1ZNXspk= X-Google-Smtp-Source: ABdhPJw05sqNyF5aOEG69SEwIjLruYo/DJstOUqHrmlwpTMjtLXNQfU8TPLHd+EcCnU+jh+vM6QI7A== X-Received: by 2002:adf:aa08:: with SMTP id p8mr17208452wrd.232.1613918218735; Sun, 21 Feb 2021 06:36:58 -0800 (PST) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paul Burton , Wainer dos Santos Moschetta , Aleksandar Rikalo , Aurelien Jarno , Marcel Apfelbaum , Cleber Rosa , "Michael S. Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Huacai Chen , Jiaxun Yang , BALATON Zoltan Subject: [PULL 29/43] vt82c686: Reorganise code Date: Sun, 21 Feb 2021 15:34:18 +0100 Message-Id: <20210221143432.2468220-30-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210221143432.2468220-1-f4bug@amsat.org> References: <20210221143432.2468220-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) From: BALATON Zoltan 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 Message-Id: <9f942989dba46fc1c23b881f6cb135948f818c2f.1610223397.git.balato= n@eik.bme.hu> Signed-off-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 30fe02f4c60..fe8961b0573 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.26.2