]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/axipmon_v6_2/src/xaxipmon.c
Add in the CORTEX_A53_64-bit_UltraScale_MPSoC demo application (a demo has been inclu...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / axipmon_v6_2 / src / xaxipmon.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2012 - 2015 Xilinx, Inc.  All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /****************************************************************************/
33 /**
34 *
35 * @file xaxipmon.c
36 *
37 * This file contains the driver API functions that can be used to access
38 * the AXI Performance Monitor device.
39 *
40 * Refer to the xaxipmon.h header file for more information about this driver.
41 *
42 * @note         None.
43 *
44 * <pre>
45 *
46 * MODIFICATION HISTORY:
47 *
48 * Ver   Who    Date     Changes
49 * ----- -----  -------- -----------------------------------------------------
50 * 1.00a bss   02/27/12  First release
51 * 2.00a bss   06/23/12  Updated to support v2_00a version of IP.
52 * 3.00a bss   09/03/12  Deleted XAxiPmon_SetAgent, XAxiPmon_GetAgent APIs and
53 *                       modified XAxiPmon_SetMetrics, XAxiPmon_GetMetrics APIs
54 *                       to support v2_01a version of IP.
55 * 3.01a bss   10/25/12  Added XAxiPmon_StartCounters and XAxiPmon_StopCounters
56 *                       APIs (CR #683799).
57 *                       Added XAxiPmon_StartEventLog and XAxiPmon_StopEventLog
58 *                       APIs (CR #683801).
59 *                       Added XAxiPmon_GetMetricName API (CR #683803).
60 *                       Modified XAxiPmon_SetMetrics and XAxiPmon_GetMetrics
61 *                       (CR #683746)
62 *                       Added XAxiPmon_EnableEventLog,
63 *                       XAxiPmon_DisableMetricsCounter,
64 *                       XAxiPmon_EnableMetricsCounter APIs to replace macros.
65 *                       Added XAxiPmon_SetMetricCounterCutOff,
66 *                       XAxiPmon_GetMetricCounterCutOff,
67 *                       XAxiPmon_EnableExternalTrigger and
68 *                       XAxiPmon_DisableExternalTrigger APIs to support new
69 *                       version of IP.
70 * 4.00a bss   01/17/13  To support new version of IP:
71 *                       Added XAxiPmon_SetLogEnableRanges,
72 *                       XAxiPmon_GetLogEnableRanges,
73 *                       XAxiPmon_EnableMetricCounterTrigger,
74 *                       XAxiPmon_DisableMetricCounterTrigger,
75 *                       XAxiPmon_EnableEventLogTrigger,
76 *                       XAxiPmon_DisableEventLogTrigger,
77 *                       XAxiPmon_SetWriteLatencyId,
78 *                       XAxiPmon_SetReadLatencyId,
79 *                       XAxiPmon_GetWriteLatencyId,
80 *                       XAxiPmon_GetReadLatencyId APIs and removed
81 *                       XAxiPmon_SetMetricCounterCutOff,
82 *                       XAxiPmon_GetMetricCounterCutOff,
83 *                       XAxiPmon_EnableExternalTrigger and
84 *                       XAxiPmon_DisableExternalTrigger APIs
85 * 5.00a bss   08/26/13  To support new version of IP:
86 *                       Modified XAxiPmon_CfgInitialize to add Mode of APM and
87 *                       ScaleFactor parameter.
88 *                       Modified Assert functions depending on Mode.
89 *                       Modified XAxiPmon_GetMetricCounter and
90 *                       XAxiPmon_GetSampledMetricCounter to include
91 *                       new Counters.
92 *                       Modified XAxiPmon_SetSampleInterval and
93 *                       XAxiPmon_GetSampleInterval to remove higher 32 bit
94 *                       value of SampleInterval since Sample Interval Register
95 *                       is only 32 bit.
96 *                       Added XAxiPmon_SetWrLatencyStart,
97 *                       XAxiPmon_SetWrLatencyEnd, XAxiPmon_SetRdLatencyStart
98 *                       XAxiPmon_SetRdLatencyEnd, XAxiPmon_GetWrLatencyStart,
99 *                       XAxiPmon_GetWrLatencyEnd, XAxiPmon_GetRdLatencyStart,
100 *                       XAxiPmon_GetRdLatencyEnd, XAxiPmon_SetWriteIdMask,
101 *                       XAxiPmon_SetReadIdMask,
102 *                       XAxiPmon_GetWriteIdMask and
103 *                       XAxiPmon_GetReadIdMask APIs.
104 *                       Renamed:
105 *                       XAxiPmon_SetWriteLatencyId to XAxiPmon_SetWriteId
106 *                       XAxiPmon_SetReadLatencyId to XAxiPmon_SetReadId
107 *                       XAxiPmon_GetWriteLatencyId to XAxiPmon_GetWriteId
108 *                       XAxiPmon_SetReadLatencyId to XAxiPmon_GetReadId.
109 * 6.2   bss  04/21/14   Updated XAxiPmon_CfgInitialize to Reset counters
110 *                       and FIFOs based on Modes(CR#782671). And if both
111 *                       profile and trace modes are present set mode as
112 *                       Advanced.
113 * 6.2   bss  03/02/15   Updated XAxiPmon_SetWriteId, XAxiPmon_SetReadId,
114 *                                               XAxiPmon_GetWriteId, XAxiPmon_GetReadId
115 *                                               XAxiPmon_SetWriteIdMask, XAxiPmon_SetReadIdMask,
116 *                                               XAxiPmon_GetWriteIdMask, XAxiPmon_GetReadIdMask
117 *                                               functions to support Zynq MP APM.
118 * </pre>
119 *
120 *****************************************************************************/
121
122 /***************************** Include Files ********************************/
123
124 #include "xaxipmon.h"
125
126 /************************** Constant Definitions *****************************/
127
128 /**************************** Type Definitions *******************************/
129
130 /***************** Macros (Inline Functions) Definitions *********************/
131
132 /************************** Function Prototypes ******************************/
133
134 /************************** Variable Definitions *****************************/
135
136 /*****************************************************************************/
137 /**
138 *
139 * This function initializes a specific XAxiPmon device/instance. This function
140 * must be called prior to using the AXI Performance Monitor device.
141 *
142 * @param        InstancePtr is a pointer to the XAxiPmon instance.
143 * @param        ConfigPtr points to the XAxiPmon device configuration structure.
144 * @param        EffectiveAddr is the device base address in the virtual memory
145 *               address space. If the address translation is not used then the
146 *               physical address is passed.
147 *               Unexpected errors may occur if the address mapping is changed
148 *               after this function is invoked.
149 *
150 * @return
151 *               - XST_SUCCESS if successful.
152 *
153 * @note         The user needs to first call the XAxiPmon_LookupConfig() API
154 *               which returns the Configuration structure pointer which is
155 *               passed as a parameter to the XAxiPmon_CfgInitialize() API.
156 *
157 ******************************************************************************/
158 int XAxiPmon_CfgInitialize(XAxiPmon *InstancePtr, XAxiPmon_Config *ConfigPtr,
159                                                 u32 EffectiveAddr)
160 {
161         /*
162          * Assert the input arguments.
163          */
164         Xil_AssertNonvoid(InstancePtr != NULL);
165         Xil_AssertNonvoid(ConfigPtr != NULL);
166
167         /*
168          * Set the values read from the device config and the base address.
169          */
170         InstancePtr->Config.DeviceId = ConfigPtr->DeviceId;
171         InstancePtr->Config.BaseAddress = EffectiveAddr;
172         InstancePtr->Config.GlobalClkCounterWidth =
173                                 ConfigPtr->GlobalClkCounterWidth;
174         InstancePtr->Config.MetricSampleCounterWidth =
175                                 ConfigPtr->MetricSampleCounterWidth;
176         InstancePtr->Config.IsEventCount =
177                                 ConfigPtr->IsEventCount;
178         InstancePtr->Config.NumberofSlots =
179                                 ConfigPtr->NumberofSlots;
180         InstancePtr->Config.NumberofCounters =
181                                 ConfigPtr->NumberofCounters;
182         InstancePtr->Config.HaveSampledCounters =
183                                 ConfigPtr->HaveSampledCounters;
184         InstancePtr->Config.IsEventLog =
185                                 ConfigPtr->IsEventLog;
186         InstancePtr->Config.FifoDepth =
187                                 ConfigPtr->FifoDepth;
188         InstancePtr->Config.FifoWidth =
189                                 ConfigPtr->FifoWidth;
190         InstancePtr->Config.TidWidth =
191                                 ConfigPtr->TidWidth;
192         InstancePtr->Config.Is32BitFiltering = ConfigPtr->Is32BitFiltering;
193
194         InstancePtr->Config.ScaleFactor = ConfigPtr->ScaleFactor;
195
196         if ((ConfigPtr->ModeProfile == ConfigPtr->ModeTrace)
197                         || ConfigPtr->ModeAdvanced == 1)
198         {
199                 InstancePtr->Mode = XAPM_MODE_ADVANCED;
200         } else if (ConfigPtr->ModeTrace == 1) {
201                 InstancePtr->Mode = XAPM_MODE_TRACE;
202         } else {
203                 InstancePtr->Mode = XAPM_MODE_PROFILE;
204         }
205
206         /*
207          * Indicate the instance is now ready to use, initialized without error.
208          */
209         InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
210
211         /*
212          * Reset the Counters and FIFO based on Modes.
213          */
214
215         /* Advanced and Profile */
216         if(InstancePtr->Mode == XAPM_MODE_ADVANCED ||
217                         InstancePtr->Mode == XAPM_MODE_PROFILE)
218         {
219                 XAxiPmon_ResetMetricCounter(InstancePtr);
220         }
221         /* Advanced */
222         if(InstancePtr->Mode == XAPM_MODE_ADVANCED)
223         {
224                 XAxiPmon_ResetGlobalClkCounter(InstancePtr);
225         }
226         /* Advanced and Trace */
227         if(InstancePtr->Mode == XAPM_MODE_ADVANCED ||
228                         InstancePtr->Mode == XAPM_MODE_TRACE)
229         {
230                 XAxiPmon_ResetFifo(InstancePtr);
231         }
232         return XST_SUCCESS;
233 }
234
235 /*****************************************************************************/
236 /**
237 *
238 * This function resets all Metric Counters and Sampled Metric Counters of
239 * AXI Performance Monitor.
240 *
241 * @param        InstancePtr is a pointer to the XAxiPmon instance.
242 *
243 * @return       XST_SUCCESS
244 *
245 *
246 * @note         None.
247 *
248 ******************************************************************************/
249 int XAxiPmon_ResetMetricCounter(XAxiPmon *InstancePtr)
250 {
251
252         u32 RegValue;
253
254         /*
255          * Assert the arguments.
256          */
257         Xil_AssertNonvoid(InstancePtr != NULL);
258         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
259         Xil_AssertNonvoid(InstancePtr->Mode != XAPM_MODE_TRACE);
260
261         /*
262          * Write the reset value to the Control register to reset
263          * Metric counters
264          */
265         RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
266                                                          XAPM_CTL_OFFSET);
267         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
268                                         (RegValue | XAPM_CR_MCNTR_RESET_MASK));
269         /*
270          * Release from Reset
271          */
272         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
273                                 (RegValue & ~(XAPM_CR_MCNTR_RESET_MASK)));
274         return XST_SUCCESS;
275
276 }
277
278 /*****************************************************************************/
279 /**
280 *
281 * This function resets Global Clock Counter of AXI Performance Monitor
282 *
283 * @param        InstancePtr is a pointer to the XAxiPmon instance.
284 *
285 * @return       None.
286 *
287 * @note         None.
288 *
289 ******************************************************************************/
290 void XAxiPmon_ResetGlobalClkCounter(XAxiPmon *InstancePtr)
291 {
292
293         u32 RegValue;
294
295         /*
296          * Assert the arguments.
297          */
298         Xil_AssertVoid(InstancePtr != NULL);
299         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
300         Xil_AssertVoid(InstancePtr->Mode == XAPM_MODE_ADVANCED);
301
302         /*
303          * Write the reset value to the Control register to reset
304          * Global Clock Counter
305          */
306         RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
307                                                          XAPM_CTL_OFFSET);
308         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
309                                         (RegValue | XAPM_CR_GCC_RESET_MASK));
310
311         /*
312          * Release from Reset
313          */
314         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
315                                 (RegValue & ~(XAPM_CR_GCC_RESET_MASK)));
316
317 }
318
319 /*****************************************************************************/
320 /**
321 *
322 * This function resets Streaming FIFO of AXI Performance Monitor
323 *
324 * @param        InstancePtr is a pointer to the XAxiPmon instance.
325 *
326 * @return       XST_SUCCESS
327 *
328 * @note         None.
329 *
330 ******************************************************************************/
331 int XAxiPmon_ResetFifo(XAxiPmon *InstancePtr)
332 {
333
334         u32 RegValue;
335
336         /*
337          * Assert the arguments.
338          */
339         Xil_AssertNonvoid(InstancePtr != NULL);
340         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
341         Xil_AssertNonvoid(InstancePtr->Mode != XAPM_MODE_PROFILE);
342
343         /* Check Event Logging is enabled in Hardware */
344         if((InstancePtr->Config.IsEventLog == 0) &&
345                         (InstancePtr->Mode == XAPM_MODE_ADVANCED))
346         {
347                 /*Event logging not enabled in Hardware*/
348                 return XST_SUCCESS;
349         }
350         /*
351          * Write the reset value to the Control register to reset
352          * FIFO
353          */
354         RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
355                                                          XAPM_CTL_OFFSET);
356         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
357                                         (RegValue | XAPM_CR_FIFO_RESET_MASK));
358         /*
359          * Release from Reset
360          */
361         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
362                                 (RegValue & ~(XAPM_CR_FIFO_RESET_MASK)));
363
364         return XST_SUCCESS;
365
366 }
367
368 /****************************************************************************/
369 /**
370 *
371 * This function sets Ranges for Incrementers depending on parameters passed.
372 *
373 * @param        InstancePtr is a pointer to the XAxiPmon instance.
374 * @param        IncrementerNum specifies the Incrementer for which Ranges
375 *               need to be set
376 * @param        RangeUpper specifies the Upper limit in 32 bit Register
377 * @param        RangeLower specifies the Lower limit in 32 bit Register
378 *
379 * @return       None.
380 *
381 * @note         None
382 *
383 *****************************************************************************/
384 void XAxiPmon_SetIncrementerRange(XAxiPmon *InstancePtr, u8 IncrementerNum,
385                                         u16 RangeUpper, u16 RangeLower)
386  {
387
388         u32 RegValue;
389
390         /*
391          * Assert the arguments.
392          */
393         Xil_AssertVoid(InstancePtr != NULL);
394         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
395         Xil_AssertVoid(InstancePtr->Mode == XAPM_MODE_ADVANCED);
396         Xil_AssertVoid(IncrementerNum < XAPM_MAX_COUNTERS);
397
398         /*
399          * Write to the specified Range register
400          */
401         RegValue = RangeUpper << 16;
402         RegValue |= RangeLower;
403         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
404                         (XAPM_RANGE0_OFFSET + (IncrementerNum * 16)),
405                         RegValue);
406  }
407
408 /****************************************************************************/
409 /**
410 *
411 * This function returns the Ranges of Incrementers Registers.
412 *
413 * @param        InstancePtr is a pointer to the XAxiPmon instance.
414 * @param        IncrementerNum specifies the Incrementer for which Ranges
415 *               need to be returned.
416 * @param        RangeUpper specifies the user reference variable which returns
417 *               the Upper Range Value of the specified Incrementer.
418 * @param        RangeLower specifies the user reference variable which returns
419 *               the Lower Range Value of the specified Incrementer.
420 *
421 * @return       None.
422 *
423 * @note         None
424 *
425 *****************************************************************************/
426 void XAxiPmon_GetIncrementerRange(XAxiPmon *InstancePtr, u8 IncrementerNum,
427                                 u16 *RangeUpper, u16 *RangeLower)
428  {
429
430         u32 RegValue;
431         /*
432          * Assert the arguments.
433          */
434         Xil_AssertVoid(InstancePtr != NULL);
435         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
436         Xil_AssertVoid(InstancePtr->Mode == XAPM_MODE_ADVANCED);
437         Xil_AssertVoid(IncrementerNum < XAPM_MAX_COUNTERS);
438
439         RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
440                                 (XAPM_RANGE0_OFFSET + (IncrementerNum * 16)));
441
442         *RangeLower = RegValue & 0xFFFF;
443         *RangeUpper = (RegValue >> 16) & 0xFFFF;
444  }
445
446 /****************************************************************************/
447 /**
448 *
449 * This function sets the Sample Interval Register
450 *
451 * @param        InstancePtr is a pointer to the XAxiPmon instance.
452 * @param        SampleInterval is the Sample Interval value to be set
453 *
454 * @return       None
455 *
456 * @note         None.
457 *
458 *****************************************************************************/
459 void XAxiPmon_SetSampleInterval(XAxiPmon *InstancePtr, u32 SampleInterval)
460 {
461
462         /*
463          * Assert the arguments.
464          */
465         Xil_AssertVoid(InstancePtr != NULL);
466         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
467         Xil_AssertVoid(InstancePtr->Mode != XAPM_MODE_TRACE);
468
469         /*
470          * Set Sample Interval Lower
471          */
472         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
473                 XAPM_SI_LOW_OFFSET, SampleInterval);
474
475 }
476
477 /****************************************************************************/
478 /**
479 *
480 * This function returns the contents of Sample Interval Register
481 *
482 * @param        InstancePtr is a pointer to the XAxiPmon instance.
483 * @param        SampleInterval is a pointer where the Sample Interval
484 *               Counter value is returned.
485 *
486 * @return       None.
487 *
488 * @note         None.
489 *
490 ******************************************************************************/
491 void XAxiPmon_GetSampleInterval(XAxiPmon *InstancePtr, u32 *SampleInterval)
492 {
493         /*
494          * Assert the arguments.
495          */
496         Xil_AssertVoid(InstancePtr != NULL);
497         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
498         Xil_AssertVoid(InstancePtr->Mode != XAPM_MODE_TRACE);
499
500         /*
501          * Set Sample Interval Lower
502          */
503         *SampleInterval = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
504                                 XAPM_SI_LOW_OFFSET);
505
506 }
507
508 /****************************************************************************/
509 /**
510 *
511 * This function sets Metrics for specified Counter in the corresponding
512 * Metric Selector Register.
513 *
514 * @param        InstancePtr is a pointer to the XAxiPmon instance.
515 * @param        Slot is the slot ID for which specified counter has to
516 *               be connected.
517 * @param        Metrics is one of the Metric Sets. User has to use
518 *               XAPM_METRIC_SET_* macros in xaxipmon.h for this parameter
519 * @param        CounterNum is the Counter Number.
520 *               The valid values are 0 to 9.
521 *
522 * @return       XST_SUCCESS if Success
523 *               XST_FAILURE if Failure
524 *
525 * @note         None.
526 *
527 *****************************************************************************/
528 int XAxiPmon_SetMetrics(XAxiPmon *InstancePtr, u8 Slot, u8 Metrics,
529                                                 u8 CounterNum)
530 {
531         u32 RegValue;
532         u32 Mask;
533         /*
534          * Assert the arguments.
535          */
536         Xil_AssertNonvoid(InstancePtr != NULL);
537         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
538         Xil_AssertNonvoid(InstancePtr->Mode == XAPM_MODE_ADVANCED);
539         Xil_AssertNonvoid(Slot < XAPM_MAX_AGENTS);
540         Xil_AssertNonvoid((Metrics <= XAPM_METRIC_SET_22) ||
541                         (Metrics == XAPM_METRIC_SET_30));
542         Xil_AssertNonvoid(CounterNum < XAPM_MAX_COUNTERS);
543
544         /* Find Mask value to force zero in counternum byte range */
545         if (CounterNum == 0 || CounterNum == 4 || CounterNum == 8) {
546                 Mask = 0xFFFFFF00;
547         }
548         else if (CounterNum == 1 || CounterNum == 5 || CounterNum == 9) {
549                 Mask = 0xFFFF00FF;
550         }
551         else if (CounterNum == 2 || CounterNum == 6) {
552                 Mask = 0xFF00FFFF;
553         }
554         else {
555                 Mask = 0x00FFFFFF;
556         }
557
558         if(CounterNum <= 3) {
559                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
560                                             XAPM_MSR0_OFFSET);
561
562                 RegValue = RegValue & Mask;
563                 RegValue = RegValue | (Metrics << (CounterNum * 8));
564                 RegValue = RegValue | (Slot << (CounterNum * 8 + 5));
565                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
566                                         XAPM_MSR0_OFFSET,RegValue);
567         }
568         else if((CounterNum >= 4) && (CounterNum <= 7)) {
569                 CounterNum = CounterNum - 4;
570                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
571                                             XAPM_MSR1_OFFSET);
572
573                 RegValue = RegValue & Mask;
574                 RegValue = RegValue | (Metrics << (CounterNum * 8));
575                 RegValue = RegValue | (Slot << (CounterNum * 8 + 5));
576                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
577                                         XAPM_MSR1_OFFSET,RegValue);
578         }
579         else {
580                 CounterNum = CounterNum - 8;
581                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
582                                             XAPM_MSR2_OFFSET);
583
584                 RegValue = RegValue & Mask;
585                 RegValue = RegValue | (Metrics << (CounterNum * 8));
586                 RegValue = RegValue | (Slot << (CounterNum * 8 + 5));
587                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
588                                         XAPM_MSR2_OFFSET,RegValue);
589         }
590         return XST_SUCCESS;
591 }
592
593 /*****************************************************************************/
594 /**
595 *
596 * This function returns Metrics in the specified Counter from the corresponding
597 * Metric Selector Register.
598 *
599 * @param        InstancePtr is a pointer to the XAxiPmon instance.
600 * @param        CounterNum is the Counter Number.
601 *               The valid values are 0 to 9.
602 * @param        Metrics is a reference parameter from application where metrics
603 *               of specified counter is filled.
604 * @praram       Slot is a reference parameter in which slot Id of
605 *               specified counter is filled
606 * @return       XST_SUCCESS if Success
607 *               XST_FAILURE if Failure
608 *
609 * @note         None.
610 *
611 *****************************************************************************/
612 int XAxiPmon_GetMetrics(XAxiPmon *InstancePtr, u8 CounterNum, u8 *Metrics,
613                                                                 u8 *Slot)
614 {
615         u32 RegValue;
616         /*
617          * Assert the arguments.
618          */
619         Xil_AssertNonvoid(InstancePtr != NULL);
620         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
621         Xil_AssertNonvoid(InstancePtr->Mode == XAPM_MODE_ADVANCED);
622         Xil_AssertNonvoid(CounterNum <= XAPM_MAX_COUNTERS);
623
624         if(CounterNum <= 3) {
625                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
626                                         XAPM_MSR0_OFFSET);
627                 *Metrics = (RegValue >> (CounterNum * 8)) & 0x1F;
628                 *Slot   = (RegValue >> (CounterNum * 8 + 5)) & 0x7;
629
630         }
631         else if((CounterNum >= 4) && (CounterNum <= 7)) {
632                 CounterNum = CounterNum - 4;
633                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
634                                         XAPM_MSR1_OFFSET);
635                 *Metrics = (RegValue >> (CounterNum * 8)) & 0x1F;
636                 *Slot   = (RegValue >> (CounterNum * 8 + 5)) & 0x7;
637         }
638         else {
639                 CounterNum = CounterNum - 8;
640                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
641                                         XAPM_MSR2_OFFSET);
642                 *Metrics = (RegValue >> (CounterNum * 8)) & 0x1F;
643                 *Slot   = (RegValue >> (CounterNum * 8 + 5)) & 0x7;
644         }
645         return XST_SUCCESS;
646 }
647
648 /****************************************************************************/
649 /**
650 *
651 * This function returns the contents of the Global Clock Counter Register.
652 *
653 * @param        InstancePtr is a pointer to the XAxiPmon instance.
654 * @param        CntHighValue is the user space pointer with which upper 32 bits
655 *               of Global Clock Counter has to be filled
656 * @param        CntLowValue is the user space pointer with which lower 32 bits
657 *               of Global Clock Counter has to be filled
658 *
659 * @return       None.
660 *
661 * @note         None.
662 *
663 *****************************************************************************/
664 void XAxiPmon_GetGlobalClkCounter(XAxiPmon *InstancePtr,u32 *CntHighValue,
665                                                         u32 *CntLowValue)
666 {
667         /*
668          * Assert the arguments.
669          */
670         Xil_AssertVoid(InstancePtr != NULL);
671         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
672         Xil_AssertVoid(InstancePtr->Mode == XAPM_MODE_ADVANCED);
673
674         *CntHighValue = 0x0;
675         *CntLowValue  = 0x0;
676
677         /*
678          * If Counter width is 64 bit then Counter Value has to be
679          * filled at CntHighValue address also.
680          */
681         if(InstancePtr->Config.GlobalClkCounterWidth == 64) {
682
683                 /* Bits[63:32] exists at XAPM_GCC_HIGH_OFFSET */
684                 *CntHighValue = XAxiPmon_ReadReg(InstancePtr->
685                                 Config.BaseAddress, XAPM_GCC_HIGH_OFFSET);
686         }
687         /* Bits[31:0] exists at XAPM_GCC_LOW_OFFSET */
688         *CntLowValue = XAxiPmon_ReadReg(InstancePtr->
689                                 Config.BaseAddress, XAPM_GCC_LOW_OFFSET);
690 }
691
692 /****************************************************************************/
693 /**
694 *
695 * This function returns the contents of the Metric Counter Register.
696 *
697 * @param        InstancePtr is a pointer to the XAxiPmon instance.
698 * @param        CounterNum is the number of the Metric Counter to be read.
699 *               Use the XAPM_METRIC_COUNTER* defines for the counter number in
700 *               xaxipmon.h. The valid values are 0 (XAPM_METRIC_COUNTER_0) to
701 *               47(XAPM_METRIC_COUNTER_47).
702 * @return       RegValue is the content of specified Metric Counter.
703 *
704 * @note         None.
705 *
706 *****************************************************************************/
707 u32 XAxiPmon_GetMetricCounter(XAxiPmon *InstancePtr, u32 CounterNum)
708 {
709
710         u32 RegValue;
711
712         /*
713          * Assert the arguments.
714          */
715         Xil_AssertNonvoid(InstancePtr != NULL);
716         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
717         Xil_AssertNonvoid(InstancePtr->Mode != XAPM_MODE_TRACE);
718         Xil_AssertNonvoid(CounterNum < XAPM_MAX_COUNTERS_PROFILE);
719
720         if (CounterNum < 10 ) {
721                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
722                         (XAPM_MC0_OFFSET + (CounterNum * 16)));
723         }
724         else if (CounterNum >= 10 && CounterNum < 12) {
725                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
726                         (XAPM_MC10_OFFSET + ((CounterNum - 10) * 16)));
727         }
728         else if (CounterNum >= 12 && CounterNum < 24) {
729                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
730                         (XAPM_MC12_OFFSET + ((CounterNum - 12) * 16)));
731         }
732         else if (CounterNum >= 24 && CounterNum < 36) {
733                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
734                         (XAPM_MC24_OFFSET + ((CounterNum - 24) * 16)));
735         }
736         else
737                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
738                         (XAPM_MC36_OFFSET + ((CounterNum - 36) * 16)));
739
740         return RegValue;
741 }
742
743 /****************************************************************************/
744 /**
745 *
746 * This function returns the contents of the Sampled Metric Counter Register.
747 *
748 * @param        InstancePtr is a pointer to the XAxiPmon instance.
749 * @param        CounterNum is the number of the Sampled Metric Counter to read.
750 *               Use the XAPM_METRIC_COUNTER* defines for the counter number in
751 *               xaxipmon.h. The valid values are 0 (XAPM_METRIC_COUNTER_0) to
752 *               47(XAPM_METRIC_COUNTER_47).
753 *
754 * @return       RegValue is the content of specified Sampled Metric Counter.
755 *
756 * @note         None.
757 *
758 *****************************************************************************/
759 u32 XAxiPmon_GetSampledMetricCounter(XAxiPmon *InstancePtr, u32 CounterNum)
760 {
761         u32 RegValue;
762
763         /*
764          * Assert the arguments.
765          */
766         Xil_AssertNonvoid(InstancePtr != NULL);
767         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
768         Xil_AssertNonvoid(InstancePtr->Mode != XAPM_MODE_TRACE);
769         Xil_AssertNonvoid(CounterNum < XAPM_MAX_COUNTERS_PROFILE);
770         Xil_AssertNonvoid(InstancePtr->Mode == XAPM_MODE_PROFILE ||
771                 ((InstancePtr->Mode == XAPM_MODE_ADVANCED) &&
772                         (InstancePtr->Config.HaveSampledCounters == 1)));
773
774         if (CounterNum < 10 ) {
775                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
776                         (XAPM_SMC0_OFFSET + (CounterNum * 16)));
777         }
778         else if (CounterNum >= 10 && CounterNum < 12) {
779                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
780                         (XAPM_SMC10_OFFSET + ((CounterNum - 10) * 16)));
781         }
782         else if (CounterNum >= 12 && CounterNum < 24) {
783                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
784                         (XAPM_SMC12_OFFSET + ((CounterNum - 12) * 16)));
785         }
786         else if (CounterNum >= 24 && CounterNum < 36) {
787                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
788                         (XAPM_SMC24_OFFSET + ((CounterNum - 24) * 16)));
789         }
790         else
791                 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
792                         (XAPM_SMC36_OFFSET + ((CounterNum - 36) * 16)));
793
794         return RegValue;
795 }
796
797 /****************************************************************************/
798 /**
799 *
800 * This function returns the contents of the Incrementer Register.
801 *
802 * @param        InstancePtr is a pointer to the XAxiPmon instance.
803 * @param        IncrementerNum is the number of the Incrementer register to
804 *               read.Use the XAPM_INCREMENTER_* defines for the Incrementer
805 *               number.The valid values are 0 (XAPM_INCREMENTER_0) to
806 *               9 (XAPM_INCREMENTER_9).
807 * @param        IncrementerNum is the number of the specified Incrementer
808 *               register
809 * @return       RegValue is content of specified Metric Incrementer register.
810 *
811 * @note         None.
812 *
813 *****************************************************************************/
814 u32 XAxiPmon_GetIncrementer(XAxiPmon *InstancePtr, u32 IncrementerNum)
815 {
816         u32 RegValue;
817
818         /*
819          * Assert the arguments.
820          */
821         Xil_AssertNonvoid(InstancePtr != NULL);
822         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
823         Xil_AssertNonvoid(InstancePtr->Mode == XAPM_MODE_ADVANCED &&
824                                 InstancePtr->Config.IsEventCount == 1);
825         Xil_AssertNonvoid(IncrementerNum < XAPM_MAX_COUNTERS);
826
827         RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
828                         (XAPM_INC0_OFFSET + (IncrementerNum * 16)));
829
830         return RegValue;
831 }
832
833 /****************************************************************************/
834 /**
835 *
836 * This function returns the contents of the Sampled Incrementer Register.
837 *
838 * @param        InstancePtr is a pointer to the XAxiPmon instance.
839 * @param        IncrementerNum is the number of the Sampled Incrementer
840 *               register to read.Use the XAPM_INCREMENTER_* defines for the
841 *               Incrementer number.The valid values are 0 (XAPM_INCREMENTER_0)
842 *               to 9 (XAPM_INCREMENTER_9).
843 * @param        IncrementerNum is the number of the specified Sampled
844 *               Incrementer register
845 * @return       RegValue is content of specified Sampled Incrementer register.
846 *
847 * @note         None.
848 *
849 *****************************************************************************/
850 u32 XAxiPmon_GetSampledIncrementer(XAxiPmon *InstancePtr, u32 IncrementerNum)
851 {
852         u32 RegValue;
853
854         /*
855          * Assert the arguments.
856          */
857         Xil_AssertNonvoid(InstancePtr != NULL);
858         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
859         Xil_AssertNonvoid(InstancePtr->Mode == XAPM_MODE_ADVANCED &&
860                                 InstancePtr->Config.IsEventCount == 1 &&
861                                 InstancePtr->Config.HaveSampledCounters == 1);
862         Xil_AssertNonvoid(IncrementerNum < XAPM_MAX_COUNTERS);
863
864         RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
865                                 (XAPM_SINC0_OFFSET + (IncrementerNum * 16)));
866         return RegValue;
867 }
868
869 /****************************************************************************/
870 /**
871 *
872 * This function sets Software-written Data Register.
873 *
874 * @param        InstancePtr is a pointer to the XAxiPmon instance.
875 * @param        SwData is the Software written Data.
876 *
877 * @return       None.
878 *
879 * @note         None.
880 *
881 *****************************************************************************/
882 void XAxiPmon_SetSwDataReg(XAxiPmon *InstancePtr, u32 SwData)
883 {
884         /*
885          * Assert the arguments.
886          */
887         Xil_AssertVoid(InstancePtr != NULL);
888         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
889
890         /*
891          * Set Software-written Data Register
892          */
893         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_SWD_OFFSET,
894                                                                 SwData);
895 }
896
897 /****************************************************************************/
898 /**
899 *
900 * This function returns contents of Software-written Data Register.
901 *
902 * @param        InstancePtr is a pointer to the XAxiPmon instance.
903 *
904 * @return       SwData.
905 *
906 * @note         None.
907 *
908 *****************************************************************************/
909 u32 XAxiPmon_GetSwDataReg(XAxiPmon *InstancePtr)
910 {
911          u32 SwData;
912
913         /*
914          * Assert the arguments.
915          */
916         Xil_AssertNonvoid(InstancePtr != NULL);
917         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
918
919         /*
920          * Set Metric Selector Register
921          */
922         SwData = (u32)XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
923                                                 XAPM_SWD_OFFSET);
924         return SwData;
925 }
926
927 /*****************************************************************************/
928 /**
929 *
930 * This function enables the following in the AXI Performance Monitor:
931 *   - Event logging
932 *
933 * @param        InstancePtr is a pointer to the XAxiPmon instance.
934 * @param        FlagEnables is a value to write to the flag enables
935 *               register defined by XAPM_FEC_OFFSET. It is recommended
936 *               to use the XAPM_FEC_*_MASK mask bits to generate.
937 *               A value of 0x0 will disable all events to the event
938 *               log streaming FIFO.
939 *
940 * @return       XST_SUCCESS
941 *
942 * @note         None
943 *
944 ******************************************************************************/
945 int XAxiPmon_StartEventLog(XAxiPmon *InstancePtr, u32 FlagEnables)
946 {
947         u32 RegValue;
948
949         /*
950          * Assert the arguments.
951          */
952         Xil_AssertNonvoid(InstancePtr != NULL);
953         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
954         Xil_AssertNonvoid(InstancePtr->Mode == XAPM_MODE_TRACE ||
955                                 ((InstancePtr->Mode == XAPM_MODE_ADVANCED) &&
956                         (InstancePtr->Config.IsEventLog == 1)));
957
958         /* Read current register value */
959         RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
960                                                         XAPM_CTL_OFFSET);
961         /* Flag Enable register is present only in Advanced Mode */
962         if(InstancePtr->Mode == XAPM_MODE_ADVANCED)
963         {
964                 /* Now write to flag enables register */
965                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
966                                 XAPM_FEC_OFFSET, FlagEnables);
967         }
968
969         /* Write the new value to the Control register to
970          *      enable event logging */
971         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
972                                   RegValue | XAPM_CR_EVENTLOG_ENABLE_MASK);
973
974         return XST_SUCCESS;
975 }
976
977 /*****************************************************************************/
978 /**
979 *
980 * This function disables the following in the AXI Performance Monitor:
981 *   - Event logging
982 *
983 * @param        InstancePtr is a pointer to the XAxiPmon instance.
984 *
985 * @return       XST_SUCCESS
986 *
987 * @note         None
988 *
989 ******************************************************************************/
990 int XAxiPmon_StopEventLog(XAxiPmon *InstancePtr)
991 {
992         u32 RegValue;
993
994         /*
995          * Assert the arguments.
996          */
997         Xil_AssertNonvoid(InstancePtr != NULL);
998         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
999         Xil_AssertNonvoid(InstancePtr->Mode == XAPM_MODE_TRACE ||
1000                         ((InstancePtr->Mode == XAPM_MODE_ADVANCED) &&
1001                         (InstancePtr->Config.IsEventLog == 1)));
1002
1003         /* Read current register value */
1004         RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1005                                                 XAPM_CTL_OFFSET);
1006
1007         /* Write the new value to the Control register to disable
1008          * event logging */
1009         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1010                             RegValue & ~XAPM_CR_EVENTLOG_ENABLE_MASK);
1011
1012         return XST_SUCCESS;
1013 }
1014
1015 /*****************************************************************************/
1016 /**
1017 *
1018 * This function enables the following in the AXI Performance Monitor:
1019 *   - Global clock counter
1020 *   - All metric counters
1021 *   - All sampled metric counters
1022 *
1023 * @param    InstancePtr is a pointer to the XAxiPmon instance.
1024 *           SampleInterval is the sample interval for the sampled metric
1025 *           counters
1026 *
1027 * @return   XST_SUCCESS
1028 *
1029 * @note     None
1030 ******************************************************************************/
1031 int XAxiPmon_StartCounters(XAxiPmon *InstancePtr, u32 SampleInterval)
1032 {
1033         u32 RegValue;
1034
1035         /*
1036          * Assert the arguments.
1037          */
1038         Xil_AssertNonvoid(InstancePtr != NULL);
1039         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1040         Xil_AssertNonvoid(InstancePtr->Mode == XAPM_MODE_PROFILE ||
1041                                 ((InstancePtr->Mode == XAPM_MODE_ADVANCED) &&
1042                                 (InstancePtr->Config.IsEventCount == 1)));
1043
1044         /* Read current register value */
1045         RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1046                                                         XAPM_CTL_OFFSET);
1047         /* Globlal Clock Counter is present in Advanced mode only */
1048         if(InstancePtr->Mode == XAPM_MODE_ADVANCED)
1049         {
1050                 RegValue = RegValue | XAPM_CR_GCC_ENABLE_MASK;
1051         }
1052
1053         /*
1054          * Write the new value to the Control register to enable
1055          * global clock counter and metric counters
1056          */
1057         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1058               RegValue | XAPM_CR_MCNTR_ENABLE_MASK);
1059
1060         /* Set, enable, and load sampled counters */
1061         XAxiPmon_SetSampleInterval(InstancePtr, SampleInterval);
1062         XAxiPmon_LoadSampleIntervalCounter(InstancePtr);
1063         XAxiPmon_EnableSampleIntervalCounter(InstancePtr);
1064
1065         return XST_SUCCESS;
1066 }
1067
1068 /*****************************************************************************/
1069 /**
1070 *
1071 * This function disables the following in the AXI Performance Monitor:
1072 *   - Global clock counter
1073 *   - All metric counters
1074 *
1075 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1076 *
1077 * @return       XST_SUCCESS
1078 *
1079 * @note         None
1080 *
1081 ******************************************************************************/
1082 int XAxiPmon_StopCounters(XAxiPmon *InstancePtr)
1083 {
1084         u32 RegValue;
1085
1086         /*
1087          * Assert the arguments.
1088          */
1089         Xil_AssertNonvoid(InstancePtr != NULL);
1090         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1091         Xil_AssertNonvoid(InstancePtr->Mode == XAPM_MODE_PROFILE ||
1092                                 ((InstancePtr->Mode == XAPM_MODE_ADVANCED) &&
1093                                 (InstancePtr->Config.IsEventCount == 1)));
1094
1095         /* Read current register value */
1096         RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1097                                                         XAPM_CTL_OFFSET);
1098         /* Globlal Clock Counter is present in Advanced mode only */
1099         if(InstancePtr->Mode == XAPM_MODE_ADVANCED)
1100         {
1101                 RegValue = RegValue & ~XAPM_CR_GCC_ENABLE_MASK;
1102         }
1103
1104         /*
1105          * Write the new value to the Control register to disable
1106          * global clock counter and metric counters
1107          */
1108         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1109         RegValue & ~XAPM_CR_MCNTR_ENABLE_MASK);
1110
1111         return XST_SUCCESS;
1112 }
1113
1114 /*****************************************************************************/
1115 /**
1116 *
1117 * This function enables Metric Counters.
1118 *
1119 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1120 *
1121 * @return       None
1122 *
1123 * @note         None
1124 *
1125 *******************************************************************************/
1126 void XAxiPmon_EnableMetricsCounter(XAxiPmon *InstancePtr)
1127 {
1128         u32 RegVal;
1129
1130         /*
1131          * Assert the arguments.
1132          */
1133         Xil_AssertVoid(InstancePtr != NULL);
1134         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1135         Xil_AssertVoid(InstancePtr->Mode == XAPM_MODE_PROFILE ||
1136                                 ((InstancePtr->Mode == XAPM_MODE_ADVANCED) &&
1137                                 (InstancePtr->Config.IsEventCount == 1)));
1138
1139         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1140                                                 XAPM_CTL_OFFSET);
1141         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1142                                         RegVal | XAPM_CR_MCNTR_ENABLE_MASK);
1143 }
1144 /****************************************************************************/
1145 /**
1146 *
1147 * This function disables the Metric Counters.
1148 *
1149 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1150 *
1151 * @return       None
1152 *
1153 * @note         None
1154 *
1155 *****************************************************************************/
1156 void XAxiPmon_DisableMetricsCounter(XAxiPmon *InstancePtr)
1157 {
1158         u32 RegVal;
1159
1160         /*
1161          * Assert the arguments.
1162          */
1163         Xil_AssertVoid(InstancePtr != NULL);
1164         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1165         Xil_AssertVoid(InstancePtr->Mode == XAPM_MODE_PROFILE ||
1166                                 ((InstancePtr->Mode == XAPM_MODE_ADVANCED) &&
1167                                 (InstancePtr->Config.IsEventCount == 1)));
1168
1169         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1170                                                         XAPM_CTL_OFFSET);
1171
1172         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1173                                         RegVal & ~(XAPM_CR_MCNTR_ENABLE_MASK));
1174 }
1175
1176 /****************************************************************************/
1177 /**
1178 *
1179 * This function sets the Upper and Lower Ranges for specified Metric Counter
1180 * Log Enable Register.Event Logging starts when corresponding Metric Counter
1181 * value falls in between these ranges
1182 *
1183 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1184 * @param        CounterNum is the Metric Counter number for which
1185 *               Ranges are to be assigned.Use the XAPM_METRIC_COUNTER*
1186 *               defines for the counter number in xaxipmon.h.
1187 *               The valid values are 0 (XAPM_METRIC_COUNTER_0) to
1188 *               9 (XAPM_METRIC_COUNTER_9).
1189 * @param        RangeUpper specifies the Upper limit in 32 bit Register
1190 * @param        RangeLower specifies the Lower limit in 32 bit Register
1191 * @return       None
1192 *
1193 * @note         None.
1194 *
1195 *****************************************************************************/
1196 void XAxiPmon_SetLogEnableRanges(XAxiPmon *InstancePtr, u32 CounterNum,
1197                                         u16 RangeUpper, u16 RangeLower)
1198 {
1199         u32 RegValue;
1200         /*
1201          * Assert the arguments.
1202          */
1203         Xil_AssertVoid(InstancePtr != NULL);
1204         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1205         Xil_AssertVoid(CounterNum < XAPM_MAX_COUNTERS);
1206         Xil_AssertVoid((InstancePtr->Mode == XAPM_MODE_ADVANCED) &&
1207                                 (InstancePtr->Config.IsEventCount == 1));
1208
1209
1210         /*
1211          * Write the specified Ranges to corresponding Metric Counter Log
1212          * Enable Register
1213          */
1214         RegValue = RangeUpper << 16;
1215         RegValue |= RangeLower;
1216         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1217                 (XAPM_MC0LOGEN_OFFSET + (CounterNum * 16)), RegValue);
1218
1219 }
1220
1221 /****************************************************************************/
1222 /**
1223 *
1224 * This function returns the Ranges of specified Metric Counter Log
1225 * Enable Register.
1226 *
1227 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1228 * @param        CounterNum is the Metric Counter number for which
1229 *               Ranges are to be returned.Use the XAPM_METRIC_COUNTER*
1230 *               defines for the counter number in xaxipmon.h.
1231 *               The valid values are 0 (XAPM_METRIC_COUNTER_0) to
1232 *               9 (XAPM_METRIC_COUNTER_9).
1233 *
1234 * @param        RangeUpper specifies the user reference variable which returns
1235 *               the Upper Range Value of the specified Metric Counter
1236 *               Log Enable Register.
1237 * @param        RangeLower specifies the user reference variable which returns
1238 *               the Lower Range Value of the specified Metric Counter
1239 *               Log Enable Register.
1240 *
1241 * @note         None.
1242 *
1243 *****************************************************************************/
1244 void XAxiPmon_GetLogEnableRanges(XAxiPmon *InstancePtr, u32 CounterNum,
1245                                         u16 *RangeUpper, u16 *RangeLower)
1246 {
1247         u32 RegValue;
1248         /*
1249          * Assert the arguments.
1250          */
1251         Xil_AssertVoid(InstancePtr != NULL);
1252         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1253         Xil_AssertVoid(CounterNum < XAPM_MAX_COUNTERS);
1254         Xil_AssertVoid((InstancePtr->Mode == XAPM_MODE_ADVANCED) &&
1255                                 (InstancePtr->Config.IsEventCount == 1));
1256
1257
1258         RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1259                                 (XAPM_MC0LOGEN_OFFSET + (CounterNum * 16)));
1260
1261         *RangeLower = RegValue & 0xFFFF;
1262         *RangeUpper = (RegValue >> 16) & 0xFFFF;
1263 }
1264
1265 /*****************************************************************************/
1266 /**
1267 *
1268 * This function enables Event Logging.
1269 *
1270 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1271 *
1272 * @return       None
1273 *
1274 * @note         None
1275 *
1276 *******************************************************************************/
1277 void XAxiPmon_EnableEventLog(XAxiPmon *InstancePtr)
1278 {
1279         u32 RegVal;
1280
1281         /*
1282          * Assert the arguments.
1283          */
1284         Xil_AssertVoid(InstancePtr != NULL);
1285         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1286         Xil_AssertVoid(InstancePtr->Mode == XAPM_MODE_TRACE ||
1287                                 ((InstancePtr->Mode == XAPM_MODE_ADVANCED) &&
1288                                 (InstancePtr->Config.IsEventLog == 1)));
1289
1290         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1291                                                         XAPM_CTL_OFFSET);
1292         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1293                                 RegVal | XAPM_CR_EVENTLOG_ENABLE_MASK);
1294 }
1295
1296 /*****************************************************************************/
1297 /**
1298 *
1299 * This function enables External trigger pulse so that Metric Counters can be
1300 * started on external trigger pulse for a Slot.
1301 *
1302 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1303 *
1304 * @return       None
1305 *
1306 * @note         None
1307 *
1308 *******************************************************************************/
1309 void XAxiPmon_EnableMetricCounterTrigger(XAxiPmon *InstancePtr)
1310 {
1311         u32 RegVal;
1312
1313         /*
1314          * Assert the arguments.
1315          */
1316         Xil_AssertVoid(InstancePtr != NULL);
1317         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1318         Xil_AssertVoid(InstancePtr->Mode != XAPM_MODE_TRACE);
1319
1320         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1321                                                         XAPM_CTL_OFFSET);
1322         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1323                                 RegVal | XAPM_CR_MCNTR_EXTTRIGGER_MASK);
1324 }
1325
1326 /****************************************************************************/
1327 /**
1328 *
1329 * This function disables the External trigger pulse used to start Metric
1330 * Counters on external trigger pulse for a Slot.
1331 *
1332 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1333 *
1334 * @return       None
1335 *
1336 * @note         None
1337 *
1338 *****************************************************************************/
1339 void XAxiPmon_DisableMetricCounterTrigger(XAxiPmon *InstancePtr)
1340 {
1341         u32 RegVal;
1342
1343         /*
1344          * Assert the arguments.
1345          */
1346         Xil_AssertVoid(InstancePtr != NULL);
1347         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1348         Xil_AssertVoid(InstancePtr->Mode != XAPM_MODE_TRACE);
1349
1350         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1351                                                         XAPM_CTL_OFFSET);
1352
1353         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1354                                 RegVal & ~(XAPM_CR_MCNTR_EXTTRIGGER_MASK));
1355 }
1356
1357 /*****************************************************************************/
1358 /**
1359 *
1360 * This function enables External trigger pulse for Event Log
1361 * so that Event Logging can be started on external trigger pulse for a Slot.
1362 *
1363 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1364 *
1365 * @return       None
1366 *
1367 * @note         None
1368 *
1369 *******************************************************************************/
1370 void XAxiPmon_EnableEventLogTrigger(XAxiPmon *InstancePtr)
1371 {
1372         u32 RegVal;
1373
1374         /*
1375          * Assert the arguments.
1376          */
1377         Xil_AssertVoid(InstancePtr != NULL);
1378         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1379         Xil_AssertVoid(InstancePtr->Mode != XAPM_MODE_PROFILE);
1380
1381         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1382                                                         XAPM_CTL_OFFSET);
1383         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1384                                 RegVal | XAPM_CR_EVTLOG_EXTTRIGGER_MASK);
1385 }
1386
1387 /****************************************************************************/
1388 /**
1389 *
1390 * This function disables the External trigger pulse used to start Event
1391 * Log on external trigger pulse for a Slot.
1392 *
1393 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1394 *
1395 * @return       None
1396 *
1397 * @note         None
1398 *
1399 *****************************************************************************/
1400 void XAxiPmon_DisableEventLogTrigger(XAxiPmon *InstancePtr)
1401 {
1402         u32 RegVal;
1403
1404         /*
1405          * Assert the arguments.
1406          */
1407         Xil_AssertVoid(InstancePtr != NULL);
1408         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1409         Xil_AssertVoid(InstancePtr->Mode != XAPM_MODE_PROFILE);
1410
1411         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1412                                                         XAPM_CTL_OFFSET);
1413
1414         XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1415                                 RegVal & ~(XAPM_CR_EVTLOG_EXTTRIGGER_MASK));
1416 }
1417
1418 /****************************************************************************/
1419 /**
1420 *
1421 * This function returns a name for a given Metric.
1422 *
1423 * @param        Metrics is one of the Metric Sets. User has to use
1424 *               XAPM_METRIC_SET_* macros in xaxipmon.h for this parameter
1425 *
1426 * @return       const char *
1427 *
1428 * @note         None
1429 *
1430 *****************************************************************************/
1431 const char * XAxiPmon_GetMetricName(u8 Metrics)
1432 {
1433         if (Metrics == XAPM_METRIC_SET_0 ){
1434                 return "Write Transaction Count";
1435         }
1436         if (Metrics == XAPM_METRIC_SET_1 ){
1437                         return "Read Transaction Count";
1438         }
1439         if (Metrics == XAPM_METRIC_SET_2 ){
1440                         return "Write Byte Count";
1441         }
1442         if (Metrics == XAPM_METRIC_SET_3 ){
1443                         return "Read Byte Count";
1444         }
1445         if (Metrics == XAPM_METRIC_SET_4 ){
1446                         return "Write Beat Count";
1447         }
1448         if (Metrics == XAPM_METRIC_SET_5 ){
1449                         return "Total Read Latency";
1450         }
1451         if (Metrics == XAPM_METRIC_SET_6 ){
1452                         return "Total Write Latency";
1453         }
1454         if (Metrics == XAPM_METRIC_SET_7 ){
1455                 return "Slv_Wr_Idle_Cnt";
1456         }
1457         if (Metrics == XAPM_METRIC_SET_8 ){
1458                         return "Mst_Rd_Idle_Cnt";
1459         }
1460         if (Metrics == XAPM_METRIC_SET_9 ){
1461                         return "Num_BValids";
1462         }
1463         if (Metrics == XAPM_METRIC_SET_10){
1464                 return "Num_WLasts";
1465         }
1466         if (Metrics == XAPM_METRIC_SET_11){
1467                         return "Num_RLasts";
1468         }
1469         if (Metrics == XAPM_METRIC_SET_12){
1470                         return "Minimum Write Latency";
1471         }
1472         if (Metrics == XAPM_METRIC_SET_13){
1473                         return "Maximum Write Latency";
1474         }
1475         if (Metrics == XAPM_METRIC_SET_14){
1476                         return "Minimum Read Latency";
1477         }
1478         if (Metrics == XAPM_METRIC_SET_15){
1479                         return "Maximum Read Latency";
1480         }
1481         if (Metrics == XAPM_METRIC_SET_16){
1482                         return "Transfer Cycle Count";
1483         }
1484         if (Metrics == XAPM_METRIC_SET_17){
1485                         return "Packet Count";
1486         }
1487         if (Metrics == XAPM_METRIC_SET_18){
1488                         return "Data Byte Count";
1489         }
1490         if (Metrics == XAPM_METRIC_SET_19){
1491                         return "Position Byte Count";
1492         }
1493         if (Metrics == XAPM_METRIC_SET_20){
1494                         return "Null Byte Count";
1495         }
1496         if (Metrics == XAPM_METRIC_SET_21){
1497                         return "Slv_Idle_Cnt";
1498         }
1499         if (Metrics == XAPM_METRIC_SET_22){
1500                         return "Mst_Idle_Cnt";
1501         }
1502         if (Metrics == XAPM_METRIC_SET_30){
1503                         return "External event count";
1504         }
1505         return "Unsupported";
1506 }
1507
1508 /****************************************************************************/
1509 /**
1510 *
1511 * This function sets Write ID in ID register.
1512 *
1513 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1514 * @param        WriteId is the Write ID to be written in ID register.
1515 *
1516 * @return       None.
1517 *
1518 * @note
1519 *                       If ID filtering for write is of 32 bits(for Zynq MP APM) width then
1520 *                       WriteID is written to XAPM_ID_OFFSET or if it is 16 bit width
1521 *                       then lower 16 bits of WriteID are written to XAPM_ID_OFFSET.
1522 *
1523 *****************************************************************************/
1524 void XAxiPmon_SetWriteId(XAxiPmon *InstancePtr, u32 WriteId)
1525 {
1526         u32 RegVal;
1527         /*
1528          * Assert the arguments.
1529          */
1530         Xil_AssertVoid(InstancePtr != NULL);
1531         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1532
1533         if (InstancePtr->Config.Is32BitFiltering == 0)
1534         {
1535                 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1536                                                         XAPM_ID_OFFSET);
1537                 RegVal = RegVal & ~(XAPM_ID_WID_MASK);
1538                 RegVal = RegVal | WriteId;
1539                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1540                                         XAPM_ID_OFFSET, RegVal);
1541         } else {
1542                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1543                                         XAPM_ID_OFFSET, WriteId);
1544         }
1545 }
1546
1547 /****************************************************************************/
1548 /**
1549 *
1550 * This function sets Read ID in ID register.
1551 *
1552 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1553 * @param        ReadId is the Read ID to be written in ID register.
1554 *
1555 * @return       None.
1556 *
1557 * @note
1558 *                       If ID filtering for read is of 32 bits(for Zynq MP APM) width then
1559 *                       ReadId is written to XAPM_RID_OFFSET or if it is 16 bit width
1560 *                       then lower 16 bits of ReadId are written to XAPM_ID_OFFSET.
1561 *
1562 *****************************************************************************/
1563 void XAxiPmon_SetReadId(XAxiPmon *InstancePtr, u32 ReadId)
1564 {
1565         u32 RegVal;
1566         /*
1567          * Assert the arguments.
1568          */
1569         Xil_AssertVoid(InstancePtr != NULL);
1570         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1571
1572         if (InstancePtr->Config.Is32BitFiltering == 0)
1573         {
1574                 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1575                                                         XAPM_ID_OFFSET);
1576                 RegVal = RegVal & ~(XAPM_ID_RID_MASK);
1577                 RegVal = RegVal | (ReadId << 16);
1578                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1579                                         XAPM_ID_OFFSET, RegVal);
1580         } else {
1581                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1582                                         XAPM_RID_OFFSET, ReadId);
1583         }
1584 }
1585
1586 /****************************************************************************/
1587 /**
1588 *
1589 * This function returns Write ID in ID register.
1590 *
1591 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1592 *
1593 * @return       WriteId is the required Write ID in ID register.
1594 *
1595 * @note         None.
1596 *                       If ID filtering for write is of 32 bits(for Zynq MP APM) width then
1597 *                       32 bit XAPM_ID_OFFSET contents are returned or if it is 16 bit
1598 *                       width then lower 16 bits of XAPM_ID_OFFSET register are returned.
1599 *
1600 *****************************************************************************/
1601 u32 XAxiPmon_GetWriteId(XAxiPmon *InstancePtr)
1602 {
1603
1604         u32 WriteId;
1605         u32 RegVal;
1606         /*
1607          * Assert the arguments.
1608          */
1609         Xil_AssertNonvoid(InstancePtr != NULL);
1610         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1611
1612         if (InstancePtr->Config.Is32BitFiltering == 0)
1613         {
1614                 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1615                                                         XAPM_ID_OFFSET);
1616                 WriteId = RegVal & XAPM_ID_WID_MASK;
1617         } else {
1618                 WriteId = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1619                                                         XAPM_ID_OFFSET);
1620         }
1621
1622         return WriteId;
1623 }
1624
1625 /****************************************************************************/
1626 /**
1627 *
1628 * This function returns Read ID in ID register.
1629 *
1630 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1631 *
1632 * @return       ReadId is the required Read ID in ID register.
1633 *
1634 * @note         None.
1635 *                       If ID filtering for write is of 32 bits(for Zynq MP APM) width then
1636 *                       32 bit XAPM_RID_OFFSET contents are returned or if it is 16 bit
1637 *                       width then higher 16 bits of XAPM_ID_OFFSET register are returned.
1638 *
1639 *****************************************************************************/
1640 u32 XAxiPmon_GetReadId(XAxiPmon *InstancePtr)
1641 {
1642
1643         u32 ReadId;
1644         u32 RegVal;
1645         /*
1646          * Assert the arguments.
1647          */
1648         Xil_AssertNonvoid(InstancePtr != NULL);
1649         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1650
1651         if (InstancePtr->Config.Is32BitFiltering == 0)
1652         {
1653                 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1654                                                         XAPM_ID_OFFSET);
1655                 RegVal = RegVal & XAPM_ID_RID_MASK;
1656                 ReadId = RegVal >> 16;
1657         } else {
1658                 ReadId = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1659                                                         XAPM_RID_OFFSET);
1660         }
1661
1662         return ReadId;
1663 }
1664
1665 /*****************************************************************************/
1666 /**
1667 *
1668 * This function sets Latency Start point to calculate write latency.
1669 *
1670 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1671 * @param        Param is XAPM_LATENCY_ADDR_ISSUE or XAPM_LATENCY_ADDR_ACCEPT
1672 *               in xaxipmon.h.
1673 * @return       None
1674 *
1675 * @note         Param can be 0 - XAPM_LATENCY_ADDR_ISSUE
1676 *               or 1 - XAPM_LATENCY_ADDR_ACCEPT
1677 *
1678 *******************************************************************************/
1679 void XAxiPmon_SetWrLatencyStart(XAxiPmon *InstancePtr, u8 Param)
1680 {
1681         u32 RegVal;
1682
1683         /*
1684          * Assert the arguments.
1685          */
1686         Xil_AssertVoid(InstancePtr != NULL);
1687         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1688
1689         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1690                                                         XAPM_CTL_OFFSET);
1691         if (Param == XAPM_LATENCY_ADDR_ACCEPT) {
1692                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1693                   XAPM_CTL_OFFSET, RegVal | XAPM_CR_WRLATENCY_START_MASK);
1694         }
1695         else {
1696                 XAxiPmon_WriteReg((InstancePtr)->Config.BaseAddress,
1697                         XAPM_CTL_OFFSET,
1698                         XAxiPmon_ReadReg((InstancePtr)->Config.BaseAddress,
1699                         XAPM_CTL_OFFSET) & ~(XAPM_CR_WRLATENCY_START_MASK));
1700         }
1701 }
1702
1703 /*****************************************************************************/
1704 /**
1705 *
1706 * This function sets Latency End point to calculate write latency.
1707 *
1708 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1709 * @param        Param is XAPM_LATENCY_LASTWR or XAPM_LATENCY_FIRSTWR
1710 *               in xaxipmon.h.
1711 *
1712 * @return       None
1713 *
1714 * @note         Param can be 0 - XAPM_LATENCY_LASTWR
1715 *               or 1 - XAPM_LATENCY_FIRSTWR
1716 *
1717 *******************************************************************************/
1718 void XAxiPmon_SetWrLatencyEnd(XAxiPmon *InstancePtr, u8 Param)
1719 {
1720         u32 RegVal;
1721
1722         /*
1723          * Assert the arguments.
1724          */
1725         Xil_AssertVoid(InstancePtr != NULL);
1726         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1727
1728         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1729                                                         XAPM_CTL_OFFSET);
1730         if (Param == XAPM_LATENCY_FIRSTWR) {
1731                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1732                   XAPM_CTL_OFFSET, RegVal | XAPM_CR_WRLATENCY_END_MASK);
1733         }
1734         else {
1735                 XAxiPmon_WriteReg((InstancePtr)->Config.BaseAddress,
1736                         XAPM_CTL_OFFSET,
1737                         XAxiPmon_ReadReg((InstancePtr)->Config.BaseAddress,
1738                         XAPM_CTL_OFFSET) & ~(XAPM_CR_WRLATENCY_END_MASK));
1739         }
1740 }
1741
1742 /*****************************************************************************/
1743 /**
1744 *
1745 * This function sets Latency Start point to calculate read latency.
1746 *
1747 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1748 * @param        Param is XAPM_LATENCY_ADDR_ISSUE or XAPM_LATENCY_ADDR_ACCEPT
1749 *               in xaxipmon.h.
1750 *
1751 * @return       None
1752 *
1753 * @note         Param can be 0 - XAPM_LATENCY_ADDR_ISSUE
1754 *               or 1 - XAPM_LATENCY_ADDR_ACCEPT
1755 *
1756 *******************************************************************************/
1757 void XAxiPmon_SetRdLatencyStart(XAxiPmon *InstancePtr, u8 Param)
1758 {
1759         u32 RegVal;
1760
1761         /*
1762          * Assert the arguments.
1763          */
1764         Xil_AssertVoid(InstancePtr != NULL);
1765         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1766
1767         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1768                                                         XAPM_CTL_OFFSET);
1769         if (Param == XAPM_LATENCY_ADDR_ACCEPT) {
1770                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1771                   XAPM_CTL_OFFSET, RegVal | XAPM_CR_RDLATENCY_START_MASK);
1772         }
1773         else {
1774                 XAxiPmon_WriteReg((InstancePtr)->Config.BaseAddress,
1775                         XAPM_CTL_OFFSET,
1776                         XAxiPmon_ReadReg((InstancePtr)->Config.BaseAddress,
1777                         XAPM_CTL_OFFSET) & ~(XAPM_CR_RDLATENCY_START_MASK));
1778         }
1779 }
1780
1781 /*****************************************************************************/
1782 /**
1783 *
1784 * This function sets Latency End point to calculate read latency.
1785 *
1786 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1787 * @param        Param is XAPM_LATENCY_LASTRD or XAPM_LATENCY_FIRSTRD
1788 *               in xaxipmon.h.
1789 *
1790 * @return       None
1791 *
1792 * @note         Param can be 0 - XAPM_LATENCY_LASTRD
1793 *               or 1 - XAPM_LATENCY_FIRSTRD
1794 *
1795 *******************************************************************************/
1796 void XAxiPmon_SetRdLatencyEnd(XAxiPmon *InstancePtr, u8 Param)
1797 {
1798         u32 RegVal;
1799
1800         /*
1801          * Assert the arguments.
1802          */
1803         Xil_AssertVoid(InstancePtr != NULL);
1804         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1805
1806         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1807                                                         XAPM_CTL_OFFSET);
1808         if (Param == XAPM_LATENCY_FIRSTRD) {
1809                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1810                   XAPM_CTL_OFFSET, RegVal | XAPM_CR_RDLATENCY_END_MASK);
1811         }
1812         else {
1813                 XAxiPmon_WriteReg((InstancePtr)->Config.BaseAddress,
1814                         XAPM_CTL_OFFSET,
1815                         XAxiPmon_ReadReg((InstancePtr)->Config.BaseAddress,
1816                         XAPM_CTL_OFFSET) & ~(XAPM_CR_RDLATENCY_END_MASK));
1817         }
1818 }
1819
1820 /*****************************************************************************/
1821 /**
1822 *
1823 * This function returns Write Latency Start point.
1824 *
1825 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1826 *
1827 * @return       Returns 0 - XAPM_LATENCY_ADDR_ISSUE or
1828 *                       1 - XAPM_LATENCY_ADDR_ACCEPT
1829 *
1830 * @note         None
1831 *
1832 *******************************************************************************/
1833 u8 XAxiPmon_GetWrLatencyStart(XAxiPmon *InstancePtr)
1834 {
1835         u8 RegVal;
1836
1837         /*
1838          * Assert the arguments.
1839          */
1840         Xil_AssertNonvoid(InstancePtr != NULL);
1841         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1842
1843         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1844                                                         XAPM_CTL_OFFSET);
1845         RegVal = RegVal & XAPM_CR_WRLATENCY_START_MASK;
1846         if (RegVal != XAPM_LATENCY_ADDR_ISSUE) {
1847                 return XAPM_LATENCY_ADDR_ACCEPT;
1848         }
1849         else {
1850                 return XAPM_LATENCY_ADDR_ISSUE;
1851         }
1852 }
1853
1854 /*****************************************************************************/
1855 /**
1856 *
1857 * This function returns Write Latency End point.
1858 *
1859 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1860 *
1861 * @return       Returns 0 - XAPM_LATENCY_LASTWR or
1862 *                       1 - XAPM_LATENCY_FIRSTWR.
1863 *
1864 * @note         None
1865 *
1866 *******************************************************************************/
1867 u8 XAxiPmon_GetWrLatencyEnd(XAxiPmon *InstancePtr)
1868 {
1869         u8 RegVal;
1870
1871         /*
1872          * Assert the arguments.
1873          */
1874         Xil_AssertNonvoid(InstancePtr != NULL);
1875         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1876
1877         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1878                                                         XAPM_CTL_OFFSET);
1879         RegVal = RegVal & XAPM_CR_WRLATENCY_END_MASK;
1880         if (RegVal != XAPM_LATENCY_LASTWR) {
1881                 return XAPM_LATENCY_FIRSTWR;
1882         }
1883         else {
1884                 return XAPM_LATENCY_LASTWR;
1885         }
1886 }
1887
1888 /*****************************************************************************/
1889 /**
1890 *
1891 * This function returns read Latency Start point.
1892 *
1893 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1894 *
1895 * @return       Returns 0 - XAPM_LATENCY_ADDR_ISSUE or
1896 *                       1 - XAPM_LATENCY_ADDR_ACCEPT
1897 *
1898 * @note         None
1899 *
1900 *******************************************************************************/
1901 u8 XAxiPmon_GetRdLatencyStart(XAxiPmon *InstancePtr)
1902 {
1903         u8 RegVal;
1904
1905         /*
1906          * Assert the arguments.
1907          */
1908         Xil_AssertNonvoid(InstancePtr != NULL);
1909         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1910
1911         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1912                                                         XAPM_CTL_OFFSET);
1913         RegVal = RegVal & XAPM_CR_RDLATENCY_START_MASK;
1914
1915         if (RegVal != XAPM_LATENCY_ADDR_ISSUE) {
1916                 return  XAPM_LATENCY_ADDR_ACCEPT;
1917         }
1918         else {
1919                 return XAPM_LATENCY_ADDR_ISSUE;
1920         }
1921 }
1922
1923 /*****************************************************************************/
1924 /**
1925 *
1926 * This function returns Read Latency End point.
1927 *
1928 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1929 *
1930 * @return       Returns 0 - XAPM_LATENCY_LASTRD or
1931 *                       1 - XAPM_LATENCY_FIRSTRD.
1932 *
1933 * @note         None
1934 *
1935 *******************************************************************************/
1936 u8 XAxiPmon_GetRdLatencyEnd(XAxiPmon *InstancePtr)
1937 {
1938         u8 RegVal;
1939
1940         /*
1941          * Assert the arguments.
1942          */
1943         Xil_AssertNonvoid(InstancePtr != NULL);
1944         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1945
1946         RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1947                                                         XAPM_CTL_OFFSET);
1948         RegVal = RegVal & XAPM_CR_RDLATENCY_END_MASK;
1949         if (RegVal != XAPM_LATENCY_LASTRD) {
1950                 return XAPM_LATENCY_FIRSTRD;
1951         }
1952         else {
1953                 return XAPM_LATENCY_LASTRD;
1954         }
1955
1956 }
1957
1958 /****************************************************************************/
1959 /**
1960 *
1961 * This function sets Write ID Mask in ID Mask register.
1962 *
1963 * @param        InstancePtr is a pointer to the XAxiPmon instance.
1964 * @param        WrMask is the Write ID mask to be written in ID register.
1965 *
1966 * @return       None.
1967 *
1968 * @note
1969 *                       If ID masking for write is of 32 bits(for Zynq MP APM) width then
1970 *                       WrMask is written to XAPM_IDMASK_OFFSET or if it is 16 bit width
1971 *                       then lower 16 bits of WrMask are written to XAPM_IDMASK_OFFSET.
1972 *
1973 *****************************************************************************/
1974 void XAxiPmon_SetWriteIdMask(XAxiPmon *InstancePtr, u32 WrMask)
1975 {
1976         u32 RegVal;
1977         /*
1978          * Assert the arguments.
1979          */
1980         Xil_AssertVoid(InstancePtr != NULL);
1981         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1982
1983         if (InstancePtr->Config.Is32BitFiltering == 0)
1984         {
1985                 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1986                                                         XAPM_IDMASK_OFFSET);
1987                 RegVal = RegVal & ~(XAPM_MASKID_WID_MASK);
1988                 RegVal = RegVal | WrMask;
1989                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1990                                                         XAPM_IDMASK_OFFSET, RegVal);
1991         } else {
1992                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1993                                                         XAPM_IDMASK_OFFSET, WrMask);
1994         }
1995 }
1996
1997 /****************************************************************************/
1998 /**
1999 *
2000 * This function sets Read ID Mask in ID Mask register.
2001 *
2002 * @param        InstancePtr is a pointer to the XAxiPmon instance.
2003 * @param        RdMask is the Read ID mask to be written in ID Mask register.
2004 *
2005 * @return       None.
2006 *
2007 * @note
2008 *                       If ID masking for read is of 32 bits(for Zynq MP APM) width then
2009 *                       RdMask is written to XAPM_RIDMASK_OFFSET or if it is 16 bit width
2010 *                       then lower 16 bits of RdMask are written to XAPM_IDMASK_OFFSET.
2011 *
2012 *****************************************************************************/
2013 void XAxiPmon_SetReadIdMask(XAxiPmon *InstancePtr, u32 RdMask)
2014 {
2015         u32 RegVal;
2016         /*
2017          * Assert the arguments.
2018          */
2019         Xil_AssertVoid(InstancePtr != NULL);
2020         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
2021
2022         if (InstancePtr->Config.Is32BitFiltering == 0)
2023         {
2024                 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
2025                                                         XAPM_IDMASK_OFFSET);
2026                 RegVal = RegVal & ~(XAPM_MASKID_RID_MASK);
2027                 RegVal = RegVal | (RdMask << 16);
2028                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
2029                                         XAPM_IDMASK_OFFSET, RegVal);
2030         } else {
2031                 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
2032                                         XAPM_RIDMASK_OFFSET, RdMask);
2033         }
2034 }
2035
2036 /****************************************************************************/
2037 /**
2038 *
2039 * This function returns Write ID Mask in ID Mask register.
2040 *
2041 * @param        InstancePtr is a pointer to the XAxiPmon instance.
2042 *
2043 * @return       WrMask is the required Write ID Mask in ID Mask register.
2044 *
2045 * @note
2046 *                       If ID masking for write is of 32 bits(for Zynq MP APM) width then
2047 *                       32 bit XAPM_IDMASK_OFFSET contents are returned or if it is 16 bit
2048 *                       width then lower 16 bits of XAPM_IDMASK_OFFSET register
2049 *                       are returned.
2050 *
2051 *****************************************************************************/
2052 u32 XAxiPmon_GetWriteIdMask(XAxiPmon *InstancePtr)
2053 {
2054
2055         u32 WrMask;
2056         u32 RegVal;
2057         /*
2058          * Assert the arguments.
2059          */
2060         Xil_AssertNonvoid(InstancePtr != NULL);
2061         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
2062
2063         if (InstancePtr->Config.Is32BitFiltering == 0)
2064         {
2065                 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
2066                                                         XAPM_IDMASK_OFFSET);
2067                 WrMask = RegVal & XAPM_MASKID_WID_MASK;
2068         } else {
2069                 WrMask = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
2070                                                         XAPM_IDMASK_OFFSET);
2071         }
2072
2073         return WrMask;
2074 }
2075
2076 /****************************************************************************/
2077 /**
2078 *
2079 * This function returns Read ID Mask in ID Mask register.
2080 *
2081 * @param        InstancePtr is a pointer to the XAxiPmon instance.
2082 *
2083 * @return       RdMask is the required Read ID Mask in ID Mask register.
2084 *
2085 * @note
2086 *                       If ID masking for read is of 32 bits(for Zynq MP APM) width then
2087 *                       32 bit XAPM_RIDMASK_OFFSET contents are returned or if it is 16 bit
2088 *                       width then higher 16 bits of XAPM_IDMASK_OFFSET register
2089 *                       are returned.
2090 *
2091 *****************************************************************************/
2092 u32 XAxiPmon_GetReadIdMask(XAxiPmon *InstancePtr)
2093 {
2094
2095         u32 RdMask;
2096         u32 RegVal;
2097         /*
2098          * Assert the arguments.
2099          */
2100         Xil_AssertNonvoid(InstancePtr != NULL);
2101         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
2102
2103         if (InstancePtr->Config.Is32BitFiltering == 0)
2104         {
2105                 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
2106                                                         XAPM_IDMASK_OFFSET);
2107                 RegVal = RegVal & XAPM_MASKID_RID_MASK;
2108                 RdMask = RegVal >> 16;
2109         } else {
2110                 RdMask = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
2111                                                                 XAPM_RIDMASK_OFFSET);
2112         }
2113
2114         return RdMask;
2115 }