summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/nova/driver.rs
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/nova/driver.rs')
-rw-r--r--drivers/gpu/drm/nova/driver.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/drivers/gpu/drm/nova/driver.rs b/drivers/gpu/drm/nova/driver.rs
index 33abf2545994..84e01dc04f82 100644
--- a/drivers/gpu/drm/nova/driver.rs
+++ b/drivers/gpu/drm/nova/driver.rs
@@ -22,6 +22,29 @@ struct NovaDevice;
/// BAR Size
pub(crate) const BAR_SIZE: usize = 16777216;
+use core::ops::{Add, BitAnd, Div, Not, Sub};
+
+/// Aligns an integer type to a power of two.
+pub(crate) fn align<T>(a: T, b: T) -> T
+where
+ T: Copy
+ + Default
+ + BitAnd<Output = T>
+ + Not<Output = T>
+ + Add<Output = T>
+ + Sub<Output = T>
+ + Div<Output = T>
+ + core::cmp::PartialEq,
+{
+ let def: T = Default::default();
+ #[allow(clippy::eq_op)]
+ let one: T = !def / !def;
+
+ assert!((b & (b - one)) == def);
+
+ (a + b - one) & !(b - one)
+}
+
impl pci::Driver for NovaDevice {
define_pci_id_table! {