/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to pci.c

  • Committer: Suren A. Chilingaryan
  • Date: 2011-02-13 14:33:26 UTC
  • Revision ID: csa@dside.dyndns.org-20110213143326-ud52k05tc0qj35ps
Print a bit more details

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
#include <getopt.h>
32
32
 
 
33
 
33
34
#include "driver/pciDriver.h"
34
35
 
 
36
#include "kernel.h"
35
37
#include "tools.h"
36
38
 
37
39
/* defines */
160
162
 
161
163
    for (i = 0; i < MAX_BANKS; i++) {
162
164
        if (board_info.bar_length[i] > 0) {
163
 
            printf(" BAR %d - Start: 0x%x, Length: 0x%x\n", i, board_info.bar_start[i], board_info.bar_length[i] );
 
165
            printf(" BAR %d - ", i);
 
166
 
 
167
            switch ( board_info.bar_flags[i]&IORESOURCE_TYPE_BITS) {
 
168
                case IORESOURCE_IO:  printf(" IO"); break;
 
169
                case IORESOURCE_MEM: printf("MEM"); break;
 
170
                case IORESOURCE_IRQ: printf("IRQ"); break;
 
171
                case IORESOURCE_DMA: printf("DMA"); break;
 
172
            }
 
173
            
 
174
            if (board_info.bar_flags[i]&IORESOURCE_MEM_64) printf("64");
 
175
            else printf("32");
 
176
            
 
177
            printf(", Start: 0x%08lx, Length: 0x% 8lx, Flags: 0x%08lx\n", board_info.bar_start[i], board_info.bar_length[i], board_info.bar_flags[i] );
164
178
        }
165
179
    }
166
180
}
168
182
void Info(int handle) {
169
183
    GetBoardInfo(handle);
170
184
 
171
 
    printf("Vendor: %lx, Device: %lx, Interrupt Pin: %i, Interrupt Line: %i\n", board_info.vendor_id, board_info.device_id, board_info.interrupt_pin, board_info.interrupt_line);
 
185
    printf("Vendor: %x, Device: %x, Interrupt Pin: %i, Interrupt Line: %i\n", board_info.vendor_id, board_info.device_id, board_info.interrupt_pin, board_info.interrupt_line);
172
186
    List(handle);
173
187
}
174
188
 
281
295
 
282
296
 
283
297
int Benchmark(int handle, int bar) {
284
 
    int i;
 
298
    int i, errors;
285
299
    void *data, *buf, *check;
286
300
    struct timeval start, end;
287
301
    unsigned long time;
358
372
        printf(", write: %8.2lf MB/s", 1000000. * size * BENCHMARK_ITERATIONS / (time * 1024 * 1024));
359
373
 
360
374
        gettimeofday(&start,NULL);
361
 
        for (i = 0; i < BENCHMARK_ITERATIONS; i++) {
 
375
        for (i = 0, errors = 0; i < BENCHMARK_ITERATIONS; i++) {
362
376
            Write(buf, handle, bar, 0, size);
363
377
            Read(check, handle, bar, 0, size);
364
 
            memcmp(buf, check, size);
 
378
            if (memcmp(buf, check, size)) ++errors;
365
379
        }
366
380
        gettimeofday(&end,NULL);
367
381
 
368
382
        time = (end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec);
369
 
        printf(", write-verify: %8.2lf MB/s\n", 1000000. * size * BENCHMARK_ITERATIONS / (time * 1024 * 1024));
 
383
        printf(", write-verify: %8.2lf MB/s", 1000000. * size * BENCHMARK_ITERATIONS / (time * 1024 * 1024));
 
384
        if (errors) printf(", errors: %u of %u", errors, BENCHMARK_ITERATIONS);
 
385
        printf("\n");
370
386
    }
371
387
    
372
388
    printf("\n\n");
397
413
    Read(buf, handle, bar, addr, size);
398
414
 
399
415
    for (i = 0; i < n; i++) {
400
 
        if ((i)&&(i%numbers_per_line == 0)) printf("\n");
401
 
        else if ((i)&&(i%numbers_per_block == 0)) printf("%*s", BLOCK_SEPARATOR_WIDTH, "");
402
 
 
403
 
        if (i%numbers_per_line == 0) printf("%8lx: ", addr + i * abs(access));
 
416
        if (i) {
 
417
            if (i%numbers_per_line == 0) printf("\n");
 
418
            else {
 
419
                printf("%*s", SEPARATOR_WIDTH, "");
 
420
                if (i%numbers_per_block == 0) printf("%*s", BLOCK_SEPARATOR_WIDTH, "");
 
421
            }
 
422
        }
 
423
            
 
424
        if (i%numbers_per_line == 0) printf("%8lx:  ", addr + i * abs(access));
404
425
 
405
426
        switch (access) {
406
 
            case 1: printf("% *hhx", access * 2 +  SEPARATOR_WIDTH, ((uint8_t*)buf)[i]); break;
407
 
            case 2: printf("% *hx", access * 2 +  SEPARATOR_WIDTH, ((uint16_t*)buf)[i]); break;
408
 
            case 4: printf("% *x", access * 2 +  SEPARATOR_WIDTH, ((uint32_t*)buf)[i]); break;
409
 
            case 8: printf("% *lx", access * 2 +  SEPARATOR_WIDTH, ((uint64_t*)buf)[i]); break;
 
427
            case 1: printf("%0*hhx", access * 2, ((uint8_t*)buf)[i]); break;
 
428
            case 2: printf("%0*hx", access * 2, ((uint16_t*)buf)[i]); break;
 
429
            case 4: printf("%0*x", access * 2, ((uint32_t*)buf)[i]); break;
 
430
            case 8: printf("%0*lx", access * 2, ((uint64_t*)buf)[i]); break;
410
431
        }
411
432
    }
412
433
    printf("\n\n");
439
460
//    ReadData(handle, bar, addr, n, access);
440
461
    Read(check, handle, bar, addr, size);
441
462
    
442
 
    if (memcmp(buf, check, size)) Error("Write failed, the data written and read differ");
 
463
    if (memcmp(buf, check, size)) {
 
464
        printf("Write failed: the data written and read differ, the foolowing is read back:");
 
465
        ReadData(handle, bar, addr, n, access);
 
466
        exit(-1);
 
467
    }
443
468
 
444
469
    free(check);
445
470
    free(buf);