From nobody Mon Dec 15 16:23:33 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=1747843472; cv=none; d=zohomail.com; s=zohoarc; b=nGhH+ejFrrxvmU87whQCDOaK3x2UG2MCbwkHoY/SyFGhepk9bqhesQeTK19eYXJxRSqTiqRTbftlXcEPzsjAto95+Wa9L7Vrs6ccmrq5bC7IDineTRuyiojAGqmq9LDBPnKepYZaildFKLnMiHDajR0mFfYu+R294bO+TVHJJs4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747843472; 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=MuKFAgwAzdWX+jRW22HkNFtK9R6Dh6rQ/ItEXnnpjQ4=; b=Qv3salLTYqOfECEOlaf0eGyZT2xeK1UzuQ1LQFZYhrNC4fREyl7V+oxAumWsy/nkHnqUfRO1RazfogIRXiHlR4t7HKPw+VvR7TEl9iPtAK/OsUe9hS/O633BbWaZavNJ85L9mOUmLRI2JLKAIBM2S2pq8pEYSL7nrc1pzEE4uIo= 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 1747843472348663.6296786817024; Wed, 21 May 2025 09:04:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.992142.1375965 (Exim 4.92) (envelope-from ) id 1uHlvL-0005gq-Ai; Wed, 21 May 2025 16:04:07 +0000 Received: by outflank-mailman (output) from mailman id 992142.1375965; Wed, 21 May 2025 16:04:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uHlvL-0005fo-7A; Wed, 21 May 2025 16:04:07 +0000 Received: by outflank-mailman (input) for mailman id 992142; Wed, 21 May 2025 16:04:05 +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 1uHlvJ-0004XB-LD for xen-devel@lists.xenproject.org; Wed, 21 May 2025 16:04:05 +0000 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [2a00:1450:4864:20::532]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 38205288-365d-11f0-a2fa-13f23c93f187; Wed, 21 May 2025 18:04:05 +0200 (CEST) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-601956fa3beso7489696a12.0 for ; Wed, 21 May 2025 09:04:05 -0700 (PDT) Received: from fedora.. (user-109-243-64-38.play-internet.pl. [109.243.64.38]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6004d502736sm9152513a12.25.2025.05.21.09.04.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 May 2025 09:04:03 -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: 38205288-365d-11f0-a2fa-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747843444; x=1748448244; 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=MuKFAgwAzdWX+jRW22HkNFtK9R6Dh6rQ/ItEXnnpjQ4=; b=WSoFoG0V5iWtBFxt1xF0zUVz9exvvJ7jtpoJ0/Y+ZjxvjQkaC2fNYdcSJvXZiqJY3I LOyQ8yzCNGt/AHOHkqNu5csmTy6Jq65ooDMhsxTXn0AJ0m9Hej7nmRfigIcMrjm8nwKJ 0ACh0u+wReNAU/OESz96NZnRLfRmrYjcA0rnsQijn45xz+Xb5/0XNUks5brZaLMVNvhz l83LTYsB8eaoow4vtQ3PbT5C/jmI9IobjMdA0r7TwIAH99a8rcNRR3WVyEGRYOw7a4U6 WBFp/f1i0zRAJoFhBFvZIjQzyp6a9Q1wNG8cn19BsMaZy6IpggJh6GKH+p71Pahteabr oLUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747843444; x=1748448244; 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=MuKFAgwAzdWX+jRW22HkNFtK9R6Dh6rQ/ItEXnnpjQ4=; b=MWPmBpDt2vwVj+qnJ4gp1/r6DTGVU/NRQClQADFn1biMUdq3dU/BlUmcRv+K/wQvg8 Hi4KJnuEzAsuGVmD3QJlz5UCJtpeFzTuT/Z29sFSAos+9S/WWX6MzrSs8axzcBwEyfBr RQRBig1OGXDTUVuQfqEQgK74HNUyJaTJb6oT8gGd8/6XWk3Q+597vbJnaZC5BZI9VIYP x1Jty5UkEytvRnESWgp+w58tmAuXQ/LL7YuePj/A4S6VZcyGI2N2BkCjuWGIPA7qVNVp Yt+ri+Vg1Xsr+5bmmBLEcDCFY5sfvanAUQO0GLdsp1Iq/fNLlNb52NEaxN5i0+sTGca6 PueA== X-Gm-Message-State: AOJu0Yz9zKtvjMZMi6yAjTModplXdQLkRYWwdCe81nSawG4nlHRjWnjC st0sAPsAqANp/60PwRX7uhJ/MTEqOOKZa0al9Z/QNlf8ChDyTp0m5cF8SLrsaQ== X-Gm-Gg: ASbGncvdA3dm1Exi/IBGSjXEuWV0aijcfm1yqb913uRM7fZtqHSiKhv3sVu9Z5V+50A CgQp+U8quvidtLJl9e8wXffbB+OBDFc0Aa+yMIIXDaasEN3uBtTVr7BSwuzPCxRRCbqFH0lXqqN JyV72ljloV7b2w3ZaNN1jEPgaH3SU9fM5I6caA49p1EGkMSIgyhOe+zTms70KOHXTjzDtHW3ltz a0P9s13Yok96Opggg3JpympksLNJhhT/2sW4z++3R4ARJDTfzpHt+YMvSCe0aG3fguKVVQC52se i5W7DdI7l5PcKAe4z8P21Rop3myfZe8pBVL+OfpuXl+X0tIv7E7R/u0JleY35InHhRFUftdUEaz ejdlxXq40kZ/KqxHaaw== X-Google-Smtp-Source: AGHT+IHMiUE1RNqkd7CFA0gkM4DTS7mv6rwNoXKENbduXzPAJdFGKEhEHzlWMu7Blf5NHSFiWG9jtg== X-Received: by 2002:aa7:d28a:0:b0:601:31e6:697f with SMTP id 4fb4d7f45d1cf-60131e66b16mr14765902a12.26.1747843444003; Wed, 21 May 2025 09:04:04 -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 v3 05/14] xen/riscv: introduce platform_get_irq() Date: Wed, 21 May 2025 18:03:45 +0200 Message-ID: <1729279a0ab39e2a2f09e475c2eb48fefd4aef54.1747843009.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: 1747843473403116600 Content-Type: text/plain; charset="utf-8" platform_get_irq() recieves information about device's irq ( type and irq number ) from device tree node and using this information update irq descriptor in irq_desc[] array. Introduce dt_irq_xlate and initialize with aplic_irq_xlate() as it is used by dt_device_get_irq() which is called by platform_get_irq(). Co-developed-by: Romain Caritey Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in V3: - Drop parentheses in return inside irq_validate_new_type(). - Add a check in platform_get_irq() that dt_irq.irq is less then NR_IRQS. Also, add BUILD_BUG_ON(NR_IRQS > INT_MAX). --- Changes in V2: - Add cf_check for aplic_irq_xlate(). - Ident label in irq_set_type(). - Return proper -E... values for platform_get_irq(). --- xen/arch/riscv/aplic.c | 20 ++++++++++++++ xen/arch/riscv/include/asm/irq.h | 3 ++ xen/arch/riscv/irq.c | 47 ++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/xen/arch/riscv/aplic.c b/xen/arch/riscv/aplic.c index caba8f8993..10ae81f7ac 100644 --- a/xen/arch/riscv/aplic.c +++ b/xen/arch/riscv/aplic.c @@ -11,6 +11,7 @@ =20 #include #include +#include #include #include =20 @@ -21,6 +22,23 @@ static struct intc_info __ro_after_init aplic_info =3D { .hw_version =3D INTC_APLIC, }; =20 +static int cf_check aplic_irq_xlate(const uint32_t *intspec, + unsigned int intsize, + unsigned int *out_hwirq, + unsigned int *out_type) +{ + if ( intsize < 2 ) + return -EINVAL; + + /* Mapping 1:1 */ + *out_hwirq =3D intspec[0]; + + if ( out_type ) + *out_type =3D intspec[1] & IRQ_TYPE_SENSE_MASK; + + return 0; +} + static int __init aplic_preinit(struct dt_device_node *node, const void *d= at) { if ( aplic_info.node ) @@ -35,6 +53,8 @@ static int __init aplic_preinit(struct dt_device_node *no= de, const void *dat) =20 aplic_info.node =3D node; =20 + dt_irq_xlate =3D aplic_irq_xlate; + return 0; } =20 diff --git a/xen/arch/riscv/include/asm/irq.h b/xen/arch/riscv/include/asm/= irq.h index ea555afd1a..84c3c2904d 100644 --- a/xen/arch/riscv/include/asm/irq.h +++ b/xen/arch/riscv/include/asm/irq.h @@ -38,6 +38,9 @@ static inline void arch_move_irqs(struct vcpu *v) BUG_ON("unimplemented"); } =20 +struct dt_device_node; +int platform_get_irq(const struct dt_device_node *device, int index); + void init_IRQ(void); =20 #endif /* ASM__RISCV__IRQ_H */ diff --git a/xen/arch/riscv/irq.c b/xen/arch/riscv/irq.c index b5ae7a114b..669ef3ae9e 100644 --- a/xen/arch/riscv/irq.c +++ b/xen/arch/riscv/irq.c @@ -7,11 +7,58 @@ */ =20 #include +#include +#include #include #include =20 static irq_desc_t irq_desc[NR_IRQS]; =20 +static bool irq_validate_new_type(unsigned int curr, unsigned int new) +{ + return curr =3D=3D IRQ_TYPE_INVALID || curr =3D=3D new; +} + +static int irq_set_type(unsigned int irq, unsigned int type) +{ + unsigned long flags; + struct irq_desc *desc =3D irq_to_desc(irq); + int ret =3D -EBUSY; + + spin_lock_irqsave(&desc->lock, flags); + + if ( !irq_validate_new_type(desc->arch.type, type) ) + goto err; + + desc->arch.type =3D type; + + ret =3D 0; + + err: + spin_unlock_irqrestore(&desc->lock, flags); + + return ret; +} + +int platform_get_irq(const struct dt_device_node *device, int index) +{ + struct dt_irq dt_irq; + int ret; + + if ( (ret =3D dt_device_get_irq(device, index, &dt_irq)) !=3D 0 ) + return ret; + + BUILD_BUG_ON(NR_IRQS > INT_MAX); + + if ( dt_irq.irq >=3D NR_IRQS ) + panic("irq%d is bigger then NR_IRQS(%d)\n", dt_irq.irq, NR_IRQS); + + if ( (ret =3D irq_set_type(dt_irq.irq, dt_irq.type)) !=3D 0 ) + return ret; + + return dt_irq.irq; +} + int arch_init_one_irq_desc(struct irq_desc *desc) { desc->arch.type =3D IRQ_TYPE_INVALID; --=20 2.49.0