From nobody Thu May 9 15:43:25 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659136070; cv=none; d=zohomail.com; s=zohoarc; b=Aur3+bjJVefLTfs27R8tEbOz4ARt7JVL+EtGS5VLNWClqislojf0lJQm5NODyH1mm74JU1Di1dOhaeEuscqqp1pV8YIuxzb0UhPeaUt85GaPkaqnW9Px4WgD1QG/015cYw1WcuvtosGfzNle63RBaor3Enktinx71FhT/P2C8lQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659136070; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=A6p7vLycGg8ZjMa3Vs1wsed64HXbSkOmTpGs5WCIBWs=; b=MRt+TEtN13YLwuiqAEPaRXLZTg3/+bzVPRBi+skSZnZOoSoXh1eCytt9zOb6Rj5X6KfV1XA1BQKGf3VZvULFZwQhA3bcV+p59IWLY90zznDKfOKxKUZayGUFi+4atWajCRJ5y0RTJy5rscVUFdLGdFjoWh5n2wJt7WpLjSoob6M= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659136070331560.4400150584949; Fri, 29 Jul 2022 16:07:50 -0700 (PDT) Received: from localhost ([::1]:36240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHZ5A-00059f-4o for importer@patchew.org; Fri, 29 Jul 2022 19:07:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHZ3l-0002wA-1u for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:21 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:34524) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHZ3i-0001qt-V0 for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:20 -0400 Received: by mail-pg1-x533.google.com with SMTP id 12so5073678pga.1 for ; Fri, 29 Jul 2022 16:06:18 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id u5-20020a170902714500b0016c574aa0fdsm4211566plm.76.2022.07.29.16.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 16:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A6p7vLycGg8ZjMa3Vs1wsed64HXbSkOmTpGs5WCIBWs=; b=UkxlUXn0w1sar0OlfCPxBAS/QIQpKXZ7RW13D9FqwklepqNDDj+HdkYyu2ODyjTQdm GhWbsvdW5vLT5FatMJgt+ZwqCo/ow59Hk61tHvaVx8IUdl3nrTHre/rS+Cb1zI5akePc xk3HGna5iWSLt66s/zxZ/rKyvKYkYD0xosrhwkBt0K4TpZDv5NORdeu3o4WsMnN51P1h ubocUfBn7TjkzcFIYQpeoFNhzfMts9R/4Cgp9WzDsQXRmcqoDP0MBTUIjrpqhLPXpRSy 8ig44OpgyTdIG6oMBhhA6GXMru1f8NrkB2kSRUAVoEZgZ0RzkNA32YdD/MCEdckNBkZL 4pig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=A6p7vLycGg8ZjMa3Vs1wsed64HXbSkOmTpGs5WCIBWs=; b=Imn7eXCz7jlBgjy75/1sf7iDLAKHxPkpyeG4JgiwXzcH24ey9g0mJqNtc5n7iLMvBe KRvClq0a1s94HCEcHoKOcOacKD02TNh+yCcLmL9gxwHRlGiv3HMDz3NKS5tlMjvTCDB0 sKvveLcFnpoxupSIUvgNBR4UHdmwsCojFHWDmaBeAkgkVknVomReA13EPHywlW0i1uQf 7CzUSYf9EWrMT3WXxH4uXe0zV6EfPhkVcZkbGekenqKJdvy2UZ5W3DHviQ8xTpLRlRW8 c4yKOc2bwusakvirkCCYb+FV/V0A1V0xeXGrhSn9OK0nXiQpybjucQNTmQqk+D0f/dh/ bVPw== X-Gm-Message-State: AJIora/+pUn+86uMGTRewcoi1Zm2hV+iV0DzxkulUng3V5aEy4jjlxwC SpQqEDAt8h+uI6dFGIP7SXjZTgG2QIngJQ== X-Google-Smtp-Source: AGRyM1t9ECx5CHFsfuRuOpvYZOSoYwBil0p81NSkvMENeJ72DzD67+jWffw0dxTE1uwpOEi8EH8nFw== X-Received: by 2002:a63:6e82:0:b0:41a:1817:15d9 with SMTP id j124-20020a636e82000000b0041a181715d9mr4675950pgc.577.1659135975995; Fri, 29 Jul 2022 16:06:15 -0700 (PDT) From: Stafford Horne To: QEMU Development Cc: Openrisc , Richard Henderson , Stafford Horne , Jia Liu Subject: [PATCH v3 01/11] hw/openrisc: Split re-usable boot time apis out to boot.c Date: Sat, 30 Jul 2022 08:01:07 +0900 Message-Id: <20220729230117.3768312-2-shorne@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220729230117.3768312-1-shorne@gmail.com> References: <20220729230117.3768312-1-shorne@gmail.com> 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: pass client-ip=2607:f8b0:4864:20::533; envelope-from=shorne@gmail.com; helo=mail-pg1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659136072035100001 Content-Type: text/plain; charset="utf-8" These will be shared with the virt platform. Reviewed-by: Richard Henderson Signed-off-by: Stafford Horne --- Since v2: - No changes hw/openrisc/boot.c | 117 +++++++++++++++++++++++++++++++++++++ hw/openrisc/meson.build | 1 + hw/openrisc/openrisc_sim.c | 106 ++------------------------------- include/hw/openrisc/boot.h | 34 +++++++++++ 4 files changed, 158 insertions(+), 100 deletions(-) create mode 100644 hw/openrisc/boot.c create mode 100644 include/hw/openrisc/boot.h diff --git a/hw/openrisc/boot.c b/hw/openrisc/boot.c new file mode 100644 index 0000000000..ca773b385e --- /dev/null +++ b/hw/openrisc/boot.c @@ -0,0 +1,117 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * QEMU OpenRISC boot helpers. + * + * (c) 2022 Stafford Horne + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "exec/cpu-defs.h" +#include "elf.h" +#include "hw/loader.h" +#include "hw/openrisc/boot.h" +#include "sysemu/device_tree.h" +#include "sysemu/qtest.h" + +#include + +#define KERNEL_LOAD_ADDR 0x100 + +hwaddr openrisc_load_kernel(ram_addr_t ram_size, + const char *kernel_filename, + uint32_t *bootstrap_pc) +{ + long kernel_size; + uint64_t elf_entry; + uint64_t high_addr; + hwaddr entry; + + if (kernel_filename && !qtest_enabled()) { + kernel_size =3D load_elf(kernel_filename, NULL, NULL, NULL, + &elf_entry, NULL, &high_addr, NULL, 1, + EM_OPENRISC, 1, 0); + entry =3D elf_entry; + if (kernel_size < 0) { + kernel_size =3D load_uimage(kernel_filename, + &entry, NULL, NULL, NULL, NULL); + high_addr =3D entry + kernel_size; + } + if (kernel_size < 0) { + kernel_size =3D load_image_targphys(kernel_filename, + KERNEL_LOAD_ADDR, + ram_size - KERNEL_LOAD_ADDR); + high_addr =3D KERNEL_LOAD_ADDR + kernel_size; + } + + if (entry <=3D 0) { + entry =3D KERNEL_LOAD_ADDR; + } + + if (kernel_size < 0) { + error_report("couldn't load the kernel '%s'", kernel_filename); + exit(1); + } + *bootstrap_pc =3D entry; + + return high_addr; + } + return 0; +} + +hwaddr openrisc_load_initrd(void *fdt, const char *filename, + hwaddr load_start, uint64_t mem_size) +{ + int size; + hwaddr start; + + /* We put the initrd right after the kernel; page aligned. */ + start =3D TARGET_PAGE_ALIGN(load_start); + + size =3D load_ramdisk(filename, start, mem_size - start); + if (size < 0) { + size =3D load_image_targphys(filename, start, mem_size - start); + if (size < 0) { + error_report("could not load ramdisk '%s'", filename); + exit(1); + } + } + + if (fdt) { + qemu_fdt_setprop_cell(fdt, "/chosen", + "linux,initrd-start", start); + qemu_fdt_setprop_cell(fdt, "/chosen", + "linux,initrd-end", start + size); + } + + return start + size; +} + +uint32_t openrisc_load_fdt(void *fdt, hwaddr load_start, + uint64_t mem_size) +{ + uint32_t fdt_addr; + int ret; + int fdtsize =3D fdt_totalsize(fdt); + + if (fdtsize <=3D 0) { + error_report("invalid device-tree"); + exit(1); + } + + /* We put fdt right after the kernel and/or initrd. */ + fdt_addr =3D TARGET_PAGE_ALIGN(load_start); + + ret =3D fdt_pack(fdt); + /* Should only fail if we've built a corrupted tree */ + g_assert(ret =3D=3D 0); + /* copy in the device tree */ + qemu_fdt_dumpdtb(fdt, fdtsize); + + rom_add_blob_fixed_as("fdt", fdt, fdtsize, fdt_addr, + &address_space_memory); + + return fdt_addr; +} + diff --git a/hw/openrisc/meson.build b/hw/openrisc/meson.build index ec48172c9d..ab563820c5 100644 --- a/hw/openrisc/meson.build +++ b/hw/openrisc/meson.build @@ -1,5 +1,6 @@ openrisc_ss =3D ss.source_set() openrisc_ss.add(files('cputimer.c')) +openrisc_ss.add(files('boot.c')) openrisc_ss.add(when: 'CONFIG_OR1K_SIM', if_true: [files('openrisc_sim.c')= , fdt]) =20 hw_arch +=3D {'openrisc': openrisc_ss} diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c index 35adce17ac..35da123aef 100644 --- a/hw/openrisc/openrisc_sim.c +++ b/hw/openrisc/openrisc_sim.c @@ -24,10 +24,9 @@ #include "cpu.h" #include "hw/irq.h" #include "hw/boards.h" -#include "elf.h" #include "hw/char/serial.h" #include "net/net.h" -#include "hw/loader.h" +#include "hw/openrisc/boot.h" #include "hw/qdev-properties.h" #include "exec/address-spaces.h" #include "sysemu/device_tree.h" @@ -283,101 +282,6 @@ static void openrisc_sim_serial_init(Or1ksimState *st= ate, hwaddr base, g_free(nodename); } =20 -static hwaddr openrisc_load_kernel(ram_addr_t ram_size, - const char *kernel_filename) -{ - long kernel_size; - uint64_t elf_entry; - uint64_t high_addr; - hwaddr entry; - - if (kernel_filename && !qtest_enabled()) { - kernel_size =3D load_elf(kernel_filename, NULL, NULL, NULL, - &elf_entry, NULL, &high_addr, NULL, 1, - EM_OPENRISC, 1, 0); - entry =3D elf_entry; - if (kernel_size < 0) { - kernel_size =3D load_uimage(kernel_filename, - &entry, NULL, NULL, NULL, NULL); - high_addr =3D entry + kernel_size; - } - if (kernel_size < 0) { - kernel_size =3D load_image_targphys(kernel_filename, - KERNEL_LOAD_ADDR, - ram_size - KERNEL_LOAD_ADDR); - high_addr =3D KERNEL_LOAD_ADDR + kernel_size; - } - - if (entry <=3D 0) { - entry =3D KERNEL_LOAD_ADDR; - } - - if (kernel_size < 0) { - error_report("couldn't load the kernel '%s'", kernel_filename); - exit(1); - } - boot_info.bootstrap_pc =3D entry; - - return high_addr; - } - return 0; -} - -static hwaddr openrisc_load_initrd(Or1ksimState *state, const char *filena= me, - hwaddr load_start, uint64_t mem_size) -{ - void *fdt =3D state->fdt; - int size; - hwaddr start; - - /* We put the initrd right after the kernel; page aligned. */ - start =3D TARGET_PAGE_ALIGN(load_start); - - size =3D load_ramdisk(filename, start, mem_size - start); - if (size < 0) { - size =3D load_image_targphys(filename, start, mem_size - start); - if (size < 0) { - error_report("could not load ramdisk '%s'", filename); - exit(1); - } - } - - qemu_fdt_setprop_cell(fdt, "/chosen", - "linux,initrd-start", start); - qemu_fdt_setprop_cell(fdt, "/chosen", - "linux,initrd-end", start + size); - - return start + size; -} - -static uint32_t openrisc_load_fdt(Or1ksimState *state, hwaddr load_start, - uint64_t mem_size) -{ - void *fdt =3D state->fdt; - uint32_t fdt_addr; - int ret; - int fdtsize =3D fdt_totalsize(fdt); - - if (fdtsize <=3D 0) { - error_report("invalid device-tree"); - exit(1); - } - - /* We put fdt right after the kernel and/or initrd. */ - fdt_addr =3D TARGET_PAGE_ALIGN(load_start); - - ret =3D fdt_pack(fdt); - /* Should only fail if we've built a corrupted tree */ - g_assert(ret =3D=3D 0); - /* copy in the device tree */ - qemu_fdt_dumpdtb(fdt, fdtsize); - - rom_add_blob_fixed_as("fdt", fdt, fdtsize, fdt_addr, - &address_space_memory); - - return fdt_addr; -} - static void openrisc_sim_init(MachineState *machine) { ram_addr_t ram_size =3D machine->ram_size; @@ -428,13 +332,15 @@ static void openrisc_sim_init(MachineState *machine) or1ksim_memmap[OR1KSIM_UART].size, smp_cpus, cpus, OR1KSIM_UART_IRQ, n); =20 - load_addr =3D openrisc_load_kernel(ram_size, kernel_filename); + load_addr =3D openrisc_load_kernel(ram_size, kernel_filename, + &boot_info.bootstrap_pc); if (load_addr > 0) { if (machine->initrd_filename) { - load_addr =3D openrisc_load_initrd(state, machine->initrd_file= name, + load_addr =3D openrisc_load_initrd(state->fdt, + machine->initrd_filename, load_addr, machine->ram_size); } - boot_info.fdt_addr =3D openrisc_load_fdt(state, load_addr, + boot_info.fdt_addr =3D openrisc_load_fdt(state->fdt, load_addr, machine->ram_size); } } diff --git a/include/hw/openrisc/boot.h b/include/hw/openrisc/boot.h new file mode 100644 index 0000000000..25a313d63a --- /dev/null +++ b/include/hw/openrisc/boot.h @@ -0,0 +1,34 @@ +/* + * QEMU OpenRISC boot helpers. + * + * Copyright (c) 2022 Stafford Horne + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#ifndef OPENRISC_BOOT_H +#define OPENRISC_BOOT_H + +#include "exec/cpu-defs.h" + +hwaddr openrisc_load_kernel(ram_addr_t ram_size, + const char *kernel_filename, + uint32_t *bootstrap_pc); + +hwaddr openrisc_load_initrd(void *fdt, const char *filename, + hwaddr load_start, uint64_t mem_size); + +uint32_t openrisc_load_fdt(void *fdt, hwaddr load_start, + uint64_t mem_size); + +#endif /* OPENRISC_BOOT_H */ --=20 2.37.1 From nobody Thu May 9 15:43:25 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659136228; cv=none; d=zohomail.com; s=zohoarc; b=eqzSXqxoyBXd8JBBo2y5qYabNoodkXf6ruWx640rVTPfhXtJAxJOWBblt3f++Zhoz+KFIF3l7yGWY1xMuCfcszW434JW3NmfTWSU936UMQcWB1rwuPL8At5vs+3IOKbjncTR8rTU88Yif5nk4VvDfA/oHCCXn6EGSNOJGnTkwrA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659136228; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TfhTaKLipR7ZnPNEZbMG+vKVDM09H6zgRLcLiJBdoNc=; b=ZUjSPzc9P+y0pl4Jrl3XaLecH1wghdWToUGAwPXHVqGzALzf2cPjHRevQ4+eXeVxr5W2W3KhN7LPuUFtirujXllsoIUinc9I/XBOOewhxfVGDq1y0ZmsvC8vEetxx6s76Kun/0INMFup+FbWhmQ8POdCBl3M+JAeRNyESqvsBpg= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659136228657858.7618446894601; Fri, 29 Jul 2022 16:10:28 -0700 (PDT) Received: from localhost ([::1]:44566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHZ7i-0002K8-OP for importer@patchew.org; Fri, 29 Jul 2022 19:10:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHZ3l-0002wC-69 for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:21 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:34525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHZ3j-0001r0-Lr for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:20 -0400 Received: by mail-pg1-x534.google.com with SMTP id 12so5073707pga.1 for ; Fri, 29 Jul 2022 16:06:19 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id f11-20020a170902860b00b0016be9d498d0sm4083896plo.211.2022.07.29.16.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 16:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TfhTaKLipR7ZnPNEZbMG+vKVDM09H6zgRLcLiJBdoNc=; b=OZhVs519WgLdi5RziBRJJZoA8/bWA/aUD7of7Eb9uR6Jql3lkm6tOTKChBIsh1L8CZ XZWacKNDLmHwQsX0uGCd7KyCaaxKI9JNd9GdOMqo4d0yio27Vrj3CnVtP+RZfMGw2Ueq mJlBEf73ARKVq/cBbLVLNd+5jbnMBRolucGMtpgB8DKnmZY8tSd2Mdq4bkc6178uLnQB Zjtc4IJ99ujXSG+Icu432hjEU1Kg/aSuBepUs/iw7kNGuvypgGygA5uBwOpjxYsmZz6q gUcssID4czv60wiaOJN5IjO8Dawiaop0nP0DYGX3Q4ZLKAMeUQtPPpjZ6HE4S0mMLu6V obCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TfhTaKLipR7ZnPNEZbMG+vKVDM09H6zgRLcLiJBdoNc=; b=cA/KHTZ7YQFDh1EodtXVDucRA/Emva7adBhwet2ZxPASKCiNj7MYNa5tTydz54n9m4 sxZEZQQLBHDfBVpbBhQDlxhA2NyI+CDLPvmVW4NfP4VghruF+Eu2/j0bw4ULSN9kJCWF lmvgS5mf0oLkHoNwOm0VwT46RFQIuFgovqYZlAWAT/B/UvdueoI62k3KWQECLRUP2ye8 Og8Vn/8wVEIleIsQ6teZnL3R9qBCQFRGUebfZojTdLtRNuJb03ER0RjeQLAPkeJ5HPcj 2d/3j2zI3Zc8AhyFG59CfBqxGi56HQMw5ayydoWYIcU0iNAB8Zo+ZGNJnIzEX3n/I5ms rv/Q== X-Gm-Message-State: AJIora+oL2szOIS2Spz1exUIDBKyYIesF6sg1lx3x3zkSFRl0NNI/B9F IMnPr4ikQ9OLsKeNxYzW8QzKfc/OH6K2tQ== X-Google-Smtp-Source: AGRyM1uPIPjtPZ6Rchwe23IWOZgfe9sKMu87ZkdW97D/i2152jhZuRU7rvGhvneC3EwkkIJCGyTyOQ== X-Received: by 2002:a05:6a00:815:b0:52b:8895:a0bd with SMTP id m21-20020a056a00081500b0052b8895a0bdmr5621588pfk.57.1659135978168; Fri, 29 Jul 2022 16:06:18 -0700 (PDT) From: Stafford Horne To: QEMU Development Cc: Openrisc , Richard Henderson , Stafford Horne Subject: [PATCH v3 02/11] target/openrisc: Fix memory reading in debugger Date: Sat, 30 Jul 2022 08:01:08 +0900 Message-Id: <20220729230117.3768312-3-shorne@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220729230117.3768312-1-shorne@gmail.com> References: <20220729230117.3768312-1-shorne@gmail.com> 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: pass client-ip=2607:f8b0:4864:20::534; envelope-from=shorne@gmail.com; helo=mail-pg1-x534.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659136228930100001 Content-Type: text/plain; charset="utf-8" In commit f0655423ca ("target/openrisc: Reorg tlb lookup") data and instruction TLB reads were combined. This, broke debugger reads where we first tried to map using the data tlb then fall back to the instruction tlb. This patch replicates this logic by first requesting a PAGE_READ protection mapping then falling back to PAGE_EXEC. Reviewed-by: Richard Henderson Signed-off-by: Stafford Horne --- Since v2: - No changes, added Reviewed-by target/openrisc/mmu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/target/openrisc/mmu.c b/target/openrisc/mmu.c index d7e1320998..0b8afdbacf 100644 --- a/target/openrisc/mmu.c +++ b/target/openrisc/mmu.c @@ -148,7 +148,13 @@ hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cs, = vaddr addr) case SR_DME | SR_IME: /* The mmu is definitely enabled. */ excp =3D get_phys_mmu(cpu, &phys_addr, &prot, addr, - PAGE_EXEC | PAGE_READ | PAGE_WRITE, + PAGE_READ, + (sr & SR_SM) !=3D 0); + if (!excp) { + return phys_addr; + } + excp =3D get_phys_mmu(cpu, &phys_addr, &prot, addr, + PAGE_EXEC, (sr & SR_SM) !=3D 0); return excp ? -1 : phys_addr; =20 --=20 2.37.1 From nobody Thu May 9 15:43:25 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659136474; cv=none; d=zohomail.com; s=zohoarc; b=Ra59ThVEUTVxrdJiYZa0T+QmOk7/f3CjnmOzJ+/DdnlYkvRQWXpXr1uvmVYr5vSEfnk2lKDgSBbfVq7t+BBjCE2bCMDS97GdmT2d3Tt1pBrAOoOYqlr87yMTxZ8z9fv1f2WyHurBHq6SNXErY5LOTscfkuEqOhdBbHkzOiTfH+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659136474; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yjU1zPUMAqicguRm1cR77GzJDaEy6d171FJDhkxwV1U=; b=dmuydfb4AyIMYfYM48UoGUrDVN5X5II316VMLfg86wumnLfLZppZ0cWrk+2//bg443M/+Gr3j6k5w4NJTdraPIT1oJCt3mYtKccoVFj2K99OVgQ/BaUsR60fuC0PzcgJoLr8v6dVk305OM0LgPF20/snPzX7MNqrf8LFCyJ67sA= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659136474577712.183549412822; Fri, 29 Jul 2022 16:14:34 -0700 (PDT) Received: from localhost ([::1]:52704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHZBh-0007wS-7j for importer@patchew.org; Fri, 29 Jul 2022 19:14:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHZ3z-0003Hh-PS; Fri, 29 Jul 2022 19:06:35 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:52894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHZ3m-0001rL-QU; Fri, 29 Jul 2022 19:06:34 -0400 Received: by mail-pj1-x1033.google.com with SMTP id ha11so6007250pjb.2; Fri, 29 Jul 2022 16:06:22 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id l5-20020a170903120500b0016d62ba5665sm4264716plh.254.2022.07.29.16.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 16:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yjU1zPUMAqicguRm1cR77GzJDaEy6d171FJDhkxwV1U=; b=KGwzI2ujPh0vwHY/g3EJxKly6e1Oq+erVA5njmecppvTTV9ZTAYqGVXUUlmjd2LgXn QTQelyJrwtMfq++oi6heGlfDfXGOjw2KoM2RynGtYgXjJVJfUaAbCyvMuiJqgXH/brSI j1xSYV8LGhKngXG9t4kUUacZvreAHQoBeWNcsjP3DpDf8lxMy4O/WwlQ+54ibTqejiMC Wc21KObTLL3vT8g4PkqOT0FysuRK4q8CaN21jp6hqL3CcW5o7HmFZbWRuR9OOVmBwIBO s5vYZt7cXMo35YGS0YbUtugJPEJShfSLPFdd09AtxVnu453M1npMWl22WcwIxcfMeiLA SXIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yjU1zPUMAqicguRm1cR77GzJDaEy6d171FJDhkxwV1U=; b=M9zE4m1xu2JTUHYjcMjL4coZMaQLj2pU4YzQ9WJwVIJCq0/VqA3D3RbEZpSUjJDqVy 1UWSyVijwl5eOVnybNHl7ZECTTv7Rdr5vwHoPuv44Ue5+YImDgurL5ZWfRhejFOC5Bop enHS+IPIeclPjw+QI8qt6YTQ418XZKgdoEokWH6ODpGbEMXXo1IDLtVVu5OquOnt22YT OVzxz3BaQsjNx9gmZA4YLb3uQ+Y5SA8ZRL9c8i6+kZI2e+Mnm7K1uMYA9mKtvLmad3Yz d+9yPQG6AwgTjzUHh4oczEF7xjC9rt1t31HgfZp9HPc04Vto3dKUERrYEpxA/xXYwwye 0p+g== X-Gm-Message-State: ACgBeo3EVf4rsb6N2yDtf9I/kJFvg1SRIePHz4qJFfwl9P8fNNTgkQxa ZqPnq3tU10PtDiXBGcAlaeuLU00qp+hbCw== X-Google-Smtp-Source: AA6agR4MNdOUyonuyAyNPJjEyXClu7+UvOblUn6RgAqnbI9MsW8Z5sswvIf361fTV7KQMmFGmgaJug== X-Received: by 2002:a17:902:8602:b0:16c:dfae:9afb with SMTP id f2-20020a170902860200b0016cdfae9afbmr6039490plo.35.1659135980879; Fri, 29 Jul 2022 16:06:20 -0700 (PDT) From: Stafford Horne To: QEMU Development Cc: Openrisc , Richard Henderson , Stafford Horne , Laurent Vivier , Anup Patel , Laurent Vivier , Anup Patel , Alistair Francis , qemu-riscv@nongnu.org (open list:Goldfish RTC) Subject: [PATCH v3 03/11] goldfish_rtc: Add big-endian property Date: Sat, 30 Jul 2022 08:01:09 +0900 Message-Id: <20220729230117.3768312-4-shorne@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220729230117.3768312-1-shorne@gmail.com> References: <20220729230117.3768312-1-shorne@gmail.com> 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: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=shorne@gmail.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659136475087100001 Content-Type: text/plain; charset="utf-8" Add a new property "big-endian" to allow configuring the RTC as either little or big endian, the default is little endian. Currently overriding the default to big endian is only used by the m68k virt platform. New platforms should prefer to use little endian and not set this. Cc: Laurent Vivier Reviewed-by: Anup Patel Signed-off-by: Stafford Horne Reviewed-by: Richard Henderson --- Since v2: - Added Reviewed-by - Changed from enum property to boolean as suggested by Richard hw/m68k/virt.c | 1 + hw/rtc/goldfish_rtc.c | 37 ++++++++++++++++++++++++++--------- include/hw/rtc/goldfish_rtc.h | 2 ++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c index 0aa383fa6b..c7a6c766e3 100644 --- a/hw/m68k/virt.c +++ b/hw/m68k/virt.c @@ -173,6 +173,7 @@ static void virt_init(MachineState *machine) io_base =3D VIRT_GF_RTC_MMIO_BASE; for (i =3D 0; i < VIRT_GF_RTC_NB; i++) { dev =3D qdev_new(TYPE_GOLDFISH_RTC); + qdev_prop_set_bit(dev, "big-endian", true); sysbus =3D SYS_BUS_DEVICE(dev); sysbus_realize_and_unref(sysbus, &error_fatal); sysbus_mmio_map(sysbus, 0, io_base); diff --git a/hw/rtc/goldfish_rtc.c b/hw/rtc/goldfish_rtc.c index 35e493be31..19a56402a0 100644 --- a/hw/rtc/goldfish_rtc.c +++ b/hw/rtc/goldfish_rtc.c @@ -216,14 +216,25 @@ static int goldfish_rtc_post_load(void *opaque, int v= ersion_id) return 0; } =20 -static const MemoryRegionOps goldfish_rtc_ops =3D { - .read =3D goldfish_rtc_read, - .write =3D goldfish_rtc_write, - .endianness =3D DEVICE_NATIVE_ENDIAN, - .valid =3D { - .min_access_size =3D 4, - .max_access_size =3D 4 - } +static const MemoryRegionOps goldfish_rtc_ops[2] =3D { + [false] =3D { + .read =3D goldfish_rtc_read, + .write =3D goldfish_rtc_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4 + } + }, + [true] =3D { + .read =3D goldfish_rtc_read, + .write =3D goldfish_rtc_write, + .endianness =3D DEVICE_BIG_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4 + } + }, }; =20 static const VMStateDescription goldfish_rtc_vmstate =3D { @@ -265,7 +276,8 @@ static void goldfish_rtc_realize(DeviceState *d, Error = **errp) SysBusDevice *dev =3D SYS_BUS_DEVICE(d); GoldfishRTCState *s =3D GOLDFISH_RTC(d); =20 - memory_region_init_io(&s->iomem, OBJECT(s), &goldfish_rtc_ops, s, + memory_region_init_io(&s->iomem, OBJECT(s), + &goldfish_rtc_ops[s->big_endian], s, "goldfish_rtc", 0x24); sysbus_init_mmio(dev, &s->iomem); =20 @@ -274,10 +286,17 @@ static void goldfish_rtc_realize(DeviceState *d, Erro= r **errp) s->timer =3D timer_new_ns(rtc_clock, goldfish_rtc_interrupt, s); } =20 +static Property goldfish_rtc_properties[] =3D { + DEFINE_PROP_BOOL("big-endian", GoldfishRTCState, big_endian, + false), + DEFINE_PROP_END_OF_LIST(), +}; + static void goldfish_rtc_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 + device_class_set_props(dc, goldfish_rtc_properties); dc->realize =3D goldfish_rtc_realize; dc->reset =3D goldfish_rtc_reset; dc->vmsd =3D &goldfish_rtc_vmstate; diff --git a/include/hw/rtc/goldfish_rtc.h b/include/hw/rtc/goldfish_rtc.h index 79ca7daf5d..162be33863 100644 --- a/include/hw/rtc/goldfish_rtc.h +++ b/include/hw/rtc/goldfish_rtc.h @@ -42,6 +42,8 @@ struct GoldfishRTCState { uint32_t irq_pending; uint32_t irq_enabled; uint32_t time_high; + + bool big_endian; }; =20 #endif --=20 2.37.1 From nobody Thu May 9 15:43:25 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659136080; cv=none; d=zohomail.com; s=zohoarc; b=O53RxwgZxA0OqA0DAOMEL5nyw6eX17vMpi/gVqgKK1jg/kiN/mxyEgWGtEvSOB7pSCu28qrVT6K2rHpg1BX60DoGYehyM9cVtESC5mNU9w+LzUZKImo3GjmGxRzKz9r3zzlCbi9/UpVzDirhw8hXn/bmD809oDG6bcsZVxIxwI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659136080; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7eRWEOO4OsWJrqTDgs7m1wYUwTTU+91A1WtKoqmKyUc=; b=m55PUl1RvKahNoUMqdwpzYxSOVDFJXZEtDft0UJJKwHETIZLhz0do7p3DbF8359lmJPAreOqC18PSSqI3VHkWu3BcMy9vH+liGH/KIkhECPaCZs6Kf7KVo2RYb5mIvEsEqIdP07Sdt5qDJqDC/HtXkIPGK4GHxU09hMQEmfVMyE= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659136080631799.8762780054045; Fri, 29 Jul 2022 16:08:00 -0700 (PDT) Received: from localhost ([::1]:37154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHZ5L-0005ku-Do for importer@patchew.org; Fri, 29 Jul 2022 19:07:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHZ3s-00033d-Dp for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:28 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:45605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHZ3q-0001rg-0u for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:28 -0400 Received: by mail-pj1-x1034.google.com with SMTP id p14-20020a17090a74ce00b001f4d04492faso376233pjl.4 for ; Fri, 29 Jul 2022 16:06:25 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id n5-20020a170902e54500b0016c0593876csm4192630plf.157.2022.07.29.16.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 16:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7eRWEOO4OsWJrqTDgs7m1wYUwTTU+91A1WtKoqmKyUc=; b=bU9C850R5WZfbPlEZRAX7IgsgKkev4cOe2SlfaydI1OI9m4McCcoLCzcD0OHUknrpD bHxBoCm7r62imks2ob78eODz8NZZvsvx/C3H/z/YIax2S22r9masPAlTfLvJYZ00qFzY mv7lY/zD79PG7/jReiVsXvR21jvn8MUso4bOxpDHI5oIaIQzw5Su7dcBlFSYZK0GRlcs rpJHAcNrwqGoiyG2y8ueqoylcoJnLVwFMr/xOhrsTXuXjcGMRrszKMJc3EPc6w4dQVon UJOxWTEFK9HmQ/6Jb/TqLGdSz/MJ0R5hbUjbb6DWoLq+ELFfGhjHCMmUC28KtHWp5unn 0vDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7eRWEOO4OsWJrqTDgs7m1wYUwTTU+91A1WtKoqmKyUc=; b=f7vtOelhOWxows9oPgXCmXC+1ALKcpyrEVj62WVKVs2Q0lcWibVazdZLwvaI6SVtV+ DMcEEJtOzCLDGiHm9zUBCX+K8G2UD2+e5t6JDynlpv+0lre7XAbBHl6vOpAAO5cDoTzB MjH1bJNCpT/P20yscUW8tPk0e1FOkTIcOAOm/BiBXObmx7qIe3HFH61dqEHPvJ1Z7/zj eOrIuHskgV0hbPeJgYa/HoMe0Dol5oJzjKjOLVwsM7o/dd8484RlU3l85pgkzSgACloq xk+R3mqHlMMqx/leoMLl/RL0B3bpsFWSwXVlqlrKZRe2H4DwGuy6BS69M4uDgfaSES4r SA6g== X-Gm-Message-State: ACgBeo0Hzq8EThHl10r7wcZ15UOlS8RWvB/HzxAHITuyjWsXZpONgd/J 3m8Gw6s9LE5o406O0+bQqhsfYT6/f7KflA== X-Google-Smtp-Source: AA6agR4HZWODw2eq2AreGAi0Q3O7wSrUkFp6ExPiK2rgurpUTUOkrEUE7g+sXG9/1HWjP8fSL8zFoA== X-Received: by 2002:a17:902:e849:b0:16e:81c6:2cb7 with SMTP id t9-20020a170902e84900b0016e81c62cb7mr3132638plg.110.1659135983166; Fri, 29 Jul 2022 16:06:23 -0700 (PDT) From: Stafford Horne To: QEMU Development Cc: Openrisc , Richard Henderson , Stafford Horne Subject: [PATCH v3 04/11] hw/openrisc: Add the OpenRISC virtual machine Date: Sat, 30 Jul 2022 08:01:10 +0900 Message-Id: <20220729230117.3768312-5-shorne@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220729230117.3768312-1-shorne@gmail.com> References: <20220729230117.3768312-1-shorne@gmail.com> 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: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=shorne@gmail.com; helo=mail-pj1-x1034.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659136082082100002 Content-Type: text/plain; charset="utf-8" This patch adds the OpenRISC virtual machine 'virt' for OpenRISC. This platform allows for a convenient CI platform for toolchain, software ports and the OpenRISC linux kernel port. Much of this has been sourced from the m68k and riscv virt platforms. The platform provides: - OpenRISC SMP with up to 4 cpus - A virtio bus with up to 8 devices - Standard ns16550a serial - Goldfish RTC - SiFive TEST device for poweroff and reboot - Generated Device Tree to automatically configure the guest kernel Signed-off-by: Stafford Horne --- Since v2: - No changes configs/devices/or1k-softmmu/default.mak | 1 + hw/openrisc/Kconfig | 9 + hw/openrisc/meson.build | 1 + hw/openrisc/virt.c | 417 +++++++++++++++++++++++ 4 files changed, 428 insertions(+) create mode 100644 hw/openrisc/virt.c diff --git a/configs/devices/or1k-softmmu/default.mak b/configs/devices/or1= k-softmmu/default.mak index 168101c39a..89c39e3123 100644 --- a/configs/devices/or1k-softmmu/default.mak +++ b/configs/devices/or1k-softmmu/default.mak @@ -3,3 +3,4 @@ # Boards: # CONFIG_OR1K_SIM=3Dy +CONFIG_OR1K_VIRT=3Dy diff --git a/hw/openrisc/Kconfig b/hw/openrisc/Kconfig index 8f284f3ba0..202134668e 100644 --- a/hw/openrisc/Kconfig +++ b/hw/openrisc/Kconfig @@ -4,3 +4,12 @@ config OR1K_SIM select OPENCORES_ETH select OMPIC select SPLIT_IRQ + +config OR1K_VIRT + bool + imply VIRTIO_VGA + imply TEST_DEVICES + select GOLDFISH_RTC + select SERIAL + select SIFIVE_TEST + select VIRTIO_MMIO diff --git a/hw/openrisc/meson.build b/hw/openrisc/meson.build index ab563820c5..2dbc6365bb 100644 --- a/hw/openrisc/meson.build +++ b/hw/openrisc/meson.build @@ -2,5 +2,6 @@ openrisc_ss =3D ss.source_set() openrisc_ss.add(files('cputimer.c')) openrisc_ss.add(files('boot.c')) openrisc_ss.add(when: 'CONFIG_OR1K_SIM', if_true: [files('openrisc_sim.c')= , fdt]) +openrisc_ss.add(when: 'CONFIG_OR1K_VIRT', if_true: [files('virt.c'), fdt]) =20 hw_arch +=3D {'openrisc': openrisc_ss} diff --git a/hw/openrisc/virt.c b/hw/openrisc/virt.c new file mode 100644 index 0000000000..54f2732a6b --- /dev/null +++ b/hw/openrisc/virt.c @@ -0,0 +1,417 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * OpenRISC QEMU virtual machine. + * + * (c) 2022 Stafford Horne + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qapi/error.h" +#include "cpu.h" +#include "exec/address-spaces.h" +#include "hw/irq.h" +#include "hw/boards.h" +#include "hw/char/serial.h" +#include "hw/core/split-irq.h" +#include "hw/openrisc/boot.h" +#include "hw/misc/sifive_test.h" +#include "hw/qdev-properties.h" +#include "hw/rtc/goldfish_rtc.h" +#include "hw/sysbus.h" +#include "hw/virtio/virtio-mmio.h" +#include "sysemu/device_tree.h" +#include "sysemu/sysemu.h" +#include "sysemu/qtest.h" +#include "sysemu/reset.h" + +#include + +#define VIRT_CPUS_MAX 4 +#define VIRT_CLK_MHZ 20000000 + +#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("virt") +#define VIRT_MACHINE(obj) \ + OBJECT_CHECK(OR1KVirtState, (obj), TYPE_VIRT_MACHINE) + +typedef struct OR1KVirtState { + /*< private >*/ + MachineState parent_obj; + + /*< public >*/ + void *fdt; + int fdt_size; + +} OR1KVirtState; + +enum { + VIRT_DRAM, + VIRT_TEST, + VIRT_RTC, + VIRT_VIRTIO, + VIRT_UART, + VIRT_OMPIC, +}; + +enum { + VIRT_OMPIC_IRQ =3D 1, + VIRT_UART_IRQ =3D 2, + VIRT_RTC_IRQ =3D 3, + VIRT_VIRTIO_IRQ =3D 4, /* to 12 */ + VIRTIO_COUNT =3D 8, +}; + +static const struct MemmapEntry { + hwaddr base; + hwaddr size; +} virt_memmap[] =3D { + [VIRT_DRAM] =3D { 0x00000000, 0 }, + [VIRT_UART] =3D { 0x90000000, 0x100 }, + [VIRT_TEST] =3D { 0x96000000, 0x8 }, + [VIRT_RTC] =3D { 0x96005000, 0x1000 }, + [VIRT_VIRTIO] =3D { 0x97000000, 0x1000 }, + [VIRT_OMPIC] =3D { 0x98000000, VIRT_CPUS_MAX * 8 }, +}; + +static struct openrisc_boot_info { + uint32_t bootstrap_pc; + uint32_t fdt_addr; +} boot_info; + +static void main_cpu_reset(void *opaque) +{ + OpenRISCCPU *cpu =3D opaque; + CPUState *cs =3D CPU(cpu); + + cpu_reset(CPU(cpu)); + + cpu_set_pc(cs, boot_info.bootstrap_pc); + cpu_set_gpr(&cpu->env, 3, boot_info.fdt_addr); +} + +static qemu_irq get_cpu_irq(OpenRISCCPU *cpus[], int cpunum, int irq_pin) +{ + return qdev_get_gpio_in_named(DEVICE(cpus[cpunum]), "IRQ", irq_pin); +} + +static qemu_irq get_per_cpu_irq(OpenRISCCPU *cpus[], int num_cpus, int irq= _pin) +{ + int i; + + if (num_cpus > 1) { + DeviceState *splitter =3D qdev_new(TYPE_SPLIT_IRQ); + qdev_prop_set_uint32(splitter, "num-lines", num_cpus); + qdev_realize_and_unref(splitter, NULL, &error_fatal); + for (i =3D 0; i < num_cpus; i++) { + qdev_connect_gpio_out(splitter, i, get_cpu_irq(cpus, i, irq_pi= n)); + } + return qdev_get_gpio_in(splitter, 0); + } else { + return get_cpu_irq(cpus, 0, irq_pin); + } +} + +static void openrisc_create_fdt(OR1KVirtState *state, + const struct MemmapEntry *memmap, + int num_cpus, uint64_t mem_size, + const char *cmdline) +{ + void *fdt; + int cpu; + char *nodename; + int pic_ph; + + fdt =3D state->fdt =3D create_device_tree(&state->fdt_size); + if (!fdt) { + error_report("create_device_tree() failed"); + exit(1); + } + + qemu_fdt_setprop_string(fdt, "/", "compatible", "opencores,or1ksim"); + qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 0x1); + qemu_fdt_setprop_cell(fdt, "/", "#size-cells", 0x1); + + qemu_fdt_add_subnode(fdt, "/soc"); + qemu_fdt_setprop(fdt, "/soc", "ranges", NULL, 0); + qemu_fdt_setprop_string(fdt, "/soc", "compatible", "simple-bus"); + qemu_fdt_setprop_cell(fdt, "/soc", "#address-cells", 0x1); + qemu_fdt_setprop_cell(fdt, "/soc", "#size-cells", 0x1); + + nodename =3D g_strdup_printf("/memory@%" HWADDR_PRIx, + memmap[VIRT_DRAM].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cells(fdt, nodename, "reg", + memmap[VIRT_DRAM].base, mem_size); + qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory"); + g_free(nodename); + + qemu_fdt_add_subnode(fdt, "/cpus"); + qemu_fdt_setprop_cell(fdt, "/cpus", "#size-cells", 0x0); + qemu_fdt_setprop_cell(fdt, "/cpus", "#address-cells", 0x1); + + for (cpu =3D 0; cpu < num_cpus; cpu++) { + nodename =3D g_strdup_printf("/cpus/cpu@%d", cpu); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", + "opencores,or1200-rtlsvn481"); + qemu_fdt_setprop_cell(fdt, nodename, "reg", cpu); + qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency", + VIRT_CLK_MHZ); + g_free(nodename); + } + + nodename =3D (char *)"/pic"; + qemu_fdt_add_subnode(fdt, nodename); + pic_ph =3D qemu_fdt_alloc_phandle(fdt); + qemu_fdt_setprop_string(fdt, nodename, "compatible", + "opencores,or1k-pic-level"); + qemu_fdt_setprop_cell(fdt, nodename, "#interrupt-cells", 1); + qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0); + qemu_fdt_setprop_cell(fdt, nodename, "phandle", pic_ph); + + qemu_fdt_setprop_cell(fdt, "/", "interrupt-parent", pic_ph); + + qemu_fdt_add_subnode(fdt, "/chosen"); + if (cmdline) { + qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); + } + + /* Create aliases node for use by devices. */ + qemu_fdt_add_subnode(fdt, "/aliases"); +} + +static void openrisc_virt_ompic_init(OR1KVirtState *state, hwaddr base, + hwaddr size, int num_cpus, + OpenRISCCPU *cpus[], int irq_pin) +{ + void *fdt =3D state->fdt; + DeviceState *dev; + SysBusDevice *s; + char *nodename; + int i; + + dev =3D qdev_new("or1k-ompic"); + qdev_prop_set_uint32(dev, "num-cpus", num_cpus); + + s =3D SYS_BUS_DEVICE(dev); + sysbus_realize_and_unref(s, &error_fatal); + for (i =3D 0; i < num_cpus; i++) { + sysbus_connect_irq(s, i, get_cpu_irq(cpus, i, irq_pin)); + } + sysbus_mmio_map(s, 0, base); + + /* Add device tree node for ompic. */ + nodename =3D g_strdup_printf("/ompic@%" HWADDR_PRIx, base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "openrisc,ompic"); + qemu_fdt_setprop_cells(fdt, nodename, "reg", base, size); + qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0); + qemu_fdt_setprop_cell(fdt, nodename, "#interrupt-cells", 0); + qemu_fdt_setprop_cell(fdt, nodename, "interrupts", irq_pin); + g_free(nodename); +} + +static void openrisc_virt_serial_init(OR1KVirtState *state, hwaddr base, + hwaddr size, int num_cpus, + OpenRISCCPU *cpus[], int irq_pin) +{ + void *fdt =3D state->fdt; + char *nodename; + qemu_irq serial_irq =3D get_per_cpu_irq(cpus, num_cpus, irq_pin); + + serial_mm_init(get_system_memory(), base, 0, serial_irq, 115200, + serial_hd(0), DEVICE_NATIVE_ENDIAN); + + /* Add device tree node for serial. */ + nodename =3D g_strdup_printf("/serial@%" HWADDR_PRIx, base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "ns16550a"); + qemu_fdt_setprop_cells(fdt, nodename, "reg", base, size); + qemu_fdt_setprop_cell(fdt, nodename, "interrupts", irq_pin); + qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency", VIRT_CLK_MHZ); + qemu_fdt_setprop(fdt, nodename, "big-endian", NULL, 0); + + /* The /chosen node is created during fdt creation. */ + qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", nodename); + qemu_fdt_setprop_string(fdt, "/aliases", "uart0", nodename); + g_free(nodename); +} + +static void openrisc_virt_test_init(OR1KVirtState *state, hwaddr base, + hwaddr size) +{ + void *fdt =3D state->fdt; + int test_ph; + char *nodename; + + /* SiFive Test MMIO device */ + sifive_test_create(base); + + /* SiFive Test MMIO Reset device FDT */ + nodename =3D g_strdup_printf("/soc/test@%" HWADDR_PRIx, base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon"); + test_ph =3D qemu_fdt_alloc_phandle(fdt); + qemu_fdt_setprop_cells(fdt, nodename, "reg", base, size); + qemu_fdt_setprop_cell(fdt, nodename, "phandle", test_ph); + qemu_fdt_setprop(fdt, nodename, "big-endian", NULL, 0); + g_free(nodename); + + nodename =3D g_strdup_printf("/soc/reboot"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-reboot"); + qemu_fdt_setprop_cell(fdt, nodename, "regmap", test_ph); + qemu_fdt_setprop_cell(fdt, nodename, "offset", 0x0); + qemu_fdt_setprop_cell(fdt, nodename, "value", FINISHER_RESET); + g_free(nodename); + + nodename =3D g_strdup_printf("/soc/poweroff"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "syscon-poweroff"= ); + qemu_fdt_setprop_cell(fdt, nodename, "regmap", test_ph); + qemu_fdt_setprop_cell(fdt, nodename, "offset", 0x0); + qemu_fdt_setprop_cell(fdt, nodename, "value", FINISHER_PASS); + g_free(nodename); + +} +static void openrisc_virt_rtc_init(OR1KVirtState *state, hwaddr base, + hwaddr size, int num_cpus, + OpenRISCCPU *cpus[], int irq_pin) +{ + void *fdt =3D state->fdt; + char *nodename; + qemu_irq rtc_irq =3D get_per_cpu_irq(cpus, num_cpus, irq_pin); + + /* Goldfish RTC */ + sysbus_create_simple(TYPE_GOLDFISH_RTC, base, rtc_irq); + + /* Goldfish RTC FDT */ + nodename =3D g_strdup_printf("/soc/rtc@%" HWADDR_PRIx, base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", + "google,goldfish-rtc"); + qemu_fdt_setprop_cells(fdt, nodename, "reg", base, size); + qemu_fdt_setprop_cell(fdt, nodename, "interrupts", irq_pin); + g_free(nodename); + +} +static void openrisc_virt_virtio_init(OR1KVirtState *state, hwaddr base, + hwaddr size, int num_cpus, + OpenRISCCPU *cpus[], int irq_pin) +{ + void *fdt =3D state->fdt; + char *nodename; + DeviceState *dev; + SysBusDevice *sysbus; + qemu_irq virtio_irq =3D get_per_cpu_irq(cpus, num_cpus, irq_pin); + + /* VirtIO MMIO devices */ + dev =3D qdev_new(TYPE_VIRTIO_MMIO); + qdev_prop_set_bit(dev, "force-legacy", false); + sysbus =3D SYS_BUS_DEVICE(dev); + sysbus_realize_and_unref(sysbus, &error_fatal); + sysbus_connect_irq(sysbus, 0, virtio_irq); + sysbus_mmio_map(sysbus, 0, base); + + /* VirtIO MMIO devices FDT */ + nodename =3D g_strdup_printf("/soc/virtio_mmio@%" HWADDR_PRIx, base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "virtio,mmio"); + qemu_fdt_setprop_cells(fdt, nodename, "reg", base, size); + qemu_fdt_setprop_cell(fdt, nodename, "interrupts", irq_pin); + g_free(nodename); +} + +static void openrisc_virt_init(MachineState *machine) +{ + ram_addr_t ram_size =3D machine->ram_size; + const char *kernel_filename =3D machine->kernel_filename; + OpenRISCCPU *cpus[VIRT_CPUS_MAX] =3D {}; + OR1KVirtState *state =3D VIRT_MACHINE(machine); + MemoryRegion *ram; + hwaddr load_addr; + int n; + unsigned int smp_cpus =3D machine->smp.cpus; + + assert(smp_cpus >=3D 1 && smp_cpus <=3D VIRT_CPUS_MAX); + for (n =3D 0; n < smp_cpus; n++) { + cpus[n] =3D OPENRISC_CPU(cpu_create(machine->cpu_type)); + if (cpus[n] =3D=3D NULL) { + fprintf(stderr, "Unable to find CPU definition!\n"); + exit(1); + } + + cpu_openrisc_clock_init(cpus[n]); + + qemu_register_reset(main_cpu_reset, cpus[n]); + } + + ram =3D g_malloc(sizeof(*ram)); + memory_region_init_ram(ram, NULL, "openrisc.ram", ram_size, &error_fat= al); + memory_region_add_subregion(get_system_memory(), 0, ram); + + openrisc_create_fdt(state, virt_memmap, smp_cpus, machine->ram_size, + machine->kernel_cmdline); + + if (smp_cpus > 1) { + openrisc_virt_ompic_init(state, virt_memmap[VIRT_OMPIC].base, + virt_memmap[VIRT_OMPIC].size, + smp_cpus, cpus, VIRT_OMPIC_IRQ); + } + + openrisc_virt_serial_init(state, virt_memmap[VIRT_UART].base, + virt_memmap[VIRT_UART].size, + smp_cpus, cpus, VIRT_UART_IRQ); + + openrisc_virt_test_init(state, virt_memmap[VIRT_TEST].base, + virt_memmap[VIRT_TEST].size); + + openrisc_virt_rtc_init(state, virt_memmap[VIRT_RTC].base, + virt_memmap[VIRT_RTC].size, smp_cpus, cpus, + VIRT_RTC_IRQ); + + for (n =3D 0; n < VIRTIO_COUNT; n++) { + openrisc_virt_virtio_init(state, virt_memmap[VIRT_VIRTIO].base + + n * virt_memmap[VIRT_VIRTIO].si= ze, + virt_memmap[VIRT_VIRTIO].size, + smp_cpus, cpus, VIRT_VIRTIO_IRQ + n); + } + + load_addr =3D openrisc_load_kernel(ram_size, kernel_filename, + &boot_info.bootstrap_pc); + if (load_addr > 0) { + if (machine->initrd_filename) { + load_addr =3D openrisc_load_initrd(state->fdt, + machine->initrd_filename, + load_addr, machine->ram_size); + } + boot_info.fdt_addr =3D openrisc_load_fdt(state->fdt, load_addr, + machine->ram_size); + } +} + +static void openrisc_virt_machine_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->desc =3D "or1k virtual machine"; + mc->init =3D openrisc_virt_init; + mc->max_cpus =3D VIRT_CPUS_MAX; + mc->is_default =3D false; + mc->default_cpu_type =3D OPENRISC_CPU_TYPE_NAME("or1200"); +} + +static const TypeInfo or1ksim_machine_typeinfo =3D { + .name =3D TYPE_VIRT_MACHINE, + .parent =3D TYPE_MACHINE, + .class_init =3D openrisc_virt_machine_init, + .instance_size =3D sizeof(OR1KVirtState), +}; + +static void or1ksim_machine_init_register_types(void) +{ + type_register_static(&or1ksim_machine_typeinfo); +} + +type_init(or1ksim_machine_init_register_types) --=20 2.37.1 From nobody Thu May 9 15:43:25 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659136285; cv=none; d=zohomail.com; s=zohoarc; b=XPK7gyjflKBzTU8anG8cseieFYHfqi5hM5PNQCtT9h5fO42NBnuMNp9oboV4nlAAJFu8FX1H5H28M4e9/cegJz1LLGIi7SuSd2vnYzK0ZeYcDucC6ZjuiuiDCQytlY9ePhYFxXg4h4AfvjDWy+aLd0YX9Hl+gRdI3x1lQMrDOPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659136285; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lwhK+uEqsgQFIgeyWnA4c2a6MyqKG9WuVXiIwSR70Dc=; b=P+eHosqCKUtP97aNqd48TSPlgnZLU/szULn3HtjucxmkFof2cROxEj+YXPV1bnA7BbETLyQuwct0LhmYK1+Lio3jV3NBcJt/4h/rCuvhc/Goi1DHvvgIopELnlGN7OmBgXO5qFPMhhuD2E2yiq3Nh+cwBrEy9psdCPB8Ij3SQv0= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659136285688827.9693325542002; Fri, 29 Jul 2022 16:11:25 -0700 (PDT) Received: from localhost ([::1]:45636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHZ8e-00031w-Kc for importer@patchew.org; Fri, 29 Jul 2022 19:11:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50536) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHZ3u-00036R-7j for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:30 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:39717) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHZ3r-0001sN-2e for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:29 -0400 Received: by mail-pj1-x1034.google.com with SMTP id h21-20020a17090aa89500b001f31a61b91dso6865710pjq.4 for ; Fri, 29 Jul 2022 16:06:26 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id g31-20020a63201f000000b0041ae78c3493sm3024009pgg.52.2022.07.29.16.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 16:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lwhK+uEqsgQFIgeyWnA4c2a6MyqKG9WuVXiIwSR70Dc=; b=fmgr/rrchXM4mk3DnimUrENvd6SKgN6mU7K2ceA57/IT2YfWj0S2rdfZnu69YDAGrd pvdxEZAPfhI2Gb7y1Cjha7FCUQBnPzT7WStWnFmsXOVJWDoPhLhCg0aBXNy0ecQrvgB4 pYz4mY/AVK/GfVwyeP1bSDd9/47uL3FO5mfBEXXpXge5fcECGv71hTomluariQ0zMAfD aaJtm3yzNfQiFddXWTzKMOYyLJpAuMFzgATfxcKKevFQ7LqM4/Pn/VQIeGqfStwpJGAe EZQDbyij0T/VY9qbiyySxUNgJZdPr/BNquqo8j4ujcB3uvwW0XiFGeQHBlgSAA1ffxcP ELNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lwhK+uEqsgQFIgeyWnA4c2a6MyqKG9WuVXiIwSR70Dc=; b=cksZIZBcRUspuuV76FOtg5qEQ8m9gyp638LvIJa4HDfXubrDMcO32qm7Hd9BFgq9QM rCHBNQybQIAD6g9uNzJhobagzUREWRkC4wuYEwoIwhPAErm22Q7xO/Xk3pIfqfOCNgOv y7rueS1n5Jetd10mu5tQK7SfbEHo+z/DZx+jzUNS069t3m9Lv5diPd1TY9VK3GYScXJl CWVxTiMtJtLDz7LMfmWtwU928xONa00smYFnIjRYUSOQKaA6Zr5L7EnASouWWH+PLr+7 1yreust/HZfKDOCHk7g8MdyX2J/It/zwoUvILDw/woqt6BTXV6q8x6FXlwdqXSCi1q/6 /1AQ== X-Gm-Message-State: ACgBeo3ECCUAIzcXh2BaXFHuYt0jomjfa3/u4nfJNwQ/uZBQgVZsx7KS RVVXje5DLJfrdp2kpWAgP+rrS0k3Qo/ZWg== X-Google-Smtp-Source: AA6agR4Wf0kespnaRiRosCc0LQs3cdNXa1osJkIwWyAkPz7/DniIdIHv0+bCxNVe8LVOUFXBji+Plw== X-Received: by 2002:a17:902:eb81:b0:16d:847a:5f95 with SMTP id q1-20020a170902eb8100b0016d847a5f95mr6034447plg.166.1659135985347; Fri, 29 Jul 2022 16:06:25 -0700 (PDT) From: Stafford Horne To: QEMU Development Cc: Openrisc , Richard Henderson , Stafford Horne Subject: [PATCH v3 05/11] hw/openrisc: Add PCI bus support to virt Date: Sat, 30 Jul 2022 08:01:11 +0900 Message-Id: <20220729230117.3768312-6-shorne@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220729230117.3768312-1-shorne@gmail.com> References: <20220729230117.3768312-1-shorne@gmail.com> 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: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=shorne@gmail.com; helo=mail-pj1-x1034.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659136287423100005 Content-Type: text/plain; charset="utf-8" This is mostly borrowed from xtensa and riscv as examples. The create_pcie_irq_map swizzle function is almost and exact copy but here we use a single cell interrupt, possibly we can make this generic. Signed-off-by: Stafford Horne --- Since v2: - No changes hw/openrisc/Kconfig | 3 + hw/openrisc/virt.c | 160 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 157 insertions(+), 6 deletions(-) diff --git a/hw/openrisc/Kconfig b/hw/openrisc/Kconfig index 202134668e..97af258b55 100644 --- a/hw/openrisc/Kconfig +++ b/hw/openrisc/Kconfig @@ -7,8 +7,11 @@ config OR1K_SIM =20 config OR1K_VIRT bool + imply PCI_DEVICES imply VIRTIO_VGA imply TEST_DEVICES + select PCI + select PCI_EXPRESS_GENERIC_BRIDGE select GOLDFISH_RTC select SERIAL select SIFIVE_TEST diff --git a/hw/openrisc/virt.c b/hw/openrisc/virt.c index 54f2732a6b..9a78234a28 100644 --- a/hw/openrisc/virt.c +++ b/hw/openrisc/virt.c @@ -17,6 +17,8 @@ #include "hw/core/split-irq.h" #include "hw/openrisc/boot.h" #include "hw/misc/sifive_test.h" +#include "hw/pci/pci.h" +#include "hw/pci-host/gpex.h" #include "hw/qdev-properties.h" #include "hw/rtc/goldfish_rtc.h" #include "hw/sysbus.h" @@ -47,6 +49,9 @@ typedef struct OR1KVirtState { =20 enum { VIRT_DRAM, + VIRT_ECAM, + VIRT_MMIO, + VIRT_PIO, VIRT_TEST, VIRT_RTC, VIRT_VIRTIO, @@ -60,6 +65,7 @@ enum { VIRT_RTC_IRQ =3D 3, VIRT_VIRTIO_IRQ =3D 4, /* to 12 */ VIRTIO_COUNT =3D 8, + VIRT_PCI_IRQ_BASE =3D 13, /* to 17 */ }; =20 static const struct MemmapEntry { @@ -72,6 +78,9 @@ static const struct MemmapEntry { [VIRT_RTC] =3D { 0x96005000, 0x1000 }, [VIRT_VIRTIO] =3D { 0x97000000, 0x1000 }, [VIRT_OMPIC] =3D { 0x98000000, VIRT_CPUS_MAX * 8 }, + [VIRT_ECAM] =3D { 0x9e000000, 0x1000000 }, + [VIRT_PIO] =3D { 0x9f000000, 0x1000000 }, + [VIRT_MMIO] =3D { 0xa0000000, 0x10000000 }, }; =20 static struct openrisc_boot_info { @@ -115,12 +124,12 @@ static qemu_irq get_per_cpu_irq(OpenRISCCPU *cpus[], = int num_cpus, int irq_pin) static void openrisc_create_fdt(OR1KVirtState *state, const struct MemmapEntry *memmap, int num_cpus, uint64_t mem_size, - const char *cmdline) + const char *cmdline, + int32_t *pic_phandle) { void *fdt; int cpu; char *nodename; - int pic_ph; =20 fdt =3D state->fdt =3D create_device_tree(&state->fdt_size); if (!fdt) { @@ -163,14 +172,14 @@ static void openrisc_create_fdt(OR1KVirtState *state, =20 nodename =3D (char *)"/pic"; qemu_fdt_add_subnode(fdt, nodename); - pic_ph =3D qemu_fdt_alloc_phandle(fdt); + *pic_phandle =3D qemu_fdt_alloc_phandle(fdt); qemu_fdt_setprop_string(fdt, nodename, "compatible", "opencores,or1k-pic-level"); qemu_fdt_setprop_cell(fdt, nodename, "#interrupt-cells", 1); qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0); - qemu_fdt_setprop_cell(fdt, nodename, "phandle", pic_ph); + qemu_fdt_setprop_cell(fdt, nodename, "phandle", *pic_phandle); =20 - qemu_fdt_setprop_cell(fdt, "/", "interrupt-parent", pic_ph); + qemu_fdt_setprop_cell(fdt, "/", "interrupt-parent", *pic_phandle); =20 qemu_fdt_add_subnode(fdt, "/chosen"); if (cmdline) { @@ -275,6 +284,7 @@ static void openrisc_virt_test_init(OR1KVirtState *stat= e, hwaddr base, g_free(nodename); =20 } + static void openrisc_virt_rtc_init(OR1KVirtState *state, hwaddr base, hwaddr size, int num_cpus, OpenRISCCPU *cpus[], int irq_pin) @@ -296,6 +306,134 @@ static void openrisc_virt_rtc_init(OR1KVirtState *sta= te, hwaddr base, g_free(nodename); =20 } + +static void create_pcie_irq_map(void *fdt, char *nodename, int irq_base, + uint32_t irqchip_phandle) +{ + 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 *irq_map =3D full_irq_map; + + /* + * This code creates a standard swizzle of interrupts such that + * each device's first interrupt is based on it's PCI_SLOT number. + * (See pci_swizzle_map_irq_fn()) + * + * We only need one entry per interrupt in the table (not one per + * 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++) { + int devfn =3D dev << 3; + + for (pin =3D 0; pin < GPEX_NUM_IRQS; pin++) { + int irq_nr =3D irq_base + ((pin + PCI_SLOT(devfn)) % GPEX_NUM_= IRQS); + int i =3D 0; + + /* Fill PCI address cells */ + irq_map[i++] =3D cpu_to_be32(devfn << 8); + irq_map[i++] =3D 0; + irq_map[i++] =3D 0; + + /* Fill PCI Interrupt cells */ + irq_map[i++] =3D cpu_to_be32(pin + 1); + + /* Fill interrupt controller phandle and cells */ + irq_map[i++] =3D cpu_to_be32(irqchip_phandle); + irq_map[i++] =3D cpu_to_be32(irq_nr); + + if (!irq_map_stride) { + irq_map_stride =3D i; + } + irq_map +=3D irq_map_stride; + } + } + + qemu_fdt_setprop(fdt, nodename, "interrupt-map", full_irq_map, + GPEX_NUM_IRQS * GPEX_NUM_IRQS * + irq_map_stride * sizeof(uint32_t)); + + qemu_fdt_setprop_cells(fdt, nodename, "interrupt-map-mask", + 0x1800, 0, 0, 0x7); +} + +static void openrisc_virt_pcie_init(OR1KVirtState *state, + hwaddr ecam_base, hwaddr ecam_size, + hwaddr pio_base, hwaddr pio_size, + hwaddr mmio_base, hwaddr mmio_size, + int num_cpus, OpenRISCCPU *cpus[], + int irq_base, int32_t pic_phandle) +{ + void *fdt =3D state->fdt; + char *nodename; + MemoryRegion *alias; + MemoryRegion *reg; + DeviceState *dev; + qemu_irq pcie_irq; + int i; + + dev =3D qdev_new(TYPE_GPEX_HOST); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + + /* Map ECAM space. */ + alias =3D g_new0(MemoryRegion, 1); + reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); + memory_region_init_alias(alias, OBJECT(dev), "pcie-ecam", + reg, 0, ecam_size); + memory_region_add_subregion(get_system_memory(), ecam_base, alias); + + /* + * Map the MMIO window into system address space so as to expose + * the section of PCI MMIO space which starts at the same base address + * (ie 1:1 mapping for that part of PCI MMIO space visible through + * the window). + */ + alias =3D g_new0(MemoryRegion, 1); + reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); + memory_region_init_alias(alias, OBJECT(dev), "pcie-mmio", + reg, mmio_base, mmio_size); + memory_region_add_subregion(get_system_memory(), mmio_base, alias); + + /* Map IO port space. */ + alias =3D g_new0(MemoryRegion, 1); + reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 2); + memory_region_init_alias(alias, OBJECT(dev), "pcie-pio", + reg, 0, pio_size); + memory_region_add_subregion(get_system_memory(), pio_base, alias); + + /* Connect IRQ lines. */ + for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + pcie_irq =3D get_per_cpu_irq(cpus, num_cpus, irq_base + i); + + sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, pcie_irq); + gpex_set_irq_num(GPEX_HOST(dev), i, irq_base + i); + } + + nodename =3D g_strdup_printf("/soc/pci@%" HWADDR_PRIx, ecam_base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "#interrupt-cells", 1); + qemu_fdt_setprop_cell(fdt, nodename, "#address-cells", 3); + qemu_fdt_setprop_cell(fdt, nodename, "#size-cells", 2); + qemu_fdt_setprop_string(fdt, nodename, "compatible", + "pci-host-ecam-generic"); + qemu_fdt_setprop_string(fdt, nodename, "device_type", "pci"); + qemu_fdt_setprop_cell(fdt, nodename, "linux,pci-domain", 0); + qemu_fdt_setprop_cells(fdt, nodename, "bus-range", 0, + ecam_size / PCIE_MMCFG_SIZE_MIN - 1); + qemu_fdt_setprop(fdt, nodename, "dma-coherent", NULL, 0); + qemu_fdt_setprop_cells(fdt, nodename, "reg", ecam_base, ecam_size); + /* pci-address(3) cpu-address(1) pci-size(2) */ + qemu_fdt_setprop_cells(fdt, nodename, "ranges", + FDT_PCI_RANGE_IOPORT, 0, 0, + pio_base, 0, pio_size, + FDT_PCI_RANGE_MMIO, 0, mmio_base, + mmio_base, 0, mmio_size); + + create_pcie_irq_map(fdt, nodename, irq_base, pic_phandle); + g_free(nodename); +} + static void openrisc_virt_virtio_init(OR1KVirtState *state, hwaddr base, hwaddr size, int num_cpus, OpenRISCCPU *cpus[], int irq_pin) @@ -333,6 +471,7 @@ static void openrisc_virt_init(MachineState *machine) hwaddr load_addr; int n; unsigned int smp_cpus =3D machine->smp.cpus; + int32_t pic_phandle; =20 assert(smp_cpus >=3D 1 && smp_cpus <=3D VIRT_CPUS_MAX); for (n =3D 0; n < smp_cpus; n++) { @@ -352,7 +491,7 @@ static void openrisc_virt_init(MachineState *machine) memory_region_add_subregion(get_system_memory(), 0, ram); =20 openrisc_create_fdt(state, virt_memmap, smp_cpus, machine->ram_size, - machine->kernel_cmdline); + machine->kernel_cmdline, &pic_phandle); =20 if (smp_cpus > 1) { openrisc_virt_ompic_init(state, virt_memmap[VIRT_OMPIC].base, @@ -371,6 +510,15 @@ static void openrisc_virt_init(MachineState *machine) virt_memmap[VIRT_RTC].size, smp_cpus, cpus, VIRT_RTC_IRQ); =20 + openrisc_virt_pcie_init(state, virt_memmap[VIRT_ECAM].base, + virt_memmap[VIRT_ECAM].size, + virt_memmap[VIRT_PIO].base, + virt_memmap[VIRT_PIO].size, + virt_memmap[VIRT_MMIO].base, + virt_memmap[VIRT_MMIO].size, + smp_cpus, cpus, + VIRT_PCI_IRQ_BASE, pic_phandle); + for (n =3D 0; n < VIRTIO_COUNT; n++) { openrisc_virt_virtio_init(state, virt_memmap[VIRT_VIRTIO].base + n * virt_memmap[VIRT_VIRTIO].si= ze, --=20 2.37.1 From nobody Thu May 9 15:43:25 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659136081; cv=none; d=zohomail.com; s=zohoarc; b=UeVYFbwhFkUIGeLPitqx1HRoyZGuACjt9yE5bEFL2JYmbpGxGiSGAoGLSad3K31fAC4JM9p4OAez2OOWPaq8oFCkIy1Mywey8Foie2QmJusZx7klQ9qFjlHyoD3zrWEJVMrewIt6IUJBsXEIWrL6HPQCHNGFtGAvk+foKDzjRsA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659136081; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HXCBntOjGzm8ardshRhxv5iuyqDFWrlT1RdhJEN5akM=; b=ITedjDlc2ZnirwbtEFxuMJehZl65mbjs8vJhzTg+iqIzX3fWiy9Xgr1n6EbSc8x8yt5NhKkynG/24dyCLGA0tDDFW1J6UbfjTqenzlX9kGhGu4VMndkI9C8hsqfs0FekKEacu2fBBC+or/IWKjE6PLqMx11juAohLvAkIKlli+g= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659136081710562.5350996388055; Fri, 29 Jul 2022 16:08:01 -0700 (PDT) Received: from localhost ([::1]:37098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHZ5L-0005iW-Lo for importer@patchew.org; Fri, 29 Jul 2022 19:07:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHZ3v-00038Y-0E for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:31 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:34372) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHZ3t-0001sZ-AW for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:30 -0400 Received: by mail-pf1-x435.google.com with SMTP id 70so5836743pfx.1 for ; Fri, 29 Jul 2022 16:06:28 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id 18-20020a621812000000b005251fff13dfsm3410715pfy.155.2022.07.29.16.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 16:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HXCBntOjGzm8ardshRhxv5iuyqDFWrlT1RdhJEN5akM=; b=jm9G1DAeu9TMKmi1nO9GRbQxTheemcGp0UMNI66bL8gsTudxEtALCru01SBxule4qT 6LGA8aehx4PAnoH95P0lT0gKya7WMyUjAw58x1zFlEg2OTxl1u0Xf587dpwN2kEPvv8A f1F8xtBCKWfzRKx0TYbb1ZuDdVg1ZvQH2dVDaRLG4Ub8I9++XJiEEwJgjG8y8JZtG/Cm CDF4rPhKNDg9WuJCaZyXn+BoLrCrG7jCSf1X2yYig1ev4t+GKy0X39XsXf8pXSap59mu 1pjD9Ijoa+OCe2zIn1H+wYNpq7Oys6olp+SgazhUBn5QLrIQrrRG1XWeF4naDyH1k6YH HGIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HXCBntOjGzm8ardshRhxv5iuyqDFWrlT1RdhJEN5akM=; b=1sO8tR15wCeClN0QOnGp17YWSjphDWq7zgMm6QYPrL90Jzv67SGYLAoDikXk64bHjn tAhsVtY5fuINH8fK4B2BvCIbFTXGB21BD4ebKagILTPkeOh1z3gi7Ue4Qd2U1/zcQL9c B/fwS6bkE1o824BK/hBz7+7lR2lJQbvcOfWJ5zP4av/K/39P/EXH8x3eVeHMKvo2q+0m PWzgRbOegNkJCjtCa/OTZGLv+aMNTHfR5PFG5Gia1i9AMrkjldILnzU/KtmFA+8VrUr2 +FzFCGyRYW8+bb0Hg55LMGVqn6rxRoQl4f8AAqR97S1zjzqfC4BOEryucHwpKsvWWgdM /uoQ== X-Gm-Message-State: AJIora8vBIiOfb8sHEx64FCoiWvSt6ud+EARU26uKYi58p4MsBEEhs7e iitSBNBBdDeG/vcxw7KmyeJ84jhedBZE6g== X-Google-Smtp-Source: AGRyM1tPsZ8OBNfYftntOYscYnHcsScjRT0EW2bPuqVRfjYJMfSsCj8B1rRfoch4bfwWWKQkBFkTQQ== X-Received: by 2002:a05:6a00:10ca:b0:4f7:5af4:47b6 with SMTP id d10-20020a056a0010ca00b004f75af447b6mr5677145pfu.6.1659135987758; Fri, 29 Jul 2022 16:06:27 -0700 (PDT) From: Stafford Horne To: QEMU Development Cc: Openrisc , Richard Henderson , Stafford Horne Subject: [PATCH v3 06/11] hw/openrisc: Initialize timer time at startup Date: Sat, 30 Jul 2022 08:01:12 +0900 Message-Id: <20220729230117.3768312-7-shorne@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220729230117.3768312-1-shorne@gmail.com> References: <20220729230117.3768312-1-shorne@gmail.com> 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: pass client-ip=2607:f8b0:4864:20::435; envelope-from=shorne@gmail.com; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659136082082100001 Content-Type: text/plain; charset="utf-8" The last_clk time was initialized at zero, this means when we calculate the first delta we will calculate 0 vs current time which could cause unnecessary hops. This patch moves timer initialization to the cpu reset. There are two resets registered here: 1. Per cpu timer mask (ttmr) reset. 2. Global cpu timer (last_clk and ttcr) reset, attached to the first cpu only. Signed-off-by: Stafford Horne Reviewed-by: Richard Henderson --- Since v2: - Moved timer init from init to reset suggested by Richard hw/openrisc/cputimer.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/hw/openrisc/cputimer.c b/hw/openrisc/cputimer.c index 93268815d8..10163b391b 100644 --- a/hw/openrisc/cputimer.c +++ b/hw/openrisc/cputimer.c @@ -22,6 +22,7 @@ #include "cpu.h" #include "migration/vmstate.h" #include "qemu/timer.h" +#include "sysemu/reset.h" =20 #define TIMER_PERIOD 50 /* 50 ns period for 20 MHz timer */ =20 @@ -122,6 +123,24 @@ static void openrisc_timer_cb(void *opaque) qemu_cpu_kick(CPU(cpu)); } =20 +/* Reset the per CPU counter state. */ +static void openrisc_count_reset(void *opaque) +{ + OpenRISCCPU *cpu =3D opaque; + + if (cpu->env.is_counting) { + cpu_openrisc_count_stop(cpu); + } + cpu->env.ttmr =3D 0x00000000; +} + +/* Reset the global timer state. */ +static void openrisc_timer_reset(void *opaque) +{ + or1k_timer->ttcr =3D 0x00000000; + or1k_timer->last_clk =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); +} + static const VMStateDescription vmstate_or1k_timer =3D { .name =3D "or1k_timer", .version_id =3D 1, @@ -136,10 +155,11 @@ static const VMStateDescription vmstate_or1k_timer = =3D { void cpu_openrisc_clock_init(OpenRISCCPU *cpu) { cpu->env.timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, &openrisc_timer_cb= , cpu); - cpu->env.ttmr =3D 0x00000000; =20 + qemu_register_reset(openrisc_count_reset, cpu); if (or1k_timer =3D=3D NULL) { or1k_timer =3D g_new0(OR1KTimerState, 1); + qemu_register_reset(openrisc_timer_reset, cpu); vmstate_register(NULL, 0, &vmstate_or1k_timer, or1k_timer); } } --=20 2.37.1 From nobody Thu May 9 15:43:25 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659136284; cv=none; d=zohomail.com; s=zohoarc; b=Ct8hzstuL4rkRt8RJesWF+sQ+TyLPwaRearbDVAotXR9wchbbJukOD2revIF2ytoMhQY8GSPQaqpOZpgeeAMjKyR1EXYzwBBWlB9EznK7VCSSWfsNfUZnFpZmFDaSxVcOeIdDOKfuvL5C5ReJ2vGJPcEab4rkgjEi1rWveLWSDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659136284; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=675f6o+9+HX/m5+vXfpzLjKZNc+MOKTIadu1Dz7TZmg=; b=ctfSPpPPcHL7JYlWArT4RLulu2i5MXe1VGjsJS9TPis9isC9K1F71aoYXLxd4tZLj8oTu2PQCAgdiDSLH2yh7KRrw9iUTd8Ide5YMPqtVTIQWk96sSr7/Isw2vU9ByTpEUCMLIM0uAe88o1Tpl85YRYnSEVwnV5pUDaSWfeSY50= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165913628445822.883510166160818; Fri, 29 Jul 2022 16:11:24 -0700 (PDT) Received: from localhost ([::1]:45552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHZ8d-0002yb-F8 for importer@patchew.org; Fri, 29 Jul 2022 19:11:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHZ41-0003PX-Rn for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:37 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]:38442) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHZ3w-0001sq-4v for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:37 -0400 Received: by mail-pl1-x62a.google.com with SMTP id o3so5812108ple.5 for ; Fri, 29 Jul 2022 16:06:31 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id nl8-20020a17090b384800b001f3e643ebbfsm960410pjb.0.2022.07.29.16.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 16:06:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=675f6o+9+HX/m5+vXfpzLjKZNc+MOKTIadu1Dz7TZmg=; b=TyLtWTaJ9zqkX1/mIZPoCZsQMfs696KhW4LJNYCHPJ09q8XfQdjpM7Ld/pTlFT2x+G LrTqSkLDVp1nVgLAFxns2DiTmm6NdJjaYC94J7TnkE4pSfmy/QZILuKwX4R63qm5JBMp IjVT0pGfYTzvoyQy7sZBHH6KYC1qQeCJI3VR8DpKv/YJpwCdd+CwuNDbWFAdG3tcbHyl 8J2bibrbv78EDDOlpQwPoOAYDnRShCtcESVAOIeq41oh/0gC32sVtX4tkFjUhLdvRr9+ pVyrcZgdOJWhGWmIFz3TGds08w9zmF9HNEfJcedeOKqFwJaG9OjIF7t/eNLc29Sq/lPw Yq/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=675f6o+9+HX/m5+vXfpzLjKZNc+MOKTIadu1Dz7TZmg=; b=HJQparEYQXdwAWUBaMHTgmi0EeF50B3PVpFCihR/vP/LJo2zUuqQz+eCKiGLtXeApq Lw59Rlq1Ds3X70WrMrm/pJuU696KR4OTGWNgu2FoWaxS3S1u20SLtrxgsbv/Coim03nc 5firpeF1mlw44uGSeoJnHP3U8EbuVzSWg7pX87ZqXkjybpKcIvdH/PtQZvOpj+V578ed e5C0I/Olan893JU17zKE/vagNl1uU93YtEsrQ4qswYVjcx83unH1Tv5vXZZX1AU6C/bl i7XI9/IzPqEBN21U87l7sfgShs1nDIecmYAbrvO7ZSkRIIzYD5fGrkYGdSOS9YLX13u3 o7tA== X-Gm-Message-State: ACgBeo2ka3LtrpR4ZF1/hog+0C0jP1HCbvg2QScznwf8xmpMWIrOuV3O hikWnDRrQrJnxcp0/HjXZMazMplVuU5Gdw== X-Google-Smtp-Source: AA6agR7Sf7jMkQWJC8pRFddCK1n3AQAfX33tUM7mEG1UwFLydd9mx9OM0xpxFKGRfnSN3Z7zQJEDzQ== X-Received: by 2002:a17:902:c713:b0:16e:cbe3:29da with SMTP id p19-20020a170902c71300b0016ecbe329damr843978plp.61.1659135990367; Fri, 29 Jul 2022 16:06:30 -0700 (PDT) From: Stafford Horne To: QEMU Development Cc: Openrisc , Richard Henderson , Stafford Horne Subject: [PATCH v3 07/11] target/openrisc: Add interrupted CPU to log Date: Sat, 30 Jul 2022 08:01:13 +0900 Message-Id: <20220729230117.3768312-8-shorne@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220729230117.3768312-1-shorne@gmail.com> References: <20220729230117.3768312-1-shorne@gmail.com> 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: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=shorne@gmail.com; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659136285306100001 Content-Type: text/plain; charset="utf-8" When we are tracing it's helpful to know which CPU's are getting interrupted, add that detail to the log line. Reviewed-by: Richard Henderson Signed-off-by: Stafford Horne --- Since v2: - Added Reviewed-by target/openrisc/interrupt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/target/openrisc/interrupt.c b/target/openrisc/interrupt.c index e5724f5371..c31c6f12c4 100644 --- a/target/openrisc/interrupt.c +++ b/target/openrisc/interrupt.c @@ -83,7 +83,9 @@ void openrisc_cpu_do_interrupt(CPUState *cs) [EXCP_TRAP] =3D "TRAP", }; =20 - qemu_log_mask(CPU_LOG_INT, "INT: %s\n", int_name[exception]); + qemu_log_mask(CPU_LOG_INT, "CPU: %d INT: %s\n", + cs->cpu_index, + int_name[exception]); =20 hwaddr vect_pc =3D exception << 8; if (env->cpucfgr & CPUCFGR_EVBARP) { --=20 2.37.1 From nobody Thu May 9 15:43:25 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659136482; cv=none; d=zohomail.com; s=zohoarc; b=jBMQt8p3qGaCxAN8xZ3ulSddU4jxCM/ch7hZA3q1Zx5U4qZKD/QDFVoxmEpYai1aSpVqbkHJ2aOYrLsd1dmEYofFUwdOHhA9JM9Hayk4ZEA2oE/IgQQx7/QSc5AsEoUx/AA4mKhjEJBTzCGxpIw8E57P6G2L+4s1d9d7rtsxhy8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659136482; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2LHdwmKsbt7AaEVYQPi9ZpWVFkuaCwouj850ieoIXdQ=; b=KifIMNh5e818liiC8BvgKEspYZddTMbvvcLvH0OCT5AIFUzi3tD3IgG1X1x5k3qxr23TVjS0DFbvKo7qV372ZMPyzyLAnyF6gOtvfXIiX33aT8T0CdtCegyuhsY9kPBJANtcPVTO/KD99ImXw6AGTlD9Nz6PocRlKBbZZkNIkSA= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659136482399660.2436565737811; Fri, 29 Jul 2022 16:14:42 -0700 (PDT) Received: from localhost ([::1]:52946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHZBp-00086F-7s for importer@patchew.org; Fri, 29 Jul 2022 19:14:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHZ4D-0003am-PS for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:50 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:39522) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHZ3y-0001sy-2a for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:49 -0400 Received: by mail-pg1-x52c.google.com with SMTP id q16so5058514pgq.6 for ; Fri, 29 Jul 2022 16:06:33 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id g4-20020a1709026b4400b0016d3ee4533csm4138832plt.18.2022.07.29.16.06.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 16:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2LHdwmKsbt7AaEVYQPi9ZpWVFkuaCwouj850ieoIXdQ=; b=CGRv/P1JHYI2ToBW5Dm/c7qo6Q0nu/ag+02wMJGky17bJ7WkUmcww+YZRvt7sP32Sm ZC4N2O0fxsYiLSCzV4AsiBcj6m+9y2rX7+sXPmAydgFy+ADmk5iYRFSLO+Ar3ylVtS8q SV7VMzLdqj5/Ddn8K/lmwjNBlt1QXvLzeknZX4c0Drw4vBmved63xIiQh945tU5d7u2O pd8/DBc90gaOsF939eR+hvFsrOp1qEmVLm0nrVOct3cSJFEJGBVS8dTJ3B5z3Ajae7P+ 7hkQnbQ46x7uc9Yq/sE58cmwF9Mj2WYX4ngseHlMkdjH7qlDJJ+9OfSwI5nmJLTUwHnG OiJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2LHdwmKsbt7AaEVYQPi9ZpWVFkuaCwouj850ieoIXdQ=; b=BS+UQvmgnmQdZWMIpVN2+7HYzGzhDW0wgz5HtfagZunC549dqLGhcszn1caiLT4y3X aorsftYb7dYtn+JAhxK3HGUNQIn/rLkhM1xazEnkzu2CuyFAG9MsbMaCvPZriEvjOHHR heGJt0hfeVpgOx/hkkDH7M6/c61Bqj8SpPbC478NCV19TphPzk+y+UnnKSs88Ctv4Lx5 GaSEDijE3ApqJr9fZfgN4iM209vR9HQMEh6hynNuefdaycDMA/GLbktWshxmIZQTmgCn 2KRhpGgaUs79ZgsuSrvVvo8VPjsYQfvxjYqIOV9xHzMVoJrKONa5DK+dX4WgtS9jdIzD 1yhA== X-Gm-Message-State: AJIora/QI/BYCQiBaoSNbsoT4vX/G6pxmpKbAgEH914BGSqwSSt500Xq G2MTiGlKB+UD7DDUcaSGrjQs6DhUQEOWFg== X-Google-Smtp-Source: AGRyM1vVUiXw5u/fXN+3hwNmop5qQzVEVMO1EODHVyIJzcOY3rzJsORomJrDbyorS8KOnnFqxwDDhg== X-Received: by 2002:a05:6a00:14d2:b0:52a:d2a1:5119 with SMTP id w18-20020a056a0014d200b0052ad2a15119mr5801199pfu.36.1659135992522; Fri, 29 Jul 2022 16:06:32 -0700 (PDT) From: Stafford Horne To: QEMU Development Cc: Openrisc , Richard Henderson , Stafford Horne Subject: [PATCH v3 08/11] target/openrisc: Enable MTTCG Date: Sat, 30 Jul 2022 08:01:14 +0900 Message-Id: <20220729230117.3768312-9-shorne@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220729230117.3768312-1-shorne@gmail.com> References: <20220729230117.3768312-1-shorne@gmail.com> 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: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=shorne@gmail.com; helo=mail-pg1-x52c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659136482838100001 Content-Type: text/plain; charset="utf-8" This patch enables multithread TCG for OpenRISC. Since the or1k shared syncrhonized timer can be updated from each vCPU via helpers we use a mutex to synchronize updates. Signed-off-by: Stafford Horne Reviewed-by: Richard Henderson --- Since v2: - Removed cpu_openrisc_timer_has_advanced lock optimization, measuring rev= ealed it did not help much. configs/targets/or1k-softmmu.mak | 1 + target/openrisc/cpu.h | 2 ++ target/openrisc/sys_helper.c | 7 ++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/configs/targets/or1k-softmmu.mak b/configs/targets/or1k-softmm= u.mak index 263e970870..432f855a30 100644 --- a/configs/targets/or1k-softmmu.mak +++ b/configs/targets/or1k-softmmu.mak @@ -1,3 +1,4 @@ TARGET_ARCH=3Dopenrisc +TARGET_SUPPORTS_MTTCG=3Dy TARGET_BIG_ENDIAN=3Dy TARGET_NEED_FDT=3Dy diff --git a/target/openrisc/cpu.h b/target/openrisc/cpu.h index b9584f10d4..1d5efa5ca2 100644 --- a/target/openrisc/cpu.h +++ b/target/openrisc/cpu.h @@ -25,6 +25,8 @@ #include "hw/core/cpu.h" #include "qom/object.h" =20 +#define TCG_GUEST_DEFAULT_MO (0) + #define TYPE_OPENRISC_CPU "or1k-cpu" =20 OBJECT_DECLARE_CPU_TYPE(OpenRISCCPU, OpenRISCCPUClass, OPENRISC_CPU) diff --git a/target/openrisc/sys_helper.c b/target/openrisc/sys_helper.c index 48674231e7..da88ad9e77 100644 --- a/target/openrisc/sys_helper.c +++ b/target/openrisc/sys_helper.c @@ -145,6 +145,7 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong = spr, target_ulong rb) break; case TO_SPR(10, 0): /* TTMR */ { + qemu_mutex_lock_iothread(); if ((env->ttmr & TTMR_M) ^ (rb & TTMR_M)) { switch (rb & TTMR_M) { case TIMER_NONE: @@ -168,14 +169,16 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulon= g spr, target_ulong rb) env->ttmr =3D rb & ~TTMR_IP; cs->interrupt_request &=3D ~CPU_INTERRUPT_TIMER; } - cpu_openrisc_timer_update(cpu); + qemu_mutex_unlock_iothread(); } break; =20 case TO_SPR(10, 1): /* TTCR */ + qemu_mutex_lock_iothread(); cpu_openrisc_count_set(cpu, rb); cpu_openrisc_timer_update(cpu); + qemu_mutex_unlock_iothread(); break; #endif =20 @@ -303,7 +306,9 @@ target_ulong HELPER(mfspr)(CPUOpenRISCState *env, targe= t_ulong rd, return env->ttmr; =20 case TO_SPR(10, 1): /* TTCR */ + qemu_mutex_lock_iothread(); cpu_openrisc_count_update(cpu); + qemu_mutex_unlock_iothread(); return cpu_openrisc_count_get(cpu); #endif =20 --=20 2.37.1 From nobody Thu May 9 15:43:25 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659136100; cv=none; d=zohomail.com; s=zohoarc; b=nANMpNx3odiUBI3EC05VklMwo8dgwlfsINWDxhQ3kQNiScwkkJ7Baj6LGLvdrDpBoVKN4f6qAEmPyRA7ikKwu5k2tYWrkjV6K8fkLm2667mH01NNhIDxrfdavtRXavXDqoLY5FOWVUcYZ8jT7aFu3VnP2w7BKMUuKcTI8O1b3Yo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659136100; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TlVFILlYi0pdD31MJQKEWmRWeQlW2WXHnVn9NT9MijI=; b=QIm7ygMvgFBtM56rQM7pyazsA8xYYxFjLY2f0ofn4N7MkSlvTBr48IilmyIjpwJ0rZtaWfukbGBmOJ2QInyaU0YfIgvCZ+fqqNL+ncsMFLZcF3N5rIabbdpO2m0estA8m0XkuMOuQWjJ2RvtG+8jJ1ywjGyIUFemrN0DW59xq+0= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659136100651170.5121412541847; Fri, 29 Jul 2022 16:08:20 -0700 (PDT) Received: from localhost ([::1]:37702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHZ5f-000683-MH for importer@patchew.org; Fri, 29 Jul 2022 19:08:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHZ43-0003Sy-GB for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:40 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:41816) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHZ40-0001tD-Qr for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:38 -0400 Received: by mail-pg1-x535.google.com with SMTP id 23so5060372pgc.8 for ; Fri, 29 Jul 2022 16:06:36 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id x185-20020a6263c2000000b00528c066678csm3419977pfb.72.2022.07.29.16.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 16:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TlVFILlYi0pdD31MJQKEWmRWeQlW2WXHnVn9NT9MijI=; b=Rw5d5PDARjD8Y4K/aF0raM2kiFzKD6LizbPe8HQ87YdHnfZ1J4GaI0cYXI3wsSpWFf nq5xVUMZQb9exaKYTdm7BPQm8KwbD5fc5xY4pkKWS/feUsY5O+bYUBkoh3KlzKCV97fr 6gCCzPsv/O8sQlr35YPcD3Kxogi2loqqWZnQfNNgy6ZnMWeFIj/cYKe76AQim+trElDZ ubNzwNzWPdeGupuy3VdIskfhWkUcAw3iqfADLVq2in9cG2xYKRtglVRAaeEjgyTYU1BR MRd6u6TVazFuTNvdiKBVRcYRqiST4Y1aBjE25+wS6IhyQBw8AF75y2KXpO3gWEWZ5BAi P+HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TlVFILlYi0pdD31MJQKEWmRWeQlW2WXHnVn9NT9MijI=; b=Bx86ulgM573U/01ImJ0fcUqI5As6oB9bmXQhjU+jeyyArLQRvRWP+4QiRPeN6atpxn 6Mkj3XxqcrkBL5xOJbOdZe/L1317uRx2vSYRHnenjXpPu5SFmjETTDJn2hHZryvstDR6 4d9HhJjLR3+Fa8edqatjxRbRWZ32MMGi7l9kcMvV4ed1h3N6sWOtRo35Ki6B0iBL/hzO fdU1QQPUk4FXTxWNXBvys1R0JF4MbkTpsYNSqTrL8JST4kocgwIO2qMv0TcRzbqxbIFR hLL584nDRa3WullKRodZmE81BKAZSJv5whJte5zqjD/MK/omgHXi5Iczj6gaL32VHi3t F36w== X-Gm-Message-State: ACgBeo04P/rowMwD6npz770P3Y+GewwfVFhyGmgXkooJ5SFvbyx1CfnY j1rElh5TDwZBEQvHmljgi194UVuDnkuLEQ== X-Google-Smtp-Source: AA6agR57g/r2FRojc1uHJGjaNttIjV8/+q9a0izc4ATW+DrCgi9fFfkvHaigIk9M4mF/9Z1g9eJWzQ== X-Received: by 2002:a62:ed0f:0:b0:52c:e8c2:b29e with SMTP id u15-20020a62ed0f000000b0052ce8c2b29emr2536029pfh.42.1659135995209; Fri, 29 Jul 2022 16:06:35 -0700 (PDT) From: Stafford Horne To: QEMU Development Cc: Openrisc , Richard Henderson , Stafford Horne Subject: [PATCH v3 09/11] target/openrisc: Interrupt handling fixes Date: Sat, 30 Jul 2022 08:01:15 +0900 Message-Id: <20220729230117.3768312-10-shorne@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220729230117.3768312-1-shorne@gmail.com> References: <20220729230117.3768312-1-shorne@gmail.com> 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: pass client-ip=2607:f8b0:4864:20::535; envelope-from=shorne@gmail.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659136102206100001 Content-Type: text/plain; charset="utf-8" When running SMP systems we sometimes were seeing lockups where IPI interrupts were being raised by never handled. This looks to be caused by 2 issues in the openrisc interrupt handling logic. 1. After clearing an interrupt the openrisc_cpu_set_irq handler will always clear PICSR. This is not correct as masked interrupts should still be visible in PICSR. 2. After setting PICMR (mask register) and exposed interrupts should cause an interrupt to be raised. This was not being done so add it. This patch fixes both issues. Reviewed-by: Richard Henderson Signed-off-by: Stafford Horne --- Since v2: - Added Reviewed-by target/openrisc/cpu.c | 1 - target/openrisc/sys_helper.c | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c index 41d1b2a24a..cb9f35f408 100644 --- a/target/openrisc/cpu.c +++ b/target/openrisc/cpu.c @@ -98,7 +98,6 @@ static void openrisc_cpu_set_irq(void *opaque, int irq, i= nt level) cpu_interrupt(cs, CPU_INTERRUPT_HARD); } else { cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); - cpu->env.picsr =3D 0; } } #endif diff --git a/target/openrisc/sys_helper.c b/target/openrisc/sys_helper.c index da88ad9e77..09b3c97d7c 100644 --- a/target/openrisc/sys_helper.c +++ b/target/openrisc/sys_helper.c @@ -139,6 +139,13 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong= spr, target_ulong rb) break; case TO_SPR(9, 0): /* PICMR */ env->picmr =3D rb; + qemu_mutex_lock_iothread(); + if (env->picsr & env->picmr) { + cpu_interrupt(cs, CPU_INTERRUPT_HARD); + } else { + cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); + } + qemu_mutex_unlock_iothread(); break; case TO_SPR(9, 2): /* PICSR */ env->picsr &=3D ~rb; --=20 2.37.1 From nobody Thu May 9 15:43:25 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659136296; cv=none; d=zohomail.com; s=zohoarc; b=TQDYFEuVlu1x72/zwvI4GHjYSQrwUsxhoL8fbz3Ta2V3zElX9dkbEqKCHDJUIouysHjMexK2sEZzjuhcuJ/cL7fDcX6O82LKdNPJTsVK3Zx5hgnNo4OuB6H0WzevIZPRPeEUSB2+V1ar/KDn38lPJf12DeVA2aNFZ8UbU2h081k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659136296; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BbWEiIuyggnyFyXXn6RRuP9nqwzyt9y0LyosHzVyHv8=; b=I4a82JFbeCyEva2QOXtp8NQusZdordGlX7mR8DvBuMriF+EleVX3HBEpEj+deD3l92GQyKc5o5S8pAKEKv+mB+bB+geCfG1vy4dkWU6FOhGm5ZftdO62CpL4OxySoLpaoXauWjddoyq/xVN8ggMi2DxamlznMQC97+l6JmlBBEA= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659136296954142.9233910211051; Fri, 29 Jul 2022 16:11:36 -0700 (PDT) Received: from localhost ([::1]:45982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHZ8o-0003Gs-1c for importer@patchew.org; Fri, 29 Jul 2022 19:11:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHZ45-0003V5-48 for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:41 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]:36779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHZ43-0001tn-J9 for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:40 -0400 Received: by mail-pf1-x433.google.com with SMTP id g12so5832231pfb.3 for ; Fri, 29 Jul 2022 16:06:39 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id y14-20020a63e24e000000b0040ced958e8fsm3051983pgj.80.2022.07.29.16.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 16:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BbWEiIuyggnyFyXXn6RRuP9nqwzyt9y0LyosHzVyHv8=; b=irWbsfVCY7EXryHUEgvv9zXRUHvT+ug+enJTNshE7OTDz6mvljflFWeSCqWVnRKXkQ 1ViHLbF59Lg2yTUire29uNENqh5ggpCL8Xft8BfQCipC7WfyfnthVLIfbfDOh24ajmqe f2uMSigEaEQmQscCfycv6pcncYI0AqXMCnvVQqf3Vi1qL5w/hNSvlRY5iS9qA4r+1D/u 5RHzG3YK1lQK3d+0ZnK6pQPf3TuBzBTORICLymG6pqP/0oTl/P33fdJKibUW1Uo4se3l CHO0ksn+P8Glqzij/isR60c2nv9maWKmUzMm6pa2hmxoJTrlgaNPs1B5TjFnvoeDWUMJ j4xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BbWEiIuyggnyFyXXn6RRuP9nqwzyt9y0LyosHzVyHv8=; b=C6e/kFkawbIQJVNNxOihl6DyWh2id5rOZgOkOQwU2M9OeGSPUNNn0KKTulImRi0Lc9 oHvTCAHo1Is857gvCFDiw7ThN50umh/wfY3PUgYq1/NtFhQDSSAwGIsokF6mvlmRZkIp Cfj/Gf9uFFrJZGpXfwNqfADwGtFj95KcZ2g+ut0+0Nhn6uV9kC6nlFO+1ZeKKWlxtWZa ynxS0ASM4Fpe/VZYk3+4v2q0kf7eBemqvfwVDXDEySDgJK6474D3qujkuO7NsRN/rocu NsnhRwz7Z0jqiRL9daA7AmMVIvSnpIlOsUYr3S5DqZMj7mVjO2I/c8v9eA0v3guu8cdb JInA== X-Gm-Message-State: AJIora+j8/h2Ii8hNY21KCJoobImXy7hHYEX9xzj3zt9BLPI4Qn+ElKh WXHudqn1WRfvLEsIglPOJ6cUXWcfH5DAuQ== X-Google-Smtp-Source: AGRyM1vyctu8vP735GDkjlYdyCKhr1opLcOO1hw5ZYtJmbkC6hXPVEihXtTtt8dvGzRGnagm1sJWmg== X-Received: by 2002:a63:c049:0:b0:41b:823d:43a8 with SMTP id z9-20020a63c049000000b0041b823d43a8mr4498276pgi.283.1659135997894; Fri, 29 Jul 2022 16:06:37 -0700 (PDT) From: Stafford Horne To: QEMU Development Cc: Openrisc , Richard Henderson , "Jason A. Donenfeld" , Stafford Horne Subject: [PATCH v3 10/11] hw/openrisc: virt: pass random seed to fdt Date: Sat, 30 Jul 2022 08:01:16 +0900 Message-Id: <20220729230117.3768312-11-shorne@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220729230117.3768312-1-shorne@gmail.com> References: <20220729230117.3768312-1-shorne@gmail.com> 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: pass client-ip=2607:f8b0:4864:20::433; envelope-from=shorne@gmail.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659136297488100001 Content-Type: text/plain; charset="utf-8" From: "Jason A. Donenfeld" If the FDT contains /chosen/rng-seed, then the Linux RNG will use it to initialize early. Set this using the usual guest random number generation function. This is confirmed to successfully initialize the RNG on Linux 5.19-rc2. Signed-off-by: Jason A. Donenfeld Reviewed-by: Richard Henderson Signed-off-by: Stafford Horne --- Since v2: - No changes hw/openrisc/virt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/openrisc/virt.c b/hw/openrisc/virt.c index 9a78234a28..f8a68a6a6b 100644 --- a/hw/openrisc/virt.c +++ b/hw/openrisc/virt.c @@ -8,6 +8,7 @@ =20 #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/guest-random.h" #include "qapi/error.h" #include "cpu.h" #include "exec/address-spaces.h" @@ -130,6 +131,7 @@ static void openrisc_create_fdt(OR1KVirtState *state, void *fdt; int cpu; char *nodename; + uint8_t rng_seed[32]; =20 fdt =3D state->fdt =3D create_device_tree(&state->fdt_size); if (!fdt) { @@ -186,6 +188,10 @@ static void openrisc_create_fdt(OR1KVirtState *state, qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); } =20 + /* Pass seed to RNG. */ + qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); + qemu_fdt_setprop(fdt, "/chosen", "rng-seed", rng_seed, sizeof(rng_seed= )); + /* Create aliases node for use by devices. */ qemu_fdt_add_subnode(fdt, "/aliases"); } --=20 2.37.1 From nobody Thu May 9 15:43:25 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659136563; cv=none; d=zohomail.com; s=zohoarc; b=aeuVnkKO/GUvYfxBjZN3fEE0WqZKY34Y5+jA6CFuBE9KtjDvbcvKZABZMotPMeyfq8NeT2Q5RHzN8fE2BRe43f/GfvEQY7dO00Bmvs6roj4qNdT/dT8gdcLTpnyHzPC13fazXuXAlJCj+0ADu9b8E9qXfQlBj063J5zLp8y094E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659136563; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/6izHYBiV3rdqjDcqKFgIg8VA1mzpR6L0cvMw2fhtCM=; b=STnYtncVfS9XPst9aT6SHijkCaT6dV9nSlCRW3CO1IjXpG3+X11qj5bm2WeI0r5Pi1jzbdpzzy6R9PRfNdqdyaeRw1aoUG/aJfcokfgTI9vOVteVRrvWnE3ceP5C7zAjgP7ZuEhd6Q1vlhNetlrfUcbA8nyBPSKkmHBzPmAnPYk= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659136563094951.4764019968093; Fri, 29 Jul 2022 16:16:03 -0700 (PDT) Received: from localhost ([::1]:56032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHZD7-0001oC-7Q for importer@patchew.org; Fri, 29 Jul 2022 19:16:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHZ4D-0003an-UQ for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:50 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:40583) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHZ48-0001v6-Ho for qemu-devel@nongnu.org; Fri, 29 Jul 2022 19:06:49 -0400 Received: by mail-pg1-x52a.google.com with SMTP id f11so5057011pgj.7 for ; Fri, 29 Jul 2022 16:06:42 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id e17-20020aa798d1000000b0052d03432f63sm290149pfm.183.2022.07.29.16.06.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 16:06:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/6izHYBiV3rdqjDcqKFgIg8VA1mzpR6L0cvMw2fhtCM=; b=I+TWE22cJ3p7lpYGASJ2D1zBpOHjjQy7q2c5jqb8fjNZ4Ov49C1QqHqg5wqIxQcGiY t8ZDMDrkcxT82rUyoDXfc5n4SMAN/suUiac7KoNacpo/pSQZ7RsrdfF5Pw9Q+KMfRfEx KJyeL38XqZu145y9HBPYXX7wNlsZQoHGpyyotypqmuwbkAyjut9bWwb8hdzsNBW2jjLY E+heWcH7Hdyar2NWu5eh7IVkJGWL+WYWMQHP1XtFRD71YeBuVB+YnisY0lKJ/ZaPKp6l eXH2AJzlGym4XBEjuQ5+SB83XhuW265Y87kMJrr1nVYzKdVXWB0Siv+qJIp8WL3Jk0+K VAYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/6izHYBiV3rdqjDcqKFgIg8VA1mzpR6L0cvMw2fhtCM=; b=wuDR5hfQmAJdluTZPdviMcd4Qrr7iIW1myRWonshdDygUatDMrgVdVbLgH4z055Imn Y4+EjO82fzShuhWLMTyoHJAqWuMpRviwyEZoFuOeQg+q1/4VZl94FxiptcgDGjLFpWCD GXCSJ8Pq+s178/E9kMgFWWmCcIidy02pWBSHwj6lhOEUjt4VOcz8oQ6TFCSQqdNN/wmR 2Wh3e8uALJKErGW3UW203/zFNnlC0hKEVtEcrXfzawS4/s/YpcJGRwp9K+y9yXvc15mC LwPII3DWKUMRUHMRrvXwZ0rRI/k3+cJTfn9ZZ1tUkpB8w9qkYhPgNP4QZsNSGsF88xmM +CBQ== X-Gm-Message-State: AJIora9L4X5aShr0lWIcVGUVD7Rl5WdYvHQqgz9wro/QFgiLLFd0HELc Sv5ZPCzZjyN11OMgR+e4sE8jEZ7Fzb/qhQ== X-Google-Smtp-Source: AGRyM1t1wMiSW5CM0qSUt4TSNawhx7/6Z2VLDP8KueCxNsVUvemxad9UdZvMu6JMO5DPVR85HqqHuw== X-Received: by 2002:a05:6a00:244a:b0:52b:e9a8:cb14 with SMTP id d10-20020a056a00244a00b0052be9a8cb14mr5656389pfj.32.1659136001144; Fri, 29 Jul 2022 16:06:41 -0700 (PDT) From: Stafford Horne To: QEMU Development Cc: Openrisc , Richard Henderson , Stafford Horne Subject: [PATCH v3 11/11] docs/system: openrisc: Add OpenRISC documentation Date: Sat, 30 Jul 2022 08:01:17 +0900 Message-Id: <20220729230117.3768312-12-shorne@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220729230117.3768312-1-shorne@gmail.com> References: <20220729230117.3768312-1-shorne@gmail.com> 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: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=shorne@gmail.com; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01, WEIRD_QUOTING=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659136563435100001 Content-Type: text/plain; charset="utf-8" Reviewed-by: Richard Henderson Signed-off-by: Stafford Horne --- Since v2; - Added Reviewed-by docs/system/openrisc/cpu-features.rst | 15 ++++++ docs/system/openrisc/emulation.rst | 17 +++++++ docs/system/openrisc/or1k-sim.rst | 43 ++++++++++++++++ docs/system/openrisc/virt.rst | 50 +++++++++++++++++++ docs/system/target-openrisc.rst | 72 +++++++++++++++++++++++++++ docs/system/targets.rst | 1 + 6 files changed, 198 insertions(+) create mode 100644 docs/system/openrisc/cpu-features.rst create mode 100644 docs/system/openrisc/emulation.rst create mode 100644 docs/system/openrisc/or1k-sim.rst create mode 100644 docs/system/openrisc/virt.rst create mode 100644 docs/system/target-openrisc.rst diff --git a/docs/system/openrisc/cpu-features.rst b/docs/system/openrisc/c= pu-features.rst new file mode 100644 index 0000000000..aeb65e22ff --- /dev/null +++ b/docs/system/openrisc/cpu-features.rst @@ -0,0 +1,15 @@ +CPU Features +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The QEMU emulation of the OpenRISC architecture provides following built in +features. + +- Shadow GPRs +- MMU TLB with 128 entries, 1 way +- Power Management (PM) +- Programmable Interrupt Controller (PIC) +- Tick Timer + +These features are on by default and the presence can be confirmed by chec= king +the contents of the Unit Presence Register (``UPR``) and CPU Configuration +Register (``CPUCFGR``). diff --git a/docs/system/openrisc/emulation.rst b/docs/system/openrisc/emul= ation.rst new file mode 100644 index 0000000000..0af898ab20 --- /dev/null +++ b/docs/system/openrisc/emulation.rst @@ -0,0 +1,17 @@ +OpenRISC 1000 CPU architecture support +=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 + +QEMU's TCG emulation includes support for the OpenRISC or1200 implementati= on of +the OpenRISC 1000 cpu architecture. + +The or1200 cpu also has support for the following instruction subsets: + +- ORBIS32 (OpenRISC Basic Instruction Set) +- ORFPX32 (OpenRISC Floating-Point eXtension) + +In addition to the instruction subsets the QEMU TCG emulation also has sup= port +for most Class II (optional) instructions. + +For information on all OpenRISC instructions please refer to the latest +architecture manual available on the OpenRISC website in the +`OpenRISC Architecture `_ section. diff --git a/docs/system/openrisc/or1k-sim.rst b/docs/system/openrisc/or1k-= sim.rst new file mode 100644 index 0000000000..ef10439737 --- /dev/null +++ b/docs/system/openrisc/or1k-sim.rst @@ -0,0 +1,43 @@ +Or1ksim board +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The QEMU Or1ksim machine emulates the standard OpenRISC board simulator wh= ich is +also the standard SoC configuration. + +Supported devices +----------------- + + * 16550A UART + * ETHOC Ethernet controller + * SMP (OpenRISC multicore using ompic) + +Boot options +------------ + +The Or1ksim machine can be started using the ``-kernel`` and ``-initrd`` o= ptions +to load a Linux kernel and optional disk image. + +.. code-block:: bash + + $ qemu-system-or1k -cpu or1220 -M or1k-sim -nographic \ + -kernel vmlinux \ + -initrd initramfs.cpio.gz \ + -m 128 + +Linux guest kernel configuration +"""""""""""""""""""""""""""""""" + +The 'or1ksim_defconfig' for Linux openrisc kernels includes the right +drivers for the or1ksim machine. If you would like to run an SMP system +choose the 'simple_smp_defconfig' config. + +Hardware configuration information +"""""""""""""""""""""""""""""""""" + +The ``or1k-sim`` board automatically generates a device tree blob ("dtb") +which it passes to the guest. This provides information about the +addresses, interrupt lines and other configuration of the various devices +in the system. + +The location of the DTB will be passed in register ``r3`` to the guest ope= rating +system. diff --git a/docs/system/openrisc/virt.rst b/docs/system/openrisc/virt.rst new file mode 100644 index 0000000000..2fe61ac942 --- /dev/null +++ b/docs/system/openrisc/virt.rst @@ -0,0 +1,50 @@ +'virt' generic virtual platform +=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 + +The ``virt`` board is a platform which does not correspond to any +real hardware; it is designed for use in virtual machines. +It is the recommended board type if you simply want to run +a guest such as Linux and do not care about reproducing the +idiosyncrasies and limitations of a particular bit of real-world +hardware. + +Supported devices +----------------- + + * PCI/PCIe devices + * 8 virtio-mmio transport devices + * 16550A UART + * Goldfish RTC + * SiFive Test device for poweroff and reboot + * SMP (OpenRISC multicore using ompic) + +Boot options +------------ + +The virt machine can be started using the ``-kernel`` and ``-initrd`` opti= ons +to load a Linux kernel and optional disk image. For example: + +.. code-block:: bash + + $ qemu-system-or1k -cpu or1220 -M or1k-sim -nographic \ + -device virtio-net-device,netdev=3Duser -netdev user,id=3Duser,net= =3D10.9.0.1/24,host=3D10.9.0.100 \ + -device virtio-blk-device,drive=3Dd0 -drive file=3Dvirt.qcow2,id= =3Dd0,if=3Dnone,format=3Dqcow2 \ + -kernel vmlinux \ + -initrd initramfs.cpio.gz \ + -m 128 + +Linux guest kernel configuration +"""""""""""""""""""""""""""""""" + +The 'virt_defconfig' for Linux openrisc kernels includes the right drivers= for +the ``virt`` machine. + +Hardware configuration information +"""""""""""""""""""""""""""""""""" + +The ``virt`` board automatically generates a device tree blob ("dtb") whic= h it +passes to the guest. This provides information about the addresses, interr= upt +lines and other configuration of the various devices in the system. + +The location of the DTB will be passed in register ``r3`` to the guest ope= rating +system. diff --git a/docs/system/target-openrisc.rst b/docs/system/target-openrisc.= rst new file mode 100644 index 0000000000..d22971a953 --- /dev/null +++ b/docs/system/target-openrisc.rst @@ -0,0 +1,72 @@ +.. _OpenRISC-System-emulator: + +OpenRISC System emulator +~~~~~~~~~~~~~~~~~~~~~~~~ + +QEMU can emulate 32-bit OpenRISC CPUs using the ``qemu-system-or1k`` execu= table. + +OpenRISC CPUs are generally built into "system-on-chip" (SoC) designs that= run +on FPGAs. These SoCs are based on the same core architecture as the or1ks= im +(the original OpenRISC instruction level simulator) which QEMU supports. F= or +this reason QEMU does not need to support many different boards to support= the +OpenRISC hardware ecosystem. + +The OpenRISC CPU supported by QEMU is the ``or1200``, it supports an MMU a= nd can +run linux. + +Choosing a board model +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +For QEMU's OpenRISC system emulation, you must specify which board model y= ou +want to use with the ``-M`` or ``--machine`` option; the default machine is +``or1k-sim``. + +If you intend to boot Linux, it is possible to have a single kernel image = that +will boot on any of the QEMU machines. To do this one would compile all re= quired +drivers into the kernel. This is possible because QEMU will create a devic= e tree +structure that describes the QEMU machine and pass a pointer to the struct= ure to +the kernel. The kernel can then use this to configure itself for the mach= ine. + +However, typically users will have specific firmware images for a specific= machine. + +If you already have a system image or a kernel that works on hardware and = you +want to boot with QEMU, check whether QEMU lists that machine in its ``-ma= chine +help`` output. If it is listed, then you can probably use that board model= . If +it is not listed, then unfortunately your image will almost certainly not = boot +on QEMU. (You might be able to extract the filesystem and use that with a +different kernel which boots on a system that QEMU does emulate.) + +If you don't care about reproducing the idiosyncrasies of a particular +bit of hardware, such as small amount of RAM, no PCI or other hard disk, e= tc., +and just want to run Linux, the best option is to use the ``virt`` board. = This +is a platform which doesn't correspond to any real hardware and is designe= d for +use in virtual machines. You'll need to compile Linux with a suitable +configuration for running on the ``virt`` board. ``virt`` supports PCI, vi= rtio +and large amounts of RAM. + +Board-specific documentation +=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 + +.. + This table of contents should be kept sorted alphabetically + by the title text of each file, which isn't the same ordering + as an alphabetical sort by filename. + +.. toctree:: + :maxdepth: 1 + + openrisc/or1k-sim + openrisc/virt + +Emulated CPU architecture support +=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 + +.. toctree:: + openrisc/emulation + +OpenRISC CPU features +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. toctree:: + openrisc/cpu-features + diff --git a/docs/system/targets.rst b/docs/system/targets.rst index 9dcd95dd84..224fadae71 100644 --- a/docs/system/targets.rst +++ b/docs/system/targets.rst @@ -21,6 +21,7 @@ Contents: target-m68k target-mips target-ppc + target-openrisc target-riscv target-rx target-s390x --=20 2.37.1