[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/22] hw/misc/applesmc: Simplify DeviceReset handler
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 07/22] hw/misc/applesmc: Simplify DeviceReset handler |
Date: |
Thu, 25 Apr 2024 13:01:40 +0200 |
Have applesmc_find_key() return a const pointer.
Since the returned buffers are not modified in
applesmc_io_data_write(), it is pointless to
delete and re-add the keys in the DeviceReset
handler. Add them once in DeviceRealize, and
discard them in the DeviceUnrealize handler.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20240410180819.92332-1-philmd@linaro.org>
---
hw/misc/applesmc.c | 36 +++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c
index 14e3ef667d..59a4899312 100644
--- a/hw/misc/applesmc.c
+++ b/hw/misc/applesmc.c
@@ -145,7 +145,7 @@ static void applesmc_io_cmd_write(void *opaque, hwaddr
addr, uint64_t val,
s->data_pos = 0;
}
-static struct AppleSMCData *applesmc_find_key(AppleSMCState *s)
+static const struct AppleSMCData *applesmc_find_key(AppleSMCState *s)
{
struct AppleSMCData *d;
@@ -161,7 +161,7 @@ static void applesmc_io_data_write(void *opaque, hwaddr
addr, uint64_t val,
unsigned size)
{
AppleSMCState *s = opaque;
- struct AppleSMCData *d;
+ const struct AppleSMCData *d;
smc_debug("DATA received: 0x%02x\n", (uint8_t)val);
switch (s->cmd) {
@@ -269,23 +269,10 @@ static void applesmc_add_key(AppleSMCState *s, const char
*key,
static void qdev_applesmc_isa_reset(DeviceState *dev)
{
AppleSMCState *s = APPLE_SMC(dev);
- struct AppleSMCData *d, *next;
- /* Remove existing entries */
- QLIST_FOREACH_SAFE(d, &s->data_def, node, next) {
- QLIST_REMOVE(d, node);
- g_free(d);
- }
s->status = 0x00;
s->status_1e = 0x00;
s->last_ret = 0x00;
-
- applesmc_add_key(s, "REV ", 6, "\x01\x13\x0f\x00\x00\x03");
- applesmc_add_key(s, "OSK0", 32, s->osk);
- applesmc_add_key(s, "OSK1", 32, s->osk + 32);
- applesmc_add_key(s, "NATJ", 1, "\0");
- applesmc_add_key(s, "MSSP", 1, "\0");
- applesmc_add_key(s, "MSSD", 1, "\0x3");
}
static const MemoryRegionOps applesmc_data_io_ops = {
@@ -343,6 +330,24 @@ static void applesmc_isa_realize(DeviceState *dev, Error
**errp)
}
QLIST_INIT(&s->data_def);
+ applesmc_add_key(s, "REV ", 6, "\x01\x13\x0f\x00\x00\x03");
+ applesmc_add_key(s, "OSK0", 32, s->osk);
+ applesmc_add_key(s, "OSK1", 32, s->osk + 32);
+ applesmc_add_key(s, "NATJ", 1, "\0");
+ applesmc_add_key(s, "MSSP", 1, "\0");
+ applesmc_add_key(s, "MSSD", 1, "\0x3");
+}
+
+static void applesmc_unrealize(DeviceState *dev)
+{
+ AppleSMCState *s = APPLE_SMC(dev);
+ struct AppleSMCData *d, *next;
+
+ /* Remove existing entries */
+ QLIST_FOREACH_SAFE(d, &s->data_def, node, next) {
+ QLIST_REMOVE(d, node);
+ g_free(d);
+ }
}
static Property applesmc_isa_properties[] = {
@@ -377,6 +382,7 @@ static void qdev_applesmc_class_init(ObjectClass *klass,
void *data)
AcpiDevAmlIfClass *adevc = ACPI_DEV_AML_IF_CLASS(klass);
dc->realize = applesmc_isa_realize;
+ dc->unrealize = applesmc_unrealize;
dc->reset = qdev_applesmc_isa_reset;
device_class_set_props(dc, applesmc_isa_properties);
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
--
2.41.0
- [PULL 00/22] Misc HW patches for 2024-04-25, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 01/22] qom: add default value, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 02/22] qmp: add dump machine type compatibility properties, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 03/22] python/qemu/machine: add method to retrieve QEMUMachine::binary field, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 04/22] scripts: add script to compare compatibility properties, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 05/22] hw/core: Remove check on NEED_CPU_H in tcg-cpu-ops.h, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 07/22] hw/misc/applesmc: Simplify DeviceReset handler,
Philippe Mathieu-Daudé <=
- [PULL 06/22] target/i386: Move APIC related code to cpu-apic.c, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 10/22] hw: Fix problem with the A*MPCORE switches in the Kconfig files, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 09/22] hw/riscv/virt: Replace sprintf by g_strdup_printf, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 13/22] hw/cxl/cxl-cdat: Make ct3_build_cdat() return boolean, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 11/22] hw: Add a Kconfig switch for the TYPE_CPU_CLUSTER device, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 08/22] hw/misc/imx: Replace sprintf() by snprintf(), Philippe Mathieu-Daudé, 2024/04/25
- [PULL 16/22] hw/xtensa: Include missing 'exec/cpu-common.h' in 'bootparam.h', Philippe Mathieu-Daudé, 2024/04/25
- [PULL 15/22] hw/elf_ops: Rename elf_ops.h -> elf_ops.h.inc, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 19/22] hw/core/machine: Introduce the module as a CPU topology level, Philippe Mathieu-Daudé, 2024/04/25
- [PULL 21/22] hw/core: Introduce module-id as the topology subindex, Philippe Mathieu-Daudé, 2024/04/25