/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-10-19 04:59:53 UTC
  • Revision ID: csa@suren.me-20151019045953-h4ur2flqzf3ky412
Provide register listings in public API

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "pcitool/sysinfo.h"
33
33
#include "pcitool/formaters.h"
34
34
 
 
35
#include "views/transform.h"
 
36
#include "views/enum.h"
35
37
#include "pci.h"
36
38
#include "plugin.h"
37
39
#include "config.h"
659
661
    }
660
662
}
661
663
 
 
664
void ViewInfo(pcilib_t *handle, pcilib_register_t reg, size_t id) {
 
665
    int err;
 
666
 
 
667
    int i;
 
668
    pcilib_value_t val = {0};
 
669
    pcilib_register_value_name_t *vnames;
 
670
 
 
671
    pcilib_view_t view;
 
672
    const pcilib_model_description_t *model_info = pcilib_get_model_description(handle);
 
673
    const pcilib_register_description_t *r;
 
674
    const pcilib_view_description_t *v;
 
675
 
 
676
    if (reg == PCILIB_REGISTER_INVALID) {
 
677
        r = NULL;
 
678
        view = id;
 
679
    } else {
 
680
        r = &model_info->registers[reg];
 
681
        view = pcilib_find_view_by_name(handle, r->views[id].view);
 
682
    }
 
683
 
 
684
    if (view == PCILIB_VIEW_INVALID) return;
 
685
    v = model_info->views[view];
 
686
 
 
687
    if (r) {
 
688
        printf("  View %s (", r->views[id].name);
 
689
    } else {
 
690
        printf("%s\n", v->name);
 
691
        printf("    Data type      : ");
 
692
    }
 
693
    switch (v->type) {
 
694
        case PCILIB_TYPE_STRING:
 
695
            printf("char*");
 
696
            break;
 
697
        case PCILIB_TYPE_DOUBLE:
 
698
            printf("double");
 
699
            break;
 
700
        case PCILIB_TYPE_LONG:
 
701
            printf("long");
 
702
            break;
 
703
        default:
 
704
            printf("unknown");
 
705
    }
 
706
    if (r) printf(")");
 
707
    printf("\n");
 
708
 
 
709
    if (r) {
 
710
        err = pcilib_read_register_view_by_id(handle, reg, r->views[id].name, &val);
 
711
    } else {
 
712
        err = pcilib_get_property(handle, v->name, &val);
 
713
    }
 
714
    if (!err) err = pcilib_convert_value_type(handle, &val, PCILIB_TYPE_STRING);
 
715
 
 
716
    if (err)
 
717
        printf("    Current value  : error %i\n", err);
 
718
    else {
 
719
        printf("    Current value  : %s", val.sval);
 
720
        if (v->unit) printf(" (units: %s)", v->unit);
 
721
        printf("\n");
 
722
    }
 
723
 
 
724
    if (v->unit) {
 
725
        pcilib_unit_t unit = pcilib_find_unit_by_name(handle, v->unit);
 
726
 
 
727
        printf("    Supported units: %s", v->unit);
 
728
 
 
729
        if (unit != PCILIB_UNIT_INVALID) {
 
730
            const pcilib_unit_description_t *u = &model_info->units[unit];
 
731
 
 
732
            for (i = 0; u->transforms[i].unit; i++)
 
733
                printf(", %s", u->transforms[i].unit);
 
734
        }
 
735
        printf("\n");
 
736
    }
 
737
 
 
738
    printf("    Access         : ");
 
739
    if ((v->mode&PCILIB_REGISTER_RW) == 0) printf("-");
 
740
    if (v->mode&PCILIB_REGISTER_R) printf("R");
 
741
    if (v->mode&PCILIB_REGISTER_W) printf("W");
 
742
    printf("\n");
 
743
 
 
744
    if ((v->api == &pcilib_enum_view_static_api)||(v->api == &pcilib_enum_view_xml_api)) {
 
745
        vnames = ((pcilib_enum_view_description_t*)v)->names;
 
746
        printf("    Value aliases  :");
 
747
        for (i = 0; vnames[i].name; i++) {
 
748
            if (i) printf(",");
 
749
            printf(" %s = %u", vnames[i].name, vnames[i].value);
 
750
            if (vnames[i].min != vnames[i].max) 
 
751
                printf(" (%u - %u)", vnames[i].min, vnames[i].max);
 
752
        }
 
753
        printf("\n");
 
754
    } else if (v->api == &pcilib_transform_view_api) {
 
755
        const pcilib_transform_view_description_t *tv = (const pcilib_transform_view_description_t*)v;
 
756
        if (tv->read_from_reg)
 
757
            printf("    Read function  : %s\n", tv->read_from_reg);
 
758
        if (tv->write_to_reg)
 
759
            printf("    Write function : %s\n", tv->write_to_reg);
 
760
    }
 
761
 
 
762
    if (v->description)
 
763
        printf("    Description    : %s\n", v->description);
 
764
}
 
765
 
