@@ -21,10 +21,11 @@ using namespace pcm;
2121
2222void print_usage (const char * progname)
2323{
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 " ;
2525 std::cout << " Reads/writes 32-bit PCICFG register \n " ;
2626 std::cout << " -w value : write the value before reading \n " ;
2727 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 " ;
2829 std::cout << " --version : print application version\n " ;
2930 std::cout << " \n " ;
3031}
@@ -49,12 +50,16 @@ int mainThrows(int argc, char * argv[])
4950 uint32 value = 0 ;
5051 bool write = false ;
5152 bool dec = false ;
53+ uint32 deviceID = 0 ;
5254
5355 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 )
5557 {
5658 switch (my_opt)
5759 {
60+ case ' i' :
61+ deviceID = (uint32)read_number (optarg);
62+ break ;
5863 case ' w' :
5964 write = true ;
6065 value = (pcm::uint32)read_number (optarg);
@@ -68,17 +73,17 @@ int mainThrows(int argc, char * argv[])
6873 }
6974 }
7075
71- if (optind + 4 >= argc)
76+ if (optind + ((deviceID)? 0 : 4 ) >= argc)
7277 {
7378 print_usage (argv[0 ]);
7479 return -1 ;
7580 }
7681
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 ;
8287
8388 #ifdef _MSC_VER
8489 // Increase the priority a bit to improve context switching delays on Windows
@@ -94,22 +99,49 @@ int mainThrows(int argc, char * argv[])
9499 return -1 ;
95100 }
96101 #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)
101119 {
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 " ;
104122 }
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+ });
108135 }
109- catch (std::exception & e)
136+ else
110137 {
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);
113144 }
145+
114146 return 0 ;
115147}
0 commit comments