From patchwork Sat Feb 26 01:59:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 12761161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF539C433F5 for ; Sat, 26 Feb 2022 02:03:06 +0000 (UTC) Received: from localhost ([::1]:42492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNmQL-0004q2-G5 for qemu-devel@archiver.kernel.org; Fri, 25 Feb 2022 21:03:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNmMv-00026Q-Mv for qemu-devel@nongnu.org; Fri, 25 Feb 2022 20:59:33 -0500 Received: from [2607:f8b0:4864:20::434] (port=35446 helo=mail-pf1-x434.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNmMu-00073Y-Bg for qemu-devel@nongnu.org; Fri, 25 Feb 2022 20:59:33 -0500 Received: by mail-pf1-x434.google.com with SMTP id l19so6229572pfu.2 for ; Fri, 25 Feb 2022 17:59:31 -0800 (PST) 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=d/xPLWx+WAFUwG3ewQ6NqeIlc0rSfL6G+5HjvVKbLiE=; b=Hr84jzuOOI8GaMlfbFDKfgxztBJuYbkMWdOF4HbYVWD2mi60Ft5a4HvOr/pjqLA/Ls JX5kXjt+9T31FnHHf7AbYMlXm+MtCDssez9A40Nr9t1j2ZrBRY7C1/p6izNNgTBVZYDl MS6K8Q6RDqoeViqY06b1XcoOFBpgbmVtUN4VC8314Fhk4zP/VLGb9T92NH2z+hU6VVo2 YaawCSaepF6JobftsXIqqmbyIA4K0p664Qa3zCOO+8wdpMkWL7z5YWEkqeRkwtf0NCBS X1IOeYNUgxlpJABX3lrqPQOdDzcgkCJ8LxUgSsdcrUlO2K67khY182NcKJRMlwXVUWDy 7/pQ== 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=d/xPLWx+WAFUwG3ewQ6NqeIlc0rSfL6G+5HjvVKbLiE=; b=y/dIiZhzBHQMl4hePs4Te6Hd9wgpbfNau66t8jesdJlNz9zMqmhDbF08qoCGA05dU4 +NAcfccvm3p5h7+d8WYJLw2DZZ2ngAoXXqtk3b3t9FOqXeE81Xxmey8i7vL+5Y1ld45j hB0CJC3AJrAnxsS1Z0CSatnRy3DZzsWNCDCTBopL780IXmqqERaaQbcKd1hxyRQrcEcI i9tEzcHzrL3f18CR2B79r93icuQZ54VC5ZGMCiIGJg1c0WycSbIydVbC0DFg0CVQU/bU /GOOlaey0PSrbH1EmRpTzUlEdQ62TVPXmKYUK3gL1jJ+fPP+7CGiCTn1jXvn37Zxc/P5 5DYA== X-Gm-Message-State: AOAM5328Pu0Y9qkIygAduln3oLm+XLGuoYrdX0f/DQnfFTdIdi2LnSoN 7weOn9B8ZzrpYJpAhno0rit6YLard8FwKA== X-Google-Smtp-Source: ABdhPJyDUwaS/e+2UD6Rws1IjhDaDr2WMradylsKA9GbZ1ZG0tfOlg9emk0gRwvLldaHwNBHY2AFMQ== X-Received: by 2002:a63:8f13:0:b0:375:2313:4096 with SMTP id n19-20020a638f13000000b0037523134096mr8436416pgd.466.1645840770653; Fri, 25 Feb 2022 17:59:30 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id g15-20020aa79f0f000000b004f3c48096d1sm4500281pfr.158.2022.02.25.17.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 17:59:30 -0800 (PST) From: Stafford Horne To: QEMU Development Subject: [PULL v2 1/6] hw/openrisc/openrisc_sim: Create machine state for or1ksim Date: Sat, 26 Feb 2022 10:59:19 +0900 Message-Id: <20220226015924.1293022-2-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220226015924.1293022-1-shorne@gmail.com> References: <20220226015924.1293022-1-shorne@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::434 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=shorne@gmail.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stafford Horne , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This will allow us to attach machine state attributes like the device tree fdt. Signed-off-by: Stafford Horne Reviewed-by: Philippe Mathieu-Daudé --- hw/openrisc/openrisc_sim.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c index 73fe383c2d..26d2370e60 100644 --- a/hw/openrisc/openrisc_sim.c +++ b/hw/openrisc/openrisc_sim.c @@ -37,6 +37,18 @@ #define KERNEL_LOAD_ADDR 0x100 +#define TYPE_OR1KSIM_MACHINE MACHINE_TYPE_NAME("or1k-sim") +#define OR1KSIM_MACHINE(obj) \ + OBJECT_CHECK(Or1ksimState, (obj), TYPE_OR1KSIM_MACHINE) + +typedef struct Or1ksimState { + /*< private >*/ + MachineState parent_obj; + + /*< public >*/ + +} Or1ksimState; + static struct openrisc_boot_info { uint32_t bootstrap_pc; } boot_info; @@ -183,8 +195,10 @@ static void openrisc_sim_init(MachineState *machine) openrisc_load_kernel(ram_size, kernel_filename); } -static void openrisc_sim_machine_init(MachineClass *mc) +static void openrisc_sim_machine_init(ObjectClass *oc, void *data) { + MachineClass *mc = MACHINE_CLASS(oc); + mc->desc = "or1k simulation"; mc->init = openrisc_sim_init; mc->max_cpus = 2; @@ -192,4 +206,16 @@ static void openrisc_sim_machine_init(MachineClass *mc) mc->default_cpu_type = OPENRISC_CPU_TYPE_NAME("or1200"); } -DEFINE_MACHINE("or1k-sim", openrisc_sim_machine_init) +static const TypeInfo or1ksim_machine_typeinfo = { + .name = TYPE_OR1KSIM_MACHINE, + .parent = TYPE_MACHINE, + .class_init = openrisc_sim_machine_init, + .instance_size = sizeof(Or1ksimState), +}; + +static void or1ksim_machine_init_register_types(void) +{ + type_register_static(&or1ksim_machine_typeinfo); +} + +type_init(or1ksim_machine_init_register_types) From patchwork Sat Feb 26 01:59:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 12761163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0F6C7C433EF for ; Sat, 26 Feb 2022 02:05:23 +0000 (UTC) Received: from localhost ([::1]:47824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNmSY-0008Qj-7B for qemu-devel@archiver.kernel.org; Fri, 25 Feb 2022 21:05:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNmMz-0002Ak-D6 for qemu-devel@nongnu.org; Fri, 25 Feb 2022 20:59:37 -0500 Received: from [2607:f8b0:4864:20::634] (port=41595 helo=mail-pl1-x634.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNmMx-00073y-6B for qemu-devel@nongnu.org; Fri, 25 Feb 2022 20:59:36 -0500 Received: by mail-pl1-x634.google.com with SMTP id z2so6212798plg.8 for ; Fri, 25 Feb 2022 17:59:34 -0800 (PST) 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=+a1/AvqQIHRNVAxSn1EGU2MopJ+WOc+lm0G/tKcRReY=; b=BC5bX26qNPBkxG06zdeOi9paDeFz73kbKnGIzzJTvBMSGbveQyYMABsIXrC1w5GpcZ vwv5ELQp0+yzx7soRlVp6WQW556XLO341XlGYhwOzUkrC2s3Wgcv44edRUbG5tISuIEE 3H2oPP9U8AuaxZ6gq+1vTSEDEsiwI56VckNHPKfyMW1BNi7TPPfaqjCB+TaUd+w1VGFL W6mRSVn8OFSSKX7goKK6n/PXulIflSKtN/sf8ErwK8ypbthuJs8iCxI9d4TyQkYeWbwN mNLPUf0fsFwD66+EAKgQC63HQIuzzzVn4BcJC+RTYvPs+WmOCY7tlfwv+GN3YMDd9dQ+ /DaA== 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=+a1/AvqQIHRNVAxSn1EGU2MopJ+WOc+lm0G/tKcRReY=; b=WPNL5anHum3OiQjE9x/8boR4tyYQysLlsarayk+teuIpHsv2XMNOyWEb5rMOnisZIJ vVlC/m3+KPkhcEtZW7u7hxgcehyj2s8WSXdg6pAxAVodU0CG0tUOd/0cd+wOcftwLTF7 B2xq1Gq0zb0WyikP+XnY4hhQL3e/hgS9r7CCyQYSWhSFSeSakFJY6hAofj8oecaS/4QJ JqFsBvn0yq2tp5GbtdYZUpPRiz2xDy6bTByPqeiam/dXyzO9mZzPVn43DWEKD3CPTlLA V+ASmWHSuAkw1OUoyTzGWM7tvyjtPuKxDpK7Mrsw4q2N65J6ojiKvw5BENqg45dXmDw+ c6sQ== X-Gm-Message-State: AOAM530kSIywRdXRlRvk0nfy+RzUOpr5eY6x3e74HnQP7Tb1t/2o94Gw 1nzW3UBS9YaK42d5dAhNjGyY56FLUkQ6PQ== X-Google-Smtp-Source: ABdhPJwJLGnhBVmUyQH4NKH4UJ+72AtUHVfmPx0wRtVESJcE+LWBnaDzvIrcs5o7/jBaqkmYo0hqjw== X-Received: by 2002:a17:90a:70c5:b0:1bc:9a6c:843c with SMTP id a5-20020a17090a70c500b001bc9a6c843cmr5925869pjm.83.1645840773175; Fri, 25 Feb 2022 17:59:33 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id x23-20020a63fe57000000b0036490068f12sm3760828pgj.90.2022.02.25.17.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 17:59:32 -0800 (PST) From: Stafford Horne To: QEMU Development Subject: [PULL v2 2/6] hw/openrisc/openrisc_sim: Parameterize initialization Date: Sat, 26 Feb 2022 10:59:20 +0900 Message-Id: <20220226015924.1293022-3-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220226015924.1293022-1-shorne@gmail.com> References: <20220226015924.1293022-1-shorne@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::634 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=shorne@gmail.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stafford Horne , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Move magic numbers to variables and enums. These will be reused for upcoming fdt initialization. Signed-off-by: Stafford Horne Reviewed-by: Philippe Mathieu-Daudé --- hw/openrisc/openrisc_sim.c | 42 ++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c index 26d2370e60..d12b3e0c5e 100644 --- a/hw/openrisc/openrisc_sim.c +++ b/hw/openrisc/openrisc_sim.c @@ -49,6 +49,29 @@ typedef struct Or1ksimState { } Or1ksimState; +enum { + OR1KSIM_DRAM, + OR1KSIM_UART, + OR1KSIM_ETHOC, + OR1KSIM_OMPIC, +}; + +enum { + OR1KSIM_OMPIC_IRQ = 1, + OR1KSIM_UART_IRQ = 2, + OR1KSIM_ETHOC_IRQ = 4, +}; + +static const struct MemmapEntry { + hwaddr base; + hwaddr size; +} or1ksim_memmap[] = { + [OR1KSIM_DRAM] = { 0x00000000, 0 }, + [OR1KSIM_UART] = { 0x90000000, 0x100 }, + [OR1KSIM_ETHOC] = { 0x92000000, 0x800 }, + [OR1KSIM_OMPIC] = { 0x98000000, 16 }, +}; + static struct openrisc_boot_info { uint32_t bootstrap_pc; } boot_info; @@ -176,21 +199,24 @@ static void openrisc_sim_init(MachineState *machine) memory_region_add_subregion(get_system_memory(), 0, ram); if (nd_table[0].used) { - openrisc_sim_net_init(0x92000000, 0x92000400, smp_cpus, - cpus, 4, nd_table); + openrisc_sim_net_init(or1ksim_memmap[OR1KSIM_ETHOC].base, + or1ksim_memmap[OR1KSIM_ETHOC].base + 0x400, + smp_cpus, cpus, + OR1KSIM_ETHOC_IRQ, nd_table); } if (smp_cpus > 1) { - openrisc_sim_ompic_init(0x98000000, smp_cpus, cpus, 1); + openrisc_sim_ompic_init(or1ksim_memmap[OR1KSIM_OMPIC].base, smp_cpus, + cpus, OR1KSIM_OMPIC_IRQ); - serial_irq = qemu_irq_split(get_cpu_irq(cpus, 0, 2), - get_cpu_irq(cpus, 1, 2)); + serial_irq = qemu_irq_split(get_cpu_irq(cpus, 0, OR1KSIM_UART_IRQ), + get_cpu_irq(cpus, 1, OR1KSIM_UART_IRQ)); } else { - serial_irq = get_cpu_irq(cpus, 0, 2); + serial_irq = get_cpu_irq(cpus, 0, OR1KSIM_UART_IRQ); } - serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq, - 115200, serial_hd(0), DEVICE_NATIVE_ENDIAN); + serial_mm_init(get_system_memory(), or1ksim_memmap[OR1KSIM_UART].base, 0, + serial_irq, 115200, serial_hd(0), DEVICE_NATIVE_ENDIAN); openrisc_load_kernel(ram_size, kernel_filename); } From patchwork Sat Feb 26 01:59:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 12761164 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D62E6C433F5 for ; Sat, 26 Feb 2022 02:05:25 +0000 (UTC) Received: from localhost ([::1]:47960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNmSa-0008W0-TO for qemu-devel@archiver.kernel.org; Fri, 25 Feb 2022 21:05:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNmN4-0002HU-FF for qemu-devel@nongnu.org; Fri, 25 Feb 2022 20:59:47 -0500 Received: from [2607:f8b0:4864:20::52f] (port=40870 helo=mail-pg1-x52f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNmMz-00074L-Sp for qemu-devel@nongnu.org; Fri, 25 Feb 2022 20:59:42 -0500 Received: by mail-pg1-x52f.google.com with SMTP id w37so6178371pga.7 for ; Fri, 25 Feb 2022 17:59:37 -0800 (PST) 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=IRWwYIpH79WnXrvA95iIW6INZqQLTad2HjWVVpgkLC0=; b=icbE9ETAU1Xb40ld5G5SOH0OoLsC3KRyzUphZh9QSxPwH3qzAaEVajXW7asyl+uACM h8S25bqjHtwswBn7MKBqepQGDWgrUX04u7FcnZBuqnIsAd8t9P5f+hyipGoeER/yzDbc FskAfZjMYMLU3bnHYw1EKaR5VyPNZsGom58vb3ny6Znx7ddCX+bY6l9+gfaRmjDri91k 4E3wDVw8LCl5u9/96YPy1zQDrN7nT4XkjLOTzKYDRRczLk7LNKPKYwta6ktUxu5HWXxH WnD/SEFlRQfdMFF2ZCKUVdKfr1rBE41sYUerqoGuy2Lrdjpd0QR1jMhJCV970OBlXW7z nHtA== 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=IRWwYIpH79WnXrvA95iIW6INZqQLTad2HjWVVpgkLC0=; b=zXaRHpSdXSMAlM+kAwkOa0GwGz4pMroZjhNBnoLyu/SwNMJUp58slCK6lsUDbigBW2 tSeohycb0Qo61ION+YpQiysqaYUKro5jOhMwbdvV5ZQMsN6RAvXDN+QZPCFouruXxIYr OjE6z19Vf/LtVxUaTZCjPeN1c3ZEG6CitpmllItC36Ma4qI4ba75MfVY6xSTw1p4tmKR QpPFxmWRG6gJYs+RC4rIwtkrnUuSzGz7+VumrY5uQEIXGRrH3aO3GkkAEStdDqYKSW17 JmeeDGNWknE3PnPinu+ENnnBiIq+cOF7tFVqE1OfrlWurfCJVx6Tq3F21iEoieJEmTSc mdXA== X-Gm-Message-State: AOAM532uHhu3dXR/sFKXe6wybPebuBbTukSNAKMy52bRzZYX4HjjWINk 8Z3+8bQXSp/1eaGPzh70ITB6O3T0JI9+vw== X-Google-Smtp-Source: ABdhPJySS7v/O9HqdLqrXrh/GUzIzbJDhv/lz97yfnGZBEMLcbtm9jinZcZEtSu09XHgiLLgGQwHbQ== X-Received: by 2002:a63:27c7:0:b0:372:c656:20b2 with SMTP id n190-20020a6327c7000000b00372c65620b2mr8501883pgn.545.1645840776133; Fri, 25 Feb 2022 17:59:36 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id g6-20020a056a001a0600b004f2a4316a0asm4477807pfv.60.2022.02.25.17.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 17:59:35 -0800 (PST) From: Stafford Horne To: QEMU Development Subject: [PULL v2 3/6] hw/openrisc/openrisc_sim: Use IRQ splitter when connecting UART Date: Sat, 26 Feb 2022 10:59:21 +0900 Message-Id: <20220226015924.1293022-4-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220226015924.1293022-1-shorne@gmail.com> References: <20220226015924.1293022-1-shorne@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::52f (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=shorne@gmail.com; helo=mail-pg1-x52f.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stafford Horne , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Currently the OpenRISC SMP configuration only supports 2 cores due to the UART IRQ routing being limited to 2 cores. As was done in commit 1eeffbeb11 ("hw/openrisc/openrisc_sim: Use IRQ splitter when connecting IRQ to multiple CPUs") we can use a splitter to wire more than 2 CPUs. This patch moves serial initialization out to it's own function and uses a splitter to connect multiple CPU irq lines to the UART. Signed-off-by: Stafford Horne Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/openrisc/openrisc_sim.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c index d12b3e0c5e..5bfbac00f8 100644 --- a/hw/openrisc/openrisc_sim.c +++ b/hw/openrisc/openrisc_sim.c @@ -137,6 +137,28 @@ static void openrisc_sim_ompic_init(hwaddr base, int num_cpus, sysbus_mmio_map(s, 0, base); } +static void openrisc_sim_serial_init(hwaddr base, int num_cpus, + OpenRISCCPU *cpus[], int irq_pin) +{ + qemu_irq serial_irq; + int i; + + if (num_cpus > 1) { + DeviceState *splitter = qdev_new(TYPE_SPLIT_IRQ); + qdev_prop_set_uint32(splitter, "num-lines", num_cpus); + qdev_realize_and_unref(splitter, NULL, &error_fatal); + for (i = 0; i < num_cpus; i++) { + qdev_connect_gpio_out(splitter, i, get_cpu_irq(cpus, i, irq_pin)); + } + serial_irq = qdev_get_gpio_in(splitter, 0); + } else { + serial_irq = get_cpu_irq(cpus, 0, irq_pin); + } + serial_mm_init(get_system_memory(), base, 0, serial_irq, 115200, + serial_hd(0), DEVICE_NATIVE_ENDIAN); +} + + static void openrisc_load_kernel(ram_addr_t ram_size, const char *kernel_filename) { @@ -177,7 +199,6 @@ static void openrisc_sim_init(MachineState *machine) const char *kernel_filename = machine->kernel_filename; OpenRISCCPU *cpus[2] = {}; MemoryRegion *ram; - qemu_irq serial_irq; int n; unsigned int smp_cpus = machine->smp.cpus; @@ -208,15 +229,10 @@ static void openrisc_sim_init(MachineState *machine) if (smp_cpus > 1) { openrisc_sim_ompic_init(or1ksim_memmap[OR1KSIM_OMPIC].base, smp_cpus, cpus, OR1KSIM_OMPIC_IRQ); - - serial_irq = qemu_irq_split(get_cpu_irq(cpus, 0, OR1KSIM_UART_IRQ), - get_cpu_irq(cpus, 1, OR1KSIM_UART_IRQ)); - } else { - serial_irq = get_cpu_irq(cpus, 0, OR1KSIM_UART_IRQ); } - serial_mm_init(get_system_memory(), or1ksim_memmap[OR1KSIM_UART].base, 0, - serial_irq, 115200, serial_hd(0), DEVICE_NATIVE_ENDIAN); + openrisc_sim_serial_init(or1ksim_memmap[OR1KSIM_UART].base, smp_cpus, cpus, + OR1KSIM_UART_IRQ); openrisc_load_kernel(ram_size, kernel_filename); } From patchwork Sat Feb 26 01:59:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 12761162 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D541C433F5 for ; Sat, 26 Feb 2022 02:03:09 +0000 (UTC) Received: from localhost ([::1]:42686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNmQO-0004z7-6o for qemu-devel@archiver.kernel.org; Fri, 25 Feb 2022 21:03:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNmN3-0002Gx-Ip for qemu-devel@nongnu.org; Fri, 25 Feb 2022 20:59:41 -0500 Received: from [2607:f8b0:4864:20::42f] (port=41838 helo=mail-pf1-x42f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNmN2-00074i-4N for qemu-devel@nongnu.org; Fri, 25 Feb 2022 20:59:41 -0500 Received: by mail-pf1-x42f.google.com with SMTP id p8so6207115pfh.8 for ; Fri, 25 Feb 2022 17:59:39 -0800 (PST) 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=MnZANHh1cEDimBVsUymqDGP9GmDwsCaQg06DqMeTQ5Y=; b=GUgLCTrVB65c0ZLEQXyTfkIDh46IAwgCjhmtZ+fAuKIAal1Iq53BURyh+DrxJdohPO q/DGL3xY13/Af/Vt6VOIm1ToM5t8dZoZJVJQRbUfAGgZ029gsf0/EzkxTccfo7Y6gEfu Zwf+2JmC0V0imc5LulGzGI2KGdRFH/ZhXx66dcFaoxTBSouELIywi6zHczqAY7TLGnpl o4sNGauj6fK6wO59jvJKuodm5iggfGMSBiE+gzIG2E47WnlbEawaSqgvbIdaXH5U4nQt /w1dBostj61IzopFWtxD0uuK55L5raA5Y7LRHy/eQOqG+QT7yz72ug326tK6TJpgRtIb ccQA== 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=MnZANHh1cEDimBVsUymqDGP9GmDwsCaQg06DqMeTQ5Y=; b=l0Bre7cF+QvtpTpO5AmJno6iIXlOtk1sO4Xh3iNIGN4BKm3H00MBcW7vtb93ETUQtz z2Y8R6YVM4BeotYZ5IrzKduHX3pirLreVVU5i++pksqPT4byYwTwiXJS3F7N03pgWIJ8 /dZo9OOxnUBwb5uAm+1vUvd01VJYqhfU8s84UPfhfEyUxEgUNQqrc/1liiMkm2K6Wv8k DH9Xxbl6ZCDJlnN71DVVeodRlDLVswRHGr4Ty/2sikD7TIYZdadvKUx/05G8v15DX8nE yxImaOOFoA5RJMQ34tw5lcTByfrRh5C2UNva+AWRPkV3Ie01SvmrvrJtNPFyhDobE3Ej vC5Q== X-Gm-Message-State: AOAM531YcEG3x6YjvCPIKea26eXy1594r2Z9+5uu/Y24tpAlfGZjaaEV Zxk76S5/FlhLOWbOxfXFiuSp591ZOXXL6w== X-Google-Smtp-Source: ABdhPJwXyRGVYmX9Np7wSX25QgF1LK4JT5l/dsVKZ5W0sgF5fh5uDukS9el1yn6ccRoPUSWSi2FvHw== X-Received: by 2002:a65:6c0d:0:b0:364:ae2e:9708 with SMTP id y13-20020a656c0d000000b00364ae2e9708mr8509401pgu.189.1645840778650; Fri, 25 Feb 2022 17:59:38 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id f15-20020a056a001acf00b004f0ed8dc8d7sm4465564pfv.108.2022.02.25.17.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 17:59:38 -0800 (PST) From: Stafford Horne To: QEMU Development Subject: [PULL v2 4/6] hw/openrisc/openrisc_sim: Increase max_cpus to 4 Date: Sat, 26 Feb 2022 10:59:22 +0900 Message-Id: <20220226015924.1293022-5-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220226015924.1293022-1-shorne@gmail.com> References: <20220226015924.1293022-1-shorne@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::42f (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=shorne@gmail.com; helo=mail-pf1-x42f.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stafford Horne , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Now that we no longer have a limit of 2 CPUs due to fixing the IRQ routing issues we can increase the max. Here we increase the limit to 4, we could go higher, but currently OMPIC has a limit of 4, so we align with that. Signed-off-by: Stafford Horne Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/openrisc/openrisc_sim.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c index 5bfbac00f8..8cfb92bec6 100644 --- a/hw/openrisc/openrisc_sim.c +++ b/hw/openrisc/openrisc_sim.c @@ -37,6 +37,8 @@ #define KERNEL_LOAD_ADDR 0x100 +#define OR1KSIM_CPUS_MAX 4 + #define TYPE_OR1KSIM_MACHINE MACHINE_TYPE_NAME("or1k-sim") #define OR1KSIM_MACHINE(obj) \ OBJECT_CHECK(Or1ksimState, (obj), TYPE_OR1KSIM_MACHINE) @@ -197,12 +199,12 @@ static void openrisc_sim_init(MachineState *machine) { ram_addr_t ram_size = machine->ram_size; const char *kernel_filename = machine->kernel_filename; - OpenRISCCPU *cpus[2] = {}; + OpenRISCCPU *cpus[OR1KSIM_CPUS_MAX] = {}; MemoryRegion *ram; int n; unsigned int smp_cpus = machine->smp.cpus; - assert(smp_cpus >= 1 && smp_cpus <= 2); + assert(smp_cpus >= 1 && smp_cpus <= OR1KSIM_CPUS_MAX); for (n = 0; n < smp_cpus; n++) { cpus[n] = OPENRISC_CPU(cpu_create(machine->cpu_type)); if (cpus[n] == NULL) { @@ -243,7 +245,7 @@ static void openrisc_sim_machine_init(ObjectClass *oc, void *data) mc->desc = "or1k simulation"; mc->init = openrisc_sim_init; - mc->max_cpus = 2; + mc->max_cpus = OR1KSIM_CPUS_MAX; mc->is_default = true; mc->default_cpu_type = OPENRISC_CPU_TYPE_NAME("or1200"); } From patchwork Sat Feb 26 01:59:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 12761165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D825C433EF for ; Sat, 26 Feb 2022 02:08:03 +0000 (UTC) Received: from localhost ([::1]:51216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNmV8-0002OC-4N for qemu-devel@archiver.kernel.org; Fri, 25 Feb 2022 21:08:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNmNB-0002J4-HO for qemu-devel@nongnu.org; Fri, 25 Feb 2022 20:59:49 -0500 Received: from [2607:f8b0:4864:20::42b] (port=46625 helo=mail-pf1-x42b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNmN4-00075J-UP for qemu-devel@nongnu.org; Fri, 25 Feb 2022 20:59:44 -0500 Received: by mail-pf1-x42b.google.com with SMTP id i21so6182679pfd.13 for ; Fri, 25 Feb 2022 17:59:42 -0800 (PST) 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=7szSUFn2MYt2MXPNffbxYgdZhZd5yTtdvvVAWrnKI0M=; b=IA2vR5chOPIY8P0tFcpBrNLIukc3mCQ4iPFlRU/iR9GHjbHd+6ZCyLoQATCJFGP+pE dB3R54gYxXE8oT3yHI3VUeuCWl1HugmQR8vBuJ8bkjwYmxBkoFqyvbaUE8Tp4PzoJAwU /sQpy1owpWzZ4ypfffhJd6wMgKIIlEWYU4VO+RzhmXszXB/tLwJ+N9dXbw7H/iUC2t9W TVEdXPL/m+AmQX3LZxYpK0F1FkpadkwYqH/e7tgylxBe7CfRVPFVxfiYl5L5O6Lz5y2S xki2CiD6wpw56QNdrYjuF1yk2hj3vA5uTe9/zfGunID8s9TjySV3UJ50xvIJ7avRKi7E VvQA== 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=7szSUFn2MYt2MXPNffbxYgdZhZd5yTtdvvVAWrnKI0M=; b=tNJGxzbXlrmKBO2fvPKYa5y+KmrNdv4B0YJCQKpuhnHaZbX0GYUlwhzvv15GXts8Wb tWmo+Sq18nkdJQWvXKfQ3qKehM6jO24vuEapMLnTS52vjPMpnNkPyw6wG1XHTEe4dRc6 Um8Nw9Y24rCKMOoGSJNWuUHpQLpi+mruOeRkOPRnXZ0W7g9EG5rDAntpuWkP8oshxUUz wsTwpWw722zrvoVGbiCmwhLGEkNTQ8vs9Sq9/Nw/wv58OPXe6N/KM/alOINVq1YDfKNV I6nF1jECIBupCppyUKDCMPrdQg799ZvqvQszyrWzbAc/GNz2Rbo8wTAgAc1GB4NzZQlW 1TNw== X-Gm-Message-State: AOAM5335nc0TQ6QsdNEpHcaFMfkDdeZF+s+d6g0VTJ4PNpVuLFjSfrup lO0DgnKuzo+8UCqexMDFaqVPTdjBdXYmpA== X-Google-Smtp-Source: ABdhPJy9aJxkdXUu5vlcq7ufLvbVY8fGVepP7moaMMQaLc9aLIV7JsAVEOY7J0gBGGp3K2YIJFBfWA== X-Received: by 2002:a63:fb46:0:b0:372:a1d6:45ea with SMTP id w6-20020a63fb46000000b00372a1d645eamr8530006pgj.549.1645840781133; Fri, 25 Feb 2022 17:59:41 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id g21-20020a17090a7d1500b001b968e82819sm10092258pjl.10.2022.02.25.17.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 17:59:40 -0800 (PST) From: Stafford Horne To: QEMU Development Subject: [PULL v2 5/6] hw/openrisc/openrisc_sim: Add automatic device tree generation Date: Sat, 26 Feb 2022 10:59:23 +0900 Message-Id: <20220226015924.1293022-6-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220226015924.1293022-1-shorne@gmail.com> References: <20220226015924.1293022-1-shorne@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::42b (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=shorne@gmail.com; helo=mail-pf1-x42b.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stafford Horne Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Using the device tree means that qemu can now directly tell the kernel what hardware is configured rather than use having to maintain and update a separate device tree file. This patch adds automatic device tree generation support for the OpenRISC simulator. A device tree is built up based on the state of the configure openrisc simulator. This is then dumped to memory and the load address is passed to the kernel in register r3. Signed-off-by: Stafford Horne Reviewed-by: Peter Maydell --- Since v1: - Added fdt to CONFIG_OR1K_SIM source set configs/targets/or1k-softmmu.mak | 1 + hw/openrisc/meson.build | 2 +- hw/openrisc/openrisc_sim.c | 189 ++++++++++++++++++++++++++++--- 3 files changed, 176 insertions(+), 16 deletions(-) diff --git a/configs/targets/or1k-softmmu.mak b/configs/targets/or1k-softmmu.mak index 1dfb93e46d..9e1d4a1fb1 100644 --- a/configs/targets/or1k-softmmu.mak +++ b/configs/targets/or1k-softmmu.mak @@ -1,2 +1,3 @@ TARGET_ARCH=openrisc TARGET_WORDS_BIGENDIAN=y +TARGET_NEED_FDT=y diff --git a/hw/openrisc/meson.build b/hw/openrisc/meson.build index 947f63ee08..ec48172c9d 100644 --- a/hw/openrisc/meson.build +++ b/hw/openrisc/meson.build @@ -1,5 +1,5 @@ openrisc_ss = ss.source_set() openrisc_ss.add(files('cputimer.c')) -openrisc_ss.add(when: 'CONFIG_OR1K_SIM', if_true: files('openrisc_sim.c')) +openrisc_ss.add(when: 'CONFIG_OR1K_SIM', if_true: [files('openrisc_sim.c'), fdt]) hw_arch += {'openrisc': openrisc_ss} diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c index 8cfb92bec6..e0e71c0faa 100644 --- a/hw/openrisc/openrisc_sim.c +++ b/hw/openrisc/openrisc_sim.c @@ -29,15 +29,20 @@ #include "net/net.h" #include "hw/loader.h" #include "hw/qdev-properties.h" +#include "exec/address-spaces.h" +#include "sysemu/device_tree.h" #include "sysemu/sysemu.h" #include "hw/sysbus.h" #include "sysemu/qtest.h" #include "sysemu/reset.h" #include "hw/core/split-irq.h" +#include + #define KERNEL_LOAD_ADDR 0x100 #define OR1KSIM_CPUS_MAX 4 +#define OR1KSIM_CLK_MHZ 20000000 #define TYPE_OR1KSIM_MACHINE MACHINE_TYPE_NAME("or1k-sim") #define OR1KSIM_MACHINE(obj) \ @@ -48,6 +53,8 @@ typedef struct Or1ksimState { MachineState parent_obj; /*< public >*/ + void *fdt; + int fdt_size; } Or1ksimState; @@ -76,6 +83,7 @@ static const struct MemmapEntry { static struct openrisc_boot_info { uint32_t bootstrap_pc; + uint32_t fdt_addr; } boot_info; static void main_cpu_reset(void *opaque) @@ -86,6 +94,7 @@ static void main_cpu_reset(void *opaque) 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) @@ -93,12 +102,77 @@ 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 void openrisc_sim_net_init(hwaddr base, hwaddr descriptors, +static void openrisc_create_fdt(Or1ksimState *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 = state->fdt = 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); + + nodename = g_strdup_printf("/memory@%" HWADDR_PRIx, + memmap[OR1KSIM_DRAM].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cells(fdt, nodename, "reg", + memmap[OR1KSIM_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 = 0; cpu < num_cpus; cpu++) { + nodename = 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", + OR1KSIM_CLK_MHZ); + g_free(nodename); + } + + nodename = (char *)"/pic"; + qemu_fdt_add_subnode(fdt, nodename); + pic_ph = 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_sim_net_init(Or1ksimState *state, hwaddr base, hwaddr size, int num_cpus, OpenRISCCPU *cpus[], int irq_pin, NICInfo *nd) { + void *fdt = state->fdt; DeviceState *dev; SysBusDevice *s; + char *nodename; int i; dev = qdev_new("open_eth"); @@ -118,14 +192,28 @@ static void openrisc_sim_net_init(hwaddr base, hwaddr descriptors, sysbus_connect_irq(s, 0, get_cpu_irq(cpus, 0, irq_pin)); } sysbus_mmio_map(s, 0, base); - sysbus_mmio_map(s, 1, descriptors); + sysbus_mmio_map(s, 1, base + 0x400); + + /* Init device tree node for ethoc. */ + nodename = g_strdup_printf("/ethoc@%" HWADDR_PRIx, base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "compatible", "opencores,ethoc"); + qemu_fdt_setprop_cells(fdt, nodename, "reg", base, size); + qemu_fdt_setprop_cell(fdt, nodename, "interrupts", irq_pin); + qemu_fdt_setprop(fdt, nodename, "big-endian", NULL, 0); + + qemu_fdt_setprop_string(fdt, "/aliases", "enet0", nodename); + g_free(nodename); } -static void openrisc_sim_ompic_init(hwaddr base, int num_cpus, +static void openrisc_sim_ompic_init(Or1ksimState *state, hwaddr base, + hwaddr size, int num_cpus, OpenRISCCPU *cpus[], int irq_pin) { + void *fdt = state->fdt; DeviceState *dev; SysBusDevice *s; + char *nodename; int i; dev = qdev_new("or1k-ompic"); @@ -137,11 +225,24 @@ static void openrisc_sim_ompic_init(hwaddr base, int num_cpus, 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 = 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_sim_serial_init(hwaddr base, int num_cpus, +static void openrisc_sim_serial_init(Or1ksimState *state, hwaddr base, + hwaddr size, int num_cpus, OpenRISCCPU *cpus[], int irq_pin) { + void *fdt = state->fdt; + char *nodename; qemu_irq serial_irq; int i; @@ -158,29 +259,45 @@ static void openrisc_sim_serial_init(hwaddr base, int num_cpus, } serial_mm_init(get_system_memory(), base, 0, serial_irq, 115200, serial_hd(0), DEVICE_NATIVE_ENDIAN); -} + /* Add device tree node for serial. */ + nodename = 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", OR1KSIM_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_load_kernel(ram_addr_t ram_size, - const char *kernel_filename) +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 = load_elf(kernel_filename, NULL, NULL, NULL, - &elf_entry, NULL, NULL, NULL, 1, EM_OPENRISC, - 1, 0); + &elf_entry, NULL, &high_addr, NULL, 1, + EM_OPENRISC, 1, 0); entry = elf_entry; if (kernel_size < 0) { kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL, NULL, NULL); + high_addr = entry + kernel_size; } if (kernel_size < 0) { kernel_size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR, ram_size - KERNEL_LOAD_ADDR); + high_addr = KERNEL_LOAD_ADDR + kernel_size; } if (entry <= 0) { @@ -192,7 +309,38 @@ static void openrisc_load_kernel(ram_addr_t ram_size, exit(1); } boot_info.bootstrap_pc = entry; + + return high_addr; } + return 0; +} + +static uint32_t openrisc_load_fdt(Or1ksimState *state, hwaddr load_start, + uint64_t mem_size) +{ + void *fdt = state->fdt; + uint32_t fdt_addr; + int ret; + int fdtsize = fdt_totalsize(fdt); + + if (fdtsize <= 0) { + error_report("invalid device-tree"); + exit(1); + } + + /* We put fdt right after the kernel and/or initrd. */ + fdt_addr = ROUND_UP(load_start, 4); + + ret = fdt_pack(fdt); + /* Should only fail if we've built a corrupted tree */ + g_assert(ret == 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) @@ -200,7 +348,9 @@ static void openrisc_sim_init(MachineState *machine) ram_addr_t ram_size = machine->ram_size; const char *kernel_filename = machine->kernel_filename; OpenRISCCPU *cpus[OR1KSIM_CPUS_MAX] = {}; + Or1ksimState *state = OR1KSIM_MACHINE(machine); MemoryRegion *ram; + hwaddr load_addr; int n; unsigned int smp_cpus = machine->smp.cpus; @@ -221,22 +371,31 @@ static void openrisc_sim_init(MachineState *machine) memory_region_init_ram(ram, NULL, "openrisc.ram", ram_size, &error_fatal); memory_region_add_subregion(get_system_memory(), 0, ram); + openrisc_create_fdt(state, or1ksim_memmap, smp_cpus, machine->ram_size, + machine->kernel_cmdline); + if (nd_table[0].used) { - openrisc_sim_net_init(or1ksim_memmap[OR1KSIM_ETHOC].base, - or1ksim_memmap[OR1KSIM_ETHOC].base + 0x400, + openrisc_sim_net_init(state, or1ksim_memmap[OR1KSIM_ETHOC].base, + or1ksim_memmap[OR1KSIM_ETHOC].size, smp_cpus, cpus, OR1KSIM_ETHOC_IRQ, nd_table); } if (smp_cpus > 1) { - openrisc_sim_ompic_init(or1ksim_memmap[OR1KSIM_OMPIC].base, smp_cpus, - cpus, OR1KSIM_OMPIC_IRQ); + openrisc_sim_ompic_init(state, or1ksim_memmap[OR1KSIM_OMPIC].base, + or1ksim_memmap[OR1KSIM_UART].size, + smp_cpus, cpus, OR1KSIM_OMPIC_IRQ); } - openrisc_sim_serial_init(or1ksim_memmap[OR1KSIM_UART].base, smp_cpus, cpus, + openrisc_sim_serial_init(state, or1ksim_memmap[OR1KSIM_UART].base, + or1ksim_memmap[OR1KSIM_UART].size, smp_cpus, cpus, OR1KSIM_UART_IRQ); - openrisc_load_kernel(ram_size, kernel_filename); + load_addr = openrisc_load_kernel(ram_size, kernel_filename); + if (load_addr > 0) { + boot_info.fdt_addr = openrisc_load_fdt(state, load_addr, + machine->ram_size); + } } static void openrisc_sim_machine_init(ObjectClass *oc, void *data) From patchwork Sat Feb 26 01:59:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 12761166 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3193C433EF for ; Sat, 26 Feb 2022 02:10:04 +0000 (UTC) Received: from localhost ([::1]:53372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNmX5-0003sJ-JI for qemu-devel@archiver.kernel.org; Fri, 25 Feb 2022 21:10:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNmND-0002LS-Sn for qemu-devel@nongnu.org; Fri, 25 Feb 2022 20:59:52 -0500 Received: from [2607:f8b0:4864:20::102d] (port=45014 helo=mail-pj1-x102d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNmNB-00075Y-8b for qemu-devel@nongnu.org; Fri, 25 Feb 2022 20:59:51 -0500 Received: by mail-pj1-x102d.google.com with SMTP id cp23-20020a17090afb9700b001bbfe0fbe94so6414707pjb.3 for ; Fri, 25 Feb 2022 17:59:45 -0800 (PST) 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=2Yn04nvZkiqD9e5fzaG3S3X/4FZpuR1OsLhndKT3BtA=; b=QvohHUfrp/iRvg5Kdre7sEfoO894aetYT0py7BXzZfeHRDfwE1dyIGBmHCAB3lr7qe zndfeUnUoxoiyQLomHehXXtRSF+rXt9cklQpDDdrKpu0T2Hl9aCEcT9yYatsy2kF5IwU TLQIyIVb/4ReUZHP+sa9DJBGH4yK1esn+geZVdQnvIOTeKzB0CAlF5Q5evhf8vnk9paF MsXeXr6yuAexKOnox969Oq/BbZbMirlMDJKeQM/ww4yY2nsKn1AT9ynOPOcHxMkaTpQp LyR4MlQF6KdPfC9Qvo94CYpELr6yssJP2WW1V92vHGD8OmHXAHOC7mnx0L/dCsWCF3Kw pvqg== 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=2Yn04nvZkiqD9e5fzaG3S3X/4FZpuR1OsLhndKT3BtA=; b=0TyxwOQsvi1JUQjON65ExgrsvKErSOGQH9U8P2roSg3cEZi6ZfrsD4kZgi5gURh7Ep 1j6cFO50M1lT0YJiP6rTs0o8AJ8VQzaAL35Cc6hyjeYnQ39rxJDaz8bny9uVkV8sY3fp /lIYXeC5Ix2W/YLXk1EuacnUpH04cZZqeCkqkpijVU5r9ssiT4+rtswIkG26XWiRC8o/ 2mg26GSMCZXrxhOTmvbO4xm3AXCoAgAoZ/XO3c2zKW5Tky0Z5cMGYp4WndPCVz9Moa86 nqj8pe7+IkxxlwmiBfiVC6NS2nFaD5pBSIF7BJma7WmgWqGqBKxeCMT0Gs5V/Za/hWa0 ULaA== X-Gm-Message-State: AOAM5312SkNXvhoYSwkhVpP19xg+PrVP+Szr9bUPAfZd9Y/xIjuB44ox PHS8ivawGDxvI41AIx4bpR0+QDRqbWygig== X-Google-Smtp-Source: ABdhPJx1WgF0TmjJXrfS8QDc1ESm6xvSen6erRz2LbRofLVKVr5ie9nfVoi2g+i59SHx5K2xPZBfLQ== X-Received: by 2002:a17:90b:3693:b0:1bc:89f0:e38f with SMTP id mj19-20020a17090b369300b001bc89f0e38fmr5976196pjb.171.1645840784142; Fri, 25 Feb 2022 17:59:44 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id c19-20020a17090ab29300b001bc13b4bf91sm10393027pjr.43.2022.02.25.17.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 17:59:43 -0800 (PST) From: Stafford Horne To: QEMU Development Subject: [PULL v2 6/6] hw/openrisc/openrisc_sim: Add support for initrd loading Date: Sat, 26 Feb 2022 10:59:24 +0900 Message-Id: <20220226015924.1293022-7-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220226015924.1293022-1-shorne@gmail.com> References: <20220226015924.1293022-1-shorne@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::102d (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=shorne@gmail.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stafford Horne Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The initrd passed via the command line is loaded into memory. It's location and size is then added to the device tree so the kernel knows where to find it. Signed-off-by: Stafford Horne Reviewed-by: Peter Maydell --- hw/openrisc/openrisc_sim.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c index e0e71c0faa..8184caa60b 100644 --- a/hw/openrisc/openrisc_sim.c +++ b/hw/openrisc/openrisc_sim.c @@ -315,6 +315,33 @@ static hwaddr openrisc_load_kernel(ram_addr_t ram_size, return 0; } +static hwaddr openrisc_load_initrd(Or1ksimState *state, const char *filename, + hwaddr load_start, uint64_t mem_size) +{ + void *fdt = state->fdt; + int size; + hwaddr start; + + /* We put the initrd right after the kernel; page aligned. */ + start = TARGET_PAGE_ALIGN(load_start); + + size = load_ramdisk(filename, start, mem_size - start); + if (size < 0) { + size = 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) { @@ -393,6 +420,10 @@ static void openrisc_sim_init(MachineState *machine) load_addr = openrisc_load_kernel(ram_size, kernel_filename); if (load_addr > 0) { + if (machine->initrd_filename) { + load_addr = openrisc_load_initrd(state, machine->initrd_filename, + load_addr, machine->ram_size); + } boot_info.fdt_addr = openrisc_load_fdt(state, load_addr, machine->ram_size); }