From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.13]) (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 94DD772 for ; Mon, 19 Jul 2021 14:02:58 +0000 (UTC) Received: from mail-wm1-f50.google.com ([209.85.128.50]) by mrelayeu.kundenserver.de (mreue108 [213.165.67.113]) with ESMTPSA (Nemesis) id 1MBUyX-1ly5sd2cm7-00CyW3 for ; Mon, 19 Jul 2021 16:02:56 +0200 Received: by mail-wm1-f50.google.com with SMTP id c17so3383342wmb.5 for ; Mon, 19 Jul 2021 07:02:55 -0700 (PDT) X-Gm-Message-State: AOAM533Ui0+YcIxwV9Of5KSzgOM5ZuBVatp2whje1d5s9QxfmvsxPb3q cqdg4AO77Q8wj4mxay2S+NXey7AP61PRSq/VY0s= X-Google-Smtp-Source: ABdhPJwmJd/Ix86WqTyiCFOB9NCP2QcoBq557RPZfJLAlXIsRpRXa6JM8SGYVKJ4v+Uec92ybRvWmJtZ1MHyYBmh9F8= X-Received: by 2002:a1c:4e0c:: with SMTP id g12mr32248772wmh.120.1626703375061; Mon, 19 Jul 2021 07:02:55 -0700 (PDT) Precedence: bulk X-Mailing-List: ksummit@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20210707203827.GI18396@quack2.suse.cz> In-Reply-To: From: Arnd Bergmann Date: Mon, 19 Jul 2021 16:02:38 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [TECH TOPIC] Rust for Linux To: Wedson Almeida Filho Cc: Linus Walleij , Miguel Ojeda , Greg KH , Bartosz Golaszewski , Kees Cook , Jan Kara , James Bottomley , Julia Lawall , Laurent Pinchart , Roland Dreier , ksummit@lists.linux.dev, Viresh Kumar Content-Type: text/plain; charset="UTF-8" X-Provags-ID: V03:K1:EVVPtr/4glnik2SWm4h/T67DPHRselC4eX1M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1PDAt02 kUboYXUVo8RixgJ9ZlxsdwCAieai5dp6anTBTSAHjoh+X66tbdmZBxOleyPP6BZ8WMA7aqlxU oOVb5A8AYQ9eKaReaBNIELnWdooHAUcpk2cUcygwbNEnAc9KxQZmmvaV4BMcfQFwVaDZGe2lV WCeV3Qw4kt9qAOb7u+LuLd85g94XIvdx0pa4wNQyOQtzrwwVeyiCZ On Mon, Jul 19, 2021 at 3:15 PM Wedson Almeida Filho wrote: > On Mon, Jul 19, 2021 at 01:24:49PM +0100, Wedson Almeida Filho wrote: > > On Fri, Jul 09, 2021 at 12:13:25AM +0200, Linus Walleij wrote: > > > I have seen that QEMU has a piece of code for the Arm PrimeCell > > > PL061 GPIO block which corresponds to drivers/gpio/gpio-pl061.c > > > Note that this hardware apart from being used in all Arm reference > > > designs is used on ARMv4T systems that are not supported by > > > LLVM but only GCC, which might complicate things. > > > > Here is a working PL061 driver in Rust (converted form the C one): > > https://raw.githubusercontent.com/wedsonaf/linux/pl061/drivers/gpio/gpio_pl061_rust.rs > > I'm also attaching an html rending of the C and Rust versions side by side where > I try to line the definitions up to make it easier to contrast the two > implementations. Thanks a lot, this looks extremely helpful! I have a couple of questions to understand some of the differences to the C version, and what the reasons are for those: - All the dev_dbg() seem to be replaced with pr_debug!(). Does that mean we lose the information about the device instance in the output, or is that magically added back? - There is a lock of type IrqDisableSpinLock, which sounds like it would correspond to a spinlock_t that is always locked with spin_lock_irqsave(), but the original driver uses raw_spin_lock_irqsave(). Does that mean it won't work on CONFIG_PREEMPT_RT until both types are supported? - What's with all the CamelCase? Is that enforced by the language, or can we use the same identifiers here that we have in the C version? - What is the mechanism behind power::Operations that replaces the #ifdef CONFIG_PM of the C version? Will the rust compiler just drop the dead code when CONFIG_PM is disabled? Arnd