From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vk1-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) (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 168BC70 for ; Mon, 19 Jul 2021 14:43:55 +0000 (UTC) Received: by mail-vk1-f172.google.com with SMTP id v186so930453vka.1 for ; Mon, 19 Jul 2021 07:43:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bDHuFf1m+i9+b73oV/Y5Nwf3Lv/igjDC49HnQ48OWvw=; b=B5/KFrzP7EgAa8a5tWaJgXPu/+yILnU5a9ntMT+6OYXob7aHUvdAekZgJCDxaWisgP TYJnNaYgcTsGoFmQ1decbPkro0lZwg9ptBqOL/7qyV3nJopy7TsQvvriwuiMIQ8MPA2F sjYzvNpXJjGkyjVmWWYdKrWEaM7yhenbrmy7IyRNCpKtvlwWlAwcIn9A/O6OC4tnDICy timqBhCsC3aFLs5+PWXM4hehBPaF+xamviR3gN/VMDesZT+a+oJxGmHwyupHvNPTUOI1 sr0y3P3DvxinyKbvshdRNneAJszoDoYEWMbLCxhVcBVxaONnoBjJx5+fL9XjMv6T8Z1k lfwQ== X-Gm-Message-State: AOAM531MHmHWuz+WNmZukaUE5PJyYzzAc0LHI99htVHaNIKMROxKdmLH +TPOdKek81peqv/utLC5RcRsCxFQHwx8ritq2ug= X-Google-Smtp-Source: ABdhPJzN74MSasdcAmCm7e9mB9oE6yfsCwpzHFTxgRu/64cSX37rkV/k372cdl8lgtqcYfCN42f1zq17ZFiep2jgFLY= X-Received: by 2002:a05:6122:a12:: with SMTP id 18mr22377379vkn.1.1626705833205; Mon, 19 Jul 2021 07:43:53 -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: Geert Uytterhoeven Date: Mon, 19 Jul 2021 16:43:41 +0200 Message-ID: Subject: Re: [TECH TOPIC] Rust for Linux To: Arnd Bergmann Cc: Wedson Almeida Filho , 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" On Mon, Jul 19, 2021 at 4:03 PM Arnd Bergmann wrote: > 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! +1 For a moment I thought I found an off-by-one bug: for offset in 0..PL061_GPIO_NR { if pending & bit(offset) != 0 { router.deliver(offset.into()); } } Turns out "a..b" in Rust does mean "range from a to b-1". That's gonna be hard to (un)learn... https://doc.rust-lang.org/reference/expressions/range-expr.html Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds