1 /*******************************************************************************
2     Copyright (c) 2015-2018 NVIDIA Corporation
3 
4     Permission is hereby granted, free of charge, to any person obtaining a copy
5     of this software and associated documentation files (the "Software"), to
6     deal in the Software without restriction, including without limitation the
7     rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8     sell copies of the Software, and to permit persons to whom the Software is
9     furnished to do so, subject to the following conditions:
10 
11         The above copyright notice and this permission notice shall be
12         included in all copies or substantial portions of the Software.
13 
14     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17     THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20     DEALINGS IN THE SOFTWARE.
21 
22 *******************************************************************************/
23 
24 #include "uvm_global.h"
25 #include "uvm_procfs.h"
26 #include "uvm_gpu.h"
27 
28 #include "nv-procfs.h"
29 #include "uvm_linux.h"
30 
31 #define UVM_PROC_DIR_NAME "driver/nvidia-uvm"
32 #define UVM_PROC_GPUS_DIR_NAME "gpus"
33 #define UVM_PROC_CPU_DIR_NAME "cpu"
34 
35 #if defined(CONFIG_PROC_FS)
36   // This parameter enables additional debug procfs entries. It's enabled by
37   // default for debug and develop builds and disabled for release builds.
38   int uvm_enable_debug_procfs = UVM_IS_DEBUG() || UVM_IS_DEVELOP();
39   module_param(uvm_enable_debug_procfs, int, S_IRUGO);
40   MODULE_PARM_DESC(uvm_enable_debug_procfs, "Enable debug procfs entries in /proc/" UVM_PROC_DIR_NAME);
41 #else
42   int uvm_enable_debug_procfs = 0;
43 #endif
44 
45 static struct proc_dir_entry *uvm_proc_dir;
46 static struct proc_dir_entry *uvm_proc_gpus;
47 static struct proc_dir_entry *uvm_proc_cpu;
48 
uvm_procfs_init(void)49 NV_STATUS uvm_procfs_init(void)
50 {
51     if (!uvm_procfs_is_enabled())
52         return NV_OK;
53 
54     uvm_proc_dir = NV_CREATE_PROC_DIR(UVM_PROC_DIR_NAME, NULL);
55     if (uvm_proc_dir == NULL)
56         return NV_ERR_OPERATING_SYSTEM;
57 
58     uvm_proc_gpus = NV_CREATE_PROC_DIR(UVM_PROC_GPUS_DIR_NAME, uvm_proc_dir);
59     if (uvm_proc_gpus == NULL)
60         return NV_ERR_OPERATING_SYSTEM;
61 
62     uvm_proc_cpu = NV_CREATE_PROC_DIR(UVM_PROC_CPU_DIR_NAME, uvm_proc_dir);
63     if (uvm_proc_cpu == NULL)
64         return NV_ERR_OPERATING_SYSTEM;
65 
66     return NV_OK;
67 }
68 
uvm_procfs_exit(void)69 void uvm_procfs_exit(void)
70 {
71     proc_remove(uvm_proc_dir);
72 }
73 
uvm_procfs_get_gpu_base_dir(void)74 struct proc_dir_entry *uvm_procfs_get_gpu_base_dir(void)
75 {
76     return uvm_proc_gpus;
77 }
78 
uvm_procfs_get_cpu_base_dir(void)79 struct proc_dir_entry *uvm_procfs_get_cpu_base_dir(void)
80 {
81     return uvm_proc_cpu;
82 }
83 
84