1 /******************************************************************************
3 * Copyright (C) 2012 - 2015 Xilinx, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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
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.
31 ******************************************************************************/
32 /****************************************************************************/
37 * This file contains the driver API functions that can be used to access
38 * the AXI Performance Monitor device.
40 * Refer to the xaxipmon.h header file for more information about this driver.
46 * MODIFICATION HISTORY:
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
57 * Added XAxiPmon_StartEventLog and XAxiPmon_StopEventLog
59 * Added XAxiPmon_GetMetricName API (CR #683803).
60 * Modified XAxiPmon_SetMetrics and XAxiPmon_GetMetrics
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
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
92 * Modified XAxiPmon_SetSampleInterval and
93 * XAxiPmon_GetSampleInterval to remove higher 32 bit
94 * value of SampleInterval since Sample Interval Register
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.
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
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.
120 *****************************************************************************/
122 /***************************** Include Files ********************************/
124 #include "xaxipmon.h"
126 /************************** Constant Definitions *****************************/
128 /**************************** Type Definitions *******************************/
130 /***************** Macros (Inline Functions) Definitions *********************/
132 /************************** Function Prototypes ******************************/
134 /************************** Variable Definitions *****************************/
136 /*****************************************************************************/
139 * This function initializes a specific XAxiPmon device/instance. This function
140 * must be called prior to using the AXI Performance Monitor device.
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.
151 * - XST_SUCCESS if successful.
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.
157 ******************************************************************************/
158 int XAxiPmon_CfgInitialize(XAxiPmon *InstancePtr, XAxiPmon_Config *ConfigPtr,
162 * Assert the input arguments.
164 Xil_AssertNonvoid(InstancePtr != NULL);
165 Xil_AssertNonvoid(ConfigPtr != NULL);
168 * Set the values read from the device config and the base address.
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 =
192 InstancePtr->Config.Is32BitFiltering = ConfigPtr->Is32BitFiltering;
194 InstancePtr->Config.ScaleFactor = ConfigPtr->ScaleFactor;
196 if ((ConfigPtr->ModeProfile == ConfigPtr->ModeTrace)
197 || ConfigPtr->ModeAdvanced == 1)
199 InstancePtr->Mode = XAPM_MODE_ADVANCED;
200 } else if (ConfigPtr->ModeTrace == 1) {
201 InstancePtr->Mode = XAPM_MODE_TRACE;
203 InstancePtr->Mode = XAPM_MODE_PROFILE;
207 * Indicate the instance is now ready to use, initialized without error.
209 InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
212 * Reset the Counters and FIFO based on Modes.
215 /* Advanced and Profile */
216 if(InstancePtr->Mode == XAPM_MODE_ADVANCED ||
217 InstancePtr->Mode == XAPM_MODE_PROFILE)
219 XAxiPmon_ResetMetricCounter(InstancePtr);
222 if(InstancePtr->Mode == XAPM_MODE_ADVANCED)
224 XAxiPmon_ResetGlobalClkCounter(InstancePtr);
226 /* Advanced and Trace */
227 if(InstancePtr->Mode == XAPM_MODE_ADVANCED ||
228 InstancePtr->Mode == XAPM_MODE_TRACE)
230 XAxiPmon_ResetFifo(InstancePtr);
235 /*****************************************************************************/
238 * This function resets all Metric Counters and Sampled Metric Counters of
239 * AXI Performance Monitor.
241 * @param InstancePtr is a pointer to the XAxiPmon instance.
243 * @return XST_SUCCESS
248 ******************************************************************************/
249 int XAxiPmon_ResetMetricCounter(XAxiPmon *InstancePtr)
255 * Assert the arguments.
257 Xil_AssertNonvoid(InstancePtr != NULL);
258 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
259 Xil_AssertNonvoid(InstancePtr->Mode != XAPM_MODE_TRACE);
262 * Write the reset value to the Control register to reset
265 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
267 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
268 (RegValue | XAPM_CR_MCNTR_RESET_MASK));
272 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
273 (RegValue & ~(XAPM_CR_MCNTR_RESET_MASK)));
278 /*****************************************************************************/
281 * This function resets Global Clock Counter of AXI Performance Monitor
283 * @param InstancePtr is a pointer to the XAxiPmon instance.
289 ******************************************************************************/
290 void XAxiPmon_ResetGlobalClkCounter(XAxiPmon *InstancePtr)
296 * Assert the arguments.
298 Xil_AssertVoid(InstancePtr != NULL);
299 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
300 Xil_AssertVoid(InstancePtr->Mode == XAPM_MODE_ADVANCED);
303 * Write the reset value to the Control register to reset
304 * Global Clock Counter
306 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
308 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
309 (RegValue | XAPM_CR_GCC_RESET_MASK));
314 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
315 (RegValue & ~(XAPM_CR_GCC_RESET_MASK)));
319 /*****************************************************************************/
322 * This function resets Streaming FIFO of AXI Performance Monitor
324 * @param InstancePtr is a pointer to the XAxiPmon instance.
326 * @return XST_SUCCESS
330 ******************************************************************************/
331 int XAxiPmon_ResetFifo(XAxiPmon *InstancePtr)
337 * Assert the arguments.
339 Xil_AssertNonvoid(InstancePtr != NULL);
340 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
341 Xil_AssertNonvoid(InstancePtr->Mode != XAPM_MODE_PROFILE);
343 /* Check Event Logging is enabled in Hardware */
344 if((InstancePtr->Config.IsEventLog == 0) &&
345 (InstancePtr->Mode == XAPM_MODE_ADVANCED))
347 /*Event logging not enabled in Hardware*/
351 * Write the reset value to the Control register to reset
354 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
356 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
357 (RegValue | XAPM_CR_FIFO_RESET_MASK));
361 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
362 (RegValue & ~(XAPM_CR_FIFO_RESET_MASK)));
368 /****************************************************************************/
371 * This function sets Ranges for Incrementers depending on parameters passed.
373 * @param InstancePtr is a pointer to the XAxiPmon instance.
374 * @param IncrementerNum specifies the Incrementer for which Ranges
376 * @param RangeUpper specifies the Upper limit in 32 bit Register
377 * @param RangeLower specifies the Lower limit in 32 bit Register
383 *****************************************************************************/
384 void XAxiPmon_SetIncrementerRange(XAxiPmon *InstancePtr, u8 IncrementerNum,
385 u16 RangeUpper, u16 RangeLower)
391 * Assert the arguments.
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);
399 * Write to the specified Range register
401 RegValue = RangeUpper << 16;
402 RegValue |= RangeLower;
403 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
404 (XAPM_RANGE0_OFFSET + (IncrementerNum * 16)),
408 /****************************************************************************/
411 * This function returns the Ranges of Incrementers Registers.
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.
425 *****************************************************************************/
426 void XAxiPmon_GetIncrementerRange(XAxiPmon *InstancePtr, u8 IncrementerNum,
427 u16 *RangeUpper, u16 *RangeLower)
432 * Assert the arguments.
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);
439 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
440 (XAPM_RANGE0_OFFSET + (IncrementerNum * 16)));
442 *RangeLower = RegValue & 0xFFFF;
443 *RangeUpper = (RegValue >> 16) & 0xFFFF;
446 /****************************************************************************/
449 * This function sets the Sample Interval Register
451 * @param InstancePtr is a pointer to the XAxiPmon instance.
452 * @param SampleInterval is the Sample Interval value to be set
458 *****************************************************************************/
459 void XAxiPmon_SetSampleInterval(XAxiPmon *InstancePtr, u32 SampleInterval)
463 * Assert the arguments.
465 Xil_AssertVoid(InstancePtr != NULL);
466 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
467 Xil_AssertVoid(InstancePtr->Mode != XAPM_MODE_TRACE);
470 * Set Sample Interval Lower
472 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
473 XAPM_SI_LOW_OFFSET, SampleInterval);
477 /****************************************************************************/
480 * This function returns the contents of Sample Interval Register
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.
490 ******************************************************************************/
491 void XAxiPmon_GetSampleInterval(XAxiPmon *InstancePtr, u32 *SampleInterval)
494 * Assert the arguments.
496 Xil_AssertVoid(InstancePtr != NULL);
497 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
498 Xil_AssertVoid(InstancePtr->Mode != XAPM_MODE_TRACE);
501 * Set Sample Interval Lower
503 *SampleInterval = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
508 /****************************************************************************/
511 * This function sets Metrics for specified Counter in the corresponding
512 * Metric Selector Register.
514 * @param InstancePtr is a pointer to the XAxiPmon instance.
515 * @param Slot is the slot ID for which specified counter has to
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.
522 * @return XST_SUCCESS if Success
523 * XST_FAILURE if Failure
527 *****************************************************************************/
528 int XAxiPmon_SetMetrics(XAxiPmon *InstancePtr, u8 Slot, u8 Metrics,
534 * Assert the arguments.
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);
544 /* Find Mask value to force zero in counternum byte range */
545 if (CounterNum == 0 || CounterNum == 4 || CounterNum == 8) {
548 else if (CounterNum == 1 || CounterNum == 5 || CounterNum == 9) {
551 else if (CounterNum == 2 || CounterNum == 6) {
558 if(CounterNum <= 3) {
559 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
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);
568 else if((CounterNum >= 4) && (CounterNum <= 7)) {
569 CounterNum = CounterNum - 4;
570 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
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);
580 CounterNum = CounterNum - 8;
581 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
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);
593 /*****************************************************************************/
596 * This function returns Metrics in the specified Counter from the corresponding
597 * Metric Selector Register.
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
611 *****************************************************************************/
612 int XAxiPmon_GetMetrics(XAxiPmon *InstancePtr, u8 CounterNum, u8 *Metrics,
617 * Assert the arguments.
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);
624 if(CounterNum <= 3) {
625 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
627 *Metrics = (RegValue >> (CounterNum * 8)) & 0x1F;
628 *Slot = (RegValue >> (CounterNum * 8 + 5)) & 0x7;
631 else if((CounterNum >= 4) && (CounterNum <= 7)) {
632 CounterNum = CounterNum - 4;
633 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
635 *Metrics = (RegValue >> (CounterNum * 8)) & 0x1F;
636 *Slot = (RegValue >> (CounterNum * 8 + 5)) & 0x7;
639 CounterNum = CounterNum - 8;
640 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
642 *Metrics = (RegValue >> (CounterNum * 8)) & 0x1F;
643 *Slot = (RegValue >> (CounterNum * 8 + 5)) & 0x7;
648 /****************************************************************************/
651 * This function returns the contents of the Global Clock Counter Register.
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
663 *****************************************************************************/
664 void XAxiPmon_GetGlobalClkCounter(XAxiPmon *InstancePtr,u32 *CntHighValue,
668 * Assert the arguments.
670 Xil_AssertVoid(InstancePtr != NULL);
671 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
672 Xil_AssertVoid(InstancePtr->Mode == XAPM_MODE_ADVANCED);
678 * If Counter width is 64 bit then Counter Value has to be
679 * filled at CntHighValue address also.
681 if(InstancePtr->Config.GlobalClkCounterWidth == 64) {
683 /* Bits[63:32] exists at XAPM_GCC_HIGH_OFFSET */
684 *CntHighValue = XAxiPmon_ReadReg(InstancePtr->
685 Config.BaseAddress, XAPM_GCC_HIGH_OFFSET);
687 /* Bits[31:0] exists at XAPM_GCC_LOW_OFFSET */
688 *CntLowValue = XAxiPmon_ReadReg(InstancePtr->
689 Config.BaseAddress, XAPM_GCC_LOW_OFFSET);
692 /****************************************************************************/
695 * This function returns the contents of the Metric Counter Register.
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.
706 *****************************************************************************/
707 u32 XAxiPmon_GetMetricCounter(XAxiPmon *InstancePtr, u32 CounterNum)
713 * Assert the arguments.
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);
720 if (CounterNum < 10 ) {
721 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
722 (XAPM_MC0_OFFSET + (CounterNum * 16)));
724 else if (CounterNum >= 10 && CounterNum < 12) {
725 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
726 (XAPM_MC10_OFFSET + ((CounterNum - 10) * 16)));
728 else if (CounterNum >= 12 && CounterNum < 24) {
729 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
730 (XAPM_MC12_OFFSET + ((CounterNum - 12) * 16)));
732 else if (CounterNum >= 24 && CounterNum < 36) {
733 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
734 (XAPM_MC24_OFFSET + ((CounterNum - 24) * 16)));
737 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
738 (XAPM_MC36_OFFSET + ((CounterNum - 36) * 16)));
743 /****************************************************************************/
746 * This function returns the contents of the Sampled Metric Counter Register.
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).
754 * @return RegValue is the content of specified Sampled Metric Counter.
758 *****************************************************************************/
759 u32 XAxiPmon_GetSampledMetricCounter(XAxiPmon *InstancePtr, u32 CounterNum)
764 * Assert the arguments.
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)));
774 if (CounterNum < 10 ) {
775 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
776 (XAPM_SMC0_OFFSET + (CounterNum * 16)));
778 else if (CounterNum >= 10 && CounterNum < 12) {
779 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
780 (XAPM_SMC10_OFFSET + ((CounterNum - 10) * 16)));
782 else if (CounterNum >= 12 && CounterNum < 24) {
783 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
784 (XAPM_SMC12_OFFSET + ((CounterNum - 12) * 16)));
786 else if (CounterNum >= 24 && CounterNum < 36) {
787 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
788 (XAPM_SMC24_OFFSET + ((CounterNum - 24) * 16)));
791 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
792 (XAPM_SMC36_OFFSET + ((CounterNum - 36) * 16)));
797 /****************************************************************************/
800 * This function returns the contents of the Incrementer Register.
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
809 * @return RegValue is content of specified Metric Incrementer register.
813 *****************************************************************************/
814 u32 XAxiPmon_GetIncrementer(XAxiPmon *InstancePtr, u32 IncrementerNum)
819 * Assert the arguments.
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);
827 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
828 (XAPM_INC0_OFFSET + (IncrementerNum * 16)));
833 /****************************************************************************/
836 * This function returns the contents of the Sampled Incrementer Register.
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.
849 *****************************************************************************/
850 u32 XAxiPmon_GetSampledIncrementer(XAxiPmon *InstancePtr, u32 IncrementerNum)
855 * Assert the arguments.
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);
864 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
865 (XAPM_SINC0_OFFSET + (IncrementerNum * 16)));
869 /****************************************************************************/
872 * This function sets Software-written Data Register.
874 * @param InstancePtr is a pointer to the XAxiPmon instance.
875 * @param SwData is the Software written Data.
881 *****************************************************************************/
882 void XAxiPmon_SetSwDataReg(XAxiPmon *InstancePtr, u32 SwData)
885 * Assert the arguments.
887 Xil_AssertVoid(InstancePtr != NULL);
888 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
891 * Set Software-written Data Register
893 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_SWD_OFFSET,
897 /****************************************************************************/
900 * This function returns contents of Software-written Data Register.
902 * @param InstancePtr is a pointer to the XAxiPmon instance.
908 *****************************************************************************/
909 u32 XAxiPmon_GetSwDataReg(XAxiPmon *InstancePtr)
914 * Assert the arguments.
916 Xil_AssertNonvoid(InstancePtr != NULL);
917 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
920 * Set Metric Selector Register
922 SwData = (u32)XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
927 /*****************************************************************************/
930 * This function enables the following in the AXI Performance Monitor:
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.
940 * @return XST_SUCCESS
944 ******************************************************************************/
945 int XAxiPmon_StartEventLog(XAxiPmon *InstancePtr, u32 FlagEnables)
950 * Assert the arguments.
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)));
958 /* Read current register value */
959 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
961 /* Flag Enable register is present only in Advanced Mode */
962 if(InstancePtr->Mode == XAPM_MODE_ADVANCED)
964 /* Now write to flag enables register */
965 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
966 XAPM_FEC_OFFSET, FlagEnables);
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);
977 /*****************************************************************************/
980 * This function disables the following in the AXI Performance Monitor:
983 * @param InstancePtr is a pointer to the XAxiPmon instance.
985 * @return XST_SUCCESS
989 ******************************************************************************/
990 int XAxiPmon_StopEventLog(XAxiPmon *InstancePtr)
995 * Assert the arguments.
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)));
1003 /* Read current register value */
1004 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1007 /* Write the new value to the Control register to disable
1009 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1010 RegValue & ~XAPM_CR_EVENTLOG_ENABLE_MASK);
1015 /*****************************************************************************/
1018 * This function enables the following in the AXI Performance Monitor:
1019 * - Global clock counter
1020 * - All metric counters
1021 * - All sampled metric counters
1023 * @param InstancePtr is a pointer to the XAxiPmon instance.
1024 * SampleInterval is the sample interval for the sampled metric
1027 * @return XST_SUCCESS
1030 ******************************************************************************/
1031 int XAxiPmon_StartCounters(XAxiPmon *InstancePtr, u32 SampleInterval)
1036 * Assert the arguments.
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)));
1044 /* Read current register value */
1045 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1047 /* Globlal Clock Counter is present in Advanced mode only */
1048 if(InstancePtr->Mode == XAPM_MODE_ADVANCED)
1050 RegValue = RegValue | XAPM_CR_GCC_ENABLE_MASK;
1054 * Write the new value to the Control register to enable
1055 * global clock counter and metric counters
1057 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1058 RegValue | XAPM_CR_MCNTR_ENABLE_MASK);
1060 /* Set, enable, and load sampled counters */
1061 XAxiPmon_SetSampleInterval(InstancePtr, SampleInterval);
1062 XAxiPmon_LoadSampleIntervalCounter(InstancePtr);
1063 XAxiPmon_EnableSampleIntervalCounter(InstancePtr);
1068 /*****************************************************************************/
1071 * This function disables the following in the AXI Performance Monitor:
1072 * - Global clock counter
1073 * - All metric counters
1075 * @param InstancePtr is a pointer to the XAxiPmon instance.
1077 * @return XST_SUCCESS
1081 ******************************************************************************/
1082 int XAxiPmon_StopCounters(XAxiPmon *InstancePtr)
1087 * Assert the arguments.
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)));
1095 /* Read current register value */
1096 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1098 /* Globlal Clock Counter is present in Advanced mode only */
1099 if(InstancePtr->Mode == XAPM_MODE_ADVANCED)
1101 RegValue = RegValue & ~XAPM_CR_GCC_ENABLE_MASK;
1105 * Write the new value to the Control register to disable
1106 * global clock counter and metric counters
1108 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1109 RegValue & ~XAPM_CR_MCNTR_ENABLE_MASK);
1114 /*****************************************************************************/
1117 * This function enables Metric Counters.
1119 * @param InstancePtr is a pointer to the XAxiPmon instance.
1125 *******************************************************************************/
1126 void XAxiPmon_EnableMetricsCounter(XAxiPmon *InstancePtr)
1131 * Assert the arguments.
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)));
1139 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1141 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1142 RegVal | XAPM_CR_MCNTR_ENABLE_MASK);
1144 /****************************************************************************/
1147 * This function disables the Metric Counters.
1149 * @param InstancePtr is a pointer to the XAxiPmon instance.
1155 *****************************************************************************/
1156 void XAxiPmon_DisableMetricsCounter(XAxiPmon *InstancePtr)
1161 * Assert the arguments.
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)));
1169 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1172 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1173 RegVal & ~(XAPM_CR_MCNTR_ENABLE_MASK));
1176 /****************************************************************************/
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
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
1195 *****************************************************************************/
1196 void XAxiPmon_SetLogEnableRanges(XAxiPmon *InstancePtr, u32 CounterNum,
1197 u16 RangeUpper, u16 RangeLower)
1201 * Assert the arguments.
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));
1211 * Write the specified Ranges to corresponding Metric Counter Log
1214 RegValue = RangeUpper << 16;
1215 RegValue |= RangeLower;
1216 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1217 (XAPM_MC0LOGEN_OFFSET + (CounterNum * 16)), RegValue);
1221 /****************************************************************************/
1224 * This function returns the Ranges of specified Metric Counter Log
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).
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.
1243 *****************************************************************************/
1244 void XAxiPmon_GetLogEnableRanges(XAxiPmon *InstancePtr, u32 CounterNum,
1245 u16 *RangeUpper, u16 *RangeLower)
1249 * Assert the arguments.
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));
1258 RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1259 (XAPM_MC0LOGEN_OFFSET + (CounterNum * 16)));
1261 *RangeLower = RegValue & 0xFFFF;
1262 *RangeUpper = (RegValue >> 16) & 0xFFFF;
1265 /*****************************************************************************/
1268 * This function enables Event Logging.
1270 * @param InstancePtr is a pointer to the XAxiPmon instance.
1276 *******************************************************************************/
1277 void XAxiPmon_EnableEventLog(XAxiPmon *InstancePtr)
1282 * Assert the arguments.
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)));
1290 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1292 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1293 RegVal | XAPM_CR_EVENTLOG_ENABLE_MASK);
1296 /*****************************************************************************/
1299 * This function enables External trigger pulse so that Metric Counters can be
1300 * started on external trigger pulse for a Slot.
1302 * @param InstancePtr is a pointer to the XAxiPmon instance.
1308 *******************************************************************************/
1309 void XAxiPmon_EnableMetricCounterTrigger(XAxiPmon *InstancePtr)
1314 * Assert the arguments.
1316 Xil_AssertVoid(InstancePtr != NULL);
1317 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1318 Xil_AssertVoid(InstancePtr->Mode != XAPM_MODE_TRACE);
1320 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1322 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1323 RegVal | XAPM_CR_MCNTR_EXTTRIGGER_MASK);
1326 /****************************************************************************/
1329 * This function disables the External trigger pulse used to start Metric
1330 * Counters on external trigger pulse for a Slot.
1332 * @param InstancePtr is a pointer to the XAxiPmon instance.
1338 *****************************************************************************/
1339 void XAxiPmon_DisableMetricCounterTrigger(XAxiPmon *InstancePtr)
1344 * Assert the arguments.
1346 Xil_AssertVoid(InstancePtr != NULL);
1347 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1348 Xil_AssertVoid(InstancePtr->Mode != XAPM_MODE_TRACE);
1350 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1353 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1354 RegVal & ~(XAPM_CR_MCNTR_EXTTRIGGER_MASK));
1357 /*****************************************************************************/
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.
1363 * @param InstancePtr is a pointer to the XAxiPmon instance.
1369 *******************************************************************************/
1370 void XAxiPmon_EnableEventLogTrigger(XAxiPmon *InstancePtr)
1375 * Assert the arguments.
1377 Xil_AssertVoid(InstancePtr != NULL);
1378 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1379 Xil_AssertVoid(InstancePtr->Mode != XAPM_MODE_PROFILE);
1381 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1383 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1384 RegVal | XAPM_CR_EVTLOG_EXTTRIGGER_MASK);
1387 /****************************************************************************/
1390 * This function disables the External trigger pulse used to start Event
1391 * Log on external trigger pulse for a Slot.
1393 * @param InstancePtr is a pointer to the XAxiPmon instance.
1399 *****************************************************************************/
1400 void XAxiPmon_DisableEventLogTrigger(XAxiPmon *InstancePtr)
1405 * Assert the arguments.
1407 Xil_AssertVoid(InstancePtr != NULL);
1408 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1409 Xil_AssertVoid(InstancePtr->Mode != XAPM_MODE_PROFILE);
1411 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1414 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress, XAPM_CTL_OFFSET,
1415 RegVal & ~(XAPM_CR_EVTLOG_EXTTRIGGER_MASK));
1418 /****************************************************************************/
1421 * This function returns a name for a given Metric.
1423 * @param Metrics is one of the Metric Sets. User has to use
1424 * XAPM_METRIC_SET_* macros in xaxipmon.h for this parameter
1426 * @return const char *
1430 *****************************************************************************/
1431 const char * XAxiPmon_GetMetricName(u8 Metrics)
1433 if (Metrics == XAPM_METRIC_SET_0 ){
1434 return "Write Transaction Count";
1436 if (Metrics == XAPM_METRIC_SET_1 ){
1437 return "Read Transaction Count";
1439 if (Metrics == XAPM_METRIC_SET_2 ){
1440 return "Write Byte Count";
1442 if (Metrics == XAPM_METRIC_SET_3 ){
1443 return "Read Byte Count";
1445 if (Metrics == XAPM_METRIC_SET_4 ){
1446 return "Write Beat Count";
1448 if (Metrics == XAPM_METRIC_SET_5 ){
1449 return "Total Read Latency";
1451 if (Metrics == XAPM_METRIC_SET_6 ){
1452 return "Total Write Latency";
1454 if (Metrics == XAPM_METRIC_SET_7 ){
1455 return "Slv_Wr_Idle_Cnt";
1457 if (Metrics == XAPM_METRIC_SET_8 ){
1458 return "Mst_Rd_Idle_Cnt";
1460 if (Metrics == XAPM_METRIC_SET_9 ){
1461 return "Num_BValids";
1463 if (Metrics == XAPM_METRIC_SET_10){
1464 return "Num_WLasts";
1466 if (Metrics == XAPM_METRIC_SET_11){
1467 return "Num_RLasts";
1469 if (Metrics == XAPM_METRIC_SET_12){
1470 return "Minimum Write Latency";
1472 if (Metrics == XAPM_METRIC_SET_13){
1473 return "Maximum Write Latency";
1475 if (Metrics == XAPM_METRIC_SET_14){
1476 return "Minimum Read Latency";
1478 if (Metrics == XAPM_METRIC_SET_15){
1479 return "Maximum Read Latency";
1481 if (Metrics == XAPM_METRIC_SET_16){
1482 return "Transfer Cycle Count";
1484 if (Metrics == XAPM_METRIC_SET_17){
1485 return "Packet Count";
1487 if (Metrics == XAPM_METRIC_SET_18){
1488 return "Data Byte Count";
1490 if (Metrics == XAPM_METRIC_SET_19){
1491 return "Position Byte Count";
1493 if (Metrics == XAPM_METRIC_SET_20){
1494 return "Null Byte Count";
1496 if (Metrics == XAPM_METRIC_SET_21){
1497 return "Slv_Idle_Cnt";
1499 if (Metrics == XAPM_METRIC_SET_22){
1500 return "Mst_Idle_Cnt";
1502 if (Metrics == XAPM_METRIC_SET_30){
1503 return "External event count";
1505 return "Unsupported";
1508 /****************************************************************************/
1511 * This function sets Write ID in ID register.
1513 * @param InstancePtr is a pointer to the XAxiPmon instance.
1514 * @param WriteId is the Write ID to be written in ID register.
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.
1523 *****************************************************************************/
1524 void XAxiPmon_SetWriteId(XAxiPmon *InstancePtr, u32 WriteId)
1528 * Assert the arguments.
1530 Xil_AssertVoid(InstancePtr != NULL);
1531 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1533 if (InstancePtr->Config.Is32BitFiltering == 0)
1535 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1537 RegVal = RegVal & ~(XAPM_ID_WID_MASK);
1538 RegVal = RegVal | WriteId;
1539 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1540 XAPM_ID_OFFSET, RegVal);
1542 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1543 XAPM_ID_OFFSET, WriteId);
1547 /****************************************************************************/
1550 * This function sets Read ID in ID register.
1552 * @param InstancePtr is a pointer to the XAxiPmon instance.
1553 * @param ReadId is the Read ID to be written in ID register.
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.
1562 *****************************************************************************/
1563 void XAxiPmon_SetReadId(XAxiPmon *InstancePtr, u32 ReadId)
1567 * Assert the arguments.
1569 Xil_AssertVoid(InstancePtr != NULL);
1570 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1572 if (InstancePtr->Config.Is32BitFiltering == 0)
1574 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1576 RegVal = RegVal & ~(XAPM_ID_RID_MASK);
1577 RegVal = RegVal | (ReadId << 16);
1578 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1579 XAPM_ID_OFFSET, RegVal);
1581 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1582 XAPM_RID_OFFSET, ReadId);
1586 /****************************************************************************/
1589 * This function returns Write ID in ID register.
1591 * @param InstancePtr is a pointer to the XAxiPmon instance.
1593 * @return WriteId is the required Write ID in ID register.
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.
1600 *****************************************************************************/
1601 u32 XAxiPmon_GetWriteId(XAxiPmon *InstancePtr)
1607 * Assert the arguments.
1609 Xil_AssertNonvoid(InstancePtr != NULL);
1610 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1612 if (InstancePtr->Config.Is32BitFiltering == 0)
1614 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1616 WriteId = RegVal & XAPM_ID_WID_MASK;
1618 WriteId = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1625 /****************************************************************************/
1628 * This function returns Read ID in ID register.
1630 * @param InstancePtr is a pointer to the XAxiPmon instance.
1632 * @return ReadId is the required Read ID in ID register.
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.
1639 *****************************************************************************/
1640 u32 XAxiPmon_GetReadId(XAxiPmon *InstancePtr)
1646 * Assert the arguments.
1648 Xil_AssertNonvoid(InstancePtr != NULL);
1649 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1651 if (InstancePtr->Config.Is32BitFiltering == 0)
1653 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1655 RegVal = RegVal & XAPM_ID_RID_MASK;
1656 ReadId = RegVal >> 16;
1658 ReadId = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1665 /*****************************************************************************/
1668 * This function sets Latency Start point to calculate write latency.
1670 * @param InstancePtr is a pointer to the XAxiPmon instance.
1671 * @param Param is XAPM_LATENCY_ADDR_ISSUE or XAPM_LATENCY_ADDR_ACCEPT
1675 * @note Param can be 0 - XAPM_LATENCY_ADDR_ISSUE
1676 * or 1 - XAPM_LATENCY_ADDR_ACCEPT
1678 *******************************************************************************/
1679 void XAxiPmon_SetWrLatencyStart(XAxiPmon *InstancePtr, u8 Param)
1684 * Assert the arguments.
1686 Xil_AssertVoid(InstancePtr != NULL);
1687 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1689 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1691 if (Param == XAPM_LATENCY_ADDR_ACCEPT) {
1692 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1693 XAPM_CTL_OFFSET, RegVal | XAPM_CR_WRLATENCY_START_MASK);
1696 XAxiPmon_WriteReg((InstancePtr)->Config.BaseAddress,
1698 XAxiPmon_ReadReg((InstancePtr)->Config.BaseAddress,
1699 XAPM_CTL_OFFSET) & ~(XAPM_CR_WRLATENCY_START_MASK));
1703 /*****************************************************************************/
1706 * This function sets Latency End point to calculate write latency.
1708 * @param InstancePtr is a pointer to the XAxiPmon instance.
1709 * @param Param is XAPM_LATENCY_LASTWR or XAPM_LATENCY_FIRSTWR
1714 * @note Param can be 0 - XAPM_LATENCY_LASTWR
1715 * or 1 - XAPM_LATENCY_FIRSTWR
1717 *******************************************************************************/
1718 void XAxiPmon_SetWrLatencyEnd(XAxiPmon *InstancePtr, u8 Param)
1723 * Assert the arguments.
1725 Xil_AssertVoid(InstancePtr != NULL);
1726 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1728 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1730 if (Param == XAPM_LATENCY_FIRSTWR) {
1731 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1732 XAPM_CTL_OFFSET, RegVal | XAPM_CR_WRLATENCY_END_MASK);
1735 XAxiPmon_WriteReg((InstancePtr)->Config.BaseAddress,
1737 XAxiPmon_ReadReg((InstancePtr)->Config.BaseAddress,
1738 XAPM_CTL_OFFSET) & ~(XAPM_CR_WRLATENCY_END_MASK));
1742 /*****************************************************************************/
1745 * This function sets Latency Start point to calculate read latency.
1747 * @param InstancePtr is a pointer to the XAxiPmon instance.
1748 * @param Param is XAPM_LATENCY_ADDR_ISSUE or XAPM_LATENCY_ADDR_ACCEPT
1753 * @note Param can be 0 - XAPM_LATENCY_ADDR_ISSUE
1754 * or 1 - XAPM_LATENCY_ADDR_ACCEPT
1756 *******************************************************************************/
1757 void XAxiPmon_SetRdLatencyStart(XAxiPmon *InstancePtr, u8 Param)
1762 * Assert the arguments.
1764 Xil_AssertVoid(InstancePtr != NULL);
1765 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1767 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1769 if (Param == XAPM_LATENCY_ADDR_ACCEPT) {
1770 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1771 XAPM_CTL_OFFSET, RegVal | XAPM_CR_RDLATENCY_START_MASK);
1774 XAxiPmon_WriteReg((InstancePtr)->Config.BaseAddress,
1776 XAxiPmon_ReadReg((InstancePtr)->Config.BaseAddress,
1777 XAPM_CTL_OFFSET) & ~(XAPM_CR_RDLATENCY_START_MASK));
1781 /*****************************************************************************/
1784 * This function sets Latency End point to calculate read latency.
1786 * @param InstancePtr is a pointer to the XAxiPmon instance.
1787 * @param Param is XAPM_LATENCY_LASTRD or XAPM_LATENCY_FIRSTRD
1792 * @note Param can be 0 - XAPM_LATENCY_LASTRD
1793 * or 1 - XAPM_LATENCY_FIRSTRD
1795 *******************************************************************************/
1796 void XAxiPmon_SetRdLatencyEnd(XAxiPmon *InstancePtr, u8 Param)
1801 * Assert the arguments.
1803 Xil_AssertVoid(InstancePtr != NULL);
1804 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1806 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1808 if (Param == XAPM_LATENCY_FIRSTRD) {
1809 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1810 XAPM_CTL_OFFSET, RegVal | XAPM_CR_RDLATENCY_END_MASK);
1813 XAxiPmon_WriteReg((InstancePtr)->Config.BaseAddress,
1815 XAxiPmon_ReadReg((InstancePtr)->Config.BaseAddress,
1816 XAPM_CTL_OFFSET) & ~(XAPM_CR_RDLATENCY_END_MASK));
1820 /*****************************************************************************/
1823 * This function returns Write Latency Start point.
1825 * @param InstancePtr is a pointer to the XAxiPmon instance.
1827 * @return Returns 0 - XAPM_LATENCY_ADDR_ISSUE or
1828 * 1 - XAPM_LATENCY_ADDR_ACCEPT
1832 *******************************************************************************/
1833 u8 XAxiPmon_GetWrLatencyStart(XAxiPmon *InstancePtr)
1838 * Assert the arguments.
1840 Xil_AssertNonvoid(InstancePtr != NULL);
1841 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1843 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1845 RegVal = RegVal & XAPM_CR_WRLATENCY_START_MASK;
1846 if (RegVal != XAPM_LATENCY_ADDR_ISSUE) {
1847 return XAPM_LATENCY_ADDR_ACCEPT;
1850 return XAPM_LATENCY_ADDR_ISSUE;
1854 /*****************************************************************************/
1857 * This function returns Write Latency End point.
1859 * @param InstancePtr is a pointer to the XAxiPmon instance.
1861 * @return Returns 0 - XAPM_LATENCY_LASTWR or
1862 * 1 - XAPM_LATENCY_FIRSTWR.
1866 *******************************************************************************/
1867 u8 XAxiPmon_GetWrLatencyEnd(XAxiPmon *InstancePtr)
1872 * Assert the arguments.
1874 Xil_AssertNonvoid(InstancePtr != NULL);
1875 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1877 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1879 RegVal = RegVal & XAPM_CR_WRLATENCY_END_MASK;
1880 if (RegVal != XAPM_LATENCY_LASTWR) {
1881 return XAPM_LATENCY_FIRSTWR;
1884 return XAPM_LATENCY_LASTWR;
1888 /*****************************************************************************/
1891 * This function returns read Latency Start point.
1893 * @param InstancePtr is a pointer to the XAxiPmon instance.
1895 * @return Returns 0 - XAPM_LATENCY_ADDR_ISSUE or
1896 * 1 - XAPM_LATENCY_ADDR_ACCEPT
1900 *******************************************************************************/
1901 u8 XAxiPmon_GetRdLatencyStart(XAxiPmon *InstancePtr)
1906 * Assert the arguments.
1908 Xil_AssertNonvoid(InstancePtr != NULL);
1909 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1911 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1913 RegVal = RegVal & XAPM_CR_RDLATENCY_START_MASK;
1915 if (RegVal != XAPM_LATENCY_ADDR_ISSUE) {
1916 return XAPM_LATENCY_ADDR_ACCEPT;
1919 return XAPM_LATENCY_ADDR_ISSUE;
1923 /*****************************************************************************/
1926 * This function returns Read Latency End point.
1928 * @param InstancePtr is a pointer to the XAxiPmon instance.
1930 * @return Returns 0 - XAPM_LATENCY_LASTRD or
1931 * 1 - XAPM_LATENCY_FIRSTRD.
1935 *******************************************************************************/
1936 u8 XAxiPmon_GetRdLatencyEnd(XAxiPmon *InstancePtr)
1941 * Assert the arguments.
1943 Xil_AssertNonvoid(InstancePtr != NULL);
1944 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1946 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
1948 RegVal = RegVal & XAPM_CR_RDLATENCY_END_MASK;
1949 if (RegVal != XAPM_LATENCY_LASTRD) {
1950 return XAPM_LATENCY_FIRSTRD;
1953 return XAPM_LATENCY_LASTRD;
1958 /****************************************************************************/
1961 * This function sets Write ID Mask in ID Mask register.
1963 * @param InstancePtr is a pointer to the XAxiPmon instance.
1964 * @param WrMask is the Write ID mask to be written in ID register.
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.
1973 *****************************************************************************/
1974 void XAxiPmon_SetWriteIdMask(XAxiPmon *InstancePtr, u32 WrMask)
1978 * Assert the arguments.
1980 Xil_AssertVoid(InstancePtr != NULL);
1981 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
1983 if (InstancePtr->Config.Is32BitFiltering == 0)
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);
1992 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
1993 XAPM_IDMASK_OFFSET, WrMask);
1997 /****************************************************************************/
2000 * This function sets Read ID Mask in ID Mask register.
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.
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.
2012 *****************************************************************************/
2013 void XAxiPmon_SetReadIdMask(XAxiPmon *InstancePtr, u32 RdMask)
2017 * Assert the arguments.
2019 Xil_AssertVoid(InstancePtr != NULL);
2020 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
2022 if (InstancePtr->Config.Is32BitFiltering == 0)
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);
2031 XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
2032 XAPM_RIDMASK_OFFSET, RdMask);
2036 /****************************************************************************/
2039 * This function returns Write ID Mask in ID Mask register.
2041 * @param InstancePtr is a pointer to the XAxiPmon instance.
2043 * @return WrMask is the required Write ID Mask in ID Mask register.
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
2051 *****************************************************************************/
2052 u32 XAxiPmon_GetWriteIdMask(XAxiPmon *InstancePtr)
2058 * Assert the arguments.
2060 Xil_AssertNonvoid(InstancePtr != NULL);
2061 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
2063 if (InstancePtr->Config.Is32BitFiltering == 0)
2065 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
2066 XAPM_IDMASK_OFFSET);
2067 WrMask = RegVal & XAPM_MASKID_WID_MASK;
2069 WrMask = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
2070 XAPM_IDMASK_OFFSET);
2076 /****************************************************************************/
2079 * This function returns Read ID Mask in ID Mask register.
2081 * @param InstancePtr is a pointer to the XAxiPmon instance.
2083 * @return RdMask is the required Read ID Mask in ID Mask register.
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
2091 *****************************************************************************/
2092 u32 XAxiPmon_GetReadIdMask(XAxiPmon *InstancePtr)
2098 * Assert the arguments.
2100 Xil_AssertNonvoid(InstancePtr != NULL);
2101 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
2103 if (InstancePtr->Config.Is32BitFiltering == 0)
2105 RegVal = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
2106 XAPM_IDMASK_OFFSET);
2107 RegVal = RegVal & XAPM_MASKID_RID_MASK;
2108 RdMask = RegVal >> 16;
2110 RdMask = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
2111 XAPM_RIDMASK_OFFSET);