remove the old broadcom wl driver for linux 2.4
[openwrt/svn-archive/archive.git] / target / linux / generic-2.4 / files / crypto / ocf / kirkwood / mvHal / mv_hal / cpu / mvCpuL2Cntrs.c
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 */
16
17 #include "mvOs.h"
18 #include "mvCpuL2Cntrs.h"
19
20
21
22 MV_CPU_L2_CNTRS_ENTRY mvCpuL2CntrsTbl[MV_CPU_L2_CNTRS_NUM];
23
24 MV_CPU_L2_CNTRS_EVENT* mvCpuL2CntrsEventTbl[128];
25
26 void mvCpuL2CntrsReset(void)
27 {
28 MV_U32 reg = 0;
29
30 MV_ASM ("mcr p15, 6, %0, c15, c13, 0" : : "r" (reg));
31 MV_ASM ("mcr p15, 6, %0, c15, c13, 1" : : "r" (reg));
32 MV_ASM ("mcr p15, 6, %0, c15, c13, 2" : : "r" (reg));
33 MV_ASM ("mcr p15, 6, %0, c15, c13, 3" : : "r" (reg));
34 }
35
36 static void mvCpuL2CntrConfig(int counter, int op)
37 {
38 MV_U32 reg = (1 << op) | 0x1; /*enable*/
39
40 switch(counter)
41 {
42 case 0:
43 MV_ASM ("mcr p15, 6, %0, c15, c12, 0" : : "r" (reg));
44 return;
45
46 case 1:
47 MV_ASM ("mcr p15, 6, %0, c15, c12, 1" : : "r" (reg));
48 return;
49
50 default:
51 mvOsPrintf("mvCpuL2CntrConfig: bad counter number (%d)\n", counter);
52 }
53 return;
54 }
55
56 void mvCpuL2CntrsEventClear(MV_CPU_L2_CNTRS_EVENT* pEvent)
57 {
58 int i;
59
60 for(i=0; i<MV_CPU_L2_CNTRS_NUM; i++)
61 {
62 pEvent->counters_sum[i] = 0;
63 }
64 pEvent->num_of_measurements = 0;
65 }
66
67
68 MV_CPU_L2_CNTRS_EVENT* mvCpuL2CntrsEventCreate(char* name, MV_U32 print_threshold)
69 {
70 int i;
71 MV_CPU_L2_CNTRS_EVENT* event = mvOsMalloc(sizeof(MV_CPU_L2_CNTRS_EVENT));
72
73 if(event)
74 {
75 strncpy(event->name, name, sizeof(event->name));
76 event->num_of_measurements = 0;
77 event->avg_sample_count = print_threshold;
78 for(i=0; i<MV_CPU_L2_CNTRS_NUM; i++)
79 {
80 event->counters_before[i] = 0;
81 event->counters_after[i] = 0;
82 event->counters_sum[i] = 0;
83 }
84 }
85 return event;
86 }
87
88 void mvCpuL2CntrsEventDelete(MV_CPU_L2_CNTRS_EVENT* event)
89 {
90 if(event != NULL)
91 mvOsFree(event);
92 }
93
94
95 MV_STATUS mvCpuL2CntrsProgram(int counter, MV_CPU_L2_CNTRS_OPS op,
96 char* name, MV_U32 overhead)
97 {
98 strncpy(mvCpuL2CntrsTbl[counter].name, name, sizeof(mvCpuL2CntrsTbl[counter].name));
99 mvCpuL2CntrsTbl[counter].operation = op;
100 mvCpuL2CntrsTbl[counter].opIdx = op;
101 mvCpuL2CntrsTbl[counter].overhead = overhead;
102 mvCpuL2CntrConfig(counter, op);
103 mvOsPrintf("CPU L2 Counter %d: operation=%d, overhead=%d\n",
104 counter, op, overhead);
105 return MV_OK;
106 }
107
108 void mvCpuL2CntrsShow(MV_CPU_L2_CNTRS_EVENT* pEvent)
109 {
110 int i;
111 MV_U64 counters_avg;
112
113 if(pEvent->num_of_measurements < pEvent->avg_sample_count)
114 return;
115
116 mvOsPrintf("%16s: ", pEvent->name);
117 for(i=0; i<MV_CPU_L2_CNTRS_NUM; i++)
118 {
119 counters_avg = mvOsDivMod64(pEvent->counters_sum[i],
120 pEvent->num_of_measurements, NULL);
121
122 if(counters_avg >= mvCpuL2CntrsTbl[i].overhead)
123 counters_avg -= mvCpuL2CntrsTbl[i].overhead;
124 else
125 counters_avg = 0;
126
127 mvOsPrintf("%s=%5llu, ", mvCpuL2CntrsTbl[i].name, counters_avg);
128 }
129 mvOsPrintf("\n");
130 mvCpuL2CntrsEventClear(pEvent);
131 mvCpuL2CntrsReset();
132 }
133
134 void mvCpuL2CntrsStatus(void)
135 {
136 int i;
137
138 for(i=0; i<MV_CPU_L2_CNTRS_NUM; i++)
139 {
140 mvOsPrintf("#%d: %s, overhead=%d\n",
141 i, mvCpuL2CntrsTbl[i].name, mvCpuL2CntrsTbl[i].overhead);
142 }
143 }