[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 20/24] vt82c686: Fix superio_cfg_{read,write}() functions
From: |
BALATON Zoltan |
Subject: |
[PATCH 20/24] vt82c686: Fix superio_cfg_{read,write}() functions |
Date: |
Sat, 02 Jan 2021 11:43:35 +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 07/24] vt82c686: Remove legacy vt82c686b_isa_init() function, (continued)
- [PATCH 07/24] vt82c686: Remove legacy vt82c686b_isa_init() function, BALATON Zoltan, 2021/01/02
- [PATCH 09/24] vt82c686: Convert debug printf to trace points, BALATON Zoltan, 2021/01/02
- [PATCH 02/24] vt82c686: Remove unnecessary _DEVICE suffix from type macros, BALATON Zoltan, 2021/01/02
- [PATCH 05/24] vt82c686: Split off via-[am]c97 into separate file in hw/audio, BALATON Zoltan, 2021/01/02
- [PATCH 10/24] vt82c686: Remove unneeded includes and defines, BALATON Zoltan, 2021/01/02
- [PATCH 11/24] vt82c686: Use shorter name for local variable holding object state, BALATON Zoltan, 2021/01/02
- [PATCH 13/24] vt82c686: Move superio memory region to SuperIOConfig struct, BALATON Zoltan, 2021/01/02
- [PATCH 21/24] vt82c686: Implement control of serial port io ranges via config regs, BALATON Zoltan, 2021/01/02
- [PATCH 20/24] vt82c686: Fix superio_cfg_{read,write}() functions,
BALATON Zoltan <=
- [PATCH 23/24] vt82c686: Add VT8231_SUPERIO based on VIA_SUPERIO, BALATON Zoltan, 2021/01/02
- [PATCH 18/24] vt82c686: Simplify vt82c686b_realize(), BALATON Zoltan, 2021/01/02
- [PATCH 15/24] vt82c686: Fix SMBus IO base and configuration registers, BALATON Zoltan, 2021/01/02
- [PATCH 17/24] vt82c686: Make vt82c686b-pm an abstract base class and add vt8231-pm based on it, BALATON Zoltan, 2021/01/02
- [PATCH 14/24] vt82c686: Reorganise code, BALATON Zoltan, 2021/01/02
- [PATCH 19/24] vt82c686: Move creation of ISA devices to the ISA bridge, BALATON Zoltan, 2021/01/02
- [PATCH 12/24] vt82c686: Rename superio config related parts, BALATON Zoltan, 2021/01/02
- [PATCH 16/24] vt82c686: Fix up power management io base and config, BALATON Zoltan, 2021/01/02
- [PATCH 24/24] vt82c686: Add emulation of VT8231 south bridge, BALATON Zoltan, 2021/01/02