Re: [PATCH 1/2] rust: sizes: add u64 variants of SZ_* constants
From: John Hubbard
Date: Tue Mar 10 2026 - 18:14:12 EST
On 3/10/26 3:08 PM, Miguel Ojeda wrote:
> On Tue, Mar 10, 2026 at 9:55 PM Danilo Krummrich <dakr@xxxxxxxxxx> wrote:
>>
>> Forgot to mention, the background of this is that existing DRM components, such
>> as GPUVM, Buddy, etc. just use u64 as a common denominator. However, this
>> becomes annoying when the corresponding device is u32 (or even smaller outside
>> of DRM). Because then we have all the fallible conversions on the other end
>> where the driver interacts with the HW.
>>
>> So, on the Rust side I think we want to abstract this, such that drivers can
>> choose the actual device size type and the corresponding APIs just work with
>> this type and store the actual value in the backing u64 internally, but hand it
>> out as the actual type the driver passed in originally.
>
> I see, thanks for that context -- yes, if the types are different and
> known, it would be better to abstract over the right one.
>
> (And perhaps it may even make sense to use newtypes too, depending on
> the details.)
It might. Because GpuAddr is a bit vague, whereas FbAddr is always going
to be u64.
OK, I think a define_size!() macro that implements a DeviceSize trait works
here. We still end up converting call sites to use sizes::u64::SZ_1M, once
DeviceSize is in scope.
And then later, one can build on top of that with things such as
<T: DeviceSize>, and such.
I'll post a v2, assuming that this sounds about right.
thanks,
--
John Hubbard