From nobody Mon Dec 15 21:31:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1749829765; cv=none; d=zohomail.com; s=zohoarc; b=i7VT3j6Y8MhDLGFS2K3YCFUmktzXFKf2IJme3NvMMhlODBlrPRjVyq6Md2ecgPz/Bmm3SGK1o0/uKT91OThOUNS6cg6MjnLkbUsNakCrJUsmaXWEO9do+kImF9sCktPpS4QewUbpPHhm1iQqqq/arIMevz0gYU7dotXbM9dpntI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749829765; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kWLYSodiRsm7mDCKtezKwf+cxQyrLPn4QIQNMit6hRc=; b=RAC7he/P0vZeOGsJn56zkJjmkoEQegmvkNIhe7lH9rTf5g0464xCU6jHILq0U/1uUDm3T3ZWzDUB8nk3k8wLfmAazZtmD7cvZPrH4MVOOO+7JXGYRAlVSAsSIgsO6HaNPhjxbUpW+RmaG8N1S5s2z6cp+0VTnmX+Gs7oQCMQ+nA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1749829765377488.26545978839783; Fri, 13 Jun 2025 08:49:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1014630.1392775 (Exim 4.92) (envelope-from ) id 1uQ6eO-0007xI-Un; Fri, 13 Jun 2025 15:49:04 +0000 Received: by outflank-mailman (output) from mailman id 1014630.1392775; Fri, 13 Jun 2025 15:49:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uQ6eO-0007wc-MR; Fri, 13 Jun 2025 15:49:04 +0000 Received: by outflank-mailman (input) for mailman id 1014630; Fri, 13 Jun 2025 15:49:03 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uQ6eN-0006ch-C6 for xen-devel@lists.xenproject.org; Fri, 13 Jun 2025 15:49:03 +0000 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [2a00:1450:4864:20::629]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id edc1ef0b-486d-11f0-a309-13f23c93f187; Fri, 13 Jun 2025 17:49:02 +0200 (CEST) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-ade48b24c97so337151766b.2 for ; Fri, 13 Jun 2025 08:49:02 -0700 (PDT) Received: from fedora.. (user-109-243-64-38.play-internet.pl. [109.243.64.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-adec8979563sm144821766b.158.2025.06.13.08.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 08:49:01 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: edc1ef0b-486d-11f0-a309-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749829742; x=1750434542; darn=lists.xenproject.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=kWLYSodiRsm7mDCKtezKwf+cxQyrLPn4QIQNMit6hRc=; b=boWo+MNP694kc4ZoJOqP0h//3WtVFQtD7ESqIvtJqnAzmWh6F8YfybhtzQ9i2o97g5 ZxXXdErgHLLcGh1hiz3RE4+viKi6q5/pyicS3HMFJXFGje9xsWKzVay8HWm+G9kCX0TV TxB/dNV6xGfxsH7I6fkMmIQgf1CFeFnfjcewkRQmILFozDmgbctBXPJsdg9FBwVjciGy hmc1BQvSnQJLPoofYLAKF+gkbuIPs//LXFBZelcHZrGQ670WDZYptNC/sLEP75W3qfnh ccCviLzD82qDoAkyjLOfAxF/+zXv67hRWby4COhC3ykx8xSmRhwS93KeACJnEBrVdi1W xlIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749829742; x=1750434542; 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=kWLYSodiRsm7mDCKtezKwf+cxQyrLPn4QIQNMit6hRc=; b=NtjstrOUYmsRy2jsxlPXjOeC4WuC0WqHuWCsf2iAz/IdXt4xLSpfPvHDJYb1YqDOOs MsMURIZ+w1RseCFl2gK9wpcpDfHT360Zn12slbJD46/srnhhU0xlSd54esNCNZp239We a1/6uEJgwxnCvbjVDsw9nCRJHHNBGXix8RoDzqiHBwa3qHJMuVf8Ql8sAg6TunIfZqxs tWrxZASp7K6kbeudcWkTX6ex2VHeBVf0z+MiNJhZgQLSB2dZSy+d8jp4OF5ubmFoeIT4 3MvAFxjcZqoR8P+W9UZKc+q5HjPlcB1751C4ijqZX0ZApIE+eGOGSbZlCRy5aBh8DFK1 yPIw== X-Gm-Message-State: AOJu0YxKojEpJJhfvKrjAhhXkPts6S/Z4HxE02cE6tpJ5Zj4v+xAWENW 6ifMTdp3paWG232EH1crYeFd91T1XdhuLkwINdiIJ+3KzXg4YgoK2lEZ/c0wRw== X-Gm-Gg: ASbGncspQTgHatMw3CwGDQhUtZiz/6JHU/AgIHgsm9x8zWsZrGEMYlOoMD0yZXzLhHT KVi9E90na5RzTjLQG6C67wYInHLlim2ej1AqFqa7TdfrrZ5kfBHjAnrT9Ag4NyvY2ydN6yNw/SE X5LfA6JHmBAS+9PAq/GqNAwJSuxPrzi4hWix3dlVR8fuFWlmWbLwxODPr3fFjwDNOM7CfnQXc9u CqUbc5+CZJ51UrFGjoT4dZEK0ZtapBIfboX+i0yFaiyqvKtgNg8rkfoOBWpP8pyYJxdO9vh5lkW xwHQTGAlVEzMz+3b0FOUHtNKMOYl0UbT8k4ksTy0+WpNAuDAzZ/oFoDZkYGOmM7AAShNHcViDIJ AaNmRk3XFm6gs+Tp9hzNDuNzObQwW X-Google-Smtp-Source: AGHT+IFwuzRAO2aMwCpzgznPpw9bLv4IXoL0CdMKxiA7lbCL/uvyHdV1Z4CzCzATm/7hUMWYyh0qBA== X-Received: by 2002:a17:907:2d08:b0:ade:9e62:5fa8 with SMTP id a640c23a62f3a-adec56ad7c9mr349658966b.30.1749829741790; Fri, 13 Jun 2025 08:49:01 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Romain Caritey Subject: [PATCH v5 5/9] xen/riscv: introduce intc_init() and helpers Date: Fri, 13 Jun 2025 17:48:44 +0200 Message-ID: <90dea26b25c0934697885da2703842106b6aebaa.1749825782.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1749829767512116600 Content-Type: text/plain; charset="utf-8" Introduce intc_init() to initialize the interrupt controller using the registered hardware ops. Also add intc_route_irq_to_xen() to route IRQs to Xen, with support for setting IRQ type and priority via new internal helpers intc_set_irq_type() and intc_set_irq_priority(). Call intc_init() to do basic initialization steps for APLIC and IMSIC. Co-developed-by: Romain Caritey Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in V5: - Nothing changed. Only rebase. --- Changes in V4: - Add Acked-by: Jan Beulich . --- Changes in V3: - Drop ASSERIT(intc_hw_ops) in intc_init(). - Drop ASSERT(intc_hw_ops) in intc_set_irq_type() and intc_set_irq_priority() as intc_init() will be called first and so if it won't crash, then intc_hw_ops is registered. --- Changes in V2: - This patch was part of "xen/riscv: Introduce intc_hw_operations abstract= ion" and splitted to have ability to merge patch "xen/riscv: initialize inter= rupt controller" to the current patch (where intc_init() call is actually introduced). - Add checks of that callbacks aren't set to NULL in intc_set_irq_priority= () and intc_set_irq_type(). - add num_irqs member to struct intc_info as it is used now in intc_route_irq_to_xen(). - Add ASSERT(spin_is_locked(&desc->lock)) to intc_set_irq_priority() in the case this function will be called outside intc_route_irq_to_xen(). --- xen/arch/riscv/include/asm/intc.h | 4 +++ xen/arch/riscv/intc.c | 41 +++++++++++++++++++++++++++++++ xen/arch/riscv/setup.c | 2 ++ 3 files changed, 47 insertions(+) diff --git a/xen/arch/riscv/include/asm/intc.h b/xen/arch/riscv/include/asm= /intc.h index 3c4b211f58..a11b7aa55e 100644 --- a/xen/arch/riscv/include/asm/intc.h +++ b/xen/arch/riscv/include/asm/intc.h @@ -43,4 +43,8 @@ void intc_preinit(void); =20 void register_intc_ops(const struct intc_hw_operations *ops); =20 +void intc_init(void); + +void intc_route_irq_to_xen(struct irq_desc *desc, unsigned int priority); + #endif /* ASM__RISCV__INTERRUPT_CONTOLLER_H */ diff --git a/xen/arch/riscv/intc.c b/xen/arch/riscv/intc.c index 1ecd651bf3..f2823267a9 100644 --- a/xen/arch/riscv/intc.c +++ b/xen/arch/riscv/intc.c @@ -1,9 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 #include +#include #include #include +#include #include +#include =20 #include =20 @@ -21,3 +24,41 @@ void __init intc_preinit(void) else panic("ACPI interrupt controller preinit() isn't implemented\n"); } + +void __init intc_init(void) +{ + if ( intc_hw_ops->init() ) + panic("Failed to initialize the interrupt controller drivers\n"); +} + +/* desc->irq needs to be disabled before calling this function */ +static void intc_set_irq_type(struct irq_desc *desc, unsigned int type) +{ + ASSERT(desc->status & IRQ_DISABLED); + ASSERT(spin_is_locked(&desc->lock)); + ASSERT(type !=3D IRQ_TYPE_INVALID); + + if ( intc_hw_ops->set_irq_type ) + intc_hw_ops->set_irq_type(desc, type); +} + +static void intc_set_irq_priority(struct irq_desc *desc, unsigned int prio= rity) +{ + ASSERT(spin_is_locked(&desc->lock)); + + if ( intc_hw_ops->set_irq_priority ) + intc_hw_ops->set_irq_priority(desc, priority); +} + +void intc_route_irq_to_xen(struct irq_desc *desc, unsigned int priority) +{ + ASSERT(desc->status & IRQ_DISABLED); + ASSERT(spin_is_locked(&desc->lock)); + /* Can't route interrupts that don't exist */ + ASSERT(intc_hw_ops && desc->irq < intc_hw_ops->info->num_irqs); + + desc->handler =3D intc_hw_ops->host_irq_type; + + intc_set_irq_type(desc, desc->arch.type); + intc_set_irq_priority(desc, priority); +} diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 8bcd19218d..0e7398159c 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -134,6 +134,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, =20 intc_preinit(); =20 + intc_init(); + printk("All set up\n"); =20 machine_halt(); --=20 2.49.0