Skip to content

Commit

Permalink
pcm-tpmi: add -i instances option
Browse files Browse the repository at this point in the history
Change-Id: I67c304949a454b09e0b9a741825654386bc68b79
  • Loading branch information
rdementi committed Jul 21, 2024
1 parent d879b4f commit 232c253
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/pcm-tpmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ void print_usage(const char * progname)
std::cout << " -b low:high : read or write only low..high bits of the register\n";
std::cout << " -e entries : perform read/write on specified entries (default is all entries)\n";
std::cout << " (examples: -e 10 -e 10-11 -e 4,6,12-20,6)\n";
std::cout << " -i instances: perform read/write on specified instances (default is all instances)\n";
std::cout << " (examples: -i 1 -i 0,1 -i 0,2-3)\n";
std::cout << " -d : output all numbers in dec (default is hex)\n";
std::cout << " -v : verbose ouput\n";
std::cout << " --version : print application version\n";
Expand All @@ -51,10 +53,10 @@ int mainThrows(int argc, char * argv[])
bool write = false;
bool dec = false;
std::pair<int64,int64> bits{-1, -1};
std::list<int> entries;
std::list<int> entries, instances;

int my_opt = -1;
while ((my_opt = getopt(argc, argv, "w:dvb:e:")) != -1)
while ((my_opt = getopt(argc, argv, "w:dvb:e:i:")) != -1)
{
switch (my_opt)
{
Expand All @@ -74,6 +76,9 @@ int mainThrows(int argc, char * argv[])
case 'e':
entries = extract_integer_list(optarg);
break;
case 'i':
instances = extract_integer_list(optarg);
break;
default:
print_usage(argv[0]);
return -1;
Expand Down Expand Up @@ -106,8 +111,20 @@ int mainThrows(int argc, char * argv[])

try
{
for (size_t i = 0; i < TPMIHandle::getNumInstances(); ++i)
if (instances.empty())
{
for (size_t i = 0; i < TPMIHandle::getNumInstances(); ++i)
{
instances.push_back(i);
}
}
for (const size_t i : instances)
{
if (i >= TPMIHandle::getNumInstances())
{
std::cerr << "Instance " << i << " does not exist\n";
continue;
}
TPMIHandle h(i, requestedID, requestedRelativeOffset, !write);
auto one = [&](const size_t p)
{
Expand Down

0 comments on commit 232c253

Please sign in to comment.