linux/samples/xilinx_apm/xaxipmon.c
<<
>>
Prefs
   1#include "xaxipmon.h"
   2/*****************************************************************************/
   3/**
   4*
   5* This function resets all Metric Counters and Sampled Metric Counters of
   6* AXI Performance Monitor.
   7*
   8* @return       XST_SUCCESS
   9*
  10*
  11* @note         None.
  12*
  13******************************************************************************/
  14int resetmetriccounter(void)
  15{
  16        u32 regval;
  17
  18        /*
  19         * Write the reset value to the Control register to reset
  20         * Metric counters
  21         */
  22        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
  23        writereg(baseaddr, XAPM_CTL_OFFSET,
  24                                        (regval | XAPM_CR_MCNTR_RESET_MASK));
  25        /*
  26         * Release from Reset
  27         */
  28        writereg(baseaddr, XAPM_CTL_OFFSET,
  29                                (regval & ~(XAPM_CR_MCNTR_RESET_MASK)));
  30        return XST_SUCCESS;
  31
  32}
  33
  34/*****************************************************************************/
  35/**
  36*
  37* This function resets Global Clock Counter of AXI Performance Monitor
  38*
  39* @return       None.
  40*
  41* @note         None.
  42*
  43******************************************************************************/
  44void resetglobalclkcounter(void)
  45{
  46
  47        u32 regval;
  48
  49        /*
  50         * Write the reset value to the Control register to reset
  51         * Global Clock Counter
  52         */
  53        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
  54        writereg(baseaddr, XAPM_CTL_OFFSET,
  55                                        (regval | XAPM_CR_GCC_RESET_MASK));
  56
  57        /*
  58         * Release from Reset
  59         */
  60        writereg(baseaddr, XAPM_CTL_OFFSET,
  61                                (regval & ~(XAPM_CR_GCC_RESET_MASK)));
  62
  63}
  64
  65/*****************************************************************************/
  66/**
  67*
  68* This function resets Streaming FIFO of AXI Performance Monitor
  69*
  70* @return       XST_SUCCESS
  71*
  72* @note         None.
  73*
  74******************************************************************************/
  75int resetfifo(void)
  76{
  77        u32 regval;
  78
  79        /* Check Event Logging is enabled in Hardware */
  80        if (params->eventlog == 0)
  81                /*Event Logging not enabled in Hardware*/
  82                return XST_SUCCESS;
  83
  84        /*
  85         * Write the reset value to the Control register to reset
  86         * FIFO
  87         */
  88        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
  89        writereg(baseaddr, XAPM_CTL_OFFSET,
  90                                        (regval | XAPM_CR_FIFO_RESET_MASK));
  91        /*
  92         * Release from Reset
  93         */
  94        writereg(baseaddr, XAPM_CTL_OFFSET,
  95                                (regval & ~(XAPM_CR_FIFO_RESET_MASK)));
  96
  97        return XST_SUCCESS;
  98}
  99
 100/****************************************************************************/
 101/**
 102*
 103* This function sets Ranges for Incrementers depending on parameters passed.
 104*
 105* @param        incrementer specifies the Incrementer for which Ranges
 106*               need to be set
 107* @param        rangehigh specifies the Upper limit in 32 bit Register
 108* @param        rangelow specifies the Lower limit in 32 bit Register
 109*
 110* @return       None.
 111*
 112* @note         None
 113*
 114*****************************************************************************/
 115void setincrementerrange(u8 incrementer, u16 rangehigh, u16 rangelow)
 116{
 117        u32 regval;
 118
 119        /*
 120         * Write to the specified Range register
 121         */
 122        regval = rangehigh << 16;
 123        regval |= rangelow;
 124        writereg(baseaddr,
 125                (XAPM_RANGE0_OFFSET + (incrementer * 16)), regval);
 126}
 127
 128/****************************************************************************/
 129/**
 130*
 131* This function returns the Ranges of Incrementers Registers.
 132*
 133* @param        incrementer specifies the Incrementer for which Ranges
 134*               need to be returned.
 135* @param        rangehigh specifies the user reference variable which returns
 136*               the Upper Range Value of the specified Incrementer.
 137* @param        rangelow specifies the user reference variable which returns
 138*               the Lower Range Value of the specified Incrementer.
 139*
 140* @return       None.
 141*
 142* @note         None
 143*
 144*****************************************************************************/
 145void getincrementerrange(u8 incrementer, u16 *rangehigh, u16 *rangelow)
 146{
 147        u32 regval;
 148
 149        regval = readreg(baseaddr, (XAPM_RANGE0_OFFSET +
 150                                        (incrementer * 16)));
 151
 152        *rangelow = regval & 0xFFFF;
 153        *rangehigh = (regval >> 16) & 0xFFFF;
 154}
 155
 156/****************************************************************************/
 157/**
 158*
 159* This function sets the Sample Interval Register
 160*
 161* @param        sampleinterval is the Sample Interval
 162*
 163* @return       None
 164*
 165* @note         None.
 166*
 167*****************************************************************************/
 168void setsampleinterval(u32 sampleinterval)
 169{
 170        /*
 171         * Set Sample Interval
 172         */
 173        writereg(baseaddr, XAPM_SI_LOW_OFFSET, sampleinterval);
 174
 175}
 176
 177/****************************************************************************/
 178/**
 179*
 180* This function returns the contents of Sample Interval Register
 181*
 182* @param        sampleinterval is a pointer where Sample Interval register
 183*               contents are returned.
 184* @return       None.
 185*
 186* @note         None.
 187*
 188******************************************************************************/
 189void getsampleinterval(u32 *sampleinterval)
 190{
 191        /*
 192         * Set Sample Interval Lower
 193         */
 194        *sampleinterval = readreg(baseaddr, XAPM_SI_LOW_OFFSET);
 195
 196}
 197
 198/****************************************************************************/
 199/**
 200*
 201* This function sets metrics for specified Counter in the corresponding
 202* Metric Selector Register.
 203*
 204* @param        slot is the slot ID for which specified counter has to
 205*               be connected.
 206* @param        metrics is one of the Metric Sets. User has to use
 207*               XAPM_METRIC_SET_* macros in xaxipmon.h for this parameter
 208* @param        counter is the Counter Number.
 209*               The valid values are 0 to 9.
 210*
 211* @return       XST_SUCCESS if Success
 212*               XST_FAILURE if Failure
 213*
 214* @note         None.
 215*
 216*****************************************************************************/
 217int setmetrics(u8 slot, u8 metrics, u8 counter)
 218{
 219        u32 regval;
 220        u32 mask;
 221
 222        /* Find mask value to force zero in counternum byte range */
 223        if (counter == 0 || counter == 4 || counter == 8)
 224                mask = 0xFFFFFF00;
 225        else if (counter == 1 || counter == 5 || counter == 9)
 226                mask = 0xFFFF00FF;
 227        else if (counter == 2 || counter == 6)
 228                mask = 0xFF00FFFF;
 229        else
 230                mask = 0x00FFFFFF;
 231
 232        if (counter <= 3) {
 233                regval = readreg(baseaddr, XAPM_MSR0_OFFSET);
 234                regval = regval & mask;
 235                regval = regval | (metrics << (counter * 8));
 236                regval = regval | (slot << (counter * 8 + 5));
 237                writereg(baseaddr, XAPM_MSR0_OFFSET, regval);
 238        } else if ((counter >= 4) && (counter <= 7)) {
 239                counter = counter - 4;
 240                regval = readreg(baseaddr, XAPM_MSR1_OFFSET);
 241                regval = regval & mask;
 242                regval = regval | (metrics << (counter * 8));
 243                regval = regval | (slot << (counter * 8 + 5));
 244                writereg(baseaddr, XAPM_MSR1_OFFSET, regval);
 245        } else {
 246                counter = counter - 8;
 247                regval = readreg(baseaddr, XAPM_MSR2_OFFSET);
 248
 249                regval = regval & mask;
 250                regval = regval | (metrics << (counter * 8));
 251                regval = regval | (slot << (counter * 8 + 5));
 252                writereg(baseaddr, XAPM_MSR2_OFFSET, regval);
 253        }
 254        return XST_SUCCESS;
 255}
 256
 257/*****************************************************************************/
 258/**
 259*
 260* This function returns metrics in the specified Counter from the corresponding
 261* Metric Selector Register.
 262*
 263* @param        counter is the Counter Number.
 264*               The valid values are 0 to 9.
 265* @param        metrics is a reference parameter from application where metrics
 266*               of specified counter is filled.
 267* @praram       slot is a reference parameter in which slot Id of
 268*               specified counter is filled
 269* @return       XST_SUCCESS if Success
 270*               XST_FAILURE if Failure
 271*
 272* @note         None.
 273*
 274*****************************************************************************/
 275int getmetrics(u8 counter, u8 *metrics, u8 *slot)
 276{
 277        u32 regval;
 278
 279        if (counter <= 3) {
 280                regval = readreg(baseaddr, XAPM_MSR0_OFFSET);
 281                *metrics = (regval >> (counter * 8)) & 0x1F;
 282                *slot   = (regval >> (counter * 8 + 5)) & 0x7;
 283        } else if ((counter >= 4) && (counter <= 7)) {
 284                counter = counter - 4;
 285                regval = readreg(baseaddr, XAPM_MSR1_OFFSET);
 286                *metrics = (regval >> (counter * 8)) & 0x1F;
 287                *slot   = (regval >> (counter * 8 + 5)) & 0x7;
 288        } else {
 289                counter = counter - 8;
 290                regval = readreg(baseaddr, XAPM_MSR2_OFFSET);
 291                *metrics = (regval >> (counter * 8)) & 0x1F;
 292                *slot   = (regval >> (counter * 8 + 5)) & 0x7;
 293        }
 294        return XST_SUCCESS;
 295}
 296
 297/****************************************************************************/
 298/**
 299*
 300* This function returns the contents of the Global Clock Counter Register.
 301*
 302* @param        cnthigh is the user space pointer with which upper 32 bits
 303*               of Global Clock Counter has to be filled
 304* @param        cntlow is the user space pointer with which lower 32 bits
 305*               of Global Clock Counter has to be filled
 306*
 307* @return       None.
 308*
 309* @note         None.
 310*
 311*****************************************************************************/
 312void getglobalclkcounter(u32 *cnthigh, u32 *cntlow)
 313{
 314        *cnthigh = 0x0;
 315        *cntlow  = 0x0;
 316
 317        /*
 318         * If Counter width is 64 bit then Counter Value has to be
 319         * filled at CntHighValue address also.
 320         */
 321        if (params->globalcntwidth == 64) {
 322                /* Bits[63:32] exists at XAPM_GCC_HIGH_OFFSET */
 323                *cnthigh = readreg(baseaddr, XAPM_GCC_HIGH_OFFSET);
 324        }
 325        /* Bits[31:0] exists at XAPM_GCC_LOW_OFFSET */
 326        *cntlow = readreg(baseaddr, XAPM_GCC_LOW_OFFSET);
 327}
 328
 329/****************************************************************************/
 330/**
 331*
 332* This function returns the contents of the Metric Counter Register.
 333*
 334* @param        counter is the number of the Metric Counter to be read.
 335*               Use the XAPM_METRIC_COUNTER* defines for the counter number in
 336*               xaxipmon.h. The valid values are 0 (XAPM_METRIC_COUNTER_0) to
 337*               9 (XAPM_METRIC_COUNTER_9).
 338* @return       regval is the content of specified Metric Counter.
 339*
 340* @note         None.
 341*
 342*****************************************************************************/
 343u32 getmetriccounter(u32 counter)
 344{
 345        u32 regval;
 346
 347        regval = readreg(baseaddr,
 348                                (XAPM_MC0_OFFSET + (counter * 16)));
 349        return regval;
 350}
 351
 352/****************************************************************************/
 353/**
 354*
 355* This function returns the contents of the Sampled Metric Counter Register.
 356*
 357* @param        counter is the number of the Sampled Metric Counter to read.
 358*               Use the XAPM_METRIC_COUNTER* defines for the counter number in
 359*               xaxipmon.h. The valid values are 0 (XAPM_METRIC_COUNTER_0) to
 360*               9 (XAPM_METRIC_COUNTER_9).
 361*
 362* @return       regval is the content of specified Sampled Metric Counter.
 363*
 364* @note         None.
 365*
 366*****************************************************************************/
 367u32 getsampledmetriccounter(u32 counter)
 368{
 369        u32 regval;
 370
 371        regval = readreg(baseaddr, (XAPM_SMC0_OFFSET +
 372                                                (counter * 16)));
 373        return regval;
 374}
 375
 376/****************************************************************************/
 377/**
 378*
 379* This function returns the contents of the Incrementer Register.
 380*
 381* @param        incrementer is the number of the Incrementer register to
 382*               read.Use the XAPM_INCREMENTER_* defines for the Incrementer
 383*               number.The valid values are 0 (XAPM_INCREMENTER_0) to
 384*               9 (XAPM_INCREMENTER_9).
 385* @param        incrementer is the number of the specified Incrementer
 386*               register
 387* @return       regval is content of specified Metric Incrementer register.
 388*
 389* @note         None.
 390*
 391*****************************************************************************/
 392u32 getincrementer(u32 incrementer)
 393{
 394        u32 regval;
 395
 396        regval = readreg(baseaddr, (XAPM_INC0_OFFSET +
 397                                                (incrementer * 16)));
 398        return regval;
 399}
 400
 401/****************************************************************************/
 402/**
 403*
 404* This function returns the contents of the Sampled Incrementer Register.
 405*
 406* @param        incrementer is the number of the Sampled Incrementer
 407*               register to read.Use the XAPM_INCREMENTER_* defines for the
 408*               Incrementer number.The valid values are 0 (XAPM_INCREMENTER_0)
 409*               to 9 (XAPM_INCREMENTER_9).
 410* @param        incrementer is the number of the specified Sampled
 411*               Incrementer register
 412* @return       regval is content of specified Sampled Incrementer register.
 413*
 414* @note         None.
 415*
 416*****************************************************************************/
 417u32 getsampledincrementer(u32 incrementer)
 418{
 419        u32 regval;
 420
 421        regval = readreg(baseaddr, (XAPM_SINC0_OFFSET +
 422                                        (incrementer * 16)));
 423        return regval;
 424}
 425
 426/****************************************************************************/
 427/**
 428*
 429* This function sets Software-written Data Register.
 430*
 431* @param        swdata is the Software written Data.
 432*
 433* @return       None.
 434*
 435* @note         None.
 436*
 437*****************************************************************************/
 438void setswdatareg(u32 swdata)
 439{
 440        /*
 441         * Set Software-written Data Register
 442         */
 443        writereg(baseaddr, XAPM_SWD_OFFSET, swdata);
 444}
 445
 446/****************************************************************************/
 447/**
 448*
 449* This function returns contents of Software-written Data Register.
 450*
 451* @return       swdata.
 452*
 453* @note         None.
 454*
 455*****************************************************************************/
 456u32 getswdatareg(void)
 457{
 458        u32 swdata;
 459
 460        /*
 461         * Set Metric Selector Register
 462         */
 463        swdata = (u32)readreg(baseaddr, XAPM_SWD_OFFSET);
 464        return swdata;
 465}
 466
 467/*****************************************************************************/
 468/**
 469*
 470* This function enables the following in the AXI Performance Monitor:
 471*   - Event logging
 472*
 473* @param        flagenables is a value to write to the flag enables
 474*               register defined by XAPM_FEC_OFFSET. It is recommended
 475*               to use the XAPM_FEC_*_MASK mask bits to generate.
 476*               A value of 0x0 will disable all events to the event
 477*               log streaming FIFO.
 478*
 479* @return       XST_SUCCESS
 480*
 481* @note         None
 482*
 483******************************************************************************/
 484int starteventlog(u32 flagenables)
 485{
 486        u32 regval;
 487
 488        /* Read current register value */
 489        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
 490        /* Now write to flag enables register */
 491        writereg(baseaddr, XAPM_FEC_OFFSET, flagenables);
 492        /* Write the new value to the Control register to
 493         *      enable event logging */
 494        writereg(baseaddr, XAPM_CTL_OFFSET,
 495                        regval | XAPM_CR_EVENTLOG_ENABLE_MASK);
 496        return XST_SUCCESS;
 497}
 498
 499/*****************************************************************************/
 500/**
 501*
 502* This function disables the following in the AXI Performance Monitor:
 503*   - Event logging
 504*
 505* @return       XST_SUCCESS
 506*
 507* @note         None
 508*
 509******************************************************************************/
 510int stopeventlog(void)
 511{
 512        u32 regval;
 513
 514        /* Read current register value */
 515        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
 516
 517        /* Write the new value to the Control register to disable
 518         * event logging */
 519        writereg(baseaddr, XAPM_CTL_OFFSET,
 520                                regval & ~XAPM_CR_EVENTLOG_ENABLE_MASK);
 521
 522        return XST_SUCCESS;
 523}
 524
 525/*****************************************************************************/
 526/**
 527*
 528* This function enables the following in the AXI Performance Monitor:
 529*   - Global clock counter
 530*   - All metric counters
 531*   - All sampled metric counters
 532*
 533* @param    sampleinterval is the sample interval
 534* @return   XST_SUCCESS
 535*
 536* @note     None
 537******************************************************************************/
 538int startcounters(u32 sampleinterval)
 539{
 540        u32 regval;
 541
 542        /* Read current register value */
 543        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
 544
 545        /* Global Clock Counter is present in Advanced Mode only */
 546        if (params->mode == 1)
 547                regval = regval | XAPM_CR_GCC_ENABLE_MASK;
 548        /*
 549         * Write the new value to the Control register to enable
 550         * global clock counter and metric counters
 551         */
 552        writereg(baseaddr, XAPM_CTL_OFFSET, regval | XAPM_CR_MCNTR_ENABLE_MASK);
 553
 554        /* Set, enable, and load sampled counters */
 555        setsampleinterval(sampleinterval);
 556        loadsic();
 557        enablesic();
 558
 559        return XST_SUCCESS;
 560}
 561
 562/****************************************************************************/
 563/**
 564*
 565* This function disables the following in the AXI Performance Monitor:
 566*   - Global clock counter
 567*   - All metric counters
 568*
 569* @return       XST_SUCCESS
 570*
 571* @note         None
 572*
 573******************************************************************************/
 574int stopcounters(void)
 575{
 576        u32 regval;
 577
 578        /* Read current register value */
 579        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
 580
 581        /* Global Clock Counter is present in Advanced Mode only */
 582        if (params->mode == 1)
 583                regval = regval & ~XAPM_CR_GCC_ENABLE_MASK;
 584
 585        /*
 586         * Write the new value to the Control register to disable
 587         * global clock counter and metric counters
 588         */
 589        writereg(baseaddr, XAPM_CTL_OFFSET,
 590                        regval & ~XAPM_CR_MCNTR_ENABLE_MASK);
 591
 592        return XST_SUCCESS;
 593}
 594
 595/*****************************************************************************/
 596/**
 597*
 598* This function enables Metric Counters.
 599*
 600* @return       None
 601*
 602* @note         None
 603*
 604******************************************************************************/
 605void enablemetricscounter(void)
 606{
 607        u32 regval;
 608
 609        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
 610        writereg(baseaddr, XAPM_CTL_OFFSET,
 611                                        regval | XAPM_CR_MCNTR_ENABLE_MASK);
 612}
 613/****************************************************************************/
 614/**
 615*
 616* This function disables the Metric Counters.
 617*
 618* @return       None
 619*
 620* @note         None
 621*
 622*****************************************************************************/
 623void disablemetricscounter(void)
 624{
 625        u32 regval;
 626
 627        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
 628
 629        writereg(baseaddr, XAPM_CTL_OFFSET,
 630                                        regval & ~(XAPM_CR_MCNTR_ENABLE_MASK));
 631}
 632
 633/****************************************************************************/
 634/**
 635*
 636* This function sets the Upper and Lower Ranges for specified Metric Counter
 637* Log Enable Register.Event Logging starts when corresponding Metric Counter
 638* value falls in between these ranges
 639*
 640* @param        counter is the Metric Counter number for which
 641*               Ranges are to be assigned.Use the XAPM_METRIC_COUNTER*
 642*               defines for the counter number in xaxipmon.h.
 643*               The valid values are 0 (XAPM_METRIC_COUNTER_0) to
 644*               9 (XAPM_METRIC_COUNTER_9).
 645* @param        rangehigh specifies the Upper limit in 32 bit Register
 646* @param        rangelow specifies the Lower limit in 32 bit Register
 647* @return       None
 648*
 649* @note         None.
 650*
 651*****************************************************************************/
 652void setlogenableranges(u32 counter, u16 rangehigh, u16 rangelow)
 653{
 654        u32 regval;
 655
 656        /*
 657         * Write the specified Ranges to corresponding Metric Counter Log
 658         * Enable Register
 659         */
 660        regval = rangehigh << 16;
 661        regval |= rangelow;
 662        writereg(baseaddr, (XAPM_MC0LOGEN_OFFSET +
 663                                        (counter * 16)), regval);
 664}
 665
 666/****************************************************************************/
 667/**
 668*
 669* This function returns the Ranges of specified Metric Counter Log
 670* Enable Register.
 671*
 672* @param        counter is the Metric Counter number for which
 673*               Ranges are to be returned.Use the XAPM_METRIC_COUNTER*
 674*               defines for the counter number in xaxipmon.h.
 675*               The valid values are 0 (XAPM_METRIC_COUNTER_0) to
 676*               9 (XAPM_METRIC_COUNTER_9).
 677*
 678* @param        rangehigh specifies the user reference variable which returns
 679*               the Upper Range Value of the specified Metric Counter
 680*               Log Enable Register.
 681* @param        rangelow specifies the user reference variable which returns
 682*               the Lower Range Value of the specified Metric Counter
 683*               Log Enable Register.
 684*
 685* @note         None.
 686*
 687*****************************************************************************/
 688void getlogenableranges(u32 counter, u16 *rangehigh, u16 *rangelow)
 689{
 690        u32 regval;
 691
 692        regval = readreg(baseaddr,
 693                                (XAPM_MC0LOGEN_OFFSET + (counter * 16)));
 694
 695        *rangelow = regval & 0xFFFF;
 696        *rangehigh = (regval >> 16) & 0xFFFF;
 697}
 698
 699/*****************************************************************************/
 700/**
 701*
 702* This function enables Event Logging.
 703*
 704* @return       None
 705*
 706* @note         None
 707*
 708******************************************************************************/
 709void enableeventlog(void)
 710{
 711        u32 regval;
 712
 713        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
 714        writereg(baseaddr, XAPM_CTL_OFFSET,
 715                                regval | XAPM_CR_EVENTLOG_ENABLE_MASK);
 716}
 717
 718/*****************************************************************************/
 719/**
 720*
 721* This function enables External trigger pulse so that Metric Counters can be
 722* started on external trigger pulse for a slot.
 723*
 724*
 725* @return       None
 726*
 727* @note         None
 728*
 729******************************************************************************/
 730void enablemctrigger(void)
 731{
 732        u32 regval;
 733
 734        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
 735        writereg(baseaddr, XAPM_CTL_OFFSET,
 736                        regval | XAPM_CR_MCNTR_EXTTRIGGER_MASK);
 737}
 738
 739/****************************************************************************/
 740/**
 741*
 742* This function disables the External trigger pulse used to start Metric
 743* Counters on external trigger pulse for a slot.
 744*
 745* @return       None
 746*
 747* @note         None
 748*
 749*****************************************************************************/
 750void disablemctrigger(void)
 751{
 752        u32 regval;
 753
 754        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
 755
 756        writereg(baseaddr, XAPM_CTL_OFFSET,
 757                        regval & ~(XAPM_CR_MCNTR_EXTTRIGGER_MASK));
 758}
 759
 760/*****************************************************************************/
 761/**
 762*
 763* This function enables External trigger pulse for Event Log
 764* so that Event Logging can be started on external trigger pulse for a slot.
 765*
 766* @return       None
 767*
 768* @note         None
 769*
 770******************************************************************************/
 771void enableeventlogtrigger(void)
 772{
 773        u32 regval;
 774
 775        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
 776        writereg(baseaddr, XAPM_CTL_OFFSET,
 777                                regval | XAPM_CR_EVTLOG_EXTTRIGGER_MASK);
 778}
 779
 780/****************************************************************************/
 781/**
 782*
 783* This function disables the External trigger pulse used to start Event
 784* Log on external trigger pulse for a slot.
 785*
 786* @return       None
 787*
 788* @note         None
 789*
 790*****************************************************************************/
 791void disableeventlogtrigger(void)
 792{
 793        u32 regval;
 794
 795        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
 796
 797        writereg(baseaddr, XAPM_CTL_OFFSET,
 798                                regval & ~(XAPM_CR_EVTLOG_EXTTRIGGER_MASK));
 799}
 800
 801/****************************************************************************/
 802/**
 803*
 804* This function returns a name for a given Metric.
 805*
 806* @param        metrics is one of the Metric Sets. User has to use
 807*               XAPM_METRIC_SET_* macros in xaxipmon.h for this parameter
 808*
 809* @return       const char *
 810*
 811* @note         None
 812*
 813*****************************************************************************/
 814const char *getmetricname(u8 metrics)
 815{
 816        if (metrics == XAPM_METRIC_SET_0)
 817                return "Write Transaction Count";
 818        if (metrics == XAPM_METRIC_SET_1)
 819                return "Read Transaction Count";
 820        if (metrics == XAPM_METRIC_SET_2)
 821                return "Write Byte Count";
 822        if (metrics == XAPM_METRIC_SET_3)
 823                return "Read Byte Count";
 824        if (metrics == XAPM_METRIC_SET_4)
 825                return "Write Beat Count";
 826        if (metrics == XAPM_METRIC_SET_5)
 827                return "Total Read Latency";
 828        if (metrics == XAPM_METRIC_SET_6)
 829                return "Total Write Latency";
 830        if (metrics == XAPM_METRIC_SET_7)
 831                return "Slv_Wr_Idle_Cnt";
 832        if (metrics == XAPM_METRIC_SET_8)
 833                return "Mst_Rd_Idle_Cnt";
 834        if (metrics == XAPM_METRIC_SET_9)
 835                return "Num_BValids";
 836        if (metrics == XAPM_METRIC_SET_10)
 837                return "Num_WLasts";
 838        if (metrics == XAPM_METRIC_SET_11)
 839                return "Num_RLasts";
 840        if (metrics == XAPM_METRIC_SET_12)
 841                return "Minimum Write Latency";
 842        if (metrics == XAPM_METRIC_SET_13)
 843                return "Maximum Write Latency";
 844        if (metrics == XAPM_METRIC_SET_14)
 845                return "Minimum Read Latency";
 846        if (metrics == XAPM_METRIC_SET_15)
 847                return "Maximum Read Latency";
 848        if (metrics == XAPM_METRIC_SET_16)
 849                return "Transfer Cycle Count";
 850        if (metrics == XAPM_METRIC_SET_17)
 851                return "Packet Count";
 852        if (metrics == XAPM_METRIC_SET_18)
 853                return "Data Byte Count";
 854        if (metrics == XAPM_METRIC_SET_19)
 855                return "Position Byte Count";
 856        if (metrics == XAPM_METRIC_SET_20)
 857                return "Null Byte Count";
 858        if (metrics == XAPM_METRIC_SET_21)
 859                return "Slv_Idle_Cnt";
 860        if (metrics == XAPM_METRIC_SET_22)
 861                return "Mst_Idle_Cnt";
 862        if (metrics == XAPM_METRIC_SET_30)
 863                return "External event count";
 864        return "Unsupported";
 865}
 866
 867/****************************************************************************/
 868/**
 869*
 870* This function sets Write ID in Latency ID register to capture Write
 871* Latency metrics.
 872*
 873* @param        writeid is the Write ID to be written in Latency ID register.
 874*
 875* @return       None.
 876*
 877* @note         None.
 878*
 879*****************************************************************************/
 880void setwriteid(u32 writeid)
 881{
 882        u32 regval;
 883
 884        if (params->is_32bit_filter == 0) {
 885                regval = readreg(baseaddr, XAPM_ID_OFFSET);
 886                regval = regval & ~(XAPM_ID_WID_MASK);
 887                regval = regval | writeid;
 888                writereg(baseaddr, XAPM_ID_OFFSET, regval);
 889        } else {
 890                writereg(baseaddr, XAPM_ID_OFFSET, writeid);
 891        }
 892}
 893
 894/****************************************************************************/
 895/**
 896*
 897* This function sets Read ID in Latency ID register to capture
 898* Read Latency metrics.
 899*
 900* @param        readid is the Read ID to be written in Latency ID register.
 901*
 902* @return       None.
 903*
 904* @note         None.
 905*
 906*****************************************************************************/
 907void setreadid(u32 readid)
 908{
 909        u32 regval;
 910
 911        if (params->is_32bit_filter == 0) {
 912                regval = readreg(baseaddr, XAPM_ID_OFFSET);
 913                regval = regval & ~(XAPM_ID_RID_MASK);
 914                regval = regval | (readid << 16);
 915                writereg(baseaddr, XAPM_ID_OFFSET, regval);
 916        } else {
 917                writereg(baseaddr, XAPM_RID_OFFSET, readid);
 918        }
 919}
 920
 921/****************************************************************************/
 922/**
 923*
 924* This function returns Write ID in Latency ID register.
 925*
 926* @return       writeid is the required Write ID in Latency ID register.
 927*
 928* @note         None.
 929*
 930*****************************************************************************/
 931u32 getwriteid(void)
 932{
 933
 934        u32 writeid;
 935        u32 regval;
 936
 937        if (params->is_32bit_filter == 0) {
 938                regval = readreg(baseaddr, XAPM_ID_OFFSET);
 939                writeid = regval & XAPM_ID_WID_MASK;
 940        } else {
 941                writeid = XAPM_IDMASK_OFFSET;
 942        }
 943
 944        return writeid;
 945}
 946
 947/****************************************************************************/
 948/**
 949*
 950* This function returns Read ID in Latency ID register.
 951*
 952* @return       readid is the required Read ID in Latency ID register.
 953*
 954* @note         None.
 955*
 956*****************************************************************************/
 957u32 getreadid(void)
 958{
 959
 960        u32 readid;
 961        u32 regval;
 962
 963        if (params->is_32bit_filter == 0) {
 964                regval = readreg(baseaddr, XAPM_ID_OFFSET);
 965                regval = regval & XAPM_ID_RID_MASK;
 966                readid = regval >> 16;
 967        } else {
 968                readid = XAPM_RID_OFFSET;
 969        }
 970
 971        return readid;
 972}
 973
 974/*****************************************************************************/
 975/**
 976*
 977* This function sets Latency Start point to calculate write latency.
 978*
 979* @param        Param can be 0 - XAPM_LATENCY_ADDR_ISSUE
 980*               or 1 - XAPM_LATENCY_ADDR_ACCEPT
 981* @return       None
 982*
 983* @note         None
 984*
 985******************************************************************************/
 986void setwrlatencystart(u8 param)
 987{
 988        u32 regval;
 989
 990        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
 991        if (param == XAPM_LATENCY_ADDR_ACCEPT)
 992                writereg(baseaddr, XAPM_CTL_OFFSET, regval |
 993                                XAPM_CR_WRLATENCY_START_MASK);
 994        else
 995                writereg(baseaddr, XAPM_CTL_OFFSET, readreg(baseaddr,
 996                        XAPM_CTL_OFFSET) & ~(XAPM_CR_WRLATENCY_START_MASK));
 997}
 998
 999/*****************************************************************************/
