M: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
S: Maintained
F: rust/bql/
+F: rust/chardev/
F: rust/common/
F: rust/migration/
F: rust/qemu-api
"migration",
]
+[[package]]
+name = "chardev"
+version = "0.1.0"
+dependencies = [
+ "bql",
+ "common",
+ "migration",
+ "qemu_api_macros",
+ "qom",
+ "util",
+]
+
[[package]]
name = "common"
version = "0.1.0"
"bilge-impl",
"bits",
"bql",
+ "chardev",
"common",
"migration",
"qemu_api",
version = "0.1.0"
dependencies = [
"bql",
+ "chardev",
"common",
"migration",
"qemu_api_macros",
--- /dev/null
+[package]
+name = "chardev"
+version = "0.1.0"
+description = "Rust bindings for QEMU/chardev"
+resolver = "2"
+publish = false
+
+authors.workspace = true
+edition.workspace = true
+homepage.workspace = true
+license.workspace = true
+repository.workspace = true
+rust-version.workspace = true
+
+[dependencies]
+common = { path = "../common" }
+bql = { path = "../bql" }
+migration = { path = "../migration" }
+qom = { path = "../qom" }
+util = { path = "../util" }
+qemu_api_macros = { path = "../qemu-api-macros" }
+
+[lints]
+workspace = true
--- /dev/null
+../util/build.rs
\ No newline at end of file
--- /dev/null
+c_enums = [
+ 'QEMUChrEvent',
+]
+_chardev_bindgen_args = []
+foreach enum : c_enums
+ _chardev_bindgen_args += ['--rustified-enum', enum]
+endforeach
+
+# TODO: Remove this comment when the clang/libclang mismatch issue is solved.
+#
+# Rust bindings generation with `bindgen` might fail in some cases where the
+# detected `libclang` does not match the expected `clang` version/target. In
+# this case you must pass the path to `clang` and `libclang` to your build
+# command invocation using the environment variables CLANG_PATH and
+# LIBCLANG_PATH
+_chardev_bindings_inc_rs = rust.bindgen(
+ input: 'wrapper.h',
+ dependencies: common_ss.all_dependencies(),
+ output: 'bindings.inc.rs',
+ include_directories: bindings_incdir,
+ bindgen_version: ['>=0.60.0'],
+ args: bindgen_args_common + _chardev_bindgen_args,
+)
+
+_chardev_rs = static_library(
+ 'chardev',
+ structured_sources(
+ [
+ 'src/lib.rs',
+ 'src/bindings.rs',
+ 'src/chardev.rs',
+ ],
+ {'.': _chardev_bindings_inc_rs}
+ ),
+ override_options: ['rust_std=2021', 'build.rust_std=2021'],
+ rust_abi: 'rust',
+ link_with: [_bql_rs, _migration_rs, _qom_rs, _util_rs],
+ dependencies: [common_rs, qemu_api_macros],
+)
+
+chardev_rs = declare_dependency(link_with: [_chardev_rs], dependencies: [qemu_api_macros, chardev, qemuutil])
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0-or-later
+#![allow(
+ dead_code,
+ improper_ctypes_definitions,
+ improper_ctypes,
+ non_camel_case_types,
+ non_snake_case,
+ non_upper_case_globals,
+ unnecessary_transmutes,
+ unsafe_op_in_unsafe_fn,
+ clippy::pedantic,
+ clippy::restriction,
+ clippy::style,
+ clippy::missing_const_for_fn,
+ clippy::ptr_offset_with_cast,
+ clippy::useless_transmute,
+ clippy::missing_safety_doc,
+ clippy::too_many_arguments
+)]
+
+use common::Zeroable;
+
+#[cfg(MESON)]
+include!("bindings.inc.rs");
+
+#[cfg(not(MESON))]
+include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
+
+// SAFETY: these are implemented in C; the bindings need to assert that the
+// BQL is taken, either directly or via `BqlCell` and `BqlRefCell`.
+// When bindings for character devices are introduced, this can be
+// moved to the Opaque<> wrapper in src/chardev.rs.
+unsafe impl Send for CharBackend {}
+unsafe impl Sync for CharBackend {}
+
+unsafe impl Zeroable for CharBackend {}
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+pub mod bindings;
+
+mod chardev;
+pub use chardev::*;
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/*
+ * This header file is meant to be used as input to the `bindgen` application
+ * in order to generate C FFI compatible Rust bindings.
+ */
+
+#ifndef __CLANG_STDATOMIC_H
+#define __CLANG_STDATOMIC_H
+/*
+ * Fix potential missing stdatomic.h error in case bindgen does not insert the
+ * correct libclang header paths on its own. We do not use stdatomic.h symbols
+ * in QEMU code, so it's fine to declare dummy types instead.
+ */
+typedef enum memory_order {
+ memory_order_relaxed,
+ memory_order_consume,
+ memory_order_acquire,
+ memory_order_release,
+ memory_order_acq_rel,
+ memory_order_seq_cst,
+} memory_order;
+#endif /* __CLANG_STDATOMIC_H */
+
+#include "qemu/osdep.h"
+
+#include "chardev/char-fe.h"
+#include "chardev/char-serial.h"
bql = { path = "../../../bql" }
migration = { path = "../../../migration" }
qom = { path = "../../../qom" }
+chardev = { path = "../../../chardev" }
qemu_api = { path = "../../../qemu-api" }
qemu_api_macros = { path = "../../../qemu-api-macros" }
bql_rs,
qemu_api_macros,
qom_rs,
+ chardev_rs,
],
)
use std::{ffi::CStr, mem::size_of};
use bql::BqlRefCell;
+use chardev::{CharBackend, Chardev, Event};
use common::{static_assert, uninit_field_mut};
use migration::{
self, impl_vmstate_forward, impl_vmstate_struct, vmstate_fields, vmstate_of,
vmstate_subsections, vmstate_unused, VMStateDescription, VMStateDescriptionBuilder,
};
use qemu_api::{
- chardev::{CharBackend, Chardev, Event},
irq::{IRQState, InterruptSource},
memory::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder},
prelude::*,
subdir('migration')
subdir('bql')
subdir('qom')
+subdir('chardev')
subdir('qemu-api')
subdir('hw')
[dependencies]
common = { path = "../common" }
+chardev = { path = "../chardev" }
migration = { path = "../migration" }
util = { path = "../util" }
bql = { path = "../bql" }
'GpioPolarity',
'MachineInitPhase',
'MemoryDeviceInfoKind',
- 'QEMUChrEvent',
'ResetType',
'device_endian',
]
endforeach
blocked_type = [
+ 'Chardev',
+ 'Error',
'ObjectClass',
'VMStateDescription',
- 'Error',
]
foreach type: blocked_type
_qemu_api_bindgen_args += ['--blocklist-type', type]
[
'src/lib.rs',
'src/bindings.rs',
- 'src/chardev.rs',
'src/irq.rs',
'src/memory.rs',
'src/prelude.rs',
override_options: ['rust_std=2021', 'build.rust_std=2021'],
rust_abi: 'rust',
rust_args: _qemu_api_cfg,
- dependencies: [anyhow_rs, bql_rs, common_rs, foreign_rs, libc_rs, migration_rs, qemu_api_macros,
- qom_rs, util_rs, hwcore, chardev],
+ dependencies: [anyhow_rs, bql_rs, chardev_rs, common_rs, foreign_rs, libc_rs, migration_rs, qemu_api_macros,
+ qom_rs, util_rs, hwcore],
)
qemu_api_rs = declare_dependency(link_with: [_qemu_api_rs],
//! `bindgen`-generated declarations.
+use chardev::bindings::Chardev;
use common::Zeroable;
use migration::bindings::VMStateDescription;
use qom::bindings::ObjectClass;
#[cfg(not(MESON))]
include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
-// SAFETY: these are implemented in C; the bindings need to assert that the
-// BQL is taken, either directly or via `BqlCell` and `BqlRefCell`.
-// When bindings for character devices are introduced, this can be
-// moved to the Opaque<> wrapper in src/chardev.rs.
-unsafe impl Send for CharBackend {}
-unsafe impl Sync for CharBackend {}
-
// SAFETY: this is a pure data struct
unsafe impl Send for CoalescedMemoryRange {}
unsafe impl Sync for CoalescedMemoryRange {}
unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 {}
unsafe impl Zeroable for crate::bindings::MemoryRegionOps {}
unsafe impl Zeroable for crate::bindings::MemTxAttrs {}
-unsafe impl Zeroable for crate::bindings::CharBackend {}
#[rustfmt::skip]
pub mod prelude;
-pub mod chardev;
pub mod irq;
pub mod memory;
pub mod qdev;
};
pub use bindings::{ClockEvent, DeviceClass, Property, ResetType};
+use chardev::Chardev;
use common::{callbacks::FnCall, Opaque};
use migration::{impl_vmstate_c_struct, VMStateDescription};
use qom::{prelude::*, ObjectClass, ObjectImpl, Owned, ParentInit};
use crate::{
bindings::{self, qdev_init_gpio_in, qdev_init_gpio_out, ResettableClass},
- chardev::Chardev,
irq::InterruptSource,
};
const VALUE: *const bindings::PropertyInfo = unsafe { &bindings::qdev_prop_uint64 };
}
-/// Use [`bindings::qdev_prop_chr`] for [`crate::chardev::CharBackend`].
-unsafe impl QDevProp for crate::chardev::CharBackend {
+/// Use [`bindings::qdev_prop_chr`] for [`chardev::CharBackend`].
+unsafe impl QDevProp for chardev::CharBackend {
const VALUE: *const bindings::PropertyInfo = unsafe { &bindings::qdev_prop_chr };
}
#include "system/system.h"
#include "hw/sysbus.h"
#include "system/memory.h"
-#include "chardev/char-fe.h"
#include "hw/clock.h"
#include "hw/qdev-clock.h"
#include "hw/qdev-properties.h"
#include "hw/qdev-properties-system.h"
#include "hw/irq.h"
-#include "chardev/char-serial.h"
#include "exec/memattrs.h"
#include "system/address-spaces.h"
#include "hw/char/pl011.h"