From patchwork Wed Apr 10 18:08:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 787533 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp820829wrs; Wed, 10 Apr 2024 11:09:08 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX1qb7vJxmNl66q2/sIiKkjUwc4hVjCyP7OayDeg2IMyr3PSG9i6PmC5QrUBRwHqg8XniBQAOfmNztv0Zt8e9HA X-Google-Smtp-Source: AGHT+IF328dUaFnO/j3fX71Z7nfmFaHQ3vIeOtIDOS2J1U26VCfnbtxafwPzAD0k6VNr5uOUqJlf X-Received: by 2002:a05:6870:5b95:b0:22f:8a05:1a6b with SMTP id em21-20020a0568705b9500b0022f8a051a6bmr3672313oab.29.1712772548093; Wed, 10 Apr 2024 11:09:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712772548; cv=none; d=google.com; s=arc-20160816; b=XldE5O4j7NoAPPdxYiI2diqepjWdnp8SVupw78nM6fkrZHhfSJlzmmMyKVlYNGU4+F C3WQlBIF0kBKXYJmqRI2Q/NGJ2o9YEVEfEfWYQAk+5zGPNfaauHpqMxqTIoD30E1KfkF Ug7tmyuGF84ouisbL1pwPQ9WCjt1/HOu9Zjfrz+Z+VhcF43Hbo3yO9M3XO3VaW4UQolQ v2cIFoFABL2aLkECfPwEPqfXreTAFfsEpTKUFblDu6iImuChpnIaprvoWAuQvygcT8Mh o2YzrvqQeikIKhVgReJGwOTZfcSLHg+RliVxF8rnnPlZoG7IkAryMkcw/gkSSwkdU6Ub VJoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=J9NiNwxiik0OPXqS4C5bJncJdvLmqX2i9ON6pLi1lts=; fh=g8Wsk2hzWGJylbvXNYHcrk0eB3CmyVsCD/YS5GCLn8Q=; b=a5vSc/ea1DWSIJqCDx/XUHTp6Wa+lW8JYqWnVwB+F4lBHZqYWRm324ZPEcmMejx391 uBU9RJiCOJGpkuFoVpKTqOjBeaen+MKk/4udA1RuNMfiwKbZ+dToDRBRSP9HHQpRmcho Xqpsd1hIuXDi6gXuy8URmVgEHVqWA9YNQRuAqY7uAeFqXFTGhhX7DEClEhPUjfS94Oga YI8H3+2YtNS4+LUrVTVYPPkuVsdxyGEtjnGg+Clq5tT1gCLUIwWZzQD5sq5YjscePT5v NZ3oGyOPAwVyx5eHMpRm0hG1bDENbJ2T2cw2X03YDfEJdwv2v5JWhEWp2IGbMkeT+qas g07w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="y/OqxLa7"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f28-20020a05620a15bc00b0078d6571a96asi7250521qkk.718.2024.04.10.11.09.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Apr 2024 11:09:08 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="y/OqxLa7"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rucN1-0000gp-JS; Wed, 10 Apr 2024 14:08:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rucN0-0000ge-IR for qemu-devel@nongnu.org; Wed, 10 Apr 2024 14:08:26 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rucMy-0005Mx-PA for qemu-devel@nongnu.org; Wed, 10 Apr 2024 14:08:26 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-417d08135b6so211425e9.1 for ; Wed, 10 Apr 2024 11:08:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712772502; x=1713377302; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=J9NiNwxiik0OPXqS4C5bJncJdvLmqX2i9ON6pLi1lts=; b=y/OqxLa7FJQuKj4DNIuXc5+nZni8/Qfg+c/9vWgRBHnysSGTjeYJquECaYBILZyfJ8 uOrUPQEgRK69NM07uXpgsnW/u2D7XHEz2A7k8EU8oUUgjs8LKuw6Kfgtpo5ZbBZv+Dl0 FnBDqMnzmx4bvF+DdWTpzY/cJKK8B1kNDlBiWTHHFqh+6kZtZyQisHnsUaSooHoQWP+3 iocRElFGJwJahCJKjT1ZcboFWX/oHcHhnf+Tg3FGjfww1FxZKrZblg0MatcyPChV6sbp KYJAqU5SaoXz03QQHZBVBNOzCtDu24qhybzpIDHozIeKrxB5c2k1a/MbfXNLt/smhzGb 5j4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712772502; x=1713377302; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=J9NiNwxiik0OPXqS4C5bJncJdvLmqX2i9ON6pLi1lts=; b=LzqaRT5gcI5ZfwXzH8gbBMDeRf9KeU2HEyBIiFDqnIchVqy5eHmvaHuaBucXng+kbT x3F0PMCPnClZnrXRG8BMt+qs8bQQWUEEcbTdfqQh/nLrg7KY8tjKGGBaO8GAR0yQYxEX 7nXP7B2w1UNs/yZGwqBl59bmigiaPEB9iXXLL78qFlxAgfoJ5rBfEGtwytxKdOJUMX8Q QUHjz6EeBx3GxWB+UIsPeIOnC3X6vpI1oAP/VlcQ+ZBYr72n0oYpLmnjAsq5Rdwt3KQl E7m5rvnczgvXZbQd1dVf1Og/ilHX2MfMLeBVL4cZicAewuGUB2tQlnR4+HoTQQjezm4m rifw== X-Gm-Message-State: AOJu0YxKb75DpexkaGlxDDu4AewTG1dwgb3qFMILQn5MfYLcPl5reWxo rB7u0p+J5nG2fndApVDbYmWTgp0nv9R8IfIRyiDYb9e6XwOxr9Ph1DSXlxzV/hp2GfDBRuc5tPc s X-Received: by 2002:a05:600c:5654:b0:415:6daf:c64b with SMTP id js20-20020a05600c565400b004156dafc64bmr2815076wmb.16.1712772502216; Wed, 10 Apr 2024 11:08:22 -0700 (PDT) Received: from m1x-phil.lan (arl95-h02-176-184-34-173.dsl.sta.abo.bbox.fr. [176.184.34.173]) by smtp.gmail.com with ESMTPSA id n3-20020a05600c4f8300b0041627ab1554sm3006269wmq.22.2024.04.10.11.08.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Apr 2024 11:08:21 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Peter Maydell , Alexander Graf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH] hw/misc/applesmc: Simplify DeviceReset handler Date: Wed, 10 Apr 2024 20:08:19 +0200 Message-ID: <20240410180819.92332-1-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é Reviewed-by: Peter Maydell --- As discussed in https://lore.kernel.org/qemu-devel/6fbcf565-f12c-4196-b6c8-559843c7a78c@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);