From nobody Sat Dec 28 22:18:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1734992485; cv=none; d=zohomail.com; s=zohoarc; b=BoIOEXEi6rQHKxezSKOyTjfRMq5b5/7XN8JiB8g8GsEgafpS0uUQnjDcRSa/hHc8RgFDq9e/pyKztwfDjgPuXqiLxo5A0PE6aCxwHu8ErGfldf+0i5+LxV3KYDOL6dh/O7fsdWmzhaqVlksXSdIqh9xg/+1jMZVfsrEEszmE34k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734992485; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=locc7ewmAp9c/ZxC6/RNESrFSC2d3Z20bafe0mdpF8I=; b=ZpdLYBPlsS/bfP7Pmeqea0sZmXsgjo145r9sx8pwTwWDjwm5ebmdpk763YgEYlrMl92CoUIOB3oJCu9uMv0NpW2Z6/2eiVbmyFukX9ETlEvUDPqNhdauvr1YQN/9JJDBQLFDy7ooK1gAxqb8SBOQuZ8RiZR11wl0MULInHASmec= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734992485562166.6678755039843; Mon, 23 Dec 2024 14:21:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tPqkI-0002e3-Ar; Mon, 23 Dec 2024 17:17:50 -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 1tPqjt-00025W-Fg for qemu-devel@nongnu.org; Mon, 23 Dec 2024 17:17:30 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tPqjn-000710-UX for qemu-devel@nongnu.org; Mon, 23 Dec 2024 17:17:24 -0500 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-43675b1155bso24972525e9.2 for ; Mon, 23 Dec 2024 14:17:19 -0800 (PST) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436611fc161sm147561075e9.10.2024.12.23.14.17.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Dec 2024 14:17:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1734992238; x=1735597038; 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=locc7ewmAp9c/ZxC6/RNESrFSC2d3Z20bafe0mdpF8I=; b=ENypt80Mk+3WCFS6787yu+n7v15dtG6GPxC6SRE1X7IJAaf/kX8PW6KXVGG0rbNVvU DC0RKbl0VWu9hrOOmZfa0z7G2HSPNOpaTO5C8keuxrKq50qjvM7AaKEavFCYcrgNPz10 tp+R/1dyqAXgzYiSl05BZM2Hz805jhpWqXLrUWoK4g2U0Emx233qppOWCHZCf/aDxk25 Yww84UxLQUb9lTzTRM42RnRoDcNYdXPj0YsuCecCmps8Mzjx1wCfhW7Ph+J1KiDErl1y 8KDaPE91tZJth0F21uL6xuYDssxtSUSQT2w8x4f4LoBa/8bjVQH1xr5ZL2aWLqAgV0au rHQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734992238; x=1735597038; 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=locc7ewmAp9c/ZxC6/RNESrFSC2d3Z20bafe0mdpF8I=; b=st/VtdlkoSw84ETEwg9dGpWmecOhLFdBa2YxUuLSSqneT5G5EzWJa3u+WHFGqdoSY9 NiPROMdinw4C/Wbv/BiGL1a2SwE9TLFszytUIfFuimrtwr/3/0rP2ATuZe6aprgYV/4y HBNzS6S1anAeLwmnloi4jv5jDEynaZ7lG4pXD8NkZhB5dxjJDs2JxYGPi7TgLzWL9p4e lwBbMK4NGD8Fgz6tMhBLKzHbZZcjg0232leXwdb6xHClVLWCU6WQLr7hzwiv14zHUbJo 7cdsJY2Bv7wf1st3Wn2y9+HYF9HY61Ap94BeKS2Bzn+VqbxMc77sJjaQGMUm+cp8oMCz JD+A== X-Gm-Message-State: AOJu0Yw++t3qxTrTe1eNWKyIbTNFfN+zQmpA1kCommpC4SXp13GToeuQ 6TPxD0m96QV0aZjcwp6v/qHYluKjuxDyWJgBz1D2rdVoiCPqM/ICE3WlyRqraQJDlF11DbiOxRX Hug== X-Gm-Gg: ASbGncvlJkiOljL5lbL3THAm3aqETKBNOVVXcoKFuWsbbawlnbMQhshw23apB77TFgI lEvGCiLV5793TEoFurgjsgYHrjNVHxeziVwKXuQjs1M1U6TShQChG/4k9QQSxUlq8zD/PiiWH6P nmoOm/yVB/JiQhZdwup+CBAdwQdBoyzRg6q9uLh2H8MqQCBvpoQ4oCJThR//T6JbKwRGfaAcZZa zvzrwSYMQn45xFbLCc5uvN0D7qDF5+Bg9hr0jSkNhCqndm7TCFvB4IS97nv0yl35H/QSydU9Qfj 5L8HBgIzZiDTvQkkTbEOcdjip17Wxgvf X-Google-Smtp-Source: AGHT+IH7COkrfk9fJASwAWNaKCyC+9eoT9M9Tfa4aWomPHhHcwLrWNi1Aycp6HbOt2U9mZJ359gzAA== X-Received: by 2002:a05:600c:1c12:b0:434:f9e1:5cf8 with SMTP id 5b1f17b1804b1-4366aabbed2mr131330355e9.31.1734992238346; Mon, 23 Dec 2024 14:17:18 -0800 (PST) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org, balaton@eik.bme.hu, Alexander Graf Subject: [PATCH v16 11/14] hw/vmapple/cfg: Introduce vmapple cfg region Date: Mon, 23 Dec 2024 23:16:42 +0100 Message-Id: <20241223221645.29911-12-phil@philjordan.eu> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241223221645.29911-1-phil@philjordan.eu> References: <20241223221645.29911-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::331; envelope-from=phil@philjordan.eu; helo=mail-wm1-x331.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1734992487236116600 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 --- v3: * Replaced legacy device reset method with Resettable method v4: * Fixed initialisation of default values for properties * Dropped superfluous endianness conversions * Moved most header code to .c, device name #define goes in vmapple.h v5: * Improved error reporting in case of string property buffer overflow. v7: * Changed error messages for overrun of properties with fixed-length strings to be more useful to users than developers. v8: * Consistent parenthesising of macro arguments for better safety. v10: * Slightly tidier error reporting for overlong property values. v15: * Constified the property table. v16: * Removed the DEFINE_PROP_END_OF_LIST marker to match recent upstream changes. hw/vmapple/Kconfig | 3 + hw/vmapple/cfg.c | 195 +++++++++++++++++++++++++++++++++++ hw/vmapple/meson.build | 1 + include/hw/vmapple/vmapple.h | 2 + 4 files changed, 201 insertions(+) create mode 100644 hw/vmapple/cfg.c diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig index 68f88876eb..8bbeb9a923 100644 --- a/hw/vmapple/Kconfig +++ b/hw/vmapple/Kconfig @@ -4,3 +4,6 @@ config VMAPPLE_AES config VMAPPLE_BDIF bool =20 +config VMAPPLE_CFG + bool + diff --git a/hw/vmapple/cfg.c b/hw/vmapple/cfg.c new file mode 100644 index 0000000000..63414d801f --- /dev/null +++ b/hw/vmapple/cfg.c @@ -0,0 +1,195 @@ +/* + * VMApple Configuration Region + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * 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 =3D VMAPPLE_CFG(obj); + VMAppleCfg *cfg; + + cfg =3D memory_region_get_ram_ptr(&s->mem); + memset(cfg, 0, VMAPPLE_CFG_SIZE); + *cfg =3D 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 =3D 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 =3D VMAPPLE_CFG(dev); + uint32_t i; + + if (!s->serial) { + s->serial =3D g_strdup("1234"); + } + if (!s->model) { + s->model =3D g_strdup("VM0001"); + } + if (!s->soc_name) { + s->soc_name =3D 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 =3D 2; + s->cfg.unk1 =3D 1; + s->cfg.unk2 =3D 1; + s->cfg.unk3 =3D 0x20; + s->cfg.unk4 =3D 0; + s->cfg.unk5 =3D 1; + s->cfg.unk6 =3D 1; + s->cfg.unk7 =3D 0; + s->cfg.unk10 =3D 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 =3D 0; i < s->cfg.nr_cpus; i++) { + s->cfg.cpu_ids[i] =3D i; + } +} + +static void vmapple_cfg_init(Object *obj) +{ + VMAppleCfgState *s =3D VMAPPLE_CFG(obj); + + memory_region_init_ram(&s->mem, obj, "VMApple Config", VMAPPLE_CFG_SIZ= E, + &error_fatal); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mem); +} + +static const Property vmapple_cfg_properties[] =3D { + 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_installe= r1, 0), + DEFINE_PROP_UINT32("run_installer2", VMAppleCfgState, cfg.run_installe= r2, 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 =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + dc->realize =3D vmapple_cfg_realize; + dc->desc =3D "VMApple Configuration Region"; + device_class_set_props(dc, vmapple_cfg_properties); + rc->phases.hold =3D vmapple_cfg_reset; +} + +static const TypeInfo vmapple_cfg_info =3D { + .name =3D TYPE_VMAPPLE_CFG, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(VMAppleCfgState), + .instance_init =3D vmapple_cfg_init, + .class_init =3D 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/meson.build b/hw/vmapple/meson.build index d4624713de..64b78693a3 100644 --- a/hw/vmapple/meson.build +++ b/hw/vmapple/meson.build @@ -1,2 +1,3 @@ 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')) diff --git a/include/hw/vmapple/vmapple.h b/include/hw/vmapple/vmapple.h index 9090e9c5ac..3bba59f5ec 100644 --- a/include/hw/vmapple/vmapple.h +++ b/include/hw/vmapple/vmapple.h @@ -16,4 +16,6 @@ =20 #define TYPE_VMAPPLE_BDIF "vmapple-bdif" =20 +#define TYPE_VMAPPLE_CFG "vmapple-cfg" + #endif /* HW_VMAPPLE_VMAPPLE_H */ --=20 2.39.5 (Apple Git-154)