From nobody Fri Nov 29 03:48:20 2024 Received: from mail-il1-f176.google.com (mail-il1-f176.google.com [209.85.166.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF7AA18C006 for ; Thu, 26 Sep 2024 06:55:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727333754; cv=none; b=sC1Jh0MBnEb0rb8h3Tcdd/VlRfd4CFR6dP8SoQmLuRa3QDVvESHUM8nfKqDKapFfMvqiYB8Fxm8jdoYN74dojgwP3K6TekImvYenkvOXWWeXuCXfPKEiJQaNSaD5kTY9Ag8HSXF8p5aiB7VoN6TyzWHlPzbSulZCRv2AEMevQio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727333754; c=relaxed/simple; bh=FBGeqsWhtUXKanzZVpX8tx8GNN2ZBAo6zLyDQdumH5Y=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AWvt1i/Zj/f3HJku1HyT6RuBqSKU1eLHvu202rs/oLJ5VrVsQELzeTWV2heBGy4VTltiDpRv1Q41OtItKA9xSndHeIGMBdgduNECxjUvjBt4gp/z0FYXC2UDs4N5at2AZa+JO4486U+our/ufpODlnOyZquOmvuJSOUGKTea/PM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=BC/yuJOI; arc=none smtp.client-ip=209.85.166.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="BC/yuJOI" Received: by mail-il1-f176.google.com with SMTP id e9e14a558f8ab-3a056727fdfso2582185ab.3 for ; Wed, 25 Sep 2024 23:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1727333752; x=1727938552; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=dz6nXOQPpHKKg/2POW9sH3ldlFQk4LGlQ9pIvX2kgEo=; b=BC/yuJOI/LdgNCbiAaFwxIatqiKzv1jzovilRe5+LrbqAv+8Rg99WcXpfSerVFm3rE 2L+PiMI79BZU5XNE0GGGSy32xvUp1CbT82/XF07jKd7JaVV3OPs8uCUv0Ntr0yhfcCKU umLqT//XCZYF56KGffTtvdEzFsUnBAiYuvQj1z8Sdv5ykMf/rtyP1LuN5b5+cWBkpMZm LyFfiytW6gR49TARKGSRJBs2IsKuJjdv3kSmR0B64vDLDQOX97B2qJn/VqVe4H9sFEY3 4fTwFQVJycQwwzKzLxHJ4Vy/uN6sZWIrHuI+0nsIl30PA35piKJTFah+IhGvgmdrooCK Z55w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727333752; x=1727938552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dz6nXOQPpHKKg/2POW9sH3ldlFQk4LGlQ9pIvX2kgEo=; b=gZ90Jg9rX+QeFuehiBLYY9LEvkDL8eLYh7thPpOEsHdJb3+4FASiEFgg3lkZvW6mKX wByD9jO4jrq7WJs9IU0od2huNea2B4gf1ylY+CJaTWvwO89KRc6j3+sWePz8GGuBCfpd p5H7Ln3sJesiT6Kl2tlV8gIR/FBHhIAe7iXukvkNNY1M3XflUW7jDgCPFs8mmE+DWl4e go0wgp+xON7dGOmmEHe/qcWm5YlwJq2KZHuSghjSqxdCqKkahWL7QXgsa5UBwuaRxq4W 1wEi3YKfMaat/45eudnCGxPIt2bLhOPn5PQsR//aannLq6N9ya3irtj8vpTt37fXRWzF 3gRg== X-Forwarded-Encrypted: i=1; AJvYcCXopPdSi0C1ranvnlCFACKeTfn1fLc5IMuHwyxOm4tvCQdDCDAWJf/Bw8AismT5Kzn+XuSbEE+QfFUwVQA=@vger.kernel.org X-Gm-Message-State: AOJu0YzrVJHh56VMtzRvl4qy6uR+ND4Zn1AibR6j+hfx7sQOX/CS1pkG UZNEoShZs+sE1d4dc/wDZqKlF23UrPPPTGTpUBaOSBqeRYAuY06UMlson7I9iKI= X-Google-Smtp-Source: AGHT+IE5HtHveKKLfQie2ZdRESQAIt2gsyCcJcr3zDTArzQG0bYH4n5mBiG2zxUxyKL4arsG6HYvQg== X-Received: by 2002:a05:6e02:1fee:b0:3a0:9ed2:67b8 with SMTP id e9e14a558f8ab-3a26d6fc9a9mr60527305ab.4.1727333751901; Wed, 25 Sep 2024 23:55:51 -0700 (PDT) Received: from hsinchu35-syssw01.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e6b7c73120sm3592352a12.68.2024.09.25.23.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 23:55:51 -0700 (PDT) From: Nick Hu To: greentime.hu@sifive.com, zong.li@sifive.com, Paul Walmsley , Palmer Dabbelt , Albert Ou , "Rafael J. Wysocki" , Pavel Machek , Daniel Lezcano , Thomas Gleixner , Anup Patel , Andrew Jones , Mayuresh Chitale , Conor Dooley , Atish Patra , Samuel Ortiz , Samuel Holland , Nick Hu , Sunil V L , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v2 1/3] riscv: Add csr_read/write_hi_lo support Date: Thu, 26 Sep 2024 14:54:16 +0800 Message-Id: <20240926065422.226518-2-nick.hu@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240926065422.226518-1-nick.hu@sifive.com> References: <20240926065422.226518-1-nick.hu@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In RV32, we may have the need to read both low 32 bit and high 32 bit of the CSR. Therefore adding the csr_read_hi_lo() and csr_write_hi_lo() to support such case. Suggested-by: Andrew Jones Suggested-by: Zong Li Signed-off-by: Nick Hu --- arch/riscv/include/asm/csr.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 25966995da04..54198284eb22 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -501,6 +501,17 @@ __v; \ }) =20 +#if __riscv_xlen < 64 +#define csr_read_hi_lo(csr) \ +({ \ + u32 hi =3D csr_read(csr##H); \ + u32 lo =3D csr_read(csr); \ + lo | ((u64)hi << 32); \ +}) +#else +#define csr_read_hi_lo csr_read +#endif + #define csr_write(csr, val) \ ({ \ unsigned long __v =3D (unsigned long)(val); \ @@ -509,6 +520,17 @@ : "memory"); \ }) =20 +#if __riscv_xlen < 64 +#define csr_write_hi_lo(csr, val) \ +({ \ + u64 _v =3D (u64)(val); \ + csr_write(csr##H, (_v) >> 32); \ + csr_write(csr, (_v)); \ +}) +#else +#define csr_write_hi_lo csr_write +#endif + #define csr_read_set(csr, val) \ ({ \ unsigned long __v =3D (unsigned long)(val); \ --=20 2.34.1