[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 08/12] vt82c686: Fix superio_cfg_{read,write}() functions
From: |
BALATON Zoltan |
Subject: |
[PATCH 08/12] vt82c686: Fix superio_cfg_{read,write}() functions |
Date: |
Wed, 06 Jan 2021 22:13:58 +0100 |
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
simpilifies object state.
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
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 3a45056226..1a876a1fbf 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 = {
typedef struct SuperIOConfig {
uint8_t regs[0x100];
- uint8_t index;
MemoryRegion io;
} SuperIOConfig;
@@ -258,42 +258,49 @@ static void superio_cfg_write(void *opaque, hwaddr addr,
uint64_t data,
unsigned size)
{
SuperIOConfig *sc = opaque;
+ uint8_t idx = sc->regs[0];
- if (addr == 0x3f0) { /* config index register */
- sc->index = data & 0xff;
- } else {
- bool can_write = 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 = false;
- break;
- /* case 0xe6 ... 0xe8: Should set base port of parallel and serial */
- default:
- break;
+ if (addr == 0) { /* config index register */
+ sc->regs[0] = data;
+ return;
+ }
- }
- if (can_write) {
- sc->regs[sc->index] = 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", idx);
+ break;
}
+ sc->regs[idx] = data;
}
static uint64_t superio_cfg_read(void *opaque, hwaddr addr, unsigned size)
{
SuperIOConfig *sc = opaque;
- uint8_t val = sc->regs[sc->index];
+ uint8_t idx = sc->regs[0];
+ uint8_t val = sc->regs[idx];
- trace_via_superio_read(sc->index, val);
+ if (addr == 0) {
+ return idx;
+ }
+ if (addr == 1 && idx == 0) {
+ val = 0; /* reading reg 0 where we store index value */
+ }
+ trace_via_superio_read(idx, val);
return val;
}
--
2.21.3
- [PATCH 04/12] vt82c686: Fix up power management io base and config, (continued)
- [PATCH 04/12] vt82c686: Fix up power management io base and config, BALATON Zoltan, 2021/01/06
- [PATCH 07/12] vt82c686: Move creation of ISA devices to the ISA bridge, BALATON Zoltan, 2021/01/06
- [PATCH 01/12] vt82c686: Move superio memory region to SuperIOConfig struct, BALATON Zoltan, 2021/01/06
- [PATCH 09/12] vt82c686: Implement control of serial port io ranges via config regs, BALATON Zoltan, 2021/01/06
- [PATCH 11/12] vt82c686: Add VT8231_SUPERIO based on VIA_SUPERIO, BALATON Zoltan, 2021/01/06
- [PATCH 03/12] vt82c686: Fix SMBus IO base and configuration registers, BALATON Zoltan, 2021/01/06
- [PATCH 02/12] vt82c686: Reorganise code, BALATON Zoltan, 2021/01/06
- [PATCH 10/12] vt82c686: QOM-ify superio related functionality, BALATON Zoltan, 2021/01/06
- [PATCH 08/12] vt82c686: Fix superio_cfg_{read,write}() functions,
BALATON Zoltan <=
- [PATCH 12/12] vt82c686: Add emulation of VT8231 south bridge, BALATON Zoltan, 2021/01/06