From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 63B083A1E7F for ; Sun, 21 Dec 2025 09:19:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766308759; cv=none; b=Gx2LvpAM7TIkY+e8iJBisUOh4O1V8oQtvAH9MfGKwvXiG4FiFf65suOtP/DXiKK+IMUngeKqpyqXDbGnmkdrK6xXsqA2nTY8/cJ9aHJ9GWmz9rTqPeIFgOaJ9v2m3Adu7DwB11Tgoo2brBYxyu9kP3tcp+HEah4H18F0Bh0EuRM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766308759; c=relaxed/simple; bh=eqlkQJRKqtMXVBqn3VqjTrRNC3dJwL/DIWa+q2BpyEE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VIoSWqE8AoRwf6kwzfdu5HJsh0bdvg3YsP6K85h4yUe5lRDMVE64BKK5W4lvP55Tfa7lxPISThiENxPxYeMaEdvi9cof8y/eZ+sx/aEB5bw9G98Tnqkqoyvf4ulkFtYrAWvT02SMeu4wQghftGuv4TOew69nvvO7cdOi4hiu4Yk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nfungn1d; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nfungn1d" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-47a95efd2ceso26465085e9.2 for ; Sun, 21 Dec 2025 01:19:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766308756; x=1766913556; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=jVxQ7m55+e7xHSmDYkZzWySVBucnYtEFV6uMMTNQV4s=; b=nfungn1d3c45/tiMnDaneo84S1c++KsDtsW9v5I9enmkWUysc+hel6YCets78c1aD/ bJvs/BLmA+Vsv5Bwq9UZOowRG1gwAkFnZv88Hm75tO1KGuUysbPBrEIAMet/+zfspsri IOTZ/BOFNhcJSXJTPNpp5a7PnMad41IJfIsjMuBX29dsoJaEu4TY33rW1ozTMZq2y7QQ 3FV7GjvaqfFNmxmk3YLunied4VFkIPDnjNHk+yulWqc2gvLtHnB4MJZnU1kzVs+vddYK zUMCZ0cOQ4iJpjvfGGyugNyLTxGAs3cRQg59qQeQO0cGqp3EBwdWRYNBjMmFZFfw/fZr k0kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766308756; x=1766913556; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jVxQ7m55+e7xHSmDYkZzWySVBucnYtEFV6uMMTNQV4s=; b=OI5mT+g31qmtZxNvcWuhIsMVtJzXieJzoQVHQIG69T9pvyGKDIaBMnrQlEzotqaPlT BblKMtS7cuHFxPGsBvqSL5E5q1jvUoIeccErV1O09nvwTUdwLHhMszw+UOc16PCbf4sj nWiwTwB/xpTfS6RZGw1m4LKArtGUEGUzI5o4uNX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Q== X-Received: by 2002:a05:600c:858e:b0:46f:c55a:5a8d with SMTP id 5b1f17b1804b1-47d1c629902mr58448525e9.4.1766308755542; Sun, 21 Dec 2025 01:19:15 -0800 (PST) Received: from ?IPV6:2003:df:bf2d:e300:9f8f:28b1:4136:8493? (p200300dfbf2de3009f8f28b141368493.dip0.t-ipconnect.de. [2003:df:bf2d:e300:9f8f:28b1:4136:8493]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47d19346d33sm135746565e9.3.2025.12.21.01.19.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Dec 2025 01:19:14 -0800 (PST) Message-ID: <4c26408c-b8ce-42a6-b0df-47053fd81eda@gmail.com> Date: Sun, 21 Dec 2025 10:19:11 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 2/4] rust: add basic serial device bus abstractions To: Markus Probst , Rob Herring , Greg Kroah-Hartman , Jiri Slaby , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Kari Argillander Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org References: <20251220-rust_serdev-v1-0-e44645767621@posteo.de> <20251220-rust_serdev-v1-2-e44645767621@posteo.de> Content-Language: de-AT-frami From: Dirk Behme In-Reply-To: <20251220-rust_serdev-v1-2-e44645767621@posteo.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Markus, On 20.12.25 19:44, Markus Probst wrote: > Implement the basic serial device bus abstractions required to write a > serial device bus device driver with or without the need for initial device > data. This includes the following data structures: > > The `serdev::Driver` trait represents the interface to the driver. > > The `serdev::Device` abstraction represents a `struct serdev_device`. > > In order to provide the Serdev specific parts to a generic > `driver::Registration` the `driver::RegistrationOps` trait is > implemented by `serdev::Adapter`. > > Co-developed-by: Kari Argillander > Signed-off-by: Kari Argillander > Signed-off-by: Markus Probst > --- > rust/bindings/bindings_helper.h | 1 + > rust/helpers/helpers.c | 1 + > rust/helpers/serdev.c | 22 ++ > rust/kernel/lib.rs | 2 + > rust/kernel/serdev.rs | 815 ++++++++++++++++++++++++++++++++++++++++ > 5 files changed, 841 insertions(+) > ... > diff --git a/rust/kernel/serdev.rs b/rust/kernel/serdev.rs > new file mode 100644 > index 000000000000..0f5ef325a054 > --- /dev/null > +++ b/rust/kernel/serdev.rs .... > + /// Write data to the serial device until the controller has accepted all the data or has > + /// been interrupted by a timeout or signal. > + /// > + /// Note that any accepted data has only been buffered by the controller. Use > + /// [ Device::wait_until_sent`] to make sure the controller write buffer has actually been > + /// emptied. > + /// > + /// Returns the number of bytes written (less than data if interrupted). Should it be "less than data.len"? Instead of just "data"? Same in the comment for `write()`below. > + /// [`kernel::error::code::ETIMEDOUT`] or [`kernel::error::code::ERESTARTSYS`] if interrupted > + /// before any bytes were written. > + pub fn write_all(&self, data: &[u8], timeout: Timeout) -> Result { > + // SAFETY: > + // - `self.as_raw()` is guaranteed to be a pointer to a valid `serdev_device`. > + // - `data.as_ptr()` is guaranteed to be a valid array pointer with the size of > + // `data.len()`. > + let ret = unsafe { > + bindings::serdev_device_write( > + self.as_raw(), > + data.as_ptr(), > + data.len(), > + timeout.into_jiffies(), > + ) > + }; > + if ret < 0 { > + // CAST: negative return values are guaranteed to be between `-MAX_ERRNO` and `-1`, > + // which always fit into a `i32`. > + Err(Error::from_errno(ret as i32)) > + } else { > + Ok(ret.unsigned_abs()) > + } > + } > + > + /// Write data to the serial device. > + /// > + /// If you want to write until the controller has accepted all the data, use > + /// [`Device::write_all`]. > + /// > + /// Note that any accepted data has only been buffered by the controller. Use > + /// [ Device::wait_until_sent`] to make sure the controller write buffer has actually been > + /// emptied. > + /// > + /// Returns the number of bytes written (less than data if interrupted). > + /// [`kernel::error::code::ETIMEDOUT`] or [`kernel::error::code::ERESTARTSYS`] if interrupted > + /// before any bytes were written. > + pub fn write(&self, data: &[u8]) -> Result { > + // SAFETY: > + // - `self.as_raw()` is guaranteed to be a pointer to a valid `serdev_device`. > + // - `data.as_ptr()` is guaranteed to be a valid array pointer with the size of > + // `data.len()`. > + let ret = > + unsafe { bindings::serdev_device_write_buf(self.as_raw(), data.as_ptr(), data.len()) }; > + if ret < 0 { > + Err(Error::from_errno(ret)) > + } else { > + Ok(ret.unsigned_abs()) > + } > + } Best regards Dirk