From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from vps0.lunn.ch (vps0.lunn.ch [185.16.172.187]) (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 1FB0E70 for ; Mon, 19 Jul 2021 15:48:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=lz57vbxJlpyr7PWU7WoUY9IjTJ6kwb0zylXx9DVOaJc=; b=wUP+z7WekgrovzNdVPrz5g696S KlnsGN0ymVMbGjLFqVkRdUQ5WHMQukdQB+vNtXFzgHXoM1b82ZRxXd0nh1hlWKMpzgi7HaMAaRXBN hDQFKOWBN2wPP3mG/MLaZX9jhkCn8q3IrIldg/yGENLgGp22cTvArPO8eZ7wD/m1Peko=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1m5UzE-00DubP-FE; Mon, 19 Jul 2021 17:15:16 +0200 Date: Mon, 19 Jul 2021 17:15:16 +0200 From: Andrew Lunn To: Miguel Ojeda Cc: Linus Walleij , Wedson Almeida Filho , Greg KH , Bartosz Golaszewski , Kees Cook , Jan Kara , James Bottomley , Julia Lawall , Laurent Pinchart , Roland Dreier , ksummit@lists.linux.dev, Viresh Kumar Subject: Re: [TECH TOPIC] Rust for Linux Message-ID: References: Precedence: bulk X-Mailing-List: ksummit@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: > For instance, the driver developer could write something like this > right in the Rust source code: > > memory_map!( > 0x0042 simple_value 2 value(u16) > 0x0044 some_flags 2 flags(..., FLAG1, FLAG2) > 0x0046 custom_type 1 value(MyCustomType) > 0x0047 across_bits 2 [ > 0..2 other_flags flags(FOO, BAR), > 2..4 _ unused, > 4..31 temp value(Temperature), > ] > ); > > And then simply call: > > driver.map.read_temp() > > and it would automatically perform the shifting, masking, unit > conversions, etc. to get the raw sensor data into a value in proper > Kelvin. Hi Miguel Can you express endianness here as well? There are often cases where the hardware is always big endian independent of the CPU endianness. Some of the readl/writel macros handle this, adding a swap when the two don't match. Andrew