Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp339468lqp; Wed, 12 Jun 2024 03:11:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVd71DOCsJiUy7CjST+VHlLMpOIRQ5wwN0ZPrgmb575TLWC0WIitt3vwb0corf0Pr730nQrzYGOImqNYp+seyTcWwrjDmi68UEi0gIIaw== X-Google-Smtp-Source: AGHT+IGMOmuCOeEmWbCw4lXxhK2ZyLZZOXNFCaP2Tqftg+9+PUWq1eVuz050PIhQFgWkwDsAhM8R X-Received: by 2002:a05:620a:1a28:b0:795:4836:33b with SMTP id af79cd13be357-797f60ceb2emr126197485a.35.1718187095222; Wed, 12 Jun 2024 03:11:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718187095; cv=pass; d=google.com; s=arc-20160816; b=nwKBJoPCIfidfg0SCmCwkYv9+K9j2t9WwilW6oH8vwM49sEfvtHPkpmalqG84sZ5ne +c/hKYFpzW8FY3UGNeEEy2szzKLPGzDeEi7i6Ba+h/djuGbho+m9FJO5A5oslOAYJa7c dzSd9VqxwHzCZzP4gRtOIpnuvFusX5wcW8wAik7XKZrTsZNdL6d5R96kqmTRaMlv+MPW NW2Yb/Ce3KnlOQaxUQb1L9aCV5NMT78Gf4LxxvMQ3COCOnEYVArQ/xSDaPg+XiTH7QmW v3IMoZpBNtJzs5axY1SHyuA0+nWYwWR9lcvbuBieZjksDwzdwlukKWxmGVW60+Qmyy4l lgzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:feedback-id:dkim-signature:dkim-signature; bh=iPbRKS8KTP23XarmKKdaRK6HQu116D/aznYejgpVkTM=; fh=qiNtu2cWk68hYivofTHRibE3jmi7UziuUm6soyA9tIU=; b=xjXH/rtHR+HAikcZc0aBJ01c6sZqR+A/8oTB/CYnZj57QS1wmpXsnfSa3FV2aj0Sbc rO8PEBDLWKYFZE7hUwC3bDvtdkoiLJ5YTtAZeLGk47lAdq/yGA4q6hX55CXHT8jEWHl3 2CLZi3pT8drEsKEGclrd/vFZKrI67eNv5TtK+NlXT3h6O3RU1w9CIPloC0VY+d+bcz9x 4NehyaYD5VORdYT3N2feQqTHmGg0MOgQTerKv08JIqI1Ev3ZpJOngKxdjHmLHXW6Bn7l ot8tUrmjyk8tXqq40u2GMyTsmSqReDeS/XhhFthDpC+EUTVqFf1HRS82pss2hjddV1oN wTMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@flygoat.com header.s=fm2 header.b=RwqP4uio; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Sw6eC1NS; arc=pass (i=1 spf=pass spfdomain=flygoat.com dkim=pass dkdomain=flygoat.com dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=flygoat.com); spf=pass (google.com: domain of linux-kernel+bounces-211334-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211334-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flygoat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-795440213desi1201008385a.781.2024.06.12.03.11.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 03:11:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211334-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@flygoat.com header.s=fm2 header.b=RwqP4uio; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Sw6eC1NS; arc=pass (i=1 spf=pass spfdomain=flygoat.com dkim=pass dkdomain=flygoat.com dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=flygoat.com); spf=pass (google.com: domain of linux-kernel+bounces-211334-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211334-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flygoat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 871451C21940 for ; Wed, 12 Jun 2024 10:10:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 56B3B16FF30; Wed, 12 Jun 2024 10:09:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="RwqP4uio"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Sw6eC1NS" Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF88C16F27B; Wed, 12 Jun 2024 10:09:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718186948; cv=none; b=W63RWupehb5BumBfyP57OQQMKYqQ/o918LiNAy5Vl64N0LPwQpTKr45RodKuElCGUpUdqWa60VZHsNDKRHooh9Nh8xKgkx9kdB0Hz0bQ78xWrK4YV1pCSqGpUeu6Xdhx+bBvBgYoAa5pAoZVAgcGMOU4IXEvivrsmchInQASlU4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718186948; c=relaxed/simple; bh=L0sI9SNX8Fl8dWHCmZcs43fJIyWpWY+8oHGPiv/o1WY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HEaC+MkiJZgDwEleSUSDtxqD88ovo0mGsEHQij9ADMNi2bXibOgL9XTZyVQUKDn72ax1k4TjHXCG6Oj9zmNKCEEtpPV7sdl+Xw/HWQ1pfhMpM/1stoW/at811n6+nY/TMQUl0uCtXHIRDKgnJPNeXafJhtYXFa9dg0Rm+Zm2vOM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=RwqP4uio; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Sw6eC1NS; arc=none smtp.client-ip=103.168.172.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id CAEC91380083; Wed, 12 Jun 2024 06:09:05 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 12 Jun 2024 06:09:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1718186945; x=1718273345; bh=iPbRKS8KTP23XarmKKdaRK6HQu116D/aznYejgpVkTM=; b= RwqP4uioREdG08LA9b6XESYE9EIuxp+Ic3pCMPDeZnfG8gkmC3IgdS+E+xxw4ztw d1M3Mkxfjy96GpIfw3QjnW8Xy8gns19TssM+5vUsV+osCbZ1KZtktDtaa71i5tEd 7QB4mePpKeHn9dT4Kbr6FcgppTuevc25LgdVEdIpvRNCF5e9xP0FDUX3GNQ4xumC 6VAlRtw0HqweGxN9KETrmoos9om9fUHzH8ADSXC/tCoJoZ3hBPsoZgyy9t5KEXEk MG+VgNPZ78ILLZ3fgDLyfs1JQoHon69i4fHJT1VunQvoZLcNulPNtqRohfZp543m nMmIfqHe1OV7fCFf6vQc5g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718186945; x= 1718273345; bh=iPbRKS8KTP23XarmKKdaRK6HQu116D/aznYejgpVkTM=; b=S w6eC1NSnubDJJ2ZGOR729+Q3fXYdkn1bgC6Ui2ftwTjRRdeG7hY7W3M3OT+Ghmhp svr2Xu861cHpZYSVANF7SeJPei+nbVwnGpxR61usIk8vP9jOxiGpMFlje987L+qA GkzkO2neWbeI4LHmn0zEQtpQ6YukvDyGXEHMbkSf5oC3qAcj51VIRYJRSGdUxn7X rZgkLF+AtASS7Q7OLV6oHCyi7cUM0yDz0WYwC832oLCa75QZyLy61zGYHovBT9Yo CZy33v5IH2zmPRmywTVOWjDBv+xMdost79599RxSADkhjBZVkSFb0u4fvani/cuo bvK6WhvNJBO2wRdZPghJA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedugedgvdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeflihgr gihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomheqne cuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffekgedugefhtdduudeghfeu veegffegudekjeelnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilh hfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Jun 2024 06:09:04 -0400 (EDT) From: Jiaxun Yang Date: Wed, 12 Jun 2024 11:08:58 +0100 Subject: [PATCH v2 6/6] MIPS: cm: Probe GCR address from DeviceTree Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240612-cm_probe-v2-6-a5b55440563c@flygoat.com> References: <20240612-cm_probe-v2-0-a5b55440563c@flygoat.com> In-Reply-To: <20240612-cm_probe-v2-0-a5b55440563c@flygoat.com> To: Paul Burton , Thomas Bogendoerfer , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Serge Semin , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3047; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=L0sI9SNX8Fl8dWHCmZcs43fJIyWpWY+8oHGPiv/o1WY=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrTM4m3tk30Z190JfPNlzmuVmrNfz70x/v/9Rleah8Xmx MRvLU0POkpZGMS4GGTFFFlCBJT6NjReXHD9QdYfmDmsTCBDGLg4BWAisQIM/3TCUti9+J5dmVbr tGDFdklpwd6V8e2+X4IvKsgu+qjQUcPIcOTo5ZffGWMu7zi1x1Nu0pqr62cfEQ086TFTJGru14X vbPgB X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Traditionally, CM GCR address can be probed from CP0_CMGCRBase. However there are chips in wild that do have CM GCR but CP0_CMGCRBase is not available from CPU point of view. Thus we need to be able to probe GCR address from DeviceTree. It is implemented as: - If only CP0_CMGCRBase present, trust CP0_CMGCRBase - If only mti,mips-cm node present, trust mti,mips-cm reg prop - If both present, remap address space to address specified in dt Signed-off-by: Jiaxun Yang --- v2: Fix build warning (test bot) --- arch/mips/kernel/mips-cm.c | 61 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/arch/mips/kernel/mips-cm.c b/arch/mips/kernel/mips-cm.c index dddc9428fe58..02afc795ba8a 100644 --- a/arch/mips/kernel/mips-cm.c +++ b/arch/mips/kernel/mips-cm.c @@ -5,6 +5,8 @@ */ #include +#include +#include #include #include @@ -179,23 +181,70 @@ static char *cm3_causes[32] = { static DEFINE_PER_CPU_ALIGNED(spinlock_t, cm_core_lock); static DEFINE_PER_CPU_ALIGNED(unsigned long, cm_core_lock_flags); +static int __init mips_cm_fdt_scan(unsigned long node, const char *uname, + int depth, void *data) +{ + u64 addr; + unsigned long *cmgcr = data; + + if (!of_flat_dt_is_compatible(node, "mti,mips-cm")) + return 0; + + addr = of_flat_dt_translate_address(node); + if (addr == OF_BAD_ADDR || addr >= ULONG_MAX) + *cmgcr = 0; + else + *cmgcr = addr; + + return 0; +} + phys_addr_t __init __weak mips_cm_phys_base(void) { - unsigned long cmgcr; + unsigned long gcr_reg = 0, gcr_dt = 0; + + if (of_have_populated_dt()) { + int err; + struct resource res; + struct device_node *cm_node; + + cm_node = of_find_compatible_node(of_root, NULL, "mti,mips-cm"); + if (cm_node) { + err = of_address_to_resource(cm_node, 0, &res); + of_node_put(cm_node); + if (!err) + gcr_dt = res.start; + } + } else { + of_scan_flat_dt(mips_cm_fdt_scan, &gcr_dt); + } /* Check the CMGCRBase register is implemented */ if (!(read_c0_config() & MIPS_CONF_M)) - return 0; + return gcr_dt; if (!(read_c0_config2() & MIPS_CONF_M)) - return 0; + return gcr_dt; if (!(read_c0_config3() & MIPS_CONF3_CMGCR)) - return 0; + return gcr_dt; /* Read the address from CMGCRBase */ - cmgcr = read_c0_cmgcrbase(); - return (cmgcr & MIPS_CMGCRF_BASE) << (36 - 32); + gcr_reg = read_c0_cmgcrbase(); + gcr_reg = (gcr_reg & MIPS_CMGCRF_BASE) << (36 - 32); + + /* If no of node, return straight away */ + if (!gcr_dt) + return gcr_reg; + + /* If the CMGCRBase mismatches with dt, remap it */ + if (gcr_reg != gcr_dt) { + pr_info("Remapping CMGCRBase from 0x%08lx to 0x%08lx\n", + gcr_reg, gcr_dt); + change_gcr_base(CM_GCR_BASE_GCRBASE, gcr_dt); + } + + return gcr_dt; } phys_addr_t __init __weak mips_cm_l2sync_phys_base(void) -- 2.43.0