From patchwork Thu Apr 25 11:01:40 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: 792042 Delivered-To: patch@linaro.org Received: by 2002:a5d:4884:0:b0:346:15ad:a2a with SMTP id g4csp1322082wrq; Thu, 25 Apr 2024 04:08:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW5ENRMTHk4J3lq/dbtwrLPzntWZ78seHC75QArfcS5Z9COF731ApF6jKYB/dOZBEW54t/UTmnGzxQN3qpB2iKb X-Google-Smtp-Source: AGHT+IH5WDkfY1P3MDmql14Au/GT8clYrAyhos8YaOTavTJwW/QvvYXmf8oKLzHH3yMSQ55A8bLH X-Received: by 2002:a05:6214:12d:b0:6a0:934d:1d7e with SMTP id w13-20020a056214012d00b006a0934d1d7emr5098891qvs.1.1714043313455; Thu, 25 Apr 2024 04:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1714043313; cv=none; d=google.com; s=arc-20160816; b=DFdqoKs8F//gbCfc2lYzzU8uvwfIUOYh9zbIrm2o2v/3K/Kfkv0wj0Vwa8M8HIbo/E ag1Rh7Yp+/yRL71YdwEq2hZxiB6tWROkEp+1ThFzFIyy0egPDVoTfwCu90TopWjoBRis w2cYvp4HBGCxJNAiIGwtoDaTBY/6OGAzcF5N+LOVBHrhIiteW7FABBYReDkNXhf0uXm/ 3Gw4aSTffmkT31SXqztDD/1oPpz53SVpbU4ITXBw4+/BFoBzW6mSXDsNf7Chxnn/gtLw JmdKEgZsINxVH/uN2bJkzuX7J0fc+LXbGyzrROXh+U95NEY6XnnhEgo6YO18Yh/L5hFx gY1A== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lYhjl1/jGiesNQD68pOCk3VBrraJnT7fa7wrXc4FOT0=; fh=Y26SNCcx7mV3+DQ4GiURg25QCLf4EDTrA1pj2iVRPwA=; b=l35JXtC92dM/9IlK5ALrW8SpLeIHK14hnmrRWemY2ijuce59MvHpGk9m0sSg62jj5y r4GcJ4U1v0fJDoFoznGsXHwONAMXRTo/GJ6ftJdiCmysXPIN4gLRzjjTUFR2omiuXwga K6dmQv6PQIfOI1Uoni7XgfwdMSnp6I+jT1croMki1W1Tr8KXy1sMdykDvk9hb+EIqNpu v2B+eJW7ZcFrkPFoL+/+G2mLOlTkhocrlHjE6WrMzFVi7v3oyQRByREOFtAzL0Iq1Kx9 fim6yusiOxaDGf3vO/5XlpsXEGTpkfwXe/SzU2FdfH/FqLLjc6ISJUNpf0HF/ZlaJtdf Wtrg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sS9SNaY2; 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 hf1-20020a0562140e8100b00695d4a4fbfasi17434266qvb.53.2024.04.25.04.08.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Apr 2024 04:08:33 -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=sS9SNaY2; 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 1rzwto-0000mc-AB; Thu, 25 Apr 2024 07:04:20 -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 1rzwsH-00085j-VR for qemu-devel@nongnu.org; Thu, 25 Apr 2024 07:02:47 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rzwsF-0008IR-Lx for qemu-devel@nongnu.org; Thu, 25 Apr 2024 07:02:44 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-347c197a464so622174f8f.2 for ; Thu, 25 Apr 2024 04:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714042960; x=1714647760; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lYhjl1/jGiesNQD68pOCk3VBrraJnT7fa7wrXc4FOT0=; b=sS9SNaY2m91SB2OuGxhRGe3Zi640dzqYr+7FM0qXPCca7ZjDwL/7jLEsJbRCeN/MHm zN1X0yKopOlZPSXZfLa3wjPoTrNBk8SINFYZR/C+049d1tuYW2c5L/Z0ui3IzYdHEbCm /hGKBzdn4K+uv4/MTZmHgpTgouyIjQAPlGqBs9O3RxD+gWzDjxjtPcu5D6Z2TY448kok 03cz9qZGWePMuofu9qcMXjLqfWrk9NMXwUz9movYjDmH9UMh8GuXIE2hefebeWK66uU5 hz7r/e/mwMwK/3nsJn/wKPm7RR9wIF+FSudPsR3mApq9xr3ehinTIGtLyNoPY+loV+th 7tww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714042960; x=1714647760; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lYhjl1/jGiesNQD68pOCk3VBrraJnT7fa7wrXc4FOT0=; b=HCwH0z+oJkeau3d32PtsS498LrzpTPZaUSJM17Q+Hul9/Wbd8LKd6B48glQs+Uu6h0 mGvHMbJm/exttrKeQUJJAXv4Kd45HQSr05mQmQscw6U50M9WYYMqfmF82NsK6IHhK5C+ 4/BFbim4oS+OT9VII5nBc/4OjcbX9p9fH0pQsL1q4Baw7xPfZH8A0Pb+1MznyXYPlBjN B3C1721xS9telADV/bE6OkkHPseVevYBat1Yak1ECfNBmC0XSTBHQz2RllzPn5ljwmAm sfudfklqfGxbjy3fMIweN7LRfPw0sklo8mdoauy8My8WkCNqVfCjaei/Wnbp2bDXKdr3 1nXw== X-Gm-Message-State: AOJu0YwfWueNHvrTL7ezpyG+HxKeKLyvolUjR9bMiZAo8/im+ThOXES1 QkAwcsjSHO5CKoUer3jkhzm8ciIB6NLfqfL0nD/dp8OWBSbWHXN53NTpGSNWgUurP+0OpI3qgUm P X-Received: by 2002:a05:6000:47:b0:33d:b376:8a07 with SMTP id k7-20020a056000004700b0033db3768a07mr3496522wrx.8.1714042960487; Thu, 25 Apr 2024 04:02:40 -0700 (PDT) Received: from localhost.localdomain ([92.88.170.77]) by smtp.gmail.com with ESMTPSA id y18-20020a5d4ad2000000b0034a0d3c0715sm19281014wrs.50.2024.04.25.04.02.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 25 Apr 2024 04:02:40 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, qemu-arm@nongnu.org, =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Peter Maydell Subject: [PULL 07/22] hw/misc/applesmc: Simplify DeviceReset handler Date: Thu, 25 Apr 2024 13:01:40 +0200 Message-ID: <20240425110157.20328-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240425110157.20328-1-philmd@linaro.org> References: <20240425110157.20328-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=philmd@linaro.org; helo=mail-wr1-x42a.google.com 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 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);