From faf6ff3f34566f09334ac8bdc86e9d0c7145cbdd Mon Sep 17 00:00:00 2001 From: Ramalingam C Date: Wed, 14 Dec 2022 10:05:04 +0000 Subject: [PATCH] gpu: nvgpu: Add pci driver support for NVGPU_NEXT_PCI_DEVICES Add the NVGPU_NEXT_PCI_DEVICES and NVGPU_NEXT_PCI_IDS into the list of the pci devices and pci ids. JIRA NVGPU-9348 Change-Id: I3d42eebc1a61f8821ef1f0f9a93262a4d84e8650 Signed-off-by: Ramalingam C Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2835338 GVS: Gerrit_Virtual_Submit Reviewed-by: Sagar Kamble Reviewed-by: Ankur Kishore --- drivers/gpu/nvgpu/os/linux/pci.c | 49 +++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/pci.c b/drivers/gpu/nvgpu/os/linux/pci.c index e6229e5f1..911cf1e50 100644 --- a/drivers/gpu/nvgpu/os/linux/pci.c +++ b/drivers/gpu/nvgpu/os/linux/pci.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2021, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016-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, @@ -48,6 +48,10 @@ #include "driver_common.h" #include "dmabuf_priv.h" +#if defined(CONFIG_NVGPU_HAL_NON_FUSA) && defined(CONFIG_NVGPU_NEXT) +#include +#endif + #define BOOT_GPC2CLK_MHZ 2581U static int nvgpu_pci_tegra_probe(struct device *dev) @@ -239,9 +243,33 @@ static struct gk20a_platform nvgpu_pci_device[] = { #endif .is_pci_igpu = false, }, - }; +static int nvgpu_pci_get_platform_data(struct gk20a_platform *platform, int index) +{ + struct gk20a_platform nvgpu_next_pci_device[] = { +#if defined(CONFIG_NVGPU_NEXT) && defined(CONFIG_NVGPU_NON_FUSA) + NVGPU_NEXT_PCI_DEVICES +#endif + }; + int device_cnt = ARRAY_SIZE(nvgpu_pci_device); + int next_device_cnt = ARRAY_SIZE(nvgpu_next_pci_device); + + if (index < device_cnt) { + nvgpu_memcpy((u8 *)platform, + (u8 *)&nvgpu_pci_device[index], + sizeof(struct gk20a_platform)); + } else if (index < device_cnt + next_device_cnt) { + nvgpu_memcpy((u8 *)platform, + (u8 *)&nvgpu_next_pci_device[index - device_cnt], + sizeof(struct gk20a_platform)); + } else { + return -EINVAL; + } + + return 0; +} + #define PCI_DEVICE_INDEX(driver_data) ((driver_data) & 0x0000FFFFU) #define PCI_DEVICE_FLAGS(driver_data) ((driver_data) & 0xFFFF0000U) @@ -325,6 +353,11 @@ static struct pci_device_id nvgpu_pci_table[] = { .class_mask = 0xff << 16, .driver_data = 3, }, +#ifdef CONFIG_NVGPU_NEXT +#if defined(CONFIG_NVGPU_HAL_NON_FUSA) && defined(CONFIG_NVGPU_NON_FUSA) + NVGPU_NEXT_PCI_IDS +#endif +#endif {} }; @@ -514,12 +547,6 @@ static int nvgpu_pci_probe(struct pci_dev *pdev, u32 device_index = PCI_DEVICE_INDEX(pent->driver_data); u32 device_flags = PCI_DEVICE_FLAGS(pent->driver_data); - /* make sure driver_data is a sane index */ - if (device_index >= sizeof(nvgpu_pci_device) / - sizeof(nvgpu_pci_device[0])) { - return -EINVAL; - } - l = kzalloc(sizeof(*l), GFP_KERNEL); if (!l) { dev_err(&pdev->dev, "couldn't allocate gk20a support"); @@ -544,9 +571,9 @@ static int nvgpu_pci_probe(struct pci_dev *pdev, } /* copy detected device data to allocated platform space*/ - nvgpu_memcpy((u8 *)platform, - (u8 *)&nvgpu_pci_device[device_index], - sizeof(struct gk20a_platform)); + err = nvgpu_pci_get_platform_data(platform, device_index); + if (err) + goto err_free_platform; g->is_pci_igpu = platform->is_pci_igpu;