From patchwork Thu Aug 3 17:58:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 709671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 479D2C001DF for ; Thu, 3 Aug 2023 17:59:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235289AbjHCR7w (ORCPT ); Thu, 3 Aug 2023 13:59:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235242AbjHCR7p (ORCPT ); Thu, 3 Aug 2023 13:59:45 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4470F30EF for ; Thu, 3 Aug 2023 10:59:42 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-68336d06620so1100290b3a.1 for ; Thu, 03 Aug 2023 10:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085582; x=1691690382; 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=UFiDx4yUD9M5LLDSVyQwmi0hMurmb+i35a+0GaoSwmM=; b=gzSCFSr/G3waueuE9A6zvWLt6I+my76zCgzC+Cixi6x1rcZmEeUXOSYMURhNyw6A6r J49EhGgoE3rXRkx6/8YpidVkV0MDlLQRzHN5khGbW0Z6Le7dX36yRwInwPOpY3NUol9K VFZda8kXmQd0g/+Bcy87pAQkGHttASe2PqLvfoe/rAFLFu56gnJi/ypQPQH0DfBUZLvh rumXtVJlEMOPyX69tNEq170gumWAvTBB487kSAKUPQbVWxjTEwxI1l6eSwdWgp1IXmU2 EXNHu9wR+N4ak1DbuoMVvmyGwft7HubO+CSmircw3jRVDj5DBYF+Ylw9aBGU2GW71/6K aTug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085582; x=1691690382; 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=UFiDx4yUD9M5LLDSVyQwmi0hMurmb+i35a+0GaoSwmM=; b=Z91aJaeKKovHFAR1FaeSKkATlNy8QgCPia92P2PaWGzTjGi9fh8cLG4JYf0YsizzQ5 gqnF1ClcY/omrXUcUhnQzeijP55qGJdqO8LKzJB3q1a/297hk5sEs2/jkILDbqLAt2wB TXK/2c8gnBr3+6DOcqwN9G0v8aKEx2um1HbM+Ff14fkPS5G0pH7JjIgey1DHPcNSVZuR 2WtGCCnWtrGCcN8+7ia5Z6z6yrcklXQMC/wOZTE6+tau8/UBp9B66BULfESHbod/iUYP Z7JPlpyOttiLajPTBIdxJP6TWL1aSzvkfMEzFn7c/jhqnIcqw/Y6SK70rsEkoM+axMXN Uykg== X-Gm-Message-State: ABy/qLbbDYunh3rStokHeMoJQ5X6ncOeRY3GPcGzoEVbMeY2jOXSBStu 3tABzvu2buXF2pPsirwpbUpczA== X-Google-Smtp-Source: APBJJlEYFTsZLTq9I40pUpD7LIXiH3Cg29Qi6vfE5k5jpjtfQAYsVuB8uUL66kNJTqe85l1gopgFEA== X-Received: by 2002:a05:6a20:7d9c:b0:13e:82ae:483 with SMTP id v28-20020a056a207d9c00b0013e82ae0483mr11419977pzj.31.1691085581732; Thu, 03 Aug 2023 10:59:41 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.10.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 10:59:41 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L , "Rafael J . Wysocki" Subject: [RFC PATCH v1 01/21] ACPICA: MADT: Add RISC-V external interrupt controllers Date: Thu, 3 Aug 2023 23:28:56 +0530 Message-Id: <20230803175916.3174453-2-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org ACPICA commit 8c048cee4ea7b9ded8db3e1b3b9c14e21e084a2c This adds 3 different external interrupt controller definitions in MADT for RISC-V. 1) RISC-V PLIC is a platform interrupt controller for handling wired interrupt in a RISC-V systems. 2) RISC-V IMSIC is MSI interrupt controller to support MSI interrupts. 3) RISC-V APLIC has dual functionality. First it can act like PLIC and direct all wired interrupts to the CPU which doesn't have MSI controller. Second, when the CPU has MSI controller (IMSIC), it will act as a converter from wired interrupts to MSI. Update the existing RINTC structure also to support these external interrupt controllers. This codefirst ECR is approved by UEFI forum and will be part of next ACPI spec version. Link: https://github.com/acpica/acpica/commit/8c048cee Co-developed-by: Haibo Xu Signed-off-by: Haibo Xu Signed-off-by: Sunil V L Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- include/acpi/actbl2.h | 50 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index 0029336775a9..280ab4c7f77a 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -893,7 +893,10 @@ enum acpi_madt_type { ACPI_MADT_TYPE_BIO_PIC = 22, ACPI_MADT_TYPE_LPC_PIC = 23, ACPI_MADT_TYPE_RINTC = 24, - ACPI_MADT_TYPE_RESERVED = 25, /* 25 to 0x7F are reserved */ + ACPI_MADT_TYPE_IMSIC = 25, + ACPI_MADT_TYPE_APLIC = 26, + ACPI_MADT_TYPE_PLIC = 27, + ACPI_MADT_TYPE_RESERVED = 28, /* 28 to 0x7F are reserved */ ACPI_MADT_TYPE_OEM_RESERVED = 0x80 /* 0x80 to 0xFF are reserved for OEM use */ }; @@ -1261,6 +1264,9 @@ struct acpi_madt_rintc { u32 flags; u64 hart_id; u32 uid; /* ACPI processor UID */ + u32 ext_intc_id; /* External INTC Id */ + u64 imsic_addr; /* IMSIC base address */ + u32 imsic_size; /* IMSIC size */ }; /* Values for RISC-V INTC Version field above */ @@ -1271,6 +1277,48 @@ enum acpi_madt_rintc_version { ACPI_MADT_RINTC_VERSION_RESERVED = 2 /* 2 and greater are reserved */ }; +/* 25: RISC-V IMSIC */ +struct acpi_madt_imsic { + struct acpi_subtable_header header; + u8 version; + u8 reserved; + u32 flags; + u16 num_ids; + u16 num_guest_ids; + u8 guest_index_bits; + u8 hart_index_bits; + u8 group_index_bits; + u8 group_index_shift; +}; + +/* 26: RISC-V APLIC */ +struct acpi_madt_aplic { + struct acpi_subtable_header header; + u8 version; + u8 id; + u32 flags; + u8 hw_id[8]; + u16 num_idcs; + u16 num_sources; + u32 gsi_base; + u64 base_addr; + u32 size; +}; + +/* 27: RISC-V PLIC */ +struct acpi_madt_plic { + struct acpi_subtable_header header; + u8 version; + u8 id; + u8 hw_id[8]; + u16 num_irqs; + u16 max_prio; + u32 flags; + u32 size; + u64 base_addr; + u32 gsi_base; +}; + /* 80: OEM data */ struct acpi_madt_oem_data { From patchwork Thu Aug 3 17:58:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 710935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AADDCC41513 for ; Thu, 3 Aug 2023 18:00:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235269AbjHCSAJ (ORCPT ); Thu, 3 Aug 2023 14:00:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235282AbjHCSAC (ORCPT ); Thu, 3 Aug 2023 14:00:02 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57D044236 for ; Thu, 3 Aug 2023 10:59:50 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6874d1c8610so906221b3a.0 for ; Thu, 03 Aug 2023 10:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085589; x=1691690389; 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=uZnV0ewqSpbZRhAC/LQ4a5BRuhAMm0ngpEEdA3S7vUc=; b=bnUHrvcB3yN6JHMYj1LgPtgbaxVQ2/kWyipu/UeXRJ2tHBpusAvGqpA2JpZ8jeIH3g SyS215bD2yhR3UKyi9XvIbGviVfviNKGBhGo/Mk/B9uovNyjuY/6JKLvXsCys19DKBzy PK3XjqkewPWtoHp1j2jTNsCLUY34QkGN+CYnMoiiMFGecT18d+z52RAzbiSaOEmldABl hBbRGcvCyS2IdMb43pHQK5fXbIjZesRZXZl+zaNJ8ai+DEh2SCarIlkd0XwjKBowE4e7 pIqmYk0rHQaaJOnTsyBYVT8t+V9YHSEPUdcUxTvVigAA3BrS9RhiMJna4uMbinUca3Rm +79g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085589; x=1691690389; 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=uZnV0ewqSpbZRhAC/LQ4a5BRuhAMm0ngpEEdA3S7vUc=; b=QJHIF0b9u6FKsZvfbUSDjhO4B8T4CeBUgewgVGe9N9f8+8qmTO4HT4+zVUeekMZcCT CYTTXU8F3/YFTmZFSSnihJxSaQ3eFB+1IIXXCBYBmsVY3ud5w49p8DpDCUtjCpzl6t1F DqJq1bR30UTiUJWAd1GqFj6Kp1Xv0bmuu0HFxrbH428GzvHooT6BqYtqY7K2dLwskHpc /iNP5RAA7+zy/8Y+HhSNQnBtAt8CeTfpif/rr6Js9br0TNvJm6QZmdgUqt9knaCcpdYv 0S7OG+mcCm9PQmc5RYrZ1iwTbGI0Gtz6CEPzRxagTlphE+cqIx8IWMJUmGzraf1wQtn8 1Emw== X-Gm-Message-State: ABy/qLZv56rrw7Hto5dA8qg8EHi+ygRpdB94kpBhkYhYHVttrjtMtquF lFUaDTy13fdYgSEww/6Ut9jHevMLM4H6DjuZwSs= X-Google-Smtp-Source: APBJJlE1b+j2IWH4TbwV8C6fjO+Svt90/nwRmWf6oRPC//NYJR0B8gyqBDu4bXvcfIVaY5ldDXWYCg== X-Received: by 2002:aa7:88c3:0:b0:687:20d6:faea with SMTP id k3-20020aa788c3000000b0068720d6faeamr17580448pff.15.1691085589326; Thu, 03 Aug 2023 10:59:49 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.10.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 10:59:49 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L , "Rafael J . Wysocki" Subject: [RFC PATCH v1 02/21] ACPICA: RHCT: Add flags, CMO and MMU nodes Date: Thu, 3 Aug 2023 23:28:57 +0530 Message-Id: <20230803175916.3174453-3-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org ACPICA commit 2eded5a6a13d892b7dc3be6096e7b1e8d4407600 Update RHCT table with below details. 1) Add additional structure to describe the Cache Management Operation (CMO) related information. 2) Add structure to describe MMU type. 3) Convert the current reserved field to flags and define a flag to indicate timer capability. This codefirst ECR is approved by UEFI forum and will be part of next ACPI spec version. Link: https://github.com/acpica/acpica/commit/2eded5a6 Signed-off-by: Sunil V L Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- include/acpi/actbl2.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index 280ab4c7f77a..3751ae69432f 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -2778,12 +2778,15 @@ enum acpi_rgrt_image_type { struct acpi_table_rhct { struct acpi_table_header header; /* Common ACPI table header */ - u32 reserved; + u32 flags; /* RHCT flags */ u64 time_base_freq; u32 node_count; u32 node_offset; }; +/* RHCT Flags */ + +#define ACPI_RHCT_TIMER_CANNOT_WAKEUP_CPU (1) /* * RHCT subtables */ @@ -2797,6 +2800,9 @@ struct acpi_rhct_node_header { enum acpi_rhct_node_type { ACPI_RHCT_NODE_TYPE_ISA_STRING = 0x0000, + ACPI_RHCT_NODE_TYPE_CMO = 0x0001, + ACPI_RHCT_NODE_TYPE_MMU = 0x0002, + ACPI_RHCT_NODE_TYPE_RESERVED = 0x0003, ACPI_RHCT_NODE_TYPE_HART_INFO = 0xFFFF, }; @@ -2810,6 +2816,24 @@ struct acpi_rhct_isa_string { char isa[]; }; +struct acpi_rhct_cmo_node { + u8 reserved; /* Must be zero */ + u8 cbom_size; /* CBOM size in powerof 2 */ + u8 cbop_size; /* CBOP size in powerof 2 */ + u8 cboz_size; /* CBOZ size in powerof 2 */ +}; + +struct acpi_rhct_mmu_node { + u8 reserved; /* Must be zero */ + u8 mmu_type; /* Virtual Address Scheme */ +}; + +enum acpi_rhct_mmu_type { + ACPI_RHCT_MMU_TYPE_SV39 = 0, + ACPI_RHCT_MMU_TYPE_SV48 = 1, + ACPI_RHCT_MMU_TYPE_SV57 = 2 +}; + /* Hart Info node structure */ struct acpi_rhct_hart_info { u16 num_offsets; From patchwork Thu Aug 3 17:58:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 709670 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10758C001DF for ; Thu, 3 Aug 2023 18:00:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235429AbjHCSAX (ORCPT ); Thu, 3 Aug 2023 14:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233822AbjHCSAH (ORCPT ); Thu, 3 Aug 2023 14:00:07 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D90D44B2 for ; Thu, 3 Aug 2023 10:59:57 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686ed1d2594so1081545b3a.2 for ; Thu, 03 Aug 2023 10:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085597; x=1691690397; 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=dlgMxBU+gnbxavLK2CnXHLqjxrOHpsQhLJivrmp7gq8=; b=Mn/vo0MoTkPiEepTolmO07DSHUYqv7rFmArT6LTUsVmzAqnBvKBjkRZBvhSJTyiZAM 1h1+n6DkofxPjLLD7asRa2i/oE66f7GWtWQqA9+nDJYue6PrwjDM067chowzEAr4ODxH vSRhcalLZi64uzfoqGFqhxbjGjGGDhdaLNb94wU3+LcfSd6SGzYCkrAI2qx43QP8mXm+ DJ0Il1lN5U+uqlCxzJ+JnPkr+AJ87TQm7Mbi6Aqs2pV30Apw6vIAlJMrvnORHqksud91 revKW71DM8rTMoqvZp3Ftaus2TBe8ju/o/MzItnmUE5tDKZn5+PQ0RhtNd0uQFIakZk6 1UZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085597; x=1691690397; 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=dlgMxBU+gnbxavLK2CnXHLqjxrOHpsQhLJivrmp7gq8=; b=eMz2+Kca/hLkep8SpGl6sH1cM5Sz/jXIHrJk8CEcG1UOIU8BwEhSA0Q0R9fZOTJFn5 HhMYFKBBkrTc4uK/CVvuXAvw2Q2B9Usa7hQNtoHpI8I58o64o5ARPVXsjY4anNDy/qAv zMrLw9oq9k8rKdKYNAtHiZa/s/vs7OXMxqUalPzwfy6MPu98ERmxpPMObEse55xzW6rt r807J6WqE4ZTFmCiJnGN2z/bWgwphHc0ksv4aKbQ05l+nH5gzkupN0/0jt0+mRJdL0dP hJq8lhiCbFuwRKM3cKvzR9xDXWXHAEfcwbdcL7vC54l6516coalBSRLl2ExxKTmmToQh GeUg== X-Gm-Message-State: ABy/qLa5k4ja5hp3RADwVo2TWGQ5/TO2i3mui/aDOEP+oDhw7wDn0BCW h+8282XD1EX7SjlAa5DpXodz8A== X-Google-Smtp-Source: APBJJlHeLQhx5wJXxieN87kQ/FrrGdUXv58YAFTjJ6UeQQPmtQGf8bvG5vbiImqAXiXcjHGvc1bNlw== X-Received: by 2002:a05:6a00:c86:b0:682:4c9f:aa0 with SMTP id a6-20020a056a000c8600b006824c9f0aa0mr23559310pfv.29.1691085596954; Thu, 03 Aug 2023 10:59:56 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.10.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 10:59:56 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L , kernel test robot Subject: [RFC PATCH v1 03/21] RISC-V: ACPI: Fix acpi_os_ioremap to return iomem address Date: Thu, 3 Aug 2023 23:28:58 +0530 Message-Id: <20230803175916.3174453-4-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org acpi_os_ioremap() currently is a wrapper to memremap() on RISC-V. But the callers of acpi_os_ioremap() expect it to return __iomem address and hence sparse tool reports a new warning. Fix this issue by type casting to __iomem type. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202307230357.egcTAefj-lkp@intel.com/ Fixes: a91a9ffbd3a5 ("RISC-V: Add support to build the ACPI core") Signed-off-by: Sunil V L Reviewed-by: Andrew Jones --- arch/riscv/include/asm/acpi.h | 2 +- arch/riscv/kernel/acpi.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h index f71ce21ff684..d5604d2073bc 100644 --- a/arch/riscv/include/asm/acpi.h +++ b/arch/riscv/include/asm/acpi.h @@ -19,7 +19,7 @@ typedef u64 phys_cpuid_t; #define PHYS_CPUID_INVALID INVALID_HARTID /* ACPI table mapping after acpi_permanent_mmap is set */ -void *acpi_os_ioremap(acpi_physical_address phys, acpi_size size); +void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size); #define acpi_os_ioremap acpi_os_ioremap #define acpi_strict 1 /* No out-of-spec workarounds on RISC-V */ diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c index 5ee03ebab80e..56cb2c986c48 100644 --- a/arch/riscv/kernel/acpi.c +++ b/arch/riscv/kernel/acpi.c @@ -215,9 +215,9 @@ void __init __acpi_unmap_table(void __iomem *map, unsigned long size) early_iounmap(map, size); } -void *acpi_os_ioremap(acpi_physical_address phys, acpi_size size) +void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size) { - return memremap(phys, size, MEMREMAP_WB); + return (void __iomem *)memremap(phys, size, MEMREMAP_WB); } #ifdef CONFIG_PCI From patchwork Thu Aug 3 17:58:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 710934 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8538C001DF for ; Thu, 3 Aug 2023 18:00:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235319AbjHCSAg (ORCPT ); Thu, 3 Aug 2023 14:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235388AbjHCSAU (ORCPT ); Thu, 3 Aug 2023 14:00:20 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57808420E for ; Thu, 3 Aug 2023 11:00:05 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-686f25d045cso930365b3a.0 for ; Thu, 03 Aug 2023 11:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085605; x=1691690405; 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=Zrij3XCVzAcOqQorsC5sehKTr0CEJKtsrFsGaW9zZqM=; b=g6+YMcM4UaL1m62Ntt4qPvlZaEv/BYe4UX4PetuB3JttzYhNsA1GY4WTrRaVsePaTR atxJKkHV0OHfvFZ2y8Ln/HQAgi5oGOO9gAsr0K+aIIaY7ouzgXaONyhs/oUd71rdBMNZ LTqtCTDaFhTgMbf7aC8o2trc7JnD/nv6tEP80GHX3A+sLyfMvPmLcM1jG9CgM37CUAlF HA8ellFJwKVcSDXCbvFRMKk1KlpyWU7+fF8Ue932AzN1tptU0DxnNrPXXKi8jfk7+sRR EjceIniHqsZY3gcJMhRO2hVSYyvOldIln61vUNwnPp8vNEzk5ArDaGdXypxKcq0OKj54 7How== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085605; x=1691690405; 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=Zrij3XCVzAcOqQorsC5sehKTr0CEJKtsrFsGaW9zZqM=; b=Whk/0WKib62g7FKqQV1vLoGHn0Mvn990cnYnMB4pzUOcSA2QES3IGBfuJmr3IQ7aXb +vR/+PMrswuWGDWOmdbzEeNPQdTKmycaDqKbGghnlh/GtbNjNDmHMTI23aNY5Er3UEMz o0QYd/EBh2s7cz+eWT9hn5Ym8ImwG9HxqiQQnQMrUY7ZWDDU1narbx/x8cpZZlBUKr08 y853sUQD6bOvQGma4jpw+qXx1jmcZvh/gV/d/aV5byug2Moa1LvkyshYCuDzgAJxHZ8U 0LMKQgBfKyh59Pu9xZR9kMMHuMkwM4aCHfUIP4iJTeF7jKN/AVen5tCODhJdDBm4Llq/ YUBw== X-Gm-Message-State: ABy/qLYngrh7yzEX8NY5gAMhjLHtGJxQMMYmu79djvxv2gUDNhZQs9jK KngjUsjcJw/RxGvsexTM3i95mQ== X-Google-Smtp-Source: APBJJlGfqnPnWK07EeosxE/Z01LsrLZM2OzMNSmgb3YDtRcKmZUzwJl9E9d4B2w1+YCc7DEVzsQZpA== X-Received: by 2002:aa7:8896:0:b0:687:4369:4ad2 with SMTP id z22-20020aa78896000000b0068743694ad2mr12618344pfe.33.1691085604789; Thu, 03 Aug 2023 11:00:04 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.10.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:00:04 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L , Ard Biesheuvel , Alexandre Ghiti Subject: [RFC PATCH v1 04/21] RISC-V: ACPI: Enhance acpi_os_ioremap with MMIO remapping Date: Thu, 3 Aug 2023 23:28:59 +0530 Message-Id: <20230803175916.3174453-5-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Enhance the acpi_os_ioremap() to support opregions in MMIO space. Also, have strict checks using EFI memory map to allow remapping the RAM similar to arm64. Cc: Ard Biesheuvel Cc: Alexandre Ghiti Signed-off-by: Sunil V L --- arch/riscv/Kconfig | 1 + arch/riscv/kernel/acpi.c | 86 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 318f62a0a187..e19f32c12a68 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -38,6 +38,7 @@ config RISCV select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAS_VDSO_DATA + select ARCH_KEEP_MEMBLOCK select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT select ARCH_STACKWALK diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c index 56cb2c986c48..aa4433bca6d9 100644 --- a/arch/riscv/kernel/acpi.c +++ b/arch/riscv/kernel/acpi.c @@ -17,6 +17,7 @@ #include #include #include +#include int acpi_noirq = 1; /* skip ACPI IRQ initialization */ int acpi_disabled = 1; @@ -217,7 +218,90 @@ void __init __acpi_unmap_table(void __iomem *map, unsigned long size) void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size) { - return (void __iomem *)memremap(phys, size, MEMREMAP_WB); + efi_memory_desc_t *md, *region = NULL; + pgprot_t prot; + + if (WARN_ON_ONCE(!efi_enabled(EFI_MEMMAP))) + return NULL; + + for_each_efi_memory_desc(md) { + u64 end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT); + + if (phys < md->phys_addr || phys >= end) + continue; + + if (phys + size > end) { + pr_warn(FW_BUG "requested region covers multiple EFI memory regions\n"); + return NULL; + } + region = md; + break; + } + + /* + * It is fine for AML to remap regions that are not represented in the + * EFI memory map at all, as it only describes normal memory, and MMIO + * regions that require a virtual mapping to make them accessible to + * the EFI runtime services. + */ + prot = PAGE_KERNEL_IO; + if (region) { + switch (region->type) { + case EFI_LOADER_CODE: + case EFI_LOADER_DATA: + case EFI_BOOT_SERVICES_CODE: + case EFI_BOOT_SERVICES_DATA: + case EFI_CONVENTIONAL_MEMORY: + case EFI_PERSISTENT_MEMORY: + if (memblock_is_map_memory(phys) || + !memblock_is_region_memory(phys, size)) { + pr_warn(FW_BUG "requested region covers kernel memory @ %p\n", + &phys); + return NULL; + } + + /* + * Mapping kernel memory is permitted if the region in + * question is covered by a single memblock with the + * NOMAP attribute set: this enables the use of ACPI + * table overrides passed via initramfs. + * This particular use case only requires read access. + */ + fallthrough; + + case EFI_RUNTIME_SERVICES_CODE: + /* + * This would be unusual, but not problematic per se, + * as long as we take care not to create a writable + * mapping for executable code. + */ + prot = PAGE_KERNEL_RO; + break; + + case EFI_ACPI_RECLAIM_MEMORY: + /* + * ACPI reclaim memory is used to pass firmware tables + * and other data that is intended for consumption by + * the OS only, which may decide it wants to reclaim + * that memory and use it for something else. We never + * do that, but we usually add it to the linear map + * anyway, in which case we should use the existing + * mapping. + */ + if (memblock_is_map_memory(phys)) + return (void __iomem *)__va(phys); + fallthrough; + + default: + if (region->attribute & EFI_MEMORY_WB) + prot = PAGE_KERNEL; + else if ((region->attribute & EFI_MEMORY_WC) || + (region->attribute & EFI_MEMORY_WT)) + prot = pgprot_writecombine(PAGE_KERNEL); + } + } + + return ioremap_prot(phys, size, pgprot_val(prot)); } #ifdef CONFIG_PCI From patchwork Thu Aug 3 17:59:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 709669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A3F2C001DB for ; Thu, 3 Aug 2023 18:00:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235375AbjHCSAr (ORCPT ); Thu, 3 Aug 2023 14:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235367AbjHCSAa (ORCPT ); Thu, 3 Aug 2023 14:00:30 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12E3A30E9 for ; Thu, 3 Aug 2023 11:00:12 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-686b879f605so882763b3a.1 for ; Thu, 03 Aug 2023 11:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085612; x=1691690412; 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=HZyznREMZ8qiEWo3qjSd8Z0EQsRbIhIXLSiUggIdL7w=; b=bhy59+dhquk68hVW4TYBfVmR4DtOFAh+z/J4S7eciFPke/xmbBwjsryJ7msuofRPuG vVdDuXH9t3SSriCDYwOVZM8q3FxGRY2RH90vlHkQIwhjf78qVjpWQhSw7wl0yRgRn9hv dZigT3MWX8H0sp5XlUOaNyc6ioh8fogPRZ5Dvjw8IWbukbzFacsVQ+t0hWC7RzB0vx7C 5ndErCCZFOKEP/ZPBnFnejvCxYDQh4yLDtIM5EBYU6GuVRO25EflgU7kXoXggtmfGuAf 5P+0nyfgM6je2/UtheiqMF3FrQn+O6GpRiGxExAmqg0NZ67AfymAIl91V/mq1CdFspIn IQWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085612; x=1691690412; 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=HZyznREMZ8qiEWo3qjSd8Z0EQsRbIhIXLSiUggIdL7w=; b=iwPa2G66jrhZouqJUGI5Xw35w8jmGhas7nCpSl3/xUSM2yk/s/hqLpsD7NBzZcGKQj BBpk3SI4uLvx+smdpfCnwcnNxXStK5EKQO6030JeADmqHl0mzzR8mg3zU1ulNfplLL3w cFgmH7ECQzOKmI+8jJcpFM794WUEzNQGT/JYs/nJab+/nHKM9gMbecc7q7NGCIaqtc6k 6oZrzXSuHMtL4aVyuHZJYMXklRj+0W0rqaiTl5uw+76TveKEaGi+qXwJ2AgzLE6Cj2Iw gDzXbqucLfUpvQ70BSaK9lSDW/KmXQA1/CgDU4DJzOJKV5GIMT1iB18rZ+LQmYfNxKsT qlqA== X-Gm-Message-State: ABy/qLaPDDdIvb6ysa0mRIAgmZ0GG+3ooohAgqXSFyyaEln8l7ZDBZ5I jbz5bvXg3x1OhAwYDJXaIkSghA== X-Google-Smtp-Source: APBJJlHWtEMJq7mXKgUBGIx9XN43JG5wb/bpmSTxX17st1RfcU7TluTI0q6kTlK66lbr30/sl+mHtg== X-Received: by 2002:a05:6a00:a0f:b0:686:2ad5:d11c with SMTP id p15-20020a056a000a0f00b006862ad5d11cmr22201623pfh.33.1691085612223; Thu, 03 Aug 2023 11:00:12 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:00:11 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 05/21] arm64: PCI: Migrate ACPI related functions to pci-acpi.c Date: Thu, 3 Aug 2023 23:29:00 +0530 Message-Id: <20230803175916.3174453-6-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The functions defined in arm64 for ACPI support are required for RISC-V also. To avoid duplication, copy these functions to common location. Signed-off-by: Sunil V L --- arch/arm64/kernel/pci.c | 193 ---------------------------------------- drivers/pci/pci-acpi.c | 182 +++++++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+), 193 deletions(-) diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c index 2276689b5411..fd9a7bed83ce 100644 --- a/arch/arm64/kernel/pci.c +++ b/arch/arm64/kernel/pci.c @@ -6,30 +6,7 @@ * Copyright (C) 2014 ARM Ltd. */ -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include - -#ifdef CONFIG_ACPI -/* - * Try to assign the IRQ number when probing a new device - */ -int pcibios_alloc_irq(struct pci_dev *dev) -{ - if (!acpi_disabled) - acpi_pci_irq_enable(dev); - - return 0; -} -#endif /* * raw_pci_read/write - Platform-specific PCI config space access. @@ -63,173 +40,3 @@ int pcibus_to_node(struct pci_bus *bus) EXPORT_SYMBOL(pcibus_to_node); #endif - -#ifdef CONFIG_ACPI - -struct acpi_pci_generic_root_info { - struct acpi_pci_root_info common; - struct pci_config_window *cfg; /* config space mapping */ -}; - -int acpi_pci_bus_find_domain_nr(struct pci_bus *bus) -{ - struct pci_config_window *cfg = bus->sysdata; - struct acpi_device *adev = to_acpi_device(cfg->parent); - struct acpi_pci_root *root = acpi_driver_data(adev); - - return root->segment; -} - -int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) -{ - struct pci_config_window *cfg; - struct acpi_device *adev; - struct device *bus_dev; - - if (acpi_disabled) - return 0; - - cfg = bridge->bus->sysdata; - - /* - * On Hyper-V there is no corresponding ACPI device for a root bridge, - * therefore ->parent is set as NULL by the driver. And set 'adev' as - * NULL in this case because there is no proper ACPI device. - */ - if (!cfg->parent) - adev = NULL; - else - adev = to_acpi_device(cfg->parent); - - bus_dev = &bridge->bus->dev; - - ACPI_COMPANION_SET(&bridge->dev, adev); - set_dev_node(bus_dev, acpi_get_node(acpi_device_handle(adev))); - - return 0; -} - -static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci) -{ - struct resource_entry *entry, *tmp; - int status; - - status = acpi_pci_probe_root_resources(ci); - resource_list_for_each_entry_safe(entry, tmp, &ci->resources) { - if (!(entry->res->flags & IORESOURCE_WINDOW)) - resource_list_destroy_entry(entry); - } - return status; -} - -/* - * Lookup the bus range for the domain in MCFG, and set up config space - * mapping. - */ -static struct pci_config_window * -pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root) -{ - struct device *dev = &root->device->dev; - struct resource *bus_res = &root->secondary; - u16 seg = root->segment; - const struct pci_ecam_ops *ecam_ops; - struct resource cfgres; - struct acpi_device *adev; - struct pci_config_window *cfg; - int ret; - - ret = pci_mcfg_lookup(root, &cfgres, &ecam_ops); - if (ret) { - dev_err(dev, "%04x:%pR ECAM region not found\n", seg, bus_res); - return NULL; - } - - adev = acpi_resource_consumer(&cfgres); - if (adev) - dev_info(dev, "ECAM area %pR reserved by %s\n", &cfgres, - dev_name(&adev->dev)); - else - dev_warn(dev, FW_BUG "ECAM area %pR not reserved in ACPI namespace\n", - &cfgres); - - cfg = pci_ecam_create(dev, &cfgres, bus_res, ecam_ops); - if (IS_ERR(cfg)) { - dev_err(dev, "%04x:%pR error %ld mapping ECAM\n", seg, bus_res, - PTR_ERR(cfg)); - return NULL; - } - - return cfg; -} - -/* release_info: free resources allocated by init_info */ -static void pci_acpi_generic_release_info(struct acpi_pci_root_info *ci) -{ - struct acpi_pci_generic_root_info *ri; - - ri = container_of(ci, struct acpi_pci_generic_root_info, common); - pci_ecam_free(ri->cfg); - kfree(ci->ops); - kfree(ri); -} - -/* Interface called from ACPI code to setup PCI host controller */ -struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) -{ - struct acpi_pci_generic_root_info *ri; - struct pci_bus *bus, *child; - struct acpi_pci_root_ops *root_ops; - struct pci_host_bridge *host; - - ri = kzalloc(sizeof(*ri), GFP_KERNEL); - if (!ri) - return NULL; - - root_ops = kzalloc(sizeof(*root_ops), GFP_KERNEL); - if (!root_ops) { - kfree(ri); - return NULL; - } - - ri->cfg = pci_acpi_setup_ecam_mapping(root); - if (!ri->cfg) { - kfree(ri); - kfree(root_ops); - return NULL; - } - - root_ops->release_info = pci_acpi_generic_release_info; - root_ops->prepare_resources = pci_acpi_root_prepare_resources; - root_ops->pci_ops = (struct pci_ops *)&ri->cfg->ops->pci_ops; - bus = acpi_pci_root_create(root, root_ops, &ri->common, ri->cfg); - if (!bus) - return NULL; - - /* If we must preserve the resource configuration, claim now */ - host = pci_find_host_bridge(bus); - if (host->preserve_config) - pci_bus_claim_resources(bus); - - /* - * Assign whatever was left unassigned. If we didn't claim above, - * this will reassign everything. - */ - pci_assign_unassigned_root_bus_resources(bus); - - list_for_each_entry(child, &bus->children, node) - pcie_bus_configure_settings(child); - - return bus; -} - -void pcibios_add_bus(struct pci_bus *bus) -{ - acpi_pci_add_bus(bus); -} - -void pcibios_remove_bus(struct pci_bus *bus) -{ - acpi_pci_remove_bus(bus); -} - -#endif diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index a05350a4e49c..d6b2d64b8237 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -1517,4 +1518,185 @@ static int __init acpi_pci_init(void) return 0; } + arch_initcall(acpi_pci_init); + +#if defined(CONFIG_ARM64) +/* + * Try to assign the IRQ number when probing a new device + */ +int pcibios_alloc_irq(struct pci_dev *dev) +{ + if (!acpi_disabled) + acpi_pci_irq_enable(dev); + + return 0; +} + +struct acpi_pci_generic_root_info { + struct acpi_pci_root_info common; + struct pci_config_window *cfg; /* config space mapping */ +}; + +int acpi_pci_bus_find_domain_nr(struct pci_bus *bus) +{ + struct pci_config_window *cfg = bus->sysdata; + struct acpi_device *adev = to_acpi_device(cfg->parent); + struct acpi_pci_root *root = acpi_driver_data(adev); + + return root->segment; +} + +int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) +{ + struct pci_config_window *cfg; + struct acpi_device *adev; + struct device *bus_dev; + + if (acpi_disabled) + return 0; + + cfg = bridge->bus->sysdata; + + /* + * On Hyper-V there is no corresponding ACPI device for a root bridge, + * therefore ->parent is set as NULL by the driver. And set 'adev' as + * NULL in this case because there is no proper ACPI device. + */ + if (!cfg->parent) + adev = NULL; + else + adev = to_acpi_device(cfg->parent); + + bus_dev = &bridge->bus->dev; + + ACPI_COMPANION_SET(&bridge->dev, adev); + set_dev_node(bus_dev, acpi_get_node(acpi_device_handle(adev))); + + return 0; +} + +static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci) +{ + struct resource_entry *entry, *tmp; + int status; + + status = acpi_pci_probe_root_resources(ci); + resource_list_for_each_entry_safe(entry, tmp, &ci->resources) { + if (!(entry->res->flags & IORESOURCE_WINDOW)) + resource_list_destroy_entry(entry); + } + return status; +} + +/* + * Lookup the bus range for the domain in MCFG, and set up config space + * mapping. + */ +static struct pci_config_window * +pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root) +{ + struct device *dev = &root->device->dev; + struct resource *bus_res = &root->secondary; + u16 seg = root->segment; + const struct pci_ecam_ops *ecam_ops; + struct resource cfgres; + struct acpi_device *adev; + struct pci_config_window *cfg; + int ret; + + ret = pci_mcfg_lookup(root, &cfgres, &ecam_ops); + if (ret) { + dev_err(dev, "%04x:%pR ECAM region not found\n", seg, bus_res); + return NULL; + } + + adev = acpi_resource_consumer(&cfgres); + if (adev) + dev_info(dev, "ECAM area %pR reserved by %s\n", &cfgres, + dev_name(&adev->dev)); + else + dev_warn(dev, FW_BUG "ECAM area %pR not reserved in ACPI namespace\n", + &cfgres); + + cfg = pci_ecam_create(dev, &cfgres, bus_res, ecam_ops); + if (IS_ERR(cfg)) { + dev_err(dev, "%04x:%pR error %ld mapping ECAM\n", seg, bus_res, + PTR_ERR(cfg)); + return NULL; + } + + return cfg; +} + +/* release_info: free resources allocated by init_info */ +static void pci_acpi_generic_release_info(struct acpi_pci_root_info *ci) +{ + struct acpi_pci_generic_root_info *ri; + + ri = container_of(ci, struct acpi_pci_generic_root_info, common); + pci_ecam_free(ri->cfg); + kfree(ci->ops); + kfree(ri); +} + +/* Interface called from ACPI code to setup PCI host controller */ +struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) +{ + struct acpi_pci_generic_root_info *ri; + struct pci_bus *bus, *child; + struct acpi_pci_root_ops *root_ops; + struct pci_host_bridge *host; + + ri = kzalloc(sizeof(*ri), GFP_KERNEL); + if (!ri) + return NULL; + + root_ops = kzalloc(sizeof(*root_ops), GFP_KERNEL); + if (!root_ops) { + kfree(ri); + return NULL; + } + + ri->cfg = pci_acpi_setup_ecam_mapping(root); + if (!ri->cfg) { + kfree(ri); + kfree(root_ops); + return NULL; + } + + root_ops->release_info = pci_acpi_generic_release_info; + root_ops->prepare_resources = pci_acpi_root_prepare_resources; + root_ops->pci_ops = (struct pci_ops *)&ri->cfg->ops->pci_ops; + bus = acpi_pci_root_create(root, root_ops, &ri->common, ri->cfg); + if (!bus) + return NULL; + + /* If we must preserve the resource configuration, claim now */ + host = pci_find_host_bridge(bus); + if (host->preserve_config) + pci_bus_claim_resources(bus); + + /* + * Assign whatever was left unassigned. If we didn't claim above, + * this will reassign everything. + */ + pci_assign_unassigned_root_bus_resources(bus); + + list_for_each_entry(child, &bus->children, node) + pcie_bus_configure_settings(child); + + return bus; +} + +void pcibios_add_bus(struct pci_bus *bus) +{ + acpi_pci_add_bus(bus); +} + +void pcibios_remove_bus(struct pci_bus *bus) +{ + acpi_pci_remove_bus(bus); +} + +#endif From patchwork Thu Aug 3 17:59:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 710933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 299E4C001DB for ; Thu, 3 Aug 2023 18:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235548AbjHCSA6 (ORCPT ); Thu, 3 Aug 2023 14:00:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235309AbjHCSAg (ORCPT ); Thu, 3 Aug 2023 14:00:36 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 258F0423F for ; Thu, 3 Aug 2023 11:00:20 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-686f0d66652so1090415b3a.2 for ; Thu, 03 Aug 2023 11:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085619; x=1691690419; 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=7mbYpJBEy7QtZn0rLm+Z46rszMOgig5KvbO250k7OII=; b=YfGQrWrqKxoHHrzv18a348oKjGYv1gGQ4cGmgyQBPY/sWq0LFcGm3LxWdqhhJX9N9s kBW3WG3VU+N9md0iX82nHkzuBp2q4t7soDxrCACNYYUFhcdhqpGhV2tZlHEQyVp7yC3I x3MZPiXRWfo/DCgcuqSvtbtyM5q1vXWl9zSat0C7GiPgfaHAdZmmf9DiiUkALXzC3yVv lSUTih5Yk/drJWTl6Lrv8KwxCFUZRYPN1Z/RXZ1bregl5jLq9/rXwM4R/ZO28pBL35/9 Tkint7JkljbwD6bJlr3TRUg/dGfiJuJLTrbOaZxni/zO2Vd+5zxHdGnGLPVhestQq1s9 FtbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085619; x=1691690419; 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=7mbYpJBEy7QtZn0rLm+Z46rszMOgig5KvbO250k7OII=; b=N05ITnY846bFQ+98jfBqDmrOHoPT+FWhLli3dQSLrEP6DncrVYQDtl7TUZaa3FrQ1W jUN0QdvRE/z6W6veRhjvVjD0aonKGGD8TuKrazaHi3kSl4vxX2nne6vCuP5Jn2FX1oM2 DiRAyR/cL6wzVoteSN78bnltUSi4/Ju1j9xbS9BvPpKwbbR2fhkR/TMgSgY/cE+4QKS4 WeL5mawA1pdBIIlDOIK9O+vLoSLs/yrAwdy6wL+66GCbeUP7+mI0xF9PQj6903A483Jj A5KeXHY5170uc/D1ndxjVHhXDxEf/nUrl3BT0RDD8cfHN1BN+KzS5k2mC8HkygnVPnGr syJQ== X-Gm-Message-State: ABy/qLbJUcM3Spt8crxV2OH56pIrSZ47xAldGO49eizqO4hwec3AfzX8 vT++dT2PmQKOI2xRlN0w2n7bgA== X-Google-Smtp-Source: APBJJlEzbrnno8tMNvQ3OeUKWzuED/8IeQRaqcQag7dwUOCCbEcY3VwgrJDme+hmO3Kc0CFMYucNRA== X-Received: by 2002:a05:6a21:718b:b0:134:b28f:b581 with SMTP id wq11-20020a056a21718b00b00134b28fb581mr20904425pzb.28.1691085619659; Thu, 03 Aug 2023 11:00:19 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.00.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:00:19 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 06/21] RISC-V: ACPI: Implement PCI related functionality Date: Thu, 3 Aug 2023 23:29:01 +0530 Message-Id: <20230803175916.3174453-7-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Replace the dummy implementation for PCI related functions with actual implementation. Signed-off-by: Sunil V L --- arch/riscv/kernel/acpi.c | 32 +++++++++++++++----------------- drivers/pci/pci-acpi.c | 2 +- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c index aa4433bca6d9..01022c5802ec 100644 --- a/arch/riscv/kernel/acpi.c +++ b/arch/riscv/kernel/acpi.c @@ -307,29 +307,27 @@ void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size) #ifdef CONFIG_PCI /* - * These interfaces are defined just to enable building ACPI core. - * TODO: Update it with actual implementation when external interrupt - * controller support is added in RISC-V ACPI. + * raw_pci_read/write - Platform-specific PCI config space access. */ -int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn, - int reg, int len, u32 *val) +int raw_pci_read(unsigned int domain, unsigned int bus, + unsigned int devfn, int reg, int len, u32 *val) { - return PCIBIOS_DEVICE_NOT_FOUND; -} + struct pci_bus *b = pci_find_bus(domain, bus); -int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn, - int reg, int len, u32 val) -{ - return PCIBIOS_DEVICE_NOT_FOUND; -} + if (!b) + return PCIBIOS_DEVICE_NOT_FOUND; -int acpi_pci_bus_find_domain_nr(struct pci_bus *bus) -{ - return -1; + return b->ops->read(b, devfn, reg, len, val); } -struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) +int raw_pci_write(unsigned int domain, unsigned int bus, + unsigned int devfn, int reg, int len, u32 val) { - return NULL; + struct pci_bus *b = pci_find_bus(domain, bus); + + if (!b) + return PCIBIOS_DEVICE_NOT_FOUND; + + return b->ops->write(b, devfn, reg, len, val); } #endif /* CONFIG_PCI */ diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index d6b2d64b8237..5af6188cdbe0 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -1521,7 +1521,7 @@ static int __init acpi_pci_init(void) arch_initcall(acpi_pci_init); -#if defined(CONFIG_ARM64) +#if defined(CONFIG_ARM64) || defined(CONFIG_RISCV) /* * Try to assign the IRQ number when probing a new device */ From patchwork Thu Aug 3 17:59:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 709668 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7638FC04E69 for ; Thu, 3 Aug 2023 18:01:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235362AbjHCSBP (ORCPT ); Thu, 3 Aug 2023 14:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235471AbjHCSAq (ORCPT ); Thu, 3 Aug 2023 14:00:46 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83A5244BE for ; Thu, 3 Aug 2023 11:00:27 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-686f94328a4so882385b3a.0 for ; Thu, 03 Aug 2023 11:00:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085627; x=1691690427; 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=jB8h6dbqqCupn7mkThrMa44SDq8B8ddxZkj2FYKCJmg=; b=fgyTbFbSIA6WSJCx4y2YtZADUaRILhcOrq5BNe2S+JpaMMQ0Ar3+k0o7cWkjb5+Oph qgBwyGFPlW+7v51hDt9HQ+dtrg7U22mFpAu7AGnL5fuAFB8QL03bAsAKMo6sSfAAj9tO jDdTdbrk/xdtviUz8UQl6ciPU76HpqnEIzJeAn4Agqnq3ujBJaj6eWmT8346PeO5SvSe cfJeGA9L8Wkm3G2l4Ck34rZn0TOgsv9hlv86jHG53oUiopUDnXtQHXBZXzHV+0bItKrF EgPUIJwUqxHZV8Ws7XnyrnBbcjoxrzadVdmuq6TIh/vwPYyDsB1PIbLGFdMcXITCD8J5 Hw6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085627; x=1691690427; 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=jB8h6dbqqCupn7mkThrMa44SDq8B8ddxZkj2FYKCJmg=; b=lZxMLbVtyMpw1/UnrMmLO5H2Hq5jL/dkNPIHX29Z/HKV1tvel78VoZ2ZZQXBSqeQ62 SRl4dQ8cBMT8xFZTqPrV9BGDKOGtw1SJ+WMSaMNVAFXDOhAQ5o1rnIBVYCvOj71y3nJi V6ORg6qPfDyvXtBk+hOJZMLJ7/hILBLDlEiZSBYLu1TPQXI34NzDgUF1CAcWXVpifVi2 3MwtPseIkwi2LWzYHoasf8DrNdxccLaJNUzb7vIsBdM1QzoCt71/VOuzW2J8RQpq1gPf 2t1Ym9sWjkqfSqvjEu+W60NFse433Dxp/97sF/xRxBs2Xq1+M643gXYfsvkDKQoP6v3n K3tw== X-Gm-Message-State: ABy/qLbYMqC7V+PHQgkY9l1RibUbcSrBYbRATlcSvOUKkKS58bmtE5MC I4MrDd5jpiFBj4OWoRjE+6vQiw== X-Google-Smtp-Source: APBJJlE5KEYBYCnrIQPqtzpicNM/OpO1N7fddfHFqyd3fUnS/DPSYBFhYR3yrvZPJTarCbPDg4LDUQ== X-Received: by 2002:a05:6a00:2e8d:b0:667:d0ff:6a0f with SMTP id fd13-20020a056a002e8d00b00667d0ff6a0fmr24530632pfb.5.1691085626970; Thu, 03 Aug 2023 11:00:26 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.00.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:00:26 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 07/21] RISC-V: Kconfig: Select ECAM and MCFG Date: Thu, 3 Aug 2023 23:29:02 +0530 Message-Id: <20230803175916.3174453-8-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Enable ECAM and MCFG to support PCIe on ACPI based platforms. Signed-off-by: Sunil V L --- arch/riscv/Kconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index e19f32c12a68..79dc35e89d5f 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -13,6 +13,7 @@ config 32BIT config RISCV def_bool y select ACPI_GENERIC_GSI if ACPI + select ACPI_MCFG if (ACPI && PCI) select ACPI_REDUCED_HARDWARE_ONLY if ACPI select ARCH_DMA_DEFAULT_COHERENT select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION @@ -147,6 +148,7 @@ config RISCV select OF_EARLY_FLATTREE select OF_IRQ select PCI_DOMAINS_GENERIC if PCI + select PCI_ECAM if (ACPI && PCI) select PCI_MSI if PCI select RISCV_ALTERNATIVE if !XIP_KERNEL select RISCV_APLIC From patchwork Thu Aug 3 17:59:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 710932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34DA9C41513 for ; Thu, 3 Aug 2023 18:01:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233980AbjHCSB3 (ORCPT ); Thu, 3 Aug 2023 14:01:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235549AbjHCSA6 (ORCPT ); Thu, 3 Aug 2023 14:00:58 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8A7E469E for ; Thu, 3 Aug 2023 11:00:34 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-68336d06620so1101211b3a.1 for ; Thu, 03 Aug 2023 11:00:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085634; x=1691690434; 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=vQhuhHdTYaoWEXKHMdQb/AIiT1M0AyktuFOnKoEYTGc=; b=InAgb86bmzIXD9aMahgzQO9of8OqAMtZa6GKa8YVTVY7PzoIGrnFhABT5iR9yUDpdb eldlLfYqaIJZ0JqKhkz88GT1tI9U1PbaGlbsR4bWfCh1DfbR0ACTXckiDCh17sNzcRLf f2WV3qxyJ/rWBuGW2ue4ffM6KV/QUAchCeozTJs9q5S/XcNQOsvfIpSb1jVFwiZ6oFq3 jlj10cncisuVGqqhaz2WZx3F8TaIGK9I5NjfThtEaXa1XobxVSAqQwN9SPkmA39vlFlT 61lNiezvzG66VfjvuK2JSEbbCShorb/rqB7QdxU1TuTKXQUwQJNjJ66LD7fLCbx8z4t0 5PbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085634; x=1691690434; 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=vQhuhHdTYaoWEXKHMdQb/AIiT1M0AyktuFOnKoEYTGc=; b=Q9xJ35vX6wj9amymqQtc/vtODEaWTME8+yYXmX/D+QGZR3wme6WZZkJCswQsv49a9n elrTNAdqpD0FEQFPny6VINjNRvDyDU4Jp0foY0vydQeK5WMVWLxcQiX/Ux+SoyZ5KOdx wFKtYfXhxzuL7Bm2VlQO5R26R8d7Za+lHhgTBj9DOEsWJ5VQVapHHCOTHbmQXqB89GK4 apMlA2jFyvMga2tkb6/laBIcDLI8L5T1P4qWPCGcBAlGalVIVhkygQtiCkXX+sDgPT1P sR8Qxpgi+gzKNVjA4bvJ4hPIJSU8bKnwKYhUxKRnUwErOZz8OiSINDnm69QVAuuPEXlu 61+Q== X-Gm-Message-State: ABy/qLZSYYwY7vFItoPgi09O8R2jMxezowmKsd9XCa1VnzaQDiikX5+J tykiz9eAeB04t5rgaxp3dgvz9Q== X-Google-Smtp-Source: APBJJlFH8jQEzxXg6hi15nylBcj+0LbOiklmHj6H9WKQlfFcoVNBUAfYIpWWjK+zKN9M7HAojMJwCw== X-Received: by 2002:a05:6a21:6d95:b0:134:4f86:7966 with SMTP id wl21-20020a056a216d9500b001344f867966mr25365705pzb.9.1691085634213; Thu, 03 Aug 2023 11:00:34 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:00:33 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 08/21] RISC-V: ACPI: RHCT: Add function to get CBO block sizes Date: Thu, 3 Aug 2023 23:29:03 +0530 Message-Id: <20230803175916.3174453-9-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org CBO related block size in ACPI is provided by RHCT. Add support to read the CMO node in RHCT to get this information. Signed-off-by: Sunil V L --- arch/riscv/include/asm/acpi.h | 9 ++++++ drivers/acpi/riscv/rhct.c | 61 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h index d5604d2073bc..0c4e8b35103e 100644 --- a/arch/riscv/include/asm/acpi.h +++ b/arch/riscv/include/asm/acpi.h @@ -66,6 +66,8 @@ int acpi_get_riscv_isa(struct acpi_table_header *table, unsigned int cpu, const char **isa); static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; } +int acpi_get_cbo_block_size(struct acpi_table_header *table, unsigned int cpu, u32 *cbom_size, + u32 *cboz_size, u32 *cbop_size); #else static inline void acpi_init_rintc_map(void) { } static inline struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu) @@ -79,6 +81,13 @@ static inline int acpi_get_riscv_isa(struct acpi_table_header *table, return -EINVAL; } +static inline int acpi_get_cbo_block_size(struct acpi_table_header *table, + unsigned int cpu, u32 *cbom_size, + u32 *cboz_size, u32 *cbop_size) +{ + return -EINVAL; +} + #endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ diff --git a/drivers/acpi/riscv/rhct.c b/drivers/acpi/riscv/rhct.c index b280b3e9c7d9..07309525f277 100644 --- a/drivers/acpi/riscv/rhct.c +++ b/drivers/acpi/riscv/rhct.c @@ -81,3 +81,64 @@ int acpi_get_riscv_isa(struct acpi_table_header *table, unsigned int cpu, const return -1; } + +/* + * During early boot, the caller should call acpi_get_table() and pass its pointer to + * these functions(and free up later). At run time, since this table can be used + * multiple times, pass NULL so that the table remains in memory + */ +int acpi_get_cbo_block_size(struct acpi_table_header *table, unsigned int cpu, + u32 *cbom_size, u32 *cboz_size, u32 *cbop_size) +{ + struct acpi_rhct_node_header *node, *ref_node, *end; + u32 size_hdr = sizeof(struct acpi_rhct_node_header); + u32 size_hartinfo = sizeof(struct acpi_rhct_hart_info); + struct acpi_rhct_hart_info *hart_info; + struct acpi_rhct_cmo_node *cmo_node; + struct acpi_table_rhct *rhct; + u32 *hart_info_node_offset; + u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu); + + BUG_ON(acpi_disabled); + + if (!table) { + rhct = (struct acpi_table_rhct *)acpi_get_rhct(); + if (!rhct) + return -ENOENT; + } else { + rhct = (struct acpi_table_rhct *)table; + } + + end = ACPI_ADD_PTR(struct acpi_rhct_node_header, rhct, rhct->header.length); + + for (node = ACPI_ADD_PTR(struct acpi_rhct_node_header, rhct, rhct->node_offset); + node < end; + node = ACPI_ADD_PTR(struct acpi_rhct_node_header, node, node->length)) { + if (node->type == ACPI_RHCT_NODE_TYPE_HART_INFO) { + hart_info = ACPI_ADD_PTR(struct acpi_rhct_hart_info, node, size_hdr); + hart_info_node_offset = ACPI_ADD_PTR(u32, hart_info, size_hartinfo); + if (acpi_cpu_id != hart_info->uid) + continue; + + for (int i = 0; i < hart_info->num_offsets; i++) { + ref_node = ACPI_ADD_PTR(struct acpi_rhct_node_header, + rhct, hart_info_node_offset[i]); + if (ref_node->type == ACPI_RHCT_NODE_TYPE_CMO) { + cmo_node = ACPI_ADD_PTR(struct acpi_rhct_cmo_node, + ref_node, size_hdr); + if (cbom_size) + *cbom_size = 1 << cmo_node->cbom_size; + + if (cboz_size) + *cboz_size = 1 << cmo_node->cboz_size; + + if (cbop_size) + *cbop_size = 1 << cmo_node->cbop_size; + return 0; + } + } + } + } + + return -ENOENT; +} From patchwork Thu Aug 3 17:59:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 709667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9E77C41513 for ; Thu, 3 Aug 2023 18:02:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235399AbjHCSCC (ORCPT ); Thu, 3 Aug 2023 14:02:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232089AbjHCSB0 (ORCPT ); Thu, 3 Aug 2023 14:01:26 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7580049C1 for ; Thu, 3 Aug 2023 11:00:53 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-686f19b6dd2so894755b3a.2 for ; Thu, 03 Aug 2023 11:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085641; x=1691690441; 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=dVaxSLrcyWrDv537p1b6trWUWlm89roci1AhpEn7YYs=; b=fYo/3hatpzRNQHoHD581iWzQIHlOzusgQsa6qibNN0GLNn1R7S4p/XTrzg4lClBc1p lJKgy1mbJhBtdMSWvCGh9zo1ep2Gb3uA2P3XQbn7aI/LMI4bTDshu3hqT/1QFrqsfu7m TIdcKLkqWqqkK/tNhUcjdcoUPhpOgQm7R1QCCvGw5YQNWhSTvYAfTTAX+lJGELc3ARqy uX+JaTHismEAtWt+icKb9NzCOg5nBT52EbnylGIEAzjm2gWGkCHux7TB4Bi59RFPoIqH 3R5ZRXHZLPpTl5R/PsHSm82EmxC7TCybtefpHDuU1MaqhlgUMegZvF1tMLSTrgHDefTg PaXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085641; x=1691690441; 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=dVaxSLrcyWrDv537p1b6trWUWlm89roci1AhpEn7YYs=; b=ZcLiSnwXW5ldkf4gKXPMAjFAdx+ztph79iR9te43B7+ngl/Rwrzgk7KoAd7OMGN2j3 3n3xVEtmXhMPdSQ21CGDRGSvPACTjzPXf8lM0ZPZI/liS988WrrsdrquMWA0x0lOmKRO //NZCBeU4i24Bh4okM2t3QQ+zTzTZKbS32uPf5ez993pVLnJaDrDnYszYe1TmC1EIxJ3 DobakF5uxatCtzV+fz1mj9I5gHVAuzeRiliZmaTkwTPKFWfiBlzC5r2oFPNN05A/zsfy y8pxxS/s/iP4vfA6wQGcsFohCbkbzFtUvXmY5X2RNahSW+Tm1neCpHFH5Gj1FrGq18sp F3Aw== X-Gm-Message-State: ABy/qLa4hWHeeaLS3cq+2RKRNcsS14wd6Yyx5sLr+1biVVUWSwqHTFlD Z9kfJR6YXNfYfrfBPBhinRpolw== X-Google-Smtp-Source: APBJJlHyvV2fJJK5WcdXx6lc335tSDfrb26H7EK1vwao55qh/vVoaQmFBsBegHbsIEKiaSY6OFT3ZQ== X-Received: by 2002:a05:6a21:6da1:b0:13d:82eb:795a with SMTP id wl33-20020a056a216da100b0013d82eb795amr13802350pzb.56.1691085641397; Thu, 03 Aug 2023 11:00:41 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.00.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:00:41 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 09/21] RISC-V: cacheflush: Initialize CBO variables on ACPI systems Date: Thu, 3 Aug 2023 23:29:04 +0530 Message-Id: <20230803175916.3174453-10-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Using new interface to get the CBO block size information in RHCT, initialize the variables on ACPI platforms. Signed-off-by: Sunil V L --- arch/riscv/mm/cacheflush.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index fbc59b3f69f2..63bb56819b37 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -4,6 +4,8 @@ */ #include +#include +#include #include #ifdef CONFIG_SMP @@ -131,15 +133,38 @@ void __init riscv_init_cbo_blocksizes(void) unsigned long cbom_hartid, cboz_hartid; u32 cbom_block_size = 0, cboz_block_size = 0; struct device_node *node; + struct acpi_table_header *rhct; + acpi_status status; + unsigned int cpu; + + if (!acpi_disabled) { + status = acpi_get_table(ACPI_SIG_RHCT, 0, &rhct); + if (ACPI_FAILURE(status)) + return; + } - for_each_of_cpu_node(node) { - /* set block-size for cbom and/or cboz extension if available */ - cbo_get_block_size(node, "riscv,cbom-block-size", - &cbom_block_size, &cbom_hartid); - cbo_get_block_size(node, "riscv,cboz-block-size", - &cboz_block_size, &cboz_hartid); + for_each_possible_cpu(cpu) { + if (acpi_disabled) { + node = of_cpu_device_node_get(cpu); + if (!node) { + pr_warn("Unable to find cpu node\n"); + continue; + } + + /* set block-size for cbom and/or cboz extension if available */ + cbo_get_block_size(node, "riscv,cbom-block-size", + &cbom_block_size, &cbom_hartid); + cbo_get_block_size(node, "riscv,cboz-block-size", + &cboz_block_size, &cboz_hartid); + } else { + acpi_get_cbo_block_size(rhct, cpu, &cbom_block_size, + &cboz_block_size, NULL); + } } + if (!acpi_disabled && rhct) + acpi_put_table((struct acpi_table_header *)rhct); + if (cbom_block_size) riscv_cbom_block_size = cbom_block_size; From patchwork Thu Aug 3 17:59:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 710931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7087C41513 for ; Thu, 3 Aug 2023 18:02:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235260AbjHCSCV (ORCPT ); Thu, 3 Aug 2023 14:02:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbjHCSBx (ORCPT ); Thu, 3 Aug 2023 14:01:53 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6AB249E3 for ; Thu, 3 Aug 2023 11:01:03 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-686d8c8fc65so914378b3a.0 for ; Thu, 03 Aug 2023 11:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085648; x=1691690448; 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=LwCzqc1PMCRcx2h1vYzs9FDmhl8QjorV5J8xX30vpfA=; b=lGptm+1FaVB2szu9+1FrX5AfEizhjltUyo0aBH0MmslTFeM8tX/ihvgQP5IVG7Tg7A TBFasNuPmX1HxnupljC5J7LAW031DE7hpjg43EwE0xDPU/lp/UPU+kc+wx4Dk9R1qb5t 7jDVmYJE9VCa4riLTon3hZNN5NOLOY08WqDcPqdaOX8wu39mZPD6VF0osJ32v9gvrbfY XACNR92dJTW4PA3wpYNW/UJoNaiuDBuB6RIXDK48vy2YclaDlPWCQiIFi0kIXCFjOqjQ 6Ca8u30WmNCuPrp25cbilzk20B3sOHrjBX7H62pImD4I+4KWuK1qabDwfjQuxSkrh1iP XS3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085648; x=1691690448; 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=LwCzqc1PMCRcx2h1vYzs9FDmhl8QjorV5J8xX30vpfA=; b=fOuJzwY3uGvwBZavClfZIw1KBpKFvxx/YSK1Fr2Ws4YtrxOazwn9+stY5IgmilS9m1 uyLwWzes7JYPDZHLDVEhiDU04PrT5JITqw4NTNir5c4zLxpo2DtRuXUbsN6+/s/Nq9x/ oqG4rqBCFOkEHgN5/dHDF7tRqYhvLC32u+AUQkMRqGkxBNFkuQqWiFxajJ668JIFhNJ4 TjgNrxRxPR5zot0C/l3+AvB5+/evmbhMsZiPY4fzz5wzWBk7DiM/rKnjI37lvQV6xLTC X4zEY9NhCIpcOQ98/pw4X8yRzg/KIOl6VYBZIwxSJoOj2wF1oEUxoHerboJqOFvsX+po mPHg== X-Gm-Message-State: ABy/qLavQ/GlFwg1g40oPEtYD+WxdQF4jG7ZR7XvQSFnB9NtZCu2H7fy ZD8NfXvKWPXB/HA4mMfL4/M4VA== X-Google-Smtp-Source: APBJJlEZPAolOiWsswMUNb/3O27FzwqkU7VHoLeXdU05Nm8+s6t/U8LeZFnf7BD1irhpUyClA9ox0w== X-Received: by 2002:a05:6a00:14d1:b0:63d:260d:f9dd with SMTP id w17-20020a056a0014d100b0063d260df9ddmr21845288pfu.33.1691085648649; Thu, 03 Aug 2023 11:00:48 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:00:48 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 10/21] clocksource/timer-riscv: ACPI: Add timer_cannot_wakeup_cpu Date: Thu, 3 Aug 2023 23:29:05 +0530 Message-Id: <20230803175916.3174453-11-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The timer capability to wakeup the cpu irrespective of its idle state is provided by the flag in RHCT. Update the timer code to set this flag. Signed-off-by: Sunil V L --- drivers/clocksource/timer-riscv.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c index da3071b387eb..50198657230e 100644 --- a/drivers/clocksource/timer-riscv.c +++ b/drivers/clocksource/timer-riscv.c @@ -212,6 +212,10 @@ TIMER_OF_DECLARE(riscv_timer, "riscv", riscv_timer_init_dt); #ifdef CONFIG_ACPI static int __init riscv_timer_acpi_init(struct acpi_table_header *table) { + struct acpi_table_rhct *rhct = (struct acpi_table_rhct *)table; + + riscv_timer_cannot_wake_cpu = rhct->flags & ACPI_RHCT_TIMER_CANNOT_WAKEUP_CPU; + return riscv_timer_init_common(); } From patchwork Thu Aug 3 17:59:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 709666 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DD5DEB64DD for ; Thu, 3 Aug 2023 18:02:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235386AbjHCSCa (ORCPT ); Thu, 3 Aug 2023 14:02:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230423AbjHCSCA (ORCPT ); Thu, 3 Aug 2023 14:02:00 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A84263C34 for ; Thu, 3 Aug 2023 11:01:11 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6873a30d02eso865763b3a.3 for ; Thu, 03 Aug 2023 11:01:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085656; x=1691690456; 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=DyY105ZWYDcmAte3LXmkGWmEUp/pfY0rBCzPBKLc5no=; b=F2No1P8dCodOCJka5dx2xLrl5WcKTOqh0CqE9s2TUtqnLixlF6cr/AUvszgzy2TZTu IpgJ+dCrZugmZepjC/tpy4R5LQ7Pz00gUcQA/TtEMUWoSfT5/uFb1jKxDzT1ZQsqsZTd n/YxBVubsZMRX+XTZS1a6+twWBxpWIcvQgGZi10KPo9NwU+hLzYpn1k3UmbuJPr0c0iN /xxd/mndMDktQMKzqNFO4efMHpBh/HZI7YvgUVyIjmX6wmoATvY7iqn4QFz7f0d+cSG4 WzANehXdmfb0puBdKFejEfzCVDWLv6Eq7vxbamEiMtycsiO96UVNPeRmqmAhUEv2O88s z+Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085656; x=1691690456; 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=DyY105ZWYDcmAte3LXmkGWmEUp/pfY0rBCzPBKLc5no=; b=YfUe9PPZ5lKcdiNxo2zStaDfwABGUwkqzbOUpoakat1BxpUsJOdLeIMskdPZvvAsrJ pMwrqZlg80NzVwBw+rIqGyNWfys2Vi7JQ7inFdrH+ysJn9pW4TN72SgRqZT57CryeUS4 gBM8u/2dEaqy6hsqb5mcN7HOs5/kKLIjNjgUVu1tCSS6LSpypTPOtspumSEdCr4+AcvS bcCMV329S/RKdtk2KXjS7pEFlc2g7SnsXPmPH8bT2MB3yZy3905q9AY9tCGMsltAOQ8q 7HcwSRB8IMHJ8p1hvIP5Ko2UfzvsPQ9BVk/R4B/XptuKrfFuKGHYOn75ErPD8xhdaFuB xVOg== X-Gm-Message-State: ABy/qLY/UcoW0c/pZ0/iUVRo8JNs86yCyBHFEjGA1fYdK8/V2wbI1nT7 NHMM0ql+v87lC8Ezp0eWAMLinA== X-Google-Smtp-Source: APBJJlF1KqR7PBmpd+0ur15adwkWpnUfiC6IMRYgAhf76Ujfi0pbNhhy0c6BhAYpNTIPaEB13Qkk0A== X-Received: by 2002:a05:6a00:1883:b0:666:b254:1c9c with SMTP id x3-20020a056a00188300b00666b2541c9cmr22057156pfh.27.1691085656078; Thu, 03 Aug 2023 11:00:56 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:00:55 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Anup Patel , Sunil V L Subject: [RFC PATCH v1 11/21] swnode: Add support to create early during boot Date: Thu, 3 Aug 2023 23:29:06 +0530 Message-Id: <20230803175916.3174453-12-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Anup Patel swnode framework can be used to create fwnode for interrupt controllers. This helps in keeping the drivers same for both DT and ACPI. To enable this, enhance the swnode framework so that it can be created early during boot without dependency on sysfs. Signed-off-by: Anup Patel Co-developed-by: Sunil V L Signed-off-by: Sunil V L --- drivers/base/swnode.c | 117 +++++++++++++++++++++++++++++++++------ include/linux/property.h | 3 + 2 files changed, 103 insertions(+), 17 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 1886995a0b3a..43f191a38980 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "base.h" @@ -21,6 +22,7 @@ struct swnode { /* hierarchy */ struct ida child_ids; + struct list_head early; struct list_head entry; struct list_head children; struct swnode *parent; @@ -32,6 +34,9 @@ struct swnode { static DEFINE_IDA(swnode_root_ids); static struct kset *swnode_kset; +static DEFINE_SPINLOCK(swnode_early_lock); +static LIST_HEAD(swnode_early_list); + #define kobj_to_swnode(_kobj_) container_of(_kobj_, struct swnode, kobj) static const struct fwnode_operations software_node_ops; @@ -73,6 +78,17 @@ software_node_to_swnode(const struct software_node *node) if (!node) return NULL; + spin_lock(&swnode_early_lock); + + list_for_each_entry(swnode, &swnode_early_list, early) { + if (swnode->node == node) { + spin_unlock(&swnode_early_lock); + return swnode; + } + } + + spin_unlock(&swnode_early_lock); + spin_lock(&swnode_kset->list_lock); list_for_each_entry(k, &swnode_kset->list, entry) { @@ -698,6 +714,19 @@ software_node_find_by_name(const struct software_node *parent, const char *name) if (!name) return NULL; + spin_lock(&swnode_early_lock); + + list_for_each_entry(swnode, &swnode_early_list, early) { + if (parent == swnode->node->parent && swnode->node->name && + !strcmp(name, swnode->node->name)) { + kobject_get(&swnode->kobj); + spin_unlock(&swnode_early_lock); + return swnode->node; + } + } + + spin_unlock(&swnode_early_lock); + spin_lock(&swnode_kset->list_lock); list_for_each_entry(k, &swnode_kset->list, entry) { @@ -742,10 +771,16 @@ static void software_node_free(const struct software_node *node) kfree(node); } -static void software_node_release(struct kobject *kobj) +static void software_node_release_common(struct kobject *kobj, bool early) { struct swnode *swnode = kobj_to_swnode(kobj); + if (early) { + spin_lock(&swnode_early_lock); + list_del(&swnode->early); + spin_unlock(&swnode_early_lock); + } + if (swnode->parent) { ida_simple_remove(&swnode->parent->child_ids, swnode->id); list_del(&swnode->entry); @@ -760,6 +795,20 @@ static void software_node_release(struct kobject *kobj) kfree(swnode); } +static void software_node_release(struct kobject *kobj) +{ + software_node_release_common(kobj, false); +} + +static void software_node_release_early(struct kobject *kobj) +{ + software_node_release_common(kobj, true); +} + +static const struct kobj_type software_node_type_early = { + .release = software_node_release_early +}; + static const struct kobj_type software_node_type = { .release = software_node_release, .sysfs_ops = &kobj_sysfs_ops, @@ -767,7 +816,7 @@ static const struct kobj_type software_node_type = { static struct fwnode_handle * swnode_register(const struct software_node *node, struct swnode *parent, - unsigned int allocated) + unsigned int allocated, unsigned int early) { struct swnode *swnode; int ret; @@ -786,21 +835,39 @@ swnode_register(const struct software_node *node, struct swnode *parent, swnode->id = ret; swnode->node = node; swnode->parent = parent; - swnode->kobj.kset = swnode_kset; + swnode->kobj.kset = (!early) ? swnode_kset : NULL; fwnode_init(&swnode->fwnode, &software_node_ops); ida_init(&swnode->child_ids); + INIT_LIST_HEAD(&swnode->early); INIT_LIST_HEAD(&swnode->entry); INIT_LIST_HEAD(&swnode->children); - if (node->name) - ret = kobject_init_and_add(&swnode->kobj, &software_node_type, - parent ? &parent->kobj : NULL, - "%s", node->name); - else - ret = kobject_init_and_add(&swnode->kobj, &software_node_type, - parent ? &parent->kobj : NULL, - "node%d", swnode->id); + if (early) { + ret = 0; + kobject_init(&swnode->kobj, &software_node_type_early); + swnode->kobj.parent = parent ? &parent->kobj : NULL; + if (node->name) + ret = kobject_set_name(&swnode->kobj, + "%s", node->name); + else + ret = kobject_set_name(&swnode->kobj, + "node%d", swnode->id); + if (!ret) { + spin_lock(&swnode_early_lock); + list_add_tail(&swnode->early, &swnode_early_list); + spin_unlock(&swnode_early_lock); + } + } else { + if (node->name) + ret = kobject_init_and_add(&swnode->kobj, &software_node_type, + parent ? &parent->kobj : NULL, + "%s", node->name); + else + ret = kobject_init_and_add(&swnode->kobj, &software_node_type, + parent ? &parent->kobj : NULL, + "node%d", swnode->id); + } if (ret) { kobject_put(&swnode->kobj); return ERR_PTR(ret); @@ -815,7 +882,8 @@ swnode_register(const struct software_node *node, struct swnode *parent, if (parent) list_add_tail(&swnode->entry, &parent->children); - kobject_uevent(&swnode->kobj, KOBJ_ADD); + if (!early) + kobject_uevent(&swnode->kobj, KOBJ_ADD); return &swnode->fwnode; } @@ -892,7 +960,7 @@ int software_node_register(const struct software_node *node) if (node->parent && !parent) return -EINVAL; - return PTR_ERR_OR_ZERO(swnode_register(node, parent, 0)); + return PTR_ERR_OR_ZERO(swnode_register(node, parent, 0, 0)); } EXPORT_SYMBOL_GPL(software_node_register); @@ -910,9 +978,10 @@ void software_node_unregister(const struct software_node *node) } EXPORT_SYMBOL_GPL(software_node_unregister); -struct fwnode_handle * -fwnode_create_software_node(const struct property_entry *properties, - const struct fwnode_handle *parent) +static struct fwnode_handle * +fwnode_create_software_node_common(const struct property_entry *properties, + const struct fwnode_handle *parent, + bool early) { struct fwnode_handle *fwnode; struct software_node *node; @@ -931,12 +1000,26 @@ fwnode_create_software_node(const struct property_entry *properties, node->parent = p ? p->node : NULL; - fwnode = swnode_register(node, p, 1); + fwnode = swnode_register(node, p, 1, early); if (IS_ERR(fwnode)) software_node_free(node); return fwnode; } + +struct fwnode_handle * +fwnode_create_software_node_early(const struct property_entry *properties, + const struct fwnode_handle *parent) +{ + return fwnode_create_software_node_common(properties, parent, true); +} + +struct fwnode_handle * +fwnode_create_software_node(const struct property_entry *properties, + const struct fwnode_handle *parent) +{ + return fwnode_create_software_node_common(properties, parent, false); +} EXPORT_SYMBOL_GPL(fwnode_create_software_node); void fwnode_remove_software_node(struct fwnode_handle *fwnode) diff --git a/include/linux/property.h b/include/linux/property.h index 8c3c6685a2ae..7137338bfabb 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -503,6 +503,9 @@ void software_node_unregister_node_group(const struct software_node **node_group int software_node_register(const struct software_node *node); void software_node_unregister(const struct software_node *node); +struct fwnode_handle * +fwnode_create_software_node_early(const struct property_entry *properties, + const struct fwnode_handle *parent); struct fwnode_handle * fwnode_create_software_node(const struct property_entry *properties, const struct fwnode_handle *parent); From patchwork Thu Aug 3 17:59:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 710930 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B68BEB64DD for ; Thu, 3 Aug 2023 18:02:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232089AbjHCSCj (ORCPT ); Thu, 3 Aug 2023 14:02:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232476AbjHCSCC (ORCPT ); Thu, 3 Aug 2023 14:02:02 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 401ED44B8 for ; Thu, 3 Aug 2023 11:01:15 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-686f8614ce5so1118688b3a.3 for ; Thu, 03 Aug 2023 11:01:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085663; x=1691690463; 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=Vqi3iZnSO0pCz4r86HvzjXAIoq/LUkNm+cOCoheLdcU=; b=RGBk6rx5Hg20bOXt+KLaRA26VcrOyNOoG/eZ7AxmlMnjFLn1DtSewmy8B6izdUW0E9 GsvBNf8e3jLCLs9h3DTaOaEA4Km0R9H4SNrQ9+L743IjhhgsHfGIylndzoIQZ265aQGL n3u5HhJfofcxpdy320nz2rQ2QoD01GiNeIZKOW51Fa3p9Z3xFqseEFfup54Xbr4HF94E 1EWqxSsfqSg9VtpcDRRRk5I1Neux3XeF5LvtGw6Xi2P1PAQzmkcPwAZHb9qGJ5o3kBoC gZ6YooLlmoRGD/mmS9270tnx8asDRFY2Qh6PHJuGg7a6wwcl70gJWrfxbZ1zW3Bv9Blq Sc+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085663; x=1691690463; 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=Vqi3iZnSO0pCz4r86HvzjXAIoq/LUkNm+cOCoheLdcU=; b=GfZ9i9ukuW9qxjYia0Se999ovzaRSaePWNNMst2fe/T9ZnMmVQYsn4Ht+Fd20n4Sdf ZOdQJ+j30ncAgRexnLoXiHZIf8f6+Z9k0sbjU5xbMEafX9/uiBgARIMZlfwWAFf1kvrR vhgPYf1Igp9HfWzwjtwgV+cA9/PfePgeNZYqx9MpCyN4sUq2sesOcWNTM8sch+9cY8Ba naZg9chLecxweup9L7lISqUX1ovOqZ41MJCEDeAQQKAw76eu9jsBjyOyS0zV0x6An0n6 c2PTQTInG8kz+byX7reaKu+QhXuqUTwJyt1quvmHzX1djt+wm381ZUSeOvKVaXx0F6ha hQ/Q== X-Gm-Message-State: ABy/qLbaYkRpj0Gj5addx2lqMPWUK+z+aWrSpCbGxU/xynKhOTDR26aU VX9y2TW1/ZfYIEHofz4z5yR8qQ== X-Google-Smtp-Source: APBJJlFqOcYVb1YmYRN4MTpyz32muTvUlVIwXMvqlj269qOtTWbHmeKplda1rvUua7TwvFx4MZypxQ== X-Received: by 2002:a05:6a00:2351:b0:687:5c3f:d834 with SMTP id j17-20020a056a00235100b006875c3fd834mr8861510pfj.11.1691085663545; Thu, 03 Aug 2023 11:01:03 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.00.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:01:03 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 12/21] irqchip/riscv-intc: Use swnode framework to create fwnode Date: Thu, 3 Aug 2023 23:29:07 +0530 Message-Id: <20230803175916.3174453-13-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org By using swnode framework, all data from ACPI tables can be populated as properties of the swnode. This simplifies the driver code and removes the need for ACPI vs DT checks. Use this framework for RISC-V INTC driver. Signed-off-by: Sunil V L --- Documentation/riscv/acpi.rst | 21 +++++++++++++++ arch/riscv/include/asm/acpi.h | 1 + drivers/acpi/riscv/Makefile | 2 +- drivers/acpi/riscv/irqchip.c | 46 ++++++++++++++++++++++++++++++++ drivers/irqchip/irq-riscv-intc.c | 12 ++++----- 5 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 drivers/acpi/riscv/irqchip.c diff --git a/Documentation/riscv/acpi.rst b/Documentation/riscv/acpi.rst index 9870a282815b..e2406546bc16 100644 --- a/Documentation/riscv/acpi.rst +++ b/Documentation/riscv/acpi.rst @@ -8,3 +8,24 @@ The ISA string parsing rules for ACPI are defined by `Version ASCIIDOC Conversion, 12/2022 of the RISC-V specifications, as defined by tag "riscv-isa-release-1239329-2023-05-23" (commit 1239329 ) `_ + +Interrupt Controller Drivers +======= + +ACPI drivers for RISC-V interrupt controllers use software node framework to +create the fwnode for the interrupt controllers. Below properties are +additionally required for some firmware nodes apart from the properties +defined by the device tree bindings for these interrupt controllers. The +properties are created using the data in MADT table. + +1) RISC-V Interrupt Controller (INTC) +----------- +``hartid`` - Hart ID of the hart this interrupt controller belongs to. + +``riscv,imsic-addr`` - Physical base address of the Incoming MSI Controller +(IMSIC) MMIO region of this hart. + +``riscv,imsic-size`` - Size in bytes of the IMSIC MMIO region of this hart. + +``riscv,ext-intc-id`` - The unique ID of the external interrupts connected +to this hart. diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h index 0c4e8b35103e..0ac2df2dd194 100644 --- a/arch/riscv/include/asm/acpi.h +++ b/arch/riscv/include/asm/acpi.h @@ -68,6 +68,7 @@ int acpi_get_riscv_isa(struct acpi_table_header *table, static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; } int acpi_get_cbo_block_size(struct acpi_table_header *table, unsigned int cpu, u32 *cbom_size, u32 *cboz_size, u32 *cbop_size); +struct fwnode_handle *acpi_rintc_create_irqchip_fwnode(struct acpi_madt_rintc *rintc); #else static inline void acpi_init_rintc_map(void) { } static inline struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu) diff --git a/drivers/acpi/riscv/Makefile b/drivers/acpi/riscv/Makefile index 8b3b126e0b94..8b664190d172 100644 --- a/drivers/acpi/riscv/Makefile +++ b/drivers/acpi/riscv/Makefile @@ -1,2 +1,2 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y += rhct.o +obj-y += rhct.o irqchip.o diff --git a/drivers/acpi/riscv/irqchip.c b/drivers/acpi/riscv/irqchip.c new file mode 100644 index 000000000000..36f066a2cad5 --- /dev/null +++ b/drivers/acpi/riscv/irqchip.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023, Ventana Micro Systems Inc + * Author: Sunil V L + * + */ + +#include +#include +#include +#include +#include + +struct riscv_irqchip_list { + struct fwnode_handle *fwnode; + struct list_head list; +}; + +LIST_HEAD(rintc_list); + +struct fwnode_handle *acpi_rintc_create_irqchip_fwnode(struct acpi_madt_rintc *rintc) +{ + struct property_entry props[6] = {}; + struct fwnode_handle *fwnode; + struct riscv_irqchip_list *rintc_element; + + props[0] = PROPERTY_ENTRY_U64("hartid", rintc->hart_id); + props[1] = PROPERTY_ENTRY_U32("riscv,ext-intc-id", rintc->ext_intc_id); + props[2] = PROPERTY_ENTRY_U64("riscv,imsic-addr", rintc->imsic_addr); + props[3] = PROPERTY_ENTRY_U32("riscv,imsic-size", rintc->imsic_size); + props[4] = PROPERTY_ENTRY_U32("#interrupt-cells", 1); + + fwnode = fwnode_create_software_node_early(props, NULL); + if (fwnode) { + rintc_element = kzalloc(sizeof(*rintc_element), GFP_KERNEL); + if (!rintc_element) { + fwnode_remove_software_node(fwnode); + return NULL; + } + + rintc_element->fwnode = fwnode; + list_add_tail(&rintc_element->list, &rintc_list); + } + + return fwnode; +} diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c index 1a0fc87152c5..1ef9cada1ed3 100644 --- a/drivers/irqchip/irq-riscv-intc.c +++ b/drivers/irqchip/irq-riscv-intc.c @@ -203,6 +203,12 @@ static int __init riscv_intc_acpi_init(union acpi_subtable_headers *header, rintc = (struct acpi_madt_rintc *)header; + fn = acpi_rintc_create_irqchip_fwnode(rintc); + if (!fn) { + pr_err("unable to create INTC FW node\n"); + return -ENOMEM; + } + /* * The ACPI MADT will have one INTC for each CPU (or HART) * so riscv_intc_acpi_init() function will be called once @@ -212,12 +218,6 @@ static int __init riscv_intc_acpi_init(union acpi_subtable_headers *header, if (riscv_hartid_to_cpuid(rintc->hart_id) != smp_processor_id()) return 0; - fn = irq_domain_alloc_named_fwnode("RISCV-INTC"); - if (!fn) { - pr_err("unable to allocate INTC FW node\n"); - return -ENOMEM; - } - return riscv_intc_init_common(fn); } From patchwork Thu Aug 3 17:59:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 709665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80F0BC04E69 for ; Thu, 3 Aug 2023 18:02:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235525AbjHCSCo (ORCPT ); Thu, 3 Aug 2023 14:02:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232900AbjHCSCP (ORCPT ); Thu, 3 Aug 2023 14:02:15 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A00C4687 for ; Thu, 3 Aug 2023 11:01:19 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-686f1240a22so1104724b3a.0 for ; Thu, 03 Aug 2023 11:01:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085671; x=1691690471; 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=B8DeeC24vpY8HEzbjyI/7Rv+Hl3+YE3NoDQiC+QP7Dk=; b=N7pjlLqaqUS81mB7h6ZTDNs9hSguqXKdZ80nnwm+cjhE5CyUhSKPbW/O26zFvL8jJV fRVdbvFgOsVMRS3Iz7NdaeUu9EONmq9WAXSFCRGYEZzaTg1/ifLsx6RVNDwO+Wif19S+ eA1IVkZowtY6UTLqlV+rWLm+7orK9S1qQUyAL/f+AV6DOQEiIUH9ui6P9m3t+VMZ2c3G nf/GIsu3qOyj/yQM3UAN+oHHwl7Pes88yfB2dpbPPTcfGg3PHyVIy1bL3rC0mgr0II7I HnwuRGavWg6/C0AD2Zois4/aEizVjaSIryyVcTiedAZ+Fh+d3MNuIT5gxonWVMzRuN1w bXEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085671; x=1691690471; 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=B8DeeC24vpY8HEzbjyI/7Rv+Hl3+YE3NoDQiC+QP7Dk=; b=gYLfTvvqLjjTnPbKSXJUcO6AILQ1AduCkwQeojSWn7MQMNQmC8UPIWefQMff1ozb+Z TcIEf1gujaE4KY2ZkKpuD1Em80TEeIkrq7wz4vAKCcC8H28mgNQSWObRcw31qK8Q3bkQ e4z5ZbfX/o9R7UqHMUGI3EHueoDSBcl+0x1ldNAQ06QKqI+bxAkuhr6zGC27UpihvAQ0 X1otBqpYbGoMbKslPm4ih54D87iPFjc4EGubj8806LyZD72wjd7v66RLcXzh/kooTxnd NVicKYKvTIOPG4O/Ngn2ncHyQPBkO8tFMaKUn9bAVaSML53XR2Uj67AdN5SBsax9DED7 H9Ow== X-Gm-Message-State: ABy/qLYPS+2+P7WgNSJHRuli+JNemhYRpImPcIcI3D4x6eAXcpEn/UwR 5meTCRngSGDjjzFp0+gORGLMpw== X-Google-Smtp-Source: APBJJlHODxCiHsxX3VdzzkL4f0OtQqwnuurJJdGSKcSJa8ej/p8fDM2WEmx10nSHB/0YuWJf8HguRg== X-Received: by 2002:a05:6a21:7889:b0:138:198f:6edf with SMTP id bf9-20020a056a21788900b00138198f6edfmr26331813pzc.46.1691085670849; Thu, 03 Aug 2023 11:01:10 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.01.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:01:10 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 13/21] irqchip/riscv-imsic-early: Add ACPI support Date: Thu, 3 Aug 2023 23:29:08 +0530 Message-Id: <20230803175916.3174453-14-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add support to probe the IMSIC early driver on ACPI based RISC-V platforms. Signed-off-by: Sunil V L --- arch/riscv/include/asm/acpi.h | 6 +++ drivers/acpi/riscv/irqchip.c | 57 +++++++++++++++++++++++++ drivers/irqchip/irq-riscv-imsic-early.c | 28 ++++++++++++ drivers/irqchip/irq-riscv-imsic-state.c | 33 +++++++++++--- 4 files changed, 119 insertions(+), 5 deletions(-) diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h index 0ac2df2dd194..6dde3d63dc0e 100644 --- a/arch/riscv/include/asm/acpi.h +++ b/arch/riscv/include/asm/acpi.h @@ -69,6 +69,8 @@ static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; } int acpi_get_cbo_block_size(struct acpi_table_header *table, unsigned int cpu, u32 *cbom_size, u32 *cboz_size, u32 *cbop_size); struct fwnode_handle *acpi_rintc_create_irqchip_fwnode(struct acpi_madt_rintc *rintc); +struct fwnode_handle *acpi_imsic_create_fwnode(struct acpi_madt_imsic *imsic); +struct fwnode_handle *acpi_riscv_get_msi_fwnode(struct device *dev); #else static inline void acpi_init_rintc_map(void) { } static inline struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu) @@ -89,6 +91,10 @@ static inline int acpi_get_cbo_block_size(struct acpi_table_header *table, return -EINVAL; } +static inline struct fwnode_handle *acpi_riscv_get_msi_fwnode(struct device *dev) +{ + return NULL; +} #endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ diff --git a/drivers/acpi/riscv/irqchip.c b/drivers/acpi/riscv/irqchip.c index 36f066a2cad5..6e15d45cb229 100644 --- a/drivers/acpi/riscv/irqchip.c +++ b/drivers/acpi/riscv/irqchip.c @@ -18,6 +18,8 @@ struct riscv_irqchip_list { LIST_HEAD(rintc_list); +static struct fwnode_handle *imsic_acpi_fwnode; + struct fwnode_handle *acpi_rintc_create_irqchip_fwnode(struct acpi_madt_rintc *rintc) { struct property_entry props[6] = {}; @@ -44,3 +46,58 @@ struct fwnode_handle *acpi_rintc_create_irqchip_fwnode(struct acpi_madt_rintc *r return fwnode; } + +static struct fwnode_handle *acpi_imsic_get_rintc_fwnode(u32 idx) +{ + struct riscv_irqchip_list *rintc_element; + struct fwnode_handle *fwnode; + struct list_head *i, *tmp; + unsigned int j = 0; + + list_for_each_safe(i, tmp, &rintc_list) { + rintc_element = list_entry(i, struct riscv_irqchip_list, list); + fwnode = rintc_element->fwnode; + + if (j == idx) + return fwnode; + + j++; + } + + return NULL; +} + +struct fwnode_handle *acpi_imsic_create_fwnode(struct acpi_madt_imsic *imsic) +{ + struct property_entry props[8] = {}; + struct software_node_ref_args *refs; + struct fwnode_handle *parent_fwnode; + unsigned int nr_rintc, i; + + props[0] = PROPERTY_ENTRY_U32("riscv,guest-index-bits", imsic->guest_index_bits); + props[1] = PROPERTY_ENTRY_U32("riscv,hart-index-bits", imsic->hart_index_bits); + props[2] = PROPERTY_ENTRY_U32("riscv,group-index-bits", imsic->group_index_bits); + props[3] = PROPERTY_ENTRY_U32("riscv,group-index-shift", imsic->group_index_shift); + props[4] = PROPERTY_ENTRY_U32("riscv,num-ids", imsic->num_ids); + props[5] = PROPERTY_ENTRY_U32("riscv,num-guest-ids", imsic->num_guest_ids); + + nr_rintc = list_count_nodes(&rintc_list); + refs = kcalloc(nr_rintc, sizeof(*refs), GFP_KERNEL); + if (!refs) + return NULL; + + for (i = 0; i < nr_rintc; i++) { + parent_fwnode = acpi_imsic_get_rintc_fwnode(i); + refs[i] = SOFTWARE_NODE_REFERENCE(to_software_node(parent_fwnode), RV_IRQ_EXT); + } + props[6] = PROPERTY_ENTRY_REF_ARRAY_LEN("interrupts-extended", refs, nr_rintc); + + imsic_acpi_fwnode = fwnode_create_software_node_early(props, NULL); + + return imsic_acpi_fwnode; +} + +struct fwnode_handle *acpi_riscv_get_msi_fwnode(struct device *dev) +{ + return imsic_acpi_fwnode; +} diff --git a/drivers/irqchip/irq-riscv-imsic-early.c b/drivers/irqchip/irq-riscv-imsic-early.c index 1de89ce1ec2f..93f4d748ca6d 100644 --- a/drivers/irqchip/irq-riscv-imsic-early.c +++ b/drivers/irqchip/irq-riscv-imsic-early.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -256,3 +257,30 @@ static int __init imsic_early_dt_init(struct device_node *node, return 0; } IRQCHIP_DECLARE(riscv_imsic, "riscv,imsics", imsic_early_dt_init); + +#ifdef CONFIG_ACPI +static int __init imsic_early_acpi_init(union acpi_subtable_headers *header, + const unsigned long end) +{ + struct fwnode_handle *fwnode; + int rc; + + /* + * There should be only one IMSIC node. + */ + fwnode = acpi_imsic_create_fwnode((struct acpi_madt_imsic *)header); + if (!fwnode) { + pr_err("unable to create IMSIC FW node\n"); + return -ENOMEM; + } + + rc = imsic_early_probe(fwnode); + if (!rc) + pci_msi_register_fwnode_provider(&acpi_riscv_get_msi_fwnode); + + return rc; +} + +IRQCHIP_ACPI_DECLARE(riscv_imsic, ACPI_MADT_TYPE_IMSIC, + NULL, 1, imsic_early_acpi_init); +#endif diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c index 412b5b919dcc..d0e09e51e8ae 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -225,15 +225,38 @@ static int __init imsic_get_parent_hartid(struct fwnode_handle *fwnode, return riscv_get_intc_hartid(parent.fwnode, hartid); } +static int __init imsic_acpi_get_mmio_resource(struct fwnode_handle *fwnode, + u32 index, struct resource *res) +{ + int rc; + struct fwnode_reference_args parent; + u64 base; + u32 size; + + rc = fwnode_property_get_reference_args(fwnode, + "interrupts-extended", NULL, + 0, index, &parent); + if (rc) + return rc; + + rc = fwnode_property_read_u64_array(parent.fwnode, "riscv,imsic-addr", + &base, 1); + rc = fwnode_property_read_u32_array(parent.fwnode, "riscv,imsic-size", + &size, 1); + if (!rc) { + res->start = base; + res->end = res->start + size - 1; + } + + return 0; +} + static int __init imsic_get_mmio_resource(struct fwnode_handle *fwnode, u32 index, struct resource *res) { - /* - * Currently, only OF fwnode is support so extend this function - * for other types of fwnode for ACPI support. - */ if (!is_of_node(fwnode)) - return -EINVAL; + return imsic_acpi_get_mmio_resource(fwnode, index, res); + return of_address_to_resource(to_of_node(fwnode), index, res); } From patchwork Thu Aug 3 17:59:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 710929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E23EBC001DB for ; Thu, 3 Aug 2023 18:03:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230135AbjHCSCz (ORCPT ); Thu, 3 Aug 2023 14:02:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232628AbjHCSCR (ORCPT ); Thu, 3 Aug 2023 14:02:17 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F1954695 for ; Thu, 3 Aug 2023 11:01:23 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-68783b2e40bso873686b3a.3 for ; Thu, 03 Aug 2023 11:01:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085679; x=1691690479; 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=/SWdbLlCMTnsfDgjj0hJXL2JTXfe1aLJEQPkrac/1+s=; b=D2G3HiLpmiaQgiit5Uw5A+KyEHMgDrbX4OUobJfTY5xZLp+QrgoNkT2MrhFFEyepif NGS8bIEgxHx46b2qZaLXX0Y0SmZd7FsXd1pRwMLzsoEhtQ8pcPTRJawrVIj/nWamed2p c8Ow5XHa5oDci6OFZ2uyC29mSIkYFExo2ugvnfWshx5bUl5bbLWflApdPwz7r/8MPdiM lWTXRBs2gyD03CeRJIWHuRF1YcIOZcbbXk5w4VPmjVHxhOze/aVypsDeH0+qQb104tHd EPWaTU8ZA96yj8ruCaOH+vJ45kbEIP06MY4/8eq+kYWiPKbchSKHc0XwVBcVevJ8/Xa6 Exvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085679; x=1691690479; 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=/SWdbLlCMTnsfDgjj0hJXL2JTXfe1aLJEQPkrac/1+s=; b=a8TjN2cgd4j54qFbkJs7U3eXtrRjHWCFGi0JBOiCJw3l69UTBn3B/CkS9tqvUQN1Ak 2YL+kB1qCKFHxUvdzWPteGmpSwBe7yumOLzyzzgqOA+ayIvJ+Ky+2ylYhziUIx6rmlhB SAZav+fRK5Hdq5pWxisXknMcaU6PWy1iGPifhLVNPaMOhtABWbz27jYat5/PrXYXlkWO 6bcZyLfOdMT5B85KZz9lfwA3/UYldkHqh0UjyiEXX6EHF1HNEqQzhljyHq+QGFlhhJYq /8KbsDAO+Rxe4BtlBEqetVVrEmPWneJK1sBTXVKPnbLpfs4KLw0e3QNu/pI1jBNGgzyH Gu7g== X-Gm-Message-State: AOJu0YxX2ORrCQISkbcWAWLyb8NvaM6xvW7QSCYp5FpKtydTuFhVR17o tDfuOvTJ4UHFQua5wumRoHdqvw== X-Google-Smtp-Source: AGHT+IFGyUpuHPIut+tVQuZEcz6NanuBhvrn3iSa68PTIe5J1FDlay1VOOe28UUCGaj1xOLlQOJYFA== X-Received: by 2002:a05:6a20:72a0:b0:13f:8a5f:ad8e with SMTP id o32-20020a056a2072a000b0013f8a5fad8emr1930770pzk.58.1691085678868; Thu, 03 Aug 2023 11:01:18 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.01.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:01:18 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 14/21] ACPI: bus: Add acpi_riscv_init function Date: Thu, 3 Aug 2023 23:29:09 +0530 Message-Id: <20230803175916.3174453-15-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add a new function for RISC-V to do any architecture specific initialization. This function will be used to create platform devices like APLIC, IMSIC MSI controller, RISC-V IOMMU etc. Signed-off-by: Sunil V L --- drivers/acpi/bus.c | 1 + drivers/acpi/riscv/Makefile | 2 +- drivers/acpi/riscv/init.c | 12 ++++++++++++ include/linux/acpi.h | 6 ++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 drivers/acpi/riscv/init.c diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 2fc2b43a4ed3..9a8c16170a4b 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -1388,6 +1388,7 @@ static int __init acpi_init(void) pci_mmcfg_late_init(); acpi_arm_init(); + acpi_riscv_init(); acpi_viot_early_init(); acpi_hest_init(); acpi_ghes_init(); diff --git a/drivers/acpi/riscv/Makefile b/drivers/acpi/riscv/Makefile index 8b664190d172..3433a19c421d 100644 --- a/drivers/acpi/riscv/Makefile +++ b/drivers/acpi/riscv/Makefile @@ -1,2 +1,2 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y += rhct.o irqchip.o +obj-y += rhct.o irqchip.o init.o diff --git a/drivers/acpi/riscv/init.c b/drivers/acpi/riscv/init.c new file mode 100644 index 000000000000..b5807bbdb171 --- /dev/null +++ b/drivers/acpi/riscv/init.c @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023, Ventana Micro Systems Inc + * Author: Sunil V L + * + */ + +#include + +void __init acpi_riscv_init(void) +{ +} diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 641dc4843987..d16739928888 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1511,6 +1511,12 @@ void acpi_arm_init(void); static inline void acpi_arm_init(void) { } #endif +#ifdef CONFIG_RISCV +void acpi_riscv_init(void); +#else +static inline void acpi_riscv_init(void) { } +#endif + #ifdef CONFIG_ACPI_PCC void acpi_init_pcc(void); #else From patchwork Thu Aug 3 17:59:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 709664 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6F27C04E69 for ; Thu, 3 Aug 2023 18:03:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229904AbjHCSDQ (ORCPT ); Thu, 3 Aug 2023 14:03:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235184AbjHCSCU (ORCPT ); Thu, 3 Aug 2023 14:02:20 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01AAB420F for ; Thu, 3 Aug 2023 11:01:29 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-686b9964ae2so889247b3a.3 for ; Thu, 03 Aug 2023 11:01:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085686; x=1691690486; 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=9aQz/o5NvlReZUl/stpeRs4o5FY0c8qnUYDCfHqNmJI=; b=Yv3oRH7T1TZNQw/AeEOc/wdAwvfBHh5qCQDTqqhRRIWLN2RT7duj6j3Mlz5B+tyUjx DwzXxTjoAWH+iw6CkKfwMxF9xCniQjo3B09L5BaQ+m3yDEsvvlfRGxAUpVXc7dZmfqkz PN5+8DYtk9mthHfXcWzvd40WNmLxpaQLT+X3GYJHhIU0xy+P4PfNU1GlwdTTN0c2vXWS N5M/tFDrDNAY9aGtxjAy1r+U43wKUASBkf3zWtuZ0PK/OlWurnWRvhkcieTUH/K57kZ9 QHExlMok+1N1kt3iHzoySeHMoWERDl2+R1ayM9E29ohmdQ7YVT4UT939xn3e7d7QWGc0 3iwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085686; x=1691690486; 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=9aQz/o5NvlReZUl/stpeRs4o5FY0c8qnUYDCfHqNmJI=; b=QXnN8v/RzO5acSyLGKBBm3kvtILkUjUcvhIVxGeKsTfaYUcAD2uJTax59GEwAxPjGP o3hdFiGR9dKCEOiQn3MTmfUOZahZqsAcep8qTyd8K54YBydVbRq5ZGfNql3n3Fi35/VX sjchpNkfsTCs4dy4szwV3n/wrU3LpObHN9XVoytSGwHaUnDWEzaSbBVrPgZZcCP0pfhI EEs2BwM15a7tQmT49ndvZs4MpWi0Pejs5yy0TwG7zec/HA4v/QVKmsyqnbQiQ5znIutb JsFNqiwleI26aT5bYTCPytM7IW3V4mTQNq6KqiKbmSZnWzPJHEypm/eL+/K4gbjUB3QO a0eQ== X-Gm-Message-State: ABy/qLZEKraU8WvgTz79q0wpzsnwGpQ5TyYze5Frh9j9csLGvpx4Rwta o78iIRPgeqfoExNEj+IJ72hG5A== X-Google-Smtp-Source: APBJJlGAchtJBdt5IHqdaCzjHt1kkOK9wPe4WveHGvpGtfcTQHQdjS3NSncu/qTOIgVracHNUgSdbg== X-Received: by 2002:a05:6a20:3d91:b0:132:c07c:f042 with SMTP id s17-20020a056a203d9100b00132c07cf042mr22166693pzi.15.1691085686344; Thu, 03 Aug 2023 11:01:26 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:01:26 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 15/21] ACPI: RISC-V: Create IMSIC platform device Date: Thu, 3 Aug 2023 23:29:10 +0530 Message-Id: <20230803175916.3174453-16-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The MSI controller functionality of the RISC-V IMSIC is probed as a platform device by the driver. So, create the IMSIC platform device if the IMSIC was discovered in MADT during early IMSIC driver probe. Signed-off-by: Sunil V L --- drivers/acpi/riscv/init.c | 2 ++ drivers/acpi/riscv/init.h | 4 ++++ drivers/acpi/riscv/irqchip.c | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 drivers/acpi/riscv/init.h diff --git a/drivers/acpi/riscv/init.c b/drivers/acpi/riscv/init.c index b5807bbdb171..be61c08ea385 100644 --- a/drivers/acpi/riscv/init.c +++ b/drivers/acpi/riscv/init.c @@ -6,7 +6,9 @@ */ #include +#include "init.h" void __init acpi_riscv_init(void) { + riscv_acpi_imsic_platform_init(); } diff --git a/drivers/acpi/riscv/init.h b/drivers/acpi/riscv/init.h new file mode 100644 index 000000000000..a2f72bb294d3 --- /dev/null +++ b/drivers/acpi/riscv/init.h @@ -0,0 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include + +void __init riscv_acpi_imsic_platform_init(void); diff --git a/drivers/acpi/riscv/irqchip.c b/drivers/acpi/riscv/irqchip.c index 6e15d45cb229..ca96bf109cf7 100644 --- a/drivers/acpi/riscv/irqchip.c +++ b/drivers/acpi/riscv/irqchip.c @@ -9,7 +9,10 @@ #include #include #include +#include +#include #include +#include "../../../drivers/pci/pci.h" struct riscv_irqchip_list { struct fwnode_handle *fwnode; @@ -101,3 +104,23 @@ struct fwnode_handle *acpi_riscv_get_msi_fwnode(struct device *dev) { return imsic_acpi_fwnode; } + +void __init riscv_acpi_imsic_platform_init(void) +{ + struct platform_device *pdev; + int ret; + + if (!acpi_riscv_get_msi_fwnode(NULL)) { + pci_no_msi(); + return; + } + + pdev = platform_device_alloc("riscv-imsic", 0); + if (!pdev) + return; + + pdev->dev.fwnode = acpi_riscv_get_msi_fwnode(NULL); + ret = platform_device_add(pdev); + if (ret) + platform_device_put(pdev); +} From patchwork Thu Aug 3 17:59:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 710928 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6BCCC04FE0 for ; Thu, 3 Aug 2023 18:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232299AbjHCSDR (ORCPT ); Thu, 3 Aug 2023 14:03:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230526AbjHCSCj (ORCPT ); Thu, 3 Aug 2023 14:02:39 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA88E4C07 for ; Thu, 3 Aug 2023 11:01:38 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-686b643df5dso901618b3a.1 for ; Thu, 03 Aug 2023 11:01:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085694; x=1691690494; 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=95yH1ZRY1l5+vMULtm7DKGPnoBqPk/7PEb2F1bhVxfo=; b=V2wPisBDGbePHms2A4risrsDPrMUWBaceOkrdFeRUdqmk8sYzA5KDWJo5ROYiF0CjX Z74IQMZ1avQxf45hCxGVP3uqUF/sUXX9QWVu+q4wSB19tXd6YUul2EoHn+erVyy3sXpW Jwz/h2pkxAshzi43we+dfVrIdTOcl++Q/N4ri/20PthUznYPeIaLZpuiw1cnyJwnvSDM pcI9H5/RIULmGhhKhSoYJUA3vVFvfyjZhhZxhPigphk2shP6Errk5T1R3GEjLQvcK1W+ BuCSuJIxsNVj9LrjOIwPOA0PDc0afRT+ExMZ+FldLPxVOWhYHGBeKMhWgQmR5Pe/ln4m 1JKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085694; x=1691690494; 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=95yH1ZRY1l5+vMULtm7DKGPnoBqPk/7PEb2F1bhVxfo=; b=OOsO1SbqlhyMdrCaZiYXtGSN/xHS2Qig/SestOzvpcA0SUDD56q4Yp6zQggZZe/2cl tJhOsF83QbGVwGJf0s0CBzpmfVKlucusPTUtsuC+mTpOW14rs0lQZ8GnfYJTgVVHMCzn fLYh2ozCXoOoKipJk9UBb7wp8msVdKOftl53QrhtuCggmsZCUX7RcZ2h9vs98Jqh1h/x G3NVtM8x8i2kvF4JwDnzcTHBeV8bQR3MkFA445K9zpaZHrUbuKk9tXpa+Fxs3CVgEU4c iE0Ni/WtrV42YYvsRp3gBAoawa1wqRl5QF87PJCC81/UbH9VZptRJiTgN5xsbvoVD9p7 xW7w== X-Gm-Message-State: ABy/qLZZL/jLjjFvxQv9wVctmJyIPLRz0iWMZtWzz7o8ondFj8A/Y+gD QBrdU5bivgdMETnKk5DJYVcx9g== X-Google-Smtp-Source: APBJJlGnVuM193+CpDLoy7mFWMwR938XQnrV4s+XW2zz4aJ0EBbZLOLGESYCRhXm5hyH4ZPKVToj3A== X-Received: by 2002:a05:6a00:843:b0:67a:9208:87a with SMTP id q3-20020a056a00084300b0067a9208087amr21529015pfk.23.1691085693539; Thu, 03 Aug 2023 11:01:33 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:01:33 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 16/21] ACPI: Add APLIC IRQ model for RISC-V Date: Thu, 3 Aug 2023 23:29:11 +0530 Message-Id: <20230803175916.3174453-17-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add the IRQ model for RISC-V APLIC so that acpi_set_irq_model can use this for RISC-V. Signed-off-by: Sunil V L --- drivers/acpi/bus.c | 3 +++ include/linux/acpi.h | 1 + 2 files changed, 4 insertions(+) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 9a8c16170a4b..dd9d80630bf6 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -1132,6 +1132,9 @@ static int __init acpi_bus_init_irq(void) case ACPI_IRQ_MODEL_LPIC: message = "LPIC"; break; + case ACPI_IRQ_MODEL_APLIC: + message = "APLIC"; + break; default: pr_info("Unknown interrupt routing model\n"); return -ENODEV; diff --git a/include/linux/acpi.h b/include/linux/acpi.h index d16739928888..698d120a1bd2 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -95,6 +95,7 @@ enum acpi_irq_model_id { ACPI_IRQ_MODEL_PLATFORM, ACPI_IRQ_MODEL_GIC, ACPI_IRQ_MODEL_LPIC, + ACPI_IRQ_MODEL_APLIC, ACPI_IRQ_MODEL_COUNT }; From patchwork Thu Aug 3 17:59:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 709663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66E0CC001DF for ; Thu, 3 Aug 2023 18:03:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230246AbjHCSDe (ORCPT ); Thu, 3 Aug 2023 14:03:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235635AbjHCSDC (ORCPT ); Thu, 3 Aug 2023 14:03:02 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BBDF4EDF for ; Thu, 3 Aug 2023 11:01:50 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686d8c8fc65so915104b3a.0 for ; Thu, 03 Aug 2023 11:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085702; x=1691690502; 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=MqlDPHKEWaBxTYs/0M8htriIKOWDT6nuJRMhsrHXzuE=; b=Mck7EqqRTTHdMEBXbHLoZwfOLdXJUnVodFv/es6odb8/Qq21nUhzlxmcrCQpHegUV1 qKWa65jRjHgYqT8ANyBw+GVASKqCOwBtVtvNwTQ9NuaGjcZ06UVpzTbD4zoHTAFAiZAq bC+kKVzDGdpGns7pLFPMO4CYn2tXf14kK4mXYgydh1+8YK5+ZpXO+dgkvzgwmGncgRDC EBqiRVaPJMAiim+QopcXM5/33h+EYYtGMCn9nVz286lZO7qUY51KfF5NwHxIJsTOYCRL nNpgZRPcRYp3J92EJNQFHRsHz+vYpZwdP4h6z60CpUAwZ3rmeewQu9jN+Ugw4weQY+0J wUTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085702; x=1691690502; 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=MqlDPHKEWaBxTYs/0M8htriIKOWDT6nuJRMhsrHXzuE=; b=L5lgZFajNp0aupok5gOsV+cOgzvY1Ne2ZkhXUET9BwsUeyDEkAQXX9fXzgMcm/VFQh M2puzZz6mh24pUxv/BlFmNC6ZRj1wtDlFsYJevxlflBtZcWHm0x/rkktIAquq6fr+Im/ 1OMvRjAJIT3fvVqs/P/0HK6nTZPaAekX80FJzL5H391df1K3FB5vbwwmKRf6jy2tEMJ4 hQ8udQpSgsq+7wuy3GDO/IL9CbMxJvG+tYBwszjzMlIKuQPtuz+wWiqgDfyH/tBjfALu 5W9qarv3q7BCpNFdBMQj4gnz7JWISD/w+N6oE6h4wncaWhUN1ybRwY2vbLXLTkJ0a9UY 29lg== X-Gm-Message-State: ABy/qLYWGJGgd6+nVB8RW8pA6fU3LhoQsIYBnLBPnKrx8O7JQDMXPD9n K42gopkyWchmb0jf+kO+iX0wJw== X-Google-Smtp-Source: APBJJlEpOrcULPp+uHqf2SkiWQTzFmTJeS1yI+fASG26f/nZjZ0ASal13fAyFeapUfbB4CtpRCGyhA== X-Received: by 2002:a05:6a21:3b44:b0:130:9638:36d4 with SMTP id zy4-20020a056a213b4400b00130963836d4mr15110479pzb.33.1691085701012; Thu, 03 Aug 2023 11:01:41 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.01.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:01:40 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 17/21] ACPI: RISC-V: Create APLIC platform device Date: Thu, 3 Aug 2023 23:29:12 +0530 Message-Id: <20230803175916.3174453-18-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Since APLIC needs to be a platform device, probe the MADT and create platform devices for each APLIC in the system. Use software node framework for the fwnode which allows to create properties and hence the actual irqchip driver doesn't need to do anything different for ACPI vs DT. Signed-off-by: Sunil V L --- Documentation/riscv/acpi.rst | 6 ++ drivers/acpi/riscv/init.c | 1 + drivers/acpi/riscv/init.h | 1 + drivers/acpi/riscv/irqchip.c | 183 +++++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+) diff --git a/Documentation/riscv/acpi.rst b/Documentation/riscv/acpi.rst index e2406546bc16..9ea9008288ea 100644 --- a/Documentation/riscv/acpi.rst +++ b/Documentation/riscv/acpi.rst @@ -29,3 +29,9 @@ properties are created using the data in MADT table. ``riscv,ext-intc-id`` - The unique ID of the external interrupts connected to this hart. + +2) RISC-V Advanced Platform Level Interrupt Controller (APLIC) +----------- + +``riscv,gsi-base`` - The global system interrupt number where this APLIC’s +interrupt inputs start. diff --git a/drivers/acpi/riscv/init.c b/drivers/acpi/riscv/init.c index be61c08ea385..ee747211174f 100644 --- a/drivers/acpi/riscv/init.c +++ b/drivers/acpi/riscv/init.c @@ -11,4 +11,5 @@ void __init acpi_riscv_init(void) { riscv_acpi_imsic_platform_init(); + riscv_acpi_aplic_platform_init(); } diff --git a/drivers/acpi/riscv/init.h b/drivers/acpi/riscv/init.h index a2f72bb294d3..17bcf0baaadb 100644 --- a/drivers/acpi/riscv/init.h +++ b/drivers/acpi/riscv/init.h @@ -2,3 +2,4 @@ #include void __init riscv_acpi_imsic_platform_init(void); +void __init riscv_acpi_aplic_platform_init(void); diff --git a/drivers/acpi/riscv/irqchip.c b/drivers/acpi/riscv/irqchip.c index ca96bf109cf7..7fb7befdb303 100644 --- a/drivers/acpi/riscv/irqchip.c +++ b/drivers/acpi/riscv/irqchip.c @@ -23,6 +23,8 @@ LIST_HEAD(rintc_list); static struct fwnode_handle *imsic_acpi_fwnode; +LIST_HEAD(aplic_list); + struct fwnode_handle *acpi_rintc_create_irqchip_fwnode(struct acpi_madt_rintc *rintc) { struct property_entry props[6] = {}; @@ -124,3 +126,184 @@ void __init riscv_acpi_imsic_platform_init(void) if (ret) platform_device_put(pdev); } + +/* + * The ext_intc_id format is as follows: + * Bits [31:24] APLIC/PLIC ID + * Bits [15:0] APLIC IDC ID / PLIC S-Mode Context ID for this hart + */ +#define APLIC_PLIC_ID(x) ((x) >> 24) +#define IDC_CONTEXT_ID(x) ((x) & 0x0000ffff) + +static struct fwnode_handle *acpi_ext_intc_get_rintc_fwnode(u8 aplic_plic_id, u16 index) +{ + struct riscv_irqchip_list *rintc_element; + struct fwnode_handle *fwnode; + struct list_head *i, *tmp; + u32 id; + int rc; + + list_for_each_safe(i, tmp, &rintc_list) { + rintc_element = list_entry(i, struct riscv_irqchip_list, list); + fwnode = rintc_element->fwnode; + rc = fwnode_property_read_u32_array(fwnode, "riscv,ext-intc-id", &id, 1); + if (rc) + continue; + + if ((APLIC_PLIC_ID(id) == aplic_plic_id) && (IDC_CONTEXT_ID(id) == index)) + return fwnode; + } + + return NULL; +} + +static struct fwnode_handle *acpi_aplic_create_fwnode(struct acpi_madt_aplic *aplic) +{ + struct fwnode_handle *fwnode, *parent_fwnode; + struct riscv_irqchip_list *aplic_element; + struct software_node_ref_args *refs; + struct property_entry props[8] = {}; + unsigned int i; + + props[0] = PROPERTY_ENTRY_U32("riscv,gsi-base", aplic->gsi_base); + props[1] = PROPERTY_ENTRY_U32("riscv,num-sources", aplic->num_sources); + props[2] = PROPERTY_ENTRY_U32("riscv,num-idcs", aplic->num_idcs); + props[3] = PROPERTY_ENTRY_U32("riscv,aplic-id", aplic->id); + props[4] = PROPERTY_ENTRY_U64("riscv,aplic-base", aplic->base_addr); + props[5] = PROPERTY_ENTRY_U32("riscv,aplic-size", aplic->size); + if (aplic->num_idcs) { + refs = kcalloc(aplic->num_idcs, sizeof(*refs), GFP_KERNEL); + if (!refs) + return NULL; + + for (i = 0; i < aplic->num_idcs; i++) { + parent_fwnode = acpi_ext_intc_get_rintc_fwnode(aplic->id, i); + refs[i] = SOFTWARE_NODE_REFERENCE(to_software_node(parent_fwnode), + RV_IRQ_EXT); + } + props[6] = PROPERTY_ENTRY_REF_ARRAY_LEN("interrupts-extended", + refs, aplic->num_idcs); + } else { + props[6] = PROPERTY_ENTRY_BOOL("msi-parent"); + } + + fwnode = fwnode_create_software_node_early(props, NULL); + + if (fwnode) { + aplic_element = kzalloc(sizeof(*aplic_element), GFP_KERNEL); + if (!aplic_element) { + fwnode_remove_software_node(fwnode); + return NULL; + } + + aplic_element->fwnode = fwnode; + list_add_tail(&aplic_element->list, &aplic_list); + } + + return fwnode; +} + +static struct fwnode_handle *aplic_get_gsi_domain_id(u32 gsi) +{ + struct riscv_irqchip_list *aplic_element; + struct fwnode_handle *fwnode; + struct list_head *i, *tmp; + u32 gsi_base; + u32 nr_irqs; + int rc; + + list_for_each_safe(i, tmp, &aplic_list) { + aplic_element = list_entry(i, struct riscv_irqchip_list, list); + fwnode = aplic_element->fwnode; + rc = fwnode_property_read_u32_array(fwnode, "riscv,gsi-base", &gsi_base, 1); + if (!rc) { + rc = fwnode_property_read_u32_array(fwnode, "riscv,num-sources", + &nr_irqs, 1); + if (!rc && (gsi >= gsi_base && gsi < gsi_base + nr_irqs)) + return fwnode; + } + } + + return NULL; +} + +static u32 __init aplic_gsi_to_irq(u32 gsi) +{ + return acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_HIGH); +} + +static int __init aplic_create_platform_device(struct fwnode_handle *fwnode) +{ + struct platform_device *pdev; + u32 aplic_size, aplic_id; + struct resource *res; + u64 aplic_base; + int ret; + + if (!fwnode) + return -ENODEV; + + ret = fwnode_property_read_u64_array(fwnode, "riscv,aplic-base", &aplic_base, 1); + if (ret) + return -ENODEV; + + ret = fwnode_property_read_u32_array(fwnode, "riscv,aplic-size", &aplic_size, 1); + if (ret) + return -ENODEV; + + ret = fwnode_property_read_u32_array(fwnode, "riscv,aplic-id", &aplic_id, 1); + if (ret) + return -ENODEV; + + pdev = platform_device_alloc("riscv-aplic", aplic_id); + if (!pdev) + return -ENOMEM; + + res = kcalloc(1, sizeof(*res), GFP_KERNEL); + if (!res) { + ret = -ENOMEM; + goto dev_put; + } + + res->start = aplic_base; + res->end = res->start + aplic_size - 1; + res->flags = IORESOURCE_MEM; + ret = platform_device_add_resources(pdev, res, 1); + /* + * Resources are duplicated in platform_device_add_resources, + * free their allocated memory + */ + kfree(res); + + pdev->dev.fwnode = fwnode; + ret = platform_device_add(pdev); + if (ret) + goto dev_put; + + return 0; + +dev_put: + platform_device_put(pdev); + return ret; +} + +static int __init aplic_parse_madt(union acpi_subtable_headers *header, + const unsigned long end) +{ + struct acpi_madt_aplic *aplic = (struct acpi_madt_aplic *)header; + struct fwnode_handle *fwnode; + + fwnode = acpi_aplic_create_fwnode(aplic); + if (fwnode) + aplic_create_platform_device(fwnode); + + return 0; +} + +void __init riscv_acpi_aplic_platform_init(void) +{ + if (acpi_table_parse_madt(ACPI_MADT_TYPE_APLIC, aplic_parse_madt, 0) > 0) { + acpi_set_irq_model(ACPI_IRQ_MODEL_APLIC, aplic_get_gsi_domain_id); + acpi_set_gsi_to_irq_fallback(aplic_gsi_to_irq); + } +} From patchwork Thu Aug 3 17:59:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 710927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4DF9C001DF for ; Thu, 3 Aug 2023 18:03:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235184AbjHCSDq (ORCPT ); Thu, 3 Aug 2023 14:03:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235711AbjHCSDK (ORCPT ); Thu, 3 Aug 2023 14:03:10 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E3A94225 for ; Thu, 3 Aug 2023 11:01:59 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-686f090310dso1141745b3a.0 for ; Thu, 03 Aug 2023 11:01:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085709; x=1691690509; 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=F92frfK1dVqJ4xjy+nPCRdMbjnNZ2BaLZfo5RMrgYGc=; b=nb8MJ8FxfTXSyHfmc46NJ78oznoJARBEyZYQLu78F886UEH05u96pGX7PrrDE+ABPy g7Q9FL6hPeKgIvk1x1g1QIiXUI+eSCTn4U5OllRWdrxcoVajrrjHY50vfrwXSfjJ56rj kDL+iKNMiAcr3+BY7DKMcKwbrcyTolBMjohszwHk8Iqo0oHT6OJUhtHPMDjrZMpsSVf8 do6JnoL+oBRfutMZgfrvxiD/OLmiQhPDP+a9oLSuKJQQ+mEjyNMxYQbZ5QXaBFSdRNqr cB+pEseV+eVkFLVS2cVDEpQHb3FQjnP4sNhw8f1RnohhupWYwX5f1MNKLJwhFIFeh8bb Vzmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085709; x=1691690509; 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=F92frfK1dVqJ4xjy+nPCRdMbjnNZ2BaLZfo5RMrgYGc=; b=VSPjbb0UvJY70yXxRjShmagJ9Y+MXWyQ/d3DPfWwQrghCxLwgWVnqt1hC/Rh8m+uRm Sl8S7H9yzgLercvMj7ATQCP8VhMgSyYnMqiyJVd4wdVwhBGzoQEp5EIGWJd4fE9R4Hn9 tv9rakQlF3yeDRyW/pdmMwLfyzfMh/UKGa2EchtDsSYyd/IphxreMTfUVtR8HuUIG67s qtod/U4KpcS30mw13o4ozTYy0e8TsFWvfQwPxidXR1onq3pF+fGYHHt9nWXQLGc/X8gB 9CAofLUtztouQA5Bpa9YBfBu1ouIzZHDLrbK04ACuq/GeJ8TtcUNHGuf0tOLOfEvIZcD iQqw== X-Gm-Message-State: ABy/qLapdXnZu2HrGdT2GIuxRLRYbLral0pyVvGozVuAp67oVeEf7Mky R1+q+fDZn/uW7MXT5KdODNTP4w== X-Google-Smtp-Source: APBJJlF693fygn/wN+Kw+cdkTi4UZipebFggWTsaaGrmDPSMtSqjJpJsaZGp1ItDXnGYwlZwJ/3sSA== X-Received: by 2002:a05:6a00:1887:b0:687:7a30:deb with SMTP id x7-20020a056a00188700b006877a300debmr6591488pfh.15.1691085709034; Thu, 03 Aug 2023 11:01:49 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:01:48 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 18/21] irqchip/irq-riscv-aplic-msi: Add ACPI support Date: Thu, 3 Aug 2023 23:29:13 +0530 Message-Id: <20230803175916.3174453-19-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Search and configure the MSI domain for the APLIC on ACPI based systems. Signed-off-by: Sunil V L --- drivers/irqchip/irq-riscv-aplic-msi.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/irqchip/irq-riscv-aplic-msi.c b/drivers/irqchip/irq-riscv-aplic-msi.c index 086d00e0429e..1948444c9e0c 100644 --- a/drivers/irqchip/irq-riscv-aplic-msi.c +++ b/drivers/irqchip/irq-riscv-aplic-msi.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "irq-riscv-aplic-main.h" @@ -178,6 +179,8 @@ static void aplic_msi_write_msg(struct msi_desc *desc, struct msi_msg *msg) int aplic_msi_setup(struct device *dev, void __iomem *regs) { const struct imsic_global_config *imsic_global; + struct irq_domain *msi_domain = NULL; + struct fwnode_handle *msi_fwnode; struct irq_domain *irqdomain; struct aplic_priv *priv; struct aplic_msicfg *mc; @@ -261,8 +264,17 @@ int aplic_msi_setup(struct device *dev, void __iomem *regs) * IMSIC and the IMSIC MSI domains are created later through * the platform driver probing so we set it explicitly here. */ - if (is_of_node(dev->fwnode)) + if (is_of_node(dev->fwnode)) { of_msi_configure(dev, to_of_node(dev->fwnode)); + } else { + msi_fwnode = acpi_riscv_get_msi_fwnode(dev); + if (msi_fwnode) + msi_domain = irq_find_matching_fwnode(msi_fwnode, + DOMAIN_BUS_PLATFORM_MSI); + + if (msi_domain) + dev_set_msi_domain(dev, msi_domain); + } } /* Create irq domain instance for the APLIC MSI-mode */ From patchwork Thu Aug 3 17:59:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 709662 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90053C001DF for ; Thu, 3 Aug 2023 18:04:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235409AbjHCSD7 (ORCPT ); Thu, 3 Aug 2023 14:03:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235756AbjHCSDO (ORCPT ); Thu, 3 Aug 2023 14:03:14 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 670754233 for ; Thu, 3 Aug 2023 11:02:05 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6873a30d02eso866551b3a.3 for ; Thu, 03 Aug 2023 11:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085716; x=1691690516; 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=oa5JuUdn7+qjYPf/m5YirkX0l5WPw2pxjpAQ3vHoF5I=; b=KQbJbLeA4TGtIxIuFW6WC8NJApS9TUoRPunkwh/7C0r1L0sLBDwJGs8OUTxRfQN8yL IZgS1FD+/A7me33MFHYJD0l0yTtrtfiDYXF3e8iNfPm93ITz3TvFfxLpZrkvFjfajmGf EMdRXrFFA3X7X7YRRnEWo+UPpR2JQ9GgdKaKpv9xyaKOqY2AwIvxxCCF7PewHi3Faua6 jFe8/UkDo4eFfqQ4KvSjqlO/i1RJALvToWFdrastu4Qw7KsNlgXKVspIMSkXJgK5IbJo eJSEBF9ZP7B5NkjyH0BsRNEDtOJgtdIONOGak2Or0tgEW0/gVlXNtRRwCRBHdYyNBhLJ 6pIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085716; x=1691690516; 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=oa5JuUdn7+qjYPf/m5YirkX0l5WPw2pxjpAQ3vHoF5I=; b=OEJWR+8Qz6PVnLS5ypZWyzbBM9B/jwSU4HpYeCmPOTXHmDMF6Rm+ylCdoHzfJU9QIB fVN+FCfN9Bfd3LrImu+UFkt+BUjbQ0lcu/z4CPt+pAOsNGjyFQPTQ7tirXlXXIYBZEK3 e3BJHHehZB4CrjoiSOgLO90dnPMLyRrDHL7ncwKuTYHJOO5JHSnTLHIDrVZlABHRLJvM a4R2+9Czch+UQjAn3q4/ldoX3eQq6hQ0819kan93F0VohbnAXoxg5BYgLIkakh2XlfXw arfKOjxSlhzQYJUax45rD1LfaWMUOPNfXZ4vwYaLWzUNE/OmafDbPPgm4aYvavQWqBkt u65g== X-Gm-Message-State: ABy/qLagTuqDdsDl9KHenShft21WvK/cYvQm4Co40Qtg/LPsru+k85EG RY71nuxmAyZtck2esVeiMCpVtA== X-Google-Smtp-Source: APBJJlEdZK4VF6uWpmNFHink+0Aa6EYjLEIulHdNF+NehNeb7SxIQC3cwBrCreK5H/j8S4RNIEykOQ== X-Received: by 2002:a05:6a20:191:b0:12f:c61e:7cac with SMTP id 17-20020a056a20019100b0012fc61e7cacmr16449922pzy.31.1691085716659; Thu, 03 Aug 2023 11:01:56 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:01:56 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 19/21] ACPI: bus: Add PLIC IRQ model Date: Thu, 3 Aug 2023 23:29:14 +0530 Message-Id: <20230803175916.3174453-20-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add the IRQ model for RISC-V PLIC so that acpi_set_irq_model can use this for RISC-V. Signed-off-by: Haibo Xu Signed-off-by: Sunil V L --- drivers/acpi/bus.c | 3 +++ include/linux/acpi.h | 1 + 2 files changed, 4 insertions(+) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index dd9d80630bf6..68b8d38ec48a 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -1135,6 +1135,9 @@ static int __init acpi_bus_init_irq(void) case ACPI_IRQ_MODEL_APLIC: message = "APLIC"; break; + case ACPI_IRQ_MODEL_PLIC: + message = "PLIC"; + break; default: pr_info("Unknown interrupt routing model\n"); return -ENODEV; diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 698d120a1bd2..31f080df179d 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -96,6 +96,7 @@ enum acpi_irq_model_id { ACPI_IRQ_MODEL_GIC, ACPI_IRQ_MODEL_LPIC, ACPI_IRQ_MODEL_APLIC, + ACPI_IRQ_MODEL_PLIC, ACPI_IRQ_MODEL_COUNT }; From patchwork Thu Aug 3 17:59:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 710926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFFA2EB64DD for ; Thu, 3 Aug 2023 18:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235480AbjHCSEG (ORCPT ); Thu, 3 Aug 2023 14:04:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235778AbjHCSDQ (ORCPT ); Thu, 3 Aug 2023 14:03:16 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D39D49C1 for ; Thu, 3 Aug 2023 11:02:09 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-686ba29ccb1so869751b3a.1 for ; Thu, 03 Aug 2023 11:02:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085724; x=1691690524; 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=4+Q8KfNrcpLCQ+Zm4Z9cXmSMTUQ/Cx2NE3GzYzgbHwU=; b=TWzDXrq5rkDXP54lt1KXIhB7yRYTfDMnjicYqveI1Fv/QGFp5xa1yM7dqucAsYbXYH htp+oGPiIC+rC4eCLBCyGmtdcF8p3+QFwFxMOgrtdUFz6o4LbGtNAZWGo0DpXwodLlTq ZKvGdwZtZf2BXqFokABG7lCPfApf0Y8vwZUy+Ee1WBFXJUNK5UGwZsuE5I2KobJ3fI8x 4ByezcpRBxt/a5trnhAacwlm3z1zVcLLfLn4VmW4p4mQ7CmLjEqbX6UzsGsZGFCuov1G RnAKm5FwFaUNNZTLqCG57ZrMHp/PjpulrpD8pmQ6sDJDUl2BfiR0RJb7qyVpPYWSy8SY h7ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085724; x=1691690524; 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=4+Q8KfNrcpLCQ+Zm4Z9cXmSMTUQ/Cx2NE3GzYzgbHwU=; b=i/P5tpvZ7Mcx3AEWjM+9bW6KuMuTNTVNWqTHHwRgQBTT9yQK6Uu8a4UuYOVEhYvWJq JcBGuBySQorMh0/1mXaJ5e+FvN3qBmQgskr0MMhI8Rp5hJ4ykF0pgiDyrEmbYuei/4zP zZgTSGgtspfjoZHJEmUdnU6g7ORnTtpx0WnowG+mT6R+DkfdHhgzaRjg0SN0rlQhc6jB 3/eYVvb8FNwsU+oNxviCuA4HO022KFke+gtU6jPGj64eZXSXToSx/UnnwbzevQj3qOVs zxUYPEEQJo6PFzy1o+lYbM7rW7kHLaqZYfebbJSJ9AgrfaiNGL5G5hgNQ5wW/P4EZICS lM7Q== X-Gm-Message-State: ABy/qLaB3pgA0KMeATqamLRzCf3fL46GE3FKbgbCWLcxq4UTcu6tj4NU 57sizIT22n3seL2YlgBqYR4uYA== X-Google-Smtp-Source: APBJJlH/rurRin9y29M3aaOJtb8cTFXCf64b42mFfS4paTtxGXHirLrg+/10tPI3KDoH92gXeSNR0A== X-Received: by 2002:a05:6a00:2286:b0:687:570c:da2d with SMTP id f6-20020a056a00228600b00687570cda2dmr10882734pfe.12.1691085723889; Thu, 03 Aug 2023 11:02:03 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:02:03 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 20/21] RISC-V: ACPI: Create PLIC platform device Date: Thu, 3 Aug 2023 23:29:15 +0530 Message-Id: <20230803175916.3174453-21-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Since PLIC needs to be a platform device, probe the MADT and create platform devices for each PLIC in the system. Use software node framework for the fwnode which allows to create properties and hence the actual irqchip driver doesn't need to do anything different for ACPI vs DT. Signed-off-by: Sunil V L Co-developed-by: Haibo Xu Signed-off-by: Haibo Xu --- Documentation/riscv/acpi.rst | 6 ++ arch/riscv/include/asm/acpi.h | 3 + drivers/acpi/riscv/init.c | 1 + drivers/acpi/riscv/init.h | 1 + drivers/acpi/riscv/irqchip.c | 198 ++++++++++++++++++++++++++++++++++ 5 files changed, 209 insertions(+) diff --git a/Documentation/riscv/acpi.rst b/Documentation/riscv/acpi.rst index 9ea9008288ea..007483dfddc1 100644 --- a/Documentation/riscv/acpi.rst +++ b/Documentation/riscv/acpi.rst @@ -35,3 +35,9 @@ to this hart. ``riscv,gsi-base`` - The global system interrupt number where this APLIC’s interrupt inputs start. + +3) RISC-V Platform Level Interrupt Controller (PLIC) +----------- + +``riscv,gsi-base`` - The global system interrupt number where this PLIC’s +interrupt inputs start. diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h index 6dde3d63dc0e..163b8eefa744 100644 --- a/arch/riscv/include/asm/acpi.h +++ b/arch/riscv/include/asm/acpi.h @@ -71,6 +71,7 @@ int acpi_get_cbo_block_size(struct acpi_table_header *table, unsigned int cpu, u struct fwnode_handle *acpi_rintc_create_irqchip_fwnode(struct acpi_madt_rintc *rintc); struct fwnode_handle *acpi_imsic_create_fwnode(struct acpi_madt_imsic *imsic); struct fwnode_handle *acpi_riscv_get_msi_fwnode(struct device *dev); +int acpi_plic_get_context_id(u8 plic_id, u16 idx); #else static inline void acpi_init_rintc_map(void) { } static inline struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu) @@ -95,6 +96,8 @@ static inline struct fwnode_handle *acpi_riscv_get_msi_fwnode(struct device *dev { return NULL; } + +static inline int acpi_plic_get_context_id(u8 plic_id, u16 idx) { return idx; } #endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ diff --git a/drivers/acpi/riscv/init.c b/drivers/acpi/riscv/init.c index ee747211174f..cc733ea9ef1d 100644 --- a/drivers/acpi/riscv/init.c +++ b/drivers/acpi/riscv/init.c @@ -12,4 +12,5 @@ void __init acpi_riscv_init(void) { riscv_acpi_imsic_platform_init(); riscv_acpi_aplic_platform_init(); + riscv_acpi_plic_platform_init(); } diff --git a/drivers/acpi/riscv/init.h b/drivers/acpi/riscv/init.h index 17bcf0baaadb..b4b305d83b3a 100644 --- a/drivers/acpi/riscv/init.h +++ b/drivers/acpi/riscv/init.h @@ -3,3 +3,4 @@ void __init riscv_acpi_imsic_platform_init(void); void __init riscv_acpi_aplic_platform_init(void); +void __init riscv_acpi_plic_platform_init(void); diff --git a/drivers/acpi/riscv/irqchip.c b/drivers/acpi/riscv/irqchip.c index 7fb7befdb303..cb70f0f2294b 100644 --- a/drivers/acpi/riscv/irqchip.c +++ b/drivers/acpi/riscv/irqchip.c @@ -25,6 +25,8 @@ static struct fwnode_handle *imsic_acpi_fwnode; LIST_HEAD(aplic_list); +LIST_HEAD(plic_list); + struct fwnode_handle *acpi_rintc_create_irqchip_fwnode(struct acpi_madt_rintc *rintc) { struct property_entry props[6] = {}; @@ -307,3 +309,199 @@ void __init riscv_acpi_aplic_platform_init(void) acpi_set_gsi_to_irq_fallback(aplic_gsi_to_irq); } } + +static int acpi_plic_get_nr_contexts(u8 plic_id) +{ + struct riscv_irqchip_list *rintc_element; + struct fwnode_handle *fwnode; + struct list_head *i, *tmp; + u32 id; + int rc, nr_contexts = 0; + + list_for_each_safe(i, tmp, &rintc_list) { + rintc_element = list_entry(i, struct riscv_irqchip_list, list); + fwnode = rintc_element->fwnode; + rc = fwnode_property_read_u32_array(fwnode, "riscv,ext-intc-id", &id, 1); + if (rc) + continue; + + if (APLIC_PLIC_ID(id) == plic_id) + nr_contexts++; + } + + return nr_contexts * 2; +} + +int acpi_plic_get_context_id(u8 plic_id, u16 idx) +{ + struct riscv_irqchip_list *rintc_element; + struct fwnode_handle *fwnode; + struct list_head *i, *tmp; + u32 id; + int rc, nr_contexts = -1; + + list_for_each_safe(i, tmp, &rintc_list) { + rintc_element = list_entry(i, struct riscv_irqchip_list, list); + fwnode = rintc_element->fwnode; + rc = fwnode_property_read_u32_array(fwnode, "riscv,ext-intc-id", &id, 1); + if (rc) + continue; + + if (APLIC_PLIC_ID(id) == plic_id) + nr_contexts++; + if (nr_contexts == idx) + return IDC_CONTEXT_ID(id); + } + + return -1; +} + +static struct fwnode_handle *acpi_plic_create_fwnode(struct acpi_madt_plic *plic) +{ + struct fwnode_handle *fwnode, *parent_fwnode; + struct riscv_irqchip_list *plic_element; + struct software_node_ref_args *refs; + struct property_entry props[8] = {}; + int nr_contexts; + + props[0] = PROPERTY_ENTRY_U32("riscv,gsi-base", plic->gsi_base); + props[1] = PROPERTY_ENTRY_U32("riscv,ndev", plic->num_irqs); + props[2] = PROPERTY_ENTRY_U32("riscv,max_prio", plic->max_prio); + props[3] = PROPERTY_ENTRY_U8("riscv,plic-id", plic->id); + props[4] = PROPERTY_ENTRY_U64("riscv,plic-base", plic->base_addr); + props[5] = PROPERTY_ENTRY_U32("riscv,plic-size", plic->size); + + nr_contexts = acpi_plic_get_nr_contexts(plic->id); + if (nr_contexts) { + refs = kcalloc(nr_contexts, sizeof(*refs), GFP_KERNEL); + for (int i = 0; i < nr_contexts / 2; i++) { + int context_id = acpi_plic_get_context_id(plic->id, i); + + parent_fwnode = acpi_ext_intc_get_rintc_fwnode(plic->id, context_id); + refs[2 * i] = SOFTWARE_NODE_REFERENCE(to_software_node(parent_fwnode), 0); + refs[2 * i + 1] = SOFTWARE_NODE_REFERENCE(to_software_node(parent_fwnode), + RV_IRQ_EXT); + } + props[6] = PROPERTY_ENTRY_REF_ARRAY_LEN("interrupts-extended", refs, nr_contexts); + } + + fwnode = fwnode_create_software_node_early(props, NULL); + + if (fwnode) { + plic_element = kzalloc(sizeof(*plic_element), GFP_KERNEL); + if (!plic_element) { + fwnode_remove_software_node(fwnode); + return NULL; + } + + plic_element->fwnode = fwnode; + list_add_tail(&plic_element->list, &plic_list); + } + + return fwnode; +} + +static struct fwnode_handle *plic_get_gsi_domain_id(u32 gsi) +{ + struct riscv_irqchip_list *plic_element; + struct fwnode_handle *fwnode; + struct list_head *i, *tmp; + u32 gsi_base; + u32 nr_irqs; + int rc; + + list_for_each_safe(i, tmp, &plic_list) { + plic_element = list_entry(i, struct riscv_irqchip_list, list); + fwnode = plic_element->fwnode; + rc = fwnode_property_read_u32_array(fwnode, "riscv,gsi-base", &gsi_base, 1); + if (!rc) { + rc = fwnode_property_read_u32_array(fwnode, "riscv,ndev", &nr_irqs, 1); + if (!rc && (gsi >= gsi_base && gsi < gsi_base + nr_irqs)) + return fwnode; + } + } + + return NULL; +} + +static u32 plic_gsi_to_irq(u32 gsi) +{ + return acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_HIGH); +} + +static int __init plic_create_platform_device(struct fwnode_handle *fwnode) +{ + struct platform_device *pdev; + u32 plic_size; + u8 plic_id; + struct resource *res; + u64 plic_base; + int ret; + + if (!fwnode) + return -ENODEV; + + ret = fwnode_property_read_u64_array(fwnode, "riscv,plic-base", &plic_base, 1); + if (ret) + return -ENODEV; + + ret = fwnode_property_read_u32_array(fwnode, "riscv,plic-size", &plic_size, 1); + if (ret) + return -ENODEV; + + ret = fwnode_property_read_u8_array(fwnode, "riscv,plic-id", &plic_id, 1); + if (ret) + return -ENODEV; + + pdev = platform_device_alloc("riscv-plic", plic_id); + if (!pdev) + return -ENOMEM; + + res = kcalloc(1, sizeof(*res), GFP_KERNEL); + if (!res) { + ret = -ENOMEM; + goto dev_put; + } + + res->start = plic_base; + res->end = res->start + plic_size - 1; + res->flags = IORESOURCE_MEM; + ret = platform_device_add_resources(pdev, res, 1); + /* + * Resources are duplicated in platform_device_add_resources, + * free their allocated memory + */ + kfree(res); + + pdev->dev.fwnode = fwnode; + ret = platform_device_add(pdev); + if (ret) + goto dev_put; + + return 0; + +dev_put: + platform_device_put(pdev); + return ret; +} + +static int __init plic_parse_madt(union acpi_subtable_headers *header, + const unsigned long end) +{ + struct acpi_madt_plic *plic = (struct acpi_madt_plic *)header; + struct fwnode_handle *fwnode; + + fwnode = acpi_plic_create_fwnode(plic); + if (fwnode) + plic_create_platform_device(fwnode); + + return 0; +} + +void __init riscv_acpi_plic_platform_init(void) +{ + if (acpi_table_parse_madt(ACPI_MADT_TYPE_PLIC, plic_parse_madt, 0) > 0) { + acpi_set_irq_model(ACPI_IRQ_MODEL_PLIC, plic_get_gsi_domain_id); + acpi_set_gsi_to_irq_fallback(plic_gsi_to_irq); + } +} From patchwork Thu Aug 3 17:59:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 709661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2612FC001DB for ; Thu, 3 Aug 2023 18:04:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231991AbjHCSEQ (ORCPT ); Thu, 3 Aug 2023 14:04:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231580AbjHCSDf (ORCPT ); Thu, 3 Aug 2023 14:03:35 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2252F448A for ; Thu, 3 Aug 2023 11:02:17 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-686f090310dso1142112b3a.0 for ; Thu, 03 Aug 2023 11:02:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085731; x=1691690531; 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=6v/OYLYVQR57/X+MrAxBhstfGEPE9Vxe5lIE5dFdYi8=; b=AeOusJd65H1nN1T0NetBGmbqBfBlOSImAu7Uelx9yA3pASs2f7sefFvXswRe4EVo2O CvUG6NJ6T0Pauy/FEY1z5ifwQKaQ06fZ/QslUnSfxbFdlQQHr+pvPalyXWSwjuG3lGFe N1LN4E6rnrgXD+zSMCTdgWsdIH0dBVzy56DIMSqXW0LgorqgduoErF2Wbz+QyBps81Ai wV5S04bojOgDVv2obMHVmqCVcIR+bI4vWpp49wguFw5PN1QGxBVRCxnEyACKDFScpqmP f1VlfC3SCiQWQ3gVN3KnKCA9ctwnKV1CBt9CVqeVS5hcazcDOMedqZBolJmK3o+QT4M9 R8QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085731; x=1691690531; 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=6v/OYLYVQR57/X+MrAxBhstfGEPE9Vxe5lIE5dFdYi8=; b=agWkTaWvgKU2S4EbCHreJFPp0yJ0GpMxB5LQ563WmvbWFD4Uxfb4d5Jts9wf4PhIqx +dcH1rzOhaF7riqdZPcljiYy4htjOe1uEsa6Djogt/dkwew1RitwPFqwoM/HehOCG9iJ EnW/53QeIC51+3XZFQVLbmnJ+D1LEf1svSiLjL7PSoicgCuUlldQ4k9SmAbdiFMmA9+g yU2VhdzVJ6MqRPpUkxr8UUvM5bfkQtlk8gD5fY9izRl7PhlzbqHkURIgZW1TpmN2Ol22 1+O84285fbBKsKvJgC9TZQ+6cHuBam0yrUxEi1GHBhkUI2xrmWfUcOO2qY/U69G6ozNX wWGA== X-Gm-Message-State: ABy/qLYPCwmupdVjYDBOJ5xo3HS+EapT3aqHCuXce+ZbkQlruKRJqVph 7XwEfaYhoT92kojnbyJrAYF3Iw== X-Google-Smtp-Source: APBJJlHFcm8ihxMfvEuKYdAJoJ0melHlBTDt1Jia2pL1VWUw/BkWIxLDR2Ghhray/SCxDTG4+7EhFQ== X-Received: by 2002:a05:6a20:938b:b0:13e:f5b5:48ee with SMTP id x11-20020a056a20938b00b0013ef5b548eemr7542379pzh.59.1691085731121; Thu, 03 Aug 2023 11:02:11 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.02.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:02:10 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra , Sunil V L Subject: [RFC PATCH v1 21/21] irqchip/sifive-plic: Add GSI conversion support Date: Thu, 3 Aug 2023 23:29:16 +0530 Message-Id: <20230803175916.3174453-22-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org ACPI uses flat Global System Interrupt Vector space and hence the GSI number needs to be converted to corresponding local IRQ number of the interrupt controller. Add a new gsi_base field in the priv structure to handle this which will be 0 on DT based systems. Signed-off-by: Sunil V L --- drivers/irqchip/irq-sifive-plic.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 72d6e06ef52b..1c22070e9cdd 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -68,6 +68,7 @@ struct plic_priv { unsigned long plic_quirks; unsigned int nr_irqs; unsigned long *prio_save; + u32 gsi_base; }; struct plic_handler { @@ -314,6 +315,10 @@ static int plic_irq_domain_translate(struct irq_domain *d, { struct plic_priv *priv = d->host_data; + /* For DT, gsi_base is always zero. */ + if (fwspec->param[0] >= priv->gsi_base) + fwspec->param[0] = fwspec->param[0] - priv->gsi_base; + if (test_bit(PLIC_QUIRK_EDGE_INTERRUPT, &priv->plic_quirks)) return irq_domain_translate_twocell(d, fwspec, hwirq, type); @@ -453,6 +458,17 @@ static int plic_probe(struct platform_device *pdev) return -EIO; } + /* + * Find out GSI base number + * + * Note: DT does not define "riscv,gsi-base" property so GSI + * base is always zero for DT. + */ + rc = fwnode_property_read_u32_array(dev->fwnode, "riscv,gsi-base", + &priv->gsi_base, 1); + if (rc) + priv->gsi_base = 0; + rc = fwnode_property_read_u32_array(dev->fwnode, "riscv,ndev", &nr_irqs, 1); if (rc) {