From 0b6eb9fd80cf53b86de0f8ca4d12db7ead499e40 Mon Sep 17 00:00:00 2001 From: Mahantesh Kumbar Date: Thu, 12 Oct 2017 22:22:18 +0530 Subject: gpu: nvgpu: Allocate memory for dGPU platform - Allocate memory for platform data for each dgpu device detected on PCIe, - Copy detected device static data to allocated platform data - Free allocated space in nvgpu_pci_remove() Issue: Static platform data is overwritten When two same SKU/device-id dGPU connected on single platform which cause accessing wrong dGPU space, Fix: Fixing issue by allocating space dynamically for each dGPU device detected & copy data from detected dGPU static data. JIRA NVGPUGV100-18 Change-Id: Idf2d2d6d2016b831c21b9da6f8ee38b34304bd12 Signed-off-by: Mahantesh Kumbar Reviewed-on: https://git-master.nvidia.com/r/1577913 GVS: Gerrit_Virtual_Submit Reviewed-by: Vijayakumar Subbu Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/common/linux/pci.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/gpu/nvgpu/common/linux/pci.c b/drivers/gpu/nvgpu/common/linux/pci.c index 50d079bb..0ce2ceef 100644 --- a/drivers/gpu/nvgpu/common/linux/pci.c +++ b/drivers/gpu/nvgpu/common/linux/pci.c @@ -443,9 +443,6 @@ static int nvgpu_pci_probe(struct pci_dev *pdev, return -EINVAL; } - platform = &nvgpu_pci_device[pent->driver_data]; - pci_set_drvdata(pdev, platform); - l = kzalloc(sizeof(*l), GFP_KERNEL); if (!l) { dev_err(&pdev->dev, "couldn't allocate gk20a support"); @@ -456,6 +453,20 @@ static int nvgpu_pci_probe(struct pci_dev *pdev, nvgpu_kmem_init(g); + /* Allocate memory to hold platform data*/ + platform = (struct gk20a_platform *)nvgpu_kzalloc( g, + sizeof(struct gk20a_platform)); + if (!platform) { + dev_err(&pdev->dev, "couldn't allocate platform data"); + return -ENOMEM; + } + + /* copy detected device data to allocated platform space*/ + memcpy((void *)platform, (void *)&nvgpu_pci_device[pent->driver_data], + sizeof(struct gk20a_platform)); + + pci_set_drvdata(pdev, platform); + err = nvgpu_init_enabled_flags(g); if (err) { kfree(g); @@ -563,6 +574,10 @@ static void nvgpu_pci_remove(struct pci_dev *pdev) enable_irq(g->irq_stall); } #endif + + /* free allocated platform data space */ + nvgpu_kfree(g, gk20a_get_platform(&pdev->dev)); + gk20a_get_platform(&pdev->dev)->g = NULL; gk20a_put(g); } -- cgit v1.2.2