From patchwork Wed Mar 5 01:21:21 2025 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: 870518 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp551332wrg; Tue, 4 Mar 2025 17:26:30 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXVtlE/H+Tsolt3xyXK/3eDjE1nUqMg1234I0JAEJuwcA0xePDv1e71sNGOmyuVxZyy6hUqsA==@linaro.org X-Google-Smtp-Source: AGHT+IFgFWO49FeZHFww0EiJZ8SgsGgmrQgGszv7LWYJtAKDVBHiITvu5XWkVTamdbcPe1C+yp04 X-Received: by 2002:a05:620a:6290:b0:7c0:b0b7:494c with SMTP id af79cd13be357-7c3d8bd2969mr249017785a.9.1741137990403; Tue, 04 Mar 2025 17:26:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741137990; cv=none; d=google.com; s=arc-20240605; b=etMp/S5tM+RxBlXU6p/g5+eOiK7mV68Fo7wlCI8IWAyH050ILI1phlk+NSvssvq4Uq iZiJ9sbfrVFNoDrfKXjq/vqQqCT9OryYzEEuzaWstGJOnnKCyi15Z0PgN+Da2STjYXlj O8RiEXUvhjU9cCbPiCEnRLUO/9GjTojGmq0zQgd4pQOL0hij8MTznebE3Y7xBHWeKBc+ DnmA+R+J+HhZMDrckrqEQZKrQkpor+d2YzYzbxDkwh1XJZB+j11YA3sPnf1omZ5uywHV fHw3sLNs5jFACI3DXWKzKQHtjH7iIPmlDklWz1Kr2SxO+JkjboApkkehbD7qQvGyGCDG 6cgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=D9JV1AwMjPXWkW/cDeAqd6rBcTJqKFQb5kxMIynKBuE=; fh=JfjgrjACOQYSbU1oI5IucLYY0iFzHOFn64TDAErOBec=; b=I61Iw67y3NF5uQVr3qsWkAKQvhREnQL8/EL4LQBc65D7JCx2wcO1/olz2L6ZxByn7h mRCGxv04r1Jy8d5e2e1e09gZxHC8ohS2+TO4FLxVqeZ5CVoLDhFWR/uAduZM6+owix34 Wko0FNVU6p9KuQCxwpn1QtkUoGCsVun7WF2ipspNOcKI3l7MrQFHd5oTd9Jw9enMdE2F 9rRGBa9KX4QmR9gVkRigfgd9b9PrgqErmb98Dcs7sJCn+nn/OWhc7tIuaD3FTzqiBGde DoSUQ6/jAO8Ia0y58Y7mkkUrL81fQ0Wh46oiCPm0luLuy/uDKWL/lYNxN3NtQ9Jxyttg FDrQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QLJkps5Q; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7c367954791si1166619385a.0.2025.03.04.17.26.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Mar 2025 17:26:30 -0800 (PST) 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=QLJkps5Q; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tpdTc-0008WI-00; Tue, 04 Mar 2025 20:23:14 -0500 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 1tpdSz-00089d-4J for qemu-devel@nongnu.org; Tue, 04 Mar 2025 20:22:37 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tpdSw-0006x3-UJ for qemu-devel@nongnu.org; Tue, 04 Mar 2025 20:22:32 -0500 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-390f69e71c8so216038f8f.0 for ; Tue, 04 Mar 2025 17:22:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741137749; x=1741742549; 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=D9JV1AwMjPXWkW/cDeAqd6rBcTJqKFQb5kxMIynKBuE=; b=QLJkps5QAekbnkdeQeMRRRgUUEl071Jdt0/lsWIeHy7ADdlhyRrPs3JJrislJHlT0T mjZjDLulifR3zWPLMek1TAHE+Xd7LhUTxtuVE1Rhg9V3VzvJZe27d9xIWakCBTW1fgrP 71X9Y4aazAsckCMPw2YVxfRtHdcYJHqidOxRM5OMPQ15TOrIPwugiczWw76RLxAcGDxm Ub8T0DnlVo2nX4c6ZV7ycgQFL150rfbPhgUAFst1OXt8t7DOfp9SKuIkOdryoI/WNOJQ y/hSULcSlTqHXiiZjTNQtO6FpAGlxt/PaArta4FmiUXVLMWlSkGEisvZMH4PngBSZjd1 7w2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741137749; x=1741742549; 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=D9JV1AwMjPXWkW/cDeAqd6rBcTJqKFQb5kxMIynKBuE=; b=wSlXmwyCupFoRjf/7zrw4VKrfuIu5M57P6/+FnOfvIXS9Aqt/63E1Ao4yUycoiNjOn ml787au9iTphqZDaM6ZUtMcmtBTslWbnY2rSUVc4eHf8Nn5la7pZ7BGYS2+eywf4LA5B WgIkv6d83A7uJiahv+pafVaEK+U/20L+fxUrrTv+0euT8ZM/w2/5khJdApANqWOeeAwH vZMeFYuOWJA4LmgsMDdolEc1M6MlC7UJvBR/475cDF61bB0GCJpPi6TJZ7OQcGOsDDnk QfyziesdEwWGdE1/ySsNeQFiY65cqVR8zWVR9qRqwHYQsxGGg8X3dzgdqGhtnLJG3Vb9 aMWg== X-Gm-Message-State: AOJu0YwzYKYYUD3OIoVV4dOhALeZ5GA7np9CaiPKidjLiPBsaciVFJEP qQ0Nx4zzTd1qCuv2aVMJIbfyri/Oex3RsnSmiNfIDPq8fS2ilicMmV0aTfCndoZf+eRIgs0ClyQ 2YtA= X-Gm-Gg: ASbGnctpXjvo6t6LQgaTP6BU/LLP3gpNoLUhBTp0C5kZzztwh7N0iXzFseT7zJg2ht5 Ob4I01/eIf879CVzia36O6oV22DcJUr9wiyD0nqtAxAy0kFGvz5AyzCIJez8bYsPfizRpgRgZIN OLLuFDCUW7HVrV8wqcez+l6sATJhENSggmZZQHdTnvIz7X7K5jwl2wWsmZKrJqQPsWtNt/4GmX1 mm6puslICBTKlBWpEXqcWtvq/zZqVXglYoEZBT+4Bm7oty3Dw+VgxDf6UleORwUQqEPykVVCUhO yGQcR2qcvpwc3K+Lv3nYg16e6Ltqnnn0zqM2lKEetiGy2kOzqmi/se46YHOctMRHdjD1dm6FuVW UKtIHHuGZ97sogy2pMOk= X-Received: by 2002:a5d:47af:0:b0:390:f116:d220 with SMTP id ffacd0b85a97d-3911e9f75d4mr872380f8f.17.1741137748778; Tue, 04 Mar 2025 17:22:28 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e47b6cd8sm19035086f8f.44.2025.03.04.17.22.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 04 Mar 2025 17:22:28 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Alexander Graf , Phil Dennis-Jordan , Akihiko Odaki , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PULL 06/41] hw/vmapple/cfg: Introduce vmapple cfg region Date: Wed, 5 Mar 2025 02:21:21 +0100 Message-ID: <20250305012157.96463-7-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250305012157.96463-1-philmd@linaro.org> References: <20250305012157.96463-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=philmd@linaro.org; helo=mail-wr1-x42b.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 From: Alexander Graf Instead of device tree or other more standardized means, VMApple passes platform configuration to the first stage boot loader in a binary encoded format that resides at a dedicated RAM region in physical address space. This patch models this configuration space as a qdev device which we can then map at the fixed location in the address space. That way, we can influence and annotate all configuration fields easily. Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan Reviewed-by: Akihiko Odaki Tested-by: Akihiko Odaki Message-ID: <20241223221645.29911-12-phil@philjordan.eu> Signed-off-by: Philippe Mathieu-Daudé --- include/hw/vmapple/vmapple.h | 2 + hw/vmapple/cfg.c | 195 +++++++++++++++++++++++++++++++++++ hw/vmapple/Kconfig | 3 + hw/vmapple/meson.build | 1 + 4 files changed, 201 insertions(+) create mode 100644 hw/vmapple/cfg.c diff --git a/include/hw/vmapple/vmapple.h b/include/hw/vmapple/vmapple.h index 9090e9c5ac8..3bba59f5ec7 100644 --- a/include/hw/vmapple/vmapple.h +++ b/include/hw/vmapple/vmapple.h @@ -16,4 +16,6 @@ #define TYPE_VMAPPLE_BDIF "vmapple-bdif" +#define TYPE_VMAPPLE_CFG "vmapple-cfg" + #endif /* HW_VMAPPLE_VMAPPLE_H */ diff --git a/hw/vmapple/cfg.c b/hw/vmapple/cfg.c new file mode 100644 index 00000000000..63414d801fe --- /dev/null +++ b/hw/vmapple/cfg.c @@ -0,0 +1,195 @@ +/* + * VMApple Configuration Region + * + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/vmapple/vmapple.h" +#include "hw/sysbus.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "net/net.h" + +OBJECT_DECLARE_SIMPLE_TYPE(VMAppleCfgState, VMAPPLE_CFG) + +#define VMAPPLE_CFG_SIZE 0x00010000 + +typedef struct VMAppleCfg { + uint32_t version; /* 0x000 */ + uint32_t nr_cpus; /* 0x004 */ + uint32_t unk1; /* 0x008 */ + uint32_t unk2; /* 0x00c */ + uint32_t unk3; /* 0x010 */ + uint32_t unk4; /* 0x014 */ + uint64_t ecid; /* 0x018 */ + uint64_t ram_size; /* 0x020 */ + uint32_t run_installer1; /* 0x028 */ + uint32_t unk5; /* 0x02c */ + uint32_t unk6; /* 0x030 */ + uint32_t run_installer2; /* 0x034 */ + uint32_t rnd; /* 0x038 */ + uint32_t unk7; /* 0x03c */ + MACAddr mac_en0; /* 0x040 */ + uint8_t pad1[2]; + MACAddr mac_en1; /* 0x048 */ + uint8_t pad2[2]; + MACAddr mac_wifi0; /* 0x050 */ + uint8_t pad3[2]; + MACAddr mac_bt0; /* 0x058 */ + uint8_t pad4[2]; + uint8_t reserved[0xa0]; /* 0x060 */ + uint32_t cpu_ids[0x80]; /* 0x100 */ + uint8_t scratch[0x200]; /* 0x180 */ + char serial[32]; /* 0x380 */ + char unk8[32]; /* 0x3a0 */ + char model[32]; /* 0x3c0 */ + uint8_t unk9[32]; /* 0x3e0 */ + uint32_t unk10; /* 0x400 */ + char soc_name[32]; /* 0x404 */ +} VMAppleCfg; + +struct VMAppleCfgState { + SysBusDevice parent_obj; + VMAppleCfg cfg; + + MemoryRegion mem; + char *serial; + char *model; + char *soc_name; +}; + +static void vmapple_cfg_reset(Object *obj, ResetType type) +{ + VMAppleCfgState *s = VMAPPLE_CFG(obj); + VMAppleCfg *cfg; + + cfg = memory_region_get_ram_ptr(&s->mem); + memset(cfg, 0, VMAPPLE_CFG_SIZE); + *cfg = s->cfg; +} + +static bool set_fixlen_property_or_error(char *restrict dst, + const char *restrict src, + size_t dst_size, Error **errp, + const char *property_name) +{ + ERRP_GUARD(); + size_t len; + + len = g_strlcpy(dst, src, dst_size); + if (len < dst_size) { /* len does not count nul terminator */ + return true; + } + + error_setg(errp, "Provided value too long for property '%s'", property_name); + error_append_hint(errp, "length (%zu) exceeds maximum of %zu\n", + len, dst_size - 1); + return false; +} + +#define set_fixlen_property_or_return(dst_array, src, errp, property_name) \ + do { \ + if (!set_fixlen_property_or_error((dst_array), (src), \ + ARRAY_SIZE(dst_array), \ + (errp), (property_name))) { \ + return; \ + } \ + } while (0) + +static void vmapple_cfg_realize(DeviceState *dev, Error **errp) +{ + VMAppleCfgState *s = VMAPPLE_CFG(dev); + uint32_t i; + + if (!s->serial) { + s->serial = g_strdup("1234"); + } + if (!s->model) { + s->model = g_strdup("VM0001"); + } + if (!s->soc_name) { + s->soc_name = g_strdup("Apple M1 (Virtual)"); + } + + set_fixlen_property_or_return(s->cfg.serial, s->serial, errp, "serial"); + set_fixlen_property_or_return(s->cfg.model, s->model, errp, "model"); + set_fixlen_property_or_return(s->cfg.soc_name, s->soc_name, errp, "soc_name"); + set_fixlen_property_or_return(s->cfg.unk8, "D/A", errp, "unk8"); + s->cfg.version = 2; + s->cfg.unk1 = 1; + s->cfg.unk2 = 1; + s->cfg.unk3 = 0x20; + s->cfg.unk4 = 0; + s->cfg.unk5 = 1; + s->cfg.unk6 = 1; + s->cfg.unk7 = 0; + s->cfg.unk10 = 1; + + if (s->cfg.nr_cpus > ARRAY_SIZE(s->cfg.cpu_ids)) { + error_setg(errp, + "Failed to create %u CPUs, vmapple machine supports %zu max", + s->cfg.nr_cpus, ARRAY_SIZE(s->cfg.cpu_ids)); + return; + } + for (i = 0; i < s->cfg.nr_cpus; i++) { + s->cfg.cpu_ids[i] = i; + } +} + +static void vmapple_cfg_init(Object *obj) +{ + VMAppleCfgState *s = VMAPPLE_CFG(obj); + + memory_region_init_ram(&s->mem, obj, "VMApple Config", VMAPPLE_CFG_SIZE, + &error_fatal); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mem); +} + +static const Property vmapple_cfg_properties[] = { + DEFINE_PROP_UINT32("nr-cpus", VMAppleCfgState, cfg.nr_cpus, 1), + DEFINE_PROP_UINT64("ecid", VMAppleCfgState, cfg.ecid, 0), + DEFINE_PROP_UINT64("ram-size", VMAppleCfgState, cfg.ram_size, 0), + DEFINE_PROP_UINT32("run_installer1", VMAppleCfgState, cfg.run_installer1, 0), + DEFINE_PROP_UINT32("run_installer2", VMAppleCfgState, cfg.run_installer2, 0), + DEFINE_PROP_UINT32("rnd", VMAppleCfgState, cfg.rnd, 0), + DEFINE_PROP_MACADDR("mac-en0", VMAppleCfgState, cfg.mac_en0), + DEFINE_PROP_MACADDR("mac-en1", VMAppleCfgState, cfg.mac_en1), + DEFINE_PROP_MACADDR("mac-wifi0", VMAppleCfgState, cfg.mac_wifi0), + DEFINE_PROP_MACADDR("mac-bt0", VMAppleCfgState, cfg.mac_bt0), + DEFINE_PROP_STRING("serial", VMAppleCfgState, serial), + DEFINE_PROP_STRING("model", VMAppleCfgState, model), + DEFINE_PROP_STRING("soc_name", VMAppleCfgState, soc_name), +}; + +static void vmapple_cfg_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + ResettableClass *rc = RESETTABLE_CLASS(klass); + + dc->realize = vmapple_cfg_realize; + dc->desc = "VMApple Configuration Region"; + device_class_set_props(dc, vmapple_cfg_properties); + rc->phases.hold = vmapple_cfg_reset; +} + +static const TypeInfo vmapple_cfg_info = { + .name = TYPE_VMAPPLE_CFG, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(VMAppleCfgState), + .instance_init = vmapple_cfg_init, + .class_init = vmapple_cfg_class_init, +}; + +static void vmapple_cfg_register_types(void) +{ + type_register_static(&vmapple_cfg_info); +} + +type_init(vmapple_cfg_register_types) diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig index ff5f97c292e..f5898661a91 100644 --- a/hw/vmapple/Kconfig +++ b/hw/vmapple/Kconfig @@ -5,3 +5,6 @@ config VMAPPLE_AES config VMAPPLE_BDIF bool + +config VMAPPLE_CFG + bool diff --git a/hw/vmapple/meson.build b/hw/vmapple/meson.build index e2aca6b7c2b..9e881c7b555 100644 --- a/hw/vmapple/meson.build +++ b/hw/vmapple/meson.build @@ -2,3 +2,4 @@ system_ss.add(when: 'CONFIG_VMAPPLE_AES', if_true: files('aes.c')) system_ss.add(when: 'CONFIG_VMAPPLE_BDIF', if_true: files('bdif.c')) +system_ss.add(when: 'CONFIG_VMAPPLE_CFG', if_true: files('cfg.c'))