...
 
Commits (12)
......@@ -72,8 +72,6 @@ MODPROBE_UTILS_DIR ?= modprobe-utils
# include the list of source files; defines SRC
include dist-files.mk
SRC += $(STAMP_C)
include $(COMMON_UTILS_DIR)/src.mk
SRC += $(addprefix $(COMMON_UTILS_DIR)/,$(COMMON_UTILS_SRC))
......@@ -121,11 +119,8 @@ $(NVIDIA_MODPROBE).unstripped: $(OBJS)
# define the rule to build each object file
$(foreach src,$(SRC),$(eval $(call DEFINE_OBJECT_RULE,TARGET,$(src))))
# define the rule to generate $(STAMP_C)
$(eval $(call DEFINE_STAMP_C_RULE, $(OBJS),$(NVIDIA_MODPROBE_PROGRAM_NAME)))
clean clobber:
rm -rf $(NVIDIA_MODPROBE) $(MANPAGE) *~ $(STAMP_C) \
rm -rf $(NVIDIA_MODPROBE) $(MANPAGE) *~ \
$(OUTPUTDIR)/*.o $(OUTPUTDIR)/*.d \
$(GEN_MANPAGE_OPTS) $(OPTIONS_1_INC)
......
......@@ -132,4 +132,6 @@ typedef enum {
NV_OPTIONAL_BOOL_TRUE = TRUE
} NVOptionalBool;
#define NV_ID_STRING PROGRAM_NAME ": version " NVIDIA_VERSION
#endif /* __COMMON_UTILS_H__ */
......@@ -67,6 +67,9 @@
#define NV_NVLINK_MODULE_NAME "nvidia-nvlink"
#define NV_NVLINK_PROC_PERM_PATH "/proc/driver/nvidia-nvlink/permissions"
#define NV_NVSWITCH_MODULE_NAME "nvidia-nvswitch"
#define NV_NVSWITCH_PROC_PERM_PATH "/proc/driver/nvidia-nvswitch/permissions"
#define NV_DEVICE_FILE_MODE_MASK (S_IRWXU|S_IRWXG|S_IRWXO)
#define NV_DEVICE_FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
#define NV_DEVICE_FILE_UID 0
......@@ -396,18 +399,20 @@ static int modprobe_helper(const int print_errors, const char *module_name)
return 0;
default:
if (waitpid(pid, &status, 0) < 0)
{
return 0;
}
if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
{
return 1;
}
else
{
return 0;
}
/*
* waitpid(2) is not always guaranteed to return success even if
* the child terminated normally. For example, if the process
* explicitly configured the handling of the SIGCHLD signal
* to SIG_IGN, then waitpid(2) will instead block until all
* children terminate and return the error ECHILD, regardless
* of the child's exit codes.
*
* Hence, ignore waitpid(2) error codes and instead check
* whether the desired kernel module is loaded.
*/
waitpid(pid, NULL, 0);
return is_kernel_module_loaded(module_name);
}
return 1;
......@@ -548,8 +553,8 @@ int nvidia_get_file_state(int minor, int module_instance)
* permissions. Returns 1 if the file is successfully created; returns 0
* if the file could not be created.
*/
int mknod_helper(int major, int minor, const char *path,
const char *proc_path)
static int mknod_helper(int major, int minor, const char *path,
const char *proc_path)
{
dev_t dev = NV_MAKE_DEVICE(major, minor);
mode_t mode;
......@@ -659,7 +664,7 @@ int nvidia_mknod(int minor, int module_instance)
* device with the specified name. Returns the major number on success,
* or -1 on failure.
*/
int get_chardev_major(const char *name)
static int get_chardev_major(const char *name)
{
int ret = -1;
char line[NV_MAX_LINE_LENGTH];
......@@ -796,11 +801,47 @@ int nvidia_nvlink_mknod(void)
NV_NVLINK_PROC_PERM_PATH);
}
/*
* Attempt to create the NVIDIA NVSwitch driver device files.
*/
int nvidia_nvswitch_mknod(int minor)
{
int major = 0;
char name[NV_MAX_CHARACTER_DEVICE_FILE_STRLEN];
int ret;
major = get_chardev_major(NV_NVSWITCH_MODULE_NAME);
if (major < 0)
{
return 0;
}
if (minor == NV_NVSWITCH_CTL_MINOR)
{
ret = snprintf(name, NV_MAX_CHARACTER_DEVICE_FILE_STRLEN,
NV_NVSWITCH_CTL_NAME);
}
else
{
ret = snprintf(name, NV_MAX_CHARACTER_DEVICE_FILE_STRLEN,
NV_NVSWITCH_DEVICE_NAME, minor);
}
if (ret <= 0)
{
return 0;
}
return mknod_helper(major, minor, name, NV_NVSWITCH_PROC_PERM_PATH);
}
int nvidia_vgpu_vfio_mknod(int minor_num)
{
int major = get_chardev_major(NV_VGPU_VFIO_MODULE_NAME);
char vgpu_dev_name[NV_MAX_CHARACTER_DEVICE_FILE_STRLEN];
char proc_path[NV_MAX_PROC_REGISTRY_PATH_SIZE];
int ret;
if (major < 0)
{
......@@ -809,8 +850,12 @@ int nvidia_vgpu_vfio_mknod(int minor_num)
assign_proc_registry_path(proc_path, NV_MODULE_INSTANCE_NONE);
snprintf(vgpu_dev_name, NV_MAX_CHARACTER_DEVICE_FILE_STRLEN,
NV_VGPU_VFIO_DEVICE_NAME, minor_num);
ret = snprintf(vgpu_dev_name, NV_MAX_CHARACTER_DEVICE_FILE_STRLEN,
NV_VGPU_VFIO_DEVICE_NAME, minor_num);
if (ret <= 0)
{
return 0;
}
vgpu_dev_name[NV_MAX_CHARACTER_DEVICE_FILE_STRLEN - 1] = '\0';
......
......@@ -36,6 +36,7 @@
#define NV_MAX_MODULE_INSTANCES 8
#define NV_CTL_DEVICE_NUM 255
#define NV_MODESET_MINOR_DEVICE_NUM 254
#define NV_NVSWITCH_CTL_MINOR 255
#define NV_FRONTEND_CONTROL_DEVICE_MINOR_MAX NV_CTL_DEVICE_NUM
......@@ -44,6 +45,8 @@
#define NV_MODESET_DEVICE_NAME "/dev/nvidia-modeset"
#define NV_VGPU_VFIO_DEVICE_NAME "/dev/nvidia-vgpu%d"
#define NV_NVLINK_DEVICE_NAME "/dev/nvidia-nvlink"
#define NV_NVSWITCH_CTL_NAME "/dev/nvidia-nvswitchctl"
#define NV_NVSWITCH_DEVICE_NAME "/dev/nvidia-nvswitch%d"
#define NV_NMODULE_CTRL_DEVICE_FILE_PATH "/dev/nvidiactl%d"
......@@ -85,9 +88,7 @@ int nvidia_modeset_modprobe(void);
int nvidia_modeset_mknod(void);
int nvidia_vgpu_vfio_mknod(int minor_num);
int nvidia_nvlink_mknod(void);
int mknod_helper(int major, int minor, const char *path, const char *proc_path);
int get_chardev_major(const char *name);
int nvidia_nvswitch_mknod(int minor);
#endif /* NV_LINUX */
......
This diff is collapsed.
/*
* Copyright (c) 2016, NVIDIA CORPORATION.
* Copyright (c) 2016-2018, NVIDIA CORPORATION.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
......@@ -28,6 +28,58 @@
#ifndef __PCI_SYSFS_H__
#define __PCI_SYSFS_H__
#if defined(NV_LINUX)
#include <linux/pci.h>
#if !defined(PCI_STD_HEADER_SIZEOF)
#define PCI_STD_HEADER_SIZEOF 64
#endif
#if !defined(PCI_CAP_ID_EXP)
#define PCI_CAP_ID_EXP 0x10 /* PCI Express */
#endif
#if !defined(PCI_EXP_LNKCAP)
#define PCI_EXP_LNKCAP 12 /* Link Capabilities */
#endif
#if !defined(PCI_EXP_LNKCAP_DLLLARC)
#define PCI_EXP_LNKCAP_DLLLARC 0x00100000 /* Data Link Layer Link Active Reporting Capable */
#endif
#if !defined(PCI_EXP_LNKCTL)
#define PCI_EXP_LNKCTL 16 /* Link Control */
#endif
#if !defined(PCI_EXP_LNKCTL_LD)
#define PCI_EXP_LNKCTL_LD 0x0010 /* Link Disable */
#endif
#if !defined(PCI_EXP_LNKSTA)
#define PCI_EXP_LNKSTA 18 /* Link Status */
#endif
#if !defined(PCI_EXP_LNKSTA_DLLLA)
#define PCI_EXP_LNKSTA_DLLLA 0x2000 /* Data Link Layer Link Active */
#endif
#define PCI_LINK_WAIT_US 200000 /* 200 ms, must be less than 1000000 (1s) */
#define PCI_LINK_DELAY_NS 100000000 /* 100 ms */
#define PCI_LINK_DLLLAR_DISABLE_DELAY_NS 30000000 /* 30ms */
#if (_POSIX_C_SOURCE >= 199309L)
#define PCI_NANOSLEEP(ts, rem) nanosleep(ts, rem)
#elif !(_POSIX_C_SOURCE >= 200809L)
#define PCI_NANOSLEEP(ts, rem) usleep((ts)->tv_sec * 1000000 + ((ts)->tv_nsec + 999) / 1000)
#else
#define PCI_NANOSLEEP(ts, rem) sleep((ts)->tv_sec + ((ts)->tv_nsec + 999999999) / 1000000000)
#endif
typedef struct {
unsigned domain;
unsigned bus;
unsigned dev;
unsigned ftn;
} pci_info_t;
int pci_rescan(uint16_t domain, uint8_t bus, uint8_t slot, uint8_t function);
int pci_find_parent_bridge(pci_info_t *p_gpu_info, pci_info_t *p_bridge_info);
int pci_bridge_link_set_enable(uint16_t domain, uint8_t bus, uint8_t device, uint8_t ftn, int enable);
#endif /* NV_LINUX */
#endif /* __PCI_SYSFS_H__ */
......@@ -44,13 +44,10 @@
#include "common-utils.h"
#include "msg.h"
extern const char *pNV_ID;
static void print_version(void)
{
nv_info_msg(NULL, "");
nv_info_msg(NULL, "%s", pNV_ID);
nv_info_msg(NULL, "%s", NV_ID_STRING);
nv_info_msg(NULL, "");
}
......
......@@ -74,9 +74,7 @@ PRINTF ?= printf
MKDIR ?= mkdir -p
RM ?= rm -f
TOUCH ?= touch
WHOAMI ?= whoami
HARDLINK ?= ln -f
HOSTNAME_CMD ?= hostname
DATE ?= date
GZIP_CMD ?= gzip
CHMOD ?= chmod
......@@ -214,6 +212,8 @@ ifndef NVIDIA_VERSION
$(error NVIDIA_VERSION undefined)
endif
CFLAGS += -DNVIDIA_VERSION=\"$(NVIDIA_VERSION)\"
##############################################################################
# Several of the functions below take an argument that indicates if
......@@ -424,37 +424,6 @@ define DEBUG_INFO_RULES
endif
endef
##############################################################################
# STAMP_C - this is a source file that is generated during the build
# to capture information about the build environment for the utility.
#
# The DEFINE_STAMP_C_RULE function is used to define the rule for
# generating STAMP_C. First argument is a list of dependencies for
# STAMP_C (g_stamp.o is filtered out of the list); second argument is
# the name of the program being built.
#
# The includer of utils.mk should add $(STAMP_C) to its list of source
# files
##############################################################################
STAMP_C = $(OUTPUTDIR)/g_stamp.c
define DEFINE_STAMP_C_RULE
$$(STAMP_C): $$(filter-out \
$$(call BUILD_OBJECT_LIST,$$(STAMP_C)),$(1)) \
$$(VERSION_MK)
@ $$(RM) $$@
@ $$(PRINTF) "%s" "const char NV_ID[] = \"nvidia id: " >> $$@
@ $$(PRINTF) "%s" "$(2): " >> $$@
@ $$(PRINTF) "%s" "version $$(NVIDIA_VERSION) " >> $$@
@ $$(PRINTF) "%s" "($$(shell $$(WHOAMI))" >> $$@
@ $$(PRINTF) "%s" "@$$(shell $$(HOSTNAME_CMD))) " >> $$@
@ $$(PRINTF) "%s\n" "$$(shell $(DATE))\";" >> $$@
@ $$(PRINTF) "%s\n" "const char *pNV_ID = NV_ID + 11;" >> $$@
endef
##############################################################################
# Define rules that can be used for embedding a file into an ELF object that
# contains the raw contents of that file and symbols pointing to the embedded
......
NVIDIA_VERSION = 390.87
NVIDIA_VERSION = 410.93