Files
nvdriver/kernel-open/nvidia/platform_driver.c
BlivionIaG cb15715316 kernel-open: add opt-in Tegra194 GV11B platform_driver and bus-agnostic rmapi_node registration (#385)
* kernel-open: add opt-in Tegra194 GV11B platform_driver and bus-agnostic rmapi_node registration

* rmapi_node: support platform dev in nv_rs_rmapi_mmap

* platform(gv11b): skip reset_control when Tegra genpd pm_domain owns GPU reset

* kernel-open(gv11b): fault-map and revoke platform BAR IO VMAs on GPU removal

* kernel-open(gv11b): extract rmapi_plat_io.h and test platform BAR VMA revocation in host fixture

* kernel-open(gv11b): propagate and report actual platform DMA mask in proc gpu info

* kernel-open(gv11b): document plat_io pgoff/BDF assumptions and harden !live release

* kernel-open(gv11b): clean up orphaned plat_io mappings on file release

* kernel-open(gv11b): resolve duplicate boot0/dma_bits fields after rebase

* kernel-open(gv11b): gate file_ref_get() on Linux >= 6.13 or NV_RS_HAVE_FILE_REF
2026-12-04 17:03:17 -08:00

723 lines
22 KiB
C

// SPDX-License-Identifier: MIT
/* Opt-in Tegra194 internal GV11B (0x15b, nvidia,gv11b) platform driver shim. */
#ifdef NV_RS_PLATFORM_HOST_FIXTURE
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
typedef int32_t s32;
typedef uint32_t u32;
typedef uint64_t u64;
typedef uint64_t resource_size_t;
#define __iomem
#define __init
#define __exit
#ifndef ENOENT
#define ENOENT 2
#endif
#ifndef EIO
#define EIO 5
#endif
#ifndef ENXIO
#define ENXIO 6
#endif
#ifndef ENOMEM
#define ENOMEM 12
#endif
#ifndef ENODEV
#define ENODEV 19
#endif
#ifndef EINVAL
#define EINVAL 22
#endif
#ifndef ERANGE
#define ERANGE 34
#endif
#ifndef U32_MAX
#define U32_MAX UINT32_MAX
#endif
#ifndef GFP_KERNEL
#define GFP_KERNEL 0
#endif
#ifndef IORESOURCE_MEM
#define IORESOURCE_MEM 0x00000200U
#endif
#define DMA_BIT_MASK(bits) ((bits) == 64 ? UINT64_MAX : ((1ULL << (bits)) - 1ULL))
#define READ_ONCE(v) (v)
#define WRITE_ONCE(v, n) ((v) = (n))
#define IS_ERR(ptr) ((uintptr_t)(ptr) >= (uintptr_t)-4095L)
#define PTR_ERR(ptr) ((int)(intptr_t)(ptr))
#define ERR_PTR(err) ((void *)(intptr_t)(err))
#ifndef container_of
#define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member)))
#endif
#define module_param(name, type, perm)
#define MODULE_PARM_DESC(name, desc)
#define dev_info(dev, fmt, ...) ((void)(dev))
#define dev_warn(dev, fmt, ...) ((void)(dev))
#define dev_err(dev, fmt, ...) ((void)(dev))
#define pr_info(fmt, ...) ((void)0)
#define LINUX_VERSION_CODE 0x070306
#define KERNEL_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
typedef uint8_t u8;
typedef uint16_t u16;
#include "platform_driver.h"
#include "rmapi_node.h"
struct kref { unsigned int count; };
static inline void kref_init(struct kref *k) { k->count = 1; }
static inline void kref_get(struct kref *k) { k->count++; }
static inline int kref_put(struct kref *k, void (*release)(struct kref *))
{
if (k->count > 0 && --k->count == 0) {
release(k);
return 1;
}
return 0;
}
struct mutex { int locked; };
static inline void mutex_init(struct mutex *m) { m->locked = 0; }
static inline void mutex_lock(struct mutex *m) { m->locked = 1; }
static inline void mutex_unlock(struct mutex *m) { m->locked = 0; }
struct of_device_id { const char *compatible; };
struct resource { resource_size_t start; resource_size_t end; unsigned long flags; };
static inline resource_size_t resource_size(const struct resource *r)
{
return (r && r->end >= r->start) ? (r->end - r->start + 1) : 0;
}
struct device { u64 dma_mask; bool pm_enabled; int pm_usage; void *pm_domain; };
struct clk { int enabled; };
struct reset_control { int deasserted; };
struct platform_device {
const char *name;
struct device dev;
struct resource res[2];
int num_resources;
int irqs[2];
int num_irqs;
void *drvdata;
struct clk *clk_gpu;
struct clk *clk_pwr;
struct clk *clk_fuse;
struct reset_control *rst_gpu;
void *mmio_bar0;
void *mmio_bar1;
int fail_dma_bits_gt;
};
struct device_driver {
const char *name;
const struct of_device_id *of_match_table;
};
struct platform_driver {
int (*probe)(struct platform_device *);
void (*remove)(struct platform_device *);
struct device_driver driver;
};
static void *nv_rs_mock_alloc(size_t sz);
static void nv_rs_mock_free(void *p);
#define kzalloc(sz, flags) ((void)(flags), nv_rs_mock_alloc(sz))
#define kfree(p) nv_rs_mock_free(p)
static inline void *platform_get_drvdata(const struct platform_device *pdev) { return pdev->drvdata; }
static inline void platform_set_drvdata(struct platform_device *pdev, void *d) { pdev->drvdata = d; }
static inline struct resource *platform_get_resource(struct platform_device *pdev,
unsigned int type, unsigned int num)
{
if ((int)num >= pdev->num_resources)
return NULL;
if ((pdev->res[num].flags & type) != type)
return NULL;
return &pdev->res[num];
}
static inline void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *r)
{
struct platform_device *pdev = (struct platform_device *)((char *)dev - offsetof(struct platform_device, dev));
if (!r)
return ERR_PTR(-EINVAL);
if (r == &pdev->res[0])
return pdev->mmio_bar0 ? pdev->mmio_bar0 : ERR_PTR(-ENOMEM);
if (r == &pdev->res[1])
return pdev->mmio_bar1 ? pdev->mmio_bar1 : ERR_PTR(-ENOMEM);
return ERR_PTR(-EINVAL);
}
static inline int dma_set_mask_and_coherent(struct device *dev, u64 mask)
{
struct platform_device *pdev = (struct platform_device *)((char *)dev - offsetof(struct platform_device, dev));
if (pdev->fail_dma_bits_gt > 0 && mask > DMA_BIT_MASK(pdev->fail_dma_bits_gt))
return -EIO;
dev->dma_mask = mask;
return 0;
}
static inline struct clk *devm_clk_get_optional(struct device *dev, const char *id)
{
struct platform_device *pdev = (struct platform_device *)((char *)dev - offsetof(struct platform_device, dev));
if (!id)
return NULL;
if (id[0] == 'g') return pdev->clk_gpu;
if (id[0] == 'p') return pdev->clk_pwr;
if (id[0] == 'f') return pdev->clk_fuse;
return NULL;
}
static inline int clk_prepare_enable(struct clk *c) { if (c) c->enabled++; return 0; }
static inline void clk_disable_unprepare(struct clk *c) { if (c && c->enabled > 0) c->enabled--; }
static inline struct reset_control *devm_reset_control_get_optional(struct device *dev, const char *id)
{
struct platform_device *pdev = (struct platform_device *)((char *)dev - offsetof(struct platform_device, dev));
(void)id;
return pdev->rst_gpu;
}
static inline int reset_control_deassert(struct reset_control *r) { if (r) r->deasserted = 1; return 0; }
static inline int reset_control_assert(struct reset_control *r) { if (r) r->deasserted = 0; return 0; }
static inline void pm_runtime_enable(struct device *dev) { dev->pm_enabled = true; }
static inline void pm_runtime_disable(struct device *dev) { dev->pm_enabled = false; }
static inline int pm_runtime_resume_and_get(struct device *dev) { dev->pm_usage++; return 0; }
static inline void pm_runtime_put_sync(struct device *dev) { if (dev->pm_usage > 0) dev->pm_usage--; }
static inline int platform_get_irq(struct platform_device *pdev, unsigned int num)
{
if ((int)num >= pdev->num_irqs) return -ENXIO;
return pdev->irqs[num];
}
static inline int platform_get_irq_optional(struct platform_device *pdev, unsigned int num)
{
if ((int)num >= pdev->num_irqs) return -ENXIO;
return pdev->irqs[num];
}
static inline u32 readl(const volatile void __iomem *addr)
{
return *(const volatile u32 *)addr;
}
static inline void writel(u32 val, volatile void __iomem *addr)
{
*(volatile u32 *)addr = val;
}
static int nv_rs_mock_plat_registered;
static inline int platform_driver_register(struct platform_driver *drv)
{
(void)drv;
nv_rs_mock_plat_registered++;
return 0;
}
static inline void platform_driver_unregister(struct platform_driver *drv)
{
(void)drv;
if (nv_rs_mock_plat_registered > 0)
nv_rs_mock_plat_registered--;
}
static int nv_rs_mock_rmapi_registered;
static int nv_rs_mock_rmapi_add_fail;
static int nv_rs_mock_rmapi_early_read_rc;
static u32 nv_rs_mock_rmapi_early_boot42;
static struct nv_rs_rmapi_gpu_desc nv_rs_mock_rmapi_desc;
static int (*nv_rs_mock_rmapi_read32)(void *cookie, u64 offset, u32 *value);
static void (*nv_rs_mock_rmapi_release)(void *cookie);
static void *nv_rs_mock_rmapi_cookie;
int nv_rs_rmapi_node_gpu_add_desc(const struct nv_rs_rmapi_gpu_desc *desc)
{
if (!desc)
return -EINVAL;
if (nv_rs_mock_rmapi_add_fail < 0)
return nv_rs_mock_rmapi_add_fail;
nv_rs_mock_rmapi_desc = *desc;
nv_rs_mock_rmapi_read32 = desc->read32;
nv_rs_mock_rmapi_release = desc->release;
nv_rs_mock_rmapi_cookie = desc->cookie;
nv_rs_mock_rmapi_early_read_rc = -ENOENT;
nv_rs_mock_rmapi_early_boot42 = 0U;
if (desc->read32)
nv_rs_mock_rmapi_early_read_rc =
desc->read32(desc->cookie, 0xa00U, &nv_rs_mock_rmapi_early_boot42);
nv_rs_mock_rmapi_registered++;
return 0;
}
int nv_rs_rmapi_node_gpu_reader_by_bdf(u32 domain, u8 bus, u8 slot,
int (*read32)(void *cookie, u64 offset, u32 *value),
void (*release)(void *cookie), void *cookie)
{
if (!nv_rs_mock_rmapi_registered || domain != NV_RS_PLAT_DOMAIN ||
bus != NV_RS_PLAT_BUS || slot != NV_RS_PLAT_SLOT)
return -ENOENT;
nv_rs_mock_rmapi_read32 = read32;
nv_rs_mock_rmapi_release = release;
nv_rs_mock_rmapi_cookie = cookie;
return 0;
}
void nv_rs_rmapi_node_gpu_remove_by_bdf(u32 domain, u8 bus, u8 slot)
{
void (*rel)(void *) = nv_rs_mock_rmapi_release;
void *cookie = nv_rs_mock_rmapi_cookie;
if (domain != NV_RS_PLAT_DOMAIN || bus != NV_RS_PLAT_BUS || slot != NV_RS_PLAT_SLOT)
return;
nv_rs_mock_rmapi_read32 = NULL;
nv_rs_mock_rmapi_release = NULL;
nv_rs_mock_rmapi_cookie = NULL;
if (nv_rs_mock_rmapi_registered > 0)
nv_rs_mock_rmapi_registered--;
if (rel)
rel(cookie);
}
#else
#include <linux/clk.h>
#include <linux/dma-mapping.h>
#include <linux/io.h>
#include <linux/ioport.h>
#include <linux/kernel.h>
#include <linux/kref.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/reset.h>
#include <linux/slab.h>
#include <linux/version.h>
#include "platform_driver.h"
#include "rmapi_node.h"
#endif
#define NV_RS_PMC_BOOT_0_OFF 0x0U
#define NV_RS_PMC_BOOT_42_OFF 0xa00U
#define NV_RS_PLAT_MIN_BAR0 0xa04U
static bool tegra_gv11b = false;
module_param(tegra_gv11b, bool, 0400);
MODULE_PARM_DESC(tegra_gv11b,
"Opt-in Tegra194 internal GV11B (nvidia,gv11b) platform device binding (default: 0)");
struct nv_rs_platform_gpu {
struct kref refcount;
struct platform_device *pdev;
void __iomem *bar0;
resource_size_t bar0_phys;
resource_size_t bar0_len;
void __iomem *bar1;
resource_size_t bar1_phys;
resource_size_t bar1_len;
struct clk *clk_gpu;
struct clk *clk_pwr;
struct clk *clk_fuse;
struct reset_control *rst_gpu;
int irq_stall;
int irq_nonstall;
unsigned int dma_bits;
u32 boot0;
u32 boot42;
struct mutex access;
bool pm_active;
bool clk_gpu_on;
bool clk_pwr_on;
bool clk_fuse_on;
bool reset_deasserted;
bool rmapi_registered;
bool removed;
};
#ifdef NV_RS_PLATFORM_HOST_FIXTURE
static struct nv_rs_platform_gpu nv_rs_mock_gpu_slot;
static bool nv_rs_mock_gpu_in_use;
static void *nv_rs_mock_alloc(size_t sz)
{
unsigned char *p = (unsigned char *)&nv_rs_mock_gpu_slot;
size_t i;
if (nv_rs_mock_gpu_in_use || sz > sizeof(nv_rs_mock_gpu_slot))
return NULL;
for (i = 0; i < sizeof(nv_rs_mock_gpu_slot); i++)
p[i] = 0;
nv_rs_mock_gpu_in_use = true;
return &nv_rs_mock_gpu_slot;
}
static void nv_rs_mock_free(void *p)
{
if (p == &nv_rs_mock_gpu_slot)
nv_rs_mock_gpu_in_use = false;
}
#endif
static bool platform_driver_registered;
static void nv_rs_platform_free(struct kref *ref)
{
struct nv_rs_platform_gpu *g = container_of(ref, struct nv_rs_platform_gpu, refcount);
kfree(g);
}
static int nv_rs_platform_rmapi_read32(void *cookie, u64 offset, u32 *value)
{
return nv_rs_platform_read32((struct nv_rs_platform_gpu *)cookie, offset, value);
}
static void nv_rs_platform_rmapi_release(void *cookie)
{
struct nv_rs_platform_gpu *g = (struct nv_rs_platform_gpu *)cookie;
if (g)
kref_put(&g->refcount, nv_rs_platform_free);
}
static void nv_rs_platform_quiesce(struct nv_rs_platform_gpu *g)
{
struct device *dev;
if (!g || !g->pdev)
return;
dev = &g->pdev->dev;
if (g->reset_deasserted && g->rst_gpu) {
reset_control_assert(g->rst_gpu);
g->reset_deasserted = false;
}
if (g->clk_fuse_on) {
clk_disable_unprepare(g->clk_fuse);
g->clk_fuse_on = false;
}
if (g->clk_pwr_on) {
clk_disable_unprepare(g->clk_pwr);
g->clk_pwr_on = false;
}
if (g->clk_gpu_on) {
clk_disable_unprepare(g->clk_gpu);
g->clk_gpu_on = false;
}
if (g->pm_active) {
pm_runtime_put_sync(dev);
pm_runtime_disable(dev);
g->pm_active = false;
}
}
bool nv_rs_platform_is_removed(struct nv_rs_platform_gpu *g)
{
return !g || READ_ONCE(g->removed);
}
int nv_rs_platform_read32(struct nv_rs_platform_gpu *g, u64 offset, u32 *value)
{
int err = 0;
if (!g || !value)
return -EINVAL;
if ((offset & 3ULL) != 0)
return -EINVAL;
if (g->bar0_len < 4 || offset > (u64)(g->bar0_len - 4))
return -ERANGE;
mutex_lock(&g->access);
if (nv_rs_platform_is_removed(g))
err = -ENODEV;
else
*value = readl((const volatile char __iomem *)g->bar0 + offset);
mutex_unlock(&g->access);
return err;
}
int nv_rs_platform_write32(struct nv_rs_platform_gpu *g, u64 offset, u32 value)
{
int err = 0;
if (!g)
return -EINVAL;
if ((offset & 3ULL) != 0)
return -EINVAL;
if (g->bar0_len < 4 || offset > (u64)(g->bar0_len - 4))
return -ERANGE;
mutex_lock(&g->access);
if (nv_rs_platform_is_removed(g))
err = -ENODEV;
else
writel(value, (volatile char __iomem *)g->bar0 + offset);
mutex_unlock(&g->access);
return err;
}
int nv_rs_platform_bar0_info(struct nv_rs_platform_gpu *g, u64 *physical, u64 *bytes)
{
if (!g || !physical || !bytes)
return -EINVAL;
if (nv_rs_platform_is_removed(g))
return -ENODEV;
*physical = (u64)g->bar0_phys;
*bytes = (u64)g->bar0_len;
return 0;
}
u32 nv_rs_platform_boot0(const struct nv_rs_platform_gpu *g)
{
return g ? g->boot0 : 0U;
}
u32 nv_rs_platform_boot42(const struct nv_rs_platform_gpu *g)
{
return g ? g->boot42 : 0U;
}
int nv_rs_platform_irq_stall(const struct nv_rs_platform_gpu *g)
{
return g ? g->irq_stall : -ENODEV;
}
int nv_rs_platform_irq_nonstall(const struct nv_rs_platform_gpu *g)
{
return g ? g->irq_nonstall : -ENODEV;
}
unsigned int nv_rs_platform_dma_bits(const struct nv_rs_platform_gpu *g)
{
return g ? g->dma_bits : 0U;
}
static int nv_rs_platform_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct nv_rs_platform_gpu *g;
struct resource *res0;
struct resource *res1;
int err;
if (!tegra_gv11b)
return -ENODEV;
res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res0 || resource_size(res0) < NV_RS_PLAT_MIN_BAR0)
return -ENXIO;
g = kzalloc(sizeof(*g), GFP_KERNEL);
if (!g)
return -ENOMEM;
kref_init(&g->refcount);
g->pdev = pdev;
mutex_init(&g->access);
g->bar0_phys = res0->start;
g->bar0_len = resource_size(res0);
g->bar0 = devm_ioremap_resource(dev, res0);
if (IS_ERR(g->bar0)) {
err = PTR_ERR(g->bar0);
dev_err(dev, "nvidia_rs: GV11B bar0 ioremap failed (%d)\n", err);
goto fail_alloc;
}
res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
if (res1 && resource_size(res1) > 0) {
g->bar1_phys = res1->start;
g->bar1_len = resource_size(res1);
g->bar1 = devm_ioremap_resource(dev, res1);
if (IS_ERR(g->bar1)) {
err = PTR_ERR(g->bar1);
dev_err(dev, "nvidia_rs: GV11B bar1 ioremap failed (%d)\n", err);
goto fail_alloc;
}
}
if (!dma_set_mask_and_coherent(dev, DMA_BIT_MASK(40)))
g->dma_bits = 40;
else if (!dma_set_mask_and_coherent(dev, DMA_BIT_MASK(36)))
g->dma_bits = 36;
else if (!dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)))
g->dma_bits = 32;
else {
err = -EIO;
dev_err(dev, "nvidia_rs: GV11B dma_set_mask failed (%d)\n", err);
goto fail_alloc;
}
g->clk_gpu = devm_clk_get_optional(dev, "gpu");
if (IS_ERR(g->clk_gpu)) {
err = PTR_ERR(g->clk_gpu);
dev_err(dev, "nvidia_rs: GV11B clk_get gpu failed (%d)\n", err);
goto fail_alloc;
}
g->clk_pwr = devm_clk_get_optional(dev, "pwr");
if (IS_ERR(g->clk_pwr)) {
err = PTR_ERR(g->clk_pwr);
dev_err(dev, "nvidia_rs: GV11B clk_get pwr failed (%d)\n", err);
goto fail_alloc;
}
g->clk_fuse = devm_clk_get_optional(dev, "fuse");
if (IS_ERR(g->clk_fuse)) {
err = PTR_ERR(g->clk_fuse);
dev_err(dev, "nvidia_rs: GV11B clk_get fuse failed (%d)\n", err);
goto fail_alloc;
}
/* Tegra194 BPMP genpd (dev->pm_domain) owns GPU reset via MRQ_PG; direct MRQ_RESET returns -EINVAL. */
if (!dev->pm_domain) {
g->rst_gpu = devm_reset_control_get_optional(dev, "gpu");
if (IS_ERR(g->rst_gpu)) {
err = PTR_ERR(g->rst_gpu);
dev_err(dev, "nvidia_rs: GV11B reset_get gpu failed (%d)\n", err);
goto fail_alloc;
}
}
pm_runtime_enable(dev);
err = pm_runtime_resume_and_get(dev);
if (err < 0) {
dev_err(dev, "nvidia_rs: GV11B pm_runtime_resume_and_get failed (%d)\n", err);
pm_runtime_disable(dev);
goto fail_alloc;
}
g->pm_active = true;
if (g->clk_gpu) {
err = clk_prepare_enable(g->clk_gpu);
if (err) {
dev_err(dev, "nvidia_rs: GV11B clk_enable gpu failed (%d)\n", err);
goto fail_power;
}
g->clk_gpu_on = true;
}
if (g->clk_pwr) {
err = clk_prepare_enable(g->clk_pwr);
if (err) {
dev_err(dev, "nvidia_rs: GV11B clk_enable pwr failed (%d)\n", err);
goto fail_power;
}
g->clk_pwr_on = true;
}
if (g->clk_fuse) {
err = clk_prepare_enable(g->clk_fuse);
if (err) {
dev_err(dev, "nvidia_rs: GV11B clk_enable fuse failed (%d)\n", err);
goto fail_power;
}
g->clk_fuse_on = true;
}
if (g->rst_gpu) {
err = reset_control_deassert(g->rst_gpu);
if (err) {
dev_err(dev, "nvidia_rs: GV11B reset_deassert gpu failed (%d)\n", err);
goto fail_power;
}
g->reset_deasserted = true;
}
g->irq_stall = platform_get_irq(pdev, 0);
if (g->irq_stall < 0) {
err = g->irq_stall;
dev_err(dev, "nvidia_rs: GV11B platform_get_irq(0) failed (%d)\n", err);
goto fail_power;
}
g->irq_nonstall = platform_get_irq_optional(pdev, 1);
g->boot0 = readl((const volatile char __iomem *)g->bar0 + NV_RS_PMC_BOOT_0_OFF);
g->boot42 = readl((const volatile char __iomem *)g->bar0 + NV_RS_PMC_BOOT_42_OFF);
if (g->boot0 == U32_MAX || g->boot42 == U32_MAX ||
!nv_rs_platform_is_gv11b(g->boot42)) {
dev_err(dev, "unexpected platform GPU identity boot0=0x%08x boot42=0x%08x\n",
g->boot0, g->boot42);
err = -ENODEV;
goto fail_power;
}
platform_set_drvdata(pdev, g);
{
u16 chip_dev = (u16)((g->boot42 >> 20) & NV_RS_GV11B_BOOT42_CHIP_MASK);
struct nv_rs_rmapi_gpu_desc rmapi_desc = {
.dev = dev,
.domain = NV_RS_PLAT_DOMAIN,
.bus = NV_RS_PLAT_BUS,
.slot = NV_RS_PLAT_SLOT,
.function = NV_RS_PLAT_FUNC,
.vendor = NV_RS_GV11B_PCI_VENDOR,
.device = chip_dev ? chip_dev : NV_RS_GV11B_PCI_DEVICE,
.subsystem_vendor = NV_RS_GV11B_PCI_VENDOR,
.subsystem = chip_dev ? chip_dev : NV_RS_GV11B_PCI_DEVICE,
.revision = (u8)(g->boot0 & 0xffU),
.irq = (g->irq_stall > 0) ? (u32)g->irq_stall : 0U,
.bar0 = (u64)g->bar0_phys,
.bar0_size = (u64)g->bar0_len,
.bar1 = (u64)g->bar1_phys,
.bar1_size = (u64)g->bar1_len,
.boot0 = g->boot0,
.dma_bits = (u8)g->dma_bits,
.read32 = nv_rs_platform_rmapi_read32,
.release = nv_rs_platform_rmapi_release,
.cookie = g,
};
int rmapi_err;
kref_get(&g->refcount);
rmapi_err = nv_rs_rmapi_node_gpu_add_desc(&rmapi_desc);
if (rmapi_err < 0) {
kref_put(&g->refcount, nv_rs_platform_free);
dev_warn(dev, "nvidia_rs: GV11B not listed on RM API control node (%d)\n",
rmapi_err);
} else {
g->rmapi_registered = true;
}
}
dev_info(dev,
"nvidia_rs: GV11B platform probe boot0=0x%08x boot42=0x%08x dma=%u-bit irq=%d\n",
g->boot0, g->boot42, g->dma_bits, g->irq_stall);
return 0;
fail_power:
nv_rs_platform_quiesce(g);
fail_alloc:
kref_put(&g->refcount, nv_rs_platform_free);
return err;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 11, 0)
static void nv_rs_platform_remove(struct platform_device *pdev)
#else
static int nv_rs_platform_remove(struct platform_device *pdev)
#endif
{
struct nv_rs_platform_gpu *g = platform_get_drvdata(pdev);
if (g) {
mutex_lock(&g->access);
WRITE_ONCE(g->removed, true);
mutex_unlock(&g->access);
platform_set_drvdata(pdev, NULL);
if (g->rmapi_registered)
nv_rs_rmapi_node_gpu_remove_by_bdf(NV_RS_PLAT_DOMAIN, NV_RS_PLAT_BUS,
NV_RS_PLAT_SLOT);
nv_rs_platform_quiesce(g);
kref_put(&g->refcount, nv_rs_platform_free);
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0)
return 0;
#endif
}
static const struct of_device_id nv_rs_platform_of_match[] = {
{ .compatible = "nvidia,gv11b" },
{ /* sentinel */ }
};
/* No MODULE_DEVICE_TABLE(of, ...): opt-in only (tegra_gv11b=1), never competes with nvgpu. */
static struct platform_driver nv_rs_platform_driver = {
.probe = nv_rs_platform_probe,
.remove = nv_rs_platform_remove,
.driver = {
.name = "nvidia_rs_gv11b",
.of_match_table = nv_rs_platform_of_match,
},
};
int nv_rs_platform_driver_register(void)
{
int err;
if (!tegra_gv11b)
return 0;
err = platform_driver_register(&nv_rs_platform_driver);
if (!err)
platform_driver_registered = true;
return err;
}
void nv_rs_platform_driver_unregister(void)
{
if (!platform_driver_registered)
return;
platform_driver_unregister(&nv_rs_platform_driver);
platform_driver_registered = false;
}