qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC 04/13] rust: add bindings for gpio_{in|out} initialization


From: Paolo Bonzini
Subject: Re: [RFC 04/13] rust: add bindings for gpio_{in|out} initialization
Date: Fri, 17 Jan 2025 13:47:53 +0100



Il ven 17 gen 2025, 11:55 Zhao Liu <zhao1.liu@intel.com> ha scritto:
> >         assert!(pins.len() > 0);
>
> !pins.is_empty().

Yes.

> But I am not sure it's needed...
> >
> >         unsafe {
> >             qdev_init_gpio_out(
> >                 self.upcast::<DeviceState>() as *const DeviceState as *mut DeviceState,
> >                 pins[0].as_ptr(),
> >                 pins.len() as c_int,
>
> ... if you use instead pins.as_ptr() without the initial dereference.

Emm, pins.as_ptr() returns `*const InterruptSource`, which can't be
converted to `*mut *mut IRQState` with InterruptSource::as_ptr().

It can be cast, since an InterruptSource is essentially a *mut IRQState, but I agree it's not pretty.

Maybe add a "pub(crate) fn as_slice_of_qemu_irq(slice: [Self]) -> [*mut IRQState)" to InterruptSource? It would just do a transmute and build the new slice with from_raw_parts. And then "let pins = InterruptSource::as_slice_of_qemu_irq(pins)" lets you use pins.as_ptr().

Paolo

So I haven't thought of a better way yet...

> > impl HPETState {
> >     ...
> >
> >     fn handle_legacy_irq(&self, irq: u32, level: u32) {
> >         if irq == HPET_LEGACY_PIT_INT {
> >             if !self.is_legacy_mode() {
> >                 self.irqs[0].set(level != 0);
> >             }
> >         } else {
> >             self.rtc_irq_level.set(level as u8);
>
> Any reason why you defined rtc_irq_level as InterruptSource<u8>
> instead of InterruptSource<u32>?

Thanks! I missed to clean up this, having previously used u8.

Regards,
Zhao


reply via email to

[Prev in Thread] Current Thread [Next in Thread]