1 // SPDX-License-Identifier: GPL-2.0 2 3 //! Generic devices that are part of the kernel's driver model. 4 //! 5 //! C header: [`include/linux/device.h`](srctree/include/linux/device.h) 6 7 use crate::{ 8 bindings, 9 types::{ARef, ForeignOwnable, Opaque}, 10 }; 11 use core::{fmt, marker::PhantomData, ptr}; 12 13 #[cfg(CONFIG_PRINTK)] 14 use crate::c_str; 15 16 pub mod property; 17 18 /// A reference-counted device. 19 /// 20 /// This structure represents the Rust abstraction for a C `struct device`. This implementation 21 /// abstracts the usage of an already existing C `struct device` within Rust code that we get 22 /// passed from the C side. 23 /// 24 /// An instance of this abstraction can be obtained temporarily or permanent. 25 /// 26 /// A temporary one is bound to the lifetime of the C `struct device` pointer used for creation. 27 /// A permanent instance is always reference-counted and hence not restricted by any lifetime 28 /// boundaries. 29 /// 30 /// For subsystems it is recommended to create a permanent instance to wrap into a subsystem 31 /// specific device structure (e.g. `pci::Device`). This is useful for passing it to drivers in 32 /// `T::probe()`, such that a driver can store the `ARef<Device>` (equivalent to storing a 33 /// `struct device` pointer in a C driver) for arbitrary purposes, e.g. allocating DMA coherent 34 /// memory. 35 /// 36 /// # Invariants 37 /// 38 /// A `Device` instance represents a valid `struct device` created by the C portion of the kernel. 39 /// 40 /// Instances of this type are always reference-counted, that is, a call to `get_device` ensures 41 /// that the allocation remains valid at least until the matching call to `put_device`. 42 /// 43 /// `bindings::device::release` is valid to be called from any thread, hence `ARef<Device>` can be 44 /// dropped from any thread. 45 #[repr(transparent)] 46 pub struct Device<Ctx: DeviceContext = Normal>(Opaque<bindings::device>, PhantomData<Ctx>); 47 48 impl Device { 49 /// Creates a new reference-counted abstraction instance of an existing `struct device` pointer. 50 /// 51 /// # Safety 52 /// 53 /// Callers must ensure that `ptr` is valid, non-null, and has a non-zero reference count, 54 /// i.e. it must be ensured that the reference count of the C `struct device` `ptr` points to 55 /// can't drop to zero, for the duration of this function call. 56 /// 57 /// It must also be ensured that `bindings::device::release` can be called from any thread. 58 /// While not officially documented, this should be the case for any `struct device`. 59 pub unsafe fn get_device(ptr: *mut bindings::device) -> ARef<Self> { 60 // SAFETY: By the safety requirements ptr is valid 61 unsafe { Self::as_ref(ptr) }.into() 62 } 63 } 64 65 impl Device<CoreInternal> { 66 /// Store a pointer to the bound driver's private data. 67 pub fn set_drvdata(&self, data: impl ForeignOwnable) { 68 // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`. 69 unsafe { bindings::dev_set_drvdata(self.as_raw(), data.into_foreign().cast()) } 70 } 71 72 /// Take ownership of the private data stored in this [`Device`]. 73 /// 74 /// # Safety 75 /// 76 /// - Must only be called once after a preceding call to [`Device::set_drvdata`]. 77 /// - The type `T` must match the type of the `ForeignOwnable` previously stored by 78 /// [`Device::set_drvdata`]. 79 pub unsafe fn drvdata_obtain<T: ForeignOwnable>(&self) -> T { 80 // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`. 81 let ptr = unsafe { bindings::dev_get_drvdata(self.as_raw()) }; 82 83 // SAFETY: 84 // - By the safety requirements of this function, `ptr` comes from a previous call to 85 // `into_foreign()`. 86 // - `dev_get_drvdata()` guarantees to return the same pointer given to `dev_set_drvdata()` 87 // in `into_foreign()`. 88 unsafe { T::from_foreign(ptr.cast()) } 89 } 90 91 /// Borrow the driver's private data bound to this [`Device`]. 92 /// 93 /// # Safety 94 /// 95 /// - Must only be called after a preceding call to [`Device::set_drvdata`] and before 96 /// [`Device::drvdata_obtain`]. 97 /// - The type `T` must match the type of the `ForeignOwnable` previously stored by 98 /// [`Device::set_drvdata`]. 99 pub unsafe fn drvdata_borrow<T: ForeignOwnable>(&self) -> T::Borrowed<'_> { 100 // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`. 101 let ptr = unsafe { bindings::dev_get_drvdata(self.as_raw()) }; 102 103 // SAFETY: 104 // - By the safety requirements of this function, `ptr` comes from a previous call to 105 // `into_foreign()`. 106 // - `dev_get_drvdata()` guarantees to return the same pointer given to `dev_set_drvdata()` 107 // in `into_foreign()`. 108 unsafe { T::borrow(ptr.cast()) } 109 } 110 } 111 112 impl<Ctx: DeviceContext> Device<Ctx> { 113 /// Obtain the raw `struct device *`. 114 pub(crate) fn as_raw(&self) -> *mut bindings::device { 115 self.0.get() 116 } 117 118 /// Returns a reference to the parent device, if any. 119 #[cfg_attr(not(CONFIG_AUXILIARY_BUS), expect(dead_code))] 120 pub(crate) fn parent(&self) -> Option<&Self> { 121 // SAFETY: 122 // - By the type invariant `self.as_raw()` is always valid. 123 // - The parent device is only ever set at device creation. 124 let parent = unsafe { (*self.as_raw()).parent }; 125 126 if parent.is_null() { 127 None 128 } else { 129 // SAFETY: 130 // - Since `parent` is not NULL, it must be a valid pointer to a `struct device`. 131 // - `parent` is valid for the lifetime of `self`, since a `struct device` holds a 132 // reference count of its parent. 133 Some(unsafe { Self::as_ref(parent) }) 134 } 135 } 136 137 /// Convert a raw C `struct device` pointer to a `&'a Device`. 138 /// 139 /// # Safety 140 /// 141 /// Callers must ensure that `ptr` is valid, non-null, and has a non-zero reference count, 142 /// i.e. it must be ensured that the reference count of the C `struct device` `ptr` points to 143 /// can't drop to zero, for the duration of this function call and the entire duration when the 144 /// returned reference exists. 145 pub unsafe fn as_ref<'a>(ptr: *mut bindings::device) -> &'a Self { 146 // SAFETY: Guaranteed by the safety requirements of the function. 147 unsafe { &*ptr.cast() } 148 } 149 150 /// Prints an emergency-level message (level 0) prefixed with device information. 151 /// 152 /// More details are available from [`dev_emerg`]. 153 /// 154 /// [`dev_emerg`]: crate::dev_emerg 155 pub fn pr_emerg(&self, args: fmt::Arguments<'_>) { 156 // SAFETY: `klevel` is null-terminated, uses one of the kernel constants. 157 unsafe { self.printk(bindings::KERN_EMERG, args) }; 158 } 159 160 /// Prints an alert-level message (level 1) prefixed with device information. 161 /// 162 /// More details are available from [`dev_alert`]. 163 /// 164 /// [`dev_alert`]: crate::dev_alert 165 pub fn pr_alert(&self, args: fmt::Arguments<'_>) { 166 // SAFETY: `klevel` is null-terminated, uses one of the kernel constants. 167 unsafe { self.printk(bindings::KERN_ALERT, args) }; 168 } 169 170 /// Prints a critical-level message (level 2) prefixed with device information. 171 /// 172 /// More details are available from [`dev_crit`]. 173 /// 174 /// [`dev_crit`]: crate::dev_crit 175 pub fn pr_crit(&self, args: fmt::Arguments<'_>) { 176 // SAFETY: `klevel` is null-terminated, uses one of the kernel constants. 177 unsafe { self.printk(bindings::KERN_CRIT, args) }; 178 } 179 180 /// Prints an error-level message (level 3) prefixed with device information. 181 /// 182 /// More details are available from [`dev_err`]. 183 /// 184 /// [`dev_err`]: crate::dev_err 185 pub fn pr_err(&self, args: fmt::Arguments<'_>) { 186 // SAFETY: `klevel` is null-terminated, uses one of the kernel constants. 187 unsafe { self.printk(bindings::KERN_ERR, args) }; 188 } 189 190 /// Prints a warning-level message (level 4) prefixed with device information. 191 /// 192 /// More details are available from [`dev_warn`]. 193 /// 194 /// [`dev_warn`]: crate::dev_warn 195 pub fn pr_warn(&self, args: fmt::Arguments<'_>) { 196 // SAFETY: `klevel` is null-terminated, uses one of the kernel constants. 197 unsafe { self.printk(bindings::KERN_WARNING, args) }; 198 } 199 200 /// Prints a notice-level message (level 5) prefixed with device information. 201 /// 202 /// More details are available from [`dev_notice`]. 203 /// 204 /// [`dev_notice`]: crate::dev_notice 205 pub fn pr_notice(&self, args: fmt::Arguments<'_>) { 206 // SAFETY: `klevel` is null-terminated, uses one of the kernel constants. 207 unsafe { self.printk(bindings::KERN_NOTICE, args) }; 208 } 209 210 /// Prints an info-level message (level 6) prefixed with device information. 211 /// 212 /// More details are available from [`dev_info`]. 213 /// 214 /// [`dev_info`]: crate::dev_info 215 pub fn pr_info(&self, args: fmt::Arguments<'_>) { 216 // SAFETY: `klevel` is null-terminated, uses one of the kernel constants. 217 unsafe { self.printk(bindings::KERN_INFO, args) }; 218 } 219 220 /// Prints a debug-level message (level 7) prefixed with device information. 221 /// 222 /// More details are available from [`dev_dbg`]. 223 /// 224 /// [`dev_dbg`]: crate::dev_dbg 225 pub fn pr_dbg(&self, args: fmt::Arguments<'_>) { 226 if cfg!(debug_assertions) { 227 // SAFETY: `klevel` is null-terminated, uses one of the kernel constants. 228 unsafe { self.printk(bindings::KERN_DEBUG, args) }; 229 } 230 } 231 232 /// Prints the provided message to the console. 233 /// 234 /// # Safety 235 /// 236 /// Callers must ensure that `klevel` is null-terminated; in particular, one of the 237 /// `KERN_*`constants, for example, `KERN_CRIT`, `KERN_ALERT`, etc. 238 #[cfg_attr(not(CONFIG_PRINTK), allow(unused_variables))] 239 unsafe fn printk(&self, klevel: &[u8], msg: fmt::Arguments<'_>) { 240 // SAFETY: `klevel` is null-terminated and one of the kernel constants. `self.as_raw` 241 // is valid because `self` is valid. The "%pA" format string expects a pointer to 242 // `fmt::Arguments`, which is what we're passing as the last argument. 243 #[cfg(CONFIG_PRINTK)] 244 unsafe { 245 bindings::_dev_printk( 246 klevel as *const _ as *const crate::ffi::c_char, 247 self.as_raw(), 248 c_str!("%pA").as_char_ptr(), 249 &msg as *const _ as *const crate::ffi::c_void, 250 ) 251 }; 252 } 253 254 /// Obtain the [`FwNode`](property::FwNode) corresponding to this [`Device`]. 255 pub fn fwnode(&self) -> Option<&property::FwNode> { 256 // SAFETY: `self` is valid. 257 let fwnode_handle = unsafe { bindings::__dev_fwnode(self.as_raw()) }; 258 if fwnode_handle.is_null() { 259 return None; 260 } 261 // SAFETY: `fwnode_handle` is valid. Its lifetime is tied to `&self`. We 262 // return a reference instead of an `ARef<FwNode>` because `dev_fwnode()` 263 // doesn't increment the refcount. It is safe to cast from a 264 // `struct fwnode_handle*` to a `*const FwNode` because `FwNode` is 265 // defined as a `#[repr(transparent)]` wrapper around `fwnode_handle`. 266 Some(unsafe { &*fwnode_handle.cast() }) 267 } 268 } 269 270 // SAFETY: `Device` is a transparent wrapper of a type that doesn't depend on `Device`'s generic 271 // argument. 272 kernel::impl_device_context_deref!(unsafe { Device }); 273 kernel::impl_device_context_into_aref!(Device); 274 275 // SAFETY: Instances of `Device` are always reference-counted. 276 unsafe impl crate::types::AlwaysRefCounted for Device { 277 fn inc_ref(&self) { 278 // SAFETY: The existence of a shared reference guarantees that the refcount is non-zero. 279 unsafe { bindings::get_device(self.as_raw()) }; 280 } 281 282 unsafe fn dec_ref(obj: ptr::NonNull<Self>) { 283 // SAFETY: The safety requirements guarantee that the refcount is non-zero. 284 unsafe { bindings::put_device(obj.cast().as_ptr()) } 285 } 286 } 287 288 // SAFETY: As by the type invariant `Device` can be sent to any thread. 289 unsafe impl Send for Device {} 290 291 // SAFETY: `Device` can be shared among threads because all immutable methods are protected by the 292 // synchronization in `struct device`. 293 unsafe impl Sync for Device {} 294 295 /// Marker trait for the context of a bus specific device. 296 /// 297 /// Some functions of a bus specific device should only be called from a certain context, i.e. bus 298 /// callbacks, such as `probe()`. 299 /// 300 /// This is the marker trait for structures representing the context of a bus specific device. 301 pub trait DeviceContext: private::Sealed {} 302 303 /// The [`Normal`] context is the context of a bus specific device when it is not an argument of 304 /// any bus callback. 305 pub struct Normal; 306 307 /// The [`Core`] context is the context of a bus specific device when it is supplied as argument of 308 /// any of the bus callbacks, such as `probe()`. 309 pub struct Core; 310 311 /// Semantically the same as [`Core`] but reserved for internal usage of the corresponding bus 312 /// abstraction. 313 pub struct CoreInternal; 314 315 /// The [`Bound`] context is the context of a bus specific device reference when it is guaranteed to 316 /// be bound for the duration of its lifetime. 317 pub struct Bound; 318 319 mod private { 320 pub trait Sealed {} 321 322 impl Sealed for super::Bound {} 323 impl Sealed for super::Core {} 324 impl Sealed for super::CoreInternal {} 325 impl Sealed for super::Normal {} 326 } 327 328 impl DeviceContext for Bound {} 329 impl DeviceContext for Core {} 330 impl DeviceContext for CoreInternal {} 331 impl DeviceContext for Normal {} 332 333 /// # Safety 334 /// 335 /// The type given as `$device` must be a transparent wrapper of a type that doesn't depend on the 336 /// generic argument of `$device`. 337 #[doc(hidden)] 338 #[macro_export] 339 macro_rules! __impl_device_context_deref { 340 (unsafe { $device:ident, $src:ty => $dst:ty }) => { 341 impl ::core::ops::Deref for $device<$src> { 342 type Target = $device<$dst>; 343 344 fn deref(&self) -> &Self::Target { 345 let ptr: *const Self = self; 346 347 // CAST: `$device<$src>` and `$device<$dst>` transparently wrap the same type by the 348 // safety requirement of the macro. 349 let ptr = ptr.cast::<Self::Target>(); 350 351 // SAFETY: `ptr` was derived from `&self`. 352 unsafe { &*ptr } 353 } 354 } 355 }; 356 } 357 358 /// Implement [`core::ops::Deref`] traits for allowed [`DeviceContext`] conversions of a (bus 359 /// specific) device. 360 /// 361 /// # Safety 362 /// 363 /// The type given as `$device` must be a transparent wrapper of a type that doesn't depend on the 364 /// generic argument of `$device`. 365 #[macro_export] 366 macro_rules! impl_device_context_deref { 367 (unsafe { $device:ident }) => { 368 // SAFETY: This macro has the exact same safety requirement as 369 // `__impl_device_context_deref!`. 370 ::kernel::__impl_device_context_deref!(unsafe { 371 $device, 372 $crate::device::CoreInternal => $crate::device::Core 373 }); 374 375 // SAFETY: This macro has the exact same safety requirement as 376 // `__impl_device_context_deref!`. 377 ::kernel::__impl_device_context_deref!(unsafe { 378 $device, 379 $crate::device::Core => $crate::device::Bound 380 }); 381 382 // SAFETY: This macro has the exact same safety requirement as 383 // `__impl_device_context_deref!`. 384 ::kernel::__impl_device_context_deref!(unsafe { 385 $device, 386 $crate::device::Bound => $crate::device::Normal 387 }); 388 }; 389 } 390 391 #[doc(hidden)] 392 #[macro_export] 393 macro_rules! __impl_device_context_into_aref { 394 ($src:ty, $device:tt) => { 395 impl ::core::convert::From<&$device<$src>> for $crate::types::ARef<$device> { 396 fn from(dev: &$device<$src>) -> Self { 397 (&**dev).into() 398 } 399 } 400 }; 401 } 402 403 /// Implement [`core::convert::From`], such that all `&Device<Ctx>` can be converted to an 404 /// `ARef<Device>`. 405 #[macro_export] 406 macro_rules! impl_device_context_into_aref { 407 ($device:tt) => { 408 ::kernel::__impl_device_context_into_aref!($crate::device::CoreInternal, $device); 409 ::kernel::__impl_device_context_into_aref!($crate::device::Core, $device); 410 ::kernel::__impl_device_context_into_aref!($crate::device::Bound, $device); 411 }; 412 } 413 414 #[doc(hidden)] 415 #[macro_export] 416 macro_rules! dev_printk { 417 ($method:ident, $dev:expr, $($f:tt)*) => { 418 { 419 ($dev).$method(::core::format_args!($($f)*)); 420 } 421 } 422 } 423 424 /// Prints an emergency-level message (level 0) prefixed with device information. 425 /// 426 /// This level should be used if the system is unusable. 427 /// 428 /// Equivalent to the kernel's `dev_emerg` macro. 429 /// 430 /// Mimics the interface of [`std::print!`]. More information about the syntax is available from 431 /// [`core::fmt`] and [`std::format!`]. 432 /// 433 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 434 /// [`std::format!`]: https://doc.rust-lang.org/std/macro.format.html 435 /// 436 /// # Examples 437 /// 438 /// ``` 439 /// # use kernel::device::Device; 440 /// 441 /// fn example(dev: &Device) { 442 /// dev_emerg!(dev, "hello {}\n", "there"); 443 /// } 444 /// ``` 445 #[macro_export] 446 macro_rules! dev_emerg { 447 ($($f:tt)*) => { $crate::dev_printk!(pr_emerg, $($f)*); } 448 } 449 450 /// Prints an alert-level message (level 1) prefixed with device information. 451 /// 452 /// This level should be used if action must be taken immediately. 453 /// 454 /// Equivalent to the kernel's `dev_alert` macro. 455 /// 456 /// Mimics the interface of [`std::print!`]. More information about the syntax is available from 457 /// [`core::fmt`] and [`std::format!`]. 458 /// 459 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 460 /// [`std::format!`]: https://doc.rust-lang.org/std/macro.format.html 461 /// 462 /// # Examples 463 /// 464 /// ``` 465 /// # use kernel::device::Device; 466 /// 467 /// fn example(dev: &Device) { 468 /// dev_alert!(dev, "hello {}\n", "there"); 469 /// } 470 /// ``` 471 #[macro_export] 472 macro_rules! dev_alert { 473 ($($f:tt)*) => { $crate::dev_printk!(pr_alert, $($f)*); } 474 } 475 476 /// Prints a critical-level message (level 2) prefixed with device information. 477 /// 478 /// This level should be used in critical conditions. 479 /// 480 /// Equivalent to the kernel's `dev_crit` macro. 481 /// 482 /// Mimics the interface of [`std::print!`]. More information about the syntax is available from 483 /// [`core::fmt`] and [`std::format!`]. 484 /// 485 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 486 /// [`std::format!`]: https://doc.rust-lang.org/std/macro.format.html 487 /// 488 /// # Examples 489 /// 490 /// ``` 491 /// # use kernel::device::Device; 492 /// 493 /// fn example(dev: &Device) { 494 /// dev_crit!(dev, "hello {}\n", "there"); 495 /// } 496 /// ``` 497 #[macro_export] 498 macro_rules! dev_crit { 499 ($($f:tt)*) => { $crate::dev_printk!(pr_crit, $($f)*); } 500 } 501 502 /// Prints an error-level message (level 3) prefixed with device information. 503 /// 504 /// This level should be used in error conditions. 505 /// 506 /// Equivalent to the kernel's `dev_err` macro. 507 /// 508 /// Mimics the interface of [`std::print!`]. More information about the syntax is available from 509 /// [`core::fmt`] and [`std::format!`]. 510 /// 511 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 512 /// [`std::format!`]: https://doc.rust-lang.org/std/macro.format.html 513 /// 514 /// # Examples 515 /// 516 /// ``` 517 /// # use kernel::device::Device; 518 /// 519 /// fn example(dev: &Device) { 520 /// dev_err!(dev, "hello {}\n", "there"); 521 /// } 522 /// ``` 523 #[macro_export] 524 macro_rules! dev_err { 525 ($($f:tt)*) => { $crate::dev_printk!(pr_err, $($f)*); } 526 } 527 528 /// Prints a warning-level message (level 4) prefixed with device information. 529 /// 530 /// This level should be used in warning conditions. 531 /// 532 /// Equivalent to the kernel's `dev_warn` macro. 533 /// 534 /// Mimics the interface of [`std::print!`]. More information about the syntax is available from 535 /// [`core::fmt`] and [`std::format!`]. 536 /// 537 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 538 /// [`std::format!`]: https://doc.rust-lang.org/std/macro.format.html 539 /// 540 /// # Examples 541 /// 542 /// ``` 543 /// # use kernel::device::Device; 544 /// 545 /// fn example(dev: &Device) { 546 /// dev_warn!(dev, "hello {}\n", "there"); 547 /// } 548 /// ``` 549 #[macro_export] 550 macro_rules! dev_warn { 551 ($($f:tt)*) => { $crate::dev_printk!(pr_warn, $($f)*); } 552 } 553 554 /// Prints a notice-level message (level 5) prefixed with device information. 555 /// 556 /// This level should be used in normal but significant conditions. 557 /// 558 /// Equivalent to the kernel's `dev_notice` macro. 559 /// 560 /// Mimics the interface of [`std::print!`]. More information about the syntax is available from 561 /// [`core::fmt`] and [`std::format!`]. 562 /// 563 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 564 /// [`std::format!`]: https://doc.rust-lang.org/std/macro.format.html 565 /// 566 /// # Examples 567 /// 568 /// ``` 569 /// # use kernel::device::Device; 570 /// 571 /// fn example(dev: &Device) { 572 /// dev_notice!(dev, "hello {}\n", "there"); 573 /// } 574 /// ``` 575 #[macro_export] 576 macro_rules! dev_notice { 577 ($($f:tt)*) => { $crate::dev_printk!(pr_notice, $($f)*); } 578 } 579 580 /// Prints an info-level message (level 6) prefixed with device information. 581 /// 582 /// This level should be used for informational messages. 583 /// 584 /// Equivalent to the kernel's `dev_info` macro. 585 /// 586 /// Mimics the interface of [`std::print!`]. More information about the syntax is available from 587 /// [`core::fmt`] and [`std::format!`]. 588 /// 589 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 590 /// [`std::format!`]: https://doc.rust-lang.org/std/macro.format.html 591 /// 592 /// # Examples 593 /// 594 /// ``` 595 /// # use kernel::device::Device; 596 /// 597 /// fn example(dev: &Device) { 598 /// dev_info!(dev, "hello {}\n", "there"); 599 /// } 600 /// ``` 601 #[macro_export] 602 macro_rules! dev_info { 603 ($($f:tt)*) => { $crate::dev_printk!(pr_info, $($f)*); } 604 } 605 606 /// Prints a debug-level message (level 7) prefixed with device information. 607 /// 608 /// This level should be used for debug messages. 609 /// 610 /// Equivalent to the kernel's `dev_dbg` macro, except that it doesn't support dynamic debug yet. 611 /// 612 /// Mimics the interface of [`std::print!`]. More information about the syntax is available from 613 /// [`core::fmt`] and [`std::format!`]. 614 /// 615 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 616 /// [`std::format!`]: https://doc.rust-lang.org/std/macro.format.html 617 /// 618 /// # Examples 619 /// 620 /// ``` 621 /// # use kernel::device::Device; 622 /// 623 /// fn example(dev: &Device) { 624 /// dev_dbg!(dev, "hello {}\n", "there"); 625 /// } 626 /// ``` 627 #[macro_export] 628 macro_rules! dev_dbg { 629 ($($f:tt)*) => { $crate::dev_printk!(pr_dbg, $($f)*); } 630 } 631