From 5a7a662974f2b2c5285de6f124fc343a612f9e4a Mon Sep 17 00:00:00 2001 From: Chris Dragan Date: Mon, 15 Oct 2018 01:59:05 -0700 Subject: [PATCH] misc: mods: update MODS driver from Perforce Bug 2418720 Change-Id: If2c51596a576ea11fd514c9bd6090b871d25c524 Signed-off-by: Chris Dragan Reviewed-on: https://git-master.nvidia.com/r/1927063 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Bharat Nihalani Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/misc/mods/mods.h | 21 +++++++- drivers/misc/mods/mods_acpi.c | 11 ++-- drivers/misc/mods/mods_debugfs.c | 1 + drivers/misc/mods/mods_internal.h | 1 + drivers/misc/mods/mods_irq.c | 39 +++++++------- drivers/misc/mods/mods_krnl.c | 63 +++++++++++++++++++---- drivers/misc/mods/mods_mem.c | 84 ++++++++++++++++++------------- drivers/misc/mods/mods_pci.c | 23 +++++---- 8 files changed, 162 insertions(+), 81 deletions(-) diff --git a/drivers/misc/mods/mods.h b/drivers/misc/mods/mods.h index 79cb5183..d484cd23 100644 --- a/drivers/misc/mods/mods.h +++ b/drivers/misc/mods/mods.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * mods.h - This file is part of NVIDIA MODS kernel driver. * @@ -24,7 +25,7 @@ /* Driver version */ #define MODS_DRIVER_VERSION_MAJOR 3 -#define MODS_DRIVER_VERSION_MINOR 87 +#define MODS_DRIVER_VERSION_MINOR 88 #define MODS_DRIVER_VERSION ((MODS_DRIVER_VERSION_MAJOR << 8) | \ ((MODS_DRIVER_VERSION_MINOR/10) << 4) | \ (MODS_DRIVER_VERSION_MINOR%10)) @@ -1071,6 +1072,19 @@ struct MODS_SET_NUM_VF { __u32 numvfs; /* number of virtual functions */ }; +/* MODS_ESC_READ_MSR + * MODS_ESC_WRITE_MSR + */ +struct MODS_MSR { + /* IN */ + __u32 reg; + __u32 cpu_num; + + /* IN/OUT */ + __u32 low; + __u32 high; +}; + #pragma pack(pop) /* ************************************************************************* */ @@ -1338,5 +1352,8 @@ struct MODS_SET_NUM_VF { _IOW(MODS_IOC_MAGIC, 118, struct MODS_PCI_DMA_MASK) #define MODS_ESC_GET_IOMMU_STATE_2 \ _IOWR(MODS_IOC_MAGIC, 119, struct MODS_GET_IOMMU_STATE) - +#define MODS_ESC_READ_MSR \ + _IOWR(MODS_IOC_MAGIC, 120, struct MODS_MSR) +#define MODS_ESC_WRITE_MSR \ + _IOW(MODS_IOC_MAGIC, 121, struct MODS_MSR) #endif /* _MODS_H_ */ diff --git a/drivers/misc/mods/mods_acpi.c b/drivers/misc/mods/mods_acpi.c index 90974ec9..e2ceb927 100644 --- a/drivers/misc/mods/mods_acpi.c +++ b/drivers/misc/mods/mods_acpi.c @@ -1,7 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * mods_acpi.c - This file is part of NVIDIA MODS kernel driver. * - * Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2008-2018, NVIDIA CORPORATION. All rights reserved. * * NVIDIA MODS kernel driver is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License, @@ -178,7 +179,7 @@ static int mods_eval_acpi_method(struct file *pfile, struct pci_dev *dev; mods_debug_printk(DEBUG_ACPI, - "ACPI %s for device %04x:%x:%02x.%x\n", + "ACPI %s for device %04x:%02x:%02x.%x\n", p->method_name, (unsigned int)pdevice->domain, (unsigned int)pdevice->bus, @@ -279,7 +280,7 @@ static int mods_acpi_get_ddc(struct file *pfile, acpi_handle lcd_dev_handle = NULL; mods_debug_printk(DEBUG_ACPI, - "ACPI _DDC (EDID) for device %04x:%x:%02x.%x\n", + "ACPI _DDC (EDID) for device %04x:%02x:%02x.%x\n", (unsigned int)pci_device->domain, (unsigned int)pci_device->bus, (unsigned int)pci_device->device, @@ -338,7 +339,7 @@ static int mods_acpi_get_ddc(struct file *pfile, lcd_dev_handle = dev->handle; mods_debug_printk(DEBUG_ACPI, - "ACPI: Found LCD 0x%x on device %04x:%x:%02x.%x\n", + "ACPI: Found LCD 0x%x on device %04x:%02x:%02x.%x\n", (unsigned int)device_id, (unsigned int)p->device.domain, (unsigned int)p->device.bus, @@ -351,7 +352,7 @@ static int mods_acpi_get_ddc(struct file *pfile, if (lcd_dev_handle == NULL) { mods_error_printk( - "ACPI: LCD not found for device %04x:%x:%02x.%x\n", + "ACPI: LCD not found for device %04x:%02x:%02x.%x\n", (unsigned int)p->device.domain, (unsigned int)p->device.bus, (unsigned int)p->device.device, diff --git a/drivers/misc/mods/mods_debugfs.c b/drivers/misc/mods/mods_debugfs.c index 1b7cfe26..6b04bb18 100644 --- a/drivers/misc/mods/mods_debugfs.c +++ b/drivers/misc/mods/mods_debugfs.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* * mods_debugfs.c - This file is part of NVIDIA MODS kernel driver. * diff --git a/drivers/misc/mods/mods_internal.h b/drivers/misc/mods/mods_internal.h index e413d6f4..e1d358a1 100644 --- a/drivers/misc/mods/mods_internal.h +++ b/drivers/misc/mods/mods_internal.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * mods_internal.h - This file is part of NVIDIA MODS kernel driver. * diff --git a/drivers/misc/mods/mods_irq.c b/drivers/misc/mods/mods_irq.c index c52ac72e..410e85e4 100644 --- a/drivers/misc/mods/mods_irq.c +++ b/drivers/misc/mods/mods_irq.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* * mods_irq.c - This file is part of NVIDIA MODS kernel driver. * @@ -69,7 +70,7 @@ struct en_dev_entry *mods_enable_device(struct mods_client *client, if (dpriv->client_id == client->client_id) return dpriv; - mods_error_printk("invalid client %u for device %04x:%x:%02x.%x\n", + mods_error_printk("invalid client %u for device %04x:%02x:%02x.%x\n", (unsigned int)client->client_id, pci_domain_nr(dev->bus), dev->bus->number, @@ -81,7 +82,7 @@ struct en_dev_entry *mods_enable_device(struct mods_client *client, ret = pci_enable_device(dev); if (ret != 0) { - mods_error_printk("failed to enable device %04x:%x:%02x.%x\n", + mods_error_printk("failed to enable device %04x:%02x:%02x.%x\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -244,7 +245,7 @@ static int rec_irq_done(struct dev_irq_map *t, #ifdef CONFIG_PCI if (t->dev) { mods_debug_printk(DEBUG_ISR_DETAILED, - "%04x:%x:%02x.%x %s IRQ 0x%x time=%uus\n", + "%04x:%02x:%02x.%x %s IRQ 0x%x time=%uus\n", (unsigned int)(pci_domain_nr(t->dev->bus)), (unsigned int)(t->dev->bus->number), (unsigned int)PCI_SLOT(t->dev->devfn), @@ -403,7 +404,7 @@ static int add_irq_map(u8 client_id, LOG_ENT(); /* Allocate memory for the new entry */ - newmap = kmalloc(sizeof(*newmap), GFP_KERNEL | __GFP_NORETRY); + newmap = kzalloc(sizeof(*newmap), GFP_KERNEL | __GFP_NORETRY); if (unlikely(!newmap)) { LOG_EXT(); return -ENOMEM; @@ -462,7 +463,7 @@ static int add_irq_map(u8 client_id, (irq_type == MODS_IRQ_TYPE_MSI) || (irq_type == MODS_IRQ_TYPE_MSIX)) { mods_debug_printk(DEBUG_ISR, - "%04x:%x:%02x.%x registered %s IRQ 0x%x\n", + "%04x:%02x:%02x.%x registered %s IRQ 0x%x\n", (unsigned int)(pci_domain_nr(pdev->bus)), (unsigned int)(pdev->bus->number), (unsigned int)PCI_SLOT(pdev->devfn), @@ -487,7 +488,7 @@ static int add_irq_map(u8 client_id, MSI_DATA_REG(cap_pos, 0), &data); mods_debug_printk(DEBUG_ISR, - "%04x:%x:%02x.%x registered MSI IRQ 0x%x data:0x%02x\n", + "%04x:%02x:%02x.%x registered MSI IRQ 0x%x data:0x%02x\n", (unsigned int)(pci_domain_nr(pdev->bus)), (unsigned int)(pdev->bus->number), (unsigned int)PCI_SLOT(pdev->devfn), @@ -496,7 +497,7 @@ static int add_irq_map(u8 client_id, (unsigned int)data); } else if (irq_type == MODS_IRQ_TYPE_MSIX) { mods_debug_printk(DEBUG_ISR, - "%04x:%x:%02x.%x registered MSI-X IRQ 0x%x\n", + "%04x:%02x:%02x.%x registered MSI-X IRQ 0x%x\n", (unsigned int)(pci_domain_nr(pdev->bus)), (unsigned int)(pdev->bus->number), (unsigned int)PCI_SLOT(pdev->devfn), @@ -639,7 +640,7 @@ static int mods_free_irqs(u8 client_id, struct pci_dev *dev) } if (dpriv->client_id != client_id) { - mods_error_printk("invalid client %u for device %04x:%x:%02x.%x\n", + mods_error_printk("invalid client %u for device %04x:%02x:%02x.%x\n", (unsigned int)client_id, pci_domain_nr(dev->bus), dev->bus->number, @@ -651,7 +652,7 @@ static int mods_free_irqs(u8 client_id, struct pci_dev *dev) } mods_debug_printk(DEBUG_ISR_DETAILED, - "(dev=%04x:%x:%02x.%x) irq_flags=0x%x nvecs=%d\n", + "(dev=%04x:%02x:%02x.%x) irq_flags=0x%x nvecs=%d\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -667,7 +668,7 @@ static int mods_free_irqs(u8 client_id, struct pci_dev *dev) list_del(&del->list); mods_debug_printk(DEBUG_ISR, - "%04x:%x:%02x.%x unregistered %s IRQ 0x%x\n", + "%04x:%02x:%02x.%x unregistered %s IRQ 0x%x\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -747,7 +748,7 @@ static int mods_allocate_irqs(u8 client_id, struct file *pfile, LOG_ENT(); mods_debug_printk(DEBUG_ISR_DETAILED, - "(dev=%04x:%x:%02x.%x, flags=0x%x, nvecs=%d)\n", + "(dev=%04x:%02x:%02x.%x, flags=0x%x, nvecs=%d)\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -760,7 +761,7 @@ static int mods_allocate_irqs(u8 client_id, struct file *pfile, #ifdef CONFIG_PCI_MSI if (pci_find_capability(dev, PCI_CAP_ID_MSI) == 0) { mods_error_printk( - "dev %04x:%x:%02x.%x does not support MSI\n", + "dev %04x:%02x:%02x.%x does not support MSI\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -776,7 +777,7 @@ static int mods_allocate_irqs(u8 client_id, struct file *pfile, #ifdef CONFIG_PCI_MSI if (pci_find_capability(dev, PCI_CAP_ID_MSIX) == 0) { mods_error_printk( - "dev %04x:%x:%02x.%x does not support MSI-X\n", + "dev %04x:%02x:%02x.%x does not support MSI-X\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -818,7 +819,7 @@ static int mods_allocate_irqs(u8 client_id, struct file *pfile, } if (pci_enable_msi(dev) != 0) { mods_error_printk( - "unable to enable MSI on dev %04x:%x:%02x.%x\n", + "unable to enable MSI on dev %04x:%02x:%02x.%x\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -891,7 +892,7 @@ static int mods_allocate_irqs(u8 client_id, struct file *pfile, } #endif else { - mods_error_printk("unsupported irq_type %d dev: %04x:%x:%02x.%x\n", + mods_error_printk("unsupported irq_type %d dev: %04x:%02x:%02x.%x\n", irq_type, pci_domain_nr(dev->bus), dev->bus->number, @@ -933,7 +934,7 @@ static int mods_register_pci_irq(struct file *pfile, dev = MODS_PCI_GET_SLOT(p->dev.domain, p->dev.bus, devfn); if (!dev) { mods_error_printk( - "unknown dev %04x:%x:%02x.%x\n", + "unknown dev %04x:%02x:%02x.%x\n", (unsigned int)p->dev.domain, (unsigned int)p->dev.bus, (unsigned int)p->dev.device, @@ -956,7 +957,7 @@ static int mods_register_pci_irq(struct file *pfile, dpriv = pci_get_drvdata(dev); if (dpriv) { if (dpriv->client_id != client_id) { - mods_error_printk("dev %04x:%x:%02x.%x already owned by client %u\n", + mods_error_printk("dev %04x:%02x:%02x.%x already owned by client %u\n", (unsigned int)p->dev.domain, (unsigned int)p->dev.bus, (unsigned int)p->dev.device, @@ -967,7 +968,7 @@ static int mods_register_pci_irq(struct file *pfile, return -EINVAL; } if (dpriv->nvecs) { - mods_error_printk("interrupt for dev %04x:%x:%02x.%x already registered\n", + mods_error_printk("interrupt for dev %04x:%02x:%02x.%x already registered\n", (unsigned int)p->dev.domain, (unsigned int)p->dev.bus, (unsigned int)p->dev.device, @@ -1319,7 +1320,7 @@ int esc_mods_query_irq_3(struct file *pfile, struct MODS_QUERY_IRQ_3 *p) /* Print info about IRQ status returned */ if (dev) { mods_debug_printk(DEBUG_ISR_DETAILED, - "retrieved IRQ index=%d dev %04x:%x:%02x.%x, time=%uus, delay=%uus\n", + "retrieved IRQ index=%d dev %04x:%02x:%02x.%x, time=%uus, delay=%uus\n", p->irq_list[i].irq_index, (unsigned int)p->irq_list[i].dev.domain, (unsigned int)p->irq_list[i].dev.bus, diff --git a/drivers/misc/mods/mods_krnl.c b/drivers/misc/mods/mods_krnl.c index 21dfbd6a..15e13ac2 100644 --- a/drivers/misc/mods/mods_krnl.c +++ b/drivers/misc/mods/mods_krnl.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* * mods_krnl.c - This file is part of NVIDIA MODS kernel driver. * @@ -35,6 +36,9 @@ # include # include #endif +#ifdef MODS_HAS_MSR +# include +#endif /*********************************************************************** * mods_krnl_* functions, driver interfaces called by the Linux kernel * @@ -174,7 +178,7 @@ static int esc_mods_set_num_vf(struct file *pfile, struct MODS_SET_NUM_VF *p) dev = MODS_PCI_GET_SLOT(p->dev.domain, p->dev.bus, devfn); if (!dev) { mods_error_printk( - "unknown dev %04x:%x:%02x.%x\n", + "unknown dev %04x:%02x:%02x.%x\n", (unsigned int)p->dev.domain, (unsigned int)p->dev.bus, (unsigned int)p->dev.device, @@ -206,7 +210,7 @@ static int esc_mods_set_total_vf(struct file *pfile, struct MODS_SET_NUM_VF *p) dev = MODS_PCI_GET_SLOT(p->dev.domain, p->dev.bus, devfn); if (!dev) { mods_error_printk( - "unknown dev %04x:%x:%02x.%x\n", + "unknown dev %04x:%02x:%02x.%x\n", (unsigned int)p->dev.domain, (unsigned int)p->dev.bus, (unsigned int)p->dev.device, @@ -439,12 +443,11 @@ static int mods_register_mapping( LOG_ENT(); - p_map_mem = kmalloc(sizeof(*p_map_mem), GFP_KERNEL | __GFP_NORETRY); + p_map_mem = kzalloc(sizeof(*p_map_mem), GFP_KERNEL | __GFP_NORETRY); if (unlikely(!p_map_mem)) { LOG_EXT(); return -ENOMEM; } - memset(p_map_mem, 0, sizeof(*p_map_mem)); p_map_mem->dma_addr = dma_addr; p_map_mem->virtual_addr = virtual_address; @@ -574,7 +577,7 @@ static pci_ers_result_t mods_pci_error_detected(struct pci_dev *dev, enum pci_channel_state state) { mods_debug_printk(DEBUG_PCI, - "pci_error_detected %04x:%x:%02x.%x\n", + "pci_error_detected %04x:%02x:%02x.%x\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -586,7 +589,7 @@ static pci_ers_result_t mods_pci_error_detected(struct pci_dev *dev, static pci_ers_result_t mods_pci_mmio_enabled(struct pci_dev *dev) { mods_debug_printk(DEBUG_PCI, - "pci_mmio_enabled %04x:%x:%02x.%x\n", + "pci_mmio_enabled %04x:%02x:%02x.%x\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -598,7 +601,7 @@ static pci_ers_result_t mods_pci_mmio_enabled(struct pci_dev *dev) static void mods_pci_resume(struct pci_dev *dev) { mods_debug_printk(DEBUG_PCI, - "pci_resume %04x:%x:%02x.%x\n", + "pci_resume %04x:%02x:%02x.%x\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -762,7 +765,7 @@ static int mods_krnl_mmap(struct file *fp, struct vm_area_struct *vma) vma->vm_ops = &mods_krnl_vm_ops; - vma_private_data = kmalloc(sizeof(*vma_private_data), + vma_private_data = kzalloc(sizeof(*vma_private_data), GFP_KERNEL | __GFP_NORETRY); if (unlikely(!vma_private_data)) { LOG_EXT(); @@ -1273,6 +1276,36 @@ static int esc_mods_write_sysfs_node(struct file *pfile, return ret; } +#ifdef MODS_HAS_MSR +static int esc_mods_read_msr(struct file *pfile, struct MODS_MSR *p) +{ + int ret = -EINVAL; + + LOG_ENT(); + + ret = rdmsr_safe_on_cpu(p->cpu_num, p->reg, &p->low, &p->high); + if (ret < 0) + mods_error_printk("Could not read MSR %u\n", p->reg); + + LOG_EXT(); + return ret; +} + +static int esc_mods_write_msr(struct file *pfile, struct MODS_MSR *p) +{ + int ret = -EINVAL; + + LOG_ENT(); + + ret = wrmsr_safe_on_cpu(p->cpu_num, p->reg, p->low, p->high); + if (ret < 0) + mods_error_printk("Could not write MSR %u\n", p->reg); + + LOG_EXT(); + return ret; +} +#endif + /************** * IO control * **************/ @@ -1301,7 +1334,7 @@ static long mods_krnl_ioctl(struct file *fp, arg_size = _IOC_SIZE(cmd); if (arg_size > (int)sizeof(buf)) { - arg_copy = kmalloc(arg_size, GFP_KERNEL | __GFP_NORETRY); + arg_copy = kzalloc(arg_size, GFP_KERNEL | __GFP_NORETRY); if (unlikely(!arg_copy)) { LOG_EXT(); return -ENOMEM; @@ -1987,6 +2020,18 @@ static long mods_krnl_ioctl(struct file *fp, break; #endif +#ifdef MODS_HAS_MSR + case MODS_ESC_READ_MSR: + MODS_IOCTL(MODS_ESC_READ_MSR, + esc_mods_read_msr, MODS_MSR); + break; + + case MODS_ESC_WRITE_MSR: + MODS_IOCTL_NORETVAL(MODS_ESC_WRITE_MSR, + esc_mods_write_msr, MODS_MSR); + break; +#endif + default: mods_error_printk("unrecognized ioctl (0x%x) dir(0x%x) type (0x%x) nr (0x%x) size (0x%x)\n", cmd, _IOC_DIR(cmd), _IOC_TYPE(cmd), diff --git a/drivers/misc/mods/mods_mem.c b/drivers/misc/mods/mods_mem.c index 09c96d88..2e5bbd9a 100644 --- a/drivers/misc/mods/mods_mem.c +++ b/drivers/misc/mods/mods_mem.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* * mods_mem.c - This file is part of NVIDIA MODS kernel driver. * @@ -58,7 +59,7 @@ static void mods_dma_unmap_page(struct MODS_DMA_MAP *p_dma_map, DMA_BIDIRECTIONAL); mods_debug_printk(DEBUG_MEM_DETAILED, - "Unmapped map_addr=0x%llx dma_addr=0x%llx on dev %x:%x:%x.%x\n", + "dma unmap map_addr=0x%llx dma_addr=0x%llx on dev %04x:%02x:%02x.%x\n", (unsigned long long)pm->map_addr, (unsigned long long)pm->pt->dma_addr, pci_domain_nr(p_dma_map->dev->bus), @@ -161,8 +162,7 @@ static void mods_dma_map_pages(struct MODS_MEM_INFO *p_mem_info, pm->map_addr); mods_debug_printk(DEBUG_MEM_DETAILED, - "%s : Mapped map_addr=0x%llx, dma_addr=0x%llx on dev %x:%x:%x.%x\n", - __func__, + "dma map map_addr=0x%llx, dma_addr=0x%llx on dev %04x:%02x:%02x.%x\n", (unsigned long long)pm->map_addr, (unsigned long long)pt->dma_addr, pci_domain_nr(p_dma_map->dev->bus), @@ -185,14 +185,12 @@ static int mods_create_dma_map(struct MODS_MEM_INFO *p_mem_info, (p_mem_info->max_chunks - 1) * sizeof(struct MODS_MAP_CHUNK); - p_dma_map = kmalloc(alloc_size, GFP_KERNEL | __GFP_NORETRY); + p_dma_map = kzalloc(alloc_size, GFP_KERNEL | __GFP_NORETRY); if (unlikely(!p_dma_map)) { mods_error_printk("failed to allocate device map data\n"); return -ENOMEM; } - memset(p_dma_map, 0, alloc_size); - p_dma_map->dev = p_pci_dev; mods_dma_map_pages(p_mem_info, p_dma_map); list_add(&p_dma_map->list, &p_mem_info->dma_map_list); @@ -304,7 +302,7 @@ static gfp_t mods_alloc_flags(struct MODS_MEM_INFO *p_mem_info) if (p_mem_info->alloc_type != MODS_ALLOC_TYPE_NON_CONTIG) flags |= __GFP_COMP; - if ((p_mem_info->addr_bits & 0xFF) == 32) + if (p_mem_info->addr_bits == 32) #ifdef MODS_HAS_DMA32 flags |= __GFP_DMA32; #else @@ -366,16 +364,18 @@ static int mods_alloc_contig_sys_pages(struct MODS_MEM_INFO *p_mem_info) p_mem_info->pages[0].dma_addr = MODS_PHYS_TO_DMA(phys_addr); mods_debug_printk(DEBUG_MEM, - "alloc contig 0x%lx bytes%s, 2^%u pages, %s, phys 0x%llx\n", + "alloc contig 0x%lx bytes%s, 2^%u pages, %s, node %d, addrbits %u, phys 0x%llx\n", (unsigned long)p_mem_info->length, p_mem_info->alloc_type == MODS_ALLOC_TYPE_BIGPHYS_AREA ? " bigphys" : "", p_mem_info->pages[0].order, mods_get_prot_str(p_mem_info->cache_type), + p_mem_info->numa_node, + (unsigned int)p_mem_info->addr_bits, (unsigned long long)p_mem_info->pages[0].dma_addr); end_addr = p_mem_info->pages[0].dma_addr + p_mem_info->length; - if (((p_mem_info->addr_bits & 0xFF) == 32) && + if ((p_mem_info->addr_bits == 32) && (end_addr > 0x100000000ULL)) { mods_error_printk("allocation exceeds 32-bit addressing\n"); mods_free_pages(p_mem_info); @@ -444,11 +444,13 @@ static int mods_alloc_noncontig_sys_pages(struct MODS_MEM_INFO *p_mem_info) } pt->dma_addr = MODS_PHYS_TO_DMA(phys_addr); mods_debug_printk(DEBUG_MEM, - "alloc 0x%lx bytes [%u], 2^%u pages, %s, phys 0x%llx\n", + "alloc 0x%lx bytes [%u], 2^%u pages, %s, node %d, addrbits %u, phys 0x%llx\n", (unsigned long)p_mem_info->length, (unsigned int)num_chunks, pt->order, mods_get_prot_str(p_mem_info->cache_type), + p_mem_info->numa_node, + (unsigned int)p_mem_info->addr_bits, (unsigned long long)pt->dma_addr); ++num_chunks; @@ -698,7 +700,7 @@ int esc_mods_device_alloc_pages_2(struct file *fp, alloc_size = sizeof(*p_mem_info) + (max_chunks - 1) * sizeof(struct MODS_PHYS_CHUNK); - p_mem_info = kmalloc(alloc_size, GFP_KERNEL | __GFP_NORETRY); + p_mem_info = kzalloc(alloc_size, GFP_KERNEL | __GFP_NORETRY); if (unlikely(!p_mem_info)) { mods_error_printk("failed to allocate auxiliary 0x%x bytes\n", alloc_size); @@ -740,7 +742,8 @@ int esc_mods_device_alloc_pages_2(struct file *fp, p_mem_info->numa_node = 0; #endif mods_debug_printk(DEBUG_MEM_DETAILED, - "affinity %x:%x.%x node %d\n", + "affinity %04x:%02x:%02x.%x node %d\n", + p->pci_device.domain, p->pci_device.bus, p->pci_device.device, p->pci_device.function, @@ -749,22 +752,21 @@ int esc_mods_device_alloc_pages_2(struct file *fp, p->memory_handle = 0; - if (p->contiguous) { - if (mods_alloc_contig_sys_pages(p_mem_info)) { - mods_error_printk( - "failed to alloc 0x%x contiguous bytes\n", - p_mem_info->length); - ret = -ENOMEM; - goto failed; - } - } else { - if (mods_alloc_noncontig_sys_pages(p_mem_info)) { - mods_error_printk( - "failed to alloc 0x%x noncontiguous bytes\n", - p_mem_info->length); - ret = -ENOMEM; - goto failed; - } + if (p->contiguous) + ret = mods_alloc_contig_sys_pages(p_mem_info); + else + ret = mods_alloc_noncontig_sys_pages(p_mem_info); + + if (ret) { + mods_error_printk( + "failed to alloc 0x%x %s bytes, %s, node %d, addrbits %u\n", + p_mem_info->length, + p->contiguous ? "contiguous" : "non-contiguous", + mods_get_prot_str(p_mem_info->cache_type), + p_mem_info->numa_node, + (unsigned int)p_mem_info->addr_bits); + ret = -ENOMEM; + goto failed; } #if defined(CONFIG_PPC64) @@ -931,7 +933,8 @@ int esc_mods_get_phys_addr_2(struct file *fp, pt = mods_find_phys_chunk(p_mem_info, p->offset, &chunk_offset); if (!pt || !pt->allocated) { - mods_error_printk("invalid offset requested\n"); + mods_error_printk("invalid offset 0x%llx requested for allocation %p\n", + p->offset, p_mem_info); LOG_EXT(); return -EINVAL; } @@ -1012,7 +1015,8 @@ int esc_mods_get_mapped_phys_addr_3(struct file *fp, pt = mods_find_phys_chunk(p_mem_info, p->offset, &chunk_offset); if (!pt || !pt->allocated) { - mods_error_printk("invalid offset requested\n"); + mods_error_printk("invalid offset 0x%llx requested for allocation %p\n", + p->offset, p_mem_info); LOG_EXT(); return -EINVAL; } @@ -1036,7 +1040,8 @@ int esc_mods_get_mapped_phys_addr_3(struct file *fp, pm = mods_find_dma_map_chunk(p_mem_info, dev, pt); if (!pm) { - mods_error_printk("invalid device mapping requested\n"); + mods_error_printk("invalid device mapping requested for allocation %p\n", + p_mem_info); LOG_EXT(); return -EINVAL; } @@ -1124,7 +1129,8 @@ int esc_mods_virtual_to_phys(struct file *fp, mutex_unlock(&client->mtx); - mods_error_printk("invalid virtual address\n"); + mods_error_printk("invalid virtual address 0x%llx\n", + p->virtual_address); return -EINVAL; } @@ -1232,14 +1238,18 @@ int esc_mods_dma_map_memory(struct file *fp, devfn); if (!p_pci_dev) { - mods_error_printk("pci device not found\n"); + mods_error_printk("pci device %04x:%02x:%02x.%x not found\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); return -EINVAL; } p_map_chunk = mods_find_dma_map_chunk(p_mem_info, p_pci_dev, NULL); if (p_map_chunk) { mods_debug_printk(DEBUG_MEM_DETAILED, - "memory %p already mapped to dev %x:%x:%x.%x\n", + "memory %p already mapped to dev %04x:%02x:%02x.%x\n", p_mem_info, p->pci_device.domain, p->pci_device.bus, @@ -1275,7 +1285,11 @@ int esc_mods_dma_unmap_memory(struct file *fp, devfn); if (!p_pci_dev) { - mods_error_printk("pci device not found\n"); + mods_error_printk("pci device %04x:%02x:%02x.%x not found\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); return -EINVAL; } diff --git a/drivers/misc/mods/mods_pci.c b/drivers/misc/mods/mods_pci.c index 2c701655..4cbf7450 100644 --- a/drivers/misc/mods/mods_pci.c +++ b/drivers/misc/mods/mods_pci.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* * mods_pci.c - This file is part of NVIDIA MODS kernel driver. * @@ -155,7 +156,7 @@ int esc_mods_pci_get_bar_info_2(struct file *pfile, return -EINVAL; mods_debug_printk(DEBUG_PCI, - "pci get bar info %04x:%x:%02x:%x, bar index %d\n", + "pci get bar info %04x:%02x:%02x:%x, bar index %d\n", (int) p->pci_device.domain, (int) p->pci_device.bus, (int) p->pci_device.device, (int) p->pci_device.function, (int) p->bar_index); @@ -238,7 +239,7 @@ int esc_mods_pci_get_irq_2(struct file *pfile, return -EINVAL; mods_debug_printk(DEBUG_PCI, - "pci get irq %04x:%x:%02x:%x\n", + "pci get irq %04x:%02x:%02x:%x\n", (int) p->pci_device.domain, (int) p->pci_device.bus, (int) p->pci_device.device, (int) p->pci_device.function); @@ -279,7 +280,7 @@ int esc_mods_pci_read_2(struct file *pfile, struct MODS_PCI_READ_2 *p) return -EINVAL; mods_debug_printk(DEBUG_PCI, - "pci read %04x:%x:%02x.%x, addr 0x%04x, size %d\n", + "pci read %04x:%02x:%02x.%x, addr 0x%04x, size %d\n", (int) p->pci_device.domain, (int) p->pci_device.bus, (int) p->pci_device.device, (int) p->pci_device.function, (int) p->address, @@ -336,7 +337,7 @@ int esc_mods_pci_write_2(struct file *pfile, struct MODS_PCI_WRITE_2 *p) unsigned int devfn; mods_debug_printk(DEBUG_PCI, - "pci write %04x:%x:%02x.%x, addr 0x%04x, size %d, data 0x%x\n", + "pci write %04x:%02x:%02x.%x, addr 0x%04x, size %d, data 0x%x\n", (int) p->pci_device.domain, (int) p->pci_device.bus, (int) p->pci_device.device, (int) p->pci_device.function, @@ -347,7 +348,7 @@ int esc_mods_pci_write_2(struct file *pfile, struct MODS_PCI_WRITE_2 *p) if (dev == NULL) { mods_error_printk( - "pci write to %04x:%x:%02x.%x, addr 0x%04x, size %d failed\n", + "pci write to %04x:%02x:%02x.%x, addr 0x%04x, size %d failed\n", (unsigned int)p->pci_device.domain, (unsigned int)p->pci_device.bus, (unsigned int)p->pci_device.device, @@ -416,7 +417,7 @@ int esc_mods_pci_hot_reset(struct file *pfile, int retval; mods_debug_printk(DEBUG_PCI, - "pci_hot_reset %04x:%x:%02x.%x\n", + "pci_hot_reset %04x:%02x:%02x.%x\n", (int) p->pci_device.domain, (int) p->pci_device.bus, (int) p->pci_device.device, @@ -427,7 +428,7 @@ int esc_mods_pci_hot_reset(struct file *pfile, if (dev == NULL) { mods_error_printk( - "pci_hot_reset cannot find pci device %04x:%x:%02x.%x\n", + "pci_hot_reset cannot find pci device %04x:%02x:%02x.%x\n", (unsigned int)p->pci_device.domain, (unsigned int)p->pci_device.bus, (unsigned int)p->pci_device.device, @@ -438,7 +439,7 @@ int esc_mods_pci_hot_reset(struct file *pfile, retval = pci_set_pcie_reset_state(dev, pcie_hot_reset); if (retval) { mods_error_printk( - "pci_hot_reset failed on %04x:%x:%02x.%x\n", + "pci_hot_reset failed on %04x:%02x:%02x.%x\n", (unsigned int)p->pci_device.domain, (unsigned int)p->pci_device.bus, (unsigned int)p->pci_device.device, @@ -449,7 +450,7 @@ int esc_mods_pci_hot_reset(struct file *pfile, retval = pci_set_pcie_reset_state(dev, pcie_deassert_reset); if (retval) { mods_error_printk( - "pci_hot_reset deassert failed on %04x:%x:%02x.%x\n", + "pci_hot_reset deassert failed on %04x:%02x:%02x.%x\n", (unsigned int)p->pci_device.domain, (unsigned int)p->pci_device.bus, (unsigned int)p->pci_device.device, @@ -519,7 +520,7 @@ int esc_mods_device_numa_info_2(struct file *fp, LOG_ENT(); if (dev == NULL) { - mods_error_printk("PCI device %04x:%x:%02x.%x not found\n", + mods_error_printk("PCI device %04x:%02x:%02x.%x not found\n", p->pci_device.domain, p->pci_device.bus, p->pci_device.device, p->pci_device.function); @@ -644,7 +645,7 @@ int esc_mods_pci_set_dma_mask(struct file *file, err = pci_set_dma_mask(dev, mask); if (err) { - mods_error_printk("failed to set dma mask 0x%llx for dev %04x:%x:%02x.%x\n", + mods_error_printk("failed to set dma mask 0x%llx for dev %04x:%02x:%02x.%x\n", mask, (unsigned int)dma_mask->pci_device.domain, (unsigned int)dma_mask->pci_device.bus,