From b2c4cdb25baf7d16abaeefb669455b0d101018e1 Mon Sep 17 00:00:00 2001 From: Ramalingam C Date: Tue, 31 Jan 2023 14:48:21 +0000 Subject: [PATCH] gpu: nvgpu: sim init for iGPU-PCIe Implement the sim init for the iGPU-PCIe devices. JIRA NVGPU-9348 Change-Id: I9088308b96c57bb1cea01959326446ccad0a8c24 Signed-off-by: Ramalingam C Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2851163 Reviewed-by: svcacv Reviewed-by: Sagar Kamble Reviewed-by: Seema Khowala GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/include/nvgpu/linux/sim.h | 5 ++- drivers/gpu/nvgpu/os/linux/pci.c | 32 +++++++++++++------ drivers/gpu/nvgpu/os/linux/platform_gk20a.h | 5 +++ drivers/gpu/nvgpu/os/linux/sim.c | 35 ++++++++++++++++++++- 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/sim.h b/drivers/gpu/nvgpu/include/nvgpu/linux/sim.h index 28a62b3b4..2d4ea141b 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/linux/sim.h +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/sim.h @@ -2,7 +2,7 @@ * * nvgpu sim support * - * Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -21,6 +21,7 @@ #define __SIM_LINUX_H__ struct platform_device; +struct gk20a_platform; struct sim_nvgpu_linux { struct sim_nvgpu sim; @@ -30,5 +31,7 @@ struct sim_nvgpu_linux { int nvgpu_init_sim_support_linux(struct gk20a *g, struct platform_device *dev); +int nvgpu_init_sim_support_linux_igpu_pci(struct gk20a *g, + struct gk20a_platform *platform); void nvgpu_remove_sim_support_linux(struct gk20a *g); #endif diff --git a/drivers/gpu/nvgpu/os/linux/pci.c b/drivers/gpu/nvgpu/os/linux/pci.c index 629c954cf..034f1cb54 100644 --- a/drivers/gpu/nvgpu/os/linux/pci.c +++ b/drivers/gpu/nvgpu/os/linux/pci.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "nvlink.h" #include "module.h" @@ -394,8 +395,9 @@ static irqreturn_t nvgpu_pci_intr_thread(int irq, void *dev_id) return IRQ_HANDLED; } -static int nvgpu_pci_init_support(struct pci_dev *pdev) +static int nvgpu_pci_init_support(struct pci_dev *pdev, bool is_pci_igpu) { + struct gk20a_platform *platform = pci_get_drvdata(pdev); int err = 0; struct gk20a *g = get_gk20a(&pdev->dev); struct device *dev = &pdev->dev; @@ -427,17 +429,29 @@ static int nvgpu_pci_init_support(struct pci_dev *pdev) } g->bar1 = (uintptr_t)addr; - err = nvgpu_init_sim_support_linux_pci(g); - if (err) - goto fail; - err = nvgpu_init_sim_support_pci(g); - if (err) - goto fail_sim; + if (is_pci_igpu) { + err = nvgpu_init_sim_support_linux_igpu_pci(g, platform); + if (err) + goto fail; + err = nvgpu_init_sim_support(g); + if (err) + goto fail_sim; + } else { + err = nvgpu_init_sim_support_linux_pci(g); + if (err) + goto fail; + err = nvgpu_init_sim_support_pci(g); + if (err) + goto fail_sim; + } return 0; fail_sim: - nvgpu_remove_sim_support_linux_pci(g); + if (is_pci_igpu) + nvgpu_remove_sim_support_linux(g); + else + nvgpu_remove_sim_support_linux_pci(g); fail: if (g->regs) g->regs = 0U; @@ -675,7 +689,7 @@ static int nvgpu_pci_probe(struct pci_dev *pdev, } nvgpu_disable_irqs(g); - err = nvgpu_pci_init_support(pdev); + err = nvgpu_pci_init_support(pdev, g->is_pci_igpu); if (err) goto err_free_irq; diff --git a/drivers/gpu/nvgpu/os/linux/platform_gk20a.h b/drivers/gpu/nvgpu/os/linux/platform_gk20a.h index 54a71d09f..6f9bc46e8 100644 --- a/drivers/gpu/nvgpu/os/linux/platform_gk20a.h +++ b/drivers/gpu/nvgpu/os/linux/platform_gk20a.h @@ -358,6 +358,11 @@ struct gk20a_platform { /* Check if igpu is available as pci device. */ bool is_pci_igpu; + +#ifdef CONFIG_NVGPU_SIM + u32 fake_rpc_base; + u32 fake_rpc_size; +#endif }; static inline struct gk20a_platform *gk20a_get_platform( diff --git a/drivers/gpu/nvgpu/os/linux/sim.c b/drivers/gpu/nvgpu/os/linux/sim.c index fb0f551e2..eca32e246 100644 --- a/drivers/gpu/nvgpu/os/linux/sim.c +++ b/drivers/gpu/nvgpu/os/linux/sim.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -80,3 +80,36 @@ fail: nvgpu_remove_sim_support_linux(g); return err; } + +int nvgpu_init_sim_support_linux_igpu_pci(struct gk20a *g, + struct gk20a_platform *platform) +{ + struct device *dev = dev_from_gk20a(g); + struct sim_nvgpu_linux *sim_linux; + void __iomem *addr; + int err = -ENOMEM; + + if (!nvgpu_platform_is_simulation(g)) + return 0; + + sim_linux = nvgpu_kzalloc(g, sizeof(*sim_linux)); + if (!sim_linux) + return err; + g->sim = &sim_linux->sim; + g->sim->g = g; + addr = nvgpu_devm_ioremap(dev, + (resource_size_t)platform->fake_rpc_base, + (resource_size_t)platform->fake_rpc_size); + if (IS_ERR(addr)) { + nvgpu_err(g, "failed to remap gpu sim regs"); + err = PTR_ERR(addr); + goto fail; + } + g->sim->regs = (uintptr_t)addr; + sim_linux->remove_support_linux = nvgpu_remove_sim_support_linux; + return 0; + +fail: + nvgpu_remove_sim_support_linux(g); + return err; +}