xref: /qemu/rust/qemu-api/src/sysbus.rs (revision 4ed4da164c957a4475b9d075206f33113a69abda)
1 // Copyright 2024 Red Hat, Inc.
2 // Author(s): Paolo Bonzini <pbonzini@redhat.com>
3 // SPDX-License-Identifier: GPL-2.0-or-later
4 
5 use std::ptr::addr_of;
6 
7 pub use bindings::{SysBusDevice, SysBusDeviceClass};
8 
9 use crate::{bindings, cell::bql_locked, irq::InterruptSource};
10 
11 impl SysBusDevice {
12     /// Return `self` cast to a mutable pointer, for use in calls to C code.
13     const fn as_mut_ptr(&self) -> *mut SysBusDevice {
14         addr_of!(*self) as *mut _
15     }
16 
17     /// Expose an interrupt source outside the device as a qdev GPIO output.
18     /// Note that the ordering of calls to `init_irq` is important, since
19     /// whoever creates the sysbus device will refer to the interrupts with
20     /// a number that corresponds to the order of calls to `init_irq`.
21     pub fn init_irq(&self, irq: &InterruptSource) {
22         assert!(bql_locked());
23         unsafe {
24             bindings::sysbus_init_irq(self.as_mut_ptr(), irq.as_ptr());
25         }
26     }
27 }
28