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