Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp969158rdh; Fri, 27 Oct 2023 00:17:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4EA4t/u9XrfsKDoMkkpTDPMHGczZbFjT/J0tT2QrRhVbOPlvaTiF6gGoUef25pGowD5F8 X-Received: by 2002:a81:c40d:0:b0:59f:4dcd:227e with SMTP id j13-20020a81c40d000000b0059f4dcd227emr1727931ywi.37.1698391045611; Fri, 27 Oct 2023 00:17:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698391045; cv=none; d=google.com; s=arc-20160816; b=IohwBb1JEkCIUe4nXko9/9Us9gz5sbxMQGC9/UEfejhHqe2YWjs8aX9ZPzVf89QG8a 4QaZCSFxclYV1Oab776fuxpPk/p5I6H9MgycpACsk4at7w0nRT+mbXb2gJMw5gAAd0MI OrZFeuRPBKCF8vTUz9mehqCetd6wNjNkSrt7hxpruezE/k4btkpuTzrZaHUgjpHXX7Cg dpKGfW1FpWwaP2JSlYAmC5ulWIFpOq44dobwyla68hJL6/Ei1uzBDIR7pWmBI5HUUqck NeLGQxCi45wnijfn/JH0WgV2410udWNFrKJw7Ged7wVYTrfLqGOIXB5dfC+Jw+NJYkod KzUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=tJqDwcTQgMk+8cL2hq8yzf1I071r2qr1bFh2PkN2FOQ=; fh=f7GKBAgWGbIXWfpm5FPyVMSxRMA3MbLHsqKCIb9iy2s=; b=Xq8tPbj0ymvyI9oLYO7NxN7KhuM6624zN59EAGYISFZBr0xrdCHI3KyIcxJKOogq6b WyDR70HeU5p1XCiXUKmHcXcvzwqkMPI38LQZU4qqJOccwQyXxThpDGR5qdJE4R/ZbKUg epvP42/0ez/tJxLnfqlXmWMhzflUVc+2RHcUiSO8pJBmZRZM3R2GQhUVAkkvXOloWbbX n/VoOnQu8xSpUkvHilm8a097tlJCroQH+rliS7eH1QbWttKFWpYiXOaWHPnyLSuXR9uq WqOvnDFzMin5SlXv/BjfzzVCA8azqB6Kxl/dpkA+3CmO86aG3TOPZTsNvhFeuzs+ceGL WCwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QznlPtY7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l5-20020a819405000000b005a813e6088bsi1710066ywg.218.2023.10.27.00.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 00:17:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QznlPtY7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2EBCD806666B; Fri, 27 Oct 2023 00:15:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345331AbjJ0HPt (ORCPT + 99 others); Fri, 27 Oct 2023 03:15:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbjJ0HPr (ORCPT ); Fri, 27 Oct 2023 03:15:47 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40D0D1B3; Fri, 27 Oct 2023 00:15:45 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3976EC433C7; Fri, 27 Oct 2023 07:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1698390944; bh=WRMtuzaQ5PUuBaVeb+CCbcTOs/PXWi9a2Kg5e5ysQ28=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QznlPtY7/rsFqZerrMxGqhj07IDXB0gQ2kx78eV+o03hNDPhH//rDL5hgmB6epPUT tMu2S+7Z+kkWF/PcWnO6/CVPNPAh6W7Aw6xbe9V2Vf8ZevqsLDkidBo9bhKsb7rgAj CkwF3dS8o7zBxn/llqF6PwXM8xv5gGZz3CPb5KnY= Date: Fri, 27 Oct 2023 09:15:41 +0200 From: Greg Kroah-Hartman To: Martin Rodriguez Reboredo Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: Re: [RFC PATCH v2 2/2] samples: rust: Add USB sample bindings Message-ID: <2023102737-juniper-trodden-afb4@gregkh> References: <20231027003504.146703-1-yakoyoku@gmail.com> <20231027003504.146703-3-yakoyoku@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231027003504.146703-3-yakoyoku@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 27 Oct 2023 00:15:56 -0700 (PDT) On Thu, Oct 26, 2023 at 09:34:51PM -0300, Martin Rodriguez Reboredo wrote: > This is a demonstration of the capabilities of doing bindings with > subsystems that may or may not be statically linked. > > Signed-off-by: Martin Rodriguez Reboredo > --- > drivers/usb/core/Kconfig | 7 +++++++ > drivers/usb/core/Makefile | 3 +++ > drivers/usb/core/usb.rs | 13 +++++++++++++ > samples/rust/Kconfig | 10 ++++++++++ > samples/rust/Makefile | 3 +++ > samples/rust/rust_usb_simple.rs | 22 ++++++++++++++++++++++ > 6 files changed, 58 insertions(+) > create mode 100644 drivers/usb/core/usb.rs > create mode 100644 samples/rust/rust_usb_simple.rs > > diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig > index 351ede4b5de2..4b5604282129 100644 > --- a/drivers/usb/core/Kconfig > +++ b/drivers/usb/core/Kconfig > @@ -116,3 +116,10 @@ config USB_AUTOSUSPEND_DELAY > The default value Linux has always had is 2 seconds. Change > this value if you want a different delay and cannot modify > the command line or module parameter. > + > +config USB_RUST > + bool "Rust USB bindings" > + depends on USB && RUST > + default n Nit, "n" is the default, this line is not needed. Also, if you want to get really picky, _which_ USB is this for, the "host" apis (you plug a USB device into a Linux maching), or the "gadget" apis (i.e. Linux is running in the device that you plug into a USB host)? Linux supports both :) > + help > + Enables Rust bindings for USB. > diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile > index 7d338e9c0657..00e116913591 100644 > --- a/drivers/usb/core/Makefile > +++ b/drivers/usb/core/Makefile > @@ -11,6 +11,7 @@ usbcore-y += phy.o port.o > usbcore-$(CONFIG_OF) += of.o > usbcore-$(CONFIG_USB_PCI) += hcd-pci.o > usbcore-$(CONFIG_ACPI) += usb-acpi.o > +usbcore-$(CONFIG_USB_RUST) += libusb.rlib > > ifdef CONFIG_USB_ONBOARD_HUB > usbcore-y += ../misc/onboard_usb_hub_pdevs.o > @@ -18,4 +19,6 @@ endif > > obj-$(CONFIG_USB) += usbcore.o > > +rust-libs := ./usb > + > obj-$(CONFIG_USB_LEDS_TRIGGER_USBPORT) += ledtrig-usbport.o > diff --git a/drivers/usb/core/usb.rs b/drivers/usb/core/usb.rs > new file mode 100644 > index 000000000000..3f7ad02153f5 > --- /dev/null > +++ b/drivers/usb/core/usb.rs > @@ -0,0 +1,13 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +//! USB devices and drivers. > +//! > +//! C header: [`include/linux/usb.h`](../../../../include/linux/usb.h) > + > +use kernel::bindings; > + > +/// Check if USB is disabled. > +pub fn disabled() -> bool { > + // SAFETY: FFI call. > + unsafe { bindings::usb_disabled() != 0 } > +} > diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig > index b0f74a81c8f9..12116f6fb526 100644 > --- a/samples/rust/Kconfig > +++ b/samples/rust/Kconfig > @@ -30,6 +30,16 @@ config SAMPLE_RUST_PRINT > > If unsure, say N. > > +config SAMPLE_RUST_USB_SIMPLE > + tristate "USB simple device driver" > + help > + This option builds the Rust USB simple driver sample. > + > + To compile this as a module, choose M here: > + the module will be called rust_usb_simple. > + > + If unsure, say N. > + > config SAMPLE_RUST_HOSTPROGS > bool "Host programs" > help > diff --git a/samples/rust/Makefile b/samples/rust/Makefile > index 03086dabbea4..f1ab58a9ecdd 100644 > --- a/samples/rust/Makefile > +++ b/samples/rust/Makefile > @@ -2,5 +2,8 @@ > > obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o > obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o > +obj-$(CONFIG_SAMPLE_RUST_USB_SIMPLE) += rust_usb_simple.o > + > +rust-libs := ../../drivers/usb/core/usb > > subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs > diff --git a/samples/rust/rust_usb_simple.rs b/samples/rust/rust_usb_simple.rs > new file mode 100644 > index 000000000000..3523f81d5eb8 > --- /dev/null > +++ b/samples/rust/rust_usb_simple.rs > @@ -0,0 +1,22 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +//! Rust USB sample. > + > +use kernel::prelude::*; > + > +module! { > + type: UsbSimple, > + name: "rust_usb_simple", > + author: "Martin Rodriguez Reboredo", > + description: "Rust USB sample", > + license: "GPL v2", > +} > + > +struct UsbSimple; "USBSimple" please. > + > +impl kernel::Module for UsbSimple { > + fn init(_module: &'static ThisModule) -> Result { > + pr_info!("usb enabled: {}", !usb::disabled()); > + Ok(UsbSimple) > + } > +} I know this is just a fake patch to test the bindings logic, so sorry for the noise, just wanted to get terminology right :) thanks, greg k-h