@@ -21,10 +21,11 @@ using namespace pcm;
21
21
22
22
void print_usage (const char * progname)
23
23
{
24
- std::cout << " Usage " << progname << " [-w value] [-d] group bus device function offset\n\n " ;
24
+ std::cout << " Usage " << progname << " [-w value] [-d] [-i ID] [ group bus device function] offset\n\n " ;
25
25
std::cout << " Reads/writes 32-bit PCICFG register \n " ;
26
26
std::cout << " -w value : write the value before reading \n " ;
27
27
std::cout << " -d : output all numbers in dec (default is hex)\n " ;
28
+ std::cout << " -i ID : specify Intel device ID instead of group bus device function\n " ;
28
29
std::cout << " --version : print application version\n " ;
29
30
std::cout << " \n " ;
30
31
}
@@ -49,12 +50,16 @@ int mainThrows(int argc, char * argv[])
49
50
uint32 value = 0 ;
50
51
bool write = false ;
51
52
bool dec = false ;
53
+ uint32 deviceID = 0 ;
52
54
53
55
int my_opt = -1 ;
54
- while ((my_opt = getopt (argc, argv, " w:d" )) != -1 )
56
+ while ((my_opt = getopt (argc, argv, " i: w:d" )) != -1 )
55
57
{
56
58
switch (my_opt)
57
59
{
60
+ case ' i' :
61
+ deviceID = (uint32)read_number (optarg );
62
+ break ;
58
63
case ' w' :
59
64
write = true ;
60
65
value = (pcm::uint32)read_number (optarg );
@@ -68,17 +73,17 @@ int mainThrows(int argc, char * argv[])
68
73
}
69
74
}
70
75
71
- if (optind + 4 >= argc)
76
+ if (optind + ((deviceID)? 0 : 4 ) >= argc)
72
77
{
73
78
print_usage (argv[0 ]);
74
79
return -1 ;
75
80
}
76
81
77
- int group = ( int ) read_number (argv[ optind ]) ;
78
- int bus = ( int ) read_number (argv[ optind + 1 ]) ;
79
- int device = ( int ) read_number (argv[ optind + 2 ]) ;
80
- int function = ( int ) read_number (argv[ optind + 3 ]) ;
81
- int offset = ( int ) read_number (argv[ optind + 4 ]) ;
82
+ int group = - 1 ;
83
+ int bus = - 1 ;
84
+ int device = - 1 ;
85
+ int function = - 1 ;
86
+ int offset = - 1 ;
82
87
83
88
#ifdef _MSC_VER
84
89
// Increase the priority a bit to improve context switching delays on Windows
@@ -94,22 +99,49 @@ int mainThrows(int argc, char * argv[])
94
99
return -1 ;
95
100
}
96
101
#endif
97
- try {
98
- PciHandleType h (group, bus, device, function);
99
- if (!dec) std::cout << std::hex << std::showbase;
100
- if (write )
102
+
103
+ auto one = [&dec,&write ](const uint32 & group, const uint32 & bus, const uint32 & device, const uint32 & function, const uint32 & offset, uint32 value)
104
+ {
105
+
106
+ try {
107
+ PciHandleType h (group, bus, device, function);
108
+ if (!dec) std::cout << std::hex << std::showbase;
109
+ if (write )
110
+ {
111
+ std::cout << " Writing " << value << " to " << group << " :" << bus << " :" << device << " :" << function << " @" << offset << " \n " ;
112
+ h.write32 (offset, value);
113
+ }
114
+ value = 0 ;
115
+ h.read32 (offset, &value);
116
+ std::cout << " Read value " << value << " from " << group << " :" << bus << " :" << device << " :" << function << " @" << offset << " \n\n " ;
117
+ }
118
+ catch (std::exception & e)
101
119
{
102
- std::cout << " Writing " << value << " to " << group << " : " << bus << " : " << device << " : " << function << " @ " << offset << " \n " ;
103
- h. write32 (offset, value) ;
120
+ std::cerr << " Error accessing registers: " << e. what () << " \n " ;
121
+ std::cerr << " Please check if the program can access MSR/PCICFG drivers. \n " ;
104
122
}
105
- value = 0 ;
106
- h.read32 (offset, &value);
107
- std::cout << " Read value " << value << " from " << group << " :" << bus << " :" << device << " :" << function << " @" << offset << " \n\n " ;
123
+ };
124
+
125
+ if (deviceID)
126
+ {
127
+ offset = (int )read_number (argv[optind ]);
128
+ forAllIntelDevices ([&deviceID,&one,&offset, &value](const uint32 group, const uint32 bus, const uint32 device, const uint32 function, const uint32 device_id)
129
+ {
130
+ if (deviceID == device_id)
131
+ {
132
+ one (group, bus, device, function, offset, value);
133
+ }
134
+ });
108
135
}
109
- catch (std:: exception & e)
136
+ else
110
137
{
111
- std::cerr << " Error accessing registers: " << e.what () << " \n " ;
112
- std::cerr << " Please check if the program can access MSR/PCICFG drivers.\n " ;
138
+ group = (int )read_number (argv[optind ]);
139
+ bus = (int )read_number (argv[optind + 1 ]);
140
+ device = (int )read_number (argv[optind + 2 ]);
141
+ function = (int )read_number (argv[optind + 3 ]);
142
+ offset = (int )read_number (argv[optind + 4 ]);
143
+ one (group, bus, device, function, offset, value);
113
144
}
145
+
114
146
return 0 ;
115
147
}
0 commit comments