diff options
author | Maxim Polyakov <max.senia.poliak@gmail.com> | 2019-10-09 18:35:23 +0300 |
---|---|---|
committer | Nico Huber <nico.h@gmx.de> | 2021-08-17 12:20:26 +0000 |
commit | d8163ede51b25dde6fc446d609adae1c7a80ca01 (patch) | |
tree | c3789a26d89ed808022ca91571e10196dc0e4937 /util/inteltool | |
parent | b11f7e2b6b4e249f544299ab5ad64309723535eb (diff) |
inteltool: Allow to set cores range for MSRs dump
Adds the ability to output MSRs dump for the specified range of CPU
cores. This makes it easier to reverse engineer server multicore
processors using the inteltool utility.
The range is set using --cpu-range <start>[-<end>] command line option:
$ sudo ./inteltool -M --cpu-range 0-7
$ sudo ./inteltool -M --cpu-range 7-15
$ sudo ./inteltool -M --cpu-range 32
$ sudo ./inteltool -M will print a register dump for all cores, just
as before.
Change-Id: I3a037cf7ac270d2b51d6e453334c358ff47b4105
Signed-off-by: Maxim Polyakov <max.senia.poliak@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/35919
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util/inteltool')
-rw-r--r-- | util/inteltool/cpu.c | 15 | ||||
-rw-r--r-- | util/inteltool/inteltool.c | 26 | ||||
-rw-r--r-- | util/inteltool/inteltool.h | 2 |
3 files changed, 38 insertions, 5 deletions
diff --git a/util/inteltool/cpu.c b/util/inteltool/cpu.c index db63d36729..74252293de 100644 --- a/util/inteltool/cpu.c +++ b/util/inteltool/cpu.c @@ -7,6 +7,7 @@ #include <stdlib.h> #include <string.h> #include <errno.h> +#include <limits.h> #include "inteltool.h" @@ -265,9 +266,9 @@ void print_tme(void) #endif } -int print_intel_core_msrs(void) +int print_intel_msrs(unsigned int range_start, unsigned int range_end) { - unsigned int i, core, id, core_num = get_number_of_cores(); + unsigned int i, core, id; msr_t msr; #define IA32_PLATFORM_ID 0x0017 @@ -2295,7 +2296,15 @@ int print_intel_core_msrs(void) close(fd_msr); - for (core = 0; core < core_num; core++) { + const unsigned int cores_range_max_limit = get_number_of_cores() - 1; + if (range_end > cores_range_max_limit) { + if (range_end != UINT_MAX) + printf("Warning: the range exceeds the maximum core number %d!\n", + cores_range_max_limit); + range_end = cores_range_max_limit; + } + + for (core = range_start; core <= range_end; core++) { #ifndef __DARWIN__ char msrfilename[64]; memset(msrfilename, 0, 64); diff --git a/util/inteltool/inteltool.c b/util/inteltool/inteltool.c index 7cff80f754..f8c5e9161d 100644 --- a/util/inteltool/inteltool.c +++ b/util/inteltool/inteltool.c @@ -10,6 +10,7 @@ #include <sys/mman.h> #include <unistd.h> #include <errno.h> +#include <limits.h> #include "inteltool.h" #include "pcr.h" @@ -21,6 +22,7 @@ enum long_only_opts { LONG_OPT_PCR = 0x100, + LONG_OPT_RANGE = 0x101, }; /* @@ -516,6 +518,7 @@ static void print_usage(const char *name) " -d | --dmibar: dump northbridge DMIBAR registers\n" " -P | --pciexpress: dump northbridge PCIEXBAR registers\n\n" " -M | --msrs: dump CPU MSRs\n" + " --cpu-range <start>[-<end>]: (optional) set CPU cores range for -M (--msrs) option\n" " -A | --ambs: dump AMB registers\n" " -x | --sgx: dump SGX status\n" " -t | --tme: dump TME status\n" @@ -585,6 +588,8 @@ int main(int argc, char *argv[]) size_t pcr_count = 0; uint8_t dump_pcr[MAX_PCR_PORTS]; + unsigned int cores_range_start = 0, cores_range_end = UINT_MAX; + static struct option long_options[] = { {"version", 0, 0, 'v'}, {"help", 0, 0, 'h'}, @@ -598,6 +603,7 @@ int main(int argc, char *argv[]) {"dmibar", 0, 0, 'd'}, {"pciexpress", 0, 0, 'P'}, {"msrs", 0, 0, 'M'}, + {"cpu-range", required_argument, 0, LONG_OPT_RANGE}, {"ambs", 0, 0, 'A'}, {"spi", 0, 0, 's'}, {"spd", 0, 0, 'S'}, @@ -657,6 +663,24 @@ int main(int argc, char *argv[]) case 'M': dump_coremsrs = 1; break; + case LONG_OPT_RANGE: + if (strlen(optarg) == 0) { + print_usage(argv[0]); + exit(1); + } + const int sscanf_ret = sscanf(optarg, "%u-%u", &cores_range_start, &cores_range_end); + if (sscanf_ret == 1) { + /* the end of the range is not specified - only for one core */ + cores_range_end = cores_range_start; + } else if (sscanf_ret != 2) { + print_usage(argv[0]); + exit(1); + } else if (cores_range_end < cores_range_start) { + printf("Error: invalid cores range <%u-%u>!\n", + cores_range_start, cores_range_end); + exit(1); + } + break; case 'a': dump_gpios = 1; show_gpio_diffs = 1; @@ -859,7 +883,7 @@ int main(int argc, char *argv[]) } if (dump_coremsrs) { - print_intel_core_msrs(); + print_intel_msrs(cores_range_start, cores_range_end); printf("\n\n"); } diff --git a/util/inteltool/inteltool.h b/util/inteltool/inteltool.h index 678aa47871..4a6eba4968 100644 --- a/util/inteltool/inteltool.h +++ b/util/inteltool/inteltool.h @@ -396,7 +396,7 @@ void *map_physical(uint64_t phys_addr, size_t len); void unmap_physical(void *virt_addr, size_t len); unsigned int cpuid(unsigned int op); -int print_intel_core_msrs(void); +int print_intel_msrs(unsigned int range_start, unsigned int range_end); int print_mchbar(struct pci_dev *nb, struct pci_access *pacc, const char *dump_spd_file); int print_pmbase(struct pci_dev *sb, struct pci_access *pacc); int print_lpc(struct pci_dev *sb, struct pci_access *pacc); |