c3c9cc3032dd1f389252bc7e1e9fd65d78dc649d
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / t6xx / kbase / src / integration_kit / MaliFns-generic.c
1 /*----------------------------------------------------------------------------
2 *
3 *The confidential and proprietary information contained in this file may
4 *only be used by a person authorised under and to the extent permitted
5 *by a subsisting licensing agreement from ARM Limited.
6 *
7 *        (C) COPYRIGHT 2008-2009,2011,2012-2013 ARM Limited.
8 *             ALL RIGHTS RESERVED
9 *             
10 *This entire notice must be reproduced on all copies of this file
11 *and copies of this file may only be made by a person if such person is
12 *permitted to do so under the terms of a subsisting license agreement
13 *from ARM Limited.
14 *Modified  : $Date: 2013-08-01 18:15:13 +0100 (Thu, 01 Aug 2013) $
15 *Revision  : $Revision: 66689 $
16 *Release   : $State: $
17 *-----------------------------------------------------------------------------
18
19 *-----------------------------------------------------------------------------
20 * Abstract :Implements all the generic APIs used for mali memory and register
21 * compares
22 *-----------------------------------------------------------------------------
23 * Overview
24 *----------
25
26 **************************************************************/
27
28 #include "MaliFns.h"
29 //#include <stdio.h>
30 //#include <string.h>
31 #include <linux/string.h>
32 #include <linux/kernel.h>
33
34 #define printf printk
35 int Mali_MemCpy(unsigned int *malidata_page,
36                 unsigned int mali_va,
37                 unsigned int *refdata,
38                 unsigned int refoffset,
39                 unsigned int len) 
40 {
41   memcpy((void *)((char *)malidata_page + (mali_va % 4096)),
42                (void *)((char *)refdata + (refoffset)),
43                len * sizeof(unsigned int));
44
45   return 0;
46 };
47
48 int Mali_MemCpyMasked(unsigned int *malidata_page,
49                       unsigned int mali_va,
50                       unsigned int *refdata,
51                       unsigned int *refmask,
52                       unsigned int refoffset,
53                       unsigned int len) 
54 {
55   unsigned int *maskptr = (unsigned int *)((char *)refmask + (refoffset));
56   unsigned int *refptr  = (unsigned int *)((char *)refdata + (refoffset));
57   unsigned int *dataptr = (unsigned int *)((char *)malidata_page + (mali_va % 4096));
58   unsigned int len2 = len;
59   unsigned int m;
60
61   while (len2--) {
62     m   = *maskptr++;
63         if (~m == 0) {
64                 *dataptr = *refptr;
65         } else {
66                 *dataptr = (*dataptr & ~m) | (*refptr & m);
67         }
68
69         *dataptr++;
70         *refptr++;
71   };
72
73   return 0;
74 };
75
76 int Mali_MemCmp(unsigned int *malidata_page,
77                 unsigned int mali_va,
78                 unsigned int *refdata,
79                 unsigned int refoffset,
80                 unsigned int len) 
81 {
82   int res;
83   int i;
84   int j;
85   int step = 4;
86
87 #ifdef MALINOCHECK
88   return 0;
89 #endif
90
91   res = memcmp((void *)((char *)malidata_page + (mali_va % 4096)),
92                (void *)((char *)refdata + (refoffset)),
93                len * sizeof(unsigned int));
94
95   if (res) {
96
97     printf("Error during check of %x bytes from address PA:%x, VA:%x with reference data at address %x\n",
98            len * 4,
99            ((unsigned int)malidata_page + (mali_va % 4096)),
100            mali_va,
101            refdata);
102
103     return -1;
104   } else {
105     return 0;
106   };
107 };
108
109 int Mali_MemCmpMasked(unsigned int *malidata_page,
110                       unsigned int mali_va,
111                       unsigned int *refdata,
112                       unsigned int *refmask,
113                       unsigned int refoffset,
114                       unsigned int len) 
115 {
116   int res = 0;
117
118   unsigned int *maskptr = (unsigned int *)((char *)refmask + (refoffset));
119   unsigned int *refptr  = (unsigned int *)((char *)refdata + (refoffset));
120   unsigned int *dataptr = (unsigned int *)((char *)malidata_page + (mali_va % 4096));
121   unsigned int len2 = len;
122   unsigned int m;
123
124 #ifdef MALINOCHECK
125   return 0;
126 #endif
127
128   while (len2--) {
129     m   = *maskptr++;
130     if ((*dataptr++ & m) != (*refptr++ & m)) {
131       res  = 1;
132       len2 = 0;
133     };
134   };
135
136   if (res) {
137     printf("Error during check of %x bytes from address PA:%x, VA:%x with reference data at address %x\n",
138            len * 4,
139            ((unsigned int)malidata_page + (mali_va % 4096)),
140            mali_va,
141            refdata);
142     return -1;
143   } else {
144     return 0;
145   };
146 };
147
148 int Mali_CompareRegs(unsigned int *reference_ptr, 
149                       int mali_unit,
150                      int mali_core,
151                      int lowreg, 
152                      int highreg)
153 {
154   unsigned int reference_base = (unsigned int)reference_ptr;
155   unsigned int *p;
156   int i;
157   unsigned int v_mali;
158   unsigned int v_testvalue;
159
160 #ifdef MALINOCHECK
161   return 0;
162 #endif
163
164   reference_base = reference_base + (lowreg % 0x10);
165   p = (unsigned int *)reference_base;
166
167   for (i=0; i < (highreg-lowreg); i += 4) {
168     v_mali = Mali_RdReg(mali_unit,mali_core,lowreg+i);
169     v_testvalue = *(p + (i/4));
170     printf ("Checking Register: %08x is value %08x\n",(mali_unit << 28) + (mali_core << 16) + lowreg + i,v_testvalue);
171     if ( v_mali != v_testvalue) {
172       printf ("Reg Compare Fail: %08x; value=%08x should be=%08x\n",(mali_unit << 28) + (mali_core << 16) + lowreg + i,v_mali,v_testvalue);
173       return -1;
174     };
175   };
176   return 0;
177 };
178
179 void Mali_DisplayReg(int unit,int core, int regnum) {
180   int v = Mali_RdReg(unit,core,regnum);
181   printf ("Reg: 0x%08x Value: %08x\n",(unit <<28)+(core<<16)+regnum,v);
182 };
183
184 void Mali_CheckReg(int unit,int core, int regnum, int value) {
185   int v = Mali_RdReg(unit,core,regnum);
186   if(v != value)
187     printf ("Reg Compare Fail: 0x%08x Value: %08x should be=%08x\n",(unit <<28)+(core<<16)+regnum,v,value);
188   else
189     printf ("Reg Compare: 0x%08x Value: %08x\n",(unit <<28)+(core<<16)+regnum,v);
190 };
191
192 /*
193  * This function simply prints out a given number of 32-bit words from a given location in memory
194  * 
195  * It is useful for debugging the GPU's job descriptors and any memory related issues
196  */
197 void Mali_PrintMem (volatile unsigned int * memory_address, unsigned int word_count)
198 {
199     int j;
200     
201     printf ("Memory readout for 0x%x:\n  ", memory_address); 
202     for (j=0;j<word_count;j++)
203     {
204       if ((j%4)==0 && j != 0)
205       {
206         printf ("\n  ");
207       }
208       printf ("word[%02d]=0x%08x ", j, *memory_address); 
209       memory_address += 1;
210     }
211     printf ("\n");
212
213 }
214
215 void Mali_ReadDescriptor (volatile unsigned int * descriptor_address)
216 {
217   Mali_PrintMem (descriptor_address, 12);
218 }
219 #undef printf