/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 pcitool/cli.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-11-19 01:21:30 UTC
  • Revision ID: csa@suren.me-20151119012130-e7qfp7563fqxqhiy
Driver versioning

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
 
75
75
typedef enum {
76
76
    MODE_INVALID,
 
77
    MODE_VERSION,
77
78
    MODE_INFO,
78
79
    MODE_LIST,
79
80
    MODE_BENCHMARK,
95
96
    MODE_DISABLE_IRQ,
96
97
    MODE_ACK_IRQ,
97
98
    MODE_WAIT_IRQ,
 
99
    MODE_SET_DMASK,
98
100
    MODE_ALLOC_KMEM,
99
101
    MODE_LIST_KMEM,
100
102
    MODE_READ_KMEM,
148
150
    OPT_GRAB = 'g',
149
151
    OPT_QUIETE = 'q',
150
152
    OPT_HELP = 'h',
151
 
    OPT_RESET = 128,
 
153
    OPT_VERSION = 128,
 
154
    OPT_RESET,
152
155
    OPT_BENCHMARK,
153
156
    OPT_TRIGGER,
154
157
    OPT_DATA_TYPE,
169
172
    OPT_ACK_IRQ,
170
173
    OPT_WAIT_IRQ,
171
174
    OPT_ITERATIONS,
 
175
    OPT_SET_DMASK,
172
176
    OPT_ALLOC_KMEM,
173
177
    OPT_LIST_KMEM,
174
178
    OPT_FREE_KMEM,
222
226
    {"disable-irq",             optional_argument, 0, OPT_DISABLE_IRQ },
223
227
    {"acknowledge-irq",         optional_argument, 0, OPT_ACK_IRQ },
224
228
    {"wait-irq",                optional_argument, 0, OPT_WAIT_IRQ },
 
229
    {"set-dma-mask",            required_argument, 0, OPT_SET_DMASK },
225
230
    {"list-kernel-memory",      optional_argument, 0, OPT_LIST_KMEM },
226
231
    {"read-kernel-memory",      required_argument, 0, OPT_READ_KMEM },
227
232
    {"alloc-kernel-memory",     required_argument, 0, OPT_ALLOC_KMEM },
239
244
    {"verify",                  no_argument, 0, OPT_VERIFY },
240
245
    {"multipacket",             no_argument, 0, OPT_MULTIPACKET },
241
246
    {"wait",                    no_argument, 0, OPT_WAIT },
 
247
    {"version",                 no_argument, 0, OPT_VERSION },
242
248
    {"help",                    no_argument, 0, OPT_HELP },
243
249
    { 0, 0, 0, 0 }
244
250
};
268
274
"   -w <addr|dmaX|reg|prop>     - Write Data/Register/Property\n"
269
275
"   --benchmark <barX|dmaX>     - Performance Evaluation\n"
270
276
"   --reset                     - Reset board\n"
 
277
"   --version                   - Version information\n"
271
278
"   --help                      - Help message\n"
272
279
"\n"
273
280
"  Property/Register Modes:\n"
297
304
"   --read-dma-buffer <dma:buf> - Read the specified buffer\n"
298
305
"\n"
299
306
"  Kernel Modes:\n"
 
307
"   --set-dma-mask [bits]       - Set DMA address width (DANGEROUS)\n"
300
308
"   --list-kernel-memory [use]  - List kernel buffers\n"
301
309
"   --read-kernel-memory <blk>  - Read the specified block of the kernel memory\n"
302
310
"                                 block is specified as: use:block_number\n"
840
848
    pcilib_free_register_info(handle, info);
841
849
}
842
850
 
 
851
void Version(pcilib_t *handle, const pcilib_model_description_t *model_info) {
 
852
    const pcilib_driver_version_t *driver_version;
 
853
 
 
854
    driver_version = pcilib_get_driver_version(handle);
 
855
 
 
856
    printf("pcilib version: %u.%u.%u\n",
 
857
        PCILIB_VERSION_GET_MAJOR(PCILIB_VERSION),
 
858
        PCILIB_VERSION_GET_MINOR(PCILIB_VERSION),
 
859
        PCILIB_VERSION_GET_MICRO(PCILIB_VERSION)
 
860
    );
 
861
 
 
862
    printf("driver version: %lu.%lu.%lu, interface: 0x%lx, registered ioctls: %lu\n",
 
863
        PCILIB_VERSION_GET_MAJOR(driver_version->version),
 
864
        PCILIB_VERSION_GET_MINOR(driver_version->version),
 
865
        PCILIB_VERSION_GET_MICRO(driver_version->version),
 
866
        driver_version->interface,
 
867
        driver_version->ioctls
 
868
    );
 
869
 
 
870
    if (model_info) {
 
871
        pcilib_version_t version = model_info->interface_version;
 
872
        printf("Model: %s", handle->model);
 
873
        if (version) {
 
874
            printf(", version: %u.%u.%u\n",
 
875
                PCILIB_VERSION_GET_MAJOR(version),
 
876
                PCILIB_VERSION_GET_MINOR(version),
 
877
                PCILIB_VERSION_GET_MICRO(version)
 
878
            );
 
879
        } else {
 
880
            printf(" (embedded)\n");
 
881
        }
 
882
    }
 
883
 
 
884
    if (model_info->dma) {
 
885
        pcilib_version_t version = model_info->dma->api->version;
 
886
        printf("DMA Engine: %s, version: %u.%u.%u\n", model_info->dma->name,
 
887
            PCILIB_VERSION_GET_MAJOR(version),
 
888
            PCILIB_VERSION_GET_MINOR(version),
 
889
            PCILIB_VERSION_GET_MICRO(version)
 
890
        );
 
891
    }
 
892
}
 
