From nobody Sun Nov 24 00:38:13 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=1727514083; cv=none; d=zohomail.com; s=zohoarc; b=d/+M64ms6nXx1c6HK0PjTbdAoGGu98mP7sQpWvxMAxXIXQZd7cI1pGLD2B18l+LEG425AdYLHLCQ9A707/j9XE8vpFHQV2kDJXMEW6HE6O7h8VeeZvjFllP6za6liBKE2voLO3OinNTt0ZN8bREwRSxagAms3Ozxnatx7Ql08bY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727514083; 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=3fZ/MRqIDe8cVUg2j9kqF76C32CYoD0xZYTluK7YWaU=; b=YehmlG57JZt3EjKiMroENkztHfAdAPqtxI+vzoBwwztW2v0H+E8pI/rjE8AVPEVqZfYIjT6C6kUH7MVTRuFWbcrBLhX+Hln/C9rJAWrIpvqK77KtUr/ttPCzUnShYYoHW3fmpQW7Xvp2d7TUqnaGCQTnz3xii1cHhtKK88MOa/U= 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 1727514083273706.2496008122222; Sat, 28 Sep 2024 02:01:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTHI-00085I-GI; Sat, 28 Sep 2024 04:58:12 -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 1suTHG-00083y-T1 for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:10 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTHD-0002GD-Lo for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:10 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-42ca4e0299eso23833835e9.2 for ; Sat, 28 Sep 2024 01:58:07 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.57.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513886; x=1728118686; 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=3fZ/MRqIDe8cVUg2j9kqF76C32CYoD0xZYTluK7YWaU=; b=h9olwFQ25UJHmUFY57pLO6xBZIMX/1xL5h4ERh2VILOoEiykDmKjB0gANpAIb3ZynH p74tj4Jxdo5QZgMJHVwzmCtSFf8Id32h6pP6auXjUaYHvg6KsiNnut+adELBBoy37yVZ z66N5dGf4uHKkQpHfbsBsZf6btiz4Cwrz0seeBOECLC2fh6pTaoAwLZPuWXNMvSBZftE L0jXE5M0+QS5YBCgJ48+lcPb5zH59PaWu+Kl5wP1D1Bc/qmJG5nB2V+QH9pr7oP9zDqm 3S1ZMQCJrDEcz2bUQdNX7nlwGhIenim7xTssPeNkWFLXXZBxR+vI2cZJlpHVzU4wKHSz 2DtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513886; x=1728118686; 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=3fZ/MRqIDe8cVUg2j9kqF76C32CYoD0xZYTluK7YWaU=; b=YoagL+JZg7R33a9nMzo/8bxKvur0z2sXhvvRpW4ZY2RXmZYjpuJvf8XmYTvulKj20+ tWiKfr/vqjq8uG8kQ2QHSOXP4FTc0T01z73giYW1qdNE6mJ6WFLTDWTAmxlvTbQLxxJB +ySTAfwSW6Mw/Wza7kNqLvwAiUWnunjQiwSCgz0gjrZGLkNBX6UloNnW7fzriKPSx6hK EZ5xsHstkq6eh1XrVVpoxY6N4VLs5PKte5Pe6v7cR66JyRwLV4fvABTFAQVWUDed6bd4 g6Xd9kKdHGMVQf9kkLpEkZgmlfnFSwLBrJXf3zPA2oaHBt04ZKHbuBgQdT5OEYaM8ICQ HpBw== X-Gm-Message-State: AOJu0YzrerB+bIqPUv/246XJhBVvF5J11+4agnMPNJRGzkGISasspsOd VrbBlcqIVpCo/KPwulUPac8tKKj89Uv8HdJ2fFTt8clscuuIm6ZaOMrYjC725vnwggewOjq1v+W izA== X-Google-Smtp-Source: AGHT+IEjt4Ps9hDZ529fa1j5JmMzo5tkpVqKLUzi9VfYW/DCwXoQvVJ09AAwN/69yyDOI3B+yUcTsQ== X-Received: by 2002:a05:600c:3b06:b0:42c:a6da:a149 with SMTP id 5b1f17b1804b1-42f58487099mr44091955e9.25.1727513885783; Sat, 28 Sep 2024 01:58:05 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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, Alexander Graf Subject: [PATCH v3 01/14] hw/display/apple-gfx: Introduce ParavirtualizedGraphics.Framework support Date: Sat, 28 Sep 2024 10:57:14 +0200 Message-Id: <20240928085727.56883-2-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-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::32b; envelope-from=phil@philjordan.eu; helo=mail-wm1-x32b.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, 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: 1727514084888116600 MacOS provides a framework (library) that allows any vmm to implement a paravirtualized 3d graphics passthrough to the host metal stack called ParavirtualizedGraphics.Framework (PVG). The library abstracts away almost every aspect of the paravirtualized device model and only provides and receives callbacks on MMIO access as well as to share memory address space between the VM and PVG. This patch implements a QEMU device that drives PVG for the VMApple variant of it. Signed-off-by: Alexander Graf Co-authored-by: Alexander Graf Subsequent changes: * Cherry-pick/rebase conflict fixes * BQL function renaming * Moved from hw/vmapple/ (useful outside that machine type) * Code review comments: Switched to DEFINE_TYPES macro & little endian MMIO. * Removed some dead/superfluous code * Mad set_mode thread & memory safe * Added migration blocker due to lack of (de-)serialisation. * Fixes to ObjC refcounting and autorelease pool usage. * Fixed ObjC new/init misuse * Switched to ObjC category extension for private property. * Simplified task memory mapping and made it thread safe. * Refactoring to split generic and vmapple MMIO variant specific code. * Switched to asynchronous MMIO writes on x86-64 * Rendering and graphics update are now done asynchronously * Fixed cursor handling * Coding convention fixes * Removed software cursor compositing Signed-off-by: Phil Dennis-Jordan --- v3: * Rebased on latest upstream, fixed breakages including switching to Reset= table methods. * Squashed patches dealing with dGPUs, MMIO area size, and GPU picking. * Allow re-entrant MMIO; this simplifies the code and solves the divergence between x86-64 and arm64 variants. hw/display/Kconfig | 9 + hw/display/apple-gfx-vmapple.m | 215 +++++++++++++ hw/display/apple-gfx.h | 57 ++++ hw/display/apple-gfx.m | 536 +++++++++++++++++++++++++++++++++ hw/display/meson.build | 2 + hw/display/trace-events | 26 ++ meson.build | 4 + 7 files changed, 849 insertions(+) create mode 100644 hw/display/apple-gfx-vmapple.m create mode 100644 hw/display/apple-gfx.h create mode 100644 hw/display/apple-gfx.m diff --git a/hw/display/Kconfig b/hw/display/Kconfig index a4552c8ed78..179a479d220 100644 --- a/hw/display/Kconfig +++ b/hw/display/Kconfig @@ -143,3 +143,12 @@ config XLNX_DISPLAYPORT =20 config DM163 bool + +config MAC_PVG + bool + default y + +config MAC_PVG_VMAPPLE + bool + depends on MAC_PVG + depends on ARM diff --git a/hw/display/apple-gfx-vmapple.m b/hw/display/apple-gfx-vmapple.m new file mode 100644 index 00000000000..d8fc7651dde --- /dev/null +++ b/hw/display/apple-gfx-vmapple.m @@ -0,0 +1,215 @@ +/* + * QEMU Apple ParavirtualizedGraphics.framework device, vmapple (arm64) va= riant + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * 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. + * + * ParavirtualizedGraphics.framework is a set of libraries that macOS prov= ides + * which implements 3d graphics passthrough to the host as well as a + * proprietary guest communication channel to drive it. This device model + * implements support to drive that library from within QEMU as an MMIO-ba= sed + * system device for macOS on arm64 VMs. + */ + +#include "apple-gfx.h" +#include "monitor/monitor.h" +#include "hw/sysbus.h" +#include "hw/irq.h" +#include "trace.h" +#import + +_Static_assert(__aarch64__, ""); + +/* + * ParavirtualizedGraphics.Framework only ships header files for the PCI + * variant which does not include IOSFC descriptors and host devices. We a= dd + * their definitions here so that we can also work with the ARM version. + */ +typedef bool(^IOSFCRaiseInterrupt)(uint32_t vector); +typedef bool(^IOSFCUnmapMemory)( + void *a, void *b, void *c, void *d, void *e, void *f); +typedef bool(^IOSFCMapMemory)( + uint64_t phys, uint64_t len, bool ro, void **va, void *e, void *f); + +@interface PGDeviceDescriptor (IOSurfaceMapper) +@property (readwrite, nonatomic) bool usingIOSurfaceMapper; +@end + +@interface PGIOSurfaceHostDeviceDescriptor : NSObject +-(PGIOSurfaceHostDeviceDescriptor *)init; +@property (readwrite, nonatomic, copy, nullable) IOSFCMapMemory mapMemory; +@property (readwrite, nonatomic, copy, nullable) IOSFCUnmapMemory unmapMem= ory; +@property (readwrite, nonatomic, copy, nullable) IOSFCRaiseInterrupt raise= Interrupt; +@end + +@interface PGIOSurfaceHostDevice : NSObject +-(instancetype)initWithDescriptor:(PGIOSurfaceHostDeviceDescriptor *) desc; +-(uint32_t)mmioReadAtOffset:(size_t) offset; +-(void)mmioWriteAtOffset:(size_t) offset value:(uint32_t)value; +@end + +typedef struct AppleGFXVmappleState { + SysBusDevice parent_obj; + + AppleGFXState common; + + qemu_irq irq_gfx; + qemu_irq irq_iosfc; + MemoryRegion iomem_iosfc; + PGIOSurfaceHostDevice *pgiosfc; +} AppleGFXVmappleState; + +OBJECT_DECLARE_SIMPLE_TYPE(AppleGFXVmappleState, APPLE_GFX_VMAPPLE) + + +static uint64_t apple_iosfc_read(void *opaque, hwaddr offset, unsigned siz= e) +{ + AppleGFXVmappleState *s =3D opaque; + uint64_t res =3D 0; + + bql_unlock(); + res =3D [s->pgiosfc mmioReadAtOffset:offset]; + bql_lock(); + + trace_apple_iosfc_read(offset, res); + + return res; +} + +static void apple_iosfc_write( + void *opaque, hwaddr offset, uint64_t val, unsigned size) +{ + AppleGFXVmappleState *s =3D opaque; + + trace_apple_iosfc_write(offset, val); + + [s->pgiosfc mmioWriteAtOffset:offset value:val]; +} + +static const MemoryRegionOps apple_iosfc_ops =3D { + .read =3D apple_iosfc_read, + .write =3D apple_iosfc_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + }, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + }, +}; + +static PGIOSurfaceHostDevice *apple_gfx_prepare_iosurface_host_device( + AppleGFXVmappleState *s) +{ + PGIOSurfaceHostDeviceDescriptor *iosfc_desc =3D + [PGIOSurfaceHostDeviceDescriptor new]; + PGIOSurfaceHostDevice *iosfc_host_dev =3D nil; + + iosfc_desc.mapMemory =3D + ^(uint64_t phys, uint64_t len, bool ro, void **va, void *e, void *= f) { + trace_apple_iosfc_map_memory(phys, len, ro, va, e, f); + MemoryRegion *tmp_mr; + *va =3D gpa2hva(&tmp_mr, phys, len, NULL); + return (bool)true; + }; + + iosfc_desc.unmapMemory =3D + ^(void *a, void *b, void *c, void *d, void *e, void *f) { + trace_apple_iosfc_unmap_memory(a, b, c, d, e, f); + return (bool)true; + }; + + iosfc_desc.raiseInterrupt =3D ^(uint32_t vector) { + trace_apple_iosfc_raise_irq(vector); + bool locked =3D bql_locked(); + if (!locked) { + bql_lock(); + } + qemu_irq_pulse(s->irq_iosfc); + if (!locked) { + bql_unlock(); + } + return (bool)true; + }; + + iosfc_host_dev =3D + [[PGIOSurfaceHostDevice alloc] initWithDescriptor:iosfc_desc]; + [iosfc_desc release]; + return iosfc_host_dev; +} + +static void apple_gfx_vmapple_realize(DeviceState *dev, Error **errp) +{ + @autoreleasepool { + AppleGFXVmappleState *s =3D APPLE_GFX_VMAPPLE(dev); + + PGDeviceDescriptor *desc =3D [PGDeviceDescriptor new]; + desc.usingIOSurfaceMapper =3D true; + desc.raiseInterrupt =3D ^(uint32_t vector) { + bool locked; + + trace_apple_gfx_raise_irq(vector); + locked =3D bql_locked(); + if (!locked) { + bql_lock(); + } + qemu_irq_pulse(s->irq_gfx); + if (!locked) { + bql_unlock(); + } + }; + + s->pgiosfc =3D apple_gfx_prepare_iosurface_host_device(s); + + apple_gfx_common_realize(&s->common, desc); + [desc release]; + desc =3D nil; + } +} + +static void apple_gfx_vmapple_init(Object *obj) +{ + AppleGFXVmappleState *s =3D APPLE_GFX_VMAPPLE(obj); + + apple_gfx_common_init(obj, &s->common, TYPE_APPLE_GFX_VMAPPLE); + + memory_region_init_io(&s->iomem_iosfc, obj, &apple_iosfc_ops, s, + TYPE_APPLE_GFX_VMAPPLE, 0x10000); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->common.iomem_gfx); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem_iosfc); + sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq_gfx); + sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq_iosfc); +} + +static void apple_gfx_vmapple_reset(Object *obj, ResetType type) +{ + AppleGFXVmappleState *s =3D APPLE_GFX_VMAPPLE(obj); + [s->common.pgdev reset]; +} + + +static void apple_gfx_vmapple_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + assert(rc->phases.hold =3D=3D NULL); + rc->phases.hold =3D apple_gfx_vmapple_reset; + + dc->realize =3D apple_gfx_vmapple_realize; +} + +static TypeInfo apple_gfx_vmapple_types[] =3D { + { + .name =3D TYPE_APPLE_GFX_VMAPPLE, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(AppleGFXVmappleState), + .class_init =3D apple_gfx_vmapple_class_init, + .instance_init =3D apple_gfx_vmapple_init, + } +}; +DEFINE_TYPES(apple_gfx_vmapple_types) diff --git a/hw/display/apple-gfx.h b/hw/display/apple-gfx.h new file mode 100644 index 00000000000..995ecf7f4a7 --- /dev/null +++ b/hw/display/apple-gfx.h @@ -0,0 +1,57 @@ +#ifndef QEMU_APPLE_GFX_H +#define QEMU_APPLE_GFX_H + +#define TYPE_APPLE_GFX_VMAPPLE "apple-gfx-vmapple" +#define TYPE_APPLE_GFX_PCI "apple-gfx-pci" + +#include "qemu/typedefs.h" + +typedef struct AppleGFXState AppleGFXState; + +void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_= name); + +#ifdef __OBJC__ + +#include "qemu/osdep.h" +#include "exec/memory.h" +#include "ui/surface.h" +#include + +@class PGDeviceDescriptor; +@protocol PGDevice; +@protocol PGDisplay; +@protocol MTLDevice; +@protocol MTLTexture; +@protocol MTLCommandQueue; + +typedef QTAILQ_HEAD(, PGTask_s) AppleGFXTaskList; + +struct AppleGFXState { + MemoryRegion iomem_gfx; + id pgdev; + id pgdisp; + AppleGFXTaskList tasks; + QemuConsole *con; + id mtl; + id mtl_queue; + bool handles_frames; + bool new_frame; + bool cursor_show; + QEMUCursor *cursor; + + dispatch_queue_t render_queue; + /* The following fields should only be accessed from render_queue: */ + bool gfx_update_requested; + bool new_frame_ready; + bool using_managed_texture_storage; + int32_t pending_frames; + void *vram; + DisplaySurface *surface; + id texture; +}; + +void apple_gfx_common_realize(AppleGFXState *s, PGDeviceDescriptor *desc); + +#endif /* __OBJC__ */ + +#endif diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m new file mode 100644 index 00000000000..837300f9cd4 --- /dev/null +++ b/hw/display/apple-gfx.m @@ -0,0 +1,536 @@ +/* + * QEMU Apple ParavirtualizedGraphics.framework device + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * 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. + * + * ParavirtualizedGraphics.framework is a set of libraries that macOS prov= ides + * which implements 3d graphics passthrough to the host as well as a + * proprietary guest communication channel to drive it. This device model + * implements support to drive that library from within QEMU. + */ + +#include "apple-gfx.h" +#include "trace.h" +#include "qemu/main-loop.h" +#include "ui/console.h" +#include "monitor/monitor.h" +#include "qapi/error.h" +#include "migration/blocker.h" +#include +#import + +static const PGDisplayCoord_t apple_gfx_modes[] =3D { + { .x =3D 1440, .y =3D 1080 }, + { .x =3D 1280, .y =3D 1024 }, +}; + +typedef struct PGTask_s { // Name matches forward declaration in PG header + QTAILQ_ENTRY(PGTask_s) node; + mach_vm_address_t address; + uint64_t len; +} AppleGFXTask; + +static Error *apple_gfx_mig_blocker; + +static void apple_gfx_render_frame_completed(AppleGFXState *s, void *vram, + id texture); + +static AppleGFXTask *apple_gfx_new_task(AppleGFXState *s, uint64_t len) +{ + mach_vm_address_t task_mem; + AppleGFXTask *task; + kern_return_t r; + + r =3D mach_vm_allocate(mach_task_self(), &task_mem, len, VM_FLAGS_ANYW= HERE); + if (r !=3D KERN_SUCCESS || task_mem =3D=3D 0) { + return NULL; + } + + task =3D g_new0(AppleGFXTask, 1); + + task->address =3D task_mem; + task->len =3D len; + QTAILQ_INSERT_TAIL(&s->tasks, task, node); + + return task; +} + +static uint64_t apple_gfx_read(void *opaque, hwaddr offset, unsigned size) +{ + AppleGFXState *s =3D opaque; + uint64_t res =3D 0; + + bql_unlock(); + res =3D [s->pgdev mmioReadAtOffset:offset]; + bql_lock(); + + trace_apple_gfx_read(offset, res); + + return res; +} + +static void apple_gfx_write(void *opaque, hwaddr offset, uint64_t val, + unsigned size) +{ + AppleGFXState *s =3D opaque; + + trace_apple_gfx_write(offset, val); + + bql_unlock(); + [s->pgdev mmioWriteAtOffset:offset value:val]; + bql_lock(); +} + +static const MemoryRegionOps apple_gfx_ops =3D { + .read =3D apple_gfx_read, + .write =3D apple_gfx_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + }, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static void apple_gfx_render_new_frame(AppleGFXState *s) +{ + BOOL r; + void *vram =3D s->vram; + uint32_t width =3D surface_width(s->surface); + uint32_t height =3D surface_height(s->surface); + MTLRegion region =3D MTLRegionMake2D(0, 0, width, height); + id command_buffer =3D [s->mtl_queue commandBuffer]; + id texture =3D s->texture; + r =3D [s->pgdisp encodeCurrentFrameToCommandBuffer:command_buffer + texture:texture + region:region]; + if (!r) { + return; + } + [texture retain]; + if (s->using_managed_texture_storage) { + /* "Managed" textures exist in both VRAM and RAM and must be synce= d. */ + id blit =3D [command_buffer blitCommandEnco= der]; + [blit synchronizeResource:texture]; + [blit endEncoding]; + } + [command_buffer retain]; + [command_buffer addCompletedHandler: + ^(id cb) + { + dispatch_async(s->render_queue, ^{ + apple_gfx_render_frame_completed(s, vram, texture); + [texture release]; + }); + [command_buffer release]; + }]; + [command_buffer commit]; +} + +static void copy_mtl_texture_to_surface_mem(id texture, void *= vram) +{ + /* TODO: Skip this entirely on a pure Metal or headless/guest-only + * rendering path, else use a blit command encoder? Needs careful + * (double?) buffering design. */ + size_t width =3D texture.width, height =3D texture.height; + MTLRegion region =3D MTLRegionMake2D(0, 0, width, height); + [texture getBytes:vram + bytesPerRow:(width * 4) + bytesPerImage:(width * height * 4) + fromRegion:region + mipmapLevel:0 + slice:0]; +} + +static void apple_gfx_render_frame_completed(AppleGFXState *s, void *vram, + id texture) +{ + --s->pending_frames; + assert(s->pending_frames >=3D 0); + + if (vram !=3D s->vram) { + /* Display mode has changed, drop this old frame. */ + assert(texture !=3D s->texture); + g_free(vram); + } else { + copy_mtl_texture_to_surface_mem(texture, vram); + if (s->gfx_update_requested) { + s->gfx_update_requested =3D false; + dpy_gfx_update_full(s->con); + graphic_hw_update_done(s->con); + s->new_frame_ready =3D false; + } else { + s->new_frame_ready =3D true; + } + } + if (s->pending_frames > 0) { + apple_gfx_render_new_frame(s); + } +} + +static void apple_gfx_fb_update_display(void *opaque) +{ + AppleGFXState *s =3D opaque; + + dispatch_async(s->render_queue, ^{ + if (s->pending_frames > 0) { + s->gfx_update_requested =3D true; + } else { + if (s->new_frame_ready) { + dpy_gfx_update_full(s->con); + s->new_frame_ready =3D false; + } + graphic_hw_update_done(s->con); + } + }); +} + +static const GraphicHwOps apple_gfx_fb_ops =3D { + .gfx_update =3D apple_gfx_fb_update_display, + .gfx_update_async =3D true, +}; + +static void update_cursor(AppleGFXState *s) +{ + dpy_mouse_set(s->con, s->pgdisp.cursorPosition.x, + s->pgdisp.cursorPosition.y, s->cursor_show); +} + +static void set_mode(AppleGFXState *s, uint32_t width, uint32_t height) +{ + void *vram =3D NULL; + DisplaySurface *surface; + MTLTextureDescriptor *textureDescriptor; + id texture =3D nil; + __block bool no_change =3D false; + + dispatch_sync(s->render_queue, + ^{ + if (s->surface && + width =3D=3D surface_width(s->surface) && + height =3D=3D surface_height(s->surface)) { + no_change =3D true; + } + }); + + if (no_change) { + return; + } + + vram =3D g_malloc0(width * height * 4); + surface =3D qemu_create_displaysurface_from(width, height, PIXMAN_LE_a= 8r8g8b8, + width * 4, vram); + + @autoreleasepool { + textureDescriptor =3D + [MTLTextureDescriptor + texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm + width:width + height:height + mipmapped:NO]; + textureDescriptor.usage =3D s->pgdisp.minimumTextureUsage; + texture =3D [s->mtl newTextureWithDescriptor:textureDescriptor]; + } + + s->using_managed_texture_storage =3D + (texture.storageMode =3D=3D MTLStorageModeManaged); + + dispatch_sync(s->render_queue, + ^{ + id old_texture =3D nil; + void *old_vram =3D s->vram; + s->vram =3D vram; + s->surface =3D surface; + + dpy_gfx_replace_surface(s->con, surface); + + old_texture =3D s->texture; + s->texture =3D texture; + [old_texture release]; + + if (s->pending_frames =3D=3D 0) { + g_free(old_vram); + } + }); +} + +static void create_fb(AppleGFXState *s) +{ + s->con =3D graphic_console_init(NULL, 0, &apple_gfx_fb_ops, s); + set_mode(s, 1440, 1080); + + s->cursor_show =3D true; +} + +static size_t apple_gfx_get_default_mmio_range_size(void) +{ + size_t mmio_range_size; + @autoreleasepool { + PGDeviceDescriptor *desc =3D [PGDeviceDescriptor new]; + mmio_range_size =3D desc.mmioLength; + [desc release]; + } + return mmio_range_size; +} + +void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_= name) +{ + Error *local_err =3D NULL; + int r; + size_t mmio_range_size =3D apple_gfx_get_default_mmio_range_size(); + + trace_apple_gfx_common_init(obj_name, mmio_range_size); + memory_region_init_io(&s->iomem_gfx, obj, &apple_gfx_ops, s, obj_name, + mmio_range_size); + s->iomem_gfx.disable_reentrancy_guard =3D true; + + /* TODO: PVG framework supports serialising device state: integrate it= ! */ + if (apple_gfx_mig_blocker =3D=3D NULL) { + error_setg(&apple_gfx_mig_blocker, + "Migration state blocked by apple-gfx display device"); + r =3D migrate_add_blocker(&apple_gfx_mig_blocker, &local_err); + if (r < 0) { + error_report_err(local_err); + } + } +} + +static void apple_gfx_register_task_mapping_handlers(AppleGFXState *s, + PGDeviceDescriptor *d= esc) +{ + desc.createTask =3D ^(uint64_t vmSize, void * _Nullable * _Nonnull bas= eAddress) { + AppleGFXTask *task =3D apple_gfx_new_task(s, vmSize); + *baseAddress =3D (void*)task->address; + trace_apple_gfx_create_task(vmSize, *baseAddress); + return task; + }; + + desc.destroyTask =3D ^(AppleGFXTask * _Nonnull task) { + trace_apple_gfx_destroy_task(task); + QTAILQ_REMOVE(&s->tasks, task, node); + mach_vm_deallocate(mach_task_self(), task->address, task->len); + g_free(task); + }; + + desc.mapMemory =3D ^(AppleGFXTask * _Nonnull task, uint32_t rangeCount, + uint64_t virtualOffset, bool readOnly, + PGPhysicalMemoryRange_t * _Nonnull ranges) { + kern_return_t r; + mach_vm_address_t target, source; + trace_apple_gfx_map_memory(task, rangeCount, virtualOffset, readOn= ly); + for (int i =3D 0; i < rangeCount; i++) { + PGPhysicalMemoryRange_t *range =3D &ranges[i]; + MemoryRegion *tmp_mr; + /* TODO: Bounds checks? r/o? */ + bql_lock(); + + trace_apple_gfx_map_memory_range(i, range->physicalAddress, + range->physicalLength); + + target =3D task->address + virtualOffset; + source =3D (mach_vm_address_t)gpa2hva(&tmp_mr, + range->physicalAddress, + range->physicalLength, NUL= L); + vm_prot_t cur_protection =3D 0; + vm_prot_t max_protection =3D 0; + // Map guest RAM at range->physicalAddress into PG task memory= range + r =3D mach_vm_remap(mach_task_self(), + &target, range->physicalLength, vm_page_size= - 1, + VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE, + mach_task_self(), + source, false /* shared mapping, no copy */, + &cur_protection, &max_protection, + VM_INHERIT_COPY); + trace_apple_gfx_remap(r, source, target); + g_assert(r =3D=3D KERN_SUCCESS); + + bql_unlock(); + + virtualOffset +=3D range->physicalLength; + } + return (bool)true; + }; + + desc.unmapMemory =3D ^(AppleGFXTask * _Nonnull task, uint64_t virtualO= ffset, + uint64_t length) { + kern_return_t r; + mach_vm_address_t range_address; + + trace_apple_gfx_unmap_memory(task, virtualOffset, length); + + /* Replace task memory range with fresh pages, undoing the mapping + * from guest RAM. */ + range_address =3D task->address + virtualOffset; + r =3D mach_vm_allocate(mach_task_self(), &range_address, length, + VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE); + g_assert(r =3D=3D KERN_SUCCESS); + + return (bool)true; + }; + + desc.readMemory =3D ^(uint64_t physicalAddress, uint64_t length, + void * _Nonnull dst) { + trace_apple_gfx_read_memory(physicalAddress, length, dst); + cpu_physical_memory_read(physicalAddress, dst, length); + return (bool)true; + }; + +} + +static PGDisplayDescriptor *apple_gfx_prepare_display_handlers(AppleGFXSta= te *s) +{ + PGDisplayDescriptor *disp_desc =3D [PGDisplayDescriptor new]; + + disp_desc.name =3D @"QEMU display"; + disp_desc.sizeInMillimeters =3D NSMakeSize(400., 300.); /* A 20" displ= ay */ + disp_desc.queue =3D dispatch_get_main_queue(); + disp_desc.newFrameEventHandler =3D ^(void) { + trace_apple_gfx_new_frame(); + dispatch_async(s->render_queue, ^{ + /* Drop frames if we get too far ahead. */ + if (s->pending_frames >=3D 2) + return; + ++s->pending_frames; + if (s->pending_frames > 1) { + return; + } + @autoreleasepool { + apple_gfx_render_new_frame(s); + } + }); + }; + disp_desc.modeChangeHandler =3D ^(PGDisplayCoord_t sizeInPixels, + OSType pixelFormat) { + trace_apple_gfx_mode_change(sizeInPixels.x, sizeInPixels.y); + set_mode(s, sizeInPixels.x, sizeInPixels.y); + }; + disp_desc.cursorGlyphHandler =3D ^(NSBitmapImageRep *glyph, + PGDisplayCoord_t hotSpot) { + uint32_t bpp =3D glyph.bitsPerPixel; + size_t width =3D glyph.pixelsWide; + size_t height =3D glyph.pixelsHigh; + size_t padding_bytes_per_row =3D glyph.bytesPerRow - width * 4; + const uint8_t* px_data =3D glyph.bitmapData; + + trace_apple_gfx_cursor_set(bpp, width, height); + + if (s->cursor) { + cursor_unref(s->cursor); + s->cursor =3D NULL; + } + + if (bpp =3D=3D 32) { /* Shouldn't be anything else, but just to be= safe...*/ + s->cursor =3D cursor_alloc(width, height); + s->cursor->hot_x =3D hotSpot.x; + s->cursor->hot_y =3D hotSpot.y; + + uint32_t *dest_px =3D s->cursor->data; + + for (size_t y =3D 0; y < height; ++y) { + for (size_t x =3D 0; x < width; ++x) { + /* NSBitmapImageRep's red & blue channels are swapped + * compared to QEMUCursor's. */ + *dest_px =3D + (px_data[0] << 16u) | + (px_data[1] << 8u) | + (px_data[2] << 0u) | + (px_data[3] << 24u); + ++dest_px; + px_data +=3D 4; + } + px_data +=3D padding_bytes_per_row; + } + dpy_cursor_define(s->con, s->cursor); + update_cursor(s); + } + }; + disp_desc.cursorShowHandler =3D ^(BOOL show) { + trace_apple_gfx_cursor_show(show); + s->cursor_show =3D show; + update_cursor(s); + }; + disp_desc.cursorMoveHandler =3D ^(void) { + trace_apple_gfx_cursor_move(); + update_cursor(s); + }; + + return disp_desc; +} + +static NSArray* apple_gfx_prepare_display_mode_array(void) +{ + PGDisplayMode *modes[ARRAY_SIZE(apple_gfx_modes)]; + NSArray* mode_array =3D nil; + int i; + + for (i =3D 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { + modes[i] =3D + [[PGDisplayMode alloc] initWithSizeInPixels:apple_gfx_modes[i]= refreshRateInHz:60.]; + } + + mode_array =3D [NSArray arrayWithObjects:modes count:ARRAY_SIZE(apple_= gfx_modes)]; + + for (i =3D 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { + [modes[i] release]; + modes[i] =3D nil; + } + + return mode_array; +} + +static id copy_suitable_metal_device(void) +{ + id dev =3D nil; + NSArray> *devs =3D MTLCopyAllDevices(); + + /* Prefer a unified memory GPU. Failing that, pick a non-removable GPU= . */ + for (size_t i =3D 0; i < devs.count; ++i) { + if (devs[i].hasUnifiedMemory) { + dev =3D devs[i]; + break; + } + if (!devs[i].removable) { + dev =3D devs[i]; + } + } + + if (dev !=3D nil) { + [dev retain]; + } else { + dev =3D MTLCreateSystemDefaultDevice(); + } + [devs release]; + + return dev; +} + +void apple_gfx_common_realize(AppleGFXState *s, PGDeviceDescriptor *desc) +{ + PGDisplayDescriptor *disp_desc =3D nil; + + QTAILQ_INIT(&s->tasks); + s->render_queue =3D dispatch_queue_create("apple-gfx.render", + DISPATCH_QUEUE_SERIAL); + s->mtl =3D copy_suitable_metal_device(); + s->mtl_queue =3D [s->mtl newCommandQueue]; + + desc.device =3D s->mtl; + + apple_gfx_register_task_mapping_handlers(s, desc); + + s->pgdev =3D PGNewDeviceWithDescriptor(desc); + + disp_desc =3D apple_gfx_prepare_display_handlers(s); + s->pgdisp =3D [s->pgdev newDisplayWithDescriptor:disp_desc + port:0 serialNum:1234]; + [disp_desc release]; + s->pgdisp.modeList =3D apple_gfx_prepare_display_mode_array(); + + create_fb(s); +} diff --git a/hw/display/meson.build b/hw/display/meson.build index 7db05eace97..70d855749c0 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -65,6 +65,8 @@ system_ss.add(when: 'CONFIG_ARTIST', if_true: files('arti= st.c')) =20 system_ss.add(when: 'CONFIG_ATI_VGA', if_true: [files('ati.c', 'ati_2d.c',= 'ati_dbg.c'), pixman]) =20 +system_ss.add(when: 'CONFIG_MAC_PVG', if_true: [files('apple-gfx.m= '), pvg, metal]) +system_ss.add(when: 'CONFIG_MAC_PVG_VMAPPLE', if_true: [files('apple-gfx-v= mapple.m'), pvg, metal]) =20 if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss =3D ss.source_set() diff --git a/hw/display/trace-events b/hw/display/trace-events index 781f8a33203..1809a358e36 100644 --- a/hw/display/trace-events +++ b/hw/display/trace-events @@ -191,3 +191,29 @@ dm163_bits_ppi(unsigned dest_width) "dest_width : %u" dm163_leds(int led, uint32_t value) "led %d: 0x%x" dm163_channels(int channel, uint8_t value) "channel %d: 0x%x" dm163_refresh_rate(uint32_t rr) "refresh rate %d" + +# apple-gfx.m +apple_gfx_read(uint64_t offset, uint64_t res) "offset=3D0x%"PRIx64" res=3D= 0x%"PRIx64 +apple_gfx_write(uint64_t offset, uint64_t val) "offset=3D0x%"PRIx64" val= =3D0x%"PRIx64 +apple_gfx_create_task(uint32_t vm_size, void *va) "vm_size=3D0x%x base_add= r=3D%p" +apple_gfx_destroy_task(void *task) "task=3D%p" +apple_gfx_map_memory(void *task, uint32_t range_count, uint64_t virtual_of= fset, uint32_t read_only) "task=3D%p range_count=3D0x%x virtual_offset=3D0x= %"PRIx64" read_only=3D%d" +apple_gfx_map_memory_range(uint32_t i, uint64_t phys_addr, uint64_t phys_l= en) "[%d] phys_addr=3D0x%"PRIx64" phys_len=3D0x%"PRIx64 +apple_gfx_remap(uint64_t retval, uint64_t source, uint64_t target) "retval= =3D%"PRId64" source=3D0x%"PRIx64" target=3D0x%"PRIx64 +apple_gfx_unmap_memory(void *task, uint64_t virtual_offset, uint64_t lengt= h) "task=3D%p virtual_offset=3D0x%"PRIx64" length=3D0x%"PRIx64 +apple_gfx_read_memory(uint64_t phys_address, uint64_t length, void *dst) "= phys_addr=3D0x%"PRIx64" length=3D0x%"PRIx64" dest=3D%p" +apple_gfx_raise_irq(uint32_t vector) "vector=3D0x%x" +apple_gfx_new_frame(void) "" +apple_gfx_mode_change(uint64_t x, uint64_t y) "x=3D%"PRId64" y=3D%"PRId64 +apple_gfx_cursor_set(uint32_t bpp, uint64_t width, uint64_t height) "bpp= =3D%d width=3D%"PRId64" height=3D0x%"PRId64 +apple_gfx_cursor_show(uint32_t show) "show=3D%d" +apple_gfx_cursor_move(void) "" +apple_gfx_common_init(const char *device_name, size_t mmio_size) "device: = %s; MMIO size: %zu bytes" + +# apple-gfx-vmapple.m +apple_iosfc_read(uint64_t offset, uint64_t res) "offset=3D0x%"PRIx64" res= =3D0x%"PRIx64 +apple_iosfc_write(uint64_t offset, uint64_t val) "offset=3D0x%"PRIx64" val= =3D0x%"PRIx64 +apple_iosfc_map_memory(uint64_t phys, uint64_t len, uint32_t ro, void *va,= void *e, void *f) "phys=3D0x%"PRIx64" len=3D0x%"PRIx64" ro=3D%d va=3D%p e= =3D%p f=3D%p" +apple_iosfc_unmap_memory(void *a, void *b, void *c, void *d, void *e, void= *f) "a=3D%p b=3D%p c=3D%p d=3D%p e=3D%p f=3D%p" +apple_iosfc_raise_irq(uint32_t vector) "vector=3D0x%x" + diff --git a/meson.build b/meson.build index 10464466ff3..f09df3f09d5 100644 --- a/meson.build +++ b/meson.build @@ -741,6 +741,8 @@ socket =3D [] version_res =3D [] coref =3D [] iokit =3D [] +pvg =3D [] +metal =3D [] emulator_link_args =3D [] midl =3D not_found widl =3D not_found @@ -762,6 +764,8 @@ elif host_os =3D=3D 'darwin' coref =3D dependency('appleframeworks', modules: 'CoreFoundation') iokit =3D dependency('appleframeworks', modules: 'IOKit', required: fals= e) host_dsosuf =3D '.dylib' + pvg =3D dependency('appleframeworks', modules: 'ParavirtualizedGraphics') + metal =3D dependency('appleframeworks', modules: 'Metal') elif host_os =3D=3D 'sunos' socket =3D [cc.find_library('socket'), cc.find_library('nsl'), --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727513936; cv=none; d=zohomail.com; s=zohoarc; b=KicbO0bG5X90M3yfFdxUr0N4MHgeealWOJn6WlcD7cTI25vgsD7C93xKYtYGpmLFtgW94Mo/NqI0JqSXzVQw4h3pY1mTo/l25TSRNZzrrxxQDXEyZUbl+qTlCNqjBqjoPReM+FEnOGGVUKaIAezDD5GJVEushU5myNoEuND8Bmw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727513936; 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=zl3mKVns8uJPgYMQEV1u67mSsyfy3FBABb4tiuHMiDI=; b=VfHIKZxLqtxTIU6N0ZF+rEnTDljyRliWf/Lcv9moV7KQASXuWTXAguRC0RjfT/3b9v9e4raGHygL3M8Kxk9EN5LH0TLqNhSA8SElfKWgFcBMeEsMWyVdbWrXIEEA74+48IQ0+z4nU9uwHyNkej0jUrhhzW1TlJaJS+DmEwtFsZw= 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 1727513936657966.5684686279415; Sat, 28 Sep 2024 01:58:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTHU-0008Lo-GY; Sat, 28 Sep 2024 04:58:24 -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 1suTHS-0008KP-Gn for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:22 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTHO-0002HL-6X for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:22 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-37cc810ce73so1767944f8f.1 for ; Sat, 28 Sep 2024 01:58:17 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.58.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513897; x=1728118697; 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=zl3mKVns8uJPgYMQEV1u67mSsyfy3FBABb4tiuHMiDI=; b=hPSLhB6CerAxQnY2lOU/dQ3JKrCdfxtAgwR6grSkxWHysihVe9OQkHd9dB0BEpJRfh ZLllGktn6xq2wG1rnQ0Zdceb2EpEInOJXgnFdooYtA3xyZGzMHJ2tAF0mrAWC5Qfx0wX dbQmvd/M9Q6nKovJXGGi0c85lpCJEo7yQFdz8rjKRpX2AJp9Hk29UkRelFkzzVQUCfV3 514ie0e9QsBNp/esX7+phvMZVzZL0Ernaz/nSuY/2Vxi6gNG6Fb5YhKFNuDojIPu0+iN obIz4iWLU8hPM3qwzNqyGfVhQEyr9pmULEayl2CbFIidlx3RDoSOKV6e4aZ1fOGbdR1M za7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513897; x=1728118697; 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=zl3mKVns8uJPgYMQEV1u67mSsyfy3FBABb4tiuHMiDI=; b=a0SKVuofaoHtMx5fz/pqIbSNzlgLWX6D0G2eqUTr4PKsfdr24t1SBrUKIARNAgmuJS gJOjVWaGgukcvYcF0aT/vyhi8nSuPSJTs5Ja89Jf1KnjOFPPQF6+WBuDT4ZWBgKFu937 LttHvR437pkgcmfHqJEr1SXyQNimyLCIRBnmBap79LHUjbw0k/fJz54/x00xiA9HVV/y AAGa1YMGJGwWhilhzIqYWAtbSA1jxiU+Vy8/toYcAit9z2fRsfsZ8N4mHfchYoaEdutQ acok7awQYnK+mKptxQFhxVA6zeAXHb96uqYv/oloIt0JJJ8WAEBKU5p5yi23kkiSIFiz dO1w== X-Gm-Message-State: AOJu0YydQgd6mNaYJ9h75kDe3pCd9GUOLhFNM9RbyP8k3d0YHzkE3dKW dbyQDSRLggv0OElbjtLyBRWoYjrW2t6NWYBMYyng6i1ELsZV5gA8H0luK1TK73MufoiT2BxYv61 ZZQ== X-Google-Smtp-Source: AGHT+IH2R3p6guMhPbRVNykPnRlw6yvmRItzkIF+0idgQV6Gc41dE5JP/kJiAhkONRmXUdvHiJSM/Q== X-Received: by 2002:adf:ed4e:0:b0:374:bad2:6a5e with SMTP id ffacd0b85a97d-37cd5ab7535mr3210984f8f.28.1727513896501; Sat, 28 Sep 2024 01:58:16 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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 Subject: [PATCH v3 02/14] hw/display/apple-gfx: Adds PCI implementation Date: Sat, 28 Sep 2024 10:57:15 +0200 Message-Id: <20240928085727.56883-3-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-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::42c; envelope-from=phil@philjordan.eu; helo=mail-wr1-x42c.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, 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: 1727513940272116600 This change wires up the PCI variant of the paravirtualised graphics device, mainly useful for x86-64 macOS guests, implemented by macOS's ParavirtualizedGraphics.framework. It builds on code shared with the vmapple/mmio variant of the PVG device. Signed-off-by: Phil Dennis-Jordan --- hw/display/Kconfig | 5 ++ hw/display/apple-gfx-pci.m | 138 +++++++++++++++++++++++++++++++++++++ hw/display/meson.build | 1 + 3 files changed, 144 insertions(+) create mode 100644 hw/display/apple-gfx-pci.m diff --git a/hw/display/Kconfig b/hw/display/Kconfig index 179a479d220..c2ec268f8e9 100644 --- a/hw/display/Kconfig +++ b/hw/display/Kconfig @@ -152,3 +152,8 @@ config MAC_PVG_VMAPPLE bool depends on MAC_PVG depends on ARM + +config MAC_PVG_PCI + bool + depends on MAC_PVG && PCI + default y if PCI_DEVICES diff --git a/hw/display/apple-gfx-pci.m b/hw/display/apple-gfx-pci.m new file mode 100644 index 00000000000..9370258ee46 --- /dev/null +++ b/hw/display/apple-gfx-pci.m @@ -0,0 +1,138 @@ +/* + * QEMU Apple ParavirtualizedGraphics.framework device, PCI variant + * + * Copyright =C2=A9 2023-2024 Phil Dennis-Jordan + * + * 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. + * + * ParavirtualizedGraphics.framework is a set of libraries that macOS prov= ides + * which implements 3d graphics passthrough to the host as well as a + * proprietary guest communication channel to drive it. This device model + * implements support to drive that library from within QEMU as a PCI devi= ce + * aimed primarily at x86-64 macOS VMs. + */ + +#include "apple-gfx.h" +#include "hw/pci/pci_device.h" +#include "hw/pci/msi.h" +#include "qapi/error.h" +#include "trace.h" +#import + +typedef struct AppleGFXPCIState { + PCIDevice parent_obj; + + AppleGFXState common; +} AppleGFXPCIState; + +OBJECT_DECLARE_SIMPLE_TYPE(AppleGFXPCIState, APPLE_GFX_PCI) + +static const char* apple_gfx_pci_option_rom_path =3D NULL; + +static void apple_gfx_init_option_rom_path(void) +{ + NSURL *option_rom_url =3D PGCopyOptionROMURL(); + const char *option_rom_path =3D option_rom_url.fileSystemRepresentatio= n; + if (option_rom_url.fileURL && option_rom_path !=3D NULL) { + apple_gfx_pci_option_rom_path =3D g_strdup(option_rom_path); + } + [option_rom_url release]; +} + +static void apple_gfx_pci_init(Object *obj) +{ + AppleGFXPCIState *s =3D APPLE_GFX_PCI(obj); + + if (!apple_gfx_pci_option_rom_path) { + /* Done on device not class init to avoid -daemonize ObjC fork cra= sh */ + PCIDeviceClass *pci =3D PCI_DEVICE_CLASS(object_get_class(obj)); + apple_gfx_init_option_rom_path(); + pci->romfile =3D apple_gfx_pci_option_rom_path; + } + + apple_gfx_common_init(obj, &s->common, TYPE_APPLE_GFX_PCI); +} + +static void apple_gfx_pci_interrupt(PCIDevice *dev, AppleGFXPCIState *s, + uint32_t vector) +{ + bool msi_ok; + trace_apple_gfx_raise_irq(vector); + + msi_ok =3D msi_enabled(dev); + if (msi_ok) { + msi_notify(dev, vector); + } +} + +static void apple_gfx_pci_realize(PCIDevice *dev, Error **errp) +{ + AppleGFXPCIState *s =3D APPLE_GFX_PCI(dev); + Error *err =3D NULL; + int ret; + + pci_register_bar(dev, PG_PCI_BAR_MMIO, + PCI_BASE_ADDRESS_SPACE_MEMORY, &s->common.iomem_gfx); + + ret =3D msi_init(dev, 0x0 /* config offset; 0 =3D find space */, + PG_PCI_MAX_MSI_VECTORS, true /* msi64bit */, + false /*msi_per_vector_mask*/, &err); + if (ret !=3D 0) { + error_propagate(errp, err); + return; + } + + @autoreleasepool { + PGDeviceDescriptor *desc =3D [PGDeviceDescriptor new]; + desc.raiseInterrupt =3D ^(uint32_t vector) { + apple_gfx_pci_interrupt(dev, s, vector); + }; + + apple_gfx_common_realize(&s->common, desc); + [desc release]; + desc =3D nil; + } +} + +static void apple_gfx_pci_reset(Object *obj, ResetType type) +{ + AppleGFXPCIState *s =3D APPLE_GFX_PCI(obj); + [s->common.pgdev reset]; +} + +static void apple_gfx_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + PCIDeviceClass *pci =3D PCI_DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + assert(rc->phases.hold =3D=3D NULL); + rc->phases.hold =3D apple_gfx_pci_reset; + dc->desc =3D "macOS Paravirtualized Graphics PCI Display Controller"; + dc->hotpluggable =3D false; + set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); + + pci->vendor_id =3D PG_PCI_VENDOR_ID; + pci->device_id =3D PG_PCI_DEVICE_ID; + pci->class_id =3D PCI_CLASS_DISPLAY_OTHER; + pci->realize =3D apple_gfx_pci_realize; + + // TODO: Property for setting mode list +} + +static TypeInfo apple_gfx_pci_types[] =3D { + { + .name =3D TYPE_APPLE_GFX_PCI, + .parent =3D TYPE_PCI_DEVICE, + .instance_size =3D sizeof(AppleGFXPCIState), + .class_init =3D apple_gfx_pci_class_init, + .instance_init =3D apple_gfx_pci_init, + .interfaces =3D (InterfaceInfo[]) { + { INTERFACE_PCIE_DEVICE }, + { }, + }, + } +}; +DEFINE_TYPES(apple_gfx_pci_types) + diff --git a/hw/display/meson.build b/hw/display/meson.build index 70d855749c0..ceb7bb07612 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -67,6 +67,7 @@ system_ss.add(when: 'CONFIG_ATI_VGA', if_true: [files('at= i.c', 'ati_2d.c', 'ati_ =20 system_ss.add(when: 'CONFIG_MAC_PVG', if_true: [files('apple-gfx.m= '), pvg, metal]) system_ss.add(when: 'CONFIG_MAC_PVG_VMAPPLE', if_true: [files('apple-gfx-v= mapple.m'), pvg, metal]) +system_ss.add(when: 'CONFIG_MAC_PVG_PCI', if_true: [files('apple-gfx-p= ci.m'), pvg, metal]) =20 if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss =3D ss.source_set() --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727513936; cv=none; d=zohomail.com; s=zohoarc; b=JKAHW7rbPvArJz8b9Ipe8a1lBUxnMU0avCAv0UEsTJpYG3Klg5zD5uSLB97XJ8BhFOet7QmEYZU7Z7O8psw1aYrDDYvK4S2qaTgBTtVJ7AU9/9jrDOyfM63U+oywbbugGfusSN7PqcHEiFjZvMb+LVL4NvWDxUAuy6yQsOO5A08= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727513936; 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=emwXegwM6KYIW65+ci8KhXuSLLm423iSwF1B6mw4630=; b=gt66E9GkdWhvAaYFbxEfPrk4X0/PItZqLIIJVu8ROcuqWbNApPZyd5mPLP30se872VlIAOTutIRMg0wHALmtLDnehmMSeJ4YxhxnCrgh8NJJ0qBaQPZ/X6RDO2WmaMWv/n4MF1UyoEa36gX+SjMt0U1gEJ+K82XaRNLLfgK4Dio= 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 1727513936656769.8450639614912; Sat, 28 Sep 2024 01:58:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTHY-00008C-Ok; Sat, 28 Sep 2024 04:58:28 -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 1suTHW-0008So-Hq for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:26 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTHT-0002IA-R2 for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:26 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-42ca4e0299eso23834685e9.2 for ; Sat, 28 Sep 2024 01:58:23 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.58.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:58:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513902; x=1728118702; 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=emwXegwM6KYIW65+ci8KhXuSLLm423iSwF1B6mw4630=; b=1sfp+CL/g/+VkSzEQGRev3AFaYxZfjMq1CJijVh0cxtsqzgvINfzWOfbtQ+TT/jmfv zRTQNJitI2fJqtYTld/ukvszKDthNhqql79E+poP7Q0JZZHwktAfiWUtgRyee4mGcLT6 gkxoHuprk4RoV/YqdHaG3REuZkfGApkDoS9ZXXMZe99w20hDl/ZPqRnmkvPBUnArlDAP HmF9aurIYkId4/p9FIv+eGia6GBYXO6afHI7h184EtYU/+RfjVc6+YKa97MQYvUaqd7t 8m2+3Lfetav2CLtCyo00seW6UuNPMMCv2dc3Pc9zij6r59xbG6Enx0DpFeXwnJedFSHG VtHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513902; x=1728118702; 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=emwXegwM6KYIW65+ci8KhXuSLLm423iSwF1B6mw4630=; b=Ps/bHlJAXz8rqoPvOOOu2hG1qlscPfODkMxpvGjEp+fGxBtzLrkz1rhmAYfmcmypDu npPncjDWLON6FxrkKq96z0be6S3Pi8FmSKcAGXsXSa3kTZwj3JHryYyxCpdhcGYNRj6H xoHKE71eUWlpcZDAMlQojSH6anVdo2Y65HJq42Wm0TRSFfgVsmWFbJ3gluX2yLH5lv5F 7NL1UkIvu21KT6+Fl2MRCD9NTQMIA9aeQdC03P3CCnEBR6bIDdjwVODcqOt3ak8sE1jY G6bIciBaHI0gFUA/Yfups0cnWLAfXVvM4M2rG4fR367FYdoF4gVKlOSpxaspRwcFX3uN fXQw== X-Gm-Message-State: AOJu0Yw+vcQtzWvoJH/O9QbHzxwOTbehV5hdVP0bYNI90n1U0S+AgJKg kIUiRh1pdEY1lzpVVh2vFT7mxjWSlqtdS3tVISWUv/Wvmk48MXkE+e2cYaK+Uq9+46HJZYOeBk0 tjQ== X-Google-Smtp-Source: AGHT+IGXZBOV88uGQzmNeyQjuqZ1N5iL/ed4zCI6+RTC9fgfOp2UZt4ohgSuxmg97vD1wvnjItC9Ig== X-Received: by 2002:a05:600c:4f82:b0:428:1310:b6b5 with SMTP id 5b1f17b1804b1-42f5849c3demr41288325e9.34.1727513902024; Sat, 28 Sep 2024 01:58:22 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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 Subject: [PATCH v3 03/14] ui/cocoa: Adds non-app runloop on main thread mode Date: Sat, 28 Sep 2024 10:57:16 +0200 Message-Id: <20240928085727.56883-4-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-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::334; envelope-from=phil@philjordan.eu; helo=mail-wm1-x334.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, 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: 1727513940216116600 Various system frameworks on macOS and other Apple platforms require a main runloop to be processing events on the process=E2=80=99s main thread. The Cocoa UI=E2=80=99s requirement to run the process as a Cocoa application automatically enables this runloop, but it can be useful to have the runloop handling events even without the Cocoa UI active. This change adds a non-app runloop mode to the cocoa_main function. This can be requested by other code, while the Cocoa UI additionally enables app mode. This arrangement ensures there is only one qemu_main function switcheroo, and the Cocoa UI=E2=80=99s app mode requirement and other subsystems=E2=80=99 runloop requests don=E2=80= =99t conflict with each other. The main runloop is required for the AppleGFX PV graphics device, so the runloop request call has been added to its initialisation. Signed-off-by: Phil Dennis-Jordan --- hw/display/apple-gfx.m | 3 +++ include/qemu-main.h | 2 ++ ui/cocoa.m | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m index 837300f9cd4..6ef1048d93d 100644 --- a/hw/display/apple-gfx.m +++ b/hw/display/apple-gfx.m @@ -14,6 +14,7 @@ =20 #include "apple-gfx.h" #include "trace.h" +#include "qemu-main.h" #include "qemu/main-loop.h" #include "ui/console.h" #include "monitor/monitor.h" @@ -299,6 +300,8 @@ void apple_gfx_common_init(Object *obj, AppleGFXState *= s, const char* obj_name) error_report_err(local_err); } } + + cocoa_enable_runloop_on_main_thread(); } =20 static void apple_gfx_register_task_mapping_handlers(AppleGFXState *s, diff --git a/include/qemu-main.h b/include/qemu-main.h index 940960a7dbc..da4516e69eb 100644 --- a/include/qemu-main.h +++ b/include/qemu-main.h @@ -8,4 +8,6 @@ int qemu_default_main(void); extern int (*qemu_main)(void); =20 +void cocoa_enable_runloop_on_main_thread(void); + #endif /* QEMU_MAIN_H */ diff --git a/ui/cocoa.m b/ui/cocoa.m index 4c2dd335323..40f65d7a45d 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -2028,6 +2028,7 @@ static void cocoa_clipboard_request(QemuClipboardInfo= *info, exit(status); } =20 +static bool run_as_cocoa_app =3D false; static int cocoa_main(void) { QemuThread thread; @@ -2040,7 +2041,11 @@ static int cocoa_main(void) =20 // Start the main event loop COCOA_DEBUG("Main thread: entering OSX run loop\n"); - [NSApp run]; + if (run_as_cocoa_app) { + [NSApp run]; + } else { + CFRunLoopRun(); + } COCOA_DEBUG("Main thread: left OSX run loop, which should never happen= \n"); =20 abort(); @@ -2114,13 +2119,19 @@ static void cocoa_cursor_define(DisplayChangeListen= er *dcl, QEMUCursor *cursor) }); } =20 +void cocoa_enable_runloop_on_main_thread(void) +{ + qemu_main =3D cocoa_main; +} + static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) { NSAutoreleasePool * pool =3D [[NSAutoreleasePool alloc] init]; =20 COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n"); =20 - qemu_main =3D cocoa_main; + run_as_cocoa_app =3D true; + cocoa_enable_runloop_on_main_thread(); =20 // Pull this console process up to being a fully-fledged graphical // app with a menubar and Dock icon --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727514149; cv=none; d=zohomail.com; s=zohoarc; b=m/RczF7ex7Ns+077GI/USS7nNXhR30xWHlZ4XsVnRaMZVrhPzElgKB4iO0xdg1+/CQqfUDhCpAIg4RkiAFClqS9nWgHcSIaMwwsqXhUu+UAn7Y1NXqbD4SxLWkKQnh7yo7EdNzAuygI+5OBjqxrUPmhmZ/ZLehUUWaaZCJXr7Y4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727514149; h=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=TnhSO9Zp03vZcISVYUidyjWsniT7WLSHtpVFi0MugPQ=; b=OVt5KZPV97yKPcwnFY3/zbY4o3mdAtquGvLFWBYDX9++FIrb4+bxSCID2taufQYT0I/xO6pgu+6dtLzuraHHdLoGsan+FItbX83ArPlfTqgr/ctm7iUTLdWPsm5wtRFXlMnJ5xhx2AIK2LQFWG/2g98fWB+K/6Bt8tVzdaYOU38= 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 1727514149271976.3717068258875; Sat, 28 Sep 2024 02:02:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTHd-0000Jm-IH; Sat, 28 Sep 2024 04:58:33 -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 1suTHb-0000Hv-KX for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:31 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTHZ-0002JB-J3 for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:31 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-37cd6ece97cso1079555f8f.1 for ; Sat, 28 Sep 2024 01:58:29 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.58.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513908; x=1728118708; 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=TnhSO9Zp03vZcISVYUidyjWsniT7WLSHtpVFi0MugPQ=; b=njx9waH74qbqDXHcDBKt3h1/WqnJlwdGs94AngFZmrtaQ+FB68I+RmvUMT3j8dUfO3 dV15YjRj+iZx1qktsaq9udrFiOUnzKjWtfflS77Ern1KjaacY7uE4y2BhjYvXvnFBaB6 KIOMMFI96xJerFH99mgQljs+P0MOXpPoH3dVMqOH+eHDbMK+MRtm36Q6aL7uge48Vnli 3qeG6PbiB/9pvcDmqIfDKfgwfR3Gk+zpZ1LzoMWQbYdIB5c0K+RKZ8S3/oyNebamldDe fMuvWklsSQQLWes7t2i8V00K3Uvcr1MwfpYeiu3CVJTZ7DY1v1RJsdCenn3H4j93+2vB VQbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513908; x=1728118708; 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=TnhSO9Zp03vZcISVYUidyjWsniT7WLSHtpVFi0MugPQ=; b=HqC3mgCXdQRU5udZ2Hh8fKwVjicjV9HoRbiSAkY9P/8nUjTsCfyUFW2nCn2Mliu2G8 B7G7ncRl1Zsi/FVagQYurMaUKSCusV++UwQ6xQwFURm4qwUPhLY/8MfsOxl6Ch7osDmi tWW3kievZhtLuyk0qn1QUeKwPoi99LRkobRlw+GO7Hz9dttsTbRErv3ZAFzBL94otOFT 7t5dc1kU1ZuiVeOdD2ElJyWrXQVkk3g9JFdJNtTrSj2LxBOo/dyHb3uG8hf0WpoSc3bv BDlxVXf64DdoqFMdIqoCINdJgWDxXWb/77eHMQutdHJ2hKPhDLN/mik2YH+7Fu3v78Tu ZIew== X-Gm-Message-State: AOJu0YyEa1H2qYk7++7r8892yqLR6/uPfB5CMEd0+B7h6JtZa+P0HJ/e nsfhwDWsKEC7Sb0cmfMaWcSqByq0teb3Zw8DguBQg9SHbbZ7XJWpKz6wN1Z4JN4PZcQb2V4GFbn 6bg== X-Google-Smtp-Source: AGHT+IF8xMaG7MBJHZEk74+QrN0YF9AJ8nWp056uZqQG03nR5muYjTa1Yb5gJAfdiHMw2RWQd28kuw== X-Received: by 2002:a5d:6acf:0:b0:37c:c4bc:181c with SMTP id ffacd0b85a97d-37cd5a6b66cmr3694968f8f.11.1727513907803; Sat, 28 Sep 2024 01:58:27 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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 Subject: [PATCH v3 04/14] hw/display/apple-gfx: Adds configurable mode list Date: Sat, 28 Sep 2024 10:57:17 +0200 Message-Id: <20240928085727.56883-5-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-1-phil@philjordan.eu> MIME-Version: 1.0 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::435; envelope-from=phil@philjordan.eu; helo=mail-wr1-x435.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, 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: 1727514151332116600 Content-Type: text/plain; charset="utf-8" This change adds a property 'display_modes' on the graphics device which permits specifying a list of display modes. (screen resolution and refresh rate) PCI variant of apple-gfx only for the moment. Signed-off-by: Phil Dennis-Jordan --- hw/display/apple-gfx-pci.m | 43 ++++++++++- hw/display/apple-gfx.h | 17 ++++- hw/display/apple-gfx.m | 151 ++++++++++++++++++++++++++++++++++--- 3 files changed, 198 insertions(+), 13 deletions(-) diff --git a/hw/display/apple-gfx-pci.m b/hw/display/apple-gfx-pci.m index 9370258ee46..ea86a1f4a21 100644 --- a/hw/display/apple-gfx-pci.m +++ b/hw/display/apple-gfx-pci.m @@ -16,6 +16,7 @@ #include "apple-gfx.h" #include "hw/pci/pci_device.h" #include "hw/pci/msi.h" +#include "hw/qdev-properties.h" #include "qapi/error.h" #include "trace.h" #import @@ -101,6 +102,46 @@ static void apple_gfx_pci_reset(Object *obj, ResetType= type) [s->common.pgdev reset]; } =20 +static void apple_gfx_pci_get_display_modes(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop =3D opaque; + AppleGFXDisplayModeList *mode_list =3D object_field_prop_ptr(obj, prop= ); + + apple_gfx_get_display_modes(mode_list, v, name, errp); +} + +static void apple_gfx_pci_set_display_modes(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop =3D opaque; + AppleGFXDisplayModeList *mode_list =3D object_field_prop_ptr(obj, prop= ); + + apple_gfx_set_display_modes(mode_list, v, name, errp); +} + +const PropertyInfo apple_gfx_pci_prop_display_modes =3D { + .name =3D "display_modes", + .description =3D + "Colon-separated list of display modes; " + "x@; the first mode is considered " + "'native'. Example: 3840x2160@60:2560x1440@60:1920x1080@60", + .get =3D apple_gfx_pci_get_display_modes, + .set =3D apple_gfx_pci_set_display_modes, +}; + +#define DEFINE_PROP_DISPLAY_MODES(_name, _state, _field) \ + DEFINE_PROP(_name, _state, _field, apple_gfx_pci_prop_display_modes, \ + AppleGFXDisplayModeList) + +static Property apple_gfx_pci_properties[] =3D { + DEFINE_PROP_DISPLAY_MODES("display-modes", AppleGFXPCIState, + common.display_modes), + DEFINE_PROP_END_OF_LIST(), +}; + static void apple_gfx_pci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -118,7 +159,7 @@ static void apple_gfx_pci_class_init(ObjectClass *klass= , void *data) pci->class_id =3D PCI_CLASS_DISPLAY_OTHER; pci->realize =3D apple_gfx_pci_realize; =20 - // TODO: Property for setting mode list + device_class_set_props(dc, apple_gfx_pci_properties); } =20 static TypeInfo apple_gfx_pci_types[] =3D { diff --git a/hw/display/apple-gfx.h b/hw/display/apple-gfx.h index 995ecf7f4a7..baad4a98652 100644 --- a/hw/display/apple-gfx.h +++ b/hw/display/apple-gfx.h @@ -5,14 +5,28 @@ #define TYPE_APPLE_GFX_PCI "apple-gfx-pci" =20 #include "qemu/typedefs.h" +#include "qemu/osdep.h" =20 typedef struct AppleGFXState AppleGFXState; =20 +typedef struct AppleGFXDisplayMode { + uint16_t width_px; + uint16_t height_px; + uint16_t refresh_rate_hz; +} AppleGFXDisplayMode; + +typedef struct AppleGFXDisplayModeList { + GArray *modes; +} AppleGFXDisplayModeList; + void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_= name); +void apple_gfx_get_display_modes(AppleGFXDisplayModeList *mode_list, Visit= or *v, + const char *name, Error **errp); +void apple_gfx_set_display_modes(AppleGFXDisplayModeList *mode_list, Visit= or *v, + const char *name, Error **errp); =20 #ifdef __OBJC__ =20 -#include "qemu/osdep.h" #include "exec/memory.h" #include "ui/surface.h" #include @@ -38,6 +52,7 @@ struct AppleGFXState { bool new_frame; bool cursor_show; QEMUCursor *cursor; + AppleGFXDisplayModeList display_modes; =20 dispatch_queue_t render_queue; /* The following fields should only be accessed from render_queue: */ diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m index 6ef1048d93d..358192db6a0 100644 --- a/hw/display/apple-gfx.m +++ b/hw/display/apple-gfx.m @@ -16,6 +16,9 @@ #include "trace.h" #include "qemu-main.h" #include "qemu/main-loop.h" +#include "qemu/cutils.h" +#include "qapi/visitor.h" +#include "qapi/error.h" #include "ui/console.h" #include "monitor/monitor.h" #include "qapi/error.h" @@ -23,9 +26,10 @@ #include #import =20 -static const PGDisplayCoord_t apple_gfx_modes[] =3D { - { .x =3D 1440, .y =3D 1080 }, - { .x =3D 1280, .y =3D 1024 }, +static const AppleGFXDisplayMode apple_gfx_default_modes[] =3D { + { 1920, 1080, 60 }, + { 1440, 1080, 60 }, + { 1280, 1024, 60 }, }; =20 typedef struct PGTask_s { // Name matches forward declaration in PG header @@ -264,7 +268,6 @@ static void set_mode(AppleGFXState *s, uint32_t width, = uint32_t height) static void create_fb(AppleGFXState *s) { s->con =3D graphic_console_init(NULL, 0, &apple_gfx_fb_ops, s); - set_mode(s, 1440, 1080); =20 s->cursor_show =3D true; } @@ -466,20 +469,24 @@ static void apple_gfx_register_task_mapping_handlers(= AppleGFXState *s, return disp_desc; } =20 -static NSArray* apple_gfx_prepare_display_mode_array(void) +static NSArray* apple_gfx_create_display_mode_array( + const AppleGFXDisplayMode display_modes[], int display_mode_count) { - PGDisplayMode *modes[ARRAY_SIZE(apple_gfx_modes)]; + PGDisplayMode **modes =3D alloca(sizeof(modes[0]) * display_mode_count= ); NSArray* mode_array =3D nil; int i; =20 - for (i =3D 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { + for (i =3D 0; i < display_mode_count; i++) { + const AppleGFXDisplayMode *mode =3D &display_modes[i]; + PGDisplayCoord_t mode_size =3D { mode->width_px, mode->height_px }; modes[i] =3D - [[PGDisplayMode alloc] initWithSizeInPixels:apple_gfx_modes[i]= refreshRateInHz:60.]; + [[PGDisplayMode alloc] initWithSizeInPixels:mode_size + refreshRateInHz:mode->refresh_rate= _hz]; } =20 - mode_array =3D [NSArray arrayWithObjects:modes count:ARRAY_SIZE(apple_= gfx_modes)]; + mode_array =3D [NSArray arrayWithObjects:modes count:display_mode_coun= t]; =20 - for (i =3D 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { + for (i =3D 0; i < display_mode_count; i++) { [modes[i] release]; modes[i] =3D nil; } @@ -516,6 +523,8 @@ static void apple_gfx_register_task_mapping_handlers(Ap= pleGFXState *s, void apple_gfx_common_realize(AppleGFXState *s, PGDeviceDescriptor *desc) { PGDisplayDescriptor *disp_desc =3D nil; + const AppleGFXDisplayMode *display_modes =3D apple_gfx_default_modes; + int num_display_modes =3D ARRAY_SIZE(apple_gfx_default_modes); =20 QTAILQ_INIT(&s->tasks); s->render_queue =3D dispatch_queue_create("apple-gfx.render", @@ -533,7 +542,127 @@ void apple_gfx_common_realize(AppleGFXState *s, PGDev= iceDescriptor *desc) s->pgdisp =3D [s->pgdev newDisplayWithDescriptor:disp_desc port:0 serialNum:1234]; [disp_desc release]; - s->pgdisp.modeList =3D apple_gfx_prepare_display_mode_array(); + + if (s->display_modes.modes !=3D NULL && s->display_modes.modes->len > = 0) { + display_modes =3D + &g_array_index(s->display_modes.modes, AppleGFXDisplayMode, 0); + num_display_modes =3D s->display_modes.modes->len; + } + s->pgdisp.modeList =3D + apple_gfx_create_display_mode_array(display_modes, num_display_mod= es); =20 create_fb(s); } + +void apple_gfx_get_display_modes(AppleGFXDisplayModeList *mode_list, Visit= or *v, + const char *name, Error **errp) +{ + GArray *modes =3D mode_list->modes; + /* 3 uint16s (max 5 digits) and 3 separator characters per mode + nul.= */ + size_t buffer_size =3D (5 + 1) * 3 * modes->len + 1; + + char *buffer =3D alloca(buffer_size); + char *pos =3D buffer; + + unsigned used =3D 0; + buffer[0] =3D '\0'; + for (guint i =3D 0; i < modes->len; ++i) + { + AppleGFXDisplayMode *mode =3D + &g_array_index(modes, AppleGFXDisplayMode, i); + int rc =3D snprintf(pos, buffer_size - used, + "%s%"PRIu16"x%"PRIu16"@%"PRIu16, + i > 0 ? ":" : "", + mode->width_px, mode->height_px, + mode->refresh_rate_hz); + used +=3D rc; + pos +=3D rc; + assert(used < buffer_size); + } + + pos =3D buffer; + visit_type_str(v, name, &pos, errp); +} + +void apple_gfx_set_display_modes(AppleGFXDisplayModeList *mode_list, Visit= or *v, + const char *name, Error **errp) +{ + Error *local_err =3D NULL; + const char *endptr; + char *str; + int ret; + unsigned int val; + uint32_t num_modes; + GArray *modes; + uint32_t mode_idx; + + visit_type_str(v, name, &str, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + // Count colons to estimate modes. No leading/trailing colons so start= at 1. + num_modes =3D 1; + for (size_t i =3D 0; str[i] !=3D '\0'; ++i) + { + if (str[i] =3D=3D ':') { + ++num_modes; + } + } + + modes =3D g_array_sized_new(false, true, sizeof(AppleGFXDisplayMode), = num_modes); + + endptr =3D str; + for (mode_idx =3D 0; mode_idx < num_modes; ++mode_idx) + { + AppleGFXDisplayMode mode =3D {}; + if (mode_idx > 0) + { + if (*endptr !=3D ':') { + goto separator_error; + } + ++endptr; + } + + ret =3D qemu_strtoui(endptr, &endptr, 10, &val); + if (ret || val > UINT16_MAX || val =3D=3D 0) { + error_setg(errp, "width of '%s' must be a decimal integer numb= er " + "of pixels in the range 1..65535", name); + goto out; + } + mode.width_px =3D val; + if (*endptr !=3D 'x') { + goto separator_error; + } + + ret =3D qemu_strtoui(endptr + 1, &endptr, 10, &val); + if (ret || val > UINT16_MAX || val =3D=3D 0) { + error_setg(errp, "height of '%s' must be a decimal integer num= ber " + "of pixels in the range 1..65535", name); + goto out; + } + mode.height_px =3D val; + if (*endptr !=3D '@') { + goto separator_error; + } + + ret =3D qemu_strtoui(endptr + 1, &endptr, 10, &val); + if (ret) { + error_setg(errp, "refresh rate of '%s'" + " must be a non-negative decimal integer (Hertz)", = name); + } + mode.refresh_rate_hz =3D val; + g_array_append_val(modes, mode); + } + + mode_list->modes =3D modes; + goto out; + +separator_error: + error_setg(errp, "Each display mode takes the format " + "'x@', modes are separated by colons. = (:)"); +out: + g_free(str); + return; +} --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727513936; cv=none; d=zohomail.com; s=zohoarc; b=jQXo0PJy7T781xFxctZeCq3YGZf5SInWjhR7CeKdydlbmGCSCRcuVG/a9Yj4eMBvJq56x9jg4t7ZwUMVWwJdWK16N3BNoojLSQB7rcpw6Ervu16J0ZY1IOCaJOLIBO26xmeCgHB++ba5uTv0vkdgSeIPLNllomFgK4w/bJPgvoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727513936; 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=FfeuSle8WU9lgCf9lWNy2Qa389vC+1vrwCadU13cu6o=; b=lg4d1dmh7OAEdvcb/N5prEGXpW8fkLbvlUO4rQcgZJt/Sqf2e5bHLIQNcLTZQF+8e9x9gxHrv4hqhlUDjuE7sfvSQIzhJFw6ecLeZW9tymco911WYbs38mF0rl6T1vwdckTD53r1nrphkSPgvINYMcTRnGwmr9lKB4g8UK74DpY= 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 1727513936588257.38593351623797; Sat, 28 Sep 2024 01:58:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTHj-0000YY-OH; Sat, 28 Sep 2024 04:58:39 -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 1suTHh-0000WD-Ai for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:37 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTHf-0002K8-Gh for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:37 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-37ce18b042fso216868f8f.1 for ; Sat, 28 Sep 2024 01:58:34 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.58.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513913; x=1728118713; 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=FfeuSle8WU9lgCf9lWNy2Qa389vC+1vrwCadU13cu6o=; b=jfBK+BRtJtF+gp8/N0evWYVshHEtFatc4vAU4REkpfEMwyNia872Xoha5jSnAopaeU DfgzpwHUF2pq/rRy0W8zWKTQVbfQXhkrKLvSCT3Wj+hPNCq15zgCji/E8iuN8dPDpEEC NjTijvUIQjt9fiAmyZd2AmGMrhm1iDa+cQ1gMEYscSAOgWKz3omVZzF3dEZ3EMTOmLES wjAC5/tlnWJPdugl019d664yNF/TKwlJzsthnXWc9x4xhyUFh+unUm8RumFJEJvPdvmU wcfDLOjiEEJQLFhdMKejW+mrLWY/vDJ2XXjfJ8J2zQSI17CxMIWmjdBcwmoGtJnzH8Gr uDjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513913; x=1728118713; 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=FfeuSle8WU9lgCf9lWNy2Qa389vC+1vrwCadU13cu6o=; b=fF+dr/fWB+TJE81U7rWzED+BUqaSH70XsNLRQ8lNtEGRvgkwfBTC/F3cJ5BWF2Q6Uu ifyAgBIQ3vdjsk9yEGRnLum3k6nCzpvvROjDoNkCjy/YSeOxn0HXUdJy5pRUyXY7ZKvH 0vjda0KbK+V+jMRSxZnbjPg32WtCWQO/megDIFHmQEnrAwYBZUutVHlJMEbdMEZRwAjO uF4Ddyt5W6o3hkzmbFyzCc5WkbXj0GHBi10kjL/MAPp2rJ2XSb4znjIPXET8YN05Fidc plbgwaGTKIwIE32jo4BqS8B2XDkxr4TxmUBfo0hOEDzDyOXGcKplcJhVQ2XjXhS9XqSw rLPQ== X-Gm-Message-State: AOJu0YwdY9INzal3+lnRY+iW5TgLfmLQ0bKvFgzDEZ3N9X7yhV7Ln74J meRQkiivIcNgVei5xDFjMfctbwuGV+XyHCjqQcMcqvCA8uSwTLAzqjaXjRbQ+15i7bQfKDssbP7 j8g== X-Google-Smtp-Source: AGHT+IGADEFUjJjdNj/ScMmbJthalbIvRiUmnE9lhPF6mFJEgYEg6JrbjYyhU/VLvr5+ABiN29vhig== X-Received: by 2002:a5d:404a:0:b0:371:a8a3:f9a1 with SMTP id ffacd0b85a97d-37cd5a831fcmr3731857f8f.11.1727513913081; Sat, 28 Sep 2024 01:58:33 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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 Subject: [PATCH v3 05/14] MAINTAINERS: Add myself as maintainer for apple-gfx, reviewer for HVF Date: Sat, 28 Sep 2024 10:57:18 +0200 Message-Id: <20240928085727.56883-6-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-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::436; envelope-from=phil@philjordan.eu; helo=mail-wr1-x436.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, 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: 1727513940095116600 I'm happy to take responsibility for the macOS PV graphics code. As HVF patches don't seem to get much attention at the moment, I'm also adding myself as designated reviewer for HVF and x86 HVF to try and improve that. I anticipate that the resulting workload should be covered by the funding I'm receiving for improving Qemu in combination with macOS. As of right now this runs out at the end of 2024; I expect the workload on apple-gfx should be relatively minor and manageable in my spare time beyond that. I may have to remove myself from more general HVF duties once the contract runs out if it's more than I can manage. Signed-off-by: Phil Dennis-Jordan --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index ffacd60f407..0133b874847 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -510,6 +510,7 @@ F: target/arm/hvf/ X86 HVF CPUs M: Cameron Esfahani M: Roman Bolshakov +R: Phil Dennis-Jordan W: https://wiki.qemu.org/Features/HVF S: Maintained F: target/i386/hvf/ @@ -517,6 +518,7 @@ F: target/i386/hvf/ HVF M: Cameron Esfahani M: Roman Bolshakov +R: Phil Dennis-Jordan W: https://wiki.qemu.org/Features/HVF S: Maintained F: accel/hvf/ @@ -2624,6 +2626,11 @@ F: hw/display/edid* F: include/hw/display/edid.h F: qemu-edid.c =20 +macOS PV Graphics (apple-gfx) +M: Phil Dennis-Jordan +S: Maintained +F: hw/display/apple-gfx* + PIIX4 South Bridge (i82371AB) M: Herv=C3=A9 Poussineau M: Philippe Mathieu-Daud=C3=A9 --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727513964; cv=none; d=zohomail.com; s=zohoarc; b=FElIhT5x3rIPWX+VH6CwmGtQGlydlerlJKDDjxXaIOjhjlgaebY+ipZHqFdgttfjvnchlUWqW+fRXith2EsGd7gFqPcXwM1ik9c5cdb9GxXr7RRWxp3NC+/R8UDySlfmQJnQtT8dA/+Wbuockqimt5f5IfJlDAL3P7Gvatm+WL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727513964; h=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=Tyonrm+foLYYFZ1a1u7JHM0QimT+pKoC8Tlz0H3o1Zo=; b=UPsvjT9Kxoby/1pwnrqSmwM6oQhcYeZjVmb043/ecesGfI70MxpThVZxR+ADpnGd8CRUFea/m6W56I1ZRc22XrdNJmvlsN1wJmXm2isB/deBEhWndt1RXAHVTmxTvkWT57p6hGymq2K7Rkvttcjp86rCGl7Pif+xV3ofMB51T94= 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 1727513964838656.8702037950718; Sat, 28 Sep 2024 01:59:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTHw-0001Ma-SY; Sat, 28 Sep 2024 04:58:52 -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 1suTHu-0001E0-S5 for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:50 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTHt-0002M2-9q for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:50 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-37a413085cbso2730049f8f.1 for ; Sat, 28 Sep 2024 01:58:48 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.58.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513928; x=1728118728; 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=Tyonrm+foLYYFZ1a1u7JHM0QimT+pKoC8Tlz0H3o1Zo=; b=B5EFXpDXAYt9YJMZmxhpiyXSuCE5xe4ecqCd8HIo+wdXquJKBnSDqrDqsni11R9uze X+U9EeeBtQndi2wkh+6uz3QGR45xxtOIM4VGsqdp95EvB1CbsjL6EuU/PDG4YjbkmG/x Co/QUaOcyg/gt4GCXZ2xgQRqu8WEBpq3bkLZN4WB/8T/2GVM1kcZ5SucDXu7SjyJ4W9R KOVdMaFp/7m6JJ+4cECfX2WN7Y1GAybtvaYTa9QDdY+QLvuGWoiRyeo2DjDreRgpBk1v RfJmeNfDqpnfm/VXyVUnXvg1OIlBS16CDs6QIPKfVGONbPdYG4fUoNK0dVM+4aSrQf4Z RAew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513928; x=1728118728; 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=Tyonrm+foLYYFZ1a1u7JHM0QimT+pKoC8Tlz0H3o1Zo=; b=n9ZRgLkV0AyieEmX+OVrW+YVnrVWbnk33GtZWi9w/zn8WEYyVMTg7Mj5uMbuc1nFhz 6paBPlYqu5h/1yLr8hw+ZVj3vSttV9UnY1ufFo9T3S3fX1B0QHaw2T01klfLfhZ8F0jf TQebid9GbnMp0cpIU6LH56bXNIAKbT/y8EWtNWoWNEPhX533h6lUPlW3T8uyCPHJb7nF 1o4NEpXjFefKvuTmDV8bRnxEYmsGJbGRdp6KV5P/MAMcOlo0SIaomHrpVi2f+2+iYUnK EJiMkxkxdbPu8MUs3+PuMNd7s9KERxFMTD1PneFPj8AtTbovRdlU0gcX9OuV6cT2Dnzo ynAA== X-Gm-Message-State: AOJu0YwajcdX17GUiR+iyPCW35EhQKiT0xDL1afvVVBKX/RQGqZv6G0c sL82NkwpwgGSmcnMW0sY7QUo7OWcFM/3BWLmErNxv6gGvUXsOiFXz50vccamRAMSiii9rNi0BRB Nkg== X-Google-Smtp-Source: AGHT+IE8r/PcKn+itB1BeOo2k6xBWCIZlVuvxPcuoNcXS5px38c25qusCsIsyLM7eSeOCAxhVrXoPw== X-Received: by 2002:a5d:4808:0:b0:374:d130:a43b with SMTP id ffacd0b85a97d-37cd5674dfemr3709937f8f.4.1727513927921; Sat, 28 Sep 2024 01:58:47 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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, Alexander Graf Subject: [PATCH v3 06/14] hw: Add vmapple subdir Date: Sat, 28 Sep 2024 10:57:19 +0200 Message-Id: <20240928085727.56883-7-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-1-phil@philjordan.eu> MIME-Version: 1.0 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::42f; envelope-from=phil@philjordan.eu; helo=mail-wr1-x42f.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, 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: 1727513966410116600 Content-Type: text/plain; charset="utf-8" From: Alexander Graf We will introduce a number of devices that are specific to the vmapple target machine. To keep them all tidily together, let's put them into a single target directory. Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan Reviewed-by: Akihiko Odaki --- MAINTAINERS | 7 +++++++ hw/Kconfig | 1 + hw/meson.build | 1 + hw/vmapple/Kconfig | 1 + hw/vmapple/meson.build | 0 hw/vmapple/trace-events | 2 ++ hw/vmapple/trace.h | 1 + meson.build | 1 + 8 files changed, 14 insertions(+) create mode 100644 hw/vmapple/Kconfig create mode 100644 hw/vmapple/meson.build create mode 100644 hw/vmapple/trace-events create mode 100644 hw/vmapple/trace.h diff --git a/MAINTAINERS b/MAINTAINERS index 0133b874847..4e7f25e5299 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2777,6 +2777,13 @@ F: hw/hyperv/hv-balloon*.h F: include/hw/hyperv/dynmem-proto.h F: include/hw/hyperv/hv-balloon.h =20 +VMapple +M: Alexander Graf +R: Phil Dennis-Jordan +S: Maintained +F: hw/vmapple/* +F: include/hw/vmapple/* + Subsystems ---------- Overall Audio backends diff --git a/hw/Kconfig b/hw/Kconfig index 6fdaff1b1be..4f0ad88a310 100644 --- a/hw/Kconfig +++ b/hw/Kconfig @@ -42,6 +42,7 @@ source ufs/Kconfig source usb/Kconfig source virtio/Kconfig source vfio/Kconfig +source vmapple/Kconfig source xen/Kconfig source watchdog/Kconfig =20 diff --git a/hw/meson.build b/hw/meson.build index e86badc5417..0b7151f948c 100644 --- a/hw/meson.build +++ b/hw/meson.build @@ -40,6 +40,7 @@ subdir('ufs') subdir('usb') subdir('vfio') subdir('virtio') +subdir('vmapple') subdir('watchdog') subdir('xen') subdir('xenpv') diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/hw/vmapple/Kconfig @@ -0,0 +1 @@ + diff --git a/hw/vmapple/meson.build b/hw/vmapple/meson.build new file mode 100644 index 00000000000..e69de29bb2d diff --git a/hw/vmapple/trace-events b/hw/vmapple/trace-events new file mode 100644 index 00000000000..9ccc5790487 --- /dev/null +++ b/hw/vmapple/trace-events @@ -0,0 +1,2 @@ +# See docs/devel/tracing.rst for syntax documentation. + diff --git a/hw/vmapple/trace.h b/hw/vmapple/trace.h new file mode 100644 index 00000000000..572adbefe04 --- /dev/null +++ b/hw/vmapple/trace.h @@ -0,0 +1 @@ +#include "trace/trace-hw_vmapple.h" diff --git a/meson.build b/meson.build index f09df3f09d5..092db201b95 100644 --- a/meson.build +++ b/meson.build @@ -3456,6 +3456,7 @@ if have_system 'hw/usb', 'hw/vfio', 'hw/virtio', + 'hw/vmapple', 'hw/watchdog', 'hw/xen', 'hw/gpio', --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727513977; cv=none; d=zohomail.com; s=zohoarc; b=Gf4dipmry4mFOrWxLRxzNtToJ22XMPNO1ETTT/L7Gnf7QjXpNgLro6RfJ+NyzaQuTQu1s4wZC+hVMQWprvq1CSnSlk7KRmZG9y+LR25HCfdhJneskJ/+XIDhD/s352WsaimzdUFTcapFTbFjs/g5MN6lrjlw66Nd1IUVAgmWoAs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727513977; 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=2fgUvUtj8SLtvDUJH3ESIndnrmz3mFFMGCb5iIRrdxk=; b=Pr/2aTVJhmmIbxbVwZ+2/ZlUHYHmUJtevkxMnNUCvs0sj9XWtG5xlnf5ZRVxB9gP7m/gsifYFgdcdzdl8A131/i+xR7PBLj36swMrcdKE3qBxjIIecW8DrbO2n6rUrnXPQPWagZ0OL4vll3d7ZvXM7yWKJ04p4D+jsKapha2VmE= 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 1727513977560625.8720787211267; Sat, 28 Sep 2024 01:59:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTI2-0001uw-RE; Sat, 28 Sep 2024 04:58:58 -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 1suTI0-0001hT-GM for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:56 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTHy-0002Mu-O9 for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:58:56 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-37cd5016d98so1340133f8f.1 for ; Sat, 28 Sep 2024 01:58:54 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.58.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513933; x=1728118733; 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=2fgUvUtj8SLtvDUJH3ESIndnrmz3mFFMGCb5iIRrdxk=; b=mAeTs7Y894QyTOTdb07jDoR8d36kvvmfwDieeGrbSeZCG8jnPzm0QyrRAbl0qjZRoD PM/qB/dCXc6HrfLe+tePW4RzD9k3CN7CqqxpF8KHvOx8XP0ZleuMADKCiKUa8mckR9bS Cz4W7fJddOXQz+AJVaC6b0uDnHdAeqn49B+DjwbEvlhm8IrdhabRkm8huE939ngAj2gb B1lOXJU/0PVDtqytJEgJs5M9POLKpm+kWz3aOsnx1zfgMhq72qu5DN32W85cOQRx5SZY cgn+X8cJm9vVM+tPHZgY614fOYFwKFtMvtgNcSGikqAQwaE2TsQbaZdTULxoq31F8/cZ 19HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513933; x=1728118733; 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=2fgUvUtj8SLtvDUJH3ESIndnrmz3mFFMGCb5iIRrdxk=; b=bfkmPdys6jukTizL6bqTEWQ8v8aPmb/F2Thv9eO/muzwjEoqxNlEn7Q5WAf6F0F0Kh +8ecGObp7HPBDGWiTZp4DUaUqsmmZVd6okXOEAZcAvZJugpZednu+PBDrUpFrFSxXlJY 5D3WuY25WvKOuOChYPJ4L1pdAp6FSHLJbBR7mUQYB4ZpdnzSLMpuYUYi1vqQ0XAu8PRK 8BjWCNb94i4zSYjsP2Bx6yH1liVLkzd+xzbzXP5hnOmoiDsv/5Wp+rljMnIJL9S+VsGU cCbWGR86GQy26pRK9doeObK+heHgVRAncJLBS33ExzbdX5I7nuF5wjUMLcYSTW1LpGJg KDIA== X-Gm-Message-State: AOJu0YxsaxD5k/OPiBRkJVqtyf2n5asZWmUo6wo7fP4h2E2wupPiML04 cHBgQfwKtBCrd3WNB+4hn6NU507xTOPZHRv2nYEgyab9LhMkNp7GQ7yxe4DmRUkSWI7sqpJ9uC3 Few== X-Google-Smtp-Source: AGHT+IHPP44FssURwBvcln3VCOEAavpMTncPBFh68+0dF/n7x2br+ZXi5HsHYcv2XU+XNXMFE7CG/g== X-Received: by 2002:a5d:5b8d:0:b0:37c:d507:aacc with SMTP id ffacd0b85a97d-37cd5ab744bmr3564813f8f.17.1727513933283; Sat, 28 Sep 2024 01:58:53 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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, Alexander Graf Subject: [PATCH v3 07/14] hw/misc/pvpanic: Add MMIO interface Date: Sat, 28 Sep 2024 10:57:20 +0200 Message-Id: <20240928085727.56883-8-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-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::436; envelope-from=phil@philjordan.eu; helo=mail-wr1-x436.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, 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: 1727513978804116600 From: Alexander Graf In addition to the ISA and PCI variants of pvpanic, let's add an MMIO platform device that we can use in embedded arm environments. Signed-off-by: Alexander Graf Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Phil Dennis-Jordan Reviewed-by: Akihiko Odaki --- v3: * Rebased on upstream, updated a header path =20 hw/misc/Kconfig | 4 +++ hw/misc/meson.build | 1 + hw/misc/pvpanic-mmio.c | 61 +++++++++++++++++++++++++++++++++++++++ include/hw/misc/pvpanic.h | 1 + 4 files changed, 67 insertions(+) create mode 100644 hw/misc/pvpanic-mmio.c diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 1e08785b832..891329971a9 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -143,6 +143,10 @@ config PVPANIC_ISA depends on ISA_BUS select PVPANIC_COMMON =20 +config PVPANIC_MMIO + bool + select PVPANIC_COMMON + config AUX bool select I2C diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 2ca8717be28..19021700192 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -127,6 +127,7 @@ system_ss.add(when: 'CONFIG_ARMSSE_MHU', if_true: files= ('armsse-mhu.c')) =20 system_ss.add(when: 'CONFIG_PVPANIC_ISA', if_true: files('pvpanic-isa.c')) system_ss.add(when: 'CONFIG_PVPANIC_PCI', if_true: files('pvpanic-pci.c')) +system_ss.add(when: 'CONFIG_PVPANIC_MMIO', if_true: files('pvpanic-mmio.c'= )) system_ss.add(when: 'CONFIG_AUX', if_true: files('auxbus.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files( 'aspeed_hace.c', diff --git a/hw/misc/pvpanic-mmio.c b/hw/misc/pvpanic-mmio.c new file mode 100644 index 00000000000..56738efee53 --- /dev/null +++ b/hw/misc/pvpanic-mmio.c @@ -0,0 +1,61 @@ +/* + * QEMU simulated pvpanic device (MMIO frontend) + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" + +#include "hw/qdev-properties.h" +#include "hw/misc/pvpanic.h" +#include "hw/sysbus.h" +#include "standard-headers/misc/pvpanic.h" + +OBJECT_DECLARE_SIMPLE_TYPE(PVPanicMMIOState, PVPANIC_MMIO_DEVICE) + +#define PVPANIC_MMIO_SIZE 0x2 + +struct PVPanicMMIOState { + SysBusDevice parent_obj; + + PVPanicState pvpanic; +}; + +static void pvpanic_mmio_initfn(Object *obj) +{ + PVPanicMMIOState *s =3D PVPANIC_MMIO_DEVICE(obj); + + pvpanic_setup_io(&s->pvpanic, DEVICE(s), PVPANIC_MMIO_SIZE); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->pvpanic.mr); +} + +static Property pvpanic_mmio_properties[] =3D { + DEFINE_PROP_UINT8("events", PVPanicMMIOState, pvpanic.events, + PVPANIC_PANICKED | PVPANIC_CRASH_LOADED), + DEFINE_PROP_END_OF_LIST(), +}; + +static void pvpanic_mmio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + device_class_set_props(dc, pvpanic_mmio_properties); + set_bit(DEVICE_CATEGORY_MISC, dc->categories); +} + +static const TypeInfo pvpanic_mmio_info =3D { + .name =3D TYPE_PVPANIC_MMIO_DEVICE, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(PVPanicMMIOState), + .instance_init =3D pvpanic_mmio_initfn, + .class_init =3D pvpanic_mmio_class_init, +}; + +static void pvpanic_register_types(void) +{ + type_register_static(&pvpanic_mmio_info); +} + +type_init(pvpanic_register_types) diff --git a/include/hw/misc/pvpanic.h b/include/hw/misc/pvpanic.h index 9a71a5ad0d7..049a94c1125 100644 --- a/include/hw/misc/pvpanic.h +++ b/include/hw/misc/pvpanic.h @@ -26,6 +26,7 @@ =20 #define TYPE_PVPANIC_ISA_DEVICE "pvpanic" #define TYPE_PVPANIC_PCI_DEVICE "pvpanic-pci" +#define TYPE_PVPANIC_MMIO_DEVICE "pvpanic-mmio" =20 #define PVPANIC_IOPORT_PROP "ioport" =20 --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727514001; cv=none; d=zohomail.com; s=zohoarc; b=hNhM01Hr0+Ul2N15KB9uiVPYGSZ+Ose2SRs8YGTAjbU+d7N2jC1lu/CqkdegDIlZhFmJWvr9jyXieHlMZNMPFFOqmM63swQqoN+M1Q/VT7vBIBMTcTylLKQSmmOD3RI0oXg9KiPu7KkVq06bIsTch3ryNpBbxjnnznc29d6zq7M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727514001; h=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=jOWzCZU6EONhTxEcdFH/GqPe9aBoTYc8FD382em+uNI=; b=QWNbFw/ZvE3eTHW7JijJmEsW7RygEyc6dBOzrl3H9tuFMa9l77fK7ond8O50oB3d0+HP7PaeL+q/Jk9DE5f6XtMSam2dBuz0HlJePq33aXNgGJrQ7Bdsphok0aSC6SAcB5ytUc5q7Uik24eV1c5odyE1kI/BvJsF0QpN60kKvwQ= 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 1727514001355558.9022675665319; Sat, 28 Sep 2024 02:00:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTI6-0002Fm-HI; Sat, 28 Sep 2024 04:59:02 -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 1suTI4-00026I-S0 for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:01 -0400 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 1suTI3-0002Nc-AG for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:00 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-37ccf0c0376so1623558f8f.3 for ; Sat, 28 Sep 2024 01:58:58 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.58.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513937; x=1728118737; 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=jOWzCZU6EONhTxEcdFH/GqPe9aBoTYc8FD382em+uNI=; b=RtlXr1xj0cNIJGlyP1P731C1zEm8BiTXkxY+W9JpOHw+IMzCfiVzT//oirRPqRCTKy qEktvMHu784cfhkX2rzvpZ+kN6mXSx1hnT7B6awmuS06OW2cvCyi7NhgojiwDQ0Y0loZ HhzC8ex1TJGYjcYzJjc3a3D67Jwsgs9Z10WwbCzmvnRYtpo7nSzY3GOBgYvBwQVNLQtJ iyk0PpRXymSf2/jRk5qiAn0rTTK9mVX1TVqPcyszDF952BcaLMHWCfQob/CJVYcvkA6A rdwLNMvGzkB/DeP3oQlPXPYatqMF3tqKoRKAD4BSlkZ6ROIzxs+3R+7A74+WtVg10dpc kF+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513937; x=1728118737; 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=jOWzCZU6EONhTxEcdFH/GqPe9aBoTYc8FD382em+uNI=; b=pAeVRSHwa/Q5C46kWLkj8CCH5fcYVig8Bl5Be5LCiVqu1EqFFymvCGODdS2LrJmR+E soC3CiQEI7VKs38w0ohQcCdnjM2X1hIQOKluzrP/nr2w1Nrp88KcZbYBxw0ykLiqA6jP tCYgWcoJ+nAuTR/stnhVRLGC9CKwd+Lt4sve3QFCX209XqinLUG/PD7uNulI+B64QaD2 9sdaApScFvtyOZMP+VWm+Rk7Ok3z4Fod1EYyoZien/zr4s+uULkV8kLCPh7POk7OCjLc i5JpV9b9bVIwmnqdmcmpB0aunukbm6SxO/zPeHhgypZ2B7C18tHACeO72HIH9C17XD7I o7mQ== X-Gm-Message-State: AOJu0Yx3Vz0tYKsPRYz5HDSVORKiT4c4m0vIqQqkL7OkOL320Ln/7hhH 6tzE/DLCUAN6idlSwqAqsSKHDlAfV+VROWQzaG6SDLiW3LI1SOrEKe5DFTNZUvobD4jCqWyTjhL Lqg== X-Google-Smtp-Source: AGHT+IFdJhZkpTqSEsQyt6nAzQa71DaG9Yi1zGT/J/DoVgoZHV7t37V+ZXSl+fuZAWzHQVO8tpg4uA== X-Received: by 2002:adf:a2de:0:b0:37c:cd71:2b96 with SMTP id ffacd0b85a97d-37cd5ae07a7mr3333315f8f.36.1727513937248; Sat, 28 Sep 2024 01:58:57 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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, Alexander Graf Subject: [PATCH v3 08/14] hvf: arm: Ignore writes to CNTP_CTL_EL0 Date: Sat, 28 Sep 2024 10:57:21 +0200 Message-Id: <20240928085727.56883-9-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-1-phil@philjordan.eu> MIME-Version: 1.0 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::42b; envelope-from=phil@philjordan.eu; helo=mail-wr1-x42b.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, 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: 1727514002287116600 Content-Type: text/plain; charset="utf-8" From: Alexander Graf MacOS unconditionally disables interrupts of the physical timer on boot and then continues to use the virtual one. We don't really want to support a full physical timer emulation, so let's just ignore those writes. Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan Reviewed-by: Akihiko Odaki --- target/arm/hvf/hvf.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index 6cea483d422..b45b764dfd0 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -11,6 +11,7 @@ =20 #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/log.h" =20 #include "sysemu/runstate.h" #include "sysemu/hvf.h" @@ -184,6 +185,7 @@ void hvf_arm_init_debug(void) #define SYSREG_OSLSR_EL1 SYSREG(2, 0, 1, 1, 4) #define SYSREG_OSDLR_EL1 SYSREG(2, 0, 1, 3, 4) #define SYSREG_CNTPCT_EL0 SYSREG(3, 3, 14, 0, 1) +#define SYSREG_CNTP_CTL_EL0 SYSREG(3, 3, 14, 2, 1) #define SYSREG_PMCR_EL0 SYSREG(3, 3, 9, 12, 0) #define SYSREG_PMUSERENR_EL0 SYSREG(3, 3, 9, 14, 0) #define SYSREG_PMCNTENSET_EL0 SYSREG(3, 3, 9, 12, 1) @@ -1620,6 +1622,13 @@ static int hvf_sysreg_write(CPUState *cpu, uint32_t = reg, uint64_t val) case SYSREG_OSLAR_EL1: env->cp15.oslsr_el1 =3D val & 1; return 0; + case SYSREG_CNTP_CTL_EL0: + /* + * Guests should not rely on the physical counter, but macOS emits + * disable writes to it. Let it do so, but ignore the requests. + */ + qemu_log_mask(LOG_UNIMP, "Unsupported write to CNTP_CTL_EL0\n"); + return 0; case SYSREG_OSDLR_EL1: /* Dummy register */ return 0; --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727514001; cv=none; d=zohomail.com; s=zohoarc; b=OsIZ0EiRVlbM05Gl/jus4RgTdKwMmSgSz0gK0W1woPAi4FWJHsGzyLGcz77bwt4yubREe2bqP9iNkvgZ/uBdQLyEgkMdE3btRlE4zR+wkn3vkP6XsV+rilmWtSRNkhqyLWw1IwNdS9Vje0uf660/0wfVDzZhC+bdKfgYb/qojig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727514001; h=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=/3sRAewHWXRo7xdE4kIcknrBxkaI+lx1xuZP5wYmCiQ=; b=FKJ6hp+W/eUn6ZzvCug/3olk1qdpmsiF/Z8WROAfm6JWuOTGRug57tUhaJV7NZAPgLsIgoBG+4Fr7cdfA6rMBZNzQ9OEHUnwiiOlSMA+qBt2xEVHwIJl13XIkWV2HxjdCASatq7VIe1hLqnydjnsVJxGu2GZOtMeFwYutTB2lFs= 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 1727514001484321.1748703266654; Sat, 28 Sep 2024 02:00:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTIG-0002oq-S6; Sat, 28 Sep 2024 04:59:12 -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 1suTIB-0002jw-Qm for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:07 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTI9-0002Oc-JT for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:07 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-42e5e758093so24058725e9.1 for ; Sat, 28 Sep 2024 01:59:05 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.58.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513944; x=1728118744; 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=/3sRAewHWXRo7xdE4kIcknrBxkaI+lx1xuZP5wYmCiQ=; b=s3Wgk6b552Pg5GOonyMAvCZ2J7L1Hq6ehzq9CwdAyRKTFnCE/geElkdVU0x+Zs9kk1 gss+W6mQbYgCMNXWvWL73r8gO6iw4m+O4Ahf3tkqxpygtVu/mXeXb4ZYmEWPs15O7pjK GQ9DYc9ksRB1nuimCPu0OBT506Yd6L6tnoiGAXLRXFlOc15G75b99gLNquFX6I8hg//Q qcdmNE1sc2B0TYLIwo3hO7qoQNYWn8X89+wAfzKzJMLjFeOxU5Zh44CnXOvOSfBAErVd DxXAfa6NMES9YdZOyIeE9oNxanydotHRofsAl3ufOuVA+baWx6R/KVoe3dgfbkRi/4p1 dslQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513944; x=1728118744; 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=/3sRAewHWXRo7xdE4kIcknrBxkaI+lx1xuZP5wYmCiQ=; b=SUylgCJh+mpqZx1d5QtfvBpjCF7kuyRat01MPlVmabG26BUNWHEhwv68QOXOPOiNCH zjmUN22hdVWR4gf4cNuLQQBIM2QEYrmGMOLSJzoVg+1Uwo/BSUBgix+DptYhCuS5WP5p sIfTxyzXqOqfIAQSdYoYvajo9rKjkTHgx4Tg3t+vPUndkj5+H5wyEgcn0MleHuUXNOtn iWpjv1XNTlUiQ55OGP3n7vseRWoLr9dG4fFhxeujAaJilfQjtDABbp+w39wnS8uFTBwA UKzAUXSoNBzIjCrP3ehgpVWkSggCsdcwg9MGSGj3j5Fcw24TebjjAT2yQ8rg4bd2OmFg A1LQ== X-Gm-Message-State: AOJu0Yz84IKw8d971pfB0X+TPbmdm9casFYd9cGcCaUtAEPCneHkhL1Q wV7veXlQOTRYbx+tvrxDQBO0TgtUKXcRf0EcifB+WLvHpx/spLU72kyAVeQOkiVNbP+Iw0JR/RY MHg== X-Google-Smtp-Source: AGHT+IFNu5YhCNaO6uKXoi2X5QerL1AS4TrSmnFpAAD17ZL+9kcE24QJFsHWz8NeJLAok2nWhAtmow== X-Received: by 2002:a05:600c:4f10:b0:42c:baf9:beed with SMTP id 5b1f17b1804b1-42f5848552bmr36860395e9.27.1727513944132; Sat, 28 Sep 2024 01:59:04 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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, Alexander Graf Subject: [PATCH v3 09/14] gpex: Allow more than 4 legacy IRQs Date: Sat, 28 Sep 2024 10:57:22 +0200 Message-Id: <20240928085727.56883-10-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-1-phil@philjordan.eu> MIME-Version: 1.0 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::335; envelope-from=phil@philjordan.eu; helo=mail-wm1-x335.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, 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: 1727514002259116600 Content-Type: text/plain; charset="utf-8" From: Alexander Graf Some boards such as vmapple don't do real legacy PCI IRQ swizzling. Instead, they just keep allocating more board IRQ lines for each new legacy IRQ. Let's support that mode by giving instantiators a new "nr_irqs" property they can use to support more than 4 legacy IRQ lines. In this mode, GPEX will export more IRQ lines, one for each device. Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan --- hw/arm/sbsa-ref.c | 2 +- hw/arm/virt.c | 2 +- hw/i386/microvm.c | 2 +- hw/loongarch/virt.c | 2 +- hw/mips/loongson3_virt.c | 2 +- hw/openrisc/virt.c | 12 ++++++------ hw/pci-host/gpex.c | 36 +++++++++++++++++++++++++++++++----- hw/riscv/virt.c | 12 ++++++------ hw/xtensa/virt.c | 2 +- include/hw/pci-host/gpex.h | 7 +++---- 10 files changed, 52 insertions(+), 27 deletions(-) diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c index e3195d54497..7e7322486c2 100644 --- a/hw/arm/sbsa-ref.c +++ b/hw/arm/sbsa-ref.c @@ -673,7 +673,7 @@ static void create_pcie(SBSAMachineState *sms) /* Map IO port space */ sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, base_pio); =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, qdev_get_gpio_in(sms->gic, irq + i)); gpex_set_irq_num(GPEX_HOST(dev), i, irq + i); diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 8b2b991d978..bd3b17be2ea 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1547,7 +1547,7 @@ static void create_pcie(VirtMachineState *vms) /* Map IO port space */ sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, base_pio); =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, qdev_get_gpio_in(vms->gic, irq + i)); gpex_set_irq_num(GPEX_HOST(dev), i, irq + i); diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index 40edcee7af2..216a169c413 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -139,7 +139,7 @@ static void create_gpex(MicrovmMachineState *mms) mms->gpex.mmio64.base, mmio64_alias); } =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, x86ms->gsi[mms->gpex.irq + i]); } diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index 75980b6e3c7..8eb7277a8d1 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -703,7 +703,7 @@ static void virt_devices_init(DeviceState *pch_pic, memory_region_add_subregion(get_system_memory(), VIRT_PCI_IO_BASE, pio_alias); =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { sysbus_connect_irq(d, i, qdev_get_gpio_in(pch_pic, 16 + i)); gpex_set_irq_num(GPEX_HOST(gpex_dev), i, 16 + i); diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c index 2067b4fecb5..acafd73129d 100644 --- a/hw/mips/loongson3_virt.c +++ b/hw/mips/loongson3_virt.c @@ -458,7 +458,7 @@ static inline void loongson3_virt_devices_init(MachineS= tate *machine, virt_memmap[VIRT_PCIE_PIO].base, s->pio_al= ias); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, virt_memmap[VIRT_PCIE_PIO].bas= e); =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { irq =3D qdev_get_gpio_in(pic, PCIE_IRQ_BASE + i); sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); gpex_set_irq_num(GPEX_HOST(dev), i, PCIE_IRQ_BASE + i); diff --git a/hw/openrisc/virt.c b/hw/openrisc/virt.c index f8a68a6a6b1..16a5676c4bb 100644 --- a/hw/openrisc/virt.c +++ b/hw/openrisc/virt.c @@ -318,7 +318,7 @@ static void create_pcie_irq_map(void *fdt, char *nodena= me, int irq_base, { int pin, dev; uint32_t irq_map_stride =3D 0; - uint32_t full_irq_map[GPEX_NUM_IRQS * GPEX_NUM_IRQS * 6] =3D {}; + uint32_t full_irq_map[PCI_NUM_PINS * PCI_NUM_PINS * 6] =3D {}; uint32_t *irq_map =3D full_irq_map; =20 /* @@ -330,11 +330,11 @@ static void create_pcie_irq_map(void *fdt, char *node= name, int irq_base, * possible slot) seeing the interrupt-map-mask will allow the table * to wrap to any number of devices. */ - for (dev =3D 0; dev < GPEX_NUM_IRQS; dev++) { + for (dev =3D 0; dev < PCI_NUM_PINS; dev++) { int devfn =3D dev << 3; =20 - for (pin =3D 0; pin < GPEX_NUM_IRQS; pin++) { - int irq_nr =3D irq_base + ((pin + PCI_SLOT(devfn)) % GPEX_NUM_= IRQS); + for (pin =3D 0; pin < PCI_NUM_PINS; pin++) { + int irq_nr =3D irq_base + ((pin + PCI_SLOT(devfn)) % PCI_NUM_P= INS); int i =3D 0; =20 /* Fill PCI address cells */ @@ -357,7 +357,7 @@ static void create_pcie_irq_map(void *fdt, char *nodena= me, int irq_base, } =20 qemu_fdt_setprop(fdt, nodename, "interrupt-map", full_irq_map, - GPEX_NUM_IRQS * GPEX_NUM_IRQS * + PCI_NUM_PINS * PCI_NUM_PINS * irq_map_stride * sizeof(uint32_t)); =20 qemu_fdt_setprop_cells(fdt, nodename, "interrupt-map-mask", @@ -409,7 +409,7 @@ static void openrisc_virt_pcie_init(OR1KVirtState *stat= e, memory_region_add_subregion(get_system_memory(), pio_base, alias); =20 /* Connect IRQ lines. */ - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { pcie_irq =3D get_per_cpu_irq(cpus, num_cpus, irq_base + i); =20 sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, pcie_irq); diff --git a/hw/pci-host/gpex.c b/hw/pci-host/gpex.c index e9cf455bf52..4aca0a95771 100644 --- a/hw/pci-host/gpex.c +++ b/hw/pci-host/gpex.c @@ -32,6 +32,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "hw/irq.h" +#include "hw/pci/pci_bus.h" #include "hw/pci-host/gpex.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" @@ -50,7 +51,7 @@ static void gpex_set_irq(void *opaque, int irq_num, int l= evel) =20 int gpex_set_irq_num(GPEXHost *s, int index, int gsi) { - if (index >=3D GPEX_NUM_IRQS) { + if (index >=3D s->nr_irqs) { return -EINVAL; } =20 @@ -74,14 +75,29 @@ static PCIINTxRoute gpex_route_intx_pin_to_irq(void *op= aque, int pin) return route; } =20 +static int gpex_swizzle_map_irq_fn(PCIDevice *pci_dev, int pin) +{ + PCIBus *bus =3D pci_device_root_bus(pci_dev); + + return (PCI_SLOT(pci_dev->devfn) + pin) % bus->nirq; +} + static void gpex_host_realize(DeviceState *dev, Error **errp) { PCIHostState *pci =3D PCI_HOST_BRIDGE(dev); GPEXHost *s =3D GPEX_HOST(dev); SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); PCIExpressHost *pex =3D PCIE_HOST_BRIDGE(dev); + pci_map_irq_fn map_irq_fn =3D pci_swizzle_map_irq_fn; int i; =20 + s->irq =3D g_malloc0(s->nr_irqs * sizeof(*s->irq)); + s->irq_num =3D g_malloc0(s->nr_irqs * sizeof(*s->irq_num)); + + if (s->nr_irqs !=3D PCI_NUM_PINS) { + map_irq_fn =3D gpex_swizzle_map_irq_fn; + } + pcie_host_mmcfg_init(pex, PCIE_MMCFG_SIZE_MAX); sysbus_init_mmio(sbd, &pex->mmio); =20 @@ -128,19 +144,27 @@ static void gpex_host_realize(DeviceState *dev, Error= **errp) sysbus_init_mmio(sbd, &s->io_ioport); } =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < s->nr_irqs; i++) { sysbus_init_irq(sbd, &s->irq[i]); s->irq_num[i] =3D -1; } =20 - pci->bus =3D pci_register_root_bus(dev, "pcie.0", gpex_set_irq, - pci_swizzle_map_irq_fn, s, &s->io_mmi= o, - &s->io_ioport, 0, 4, TYPE_PCIE_BUS); + pci->bus =3D pci_register_root_bus(dev, "pcie.0", gpex_set_irq, map_ir= q_fn, + s, &s->io_mmio, &s->io_ioport, 0, + s->nr_irqs, TYPE_PCIE_BUS); =20 pci_bus_set_route_irq_fn(pci->bus, gpex_route_intx_pin_to_irq); qdev_realize(DEVICE(&s->gpex_root), BUS(pci->bus), &error_fatal); } =20 +static void gpex_host_unrealize(DeviceState *dev) +{ + GPEXHost *s =3D GPEX_HOST(dev); + + g_free(s->irq); + g_free(s->irq_num); +} + static const char *gpex_host_root_bus_path(PCIHostState *host_bridge, PCIBus *rootbus) { @@ -166,6 +190,7 @@ static Property gpex_host_properties[] =3D { gpex_cfg.mmio64.base, 0), DEFINE_PROP_SIZE(PCI_HOST_ABOVE_4G_MMIO_SIZE, GPEXHost, gpex_cfg.mmio64.size, 0), + DEFINE_PROP_UINT32("nr-irqs", GPEXHost, nr_irqs, PCI_NUM_PINS), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -176,6 +201,7 @@ static void gpex_host_class_init(ObjectClass *klass, vo= id *data) =20 hc->root_bus_path =3D gpex_host_root_bus_path; dc->realize =3D gpex_host_realize; + dc->unrealize =3D gpex_host_unrealize; set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); dc->fw_name =3D "pci"; device_class_set_props(dc, gpex_host_properties); diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index cef41c150aa..6c3ed4b3d9c 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -167,7 +167,7 @@ static void create_pcie_irq_map(RISCVVirtState *s, void= *fdt, char *nodename, { int pin, dev; uint32_t irq_map_stride =3D 0; - uint32_t full_irq_map[GPEX_NUM_IRQS * GPEX_NUM_IRQS * + uint32_t full_irq_map[PCI_NUM_PINS * PCI_NUM_PINS * FDT_MAX_INT_MAP_WIDTH] =3D {}; uint32_t *irq_map =3D full_irq_map; =20 @@ -179,11 +179,11 @@ static void create_pcie_irq_map(RISCVVirtState *s, vo= id *fdt, char *nodename, * possible slot) seeing the interrupt-map-mask will allow the table * to wrap to any number of devices. */ - for (dev =3D 0; dev < GPEX_NUM_IRQS; dev++) { + for (dev =3D 0; dev < PCI_NUM_PINS; dev++) { int devfn =3D dev * 0x8; =20 - for (pin =3D 0; pin < GPEX_NUM_IRQS; pin++) { - int irq_nr =3D PCIE_IRQ + ((pin + PCI_SLOT(devfn)) % GPEX_NUM_= IRQS); + for (pin =3D 0; pin < PCI_NUM_PINS; pin++) { + int irq_nr =3D PCIE_IRQ + ((pin + PCI_SLOT(devfn)) % PCI_NUM_P= INS); int i =3D 0; =20 /* Fill PCI address cells */ @@ -209,7 +209,7 @@ static void create_pcie_irq_map(RISCVVirtState *s, void= *fdt, char *nodename, } =20 qemu_fdt_setprop(fdt, nodename, "interrupt-map", full_irq_map, - GPEX_NUM_IRQS * GPEX_NUM_IRQS * + PCI_NUM_PINS * PCI_NUM_PINS * irq_map_stride * sizeof(uint32_t)); =20 qemu_fdt_setprop_cells(fdt, nodename, "interrupt-map-mask", @@ -1157,7 +1157,7 @@ static inline DeviceState *gpex_pcie_init(MemoryRegio= n *sys_mem, =20 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, pio_base); =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { irq =3D qdev_get_gpio_in(irqchip, PCIE_IRQ + i); =20 sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); diff --git a/hw/xtensa/virt.c b/hw/xtensa/virt.c index 5310a888613..8f5c2009d29 100644 --- a/hw/xtensa/virt.c +++ b/hw/xtensa/virt.c @@ -93,7 +93,7 @@ static void create_pcie(MachineState *ms, CPUXtensaState = *env, int irq_base, /* Connect IRQ lines. */ extints =3D xtensa_get_extints(env); =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { void *q =3D extints[irq_base + i]; =20 sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, q); diff --git a/include/hw/pci-host/gpex.h b/include/hw/pci-host/gpex.h index dce883573ba..8f87a3872cb 100644 --- a/include/hw/pci-host/gpex.h +++ b/include/hw/pci-host/gpex.h @@ -32,8 +32,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(GPEXHost, GPEX_HOST) #define TYPE_GPEX_ROOT_DEVICE "gpex-root" OBJECT_DECLARE_SIMPLE_TYPE(GPEXRootState, GPEX_ROOT_DEVICE) =20 -#define GPEX_NUM_IRQS 4 - struct GPEXRootState { /*< private >*/ PCIDevice parent_obj; @@ -60,8 +58,9 @@ struct GPEXHost { MemoryRegion io_mmio; MemoryRegion io_ioport_window; MemoryRegion io_mmio_window; - qemu_irq irq[GPEX_NUM_IRQS]; - int irq_num[GPEX_NUM_IRQS]; + uint32_t nr_irqs; + qemu_irq *irq; + int *irq_num; =20 bool allow_unmapped_accesses; =20 --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727514038; cv=none; d=zohomail.com; s=zohoarc; b=Z7cl5Vuhf9bmm4gSqe34Ig9/yDoQXXsrh74eRWCwWk5MYS9VpSMiij1ft6IluC1nSdwqLKiJ7nIGwPUfF/8VAysf15jQBSSUf3fJfoC/bw0E7unx2xyVJjpAneXc2tAR3BAAnMHahnP0HWB/LGvBbPsgdvzOUsUSRP2j2MgapOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727514038; 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=s5GE78W+mN6uEIVTw8QGR5xCCkDAxEmOwTVSHyseW6I=; b=ILwpI3oQbAJh2oIdKqL/mBYpWEJXLpOrssTDjzp1tulz7l1oPOq4as1Oie5RJQ+ijgBRPLaYNO1rzZptx/yXOmcfrWQWYazE2vDlRo2+ANa9fweXV68hGkD1/JaSPeauLOaSbPlHuFe5+XGnEBrr9UcfWDRMyno3q+M9mplIXSQ= 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 1727514038189114.46620007499519; Sat, 28 Sep 2024 02:00:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTIL-0003Xi-UC; Sat, 28 Sep 2024 04:59:17 -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 1suTIJ-0003K0-Pt for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:15 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTIG-0002Pm-6H for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:14 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-42cb806623eso23298055e9.2 for ; Sat, 28 Sep 2024 01:59:11 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.59.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513951; x=1728118751; 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=s5GE78W+mN6uEIVTw8QGR5xCCkDAxEmOwTVSHyseW6I=; b=ORWH0Po2EE+G15v3KJHCF24IcGH5YIw//Fx/8TT50iVptOkZRfNjIvk6d3hwAroe8k 4BMML7gY0hEjEEBOqum3sAR4mt9RnpOQsm7YlWPN601iXymKZwELBlEw4At0qxzcx06n YFiEm4nDlmwOj6NVoQAJ2mDtmj93lGMYJ8UyCpuDrVdcMvDZ9ZKxD30uRChWTjYUaq9e Q/pxgbszaxDgOseodHH7T/Sn6HjghAeR700PUhJ/ZuucdqNulioqBuMCLB3k3A3poUPH bugn4+gKSwHG9Un5nmR1cghKcC4HiO9d9ajlypJP59DdKjlJr6k0fRPBwHWdoDY+NWcu zH2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513951; x=1728118751; 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=s5GE78W+mN6uEIVTw8QGR5xCCkDAxEmOwTVSHyseW6I=; b=YS9VG4Tbq3Zj00ZnF7fkhSSjxk4SLjL5chituvDLNN+1+MnSUulvlRv20GnCF15c3J PTbpS/7xTAa1k7Z01Wp4eN+zemduLZ02oQubWnl5ZHGZoMZ8Y+cXbfzPMno/oIpDNUsl wnfN4g6XleOglsQjJTLN/3x0TIEB8egwFo3B3uDyMxp5GneAky+WbYUiC343MEqV0H2f DIrlzmnmvpOIV1GnDma6RD673lJLDbv/bwfxfsx9PIDr7AXKhEYXP2eC8udrj1CDM3M8 iclaCRHLPjOOWalPqXfXzcCVcEFaXa0OVqZuNpdzFyQ3xA3/zm6Z9ZxWUmIjjqWHuiq0 f9Ow== X-Gm-Message-State: AOJu0Yw9oOELGMtkFNjljOUfJR4WOTEukRviezntSU0/qc5aejrdme4h PLLLL/YTcnPWNpv2U2/tGkToycgwUQr/XNL1fD7LQTjbFGzCDt+RCO1wQY8j58xuJwMJvLuwd1c YKg== X-Google-Smtp-Source: AGHT+IHA2izUfuhANExjGzzXRisS58eiLsaJoV1z6wlIRHSNVDI479qZfPjEtGjXAgK+/FcKS0nW9Q== X-Received: by 2002:a05:600c:cc8:b0:428:1965:450d with SMTP id 5b1f17b1804b1-42f58439cdcmr41480265e9.17.1727513950654; Sat, 28 Sep 2024 01:59:10 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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, Alexander Graf Subject: [PATCH v3 10/14] hw/vmapple/aes: Introduce aes engine Date: Sat, 28 Sep 2024 10:57:23 +0200 Message-Id: <20240928085727.56883-11-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-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::32b; envelope-from=phil@philjordan.eu; helo=mail-wm1-x32b.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, 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: 1727514041967116600 From: Alexander Graf VMApple contains an "aes" engine device that it uses to encrypt and decrypt its nvram. It has trivial hard coded keys it uses for that purpose. Add device emulation for this device model. Signed-off-by: Alexander Graf Co-authored-by: Phil Dennis-Jordan=C2=A0 Signed-off-by: Phil Dennis-Jordan --- v3: * Rebased on latest upstream and fixed minor breakages. * Replaced legacy device reset method with Resettable method hw/vmapple/Kconfig | 2 + hw/vmapple/aes.c | 584 ++++++++++++++++++++++++++++++++++++++++ hw/vmapple/meson.build | 1 + hw/vmapple/trace-events | 19 ++ 4 files changed, 606 insertions(+) create mode 100644 hw/vmapple/aes.c diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig index 8b137891791..a73504d5999 100644 --- a/hw/vmapple/Kconfig +++ b/hw/vmapple/Kconfig @@ -1 +1,3 @@ +config VMAPPLE_AES + bool =20 diff --git a/hw/vmapple/aes.c b/hw/vmapple/aes.c new file mode 100644 index 00000000000..074fbdd9c36 --- /dev/null +++ b/hw/vmapple/aes.c @@ -0,0 +1,584 @@ +/* + * QEMU Apple AES device emulation + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * 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/irq.h" +#include "migration/vmstate.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "trace.h" +#include "hw/sysbus.h" +#include "crypto/hash.h" +#include "crypto/aes.h" +#include "crypto/cipher.h" + +#define TYPE_AES "apple-aes" +#define MAX_FIFO_SIZE 9 + +#define CMD_KEY 0x1 +#define CMD_KEY_CONTEXT_SHIFT 27 +#define CMD_KEY_CONTEXT_MASK (0x1 << CMD_KEY_CONTEXT_SHIFT) +#define CMD_KEY_SELECT_SHIFT 24 +#define CMD_KEY_SELECT_MASK (0x7 << CMD_KEY_SELECT_SHIFT) +#define CMD_KEY_KEY_LEN_SHIFT 22 +#define CMD_KEY_KEY_LEN_MASK (0x3 << CMD_KEY_KEY_LEN_SHIFT) +#define CMD_KEY_ENCRYPT_SHIFT 20 +#define CMD_KEY_ENCRYPT_MASK (0x1 << CMD_KEY_ENCRYPT_SHIFT) +#define CMD_KEY_BLOCK_MODE_SHIFT 16 +#define CMD_KEY_BLOCK_MODE_MASK (0x3 << CMD_KEY_BLOCK_MODE_SHIFT) +#define CMD_IV 0x2 +#define CMD_IV_CONTEXT_SHIFT 26 +#define CMD_IV_CONTEXT_MASK (0x3 << CMD_KEY_CONTEXT_SHIFT) +#define CMD_DSB 0x3 +#define CMD_SKG 0x4 +#define CMD_DATA 0x5 +#define CMD_DATA_KEY_CTX_SHIFT 27 +#define CMD_DATA_KEY_CTX_MASK (0x1 << CMD_DATA_KEY_CTX_SHIFT) +#define CMD_DATA_IV_CTX_SHIFT 25 +#define CMD_DATA_IV_CTX_MASK (0x3 << CMD_DATA_IV_CTX_SHIFT) +#define CMD_DATA_LEN_MASK 0xffffff +#define CMD_STORE_IV 0x6 +#define CMD_STORE_IV_ADDR_MASK 0xffffff +#define CMD_WRITE_REG 0x7 +#define CMD_FLAG 0x8 +#define CMD_FLAG_STOP_MASK BIT(26) +#define CMD_FLAG_RAISE_IRQ_MASK BIT(27) +#define CMD_FLAG_INFO_MASK 0xff +#define CMD_MAX 0x10 + +#define CMD_SHIFT 28 + +#define REG_STATUS 0xc +#define REG_STATUS_DMA_READ_RUNNING BIT(0) +#define REG_STATUS_DMA_READ_PENDING BIT(1) +#define REG_STATUS_DMA_WRITE_RUNNING BIT(2) +#define REG_STATUS_DMA_WRITE_PENDING BIT(3) +#define REG_STATUS_BUSY BIT(4) +#define REG_STATUS_EXECUTING BIT(5) +#define REG_STATUS_READY BIT(6) +#define REG_STATUS_TEXT_DPA_SEEDED BIT(7) +#define REG_STATUS_UNWRAP_DPA_SEEDED BIT(8) + +#define REG_IRQ_STATUS 0x18 +#define REG_IRQ_STATUS_INVALID_CMD BIT(2) +#define REG_IRQ_STATUS_FLAG BIT(5) +#define REG_IRQ_ENABLE 0x1c +#define REG_WATERMARK 0x20 +#define REG_Q_STATUS 0x24 +#define REG_FLAG_INFO 0x30 +#define REG_FIFO 0x200 + +static const uint32_t key_lens[4] =3D { + [0] =3D 16, + [1] =3D 24, + [2] =3D 32, + [3] =3D 64, +}; + +struct key { + uint32_t key_len; + uint32_t key[8]; +}; + +struct iv { + uint32_t iv[4]; +}; + +struct context { + struct key key; + struct iv iv; +}; + +static struct key builtin_keys[7] =3D { + [1] =3D { + .key_len =3D 32, + .key =3D { 0x1 }, + }, + [2] =3D { + .key_len =3D 32, + .key =3D { 0x2 }, + }, + [3] =3D { + .key_len =3D 32, + .key =3D { 0x3 }, + } +}; + +typedef struct AESState { + /* Private */ + SysBusDevice parent_obj; + + /* Public */ + qemu_irq irq; + MemoryRegion iomem1; + MemoryRegion iomem2; + + uint32_t status; + uint32_t q_status; + uint32_t irq_status; + uint32_t irq_enable; + uint32_t watermark; + uint32_t flag_info; + uint32_t fifo[MAX_FIFO_SIZE]; + uint32_t fifo_idx; + struct key key[2]; + struct iv iv[4]; + bool is_encrypt; + QCryptoCipherMode block_mode; +} AESState; + +OBJECT_DECLARE_SIMPLE_TYPE(AESState, AES) + +static void aes_update_irq(AESState *s) +{ + qemu_set_irq(s->irq, !!(s->irq_status & s->irq_enable)); +} + +static uint64_t aes1_read(void *opaque, hwaddr offset, unsigned size) +{ + AESState *s =3D opaque; + uint64_t res =3D 0; + + switch (offset) { + case REG_STATUS: + res =3D s->status; + break; + case REG_IRQ_STATUS: + res =3D s->irq_status; + break; + case REG_IRQ_ENABLE: + res =3D s->irq_enable; + break; + case REG_WATERMARK: + res =3D s->watermark; + break; + case REG_Q_STATUS: + res =3D s->q_status; + break; + case REG_FLAG_INFO: + res =3D s->flag_info; + break; + + default: + trace_aes_read_unknown(offset); + break; + } + + trace_aes_read(offset, res); + + return res; +} + +static void fifo_append(AESState *s, uint64_t val) +{ + if (s->fifo_idx =3D=3D MAX_FIFO_SIZE) { + /* Exceeded the FIFO. Bail out */ + return; + } + + s->fifo[s->fifo_idx++] =3D val; +} + +static bool has_payload(AESState *s, uint32_t elems) +{ + return s->fifo_idx >=3D (elems + 1); +} + +static bool cmd_key(AESState *s) +{ + uint32_t cmd =3D s->fifo[0]; + uint32_t key_select =3D (cmd & CMD_KEY_SELECT_MASK) >> CMD_KEY_SELECT_= SHIFT; + uint32_t ctxt =3D (cmd & CMD_KEY_CONTEXT_MASK) >> CMD_KEY_CONTEXT_SHIF= T; + uint32_t key_len; + + switch ((cmd & CMD_KEY_BLOCK_MODE_MASK) >> CMD_KEY_BLOCK_MODE_SHIFT) { + case 0: + s->block_mode =3D QCRYPTO_CIPHER_MODE_ECB; + break; + case 1: + s->block_mode =3D QCRYPTO_CIPHER_MODE_CBC; + break; + default: + return false; + } + + s->is_encrypt =3D !!((cmd & CMD_KEY_ENCRYPT_MASK) >> CMD_KEY_ENCRYPT_S= HIFT); + key_len =3D key_lens[((cmd & CMD_KEY_KEY_LEN_MASK) >> CMD_KEY_KEY_LEN_= SHIFT)]; + + if (key_select) { + trace_aes_cmd_key_select_builtin(ctxt, key_select, + s->is_encrypt ? "en" : "de", + QCryptoCipherMode_str(s->block_mo= de)); + s->key[ctxt] =3D builtin_keys[key_select]; + } else { + trace_aes_cmd_key_select_new(ctxt, key_len, + s->is_encrypt ? "en" : "de", + QCryptoCipherMode_str(s->block_mode)); + if (key_len > sizeof(s->key[ctxt].key)) { + return false; + } + if (!has_payload(s, key_len / sizeof(uint32_t))) { + /* wait for payload */ + return false; + } + memcpy(&s->key[ctxt].key, &s->fifo[1], key_len); + s->key[ctxt].key_len =3D key_len; + } + + return true; +} + +static bool cmd_iv(AESState *s) +{ + uint32_t cmd =3D s->fifo[0]; + uint32_t ctxt =3D (cmd & CMD_IV_CONTEXT_MASK) >> CMD_IV_CONTEXT_SHIFT; + + if (!has_payload(s, 4)) { + /* wait for payload */ + return false; + } + memcpy(&s->iv[ctxt].iv, &s->fifo[1], sizeof(s->iv[ctxt].iv)); + trace_aes_cmd_iv(ctxt, s->fifo[1], s->fifo[2], s->fifo[3], s->fifo[4]); + + return true; +} + +static char hexdigit2str(uint8_t val) +{ + g_assert(val < 0x10); + if (val >=3D 0xa) { + return 'a' + (val - 0xa); + } else { + return '0' + val; + } +} + +static void dump_data(const char *desc, const void *p, size_t len) +{ + char *hex =3D alloca((len * 2) + 1); + const uint8_t *data =3D p; + char *hexp =3D hex; + size_t i; + + if (len > 0x1000) { + /* Too large buffer, let's bail out */ + return; + } + + for (i =3D 0; i < len; i++) { + uint8_t val =3D data[i]; + *(hexp++) =3D hexdigit2str(val >> 4); + *(hexp++) =3D hexdigit2str(val & 0xf); + } + *hexp =3D '\0'; + + trace_aes_dump_data(desc, hex); +} + +static bool cmd_data(AESState *s) +{ + uint32_t cmd =3D s->fifo[0]; + uint32_t ctxt_iv =3D 0; + uint32_t ctxt_key =3D (cmd & CMD_DATA_KEY_CTX_MASK) >> CMD_DATA_KEY_CT= X_SHIFT; + uint32_t len =3D cmd & CMD_DATA_LEN_MASK; + uint64_t src_addr =3D s->fifo[2]; + uint64_t dst_addr =3D s->fifo[3]; + QCryptoCipherAlgo alg; + QCryptoCipher *cipher; + char *src; + char *dst; + + src_addr |=3D ((uint64_t)s->fifo[1] << 16) & 0xffff00000000ULL; + dst_addr |=3D ((uint64_t)s->fifo[1] << 32) & 0xffff00000000ULL; + + trace_aes_cmd_data(ctxt_key, ctxt_iv, src_addr, dst_addr, len); + + if (!has_payload(s, 3)) { + /* wait for payload */ + trace_aes_cmd_data_error("No payload"); + return false; + } + + if (ctxt_key >=3D ARRAY_SIZE(s->key) || + ctxt_iv >=3D ARRAY_SIZE(s->iv)) { + /* Invalid input */ + trace_aes_cmd_data_error("Invalid key or iv"); + return false; + } + + src =3D g_malloc0(len); + dst =3D g_malloc0(len); + + cpu_physical_memory_read(src_addr, src, len); + + dump_data("cmd_data(): src_data=3D", src, len); + + switch (s->key[ctxt_key].key_len) { + case 128 / 8: + alg =3D QCRYPTO_CIPHER_ALGO_AES_128; + break; + case 192 / 8: + alg =3D QCRYPTO_CIPHER_ALGO_AES_192; + break; + case 256 / 8: + alg =3D QCRYPTO_CIPHER_ALGO_AES_256; + break; + default: + trace_aes_cmd_data_error("Invalid key len"); + goto err_free; + } + cipher =3D qcrypto_cipher_new(alg, s->block_mode, + (void *)s->key[ctxt_key].key, + s->key[ctxt_key].key_len, NULL); + g_assert(cipher !=3D NULL); + if (s->block_mode !=3D QCRYPTO_CIPHER_MODE_ECB) { + if (qcrypto_cipher_setiv(cipher, (void *)s->iv[ctxt_iv].iv, + sizeof(s->iv[ctxt_iv].iv), NULL) !=3D 0) { + trace_aes_cmd_data_error("Failed to set IV"); + goto err_free_cipher; + } + } + if (s->is_encrypt) { + if (qcrypto_cipher_encrypt(cipher, src, dst, len, NULL) !=3D 0) { + trace_aes_cmd_data_error("Encrypt failed"); + goto err_free_cipher; + } + } else { + if (qcrypto_cipher_decrypt(cipher, src, dst, len, NULL) !=3D 0) { + trace_aes_cmd_data_error("Decrypt failed"); + goto err_free_cipher; + } + } + qcrypto_cipher_free(cipher); + + dump_data("cmd_data(): dst_data=3D", dst, len); + cpu_physical_memory_write(dst_addr, dst, len); + g_free(src); + g_free(dst); + + return true; + +err_free_cipher: + qcrypto_cipher_free(cipher); +err_free: + g_free(src); + g_free(dst); + return false; +} + +static bool cmd_store_iv(AESState *s) +{ + uint32_t cmd =3D s->fifo[0]; + uint32_t ctxt =3D (cmd & CMD_IV_CONTEXT_MASK) >> CMD_IV_CONTEXT_SHIFT; + uint64_t addr =3D s->fifo[1]; + + if (!has_payload(s, 1)) { + /* wait for payload */ + return false; + } + + if (ctxt >=3D ARRAY_SIZE(s->iv)) { + /* Invalid context selected */ + return false; + } + + addr |=3D ((uint64_t)cmd << 32) & 0xff00000000ULL; + cpu_physical_memory_write(addr, &s->iv[ctxt].iv, sizeof(s->iv[ctxt].iv= )); + + trace_aes_cmd_store_iv(ctxt, addr, s->iv[ctxt].iv[0], s->iv[ctxt].iv[1= ], + s->iv[ctxt].iv[2], s->iv[ctxt].iv[3]); + + return true; +} + +static bool cmd_flag(AESState *s) +{ + uint32_t cmd =3D s->fifo[0]; + uint32_t raise_irq =3D cmd & CMD_FLAG_RAISE_IRQ_MASK; + + /* We always process data when it's coming in, so fire an IRQ immediat= ely */ + if (raise_irq) { + s->irq_status |=3D REG_IRQ_STATUS_FLAG; + } + + s->flag_info =3D cmd & CMD_FLAG_INFO_MASK; + + trace_aes_cmd_flag(!!raise_irq, s->flag_info); + + return true; +} + +static void fifo_process(AESState *s) +{ + uint32_t cmd =3D s->fifo[0] >> CMD_SHIFT; + bool success =3D false; + + if (!s->fifo_idx) { + return; + } + + switch (cmd) { + case CMD_KEY: + success =3D cmd_key(s); + break; + case CMD_IV: + success =3D cmd_iv(s); + break; + case CMD_DATA: + success =3D cmd_data(s); + break; + case CMD_STORE_IV: + success =3D cmd_store_iv(s); + break; + case CMD_FLAG: + success =3D cmd_flag(s); + break; + default: + s->irq_status |=3D REG_IRQ_STATUS_INVALID_CMD; + break; + } + + if (success) { + s->fifo_idx =3D 0; + } + + trace_aes_fifo_process(cmd, success ? 1 : 0); +} + +static void aes1_write(void *opaque, hwaddr offset, uint64_t val, unsigned= size) +{ + AESState *s =3D opaque; + + trace_aes_write(offset, val); + + switch (offset) { + case REG_IRQ_STATUS: + s->irq_status &=3D ~val; + break; + case REG_IRQ_ENABLE: + s->irq_enable =3D val; + break; + case REG_FIFO: + fifo_append(s, val); + fifo_process(s); + break; + default: + trace_aes_write_unknown(offset); + return; + } + + aes_update_irq(s); +} + +static const MemoryRegionOps aes1_ops =3D { + .read =3D aes1_read, + .write =3D aes1_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + }, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static uint64_t aes2_read(void *opaque, hwaddr offset, unsigned size) +{ + uint64_t res =3D 0; + + switch (offset) { + case 0: + res =3D 0; + break; + default: + trace_aes_2_read_unknown(offset); + break; + } + + trace_aes_2_read(offset, res); + + return res; +} + +static void aes2_write(void *opaque, hwaddr offset, uint64_t val, unsigned= size) +{ + trace_aes_2_write(offset, val); + + switch (offset) { + default: + trace_aes_2_write_unknown(offset); + return; + } +} + +static const MemoryRegionOps aes2_ops =3D { + .read =3D aes2_read, + .write =3D aes2_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + }, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static void aes_reset(Object *obj, ResetType type) +{ + AESState *s =3D AES(obj); + + s->status =3D 0x3f80; + s->q_status =3D 2; + s->irq_status =3D 0; + s->irq_enable =3D 0; + s->watermark =3D 0; +} + +static void aes_init(Object *obj) +{ + AESState *s =3D AES(obj); + + memory_region_init_io(&s->iomem1, obj, &aes1_ops, s, TYPE_AES, 0x4000); + memory_region_init_io(&s->iomem2, obj, &aes2_ops, s, TYPE_AES, 0x4000); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem1); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem2); + sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq); +} + +static void aes_realize(DeviceState *dev, Error **errp) +{ +} + +static void aes_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + rc->phases.hold =3D aes_reset; + dc->realize =3D aes_realize; +} + +static const TypeInfo aes_info =3D { + .name =3D TYPE_AES, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(AESState), + .class_init =3D aes_class_init, + .instance_init =3D aes_init, +}; + +static void aes_register_types(void) +{ + type_register_static(&aes_info); +} + +type_init(aes_register_types) diff --git a/hw/vmapple/meson.build b/hw/vmapple/meson.build index e69de29bb2d..bcd4dcb28d2 100644 --- a/hw/vmapple/meson.build +++ b/hw/vmapple/meson.build @@ -0,0 +1 @@ +system_ss.add(when: 'CONFIG_VMAPPLE_AES', if_true: files('aes.c')) diff --git a/hw/vmapple/trace-events b/hw/vmapple/trace-events index 9ccc5790487..1c9a3326eb4 100644 --- a/hw/vmapple/trace-events +++ b/hw/vmapple/trace-events @@ -1,2 +1,21 @@ # See docs/devel/tracing.rst for syntax documentation. =20 +# aes.c +aes_read_unknown(uint64_t offset) "offset=3D0x%"PRIx64 +aes_read(uint64_t offset, uint64_t res) "offset=3D0x%"PRIx64" res=3D0x%"PR= Ix64 +aes_cmd_key_select_builtin(uint32_t ctx, uint32_t key_id, const char *dire= ction, const char *cipher) "[%d] Selecting builtin key %d to %scrypt with %= s" +aes_cmd_key_select_new(uint32_t ctx, uint32_t key_len, const char *directi= on, const char *cipher) "[%d] Selecting new key size=3D%d to %scrypt with %= s" +aes_cmd_iv(uint32_t ctx, uint32_t iv0, uint32_t iv1, uint32_t iv2, uint32_= t iv3) "[%d] 0x%08x 0x%08x 0x%08x 0x%08x" +aes_cmd_data(uint32_t key, uint32_t iv, uint64_t src, uint64_t dst, uint32= _t len) "[key=3D%d iv=3D%d] src=3D0x%"PRIx64" dst=3D0x%"PRIx64" len=3D0x%x" +aes_cmd_data_error(const char *reason) "reason=3D%s" +aes_cmd_store_iv(uint32_t ctx, uint64_t addr, uint32_t iv0, uint32_t iv1, = uint32_t iv2, uint32_t iv3) "[%d] addr=3D0x%"PRIx64"x -> 0x%08x 0x%08x 0x%0= 8x 0x%08x" +aes_cmd_flag(uint32_t raise, uint32_t flag_info) "raise=3D%d flag_info=3D0= x%x" +aes_fifo_process(uint32_t cmd, uint32_t success) "cmd=3D%d success=3D%d" +aes_write_unknown(uint64_t offset) "offset=3D0x%"PRIx64 +aes_write(uint64_t offset, uint64_t val) "offset=3D0x%"PRIx64" val=3D0x%"P= RIx64 +aes_2_read_unknown(uint64_t offset) "offset=3D0x%"PRIx64 +aes_2_read(uint64_t offset, uint64_t res) "offset=3D0x%"PRIx64" res=3D0x%"= PRIx64 +aes_2_write_unknown(uint64_t offset) "offset=3D0x%"PRIx64 +aes_2_write(uint64_t offset, uint64_t val) "offset=3D0x%"PRIx64" val=3D0x%= "PRIx64 +aes_dump_data(const char *desc, const char *hex) "%s%s" + --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727514052; cv=none; d=zohomail.com; s=zohoarc; b=nJ9gyEvyMfTy1TAFrPgRgpeXvNEpSdK22Hk6ijcNB/yPyEDQw2FSWNxRNCZUL9MLw5k/smeW8w50RqQe9Pr61nIQPGsitq37eZH3hHe5EQ9XbikwL8SmavhwFX52/Yv8fPIblxmjljVSap1hsptCj0TR6oIeXKTvyu1nVMjKVy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727514052; 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=p5c0Ybd8ZWtXjev9WIqMz6Hpheesut5QBMxaBpA4954=; b=Oy0Kb52YWwEY3l5I2twJlOHsOlwUv1LAWLRyUPHheRt2ctQDQ5G05Kn3rHOBx3a9lCHFJCV5c5IM5OstUviBJ9evv16KNeZQPMkQny/LWI2L/QMX0gi0i1Aseg7BGkPusHMnfdQXdfayXf6nuuDlZuGo4Za7vtQ2II+rrNBpAKQ= 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 1727514051998141.1015674125398; Sat, 28 Sep 2024 02:00:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTIO-0003ys-Tr; Sat, 28 Sep 2024 04:59: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 1suTIN-0003mP-7m for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:19 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTIL-0002QR-2c for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:18 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-37cc9aeb01dso1706587f8f.2 for ; Sat, 28 Sep 2024 01:59:16 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.59.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513955; x=1728118755; 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=p5c0Ybd8ZWtXjev9WIqMz6Hpheesut5QBMxaBpA4954=; b=f+pRRKH5qtq4vaskHVQC3mO2ynboRrZuI/GoR8eKaZ6vYLw0KpnLByifbF5VGtRkqA eherDwXFggFWXxo+9p7gxFuq/QwoHtFxEPXUj3+h6aAChkxirsPNhiZl473Cn3vtAXt2 28Rx/PFbv4fcqsEIg8lwD4U940pzFrMvyueBGo5d6kzre07fSHuUhEGxGBpyKyq/u/9R Un35zm8aRn7VeqKVZfNseM6xj7PxG4uoVtzleE9mDblO4dNznzfSK7s73Zq41ge6wJgs 9PLkpjuxFw7c60Wo0VArEApjURJmtdCuEaKOWIQX0+h+gmE/57QZFxW5eYnOGJsZ9YiD fVBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513955; x=1728118755; 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=p5c0Ybd8ZWtXjev9WIqMz6Hpheesut5QBMxaBpA4954=; b=mdILzvbLuRclvi6e/CFHPCcqR6pldeR7QrYpqLPtB7+kSFDqA3deFWxUvPaR1yFlvL u8mRvOMJz/M+T43uRkHMJ2oIHTNITI07fVn0uzjRYREr2FddqTEjCN1fPLGOexsZBXWc huvWqOKcNDVzbdpcoYjUqV3aC5HjNlSHS5Bw0aBGyEZPinbm7iVtQZALl1PKGneqoiWN M4eUCu0K6bNX6MGzcyYEDepjLHyIxPu3ujLTuN2j187wZXw5A3p5mH3q24R1yzNIuP6h Jc/TZAwZUvRziyItGNJQVRxkKHOjc9fi5WJcHZXHkly2P2JkFEB5i9hkmYgruXeCJue6 u2SQ== X-Gm-Message-State: AOJu0YweMPd+Ad1R15NMJQMvtCnWGAfStwWVIfRm4aDDmaD9oJYc3XOe DMAORpDx3UMSUYRzBf55OGwQ7o07y2Bnal9itb8tJllJezVH02nYQ1XBn2MQWol9mI9NMq/0+sx KBg== X-Google-Smtp-Source: AGHT+IFBQsvwwA5kVVio1IWSp56G91RKKxaCb6Sdd/j71IdKA2/cP+LXjmsoEfT/FUm8wBry0Q7UJw== X-Received: by 2002:adf:a2de:0:b0:37c:cd71:2b96 with SMTP id ffacd0b85a97d-37cd5ae07a7mr3333652f8f.36.1727513955515; Sat, 28 Sep 2024 01:59:15 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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, Alexander Graf Subject: [PATCH v3 11/14] hw/vmapple/bdif: Introduce vmapple backdoor interface Date: Sat, 28 Sep 2024 10:57:24 +0200 Message-Id: <20240928085727.56883-12-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-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::433; envelope-from=phil@philjordan.eu; helo=mail-wr1-x433.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, 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: 1727514052821116600 From: Alexander Graf The VMApple machine exposes AUX and ROOT block devices (as well as USB OTG emulation) via virtio-pci as well as a special, simple backdoor platform device. This patch implements this backdoor platform device to the best of my understanding. I left out any USB OTG parts; they're only needed for guest recovery and I don't understand the protocol yet. Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan --- hw/vmapple/Kconfig | 3 + hw/vmapple/bdif.c | 245 ++++++++++++++++++++++++++++++++++++++ hw/vmapple/meson.build | 1 + hw/vmapple/trace-events | 5 + include/hw/vmapple/bdif.h | 31 +++++ 5 files changed, 285 insertions(+) create mode 100644 hw/vmapple/bdif.c create mode 100644 include/hw/vmapple/bdif.h diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig index a73504d5999..68f88876eb9 100644 --- a/hw/vmapple/Kconfig +++ b/hw/vmapple/Kconfig @@ -1,3 +1,6 @@ config VMAPPLE_AES bool =20 +config VMAPPLE_BDIF + bool + diff --git a/hw/vmapple/bdif.c b/hw/vmapple/bdif.c new file mode 100644 index 00000000000..36b5915ff30 --- /dev/null +++ b/hw/vmapple/bdif.c @@ -0,0 +1,245 @@ +/* + * VMApple Backdoor Interface + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * 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/bdif.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "trace.h" +#include "hw/block/block.h" +#include "sysemu/block-backend.h" + +#define REG_DEVID_MASK 0xffff0000 +#define DEVID_ROOT 0x00000000 +#define DEVID_AUX 0x00010000 +#define DEVID_USB 0x00100000 + +#define REG_STATUS 0x0 +#define REG_STATUS_ACTIVE BIT(0) +#define REG_CFG 0x4 +#define REG_CFG_ACTIVE BIT(1) +#define REG_UNK1 0x8 +#define REG_BUSY 0x10 +#define REG_BUSY_READY BIT(0) +#define REG_UNK2 0x400 +#define REG_CMD 0x408 +#define REG_NEXT_DEVICE 0x420 +#define REG_UNK3 0x434 + +typedef struct vblk_sector { + uint32_t pad; + uint32_t pad2; + uint32_t sector; + uint32_t pad3; +} VblkSector; + +typedef struct vblk_req_cmd { + uint64_t addr; + uint32_t len; + uint32_t flags; +} VblkReqCmd; + +typedef struct vblk_req { + VblkReqCmd sector; + VblkReqCmd data; + VblkReqCmd retval; +} VblkReq; + +#define VBLK_DATA_FLAGS_READ 0x00030001 +#define VBLK_DATA_FLAGS_WRITE 0x00010001 + +#define VBLK_RET_SUCCESS 0 +#define VBLK_RET_FAILED 1 + +static uint64_t bdif_read(void *opaque, hwaddr offset, unsigned size) +{ + uint64_t ret =3D -1; + uint64_t devid =3D (offset & REG_DEVID_MASK); + + switch (offset & ~REG_DEVID_MASK) { + case REG_STATUS: + ret =3D REG_STATUS_ACTIVE; + break; + case REG_CFG: + ret =3D REG_CFG_ACTIVE; + break; + case REG_UNK1: + ret =3D 0x420; + break; + case REG_BUSY: + ret =3D REG_BUSY_READY; + break; + case REG_UNK2: + ret =3D 0x1; + break; + case REG_UNK3: + ret =3D 0x0; + break; + case REG_NEXT_DEVICE: + switch (devid) { + case DEVID_ROOT: + ret =3D 0x8000000; + break; + case DEVID_AUX: + ret =3D 0x10000; + break; + } + break; + } + + trace_bdif_read(offset, size, ret); + return ret; +} + +static void le2cpu_sector(VblkSector *sector) +{ + sector->sector =3D le32_to_cpu(sector->sector); +} + +static void le2cpu_reqcmd(VblkReqCmd *cmd) +{ + cmd->addr =3D le64_to_cpu(cmd->addr); + cmd->len =3D le32_to_cpu(cmd->len); + cmd->flags =3D le32_to_cpu(cmd->flags); +} + +static void le2cpu_req(VblkReq *req) +{ + le2cpu_reqcmd(&req->sector); + le2cpu_reqcmd(&req->data); + le2cpu_reqcmd(&req->retval); +} + +static void vblk_cmd(uint64_t devid, BlockBackend *blk, uint64_t value, + uint64_t static_off) +{ + VblkReq req; + VblkSector sector; + uint64_t off =3D 0; + char *buf =3D NULL; + uint8_t ret =3D VBLK_RET_FAILED; + int r; + + cpu_physical_memory_read(value, &req, sizeof(req)); + le2cpu_req(&req); + + if (req.sector.len !=3D sizeof(sector)) { + ret =3D VBLK_RET_FAILED; + goto out; + } + + /* Read the vblk command */ + cpu_physical_memory_read(req.sector.addr, §or, sizeof(sector)); + le2cpu_sector(§or); + + off =3D sector.sector * 512ULL + static_off; + + /* Sanity check that we're not allocating bogus sizes */ + if (req.data.len > (128 * 1024 * 1024)) { + goto out; + } + + buf =3D g_malloc0(req.data.len); + switch (req.data.flags) { + case VBLK_DATA_FLAGS_READ: + r =3D blk_pread(blk, off, req.data.len, buf, 0); + trace_bdif_vblk_read(devid =3D=3D DEVID_AUX ? "aux" : "root", + req.data.addr, off, req.data.len, r); + if (r < 0) { + goto out; + } + cpu_physical_memory_write(req.data.addr, buf, req.data.len); + ret =3D VBLK_RET_SUCCESS; + break; + case VBLK_DATA_FLAGS_WRITE: + /* Not needed, iBoot only reads */ + break; + default: + break; + } + +out: + g_free(buf); + cpu_physical_memory_write(req.retval.addr, &ret, 1); +} + +static void bdif_write(void *opaque, hwaddr offset, + uint64_t value, unsigned size) +{ + VMAppleBdifState *s =3D opaque; + uint64_t devid =3D (offset & REG_DEVID_MASK); + + trace_bdif_write(offset, size, value); + + switch (offset & ~REG_DEVID_MASK) { + case REG_CMD: + switch (devid) { + case DEVID_ROOT: + vblk_cmd(devid, s->root, value, 0x0); + break; + case DEVID_AUX: + vblk_cmd(devid, s->aux, value, 0x0); + break; + } + break; + } +} + +static const MemoryRegionOps bdif_ops =3D { + .read =3D bdif_read, + .write =3D bdif_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 8, + }, + .impl =3D { + .min_access_size =3D 1, + .max_access_size =3D 8, + }, +}; + +static void bdif_init(Object *obj) +{ + VMAppleBdifState *s =3D VMAPPLE_BDIF(obj); + + memory_region_init_io(&s->mmio, obj, &bdif_ops, obj, + "VMApple Backdoor Interface", VMAPPLE_BDIF_SIZE); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); +} + +static Property bdif_properties[] =3D { + DEFINE_PROP_DRIVE("aux", VMAppleBdifState, aux), + DEFINE_PROP_DRIVE("root", VMAppleBdifState, root), + DEFINE_PROP_END_OF_LIST(), +}; + +static void bdif_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->desc =3D "VMApple Backdoor Interface"; + device_class_set_props(dc, bdif_properties); +} + +static const TypeInfo bdif_info =3D { + .name =3D TYPE_VMAPPLE_BDIF, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(VMAppleBdifState), + .instance_init =3D bdif_init, + .class_init =3D bdif_class_init, +}; + +static void bdif_register_types(void) +{ + type_register_static(&bdif_info); +} + +type_init(bdif_register_types) diff --git a/hw/vmapple/meson.build b/hw/vmapple/meson.build index bcd4dcb28d2..d4624713deb 100644 --- a/hw/vmapple/meson.build +++ b/hw/vmapple/meson.build @@ -1 +1,2 @@ system_ss.add(when: 'CONFIG_VMAPPLE_AES', if_true: files('aes.c')) +system_ss.add(when: 'CONFIG_VMAPPLE_BDIF', if_true: files('bdif.c')) diff --git a/hw/vmapple/trace-events b/hw/vmapple/trace-events index 1c9a3326eb4..fc8e9cc5897 100644 --- a/hw/vmapple/trace-events +++ b/hw/vmapple/trace-events @@ -19,3 +19,8 @@ aes_2_write_unknown(uint64_t offset) "offset=3D0x%"PRIx64 aes_2_write(uint64_t offset, uint64_t val) "offset=3D0x%"PRIx64" val=3D0x%= "PRIx64 aes_dump_data(const char *desc, const char *hex) "%s%s" =20 +# bdif.c +bdif_read(uint64_t offset, uint32_t size, uint64_t value) "offset=3D0x%"PR= Ix64" size=3D0x%x value=3D0x%"PRIx64 +bdif_write(uint64_t offset, uint32_t size, uint64_t value) "offset=3D0x%"P= RIx64" size=3D0x%x value=3D0x%"PRIx64 +bdif_vblk_read(const char *dev, uint64_t addr, uint64_t offset, uint32_t l= en, int r) "dev=3D%s addr=3D0x%"PRIx64" off=3D0x%"PRIx64" size=3D0x%x r=3D%= d" + diff --git a/include/hw/vmapple/bdif.h b/include/hw/vmapple/bdif.h new file mode 100644 index 00000000000..65ee43457b9 --- /dev/null +++ b/include/hw/vmapple/bdif.h @@ -0,0 +1,31 @@ +/* + * VMApple Backdoor Interface + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * 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. + */ + +#ifndef HW_VMAPPLE_BDIF_H +#define HW_VMAPPLE_BDIF_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_VMAPPLE_BDIF "vmapple-bdif" +OBJECT_DECLARE_SIMPLE_TYPE(VMAppleBdifState, VMAPPLE_BDIF) + +struct VMAppleBdifState { + /* */ + SysBusDevice parent_obj; + + /* */ + BlockBackend *aux; + BlockBackend *root; + MemoryRegion mmio; +}; + +#define VMAPPLE_BDIF_SIZE 0x00200000 + +#endif /* HW_VMAPPLE_BDIF_H */ --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727514097; cv=none; d=zohomail.com; s=zohoarc; b=BxPJwRzJNT/t6x+tLZkSMF1w4fR6Q3KiiEsRf0trsTmdzUAKfTTQxtAQnSaMsUpwHhkdXmz+gSjpYwvZYPq516BCXsSkN1mRS2/FceT2BF3fAxeadIS+pWpyU99xYDFo/DLkey9+fUK6gtGry44qbpGAfbr0O0EGIOUeNQbpYCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727514097; 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=SseSKGbzBfpGZIH6BILqp0UJmtMdERPGWCDtKLJR6rw=; b=nSgFKvvqviOqAdPqZZo59vB9l+Ew6LbMzUqlILW2Z4JEG9cWUkQN6crUNZr3PxE7rqnUHlrV1Grv/Q5WUvJOU2Iz7FA1/++0WyVzMzPtSbwyL5T3ZsPCHQmM4i7xTId7kFGGzpVh3PMEdqIyxLOCcIm3ykk53zoRoS7D3sxlGmg= 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 172751409701656.043229443171185; Sat, 28 Sep 2024 02:01:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTIe-0005Kx-64; Sat, 28 Sep 2024 04:59:36 -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 1suTIU-0004af-DF for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:26 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTIQ-0002RZ-VO for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:26 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-42cb9a0c300so23476125e9.0 for ; Sat, 28 Sep 2024 01:59:22 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.59.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513961; x=1728118761; 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=SseSKGbzBfpGZIH6BILqp0UJmtMdERPGWCDtKLJR6rw=; b=IW+SYFCpEe5EttlxNen1GAEWTZh/zAi9EzqvjSqxyVEQ5AACI5YGtDnD2a8en9ISVF nUWSd9NYce0JLdqjf2agn4eR5cp5/GnOmRlkX289fuLvB7XQerWdb6hsjMMKoF35JnO+ mhyB34uUkvzG/XOofxTswOzYguplrrKFqDoMs1vMxbkahoayr5ZwdtVxKZsyCn38TqE8 exSYsWu4I/L49yyHffxQn66+QVyb2P8rlmP556aU7PfP3WLcTHHsiRR7VOPG2uylNWzB CV0IIyvWyLyTL05bBNaORBgeg8lYTjba/p6J6QMLMOD4bOUKo2FtxflwN1b6EdvzruF+ KUow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513961; x=1728118761; 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=SseSKGbzBfpGZIH6BILqp0UJmtMdERPGWCDtKLJR6rw=; b=dd5FvpUrsjCdMGEwJAN7GV0BsJSg30adnREh2BfSKBSFcf18ee8x3SdTkua0yHwpwm ck6UYljAa6CUSI6w4eGX408k3wDUutdA2NqR2qZJM8on06XPWvEM0TYhdDZ8obXuC5ZC d9f3SC0lD3B/sA/i0QwP0js0GGl8ng4N/VigDR2t3W4pesz+v0hELYijRUq3VPmUDNCR EKYGLWm2qX/4slPyHKoghGRvg6AkVMEm7NkGAm5cH0us8l4mZ/ZeDpwHB5ZJcPkU/ELU ALJJ4+fRRQ/zvhr5HAjEvuwXpGwZRWaiMQFYQshsGROjxowA3EAIvp3vtyLj/3S940aF uBQA== X-Gm-Message-State: AOJu0Yw96c9iL9pVYhZUetyIFujzqwIDDu0h1v671fwS4RevFOJPoNKO G+BCPyUijrghfous5Wn44deN48JQhbGv9QZMqVMxBlp1UMp1/IFKe6q+HR3H8IoHIiLkfeXBY7s bdg== X-Google-Smtp-Source: AGHT+IEUgWe00DAUfjqvnOCRLArfK5lDZlT0OMH5v37RfhdOUmbTp7wJsZv7loh7VNvsv4Ut0XYt/A== X-Received: by 2002:a5d:6411:0:b0:37c:d0f2:bab2 with SMTP id ffacd0b85a97d-37cd5a68d0dmr3607062f8f.3.1727513961103; Sat, 28 Sep 2024 01:59:21 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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, Alexander Graf Subject: [PATCH v3 12/14] hw/vmapple/cfg: Introduce vmapple cfg region Date: Sat, 28 Sep 2024 10:57:25 +0200 Message-Id: <20240928085727.56883-13-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-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::32c; envelope-from=phil@philjordan.eu; helo=mail-wm1-x32c.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, 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: 1727514098993116600 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 --- v3: * Replaced legacy device reset method with Resettable method hw/vmapple/Kconfig | 3 ++ hw/vmapple/cfg.c | 106 +++++++++++++++++++++++++++++++++++++++ hw/vmapple/meson.build | 1 + include/hw/vmapple/cfg.h | 68 +++++++++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 hw/vmapple/cfg.c create mode 100644 include/hw/vmapple/cfg.h diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig index 68f88876eb9..8bbeb9a9237 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 00000000000..a5e5c62f59f --- /dev/null +++ b/hw/vmapple/cfg.c @@ -0,0 +1,106 @@ +/* + * VMApple Configuration Region + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * 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/cfg.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" + +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((void *)cfg, 0, VMAPPLE_CFG_SIZE); + *cfg =3D s->cfg; +} + +static void vmapple_cfg_realize(DeviceState *dev, Error **errp) +{ + VMAppleCfgState *s =3D VMAPPLE_CFG(dev); + uint32_t i; + + strncpy(s->cfg.serial, s->serial, sizeof(s->cfg.serial)); + strncpy(s->cfg.model, s->model, sizeof(s->cfg.model)); + strncpy(s->cfg.soc_name, s->soc_name, sizeof(s->cfg.soc_name)); + strncpy(s->cfg.unk8, "D/A", sizeof(s->cfg.soc_name)); + s->cfg.ecid =3D cpu_to_be64(s->cfg.ecid); + 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; + + g_assert(s->cfg.nr_cpus < ARRAY_SIZE(s->cfg.cpu_ids)); + 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); + + s->serial =3D (char *)"1234"; + s->model =3D (char *)"VM0001"; + s->soc_name =3D (char *)"Apple M1 (Virtual)"; +} + +static 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), + DEFINE_PROP_END_OF_LIST(), +}; + +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 d4624713deb..64b78693a31 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/cfg.h b/include/hw/vmapple/cfg.h new file mode 100644 index 00000000000..3337064e447 --- /dev/null +++ b/include/hw/vmapple/cfg.h @@ -0,0 +1,68 @@ +/* + * VMApple Configuration Region + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * 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. + */ + +#ifndef HW_VMAPPLE_CFG_H +#define HW_VMAPPLE_CFG_H + +#include "hw/sysbus.h" +#include "qom/object.h" +#include "net/net.h" + +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; + +#define TYPE_VMAPPLE_CFG "vmapple-cfg" +OBJECT_DECLARE_SIMPLE_TYPE(VMAppleCfgState, VMAPPLE_CFG) + +struct VMAppleCfgState { + /* */ + SysBusDevice parent_obj; + VMAppleCfg cfg; + + /* */ + MemoryRegion mem; + char *serial; + char *model; + char *soc_name; +}; + +#define VMAPPLE_CFG_SIZE 0x00010000 + +#endif /* HW_VMAPPLE_CFG_H */ --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727514043; cv=none; d=zohomail.com; s=zohoarc; b=fGJMhPExFMidqL5MQcQsIKVzIzqGauCtKF8wQ+rFnNCTMPIR9L8MwL613czxiNQF6dIjJOeRcIlndI6BKfhCfFQ7AB7i7O3HmcrQIU6igCC4D5PXjxcGGjziNRZKB7l0To0p7qll8r8H+0MXtaoYPkCGyC28bfoh+azJaGns4AM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727514043; 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=vnJbHfbRpxiH7lm9OYUgmVKZzN/3LCteRLW7vnwJa7M=; b=HecWzFI4JJlncwTGqXreli+GYH0RnokaXhM9gdojff6Meahr/x+AxthmgMVyjJFRYAkghLglcqa2af3E8DY9G05BvU/OttUswrt/YbFOKAGVIrdwgMVSnKi3lqoqneE/hTlkGwKncnxOgP5awmAg9kGFG6AYh64T1r2svcPcEKI= 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 1727514043238809.0765960447615; Sat, 28 Sep 2024 02:00:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTIi-0005fu-Tn; Sat, 28 Sep 2024 04:59:44 -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 1suTIe-0005OR-Fr for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:36 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTIb-0002Ss-Fl for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:36 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-37ccdc0d7f6so1565972f8f.0 for ; Sat, 28 Sep 2024 01:59:32 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.59.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:59:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513971; x=1728118771; 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=vnJbHfbRpxiH7lm9OYUgmVKZzN/3LCteRLW7vnwJa7M=; b=QNg9TPELGjoL5duAwvUBXR/fkYStU4/l/8qNad44+yCxfGZ74LRhuNXjG44VZZR4ET X1MzybwIuT6+WXoafmrCKs5/da5lZPbcDmlP69NbibWTwBRVk9++8AqnwjOHOgcizsDe Ei/XdTx3Yv3kFk5CFHrlmbzgZrx590ApYDMyOpL+XXRtfiTm3DFJW2LA163rmFk/7oQO IwmgGcE8c2sti40RL4FLy+cYS28itNS6nicb7uHxNMa5EIj2rbdM7cgDRG3cvR50Ch3p tz52LJnW01DyYLZyeqK6wyX1MaibVh0KtNFlg/ddmzuLalt7Nx9q7Q14CPUSUozQGCfE RX8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513971; x=1728118771; 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=vnJbHfbRpxiH7lm9OYUgmVKZzN/3LCteRLW7vnwJa7M=; b=IjPuRIAZ5PDRM814YocklUo3ZAtPbx7MOuH22ovt3hOOZmla5LjteParvoxLfekKu5 s95tllk6kizsLI/1Rua+kzjiyi0z9J16nXSoI+8O5dDczO7WdgyxCEv5F53SOzhg0gK5 A/F9iErIPFQgmlpf8L7bDmO9DeuTEkQ7Y/JOaQ1uzmuPXG6xo6tU6r18SPIhBJoZEfbM TsLdRzyNMHLaZ2cNzgO5JGQxW0C9+KJYOSR8sIj51PUFewhbOuBbpKdZuHl8dePdVICd g1jwW+cCLSxCCq0o8bouwnGMLygDpPRf5ulnrzyxaMs8RlPSE1QLY9K/Vr9fc4aLtiUR T4Lg== X-Gm-Message-State: AOJu0YwfBn3uWHjLtYjPye4aMlCnDabZYXdqw5xwf8WhBKzuRpsWncOs Y4kEPPyZWiUdHwowq55zRf8eSyKQyhQtzgVVTRiPg0w84ChFITSmwJrZ4FA0tu7ymESaVuHBk6X ZYQ== X-Google-Smtp-Source: AGHT+IEqYjbKQj/waLteF3SmDa8WqqfWxrXj/vn12Y0qkz0bxphs/J+TZdcBTfpCWZuEIlYmtJL/GQ== X-Received: by 2002:a05:6000:108f:b0:37c:cd0d:3437 with SMTP id ffacd0b85a97d-37cd5b09c91mr2650715f8f.58.1727513970866; Sat, 28 Sep 2024 01:59:30 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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, Alexander Graf Subject: [PATCH v3 13/14] hw/vmapple/virtio-blk: Add support for apple virtio-blk Date: Sat, 28 Sep 2024 10:57:26 +0200 Message-Id: <20240928085727.56883-14-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-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::429; envelope-from=phil@philjordan.eu; helo=mail-wr1-x429.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, 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: 1727514044601116600 From: Alexander Graf Apple has its own virtio-blk PCI device ID where it deviates from the official virtio-pci spec slightly: It puts a new "apple type" field at a static offset in config space and introduces a new barrier command. This patch first creates a mechanism for virtio-blk downstream classes to handle unknown commands. It then creates such a downstream class and a new vmapple-virtio-blk-pci class which support the additional apple type config identifier as well as the barrier command. It then exposes 2 subclasses from that that we can use to expose root and aux virtio-blk devices: "vmapple-virtio-root" and "vmapple-virtio-aux". Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan --- hw/block/virtio-blk.c | 19 ++- hw/vmapple/Kconfig | 3 + hw/vmapple/meson.build | 1 + hw/vmapple/virtio-blk.c | 212 ++++++++++++++++++++++++++++++++ include/hw/pci/pci_ids.h | 1 + include/hw/virtio/virtio-blk.h | 12 +- include/hw/vmapple/virtio-blk.h | 39 ++++++ 7 files changed, 282 insertions(+), 5 deletions(-) create mode 100644 hw/vmapple/virtio-blk.c create mode 100644 include/hw/vmapple/virtio-blk.h diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 115795392c4..cecc4cef9e4 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -50,12 +50,12 @@ static void virtio_blk_init_request(VirtIOBlock *s, Vir= tQueue *vq, req->mr_next =3D NULL; } =20 -static void virtio_blk_free_request(VirtIOBlockReq *req) +void virtio_blk_free_request(VirtIOBlockReq *req) { g_free(req); } =20 -static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char sta= tus) +void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status) { VirtIOBlock *s =3D req->dev; VirtIODevice *vdev =3D VIRTIO_DEVICE(s); @@ -966,8 +966,18 @@ static int virtio_blk_handle_request(VirtIOBlockReq *r= eq, MultiReqBuffer *mrb) break; } default: - virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP); - virtio_blk_free_request(req); + { + /* + * Give subclasses a chance to handle unknown requests. This way t= he + * class lookup is not in the hot path. + */ + VirtIOBlkClass *vbk =3D VIRTIO_BLK_GET_CLASS(s); + if (!vbk->handle_unknown_request || + !vbk->handle_unknown_request(req, mrb, type)) { + virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP); + virtio_blk_free_request(req); + } + } } return 0; } @@ -2044,6 +2054,7 @@ static const TypeInfo virtio_blk_info =3D { .instance_size =3D sizeof(VirtIOBlock), .instance_init =3D virtio_blk_instance_init, .class_init =3D virtio_blk_class_init, + .class_size =3D sizeof(VirtIOBlkClass), }; =20 static void virtio_register_types(void) diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig index 8bbeb9a9237..bcd1be63e3c 100644 --- a/hw/vmapple/Kconfig +++ b/hw/vmapple/Kconfig @@ -7,3 +7,6 @@ config VMAPPLE_BDIF config VMAPPLE_CFG bool =20 +config VMAPPLE_VIRTIO_BLK + bool + diff --git a/hw/vmapple/meson.build b/hw/vmapple/meson.build index 64b78693a31..bf17cf906c9 100644 --- a/hw/vmapple/meson.build +++ b/hw/vmapple/meson.build @@ -1,3 +1,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')) +system_ss.add(when: 'CONFIG_VMAPPLE_VIRTIO_BLK', if_true: files('virtio-b= lk.c')) diff --git a/hw/vmapple/virtio-blk.c b/hw/vmapple/virtio-blk.c new file mode 100644 index 00000000000..720eaa61a86 --- /dev/null +++ b/hw/vmapple/virtio-blk.c @@ -0,0 +1,212 @@ +/* + * VMApple specific VirtIO Block implementation + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * 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. + * + * VMApple uses almost standard VirtIO Block, but with a few key differenc= es: + * + * - Different PCI device/vendor ID + * - An additional "type" identifier to differentiate AUX and Root volumes + * - An additional BARRIER command + */ + +#include "qemu/osdep.h" +#include "hw/vmapple/virtio-blk.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" + +#define VIRTIO_BLK_T_APPLE_BARRIER 0x10000 + +#define VIRTIO_APPLE_TYPE_ROOT 1 +#define VIRTIO_APPLE_TYPE_AUX 2 + +static bool vmapple_virtio_blk_handle_unknown_request(VirtIOBlockReq *req, + MultiReqBuffer *mrb, + uint32_t type) +{ + switch (type) { + case VIRTIO_BLK_T_APPLE_BARRIER: + /* We ignore barriers for now. YOLO. */ + virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); + virtio_blk_free_request(req); + return true; + default: + return false; + } +} + +/* + * VMApple virtio-blk uses the same config format as normal virtio, with o= ne + * exception: It adds an "apple type" specififer at the same location that + * the spec reserves for max_secure_erase_sectors. Let's hook into the + * get_config code path here, run it as usual and then patch in the apple = type. + */ +static void vmapple_virtio_blk_get_config(VirtIODevice *vdev, uint8_t *con= fig) +{ + VMAppleVirtIOBlk *dev =3D VMAPPLE_VIRTIO_BLK(vdev); + VMAppleVirtIOBlkClass *vvbk =3D VMAPPLE_VIRTIO_BLK_GET_CLASS(dev); + struct virtio_blk_config *blkcfg =3D (struct virtio_blk_config *)confi= g; + + vvbk->get_config(vdev, config); + + g_assert(dev->parent_obj.config_size >=3D endof(struct virtio_blk_conf= ig, zoned)); + + /* Apple abuses the field for max_secure_erase_sectors as type id */ + blkcfg->max_secure_erase_sectors =3D dev->apple_type; +} + +static Property vmapple_virtio_blk_properties[] =3D { + DEFINE_PROP_UINT32("apple-type", VMAppleVirtIOBlk, apple_type, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vmapple_virtio_blk_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtIOBlkClass *vbk =3D VIRTIO_BLK_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + VMAppleVirtIOBlkClass *vvbk =3D VMAPPLE_VIRTIO_BLK_CLASS(klass); + + vbk->handle_unknown_request =3D vmapple_virtio_blk_handle_unknown_requ= est; + vvbk->get_config =3D vdc->get_config; + vdc->get_config =3D vmapple_virtio_blk_get_config; + device_class_set_props(dc, vmapple_virtio_blk_properties); +} + +static const TypeInfo vmapple_virtio_blk_info =3D { + .name =3D TYPE_VMAPPLE_VIRTIO_BLK, + .parent =3D TYPE_VIRTIO_BLK, + .instance_size =3D sizeof(VMAppleVirtIOBlk), + .class_init =3D vmapple_virtio_blk_class_init, +}; + +/* PCI Devices */ + +typedef struct VMAppleVirtIOBlkPCI { + VirtIOPCIProxy parent_obj; + VMAppleVirtIOBlk vdev; + uint32_t apple_type; +} VMAppleVirtIOBlkPCI; + +/* + * vmapple-virtio-blk-pci: This extends VirtioPCIProxy. + */ +#define TYPE_VMAPPLE_VIRTIO_BLK_PCI "vmapple-virtio-blk-pci-base" +DECLARE_INSTANCE_CHECKER(VMAppleVirtIOBlkPCI, VMAPPLE_VIRTIO_BLK_PCI, + TYPE_VMAPPLE_VIRTIO_BLK_PCI) + +static Property vmapple_virtio_blk_pci_properties[] =3D { + DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0), + DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, + VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, + DEV_NVECTORS_UNSPECIFIED), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vmapple_virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error= **errp) +{ + VMAppleVirtIOBlkPCI *dev =3D VMAPPLE_VIRTIO_BLK_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + VirtIOBlkConf *conf =3D &dev->vdev.parent_obj.conf; + + if (conf->num_queues =3D=3D VIRTIO_BLK_AUTO_NUM_QUEUES) { + conf->num_queues =3D virtio_pci_optimal_num_queues(0); + } + + if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors =3D conf->num_queues + 1; + } + + /* + * We don't support zones, but we need the additional config space siz= e. + * Let's just expose the feature so the rest of the virtio-blk logic + * allocates enough space for us. The guest will ignore zones anyway. + */ + virtio_add_feature(&dev->vdev.parent_obj.host_features, VIRTIO_BLK_F_Z= ONED); + /* Propagate the apple type down to the virtio-blk device */ + qdev_prop_set_uint32(DEVICE(&dev->vdev), "apple-type", dev->apple_type= ); + /* and spawn the virtio-blk device */ + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); + + /* + * The virtio-pci machinery adjusts its vendor/device ID based on whet= her + * we support modern or legacy virtio. Let's patch it back to the Apple + * identifiers here. + */ + pci_config_set_vendor_id(vpci_dev->pci_dev.config, PCI_VENDOR_ID_APPLE= ); + pci_config_set_device_id(vpci_dev->pci_dev.config, PCI_DEVICE_ID_APPLE= _VIRTIO_BLK); +} + +static void vmapple_virtio_blk_pci_class_init(ObjectClass *klass, void *da= ta) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + device_class_set_props(dc, vmapple_virtio_blk_pci_properties); + k->realize =3D vmapple_virtio_blk_pci_realize; + pcidev_k->vendor_id =3D PCI_VENDOR_ID_APPLE; + pcidev_k->device_id =3D PCI_DEVICE_ID_APPLE_VIRTIO_BLK; + pcidev_k->revision =3D VIRTIO_PCI_ABI_VERSION; + pcidev_k->class_id =3D PCI_CLASS_STORAGE_SCSI; +} + +static void vmapple_virtio_blk_pci_instance_init(Object *obj) +{ + VMAppleVirtIOBlkPCI *dev =3D VMAPPLE_VIRTIO_BLK_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VMAPPLE_VIRTIO_BLK); +} + +static const VirtioPCIDeviceTypeInfo vmapple_virtio_blk_pci_info =3D { + .base_name =3D TYPE_VMAPPLE_VIRTIO_BLK_PCI, + .generic_name =3D "vmapple-virtio-blk-pci", + .instance_size =3D sizeof(VMAppleVirtIOBlkPCI), + .instance_init =3D vmapple_virtio_blk_pci_instance_init, + .class_init =3D vmapple_virtio_blk_pci_class_init, +}; + +static void vmapple_virtio_root_instance_init(Object *obj) +{ + VMAppleVirtIOBlkPCI *dev =3D VMAPPLE_VIRTIO_BLK_PCI(obj); + + dev->apple_type =3D VIRTIO_APPLE_TYPE_ROOT; +} + +static const TypeInfo vmapple_virtio_root_info =3D { + .name =3D TYPE_VMAPPLE_VIRTIO_ROOT, + .parent =3D "vmapple-virtio-blk-pci", + .instance_size =3D sizeof(VMAppleVirtIOBlkPCI), + .instance_init =3D vmapple_virtio_root_instance_init, +}; + +static void vmapple_virtio_aux_instance_init(Object *obj) +{ + VMAppleVirtIOBlkPCI *dev =3D VMAPPLE_VIRTIO_BLK_PCI(obj); + + dev->apple_type =3D VIRTIO_APPLE_TYPE_AUX; +} + +static const TypeInfo vmapple_virtio_aux_info =3D { + .name =3D TYPE_VMAPPLE_VIRTIO_AUX, + .parent =3D "vmapple-virtio-blk-pci", + .instance_size =3D sizeof(VMAppleVirtIOBlkPCI), + .instance_init =3D vmapple_virtio_aux_instance_init, +}; + +static void vmapple_virtio_blk_register_types(void) +{ + type_register_static(&vmapple_virtio_blk_info); + virtio_pci_types_register(&vmapple_virtio_blk_pci_info); + type_register_static(&vmapple_virtio_root_info); + type_register_static(&vmapple_virtio_aux_info); +} + +type_init(vmapple_virtio_blk_register_types) diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h index f1a53fea8d6..33e2898be95 100644 --- a/include/hw/pci/pci_ids.h +++ b/include/hw/pci/pci_ids.h @@ -191,6 +191,7 @@ #define PCI_DEVICE_ID_APPLE_UNI_N_AGP 0x0020 #define PCI_DEVICE_ID_APPLE_U3_AGP 0x004b #define PCI_DEVICE_ID_APPLE_UNI_N_GMAC 0x0021 +#define PCI_DEVICE_ID_APPLE_VIRTIO_BLK 0x1a00 =20 #define PCI_VENDOR_ID_SUN 0x108e #define PCI_DEVICE_ID_SUN_EBUS 0x1000 diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 5c14110c4b1..28d5046ea6c 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -24,7 +24,7 @@ #include "qapi/qapi-types-virtio.h" =20 #define TYPE_VIRTIO_BLK "virtio-blk-device" -OBJECT_DECLARE_SIMPLE_TYPE(VirtIOBlock, VIRTIO_BLK) +OBJECT_DECLARE_TYPE(VirtIOBlock, VirtIOBlkClass, VIRTIO_BLK) =20 /* This is the last element of the write scatter-gather list */ struct virtio_blk_inhdr @@ -100,6 +100,16 @@ typedef struct MultiReqBuffer { bool is_write; } MultiReqBuffer; =20 +typedef struct VirtIOBlkClass { + /*< private >*/ + VirtioDeviceClass parent; + /*< public >*/ + bool (*handle_unknown_request)(VirtIOBlockReq *req, MultiReqBuffer *mr= b, + uint32_t type); +} VirtIOBlkClass; + void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq); +void virtio_blk_free_request(VirtIOBlockReq *req); +void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status); =20 #endif diff --git a/include/hw/vmapple/virtio-blk.h b/include/hw/vmapple/virtio-bl= k.h new file mode 100644 index 00000000000..b23106a3dfb --- /dev/null +++ b/include/hw/vmapple/virtio-blk.h @@ -0,0 +1,39 @@ +/* + * VMApple specific VirtIO Block implementation + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * 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. + */ + +#ifndef HW_VMAPPLE_CFG_H +#define HW_VMAPPLE_CFG_H + +#include "hw/sysbus.h" +#include "qom/object.h" +#include "hw/virtio/virtio-pci.h" +#include "hw/virtio/virtio-blk.h" + +#define TYPE_VMAPPLE_VIRTIO_BLK "vmapple-virtio-blk" +#define TYPE_VMAPPLE_VIRTIO_ROOT "vmapple-virtio-root" +#define TYPE_VMAPPLE_VIRTIO_AUX "vmapple-virtio-aux" + +OBJECT_DECLARE_TYPE(VMAppleVirtIOBlk, VMAppleVirtIOBlkClass, VMAPPLE_VIRTI= O_BLK) + +typedef struct VMAppleVirtIOBlkClass { + /*< private >*/ + VirtIOBlkClass parent; + /*< public >*/ + void (*get_config)(VirtIODevice *vdev, uint8_t *config); +} VMAppleVirtIOBlkClass; + +typedef struct VMAppleVirtIOBlk { + /* */ + VirtIOBlock parent_obj; + + /* */ + uint32_t apple_type; +} VMAppleVirtIOBlk; + +#endif /* HW_VMAPPLE_CFG_H */ --=20 2.39.3 (Apple Git-145) From nobody Sun Nov 24 00:38:13 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=1727514040; cv=none; d=zohomail.com; s=zohoarc; b=jQeQlD+KLBkUcIjnftxdXAOFG/JZa3iBLZsHhVoNPsyaSQFFSRULuKb7vnu/mhaSAsQmg9Nh5AG03G22XSt8GlE1Y8Vw+35pycPUfWgI5knash9SvoTFHXg5AvV0lsauBvfNYrN1MKTbrrGqNcqCWoG0QwhCpKcYpt5jxy4a0WY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727514040; 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=4MLloGuymuEEk56VSg88Zxwdcm1NV10NLgGx4FyCgl8=; b=QlauYEq3oB+OLqLpxgMEHkpY7IU8qaSHXYZZeHzNjldszILHhyEX9GRIxX0qfF/exih+s++Evb1zJMeOPQHauIfsm5udOtHqGWEwxTlr1uIA4XFySO3Q/Cj2q7SGFoGQQeHJc2hTerjDUtDOGAv3zyeR3AflSFQSj2qyW7pgQzE= 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 1727514040321553.1715215217355; Sat, 28 Sep 2024 02:00:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTIt-0006vn-SC; Sat, 28 Sep 2024 04:59:51 -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 1suTIp-0006RT-S4 for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:48 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suTIj-0002U7-Lz for qemu-devel@nongnu.org; Sat, 28 Sep 2024 04:59:47 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-37cd26c6dd1so2050306f8f.3 for ; Sat, 28 Sep 2024 01:59:38 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:2ae:e42d:7dbb:76ba:120d:8a28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm4313167f8f.90.2024.09.28.01.59.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Sep 2024 01:59:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1727513977; x=1728118777; 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=4MLloGuymuEEk56VSg88Zxwdcm1NV10NLgGx4FyCgl8=; b=B1lGUzjH5CT5PQpoSrkIP2jO7ZdChGPUTqef+Y950pp1KKSw/3EfoopkrMft2+nSLM NTLTlR0jj3HcHK72Ci/cpvus0CTpjgkfk4BRAWM3KjX9KaDP2m/am41+9aZfjgln2G6U YG/t03y10iusFnPXOVpZFTedr7EuQDpPWveGZakDtwD08WZU1cNml7javl+mPo+F2/Vj LyP7hhHZUluN+iZtnXUnO3cWHjvrhFqqVf859C7TXt2mGL3rmXOncbj2FWEmQgcP4NQB BtbPmGCVPT7Z6ubpywekB9ttl7BZUf/1bJvlnmVN3CRUTnXbVm4YiMrbcJL7UYJSBmWp Kpew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727513977; x=1728118777; 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=4MLloGuymuEEk56VSg88Zxwdcm1NV10NLgGx4FyCgl8=; b=boQyVtEWtOIqqLJAK3TCI+hh/JwNsRHaum8/gAFigzlmonjrLavgSyuC2x7I9vvS3/ XskcEZ8dVOldfCVtSS8+aa7KfIkl24LE+XxzyjGz0I7YUWve5uFDxd0iusBZ6/kkxRxa f5A8MFnnkbAW1aI3K/sPlA6hFTfKIfgpvFjc6FweBTyHhpVnlegvk60Bchqb5sra1c6D cjIUjVo2e9cbeb23JYDyh28Od6/nnkckmMPBRLDk5lQZruRzaC+7zuGqV0sqDuuqFx4U Z7k9pbVINb36FTSH4GKXnGW9gHSC0I7QmPTy3qpOs3TUXUyq9jqO6LGjm3WvChq3t42q 8BRQ== X-Gm-Message-State: AOJu0YwpYNgeCwKglhlKpxnBBLaWvovka4DfO53YBdtcdsndfx8iaxr7 +iFOoDCNjxdC2gDY2XlHhKDcGgKXpKTcmOJSZ1di0cPdoXiA4TZWXoSxhlCSyMlF8rTSdPMIPQr VuQ== X-Google-Smtp-Source: AGHT+IFYNpGFrP/rfpjThVub6DOo0ZQQt/eAH3ElJWCYu/4aMCb81QSzoiirqUUBclUeLV8Tvkg8VQ== X-Received: by 2002:adf:ec05:0:b0:37c:d507:aacd with SMTP id ffacd0b85a97d-37cd5a87fbamr5625672f8f.14.1727513977349; Sat, 28 Sep 2024 01:59:37 -0700 (PDT) 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, marcin.juszkiewicz@linaro.org, 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, Alexander Graf Subject: [PATCH v3 14/14] hw/vmapple/vmapple: Add vmapple machine type Date: Sat, 28 Sep 2024 10:57:27 +0200 Message-Id: <20240928085727.56883-15-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240928085727.56883-1-phil@philjordan.eu> References: <20240928085727.56883-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::433; envelope-from=phil@philjordan.eu; helo=mail-wr1-x433.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, 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: 1727514042566116600 From: Alexander Graf Apple defines a new "vmapple" machine type as part of its proprietary macOS Virtualization.Framework vmm. This machine type is similar to the virt one, but with subtle differences in base devices, a few special vmapple device additions and a vastly different boot chain. This patch reimplements this machine type in QEMU. To use it, you have to have a readily installed version of macOS for VMApple, run on macOS with -accel hvf, pass the Virtualization.Framework boot rom (AVPBooter) in via -bios, pass the aux and root volume as pflash and pass aux and root volume as virtio drives. In addition, you also need to find the machine UUID and pass that as -M vmapple,uuid=3D parameter: $ qemu-system-aarch64 -accel hvf -M vmapple,uuid=3D0x1234 -m 4G \ -bios /System/Library/Frameworks/Virtualization.framework/Versions/A/Re= sources/AVPBooter.vmapple2.bin -drive file=3Daux,if=3Dpflash,format=3Draw \ -drive file=3Droot,if=3Dpflash,format=3Draw \ -drive file=3Daux,if=3Dnone,id=3Daux,format=3Draw \ -device vmapple-virtio-aux,drive=3Daux \ -drive file=3Droot,if=3Dnone,id=3Droot,format=3Draw \ -device vmapple-virtio-root,drive=3Droot With all these in place, you should be able to see macOS booting successfully. Known issues: - Keyboard and mouse/tablet input is laggy. The reason for this is either that macOS's XHCI driver is broken when the device/platform does not support MSI/MSI-X, or there's some unfortunate interplay with Qemu's XHCI implementation in this scenario. - Currently only macOS 12 guests are supported. The boot process for 13+ will need further investigation and adjustment. Signed-off-by: Alexander Graf Co-authored-by: Phil Dennis-Jordan Signed-off-by: Phil Dennis-Jordan --- v3: * Rebased on latest upstream, updated affinity and NIC creation API usage * Included Apple-variant virtio-blk in build dependency * Updated API usage for setting 'redist-region-count' array-typed property= on GIC. * Switched from virtio HID devices (for which macOS 12 does not contain dr= ivers) to an XHCI USB controller and USB HID devices. MAINTAINERS | 1 + docs/system/arm/vmapple.rst | 63 ++++ docs/system/target-arm.rst | 1 + hw/vmapple/Kconfig | 20 ++ hw/vmapple/meson.build | 1 + hw/vmapple/vmapple.c | 661 ++++++++++++++++++++++++++++++++++++ 6 files changed, 747 insertions(+) create mode 100644 docs/system/arm/vmapple.rst create mode 100644 hw/vmapple/vmapple.c diff --git a/MAINTAINERS b/MAINTAINERS index 4e7f25e5299..89ef071a01a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2783,6 +2783,7 @@ R: Phil Dennis-Jordan S: Maintained F: hw/vmapple/* F: include/hw/vmapple/* +F: docs/system/arm/vmapple.rst =20 Subsystems ---------- diff --git a/docs/system/arm/vmapple.rst b/docs/system/arm/vmapple.rst new file mode 100644 index 00000000000..acb921ffb35 --- /dev/null +++ b/docs/system/arm/vmapple.rst @@ -0,0 +1,63 @@ +VMApple machine emulation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +VMApple is the device model that the macOS built-in hypervisor called "Vir= tualization.framework" +exposes to Apple Silicon macOS guests. The "vmapple" machine model in QEMU= implements the same +device model, but does not use any code from Virtualization.Framework. + +Prerequisites +------------- + +To run the vmapple machine model, you need to + + * Run on Apple Silicon + * Run on macOS 12.0 or above + * Have an already installed copy of a Virtualization.Framework macOS 12 v= irtual machine. I will + assume that you installed it using the macosvm CLI. + +First, we need to extract the UUID from the virtual machine that you insta= lled. You can do this +by running the following shell script: + +.. code-block:: bash + :caption: uuid.sh script to extract the UUID from a macosvm.json file + + #!/bin/bash + + MID=3D$(cat "$1" | python3 -c 'import json,sys;obj=3Djson.load(sys.stdin= );print(obj["machineId"]);') + echo "$MID" | base64 -d | plutil -extract ECID raw - + +Now we also need to trim the aux partition. It contains metadata that we c= an just discard: + +.. code-block:: bash + :caption: Command to trim the aux file + + $ dd if=3D"aux.img" of=3D"aux.img.trimmed" bs=3D$(( 0x4000 )) skip=3D1 + +How to run +---------- + +Then, we can launch QEMU with the Virtualization.Framework pre-boot enviro= nment and the readily +installed target disk images. I recommend to port forward the VM's ssh and= vnc ports to the host +to get better interactive access into the target system: + +.. code-block:: bash + :caption: Example execution command line + + $ UUID=3D$(uuid.sh macosvm.json) + $ AVPBOOTER=3D/System/Library/Frameworks/Virtualization.framework/Resour= ces/AVPBooter.vmapple2.bin + $ AUX=3Daux.img.trimmed + $ DISK=3Ddisk.img + $ qemu-system-aarch64 \ + -serial mon:stdio \ + -m 4G \ + -accel hvf \ + -M vmapple,uuid=3D$UUID \ + -bios $AVPBOOTER \ + -drive file=3D"$AUX",if=3Dpflash,format=3Draw \ + -drive file=3D"$DISK",if=3Dpflash,format=3Draw \ + -drive file=3D"$AUX",if=3Dnone,id=3Daux,format=3Draw \ + -drive file=3D"$DISK",if=3Dnone,id=3Droot,format=3Draw \ + -device vmapple-virtio-aux,drive=3Daux \ + -device vmapple-virtio-root,drive=3Droot \ + -net user,ipv6=3Doff,hostfwd=3Dtcp::2222-:22,hostfwd=3Dtcp::5901-:5= 900 \ + -net nic,model=3Dvirtio-net-pci \ diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst index 7b992722846..f1948abb545 100644 --- a/docs/system/target-arm.rst +++ b/docs/system/target-arm.rst @@ -107,6 +107,7 @@ undocumented; you can get a complete list by running arm/stellaris arm/stm32 arm/virt + arm/vmapple arm/xenpvh arm/xlnx-versal-virt arm/xlnx-zynq diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig index bcd1be63e3c..0f83d4259fc 100644 --- a/hw/vmapple/Kconfig +++ b/hw/vmapple/Kconfig @@ -10,3 +10,23 @@ config VMAPPLE_CFG config VMAPPLE_VIRTIO_BLK bool =20 +config VMAPPLE + bool + depends on ARM + depends on HVF + default y if ARM + imply PCI_DEVICES + select ARM_GIC + select PLATFORM_BUS + select PCI_EXPRESS + select PCI_EXPRESS_GENERIC_BRIDGE + select PL011 # UART + select PL031 # RTC + select PL061 # GPIO + select GPIO_PWR + select PVPANIC_MMIO + select VMAPPLE_AES + select VMAPPLE_BDIF + select VMAPPLE_CFG + select MAC_PVG_VMAPPLE + select VMAPPLE_VIRTIO_BLK diff --git a/hw/vmapple/meson.build b/hw/vmapple/meson.build index bf17cf906c9..e572f7d5602 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')) system_ss.add(when: 'CONFIG_VMAPPLE_VIRTIO_BLK', if_true: files('virtio-b= lk.c')) +specific_ss.add(when: 'CONFIG_VMAPPLE', if_true: files('vmapple.c')) diff --git a/hw/vmapple/vmapple.c b/hw/vmapple/vmapple.c new file mode 100644 index 00000000000..f0060a6f7ee --- /dev/null +++ b/hw/vmapple/vmapple.c @@ -0,0 +1,661 @@ +/* + * VMApple machine emulation + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * 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. + * + * VMApple is the device model that the macOS built-in hypervisor called + * "Virtualization.framework" exposes to Apple Silicon macOS guests. The + * machine model in this file implements the same device model in QEMU, but + * does not use any code from Virtualization.Framework. + */ + +#include "qemu/osdep.h" +#include "qemu/help-texts.h" +#include "qemu/datadir.h" +#include "qemu/units.h" +#include "qemu/option.h" +#include "monitor/qdev.h" +#include "hw/sysbus.h" +#include "hw/arm/boot.h" +#include "hw/arm/primecell.h" +#include "hw/boards.h" +#include "hw/usb.h" +#include "net/net.h" +#include "sysemu/sysemu.h" +#include "sysemu/runstate.h" +#include "sysemu/kvm.h" +#include "sysemu/hvf.h" +#include "hw/loader.h" +#include "qapi/error.h" +#include "qapi/qmp/qlist.h" +#include "qemu/bitops.h" +#include "qemu/error-report.h" +#include "qemu/module.h" +#include "hw/pci-host/gpex.h" +#include "hw/virtio/virtio-pci.h" +#include "hw/qdev-properties.h" +#include "hw/intc/arm_gic.h" +#include "hw/intc/arm_gicv3_common.h" +#include "hw/irq.h" +#include "hw/usb/xhci.h" +#include "qapi/visitor.h" +#include "qapi/qapi-visit-common.h" +#include "standard-headers/linux/input.h" +#include "target/arm/internals.h" +#include "target/arm/kvm_arm.h" +#include "hw/char/pl011.h" +#include "qemu/guest-random.h" +#include "sysemu/reset.h" +#include "qemu/log.h" +#include "hw/vmapple/cfg.h" +#include "hw/misc/pvpanic.h" +#include "hw/vmapple/bdif.h" + +struct VMAppleMachineClass { + MachineClass parent; +}; + +struct VMAppleMachineState { + MachineState parent; + =20 + Notifier machine_done; + struct arm_boot_info bootinfo; + MemMapEntry *memmap; + const int *irqmap; + DeviceState *gic; + DeviceState *cfg; + Notifier powerdown_notifier; + PCIBus *bus; + MemoryRegion fw_mr; + uint64_t uuid; +}; + +#define DEFINE_VMAPPLE_MACHINE_LATEST(major, minor, latest) \ + static void vmapple##major##_##minor##_class_init(ObjectClass *oc, \ + void *data) \ + { \ + MachineClass *mc =3D MACHINE_CLASS(oc); \ + vmapple_machine_##major##_##minor##_options(mc); \ + mc->desc =3D "QEMU " # major "." # minor " Apple Virtual Machine";= \ + if (latest) { \ + mc->alias =3D "vmapple"; \ + } \ + } \ + static const TypeInfo machvmapple##major##_##minor##_info =3D { \ + .name =3D MACHINE_TYPE_NAME("vmapple-" # major "." # minor), \ + .parent =3D TYPE_VMAPPLE_MACHINE, \ + .class_init =3D vmapple##major##_##minor##_class_init, \ + }; \ + static void machvmapple_machine_##major##_##minor##_init(void) \ + { \ + type_register_static(&machvmapple##major##_##minor##_info); \ + } \ + type_init(machvmapple_machine_##major##_##minor##_init); + +#define DEFINE_VMAPPLE_MACHINE_AS_LATEST(major, minor) \ + DEFINE_VMAPPLE_MACHINE_LATEST(major, minor, true) +#define DEFINE_VMAPPLE_MACHINE(major, minor) \ + DEFINE_VMAPPLE_MACHINE_LATEST(major, minor, false) + +#define TYPE_VMAPPLE_MACHINE MACHINE_TYPE_NAME("vmapple") +OBJECT_DECLARE_TYPE(VMAppleMachineState, VMAppleMachineClass, VMAPPLE_MACH= INE) + +/* Number of external interrupt lines to configure the GIC with */ +#define NUM_IRQS 256 + +enum { + VMAPPLE_FIRMWARE, + VMAPPLE_CONFIG, + VMAPPLE_MEM, + VMAPPLE_GIC_DIST, + VMAPPLE_GIC_REDIST, + VMAPPLE_UART, + VMAPPLE_RTC, + VMAPPLE_PCIE, + VMAPPLE_PCIE_MMIO, + VMAPPLE_PCIE_ECAM, + VMAPPLE_GPIO, + VMAPPLE_PVPANIC, + VMAPPLE_APV_GFX, + VMAPPLE_APV_IOSFC, + VMAPPLE_AES_1, + VMAPPLE_AES_2, + VMAPPLE_BDOOR, + VMAPPLE_MEMMAP_LAST, +}; + +static MemMapEntry memmap[] =3D { + [VMAPPLE_FIRMWARE] =3D { 0x00100000, 0x00100000 }, + [VMAPPLE_CONFIG] =3D { 0x00400000, 0x00010000 }, + + [VMAPPLE_GIC_DIST] =3D { 0x10000000, 0x00010000 }, + [VMAPPLE_GIC_REDIST] =3D { 0x10010000, 0x00400000 }, + + [VMAPPLE_UART] =3D { 0x20010000, 0x00010000 }, + [VMAPPLE_RTC] =3D { 0x20050000, 0x00001000 }, + [VMAPPLE_GPIO] =3D { 0x20060000, 0x00001000 }, + [VMAPPLE_PVPANIC] =3D { 0x20070000, 0x00000002 }, + [VMAPPLE_BDOOR] =3D { 0x30000000, 0x00200000 }, + [VMAPPLE_APV_GFX] =3D { 0x30200000, 0x00010000 }, + [VMAPPLE_APV_IOSFC] =3D { 0x30210000, 0x00010000 }, + [VMAPPLE_AES_1] =3D { 0x30220000, 0x00004000 }, + [VMAPPLE_AES_2] =3D { 0x30230000, 0x00004000 }, + [VMAPPLE_PCIE_ECAM] =3D { 0x40000000, 0x10000000 }, + [VMAPPLE_PCIE_MMIO] =3D { 0x50000000, 0x1fff0000 }, + + /* Actual RAM size depends on configuration */ + [VMAPPLE_MEM] =3D { 0x70000000ULL, GiB}, +}; + +static const int irqmap[] =3D { + [VMAPPLE_UART] =3D 1, + [VMAPPLE_RTC] =3D 2, + [VMAPPLE_GPIO] =3D 0x5, + [VMAPPLE_APV_IOSFC] =3D 0x10, + [VMAPPLE_APV_GFX] =3D 0x11, + [VMAPPLE_AES_1] =3D 0x12, + [VMAPPLE_PCIE] =3D 0x20, +}; + +#define GPEX_NUM_IRQS 16 + +static void create_bdif(VMAppleMachineState *vms, MemoryRegion *mem) +{ + DeviceState *bdif; + SysBusDevice *bdif_sb; + DriveInfo *di_aux =3D drive_get(IF_PFLASH, 0, 0); + DriveInfo *di_root =3D drive_get(IF_PFLASH, 0, 1); + + if (!di_aux) { + error_report("No AUX device found. Please specify one as pflash dr= ive"); + exit(1); + } + + if (!di_root) { + /* Fall back to the first IF_VIRTIO device as root device */ + di_root =3D drive_get(IF_VIRTIO, 0, 0); + } + + if (!di_root) { + error_report("No root device found. Please specify one as virtio d= rive"); + exit(1); + } + + /* PV backdoor device */ + bdif =3D qdev_new(TYPE_VMAPPLE_BDIF); + bdif_sb =3D SYS_BUS_DEVICE(bdif); + sysbus_mmio_map(bdif_sb, 0, vms->memmap[VMAPPLE_BDOOR].base); + + qdev_prop_set_drive(DEVICE(bdif), "aux", blk_by_legacy_dinfo(di_aux)); + qdev_prop_set_drive(DEVICE(bdif), "root", blk_by_legacy_dinfo(di_root)= ); + + sysbus_realize_and_unref(bdif_sb, &error_fatal); +} + +static void create_pvpanic(VMAppleMachineState *vms, MemoryRegion *mem) +{ + SysBusDevice *cfg; + + vms->cfg =3D qdev_new(TYPE_PVPANIC_MMIO_DEVICE); + cfg =3D SYS_BUS_DEVICE(vms->cfg); + sysbus_mmio_map(cfg, 0, vms->memmap[VMAPPLE_PVPANIC].base); + + sysbus_realize_and_unref(cfg, &error_fatal); +} + +static void create_cfg(VMAppleMachineState *vms, MemoryRegion *mem) +{ + SysBusDevice *cfg; + MachineState *machine =3D MACHINE(vms); + uint32_t rnd =3D 1; + + vms->cfg =3D qdev_new(TYPE_VMAPPLE_CFG); + cfg =3D SYS_BUS_DEVICE(vms->cfg); + sysbus_mmio_map(cfg, 0, vms->memmap[VMAPPLE_CONFIG].base); + + qemu_guest_getrandom_nofail(&rnd, sizeof(rnd)); + + qdev_prop_set_uint32(vms->cfg, "nr-cpus", machine->smp.cpus); + qdev_prop_set_uint64(vms->cfg, "ecid", vms->uuid); + qdev_prop_set_uint64(vms->cfg, "ram-size", machine->ram_size); + qdev_prop_set_uint32(vms->cfg, "rnd", rnd); + + sysbus_realize_and_unref(cfg, &error_fatal); +} + +static void create_gfx(VMAppleMachineState *vms, MemoryRegion *mem) +{ + int irq_gfx =3D vms->irqmap[VMAPPLE_APV_GFX]; + int irq_iosfc =3D vms->irqmap[VMAPPLE_APV_IOSFC]; + SysBusDevice *aes; + + aes =3D SYS_BUS_DEVICE(qdev_new("apple-gfx-vmapple")); + sysbus_mmio_map(aes, 0, vms->memmap[VMAPPLE_APV_GFX].base); + sysbus_mmio_map(aes, 1, vms->memmap[VMAPPLE_APV_IOSFC].base); + sysbus_connect_irq(aes, 0, qdev_get_gpio_in(vms->gic, irq_gfx)); + sysbus_connect_irq(aes, 1, qdev_get_gpio_in(vms->gic, irq_iosfc)); + sysbus_realize_and_unref(aes, &error_fatal); +} + +static void create_aes(VMAppleMachineState *vms, MemoryRegion *mem) +{ + int irq =3D vms->irqmap[VMAPPLE_AES_1]; + SysBusDevice *aes; + + aes =3D SYS_BUS_DEVICE(qdev_new("apple-aes")); + sysbus_mmio_map(aes, 0, vms->memmap[VMAPPLE_AES_1].base); + sysbus_mmio_map(aes, 1, vms->memmap[VMAPPLE_AES_2].base); + sysbus_connect_irq(aes, 0, qdev_get_gpio_in(vms->gic, irq)); + sysbus_realize_and_unref(aes, &error_fatal); +} + +static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index) +{ + return NUM_IRQS + cpu_nr * GIC_INTERNAL + ppi_index; +} + +static void create_gic(VMAppleMachineState *vms, MemoryRegion *mem) +{ + MachineState *ms =3D MACHINE(vms); + /* We create a standalone GIC */ + SysBusDevice *gicbusdev; + QList *redist_region_count; + int i; + unsigned int smp_cpus =3D ms->smp.cpus; + + vms->gic =3D qdev_new(gicv3_class_name()); + qdev_prop_set_uint32(vms->gic, "revision", 3); + qdev_prop_set_uint32(vms->gic, "num-cpu", smp_cpus); + /* + * Note that the num-irq property counts both internal and external + * interrupts; there are always 32 of the former (mandated by GIC spec= ). + */ + qdev_prop_set_uint32(vms->gic, "num-irq", NUM_IRQS + 32); + + uint32_t redist0_capacity =3D + vms->memmap[VMAPPLE_GIC_REDIST].size / GICV3_REDIST_SIZE; + uint32_t redist0_count =3D MIN(smp_cpus, redist0_capacity); + + redist_region_count =3D qlist_new(); + qlist_append_int(redist_region_count, redist0_count); + qdev_prop_set_array(vms->gic, "redist-region-count", redist_region_cou= nt); + + gicbusdev =3D SYS_BUS_DEVICE(vms->gic); + sysbus_realize_and_unref(gicbusdev, &error_fatal); + sysbus_mmio_map(gicbusdev, 0, vms->memmap[VMAPPLE_GIC_DIST].base); + sysbus_mmio_map(gicbusdev, 1, vms->memmap[VMAPPLE_GIC_REDIST].base); + + /* + * Wire the outputs from each CPU's generic timer and the GICv3 + * maintenance interrupt signal to the appropriate GIC PPI inputs, + * and the GIC's IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU's inpu= ts. + */ + for (i =3D 0; i < smp_cpus; i++) { + DeviceState *cpudev =3D DEVICE(qemu_get_cpu(i)); + + /* Map the virt timer to PPI 27 */ + qdev_connect_gpio_out(cpudev, GTIMER_VIRT, + qdev_get_gpio_in(vms->gic, + arm_gic_ppi_index(i, 27))); + + /* Map the GIC IRQ and FIQ lines to CPU */ + sysbus_connect_irq(gicbusdev, i, qdev_get_gpio_in(cpudev, ARM_CPU_= IRQ)); + sysbus_connect_irq(gicbusdev, i + smp_cpus, + qdev_get_gpio_in(cpudev, ARM_CPU_FIQ)); + } +} + +static void create_uart(const VMAppleMachineState *vms, int uart, + MemoryRegion *mem, Chardev *chr) +{ + hwaddr base =3D vms->memmap[uart].base; + int irq =3D vms->irqmap[uart]; + DeviceState *dev =3D qdev_new(TYPE_PL011); + SysBusDevice *s =3D SYS_BUS_DEVICE(dev); + + qdev_prop_set_chr(dev, "chardev", chr); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + memory_region_add_subregion(mem, base, + sysbus_mmio_get_region(s, 0)); + sysbus_connect_irq(s, 0, qdev_get_gpio_in(vms->gic, irq)); +} + +static void create_rtc(const VMAppleMachineState *vms) +{ + hwaddr base =3D vms->memmap[VMAPPLE_RTC].base; + int irq =3D vms->irqmap[VMAPPLE_RTC]; + + sysbus_create_simple("pl031", base, qdev_get_gpio_in(vms->gic, irq)); +} + +static DeviceState *gpio_key_dev; +static void vmapple_powerdown_req(Notifier *n, void *opaque) +{ + /* use gpio Pin 3 for power button event */ + qemu_set_irq(qdev_get_gpio_in(gpio_key_dev, 0), 1); +} + +static void create_gpio_devices(const VMAppleMachineState *vms, int gpio, + MemoryRegion *mem) +{ + DeviceState *pl061_dev; + hwaddr base =3D vms->memmap[gpio].base; + int irq =3D vms->irqmap[gpio]; + SysBusDevice *s; + + pl061_dev =3D qdev_new("pl061"); + /* Pull lines down to 0 if not driven by the PL061 */ + qdev_prop_set_uint32(pl061_dev, "pullups", 0); + qdev_prop_set_uint32(pl061_dev, "pulldowns", 0xff); + s =3D SYS_BUS_DEVICE(pl061_dev); + sysbus_realize_and_unref(s, &error_fatal); + memory_region_add_subregion(mem, base, sysbus_mmio_get_region(s, 0)); + sysbus_connect_irq(s, 0, qdev_get_gpio_in(vms->gic, irq)); + gpio_key_dev =3D sysbus_create_simple("gpio-key", -1, + qdev_get_gpio_in(pl061_dev, 3)); +} + +static void vmapple_firmware_init(VMAppleMachineState *vms, + MemoryRegion *sysmem) +{ + hwaddr size =3D vms->memmap[VMAPPLE_FIRMWARE].size; + hwaddr base =3D vms->memmap[VMAPPLE_FIRMWARE].base; + const char *bios_name; + int image_size; + char *fname; + + bios_name =3D MACHINE(vms)->firmware; + if (!bios_name) { + error_report("No firmware specified"); + exit(1); + } + + fname =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); + if (!fname) { + error_report("Could not find ROM image '%s'", bios_name); + exit(1); + } + + memory_region_init_ram(&vms->fw_mr, NULL, "firmware", size, NULL); + image_size =3D load_image_mr(fname, &vms->fw_mr); + + g_free(fname); + if (image_size < 0) { + error_report("Could not load ROM image '%s'", bios_name); + exit(1); + } + + memory_region_add_subregion(get_system_memory(), base, &vms->fw_mr); +} + +static void create_pcie(VMAppleMachineState *vms) +{ + hwaddr base_mmio =3D vms->memmap[VMAPPLE_PCIE_MMIO].base; + hwaddr size_mmio =3D vms->memmap[VMAPPLE_PCIE_MMIO].size; + hwaddr base_ecam =3D vms->memmap[VMAPPLE_PCIE_ECAM].base; + hwaddr size_ecam =3D vms->memmap[VMAPPLE_PCIE_ECAM].size; + int irq =3D vms->irqmap[VMAPPLE_PCIE]; + MemoryRegion *mmio_alias; + MemoryRegion *mmio_reg; + MemoryRegion *ecam_alias; + MemoryRegion *ecam_reg; + DeviceState *dev; + int i; + PCIHostState *pci; + DeviceState *usb_controller; + USBBus *usb_bus; + + dev =3D qdev_new(TYPE_GPEX_HOST); + qdev_prop_set_uint32(dev, "nr-irqs", GPEX_NUM_IRQS); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + + /* Map only the first size_ecam bytes of ECAM space */ + ecam_alias =3D g_new0(MemoryRegion, 1); + ecam_reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); + memory_region_init_alias(ecam_alias, OBJECT(dev), "pcie-ecam", + ecam_reg, 0, size_ecam); + memory_region_add_subregion(get_system_memory(), base_ecam, ecam_alias= ); + + /* + * Map the MMIO window from [0x50000000-0x7fff0000] in PCI space into + * system address space at [0x50000000-0x7fff0000]. + */ + mmio_alias =3D g_new0(MemoryRegion, 1); + mmio_reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); + memory_region_init_alias(mmio_alias, OBJECT(dev), "pcie-mmio", + mmio_reg, base_mmio, size_mmio); + memory_region_add_subregion(get_system_memory(), base_mmio, mmio_alias= ); + + for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, + qdev_get_gpio_in(vms->gic, irq + i)); + gpex_set_irq_num(GPEX_HOST(dev), i, irq + i); + } + + pci =3D PCI_HOST_BRIDGE(dev); + vms->bus =3D pci->bus; + g_assert_nonnull(vms->bus); + + while ((dev =3D qemu_create_nic_device("virtio-net-pci", true, NULL)))= { + qdev_realize_and_unref(dev, BUS(vms->bus), &error_fatal); + } + + usb_controller =3D qdev_new(TYPE_QEMU_XHCI); + qdev_realize_and_unref(usb_controller, BUS(pci->bus), &error_fatal); + + usb_bus =3D USB_BUS(object_resolve_type_unambiguous(TYPE_USB_BUS, + &error_fatal)); + usb_create_simple(usb_bus, "usb-kbd"); + usb_create_simple(usb_bus, "usb-tablet"); +} + +static void vmapple_reset(void *opaque) +{ + VMAppleMachineState *vms =3D opaque; + hwaddr base =3D vms->memmap[VMAPPLE_FIRMWARE].base; + + cpu_set_pc(first_cpu, base); +} + +static void mach_vmapple_init(MachineState *machine) +{ + VMAppleMachineState *vms =3D VMAPPLE_MACHINE(machine); + MachineClass *mc =3D MACHINE_GET_CLASS(machine); + const CPUArchIdList *possible_cpus; + MemoryRegion *sysmem =3D get_system_memory(); + int n; + unsigned int smp_cpus =3D machine->smp.cpus; + unsigned int max_cpus =3D machine->smp.max_cpus; + + vms->memmap =3D memmap; + machine->usb =3D true; + + possible_cpus =3D mc->possible_cpu_arch_ids(machine); + assert(possible_cpus->len =3D=3D max_cpus); + for (n =3D 0; n < possible_cpus->len; n++) { + Object *cpu; + CPUState *cs; + + if (n >=3D smp_cpus) { + break; + } + + cpu =3D object_new(possible_cpus->cpus[n].type); + object_property_set_int(cpu, "mp-affinity", + possible_cpus->cpus[n].arch_id, NULL); + + cs =3D CPU(cpu); + cs->cpu_index =3D n; + + numa_cpu_pre_plug(&possible_cpus->cpus[cs->cpu_index], DEVICE(cpu), + &error_fatal); + + object_property_set_bool(cpu, "has_el3", false, NULL); + object_property_set_bool(cpu, "has_el2", false, NULL); + object_property_set_int(cpu, "psci-conduit", QEMU_PSCI_CONDUIT_HVC, + NULL); + + /* Secondary CPUs start in PSCI powered-down state */ + if (n > 0) { + object_property_set_bool(cpu, "start-powered-off", true, NULL); + } + + object_property_set_link(cpu, "memory", OBJECT(sysmem), &error_abo= rt); + qdev_realize(DEVICE(cpu), NULL, &error_fatal); + object_unref(cpu); + } + + memory_region_add_subregion(sysmem, vms->memmap[VMAPPLE_MEM].base, + machine->ram); + + create_gic(vms, sysmem); + create_bdif(vms, sysmem); + create_pvpanic(vms, sysmem); + create_aes(vms, sysmem); + create_gfx(vms, sysmem); + create_uart(vms, VMAPPLE_UART, sysmem, serial_hd(0)); + create_rtc(vms); + create_pcie(vms); + + create_gpio_devices(vms, VMAPPLE_GPIO, sysmem); + + vmapple_firmware_init(vms, sysmem); + create_cfg(vms, sysmem); + + /* connect powerdown request */ + vms->powerdown_notifier.notify =3D vmapple_powerdown_req; + qemu_register_powerdown_notifier(&vms->powerdown_notifier); + + vms->bootinfo.ram_size =3D machine->ram_size; + vms->bootinfo.board_id =3D -1; + vms->bootinfo.loader_start =3D vms->memmap[VMAPPLE_MEM].base; + vms->bootinfo.skip_dtb_autoload =3D true; + vms->bootinfo.firmware_loaded =3D true; + arm_load_kernel(ARM_CPU(first_cpu), machine, &vms->bootinfo); + + qemu_register_reset(vmapple_reset, vms); +} + +static CpuInstanceProperties +vmapple_cpu_index_to_props(MachineState *ms, unsigned cpu_index) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + const CPUArchIdList *possible_cpus =3D mc->possible_cpu_arch_ids(ms); + + assert(cpu_index < possible_cpus->len); + return possible_cpus->cpus[cpu_index].props; +} + + +static int64_t vmapple_get_default_cpu_node_id(const MachineState *ms, int= idx) +{ + return idx % ms->numa_state->num_nodes; +} + +static const CPUArchIdList *vmapple_possible_cpu_arch_ids(MachineState *ms) +{ + int n; + unsigned int max_cpus =3D ms->smp.max_cpus; + + if (ms->possible_cpus) { + assert(ms->possible_cpus->len =3D=3D max_cpus); + return ms->possible_cpus; + } + + ms->possible_cpus =3D g_malloc0(sizeof(CPUArchIdList) + + sizeof(CPUArchId) * max_cpus); + ms->possible_cpus->len =3D max_cpus; + for (n =3D 0; n < ms->possible_cpus->len; n++) { + ms->possible_cpus->cpus[n].type =3D ms->cpu_type; + ms->possible_cpus->cpus[n].arch_id =3D + arm_build_mp_affinity(n, GICV3_TARGETLIST_BITS); + ms->possible_cpus->cpus[n].props.has_thread_id =3D true; + ms->possible_cpus->cpus[n].props.thread_id =3D n; + } + return ms->possible_cpus; +} + +static void vmapple_get_uuid(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + VMAppleMachineState *vms =3D VMAPPLE_MACHINE(obj); + uint64_t value =3D be64_to_cpu(vms->uuid); + + visit_type_uint64(v, name, &value, errp); +} + +static void vmapple_set_uuid(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + VMAppleMachineState *vms =3D VMAPPLE_MACHINE(obj); + Error *error =3D NULL; + uint64_t value; + + visit_type_uint64(v, name, &value, &error); + if (error) { + error_propagate(errp, error); + return; + } + + vms->uuid =3D cpu_to_be64(value); +} + +static void vmapple_machine_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->init =3D mach_vmapple_init; + mc->max_cpus =3D 32; + mc->block_default_type =3D IF_VIRTIO; + mc->no_cdrom =3D 1; + mc->pci_allow_0_address =3D true; + mc->minimum_page_bits =3D 12; + mc->possible_cpu_arch_ids =3D vmapple_possible_cpu_arch_ids; + mc->cpu_index_to_instance_props =3D vmapple_cpu_index_to_props; + if (hvf_enabled()) { + mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("host"); + } else { + mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("max"); + } + mc->get_default_cpu_node_id =3D vmapple_get_default_cpu_node_id; + mc->default_ram_id =3D "mach-vmapple.ram"; + + object_register_sugar_prop(TYPE_VIRTIO_PCI, "disable-legacy", + "on", true); + + object_class_property_add(oc, "uuid", "uint64", vmapple_get_uuid, + vmapple_set_uuid, NULL, NULL); + object_class_property_set_description(oc, "uuid", "Machine UUID (SDOM)= "); +} + +static void vmapple_instance_init(Object *obj) +{ + VMAppleMachineState *vms =3D VMAPPLE_MACHINE(obj); + + vms->irqmap =3D irqmap; +} + +static const TypeInfo vmapple_machine_info =3D { + .name =3D TYPE_VMAPPLE_MACHINE, + .parent =3D TYPE_MACHINE, + .abstract =3D true, + .instance_size =3D sizeof(VMAppleMachineState), + .class_size =3D sizeof(VMAppleMachineClass), + .class_init =3D vmapple_machine_class_init, + .instance_init =3D vmapple_instance_init, +}; + +static void machvmapple_machine_init(void) +{ + type_register_static(&vmapple_machine_info); +} +type_init(machvmapple_machine_init); + +static void vmapple_machine_8_1_options(MachineClass *mc) +{ +} +DEFINE_VMAPPLE_MACHINE_AS_LATEST(8, 1) + --=20 2.39.3 (Apple Git-145)