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 <mkumbar@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1577913
GVS: Gerrit_Virtual_Submit
Reviewed-by: Vijayakumar Subbu <vsubbu@nvidia.com>
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
This commit is contained in:
Mahantesh Kumbar
2017-10-12 22:22:18 +05:30
committed by mobile promotions
parent 61b263d832
commit 0b6eb9fd80

View File

@@ -443,9 +443,6 @@ static int nvgpu_pci_probe(struct pci_dev *pdev,
return -EINVAL; return -EINVAL;
} }
platform = &nvgpu_pci_device[pent->driver_data];
pci_set_drvdata(pdev, platform);
l = kzalloc(sizeof(*l), GFP_KERNEL); l = kzalloc(sizeof(*l), GFP_KERNEL);
if (!l) { if (!l) {
dev_err(&pdev->dev, "couldn't allocate gk20a support"); 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); 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); err = nvgpu_init_enabled_flags(g);
if (err) { if (err) {
kfree(g); kfree(g);
@@ -563,6 +574,10 @@ static void nvgpu_pci_remove(struct pci_dev *pdev)
enable_irq(g->irq_stall); enable_irq(g->irq_stall);
} }
#endif #endif
/* free allocated platform data space */
nvgpu_kfree(g, gk20a_get_platform(&pdev->dev));
gk20a_get_platform(&pdev->dev)->g = NULL; gk20a_get_platform(&pdev->dev)->g = NULL;
gk20a_put(g); gk20a_put(g);
} }