summaryrefslogtreecommitdiff
path: root/libpeci/peci_cmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'libpeci/peci_cmds.c')
-rw-r--r--libpeci/peci_cmds.c191
1 files changed, 80 insertions, 111 deletions
diff --git a/libpeci/peci_cmds.c b/libpeci/peci_cmds.c
index 9aafe06..efc5b86 100644
--- a/libpeci/peci_cmds.c
+++ b/libpeci/peci_cmds.c
@@ -39,7 +39,6 @@ void Usage(char* progname)
printf("\t%s [-a <addr>] [-s <size>] <command> [parameters]\n", progname);
printf("\t\t-a : Address of the target in decimal. Default is 48.\n");
printf("\t\t-s : Size of data to read or write in bytes. Default is 4.\n");
- printf("\t\t-b : Display completion code.\n");
printf("\t\t-n : Ping the target.\n");
printf("\t\t-t : Get the temperature.\n");
printf("\t\t-d : Get the DIB.\n");
@@ -54,15 +53,15 @@ void Usage(char* progname)
"[Reg]>.\n");
printf("\t\t-lw : Local PCI Write for specific hex address <Bus Dev Func "
"[Reg] Data>.\n");
- printf("\t\t-e : Endpoint Local PCI Config Read <Seg Bus Dev Func [Reg]>."
- "\n");
+ printf(
+ "\t\t-e : Endpoint Local PCI Config Read <Seg Bus Dev Func [Reg]>.\n");
printf("\t\t-ew : Endpoint Local PCI Config Write <Seg Bus Dev Func [Reg] "
"Data>.\n");
printf("\t\t-f : Endpoint PCI Config Read <Seg Bus Dev Func [Reg]>.\n");
- printf("\t\t-fw : Endpoint PCI Config Write <Seg Bus Dev Func [Reg] Data>."
- "\n");
- printf("\t\t-g : Endpoint MMIO Read <AType Bar Seg Bus Dev Func [Reg]>."
- "\n");
+ printf(
+ "\t\t-fw : Endpoint PCI Config Write <Seg Bus Dev Func [Reg] Data>.\n");
+ printf(
+ "\t\t-g : Endpoint MMIO Read <AType Bar Seg Bus Dev Func [Reg]>.\n");
printf("\n");
}
@@ -94,12 +93,11 @@ int main(int argc, char* argv[])
uint64_t dib;
uint8_t u8Index = 0;
uint8_t cc = 0;
- bool showCc = false;
//
// Parse arguments.
//
- while (-1 != (c = getopt(argc, argv, "a:s:nbtdp::c::m::l::e::f::g")))
+ while (-1 != (c = getopt(argc, argv, "a:s:ntdp::c::m::l::e::f::g")))
{
switch (c)
{
@@ -113,10 +111,6 @@ int main(int argc, char* argv[])
u8Size = (unsigned char)atoi(optarg);
break;
- case 'b':
- showCc = true;
- break;
-
case 'n':
cnt++;
u8Cmd = PECI_CMD_PING;
@@ -193,23 +187,24 @@ int main(int argc, char* argv[])
//
// Execute the command
//
- printf("PECI target[%u]: ", (int)address);
+ printf("PECI target[%u]: ", address);
switch (u8Cmd)
{
case PECI_CMD_PING:
printf("Pinging ... ");
- (0 == peci_Ping(address)) ? printf("Succeeded.\n")
- : printf("Failed.\n");
+ (0 == peci_Ping(address)) ? printf("Succeeded\n")
+ : printf("Failed\n");
break;
case PECI_CMD_GET_TEMP:
+ printf("GetTemp\n");
ret = peci_GetTemp(address, &temperature);
if (0 != ret)
{
- printf("ERROR: Retrieving temperature failed.\n");
+ printf("ERROR %d: Retrieving temperature failed\n", ret);
break;
}
- printf("Temperature is %04xh (%c%d.%02dC).\n",
+ printf(" %04xh (%c%d.%02dC)\n",
(int)(unsigned int)(unsigned short)temperature,
(0 > temperature) ? '-' : '+',
(int)((unsigned int)ABS(temperature) / 64),
@@ -217,13 +212,14 @@ int main(int argc, char* argv[])
break;
case PECI_CMD_GET_DIB:
+ printf("GetDIB\n");
ret = peci_GetDIB(address, &dib);
if (0 != ret)
{
- printf("ERROR: Retrieving DIB failed.\n");
+ printf("ERROR %d: Retrieving DIB failed\n", ret);
break;
}
- printf("GetDIB Returned: 0x%" PRIx64 "\n", dib);
+ printf(" 0x%" PRIx64 "\n", dib);
break;
case PECI_CMD_RD_PCI_CFG:
@@ -240,21 +236,20 @@ int main(int argc, char* argv[])
u8PciBus = strtoul(argv[--u8Index], NULL, 16);
break;
default:
- printf("ERROR: Unsupported arguments for PCI Write\n");
+ printf("ERROR: Unsupported arguments for PCI Read\n");
goto ErrorExit;
break;
}
+ printf("PCI Read of %02x:%02x:%02x Reg %02x\n", u8PciBus, u8PciDev,
+ u8PciFunc, u16PciReg);
ret = peci_RdPCIConfig(address, u8PciBus, u8PciDev, u8PciFunc,
u16PciReg, (uint8_t*)&u32PciReadVal, &cc);
- if (showCc)
- printf("PCI Read cc:0x%x\n", cc);
if (0 != ret)
{
- printf("ERROR: PCI Read failed or is not supported.\n");
+ printf("ERROR %d: command failed\n", ret);
break;
}
- printf("PCI Read of %02x:%02x:%02x Reg %02x: 0x%0*x\n", u8PciBus,
- u8PciDev, u8PciFunc, u16PciReg, u8Size * 2, u32PciReadVal);
+ printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, u32PciReadVal);
break;
case PECI_CMD_RD_PKG_CFG:
@@ -270,17 +265,16 @@ int main(int argc, char* argv[])
goto ErrorExit;
break;
}
+ printf("Pkg Read of Index %02x Param %04x\n", u8PkgIndex,
+ u16PkgParam);
ret = peci_RdPkgConfig(address, u8PkgIndex, u16PkgParam, u8Size,
(uint8_t*)&u32PkgValue, &cc);
- if (showCc)
- printf("Pkg Read cc:0x%x\n", cc);
if (0 != ret)
{
- printf("ERROR: Read Package failed or is not supported.\n");
+ printf("ERROR %d: command failed\n", ret);
break;
}
- printf("Pkg Read of Index %02x Param %04x: 0x%0*x\n", u8PkgIndex,
- u16PkgParam, u8Size * 2, u32PkgValue);
+ printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, u32PkgValue);
break;
case PECI_CMD_WR_PKG_CFG:
@@ -301,10 +295,12 @@ int main(int argc, char* argv[])
u16PkgParam, u8Size * 2, u32PkgValue);
ret = peci_WrPkgConfig(address, u8PkgIndex, u16PkgParam,
u32PkgValue, u8Size, &cc);
- if (showCc)
- printf("Pkg Write cc:0x%x\n", cc);
- (0 == ret) ? printf("Succeeded.\n")
- : printf("Failed or not supported.\n");
+ if (0 != ret)
+ {
+ printf("ERROR %d: command failed\n", ret);
+ break;
+ }
+ printf(" cc:0x%02x\n", cc);
break;
case PECI_CMD_RD_IA_MSR:
@@ -320,17 +316,16 @@ int main(int argc, char* argv[])
goto ErrorExit;
break;
}
+ printf("MSR Read of Thread %02x MSR %04x\n", u8MsrThread,
+ u16MsrAddr);
ret =
peci_RdIAMSR(address, u8MsrThread, u16MsrAddr, &u64MsrVal, &cc);
- if (showCc)
- printf("MSR Read cc:0x%x\n", cc);
if (0 != ret)
{
- printf("ERROR: Read MSR failed or is not supported. %x\n", ret);
+ printf("ERROR %d: command failed\n", ret);
break;
}
- printf("MSR Read of Thread %02x MSR %04x: 0x%0*" PRIx64 "\n",
- u8MsrThread, u16MsrAddr, u8Size * 2, u64MsrVal);
+ printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, u64MsrVal);
break;
case PECI_CMD_RD_PCI_CFG_LOCAL:
@@ -347,24 +342,21 @@ int main(int argc, char* argv[])
u8PciBus = strtoul(argv[--u8Index], NULL, 16);
break;
default:
- printf(
- "ERROR: Unsupported arguments for Local PCI Write\n");
+ printf("ERROR: Unsupported arguments for Local PCI Read\n");
goto ErrorExit;
break;
}
+ printf("Local PCI Read of %02x:%02x:%02x Reg %02x\n", u8PciBus,
+ u8PciDev, u8PciFunc, u16PciReg);
ret = peci_RdPCIConfigLocal(address, u8PciBus, u8PciDev, u8PciFunc,
u16PciReg, u8Size,
(uint8_t*)&u32PciReadVal, &cc);
- if (showCc)
- printf("Local PCI Read cc:0x%x\n", cc);
if (0 != ret)
{
- printf("ERROR: Local PCI Read failed or is not supported.\n");
+ printf("ERROR %d: command failed\n", ret);
break;
}
- printf("Local PCI Read of %02x:%02x:%02x Reg %02x: 0x%0*x\n",
- u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2,
- u32PciReadVal);
+ printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, u32PciReadVal);
break;
case PECI_CMD_WR_PCI_CFG_LOCAL:
@@ -392,10 +384,12 @@ int main(int argc, char* argv[])
u32PciWriteVal);
ret = peci_WrPCIConfigLocal(address, u8PciBus, u8PciDev, u8PciFunc,
u16PciReg, u8Size, u32PciWriteVal, &cc);
- if (showCc)
- printf("Local PCI Write cc:0x%x\n", cc);
- (0 == ret) ? printf("Succeeded.\n")
- : printf("Failed or not supported.\n");
+ if (0 != ret)
+ {
+ printf("ERROR %d: command failed\n", ret);
+ break;
+ }
+ printf(" cc:0x%02x\n", cc);
break;
case PECI_CMD_RD_END_PT_CFG_LOCAL_PCI:
@@ -411,28 +405,22 @@ int main(int argc, char* argv[])
break;
default:
- printf("ERROR: Unsupported arguments for Endpoint Local"
+ printf("ERROR: Unsupported arguments for Endpoint Local "
"PCI Read\n");
goto ErrorExit;
}
-
+ printf(
+ "Endpoint Local PCI Read of Seg:%02x %02x:%02x:%02x Reg %02x\n",
+ u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg);
ret = peci_RdEndPointConfigPciLocal(
address, u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg,
u8Size, (uint8_t*)&u32PciReadVal, &cc);
- if (showCc)
- {
- printf("Endpoint Local PCI Read cc:0x%x\n", cc);
- }
- printf("Seg:%02x %02x:%02x:%02x "
- "Reg %02x: 0x%0*x\n",
- u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2,
- u32PciReadVal);
if (0 != ret)
{
- printf("ERROR: Endpoint Local PCI Read failed or is "
- "not supported.\n");
+ printf("ERROR %d: command failed\n", ret);
break;
}
+ printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, u32PciReadVal);
break;
case PECI_CMD_WR_END_PT_CFG_LOCAL_PCI:
@@ -453,23 +441,19 @@ int main(int argc, char* argv[])
"PCI Write\n");
goto ErrorExit;
}
-
+ printf("Endpoint Local PCI Write of Seg:%02x %02x:%02x:%02x Reg "
+ "%02x: 0x%0*x\n",
+ u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2,
+ u32PciWriteVal);
ret = peci_WrEndPointPCIConfigLocal(address, u8Seg, u8PciBus,
u8PciDev, u8PciFunc, u16PciReg,
u8Size, u32PciWriteVal, &cc);
- if (showCc)
- {
- printf("Endpoint Local PCI Write cc:0x%x\n", cc);
- }
- printf("Seg:%02x %02x:%02x:%02x Reg %02x: 0x%0*x\n", u8Seg,
- u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2,
- u32PciWriteVal);
if (0 != ret)
{
- printf("ERROR: Endpoint Local PCI Write failed "
- "or is not supported.\n");
+ printf("ERROR %d: command failed\n", ret);
break;
}
+ printf(" cc:0x%02x\n", cc);
break;
case PECI_CMD_RD_END_PT_CFG_PCI:
@@ -485,27 +469,21 @@ int main(int argc, char* argv[])
break;
default:
- printf("ERROR: Unsupported arguments for Endpoint PCI Read"
- "\n");
+ printf(
+ "ERROR: Unsupported arguments for Endpoint PCI Read\n");
goto ErrorExit;
}
-
+ printf("Endpoint PCI Read of Seg:%02x %02x:%02x:%02x Reg %02x\n",
+ u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg);
ret = peci_RdEndPointConfigPci(address, u8Seg, u8PciBus, u8PciDev,
u8PciFunc, u16PciReg, u8Size,
(uint8_t*)&u32PciReadVal, &cc);
- if (showCc)
- {
- printf("Endpoint PCI Read cc:0x%x\n", cc);
- }
- printf("Seg:%02x %02x:%02x:%02x Reg %02x: 0x%0*x\n", u8Seg,
- u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2,
- u32PciReadVal);
if (0 != ret)
{
- printf("ERROR: Endpoint PCI Read failed or is not supported."
- "\n");
+ printf("ERROR %d: command failed\n", ret);
break;
}
+ printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, u32PciReadVal);
break;
case PECI_CMD_WR_END_PT_CFG_PCI:
@@ -522,27 +500,23 @@ int main(int argc, char* argv[])
break;
default:
- printf("ERROR: Unsupported arguments for Endpoint PCI Write"
- "\n");
+ printf("ERROR: Unsupported arguments for Endpoint PCI "
+ "Write\n");
goto ErrorExit;
}
-
+ printf("Endpoint PCI Write of Seg:%02x %02x:%02x:%02x Reg %02x: "
+ "0x%0*x\n",
+ u8Seg, u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2,
+ u32PciWriteVal);
ret = peci_WrEndPointPCIConfig(address, u8Seg, u8PciBus, u8PciDev,
u8PciFunc, u16PciReg, u8Size,
u32PciWriteVal, &cc);
- if (showCc)
- {
- printf("Endpoint PCI Write cc:0x%x\n", cc);
- }
- printf("Seg:%02x %02x:%02x:%02x Reg %02x: 0x%0*x\n", u8Seg,
- u8PciBus, u8PciDev, u8PciFunc, u16PciReg, u8Size * 2,
- u32PciWriteVal);
if (0 != ret)
{
- printf("ERROR: Endpoint PCI Write failed or is not supported."
- "\n");
+ printf("ERROR %d: command failed\n", ret);
break;
}
+ printf(" cc:0x%02x\n", cc);
break;
case PECI_CMD_RD_END_PT_CFG_MMIO:
@@ -560,28 +534,23 @@ int main(int argc, char* argv[])
break;
default:
- printf("ERROR: Unsupported arguments for Endpoint MMIO Read"
- "\n");
+ printf("ERROR: Unsupported arguments for Endpoint MMIO "
+ "Read\n");
goto ErrorExit;
}
-
+ printf("Endpoint MMIO Read of Seg:%02x %02x:%02x:%02x AType:%02x "
+ "Bar:%02x Offset:0x%" PRIx64 "\n",
+ u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8AddrType, u8Bar,
+ u64Offset);
ret = peci_RdEndPointConfigMmio(
address, u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8Bar,
u8AddrType, u64Offset, u8Size, (uint8_t*)&u32PciReadVal, &cc);
- if (showCc)
- {
- printf("Endpoint MMIO Read cc:0x%x\n", cc);
- }
- printf("Seg:%02x %02x:%02x:%02x AType:%02x Bar:%02x "
- "Offset:0x%" PRIx64 " Data:0x%0*x\n",
- u8Seg, u8PciBus, u8PciDev, u8PciFunc, u8AddrType, u8Bar,
- u64Offset, u8Size * 2, u32PciReadVal);
if (0 != ret)
{
- printf("ERROR: Endpoint MMIO Read failed or is not supported."
- "\n");
+ printf("ERROR %d: command failed\n", ret);
break;
}
+ printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, u32PciReadVal);
break;
default: