371
373
else registers = model_info->registers;
374
pcilib_register_bank_addr_t bank_addr;
376
pcilib_register_bank_addr_t bank_addr = 0;
376
378
pcilib_register_bank_t bank_id = pcilib_find_bank(handle, bank);
377
379
pcilib_register_bank_description_t *b = model_info->banks + bank_id;
459
461
int i, j, errors;
460
462
void *data, *buf, *check;
462
464
struct timeval start, end;
463
465
unsigned long time;
464
466
size_t size, min_size, max_size;
483
485
err = pcilib_wait_irq(handle, 0, 0, &irqs);
484
486
if (err) irqs = 0;
486
printf("%8i KB - ", size / 1024);
488
printf("%8zu KB - ", size / 1024);
489
491
if (mbs < 0) printf("failed ... ");
571
573
gettimeofday(&end,NULL);
573
575
time = (end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec);
574
printf("%8i bytes - read: %8.2lf MB/s", size, 1000000. * size * BENCHMARK_ITERATIONS / (time * 1024. * 1024.));
576
printf("%8zu bytes - read: %8.2lf MB/s", size, 1000000. * size * BENCHMARK_ITERATIONS / (time * 1024. * 1024.));
611
613
gettimeofday(&end,NULL);
613
615
time = (end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec);
614
printf("%8i bytes - read: %8.2lf MB/s", size, 1000000. * size * BENCHMARK_ITERATIONS / (time * 1024. * 1024.));
616
printf("%8zu bytes - read: %8.2lf MB/s", size, 1000000. * size * BENCHMARK_ITERATIONS / (time * 1024. * 1024.));
873
877
int access = banks[bank_id].access / 8;
874
int size = n * abs(access);
878
// int size = n * abs(access);
875
879
int block_width, blocks_per_line;
876
880
int numbers_per_block, numbers_per_line;
918
922
int WriteData(pcilib_t *handle, ACCESS_MODE mode, pcilib_dma_engine_addr_t dma, pcilib_bar_t bar, uintptr_t addr, size_t n, access_t access, int endianess, char ** data) {
919
923
int read_back = 0;
920
924
void *buf, *check;
922
926
int size = n * abs(access);
924
928
pcilib_dma_engine_t dmaid;
933
937
case 2: res = sscanf(data[i], "%hx", ((uint16_t*)buf)+i); break;
934
938
case 4: res = sscanf(data[i], "%x", ((uint32_t*)buf)+i); break;
935
939
case 8: res = sscanf(data[i], "%lx", ((uint64_t*)buf)+i); break;
940
default: Error("Unexpected data size (%lu)", access);
937
942
if ((res != 1)||(!isxnumber(data[i]))) Error("Can't parse data value at poition %i, (%s) is not valid hex number", i, data[i]);
1011
1016
int WriteRegister(pcilib_t *handle, pcilib_model_description_t *model_info, const char *bank, const char *reg, char ** data) {
1015
1019
unsigned long val;
1016
1020
pcilib_register_value_t value;
1022
const char *format = NULL;
1020
1024
pcilib_register_t regid = pcilib_find_register(handle, bank, reg);
1021
1025
if (regid == PCILIB_REGISTER_INVALID) Error("Can't find register (%s) from bank (%s)", reg, bank?bank:"autodetected");
1119
1123
if (info->flags&PCILIB_EVENT_INFO_FLAG_BROKEN) {
1120
1124
ctx->broken_count++;
1125
return PCILIB_STREAMING_CONTINUE;
1124
1128
data = pcilib_get_data(handle, event_id, ctx->data, &size);
1126
1130
ctx->broken_count++;
1131
return PCILIB_STREAMING_CONTINUE;
1136
1140
else Error("Write failed");
1139
pcilib_return_data(handle, event_id, data);
1143
pcilib_return_data(handle, event_id, ctx->data, data);
1141
1145
// printf("%lu %lu\n", info->seqnum, info->offset);
1163
1167
// printf("data callback: %lu\n", event_id);
1168
return PCILIB_STREAMING_CONTINUE;
1167
1171
int raw_data(pcilib_event_id_t event_id, pcilib_event_info_t *info, pcilib_event_flags_t flags, size_t size, void *data, void *user) {
1168
1172
// printf("%i\n", event_id);
1173
return PCILIB_STREAMING_CONTINUE;
1582
1587
printf("%08lx ", uses[i].use);
1583
1588
if (!i) printf("All Others ");
1584
else if ((uses[i].use >> 16) == PCILIB_KMEM_USE_DMA_RING) printf("DMA%u %s Ring ", uses[i].use&0x7F, ((uses[i].use&0x80)?"S2C":"C2S"));
1585
else if ((uses[i].use >> 16) == PCILIB_KMEM_USE_DMA_PAGES) printf("DMA%u %s Pages ", uses[i].use&0x7F, ((uses[i].use&0x80)?"S2C":"C2S"));
1586
else printf (" ", uses[i].use);
1589
else if ((uses[i].use >> 16) == PCILIB_KMEM_USE_DMA_RING) printf("DMA%lu %s Ring ", uses[i].use&0x7F, ((uses[i].use&0x80)?"S2C":"C2S"));
1590
else if ((uses[i].use >> 16) == PCILIB_KMEM_USE_DMA_PAGES) printf("DMA%lu %s Pages ", uses[i].use&0x7F, ((uses[i].use&0x80)?"S2C":"C2S"));
1588
1593
printf("% 6lu", uses[i].count);
1613
1618
pcilib_kmem_handle_t *kbuf;
1615
1620
kbuf = pcilib_alloc_kernel_memory(handle, 0, block + 1, 0, 0, use, PCILIB_KMEM_FLAG_REUSE|PCILIB_KMEM_FLAG_TRY);
1617
1622
printf("The specified kernel buffer is not allocated\n");
1621
1626
data = pcilib_kmem_get_block_ua(handle, kbuf, block);
1623
1628
size = pcilib_kmem_get_block_size(handle, kbuf, block);
1627
1632
printf("The specified block is not existing\n");
1630
1635
pcilib_free_kernel_memory(handle, kbuf, KMEM_FLAG_REUSE);
1633
1640
int FreeKMEM(pcilib_t *handle, const char *device, const char *use, int force) {
1637
1644
unsigned long useid;
1639
1646
pcilib_kmem_flags_t flags = PCILIB_KMEM_FLAG_HARDWARE|PCILIB_KMEM_FLAG_PERSISTENT|PCILIB_KMEM_FLAG_EXCLUSIVE;
1640
1647
if (force) flags |= PCILIB_KMEM_FLAG_FORCE; // this will ignore mmap locks as well.
1657
1664
if ((!isxnumber(use))||(sscanf(use, "%lx", &useid) != 1)) Error("Invalid use (%s) is specified", use);
1659
1666
err = pcilib_clean_kernel_memory(handle, useid, flags);
1660
1667
if (err) Error("Error cleaning kernel buffers for use (0x%lx)", useid);
1689
1696
printf("--------------------------------------------------------------------------------\n");
1690
1697
while ((entry = readdir(dir)) != NULL) {
1696
unsigned long hwref;
1699
unsigned long use = 0;
1700
unsigned long size = 0;
1701
unsigned long refs = 0;
1702
unsigned long mode = 0;
1703
unsigned long hwref = 0;
1698
1705
if (strncmp(entry->d_name, "kbuf", 4)) continue;
1699
1706
if (!isnumber(entry->d_name+4)) continue;
1724
1731
if (dmaid == PCILIB_DMA_ENGINE_INVALID) continue;
1727
printf("DMA%u %s ", use&0x7F, (use&0x80)?"S2C":"C2S");
1734
printf("DMA%lu %s ", use&0x7F, (use&0x80)?"S2C":"C2S");
1728
1735
err = pcilib_start_dma(handle, dmaid, 0);
1730
1737
printf("-- Wrong state, start is failed\n");
1774
1781
dmaid = pcilib_find_dma_by_addr(handle, dma_direction, dma);
1775
1782
if (dmaid == PCILIB_DMA_ENGINE_INVALID) Error("The specified DMA engine is not found");
1777
1784
err = pcilib_start_dma(handle, dmaid, 0);
1778
1785
if (err) Error("Error starting the specified DMA engine");
1780
1787
err = pcilib_get_dma_status(handle, dmaid, &status, 0, NULL);
1781
1788
if (err) Error("Failed to obtain status of the specified DMA engine");
1783
1790
buffer = (pcilib_dma_buffer_status_t*)malloc(status.ring_size*sizeof(pcilib_dma_buffer_status_t));
1784
1791
if (!buffer) Error("Failed to allocate memory for status buffer");
1786
1793
err = pcilib_get_dma_status(handle, dmaid, &status, status.ring_size, buffer);
1787
1794
if (err) Error("Failed to obtain extended status of the specified DMA engine");
1790
1797
printf("Buffer Status Total Size \n");
1791
1798
printf("--------------------------------------------------------------------------------\n");
1793
1800
for (i = 0; i < status.ring_size; i++) {
1794
1801
printf("%8zu ", i);
1795
1802
printf("%c%c %c%c ", buffer[i].used?'U':' ', buffer[i].error?'E':' ', buffer[i].first?'F':' ', buffer[i].last?'L':' ');
1796
1803
printf("% 10s", PrintSize(stmp, buffer[i].size));
1800
1807
printf("--------------------------------------------------------------------------------\n");
1801
1808
printf("U - Used, E - Error, F - First block, L - Last Block\n");
1805
1812
pcilib_stop_dma(handle, dmaid, 0);
1809
1817
int ReadBuffer(pcilib_t *handle, const char *device, pcilib_model_description_t *model_info, pcilib_dma_engine_addr_t dma, pcilib_dma_direction_t dma_direction, size_t block, FILE *o) {
1812
1819
pcilib_dma_engine_t dmaid;
1813
1820
pcilib_dma_engine_status_t status;
1814
1821
pcilib_dma_buffer_status_t *buffer;
1818
1824
dmaid = pcilib_find_dma_by_addr(handle, dma_direction, dma);
1819
1825
if (dmaid == PCILIB_DMA_ENGINE_INVALID) Error("The specified DMA engine is not found");
1902
1908
const char *data_type = NULL;
1903
1909
const char *dma_channel = NULL;
1904
1910
const char *use = NULL;
1905
pcilib_kmem_use_t use_id;
1911
pcilib_kmem_use_t use_id = 0;
1906
1912
size_t block = 0;
1907
pcilib_irq_hw_source_t irq_source;
1913
pcilib_irq_hw_source_t irq_source = PCILIB_IRQ_SOURCE_DEFAULT;
1908
1914
pcilib_dma_direction_t dma_direction = PCILIB_DMA_BIDIRECTIONAL;
1910
1916
pcilib_dma_engine_addr_t dma = PCILIB_DMA_ENGINE_ADDR_INVALID;
2046
2052
mode = MODE_WAIT_IRQ;
2047
2053
if (optarg) num_offset = optarg;
2048
2054
else if ((optind < argc)&&(argv[optind][0] != '-')) num_offset = argv[optind++];
2055
else num_offset = NULL;
2050
if ((!isnumber(num_offset))||(sscanf(num_offset, "%li", &itmp) != 1))
2051
Usage(argc, argv, "Invalid IRQ source is specified (%s)", num_offset);
2058
if ((!isnumber(num_offset))||(sscanf(num_offset, "%li", &itmp) != 1))
2059
Usage(argc, argv, "Invalid IRQ source is specified (%s)", num_offset);
2055
2064
case OPT_LIST_KMEM:
2056
2065
if (mode != MODE_INVALID) Usage(argc, argv, "Multiple operations are not supported");
2135
if ((!isnumber(optarg))||(sscanf(optarg, "%zu", &size) != 1))
2144
if ((!isnumber(optarg))||(sscanf(optarg, "%zu", &size) != 1)) {
2136
2145
if (strcasecmp(optarg, "unlimited"))
2137
2146
Usage(argc, argv, "Invalid size is specified (%s)", optarg);
2139
2148
size = 0;//(size_t)-1;
2153
2163
case OPT_TIMEOUT:
2154
if ((!isnumber(optarg))||(sscanf(optarg, "%zu", &timeout) != 1))
2164
if ((!isnumber(optarg))||(sscanf(optarg, "%zu", &timeout) != 1)) {
2155
2165
if (strcasecmp(optarg, "unlimited"))
2156
2166
Usage(argc, argv, "Invalid timeout is specified (%s)", optarg);
2158
2168
timeout = PCILIB_TIMEOUT_INFINITE;
2159
2170
timeout_set = 1;
2161
2172
case OPT_OUTPUT:
2172
2183
data_type = optarg;
2174
2185
case OPT_RUN_TIME:
2175
if ((!isnumber(optarg))||(sscanf(optarg, "%zu", &run_time) != 1))
2186
if ((!isnumber(optarg))||(sscanf(optarg, "%zu", &run_time) != 1)) {
2176
2187
if (strcasecmp(optarg, "unlimited"))
2177
2188
Usage(argc, argv, "Invalid run-time is specified (%s)", optarg);
2180
2192
run_time_set = 1;
2182
2194
case OPT_TRIGGER_TIME: