From nobody Thu Sep 19 00:57:17 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1721309790; cv=none; d=zohomail.com; s=zohoarc; b=mT+We9K6czzpU6w46MfxOglH62gbACnP3CwswhRjLNBw/fCcubAxxYjyAFomRcLK7zI7rz04BGdyUBYZu30MQ+6RrWd1c94qVfM/N0X2Od5213ss158681uoS5K6/RzmONedTC/K6YQ41B8KSoxpt+kW8/O/ZW3EBP/hVSfGpeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721309790; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kccTi0ZFoJFLXkrpp7aedV5PRYpdvGGcofBCMl8r5k4=; b=X6u+zkN7aRLNkSmqJmVeu5cyMnOA/WxnyLcpuc4bAs2Vr1SVxhBvCblVTrSadO/iRMK7pSO8E7MHbyMQr/TEc0fZKOGHBhMJ/7woo28RW5Av0lu1hrmRZCLVawJLYbaQJJ4mkxcXFVnNx/6Y5Pnf3q9mbhnLkC3YyvoFBW1S9n8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1721309790521574.0987971814792; Thu, 18 Jul 2024 06:36:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sURHb-0003W3-ID; Thu, 18 Jul 2024 09:34:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sURHR-0002dN-SG for qemu-devel@nongnu.org; Thu, 18 Jul 2024 09:34:48 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sURHP-00007F-VO for qemu-devel@nongnu.org; Thu, 18 Jul 2024 09:34:45 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4266f344091so2837445e9.0 for ; Thu, 18 Jul 2024 06:34:43 -0700 (PDT) Received: from localhost.localdomain ([176.176.173.113]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2b29342sm13216315e9.31.2024.07.18.06.34.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 18 Jul 2024 06:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721309682; x=1721914482; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kccTi0ZFoJFLXkrpp7aedV5PRYpdvGGcofBCMl8r5k4=; b=ezM4RzB5wjGpMikxSaKOmyv7iZUmBCRMGXrwXuriIuMJ/20lycBxhLo2GihFg5SuwT 5w0nOhVtDO525Dj6+Dm3EwRcMiL55kpOWiM5xQs8IrAphFcKwFGUgKv6ZFPk11rYxxQa gmvD+MJ75SCHZ/bC02qZm507ihGkWHnJ0qz/nt/Yi5AUqJPkbFDK8Kd/u+O258p1tAFL CtAkwS8od7V2i5VVcP1D4XX1JD6BbtJxRbcQrQ2ohXMja1qa+kifQR83XEijOdq9ifSv osdP5ZiK9hb3TGpPNnL/dtMJjQDudeBFiR3JxcFfqJNSmjl0KnPIfXZnGG+9FVZ8ACTk RC1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721309682; x=1721914482; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kccTi0ZFoJFLXkrpp7aedV5PRYpdvGGcofBCMl8r5k4=; b=COu6VisSmJtt9RmnzlGpuTls0qz5xlAQPH0zK7MF6puFAgEjyoY3uprfhSdxXitxA/ MTmjZ6RRH1NzxlSME+bQ7n4Wv4edeDwfSrIEYwKfAAbvl28dlL9OMXERNhEm7RLeGfFd K394WtZBxyeQ2LweQRfym+50lnP9yKOIHQiIVBRDnzaIeFPUZDued+4SbgBR/KpSIcQm 8aJZF+hAmj2E2V4JDvajgcN8JeIWS7W1Ebp4OCL80+Pbr6K791Bvxdot4gOprdxrgIJv AUH4ofTMGchK0ZbrEWdrby86kYN3Kni/4VFU9zyvABuib4SX88OBWYB6h4jCMhxYf8pH TKww== X-Forwarded-Encrypted: i=1; AJvYcCXE2l/TxH43szqoarf3dcwAF4yAPaVXwFclQyqOgq4GFU7iEcLYxzMP74t24zR/Ac3mc61jsrL/aOONCvBTjbRywjy2rmU= X-Gm-Message-State: AOJu0YwL7GpcDwrTNphtt7rzxPzTLBepsRS2GpBGG4E8xju0gtN+j3Zk njcKJRZRRTxkSUV61oMvJU+oHugNMgYpFZUCIo9gmkE47hbLilwIKAADzwlwTyo= X-Google-Smtp-Source: AGHT+IFOBybHuents0oOXDPA5tCz5I324tpOomQ11JBzSRe37TP5mxsbbu9bxiokep1nm7ZSuTxGPg== X-Received: by 2002:a05:600c:4e90:b0:426:6326:4cec with SMTP id 5b1f17b1804b1-427c2ce8d0emr35264935e9.29.1721309682223; Thu, 18 Jul 2024 06:34:42 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Bibo Mao , qemu-devel@nongnu.org, Jiaxun Yang Cc: Song Gao , Paolo Bonzini , Huacai Chen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiaojuan Yang , Xianglai Li Subject: [PATCH v5 15/19] hw/intc/loongarch_ipi: Add loongarch IPI support Date: Thu, 18 Jul 2024 15:33:07 +0200 Message-ID: <20240718133312.10324-16-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240718133312.10324-1-philmd@linaro.org> References: <20240718133312.10324-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=philmd@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1721309791956116300 From: Bibo Mao Loongarch IPI is added here, it inherits from class TYPE_LOONGSON_IPI_COMMON, and two interfaces get_iocsr_as() and cpu_by_arch_id() are added for Loongarch 3A5000 machine. It can be used when ipi is emulated in userspace with KVM mode. Signed-off-by: Bibo Mao [PMD: Rebased and simplified] Co-Developed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bibo Mao Tested-by: Bibo Mao Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Song Gao --- include/hw/intc/loongarch_ipi.h | 25 ++++++++++++ hw/intc/loongarch_ipi.c | 68 +++++++++++++++++++++++++++++++++ hw/intc/Kconfig | 4 ++ hw/intc/meson.build | 1 + 4 files changed, 98 insertions(+) create mode 100644 include/hw/intc/loongarch_ipi.h create mode 100644 hw/intc/loongarch_ipi.c diff --git a/include/hw/intc/loongarch_ipi.h b/include/hw/intc/loongarch_ip= i.h new file mode 100644 index 0000000000..276b3040a3 --- /dev/null +++ b/include/hw/intc/loongarch_ipi.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * LoongArch IPI interrupt header files + * + * Copyright (C) 2024 Loongson Technology Corporation Limited + */ + +#ifndef HW_LOONGARCH_IPI_H +#define HW_LOONGARCH_IPI_H + +#include "qom/object.h" +#include "hw/intc/loongson_ipi_common.h" + +#define TYPE_LOONGARCH_IPI "loongarch_ipi" +OBJECT_DECLARE_TYPE(LoongarchIPIState, LoongarchIPIClass, LOONGARCH_IPI) + +struct LoongarchIPIState { + LoongsonIPICommonState parent_obj; +}; + +struct LoongarchIPIClass { + LoongsonIPICommonClass parent_class; +}; + +#endif diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c new file mode 100644 index 0000000000..2ae1a42c46 --- /dev/null +++ b/hw/intc/loongarch_ipi.c @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * LoongArch IPI interrupt support + * + * Copyright (C) 2024 Loongson Technology Corporation Limited + */ + +#include "qemu/osdep.h" +#include "hw/boards.h" +#include "hw/intc/loongarch_ipi.h" +#include "target/loongarch/cpu.h" + +static AddressSpace *get_iocsr_as(CPUState *cpu) +{ + return LOONGARCH_CPU(cpu)->env.address_space_iocsr; +} + +static int archid_cmp(const void *a, const void *b) +{ + CPUArchId *archid_a =3D (CPUArchId *)a; + CPUArchId *archid_b =3D (CPUArchId *)b; + + return archid_a->arch_id - archid_b->arch_id; +} + +static CPUArchId *find_cpu_by_archid(MachineState *ms, uint32_t id) +{ + CPUArchId apic_id, *found_cpu; + + apic_id.arch_id =3D id; + found_cpu =3D bsearch(&apic_id, ms->possible_cpus->cpus, + ms->possible_cpus->len, + sizeof(*ms->possible_cpus->cpus), + archid_cmp); + + return found_cpu; +} + +static CPUState *loongarch_cpu_by_arch_id(int64_t arch_id) +{ + MachineState *machine =3D MACHINE(qdev_get_machine()); + CPUArchId *archid; + + archid =3D find_cpu_by_archid(machine, arch_id); + if (archid) { + return CPU(archid->cpu); + } + + return NULL; +} + +static void loongarch_ipi_class_init(ObjectClass *klass, void *data) +{ + LoongsonIPICommonClass *licc =3D LOONGSON_IPI_COMMON_CLASS(klass); + + licc->get_iocsr_as =3D get_iocsr_as; + licc->cpu_by_arch_id =3D loongarch_cpu_by_arch_id; +} + +static const TypeInfo loongarch_ipi_types[] =3D { + { + .name =3D TYPE_LOONGARCH_IPI, + .parent =3D TYPE_LOONGSON_IPI_COMMON, + .class_init =3D loongarch_ipi_class_init, + } +}; + +DEFINE_TYPES(loongarch_ipi_types) diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig index a2a0fdca85..dd405bdb5d 100644 --- a/hw/intc/Kconfig +++ b/hw/intc/Kconfig @@ -94,6 +94,10 @@ config LOONGSON_IPI bool select LOONGSON_IPI_COMMON =20 +config LOONGARCH_IPI + bool + select LOONGSON_IPI_COMMON + config LOONGARCH_PCH_PIC bool select UNIMP diff --git a/hw/intc/meson.build b/hw/intc/meson.build index a09a527207..f4d81eb8e4 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -71,6 +71,7 @@ specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XIVE'], specific_ss.add(when: 'CONFIG_M68K_IRQC', if_true: files('m68k_irqc.c')) specific_ss.add(when: 'CONFIG_LOONGSON_IPI_COMMON', if_true: files('loongs= on_ipi_common.c')) specific_ss.add(when: 'CONFIG_LOONGSON_IPI', if_true: files('loongson_ipi.= c')) +specific_ss.add(when: 'CONFIG_LOONGARCH_IPI', if_true: files('loongarch_ip= i.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarc= h_pch_pic.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_MSI', if_true: files('loongarc= h_pch_msi.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_EXTIOI', if_true: files('loongarch= _extioi.c')) --=20 2.41.0