662
766
void RegisterInfo(pcilib_t *handle, pcilib_register_t reg) {
663
767
    int err;
664
 
    pcilib_value_t val = {0};
 
768
 
 
769
    int i;
665
770
    pcilib_register_value_t regval;
 
771
    pcilib_register_info_t *info;
666
772
 
667
773
    const pcilib_model_description_t *model_info = pcilib_get_model_description(handle);
668
774
    const pcilib_register_description_t *r = &model_info->registers[reg];
670
776
    const pcilib_register_bank_description_t *b = &model_info->banks[bank];
671
777
 
672
778
    err = pcilib_read_register_by_id(handle, reg, &regval);
673
 
    
 
779
 
 
780
    info = pcilib_get_register_info(handle, b->name, r->name, 0);
 
781
    if (!info) Error("Can't obtain register info for %s", r->name);
674
782
 
675
783
    printf("%s/%s\n", b->name, r->name);
676
784
    printf("  Current value: ");
680
788
    if (r->mode&PCILIB_REGISTER_W) {
681
789
        printf(" (default: ");
682
790
        printf(b->format, r->defvalue);
 
791
        if (info->range) {
 
792
            printf(", range: ");
 
793
            printf(b->format, info->range->min);
 
794
            printf (" - ");
 
795
            printf(b->format, info->range->max);
 
796
        }
683
797
        printf(")");
684
798
    }
685
799
    printf("\n");
686
800
 
687
801
    printf("  Address      : 0x%x [%u:%u]\n", r->addr, r->offset, r->offset + r->bits);
 
802
    if ((info->values)&&(info->values[0].name)) {
 
803
        printf("  Value aliases:");
 
804
        for (i = 0; info->values[i].name; i++)
 
805
            printf(" %s", info->values[i].name);
 
806
        printf("\n");
 
807
    }
688
808
    printf("  Access       : ");
689
809
    if ((r->mode&PCILIB_REGISTER_RW) == 0) printf("-");
690
810
    if (r->mode&PCILIB_REGISTER_R) printf("R");
698
818
        printf("  Description  : %s\n", r->description);
699
819
 
700
820
    if (r->views) {
701
 
        int i;
702
821
        printf("\nSupported Views:\n");
703
822
        for (i = 0; r->views[i].name; i++) {
704
 
            pcilib_view_t view = pcilib_find_view_by_name(handle, r->views[i].view);
705
 
            if (view == PCILIB_VIEW_INVALID) continue;
706
 
 
707
 
            const pcilib_view_description_t *v = model_info->views[view];
708
 
 
709
 
            printf("  View %s (", r->views[i].name);
710
 
            switch (v->type) {
711
 
                case PCILIB_TYPE_STRING:
712
 
                    printf("char*");
713
 
                    break;
714
 
                case PCILIB_TYPE_DOUBLE:
715
 
                    printf("double");
716
 
                    break;
717
 
                default:
718
 
                    printf("unknown");
719
 
            }
720
 
            printf(")\n");
721
 
 
722
 
            err = pcilib_read_register_view(handle, b->name, r->name, r->views[i].name, &val);
723
 
            if (!err) err = pcilib_convert_value_type(handle, &val, PCILIB_TYPE_STRING);
724
 
 
725
 
            if (err)
726
 
                printf("    Current value  : error %i\n", err);
727
 
            else {
728
 
                printf("    Current value  : %s", val.sval);
729
 
                if (v->unit) printf(" (units: %s)", v->unit);
730
 
                printf("\n");
731
 
            }
732
 
 
733
 
            if (v->unit) {
734
 
                pcilib_unit_t unit = pcilib_find_unit_by_name(handle, v->unit);
735
 
 
736
 
                printf("    Supported units: %s", v->unit);
737
 
 
738
 
                if (unit != PCILIB_UNIT_INVALID) {
739
 
                    int j;
740
 
                    const pcilib_unit_description_t *u = &model_info->units[unit];
741
 
 
742
 
                    for (j = 0; u->transforms[j].unit; j++)
743
 
                        printf(", %s", u->transforms[j].unit);
744
 
                }
745
 
                printf("\n");
746
 
            }
747
 
 
748
 
            if (v->description)
749
 
                printf("    Description    : %s\n", v->description);
 
823
            ViewInfo(handle, reg, i);
750
824
        }
751
825
    }
752
826
 
753
 
 
754
 
//    printf("Type: %s". r->rw
 
827
    pcilib_free_register_info(handle, info);
755
828
}
756
829
 
757
830
void Info(pcilib_t *handle, const pcilib_model_description_t *model_info, const char *target) {
780
853
    printf("\n");
781
854
 
782
855
    if (target) {
783
 
        pcilib_register_t reg;
784
 
        
785
 
        reg = pcilib_find_register(handle, NULL, target);
786
 
        if (reg != PCILIB_REGISTER_INVALID) 
787
 
            return RegisterInfo(handle, reg);
788
 
        
789
 
        Error(" No register %s is found", target);
 
856
        if (*target == '/') {
 
857
            pcilib_view_t view;
 
858
            view = pcilib_find_view_by_name(handle, target);
 
859
            if (view != PCILIB_VIEW_INVALID)
 
860
                return ViewInfo(handle, PCILIB_REGISTER_INVALID, view);
 
861
 
 
862
            Error(" No property %s is found", target);
 
863
        } else {
 
864
            pcilib_register_t reg;
 
865
        
 
866
            reg = pcilib_find_register(handle, NULL, target);
 
867
            if (reg != PCILIB_REGISTER_INVALID) 
 
868
                return RegisterInfo(handle, reg);
 
869
 
 
870
            Error(" No register %s is found", target);
 
871
        }
 
872
        
790
873
    }
791
874
 
792
875
    List(handle, model_info, (char*)-1, 0);