Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53063C433DB for ; Mon, 18 Jan 2021 01:19:53 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0E7E9207AE for ; Mon, 18 Jan 2021 01:19:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E7E9207AE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=flygoat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1JCy-0001NF-5E for qemu-devel@archiver.kernel.org; Sun, 17 Jan 2021 20:19:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1JAd-0007Tu-DS for qemu-devel@nongnu.org; Sun, 17 Jan 2021 20:17:27 -0500 Received: from wnew1-smtp.messagingengine.com ([64.147.123.26]:53451) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1JAb-0007Hl-Ci for qemu-devel@nongnu.org; Sun, 17 Jan 2021 20:17:27 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailnew.west.internal (Postfix) with ESMTP id C07A211ED; Sun, 17 Jan 2021 20:17:23 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sun, 17 Jan 2021 20:17:24 -0500 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=1QcGBRgR4Y8AGVk+WiBOYdLWJdbpL aGJGC7iuCjXu/m9I3OmNcFYjVlxIbC3VPKKQSb7UCjxlypjcs+RbJR7U0QKA6LqJ Zri9Xqs8EU3PJyKLr89wwpeF9WMG8tyrTwaROt3C8YF7qXNVP8MhKPD/iAdFst9K OIj6MGLMA84gOptJDpxd6YpjEvG2iEkrDEakxzjiGj1Pyeu8b6RCl/ohPi8EzVBe ujDrtg1EAUUI6xcsi8Hmnm7ENgEUbpzd20NGlMXLb1RV/ruTrCq38pneejrAird3 nvbFenv6SfpnFEWa5Zsn05NhUm0dqFPnG56xYHCfGDSe9O8dw5fCYVvuQ== 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=h+Ja3LFb 5KCtqHSNTaDI8UgS0uB4Tdk7r77vSY2NmCu0+GpGN8jxIMbBrbqLBQZe8nx9unNE BftnBrTKsgiBq9sxQkAB+sZXlqgVhksgAzxJNPfdwJTkSVj5PnYItfIe0cjJmrM4 T4Atk4xFhDsh60WxUem3X6ij0oitAwZ7CO9z402q7Bos05LQ4hI8Tq6RVHlfQf/c TYUJELyzrXdfmt4DbBKOQrhpBXErG1ARquPHKh8Pmu/7K6V75sWsGyAs8KiApn+N KpwJlXkqoMIF0Kh5s7XJdkKc9CifRjF6W74YOmoIdBrCd/V1ccHvUKfeGatuSnK3 5fEqKgsPX2bEpQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrtdejgdefvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhirgiguhhn ucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqeenucggtf frrghtthgvrhhnpeffgfekleeugeeujeegiedvhfehtdfhkefgvdeiledthfejleekvdel udffuedvieenucffohhmrghinhepghhnuhdrohhrghenucfkphepudduiedrvddvkedrke egrddvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep jhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomh X-ME-Proxy: Received: from strike.U-LINK.com (unknown [116.228.84.2]) by mail.messagingengine.com (Postfix) with ESMTPA id 7C5D924005C; Sun, 17 Jan 2021 20:17:18 -0500 (EST) From: Jiaxun Yang To: qemu-devel@nongnu.org Subject: [PATCH v3 1/2] hw/intc: Add Loongson Inter Processor Interrupt controller Date: Mon, 18 Jan 2021 09:17:05 +0800 Message-Id: <20210118011706.22639-2-jiaxun.yang@flygoat.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210118011706.22639-1-jiaxun.yang@flygoat.com> References: <20210118011706.22639-1-jiaxun.yang@flygoat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=64.147.123.26; envelope-from=jiaxun.yang@flygoat.com; helo=wnew1-smtp.messagingengine.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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_SORBS_WEB=1.5, 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: Huacai Chen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 Public + * 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_LOONGSON_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 = 0, + R_IEN = 1, + R_SET = 2, + R_CLR = 3, + /* No register at 0x10~0x20 */ + R_MBOX0 = 8, + R_END = 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 = opaque; + uint64_t r = 0; + + addr >>= 2; + switch (addr) { + case R_ISR: + r = p->isr; + break; + case R_IEN: + r = 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 = 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 = opaque; + uint32_t value = val64; + + addr >>= 2; + switch (addr) { + case R_ISR: + /* Do nothing */ + break; + case R_IEN: + p->ien = value; + break; + case R_SET: + p->isr |= value; + break; + case R_CLR: + p->isr &= ~value; + break; + case R_MBOX0 ... (R_END - 1): + p->mbox[addr - R_MBOX0] = value; + break; + default: + break; + } + p->isr &= 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 = opaque; + + p->ien = 0; + p->isr = 0; + for (i = 0; i < NUM_MBOX; i++) { + p->mbox[i] = 0; + } +} + +static const MemoryRegionOps pic_mmio_ops = { + .read = ipi_read, + .write = ipi_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .impl = { + .min_access_size = 4, + .max_access_size = 4 + }, + .valid = { + .min_access_size = 4, + .max_access_size = 8 + }, +}; + +static void loongson_ipi_init(Object *obj) +{ + struct loongson_ipi *p = 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 = { + .name = TYPE_LOONGSON_IPI, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(struct loongson_ipi), + .instance_init = 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 +config LOONGSON_IPI + bool + config SIFIVE_CLINT bool 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('grlib_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" +# loongson_ipi.c +loongson_ipi_read(uint64_t addr, uint64_t value) "addr 0x%02" PRIx64 " value 0x%08" PRIx64 +loongson_ipi_write(uint64_t addr, uint64_t value) "addr 0x%02" PRIx64 " value 0x%08" PRIx64 + # xics.c xics_icp_check_ipi(int server, uint8_t mfrr) "CPU %d can take IPI mfrr=0x%x" xics_icp_accept(uint32_t old_xirr, uint32_t new_xirr) "icp_accept: XIRR 0x%"PRIx32"->0x%"PRIx32 -- 2.30.0