summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/nova/nova_drv.rs
blob: 0dd0735db674bdc399cbfe7ba7dfbf44e4a32a0f (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! Nova GPU Driver

// For now, catch 'em all!

mod gpu;
mod bios;
mod fwsec;

use crate::gpu::CardType;
use alloc::boxed::Box;
use core::{
    cell::UnsafeCell,
    convert::TryInto,
    format_args,
    pin::Pin,
    sync::atomic::{AtomicU16, AtomicU32, AtomicU64, Ordering},
};
use kernel::{
    bindings,
    c_str,
    device::{self, Device, RawDevice},
    dma, driver,
    error::code::*,
    firmware::{Firmware},
    io_mem::IoMem,
    new_mutex, new_spinlock, pci,
    pci::define_pci_id_table,
    prelude::*,
    stack_pin_init,
    sync::Mutex,
    sync::{Arc, SpinLock},
    types::AtomicOptionalBoxedPtr,
};

use gpu::Gpu;
struct NovaDevice;

/// BAR Size
pub(crate) const BAR_SIZE: usize = 16777216;

impl pci::Driver for NovaDevice {

    define_pci_id_table! {
        (),
        [ (pci::DeviceId::new(bindings::PCI_VENDOR_ID_NVIDIA, bindings::PCI_ANY_ID as u32), None) ]
    }

    fn probe(dev: &mut pci::Device, _id_info: Option<&Self::IdInfo>) -> Result {
        pr_info!("probe()\n");

        dev.enable_device_mem()?;
        dev.set_master();

        let bars = dev.select_bars(bindings::IORESOURCE_MEM.into());

        let res = dev.take_resource(0).ok_or(ENXIO)?;
        let bar = unsafe { IoMem::<BAR_SIZE>::try_new(res) }?;

        let boot0 = u64::from_le(bar.readq(0));

        if boot0 & 0x1f000000 == 0 {
            return Err(ENODEV);
        }
        pr_info!("nvidia hw rev 0x{:#x}", boot0);
        let chipset = (boot0 & 0x1ff00000) >> 20;
        let chiprev = boot0 & 0xff;

        let card_type = match chipset & 0x1f0 {
            0x160 => { pr_info!("TU100"); CardType::TU100 },
            0x170 => { pr_info!("GA100"); CardType::GA100 },
            0x190 => { pr_info!("AD100"); CardType::AD100 },
            _ => return Err(ENODEV)
        };

	let mut gpu = Gpu::new(card_type, bar);

	let _ = gpu.init(dev)?;
//        match self.booter_load_fw.request(c_str!("nvidia/ad102/gsp/booter_load-535.113.01.bin"), dev) {
//	    Err(e) => return Err(e),
//	    Ok(()) => pr_info!("loaded fw: {} ", self.booter_load_fw.size())
	//	}
	Ok(())
    }

    fn remove(_data: &Self::Data) {
        pr_info!("remove()\n");
    }
}

struct NovaModule {
    _registration: Pin<Box<driver::Registration<pci::Adapter<NovaDevice>>>>,
}

impl kernel::Module for NovaModule {
    fn init(_name: &'static CStr, module: &'static ThisModule) -> Result<Self> {
        pr_info!("Module loaded!\n");

        let registration = driver::Registration::new_pinned(c_str!("nova"), module)?;
        pr_info!("Registerd PCI driver.\n");

        Ok(Self {
            _registration: registration,
        })
    }
}

module! {
    type: NovaModule,
    name: "Nova",
    author: "Danilo Krummrich",
    description: "Nova GPU driver",
    license: "GPL v2",
    params: {
    },
}