diff options
author | Jason M. Bills <jason.m.bills@linux.intel.com> | 2019-10-17 04:06:56 +0300 |
---|---|---|
committer | Bills, Jason M <jason.m.bills@intel.com> | 2019-10-25 18:51:09 +0300 |
commit | e652d91e36ca1a48215ca22cb8fde6dbf2db5400 (patch) | |
tree | 4a81434d53f6d4b5cfc5c2b8c2630be3ce2298f4 | |
parent | 211e060da219cd38a9f0ebeb661b32d1c041edbe (diff) | |
download | provingground-e652d91e36ca1a48215ca22cb8fde6dbf2db5400.tar.xz |
Add a raw command to peci_cmds
This change adds a raw command to peci_cmds that can be used to
send a raw PECI command to the CPU.
Tested:
peci_cmds raw 0x30
ERROR: Unsupported arguments for raw command
peci_cmds raw 0x30 5 9 0xa1 0 0 0
ERROR: Incorrect write length for raw command
peci_cmds raw 0x30 5 9 0xa1 0 0 0 0
0x40 0x54 0x06 0x05 0x00 0x00 0x00 0x00 0x00
Change-Id: If1cb4c06d379786faea1ca0f8f9dc1a286aa98d6
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
-rw-r--r-- | libpeci/peci_cmds.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/libpeci/peci_cmds.c b/libpeci/peci_cmds.c index 91e7eb9..0123961 100644 --- a/libpeci/peci_cmds.c +++ b/libpeci/peci_cmds.c @@ -65,6 +65,7 @@ void Usage(char* progname) "Endpoint PCI Config Write <Seg Bus Dev Func Reg Data>"); printf("\t%-28s%s\n", "RdEndpointConfigMMIO", "Endpoint MMIO Read <AType Bar Seg Bus Dev Func Reg>"); + printf("\t%-28s%s\n", "raw", "Raw PECI command in hex bytes"); printf("\n"); } @@ -575,6 +576,76 @@ int main(int argc, char* argv[]) } printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, u32PciReadVal); } + else if (strcmp(cmd, "raw") == 0) + { + if ((argc - optind) < 3) + { + printf("ERROR: Unsupported arguments for raw command\n"); + goto ErrorExit; + } + + // Address is provided in the first byte of the PECI command + uint8_t rawAddr = (uint8_t)strtoul(argv[optind++], NULL, 16); + // Write length is provided in the second byte of the PECI command + uint8_t writeLength = (uint8_t)strtoul(argv[optind++], NULL, 16); + // Read length is provided in the third byte of the PECI command + uint8_t readLength = (uint8_t)strtoul(argv[optind++], NULL, 16); + + // remaining parameters should match write length + if ((argc - optind) != writeLength) + { + printf("ERROR: Incorrect write length for raw command\n"); + goto ErrorExit; + } + uint8_t* rawCmd = (uint8_t*)calloc(writeLength, sizeof(uint8_t)); + if (rawCmd == NULL) + { + // calloc failed, abort the sequence + printf("Raw command memory allocation failed\n"); + return 1; + } + for (i = 0; i < writeLength; i++) + { + rawCmd[i] = (uint8_t)strtoul(argv[i + optind], NULL, 16); + } + if (verbose) + { + printf("Raw command: %02x %02x %02x ", rawAddr, writeLength, + readLength); + for (i = 0; i < writeLength; i++) + { + printf("0x%02x ", rawCmd[i]); + } + printf("\n"); + } + + uint8_t* rawResp = (uint8_t*)calloc(readLength, sizeof(uint8_t)); + if (rawResp == NULL) + { + // calloc failed, abort the sequence + printf("Raw command memory allocation failed\n"); + free(rawCmd); + return 1; + } + ret = peci_raw(rawAddr, readLength, rawCmd, writeLength, rawResp, + readLength); + if (0 != ret) + { + printf("ERROR %d: command failed\n", ret); + free(rawCmd); + free(rawResp); + return 1; + } + printf(" "); + for (i = 0; i < readLength; i++) + { + printf("0x%02x ", rawResp[i]); + } + printf("\n"); + + free(rawCmd); + free(rawResp); + } else { printf("ERROR: Unrecognized command\n"); |