From patchwork Thu Nov 11 01:35:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaojuan Yang X-Patchwork-Id: 12613831 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03790C433EF for ; Thu, 11 Nov 2021 02:03:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 9AB7461073 for ; Thu, 11 Nov 2021 02:03:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9AB7461073 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:39128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mkzRG-0002Bg-R3 for qemu-devel@archiver.kernel.org; Wed, 10 Nov 2021 21:03:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mkz0z-0006di-FT for qemu-devel@nongnu.org; Wed, 10 Nov 2021 20:36:36 -0500 Received: from mail.loongson.cn ([114.242.206.163]:54360 helo=loongson.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mkz0w-0001sv-3h for qemu-devel@nongnu.org; Wed, 10 Nov 2021 20:36:31 -0500 Received: from kvm-dev1.localdomain (unknown [10.2.5.134]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxr9Ngc4xh9RMCAA--.4955S29; Thu, 11 Nov 2021 09:36:15 +0800 (CST) From: Xiaojuan Yang To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 27/30] hw/loongarch: Add LoongArch smbios support Date: Thu, 11 Nov 2021 09:35:25 +0800 Message-Id: <1636594528-8175-28-git-send-email-yangxiaojuan@loongson.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1636594528-8175-1-git-send-email-yangxiaojuan@loongson.cn> References: <1636594528-8175-1-git-send-email-yangxiaojuan@loongson.cn> X-CM-TRANSID: AQAAf9Dxr9Ngc4xh9RMCAA--.4955S29 X-Coremail-Antispam: 1UD129KBjvJXoWxGry8Zw18trWkCw1xGw4xCrg_yoW5uw4xpF y7CF1kurs5Xrn3KrZIq347WFn5Zws7Kw12qFWIy3yFkFZrAr1Uuw4kA34qyFy8J3y8Ga4j vFn5K3W3Xa1UJ37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UUUUUUUUU== X-CM-SenderInfo: p1dqw5xldry3tdq6z05rqj20fqof0/ Received-SPF: pass client-ip=114.242.206.163; envelope-from=yangxiaojuan@loongson.cn; helo=loongson.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Song Gao Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Xiaojuan Yang Signed-off-by: Song Gao --- hw/loongarch/Kconfig | 1 + hw/loongarch/ls3a5000_virt.c | 41 ++++++++++++++++++++++++++++++++ include/hw/loongarch/loongarch.h | 2 ++ 3 files changed, 44 insertions(+) diff --git a/hw/loongarch/Kconfig b/hw/loongarch/Kconfig index b59cd98a7a..595c19ad83 100644 --- a/hw/loongarch/Kconfig +++ b/hw/loongarch/Kconfig @@ -14,6 +14,7 @@ config LOONGSON_3A5000 select LOONGARCH_EXTIOI select LS7A_RTC select FW_CFG_LOONGARCH + select SMBIOS config FW_CFG_LOONGARCH bool diff --git a/hw/loongarch/ls3a5000_virt.c b/hw/loongarch/ls3a5000_virt.c index 902a0c7630..bfe8dd4757 100644 --- a/hw/loongarch/ls3a5000_virt.c +++ b/hw/loongarch/ls3a5000_virt.c @@ -26,6 +26,7 @@ #include "hw/pci-host/ls7a.h" #include "hw/misc/unimp.h" #include "hw/loongarch/fw_cfg.h" +#include "hw/firmware/smbios.h" #define LOONGSON3_BIOSNAME "loongarch_bios.bin" @@ -101,6 +102,43 @@ static void fw_cfg_add_kernel_info(FWCfgState *fw_cfg) fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, (const char *)cmdline_buf); } +static void loongarch_build_smbios(LoongArchMachineState *lams) +{ + MachineState *ms = MACHINE(lams); + MachineClass *mc = MACHINE_GET_CLASS(lams); + uint8_t *smbios_tables, *smbios_anchor; + size_t smbios_tables_len, smbios_anchor_len; + const char *product = "QEMU Virtual Machine"; + ms->smp.cores = 4; + + if (!lams->fw_cfg) { + return; + } + + product = "LoongArch-3A5K-7A1000-TCG"; + + smbios_set_defaults("QEMU", product, mc->name, false, + true, SMBIOS_ENTRY_POINT_30); + + smbios_get_tables(ms, NULL, 0, &smbios_tables, &smbios_tables_len, + &smbios_anchor, &smbios_anchor_len, &error_fatal); + + if (smbios_anchor) { + fw_cfg_add_file(lams->fw_cfg, "etc/smbios/smbios-tables", + smbios_tables, smbios_tables_len); + fw_cfg_add_file(lams->fw_cfg, "etc/smbios/smbios-anchor", + smbios_anchor, smbios_anchor_len); + } +} + +static +void loongarch_machine_done(Notifier *notifier, void *data) +{ + LoongArchMachineState *lams = container_of(notifier, + LoongArchMachineState, machine_done); + loongarch_build_smbios(lams); +} + static void main_cpu_reset(void *opaque) { LoongArchCPU *cpu = opaque; @@ -377,6 +415,9 @@ static void ls3a5000_virt_init(MachineState *machine) memory_region_set_readonly(bios, true); memory_region_add_subregion(get_system_memory(), LA_BIOS_BASE, bios); + lams->machine_done.notify = loongarch_machine_done; + qemu_add_machine_init_done_notifier(&lams->machine_done); + /* Add PM mmio memory for reboot and shutdown*/ iomem = g_new(MemoryRegion, 1); memory_region_init_io(iomem, NULL, &loongarch_pm_ops, NULL, diff --git a/include/hw/loongarch/loongarch.h b/include/hw/loongarch/loongarch.h index dc7617ab64..b165b4fd07 100644 --- a/include/hw/loongarch/loongarch.h +++ b/include/hw/loongarch/loongarch.h @@ -49,6 +49,8 @@ typedef struct LoongArchMachineState { AddressSpace *address_space_iocsr; MemoryRegion *system_iocsr; + /* State for other subsystems/APIs: */ + Notifier machine_done; gipiState *gipi; qemu_irq *pch_irq; FWCfgState *fw_cfg;