From patchwork Mon May 27 17:15:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13675661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 381ACC25B74 for ; Mon, 27 May 2024 17:16:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBdwQ-0002zT-OU; Mon, 27 May 2024 13:15:23 -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 1sBdwM-0002yD-V6 for qemu-devel@nongnu.org; Mon, 27 May 2024 13:15:18 -0400 Received: from wfhigh3-smtp.messagingengine.com ([64.147.123.154]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBdwG-0004dO-JB for qemu-devel@nongnu.org; Mon, 27 May 2024 13:15:18 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id F294F1800110; Mon, 27 May 2024 13:15:08 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 27 May 2024 13:15:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1716830108; x=1716916508; bh=hYYUXh07/gcoXF51WzyMOORAJzyXrEZcGGa7G4S/qJM=; b= Unrv661kj8kfAT4BKmuCw9HE+V/+Tjdmw6p2GaDTLYpDD5hozbLpez4RrylRBkcG syTtZZGcc3RCO/f5xZ1McVMQM+ABtHOFFhrm7Bw6E/mzVY+QsuJM6M1AP1TPu3E+ 0q2VKD1C2ZGBSj6poEx3p5gi9gcCNAuroCfjwL3o7zs+WEf9789F1tqN0z5tzOoq UH7JT95pGnvl9jJNPHjxDqAYdKNLDIHogvrkW7RY0OM4vbLiKge/cuTK5/rafSLY wACg9m8ME13mvQSoSZmrcrdD15gZ8UL7vxwpiEoeuo63x7xbl4BjoJChMViAr2xQ zf08xYqD8AFkIjzofU522w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1716830108; x= 1716916508; bh=hYYUXh07/gcoXF51WzyMOORAJzyXrEZcGGa7G4S/qJM=; b=V 5y6XDXLNce7gPGnUkLVqd5/wfOXw42OI8GOWD0X2zGlx3HXUfVdNn5r3ZLQ2ICl4 YohjUynO1M8kGMdMKgjygqIa8QPJogHQ287on+yi3/g995kE7IUaBRJzxjboeb5C /9qhR3B0NpmApAMxzoX7DI8J9Y0duoWCzXeis1TarMmFn66AVT5WFU7RJyepyVGj c7bEjdJgVdEpE+JsZi/UY71nLWANwLnY0PSEpLJKKijurJcIbUhUE80r5zzRf0qr NB/PV+wLXNC7ZJrpLog2rujrsyAxgnNpWMrQiGPnvhBJ1a+FjA5dNcpvS20AL10+ DQreKhnSpNEBk+cqm0gRQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejgedguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 13:15:07 -0400 (EDT) From: Jiaxun Yang Date: Mon, 27 May 2024 18:15:04 +0100 Subject: [PATCH 1/4] hw/m68k/virt: Add a XHCI controller MIME-Version: 1.0 Message-Id: <20240527-m68k-bios-v1-1-6de26552fa77@flygoat.com> References: <20240527-m68k-bios-v1-0-6de26552fa77@flygoat.com> In-Reply-To: <20240527-m68k-bios-v1-0-6de26552fa77@flygoat.com> To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Laurent Vivier , "Michael S. Tsirkin" , Cornelia Huck , Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3672; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=meVJ+Hif6qYmAV3H2p1MdJpBK1pNp/dXQjk1XyRz74k=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrSQ/TNfLGCflM33ef3eq4G+a00OPzPlFRe70t1rt8/yp +W6vyuMOkpZGMS4GGTFFFlCBJT6NjReXHD9QdYfmDmsTCBDGLg4BWAiylsY/ilP7N1ek7KfLTmm pPeIyLkFnbdUUoW3/XCe02Ju1JXMpM3IsHH+YfbM0z+l6o5P2zMzU6UqlqNNodiw8Jkmn5iWyrI aNgA= X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Received-SPF: pass client-ip=64.147.123.154; envelope-from=jiaxun.yang@flygoat.com; helo=wfhigh3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org VirtIO is somewhat limited on the diversity of devices. We lack proper audio, webcam and so on support on m68k virt machine. This can be improved by providing a XHCI controller, which enables provision of many different discoverable devices. Signed-off-by: Jiaxun Yang --- hw/m68k/Kconfig | 1 + hw/m68k/virt.c | 22 +++++++++++++++++++++- include/standard-headers/asm-m68k/bootinfo-virt.h | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/hw/m68k/Kconfig b/hw/m68k/Kconfig index 0092cda4e9c8..66e63cd60b57 100644 --- a/hw/m68k/Kconfig +++ b/hw/m68k/Kconfig @@ -44,4 +44,5 @@ config M68K_VIRT select GOLDFISH_PIC select GOLDFISH_TTY select GOLDFISH_RTC + select USB_XHCI_SYSBUS select VIRTIO_MMIO diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c index 09bc9bdfefb2..7b3917dcbd2b 100644 --- a/hw/m68k/virt.c +++ b/hw/m68k/virt.c @@ -33,13 +33,16 @@ #include "hw/char/goldfish_tty.h" #include "hw/rtc/goldfish_rtc.h" #include "hw/intc/goldfish_pic.h" +#include "hw/usb/hcd-xhci-sysbus.h" #include "hw/virtio/virtio-mmio.h" #include "hw/virtio/virtio-blk.h" /* * 6 goldfish-pic for CPU IRQ #1 to IRQ #6 * CPU IRQ #1 -> PIC #1 - * IRQ #1 to IRQ #31 -> unused + * IRQ #1 -> virt-ctrl + * IRQ #2 -> xhci + * IRQ #3 to IRQ #31 -> unused * IRQ #32 -> goldfish-tty * CPU IRQ #2 -> PIC #2 * IRQ #1 to IRQ #32 -> virtio-mmio from 1 to 32 @@ -86,6 +89,9 @@ #define VIRT_VIRTIO_MMIO_BASE 0xff010000 /* MMIO: 0xff010000 - 0xff01ffff */ #define VIRT_VIRTIO_IRQ_BASE PIC_IRQ(2, 1) /* PIC: 2, 3, 4, 5, IRQ: ALL */ +#define VIRT_XHCI_MMIO_BASE 0xff020000 /* MMIO: 0xff020000 - 0xff023fff */ +#define VIRT_XHCI_IRQ_BASE PIC_IRQ(1, 2) /* PIC: #1, IRQ: #2 */ + typedef struct { M68kCPU *cpu; hwaddr initial_pc; @@ -216,6 +222,16 @@ static void virt_init(MachineState *machine) io_base += 0x200; } + /* xhci */ + if (machine_usb(machine)) { + dev = qdev_new(TYPE_XHCI_SYSBUS); + qdev_prop_set_uint32(dev, "intrs", 1); + sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, VIRT_XHCI_MMIO_BASE); + sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, + PIC_GPIO(VIRT_XHCI_IRQ_BASE)); + } + if (kernel_filename) { CPUState *cs = CPU(cpu); uint64_t high; @@ -268,6 +284,10 @@ static void virt_init(MachineState *machine) VIRT_CTRL_MMIO_BASE, VIRT_CTRL_IRQ_BASE); BOOTINFO2(param_ptr, BI_VIRT_VIRTIO_BASE, VIRT_VIRTIO_MMIO_BASE, VIRT_VIRTIO_IRQ_BASE); + if (machine_usb(machine)) { + BOOTINFO2(param_ptr, BI_VIRT_XHCI_BASE, + VIRT_XHCI_MMIO_BASE, VIRT_XHCI_IRQ_BASE); + } if (kernel_cmdline) { BOOTINFOSTR(param_ptr, BI_COMMAND_LINE, diff --git a/include/standard-headers/asm-m68k/bootinfo-virt.h b/include/standard-headers/asm-m68k/bootinfo-virt.h index 75ac6bbd7d73..1700c3ada765 100644 --- a/include/standard-headers/asm-m68k/bootinfo-virt.h +++ b/include/standard-headers/asm-m68k/bootinfo-virt.h @@ -16,6 +16,8 @@ /* No longer used -- replaced with BI_RNG_SEED -- but don't reuse this index: * #define BI_VIRT_RNG_SEED 0x8006 */ +#define BI_VIRT_XHCI_BASE 0x8007 + #define VIRT_BOOTI_VERSION MK_BI_VERSION(2, 0) #endif /* _UAPI_ASM_M68K_BOOTINFO_MAC_H */ From patchwork Mon May 27 17:15:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13675663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 75661C41513 for ; Mon, 27 May 2024 17:16:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBdwT-0002zx-Ql; Mon, 27 May 2024 13:15:25 -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 1sBdwK-0002xk-Ni for qemu-devel@nongnu.org; Mon, 27 May 2024 13:15:18 -0400 Received: from wfhigh3-smtp.messagingengine.com ([64.147.123.154]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBdwG-0004dc-Tk for qemu-devel@nongnu.org; Mon, 27 May 2024 13:15:15 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.west.internal (Postfix) with ESMTP id 287CB1800131; Mon, 27 May 2024 13:15:11 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 27 May 2024 13:15:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1716830110; x=1716916510; bh=jvNC3cWl9R/X7w/YW3guvENAd+31abtJId4SHxU/qLQ=; b= CkOt7UyAWVdOclErtyI1KWuvwY43iyJLr2D+Nw3DVGQ4S23KSZlSuekHJ/smj9B5 lCSvagXAeiEFjuVxbUR24EWYF0w2DTx8bJC8J/t5TPx88/nObjDNDlvF4GdlF7mj u2GqIryTY4hSeaf+72+oDYhnkQ6qaPPNfNDfdKrQZUZ+lFFtZlf2MrJXMb/fKKX8 opWGac3/60q6Nmg1YbXrGDNAK/+Xwhu3yubjR8KCsBkB+KMsHQGRRykfjEpBkgkH 6nArJzg3OD8tUPqWQFtkwflVNxR4svY/3k90frnLMqEbz0XFVZZ+SX5qf3XkPzO0 aecRuZy4KjHFWaaAJp3eyA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1716830110; x= 1716916510; bh=jvNC3cWl9R/X7w/YW3guvENAd+31abtJId4SHxU/qLQ=; b=M pK+MJGjXtk8zZ0L+OfYFLcmQAyviiWTXaGXFe2TCwRUbBHinDOXrZqWbPyEe11dy 5XASjU8qBp/OorUiWgNh4WszmXkLUN6GqhGKLyq97Vx+1d87XIm+F1oxVmaqQyRT o93l+DsnHkXXjQcf4/dqZdx2jWeJBbYElvoZihckuhYI94jkD1UjxLOP4d62fgXR R2GC9Y6BKI2jJpxvhnKO0ch0cx9g9v46ZaIyXqhyDF7vr2SbYO2RWFTJtxY8B/QI 5juTYHVAirWV3aiPDbFd+IgBZfFcKwbqYKViq/dK1ngl3TcnfMsXXP7djKRYIjfg DUNDbbqEN91C3l5BpgMuA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejgedguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 13:15:09 -0400 (EDT) From: Jiaxun Yang Date: Mon, 27 May 2024 18:15:05 +0100 Subject: [PATCH 2/4] hw/m68k/virt: Add fw_cfg controller MIME-Version: 1.0 Message-Id: <20240527-m68k-bios-v1-2-6de26552fa77@flygoat.com> References: <20240527-m68k-bios-v1-0-6de26552fa77@flygoat.com> In-Reply-To: <20240527-m68k-bios-v1-0-6de26552fa77@flygoat.com> To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Laurent Vivier , "Michael S. Tsirkin" , Cornelia Huck , Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3889; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=WHIaU6YdNuXiaOECEnngbdVzYw5RB6CGQXmlvSk15Vk=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrSQ/TMf5P7p1fmzcNtuaxHlIlPt/3/mxlb1hG/8ZMa5f UvotVMfO0pZGMS4GGTFFFlCBJT6NjReXHD9QdYfmDmsTCBDGLg4BeAmX2ZkmFtWNGXvH/5+5kam DLUaqZokAS+N9dn/9qXqvT1X2mNTzshwvGJT1/YFCzco+s5WP/vQWEAv169cmCMz7+PZZIutWk6 cAA== X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Received-SPF: pass client-ip=64.147.123.154; envelope-from=jiaxun.yang@flygoat.com; helo=wfhigh3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add a fw_cfg controller to pass essential information to firmware. Signed-off-by: Jiaxun Yang --- hw/m68k/Kconfig | 1 + hw/m68k/virt.c | 25 ++++++++++++++++++++++- include/standard-headers/asm-m68k/bootinfo-virt.h | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/hw/m68k/Kconfig b/hw/m68k/Kconfig index 66e63cd60b57..4501da56ff6d 100644 --- a/hw/m68k/Kconfig +++ b/hw/m68k/Kconfig @@ -40,6 +40,7 @@ config M68K_VIRT default y depends on M68K select M68K_IRQC + select FW_CFG_DMA select VIRT_CTRL select GOLDFISH_PIC select GOLDFISH_TTY diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c index 7b3917dcbd2b..7590e6515ac3 100644 --- a/hw/m68k/virt.c +++ b/hw/m68k/virt.c @@ -42,7 +42,8 @@ * CPU IRQ #1 -> PIC #1 * IRQ #1 -> virt-ctrl * IRQ #2 -> xhci - * IRQ #3 to IRQ #31 -> unused + * IRQ #3 -> fw_cfg + * IRQ #4 to IRQ #31 -> unused * IRQ #32 -> goldfish-tty * CPU IRQ #2 -> PIC #2 * IRQ #1 to IRQ #32 -> virtio-mmio from 1 to 32 @@ -80,6 +81,10 @@ #define VIRT_CTRL_MMIO_BASE 0xff009000 /* MMIO: 0xff009000 - 0xff009fff */ #define VIRT_CTRL_IRQ_BASE PIC_IRQ(1, 1) /* PIC: #1, IRQ: #1 */ +/* 1 fw_cfg */ +#define VIRT_FW_CFG_MMIO_BASE 0xff00a000 /* MMIO: 0xff00a000 - 0xff00afff */ +#define VIRT_FW_CFG_IRQ_BASE PIC_IRQ(1, 3) /* PIC: #1, IRQ: #3 */ + /* * virtio-mmio size is 0x200 bytes * we use 4 goldfish-pic to attach them, @@ -116,6 +121,12 @@ static void rerandomize_rng_seed(void *opaque) be16_to_cpu(*(uint16_t *)rng_seed->data)); } +static void fw_cfg_boot_set(void *opaque, const char *boot_device, + Error **errp) +{ + fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); +} + static void virt_init(MachineState *machine) { M68kCPU *cpu = NULL; @@ -134,6 +145,7 @@ static void virt_init(MachineState *machine) SysBusDevice *sysbus; hwaddr io_base; int i; + FWCfgState *fw_cfg; ResetInfo *reset_info; uint8_t rng_seed[32]; @@ -210,6 +222,15 @@ static void virt_init(MachineState *machine) dev = sysbus_create_simple(TYPE_VIRT_CTRL, VIRT_CTRL_MMIO_BASE, PIC_GPIO(VIRT_CTRL_IRQ_BASE)); + /* fw_cfg */ + fw_cfg = fw_cfg_init_mem_wide(VIRT_FW_CFG_MMIO_BASE + 8, + VIRT_FW_CFG_MMIO_BASE, 8, + VIRT_FW_CFG_MMIO_BASE + 16, + &address_space_memory); + fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); + qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); + rom_set_fw(fw_cfg); + /* virtio-mmio */ io_base = VIRT_VIRTIO_MMIO_BASE; for (i = 0; i < 128; i++) { @@ -288,6 +309,8 @@ static void virt_init(MachineState *machine) BOOTINFO2(param_ptr, BI_VIRT_XHCI_BASE, VIRT_XHCI_MMIO_BASE, VIRT_XHCI_IRQ_BASE); } + BOOTINFO2(param_ptr, BI_VIRT_FW_CFG_BASE, + VIRT_FW_CFG_MMIO_BASE, VIRT_FW_CFG_IRQ_BASE); if (kernel_cmdline) { BOOTINFOSTR(param_ptr, BI_COMMAND_LINE, diff --git a/include/standard-headers/asm-m68k/bootinfo-virt.h b/include/standard-headers/asm-m68k/bootinfo-virt.h index 1700c3ada765..7f90be1aa7bd 100644 --- a/include/standard-headers/asm-m68k/bootinfo-virt.h +++ b/include/standard-headers/asm-m68k/bootinfo-virt.h @@ -17,6 +17,7 @@ * #define BI_VIRT_RNG_SEED 0x8006 */ #define BI_VIRT_XHCI_BASE 0x8007 +#define BI_VIRT_FW_CFG_BASE 0x8008 #define VIRT_BOOTI_VERSION MK_BI_VERSION(2, 0) From patchwork Mon May 27 17:15:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13675660 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 02FBEC25B78 for ; Mon, 27 May 2024 17:16:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBdwQ-0002zB-1K; Mon, 27 May 2024 13:15:22 -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 1sBdwK-0002xl-Nm for qemu-devel@nongnu.org; Mon, 27 May 2024 13:15:18 -0400 Received: from wfout8-smtp.messagingengine.com ([64.147.123.151]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBdwI-0004eM-Qv for qemu-devel@nongnu.org; Mon, 27 May 2024 13:15:16 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 516791C00101; Mon, 27 May 2024 13:15:13 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Mon, 27 May 2024 13:15:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1716830112; x=1716916512; bh=PDOlHUdSMFMmwhGnB9Nfy+pD/I3z/lyl57D5tIw/ew8=; b= FcGHxfH+NkoUyFqYRP9CfD109luutqb74qYMdsoE6y7p4wi3e5n5iH+cReM5WJ6c oKswXt1b95o67ZmZ/7TZ7exD24kN1zHFVrYaoUv9CYehUdEtQAcEC+M16Bq/JgzF 8ATRmoLU/wD8tXcNTQiQWc6rPlrs0btUoJrIJZX5kwANFxDh92m4BuK8/mS322U8 mS1qLjr3fZUPxhtvEHaelyQxuWL7sG0BopPfhvHuFVoqkr/chwVnFOx+7y5NKYUa KFeQdEhx0c8p8BOvV6cnKABfDZ1RTV0EtG32IoU8tqJOc6QOmZA5vHXrqmIXA1bv BZ0Mqh9Uni3AoXDhnK1Kdw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1716830112; x= 1716916512; bh=PDOlHUdSMFMmwhGnB9Nfy+pD/I3z/lyl57D5tIw/ew8=; b=f rPTprox4nwPPx6CcMMH50eWoaBnfdIJ9QfQ2a4BgxPbybsimHVpVB8lKycxA0ttM 9nKYKiZFjCHxClfGzm5VmSzgXAhrecZDgeGzJiESsoJDR3zXQ0Wvouq87pMuhrMe rRSeYVO5LqwuCFZ8WKhy8s/h07tcOd6LTS+aqIjhDThwBlclov9KTRa2eyrm1924 +ivopHIwpqk4OvLnQls+jI0wan/boQsFDFGbxoe2pcdWaTjTmqVgpLM4bzJYFrvB dGk1duLjKFQ6KxxxqpCb10dJzvo1qjHRhwn7SNTCzcF9G2n4wdw5CFO+NHV2h3Iz nH3UFiVEI3CFqFK7g6y1g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejgedguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 13:15:11 -0400 (EDT) From: Jiaxun Yang Date: Mon, 27 May 2024 18:15:06 +0100 Subject: [PATCH 3/4] hw/m68k/virt: Add a pflash controller for BIOS firmware MIME-Version: 1.0 Message-Id: <20240527-m68k-bios-v1-3-6de26552fa77@flygoat.com> References: <20240527-m68k-bios-v1-0-6de26552fa77@flygoat.com> In-Reply-To: <20240527-m68k-bios-v1-0-6de26552fa77@flygoat.com> To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Laurent Vivier , "Michael S. Tsirkin" , Cornelia Huck , Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4712; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=2B4K90KB5IO8QrMlToSRMNmgqJiaPI2aG2lLp41ikuY=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrSQ/TPnSvVwLhSfJSe+5/zDe6z1jjM1rk+xZp6wT0BNy 5fnkL9NRykLgxgXg6yYIkuIgFLfhsaLC64/yPoDM4eVCWQIAxenAExklxfD/+ITwiGnSuKTWaxX BV5LX9i5wY4hu2Tt9IwNX3nq5tfrHWD4XxT/VNXv2tPNkXfUV93dKMrH+W7qH1/jby8mmC6y3C1 twwIA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Received-SPF: pass client-ip=64.147.123.151; envelope-from=jiaxun.yang@flygoat.com; helo=wfout8-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add a 8 MiB pflash controller for BIOS firmware, and boot from it if possible. Signed-off-by: Jiaxun Yang --- hw/m68k/Kconfig | 1 + hw/m68k/virt.c | 44 +++++++++++++++++++++++ include/standard-headers/asm-m68k/bootinfo-virt.h | 1 + 3 files changed, 46 insertions(+) diff --git a/hw/m68k/Kconfig b/hw/m68k/Kconfig index 4501da56ff6d..f233a5948f19 100644 --- a/hw/m68k/Kconfig +++ b/hw/m68k/Kconfig @@ -42,6 +42,7 @@ config M68K_VIRT select M68K_IRQC select FW_CFG_DMA select VIRT_CTRL + select PFLASH_CFI01 select GOLDFISH_PIC select GOLDFISH_TTY select GOLDFISH_RTC diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c index 7590e6515ac3..a2eebc0f2243 100644 --- a/hw/m68k/virt.c +++ b/hw/m68k/virt.c @@ -8,6 +8,7 @@ */ #include "qemu/osdep.h" +#include "qemu/datadir.h" #include "qemu/units.h" #include "qemu/guest-random.h" #include "sysemu/sysemu.h" @@ -28,6 +29,7 @@ #include "sysemu/runstate.h" #include "sysemu/reset.h" +#include "hw/block/flash.h" #include "hw/intc/m68k_irqc.h" #include "hw/misc/virt_ctrl.h" #include "hw/char/goldfish_tty.h" @@ -97,6 +99,10 @@ #define VIRT_XHCI_MMIO_BASE 0xff020000 /* MMIO: 0xff020000 - 0xff023fff */ #define VIRT_XHCI_IRQ_BASE PIC_IRQ(1, 2) /* PIC: #1, IRQ: #2 */ +#define VIRT_PFLASH_MMIO_BASE 0xff800000 /* MMIO: 0xff800000 - 0xffffffff */ +#define VIRT_PFLASH_SIZE 0x800000 /* 8 MiB */ +#define VIRT_PFLASH_SECTOR_SIZE (128 * KiB) /* 64 KiB */ + typedef struct { M68kCPU *cpu; hwaddr initial_pc; @@ -139,6 +145,7 @@ static void virt_init(MachineState *machine) const char *initrd_filename = machine->initrd_filename; const char *kernel_cmdline = machine->kernel_cmdline; hwaddr parameters_base; + DriveInfo *dinfo; DeviceState *dev; DeviceState *irqc_dev; DeviceState *pic_dev[VIRT_GF_PIC_NB]; @@ -165,6 +172,8 @@ static void virt_init(MachineState *machine) cpu = M68K_CPU(cpu_create(machine->cpu_type)); reset_info->cpu = cpu; + reset_info->initial_pc = VIRT_PFLASH_MMIO_BASE; + reset_info->initial_stack = ram_size; qemu_register_reset(main_cpu_reset, reset_info); /* RAM */ @@ -253,6 +262,39 @@ static void virt_init(MachineState *machine) PIC_GPIO(VIRT_XHCI_IRQ_BASE)); } + /* pflash */ + dinfo = drive_get(IF_PFLASH, 0, 0); + pflash_cfi01_register(VIRT_PFLASH_MMIO_BASE, + "virt.pflash0", + VIRT_PFLASH_SIZE, + dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, + VIRT_PFLASH_SECTOR_SIZE, 4, + 0x89, 0x18, 0, 0, 1); + + if (machine->firmware) { + char *fn; + int image_size; + + if (drive_get(IF_PFLASH, 0, 0)) { + error_report("The contents of the first flash device may be " + "specified with -bios or with -drive if=pflash... " + "but you cannot use both options at once"); + exit(1); + } + fn = qemu_find_file(QEMU_FILE_TYPE_BIOS, machine->firmware); + if (!fn) { + error_report("Could not find ROM image '%s'", machine->firmware); + exit(1); + } + image_size = load_image_targphys(fn, VIRT_PFLASH_MMIO_BASE, + VIRT_PFLASH_SIZE); + g_free(fn); + if (image_size < 0) { + error_report("Could not load ROM image '%s'", machine->firmware); + exit(1); + } + } + if (kernel_filename) { CPUState *cs = CPU(cpu); uint64_t high; @@ -311,6 +353,8 @@ static void virt_init(MachineState *machine) } BOOTINFO2(param_ptr, BI_VIRT_FW_CFG_BASE, VIRT_FW_CFG_MMIO_BASE, VIRT_FW_CFG_IRQ_BASE); + BOOTINFO2(param_ptr, BI_VIRT_PFLASH_BASE, + VIRT_PFLASH_MMIO_BASE, 0); if (kernel_cmdline) { BOOTINFOSTR(param_ptr, BI_COMMAND_LINE, diff --git a/include/standard-headers/asm-m68k/bootinfo-virt.h b/include/standard-headers/asm-m68k/bootinfo-virt.h index 7f90be1aa7bd..21c9a98d2912 100644 --- a/include/standard-headers/asm-m68k/bootinfo-virt.h +++ b/include/standard-headers/asm-m68k/bootinfo-virt.h @@ -18,6 +18,7 @@ #define BI_VIRT_XHCI_BASE 0x8007 #define BI_VIRT_FW_CFG_BASE 0x8008 +#define BI_VIRT_PFLASH_BASE 0x8009 #define VIRT_BOOTI_VERSION MK_BI_VERSION(2, 0) From patchwork Mon May 27 17:15:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13675664 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 66E7EC25B78 for ; Mon, 27 May 2024 17:16:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBdwV-00030S-58; Mon, 27 May 2024 13:15:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBdwO-0002yd-3W for qemu-devel@nongnu.org; Mon, 27 May 2024 13:15:20 -0400 Received: from wfhigh3-smtp.messagingengine.com ([64.147.123.154]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBdwM-0004gT-2S for qemu-devel@nongnu.org; Mon, 27 May 2024 13:15:19 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.west.internal (Postfix) with ESMTP id 77A281800139; Mon, 27 May 2024 13:15:15 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Mon, 27 May 2024 13:15:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1716830115; x=1716916515; bh=TpF+LHkA27GmX2zM44+D/InSAryVrJfrT0+bWhayZYQ=; b= pR7brity8sNFDTvaixsYjmsSCcf6aeW+o05fcxeeMRbxx4UlLtVZUthoiHKOzMb+ v0qM9qNfPbqEomq6ooDr7FgBTHbf21qCiCOnz2zESj01AV+t0zI2eLSuHW3Deo6o UJyz+FtuQmRntbe5NDticsNy6q2P1StdSRZLphxQC0iOIKmmMnnbRS92cF1LLuuL 4wJ27WceFGRdGZhkJkcUManQLjD8QiBe/BfOtelLyw2ii99r8NqBO3ktn8Z1UowV bwHjkPbtxVrm3S6RoH7zKxhLPT5SbMRlFNb45B6y0TFo9MZXvnpXi9CJMopZBeTW xnfGSSNlkR1I+s6Mi48VfQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1716830115; x= 1716916515; bh=TpF+LHkA27GmX2zM44+D/InSAryVrJfrT0+bWhayZYQ=; b=S TiHhqxmg3bFxyDKw2yXUGc7Tc2/VhAksbJD2A/xRZJDo76ZNWxsWlw1zgQLJeuyD 7GeBxKHGP2c6Y/euFIYsS1xO+54T6ts1+2JIpS6XVcC3yW96DP4Qgcc2WKgvQHr1 gqrXB/B9ZTDg/o1KdVkNYmhi9iGg/3Yw1yWk/86Aj3NPUfSZXBHmaAxm0f6lTajc HKFcUZun73UHVUqEOlIxkGmPzl5kUFyAh9SJFGbxYeYS+AXn2Z+zGj01TN+BDItg HkbmarY8A/ARLP5vOaDR3bn5WB22PCBiz+hGraSq3bpVoB7uYwazv2ngmQAiMcK7 2d6FYBOP9qi0hGjdB+WVg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejgedguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 13:15:13 -0400 (EDT) From: Jiaxun Yang Date: Mon, 27 May 2024 18:15:07 +0100 Subject: [PATCH 4/4] hw/m68k/virt: Supply bootinfo for BIOS MIME-Version: 1.0 Message-Id: <20240527-m68k-bios-v1-4-6de26552fa77@flygoat.com> References: <20240527-m68k-bios-v1-0-6de26552fa77@flygoat.com> In-Reply-To: <20240527-m68k-bios-v1-0-6de26552fa77@flygoat.com> To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Laurent Vivier , "Michael S. Tsirkin" , Cornelia Huck , Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=9672; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=nHaNjYJp2Db3HKKzI2WU5EhbcN3PdSAvxdjvtn6y5K0=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrSQ/TOZJ5UevfHWcE/V4T3i0jsDG2zCFvzsW2DREv9/6 RLj9UYBHaUsDGJcDLJiiiwhAkp9GxovLrj+IOsPzBxWJpAhDFycAjCRKycZ/nAcOjNxkagMl0bb 5uDDQVzLLCyKOXZxTDSzKen5wua5mZPhf55aUtQNtVzOhJ2HEyf1389w1N+99qJbp275UpkTcfP UOAE= X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Received-SPF: pass client-ip=64.147.123.154; envelope-from=jiaxun.yang@flygoat.com; helo=wfhigh3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We follow common function split between BIOS and QEMU loader, When BIOS firmware is available QEMU does not load kernel/initrd binary to memory, instead BIOS retrieve those binaries from fw_cfg. A stripped version of bootinfo is placed at 1 KiB position of memory. This allows BIOS to probe board level information. It does not contain any booting related information (kernel, initrd, cmdline, random). Signed-off-by: Jiaxun Yang --- hw/m68k/virt.c | 160 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 90 insertions(+), 70 deletions(-) diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c index a2eebc0f2243..ea7a1bb430fc 100644 --- a/hw/m68k/virt.c +++ b/hw/m68k/virt.c @@ -138,13 +138,16 @@ static void virt_init(MachineState *machine) M68kCPU *cpu = NULL; int32_t kernel_size; uint64_t elf_entry; - ram_addr_t initrd_base; - int32_t initrd_size; + ram_addr_t initrd_base = 0; + int32_t initrd_size = 0; + int32_t bootinfo_size; + bool bios_loaded = false; ram_addr_t ram_size = machine->ram_size; const char *kernel_filename = machine->kernel_filename; const char *initrd_filename = machine->initrd_filename; const char *kernel_cmdline = machine->kernel_cmdline; - hwaddr parameters_base; + void *param_blob, *param_ptr, *param_rng_seed = NULL; + hwaddr parameters_base = 1 * KiB; DriveInfo *dinfo; DeviceState *dev; DeviceState *irqc_dev; @@ -264,6 +267,9 @@ static void virt_init(MachineState *machine) /* pflash */ dinfo = drive_get(IF_PFLASH, 0, 0); + if (dinfo) { + bios_loaded = true; + } pflash_cfi01_register(VIRT_PFLASH_MMIO_BASE, "virt.pflash0", VIRT_PFLASH_SIZE, @@ -293,18 +299,12 @@ static void virt_init(MachineState *machine) error_report("Could not load ROM image '%s'", machine->firmware); exit(1); } + + bios_loaded = true; } - if (kernel_filename) { - CPUState *cs = CPU(cpu); + if (kernel_filename && !bios_loaded) { uint64_t high; - void *param_blob, *param_ptr, *param_rng_seed; - - if (kernel_cmdline) { - param_blob = g_malloc(strlen(kernel_cmdline) + 1024); - } else { - param_blob = g_malloc(1024); - } kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, &elf_entry, NULL, &high, NULL, 1, @@ -315,57 +315,6 @@ static void virt_init(MachineState *machine) } reset_info->initial_pc = elf_entry; parameters_base = (high + 1) & ~1; - param_ptr = param_blob; - - BOOTINFO1(param_ptr, BI_MACHTYPE, MACH_VIRT); - if (m68k_feature(&cpu->env, M68K_FEATURE_M68020)) { - BOOTINFO1(param_ptr, BI_CPUTYPE, CPU_68020); - } else if (m68k_feature(&cpu->env, M68K_FEATURE_M68030)) { - BOOTINFO1(param_ptr, BI_MMUTYPE, MMU_68030); - BOOTINFO1(param_ptr, BI_CPUTYPE, CPU_68030); - } else if (m68k_feature(&cpu->env, M68K_FEATURE_M68040)) { - BOOTINFO1(param_ptr, BI_FPUTYPE, FPU_68040); - BOOTINFO1(param_ptr, BI_MMUTYPE, MMU_68040); - BOOTINFO1(param_ptr, BI_CPUTYPE, CPU_68040); - } else if (m68k_feature(&cpu->env, M68K_FEATURE_M68060)) { - BOOTINFO1(param_ptr, BI_FPUTYPE, FPU_68060); - BOOTINFO1(param_ptr, BI_MMUTYPE, MMU_68060); - BOOTINFO1(param_ptr, BI_CPUTYPE, CPU_68060); - } - BOOTINFO2(param_ptr, BI_MEMCHUNK, 0, ram_size); - - BOOTINFO1(param_ptr, BI_VIRT_QEMU_VERSION, - ((QEMU_VERSION_MAJOR << 24) | (QEMU_VERSION_MINOR << 16) | - (QEMU_VERSION_MICRO << 8))); - BOOTINFO2(param_ptr, BI_VIRT_GF_PIC_BASE, - VIRT_GF_PIC_MMIO_BASE, VIRT_GF_PIC_IRQ_BASE); - BOOTINFO2(param_ptr, BI_VIRT_GF_RTC_BASE, - VIRT_GF_RTC_MMIO_BASE, VIRT_GF_RTC_IRQ_BASE); - BOOTINFO2(param_ptr, BI_VIRT_GF_TTY_BASE, - VIRT_GF_TTY_MMIO_BASE, VIRT_GF_TTY_IRQ_BASE); - BOOTINFO2(param_ptr, BI_VIRT_CTRL_BASE, - VIRT_CTRL_MMIO_BASE, VIRT_CTRL_IRQ_BASE); - BOOTINFO2(param_ptr, BI_VIRT_VIRTIO_BASE, - VIRT_VIRTIO_MMIO_BASE, VIRT_VIRTIO_IRQ_BASE); - if (machine_usb(machine)) { - BOOTINFO2(param_ptr, BI_VIRT_XHCI_BASE, - VIRT_XHCI_MMIO_BASE, VIRT_XHCI_IRQ_BASE); - } - BOOTINFO2(param_ptr, BI_VIRT_FW_CFG_BASE, - VIRT_FW_CFG_MMIO_BASE, VIRT_FW_CFG_IRQ_BASE); - BOOTINFO2(param_ptr, BI_VIRT_PFLASH_BASE, - VIRT_PFLASH_MMIO_BASE, 0); - - if (kernel_cmdline) { - BOOTINFOSTR(param_ptr, BI_COMMAND_LINE, - kernel_cmdline); - } - - /* Pass seed to RNG. */ - param_rng_seed = param_ptr; - qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); - BOOTINFODATA(param_ptr, BI_RNG_SEED, - rng_seed, sizeof(rng_seed)); /* load initrd */ if (initrd_filename) { @@ -379,21 +328,92 @@ static void virt_init(MachineState *machine) initrd_base = (ram_size - initrd_size) & TARGET_PAGE_MASK; load_image_targphys(initrd_filename, initrd_base, ram_size - initrd_base); - BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base, - initrd_size); } else { initrd_base = 0; initrd_size = 0; } - BOOTINFO0(param_ptr, BI_LAST); - rom_add_blob_fixed_as("bootinfo", param_blob, param_ptr - param_blob, - parameters_base, cs->as); + } + + /* BIOS is going to retrive cmdline from fw_cfg */ + if (kernel_cmdline && !bios_loaded) { + param_blob = g_malloc(strlen(kernel_cmdline) + 1024); + } else { + param_blob = g_malloc(1024); + } + + param_ptr = param_blob; + BOOTINFO1(param_ptr, BI_MACHTYPE, MACH_VIRT); + if (m68k_feature(&cpu->env, M68K_FEATURE_M68020)) { + BOOTINFO1(param_ptr, BI_CPUTYPE, CPU_68020); + } else if (m68k_feature(&cpu->env, M68K_FEATURE_M68030)) { + BOOTINFO1(param_ptr, BI_MMUTYPE, MMU_68030); + BOOTINFO1(param_ptr, BI_CPUTYPE, CPU_68030); + } else if (m68k_feature(&cpu->env, M68K_FEATURE_M68040)) { + BOOTINFO1(param_ptr, BI_FPUTYPE, FPU_68040); + BOOTINFO1(param_ptr, BI_MMUTYPE, MMU_68040); + BOOTINFO1(param_ptr, BI_CPUTYPE, CPU_68040); + } else if (m68k_feature(&cpu->env, M68K_FEATURE_M68060)) { + BOOTINFO1(param_ptr, BI_FPUTYPE, FPU_68060); + BOOTINFO1(param_ptr, BI_MMUTYPE, MMU_68060); + BOOTINFO1(param_ptr, BI_CPUTYPE, CPU_68060); + } + BOOTINFO2(param_ptr, BI_MEMCHUNK, 0, ram_size); + + BOOTINFO1(param_ptr, BI_VIRT_QEMU_VERSION, + ((QEMU_VERSION_MAJOR << 24) | (QEMU_VERSION_MINOR << 16) | + (QEMU_VERSION_MICRO << 8))); + BOOTINFO2(param_ptr, BI_VIRT_GF_PIC_BASE, + VIRT_GF_PIC_MMIO_BASE, VIRT_GF_PIC_IRQ_BASE); + BOOTINFO2(param_ptr, BI_VIRT_GF_RTC_BASE, + VIRT_GF_RTC_MMIO_BASE, VIRT_GF_RTC_IRQ_BASE); + BOOTINFO2(param_ptr, BI_VIRT_GF_TTY_BASE, + VIRT_GF_TTY_MMIO_BASE, VIRT_GF_TTY_IRQ_BASE); + BOOTINFO2(param_ptr, BI_VIRT_CTRL_BASE, + VIRT_CTRL_MMIO_BASE, VIRT_CTRL_IRQ_BASE); + BOOTINFO2(param_ptr, BI_VIRT_VIRTIO_BASE, + VIRT_VIRTIO_MMIO_BASE, VIRT_VIRTIO_IRQ_BASE); + if (machine_usb(machine)) { + BOOTINFO2(param_ptr, BI_VIRT_XHCI_BASE, + VIRT_XHCI_MMIO_BASE, VIRT_XHCI_IRQ_BASE); + } + BOOTINFO2(param_ptr, BI_VIRT_FW_CFG_BASE, + VIRT_FW_CFG_MMIO_BASE, VIRT_FW_CFG_IRQ_BASE); + BOOTINFO2(param_ptr, BI_VIRT_PFLASH_BASE, + VIRT_PFLASH_MMIO_BASE, 0); + + /* Boot related */ + if (!bios_loaded) { + if (kernel_cmdline) { + BOOTINFOSTR(param_ptr, BI_COMMAND_LINE, + kernel_cmdline); + } + if (initrd_size) { + BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base, + initrd_size); + } + + /* Pass seed to RNG. */ + param_rng_seed = param_ptr; + qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); + BOOTINFODATA(param_ptr, BI_RNG_SEED, + rng_seed, sizeof(rng_seed)); + } + + BOOTINFO0(param_ptr, BI_LAST); + bootinfo_size = param_ptr - param_blob; + rom_add_blob_fixed_as("bootinfo", param_blob, bootinfo_size, + parameters_base, &address_space_memory); + if (param_rng_seed) { qemu_register_reset_nosnapshotload(rerandomize_rng_seed, - rom_ptr_for_as(cs->as, parameters_base, + rom_ptr_for_as(&address_space_memory, + parameters_base, param_ptr - param_blob) + (param_rng_seed - param_blob)); - g_free(param_blob); } + + fw_cfg_add_file(fw_cfg, "etc/bootinfo", + g_memdup2(param_blob, bootinfo_size), bootinfo_size); + g_free(param_blob); } static void virt_machine_class_init(ObjectClass *oc, void *data)