From patchwork Tue Jan 30 19:47:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christina Quast X-Patchwork-Id: 194310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1460958dyb; Tue, 30 Jan 2024 11:55:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHucztIuyj4f00WZeIcBg2ZpwpV2HOY9RpO2JDNGaxP2F7BIgV2zhU3lUToLCwCFfH69n7i X-Received: by 2002:a05:6a00:1798:b0:6db:d5b5:e380 with SMTP id s24-20020a056a00179800b006dbd5b5e380mr7575403pfg.24.1706644511832; Tue, 30 Jan 2024 11:55:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706644511; cv=pass; d=google.com; s=arc-20160816; b=Q906iEnXUcbyKys2zGfRibMEBWtATXGQ1KoLtHznn4AwVKq/2Sw9deqpiGtH27/fYn lNQZFQHhGp1+YdAX++gJRiGp37HsgFfQNICOmcxIe7VjktIQUU5lpKezD6zS6xRDlASS yLo82F2KOZzXzVc7dBDZxwc+klh/MBmqir8PXWy2ub3eBh810sX4KAgSNXNxitsb44xy uyH/S+jQ4dyLopFOIDlwCbbkHyKaTKvV5q0s8C3Epq1A+j9XghIV+lXoFGavBhHbvBzm Ne0o8uNq/hyO2G7+m1BxVlkgGSBQQRZs3DH1eWa+97HbQzDx8BNFlLLto79Vzjl9+28T LgSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from; bh=0ADVgV0W2qr4/2M8YAKPNuJ/PmdJI1oDioLd2H2CEhs=; fh=hUsCs6AAE1rR6UueQu8Ky7Vz1eqbksdHYaZcO+jXHjI=; b=F5LToZ9hU966tpcfvZcMjqXOZY5fgsRF3Ri9acAzDue8zb7cJIXGcj0qXUtqeQfGVF dBbjlRUcotZ0zKnkGvfor5YgT48N9mzUB2kMDMbsZQYyhC/9QIcxUzoEunG34c0MAQ0Z 5QYXuCDVpZBDuUpY7a2cRlDcJVBfH17FI4lS1BK2+B1Q6vpOEslMfgTq+oBCoK/lCCzv kQyd4njHPrR+PpDjdRxNo/ok09MNRrEMoykLE1pX45PgzyI+zfkfFSX2fQUTmWwTCZ7g 9RSAd3Hu7I7plGwo33vHN7s5/8wZSsNuHa+/gS7sSsHZ5fQ8JOJG3drptWvLscISTBM/ BQAw== 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-45225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45225-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id du2-20020a056a002b4200b006dadc44566bsi7954567pfb.58.2024.01.30.11.55.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 11:55:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-45225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45225-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 90E8D28816B for ; Tue, 30 Jan 2024 19:55:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 69DD371B45; Tue, 30 Jan 2024 19:54:51 +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 CAB4869D36; Tue, 30 Jan 2024 19:54:46 +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=1706644489; cv=none; b=SZrcNhMEbtnW3wQkC+WCFuHDDo7PkyoC0e2eRu7q0AUyliwd49mTqz4JQy/3nlVTIUhWjbWPCH7nFpyCB+5Z7SGTUAmCTHUt9kuGcNvlN2PftyC3DPcbjS/rHAvIF67YtVBLLEYdpcF3z/eFzVWDde9D0OGIM7MToTYcMCYW8bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706644489; c=relaxed/simple; bh=xgl3MC3s1y+/xuGn3VPAMSHRrzUBbY9DHF1bmTq1orY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=C94QUUE5DzNl4R2tzPv6/+R5lzdJelKEGFKFod5QIj4m1kABJ0hz0TBcG1vtcISMwcNPBzvNRJb+07/DOehgj1jFZOBU5GtDjVG9e0URGHHWVUhON95e8OBbBLZ2zGq7uLslOps/AAFV7wgWuF9mQ+s4o6zYzn2+FDlv7CsTIxw= 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 AC348A2194; Tue, 30 Jan 2024 20:48:00 +0100 (CET) From: Christina Quast Date: Tue, 30 Jan 2024 20:47:51 +0100 Subject: [PATCH] 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: <20240130-rust-bit-v1-1-ed2ed6389a58@christina-quast.de> X-B4-Tracking: v=1; b=H4sIAGZSuWUC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDQ2MD3aLS4hLdpMwSXUvLlBSzFONEA1NjMyWg8oKi1LTMCrBR0bG1tQD yELu2WgAAAA== 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 Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Christina Quast X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706644076; l=1210; i=contact@christina-quast.de; s=20240130; h=from:subject:message-id; bh=xgl3MC3s1y+/xuGn3VPAMSHRrzUBbY9DHF1bmTq1orY=; b=IHKGeUwSlFiuDYNIGEj+pe7lXU8/JC4z+PlzeygWkPNGUN6EbHVPeknbOQfa0VAhLSpY85+Pq jeN5dZXFEzADtKZ73EE41EokaLOnYmLWM/7L6Fez0t3E5YP0i9LR9MK X-Developer-Key: i=contact@christina-quast.de; a=ed25519; pk=aoQfinjbnr265vCkIZdYteLDcmIqLBhY1m74WfFUU9E= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789546475580402759 X-GMAIL-MSGID: 1789546475580402759 In order to create masks easily, the define BIT() is used in C code. This commit adds the same functionality to the rust kernel. To use it, include the following into your rust file: use kernel::prelude::bit Signed-off-by: Christina Quast Reviewed-by: Carlos Bilbao --- This patch is needed for further patches porting the rockchip phy driver to rust. --- rust/kernel/prelude.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) --- base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d change-id: 20240130-rust-bit-99dd6d3a0536 Best regards, 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 +}