From patchwork Fri Feb 25 08:32:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 12759991 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 4761CC433F5 for ; Fri, 25 Feb 2022 09:39:54 +0000 (UTC) Received: from localhost ([::1]:50376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNX4r-0001Mh-2M for qemu-devel@archiver.kernel.org; Fri, 25 Feb 2022 04:39:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNW1t-0004ck-85 for qemu-devel@nongnu.org; Fri, 25 Feb 2022 03:32:50 -0500 Received: from [2607:f8b0:4864:20::62a] (port=42608 helo=mail-pl1-x62a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNW1o-0002uo-Id for qemu-devel@nongnu.org; Fri, 25 Feb 2022 03:32:43 -0500 Received: by mail-pl1-x62a.google.com with SMTP id p17so4187389plo.9 for ; Fri, 25 Feb 2022 00:32:35 -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=f5XxEiNTUAaUoZl9qpwSizSAgeoqsdZQDIr8qcxHkEDiXDayeBCVCxN1oBRH7iU4CI 9iIuXyIsPGuVjYHI7Q2tTeoTZw2YIxC3Cny2NukxiJNq37WBsxnG96v4mOY59FrSapNK M53hF5TFOSOAqmCVR72vQLTSqHkNtPURt/QhG+3ocTxnw1fWWo1w5Vh9n1DLYHyrLoT1 5f51Rb8zJasodrfwYU232GBALNtSoagWT1O8OpeaC0QRgQ1OH+UhhY1M6QR+szoZeZhy GopSSp3ITJDAJGtFzxC4r/JZEyBrnolyA8RWbKhYvlp+cZ8XVW/j/HKgOWdb/GyqY0NE 2Rmw== 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=CfrAbx0LVVB2sWcKIGadKp5XM+XGvIFGjm4D0sIu/lipLjkGuGkoK3tJpihCYmabxU b6yUYeRDApdOzy7c+btYtnsYLh10Pg5AC7EifTSCyRgj4pDgHOl3iuFGWhpz2fSKdd05 RfVU73VHbF2E47lJlSQCADVZPfeEbts6PoP/9+r/tIgNAMoo+JJraAULTQHCL/c4w23P tCDCHdFJdbE4cwW0q81Y3i3nC0Pt92Hp8BqKdcSjM4S7F7yp3oO7LH+0rVnM0NzmvXI6 rkSS3c4CPyMQ7BI6e6T+pGVRQcelYDtYFiqpPU8PhO2kG5iQ+AVJMWe41eKKoYiTWezA 6H3A== X-Gm-Message-State: AOAM5318IcySpW0fLZE4hssCDwGPR2g1ZqF0UWPhRyYU6OzPTZX3rD2Q 6hJAInNHH7a4TIyv8hy0hvQwK6AK/Sf2yokH X-Google-Smtp-Source: ABdhPJznRFvVyfpvWLRG7p6yS6cBe5YNkb8tQg4Lziw9RFdAKCqxV5psMcJaO9NInF/ZD9iQtFvz2A== X-Received: by 2002:a17:902:f605:b0:14f:5d75:4fb0 with SMTP id n5-20020a170902f60500b0014f5d754fb0mr6168437plg.101.1645777954361; Fri, 25 Feb 2022 00:32:34 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id b2-20020a056a000a8200b004e1414f0bb1sm2070007pfl.135.2022.02.25.00.32.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 00:32:33 -0800 (PST) From: Stafford Horne To: QEMU Development Subject: [PULL 1/6] hw/openrisc/openrisc_sim: Create machine state for or1ksim Date: Fri, 25 Feb 2022 17:32:17 +0900 Message-Id: <20220225083222.1174517-2-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220225083222.1174517-1-shorne@gmail.com> References: <20220225083222.1174517-1-shorne@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::62a (failed) 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: -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 Fri Feb 25 08:32:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 12759985 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 85218C433F5 for ; Fri, 25 Feb 2022 09:25:53 +0000 (UTC) Received: from localhost ([::1]:36142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNWrI-00081H-4h for qemu-devel@archiver.kernel.org; Fri, 25 Feb 2022 04:25:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNW1s-0004ca-J3 for qemu-devel@nongnu.org; Fri, 25 Feb 2022 03:32:50 -0500 Received: from [2607:f8b0:4864:20::436] (port=46955 helo=mail-pf1-x436.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNW1o-0002uv-K5 for qemu-devel@nongnu.org; Fri, 25 Feb 2022 03:32:43 -0500 Received: by mail-pf1-x436.google.com with SMTP id i21so4068157pfd.13 for ; Fri, 25 Feb 2022 00:32:38 -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=JRJZdVx74yTmLburHoDuQ0mq7ttaVuLJ5HoAFlFRlzm6+3EFdpHSHEZG/ZH6mRqGPK y6bnTY3RJ+PMd1KUGvqm786p2IYjLgM34FoZ+iGaXMPXglxRB0DLqayHXqUXd7fEUIoy a4/J0xuT9yBvQz4/4FZfz+eGt78uDyDaj6PP7k37m3t/6RxZI/gEpMe5FAWMIAcsGIkX qEfe0l/qA3KGQP9oE61v7b02V1O5pCJ6J13T/PLECmJs9Y3XjlIXiEV9QItM9o99TINI d20GKJVr3dO80v1hi2pEFc4nWinEUpfgIQIY5vjByyR41gD+GMi0Cn0hf7G3qvHFO6p3 4ydg== 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=PxmDv17y5tltYQqm33VlNEO2V7R+gFcwZqKvGirA//1aISqueF9kgwEyG7OjAXe83o mFU7d7qzaBnpdyB/BjuJcalnDiDuB3y59EYjKD2h5B9RRX8+bpUyECxo4Q8D05zgxmUq PZsh7WzZJlwM43AyU14CdvVJ6CA/7q9VwbbhxxY9bvXdcUeD5WeULZXNLOuBSgIZipgl 5KQunPJIVuUO8Q7th0M6p5azBbx38un9o365cXJFi2dLpTIDpfh7KMYSE7mZv6RE+lk9 kg02BVd/HHOolpXPPOwZHzn5RiPDuwbbhRkmWkW9HQwR5xXIy8NGEz/Ua9IIePS5YPw3 hS2A== X-Gm-Message-State: AOAM5334HB3yqYh3xdXzEFleC+JQF5FmA4mEgYV43H0/pGeF+Vbzi3Br NGo1xCQqwsf6Msu5eiw0ch9mTuSkIffHrRRp X-Google-Smtp-Source: ABdhPJyfHqfDUriPxysx1Mcrw/PKeNd6vTiWag5H91FJzVOPjjsB6Q3vo2Tvc8PjdR+eSWYBWkXAtQ== X-Received: by 2002:a65:5941:0:b0:375:9bfd:473d with SMTP id g1-20020a655941000000b003759bfd473dmr3825378pgu.348.1645777956936; Fri, 25 Feb 2022 00:32:36 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id j9-20020a056a00174900b004dff2f1526fsm1505235pfc.122.2022.02.25.00.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 00:32:36 -0800 (PST) From: Stafford Horne To: QEMU Development Subject: [PULL 2/6] hw/openrisc/openrisc_sim: Parameterize initialization Date: Fri, 25 Feb 2022 17:32:18 +0900 Message-Id: <20220225083222.1174517-3-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220225083222.1174517-1-shorne@gmail.com> References: <20220225083222.1174517-1-shorne@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::436 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=shorne@gmail.com; helo=mail-pf1-x436.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 Fri Feb 25 08:32: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: 12759988 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 9C14EC433F5 for ; Fri, 25 Feb 2022 09:33:46 +0000 (UTC) Received: from localhost ([::1]:43768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNWyv-00050t-JB for qemu-devel@archiver.kernel.org; Fri, 25 Feb 2022 04:33:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNW1t-0004cl-Nd for qemu-devel@nongnu.org; Fri, 25 Feb 2022 03:32:50 -0500 Received: from [2607:f8b0:4864:20::102c] (port=34511 helo=mail-pj1-x102c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNW1q-0002v3-5W for qemu-devel@nongnu.org; Fri, 25 Feb 2022 03:32:45 -0500 Received: by mail-pj1-x102c.google.com with SMTP id gl14-20020a17090b120e00b001bc2182c3d5so7056315pjb.1 for ; Fri, 25 Feb 2022 00:32:41 -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=d2vYCXBUwAUdtwRb8+lixc3GqHHLg5JstEinwApB7pgg23hA8rbgY0Sy17Fe+1vcAp VyJorYTrC5Og/KD6fgDnaHQMc+ya/DbkcQzu68eVzb3OrnzcWaNLHbF+SPJdktzXsCz/ UTOp+JJ5RGvhF6Thay3qOipiF1ZsQNdexr6J8Sm26RLTJw4afkTA7gFcw7vXuxgfZwej M8d3zAjyVlI+y5NWAsTJtgjB6agV9KW3NRIJy0dJtPcdIdvD+43GpsSddQSOV0nbbI+f 9t3S43z742ziQYOBcmM863oZNVUnu8AR5DD/zrbDgjYPKZTByBO5NykVbnMKiqfjcwtB Udeg== 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=ey1V9nESJr1BKxfyBUafoIPlYgR2te4M5jtAKlrnZ8yVSrIzJk7o47k7hpRXy6uoZn jBRUR3e6+sDierJHqUyUE88iBBd7SWRObCbRaiSFsJ1yGOJbVVzZUK86wnw8lMyij7VK zao95CXY+o/nv0gK1AzSztNqc/A8QnJ1wwpLRZ6wD7sIdasfUgy3ujoLeXXPj/z93nH6 h7k26iBoOGL4OM//okowwejV5uZ74aAJ4A7P5RwKked8M+qT7tMZP1kvUjbm38NYRB9V Hg3JXwvyYfxF3y58k+8df4oulOP1YjHogKn/b7iYb+U/DyytNlo4FXyrH1QonNnt63QL dHjg== X-Gm-Message-State: AOAM531hYUJwoupIH5/pqa4tueJJA/OWZYbLzDwNMMNC5/LE6gub2QH6 xaGM4l45OwkB3m1+rLXVoxntIDoomqWhWeL0 X-Google-Smtp-Source: ABdhPJzIAaq/Fp1ckAgbgC7UMnjuCx9aGEB4S91f68yiwsDDMTY0MgigZKSEbQNAMNS5S0a8LNvujg== X-Received: by 2002:a17:902:e289:b0:14f:ffd3:29bc with SMTP id o9-20020a170902e28900b0014fffd329bcmr6463021plc.35.1645777959979; Fri, 25 Feb 2022 00:32:39 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id o7-20020a63f147000000b00373facf1083sm1769463pgk.57.2022.02.25.00.32.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 00:32:39 -0800 (PST) From: Stafford Horne To: QEMU Development Subject: [PULL 3/6] hw/openrisc/openrisc_sim: Use IRQ splitter when connecting UART Date: Fri, 25 Feb 2022 17:32:19 +0900 Message-Id: <20220225083222.1174517-4-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220225083222.1174517-1-shorne@gmail.com> References: <20220225083222.1174517-1-shorne@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::102c (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=shorne@gmail.com; helo=mail-pj1-x102c.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 Fri Feb 25 08:32: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: 12759986 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 97303C43217 for ; Fri, 25 Feb 2022 09:26:02 +0000 (UTC) Received: from localhost ([::1]:36776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNWrR-0008Qp-KK for qemu-devel@archiver.kernel.org; Fri, 25 Feb 2022 04:26:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNW1v-0004cp-JW for qemu-devel@nongnu.org; Fri, 25 Feb 2022 03:32:50 -0500 Received: from [2607:f8b0:4864:20::42a] (port=44767 helo=mail-pf1-x42a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNW1t-0002vS-FF for qemu-devel@nongnu.org; Fri, 25 Feb 2022 03:32:47 -0500 Received: by mail-pf1-x42a.google.com with SMTP id w2so4084503pfu.11 for ; Fri, 25 Feb 2022 00:32:44 -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=FWYMy1bMW/OjH9efA9gSn4yGVjxWYCWAzyAO+cH0qFBPyTK8yyKG5pXgnxP6osF+N+ C7sAcN7j9uBVGiIRXrJyu3x2gg5lgs3StGWGtb9Rph4U1q2J0wvYlTrjMLC2Mf8+JlXb TLFrawCexxbuOxNqtQntqzWkkoCWasLotR7PrHUwtNbOo4sY11y8IHRkihJ4ca7dy3LG 2fUS/6zv+5sftEvOlwWT0lF+q2AjraJHOZ+t8vJHDMjmr9uaMBvdqG7qCpkBuTxtb8it Tiyx4IZSyUDa0q4qKRiBYi5e4yKtSpFjLzIwE07Jp2J9Mn6JkULS+F+mWqo6NotIMieA nLKg== 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=JtUnPRH3O5VPlfxXA6F6q/a5csRcbrbczjMNrpWtuYOBK5Fl1Vc8Qa9dblAaNadJ3g XWNFElwspmv2umVU4MNHjZTFFGHj4gQfWHFR2bSDlhshL/h9aTORil0VVDOdi5cQbfCZ WTFFSy4i+euiWdjwepxFeE16FPOWLoOf8qjul+qK57dOEB42kQ5gwJr5bAPdu6ez4iYA DA8n0uGX+8T25K5wf9y8dzhBoxwirrzfPhb4u3gdKTznQ0G7qUsqcE45AU0XblQFFy4r qQOxGJXLo6E1jw9TnGiZmIeW4eiFnjmP8y9eFlw/pPH3vLkVXvi+9Gj/co+SiAyv70FI wAsg== X-Gm-Message-State: AOAM532EUd6VMO+scEeLbXLTKxKq94MazbZn4+z+hRPwSG3DTUD1RAJW JlIsamzaIW1otZDQUOjJ8frDLYHnVtVSwuQN X-Google-Smtp-Source: ABdhPJwklxvTn9phMnsYVmylKcDpjTD46XyqFAxhrCujKqoLToGZwiv9WXcgKaP5mSZ/cap92j30Ew== X-Received: by 2002:a05:6a00:84b:b0:4e1:be36:7cce with SMTP id q11-20020a056a00084b00b004e1be367ccemr6600227pfk.23.1645777963152; Fri, 25 Feb 2022 00:32:43 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id i7-20020a17090a65c700b001b936b8abe0sm8524291pjs.7.2022.02.25.00.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 00:32:42 -0800 (PST) From: Stafford Horne To: QEMU Development Subject: [PULL 4/6] hw/openrisc/openrisc_sim: Increase max_cpus to 4 Date: Fri, 25 Feb 2022 17:32:20 +0900 Message-Id: <20220225083222.1174517-5-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220225083222.1174517-1-shorne@gmail.com> References: <20220225083222.1174517-1-shorne@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::42a (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=shorne@gmail.com; helo=mail-pf1-x42a.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 Fri Feb 25 08:32:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 12759993 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 D4C07C433FE for ; Fri, 25 Feb 2022 09:44:26 +0000 (UTC) Received: from localhost ([::1]:55354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNX9F-00053M-K2 for qemu-devel@archiver.kernel.org; Fri, 25 Feb 2022 04:44:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNW1z-0004cv-0a for qemu-devel@nongnu.org; Fri, 25 Feb 2022 03:32:53 -0500 Received: from [2607:f8b0:4864:20::1035] (port=55182 helo=mail-pj1-x1035.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNW1w-0002vt-58 for qemu-devel@nongnu.org; Fri, 25 Feb 2022 03:32:50 -0500 Received: by mail-pj1-x1035.google.com with SMTP id b8so4182178pjb.4 for ; Fri, 25 Feb 2022 00:32:47 -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=U6bYxsAh3+guLnp4fMGAdftsYRKJtOjCH26W44rqWsE=; b=q3bOQxP+c0RXVhmLsGaTM3IPSxX7ZJ6Yx7GxEEc76BNT6knNHFKaO2kmej4itIP3Q8 9r7obgZPcf7dz0vdaQ2IfkSrvfbJou7cPVHgPKpGHZUzTyLMT3Ala+sH2QIjWqrCnZSw GVbUHZwJVPIJqBHBwtwPd4NqtYuMd5cehSAOtHkrJeD4Gyi9XmnM/u1c86B0/biu9JAK wntpvV8e8z1vGEQgwpWdZUMT1V0ZfWo4mrZcE7BEBIuMuiO24FKLt8CSZ/6XMkIe+Ifg Oyqv8QHbJQQ3st1vGgg98gyIQ3YiRi69pbfk88ODFI5N9wLEzEqFt+iCMfdyE726Z/1B 9NMw== 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=U6bYxsAh3+guLnp4fMGAdftsYRKJtOjCH26W44rqWsE=; b=HnlTkpVp6gY8+HEhPXnfot9W2IKQ+JjfjS05lzK+caG/MUtbNfgE4HIPxMi2hT8Aeb z2ldboXzButu0+xs0V3x9I+iipg8R54KUkl6p9iyfXUqa0xrW3Nb4ROish/7aGRWGib/ NVxaoL5nbV8aBFcST5IHVRYa2wdnN/7XdagtHAJRrweT44+mkWiueMYFaHWVjx6kQfpt 4nSpIumPQzPEER0TdVZrv49MtEsWxy2HXBk7RuXQat2Ok5I1l1ll8jpBPF1gL5Ax1cRE CY1VDQ8qfiwTE4l2LwQ0uG28qVCNjsSBvb4Va8nz5xy2+lLJgTopJqJUJSjRskylyOBx Teow== X-Gm-Message-State: AOAM530wLWiadZXsEW5T5uFbPq4bAQpC+e2GH39Wrr+a2q+61e8ekFYJ K94nyBxVYvZqRaJJBzfJFA+SWARO7zy3XiJ9 X-Google-Smtp-Source: ABdhPJwBu/Llboq1ePh5rxZvBRmcW1g+7RW1VvNOAfMT9g/S5lrJYJ+1KYFQcrEL0ScyjwrYm5gW4w== X-Received: by 2002:a17:90b:3ce:b0:1bc:7783:4ce0 with SMTP id go14-20020a17090b03ce00b001bc77834ce0mr2142653pjb.60.1645777966216; Fri, 25 Feb 2022 00:32:46 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id g5-20020a63fa45000000b0037407b6ffdasm1891405pgk.5.2022.02.25.00.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 00:32:45 -0800 (PST) From: Stafford Horne To: QEMU Development Subject: [PULL 5/6] hw/openrisc/openrisc_sim: Add automatic device tree generation Date: Fri, 25 Feb 2022 17:32:21 +0900 Message-Id: <20220225083222.1174517-6-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220225083222.1174517-1-shorne@gmail.com> References: <20220225083222.1174517-1-shorne@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1035 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=shorne@gmail.com; helo=mail-pj1-x1035.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 --- configs/targets/or1k-softmmu.mak | 1 + hw/openrisc/openrisc_sim.c | 189 ++++++++++++++++++++++++++++--- 2 files changed, 175 insertions(+), 15 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/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 Fri Feb 25 08:32:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 12759948 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 1E880C433F5 for ; Fri, 25 Feb 2022 09:01:13 +0000 (UTC) Received: from localhost ([::1]:36564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNWTO-0005Ag-7x for qemu-devel@archiver.kernel.org; Fri, 25 Feb 2022 04:01:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNW20-0004d4-J9 for qemu-devel@nongnu.org; Fri, 25 Feb 2022 03:32:53 -0500 Received: from [2607:f8b0:4864:20::102c] (port=56173 helo=mail-pj1-x102c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNW1y-0002wA-Qt for qemu-devel@nongnu.org; Fri, 25 Feb 2022 03:32:52 -0500 Received: by mail-pj1-x102c.google.com with SMTP id gb21so4189237pjb.5 for ; Fri, 25 Feb 2022 00:32:50 -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=mpqGE9uMg7sW7MF5Cbm8/IKuVdqADRZx+gElgRze6d5yMEobvs9izQrxExX/p8oXU7 k53/6zx+iSk+BaZhT9+b2QO4BiB+erqG+7lmpESLMJ4iW/PsbeGu2sinFQqbjY/fpRNv Ksora34nksW0hx/ywW6EfLE5fOw0PNa2KP0sws7jRlvdru5TD/p7QDcTr/rAU4xss8ur eHRqhw54SUiOqr9Kf7JNaFAPfQo4H/OYMrgl/Ji6Y5LtIseJWrAnLKekXxgjM2BWNlvU 3Yt5RG/hesS2/B045hwDxZK8jWFYXYJxGezvHOsaV6EZZeo1kYSD/Cq7a8DMRZk9TOew C/cw== 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=JR2+8dwbNhfwCmdzwb+HMVwYfZn1jwH2iODs0pSZ2QKKZEw0ozD0rwOMVZBDUwVKbI kBq5DWrYTh2xmN6UGb0nsW8Qmz5Qt5hI8jwvZtx6Zat72XioNrun/3LKvjyVITyTxRWw RcD6xgO3ltvtbnYlvpK9TZcH9h0eS1x/P8BQYZ1jIywDD7+pVlwpL/WnOaa6q1LSqiKl rj20tFk0eb6fyHzlRW0jFlsr6167DIU7dN9TQ/jRECueAeUz4nWcDsoCKn+cILNHsLgM 35IrBod4zsSX++MjU/1fQBMlJsf4+uKCmZGf2jRjpuTMbaDC2gd1YEfawWqcHj5OQPz5 pNlA== X-Gm-Message-State: AOAM530CjR46r6cqIQuzWU9Z1SmEwqEdUvzAcD6mMLFfAa6mji7lZqz4 +n0p2DbtvehtHHimI9OIRMx2GZelvaZSqM0e X-Google-Smtp-Source: ABdhPJyJ5fbRxuXg4nqW/bywO5QsoiUEw7eT5cxJdr69iGOVKMlEtQ2Aff2gnRz/bZ0pmBah4O+j5Q== X-Received: by 2002:a17:902:f711:b0:14d:61ba:8baf with SMTP id h17-20020a170902f71100b0014d61ba8bafmr6360556plo.39.1645777969255; Fri, 25 Feb 2022 00:32:49 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id d7-20020a056a00244700b004e1300a2f7csm2070324pfj.212.2022.02.25.00.32.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 00:32:48 -0800 (PST) From: Stafford Horne To: QEMU Development Subject: [PULL 6/6] hw/openrisc/openrisc_sim: Add support for initrd loading Date: Fri, 25 Feb 2022 17:32:22 +0900 Message-Id: <20220225083222.1174517-7-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220225083222.1174517-1-shorne@gmail.com> References: <20220225083222.1174517-1-shorne@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::102c (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=shorne@gmail.com; helo=mail-pj1-x102c.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); }