rmapi: add OS-event posting/poll wakeup and GA10x RM facts & usermode/shared-data classes

Cherry-picked MIT-clean pieces from PR #25:
- rmapi_node.c/.h: add nv_rs_rmapi_file_post() and report posted dataless OS events once in nv_rs_rmapi_poll() (EPOLLPRI | EPOLLIN, matching stock nvidia_poll).
- rmapi/gpu.rs: add GpuFacts::is_ga10x(), allow GA10x in MMU v2 vaspace/video memory paths, add Turing/Ampere usermode window 0xc461/0xc561 (0xbb_0000), and RM_USER_SHARED_DATA (0xde).

Co-authored-by: Kamil Skowron <1019893+Cinderella-Man@users.noreply.github.com>
This commit is contained in:
Eric Hartford
2026-12-01 01:55:26 +00:00
parent a4c053c3e2
commit c9c47069db
3 changed files with 35 additions and 6 deletions

View File

@ -104,6 +104,8 @@ struct nv_rs_rmapi_file {
unsigned int generation;
struct file *control;
wait_queue_head_t wait;
/* bit 0 = a dataless OS event was posted to this file (nv_rs_rmapi_file_post) */
unsigned long events;
/* The mapping context NV_ESC_RM_MAP_MEMORY attached to this (control) file. Written
* once under nv_rs_rmapi_lock and published through `valid`; it then stays for the
* life of the file, as the original's nv_alloc_mapping_context_t does, and holds one
@ -1559,14 +1561,25 @@ static int nv_rs_rmapi_mmap(struct file *file, struct vm_area_struct *vma)
return 0;
}
/* OS events can be allocated and event objects registered on them (rmapi::event), but
* nothing posts an event yet, so nothing is ever pending: like the original's nvidia_poll
* with an empty queue, the caller is queued and no bit is reported. */
/* Post a dataless OS event to `owner` (matching stock `nv_post_event` without data).
* Caller must hold `nv_rs_rmapi_lock` so the file context stays alive. */
void nv_rs_rmapi_file_post(u64 owner)
{
struct nv_rs_rmapi_file *context = (struct nv_rs_rmapi_file *)(unsigned long)owner;
if (!context)
return;
set_bit(0, &context->events);
wake_up_interruptible(&context->wait);
}
static __poll_t nv_rs_rmapi_poll(struct file *file, poll_table *wait)
{
struct nv_rs_rmapi_file *context = file->private_data;
if (!(file->f_flags & O_NONBLOCK))
poll_wait(file, &context->wait, wait);
/* Report a posted dataless event once, matching stock `nvidia_poll`. */
if (test_and_clear_bit(0, &context->events))
return EPOLLPRI | EPOLLIN;
return 0;
}

View File

@ -25,6 +25,7 @@ int nv_rs_rmapi_node_gpu_reader(struct pci_dev *pdev,
int nv_rs_rmapi_node_gpu_runtime(struct pci_dev *pdev, struct nv_rs_gpu_owner *owner);
void nv_rs_rmapi_node_gpu_remove(struct pci_dev *pdev);
struct device *nv_rs_rmapi_gpu_device_get(u32 gpu_id);
void nv_rs_rmapi_file_post(u64 owner);
void nv_rs_rmapi_gpu_negotiate_dma(u32 gpu_id, unsigned int bits);
u32 nv_rs_rmapi_handle_rc_fault(u32 gpu_id, u64 inst_ptr, u64 fault_va, u32 xid_code);
#endif

View File

@ -2715,6 +2715,11 @@ impl GpuFacts {
let [architecture, implementation, _] = self.arch();
(architecture, implementation) == (0x140, 0)
}
/// An Ampere GA10x GPU (GA102..GA107), driven through GSP-RM.
pub fn is_ga10x(&self) -> bool {
let [architecture, implementation, _] = self.arch();
architecture == 0x170 && implementation >= 2
}
}
/// System-wide inputs of the commands above.
@ -3862,9 +3867,9 @@ impl<const N: usize, A: RmAlloc> Bound<'_, N, A> {
if !self
.gpus
.facts_mut(device.gpu_id)
.is_some_and(|facts| facts.is_gv100())
.is_some_and(|facts| facts.is_gv100() || facts.is_ga10x())
{
// The format constants of `vaspace` are a GV100's.
// The format constants of `vaspace` are a GV100's (GA10x shares MMU v2).
return status::NOT_SUPPORTED;
}
let default = (device.va_mode != 2 && device.va_plain).then_some(VaSpace::DEVICE_DEFAULT);
@ -4089,7 +4094,7 @@ impl<const N: usize, A: RmAlloc> Bound<'_, N, A> {
return status::INVALID_OBJECT_PARENT;
};
let region = match self.gpus.facts_mut(device.gpu_id) {
Some(facts) if facts.is_gv100() => facts.video,
Some(facts) if facts.is_gv100() || facts.is_ga10x() => facts.video,
_ => None,
};
let Some(region) = region else {
@ -4840,6 +4845,16 @@ impl<const N: usize, A: RmAlloc> Objects for Bound<'_, N, A> {
memory::CLASS_VIRTUAL => self.virtual_memory(object, params),
memory::CLASS_OS_DESCRIPTOR => self.os_descriptor_memory(object, params, scope),
memory::CLASS_USERMODE => self.register_window(object, 0x81_0000, 0x1_0000, true),
// Turing / Ampere usermode window (`NV_VIRTUAL_FUNCTION + 0x30000`).
0xc461 | 0xc561 => self.register_window(object, 0xbb_0000, 0x1_0000, true),
// `RM_USER_SHARED_DATA` (`0xde`): 16 KiB shared-data sysmem buffer.
0xde => {
let mut synth = [0u8; memory::PARAMS];
put(&mut synth, 0, 0x4e56_5253);
put(&mut synth, 24, 0x2a00_0000);
put(&mut synth, 64, 0x4000);
self.system_memory(object, &mut synth)
}
memory::CLASS_SUBDEVICE_MASTER => self.register_window(object, 0, 0x1000, false),
channel::CLASS_GROUP => self.channel_group(object, params, scope),
channel::CLASS_SHARE => self.context_share(object, params),