From patchwork Tue Aug 6 12:51:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 817036 Delivered-To: patch@linaro.org Received: by 2002:adf:e00d:0:b0:367:895a:4699 with SMTP id s13csp1782702wrh; Tue, 6 Aug 2024 05:53:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWKGZoYDd5U06BglqrhHtp9rBPzcvNPPde54B6jsy5vBNPQMq6+ajBbG2NBPqZaIFraUV8gaok0sfnDJiyoUMGE X-Google-Smtp-Source: AGHT+IFRVGktpu4MTIgVUATEarKWUwAKb4ascyozIVa/MZ2T/pZD29mkp5W+M9/FwBnx635s5tpg X-Received: by 2002:a05:6358:c607:b0:1ac:f854:b68 with SMTP id e5c5f4694b2df-1af3bb8ccd4mr1541180255d.29.1722948815595; Tue, 06 Aug 2024 05:53:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722948815; cv=none; d=google.com; s=arc-20160816; b=D/lovLraiZDQAuUlhdCxj7+czgAQjsEZBjOorfEh/p33fB/Qb3HSxC8fMr8iJhrYOb Hohoxhq6jLemsSpIX0HdUS5CAzhfk37tiTIhjEcrG6IycNb4lTlw5Qv0hAziJQ2u4/kz V9OMBZNSKA/Q7ZpWMVb+NATioOCQwaICYotvCbr2ulcB2rb+l5JlfD75pe3dWI/nawts qzDrMpkeG0k9ZowCJNR63H8v0XsfDcEj0jZbQ8W6cv3C9gFLv9X2PjafxoyXnfT3sPYh WNJPLkUTU7vxlMXo1tQ0mB1+ojqb4uZdv3XMKWLbkkHkqoLVNgX3IBfJEbWVlmOhKLpD ab2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=U580Wrx23+PhRsFUSNYJ7VRxWznSc+VPsbnAWBKD3bQ=; fh=rxGWTSOrq9MmYE4+hMcV/u38d68oc92wX5eFok0A+84=; b=AZf4gghKqm4TyvKXSG5nU+ET+I4Kz3DKiLCcC4u/cX1TXBpkYS2xMlZBiLSS7hsKyH yQ0h74q8Km5Wt1IVbJzdAz7r4/zvSyd+5ZRXU4q9BdJDpQdu96K86jQawbYKJK6kDhOL QYhCNoayQ+BTIIUUqp65mBFKbgnOKfwp5cztBpTUn2oAZW5C0Xa33gSS6XtAM1hbL75I S2sLY615DYmhrkfdA3K3t5Bn4iSwR+meEX5GIYyEa8HKOC3doQGrTfX4wAjorSBFGlfB ppIoChnng9+xMKdOb0P/E2PzyJFDKPoGmH5cGDdj1W+++5TQl2iLuQcPBs96UCITEg41 WI9A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="sDqRb/Rb"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6bb9c86f254si116830446d6.327.2024.08.06.05.53.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Aug 2024 05:53:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="sDqRb/Rb"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sbJgt-0002Dd-TO; Tue, 06 Aug 2024 08:53:27 -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 1sbJgm-0001QQ-N6 for qemu-devel@nongnu.org; Tue, 06 Aug 2024 08:53:23 -0400 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sbJgk-00004q-DM for qemu-devel@nongnu.org; Tue, 06 Aug 2024 08:53:20 -0400 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-52fc4388a64so755589e87.1 for ; Tue, 06 Aug 2024 05:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722948796; x=1723553596; 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=U580Wrx23+PhRsFUSNYJ7VRxWznSc+VPsbnAWBKD3bQ=; b=sDqRb/RbBX0jVhU208EUXKra82bsALAL6DeXOUAFDWNxuFsF02JR6Ys9g5DGSgDUu4 uDE5ZADoiJ/LJUH38wVHQiRiHcH1s/6hnqmTaSwlUyrEFAE/YbHSnCl3smBDDvQFbbab mDYpYl0iroYvywYFzaKMiBmOXicTnsNwac39haFHBcCRGS24c0M43OdcQMWPHikxY9K8 b46ZavsqnVYuGiiWMrcS3jen6wSUMB7MCYj9ukSj0RRVA001mIBolZLjTMaZut26wgCC xG8d9nPsMNKDw4xvR4/FxxSuhYMqX4Pswoy7F+KslvHUlrEvoAgA5hF1VNERUtIe6Y46 UDjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722948796; x=1723553596; 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=U580Wrx23+PhRsFUSNYJ7VRxWznSc+VPsbnAWBKD3bQ=; b=DqBny5W78Y9Hb02rctLYXkcYtIq/NCFvqvyLI/NDo9A0umdXwrKYYQd6i135gHjwpE RA0T+CxQf8JpskJ3o7qYythtQVwbEKnX9d3XqTcXK33BVY0X0FL2n8mCppzBhP8QNi+h Dc8/EapvA4IZW3KcUbZj8dJP3i7Ra0ANA1+sBVP4G/pzTNyMMOfhUceAXTITrp0CtOAk YGhoY0V9yhyqyKYjxs2R6DD91IXLEkUkqTvtfOqyv3bgEoyjpKlT1fVMqvtOZCdEKL3W YlB5wzqnkkeSUG1d6Z86rQqC5Xl664KbGNkrTpse9MjZ+WIySW5U/ZY3b8nwYoDYSYT3 eGCQ== X-Gm-Message-State: AOJu0YxX+8YrWpj9+JJWMUs3N7SFKO7f4s9UcbZMSIxyrImefeFh7ljy hcmS9pAkJspwBs17c16J6LZQGNcEbcexC+eC9lkdBt41m5gijpzYDDRDQxfjLDvgOU4MC/yIjOv I X-Received: by 2002:a05:6512:3b8b:b0:530:ae0d:9fc8 with SMTP id 2adb3069b0e04-530bb36b6bcmr11186553e87.2.1722948795857; Tue, 06 Aug 2024 05:53:15 -0700 (PDT) Received: from m1x-phil.lan (cor91-h02-176-184-30-206.dsl.sta.abo.bbox.fr. [176.184.30.206]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9d433fesm553882366b.142.2024.08.06.05.53.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 06 Aug 2024 05:53:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bibo Mao , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Song Gao , Richard Henderson , Jiaxun Yang Subject: [PULL 12/28] hw/intc/loongarch_ipi: Add loongarch IPI support Date: Tue, 6 Aug 2024 14:51:40 +0200 Message-ID: <20240806125157.91185-13-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240806125157.91185-1-philmd@linaro.org> References: <20240806125157.91185-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::135; envelope-from=philmd@linaro.org; helo=mail-lf1-x135.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é Reviewed-by: Bibo Mao Tested-by: Bibo Mao Signed-off-by: Philippe Mathieu-Daudé Acked-by: Song Gao Reviewed-by: Richard Henderson Reviewed-by: Jiaxun Yang Tested-by: Jiaxun Yang Message-Id: <20240805180622.21001-13-philmd@linaro.org> --- 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_ipi.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 = (CPUArchId *)a; + CPUArchId *archid_b = (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 = id; + found_cpu = 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 = MACHINE(qdev_get_machine()); + CPUArchId *archid; + + archid = 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 = LOONGSON_IPI_COMMON_CLASS(klass); + + licc->get_iocsr_as = get_iocsr_as; + licc->cpu_by_arch_id = loongarch_cpu_by_arch_id; +} + +static const TypeInfo loongarch_ipi_types[] = { + { + .name = TYPE_LOONGARCH_IPI, + .parent = TYPE_LOONGSON_IPI_COMMON, + .class_init = 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 +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('loongson_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_ipi.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarch_pch_pic.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_MSI', if_true: files('loongarch_pch_msi.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_EXTIOI', if_true: files('loongarch_extioi.c'))