510.39.01
Aaron Plattner
2 years ago
76 | 76 | include $(COMMON_UTILS_DIR)/src.mk |
77 | 77 | SRC += $(addprefix $(COMMON_UTILS_DIR)/,$(COMMON_UTILS_SRC)) |
78 | 78 | |
79 | # rpcgen generates code that emits unused variable warnings | |
79 | # rpcgen generates code that emits unused variable warnings and suspicious | |
80 | # function type casts | |
80 | 81 | $(call BUILD_OBJECT_LIST,$(RPC_SRC)): CFLAGS += -Wno-unused-variable |
82 | suppress_cast_func_type_warning := $(call TEST_CC_ARG,-Wno-cast-function-type) | |
83 | $(call BUILD_OBJECT_LIST,$(RPC_SRC)): CFLAGS += $(suppress_cast_func_type_warning) | |
81 | 84 | |
82 | 85 | OBJS = $(call BUILD_OBJECT_LIST,$(SRC)) |
83 | 86 |
112 | 112 | NV_VSNPRINTF(buf, fmt); \ |
113 | 113 | format(stream, prefix, buf, whitespace); \ |
114 | 114 | free (buf); \ |
115 | } while(0) | |
115 | } while (0) | |
116 | 116 | |
117 | 117 | |
118 | 118 | /* |
188 | 188 | if (a[0] == '-') a++; |
189 | 189 | if (a[0] == '+') a++; |
190 | 190 | |
191 | while(a[0]) { a[0] = a[1]; a++; } | |
191 | while (a[0]) { a[0] = a[1]; a++; } | |
192 | 192 | |
193 | 193 | /* |
194 | 194 | * decrement argv_index so that we process this |
0 | /* | |
1 | * Copyright (C) 2021 NVIDIA Corporation | |
2 | * | |
3 | * Permission is hereby granted, free of charge, to any person obtaining a | |
4 | * copy of this software and associated documentation files (the "Software"), | |
5 | * to deal in the Software without restriction, including without limitation | |
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
7 | * and/or sell copies of the Software, and to permit persons to whom the | |
8 | * Software is furnished to do so, subject to the following conditions: | |
9 | * | |
10 | * The above copyright notice and this permission notice shall be included in | |
11 | * all copies or substantial portions of the Software. | |
12 | * | |
13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
19 | * DEALINGS IN THE SOFTWARE. | |
20 | */ | |
21 | ||
22 | #include "nvpci-utils.h" | |
23 | ||
24 | /* | |
25 | * libpciaccess stores the device class in bits 16-23, subclass in 8-15, and | |
26 | * interface in bits 0-7 of dev->device_class. We care only about the class | |
27 | * and subclass. | |
28 | */ | |
29 | const uint32_t PCI_CLASS_DISPLAY_VGA = 0x30000; | |
30 | const uint32_t PCI_CLASS_SUBCLASS_MASK = 0xffff00; | |
31 | ||
32 | /* | |
33 | * nvpci_find_gpu_by_vendor() - use libpciaccess to find all VGA and 3D PCI | |
34 | * devices matching the passed-in vendor_id (which may be set to PCI_MATCH_ANY). | |
35 | * The caller is responsible for calling pci_system_init() before using this | |
36 | * function, and pci_system_cleanup() when libpciaccess is no longer needed. | |
37 | */ | |
38 | struct pci_device_iterator *nvpci_find_gpu_by_vendor(uint32_t vendor_id) | |
39 | { | |
40 | const struct pci_id_match match = { | |
41 | .vendor_id = vendor_id, | |
42 | .device_id = PCI_MATCH_ANY, | |
43 | .subvendor_id = PCI_MATCH_ANY, | |
44 | .subdevice_id = PCI_MATCH_ANY, | |
45 | .device_class = PCI_CLASS_DISPLAY_VGA, | |
46 | /* | |
47 | * Ignore bit 1 of the subclass, to allow both 0x30000 (VGA controller) | |
48 | * and 0x30200 (3D controller). | |
49 | */ | |
50 | .device_class_mask = PCI_CLASS_SUBCLASS_MASK & ~0x200, | |
51 | }; | |
52 | ||
53 | return pci_id_match_iterator_create(&match); | |
54 | } | |
55 | ||
56 | /* | |
57 | * nvpci_dev_is_vga() - test whether the passed-in struct pci_device* has the | |
58 | * VGA device class 0x0300 (and not 3D class 0x0302). | |
59 | */ | |
60 | int nvpci_dev_is_vga(struct pci_device *dev) | |
61 | { | |
62 | return (dev->device_class & PCI_CLASS_SUBCLASS_MASK) == | |
63 | PCI_CLASS_DISPLAY_VGA; | |
64 | } |
0 | /* | |
1 | * Copyright (C) 2021 NVIDIA Corporation | |
2 | * | |
3 | * Permission is hereby granted, free of charge, to any person obtaining a | |
4 | * copy of this software and associated documentation files (the "Software"), | |
5 | * to deal in the Software without restriction, including without limitation | |
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
7 | * and/or sell copies of the Software, and to permit persons to whom the | |
8 | * Software is furnished to do so, subject to the following conditions: | |
9 | * | |
10 | * The above copyright notice and this permission notice shall be included in | |
11 | * all copies or substantial portions of the Software. | |
12 | * | |
13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
19 | * DEALINGS IN THE SOFTWARE. | |
20 | */ | |
21 | ||
22 | #ifndef __NVPCI_UTILS_H__ | |
23 | #define __NVPCI_UTILS_H__ | |
24 | ||
25 | #include <pciaccess.h> | |
26 | ||
27 | #define NV_PCI_VENDOR_ID 0x10de | |
28 | ||
29 | struct pci_device_iterator *nvpci_find_gpu_by_vendor(uint32_t vendor_id); | |
30 | int nvpci_dev_is_vga(struct pci_device *dev); | |
31 | ||
32 | #endif /* __NVPCI_UTILS_H__ */ |
0 | 0 | # makefile fragment included by nvidia-xconfig, nvidia-settings, and nvidia-installer |
1 | ||
2 | # the including makefile should set this if the relevant program uses pciaccess | |
3 | COMMON_UTILS_PCIACCESS ?= | |
1 | 4 | |
2 | 5 | COMMON_UTILS_SRC += nvgetopt.c |
3 | 6 | COMMON_UTILS_SRC += common-utils.c |
8 | 11 | COMMON_UTILS_EXTRA_DIST += msg.h |
9 | 12 | COMMON_UTILS_EXTRA_DIST += src.mk |
10 | 13 | |
14 | # only build nvpci-utils.c for programs that actually use libpciaccess, to | |
15 | # prevent other programs from needing to set the right CFLAGS/LDFLAGS for code | |
16 | # they won't use. Otherwise, just package it in the source tarball. | |
17 | ifneq ($(COMMON_UTILS_PCIACCESS),) | |
18 | COMMON_UTILS_SRC += nvpci-utils.c | |
19 | else | |
20 | COMMON_UTILS_EXTRA_DIST += nvpci-utils.c | |
21 | endif | |
22 | COMMON_UTILS_EXTRA_DIST += nvpci-utils.h | |
23 | ||
11 | 24 | # gen-manpage-opts-helper.c is listed in EXTRA_DIST, rather than SRC, |
12 | 25 | # because it is not compiled into the utilities themselves, but used |
13 | 26 | # when building the utility's gen-manpage-opts |
185 | 185 | |
186 | 186 | NV_GENERATED_HEADERS ?= |
187 | 187 | |
188 | PCIACCESS_CFLAGS ?= | |
189 | PCIACCESS_LDFLAGS ?= | |
188 | 190 | |
189 | 191 | ############################################################################## |
190 | 192 | # This makefile uses the $(eval) builtin function, which was added in |
379 | 381 | BUILD_OBJECT_LIST = \ |
380 | 382 | $(call BUILD_OBJECT_LIST_WITH_DIR,$(1),$(OUTPUTDIR)) |
381 | 383 | |
384 | $(call BUILD_OBJECT_LIST,nvpci-utils.c): CFLAGS += $(PCIACCESS_CFLAGS) | |
382 | 385 | |
383 | 386 | ############################################################################## |
384 | 387 | # function to generate a list of dependency files from their |