summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/nova/gem.rs
blob: 51bc30c226e2948f4ce190e5e6bcc29ff8b5eff0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: GPL-2.0

use kernel::{
    drm::{
        gem,
        gem::{BaseObject, ObjectRef},
    },
    prelude::*,
};

use crate::{
    driver::{NovaDevice, NovaDriver},
    file::DrmFile,
};

/// GEM Object inner driver data
#[pin_data]
pub(crate) struct DriverObject {}

/// Type alias for the GEM object tyoe for this driver.
pub(crate) type Object = gem::Object<DriverObject>;

impl gem::BaseDriverObject<Object> for DriverObject {
    fn new(dev: &NovaDevice, _size: usize) -> impl PinInit<Self, Error> {
        dev_dbg!(dev.as_ref(), "DriverObject::new\n");
        DriverObject {}
    }
}

impl gem::DriverObject for DriverObject {
    type Driver = NovaDriver;
}

/// Create a new DRM GEM object.
pub(crate) fn object_new(dev: &NovaDevice, size: usize) -> Result<ObjectRef<Object>> {
    let aligned_size = size.next_multiple_of(1 << 12);

    if size == 0 || size > aligned_size {
        return Err(EINVAL);
    }

    let gem = Object::new(dev, aligned_size)?;

    Ok(ObjectRef::from_pinned_unique(gem))
}

/// Look up a GEM object handle for a `File` and return an `ObjectRef` for it.
pub(crate) fn lookup_handle(file: &DrmFile, handle: u32) -> Result<ObjectRef<Object>> {
    Object::lookup_handle(file, handle)
}