1000/**
1001*
1002* This function sets Latency End point to calculate write latency.
1003*
1004* @param        Param can be 0 - XAPM_LATENCY_LASTWR
1005*               or 1 - XAPM_LATENCY_FIRSTWR
1006* @return       None
1007*
1008* @note         None
1009*
1010******************************************************************************/
1011void setwrlatencyend(u8 param)
1012{
1013        u32 regval;
1014
1015        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
1016        if (param == XAPM_LATENCY_FIRSTWR)
1017                writereg(baseaddr, XAPM_CTL_OFFSET, regval |
1018                                        XAPM_CR_WRLATENCY_END_MASK);
1019        else
1020                writereg(baseaddr, XAPM_CTL_OFFSET, readreg(baseaddr,
1021                        XAPM_CTL_OFFSET) & ~(XAPM_CR_WRLATENCY_END_MASK));
1022}
1023
1024/*****************************************************************************/
1025/**
1026*
1027* This function sets Latency Start point to calculate read latency.
1028*
1029* @param        Param can be 0 - XAPM_LATENCY_ADDR_ISSUE
1030*               or 1 - XAPM_LATENCY_ADDR_ACCEPT
1031* @return       None
1032*
1033* @note         None
1034*
1035******************************************************************************/
1036void setrdlatencystart(u8 param)
1037{
1038        u32 regval;
1039
1040        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
1041        if (param == XAPM_LATENCY_ADDR_ACCEPT)
1042                writereg(baseaddr, XAPM_CTL_OFFSET, regval |
1043                                        XAPM_CR_RDLATENCY_START_MASK);
1044        else
1045                writereg(baseaddr, XAPM_CTL_OFFSET, readreg(baseaddr,
1046                        XAPM_CTL_OFFSET) & ~(XAPM_CR_RDLATENCY_START_MASK));
1047}
1048
1049/*****************************************************************************/
1050/**
1051*
1052* This function sets Latency End point to calculate read latency.
1053*
1054* @param        Param can be 0 - XAPM_LATENCY_LASTRD
1055*               or 1 - XAPM_LATENCY_FIRSTRD
1056* @return       None
1057*
1058* @note         None
1059*
1060******************************************************************************/
1061void setrdlatencyend(u8 param)
1062{
1063        u32 regval;
1064
1065        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
1066        if (param == XAPM_LATENCY_FIRSTRD)
1067                writereg(baseaddr, XAPM_CTL_OFFSET, regval |
1068                                XAPM_CR_RDLATENCY_END_MASK);
1069        else
1070                writereg(baseaddr, XAPM_CTL_OFFSET, readreg(baseaddr,
1071                        XAPM_CTL_OFFSET) & ~(XAPM_CR_RDLATENCY_END_MASK));
1072}
1073
1074/*****************************************************************************/
1075/**
1076*
1077* This function returns Write Latency Start point.
1078*
1079* @return       Returns 0 - XAPM_LATENCY_ADDR_ISSUE or
1080*                       1 - XAPM_LATENCY_ADDR_ACCEPT
1081*
1082* @note         None
1083*
1084******************************************************************************/
1085u8 getwrlatencystart(void)
1086{
1087        u8 regval;
1088
1089        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
1090        regval = regval & XAPM_CR_WRLATENCY_START_MASK;
1091        if (regval != XAPM_LATENCY_ADDR_ISSUE)
1092                return XAPM_LATENCY_ADDR_ACCEPT;
1093        else
1094                return XAPM_LATENCY_ADDR_ISSUE;
1095}
1096
1097/*****************************************************************************/
1098/**
1099*
1100* This function returns Write Latency End point.
1101*
1102* @return       Returns 0 - XAPM_LATENCY_LASTWR or
1103*                       1 - XAPM_LATENCY_FIRSTWR.
1104*
1105* @note         None
1106*
1107******************************************************************************/
1108u8 getwrlatencyend(void)
1109{
1110        u8 regval;
1111
1112        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
1113        regval = regval & XAPM_CR_WRLATENCY_END_MASK;
1114        if (regval != XAPM_LATENCY_LASTWR)
1115                return XAPM_LATENCY_FIRSTWR;
1116        else
1117                return XAPM_LATENCY_LASTWR;
1118}
1119
1120/*****************************************************************************/
1121/**
1122*
1123* This function returns read Latency Start point.
1124*
1125* @return       Returns 0 - XAPM_LATENCY_ADDR_ISSUE or
1126*                       1 - XAPM_LATENCY_ADDR_ACCEPT
1127*
1128* @note         None
1129*
1130******************************************************************************/
1131u8 getrdlatencystart(void)
1132{
1133        u8 regval;
1134
1135        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
1136        regval = regval & XAPM_CR_RDLATENCY_START_MASK;
1137
1138        if (regval != XAPM_LATENCY_ADDR_ISSUE)
1139                return  XAPM_LATENCY_ADDR_ACCEPT;
1140        else
1141                return XAPM_LATENCY_ADDR_ISSUE;
1142}
1143
1144/*****************************************************************************/
1145/**
1146*
1147* This function returns Read Latency End point.
1148*
1149* @return       Returns 0 - XAPM_LATENCY_LASTRD or
1150*                       1 - XAPM_LATENCY_FIRSTRD.
1151*
1152* @note         None
1153*
1154******************************************************************************/
1155u8 getrdlatencyend(void)
1156{
1157        u8 regval;
1158
1159        regval = readreg(baseaddr, XAPM_CTL_OFFSET);
1160        regval = regval & XAPM_CR_RDLATENCY_END_MASK;
1161        if (regval != XAPM_LATENCY_LASTRD)
1162                return XAPM_LATENCY_FIRSTRD;
1163        else
1164                return XAPM_LATENCY_LASTRD;
1165
1166}
1167
1168/****************************************************************************/
1169/**
1170*
1171* This function sets Write ID Mask in ID Mask register.
1172*
1173* @param        wrmask is the Write ID mask to be written in ID register.
1174*
1175* @return       None.
1176*
1177* @note         None.
1178*
1179*****************************************************************************/
1180void setwriteidmask(u32 wrmask)
1181{
1182        u32 regval;
1183
1184        if (params->is_32bit_filter == 0) {
1185                regval = readreg(baseaddr, XAPM_IDMASK_OFFSET);
1186                regval = regval & ~(XAPM_MASKID_WID_MASK);
1187                regval = regval | wrmask;
1188                writereg(baseaddr, XAPM_IDMASK_OFFSET, regval);
1189        } else {
1190                writereg(baseaddr, XAPM_IDMASK_OFFSET, wrmask);
1191        }
1192}
1193
1194/****************************************************************************/
1195/**
1196*
1197* This function sets Read ID Mask in ID Mask register.
1198*
1199* @param        rdmask is the Read ID mask to be written in ID Mask register.
1200*
1201* @return       None.
1202*
1203* @note         None.
1204*
1205*****************************************************************************/
1206void setreadidmask(u32 rdmask)
1207{
1208        u32 regval;
1209
1210        if (params->is_32bit_filter == 0) {
1211                regval = readreg(baseaddr, XAPM_IDMASK_OFFSET);
1212                regval = regval & ~(XAPM_MASKID_RID_MASK);
1213                regval = regval | (rdmask << 16);
1214                writereg(baseaddr, XAPM_IDMASK_OFFSET, regval);
1215        } else {
1216                writereg(baseaddr, XAPM_RIDMASK_OFFSET, rdmask);
1217        }
1218}
1219
1220/****************************************************************************/
1221/**
1222*
1223* This function returns Write ID Mask in ID Mask register.
1224*
1225* @return       wrmask is the required Write ID Mask in ID Mask register.
1226*
1227* @note         None.
1228*
1229*****************************************************************************/
1230u32 getwriteidmask(void)
1231{
1232
1233        u32 wrmask;
1234        u32 regval;
1235
1236        if (params->is_32bit_filter == 0) {
1237                regval = readreg(baseaddr, XAPM_IDMASK_OFFSET);
1238                wrmask = regval & XAPM_MASKID_WID_MASK;
1239        } else {
1240                wrmask = XAPM_IDMASK_OFFSET;
1241        }
1242        return wrmask;
1243}
1244
1245/****************************************************************************/
1246/**
1247*
1248* This function returns Read ID Mask in ID Mask register.
1249*
1250* @return       rdmask is the required Read ID Mask in ID Mask register.
1251*
1252* @note         None.
1253*
1254*****************************************************************************/
1255u32 getreadidmask(void)
1256{
1257
1258        u32 rdmask;
1259        u32 regval;
1260
1261        if (params->is_32bit_filter == 0) {
1262                regval = readreg(baseaddr, XAPM_IDMASK_OFFSET);
1263                regval = regval & XAPM_MASKID_RID_MASK;
1264                rdmask = regval >> 16;
1265        } else {
1266                rdmask = XAPM_RIDMASK_OFFSET;
1267        }
1268        return rdmask;
1269}
1270