From patchwork Fri Feb 24 10:53:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asahi Lina X-Patchwork-Id: 61255 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp836572wrd; Fri, 24 Feb 2023 03:01:09 -0800 (PST) X-Google-Smtp-Source: AK7set9hfHNsuT8GC0WZJNSIOeMCXoD7wxJH/4nSj1cqnjhgbE188BxUVOjeqJd7/xo6byBm4ZbE X-Received: by 2002:a05:6402:20c:b0:4ab:1d33:69ba with SMTP id t12-20020a056402020c00b004ab1d3369bamr13608604edv.16.1677236468885; Fri, 24 Feb 2023 03:01:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677236468; cv=none; d=google.com; s=arc-20160816; b=my1s3TChG+QKqhofrTSJIkxTgwyMYxDdv27gQwA291ilZ32l9MtUHYAizFmibP1c4v QR9gJE+IWoequymq+ZNN7ch5Z9QShx9fk3s5Ip7/3YrU0ahqdmN/dGiZ1tFMIreVcf18 uiVLobYV/2ydtA8TtvZEQfezvnKSJbGSupV2sXjDc+DVF0m0CdVQnfD4KLEKoZR5epjR k1ObfipLtf0nLQhA6H/E0qcMWB4gfzWKRKq+BfSNOZ8Le6J+Q+En/AZiqRaXOFauaN1U Mb+bnynlTXBA8igVG/i9wYHuNXLnOgAFiElzvLxGoxLu7XLMzlkkh1QUiCHfsX8FAdmc HTDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=E45BpH984Exa0fMcJL/obVfS9/NpUGLW4abDz1Bq+Hg=; b=dvMrkHYGNkjrJx0lR/M5sKaJt97KirG+mbHWwtBFSIEDDDG06zJgK+1W4iwmdQ3Jpw jxOzE9ZPRApeVJZGdZ0sdBghja7+92/J3RSqkjSCNnrWtZD79PDWIjheqv2djwyqOC/0 UE3hmbpC/UfVhR4abyqsWKH/0G5V9pa0V6nWAQI6K6d0uESqZC7tR6HGyLUFEJViz6r0 N5fBHimKTwSK1jLXTMUj6X3zua0HWT81Rp82IHLdXBiLO3rhhSZwPgLAERD7rbsVpUOd GFXiiiz0m72Phd46DXOt5FUAE2pN+WBaKNJ5y+1oQSCBD8bkmZNFr8UmbDZt0sha6TEz efuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@asahilina.net header.s=default header.b=S5GfRRLt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=asahilina.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y25-20020a50e619000000b004aef1b3a863si15019470edm.518.2023.02.24.03.00.44; Fri, 24 Feb 2023 03:01:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@asahilina.net header.s=default header.b=S5GfRRLt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=asahilina.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230148AbjBXKyE (ORCPT + 99 others); Fri, 24 Feb 2023 05:54:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbjBXKyA (ORCPT ); Fri, 24 Feb 2023 05:54:00 -0500 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E7DD149A5; Fri, 24 Feb 2023 02:53:51 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: linasend@asahilina.net) by mail.marcansoft.com (Postfix) with ESMTPSA id C3BF64248B; Fri, 24 Feb 2023 10:53:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=asahilina.net; s=default; t=1677236029; bh=XcpgOxW9xbW5RI+qtCoIK9qZZvy3Hmqang8OrPgwtSc=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=S5GfRRLtjTEa1GDauhqm4LwpVNGK9hwlbYZMDG1ymiXWS62XPbSGKGYfVdiESMhsi oUWZbjIsVtLtdpjnPlNLc77tt5cg+DOJTJpoB3SVHHaCuQoH8yutbwrBHCwUAni2W1 mqtw2lyg9Mt87jqcgmsl1HYvkyr9NBfRbfvZgjxMbTcr393YYR5lLtfwsxo3q3n7pq ++U2vR8szdn9AXLuHQV+Y5Rvt+zp2PfwNt4/xhZjI/W2vjqvDSw+Fg+khrXomc4NsQ 0TGF7QjLUZgLXGpMl/IEJlXXz2yC5DOQ17LEM+bGey75KDq1KQM6dPemGRxock3Wkv rB9HwMDHJCxtg== From: Asahi Lina Date: Fri, 24 Feb 2023 19:53:14 +0900 Subject: [PATCH 2/5] rust: device: Add a minimal RawDevice trait MIME-Version: 1.0 Message-Id: <20230224-rust-iopt-rtkit-v1-2-49ced3391295@asahilina.net> References: <20230224-rust-iopt-rtkit-v1-0-49ced3391295@asahilina.net> In-Reply-To: <20230224-rust-iopt-rtkit-v1-0-49ced3391295@asahilina.net> To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Will Deacon , Robin Murphy , Joerg Roedel , Hector Martin , Sven Peter , Arnd Bergmann , Greg Kroah-Hartman Cc: "Rafael J. Wysocki" , Alyssa Rosenzweig , Neal Gompa , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, asahi@lists.linux.dev, Asahi Lina X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1677236013; l=2542; i=lina@asahilina.net; s=20230221; h=from:subject:message-id; bh=soR466tRTXjasiXIM/nVS1quyj2/l4EZ0DnmL76tJBs=; b=lgy1PZ0uyKdd/tM/G8noK7EaD5kUIHfT1uSUmIXZ1IA3ri0x3dNuPzq/TelJO3hm34TrgUqE9 bNEhHLGfh08CnZPIzu2dvrfFa3L9h2u7tHdI6Yy4lBJWvKiNRcLpm1x X-Developer-Key: i=lina@asahilina.net; a=ed25519; pk=Qn8jZuOtR1m5GaiDfTrAoQ4NE1XoYVZ/wmt5YtXWFC4= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758709907756889089?= X-GMAIL-MSGID: =?utf-8?q?1758709907756889089?= From: Wedson Almeida Filho Add a RawDevice trait which can be implemented by any type representing a device class (such as a PlatformDevice). This is the minimum amount of Device support code required to unblock abstractions that need to take device pointers. Lina: Rewrote commit message, and dropped everything except RawDevice. Co-developed-by: Miguel Ojeda Signed-off-by: Miguel Ojeda Signed-off-by: Wedson Almeida Filho Signed-off-by: Asahi Lina --- rust/bindings/bindings_helper.h | 1 + rust/kernel/device.rs | 23 +++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 3 files changed, 25 insertions(+) diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index 75d85bd6c592..3632a39a28a6 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -6,6 +6,7 @@ * Sorted alphabetically. */ +#include #include #include diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs new file mode 100644 index 000000000000..9be021e393ca --- /dev/null +++ b/rust/kernel/device.rs @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Generic devices that are part of the kernel's driver model. +//! +//! C header: [`include/linux/device.h`](../../../../include/linux/device.h) + +use crate::bindings; + +/// A raw device. +/// +/// # Safety +/// +/// Implementers must ensure that the `*mut device` returned by [`RawDevice::raw_device`] is +/// related to `self`, that is, actions on it will affect `self`. For example, if one calls +/// `get_device`, then the refcount on the device represented by `self` will be incremented. +/// +/// Additionally, implementers must ensure that the device is never renamed. Commit a5462516aa99 +/// ("driver-core: document restrictions on device_rename()") has details on why `device_rename` +/// should not be used. +pub unsafe trait RawDevice { + /// Returns the raw `struct device` related to `self`. + fn raw_device(&self) -> *mut bindings::device; +} diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 82dff6f4cf60..de44092718f8 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -29,6 +29,7 @@ compile_error!("Missing kernel configuration for conditional compilation"); #[cfg(not(testlib))] mod allocator; mod build_assert; +pub mod device; pub mod error; pub mod prelude; pub mod print;