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.c230
1 files changed, 228 insertions, 2 deletions
diff --git a/libpeci/peci_cmds.c b/libpeci/peci_cmds.c
index ba37810..9aafe06 100644
--- a/libpeci/peci_cmds.c
+++ b/libpeci/peci_cmds.c
@@ -22,6 +22,15 @@
#define ABS(_v_) (((_v_) > 0) ? (_v_) : -(_v_))
#endif
+enum peci_cmd_subtype
+{
+ PECI_CMD_RD_END_PT_CFG_LOCAL_PCI = PECI_CMD_MAX + 1,
+ PECI_CMD_RD_END_PT_CFG_PCI,
+ PECI_CMD_RD_END_PT_CFG_MMIO,
+ PECI_CMD_WR_END_PT_CFG_LOCAL_PCI,
+ PECI_CMD_WR_END_PT_CFG_PCI,
+};
+
extern EPECIStatus peci_GetDIB(uint8_t target, uint64_t* dib);
void Usage(char* progname)
@@ -45,6 +54,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-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("\n");
}
@@ -57,10 +75,14 @@ int main(int argc, char* argv[])
uint8_t address = 0x30; // use default address of 48d
uint8_t u8Size = 4; // default to a DWORD
uint32_t u32PciReadVal = 0;
+ uint8_t u8Seg = 0;
+ uint8_t u8Bar = 0;
+ uint8_t u8AddrType = 0;
uint8_t u8PciBus = 0;
uint8_t u8PciDev = 0;
uint8_t u8PciFunc = 0;
uint16_t u16PciReg = 0;
+ uint64_t u64Offset = 0;
uint32_t u32PciWriteVal = 0;
uint8_t u8PkgIndex = 0;
uint16_t u16PkgParam = 0;
@@ -77,7 +99,7 @@ int main(int argc, char* argv[])
//
// Parse arguments.
//
- while (-1 != (c = getopt(argc, argv, "a:s:nbtdp::c::m::l::")))
+ while (-1 != (c = getopt(argc, argv, "a:s:nbtdp::c::m::l::e::f::g")))
{
switch (c)
{
@@ -136,6 +158,25 @@ int main(int argc, char* argv[])
u8Cmd = PECI_CMD_WR_PCI_CFG_LOCAL;
break;
+ case 'e':
+ cnt++;
+ u8Cmd = PECI_CMD_RD_END_PT_CFG_LOCAL_PCI;
+ if (optarg != NULL && optarg[0] == 'w')
+ u8Cmd = PECI_CMD_WR_END_PT_CFG_LOCAL_PCI;
+ break;
+
+ case 'f':
+ cnt++;
+ u8Cmd = PECI_CMD_RD_END_PT_CFG_PCI;
+ if (optarg != NULL && optarg[0] == 'w')
+ u8Cmd = PECI_CMD_WR_END_PT_CFG_PCI;
+ break;
+
+ case 'g':
+ cnt++;
+ u8Cmd = PECI_CMD_RD_END_PT_CFG_MMIO;
+ break;
+
default:
printf("ERROR: Unrecognized option \"-%c\".\n", optopt);
goto ErrorExit;
@@ -357,10 +398,195 @@ int main(int argc, char* argv[])
: printf("Failed or not supported.\n");
break;
+ case PECI_CMD_RD_END_PT_CFG_LOCAL_PCI:
+ u8Index = argc;
+ switch (argc - optind)
+ {
+ case 5:
+ u16PciReg = strtoul(argv[--u8Index], NULL, 16);
+ u8PciFunc = strtoul(argv[--u8Index], NULL, 16);
+ u8PciDev = strtoul(argv[--u8Index], NULL, 16);
+ u8PciBus = strtoul(argv[--u8Index], NULL, 16);
+ u8Seg = strtoul(argv[--u8Index], NULL, 16);
+ break;
+
+ default:
+ printf("ERROR: Unsupported arguments for Endpoint Local"
+ "PCI Read\n");
+ goto ErrorExit;
+ }
+
+ 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");
+ break;
+ }
+ break;
+
+ case PECI_CMD_WR_END_PT_CFG_LOCAL_PCI:
+ u8Index = argc;
+ switch (argc - optind)
+ {
+ case 6:
+ u32PciWriteVal = strtoul(argv[--u8Index], NULL, 16);
+ u16PciReg = strtoul(argv[--u8Index], NULL, 16);
+ u8PciFunc = strtoul(argv[--u8Index], NULL, 16);
+ u8PciDev = strtoul(argv[--u8Index], NULL, 16);
+ u8PciBus = strtoul(argv[--u8Index], NULL, 16);
+ u8Seg = strtoul(argv[--u8Index], NULL, 16);
+ break;
+
+ default:
+ printf("ERROR: Unsupported arguments for Endpoint Local "
+ "PCI Write\n");
+ goto ErrorExit;
+ }
+
+ 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");
+ break;
+ }
+ break;
+
+ case PECI_CMD_RD_END_PT_CFG_PCI:
+ u8Index = argc;
+ switch (argc - optind)
+ {
+ case 5:
+ u16PciReg = strtoul(argv[--u8Index], NULL, 16);
+ u8PciFunc = strtoul(argv[--u8Index], NULL, 16);
+ u8PciDev = strtoul(argv[--u8Index], NULL, 16);
+ u8PciBus = strtoul(argv[--u8Index], NULL, 16);
+ u8Seg = strtoul(argv[--u8Index], NULL, 16);
+ break;
+
+ default:
+ printf("ERROR: Unsupported arguments for Endpoint PCI Read"
+ "\n");
+ goto ErrorExit;
+ }
+
+ 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");
+ break;
+ }
+ break;
+
+ case PECI_CMD_WR_END_PT_CFG_PCI:
+ u8Index = argc;
+ switch (argc - optind)
+ {
+ case 6:
+ u32PciWriteVal = strtoul(argv[--u8Index], NULL, 16);
+ u16PciReg = strtoul(argv[--u8Index], NULL, 16);
+ u8PciFunc = strtoul(argv[--u8Index], NULL, 16);
+ u8PciDev = strtoul(argv[--u8Index], NULL, 16);
+ u8PciBus = strtoul(argv[--u8Index], NULL, 16);
+ u8Seg = strtoul(argv[--u8Index], NULL, 16);
+ break;
+
+ default:
+ printf("ERROR: Unsupported arguments for Endpoint PCI Write"
+ "\n");
+ goto ErrorExit;
+ }
+
+ 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");
+ break;
+ }
+ break;
+
+ case PECI_CMD_RD_END_PT_CFG_MMIO:
+ u8Index = argc;
+ switch (argc - optind)
+ {
+ case 7:
+ u64Offset = strtoul(argv[--u8Index], NULL, 16);
+ u8PciFunc = strtoul(argv[--u8Index], NULL, 16);
+ u8PciDev = strtoul(argv[--u8Index], NULL, 16);
+ u8PciBus = strtoul(argv[--u8Index], NULL, 16);
+ u8Seg = strtoul(argv[--u8Index], NULL, 16);
+ u8Bar = strtoul(argv[--u8Index], NULL, 16);
+ u8AddrType = strtoul(argv[--u8Index], NULL, 16);
+ break;
+
+ default:
+ printf("ERROR: Unsupported arguments for Endpoint MMIO Read"
+ "\n");
+ goto ErrorExit;
+ }
+
+ 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");
+ break;
+ }
+ break;
+
default:
printf("ERROR: Unrecognized command\n");
goto ErrorExit;
- break;
}
return 0;