Commit 1944a4ea authored by Andreas Beckmann's avatar Andreas Beckmann

New upstream version 375.26

parents c66b77e1 e4538109
......@@ -36,6 +36,7 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include "nvidia-modprobe-utils.h"
#include "pci-enum.h"
......@@ -218,6 +219,24 @@ static int is_kernel_module_loaded(const char *nv_module_name)
return module_loaded;
}
/*
* Attempt to redirect STDOUT and STDERR to /dev/null.
*
* This is only for the cosmetics of silencing warnings, so do not
* treat any errors here as fatal.
*/
static void silence_current_process(void)
{
int dev_null_fd = open("/dev/null", O_RDWR);
if (dev_null_fd < 0)
{
return;
}
dup2(dev_null_fd, STDOUT_FILENO);
dup2(dev_null_fd, STDERR_FILENO);
close(dev_null_fd);
}
/*
* Attempt to load a kernel module; returns 1 if kernel module is
......@@ -344,6 +363,17 @@ static int modprobe_helper(const int print_errors, const char *module_name)
{
case 0:
/*
* modprobe might complain in expected scenarios. E.g.,
* `modprobe nvidia` on a Tegra system with dGPU where no nvidia.ko is
* present will complain:
*
* "modprobe: FATAL: Module nvidia not found."
*
* Silence the current process to avoid such unwanted messages.
*/
silence_current_process();
execle(modprobe_path, "modprobe",
module_name, NULL, envp);
......
......@@ -3,3 +3,4 @@ MODPROBE_UTILS_SRC += pci-sysfs.c
MODPROBE_UTILS_EXTRA_DIST += nvidia-modprobe-utils.h
MODPROBE_UTILS_EXTRA_DIST += nvidia-modprobe-utils.mk
MODPROBE_UTILS_EXTRA_DIST += pci-enum.h
MODPROBE_UTILS_EXTRA_DIST += pci-sysfs.h
......@@ -53,8 +53,14 @@
#include <errno.h>
#include "pci-enum.h"
#include "pci-sysfs.h"
#define SYS_BUS_PCI "/sys/bus/pci/devices"
#define SYS_BUS_PCI "/sys/bus/pci/"
#define SYS_BUS_PCI_DEVICES SYS_BUS_PCI "devices"
#define SYS_BUS_PCI_RESCAN SYS_BUS_PCI "rescan"
#define SYSFS_PCI_BRIDGE_RESCAN_FMT SYS_BUS_PCI_DEVICES "/%04x:%02x:%02x.%1x/rescan"
#define SYSFS_RESCAN_STRING "1\n"
#define SYSFS_RESCAN_STRING_SIZE 2
static int pci_sysfs_read_cfg(uint16_t, uint16_t, uint16_t, uint16_t, void *,
uint16_t size, uint16_t *);
......@@ -77,7 +83,7 @@ pci_enum_match_id(struct pci_id_match *match)
* can be accessed using this interface.
*/
match->num_matches = 0;
if (stat(SYS_BUS_PCI, &st) == 0)
if (stat(SYS_BUS_PCI_DEVICES, &st) == 0)
{
err = find_matches(match);
}
......@@ -102,7 +108,7 @@ find_matches(struct pci_id_match *match)
DIR *sysfs_pci_dir;
int err = 0;
sysfs_pci_dir = opendir(SYS_BUS_PCI);
sysfs_pci_dir = opendir(SYS_BUS_PCI_DEVICES);
if (sysfs_pci_dir == NULL)
{
return errno;
......@@ -185,7 +191,7 @@ pci_sysfs_read_cfg(uint16_t domain, uint16_t bus, uint16_t device,
* device.
*/
snprintf(name, 255, "%s/%04x:%02x:%02x.%1u/config",
SYS_BUS_PCI, domain, bus, device, function);
SYS_BUS_PCI_DEVICES, domain, bus, device, function);
fd = open(name, O_RDONLY);
if (fd < 0)
......@@ -220,4 +226,38 @@ pci_sysfs_read_cfg(uint16_t domain, uint16_t bus, uint16_t device,
return err;
}
int
pci_rescan(uint16_t domain, uint8_t bus, uint8_t slot, uint8_t function)
{
char const *node;
char node_buf[256];
int node_fd;
ssize_t cnt;
if ((domain | bus | slot | function) == 0)
{
/* rescan the entire PCI tree */
node = SYS_BUS_PCI_RESCAN;
}
else
{
snprintf(node_buf, sizeof(node_buf) - 1, SYSFS_PCI_BRIDGE_RESCAN_FMT,
domain, bus, slot, function);
node = node_buf;
}
node_fd = open(node, O_WRONLY);
if (node_fd < 0)
{
return errno;
}
cnt = write(node_fd, SYSFS_RESCAN_STRING, SYSFS_RESCAN_STRING_SIZE);
close(node_fd);
return cnt == SYSFS_RESCAN_STRING_SIZE ? 0 : EIO;
}
#endif /* defined(NV_LINUX) */
/*
* Copyright (c) 2016, NVIDIA CORPORATION.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* This file provides utility functions on Linux for interfacing
* with the sysfs/PCI kernel facility.
*/
#ifndef __PCI_SYSFS_H__
#define __PCI_SYSFS_H__
int pci_rescan(uint16_t domain, uint8_t bus, uint8_t slot, uint8_t function);
#endif /* __PCI_SYSFS_H__ */
NVIDIA_VERSION = 367.44
NVIDIA_VERSION = 375.26
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment