From patchwork Thu Jun 27 15:20:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 11020009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C3621708 for ; Thu, 27 Jun 2019 15:55:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C871283E8 for ; Thu, 27 Jun 2019 15:55:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2C75283F9; Thu, 27 Jun 2019 15:55:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9D02F283E8 for ; Thu, 27 Jun 2019 15:55:56 +0000 (UTC) Received: from localhost ([::1]:52006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hgWkd-00070N-W9 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 27 Jun 2019 11:55:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32861) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hgWHO-0002xV-M9 for qemu-devel@nongnu.org; Thu, 27 Jun 2019 11:25:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hgWHJ-0008LT-0A for qemu-devel@nongnu.org; Thu, 27 Jun 2019 11:25:38 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:44866) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hgWHE-0007LM-FV for qemu-devel@nongnu.org; Thu, 27 Jun 2019 11:25:35 -0400 Received: by mail-pf1-f193.google.com with SMTP id t16so1393346pfe.11 for ; Thu, 27 Jun 2019 08:24:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:cc:from:to; bh=fcm0+r8fxMNfE/F4H9Cg6/O9Ghx9bryN1yVdrSBGRYk=; b=nimDNKQF9BRNDiPsVF98PinuG0zz9fjw/Elspk8mKNIwjuxK7cJP9zfheCgd8b5I8s jl3WxcU+MnCi6qKU9y4DTABobVtJSJd/jIF/cem66nEb0P8FmDVd6ap+RdwP2PX10TGS mMLczkWhEqckh7B21C8wp2IicdqhFm2N5wuWxHO4ktPaL67a4GG2JDR39VglEAIMEZNz qMDsGsZq2Uub+4VVQoRSILoMV3+re2s3wxYAaLFYxBMR3TsINjTG4uoHUk11DcG/DtXb 2hkThOuydp6HXhaCiFznc8M9WnW0FJQ5DuWpyQAAja9EJULier1JFofuEHyT8Ze9pVdh AVoQ== X-Gm-Message-State: APjAAAW46zh83FlchNMWtxsetZHlvCxBaIETC5tYIJNvdotdF3SEq13D kDq+/+dE2ZZIroUdscOFWr1Eqg== X-Google-Smtp-Source: APXvYqzxQ+Uu+CcqODIS+7c07XpMzXjR41fSSWHLjHPmSnJvt2vMl0lO9TAR4HaqokalkD7M2IAG/Q== X-Received: by 2002:a63:1365:: with SMTP id 37mr4252663pgt.266.1561649074204; Thu, 27 Jun 2019 08:24:34 -0700 (PDT) Received: from localhost (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id q144sm4013593pfc.103.2019.06.27.08.24.33 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 08:24:33 -0700 (PDT) Date: Thu, 27 Jun 2019 08:20:06 -0700 Message-Id: <20190627152011.18686-30-palmer@sifive.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190627152011.18686-1-palmer@sifive.com> References: <20190627152011.18686-1-palmer@sifive.com> MIME-Version: 1.0 From: Palmer Dabbelt To: Peter Maydell X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.210.193 Subject: [Qemu-devel] [PULL 29/34] riscv: sifive_u: Update the plic hart config to support multicore X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair Francis , Bin Meng , qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Palmer Dabbelt Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Bin Meng At present the PLIC is instantiated to support only one hart, while the machine allows at most 4 harts to be created. When more than 1 hart is configured, PLIC needs to instantiated to support multicore, otherwise an SMP OS does not work. Signed-off-by: Bin Meng Reviewed-by: Alistair Francis Signed-off-by: Palmer Dabbelt --- hw/riscv/sifive_u.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index e2120ac7a5d3..a416d5d08b4d 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -344,6 +344,8 @@ static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp) MemoryRegion *system_memory = get_system_memory(); MemoryRegion *mask_rom = g_new(MemoryRegion, 1); qemu_irq plic_gpios[SIFIVE_U_PLIC_NUM_SOURCES]; + char *plic_hart_config; + size_t plic_hart_config_len; int i; Error *err = NULL; NICInfo *nd = &nd_table[0]; @@ -357,9 +359,21 @@ static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp) memory_region_add_subregion(system_memory, memmap[SIFIVE_U_MROM].base, mask_rom); + /* create PLIC hart topology configuration string */ + plic_hart_config_len = (strlen(SIFIVE_U_PLIC_HART_CONFIG) + 1) * smp_cpus; + plic_hart_config = g_malloc0(plic_hart_config_len); + for (i = 0; i < smp_cpus; i++) { + if (i != 0) { + strncat(plic_hart_config, ",", plic_hart_config_len); + } + strncat(plic_hart_config, SIFIVE_U_PLIC_HART_CONFIG, + plic_hart_config_len); + plic_hart_config_len -= (strlen(SIFIVE_U_PLIC_HART_CONFIG) + 1); + } + /* MMIO */ s->plic = sifive_plic_create(memmap[SIFIVE_U_PLIC].base, - (char *)SIFIVE_U_PLIC_HART_CONFIG, + plic_hart_config, SIFIVE_U_PLIC_NUM_SOURCES, SIFIVE_U_PLIC_NUM_PRIORITIES, SIFIVE_U_PLIC_PRIORITY_BASE,