893
 
843
894
void Info(pcilib_t *handle, const pcilib_model_description_t *model_info, const char *target) {
844
895
    int i, j;
845
896
    DIR *dir;
850
901
    const pcilib_board_info_t *board_info = pcilib_get_board_info(handle);
851
902
    const pcilib_pcie_link_info_t *link_info = pcilib_get_pcie_link_info(handle);
852
903
 
 
904
    int have_state;
 
905
    pcilib_device_state_t state;
 
906
 
853
907
    path = getenv("PCILIB_PLUGIN_DIR");
854
908
    if (!path) path = PCILIB_PLUGIN_DIR;
855
909
 
 
910
    have_state = !pcilib_get_device_state(handle, &state);
 
911
 
856
912
    if (board_info)
857
913
        printf("Vendor: %x, Device: %x, Bus: %x, Slot: %x, Function: %x, Model: %s\n", board_info->vendor_id, board_info->device_id, board_info->bus, board_info->slot, board_info->func, handle->model);
858
914
 
859
915
    if (link_info) {
860
 
        printf(" PCIe x%u (gen%u), DMA Payload: %u (of %u)\n", link_info->link_width, link_info->link_speed, 1<<link_info->payload, 1<<link_info->max_payload);
 
916
        printf(" PCIe x%u (gen%u), DMA Payload: %u (of %u)", link_info->link_width, link_info->link_speed, 1<<link_info->payload, 1<<link_info->max_payload);
 
917
        if (have_state) {
 
918
            int bits = 0;
 
919
            unsigned long mask;
 
920
 
 
921
            for (mask = state.dma_mask; mask&1; mask>>=1) bits++;
 
922
 
 
923
            printf(", DMA Mask: ");
 
924
 
 
925
            if (mask) printf("0x%lx", state.dma_mask);
 
926
            else printf("%u bits", bits);
 
927
 
 
928
            printf(", IOMMU: %s", state.iommu?"on":"off");
 
929
        }
 
930
        printf("\n");
861
931
    }
862
932
 
863
933
    if (board_info)
3018
3088
    FILE *ofile = NULL;
3019
3089
    size_t iterations = BENCHMARK_ITERATIONS;
3020
3090
 
 
3091
    unsigned long dma_mask = 0;
 
3092
 
3021
3093
    pcilib_t *handle;
3022
3094
 
3023
3095
    int size_set = 0;
3032
3104
            case OPT_HELP:
3033
3105
                Usage(argc, argv, NULL);
3034
3106
            break;
 
3107
            case OPT_VERSION:
 
3108
                if (mode != MODE_INVALID) Usage(argc, argv, "Multiple operations are not supported");
 
3109
                mode = MODE_VERSION;
 
3110
            break;
3035
3111
            case OPT_INFO:
3036
3112
                if (mode != MODE_INVALID) Usage(argc, argv, "Multiple operations are not supported");
3037
3113
 
3207
3283
                    irq_source = itmp;
3208
3284
                }
3209
3285
            break;
 
3286
            case OPT_SET_DMASK:
 
3287
                if (mode != MODE_INVALID) Usage(argc, argv, "Multiple operations are not supported");
 
3288
                mode = MODE_SET_DMASK;
 
3289
 
 
3290
                if ((!isnumber(optarg))||(sscanf(optarg, "%lu", &dma_mask) != 1)||(dma_mask<24)||(dma_mask>64))
 
3291
                        Usage(argc, argv, "Invalid DMA mask is specified (%s)", optarg);
 
3292
            break;
3210
3293
            case OPT_LIST_KMEM:
3211
3294
                if (mode != MODE_INVALID) Usage(argc, argv, "Multiple operations are not supported");
3212
3295
                mode = MODE_LIST_KMEM;
3729
3812
    }
3730
3813
 
3731
3814
    switch (mode) {
 
3815
     case MODE_VERSION:
 
3816
        Version(handle, model_info);
 
3817
    break;
3732
3818
     case MODE_INFO:
3733
3819
        Info(handle, model_info, info_target);
3734
3820
     break;
3799
3885
     case MODE_WAIT_IRQ:
3800
3886
        WaitIRQ(handle, model_info, irq_source, timeout);
3801
3887
     break;
 
3888
     case MODE_SET_DMASK:
 
3889
        pcilib_set_dma_mask(handle, dma_mask);
 
3890
     break;
3802
3891
     case MODE_LIST_KMEM:
3803
3892
        if (use) DetailKMEM(handle, fpga_device, use, block);
3804
3893
        else ListKMEM(handle, fpga_device);