From patchwork Tue Oct 31 16:49:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Rikalo X-Patchwork-Id: 13442123 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 1C74FC0018A for ; Tue, 31 Oct 2023 16:52:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346973AbjJaQwd (ORCPT ); Tue, 31 Oct 2023 12:52:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346981AbjJaQwL (ORCPT ); Tue, 31 Oct 2023 12:52:11 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2093.outbound.protection.outlook.com [40.107.21.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65AB4109; Tue, 31 Oct 2023 09:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KyS/DoXmFfJ8MjiBCYM0+zbqOnoXK07kgmukHETT0T5sP8V6vX5FPjjIB5omDOPrkBh1CR1mSs5fijegvm5cKx1tFAXGUdAE0XEdqxmiAuarBKMVG6bgEChRdYJe6qbPkMwhkb/G3oCQpQ06sJwJbIFWnVqAy8L08HrHaaoZaMBPli42U5HYlvnDE25S70fh71k1JxNiC1shBrDt4QzHyPyy2MQRx14dGs2WKW3CWZE3sxdGoPmO4EwnVwFEpv5tSmbE1bpEqxb3ZLyK8nU2lQsKSFGWVTz/MtWJU4fDUPl8M1RQ/JIdn/d1tSiyQBv0E+VxJwOD42Fwicd2InFDEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=h2jU9hcJJvjycWI0LzJaha4TVcJ8lynqddYoHA2of7o=; b=VUJ/bw0AmTvAri5GldJw8DNdpmeFjC0g5qum6ajSlmX4jofVgAReWVxqp2Iaw+H6LO/WTTCGaIPabSIttFo2gL2NVXoxeZsMn28R2xtI25dR5USLOxP36n30AUtt/YuTS1deEBQCjbvZS8zNg/wnnCxC0MJxoqx0zk4jmoDBqOi0oUV8P8/BSo4Izi1gQogOO45XRFHx8iBCPjdH1FyivUVQOsMpMtzkk7UuJEAKsLX77mV0VwNEFyp4baWU5qpjjJ4Tr58AMBUHhDHwdxzVPWrAd8MAx72bXpgS6YzD+nVBOciDArBaCCL3MWthGicddkpy2yyYLzWqtARGmWXCWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=h2jU9hcJJvjycWI0LzJaha4TVcJ8lynqddYoHA2of7o=; b=ABUXcuSyyAsmxmKGA1xrXOdYwRbDrA0yk28bg7Uqp/0yanStMMsIkYiVytsIbIRY5Mzrm0DDdV34rEGiuLfkzLVSqLXOShKJwsRpvvUjhnHCG6EuIUIyjLjSdtOh38Ib3sow0DgvsKGCQW2n1zrXvoTwUWK6b8vUoXnM5yZbPA4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=syrmia.com; Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) by AM9PR03MB7187.eurprd03.prod.outlook.com (2603:10a6:20b:26f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19; Tue, 31 Oct 2023 16:49:38 +0000 Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa]) by VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa%4]) with mapi id 15.20.6907.032; Tue, 31 Oct 2023 16:49:37 +0000 From: Aleksandar Rikalo To: Thomas Bogendoerfer Cc: Aleksandar Rikalo , Chao-ying Fu , Daniel Lezcano , Dragan Mladjenovic , Geert Uytterhoeven , Greg Ungerer , Hauke Mehrtens , Ilya Lipnitskiy , Jiaxun Yang , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Marc Zyngier , Paul Burton , Peter Zijlstra , Serge Semin , Thomas Gleixner , Tiezhu Yang Subject: [PATCH v3 01/11] MIPS: CPS: Add a couple of multi-cluster utility functions Date: Tue, 31 Oct 2023 17:49:17 +0100 Message-Id: <20231031164927.371663-2-aleksandar.rikalo@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> References: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> X-ClientProxiedBy: AM0PR10CA0065.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::18) To VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0302MB3486:EE_|AM9PR03MB7187:EE_ X-MS-Office365-Filtering-Correlation-Id: a58be8d6-331a-4342-f1aa-08dbda315e89 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4phfKkbMAc0VRJF01Ltt6dBAjYVo9XtKG+G8O03AItSChvwLeV2aaJwv6FLnGxNoHSZ365reKeHS3rGsdmbNk/b1TgT6LcIi1+RyasXyjpjRLAr2bejMt/SNXQbkhMGGQf8T9+qwE4M0ZnwWLCNi58Mb4KY1+7L09Wttr1VDvtE37IpE4nYnJxOiriaQUSA/RJMNqhuOeygctLDRhPYfvOcLRvYdeN6DArsSsOpY8J/QEylvFiA/4iWKCPW3blfTQPYh1TG3YzDYfUJoQNUWtcdwjSOy+hiWLqp6LalBJCv08ukGEetjE7aEQScrddnl3idH12DPYpdjOJmVbqEeowNBFHD0aKGJR0dvBOhh7gKJ1Kqi6qE5/pGhR7pJKYVdtJqYQiBJmRdSuXkpBAwV9A8AjWvgEQV/fcalWL1u4iKhCKQlyhHWHHIeMu4c2T+216/IkyjOIbXVSiDXbxeJ4jwAg/c+gVjGXy1EftGk/4cPNc2SFpiRs/rTIoNlghMzqtVrK0ETssirhcL3bkfRDkRSq3+1J32OjP/wjKEtUdF5fwmOqSyzU9/k7I0cFYN8s1/GJ4dhdPg7Bh60GJDPeRq1PCp/pGOdlZFWy1p4WtOMqNsiqrPu01MYiLcOpwfC X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0302MB3486.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(376002)(136003)(346002)(39840400004)(230922051799003)(1800799009)(64100799003)(451199024)(186009)(41300700001)(44832011)(316002)(54906003)(6916009)(66946007)(66556008)(66476007)(8936002)(7416002)(478600001)(2906002)(4326008)(5660300002)(8676002)(6486002)(26005)(52116002)(6512007)(6506007)(2616005)(83380400001)(36756003)(1076003)(38350700005)(38100700002)(6666004)(86362001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xEddZ16Vfy9XVW3TlGCbi8l5XRxRGMbFz6DqcFottOeBmIUZp5JF0sgpEfIfQvZeE9rU8qqKIpwcdz0MHZovNpAsA7K81hCWz2zD4SY+V2rkIc/zdOI5Ero7OGgE842PID7lP/pA96eQ9ViLHCAZC48kznaBvKKnAnI4h9MIVGhxl/vnNpVbgwiWNH8IYsyF53nFxu+x6yCMM53xpDznlnoQ0Kj9xwTUhuV0NuXxZKY0Jiz3Miyr07TKvJcVVYJINtJ6Ug/8Rtx5rZCs17z1RXUMtYCSR8+KvJCov/Zn7QWJ9zh+3YRHzQigPOhCXCPpzNNi18Mx07/xMn/HydYmtCReQGck0oOsc4XKJ8nUgP9LJmqBeTjk/HXrgkFlyye/PmnGbPo2YVwHURVF5lI4upA91z0H26dh+thW1bc+FMPrQaEbtaYEqCdO7L2LCR+1B6Eiow+4opztkQhARh2hoMXyqI8zEaSofNRyht1v8KHieK/4eN0MF/nR/op7knD9UCrJ9z6Ya1L6UCORW6YdLq8so2XTZZFIOjcXRkFBytSmdrGuUdWButVShgK/J67uz7Jrovsgz91FNFAxhZIXAJ7jxqiSGL2pH3CpsMjvtSzwX0Fr+MCrvf2v/XxRjV3nit+TOynQhG9jCJ1F4nsmOCf0OcnKlNUU8naSUh2wRsz1ahD4shcagl8FX1uG3dFNtZ4BPV1KiC2DnkvaC0FJtqetmYLuw7xmQ1FfprIeAKBGfmonxQ/GtSWI8I/RrFHboOm3Sd4+mCKs+Hqsj2UY3XbYZsx4aiV9wqdGsNxElldnJW2pvUDmrNW+4vxNIKTFSAbblidciIeoBNQW4qLGIDtQLe3ApAxMqC0h6WRpozj4fhp3mLs6M7WE6AjhwMia+mCpk8gZ8HNCpIKlaR2kGfsDTPr4mnepZuFFAUs9xcK4aJ4/GWJes+C1iX+RucmkIU37oxSbV+EvNSaCcag8Wl3zq+ucr4hNbwPuXUYZJ+hkOD19bs1kq571UwZ81vnTJCEQHW0Saamr5qLyQy4Tuk3Uu4G6cJ+zT7eStiHGfEl1XoIDy4gvcdPNoXEJPvDWMA0nGgQ81IfcWXSxkZkgqrdkozbBQsd9TNeGtBMiTRDt9ItqgyQSJATEw0s0uv5qIqWeeta8pfjoXYZPQFu5zxLCwSjbsXwbgkcgeUD8E/C23+zyTfXcH4sBF/FJgHMDHnzHexhUoZu93e7Eq6OPJjcQZKDUds2RfWprhEVF795sx8KdH0aMcwKyxyYEoE0ALOnRvZURi9H2LWUJjcrX6FSfdVgEKk6NH7uU13/9akRpVlRzTil8qR0ho31FdfAjki1gC/oSOr1blHTgcOX7T1SA+xfhY8k2W0s0HXdrorni9+tltCKLxVqw3LJmJ/oLqs6/SCC5J27iVL7/PFVd5igNInjTtBPedX+7t4Xpa2bi4ieJUH3tvKSszITdEH3vfYlxGpegPplHxul5KTCKJ57wGL0Jsoed7SAPL58Z8sVW3dv1uW+Sh6pP0ZN7DOw+5+6a6K285N+1LX/kLAgvxzz2+NPStoqa+lYQBQ44gYzl15XK2DGPngVosRBBOULCDATmvPYfCHJLYBQy6zqfaA== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a58be8d6-331a-4342-f1aa-08dbda315e89 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0302MB3486.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 16:49:37.8713 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: FYDvuTF9hLWFt69mvyz6pr+xy4s/nQbZjfQwoERftrpwdGr6arPMmJXXk4TVZC8NtU24bf9FjJ+VXFDYWK/BUgMDUIPmpafTuR5xIOMpbHY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7187 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Paul Burton This patch introduces a couple of utility functions which help later patches with introducing support for multi-cluster systems. - mips_cps_multicluster_cpus() allows its caller to determine whether the system includes CPUs spread across multiple clusters. This is useful because in some cases behaviour can be more optimal taking this knowledge into account. The means by which we check this is dependent upon the way we probe CPUs & assign their numbers, so keeping this knowledge confined here in arch/mips/ seems appropriate. - mips_cps_first_online_in_cluster() allows its caller to determine whether it is running upon the first CPU online within its cluster. This information is useful in cases where some cluster-wide configuration may need to occur, but should not be repeated if another CPU in the cluster is already online. Similarly to the above this is determined based upon knowledge of CPU numbering so it makes sense to keep that knowledge in arch/mips/. The function is defined in mips-cm.c rather than in asm/mips-cps.h in order to allow us to use asm/cpu-info.h & linux/smp.h without encountering an include nightmare. Signed-off-by: Paul Burton Signed-off-by: Chao-ying Fu Signed-off-by: Dragan Mladjenovic Signed-off-by: Aleksandar Rikalo --- arch/mips/include/asm/mips-cps.h | 38 ++++++++++++++++++++++++++++++++ arch/mips/kernel/mips-cm.c | 37 +++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/arch/mips/include/asm/mips-cps.h b/arch/mips/include/asm/mips-cps.h index c077e8d100f5..fa71cf3a25d7 100644 --- a/arch/mips/include/asm/mips-cps.h +++ b/arch/mips/include/asm/mips-cps.h @@ -228,4 +228,42 @@ static inline unsigned int mips_cps_numvps(unsigned int cluster, unsigned int co return FIELD_GET(CM_GCR_Cx_CONFIG_PVPE, cfg + 1); } +/** + * mips_cps_multicluster_cpus() - Detect whether CPUs are in multiple clusters + * + * Determine whether the system includes CPUs in multiple clusters - ie. + * whether we can treat the system as single or multi-cluster as far as CPUs + * are concerned. Note that this is slightly different to simply checking + * whether multiple clusters are present - it is possible for there to be + * clusters which contain no CPUs, which this function will effectively ignore. + * + * Returns true if CPUs are spread across multiple clusters, else false. + */ +static inline bool mips_cps_multicluster_cpus(void) +{ + unsigned int first_cl, last_cl; + + /* + * CPUs are numbered sequentially by cluster - ie. CPUs 0..X will be in + * cluster 0, CPUs X+1..Y in cluster 1, CPUs Y+1..Z in cluster 2 etc. + * + * Thus we can detect multiple clusters trivially by checking whether + * the first & last CPUs belong to the same cluster. + */ + first_cl = cpu_cluster(&boot_cpu_data); + last_cl = cpu_cluster(&cpu_data[nr_cpu_ids - 1]); + return first_cl != last_cl; +} + +/** + * mips_cps_first_online_in_cluster() - Detect if CPU is first online in cluster + * + * Determine whether the local CPU is the first to be brought online in its + * cluster - that is, whether there are any other online CPUs in the local + * cluster. + * + * Returns true if this CPU is first online, else false. + */ +extern unsigned int mips_cps_first_online_in_cluster(void); + #endif /* __MIPS_ASM_MIPS_CPS_H__ */ diff --git a/arch/mips/kernel/mips-cm.c b/arch/mips/kernel/mips-cm.c index 3f00788b0871..2a59f0842a4a 100644 --- a/arch/mips/kernel/mips-cm.c +++ b/arch/mips/kernel/mips-cm.c @@ -518,3 +518,40 @@ void mips_cm_error_report(void) /* reprime cause register */ write_gcr_error_cause(cm_error); } + +unsigned int mips_cps_first_online_in_cluster(void) +{ + unsigned int local_cl; + int i; + + local_cl = cpu_cluster(¤t_cpu_data); + + /* + * We rely upon knowledge that CPUs are numbered sequentially by + * cluster - ie. CPUs 0..X will be in cluster 0, CPUs X+1..Y in cluster + * 1, CPUs Y+1..Z in cluster 2 etc. This means that CPUs in the same + * cluster will immediately precede or follow one another. + * + * First we scan backwards, until we find an online CPU in the cluster + * or we move on to another cluster. + */ + for (i = smp_processor_id() - 1; i >= 0; i--) { + if (cpu_cluster(&cpu_data[i]) != local_cl) + break; + if (!cpu_online(i)) + continue; + return false; + } + + /* Then do the same for higher numbered CPUs */ + for (i = smp_processor_id() + 1; i < nr_cpu_ids; i++) { + if (cpu_cluster(&cpu_data[i]) != local_cl) + break; + if (!cpu_online(i)) + continue; + return false; + } + + /* We found no online CPUs in the local cluster */ + return true; +} From patchwork Tue Oct 31 16:49:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Rikalo X-Patchwork-Id: 13442122 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 4DC4DC4167B for ; Tue, 31 Oct 2023 16:52:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346836AbjJaQwb (ORCPT ); Tue, 31 Oct 2023 12:52:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346986AbjJaQwL (ORCPT ); Tue, 31 Oct 2023 12:52:11 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2093.outbound.protection.outlook.com [40.107.21.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3096BA2; Tue, 31 Oct 2023 09:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VMbOBMvLyvdwi6U6WFzfa+FuMY+/FMKP4Bvrbj+Zp011P8oQGikYfgLEq7NUJeK0nIfybRM5X5rolVoOK1yjV2xfAWljiQOYeBMZDIj5T/D1+YLnwpJXy2APk2o7pyKJ3HRngMqFBmkEaZPQ1M8/L7HPpM+abuqhJCxBkjr3aeYtlLeTaTSVi6EfBd0+DKsAo8v4VYOxiSjsmkyjXrzoaVVDoQ6imISlWWqX9jefcPQIgsdsXgYCMztNLpKTgB6GVKkxzL3ycCsWWC88bYquFL19sfL5OWtCcuN9FPE9n3CThQQHdh4wCiNbant37SGeykVYLTSyfYST3i/675SHrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=J441UACOmM+plHFUNs2UCVgRdvQT0qPnSeGsc/Q08Aw=; b=GcSgjhfZLZ0tEYU7aAaGOB2hLBge2Yg5YT8kYm+LME1CWG5Revyhv40FiexfM94vbkyxDt2bfG2qFx4qI/32vfmoJQsUaXaHPXQb9NGTQi1Rzt+VVsrox+uj5/XGuGt5Sl0Qzdg+58VU8bOAChffda0jjoIpDkJ7ZHbLj8zLt72qm/EKaAjOpZ5XZWueSlR6TIfLsG3xs8nc3sieDxDJy5x5utQLHHlpRwflw4KyXc9O9PjeGHpNqPmlYHGpPfqkPozYpMIQBr70KD6g6z9DlhEdi3Zsyx1IicsiIEfQGTxFA9qElx9H7s07AdK+0xQ1JYH8osWl+GE5B2lwmwXsYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J441UACOmM+plHFUNs2UCVgRdvQT0qPnSeGsc/Q08Aw=; b=SPshZl/9NE3/T5GO+y9KXv1mvt9XaiJYper0PtfUBeG/mm0y8iPc12c7870OaeO9u4glGiKtAV1UcGCLbQd21os4bDVci0xHtcFEzv+bwM1tBTLrLlN39eNV4h8dkpKKRL0jtiuKwRbQUgLsydo2PVn7EbsutNuIP5TRzTI1PLE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=syrmia.com; Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) by AM9PR03MB7187.eurprd03.prod.outlook.com (2603:10a6:20b:26f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19; Tue, 31 Oct 2023 16:49:39 +0000 Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa]) by VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa%4]) with mapi id 15.20.6907.032; Tue, 31 Oct 2023 16:49:39 +0000 From: Aleksandar Rikalo To: Thomas Bogendoerfer Cc: Aleksandar Rikalo , Chao-ying Fu , Daniel Lezcano , Dragan Mladjenovic , Geert Uytterhoeven , Greg Ungerer , Hauke Mehrtens , Ilya Lipnitskiy , Jiaxun Yang , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Marc Zyngier , Paul Burton , Peter Zijlstra , Serge Semin , Thomas Gleixner , Tiezhu Yang Subject: [PATCH v3 02/11] MIPS: GIC: Generate redirect block accessors Date: Tue, 31 Oct 2023 17:49:18 +0100 Message-Id: <20231031164927.371663-3-aleksandar.rikalo@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> References: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> X-ClientProxiedBy: AM0PR10CA0065.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::18) To VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0302MB3486:EE_|AM9PR03MB7187:EE_ X-MS-Office365-Filtering-Correlation-Id: c0065edd-c448-402f-204a-08dbda315f9c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6DIEhVIb7q1m2HlymGmzOTNEKkHaWR21z3vaCE6Fni3kAuNiEzCfBiBW4k+BL081AWXWf86FwtgDol6kvVYaRlUu8i75OepjdqxH5069CkzK2fzOQ8SZEGUQUbX9+p3sgu4wnte1BvP42hQ+jnUUUw1fZM20G9fvnbwjKbHDtKlvu9PhrVd4uN/KmjhgGKsvONtXfZr+Ab2NaotxriYoXqvJMcGOxrGjRGcDeffI5rHPtMrY0af5FeulAn25igx/SIMngytTamjC5Ntp3KCUtcyfjJ2v0C2USoLK+UGWxZOp6yF8x1qJD54jpyW7tVF3TLPK+2URDTzV6MMdAubVTOV0GsVmaAVqjTmtp5BjbztqtRXHCkMnyyIHPMXrsHE/CQwyKnNFqo2fxXKaYAUpk8FeWDuPJ7ciD0dhLPtHmAzQjs+zLtprj4TMResKcsBXQhrEc4IuEJWpL8YJaHr6PyIvjcs1FnRpxP59OB9jqHillobM9eoIeq3XljWNYlAfEEmMvn2YuoPLny+FrgnifNfAFUrlJfxaQCIkWh1atmIJlFfwxtv+RrtPpiytBfbdssrGciylcolF0aD7wkG2ieZ/DFCoC8ZGJ/NFHy4JHtHpdYXtGsqHLl5lMrAj4sbS X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0302MB3486.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(376002)(136003)(346002)(39840400004)(230922051799003)(1800799009)(64100799003)(451199024)(186009)(41300700001)(44832011)(316002)(54906003)(6916009)(66946007)(66556008)(66476007)(8936002)(7416002)(478600001)(2906002)(4326008)(5660300002)(8676002)(6486002)(26005)(52116002)(6512007)(6506007)(2616005)(83380400001)(36756003)(1076003)(38350700005)(38100700002)(6666004)(86362001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HUEFBIF9YntORipCHBEGVPEK5SOzz+i6b9tRG0g5VSQB4zvQXRcLD3PMUeYif5IaCcbUQq+ykLlsy1bzbVYHe2m3j13Ic5aDOFl59vj76IsyeKTBSKdubNtQnqnxaNUaBN/q6DrHGxUk34ejOEeansaa3s1CSOgkHke3DKt6OVFQGMM1ozqt2dwCZoaXYehK9dR+U+AQ0X8Um2sV07GudDoJUh+Vh4EyLMImB64v6FnMlIwDrNNlMLgQIJF7W58NcSzVcPeULL0Rnn42Daxn86fExMTudXd2YTELykq8PV4bzFiVnOKBiO9orRQvN2vEGXTtd97chsMl0GcQKoxtp8rHW7aDARCzQZtNl/HzRogqpeUuOhW7LEZ7npLOrnFgfG83hYCHMflMMtoGxssP134yUxGsAV1HCQFdGKwz6ZiewNm94H6nWVBF0h2Q1DGel3y/zSdpKbSs0UFiohF1qcuGItACZ9DQ2Pd7xRKzfZuHJYHE2/qaAqMjRW8ZrQBD5S6FAaD2w229yjESbRPFuaGBDdVH6QptYy7T973WCa4wN/0DQwtSA1H9Gur7PGb51Slo1NYi8vxDlFXkOs5YSmxsrqUkB7EwftO0Nd6JZ1/qrO8IAzkuD2eDL7dW7JBthqETD5jtqjeCslBFGXNez/3fyRFp75Mt7+kU4tD7kgZTXqYuJHqoyizAxVih81C6ZvbhSSG4UTusPejUEJRsB8iZa85hL2X3eepyDEfICYVlzNdD/4gxR6nQLkEqeoJoivC5pGlTYJsWpO3ImAZAVQYz4+t8Xu499gzgQd52CtmHgsP5Tps5J4fDwZVCrpn5RJekb/L4g38OpLrg12U9yZS+YwRKiNFGo4sE9DBYPQsIrjSNto8JE2euhoVc8f5GYpAjhumcroFTOL5R7ud3mo3FTcTKOuypl42LxODqan5eo8JFQhD5b+2UBoXazw+/PZMnXMDCLNrhuKuauJ3PVpRsyu6P1GnOyRzIurShke/lFEH9pRqzyixRFGNJax/fPC03d6qfotDBXbii782WJtJwlgqYsJeQ+SKC8EczyNBWxCGX3J8d+0nAenOsk4gGqb0dJyQaiOCqGFD/2upNkEkh3IC5bx9557OsLN6flfGeBahmySPxzVMQDxggkM7NsHOyT8Jx12erfkRIzUeoSmeeXmmJ19A9v2XEwzxh5QjO8SLudG/kkZPigvXsH88tQdPPrWoFiawHB1R5Yy9F223p4CNueUkakJar2vuDM3ZVJK1FnyJ32/9qRHOz0Z5h2B50EV4ERCT90X80wiNQgTNzO7XcRpmpDxl+8yifL8TthAJT6QOnKpkvtOZ+iE3kArSiti410O94HgQNv5kmta1H0clsJzQeya3xiIqdwqEvB/pE2sNp33wR57epIat7vteSRirvRHEFezatUV0vgtWUlub6p619SzDsHd5WugDRNs2dDRxqYlVxMidlWD5o7RdAofBq5foRXU34NxkXP0PQ7EsLredOIVOwjQsN700JCz5v/YrDFLWCbDgVkubiovgfWMhc3ZFfF6mr/ZyzWyN/l+V9VpfEIwhyykd5CkVK5oAXXUFaF7RhBEcT3jcAooWi1mYcbcORyNiblJI76A== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0065edd-c448-402f-204a-08dbda315f9c X-MS-Exchange-CrossTenant-AuthSource: VI1PR0302MB3486.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 16:49:39.6876 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SlkzTubqqotJ3KHI6k1jsgBLPlTc4Lofq4vOKfN9EAzscHv5MXTwXHxwHkqom+qJ5qL4GuoJFdtH4bRcRLip6KRxauaOIsjssLBv+4+NtyY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7187 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Paul Burton With CM 3.5 the "core-other" register block evolves into the "redirect" register block, which is capable of accessing not only the core local registers of other cores but also the shared/global registers of other clusters. This patch generates accessor functions for shared/global registers accessed via the redirect block, with "redir_" inserted after "gic_" in their names. For example the accessor function: read_gic_config() ...accesses the GIC_CONFIG register of the GIC in the local cluster. With this patch a new function: read_gic_redir_config() ...is added which accesses the GIC_CONFIG register of the GIC in whichever cluster the GCR_CL_REDIRECT register is configured to access. This mirrors the similar redirect block accessors already provided for the CM & CPC. Reviewed-by: Jiaxun Yang Signed-off-by: Paul Burton Signed-off-by: Chao-ying Fu Signed-off-by: Dragan Mladjenovic Signed-off-by: Aleksandar Rikalo --- arch/mips/include/asm/mips-gic.h | 50 ++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/arch/mips/include/asm/mips-gic.h b/arch/mips/include/asm/mips-gic.h index 084cac1c5ea2..fd9da5e3beaa 100644 --- a/arch/mips/include/asm/mips-gic.h +++ b/arch/mips/include/asm/mips-gic.h @@ -28,11 +28,13 @@ extern void __iomem *mips_gic_base; /* For read-only shared registers */ #define GIC_ACCESSOR_RO(sz, off, name) \ - CPS_ACCESSOR_RO(gic, sz, MIPS_GIC_SHARED_OFS + off, name) + CPS_ACCESSOR_RO(gic, sz, MIPS_GIC_SHARED_OFS + off, name) \ + CPS_ACCESSOR_RO(gic, sz, MIPS_GIC_REDIR_OFS + off, redir_##name) /* For read-write shared registers */ #define GIC_ACCESSOR_RW(sz, off, name) \ - CPS_ACCESSOR_RW(gic, sz, MIPS_GIC_SHARED_OFS + off, name) + CPS_ACCESSOR_RW(gic, sz, MIPS_GIC_SHARED_OFS + off, name) \ + CPS_ACCESSOR_RW(gic, sz, MIPS_GIC_REDIR_OFS + off, redir_##name) /* For read-only local registers */ #define GIC_VX_ACCESSOR_RO(sz, off, name) \ @@ -45,7 +47,7 @@ extern void __iomem *mips_gic_base; CPS_ACCESSOR_RW(gic, sz, MIPS_GIC_REDIR_OFS + off, vo_##name) /* For read-only shared per-interrupt registers */ -#define GIC_ACCESSOR_RO_INTR_REG(sz, off, stride, name) \ +#define _GIC_ACCESSOR_RO_INTR_REG(sz, off, stride, name) \ static inline void __iomem *addr_gic_##name(unsigned int intr) \ { \ return mips_gic_base + (off) + (intr * (stride)); \ @@ -58,8 +60,8 @@ static inline unsigned int read_gic_##name(unsigned int intr) \ } /* For read-write shared per-interrupt registers */ -#define GIC_ACCESSOR_RW_INTR_REG(sz, off, stride, name) \ - GIC_ACCESSOR_RO_INTR_REG(sz, off, stride, name) \ +#define _GIC_ACCESSOR_RW_INTR_REG(sz, off, stride, name) \ + _GIC_ACCESSOR_RO_INTR_REG(sz, off, stride, name) \ \ static inline void write_gic_##name(unsigned int intr, \ unsigned int val) \ @@ -68,22 +70,30 @@ static inline void write_gic_##name(unsigned int intr, \ __raw_writel(val, addr_gic_##name(intr)); \ } +#define GIC_ACCESSOR_RO_INTR_REG(sz, off, stride, name) \ + _GIC_ACCESSOR_RO_INTR_REG(sz, off, stride, name) \ + _GIC_ACCESSOR_RO_INTR_REG(sz, MIPS_GIC_REDIR_OFS + off, stride, redir_##name) + +#define GIC_ACCESSOR_RW_INTR_REG(sz, off, stride, name) \ + _GIC_ACCESSOR_RW_INTR_REG(sz, off, stride, name) \ + _GIC_ACCESSOR_RW_INTR_REG(sz, MIPS_GIC_REDIR_OFS + off, stride, redir_##name) + /* For read-only local per-interrupt registers */ #define GIC_VX_ACCESSOR_RO_INTR_REG(sz, off, stride, name) \ - GIC_ACCESSOR_RO_INTR_REG(sz, MIPS_GIC_LOCAL_OFS + off, \ + _GIC_ACCESSOR_RO_INTR_REG(sz, MIPS_GIC_LOCAL_OFS + off, \ stride, vl_##name) \ - GIC_ACCESSOR_RO_INTR_REG(sz, MIPS_GIC_REDIR_OFS + off, \ + _GIC_ACCESSOR_RO_INTR_REG(sz, MIPS_GIC_REDIR_OFS + off, \ stride, vo_##name) /* For read-write local per-interrupt registers */ #define GIC_VX_ACCESSOR_RW_INTR_REG(sz, off, stride, name) \ - GIC_ACCESSOR_RW_INTR_REG(sz, MIPS_GIC_LOCAL_OFS + off, \ + _GIC_ACCESSOR_RW_INTR_REG(sz, MIPS_GIC_LOCAL_OFS + off, \ stride, vl_##name) \ - GIC_ACCESSOR_RW_INTR_REG(sz, MIPS_GIC_REDIR_OFS + off, \ + _GIC_ACCESSOR_RW_INTR_REG(sz, MIPS_GIC_REDIR_OFS + off, \ stride, vo_##name) /* For read-only shared bit-per-interrupt registers */ -#define GIC_ACCESSOR_RO_INTR_BIT(off, name) \ +#define _GIC_ACCESSOR_RO_INTR_BIT(off, name) \ static inline void __iomem *addr_gic_##name(void) \ { \ return mips_gic_base + (off); \ @@ -106,8 +116,8 @@ static inline unsigned int read_gic_##name(unsigned int intr) \ } /* For read-write shared bit-per-interrupt registers */ -#define GIC_ACCESSOR_RW_INTR_BIT(off, name) \ - GIC_ACCESSOR_RO_INTR_BIT(off, name) \ +#define _GIC_ACCESSOR_RW_INTR_BIT(off, name) \ + _GIC_ACCESSOR_RO_INTR_BIT(off, name) \ \ static inline void write_gic_##name(unsigned int intr) \ { \ @@ -146,6 +156,14 @@ static inline void change_gic_##name(unsigned int intr, \ } \ } +#define GIC_ACCESSOR_RO_INTR_BIT(off, name) \ + _GIC_ACCESSOR_RO_INTR_BIT(off, name) \ + _GIC_ACCESSOR_RO_INTR_BIT(MIPS_GIC_REDIR_OFS + off, redir_##name) + +#define GIC_ACCESSOR_RW_INTR_BIT(off, name) \ + _GIC_ACCESSOR_RW_INTR_BIT(off, name) \ + _GIC_ACCESSOR_RW_INTR_BIT(MIPS_GIC_REDIR_OFS + off, redir_##name) + /* For read-only local bit-per-interrupt registers */ #define GIC_VX_ACCESSOR_RO_INTR_BIT(sz, off, name) \ GIC_ACCESSOR_RO_INTR_BIT(sz, MIPS_GIC_LOCAL_OFS + off, \ @@ -155,10 +173,10 @@ static inline void change_gic_##name(unsigned int intr, \ /* For read-write local bit-per-interrupt registers */ #define GIC_VX_ACCESSOR_RW_INTR_BIT(sz, off, name) \ - GIC_ACCESSOR_RW_INTR_BIT(sz, MIPS_GIC_LOCAL_OFS + off, \ - vl_##name) \ - GIC_ACCESSOR_RW_INTR_BIT(sz, MIPS_GIC_REDIR_OFS + off, \ - vo_##name) + _GIC_ACCESSOR_RW_INTR_BIT(sz, MIPS_GIC_LOCAL_OFS + off, \ + vl_##name) \ + _GIC_ACCESSOR_RW_INTR_BIT(sz, MIPS_GIC_REDIR_OFS + off, \ + vo_##name) /* GIC_SH_CONFIG - Information about the GIC configuration */ GIC_ACCESSOR_RW(32, 0x000, config) From patchwork Tue Oct 31 16:49:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Rikalo X-Patchwork-Id: 13442124 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 B7B77C4167D for ; Tue, 31 Oct 2023 16:52:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346792AbjJaQwe (ORCPT ); Tue, 31 Oct 2023 12:52:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346983AbjJaQwQ (ORCPT ); Tue, 31 Oct 2023 12:52:16 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2093.outbound.protection.outlook.com [40.107.21.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAAFB11A; Tue, 31 Oct 2023 09:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hpILFy7yCT2980Thvy4sy3m7MgbsHcJPLDhUrqOGd9mP3avfgjXixCawxKQ56N224tzoUMKbo6/evc+Oh8fKbGwbX4glPt5lwcxZvdCRPApETq6qsmYOeqalupn9B6Nt3IAvMzSm34UDEvRFFFxWNqbkGwN5sbzzhtUyW0gO0AdyxhGd3X4tvuGDhBGTSP4UcclU+XnG1YCuN7CRRX44Y8UB4pxQl1asLmzacsJZLuhtjKQdL/akhaiH1mTwF0YnzqbRwCWE/bOFWIxKXtzxI6wiJxgbdXC7lGDtpl6E5GNgx+nylJEocbD0A1jIRxDKVICbHrMUkDEOwCmf+wOxig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6L+xQIcU/M2AFE9gICKDEMemb0+dOzf9wEODUdS5KNo=; b=fiMaqD8mnlzo0YrNItisW0OGbnEd0Z3zPwfKrB8n5GRAwAvtXUmKuHmDesBA2TjuwO7f7RAuTx0xkmw/I6BybXZeku9wwgxMAYc4Nj3qNC3/jjPUe+eoS2Omj+3RuOcOKpNs1LAIdDB1uheO3T3uO+zYZrFpgL44rBnDa+jssz0JgGZLvkSQoxjz4PvZxZ9bfU3SR3lf7wiTfWhJI0m1po/4EPIYjfRI5B7WrlBLg9Vcfoo+gZjuQWgK8BOTRTrSdyUidh8jg5WFEQQE6d8o06AO2R4neLfbtXnlWQBPwZHVc2hv5W1SAvnsX8ykM3W2WNqN6uhK0TBXEO3eP/8q9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6L+xQIcU/M2AFE9gICKDEMemb0+dOzf9wEODUdS5KNo=; b=Rnxl0E0jc/MI/exgNJS+tgOArdRCiiyMb05STfP//d1xJsVlyZCTIIGfd7k04XC6P5b4rFJUSokh/gaK+OB7Kjiwlb3iIglY4Ow0WampccZGcYntOT4+38GT4y2iBIZseBw5jx/EsBqFx9vOqYB09M75l2v/wKWvBmbbo6z7HjY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=syrmia.com; Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) by AM9PR03MB7187.eurprd03.prod.outlook.com (2603:10a6:20b:26f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19; Tue, 31 Oct 2023 16:49:41 +0000 Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa]) by VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa%4]) with mapi id 15.20.6907.032; Tue, 31 Oct 2023 16:49:41 +0000 From: Aleksandar Rikalo To: Thomas Bogendoerfer Cc: Aleksandar Rikalo , Chao-ying Fu , Daniel Lezcano , Dragan Mladjenovic , Geert Uytterhoeven , Greg Ungerer , Hauke Mehrtens , Ilya Lipnitskiy , Jiaxun Yang , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Marc Zyngier , Paul Burton , Peter Zijlstra , Serge Semin , Thomas Gleixner , Tiezhu Yang Subject: [PATCH v3 03/11] irqchip: mips-gic: Introduce for_each_online_cpu_gic() Date: Tue, 31 Oct 2023 17:49:19 +0100 Message-Id: <20231031164927.371663-4-aleksandar.rikalo@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> References: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> X-ClientProxiedBy: AM0PR10CA0065.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::18) To VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0302MB3486:EE_|AM9PR03MB7187:EE_ X-MS-Office365-Filtering-Correlation-Id: ac47c71d-db40-4c4a-4eec-08dbda3160ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zhhAWW8jZqpEJ9TgzoEroN07DQlZsH2aYp/+R5uLOr3jVXBKp8a8LtnqPgipPls9KXkuw9b8M3xt7Fr/lu7VDbYDipijTwMohGW3cY2gNpnopmy+yXJMWY36B+rCbExFcXf7m+KAqaNb1BzFHwEcnDonOoPFannc5SAnV6KUD/b1fCuDZNQjk2CK6N2nWzkIiyZdl0kFzYA4u0Dn9RYMUeQotOyAP3V99i0ROlIH7bvoXFpC8qWgzFGUN+lRatV3mdSTTh9AdlZxIumB5BgmAFpF2XQK78vAbxuCDd2jaB72V1Glln7M1mVvr/8N7g5yGgGi9d0FfQrtMM/nV1p15sZUPc/yTLDrFxR0WLBzTHXlYe5rMudwCbAlEd1Jg7Ey79yc4zeqiUi+lfMTeWktdv+qUKsUKoXGnf12Mjo70rEPWse6mQA8zEVm2I65prSP8nZlzG/VHHY6fGNnMjCaw6eweM00F2zLHppfezs2jy9jBKSzjwde5ceTNRLjWs8sQxA90/x16VVZGsHtgzC0FZ2z2gTxhes/GHYVBq4/VaCYGfDDfyZwNXJpeMwilgNQ13LuJopEbI4TSQ56SVDDxr/uPvl5cQsqcCnbhirFesKgZdGuwE+Vvz4dihJSyDzM X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0302MB3486.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(376002)(136003)(346002)(39840400004)(230922051799003)(1800799009)(64100799003)(451199024)(186009)(41300700001)(44832011)(316002)(54906003)(6916009)(66946007)(66556008)(66476007)(8936002)(7416002)(478600001)(2906002)(4326008)(5660300002)(8676002)(6486002)(26005)(52116002)(6512007)(6506007)(2616005)(83380400001)(36756003)(1076003)(38350700005)(38100700002)(6666004)(86362001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: y8r+B4Res9tRcGHWGhN/env3YcGyqMLvmsuLzUCSbR5S4avvzJlwQ8uwYIizg7bu2acuKaYbOINZTDiId26XdX1qzExlJhvop3qHzkd5NBlzxAUEUM7V1zfKk/dC/+YXnbjGfI5ISIc7ulZilWqjWRteHH5y58JoGh7NB7pQF4PLghPZ8QplGRmWz0jYhQWUebnTJY9NeOenoC6Vpos5K61jCK8SLOYWqXLfHUqFBJV5oIUY75QcyHVQU66e1u0/4vVkNbsJP8j4lq7++O2ADwxNbTHzT4LfnhnD90uJQVRH+IK9PZ/Ca02HR60sBsBlM0+WoUt7IaeZSt1ahGtD0JVlDEajV5xQqpTT7FQDxNg0F9vWxd2hPzCeSylFe6uxpVaW07Tk/PQYY5VfFgyCZOKbmOQO5Y1DBq8UlTDBtGDswxEHoIEi8STZedJKlWe3kPiao6NTAq3WgC0/OCacMwta80rosx6h0wNQ1sIrG2yiTzEdDIJQR8kqpmh+EYRr2ar4e0uHFvtMETxbCtO1WJciaUKxkd3kAFgZUJUTk8zavV/5sG8bzKAYrc/phL7Cvvw0IKoWrVaDE1+sNFvQxIpnpnt80L/cy8NTI0FLp9roQoSTa8CeQTzJgB/aKbwWL5Uy10bXAQXHpxG78Xq/pzhVl4cYy1dGdIN9NMZFEad5osQJgNsjNYBLlHsQCrhz6OE4QTnsr80vyjHLDME3rhnsDDEWlhUbah/BZxc2RCs5OrfWJF8fm6z8LFpG5IgCdYjiXylaQQPX2ZcMQPx75WzqhDMFhttGbg3wyE5L/nq9ChZbyseLxeC8/86WaNlJus62e6DhE1dFl7BdN0SO6dniWBPRzgYGD0Zv22NNzSVv3SUeIr9vRwkoH6G6n5jlzsBWab71Jwj1qHZbqs7kmoKUSFqhC98IjzGVJx2Jqafmc5mNBEDMwFZskd0BR11Hs6xaJ0nIt+n/f+s+CWDq48RnYMA7Of7R9TNT7eOs52wQCQKh6sBvrOarQy6FMBzCa0V9DL2mQcV4iRJy+tl5ljnqrG47ShhQVkTx+X0N8DTevbB8rbdA/PENXUuJh+EbXUVukdVWik1JcYOuCNgDMDrb1KkuvvI47w+13Q1BgNQMbIu+1IbZnhpSbPWsFaTkS4PtAUcr95blQEY5Zh/4o2el/5FF6RadJpynYLHpgufjB+3cg12Bzqvf/ga/SNnHWLSNvGP9HGtv7cp5CSoPjZ/SCIHllQtG6mUzQgp/AIWgfEcMeeqmTmbrP3wbNQivz96s0YM0k9qqMWV0HJ1uZv+Up2wjuL5tJkocpBts1Zu7F90PDKlW566bGEMF9u9Nx2vvAFiFV4y1wfKdrujNGIsqFhdSTY37DGfQ7kLnf3f5ndzXnsOK4TCp9w1jA7KDchuHtMlxMBjo4MuZTWTWWsFUJiIK7U4TJTogCs+9XASAm9qXQfiBv0WRkL3WXfwlKDF4wzBSBpgJ2Kw1x+7e0pjwIB+FJLxw8vSiHMHr9ECDWTh7r213Y7wrNNJUKtwhK89G80nlZQEm0xOUxZiLJ+7U66Vj9RfauyLleyS5DfC4d0GQwa+/b+7UBzhZYXc808g42XCib7iPV69bV8dA8Q== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac47c71d-db40-4c4a-4eec-08dbda3160ae X-MS-Exchange-CrossTenant-AuthSource: VI1PR0302MB3486.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 16:49:41.4592 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HoqN+gM0JP0Ia3LhJA31cSyc7BX5hdRY0omzCeS5j/Mkc+OCeaDi2xrGgZwJah/xK8U0FcZBxaTjAXtCP8aIU8o/ZFNe5FrDDg0DcqMHrdw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7187 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Paul Burton A few pieces of code in the MIPS GIC driver operate on the GIC local register block for each online CPU, accessing each via the GIC's other/redirect register block. This patch abstracts the process of iterating over online CPUs & configuring the other/redirect region to access their registers through a new for_each_online_cpu_gic() macro. This simplifies users of the new macro slightly, and more importantly prepares us for handling multi-cluster systems where the register configuration will be done via the CM's GCR_CL_REDIRECT register. By abstracting all other/redirect block configuration through this macro, and the __gic_with_next_online_cpu() function which backs it, users will trivially gain support for multi-cluster when it is implemented in __gic_with_next_online_cpu(). Signed-off-by: Paul Burton Signed-off-by: Chao-ying Fu Signed-off-by: Dragan Mladjenovic Signed-off-by: Aleksandar Rikalo --- drivers/irqchip/irq-mips-gic.c | 61 +++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c index 76253e864f23..9e7182150b5c 100644 --- a/drivers/irqchip/irq-mips-gic.c +++ b/drivers/irqchip/irq-mips-gic.c @@ -66,6 +66,52 @@ static struct gic_all_vpes_chip_data { bool mask; } gic_all_vpes_chip_data[GIC_NUM_LOCAL_INTRS]; +static int __gic_with_next_online_cpu(int prev) +{ + unsigned int cpu; + + /* Discover the next online CPU */ + cpu = cpumask_next(prev, cpu_online_mask); + + /* If there isn't one, we're done */ + if (cpu >= nr_cpu_ids) + return cpu; + + /* + * Lock access to the next CPU's GIC local register block. + * + * In the single cluster case we simply set GIC_VL_OTHER. The caller + * holds gic_lock so nothing can clobber the value we write. + */ + write_gic_vl_other(mips_cm_vp_id(cpu)); + + return cpu; +} + +static inline void __lockdep_assert_held(raw_spinlock_t *gic_lock) +{ + lockdep_assert_held(gic_lock); +} + +/** + * for_each_online_cpu_gic() - Iterate over online CPUs, access local registers + * @cpu: An integer variable to hold the current CPU number + * @gic_lock: A pointer to raw spin lock used as a guard + * + * Iterate over online CPUs & configure the other/redirect register region to + * access each CPUs GIC local register block, which can be accessed from the + * loop body using read_gic_vo_*() or write_gic_vo_*() accessor functions or + * their derivatives. + * + * The caller must hold gic_lock throughout the loop, such that GIC_VL_OTHER + * cannot be clobbered. + */ +#define for_each_online_cpu_gic(cpu, gic_lock) \ + for (__lockdep_assert_held(gic_lock), \ + (cpu) = __gic_with_next_online_cpu(-1); \ + (cpu) = __gic_with_next_online_cpu(cpu), \ + (cpu) < nr_cpu_ids;) + static void gic_clear_pcpu_masks(unsigned int intr) { unsigned int i; @@ -358,10 +404,9 @@ static void gic_mask_local_irq_all_vpes(struct irq_data *d) cd->mask = false; raw_spin_lock_irqsave(&gic_lock, flags); - for_each_online_cpu(cpu) { - write_gic_vl_other(mips_cm_vp_id(cpu)); + for_each_online_cpu_gic(cpu, &gic_lock) write_gic_vo_rmask(BIT(intr)); - } + raw_spin_unlock_irqrestore(&gic_lock, flags); } @@ -376,10 +421,9 @@ static void gic_unmask_local_irq_all_vpes(struct irq_data *d) cd->mask = true; raw_spin_lock_irqsave(&gic_lock, flags); - for_each_online_cpu(cpu) { - write_gic_vl_other(mips_cm_vp_id(cpu)); + for_each_online_cpu_gic(cpu, &gic_lock) write_gic_vo_smask(BIT(intr)); - } + raw_spin_unlock_irqrestore(&gic_lock, flags); } @@ -534,10 +578,9 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq, return -EPERM; raw_spin_lock_irqsave(&gic_lock, flags); - for_each_online_cpu(cpu) { - write_gic_vl_other(mips_cm_vp_id(cpu)); + for_each_online_cpu_gic(cpu, &gic_lock) write_gic_vo_map(mips_gic_vx_map_reg(intr), map); - } + raw_spin_unlock_irqrestore(&gic_lock, flags); return 0; From patchwork Tue Oct 31 16:49:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Rikalo X-Patchwork-Id: 13442126 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 933E6C0018A for ; Tue, 31 Oct 2023 16:52:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346818AbjJaQwg (ORCPT ); Tue, 31 Oct 2023 12:52:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346906AbjJaQwR (ORCPT ); Tue, 31 Oct 2023 12:52:17 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2093.outbound.protection.outlook.com [40.107.21.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C05D3D44; Tue, 31 Oct 2023 09:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kQnz0uJk59Ttrs69uQDCKEdeXXzv8FyH5EUYBoFghVn/iH3T6Vq0DbdSdAPAQHCzRx8QjHMfpM3XiIBWB5WrFGhxh0aKrNNzLoqY1hgy0VamF4eSiI/T6zxrxJkO4xwtg+iQZf8X+/7rzmO/9+ileMnGsrkvW0cxr4boIYNqQT3dYPhrAquEh2vsTHP9OttkW2Uhuv82BoluYDgz9VWCooVGOg1qNsijc3E239/1dlFgTfzhsVANAuixrz3/q0MLu8qbEL++zZ7Mafn1EiMopM7q6OD5Tw9OOpMNj4Vkp/aHIzyOlMu7i+hXBJrZSCHscZVjjSw4CzdPLaBH41nJmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zivLEPzK2yPb03tjtLC8DJTk3RiZnwMaBX5KORprkw0=; b=B6oCupeF0DrNLNrWRM+cbs7kwI/KK9MODUTjnTBA91MqldBqX7JsdgUihOmR7j09eIg4dPuslgpKn/ISCLvPqYAgvh6qyrhWJOmXRQsB0gV1M5Ea41HGbE3waTpPsPVwkaMBYSoQoDkFW6Jc2jh+V8N8aD6Z/+XKdKK4nVI92wCQqA79zkKamII5n6MV4rNxSPksaxd+ZlcpUonQuGO0yqF17sCkrhOtvx9ZvqEw9Bm0M4WwF00/e6QDgbVsE0Li1GdlZVpIssJMyr+fIxF/lw3hlzwTfn2SPMEw44awhSIgkNbHIynPw6eZqbshbZI5rNfXoPwdB3z4UlJDSsYLig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zivLEPzK2yPb03tjtLC8DJTk3RiZnwMaBX5KORprkw0=; b=aakof/Cb0duhsJ9WXHxO8ZDr2G0A4EKVQpG2w5cD6hQ5jv4KIr6WHP+xEWVl9itx37aR1Vd3vIbz2n7AlkGkeetQBhwZ1ts8gKxM9XclRxuzpVTUA6GAZHGJ7zCkw/9MQNESCbOuJhHiYbDEv2Qd733YvFri2HoXAk1A5y0g97U= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=syrmia.com; Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) by AM9PR03MB7187.eurprd03.prod.outlook.com (2603:10a6:20b:26f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19; Tue, 31 Oct 2023 16:49:43 +0000 Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa]) by VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa%4]) with mapi id 15.20.6907.032; Tue, 31 Oct 2023 16:49:43 +0000 From: Aleksandar Rikalo To: Thomas Bogendoerfer Cc: Aleksandar Rikalo , Chao-ying Fu , Daniel Lezcano , Dragan Mladjenovic , Geert Uytterhoeven , Greg Ungerer , Hauke Mehrtens , Ilya Lipnitskiy , Jiaxun Yang , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Marc Zyngier , Paul Burton , Peter Zijlstra , Serge Semin , Thomas Gleixner , Tiezhu Yang Subject: [PATCH v3 04/11] irqchip: mips-gic: Support multi-cluster in for_each_online_cpu_gic() Date: Tue, 31 Oct 2023 17:49:20 +0100 Message-Id: <20231031164927.371663-5-aleksandar.rikalo@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> References: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> X-ClientProxiedBy: AM0PR10CA0065.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::18) To VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0302MB3486:EE_|AM9PR03MB7187:EE_ X-MS-Office365-Filtering-Correlation-Id: eb3e7f4a-3b39-4b8b-b8c6-08dbda3161bb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AF7NbW9PLdqL9aw1/uWuzP/DdQdp/ZcNGKk+INBm+7X3rL1BvD/R+X2t6+eBqpOUSxuNMob5PFQzzpTtazWWk3GrFrXbA/J/etpl1qqOtQeQVG44S9a8s2zG99vfPioeF05G/gQ16bRgwduJuoUADRq+K1f78BtqyXYQIUMNlEWgeGIkcKMj7C37spj9K3K67XwZGKaEvKYnJHFBRJYyML78uM+lJJiR3BLyzbh9W8JrdjtVTiu179ixDCw2l7ct7XbLx7+9OvPIzBnbWfZeXYOyt+y5H+v+OX/WZbBaqyCzzmKAYHpkQqEaJuWzX5ZcE/bt6xFT5wbyyXZwxsLfGTVTL7xR944NqtmdW7qQ21PpmZocnWMocktAx72+hUEMSMHytb8WWWk05TmiEPJBmAyXul2prRuES6mmTMdo5gxg9ETA3zhP7SSJDevAZU0PffLAQ15it6afAWiVcvNz8IuAT3mDj8ctwpKzNSuuEZNRQFZQKGdp3/1zh/xKMW+tmIl7v1Que7Kol1dWBDt084slrPF2A4xfL5m6tVLlXcOnSz6Rbkjc899DVNVhXcq6UAlip6sSgItCJ781dYRwqgKi4aE5cZDmx4kAugpH3gW5xbfTDnejQeLE0JIHlYyE X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0302MB3486.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(376002)(136003)(346002)(39840400004)(230922051799003)(1800799009)(64100799003)(451199024)(186009)(41300700001)(44832011)(316002)(54906003)(6916009)(66946007)(66556008)(66476007)(8936002)(7416002)(478600001)(2906002)(4326008)(5660300002)(8676002)(6486002)(26005)(52116002)(6512007)(6506007)(2616005)(83380400001)(36756003)(1076003)(38350700005)(38100700002)(6666004)(86362001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: x0R3kE8UgxS3Fi6zSkA2SdKRmmW3AzyGwX9TII5HLgW1QUM06SzVW6LhKToeoIgbCtsjwLcEjVOJgemzFlc3cFTx1Xmt6EJ/11zkBDJhHWHeExOZ4brI0qCHUbMJBtjgAtOA06oAsRVJRBZXiuy4uF0JzxUw7k12902niRM+hS9ZdeUjyvQZuevoHKodX0skFGz18gEEadDQDDDgKvdFGxW/yo7yEY34LUFpCWjCzwEx9SoXTgwQJ/VnQX+WxTg7Rs5moA/Gyg2i0JYqjdEIo3ab/HLOe3YI+nxDWjG9wXqLzdSFD9gYFgVahxX7O4setuXZp8WXE2Y659blgijQkaIIgbWeWcBszyGHpdV2yXpxNGCXECUp/CY2yTr91uYPo+06l/sHrABefzq6UTWBiOWjuUMei3H1kr8IA8YFpqQBrUBV1EgcZfmeY5Jd9F4o7ZZBTjq4yOcOFg4kJcBa+45XyvJzCXBIFoLmjuJzEqn12pqcTp9tWnd7L+ApBtOdd02U6rlbb4x6LsdjK4EegsAiEdALsLfT8XRsmog0LuHEzkm0T7oie1+znbBeG7ONfgX6CfD+X7fHgLKYwbjAuGwGVmpONmCE9mrXonLTsw3z3YSK/vxEv4tmV6tWAa/4ONDPgWxS07xc2vLeVV9Kzcj2A0SLWGCt8/V+JuuTk5v9Dqc0o3HlvFPhciSU1Ts/Y5MJBuXphcj1vGZdWGA8r/5rq0YjFbLnLdrAfci9Tmpj3/alAHFrj5bJNIGwiMV/RAqx2mIXP0P3FxmvvZbziSn37FCx4uu4paWpyxXmkixq4eT+GmyHx/g42LT8FUnvkvqP+O8MLfqUiOlmOX2YEHeegCOFX97PdqCgs2lVnJfQH5aT2A/32ZLL60Rp1vz6Q/UyApmTq2YO3M3Tcbp7c1+2PSIP/AdWYv/Xpb1/7Yidp+NDB8N2dkvqT2T7c0PGnhcIG4fNN8onVdHVJRl65WlK7ZtDCI+xFzxpm2cmvWnDARvvibyhNYKM6Hxt+TFQ4aYusd6/KZDS7j7sDUM6ag3hB8RNZXz5NfxLrcAtghl6dUylHWZ9tX76a9NV32f1Q+rLE8Tzy5+ONLgUlOnfISyjdF9arHhxq5eNWBe3KPZgW46sKeRa3JN4xV2w3ph/WJckoJqERaSpmjUA+kDIAHOXZuhNnFIcVOZ8uw31p9+dZfVTVauvcQprhNu84xq2vQFan2ta60SaSDdaRZiKpd/QEwkF5jJFliO/Vex64aDYvRYKpHUonbeK2p0vXPusTJlbwj84U8eFxFJ1hntRiQ5z1io6iz2GSQTCG/gN1QxlO7gKuElbqzwyCB+qa1ZEXVxp+5OArqqZTT/WKL0acPiCY1rHzq3Ub3+BW03MXABo6wPV/R0hIzkrvjcvOsXB+BXLbMPhmPb7A0tjCqG1qtmQlekWraenFYpxaYY/i+ZhaCzAXmzDlDLXRyjD9E/UaE8K6xs6bgK+kK8xVc6KgJISBTEaqea7L8yPHs/r+yBQ2pIEbQ5TMIvRa1PZboW3z7YRM/fDTQbqLbH8JB3GlB14DUHPL/s5iUNZEYB88qWBRCi2HFM6+aiMIwEDQ18kXUQJk3PDGSMNPqP0QS4x4w== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: eb3e7f4a-3b39-4b8b-b8c6-08dbda3161bb X-MS-Exchange-CrossTenant-AuthSource: VI1PR0302MB3486.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 16:49:43.2572 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8chkTFbEuC5q2LC+w3S30s5jf7gpb1FxPlF8zoZEKhPUsSJNfebhcMJzV3H2g/ut0Suu8In7BULBbEYHJ2BQfjjI3baOQKbBk+FzShRHlTk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7187 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Paul Burton Introduce support for multi-cluster GIC register access in __gic_with_next_online_cpu(), and therefore in its user for_each_online_cpu_gic(). We access registers in remote clusters using the CM's GCR_CL_REDIRECT register, and so here we delegate to mips_cm_lock_other() in order to configure this access. With this done, users of gic_with_each_online_cpu() gain support for multi-cluster with no further changes. Signed-off-by: Paul Burton Signed-off-by: Chao-ying Fu Signed-off-by: Dragan Mladjenovic Signed-off-by: Aleksandar Rikalo --- drivers/irqchip/irq-mips-gic.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c index 9e7182150b5c..317ccc2593d1 100644 --- a/drivers/irqchip/irq-mips-gic.c +++ b/drivers/irqchip/irq-mips-gic.c @@ -70,6 +70,20 @@ static int __gic_with_next_online_cpu(int prev) { unsigned int cpu; + /* + * Unlock access to the previous CPU's GIC local register block. + * + * Delegate to the CM locking code in the multi-cluster case, since + * other clusters can only be accessed using GCR_CL_REDIRECT. + * + * In the single cluster case we don't need to do anything; the caller + * is responsible for maintaining gic_lock & nothing should be + * expecting any particular value of GIC_VL_OTHER so we can leave it + * as-is. + */ + if ((prev != -1) && mips_cps_multicluster_cpus()) + mips_cm_unlock_other(); + /* Discover the next online CPU */ cpu = cpumask_next(prev, cpu_online_mask); @@ -80,10 +94,16 @@ static int __gic_with_next_online_cpu(int prev) /* * Lock access to the next CPU's GIC local register block. * + * Delegate to the CM locking code in the multi-cluster case, since + * other clusters can only be accessed using GCR_CL_REDIRECT. + * * In the single cluster case we simply set GIC_VL_OTHER. The caller * holds gic_lock so nothing can clobber the value we write. */ - write_gic_vl_other(mips_cm_vp_id(cpu)); + if (mips_cps_multicluster_cpus()) + mips_cm_lock_other_cpu(cpu, CM_GCR_Cx_OTHER_BLOCK_LOCAL); + else + write_gic_vl_other(mips_cm_vp_id(cpu)); return cpu; } @@ -105,6 +125,9 @@ static inline void __lockdep_assert_held(raw_spinlock_t *gic_lock) * * The caller must hold gic_lock throughout the loop, such that GIC_VL_OTHER * cannot be clobbered. + * + * Please note that if you start a loop this way, it must be completed to the + * end, otherwise, GIC local register block will remain locked. */ #define for_each_online_cpu_gic(cpu, gic_lock) \ for (__lockdep_assert_held(gic_lock), \ From patchwork Tue Oct 31 16:49:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Rikalo X-Patchwork-Id: 13442125 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 DB213C4708E for ; Tue, 31 Oct 2023 16:52:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347002AbjJaQwe (ORCPT ); Tue, 31 Oct 2023 12:52:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346911AbjJaQwR (ORCPT ); Tue, 31 Oct 2023 12:52:17 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2093.outbound.protection.outlook.com [40.107.21.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3355BD4C; Tue, 31 Oct 2023 09:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JjcRJCW+e/sakOy+cTxQLJB6Qq52C9QiNfEpZCH3TEElWNxU/BUXufuUSZLxjWRDHm4/iUBrwxAMtYbeWhKvUNjoqU5XsFXnAitX3wEd+aB51cA3sjrV6e5z7/cgE8qChrclbqUO2fGxbO48YwIxY/az9bkvvhp66i2d3KPyfpRXgtXilvy/dxMdvLTSBlR2FDpEPEo4+Tv71kU9JhW87pOFrJdoOCfBsOGw+KkpoSHtNFoYxDp9upNW525MGK7CtxfoiHU2yiYLfo/1664DP//oaHQF8z7pC4VM+BNDgz1rI+5qc3Z2E6nsBpA6jXHPpNB/trQVMCy8+kZZODbmkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=38E6eM+S/5PuGgIFZvPuBnf0H+1kJD3Y+e8qzqv2r1s=; b=V9gKpJs21886leUkNCYlhvM92cnxF0/rpdigSBsFI7GFlSe3yPEymCNwxIdBs2ipHUau7/0GmGwfOEsJxos4hqDXjjW7IWGynNqvfb1or0cq6a5jrPjXEVDLkI9GEtcRsEoh+EZCpWAgXinL5LD/xkvi6tj0FITJ04/v1558/4BvqW3FDjTFNrPRy9yOdBnRGgdLZZtFWyf5jn+F0Ow55fPYzIP0qpk+j81yyrz8Dl19PT0R91IpFEgZw9TuvOgN91IRzvhs/ZZfWyPRfCOLBftgS8qiYR068GTXfsoRnBOkoQHyr8YvuubaJOcMfYMiQwJK7YoMykM5CxmnLvD5DQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=38E6eM+S/5PuGgIFZvPuBnf0H+1kJD3Y+e8qzqv2r1s=; b=Yb9eAwTGC9yw0PBLq5EDVIGfTo2BDdN1GgliqQdZkDeVzHpmYC5bVhu3HUjPlifEQc5z4F87C7oLz/u6ECftN+Q/mnQ+us/NoqZHXn0yvvjXtrKaYi+mkp4frwj3gIILzEh9rqwXRbPh2JcYTr9KkeSUdIEbwx1dw1F5TyavVRU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=syrmia.com; Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) by AM9PR03MB7187.eurprd03.prod.outlook.com (2603:10a6:20b:26f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19; Tue, 31 Oct 2023 16:49:45 +0000 Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa]) by VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa%4]) with mapi id 15.20.6907.032; Tue, 31 Oct 2023 16:49:45 +0000 From: Aleksandar Rikalo To: Thomas Bogendoerfer Cc: Aleksandar Rikalo , Chao-ying Fu , Daniel Lezcano , Dragan Mladjenovic , Geert Uytterhoeven , Greg Ungerer , Hauke Mehrtens , Ilya Lipnitskiy , Jiaxun Yang , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Marc Zyngier , Paul Burton , Peter Zijlstra , Serge Semin , Thomas Gleixner , Tiezhu Yang Subject: [PATCH v3 05/11] irqchip: mips-gic: Setup defaults in each cluster Date: Tue, 31 Oct 2023 17:49:21 +0100 Message-Id: <20231031164927.371663-6-aleksandar.rikalo@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> References: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> X-ClientProxiedBy: AM0PR10CA0065.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::18) To VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0302MB3486:EE_|AM9PR03MB7187:EE_ X-MS-Office365-Filtering-Correlation-Id: e389fbf5-ca02-460c-7120-08dbda3162d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ebos1BIIuH61sr81rw72KWDOgPwx5z4OsyXo6GEh445oLSWzMXmIBzfvYRxmsOV0xZimHS5wjGJ2vNM6pVq1oIZ+0RXnEZhTkBmGqtXilAPbHtuL3tMtaozHwwHvUTPUQCSBU0OnhBMMA6cUMFWNok3/Jy60XKzyVhc09a68WwJLDyiPo+Lu1XGGJn25F/4EsTH3T+y1+GndxJ5kVQ0EPdPJJim5VULLiwcL/hSuzliBaG7QFwQrA3n8BkN36DGP5mizFmtNunPVs3jf45xZ/yveWpbAtNYAqeWvf9WeIFGfDS/6eAYchYNzYD6tjw9uRMnMF7xuOgQk0oA002fIMPthdrfmFDN+WQI5Iri0HuuAJBHfqOHzPozUxlKw9MwjraUZZs67JF2m5P2brjyrzt8olhBT173LqL04bHPIWiqGYgF9ChI6323SHs4tUA3iUZbabLA3S+qJEihyUgbdtNMUJ9S0JGb529Firm8za5s/AYDh2KWndQ+qDqcYy+C7KgZof5a+Ny7l6cSgKl67fz9jGcQO3HOzDqFLpT7yZ3Utl95eb5rD9aPgj2lAeekGWV2GRieNu+t+YCUYRrD8/3k089bdCkwmNRXpfhkxvcPKunnKGXyyIX7ZEIaTriuy X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0302MB3486.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(376002)(136003)(346002)(39840400004)(230922051799003)(1800799009)(64100799003)(451199024)(186009)(41300700001)(44832011)(316002)(54906003)(6916009)(66946007)(66556008)(66476007)(8936002)(7416002)(478600001)(2906002)(4326008)(5660300002)(8676002)(6486002)(26005)(52116002)(6512007)(6506007)(2616005)(83380400001)(36756003)(1076003)(38350700005)(38100700002)(6666004)(86362001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: r1UkWIKcKj7Ix5HpBF4MBumoUdlZMT9Hdxtgt5e5xP6sRY9MCLJ2kpMoDfYA5NaJN5LY56nFylc42sTxidlhOpLqcK4iQw5dIrKuVlgU6fPu9w06dnqDZsOh9L4SyuLYHkgdWXc7OmWMIYWrGL5ZlhgEzK9k+7hljLod+T6TbLjqSh8Bk/JMTA9J+82WbmMS66zJgLRAZ6T25r5WLsK83o3xP7NGNm3ak5efEyn/SurBZeCl/cj/4U5C5YLnyxjqHK0maBhbtztY3YI9SX5JhfmGG2sVktM0JZ/ZvYx+/ccdJgNuHsBxo3sf5UW5ANorq4IXQXoI7YJ81fUQ1KRRuR9K6Zqgeyn3AVNavFzIVAcP7j8BtLzr2++msBxWcYMNCCLm8enAh7bwHr0eAKhOqdnD/vJWJWqlYry/HFXKsC2/4bZGjvATrzNkJUGaIvWZVKGZoU7rw6EgYwBYTpJN8/WeqbAaPkgriuKENLXLeP+VlV7dDQzquQZsmlZqF5YA3UE4gT16M2IEBnWgKrZ0/IgU0c7aqR/KTuwqi2kQo5ibMjtWlPyUf0yssmUUSBgg5tUtSCbYA03FMEaY74jfEAICjLTi+AvE8Rsm28WEiA8ni32GAUuWCsBwYuYf0DyFBr0kGGdH94ZhSyYLQ5RSM/THJVTYQhqwQURv1Qy87SEmusio22fAJbxcL4Cbfb59HIur3bkyDvj++dwKEHsHipACr27VVQ5tvMcW98vLN9OR2HnnBSHiPmsezFwqITXnPfQg34QsqcpEpx/VxngwDgJMA6tPwoDhRhnst9F0b0NkPNj0GSbYY3/pzF0yBqEp43Zic2PcmX93jHVOqnUkbOXCjj4JxoQQr0RdftBVMc95DAhHIl5fXJiRPJQ9hELdEv7N5WNFpv4SL9aoEB0LcRPiMu3sGsPPayxNO8HGrVdmDLQEKxsnkDPiS8wPQ3USbAWq5eQK+NwWI9VZuHAymND+pHz8BYcqYhv6KV8KwNlW3D0zku7jH+PpjphnM372nlNPbc0ci6M5058bOg5B/8zNPSV24rmu5bevomimAgEFNqv7ULE9/GnvhgGQLGhgYKQ8P7cdItE0b+hnL6AD4M1OWxWuFjhdvIuXaf0F+/EoVoKVxM5THsQ76oW6/GkG0Fi+yTgGrDXbAeG/mXoHbWApNYlRabh+SK7+dAsjKq+NTrkHZbHDs8cfcrWiPxXt+fG5dH+CsWWctAtwS4hZ2E3R2m/WXnFQp13yvQVyuxDr18IYhoaZqbO1gQzv5AQqQgpyn9BO3j3at5F90Rj1fsBMz547jzxordaMnZ6vce2j05jkQvdE9j2m8DNrDDNhent8EIQF5QjJRDyGQwtIuFnOMgUCTB5cwe3ipkPEykKr9MQPlvWkCoS7HdgXkDFtZLv/HNJT8GEgN1imiYzUKrnL5MCCotztghebQsl75CHsekIGBu6BMeNNOI4Y8e5kiL+E/D5sQRuZkAdNYfd0Ymme+V9rFeepp/7fuq7PAy4qR8kUuFR211wELBNyIRDWtYB34biJieyXDL47cjJcGUnmlNoUImnkj7iX4/p4R0R0YYPykc0W9SiirTNMWEbyGAFw8G/ek7HztgKj92c8NA== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e389fbf5-ca02-460c-7120-08dbda3162d7 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0302MB3486.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 16:49:45.0911 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vRoPS8Ti+rh8Hn5VGmD65h318+S82Um1bX2QiSLRze4LyvnBft4bYKsBJXDYwvsFz4loj72czRUbGhfjUL1UBgAMB9RpAvHd6v7ZERpHgmY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7187 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Chao-ying Fu In multi-cluster MIPS I6500 systems we have a GIC per cluster. The default shared interrupt setup that we configure in gic_of_init() will only apply to the GIC in the cluster containing the boot CPU, leaving the GICs of other clusters unconfigured. Similarly configure other clusters here. Signed-off-by: Chao-ying Fu Signed-off-by: Dragan Mladjenovic Signed-off-by: Aleksandar Rikalo --- drivers/irqchip/irq-mips-gic.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c index 317ccc2593d1..cdd8973912a9 100644 --- a/drivers/irqchip/irq-mips-gic.c +++ b/drivers/irqchip/irq-mips-gic.c @@ -800,7 +800,7 @@ static int gic_cpu_startup(unsigned int cpu) static int __init gic_of_init(struct device_node *node, struct device_node *parent) { - unsigned int cpu_vec, i, gicconfig; + unsigned int cpu_vec, i, gicconfig, cl, nclusters; unsigned long reserved; phys_addr_t gic_base; struct resource res; @@ -881,11 +881,30 @@ static int __init gic_of_init(struct device_node *node, board_bind_eic_interrupt = &gic_bind_eic_interrupt; - /* Setup defaults */ - for (i = 0; i < gic_shared_intrs; i++) { - change_gic_pol(i, GIC_POL_ACTIVE_HIGH); - change_gic_trig(i, GIC_TRIG_LEVEL); - write_gic_rmask(i); + /* + * Initialise each cluster's GIC shared registers to sane default + * values. + * Otherwise, the IPI set up will be erased if we move code + * to gic_cpu_startup for each cpu. + */ + nclusters = mips_cps_numclusters(); + for (cl = 0; cl < nclusters; cl++) { + if (cl == cpu_cluster(¤t_cpu_data)) { + for (i = 0; i < gic_shared_intrs; i++) { + change_gic_pol(i, GIC_POL_ACTIVE_HIGH); + change_gic_trig(i, GIC_TRIG_LEVEL); + write_gic_rmask(i); + } + } else { + mips_cm_lock_other(cl, 0, 0, + CM_GCR_Cx_OTHER_BLOCK_GLOBAL); + for (i = 0; i < gic_shared_intrs; i++) { + change_gic_redir_pol(i, GIC_POL_ACTIVE_HIGH); + change_gic_redir_trig(i, GIC_TRIG_LEVEL); + write_gic_redir_rmask(i); + } + mips_cm_unlock_other(); + } } return cpuhp_setup_state(CPUHP_AP_IRQ_MIPS_GIC_STARTING, From patchwork Tue Oct 31 16:49:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Rikalo X-Patchwork-Id: 13442127 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 30B6EC001DD for ; Tue, 31 Oct 2023 16:52:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346918AbjJaQwn (ORCPT ); Tue, 31 Oct 2023 12:52:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346925AbjJaQwT (ORCPT ); Tue, 31 Oct 2023 12:52:19 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2090.outbound.protection.outlook.com [40.107.21.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46BB3D51; Tue, 31 Oct 2023 09:49:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J+u3BRrCf8XM0tL/DSELf5pTMJwL7GJ4/4yXipQrC9yb+6jtQO0HPRvA17ZlDjnTGM61PY0TTA6N6V/BvOViwKAqP8mnNZmwVsBj4HGptIhofBCEkH/FubGY+z4F/cFTdcb+LtDNGOFNJcxUQ2Abpnvi8JLBIaiTXR3osys7Wo6yAqCwqNDMVQ0Vcx4jRlDbVJy2uAtTT9k3CCfoCsS6NfOMy3QHh434TQ3HUVrT8IkNDj0zAXcxuAWmBPzwi5UcH1SYVHGmS9Eqt18S82gDF3Hr3epdh4DvS7Z+kb/5bpKYWzAmHe3P+qJBOH3U2DceiR9bz/OeL2kTLsNQ3+aElA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iUH/PV7lf2dA/eXCHHs/LTQ+8FVXpAU8YrKqDiAofvo=; b=nt3ZRDTT1MOik916FkmG5BSnTyXDQ3EqMzGDNoz+BIgc2oe/xo4SvtOfJfimz+yVdgR5s3tVzYGMhZVz18ee2BOFccCIml+xphM7tvRlWJke5VK/7whh9qYhoLddfs31l38G82iXGSSxuddy5Bddz/1aZxSGbxagmYUe3t5F0Tn8TrFYS3v2gA1rxjSVLKnRQftIHh6nDIbDqzOUmKPEc+0bFnxezwfzYqXhE+LYom455N4ouz/+jaFkzEcKsle2WhCeX7ms0CWq9dBnpf48uy1YPMEgl+3J92ztBRxTWNTUOtHr1p/8lUHe8UnLMRHghYgvuSEZ0gjxjFFoylCoJQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iUH/PV7lf2dA/eXCHHs/LTQ+8FVXpAU8YrKqDiAofvo=; b=0ZMcffUnkM82D2Lh4EFCG85oJ975NQfUdMmaCpUkJQhSJ+IfInswDVO3/7jgFQJB6pfzf1U0VXr0tg8kd//L/C6r5Wh6hUNyhdLhyg+754UJXTx3dczIQsKLkrJ37e3mBq5vIF4OshKaHQoeTznftMHJBA+UOvyHQXBH+28z3Xo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=syrmia.com; Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) by AM9PR03MB7187.eurprd03.prod.outlook.com (2603:10a6:20b:26f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19; Tue, 31 Oct 2023 16:49:47 +0000 Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa]) by VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa%4]) with mapi id 15.20.6907.032; Tue, 31 Oct 2023 16:49:47 +0000 From: Aleksandar Rikalo To: Thomas Bogendoerfer Cc: Aleksandar Rikalo , Chao-ying Fu , Daniel Lezcano , Dragan Mladjenovic , Geert Uytterhoeven , Greg Ungerer , Hauke Mehrtens , Ilya Lipnitskiy , Jiaxun Yang , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Marc Zyngier , Paul Burton , Peter Zijlstra , Serge Semin , Thomas Gleixner , Tiezhu Yang Subject: [PATCH v3 06/11] irqchip: mips-gic: Multi-cluster support Date: Tue, 31 Oct 2023 17:49:22 +0100 Message-Id: <20231031164927.371663-7-aleksandar.rikalo@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> References: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> X-ClientProxiedBy: AM0PR10CA0065.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::18) To VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0302MB3486:EE_|AM9PR03MB7187:EE_ X-MS-Office365-Filtering-Correlation-Id: b830f2ca-5b7d-49b2-c235-08dbda31644d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Sh0ZRkpuXadeDuaObdP2nJk76jOUHXI/gqF6auBuXdjfWxDIBthCOcwpJQIdYbxpvZZBvoJexJBAiX1hsD/U0LN/X8Gj/A5r9mDgEQp5+dxbU2pC52ACdORstJvnHTpcF1ER0tC2UXPkxYvyaAx39/woJxg6/WUbmZP74BA8iJVeSG7siRroReJrRyBVMvcsj6ulLriXHghVAnlp9RNcQOGYbj250L+JPz+mf6Fese7pvP8Cplxp4Nt7AAeNHdX7UiPimgN761zYPY2BTwV0H3DHgGad9RnZRuEPUN+gtRRoX3aw/OLSwyT9FMFvLAZUXZVtgghcR14GcZqyhhKRQ96CDV+GAz9lTfIcnEQh+yw/1cgX/l2jXoGvJsnEP0s8t/G55Yf0m9uWom38z2GaNCreZfrCeLTQATixIPMeVlyRaC566SQRiymLKWu4tqDbbBO0FUHvgypy5ySTttfZPAugrVsMuw840MvhMwJZpP8Ca8C5QMSS4IV9sBtWXr2fPSRbJ/YBDzA4goAz5ZYioWskeBea/QUMk7Qa5SUjiErwbp/2xBGYc0e4VqeuIi8GmKWMil+VUDvjzcVXOlARRuG6iy3yZO1TR3lg2khLea1HT1kN+FOd/doSszFK8QFsBR38WE5EkqgO6thhmr1w+VT0Do1LxCfDly9cj++DN2o= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0302MB3486.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(376002)(136003)(346002)(39840400004)(230273577357003)(230173577357003)(230922051799003)(1800799009)(64100799003)(451199024)(186009)(41300700001)(44832011)(316002)(54906003)(6916009)(66946007)(66556008)(66476007)(8936002)(30864003)(7416002)(478600001)(2906002)(4326008)(5660300002)(8676002)(6486002)(26005)(52116002)(6512007)(6506007)(2616005)(83380400001)(36756003)(1076003)(38350700005)(38100700002)(6666004)(86362001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1/qmUVBxeH5MvjgJJm2hv16h+RrHeVYYifCGe55M0GOlvhzQst7WYuXDcE3fWiC19NFNP7K/jk7xPdtuUsS7ttQYtQZxQDjJny57voQtutmHGTVhgVkWYz0cxRMEbgYWIrBtRL/4m8jQP6QLYRIs/AEgPFNoXlRz2UrV0F2AIYxmbjsEe/6TxcHo0GZzGvnkwbahedFI28OtbW3mdk73zcuVFpasDeoP44N4RMAY8fpkzr48Yd6vU9ReJF67ecaFyZWfI7IPMZAFB5kLdMvtfQzZzDoTrGWUaBITtznGKLpoJ/NKiXwOlKpgL0BgrqEnVXL1rcFSfvq1NSp6MRwtgOZg7DdbU19CJRjqxuRr4qCaxSuDItHMsZamzPGQDuhP/SaOmc/i+GWrPeVfMKVDmNIo9BB/HxoQ8Iuuh8O+ZeR/YLIvq6DuRsaimdkeLfBIGz06tvyJrh32u/9dhvDoSp/vzErQ7VfKGFVcp+issePNe0zXrq2Z7OyXzWFANYN8uVcdHcwNUnlNXtZKrtzNo3mTeYeCibVwu0UwBUY7kqZTejOhwi2nbl8qwIvfqquxKyk6RwCBGZY+vthPmPBybitfXjBy/s5Kfr42n0yDnJoD4VmGckSWckqyIeruhQKvB50pv/BYD7ryXMnU6XiY7ybuPefomWLs1B+6aDcwp6ywehYZpzvm4FtjeBi2+L3bA/7fH7gDoOZsNdfBIQo97Qr20gYHxdG3WnQwe03MVEqxGPL5PuMqPHnYSPHSaQIzgjwYwJQRva62iyw7ljIP1RjCAo0lUG67UIgy6IJpLt0qka/YngZzEj+VqkHFN8DcHi6WVjTbcVBODeyg4kIF0iTSPXd+QIGnxsWwYDNKmhFBvgYD1hmVSNeYka2uUddXdQRwyx2JdQvUkq5tKqzJiQ1ghYK+rkMx/CGneZM7+F2XsT+KIl8n67DpOEWBhYzsSN4AtVSiWIGgEjRQvcGbkrgrFEknhhL2mJjKTTLXPV2eKF8wNB7/cUFlBB3fZbTgxpJM8j7UzDOzq+84LpPm2pwD1krlF+xN1sYmPUIXQ2Guz6gB7hpRLAI1ZfXWtQNK7EnbAy0nXfhoT+eFA9IumstHHV+zOsgbWy9AY3vAR4sDZPT2VqLo2yaPDUsPMarYKl3smZTC6ngI8S0LOCS2aJxd804IgHdsO0gJw1VuLXdYrHAwPI0bNQr6Jzrng3v+YqEteRn0f6NSzuXkrwt0uX+XiLJaJIHFrkLme5eSCXHOH/VgZwmz+X4GkSk5KL8fu6pFmZyaCVWYTqxjdgG3qX3yByKEdRVEsfB2iyyIUSrZkMNQU218OSpmGJDuQHpojJFdhZGB/irw9+ybT/aBEpjW3IDzX/kkneuq2luuCdXcJ3TjW2LkWg2BDpfNr+nbQZwva4Z42ksuYobDaky5lbO5nCfPKU0mSYd7DFz11eYSFR4naheVhE2aeX6XXa3hjMpL5sPUVjCDTwAa1629VWrWf1citAtFpm5RvrIUfEcp8prhTjmGGo79DRxAZT9ag5ztr6CAqLVpTwW9dCWFoUhPvjBabP+7H37TuUk2irzfYRKgovNfLg8Q965aztXfrWGUszvo0l2tOYOgGyoaEg== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b830f2ca-5b7d-49b2-c235-08dbda31644d X-MS-Exchange-CrossTenant-AuthSource: VI1PR0302MB3486.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 16:49:47.6473 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3q2jhfBmP+hYdaVJynZM8G/yxNvQJfGqqOwsITTqIx3ZRtODS2y3mukbxpr5oTBdWdvtifGi9kUQf3vU9+Gy7DW1M/xYwWpIgZrLtF580Pk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7187 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Paul Burton The MIPS I6500 CPU & CM (Coherence Manager) 3.5 introduce the concept of multiple clusters to the system. In these systems each cluster contains its own GIC, so the GIC isn't truly global any longer. We do have the ability to access registers in the GICs of remote clusters using a redirect register block much like the redirect register blocks provided by the CM & CPC, and configured through the same GCR_REDIRECT register that we our mips_cm_lock_other() abstraction builds upon. It is expected that external interrupts are connected identically to all clusters. That is, if we have a device providing an interrupt connected to GIC interrupt pin 0 then it should be connected to pin 0 of every GIC in the system. This simplifies things somewhat by allowing us for the most part to treat the GIC as though it is still truly global, so long as we take care to configure interrupts in the cluster that we want them affine to. This patch introduces support for such multi-cluster systems in the MIPS GIC irqchip driver. We introduce a new gic_irq_lock_cluster() function which allows us to either: 1) Configure access to a GIC in a remote cluster via the redirect register block, using mips_cm_lock_other(). Or: 2) Detect that the interrupt in question is affine to the local cluster and we should use plain old GIC register access to the GIC in the local cluster. It is possible to access the local cluster's GIC registers via the redirect block, but keeping the special case for them is both good for performance (because we avoid the locking & indirection overhead of using the redirect block) and necessary to maintain compatibility with systems using CM revisions prior to 3.5 which don't support the redirect block. The gic_irq_lock_cluster() function relies upon an IRQs effective affinity in order to discover which cluster the IRQ is affine to. In order to track this & allow it to be updated at an appropriate point during gic_set_affinity() we select the generic support for effective affinity using CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK. gic_set_affinity() is the one function which gains much complexity. It now deconfigures routing to any VP(E), ie. CPU, on the old cluster when moving affinity to a new cluster. Because we only configure an interrupts trigger type in the cluster which it is affine to we call gic_set_type() to configure that in the new cluster, after having updated the effective affinity mask such that gic_irq_lock_cluster() begins operating on the new cluster. Finally we map the interrupt to the appropriate pin & VP(E) in the new cluster. gic_shared_irq_domain_map() moves its update of the IRQs effective affinity to before its use of gic_irq_lock_cluster(), in order to ensure we operate on the cluster the IRQ is affine to. The remaining changes are straightforward use of the gic_irq_lock_cluster() function to select between local cluster & remote cluster code-paths when configuring interrupts. Signed-off-by: Paul Burton Signed-off-by: Chao-ying Fu Signed-off-by: Dragan Mladjenovic Signed-off-by: Aleksandar Rikalo --- drivers/irqchip/Kconfig | 1 + drivers/irqchip/irq-mips-gic.c | 161 +++++++++++++++++++++++++++++---- 2 files changed, 143 insertions(+), 19 deletions(-) diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index f7149d0f3d45..be9f0797c4ed 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -328,6 +328,7 @@ config KEYSTONE_IRQ config MIPS_GIC bool + select GENERIC_IRQ_EFFECTIVE_AFF_MASK select GENERIC_IRQ_IPI if SMP select IRQ_DOMAIN_HIERARCHY select MIPS_CM diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c index cdd8973912a9..8e9046516e63 100644 --- a/drivers/irqchip/irq-mips-gic.c +++ b/drivers/irqchip/irq-mips-gic.c @@ -135,6 +135,41 @@ static inline void __lockdep_assert_held(raw_spinlock_t *gic_lock) (cpu) = __gic_with_next_online_cpu(cpu), \ (cpu) < nr_cpu_ids;) +/** + * gic_irq_lock_cluster() - Lock redirect block access to IRQ's cluster + * @d: struct irq_data corresponding to the interrupt we're interested in + * + * Locks redirect register block access to the global register block of the GIC + * within the remote cluster that the IRQ corresponding to @d is affine to, + * returning true when this redirect block setup & locking has been performed. + * + * If @d is affine to the local cluster then no locking is performed and this + * function will return false, indicating to the caller that it should access + * the local clusters registers without the overhead of indirection through the + * redirect block. + * + * In summary, if this function returns true then the caller should access GIC + * registers using redirect register block accessors & then call + * mips_cm_unlock_other() when done. If this function returns false then the + * caller should trivially access GIC registers in the local cluster. + * + * Returns true if locking performed, else false. + */ +static bool gic_irq_lock_cluster(struct irq_data *d) +{ + unsigned int cpu, cl; + + cpu = cpumask_first(irq_data_get_effective_affinity_mask(d)); + BUG_ON(cpu >= NR_CPUS); + + cl = cpu_cluster(&cpu_data[cpu]); + if (cl == cpu_cluster(¤t_cpu_data)) + return false; + + mips_cm_lock_other(cl, 0, 0, CM_GCR_Cx_OTHER_BLOCK_GLOBAL); + return true; +} + static void gic_clear_pcpu_masks(unsigned int intr) { unsigned int i; @@ -181,7 +216,12 @@ static void gic_send_ipi(struct irq_data *d, unsigned int cpu) { irq_hw_number_t hwirq = GIC_HWIRQ_TO_SHARED(irqd_to_hwirq(d)); - write_gic_wedge(GIC_WEDGE_RW | hwirq); + if (gic_irq_lock_cluster(d)) { + write_gic_redir_wedge(GIC_WEDGE_RW | hwirq); + mips_cm_unlock_other(); + } else { + write_gic_wedge(GIC_WEDGE_RW | hwirq); + } } int gic_get_c0_compare_int(void) @@ -249,7 +289,13 @@ static void gic_mask_irq(struct irq_data *d) { unsigned int intr = GIC_HWIRQ_TO_SHARED(d->hwirq); - write_gic_rmask(intr); + if (gic_irq_lock_cluster(d)) { + write_gic_redir_rmask(intr); + mips_cm_unlock_other(); + } else { + write_gic_rmask(intr); + } + gic_clear_pcpu_masks(intr); } @@ -258,7 +304,12 @@ static void gic_unmask_irq(struct irq_data *d) unsigned int intr = GIC_HWIRQ_TO_SHARED(d->hwirq); unsigned int cpu; - write_gic_smask(intr); + if (gic_irq_lock_cluster(d)) { + write_gic_redir_smask(intr); + mips_cm_unlock_other(); + } else { + write_gic_smask(intr); + } gic_clear_pcpu_masks(intr); cpu = cpumask_first(irq_data_get_effective_affinity_mask(d)); @@ -269,7 +320,12 @@ static void gic_ack_irq(struct irq_data *d) { unsigned int irq = GIC_HWIRQ_TO_SHARED(d->hwirq); - write_gic_wedge(irq); + if (gic_irq_lock_cluster(d)) { + write_gic_redir_wedge(irq); + mips_cm_unlock_other(); + } else { + write_gic_wedge(irq); + } } static int gic_set_type(struct irq_data *d, unsigned int type) @@ -309,9 +365,16 @@ static int gic_set_type(struct irq_data *d, unsigned int type) break; } - change_gic_pol(irq, pol); - change_gic_trig(irq, trig); - change_gic_dual(irq, dual); + if (gic_irq_lock_cluster(d)) { + change_gic_redir_pol(irq, pol); + change_gic_redir_trig(irq, trig); + change_gic_redir_dual(irq, dual); + mips_cm_unlock_other(); + } else { + change_gic_pol(irq, pol); + change_gic_trig(irq, trig); + change_gic_dual(irq, dual); + } if (trig == GIC_TRIG_EDGE) irq_set_chip_handler_name_locked(d, &gic_edge_irq_controller, @@ -329,25 +392,72 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *cpumask, bool force) { unsigned int irq = GIC_HWIRQ_TO_SHARED(d->hwirq); + unsigned int cpu, cl, old_cpu, old_cl; unsigned long flags; - unsigned int cpu; + /* + * The GIC specifies that we can only route an interrupt to one VP(E), + * ie. CPU in Linux parlance, at a time. Therefore we always route to + * the first online CPU in the mask. + */ cpu = cpumask_first_and(cpumask, cpu_online_mask); if (cpu >= NR_CPUS) return -EINVAL; - /* Assumption : cpumask refers to a single CPU */ - raw_spin_lock_irqsave(&gic_lock, flags); + old_cpu = cpumask_first(irq_data_get_effective_affinity_mask(d)); + old_cl = cpu_cluster(&cpu_data[old_cpu]); + cl = cpu_cluster(&cpu_data[cpu]); - /* Re-route this IRQ */ - write_gic_map_vp(irq, BIT(mips_cm_vp_id(cpu))); + raw_spin_lock_irqsave(&gic_lock, flags); - /* Update the pcpu_masks */ - gic_clear_pcpu_masks(irq); - if (read_gic_mask(irq)) - set_bit(irq, per_cpu_ptr(pcpu_masks, cpu)); + /* + * If we're moving affinity between clusters, stop routing the + * interrupt to any VP(E) in the old cluster. + */ + if (cl != old_cl) { + if (gic_irq_lock_cluster(d)) { + write_gic_redir_map_vp(irq, 0); + mips_cm_unlock_other(); + } else { + write_gic_map_vp(irq, 0); + } + } + /* + * Update effective affinity - after this gic_irq_lock_cluster() will + * begin operating on the new cluster. + */ irq_data_update_effective_affinity(d, cpumask_of(cpu)); + + /* + * If we're moving affinity between clusters, configure the interrupt + * trigger type in the new cluster. + */ + if (cl != old_cl) + gic_set_type(d, irqd_get_trigger_type(d)); + + /* Route the interrupt to its new VP(E) */ + if (gic_irq_lock_cluster(d)) { + write_gic_redir_map_pin(irq, + GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin); + write_gic_redir_map_vp(irq, BIT(mips_cm_vp_id(cpu))); + + /* Update the pcpu_masks */ + gic_clear_pcpu_masks(irq); + if (read_gic_redir_mask(irq)) + set_bit(irq, per_cpu_ptr(pcpu_masks, cpu)); + + mips_cm_unlock_other(); + } else { + write_gic_map_pin(irq, GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin); + write_gic_map_vp(irq, BIT(mips_cm_vp_id(cpu))); + + /* Update the pcpu_masks */ + gic_clear_pcpu_masks(irq); + if (read_gic_mask(irq)) + set_bit(irq, per_cpu_ptr(pcpu_masks, cpu)); + } + raw_spin_unlock_irqrestore(&gic_lock, flags); return IRQ_SET_MASK_OK; @@ -503,11 +613,21 @@ static int gic_shared_irq_domain_map(struct irq_domain *d, unsigned int virq, unsigned long flags; data = irq_get_irq_data(virq); + irq_data_update_effective_affinity(data, cpumask_of(cpu)); raw_spin_lock_irqsave(&gic_lock, flags); - write_gic_map_pin(intr, GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin); - write_gic_map_vp(intr, BIT(mips_cm_vp_id(cpu))); - irq_data_update_effective_affinity(data, cpumask_of(cpu)); + + /* Route the interrupt to its VP(E) */ + if (gic_irq_lock_cluster(data)) { + write_gic_redir_map_pin(intr, + GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin); + write_gic_redir_map_vp(intr, BIT(mips_cm_vp_id(cpu))); + mips_cm_unlock_other(); + } else { + write_gic_map_pin(intr, GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin); + write_gic_map_vp(intr, BIT(mips_cm_vp_id(cpu))); + } + raw_spin_unlock_irqrestore(&gic_lock, flags); return 0; @@ -687,6 +807,9 @@ static int gic_ipi_domain_alloc(struct irq_domain *d, unsigned int virq, if (ret) goto error; + /* Set affinity to cpu. */ + irq_data_update_effective_affinity(irq_get_irq_data(virq + i), + cpumask_of(cpu)); ret = irq_set_irq_type(virq + i, IRQ_TYPE_EDGE_RISING); if (ret) goto error; From patchwork Tue Oct 31 16:49:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Rikalo X-Patchwork-Id: 13442128 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 B6C64C4167D for ; Tue, 31 Oct 2023 16:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347016AbjJaQwz (ORCPT ); Tue, 31 Oct 2023 12:52:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346564AbjJaQwV (ORCPT ); Tue, 31 Oct 2023 12:52:21 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2111.outbound.protection.outlook.com [40.107.21.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61818D66; Tue, 31 Oct 2023 09:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Eeq4Us+7gLBAUUS54Yeh1SgmxfEOj6Rv7miU0TIfM5affryinP69Lcq7oQhOfGNfsvYWe838IbPqY3+ddYXlgVtV0JjXQShjFQpeQMlWRrPHHcbKh0P7WgrUL2gL/wUE/4jgie3CLb+VYjTV1k25t4ZkiqcVvnmFFomY5xclZTp1KTXqoHbHwKUPlpM4Cp4EqGeCiyvPJ50qh0Ba7fNlEpo1Q2Myw3iHL1KABI1GK5ITSd5bSEgaohICt+wtW3VOH88kVOmVbQOAw+nCMvqEnECSShyUvbUcaYEMXP04LGjSFqBLyBodi6n/+TAKNEV6v0pxJNyrDf9l4BfR46vnkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ycEafZF00N9zzFb7QKUWXvaaWImNBOBHoDnUbB3BRsg=; b=WB/mgxmHZth4KYS3wO2K1AzT21tSRUxitEDHAPAB6d4KHdwyn0ICf7bpqBoaux+F6q0sVOp3KdHK7KeurMgubhxWdEQ1aZ7Gnen3hO8jlyPVZ89kglH9NQzPAihsSk942SSh5ZcC2aIESPvHF3Vrbq6yGvWWAsaUQN+360Acoq8Ec2Xv/0/Xy1tJa9Uyp7Y+fjY3EFvsMHVOtSXJoqmlEncQvs/XD8t8ectknmFzjoJD1AeLpaybehX3njxpRYfbBNkkvq7D+KlFdVFJcgbM4mCUqcxhVBXbWIUb9rVAXxlrM7RGy6GBkVfUK0tODQ9eCdd/6HYPEWdFMGwAGjPxtg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ycEafZF00N9zzFb7QKUWXvaaWImNBOBHoDnUbB3BRsg=; b=Xc6VUORD0AdzUVHtEGLZDC3/pyB69+lj/UJ5ztmsnRCOmpK0VDO9XhPyLDHAGVoQ+dd1cmnF2/vznSt1Tsh/9XaN1XuY62AsFEzTlB6gS+olNwbt0D5WOpdZj72byxQigCdg2SVO0aRieK2sCAIdzoTQoQpE8Ot54ywCtytncOM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=syrmia.com; Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) by DB4PR03MB8706.eurprd03.prod.outlook.com (2603:10a6:10:382::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28; Tue, 31 Oct 2023 16:49:49 +0000 Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa]) by VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa%4]) with mapi id 15.20.6907.032; Tue, 31 Oct 2023 16:49:49 +0000 From: Aleksandar Rikalo To: Thomas Bogendoerfer Cc: Aleksandar Rikalo , Chao-ying Fu , Daniel Lezcano , Dragan Mladjenovic , Geert Uytterhoeven , Greg Ungerer , Hauke Mehrtens , Ilya Lipnitskiy , Jiaxun Yang , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Marc Zyngier , Paul Burton , Peter Zijlstra , Serge Semin , Thomas Gleixner , Tiezhu Yang Subject: [PATCH v3 07/11] clocksource: mips-gic-timer: Always use cluster 0 counter as clocksource Date: Tue, 31 Oct 2023 17:49:23 +0100 Message-Id: <20231031164927.371663-8-aleksandar.rikalo@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> References: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> X-ClientProxiedBy: AM0PR10CA0065.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::18) To VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0302MB3486:EE_|DB4PR03MB8706:EE_ X-MS-Office365-Filtering-Correlation-Id: 6aa1f8e2-7f7e-4f8f-7a3e-08dbda316569 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V4QtzvVOt1LA31hNatq6wES4WXW2Pw0dXurtziAsYa+NspcK0fhQvFFqW1x3nk6ZuMgjKia3s9m24rPZOepH5J/Z9ih6nLwfee5FiHHO95uxxMreJanzMzuz+KmwIfcd3cqa3wUpmPtt3B+SaXHtNwAl5R2NHUx/8VUpTmxGdlSK6v/GK9y0ADD2RQZF21Czu9DjMCD5MjAPHgJEsBiQ0zhxNZzogTQNb/0olkQKqV8/TgwH40n3Ec28ufknuOE+j9vtBfzfizPL5X37jFc/5JRl+LHtCDsOMr6BlMjUnC3yHwTPRcixlLHDfN/iZ2bW4SusMSDtsg+6Y8byQ2WOBKdR8YdQ8wd/S6tCx1g01plZMtxaKQHiRHxfRz9NyOwkazlt/alJpqc4/heDLyyX6dpSCfXaX5m38HPaEXUu9glDnfcQN0bvsbDUhQUU0aoMlgFEgHL31H0RhqnRGwVa4Fo9P0zwCp7J3G7cupJzEPN01MZCSNiUeYTYvKv0+mv5vHWj1tCrtP18RUwJKidB90LEvMGwaSOMdWi28Ug/h7ozSZi/ESbCYEUMrJi7NnbahXQqSxNxqSGKDcyqEI4/aIQgrwjXtvgJKr0M7r5sP1XCJ0lDZR5J6G6QzlUeLcaZ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0302MB3486.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(39830400003)(346002)(376002)(136003)(230922051799003)(186009)(64100799003)(451199024)(1800799009)(6512007)(2616005)(1076003)(26005)(6666004)(478600001)(4326008)(6506007)(83380400001)(44832011)(6486002)(7416002)(2906002)(41300700001)(66556008)(66946007)(66476007)(8936002)(8676002)(52116002)(6916009)(5660300002)(54906003)(316002)(36756003)(38100700002)(86362001)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IXrbR42uKgIc3XGKfxA22l1XukV5C88Q6vMxEuPSkcUcXMFURySTrBiR82Djwe6AqJd+vtEqTy+9hVyXegcJlKdFE7OrxEhJPr3LuucbRd+OioMm8n8CX2t5aKmHOZ9o0r9dD7jqrpvoO/Pa2+QaFOpWxad2jDs7gxVod2BNmO+dAhmR10HoHRGnMBUScfWPCi9uOnY2ur2zuIyigAJtg1mE6qg2/WRrgIB8RcgaGOtjSWP5b11tJJr2gmNQke2X1EqJ6lyBniIXmYcvzYVfUQsMYSwvA9xHa2ML++Iv5IPvGf0k9vrnXZbPjXopmcLuP3qMjkvYc8MAp/NBuu+xAspBjABM0jxCXlysxs/prgauFnrgacl6XHWcGzuvn/yArMmS7TU8eaafBxTjI/0OJr5H0GhlqOWDItcWWJ8nlnNKWnLLLC1+SMcIRmHdKRkeMCtYiATs/JlQg+wUaGyuhX85N2DPECxg/dq3SfbblUhnbKYRKzrkx/FuysILgeP+sBpqlN8TikOLk/XepK+m+9iAZrlZ+cP+tIi8D1F1XBF+CCkmFdswK0B49HtGuOXrjB13L792cKyrxnwF1Ooa3rOwk9hHeJBh9G3QLZMg6fVMd7iJhT8uDaDUpV6UTGthvPcac8LMNpVSBZs4DaTMyD50GrYh0Tl8yAZfHi5geg/ieu6wAk/oaCtRTlfkbcboPgr6P17iYlWrITzjfqCUVJOSEH5fVsps17POLS8iieHDMggH73bhPD2zVuf2hISahgF3Covue6ZltNxSv6lz12X0P6OnEzvJEw1GwFS6wmLjjsXJxsnXlNnBCs+tF+SaZPgJeyl2DWkMs2uOPOGSOeYtK26uzkn9OTRGd7zsXgW1Y2KTifMpKbOFatDtftm6GJGcEgqRwsFqdut1yv6pRe8pH6ODiZ0oZ5F2PngYL2iSXpK/5expolO9QPBuDdE79ffM0Qr/Es18u3KrvSEpI5zAtXMRR2V7HPfmkSmxoOFQ0tve2HSl9cFNMBwoIB5ri9QcbjatV9AeGfiiLlDqG/TC8XzSPiXSZPCGZZRrBLKyg6V6dY/2097bVvBdGhFUczc1d21K379ODLZRTg0+ZCzR4XXgglmmRQOK/PBiuEzBjPqO5bESWMkCksS5e3sl4o6XynRkwvFyb+u7ytrrIAV6gFJzFkiTd05sB4igSwkzxGQM5Uf9gp7kpkfTNj6dGIZts9Gr3QS64i43Kr1zPDZF87d7ERek+1VQeMu2P3h9iROE/GZyTXM5V/N0wdlERpM844gKt6y3mez62C8ktFB9Oac2jssonJofTnKxix+n0m+/sIlmA1OwKQXQSnBUlgnHqFEgGq2QIzmgaklB3SjRvu1AU4mvwh9AyR+IFPoM8bb7trUbFZnFZbsY3WKB4lxBnga4rjc+8okQUEMQtgMsAwyqNIoTzG690f7OagkJUMycCpf0eqGQ2n7SkNodnPgDJzDc1buJoZsQDh3MPnCU0jlEzkOuVDk9gaj3LPz66xUG7T+hCikpaBbqA6PiGqZBTQa53hj44mtxFvqgAj5g2i5AbDznPA6/pqYhse7fzH3uwYL1VrnXdiczEQAc827dRlyQIehTl5k4E9Dhmg== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6aa1f8e2-7f7e-4f8f-7a3e-08dbda316569 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0302MB3486.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 16:49:49.4211 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eBuu64R/0pkIKwawouG/XaYppsMzw/yw6wS7Z7zTtnMr1WnpvOaoXTK2noPcw67UklIHz5VEDMteRvRd8/6NJss+I0nwf4IAuWNqfvfp5oQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR03MB8706 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Paul Burton In a multi-cluster MIPS system we have multiple GICs - one in each cluster - each of which has its own independent counter. The counters in each GIC are not synchronised in any way, so they can drift relative to one another through the lifetime of the system. This is problematic for a clocksource which ought to be global. Avoid problems by always accessing cluster 0's counter, using cross-cluster register access. This adds overhead so we only do so on systems where we actually have CPUs present in multiple clusters. For now, be extra conservative and don't use gic counter for vdso or sched_clock in this case. Signed-off-by: Paul Burton Signed-off-by: Chao-ying Fu Signed-off-by: Dragan Mladjenovic Signed-off-by: Aleksandar Rikalo --- drivers/clocksource/mips-gic-timer.c | 39 +++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/clocksource/mips-gic-timer.c b/drivers/clocksource/mips-gic-timer.c index b3ae38f36720..ebf308916fb1 100644 --- a/drivers/clocksource/mips-gic-timer.c +++ b/drivers/clocksource/mips-gic-timer.c @@ -165,6 +165,37 @@ static u64 gic_hpt_read(struct clocksource *cs) return gic_read_count(); } +static u64 gic_hpt_read_multicluster(struct clocksource *cs) +{ + unsigned int hi, hi2, lo; + u64 count; + + mips_cm_lock_other(0, 0, 0, CM_GCR_Cx_OTHER_BLOCK_GLOBAL); + + if (mips_cm_is64) { + count = read_gic_redir_counter(); + goto out; + } + + hi = read_gic_redir_counter_32h(); + while (true) { + lo = read_gic_redir_counter_32l(); + + /* If hi didn't change then lo didn't wrap & we're done */ + hi2 = read_gic_redir_counter_32h(); + if (hi2 == hi) + break; + + /* Otherwise, repeat with the latest hi value */ + hi = hi2; + } + + count = (((u64)hi) << 32) + lo; +out: + mips_cm_unlock_other(); + return count; +} + static struct clocksource gic_clocksource = { .name = "GIC", .read = gic_hpt_read, @@ -199,6 +230,11 @@ static int __init __gic_clocksource_init(void) /* Calculate a somewhat reasonable rating value. */ gic_clocksource.rating = 200 + gic_frequency / 10000000; + if (mips_cps_multicluster_cpus()) { + gic_clocksource.read = &gic_hpt_read_multicluster; + gic_clocksource.vdso_clock_mode = VDSO_CLOCKMODE_NONE; + } + ret = clocksource_register_hz(&gic_clocksource, gic_frequency); if (ret < 0) pr_warn("Unable to register clocksource\n"); @@ -257,7 +293,8 @@ static int __init gic_clocksource_of_init(struct device_node *node) * stable CPU frequency or on the platforms with CM3 and CPU frequency * change performed by the CPC core clocks divider. */ - if (mips_cm_revision() >= CM_REV_CM3 || !IS_ENABLED(CONFIG_CPU_FREQ)) { + if ((mips_cm_revision() >= CM_REV_CM3 || !IS_ENABLED(CONFIG_CPU_FREQ)) && + !mips_cps_multicluster_cpus()) { sched_clock_register(mips_cm_is64 ? gic_read_count_64 : gic_read_count_2x32, 64, gic_frequency); From patchwork Tue Oct 31 16:49:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Rikalo X-Patchwork-Id: 13442129 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 220F0C41535 for ; Tue, 31 Oct 2023 16:52:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347029AbjJaQw6 (ORCPT ); Tue, 31 Oct 2023 12:52:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346620AbjJaQwZ (ORCPT ); Tue, 31 Oct 2023 12:52:25 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2111.outbound.protection.outlook.com [40.107.21.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCB71D7A; Tue, 31 Oct 2023 09:49:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TN3mjdpy1jj2JsLNaO7Chj6xHRbWraMb4I/SBTVFF7JSfV3tfAK0X9n/OHEEt3CJvCZcvH1F8knQW/4o/2zjoqAimezPt5Utl0tdwzynNNP1krlNuWNIi+LRhpWpQFjQfOrTnrD8a00bZfXjQSFJZFj/aadPNPSv9S8miuwBOBkwJwk0S+ul8yLuA/NkcFZWiiUvfz8BPnXCiZhnjo2gTLs8fnNH/3MYLxP5lnuWI6qJhILdD/0BO6CoT9lW+MmIgtaBnnMlGkAYXutlbI2pgKZD0syT/gkk3glznVsYvdkcNZa48V+m0HeYg6ZPdhS/Vn3/YsqNS/fKSyk3LcCwUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iz1LL4xwR1qY+CI3VRAXbhSeafq8ULEMhuPza2lb/BY=; b=OfLJiE8p5xZy7giJg7NkMqu9JlUU+CW+VwVFr5b4IXYOL5KrVVn4oe5cfyuVxhaDspA4vxX+rIiJbvzPfdbA4zFo59Ul61bfDmdQaZM+MSEWCQ25aNGPtRFM7FVWUOVJ5PctHarCcmoHr/FJcybyEzn4N4o7EdgeyAhgxLNFa8jAu6Yx/YttKRbGgLVoqmuvB0eoPd5ddgmETZLVKvXxQV0WokY9GysE0XPSUdVGIAbS2CHH1HxXm61/W2E1JdEUBPCfvXjx1vFLEoaaSQEBnwtilqV1f2C2dpGmHkLDBn2Y58HeTCzF+BMn3PNYTdBSrZI8SDAZCRkn/hk2r1Nqdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iz1LL4xwR1qY+CI3VRAXbhSeafq8ULEMhuPza2lb/BY=; b=KPPbPEz/06axtAnDSocWpf9QJTTGRWAHQ/UgSMHydIju0bneRWXJnYWWh+YnrthNfb4RHv6wLmkBoTIpX6CIxk90IuxaKZgmZa3zg3TwkSea5rxVkEI5X4egYPQ7AW7lTNI5mv2Sv+eeh+Z9MYTGw4gNfHAD+wcDgOXrJvSRY/8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=syrmia.com; Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) by DB4PR03MB8706.eurprd03.prod.outlook.com (2603:10a6:10:382::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28; Tue, 31 Oct 2023 16:49:51 +0000 Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa]) by VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa%4]) with mapi id 15.20.6907.032; Tue, 31 Oct 2023 16:49:51 +0000 From: Aleksandar Rikalo To: Thomas Bogendoerfer Cc: Aleksandar Rikalo , Chao-ying Fu , Daniel Lezcano , Dragan Mladjenovic , Geert Uytterhoeven , Greg Ungerer , Hauke Mehrtens , Ilya Lipnitskiy , Jiaxun Yang , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Marc Zyngier , Paul Burton , Peter Zijlstra , Serge Semin , Thomas Gleixner , Tiezhu Yang Subject: [PATCH v3 08/11] clocksource: mips-gic-timer: Enable counter when CPUs start Date: Tue, 31 Oct 2023 17:49:24 +0100 Message-Id: <20231031164927.371663-9-aleksandar.rikalo@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> References: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> X-ClientProxiedBy: AM0PR10CA0065.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::18) To VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0302MB3486:EE_|DB4PR03MB8706:EE_ X-MS-Office365-Filtering-Correlation-Id: 9249120b-70be-44dd-94a4-08dbda316687 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ff9Xids/O+qs00O8/MN5BaksOcwD8KU7oKUe2I9DWmoh1F61u+fs/JU0zB9ggQQJcL4icfSGEo0MBE4Sr9izGGmA9Byr/AqwXItTzJh2rhF0/fURYxmcNUK6itW35xXqAJTTheThhBYfawRXvjGUczVaQ9MosxW8OCmb3arbFG3hHWkQl8gzNo+/EHYV2cajVR378p7F9xh7abzYh3HT6U810xaoj8QO5HnTRh0vZz5EKaOu3jPvCS+5oOjARFyqA2+sCq0gOKKi8MGAxD/E3F2tsqC744Oy1olXcVz4aypzkvNwNdfkKlKPNqeRmEih3bwwMewqMK6wMyAEGVOFVnExvtrkeVc3cjYxEAp4zJwZWlOs84/v/lAkUnNfHqD16TyfYbhWsqavmAu5uCKGA4ZYmzBmHMITqdxgQqN26JfMvU13UFsHIPP4i1b7JEdyQb2UNCkUY5fvFTwroItqgAwh/VCfQ7vvCQeSJu0xwfK4W1HucAFl+/WAK83M6LZO9Ob5RR6c2oDVRaSu1zVu3WNUkZ8w0Z7Mjq10WSvRK+rpcmKg/Y/tz46zE8YtTnmLH806nbeXhlaZ9WKYTBQrzoeAuLeSsIi2X0vbPywru31gNmnREU6RT0lcPQJ8XN7j X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0302MB3486.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(39830400003)(346002)(376002)(136003)(230922051799003)(186009)(64100799003)(451199024)(1800799009)(6512007)(2616005)(1076003)(26005)(6666004)(478600001)(4326008)(6506007)(83380400001)(44832011)(6486002)(7416002)(2906002)(41300700001)(66556008)(66946007)(66476007)(8936002)(8676002)(52116002)(6916009)(5660300002)(54906003)(316002)(36756003)(38100700002)(86362001)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AP4HNrQMni7j3Rcag9IgZ8nI+rsB72kkqP0VY1Ay0uzulvXNoFp9LkMfDgoMaaMKBIkyE/M45sQExzr4tzPb08AxTOzBsk48ZkP9CuxHKCKmkPeVe7PvdBAdhF8E2WLKu6EkaR4PopGq7yFI7GgApk3zwze84w4ThHFUfYW9B+yTwvBf99q0MnTaVjmY4p9xsReCFTFpQuoEUIa/oMtGERluUtaAjDfzLR1jAFWRVexLotEZtBWekbpWNgnGmIUPfh2lmWuhgbHeCN/BHvaGNsPKJRKO9SYBJPuB34LEbbaz+8SedqOGUHMuKiYLtZpx0afPIwPOXdBQbfa6+Xhf2CPxiPrann60XbVFrphBk/Zu4eO77nf0ZC/z1HrJe2bhKfmEbY3t4x4ejrWBmraOTbQwNiKB11FLP4KvVzAVi7k0IPk/+0erl/BVzwtAACoTpwuX627Tv+acVMqiK2EbDs21MeZVxvI5iKq9WOGsz+MC7H71aT1gd4hFINLTsbCii7SPZIq9AJG3afE3xXt1BKFLdBQJY8urr9AjLkJynd8HwoJtXQJzL+ml/tD+taOCnwgyxjV96fAkvOa859ObBMXAdSD7t9gDzlgh9n61nDyoaGTGACIH5nRHQH7IgFV8T/aHbheGexdDaqG12qpJWXZle/QNNNZ3iu+XuhqkWRLGOaFzEWzvlxAbFukVPT7CZAdO7Fcdqig90Is3tAN8hfChttwmczqD3DVki1tFhtJVrHUnpDi3V1AlQxt4CB+eo3v8oSy4j26sOXWTmxjmOj3mrUM0NunCxd3ZryXJ81ZGkY8YYeARnz+G6i6wB1TouavUvNrl51cqR2ucQlMvdgcINwYZMaZmNaKSeF7mDPeUnvLESF6/KWEGHtiagBumYEP0qKBj9PrQB34pSRZe957SV7zO4Czdi+J0ndy17MXTVgoZveXPGVFyoODzB6I/O7byCG+3OYIR5P0u+leI25Lg2ZbOpCDq2YiR5iqSqQkeAueO5SLehMAKKU7LuEJbIQtdqJ1VIUc3FvtPp6FAkz4umE85TweQ101zGoVzmqGwA3osy1obzYkLvLmPoBqpXZwPWWk/rBmdqzmeKg+iEMNkUa/Mo8G+gbqXWC+PU2as7eBO+kRxerREIByWTBqIpYj2IpeTsfUkZi2WzB+e0mk4bmcr+SPrGRGEkuWEcjdiXTXf/uKMvqkE031PWhUrXVEKZXWJW89aKvL42ESfqeQUfCpEdGI3RV0VUHZ1VdWkB+YiJAYhrkE1KkfEulqoR26vEBp202eIYkqCkeWcaiYGTz2agpv8IOR4pGGs4Jyct3UjOYaMnxf3iu2sx/kbfUTj+XRgmtRuXmZOiad61oIGQsrglx4KgKaTZolu6JtLmaumItF2zPIkKQ2EXoq/rg0BxB4hPWCENhLcbPsbTuseJ5S8w2TPcBYRD/m3xmP6tlv0Qhmdrgqd1LfA8WawLhiL8pR54wNSsToBFRyK0aJ6mU4Iog9MSKvf7X5JGn1Y3QGN592XPiQPT31wQRRU0qB94GUx/CdZohiEDnnFbEJLO2YSm52IhLE1I3/mXlqm8lix+h0I1rr0zkOZFq19A83LtBmCMcy5urAeK0Xgyg== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9249120b-70be-44dd-94a4-08dbda316687 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0302MB3486.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 16:49:51.2739 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: OxwSUaRS2OkLiZnGwalwvQlJpBlKKXTkwTqyk1IaCAbI20eRX/FmNNtjy458wFlwrKmZi6hKk4CEcl9C+h7IpsXKeH1KbbHoNo09WUraji4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR03MB8706 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Paul Burton In multi-cluster MIPS I6500 systems we have a GIC in each cluster, each with its own counter. When a cluster powers up the counter will be stopped, with the COUNTSTOP bit set in the GIC_CONFIG register. In single cluster systems it has been fine for us to clear COUNTSTOP once in gic_clocksource_of_init() in order to start the counter, since with only one cluster we know that we won't be resetting that cluster's GIC at any point (ignoring suspend/resume cycles which would need to handle clearing COUNTSTOP in the resume path). Once we support multi-cluster systems this will only have started the counter in the boot cluster, and any CPUs in other clusters will find their counter stopped which will break the GIC clock_event_device. Resolve this by having CPUs clear the COUNTSTOP bit when they come online, using the existing gic_starting_cpu() CPU hotplug callback. This will allow CPUs in secondary clusters to ensure that the cluster's GIC counter is running as expected. Signed-off-by: Paul Burton Signed-off-by: Chao-ying Fu Signed-off-by: Dragan Mladjenovic Signed-off-by: Aleksandar Rikalo --- drivers/clocksource/mips-gic-timer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/clocksource/mips-gic-timer.c b/drivers/clocksource/mips-gic-timer.c index ebf308916fb1..4d7659c119e1 100644 --- a/drivers/clocksource/mips-gic-timer.c +++ b/drivers/clocksource/mips-gic-timer.c @@ -114,6 +114,9 @@ static void gic_update_frequency(void *data) static int gic_starting_cpu(unsigned int cpu) { + /* Ensure the GIC counter is running */ + clear_gic_config(GIC_CONFIG_COUNTSTOP); + gic_clockevent_cpu_init(cpu, this_cpu_ptr(&gic_clockevent_device)); return 0; } @@ -284,9 +287,6 @@ static int __init gic_clocksource_of_init(struct device_node *node) pr_warn("Unable to register clock notifier\n"); } - /* And finally start the counter */ - clear_gic_config(GIC_CONFIG_COUNTSTOP); - /* * It's safe to use the MIPS GIC timer as a sched clock source only if * its ticks are stable, which is true on either the platforms with From patchwork Tue Oct 31 16:49:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Rikalo X-Patchwork-Id: 13442130 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 BED21C4167B for ; Tue, 31 Oct 2023 16:52:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347038AbjJaQw7 (ORCPT ); Tue, 31 Oct 2023 12:52:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346788AbjJaQw0 (ORCPT ); Tue, 31 Oct 2023 12:52:26 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2111.outbound.protection.outlook.com [40.107.21.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD77310CA; Tue, 31 Oct 2023 09:49:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=igVGpNMP9KC3ZB/STj5EiiRNGczo7Whr2IgaCUCZ0oM/9scvfcxSDTXjGrypZLTrTQ0VojN+ttavjm0vzDBavNIpMEJYbNcuHbDbDKZ29l0JWaa3VUXyup5w2n7df3geYdbFyAVFGYCtAgJqq7un4EHpxTdmQPcW7BjgvP8Bmi7Ko9brNDjcGEwahkf1adKoHoa2Mt2s8vwPGY+LbtxkxlRHUW3Ii65cnlCLwz98tydShBsVQESx4kvc9BTZjCq5pjalCTZ6/RGUjCcs14yHuV7Kypw3W544Lepzg5PbRsUt9xAgpN2gZs0+99+Lz3wvpBiMkm2GqFLLTMwYaVzw4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1JHK0hircicLZe+BQeKQFtK0FkTAy+hezrKCg4iJ0KA=; b=i+6Sc8cFzWZPTW3EraAqK2Fux65tlwY8slrzN0hSMUwd21AFeybEFHxZ/FyOll1Y/thOY5G8qJqPSTP2nkKW5II6di08tKcPLvAE68uthFrkwuLI/dJskLndECR9WtCYbEjMcfHtS69ygN7LRnVTSpOXwLklXVLPlFvPPo8oQbKwKwhew7nGeQoS5Il4wEkMGkFzRGjWanYkbhN+D+8NQ7TO9lWLo6eLP/c570w0JhRdKCpfi2tjPGexoXco1Ru4tJ+vY738Zy1ICedcAT9t4TKHCBBRHbtGVgZ6mQkLjhFhxHaafTmESxIJui0Aw6RXSoYRFDt616Aun6HSeTZrKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1JHK0hircicLZe+BQeKQFtK0FkTAy+hezrKCg4iJ0KA=; b=TjJYOXJFwgCnL0git/ZPtRptHmoYL6yY+Eg0NFVP5hoDCzicbJTfzoXa8sJEl4aWhBZz7CrxQrtqW2fopaBX43feMC7T0Y+XzgMDBd/eSH+gAG7f/NDgnvVeH2dzmzDx84RCSlarIFtckFfCXNY3CTpfpl9baDyH8JzxFSK+mck= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=syrmia.com; Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) by DB4PR03MB8706.eurprd03.prod.outlook.com (2603:10a6:10:382::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28; Tue, 31 Oct 2023 16:49:53 +0000 Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa]) by VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa%4]) with mapi id 15.20.6907.032; Tue, 31 Oct 2023 16:49:53 +0000 From: Aleksandar Rikalo To: Thomas Bogendoerfer Cc: Aleksandar Rikalo , Chao-ying Fu , Daniel Lezcano , Dragan Mladjenovic , Geert Uytterhoeven , Greg Ungerer , Hauke Mehrtens , Ilya Lipnitskiy , Jiaxun Yang , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Marc Zyngier , Paul Burton , Peter Zijlstra , Serge Semin , Thomas Gleixner , Tiezhu Yang Subject: [PATCH v3 09/11] MIPS: pm-cps: Use per-CPU variables as per-CPU, not per-core Date: Tue, 31 Oct 2023 17:49:25 +0100 Message-Id: <20231031164927.371663-10-aleksandar.rikalo@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> References: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> X-ClientProxiedBy: AM0PR10CA0065.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::18) To VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0302MB3486:EE_|DB4PR03MB8706:EE_ X-MS-Office365-Filtering-Correlation-Id: 25649b2e-5b85-4b01-ea3f-08dbda3167a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8WgMLgo+wMGAjnHY9SRI0NMnmHf2ylMr0POALF5eaB8i2UZOPz5auzfm25EZgsR9Y97j08EuKpSJYx27zZVS2sQ457c4if7McTRddAQDLYWNQO1F/ecWuhOAXTydybeDhgaiVQxiZv3l8FG7sMfwpPriXF0LWmLNEfhzfC2wvZh/BbC7VJFRvXXI17LCssrMEjq8nKzwimtqfDHzkTQcCBhPxQg3xT/jOIuT7cTG8UQu9uHo6ursTLQPZwwbx6+NZpZxBKhC8MaMyD04SBGa2yM9CAMA+GOyAI4rjKygMf3/V4M18OYZiDRLhojDIOXvT8D3d2f9NFjnmVj6v6J5lno2Tl9aF1Y4/IzGvKv1vsdUaoSaYv/lYy84VLvz0O5CFPiZ507aTLOC4GxrbA7bJywV2tDnsmrjvHb3HO8ymGFav41LxkGNYd6tJqm50TEx4c3WStl2gOpV3+hBXQWVFlBa8/+w5X7v1A6vQi7d55P8Gk0A6BZtal30TAmZzCwQnYxVX5X/E5UTSU6xZu3EPblRMBoJiQ0Av8PkjlA/qglC4+RvlZ+nRicOLBJ55Jja3608g/yidt/A3hhhL6DwD/kxlUYTUe1NGaJ+KoYHRs4UDkeH+PPHk+AXWf+EjS15 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0302MB3486.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(39830400003)(346002)(376002)(136003)(230922051799003)(186009)(64100799003)(451199024)(1800799009)(6512007)(2616005)(1076003)(26005)(6666004)(478600001)(4326008)(6506007)(83380400001)(44832011)(6486002)(7416002)(2906002)(41300700001)(66556008)(66946007)(66476007)(8936002)(8676002)(52116002)(6916009)(5660300002)(54906003)(316002)(36756003)(38100700002)(86362001)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /hrsxKKvaE4y25wmtisPEuOBfW8GHfo6t9ueLKV5G4qOgyHC2p7yKPfEz6tQAHF1s32dmoLfp/bvcd0aQbyniU9tIQt2PpOdHnN0acBfI5SJhC8fuhLC5rFswzvlk5/dYUKstA6a5U4lq4p0YylJcTqrMae6VCbulsHORd4dNFE/P5JSzHrvnUxaMBHfLKgYg4k/VMMTmKBUVp3swErNwWWcgdlE+MgN52NHEmcD3NH7XXV+SYrUlUwQoL7PPuLV2C8PphG/ESdDyhdOVJSAC4Al3MTsRt9igwdH1KHTFTm2jqoQPvasz5Qba+NtJbNNfQrtTptSc7Vq8Px6jJ9Y7eUTVtHXP2LC90Cl4cyBGr0+7Jr1QEhi+cgtPvGFDH/zlpjn6hHtaHa81de0g08FxgqNjXU+knpiCHutrX61JJGi1caCgWd4/EemTd7cI/BwwW8OpIfVNrb/33W4vleEQ9Q4i1augmf+gUrdPJKm53ZwE+ce1IKavXCSUPe84VD3kg7wILK6Tu2MH8VXCds3MeeJ1wmEOWXR2yAGsPrQmX0GBvHytf7xq/in/Kgp0JLoQ2AlW39ZqgdB+GCv5EMq3AJBlqYxBM8J1dUnTYxz+AeKwZCcyd65dAi15s0Nen1PSFQBOsd22rcPAVNIvz6PTfGzeONMu0i4gsOY9+wMho5XP70jzURg1dtTNkb+5X2pIPxYraTuBBhkI4Te8tt2JJBZ97TIQGhHH2tM1RD+K8o9Y2EByGXPz8J8E+2K10jCsUIRARYa2rG9ocZcya0umj1Ln1dlLENlucie91BZYfPoOzAuUnnJjEJCULnJxL7ngTH3eM7VvtHi90tnyiblyj12zppBrg6r7bi6Zl1NF7AA9/0hHtupETdzXhhLI4jHZbK6RG+Q2nn2E/GtIBOwU+Jd2K2+UjuG7mGZO9dq9P9seCb9B5JkUlybrYWJ4aJ5HrVpVzV9T1ojITHL94meljs/cgSDCqjC5AJn8iaNvtSjcuImN0cl7fmOot0maAP05c9yShsf6JFS+y97rn0Ap63WHEro/KDmfSWijx0xNZ3DmV2AFRvJqx1Ts2EQDHN3k2wyJKTjpVqRs9+fMMiRIsrYbxUWa/O81aWX8WysdGa5xwEiAWtIDl6el0zqMBNpAyqpYBvd3wlvA4biImV6zaeKUhwQKxH+bF1O1O49jimMFGY16unnBeZS8ysRlnTqkINYeX1kvUh0B9hRaqdLCrQPRQ2/oCXhDI/N+8m3qj9cR1aS9/PM7z5i7DqsXhVewAqNJX1BwkWKdr3EIx978ID3MfMuX1ig+oi9KwaqmVR8NAvNU3i8HouGlqdDOqijYh1asHEPuGeO19GZJSxZZLHheX7TPrSt91r54an/aT3DkuGkYDBKML/b1cQhggIWkYb2hnXzkPNX+vSQWNVMCF8zUUka1C8ymZ9WmQ/EsQCZ7Jds4EyoEPVEaLCf127tX/t+iK0vrX/XhJCQTpENM+eYegHkH40qRRr+16HhQF/BU0cBsK/pfheKdz5DmTAVl7JZUXvtYbk51QSEwgwyCrNKLaPC7gugfJT4ROJr6WMS6kGFcicPKKL3LBW3R/lMNJVQZVuL18gkB6ITLfB/oQ== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25649b2e-5b85-4b01-ea3f-08dbda3167a0 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0302MB3486.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 16:49:53.1212 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Sd6aAnnu+KWbsCkGWnlGaycJqgAboZm+3YBrsQcuss7Ttdxny3jEDGz+EBBpO4H9t4XyzG+U6fU+7kiHAejpvXvKvo/bfKW5lLPLnNzEFZw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR03MB8706 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Paul Burton The pm-cps code has up until now used per-CPU variables indexed by core, rather than CPU number, in order to share data amongst sibling CPUs (ie. VPs/threads in a core). This works fine for single cluster systems, but with multi-cluster systems a core number is no longer unique in the system, leading to sharing between CPUs that are not actually siblings. Avoid this issue by using per-CPU variables as they are more generally used - ie. access them using CPU numbers rather than core numbers. Sharing between siblings is then accomplished by: - Assigning the same pointer to entries for each sibling CPU for the nc_asm_enter & ready_count variables, which allow this by virtue of being per-CPU pointers. - Indexing by the first CPU set in a CPUs cpu_sibling_map in the case of pm_barrier, for which we can't use the previous approach because the per-CPU variable is not a pointer. Signed-off-by: Paul Burton Signed-off-by: Dragan Mladjenovic Signed-off-by: Aleksandar Rikalo --- arch/mips/kernel/pm-cps.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c index 9bf60d7d44d3..a7bcf2b814c8 100644 --- a/arch/mips/kernel/pm-cps.c +++ b/arch/mips/kernel/pm-cps.c @@ -56,10 +56,7 @@ static DEFINE_PER_CPU_ALIGNED(u32*, ready_count); /* Indicates online CPUs coupled with the current CPU */ static DEFINE_PER_CPU_ALIGNED(cpumask_t, online_coupled); -/* - * Used to synchronize entry to deep idle states. Actually per-core rather - * than per-CPU. - */ +/* Used to synchronize entry to deep idle states */ static DEFINE_PER_CPU_ALIGNED(atomic_t, pm_barrier); /* Saved CPU state across the CPS_PM_POWER_GATED state */ @@ -118,9 +115,10 @@ int cps_pm_enter_state(enum cps_pm_state state) cps_nc_entry_fn entry; struct core_boot_config *core_cfg; struct vpe_boot_config *vpe_cfg; + atomic_t *barrier; /* Check that there is an entry function for this state */ - entry = per_cpu(nc_asm_enter, core)[state]; + entry = per_cpu(nc_asm_enter, cpu)[state]; if (!entry) return -EINVAL; @@ -156,7 +154,7 @@ int cps_pm_enter_state(enum cps_pm_state state) smp_mb__after_atomic(); /* Create a non-coherent mapping of the core ready_count */ - core_ready_count = per_cpu(ready_count, core); + core_ready_count = per_cpu(ready_count, cpu); nc_addr = kmap_noncoherent(virt_to_page(core_ready_count), (unsigned long)core_ready_count); nc_addr += ((unsigned long)core_ready_count & ~PAGE_MASK); @@ -164,7 +162,8 @@ int cps_pm_enter_state(enum cps_pm_state state) /* Ensure ready_count is zero-initialised before the assembly runs */ WRITE_ONCE(*nc_core_ready_count, 0); - coupled_barrier(&per_cpu(pm_barrier, core), online); + barrier = &per_cpu(pm_barrier, cpumask_first(&cpu_sibling_map[cpu])); + coupled_barrier(barrier, online); /* Run the generated entry code */ left = entry(online, nc_core_ready_count); @@ -635,12 +634,14 @@ static void *cps_gen_entry_code(unsigned cpu, enum cps_pm_state state) static int cps_pm_online_cpu(unsigned int cpu) { - enum cps_pm_state state; - unsigned core = cpu_core(&cpu_data[cpu]); + unsigned int sibling, core; void *entry_fn, *core_rc; + enum cps_pm_state state; + + core = cpu_core(&cpu_data[cpu]); for (state = CPS_PM_NC_WAIT; state < CPS_PM_STATE_COUNT; state++) { - if (per_cpu(nc_asm_enter, core)[state]) + if (per_cpu(nc_asm_enter, cpu)[state]) continue; if (!test_bit(state, state_support)) continue; @@ -652,16 +653,19 @@ static int cps_pm_online_cpu(unsigned int cpu) clear_bit(state, state_support); } - per_cpu(nc_asm_enter, core)[state] = entry_fn; + for_each_cpu(sibling, &cpu_sibling_map[cpu]) + per_cpu(nc_asm_enter, sibling)[state] = entry_fn; } - if (!per_cpu(ready_count, core)) { + if (!per_cpu(ready_count, cpu)) { core_rc = kmalloc(sizeof(u32), GFP_KERNEL); if (!core_rc) { pr_err("Failed allocate core %u ready_count\n", core); return -ENOMEM; } - per_cpu(ready_count, core) = core_rc; + + for_each_cpu(sibling, &cpu_sibling_map[cpu]) + per_cpu(ready_count, sibling) = core_rc; } return 0; From patchwork Tue Oct 31 16:49:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Rikalo X-Patchwork-Id: 13442131 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 12BDFC001B0 for ; Tue, 31 Oct 2023 16:53:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346865AbjJaQxC (ORCPT ); Tue, 31 Oct 2023 12:53:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346929AbjJaQw2 (ORCPT ); Tue, 31 Oct 2023 12:52:28 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2111.outbound.protection.outlook.com [40.107.21.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10EED10D2; Tue, 31 Oct 2023 09:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iUZw6tipNtTa+9WoLdvIa/pgT87zdaDL5ANm++rc8r0VKzlr8330HZmvNr0z5+bzfhMR+3jnVivMKJWFcwWgDWmoXmUT1LRDAk70c9z7OYzt+jsRRc8qi/e775MMFRgORKFxnlPTsZ51RzLaAjhjS6zC5WQ7erLSSrCoy4ekZ3u06eV19hBv80RY3dbEf3O/yR11pTbWYFZMuQpw7DTqMbGJSJXCWHUpJhHl/EjF8rczyCOqIHTLbL37xfQjB7/rs+f40NduFckbDlVAHDsIL0g/gA1icXsSVmrHuHaTmPP0iSK3bJBdiELTgDg7igtRZiuyE9Sj2MImRecbawA6yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zQAW+J0i3ESdDw9xb3AUaNxdIIfwKPJkxFoZkOQOjHo=; b=nlUeJ/rbz9zOioFKpPEHQ0km7P+eEfzCA0sbSRiZ80ERi0akhx0+DwcVjuCeJRIfOk8M3UX+AOFmlBx3s2WlZJgUpUCd7UejATVisYrNShHRiT8AimwrwGfVgqRVqulkfxCu7tr55RicYcdXQQHZlFqmhj9VH6k8zsUvP9mPKO/BLZDDWaN0S8928YX+FJ/4FWtlIXaHWjK49b4QioSZA3hTrf8cRm9XKWxaTiJ0tZIciqF3G1059wntRyUWJ4G7JsN4NO6xQ+4TTa1fDE4KTR1fB0vm0avPHRzSIaMZVSqYFX8y4/h3QX3je0LjjJHidfO/8T0VDRLwuTpR8NYheA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zQAW+J0i3ESdDw9xb3AUaNxdIIfwKPJkxFoZkOQOjHo=; b=b0BIC5BtTx3+Uhy1xrbmq6X8c2uMo664whUwEBG6j/5YsoT761IauAb+urx2EMnh/qjCXKq+EnbnJaVACZWg74T0oiDxEijR2J6Yr/0A4qRffH19kuhP+AyleDSLeJ7XRXPYEZPyTxWDGkhOc5OZ3HaptpEaes1+E09CTflZojw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=syrmia.com; Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) by DB4PR03MB8706.eurprd03.prod.outlook.com (2603:10a6:10:382::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28; Tue, 31 Oct 2023 16:49:55 +0000 Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa]) by VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa%4]) with mapi id 15.20.6907.032; Tue, 31 Oct 2023 16:49:55 +0000 From: Aleksandar Rikalo To: Thomas Bogendoerfer Cc: Aleksandar Rikalo , Chao-ying Fu , Daniel Lezcano , Dragan Mladjenovic , Geert Uytterhoeven , Greg Ungerer , Hauke Mehrtens , Ilya Lipnitskiy , Jiaxun Yang , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Marc Zyngier , Paul Burton , Peter Zijlstra , Serge Semin , Thomas Gleixner , Tiezhu Yang Subject: [PATCH v3 10/11] MIPS: CPS: Introduce struct cluster_boot_config Date: Tue, 31 Oct 2023 17:49:26 +0100 Message-Id: <20231031164927.371663-11-aleksandar.rikalo@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> References: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> X-ClientProxiedBy: AM0PR10CA0065.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::18) To VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0302MB3486:EE_|DB4PR03MB8706:EE_ X-MS-Office365-Filtering-Correlation-Id: 774cf6c3-43e2-44f6-7b3f-08dbda3168b5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xOtfG1ZROqzAdL1Rdz1oIziPowtIcwgHFA7eOgHBjTgNcQIkS+rZYHFZs8PmcZ/gaRIKElfTqDmrK/ESpX8Z4gVCE/TxTDlGdsfrLeE7N91GP5NGWjFmyfeVvYoa6rboDZ40dkug2rDbPDmZj79GXIwhpU7Pq0qBTucnJBIhurnapYw+5xzlVYbs9boWrdbtVHvbDigbLeiSc6HElRWQXDUr6GC3ioPB9d5qoUBUe3SKrVIqpkL8tBi91u+Rx2fOFcwdJAlxFGHwqmyLRCZ4FBfWKttGYC8fgldQYsIT4u1ZOfH1gou1IgETZjr2xberY69guV2Rs8wUFsdIpSW2HWjipbq/KXZ9pzTjTN5uPS/CBMrQ/Ht8NRmaortY0cg24HCqn27dbvy3ozxp+qH4eCNflQl+kbNgcHH22iVmMqJcpQT3QndwtNiwAAqW0InXCPI2jkHi3wjXbKUvl8eTNFnRx7ulP9cH42bHixY1hU4Dq+s2c13kttXiIcc0F9m14aTzaalQ2fHTS+Qk6C9/v//A+i4Lks1FZ7/9AEoyyxnn7JwjERFI9DrtNt+GhzLQfnY0VN+6Acl/+0hRKX0PIkfrQMIpMy9X5m1rdSsSL1Dg/Kl6WJXbsXKa1K1XymLL X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0302MB3486.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(39830400003)(346002)(376002)(136003)(230922051799003)(186009)(64100799003)(451199024)(1800799009)(6512007)(2616005)(1076003)(26005)(6666004)(478600001)(4326008)(6506007)(83380400001)(44832011)(6486002)(7416002)(2906002)(41300700001)(66556008)(66946007)(66476007)(8936002)(8676002)(52116002)(6916009)(5660300002)(54906003)(316002)(36756003)(38100700002)(86362001)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wgQdV0xT8Yy/Zm7FVEwXhrqFBUHLGFnCqtH31meyH2Eq2+0I7/GSXZVERjG8yOS2RQm2uIrDLmzzJ5wbJlLpysZx5gmyoSBahsgcRwcQKo476gczSvo/mdPm7aca3Wg+JwljYmwt8oxeswyypuIlG7WHB7KbWjAXirxnI/3F2Gx+P2jn6a2/vwj1F0KmRqFos5E/stgVfC7Zn0nyfbywvBzXbJH4OpAlUykhDbPRLDRll5OvW5TlyGmd1GGKz4VVBJPJTBLYqMg81q1UWW+JkYFWiXDhLVrZvOBWhQAlmVxPMk6eWP3aO88s4M7Tq34iv5HtfFbAH1Z/PPdLC+9yM7NCafn5ILQ2UIxDEX98Ab1wT3Bg6nusVrMPW69f5FTzh36zqa8PSYgWwxSWvvDowY2Q1ZbO1E//j88U/wevLAqeLEivBLbZl1aBHx2DwhPzpNtuWA8jog1h151PsC7u9wkVZLR5qhq5EZMOrVfwzgwaf6ss9khdohLFTM4RCQAHiRz1WJlXFomEaNO8o5Vdm6mpfSh9qnauIYe8XcBB17Gf08LdhfA1IemxqUo6BTc6I1ksGDQfMVUN9UQVqqpslY6GTes4gruw0Nwh313aACiXRurAjFnEKsWEmHCa8xDcCUJhDSEp6pA9mVDD+xGRZBImr14cLN5oBlCL9Etm9Bt8Y+FIzdDvBiXGs84H+RKCLvPI5YqR/XrJaFkBmE89zlesfBoLJyMjI2XbG1lU9uBkcwAhmUSEy991WXTfmq+cEwjb1WQsWWM7ykMibmxVe0i4MxE9BYaMN3+YAC47XFTl5ZMhPJ5Vo1XBLzmdnRadlkxibyzyoasG0h4OzqLy9JKDS4CdnYGMfQGRZlmcgAAf6J51yU3JKR7wGA9n//6AYtLWd1KoLP6sxECiQbuUWr7C452P3pYA3M7dAiAUpL0xjOfqI/pQHup88WC1VBCYlAOSAhTVnGeQUNmxp4taHZ7fe8bSgRfnw0wRuoZuN6KyAHyXKpaov5i06kkgJdDrfbsRQ4OfWkYSpACRAFkbEpLixfJDNwhqpTIDJrsajgFedc5xHbrYjyzDsgnk3e49rHEMMmVsK8vgkxIKMfLFn+BrdVaC7k4cs0EuqQ8V4fYxuttnYz35f7rSsscEREIdUC6Z9Fvyt/1a1kKvu3gkTm+447XEHciAVO8DtB37saWgU2ate0dRoXlZwrxV81bOHmNB/+9FLIX5+8A64xOd9oB47oUaHuTdTBpRcQUv00tfJpcOTWZKGnJbFS+PaO/aTyyznEQcOUPZCm4hq8M1GjwTpNys5QET/rE8uguZLPA/0u7tRUgXhOHTRbuGj1BbuGstyFBkr0U3FM5opzr+QFFDSX4v85RA8V5Iua3a+hH9G/mtnwNR7+VgvQ0XjvsvWi4Z23da/pamPvKLWoyCWtLqnOGPkeLlH0Lz71twtK7sii0pOfF26507Axt2Zc4jfabhkwXcXeWzkF2koPEUks7YKBA73WGUnaOIdookZfwGgynP2sJBx5UXlwPyjfmmD/KFtt6lZlbggQhgE0ZSMW+aABQK3f8neuFWdggzh5jRdSdNb9TOfJONASbQRZxmIb+s65qVzjTL1ciuDhS0Hw== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 774cf6c3-43e2-44f6-7b3f-08dbda3168b5 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0302MB3486.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 16:49:55.0076 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: E3OjzoUkD+9Dc4JR129Itmw8tOOAkmX9coTuJNtF8s7j8lvLqlmsarf+/TGxsZscRN9vOqGWoZlr5/9i4YI12ZR0F/RyiIQP2GUYP10yLEg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR03MB8706 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Paul Burton In preparation for supporting multi-cluster systems, introduce a struct cluster_boot_config as an extra layer in the boot configuration maintained by the MIPS Coherent Processing System (CPS) SMP implementation. For now only one struct cluster_boot_config will be allocated & we'll simply defererence its core_config field to find the struct core_boot_config array which we use to boot as usual. Signed-off-by: Paul Burton Signed-off-by: Dragan Mladjenovic Signed-off-by: Aleksandar Rikalo --- arch/mips/include/asm/smp-cps.h | 6 ++- arch/mips/kernel/asm-offsets.c | 3 ++ arch/mips/kernel/cps-vec.S | 19 ++++++-- arch/mips/kernel/pm-cps.c | 5 +- arch/mips/kernel/smp-cps.c | 82 +++++++++++++++++++++------------ 5 files changed, 81 insertions(+), 34 deletions(-) diff --git a/arch/mips/include/asm/smp-cps.h b/arch/mips/include/asm/smp-cps.h index 22a572b70fe3..2893d1d0bc63 100644 --- a/arch/mips/include/asm/smp-cps.h +++ b/arch/mips/include/asm/smp-cps.h @@ -22,7 +22,11 @@ struct core_boot_config { struct vpe_boot_config *vpe_config; }; -extern struct core_boot_config *mips_cps_core_bootcfg; +struct cluster_boot_config { + struct core_boot_config *core_config; +}; + +extern struct cluster_boot_config *mips_cps_cluster_bootcfg; extern void mips_cps_core_entry(void); extern void mips_cps_core_init(void); diff --git a/arch/mips/kernel/asm-offsets.c b/arch/mips/kernel/asm-offsets.c index d1b11f66f748..e978fe2f4cdb 100644 --- a/arch/mips/kernel/asm-offsets.c +++ b/arch/mips/kernel/asm-offsets.c @@ -403,6 +403,9 @@ void output_cps_defines(void) { COMMENT(" MIPS CPS offsets. "); + OFFSET(CLUSTERBOOTCFG_CORECONFIG, cluster_boot_config, core_config); + DEFINE(CLUSTERBOOTCFG_SIZE, sizeof(struct cluster_boot_config)); + OFFSET(COREBOOTCFG_VPEMASK, core_boot_config, vpe_mask); OFFSET(COREBOOTCFG_VPECONFIG, core_boot_config, vpe_config); DEFINE(COREBOOTCFG_SIZE, sizeof(struct core_boot_config)); diff --git a/arch/mips/kernel/cps-vec.S b/arch/mips/kernel/cps-vec.S index 64ecfdac6580..179c55f665fd 100644 --- a/arch/mips/kernel/cps-vec.S +++ b/arch/mips/kernel/cps-vec.S @@ -18,6 +18,10 @@ #define GCR_CPC_BASE_OFS 0x0088 #define GCR_CL_COHERENCE_OFS 0x2008 #define GCR_CL_ID_OFS 0x2028 +#define CM3_GCR_Cx_ID_CLUSTER_SHF 8 +#define CM3_GCR_Cx_ID_CLUSTER_MSK (0xff << 8) +#define CM3_GCR_Cx_ID_CORENUM_SHF 0 +#define CM3_GCR_Cx_ID_CORENUM_MSK (0xff << 0) #define CPC_CL_VC_STOP_OFS 0x2020 #define CPC_CL_VC_RUN_OFS 0x2028 @@ -303,12 +307,21 @@ LEAF(mips_cps_core_init) */ LEAF(mips_cps_get_bootcfg) /* Calculate a pointer to this cores struct core_boot_config */ + PTR_LA v0, mips_cps_cluster_bootcfg + PTR_L v0, 0(v0) lw t0, GCR_CL_ID_OFS(s1) +#ifdef CONFIG_CPU_MIPSR6 + ext t1, t0, CM3_GCR_Cx_ID_CLUSTER_SHF, 8 + li t2, CLUSTERBOOTCFG_SIZE + mul t1, t1, t2 + PTR_ADDU \ + v0, v0, t1 +#endif + PTR_L v0, CLUSTERBOOTCFG_CORECONFIG(v0) + andi t0, t0, CM3_GCR_Cx_ID_CORENUM_MSK li t1, COREBOOTCFG_SIZE mul t0, t0, t1 - PTR_LA t1, mips_cps_core_bootcfg - PTR_L t1, 0(t1) - PTR_ADDU v0, t0, t1 + PTR_ADDU v0, v0, t0 /* Calculate this VPEs ID. If the core doesn't support MT use 0 */ li t9, 0 diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c index a7bcf2b814c8..84e79bd84971 100644 --- a/arch/mips/kernel/pm-cps.c +++ b/arch/mips/kernel/pm-cps.c @@ -107,12 +107,14 @@ static void coupled_barrier(atomic_t *a, unsigned online) int cps_pm_enter_state(enum cps_pm_state state) { unsigned cpu = smp_processor_id(); + unsigned int cluster = cpu_cluster(¤t_cpu_data); unsigned core = cpu_core(¤t_cpu_data); unsigned online, left; cpumask_t *coupled_mask = this_cpu_ptr(&online_coupled); u32 *core_ready_count, *nc_core_ready_count; void *nc_addr; cps_nc_entry_fn entry; + struct cluster_boot_config *cluster_cfg; struct core_boot_config *core_cfg; struct vpe_boot_config *vpe_cfg; atomic_t *barrier; @@ -142,7 +144,8 @@ int cps_pm_enter_state(enum cps_pm_state state) if (!mips_cps_smp_in_use()) return -EINVAL; - core_cfg = &mips_cps_core_bootcfg[core]; + cluster_cfg = &mips_cps_cluster_bootcfg[cluster]; + core_cfg = &cluster_cfg->core_config[core]; vpe_cfg = &core_cfg->vpe_config[cpu_vpe_id(¤t_cpu_data)]; vpe_cfg->pc = (unsigned long)mips_cps_pm_restore; vpe_cfg->gp = (unsigned long)current_thread_info(); diff --git a/arch/mips/kernel/smp-cps.c b/arch/mips/kernel/smp-cps.c index dd55d59b88db..b8863722d816 100644 --- a/arch/mips/kernel/smp-cps.c +++ b/arch/mips/kernel/smp-cps.c @@ -27,7 +27,7 @@ static DECLARE_BITMAP(core_power, NR_CPUS); -struct core_boot_config *mips_cps_core_bootcfg; +struct cluster_boot_config *mips_cps_cluster_bootcfg; static unsigned __init core_vpe_count(unsigned int cluster, unsigned core) { @@ -108,9 +108,11 @@ static void __init cps_smp_setup(void) static void __init cps_prepare_cpus(unsigned int max_cpus) { - unsigned ncores, core_vpes, c, cca; + unsigned int nclusters, ncores, core_vpes, c, cl, cca; bool cca_unsuitable, cores_limited; u32 *entry_code; + struct cluster_boot_config *cluster_bootcfg; + struct core_boot_config *core_bootcfg; mips_mt_set_cpuoptions(); @@ -160,40 +162,54 @@ static void __init cps_prepare_cpus(unsigned int max_cpus) (void *)entry_code - (void *)&mips_cps_core_entry); __sync(); - /* Allocate core boot configuration structs */ - ncores = mips_cps_numcores(0); - mips_cps_core_bootcfg = kcalloc(ncores, sizeof(*mips_cps_core_bootcfg), - GFP_KERNEL); - if (!mips_cps_core_bootcfg) { - pr_err("Failed to allocate boot config for %u cores\n", ncores); - goto err_out; - } + /* Allocate cluster boot configuration structs */ + nclusters = mips_cps_numclusters(); + mips_cps_cluster_bootcfg = kcalloc(nclusters, + sizeof(*mips_cps_cluster_bootcfg), + GFP_KERNEL); - /* Allocate VPE boot configuration structs */ - for (c = 0; c < ncores; c++) { - core_vpes = core_vpe_count(0, c); - mips_cps_core_bootcfg[c].vpe_config = kcalloc(core_vpes, - sizeof(*mips_cps_core_bootcfg[c].vpe_config), - GFP_KERNEL); - if (!mips_cps_core_bootcfg[c].vpe_config) { - pr_err("Failed to allocate %u VPE boot configs\n", - core_vpes); + for (cl = 0; cl < nclusters; cl++) { + /* Allocate core boot configuration structs */ + ncores = mips_cps_numcores(cl); + core_bootcfg = kcalloc(ncores, sizeof(*core_bootcfg), + GFP_KERNEL); + if (!core_bootcfg) goto err_out; + mips_cps_cluster_bootcfg[cl].core_config = core_bootcfg; + + /* Allocate VPE boot configuration structs */ + for (c = 0; c < ncores; c++) { + core_vpes = core_vpe_count(cl, c); + core_bootcfg[c].vpe_config = kcalloc(core_vpes, + sizeof(*core_bootcfg[c].vpe_config), + GFP_KERNEL); + if (!core_bootcfg[c].vpe_config) + goto err_out; } } /* Mark this CPU as booted */ - atomic_set(&mips_cps_core_bootcfg[cpu_core(¤t_cpu_data)].vpe_mask, - 1 << cpu_vpe_id(¤t_cpu_data)); + cl = cpu_cluster(¤t_cpu_data); + c = cpu_core(¤t_cpu_data); + cluster_bootcfg = &mips_cps_cluster_bootcfg[cl]; + core_bootcfg = &cluster_bootcfg->core_config[c]; + atomic_set(&core_bootcfg->vpe_mask, 1 << cpu_vpe_id(¤t_cpu_data)); return; err_out: /* Clean up allocations */ - if (mips_cps_core_bootcfg) { - for (c = 0; c < ncores; c++) - kfree(mips_cps_core_bootcfg[c].vpe_config); - kfree(mips_cps_core_bootcfg); - mips_cps_core_bootcfg = NULL; + if (mips_cps_cluster_bootcfg) { + for (cl = 0; cl < nclusters; cl++) { + cluster_bootcfg = &mips_cps_cluster_bootcfg[cl]; + ncores = mips_cps_numcores(cl); + for (c = 0; c < ncores; c++) { + core_bootcfg = &cluster_bootcfg->core_config[c]; + kfree(core_bootcfg->vpe_config); + } + kfree(mips_cps_cluster_bootcfg[c].core_config); + } + kfree(mips_cps_cluster_bootcfg); + mips_cps_cluster_bootcfg = NULL; } /* Effectively disable SMP by declaring CPUs not present */ @@ -278,17 +294,23 @@ static void boot_core(unsigned int core, unsigned int vpe_id) static void remote_vpe_boot(void *dummy) { + unsigned int cluster = cpu_cluster(¤t_cpu_data); unsigned core = cpu_core(¤t_cpu_data); - struct core_boot_config *core_cfg = &mips_cps_core_bootcfg[core]; + struct cluster_boot_config *cluster_cfg = + &mips_cps_cluster_bootcfg[cluster]; + struct core_boot_config *core_cfg = &cluster_cfg->core_config[core]; mips_cps_boot_vpes(core_cfg, cpu_vpe_id(¤t_cpu_data)); } static int cps_boot_secondary(int cpu, struct task_struct *idle) { + unsigned int cluster = cpu_cluster(&cpu_data[cpu]); unsigned core = cpu_core(&cpu_data[cpu]); unsigned vpe_id = cpu_vpe_id(&cpu_data[cpu]); - struct core_boot_config *core_cfg = &mips_cps_core_bootcfg[core]; + struct cluster_boot_config *cluster_cfg = + &mips_cps_cluster_bootcfg[cluster]; + struct core_boot_config *core_cfg = &cluster_cfg->core_config[core]; struct vpe_boot_config *vpe_cfg = &core_cfg->vpe_config[vpe_id]; unsigned long core_entry; unsigned int remote; @@ -448,12 +470,14 @@ static void cps_kexec_nonboot_cpu(void) static int cps_cpu_disable(void) { unsigned cpu = smp_processor_id(); + struct cluster_boot_config *cluster_cfg; struct core_boot_config *core_cfg; if (!cps_pm_support_state(CPS_PM_POWER_GATED)) return -EINVAL; - core_cfg = &mips_cps_core_bootcfg[cpu_core(¤t_cpu_data)]; + cluster_cfg = &mips_cps_cluster_bootcfg[cpu_cluster(¤t_cpu_data)]; + core_cfg = &cluster_cfg->core_config[cpu_core(¤t_cpu_data)]; atomic_sub(1 << cpu_vpe_id(¤t_cpu_data), &core_cfg->vpe_mask); smp_mb__after_atomic(); set_cpu_online(cpu, false); From patchwork Tue Oct 31 16:49:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Rikalo X-Patchwork-Id: 13442132 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 06C92C4167D for ; Tue, 31 Oct 2023 16:53:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346821AbjJaQxc (ORCPT ); Tue, 31 Oct 2023 12:53:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346828AbjJaQwc (ORCPT ); Tue, 31 Oct 2023 12:52:32 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2111.outbound.protection.outlook.com [40.107.21.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7524210B; Tue, 31 Oct 2023 09:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nzoRdX7yHKJw5iYypimP47ZqZWUzlQK05CkEDLsrusaLA7JVgG/QMx2hCh8DouTrwgZCemKyQK5IrqwR5LRw4OK6/0AI2IanMgj5u30pgFmmtMuDNQmwsCwEAfYsRb9sv9JBADXGbuA7kFayRyRJ1WNHJBSvzHDBP4QUgwRz5RnEPZ8YnZ29SyWowgq/rG9+PHNDDeENsoowhdlhutTMTgZtcG6RcnjbI6riNptNPQU+sIQCjoo7DqO9BrsxaAOs2u0kHpF9tkscleRSEgK7EDJbJZH9QvqWrV1uJbPLMajmCTkP4hsOFkegk5hrrKfxV5sELaigIMc7aUMCNchnJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sDubzoWDSwzU69UFQNp0UxSMsJBCiAFWs7lpjdGW5y0=; b=cn/Tu2VHode4KPF9G4jBzdSvBrolqk6I51i5fqR/fYgsUujsoRmLbkuQp33eTuQb0b1XhQFq2GMZDADS96VDJXazoHylZM4lgqoImal62c+XEGH2svBD4pcDHkobSqjJQHt6snRwWkQWpVB8Fg69QNqFziFUIB/9Ij3qZY5WuvU+4+KPhpCi8xvDRv0nRdm7pGtfQ6+kSmZfqWMd9r8Tfpu+AfY8voJG3i2Vyu2dq5ZiRpFAy+o1FYhsSxPzbkgHxemsIw5rIpkUOpcgtCtgGmEtUfhAEsDL5AYK4NcoJAIKyCTle9MHex3duJqq+QCAcCVigcMhSRTQIyQg4DPPfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sDubzoWDSwzU69UFQNp0UxSMsJBCiAFWs7lpjdGW5y0=; b=rwlqEp6dNAX+uKky6hZQTb9vSijca9T0Kr6dlimXDq1fI0J9L7Jtsmq+pg0qP6qiLu50Lk30tTyzHsa2sm4zB3Ph3mJLuWTjUeRxgrb9A4fHehLoEQut0WjH/HnDSkl6gr0eCAnQF9zJ9TF9myk0YExKAaIbPEI6vC1KLuxZjR0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=syrmia.com; Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) by DB4PR03MB8706.eurprd03.prod.outlook.com (2603:10a6:10:382::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28; Tue, 31 Oct 2023 16:49:57 +0000 Received: from VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa]) by VI1PR0302MB3486.eurprd03.prod.outlook.com ([fe80::59be:1f7c:f22b:baaa%4]) with mapi id 15.20.6907.032; Tue, 31 Oct 2023 16:49:57 +0000 From: Aleksandar Rikalo To: Thomas Bogendoerfer Cc: Aleksandar Rikalo , Chao-ying Fu , Daniel Lezcano , Dragan Mladjenovic , Geert Uytterhoeven , Greg Ungerer , Hauke Mehrtens , Ilya Lipnitskiy , Jiaxun Yang , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Marc Zyngier , Paul Burton , Peter Zijlstra , Serge Semin , Thomas Gleixner , Tiezhu Yang Subject: [PATCH v3 11/11] MIPS: CPS: Boot CPUs in secondary clusters Date: Tue, 31 Oct 2023 17:49:27 +0100 Message-Id: <20231031164927.371663-12-aleksandar.rikalo@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> References: <20231031164927.371663-1-aleksandar.rikalo@syrmia.com> X-ClientProxiedBy: AM0PR10CA0065.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::18) To VI1PR0302MB3486.eurprd03.prod.outlook.com (2603:10a6:803:1e::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0302MB3486:EE_|DB4PR03MB8706:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e08e41c-4409-49bf-5a76-08dbda3169d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wBE0mJRqMVFYD0lbBZg+0GhWlELXZzgTiFKsUk47AR89e4cY7qk92483qRyRaB5SQacY65M64tsQQqvcnFC9HFbr0Z7GOCEMsORWCcN3ljyz3NvyUa8yOlKTUnj5d5jXIwwa8jF/Ly/9F5LUBNLA7gu3Ydzw0+hY7g/J/p3IWle1tUN2TaGDEgD1a8DYefU05Roj0eobRLs8YTPNX1za4b5aHyJ80FsKlBKLpiFcwLUPCIqlONuJOixEb9Zz2+WNpor6Codmy3q0Sgo7PNFS1NryFIjDnxwcV32styXK2O0m7l6g751UbgVdftfWgWlHgpbVqbmejITffhAOyYUDWcAQR4Oipp4YHjcwBUG/p6R9vDO89+s2SlWuqMk97yNJ714yAb0h5x6bXlRp6romacLCdlePYeEyH0QMBy8wXEAPuUoN84hs7I3sfOsq0hr3h8KXKS/rLrpQW5kpjpOLrPvM6+tPC7KepWvG6BNAeUuwt2UU4+p1EJ0QU+9MpDKDL4kLrhA934IKQvarIi6bV2hC11S1NAirsJb8ikCT+c4MQ7DWImGRr1JI01eQAXSeDN21tyId8L0NW8C7mM4KWKgEiKUUPnPYOopISj4BAuTdu8ZEY/lUK/169GCK+0ID X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0302MB3486.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(39830400003)(346002)(376002)(136003)(230922051799003)(186009)(64100799003)(451199024)(1800799009)(6512007)(2616005)(1076003)(26005)(6666004)(478600001)(4326008)(6506007)(83380400001)(44832011)(6486002)(7416002)(30864003)(2906002)(41300700001)(66556008)(66946007)(66476007)(8936002)(8676002)(52116002)(6916009)(5660300002)(54906003)(316002)(36756003)(38100700002)(86362001)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8nP1ZRF3xXOcLoQtUcVwtb5+RL2qPnNwJKhlApUjo6D2BuI2yal5p6voL1kVOVq6ZDAbMqSMdV8NC/jFvGpRwLJ8DJNsMBzeytGUgow7F4Xnxm7G8Z0AhgKyVSoH9YSfmm8i5pZ+tFAzH7TnPEPZc7vKxCCUqCX0hzEjL4CDfTS3zq+zflp+FDGqIotT7eCi3PSrKkz5TCzmVZgwbjrRt0tNc4U6uzt6jv7OgvKxya/hP0tVCmM8TJ+g36xqsgFsdnQq+B8ANT3R1coxs/xTaqOajnr8KDHidabVKqD49oKYaj1BW5iVwihWyxsOd496kI7rA0wgm4sbIpyccBC4vf5W6qOiQyGDDjCAiaHbPoClvkZ3adZABs1pERmJ1CCgvlgxl0K5kZMBDgLiLJST/BpEQ3QB9UmQ3svKo0k0/yQofV5Xhq1k0WT43HET4BmjlpOmflmww18DX8NxR7xmZUHYjefe+PnJoWizOZznljgWg5GnLnxVw84yMc7Wi7sjjN30sAKHVNHZqBuzGNEyYZ0syEaJxT71doLGWT0fZ+Jgb6gINs1rozorrd/61Qnb/8aSFS/F505y4b74vsqOd9AxtYg6keKK9Dvv5wOx0OeBxIuJ9Al0rv7ar6mitT+2TEEQz8VDms4dquhV2KBQ/woT0hIHG5fmLrb9MstiWze3f6wWueWnGacBs/C65R59nsxll9hf7XGhyX8PdMVLZCgbWjK2g9fhkmPV0YBoPA+XTMUgDKjwbUdRyUW8Yv2AOyuY+tkyAlRrv47snZHo07U6MQxk1EVta29YN5I+g/fxQt62c3+QYl0ekd2Ya8ut0nvYFZxrHaZCD5ZqCjr6MWX9r7bDLx/Zd8HK6hLU/AZ85k7n4DFTEfrTWrhDAchZCi5H7Yrh81MsnI+zblsTZ7B43NN1nvhK6oNGAenonobQWHDc/ciVIHlyAoqVhymgzgRerTD8dspglxA+d0uZ4dtSS9RwFYEZId5+RvY1cyQlh2gxMjshPATq5zvkns2D0r0DzSLJikQRaUNGLvSlfG1fKLebrsyJbfsvvGBh4KJaVYqavUh4rRklK+GYeX5xPA3nFdPpkBBZjYOOL6vG0bdm0C9lq+HhrypnyuJRSkBcC2o023ZHqThTzaghQyW9u6vc5Ja+RYmByWKCXiLpG3vRRdBEHQsD+lp81TjmP0Lz2gC3BXRMYeN5kgwtRTLPHZ4ChfF7l50MghIDkrxKo895IQRsslkkTU/LAMhpZmHfmza6px9vXIy7UpGawz6Rz2rtx13GnQpBlY7H+SYELzp7bphnilVHoHUDU8Nd8EPtFbjrdUINQwZjT5dgvLh24+8xCdkSV++L/YVCp8UyK+seIaMcj3Nkvx+TCH5elaqN7u1dPzwHPDPmyzMiCEnSja5zQxt5ZVwciLCK6/2VBZJrzvwHmnqIAyjPVjEa+y16TYiXxzMcCPBs6KxWWpkFMysyF0ET3+FarRIn8ugXIfTvCT+wbzGZuq9KQYsWj1Rk2HUZo3u4VCeq3r7JSdKNlr0fLvNJu92+myxw0YxWOlEmFbbho89xEr2PiSXh5NS7/A/xix3D1LX8bWaC7Yhal/yar1LVxIbsK7CD0aRv3A== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e08e41c-4409-49bf-5a76-08dbda3169d8 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0302MB3486.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2023 16:49:56.9038 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Q3Gz8RrERJbDkV3jO2mthWQOWcYfPA4aABWwUnkorRrJ+DYGR8GQxW34X6FnWHdrFe2cyyJI+NErnJmPQ07IXvqiYtvF2jxo/xhKbf7YKHY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR03MB8706 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Paul Burton Probe for & boot CPUs (cores & VPs) in secondary clusters (ie. not the cluster that began booting Linux) when they are present in systems with CM 3.5 or higher. Signed-off-by: Paul Burton Signed-off-by: Chao-ying Fu Signed-off-by: Dragan Mladjenovic Signed-off-by: Aleksandar Rikalo --- arch/mips/include/asm/mips-cm.h | 18 +++ arch/mips/include/asm/smp-cps.h | 1 + arch/mips/kernel/mips-cm.c | 4 +- arch/mips/kernel/smp-cps.c | 217 ++++++++++++++++++++++++++++---- 4 files changed, 212 insertions(+), 28 deletions(-) diff --git a/arch/mips/include/asm/mips-cm.h b/arch/mips/include/asm/mips-cm.h index 23c67c0871b1..435049907e44 100644 --- a/arch/mips/include/asm/mips-cm.h +++ b/arch/mips/include/asm/mips-cm.h @@ -239,6 +239,12 @@ GCR_ACCESSOR_RW(32, 0x130, l2_config) GCR_ACCESSOR_RO(32, 0x150, sys_config2) #define CM_GCR_SYS_CONFIG2_MAXVPW GENMASK(3, 0) +/* GCR_L2-RAM_CONFIG - Configuration & status of L2 cache RAMs */ +GCR_ACCESSOR_RW(64, 0x240, l2_ram_config) +#define CM_GCR_L2_RAM_CONFIG_PRESENT BIT(31) +#define CM_GCR_L2_RAM_CONFIG_HCI_DONE BIT(30) +#define CM_GCR_L2_RAM_CONFIG_HCI_SUPPORTED BIT(29) + /* GCR_L2_PFT_CONTROL - Controls hardware L2 prefetching */ GCR_ACCESSOR_RW(32, 0x300, l2_pft_control) #define CM_GCR_L2_PFT_CONTROL_PAGEMASK GENMASK(31, 12) @@ -250,6 +256,18 @@ GCR_ACCESSOR_RW(32, 0x308, l2_pft_control_b) #define CM_GCR_L2_PFT_CONTROL_B_CEN BIT(8) #define CM_GCR_L2_PFT_CONTROL_B_PORTID GENMASK(7, 0) +/* GCR_L2_TAG_ADDR - Access addresses in L2 cache tags */ +GCR_ACCESSOR_RW(64, 0x600, l2_tag_addr) + +/* GCR_L2_TAG_STATE - Access L2 cache tag state */ +GCR_ACCESSOR_RW(64, 0x608, l2_tag_state) + +/* GCR_L2_DATA - Access data in L2 cache lines */ +GCR_ACCESSOR_RW(64, 0x610, l2_data) + +/* GCR_L2_ECC - Access ECC information from L2 cache lines */ +GCR_ACCESSOR_RW(64, 0x618, l2_ecc) + /* GCR_L2SM_COP - L2 cache op state machine control */ GCR_ACCESSOR_RW(32, 0x620, l2sm_cop) #define CM_GCR_L2SM_COP_PRESENT BIT(31) diff --git a/arch/mips/include/asm/smp-cps.h b/arch/mips/include/asm/smp-cps.h index 2893d1d0bc63..d784f65966d7 100644 --- a/arch/mips/include/asm/smp-cps.h +++ b/arch/mips/include/asm/smp-cps.h @@ -23,6 +23,7 @@ struct core_boot_config { }; struct cluster_boot_config { + unsigned long *core_power; struct core_boot_config *core_config; }; diff --git a/arch/mips/kernel/mips-cm.c b/arch/mips/kernel/mips-cm.c index 2a59f0842a4a..074894a19170 100644 --- a/arch/mips/kernel/mips-cm.c +++ b/arch/mips/kernel/mips-cm.c @@ -314,7 +314,9 @@ void mips_cm_lock_other(unsigned int cluster, unsigned int core, FIELD_PREP(CM3_GCR_Cx_OTHER_VP, vp); if (cm_rev >= CM_REV_CM3_5) { - val |= CM_GCR_Cx_OTHER_CLUSTER_EN; + if (cluster != cpu_cluster(¤t_cpu_data)) + val |= CM_GCR_Cx_OTHER_CLUSTER_EN; + val |= CM_GCR_Cx_OTHER_GIC_EN; val |= FIELD_PREP(CM_GCR_Cx_OTHER_CLUSTER, cluster); val |= FIELD_PREP(CM_GCR_Cx_OTHER_BLOCK, block); } else { diff --git a/arch/mips/kernel/smp-cps.c b/arch/mips/kernel/smp-cps.c index b8863722d816..06a2d57e768c 100644 --- a/arch/mips/kernel/smp-cps.c +++ b/arch/mips/kernel/smp-cps.c @@ -25,10 +25,54 @@ #include #include -static DECLARE_BITMAP(core_power, NR_CPUS); struct cluster_boot_config *mips_cps_cluster_bootcfg; +static void power_up_other_cluster(unsigned int cluster) +{ + u32 stat, seq_state; + unsigned int timeout; + + mips_cm_lock_other(cluster, CM_GCR_Cx_OTHER_CORE_CM, 0, + CM_GCR_Cx_OTHER_BLOCK_LOCAL); + stat = read_cpc_co_stat_conf(); + mips_cm_unlock_other(); + + seq_state = stat & CPC_Cx_STAT_CONF_SEQSTATE; + seq_state >>= __ffs(CPC_Cx_STAT_CONF_SEQSTATE); + if (seq_state == CPC_Cx_STAT_CONF_SEQSTATE_U5) + return; + + /* Set endianness & power up the CM */ + mips_cm_lock_other(cluster, 0, 0, CM_GCR_Cx_OTHER_BLOCK_GLOBAL); + write_cpc_redir_sys_config(IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)); + write_cpc_redir_pwrup_ctl(1); + mips_cm_unlock_other(); + + /* Wait for the CM to start up */ + timeout = 1000; + mips_cm_lock_other(cluster, CM_GCR_Cx_OTHER_CORE_CM, 0, + CM_GCR_Cx_OTHER_BLOCK_LOCAL); + while (1) { + stat = read_cpc_co_stat_conf(); + seq_state = stat & CPC_Cx_STAT_CONF_SEQSTATE; + seq_state >>= __ffs(CPC_Cx_STAT_CONF_SEQSTATE); + if (seq_state == CPC_Cx_STAT_CONF_SEQSTATE_U5) + break; + + if (timeout) { + mdelay(1); + timeout--; + } else { + pr_warn("Waiting for cluster %u CM to power up... STAT_CONF=0x%x\n", + cluster, stat); + mdelay(1000); + } + } + + mips_cm_unlock_other(); +} + static unsigned __init core_vpe_count(unsigned int cluster, unsigned core) { return min(smp_max_threads, mips_cps_numvps(cluster, core)); @@ -49,6 +93,9 @@ static void __init cps_smp_setup(void) pr_cont(","); pr_cont("{"); + if (mips_cm_revision() >= CM_REV_CM3_5) + power_up_other_cluster(cl); + ncores = mips_cps_numcores(cl); for (c = 0; c < ncores; c++) { core_vpes = core_vpe_count(cl, c); @@ -76,8 +123,8 @@ static void __init cps_smp_setup(void) /* Indicate present CPUs (CPU being synonymous with VPE) */ for (v = 0; v < min_t(unsigned, nvpes, NR_CPUS); v++) { - set_cpu_possible(v, cpu_cluster(&cpu_data[v]) == 0); - set_cpu_present(v, cpu_cluster(&cpu_data[v]) == 0); + set_cpu_possible(v, true); + set_cpu_present(v, true); __cpu_number_map[v] = v; __cpu_logical_map[v] = v; } @@ -85,19 +132,15 @@ static void __init cps_smp_setup(void) /* Set a coherent default CCA (CWB) */ change_c0_config(CONF_CM_CMASK, 0x5); - /* Core 0 is powered up (we're running on it) */ - bitmap_set(core_power, 0, 1); - /* Initialise core 0 */ mips_cps_core_init(); /* Make core 0 coherent with everything */ write_gcr_cl_coherence(0xff); - if (mips_cm_revision() >= CM_REV_CM3) { - core_entry = CKSEG1ADDR((unsigned long)mips_cps_core_entry); + core_entry = CKSEG1ADDR((unsigned long)mips_cps_core_entry); + if (mips_cm_revision() >= CM_REV_CM3) write_gcr_bev_base(core_entry); - } #ifdef CONFIG_MIPS_MT_FPAFF /* If we have an FPU, enroll ourselves in the FPU-full mask */ @@ -177,6 +220,10 @@ static void __init cps_prepare_cpus(unsigned int max_cpus) goto err_out; mips_cps_cluster_bootcfg[cl].core_config = core_bootcfg; + mips_cps_cluster_bootcfg[cl].core_power = + kcalloc(BITS_TO_LONGS(ncores), sizeof(unsigned long), + GFP_KERNEL); + /* Allocate VPE boot configuration structs */ for (c = 0; c < ncores; c++) { core_vpes = core_vpe_count(cl, c); @@ -188,11 +235,12 @@ static void __init cps_prepare_cpus(unsigned int max_cpus) } } - /* Mark this CPU as booted */ + /* Mark this CPU as powered up & booted */ cl = cpu_cluster(¤t_cpu_data); c = cpu_core(¤t_cpu_data); cluster_bootcfg = &mips_cps_cluster_bootcfg[cl]; core_bootcfg = &cluster_bootcfg->core_config[c]; + bitmap_set(cluster_bootcfg->core_power, cpu_core(¤t_cpu_data), 1); atomic_set(&core_bootcfg->vpe_mask, 1 << cpu_vpe_id(¤t_cpu_data)); return; @@ -220,16 +268,123 @@ static void __init cps_prepare_cpus(unsigned int max_cpus) } } -static void boot_core(unsigned int core, unsigned int vpe_id) +static void init_cluster_l2(void) { - u32 stat, seq_state; - unsigned timeout; + u32 l2_cfg, l2sm_cop, result; + + while (1) { + l2_cfg = read_gcr_redir_l2_ram_config(); + + /* If HCI is not supported, use the state machine below */ + if (!(l2_cfg & CM_GCR_L2_RAM_CONFIG_PRESENT)) + break; + if (!(l2_cfg & CM_GCR_L2_RAM_CONFIG_HCI_SUPPORTED)) + break; + + /* If the HCI_DONE bit is set, we're finished */ + if (l2_cfg & CM_GCR_L2_RAM_CONFIG_HCI_DONE) + return; + } + + l2sm_cop = read_gcr_redir_l2sm_cop(); + if (WARN(!(l2sm_cop & CM_GCR_L2SM_COP_PRESENT), + "L2 init not supported on this system yet")) + return; + + /* Clear L2 tag registers */ + write_gcr_redir_l2_tag_state(0); + write_gcr_redir_l2_ecc(0); + + /* Ensure the L2 tag writes complete before the state machine starts */ + mb(); + + /* Wait for the L2 state machine to be idle */ + do { + l2sm_cop = read_gcr_redir_l2sm_cop(); + } while (l2sm_cop & CM_GCR_L2SM_COP_RUNNING); + + /* Start a store tag operation */ + l2sm_cop = CM_GCR_L2SM_COP_TYPE_IDX_STORETAG; + l2sm_cop <<= __ffs(CM_GCR_L2SM_COP_TYPE); + l2sm_cop |= CM_GCR_L2SM_COP_CMD_START; + write_gcr_redir_l2sm_cop(l2sm_cop); + + /* Ensure the state machine starts before we poll for completion */ + mb(); + + /* Wait for the operation to be complete */ + do { + l2sm_cop = read_gcr_redir_l2sm_cop(); + result = l2sm_cop & CM_GCR_L2SM_COP_RESULT; + result >>= __ffs(CM_GCR_L2SM_COP_RESULT); + } while (!result); + + WARN(result != CM_GCR_L2SM_COP_RESULT_DONE_OK, + "L2 state machine failed cache init with error %u\n", result); +} + +static void boot_core(unsigned int cluster, unsigned int core, + unsigned int vpe_id) +{ + struct cluster_boot_config *cluster_cfg; + u32 access, stat, seq_state; + unsigned int timeout, ncores; + unsigned long core_entry; + + cluster_cfg = &mips_cps_cluster_bootcfg[cluster]; + ncores = mips_cps_numcores(cluster); + core_entry = CKSEG1ADDR((unsigned long)mips_cps_core_entry); + + if ((cluster != cpu_cluster(¤t_cpu_data)) && + bitmap_empty(cluster_cfg->core_power, ncores)) { + power_up_other_cluster(cluster); + + mips_cm_lock_other(cluster, core, 0, + CM_GCR_Cx_OTHER_BLOCK_GLOBAL); + + /* Ensure cluster GCRs are where we expect */ + write_gcr_redir_base(read_gcr_base()); + write_gcr_redir_cpc_base(read_gcr_cpc_base()); + write_gcr_redir_gic_base(read_gcr_gic_base()); + + init_cluster_l2(); + + /* Mirror L2 configuration */ + write_gcr_redir_l2_only_sync_base(read_gcr_l2_only_sync_base()); + write_gcr_redir_l2_pft_control(read_gcr_l2_pft_control()); + write_gcr_redir_l2_pft_control_b(read_gcr_l2_pft_control_b()); + + /* Mirror ECC/parity setup */ + write_gcr_redir_err_control(read_gcr_err_control()); + + /* Set BEV base */ + write_gcr_redir_bev_base(core_entry); + + mips_cm_unlock_other(); + } + + if (cluster != cpu_cluster(¤t_cpu_data)) { + mips_cm_lock_other(cluster, core, 0, + CM_GCR_Cx_OTHER_BLOCK_GLOBAL); + + /* Ensure the core can access the GCRs */ + access = read_gcr_redir_access(); + access |= BIT(core); + write_gcr_redir_access(access); + + mips_cm_unlock_other(); + } else { + /* Ensure the core can access the GCRs */ + access = read_gcr_access(); + access |= BIT(core); + write_gcr_access(access); + } /* Select the appropriate core */ - mips_cm_lock_other(0, core, 0, CM_GCR_Cx_OTHER_BLOCK_LOCAL); + mips_cm_lock_other(cluster, core, 0, CM_GCR_Cx_OTHER_BLOCK_LOCAL); /* Set its reset vector */ - write_gcr_co_reset_base(CKSEG1ADDR((unsigned long)mips_cps_core_entry)); + write_gcr_co_reset_base(core_entry); /* Ensure its coherency is disabled */ write_gcr_co_coherence(0); @@ -237,9 +392,6 @@ static void boot_core(unsigned int core, unsigned int vpe_id) /* Start it with the legacy memory map and exception base */ write_gcr_co_reset_ext_base(CM_GCR_Cx_RESET_EXT_BASE_UEB); - /* Ensure the core can access the GCRs */ - set_gcr_access(1 << core); - if (mips_cpc_present()) { /* Reset the core */ mips_cpc_lock_other(core); @@ -289,7 +441,17 @@ static void boot_core(unsigned int core, unsigned int vpe_id) mips_cm_unlock_other(); /* The core is now powered up */ - bitmap_set(core_power, core, 1); + bitmap_set(cluster_cfg->core_power, core, 1); + + /* + * Restore CM_PWRUP=0 so that the CM can power down if all the cores in + * the cluster do (eg. if they're all removed via hotplug. + */ + if (mips_cm_revision() >= CM_REV_CM3_5) { + mips_cm_lock_other(cluster, 0, 0, CM_GCR_Cx_OTHER_BLOCK_GLOBAL); + write_cpc_redir_pwrup_ctl(0); + mips_cm_unlock_other(); + } } static void remote_vpe_boot(void *dummy) @@ -316,10 +478,6 @@ static int cps_boot_secondary(int cpu, struct task_struct *idle) unsigned int remote; int err; - /* We don't yet support booting CPUs in other clusters */ - if (cpu_cluster(&cpu_data[cpu]) != cpu_cluster(&raw_current_cpu_data)) - return -ENOSYS; - vpe_cfg->pc = (unsigned long)&smp_bootstrap; vpe_cfg->sp = __KSTK_TOS(idle); vpe_cfg->gp = (unsigned long)task_thread_info(idle); @@ -328,14 +486,15 @@ static int cps_boot_secondary(int cpu, struct task_struct *idle) preempt_disable(); - if (!test_bit(core, core_power)) { + if (!test_bit(core, cluster_cfg->core_power)) { /* Boot a VPE on a powered down core */ - boot_core(core, vpe_id); + boot_core(cluster, core, vpe_id); goto out; } if (cpu_has_vp) { - mips_cm_lock_other(0, core, vpe_id, CM_GCR_Cx_OTHER_BLOCK_LOCAL); + mips_cm_lock_other(cluster, core, vpe_id, + CM_GCR_Cx_OTHER_BLOCK_LOCAL); core_entry = CKSEG1ADDR((unsigned long)mips_cps_core_entry); write_gcr_co_reset_base(core_entry); mips_cm_unlock_other(); @@ -543,11 +702,15 @@ static void cps_cpu_die(unsigned int cpu) { } static void cps_cleanup_dead_cpu(unsigned cpu) { + unsigned int cluster = cpu_cluster(&cpu_data[cpu]); unsigned core = cpu_core(&cpu_data[cpu]); unsigned int vpe_id = cpu_vpe_id(&cpu_data[cpu]); ktime_t fail_time; unsigned stat; int err; + struct cluster_boot_config *cluster_cfg; + + cluster_cfg = &mips_cps_cluster_bootcfg[cluster]; /* * Now wait for the CPU to actually offline. Without doing this that @@ -599,7 +762,7 @@ static void cps_cleanup_dead_cpu(unsigned cpu) } while (1); /* Indicate the core is powered off */ - bitmap_clear(core_power, core, 1); + bitmap_clear(cluster_cfg->core_power, core, 1); } else if (cpu_has_mipsmt) { /* * Have a CPU with access to the offlined CPUs registers wait