Files
nvdriver/kernel-open/nvidia/dma_adapter.h
Eric Hartford 33ff608a88 Add MIT LICENSE and unify repository SPDX/Cargo/module licensing
- Add root LICENSE (MIT License, Copyright (c) 2026 QuixiAI / Eric Hartford).
- Set license = "MIT" in workspace Cargo.toml and member crates (zero non-MIT dependencies).
- Update all kernel-open/ and tests/vm/ SPDX headers to MIT and EXPORT_SYMBOL_GPL -> EXPORT_SYMBOL.
- Use MODULE_LICENSE("Dual MIT/GPL") in Linux .ko modules so Linux modpost permits linking against the kernel's own EXPORT_SYMBOL_GPL symbols while keeping the repository source 100% MIT.

Closes #12.
2026-12-01 00:20:02 +00:00

61 lines
3.8 KiB
C

/* SPDX-License-Identifier: MIT */
#ifndef NV_RS_DMA_ADAPTER_H
#define NV_RS_DMA_ADAPTER_H
#include <linux/types.h>
struct nv_rs_pci;
struct nv_rs_dma_context;
struct nv_rs_dma_backing {
u64 token, cpu_token, bytes, alignment;
u32 coherent, reserved;
};
struct nv_rs_dma_mapping { u64 token, address, bytes; };
/* Caller must own/enabled device and negotiate its DMA masks before creation.
* Context holds a PCI lease; close succeeds only after every allocation
* has been explicitly unmapped and freed. Never call on a foreign-owned GPU.
* The owner serializes close against every context operation; the internal
* mutex serializes slot operations, not raw-pointer context lifetime.
* PCI references do not pin module text; the enclosing GPU/driver owner must
* keep code loaded until the context is closed. */
int nv_rs_dma_context_create(struct nv_rs_pci *, unsigned int dma_bits,
struct nv_rs_dma_context **);
int nv_rs_dma_context_close(struct nv_rs_dma_context *);
/* Last resort when close returns -EBUSY: frees every allocation still held,
* mapped or not, then closes. Only for an owner that has established that the
* device can no longer reach system memory (bus mastering off, or removed);
* otherwise the device writes into freed pages. Stores the number freed. */
int nv_rs_dma_context_force_close(struct nv_rs_dma_context *, unsigned int *freed);
/* Allocations the context still holds. */
unsigned int nv_rs_dma_context_live(struct nv_rs_dma_context *);
/* Reports a context whose owner let go of it without closing it. Nothing is
* freed: the memory may still be in use by the device. */
void nv_rs_dma_context_leaked(struct nv_rs_dma_context *);
int nv_rs_dma_allocate(struct nv_rs_dma_context *, u64 bytes, u64 alignment,
struct nv_rs_dma_backing *);
int nv_rs_dma_map(struct nv_rs_dma_context *, const struct nv_rs_dma_backing *,
struct nv_rs_dma_mapping *);
int nv_rs_dma_sync_device(struct nv_rs_dma_context *, const struct nv_rs_dma_backing *,
const struct nv_rs_dma_mapping *, u64 offset, u64 bytes);
int nv_rs_dma_sync_cpu(struct nv_rs_dma_context *, const struct nv_rs_dma_backing *,
const struct nv_rs_dma_mapping *, u64 offset, u64 bytes);
int nv_rs_dma_unmap(struct nv_rs_dma_context *, const struct nv_rs_dma_backing *,
const struct nv_rs_dma_mapping *);
int nv_rs_dma_release(struct nv_rs_dma_context *, const struct nv_rs_dma_backing *);
/* CPU access to coherent backing. Buffers are validated kernel memory, never
* user pointers. Caller proves GPU quiescence/ownership for the copied range. */
int nv_rs_dma_read(struct nv_rs_dma_context *, const struct nv_rs_dma_backing *,
u64 offset, void *destination, u64 bytes);
int nv_rs_dma_write(struct nv_rs_dma_context *, const struct nv_rs_dma_backing *,
u64 offset, const void *source, u64 bytes);
/* Device-shared coherent words: aligned native 32-bit access only, validated
* against both live backing and mapping. Caller owns the device protocol:
* acquire barrier AFTER observing valid, no producer reuse before GET, and
* store barrier BEFORE publishing GET. These functions do not quiesce DMA.
* They sleep on the context mutex and cannot run in hardirq context. */
int nv_rs_dma_read_word(struct nv_rs_dma_context *, const struct nv_rs_dma_backing *,
const struct nv_rs_dma_mapping *, u64 offset, u32 *value);
int nv_rs_dma_write_word(struct nv_rs_dma_context *, const struct nv_rs_dma_backing *,
const struct nv_rs_dma_mapping *, u64 offset, u32 value);
/* Full system-memory publication fence; not a GPU cache/TLB invalidation. */
int nv_rs_dma_flush_sysmem(struct nv_rs_dma_context *, const struct nv_rs_dma_backing *);
#endif