From patchwork Thu Feb 1 18:06:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christina Quast X-Patchwork-Id: 195428 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp346591dyb; Thu, 1 Feb 2024 10:12:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IEyrrgh9sj9JuxDHhtMhEsJv/ccCfTUzkBWfxhtfpT0urn/C5XYUMlRkTBhWsLSTxfvOfQn X-Received: by 2002:ac8:5a0f:0:b0:42b:ecc3:d1ab with SMTP id n15-20020ac85a0f000000b0042becc3d1abmr5802691qta.5.1706811127909; Thu, 01 Feb 2024 10:12:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706811127; cv=pass; d=google.com; s=arc-20160816; b=PUZ0c8N6xF3ZWZLO1rlbVhuuLTHAwvyDbQcScp/YtGoaoZRhGvM3WxxExynhNtfRxQ XZu61Ed/VnJS50Rn7OoVkiCuxfzv3/QLMpC8b0jya/FmNoHJZabowZ5SOJ5KCqW3N9YH ro5T1wq4hL17u5Pa7pQ3v2g7NXe1rSo4A47xuykUtZwFM42aVqSCy4CBXUGSOWOuggHx bbntJQNUT0/cvglSNYgcr7Zt6qIK/jEPxjSwKG24J2hXRy/WgMKlkRacfXR2fpWLizat Upz+0cUaa+KNH3mbWIEuHTxBrnmEbMjXUtda/hZdoUaY0M5j20eEed3fcMLLrZgzEzKd XqAA== 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; bh=/BU9D4HcvXvKXNPcylF3xNxeKcyxIj1bNUEaYf083ys=; fh=4Vwmn140VMLDgEMVFAb7YMHzFEKwV3CzIzI+hKY4E4Y=; b=YCtws1dW62DwCQEhsGCOycAKZh54ladaoTzENIqNcc14mXnpgUN8XJih/N2oZ+wNTJ kKjSHq3y0kOcf13jnFOatz2cS3F9GW1fonswY/IFzAQ0Ybt2/J3X1hewBcepZXMAWXhV 2PvD73/+qzwWM0s7akyl5/UOjEHA0HK2qYv25/BeBoI8FIljHNOr+PohxiPx0VPXfLEl n/7tijqrArknUGfiUYa+Diax4FjfjkiT6ZLVOVoYNBLtl3xMbGR02s6Uom+4lDfA2CQy x26I0wrJtbDWacYuZDAf9w9n8SfKi+n/Kn6VsQ9C7VjLeGAdFhT0wVUW4/BFcUHIkA6C iA9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=christina-quast.de); spf=pass (google.com: domain of linux-kernel+bounces-48662-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48662-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUQkFkmFAvkfxFuCMtGFeeECZxHtvt544UHuFAG14YVG4NG4OV74OV20cBeWpjQWLtNX1a2j/2n69KcCaF3yl6iuZO2PA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o12-20020ac87c4c000000b0042be8dbb129si27038qtv.166.2024.02.01.10.12.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 10:12:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48662-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=christina-quast.de); spf=pass (google.com: domain of linux-kernel+bounces-48662-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48662-ouuuleilei=gmail.com@vger.kernel.org" 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 D56A91C29F0C for ; Thu, 1 Feb 2024 18:11:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D408B12E1DB; Thu, 1 Feb 2024 18:07:20 +0000 (UTC) Received: from mail.someserver.de (mail.someserver.de [116.202.193.223]) (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 8050884FC5; Thu, 1 Feb 2024 18:07:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.202.193.223 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706810839; cv=none; b=lhmOxoCR6j9xG30P71NDE43OYBogv2Sahw1MOflrNVBGKJdHjP9u/7HaCQB40l1wMp4f/eEel5S2anzX3vgJJlwUwB8HnJh0nRBNUOsU7Soun0NS2sO2N5JALXZEdz8gayxJEcsFv9QZ+tQAjVF6aHOGJ/vYimuKbflChKlQsqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706810839; c=relaxed/simple; bh=I9yo8gFF9g6Nktp5khK01f/99bXfCpCeui/xCrTFEX0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jaeqw0/DX8LyMACjAD6mrdbcIz4pYRKBWCFCG3ZBMpXtzxZ9FtnUyN2ofn6v7Q3NXiKnBrpozmsSo97HYZF5ECKasOAPURAIUCzpbLqGmW400oBpq8qj55DrKRWncVNAg6px67UKO37LRd50tBJQ/Lw6C6KzLMagDv0SnbtIRkw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=christina-quast.de; spf=pass smtp.mailfrom=christina-quast.de; arc=none smtp.client-ip=116.202.193.223 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=christina-quast.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=christina-quast.de Received: from localhost (unknown [195.162.191.218]) by mail.someserver.de (Postfix) with ESMTPSA id 2965DA21AE; Thu, 1 Feb 2024 19:07:13 +0100 (CET) From: Christina Quast Date: Thu, 01 Feb 2024 19:06:58 +0100 Subject: [PATCH v2 1/3] DONOTMERGE: rust: prelude: add bit function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240201-rockchip-rust-phy_depend-v2-1-c5fa4faab924@christina-quast.de> References: <20240201-rockchip-rust-phy_depend-v2-0-c5fa4faab924@christina-quast.de> In-Reply-To: <20240201-rockchip-rust-phy_depend-v2-0-c5fa4faab924@christina-quast.de> To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , FUJITA Tomonori , Trevor Gross , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiko Stuebner Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, Christina Quast X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706810819; l=1166; i=contact@christina-quast.de; s=20240130; h=from:subject:message-id; bh=I9yo8gFF9g6Nktp5khK01f/99bXfCpCeui/xCrTFEX0=; b=PD/auZkWvS/a6RAELm9LZMt+cqhgGaqOca8QQUD5tdAWmf0dbh8OFZXYaJmqZgB58v2xzsXPY 6aq5k52d6jBD1X+2SRUI45jUSSAeNaaKZovXt/2kXeZa7O2MuqHekKw X-Developer-Key: i=contact@christina-quast.de; a=ed25519; pk=aoQfinjbnr265vCkIZdYteLDcmIqLBhY1m74WfFUU9E= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789721185352118387 X-GMAIL-MSGID: 1789721185352118387 In order to create masks easily, the define BIT() is used in C code. This commit adds the same functionality to the rust kernel. Do not merge this commit, because rust/kernel/types.rs in Rust-for-Linux already contains this functionality and will be merged into next-net soon. But this driver does not compile without this commit, so I am adding it to the patchset to get more feedback on the actual driver. Signed-off-by: Christina Quast --- rust/kernel/prelude.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rust/kernel/prelude.rs b/rust/kernel/prelude.rs index ae21600970b3..16e483de2f27 100644 --- a/rust/kernel/prelude.rs +++ b/rust/kernel/prelude.rs @@ -38,3 +38,19 @@ pub use super::init::{InPlaceInit, Init, PinInit}; pub use super::current; + +/// Returns a `u32` number that has only the `n`th bit set. +/// +/// # Arguments +/// +/// * `n` - A `u32` that specifies the bit position (zero-based index) +/// +/// # Example +/// +/// ``` +/// let b = bit(2); +/// assert_eq!(b, 4); +#[inline] +pub const fn bit(n: u32) -> u32 { + 1 << n +}