From nobody Thu Mar 28 16:26:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1610588120; cv=none; d=zohomail.com; s=zohoarc; b=H/GOJF+R7fw6b7CXAAVunCOBVz1lCa9L9IvC/uBy3VqsfOtcjgy0UeW5+sTNQdQ/KHX6LZpCgcgoITT8S//u3310guGRqbpJA89U6/bhsr0sGJ4MgCon1V1ImZFiv3mpvuZx8XcFvbMG/Xg+U1XqbPPrDToXC/dtcyo/NV8kJyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610588120; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=v3BVYMLpE7zubOvuCTCkhNzBABvMHf5Y6mSaeLMlJ1g=; b=aqFwRIUvrsRIb3wnDeW+9g/hvV3dIIXqu7Nu/TJpnzKOX47qZAlhsI54FUgoqQdVvtEcPUN2fUuPjAEIXw9sGvk79faSVhsijEntfh+tVi4quPVrH7s/4bGipztVyfv+WEuGGjNId85L7jYls1rB7TBsIX+EcEIkZVDvddCC95M= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610588120073464.90085627007284; Wed, 13 Jan 2021 17:35:20 -0800 (PST) Received: from localhost ([::1]:48160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzrXj-0002g0-0T for importer@patchew.org; Wed, 13 Jan 2021 20:35:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzrVR-0001MR-7j for qemu-devel@nongnu.org; Wed, 13 Jan 2021 20:32:57 -0500 Received: from new4-smtp.messagingengine.com ([66.111.4.230]:34027) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzrVP-0005NH-9K for qemu-devel@nongnu.org; Wed, 13 Jan 2021 20:32:57 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailnew.nyi.internal (Postfix) with ESMTP id 98BAA5805C0; Wed, 13 Jan 2021 20:32:54 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 13 Jan 2021 20:32:54 -0500 Received: from localhost.localdomain (unknown [117.136.8.144]) by mail.messagingengine.com (Postfix) with ESMTPA id 7CA021080059; Wed, 13 Jan 2021 20:32:49 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=v3BVYMLpE7zub OvuCTCkhNzBABvMHf5Y6mSaeLMlJ1g=; b=hzC3GC7Ku5HpRYbZ4h+aQI6FLPUhq cQnGk9GVmRp4oHYoPPaZaqA4nPMb8nZUhTGDpxT5ucrfaMNonV3MrRn74eYG0SGV k9o+IyyqQY0VhmBefHhiaSsbVOL7PjuCUpBaO3cwFqQC4oaZ3YqrLOFQ69Dza/Hq 2Ah0xNwydfMudnM1bReoHYEV3+PiFJBjl41ozvDNWRB6YwTwpVTHNwAojfR4ZUTC y6OJ2cBH3+AaEtkVIUJXAr4LTASNru3ur8gP68pFWpvd4IfDLShlf6hv5LSqL3Jx 5q7X4JxXd3gop5IcagqzyPawwWw0xO8PXkips1oTqWHfd1/DD1loxX4/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=v3BVYMLpE7zubOvuCTCkhNzBABvMHf5Y6mSaeLMlJ1g=; b=XSs6POvu QxxYBQWrSY6lTNiAZMvUUsvcrLe4NNHzN/pyIPp38Zl8/TdRyiLpNUoxQqzfwoTZ AC7oe8f9P/DG6CBkLaNVEshr9XqwiauyvRVRuNWlAjTKWEX9zg4pZOJukX4T7q3C b68GWbOslKQJYh5RUImPTYKDYXFAjR2AVDarV/xZAxaHt0ECOuKAJzkAo1UD0pfs YvBaa0EZin3g2fVEoLsXpPuUIr2pKb73f1jN6AlnflA9bi5bnqbgXMc04tjFjDiv PHUVKnx/Tntzzt9gKeveRf11zvm96UL1ffUg5705t6BK0GsDk24r6RIyvlxNxLCa 1QTXFZzvVvVndw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedukedrtdeggdefhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhirgiguhhn ucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqeenucggtf frrghtthgvrhhnpeffgfekleeugeeujeegiedvhfehtdfhkefgvdeiledthfejleekvdel udffuedvieenucffohhmrghinhepghhnuhdrohhrghenucfkphepuddujedrudefiedrke drudeggeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: From: Jiaxun Yang To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] hw/intc: Add Loongson Inter Processor Interrupt controller Date: Thu, 14 Jan 2021 09:31:46 +0800 Message-Id: <20210114013147.92962-2-jiaxun.yang@flygoat.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210114013147.92962-1-jiaxun.yang@flygoat.com> References: <20210114013147.92962-1-jiaxun.yang@flygoat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=66.111.4.230; envelope-from=jiaxun.yang@flygoat.com; helo=new4-smtp.messagingengine.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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: Aurelien Jarno , Aleksandar Rikalo , Huacai Chen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Loongson IPI controller is a MMIO based simple level triggered interrupt controller. It will trigger IRQ to it's upstream processor when set register is written. It also has 4 64bit mailboxes to pass boot information to secondary processor. Signed-off-by: Jiaxun Yang Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/intc/loongson_ipi.h | 20 ++++ hw/intc/loongson_ipi.c | 174 +++++++++++++++++++++++++++++++++ hw/intc/Kconfig | 3 + hw/intc/meson.build | 1 + hw/intc/trace-events | 4 + 5 files changed, 202 insertions(+) create mode 100644 include/hw/intc/loongson_ipi.h create mode 100644 hw/intc/loongson_ipi.c diff --git a/include/hw/intc/loongson_ipi.h b/include/hw/intc/loongson_ipi.h new file mode 100644 index 0000000000..a535c467bf --- /dev/null +++ b/include/hw/intc/loongson_ipi.h @@ -0,0 +1,20 @@ +/* + * This file is subject to the terms and conditions of the GNU General Pub= lic + * License. See the file "COPYING" in the main directory of this archive + * for more details. + * + * Copyright (c) 2020-2021 Jiaxun Yang + * + */ + +#ifndef LOONGSON_IPI_H +#define LOONGSON_IPI_H + +#include "qemu/units.h" +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_LOONGSON_IPI "loongson.ipi" +#define LOONGSON_IPI(obj) OBJECT_CHECK(struct loongson_ipi, (obj), TYPE_LO= ONGSON_IPI) + +#endif /* LOONGSON_IPI_H */ diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c new file mode 100644 index 0000000000..cce1da8fb9 --- /dev/null +++ b/hw/intc/loongson_ipi.c @@ -0,0 +1,174 @@ +/* + * QEMU Loongson Inter Processor Interrupt Controller + * + * Copyright (c) 2020-2021 Jiaxun Yang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "qemu/osdep.h" +#include "hw/sysbus.h" +#include "qemu/module.h" +#include "qemu/log.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/intc/loongson_ipi.h" +#include "sysemu/reset.h" +#include "trace.h" + +/* + * Mailboxes are actually 4 64bit registers but we treat it as 8 32bit + * to simplify implementation. + */ +#define NUM_MBOX 8 + +enum { + R_ISR =3D 0, + R_IEN =3D 1, + R_SET =3D 2, + R_CLR =3D 3, + /* No register at 0x10~0x20 */ + R_MBOX0 =3D 8, + R_END =3D R_MBOX0 + NUM_MBOX +}; + +struct loongson_ipi { + SysBusDevice parent_obj; + + MemoryRegion mmio; + qemu_irq parent_irq; + + uint32_t isr; + uint32_t ien; + uint32_t mbox[NUM_MBOX]; +}; + +static uint64_t +ipi_read(void *opaque, hwaddr addr, unsigned int size) +{ + struct loongson_ipi *p =3D opaque; + uint64_t r =3D 0; + + addr >>=3D 2; + switch (addr) { + case R_ISR: + r =3D p->isr; + break; + case R_IEN: + r =3D p->ien; + break; + case R_SET: + case R_CLR: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Reading write only reg: 0x%" HWADDR_PRIx "\n", + __func__, addr); + break; + case R_MBOX0 ... (R_END - 1): + r =3D p->mbox[addr - R_MBOX0]; + break; + default: + break; + } + + trace_loongson_ipi_read(addr, r); + + return r; +} + +static void +ipi_write(void *opaque, hwaddr addr, + uint64_t val64, unsigned int size) +{ + struct loongson_ipi *p =3D opaque; + uint32_t value =3D val64; + + addr >>=3D 2; + switch (addr) { + case R_ISR: + /* Do nothing */ + break; + case R_IEN: + p->ien =3D value; + break; + case R_SET: + p->isr |=3D value; + break; + case R_CLR: + p->isr &=3D ~value; + break; + case R_MBOX0 ... (R_END - 1): + p->mbox[addr - R_MBOX0] =3D value; + break; + default: + break; + } + p->isr &=3D p->ien; + + trace_loongson_ipi_write(addr, value); + + qemu_set_irq(p->parent_irq, !!p->isr); +} + +static void ipi_reset(void *opaque) +{ + int i; + struct loongson_ipi *p =3D opaque; + + p->ien =3D 0; + p->isr =3D 0; + for (i =3D 0; i < NUM_MBOX; i++) { + p->mbox[i] =3D 0; + } +} + +static const MemoryRegionOps pic_mmio_ops =3D { + .read =3D ipi_read, + .write =3D ipi_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 4 + }, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 8 + }, +}; + +static void loongson_ipi_init(Object *obj) +{ + struct loongson_ipi *p =3D LOONGSON_IPI(obj); + + sysbus_init_irq(SYS_BUS_DEVICE(obj), &p->parent_irq); + + memory_region_init_io(&p->mmio, obj, &pic_mmio_ops, p, + "loongson.ipi", R_END * 4); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &p->mmio); + qemu_register_reset(ipi_reset, p); +} + +static const TypeInfo loongson_ipi_info =3D { + .name =3D TYPE_LOONGSON_IPI, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(struct loongson_ipi), + .instance_init =3D loongson_ipi_init, +}; + +static void loongson_ipi_register_types(void) +{ + type_register_static(&loongson_ipi_info); +} + +type_init(loongson_ipi_register_types) diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig index c18d11142a..0e15102662 100644 --- a/hw/intc/Kconfig +++ b/hw/intc/Kconfig @@ -59,6 +59,9 @@ config RX_ICU config LOONGSON_LIOINTC bool =20 +config LOONGSON_IPI + bool + config SIFIVE_CLINT bool =20 diff --git a/hw/intc/meson.build b/hw/intc/meson.build index 53cba11569..5257c5fb94 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -36,6 +36,7 @@ specific_ss.add(when: 'CONFIG_GRLIB', if_true: files('grl= ib_irqmp.c')) specific_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_plic.c')) specific_ss.add(when: 'CONFIG_IOAPIC', if_true: files('ioapic.c')) specific_ss.add(when: 'CONFIG_LOONGSON_LIOINTC', if_true: files('loongson_= liointc.c')) +specific_ss.add(when: 'CONFIG_LOONGSON_IPI', if_true: files('loongson_ipi.= c')) specific_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('mips_gic.c')) specific_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_intc.c')) specific_ss.add(when: 'CONFIG_OMPIC', if_true: files('ompic.c')) diff --git a/hw/intc/trace-events b/hw/intc/trace-events index 8ed397a0d5..e43e318be0 100644 --- a/hw/intc/trace-events +++ b/hw/intc/trace-events @@ -60,6 +60,10 @@ lm32_pic_set_ip(uint32_t ip) "ip 0x%08x" lm32_pic_get_im(uint32_t im) "im 0x%08x" lm32_pic_get_ip(uint32_t ip) "ip 0x%08x" =20 +# loongson_ipi.c +loongson_ipi_read(uint64_t addr, uint64_t value) "addr 0x%02" PRIx64 " val= ue 0x%08" PRIx64 +loongson_ipi_write(uint64_t addr, uint64_t value) "addr 0x%02" PRIx64 " va= lue 0x%08" PRIx64 + # xics.c xics_icp_check_ipi(int server, uint8_t mfrr) "CPU %d can take IPI mfrr=3D0= x%x" xics_icp_accept(uint32_t old_xirr, uint32_t new_xirr) "icp_accept: XIRR 0x= %"PRIx32"->0x%"PRIx32 --=20 2.30.0 From nobody Thu Mar 28 16:26:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1610588300; cv=none; d=zohomail.com; s=zohoarc; b=JW27Uk0N3QfNouTtTYbC7Np0u6Mfq6bxpx3hFkB3MUV9BL7WHEHAKKiGNFPC+Xime2Ms5kQ686/sVipVlvw0ACNkgcVhkd4dwbnTABrug+Pd7Nh4i8aC0YAqU1eH9NSbsAn487omTh98QXohsaFcA4AuznJaXNx/25STeB039gU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610588300; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XOlNwBn84S6z3g0YsZCrh7EPCXFotK9cQmm+pumQZhg=; b=Gcio7q6lc7ZyWY7zrXUVueGhs6cIgFJt/yd1yTZ2BXRjQqUPmFkpeDtOChd6eE3BChamjC7zQGp8gaGWnYqut+QWtqsbcct2bI9BgTbpWHkdxPA3qeUFKOdxAf3EoKucjobWUxR4DBJeKzxIlhuLEM+BgMQCNTH2xv+qWRNgOfo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610588300630481.99337839434713; Wed, 13 Jan 2021 17:38:20 -0800 (PST) Received: from localhost ([::1]:52772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzrad-0004kW-Jc for importer@patchew.org; Wed, 13 Jan 2021 20:38:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzrVU-0001S8-4S for qemu-devel@nongnu.org; Wed, 13 Jan 2021 20:33:00 -0500 Received: from new4-smtp.messagingengine.com ([66.111.4.230]:37715) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzrVS-0005OI-HD for qemu-devel@nongnu.org; Wed, 13 Jan 2021 20:32:59 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailnew.nyi.internal (Postfix) with ESMTP id 155035805C1; Wed, 13 Jan 2021 20:32:58 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 13 Jan 2021 20:32:58 -0500 Received: from localhost.localdomain (unknown [117.136.8.144]) by mail.messagingengine.com (Postfix) with ESMTPA id B3BDC1080059; Wed, 13 Jan 2021 20:32:54 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=XOlNwBn84S6z3 g0YsZCrh7EPCXFotK9cQmm+pumQZhg=; b=YbObHP/M0Tz25bwt8Sd8Sl6gMxv4J 8te+rZA0uTR1NfUiBYVNaHDL/R7fo7G7isxUv7CVIsY5Tewr4JeiytlfOza4FZ3j 0VhRhNbJBHG0SMOA9gwisDq883irHKdI+KEp3lbcLWmXH0N/kqG+rVCqgQZlFnLc KXQ8oD3ryNQ0tzf3EDuMmBxlx/X4wZpV8TusYOKyLtJIJ1HFSJApWYOgBVUlBaPR bIBdkLQTH/7ZZUP1ABpWX1k6nPfnXci6mdkI2MmK0N9H5jr7HNY8/asuQs2gLQKh 6xayUWG3mDNsct+b9xsniO0tx+8Vr/E/a6giNCCFA+qbfFf9GBEz2PoIA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=XOlNwBn84S6z3g0YsZCrh7EPCXFotK9cQmm+pumQZhg=; b=a9MQRb5l ZBE6juQo/KnQDA6iQbaaVrngO4uHSBumcuUfTeZ552pmrMnw/g0KvSHSJFufA1rZ hl7qyKWdblRmMztqqSSqCJ+sMTV3pAMsZnfDSs+uN3Ngvu7OrPOMzwloAl6lL8P4 Jqyu5rLRsgPBSAuECkP3vG2xAXpf1d1AxpTXK73j80NW4w7QsFKG9lEAJdGH52N0 fcHx17Z8oCf86PNnY0UWKdW1369MuIsgjhUvsUPMM4XJfSM47CbhtpbUD+zOLRma UlxwI0mUCicyEn9ANu6QaHBqQG3tA9UsB5VMylcPCRyYZLFMMz4R2sNcqhtahLLE mv17i/JjYusWYg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedukedrtdeggdefhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhirgiguhhn ucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqeenucggtf frrghtthgvrhhnpeejiefhgfetleekleffudektdehvedujedvgeekkeejfefhhffhtedu tefgtdffueenucfkphepuddujedrudefiedrkedrudeggeenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhih ghhorghtrdgtohhm X-ME-Proxy: From: Jiaxun Yang To: qemu-devel@nongnu.org Subject: [PATCH v2 2/2] hw/mips/loongson3_virt: Add TCG SMP support Date: Thu, 14 Jan 2021 09:31:47 +0800 Message-Id: <20210114013147.92962-3-jiaxun.yang@flygoat.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210114013147.92962-1-jiaxun.yang@flygoat.com> References: <20210114013147.92962-1-jiaxun.yang@flygoat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=66.111.4.230; envelope-from=jiaxun.yang@flygoat.com; helo=new4-smtp.messagingengine.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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: Aurelien Jarno , Aleksandar Rikalo , Huacai Chen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" loongson3_virt has KVM SMP support in kenrel. This patch adds TCG SMP support by enable IPI controller for machine. Note that TCG SMP can only support up to 4 CPUs as we didn't implement multi-node support. Signed-off-by: Jiaxun Yang --- hw/mips/loongson3_bootp.h | 1 + hw/mips/loongson3_virt.c | 20 +++++++++++++++++++- hw/mips/Kconfig | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hw/mips/loongson3_bootp.h b/hw/mips/loongson3_bootp.h index 09f8480abf..4756aa44f6 100644 --- a/hw/mips/loongson3_bootp.h +++ b/hw/mips/loongson3_bootp.h @@ -210,6 +210,7 @@ enum { VIRT_PCIE_ECAM, VIRT_BIOS_ROM, VIRT_UART, + VIRT_IPIS, VIRT_LIOINTC, VIRT_PCIE_MMIO, VIRT_HIGHMEM diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c index d4a82fa536..0684a035b0 100644 --- a/hw/mips/loongson3_virt.c +++ b/hw/mips/loongson3_virt.c @@ -35,6 +35,7 @@ #include "hw/boards.h" #include "hw/char/serial.h" #include "hw/intc/loongson_liointc.h" +#include "hw/intc/loongson_ipi.h" #include "hw/mips/mips.h" #include "hw/mips/cpudevs.h" #include "hw/mips/fw_cfg.h" @@ -59,6 +60,7 @@ =20 #define PM_CNTL_MODE 0x10 =20 +#define LOONGSON_TCG_MAX_VCPUS 4 #define LOONGSON_MAX_VCPUS 16 =20 /* @@ -71,6 +73,7 @@ #define UART_IRQ 0 #define RTC_IRQ 1 #define PCIE_IRQ_BASE 2 +#define IPI_REG_SPACE 0x100 =20 const struct MemmapEntry virt_memmap[] =3D { [VIRT_LOWMEM] =3D { 0x00000000, 0x10000000 }, @@ -81,6 +84,7 @@ const struct MemmapEntry virt_memmap[] =3D { [VIRT_PCIE_ECAM] =3D { 0x1a000000, 0x2000000 }, [VIRT_BIOS_ROM] =3D { 0x1fc00000, 0x200000 }, [VIRT_UART] =3D { 0x1fe001e0, 0x8 }, + [VIRT_IPIS] =3D { 0x3ff01000, 0x400 }, [VIRT_LIOINTC] =3D { 0x3ff01400, 0x64 }, [VIRT_PCIE_MMIO] =3D { 0x40000000, 0x40000000 }, [VIRT_HIGHMEM] =3D { 0x80000000, 0x0 }, /* Variable */ @@ -495,6 +499,10 @@ static void mips_loongson3_virt_init(MachineState *mac= hine) error_report("Loongson-3/TCG needs cpu type Loongson-3A1000"); exit(1); } + if (machine->smp.cpus > LOONGSON_TCG_MAX_VCPUS) { + error_report("Loongson-3/TCG supports up to 4 CPUs"); + exit(1); + } } else { if (!machine->cpu_type) { machine->cpu_type =3D MIPS_CPU_TYPE_NAME("Loongson-3A4000"); @@ -545,7 +553,17 @@ static void mips_loongson3_virt_init(MachineState *mac= hine) qemu_register_reset(main_cpu_reset, cpu); =20 if (i >=3D 4) { - continue; /* Only node-0 can be connected to LIOINTC */ + continue; /* Only node-0 can be connected to LIOINTC and IPI */ + } + + if (!kvm_enabled()) { + /* IPI is handled by kernel for KVM */ + DeviceState *ipi; + ipi =3D qdev_new(TYPE_LOONGSON_IPI); + sysbus_realize_and_unref(SYS_BUS_DEVICE(ipi), &error_fatal); + sysbus_mmio_map(SYS_BUS_DEVICE(ipi), 0, + virt_memmap[VIRT_IPIS].base + IPI_REG_SPACE * = i); + sysbus_connect_irq(SYS_BUS_DEVICE(ipi), 0, cpu->env.irq[6]); } =20 for (ip =3D 0; ip < 4 ; ip++) { diff --git a/hw/mips/Kconfig b/hw/mips/Kconfig index aadd436bf4..4fb0cc49e8 100644 --- a/hw/mips/Kconfig +++ b/hw/mips/Kconfig @@ -39,6 +39,7 @@ config LOONGSON3V select SERIAL select GOLDFISH_RTC select LOONGSON_LIOINTC + select LOONGSON_IPI if TCG select PCI_DEVICES select PCI_EXPRESS_GENERIC_BRIDGE select MSI_NONBROKEN --=20 2.30.0