summaryrefslogtreecommitdiff
path: root/drivers/misc/gpsip/cgdriver/CgCpuLinux.c
blob: 7dc9f6b7a1b86f5d84de2e7355faafbfe850db1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/******************************************************************************
 *                                LEGAL NOTICE                                *
 *                                                                            *
 *  USE OF THIS SOFTWARE (including any copy or compiled version thereof) AND *
 *  DOCUMENTATION IS SUBJECT TO THE SOFTWARE LICENSE AND RESTRICTIONS AND THE *
 *  WARRANTY DISLCAIMER SET FORTH IN LEGAL_NOTICE.TXT FILE. IF YOU DO NOT     *
 *  FULLY ACCEPT THE TERMS, YOU MAY NOT INSTALL OR OTHERWISE USE THE SOFTWARE *
 *  OR DOCUMENTATION.                                                         *
 *  NOTWITHSTANDING ANYTHING TO THE CONTRARY IN THIS NOTICE, INSTALLING OR    *
 *  OTHERISE USING THE SOFTWARE OR DOCUMENTATION INDICATES YOUR ACCEPTANCE OF *
 *  THE LICENSE TERMS AS STATED.                                              *
 *                                                                            *
 ******************************************************************************/
/* Version: 1.8.9\3686 */
/* Build  : 13 */
/* Date   : 12/08/2012 */

/**
    \cond OS_LINUX
*/


/**
	\file
	\brief Linux implementation of OS depended CellGuide CPU API
	\attention This file should not be modified.
		If you think something is wrong here, please contact CellGuide



*/
#include <stdarg.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/pagemap.h>
#include <linux/vmalloc.h>
#include <linux/delay.h>
#include <linux/cdev.h>
#include <linux/interrupt.h>
#include <linux/workqueue.h>
#include <linux/dma-mapping.h>
#include <linux/wait.h>

#include <linux/sched.h>
#include <linux/time.h>

#include <asm/io.h>
#include <asm/dma.h>
#include <asm/cacheflush.h>

#include "CgCpuOs.h"
#include "CgCpu.h"
#include "platform.h"






TCgReturnCode CgCpuIntrDone(U32 aInterruptCode)
{
	TCgReturnCode rc = ECgOk;
	//InterruptDone(aInterruptCode);
	return rc;
}



TCgReturnCode CgCpuVirtualAllocate(volatile void **pObject, unsigned long aBaseAddr, unsigned long aSize)
{
	ASSERT_NOT_NULL(pObject);

    *pObject = ioremap_nocache(aBaseAddr, aSize);

    return (*pObject != NULL) ? ECgOk : ECgErrMemory;
}


TCgReturnCode CgCpuVirtualFree(volatile void **pObject)
{
	ASSERT_NOT_NULL(pObject);

    iounmap((void *)*pObject);
    *pObject = NULL;

    return ECgOk;
}


TCgReturnCode CgCpuPhysicalAllocate(void **pObject, U32 *pAddress, U32 aSize)
{
	DBG_FUNC_NAME("CgCpuPhysicalAllocate")
	TCgReturnCode rc = ECgOk;
	ASSERT_NOT_NULL(pObject);
	//DBGMSG1("Trying to allocate %d bytes", aSize);

	//*pObject = dma_alloc_writecombine(0, aSize + 32, (dma_addr_t *)pAddress, GFP_KERNEL);

	if(*pObject == NULL) {
		DBGMSG("Error! Failed allocating buffer");
		rc = ECgErrMemory;
		}
	else {
		DBGMSG2("buffer allocated: ptr=0x%08X, addr=0x%08X", *pObject, *pAddress);
//		memset((void *)*pObject, 0, aSize);
		}

	*pObject = (unsigned char *)((((unsigned long)*pObject + 32 - 1) / 32) * 32);
	*pAddress = ((*pAddress + 32 - 1) / 32) * 32;

	return rc;
}

TCgReturnCode CgCpuPhysicalFree(void **pObject, U32 *pAddress, unsigned long aSize)
{
	DBG_FUNC_NAME("CgCpuPhysicalFree")
	TCgReturnCode rc = ECgOk;
	ASSERT_NOT_NULL(pObject);
	DBGMSG1("pObject=0x%08X", *pObject);

	if (*pAddress != 0)
	//	dma_free_writecombine(0, aSize + 32, *pObject, *pAddress);

	*pObject = NULL;

	return rc;
}




TCgReturnCode CgxCpuReadMemory(U32 aBaseAddr, U32 aOffset, U32 *apValue)
{
    	DBG_FUNC_NAME("CgxCpuReadMemory")

         DBGMSG1("read addd ress %x",aBaseAddr);


    *apValue = sci_glb_read((aBaseAddr + aOffset),-1UL);
    return ECgOk;
}

TCgReturnCode CgxCpuWriteMemory(U32 aBaseAddr, U32 aOffset, U32 aValue)
{
    DBG_FUNC_NAME("CgxCpuWriteMemory")

    DBGMSG1("addd ress %x",aBaseAddr);

	sci_glb_write((aBaseAddr + aOffset), aValue, -1UL);

    return ECgOk;
}

TCgReturnCode CgCpuKernelModeEnter(void)
{
	return ECgOk;
}


TCgReturnCode CgCpuKernelModeExit(void)
{
	return ECgOk;
}


TCgReturnCode CgCpuCacheSync(void)
{
	//DBG_FUNC_NAME("CgCpuCacheSync")
#ifndef ACP_PORT
	flush_cache_all();
#else
    DBGMSG("enable ACP");
#endif

	return ECgOk;
}



#ifdef TRACE_ON
#define MAX_LINE_LENGTH  256


TCgReturnCode CgxCpuPrint(char *aText)
{
	printk(KERN_EMERG "%s", aText);

	return ECgOk;
}

TCgReturnCode CgxCpuMsg(const char *aFuncName, const char *aFileName, U32 aLineNum, char *aFormat, ...)
{
#if 0
  	va_list args;
    char buf[MAX_LINE_LENGTH]= {0};
	int n = 0;
	U32 curTickMSec = 0;
   	va_start(args, aFormat); // prepare the arguments
	n = vsnprintf(buf, MAX_LINE_LENGTH, aFormat, args);
   	va_end(args); // clean the stack

	// Get current tick
	CgxCpuTick(&curTickMSec);

	if (n > 0)
		printk(KERN_EMERG ">>> %d.%03d %s[%d]: %s\n", curTickMSec / 1000, curTickMSec % 1000, aFuncName, (int)aLineNum, buf);
	#endif
	return ECgOk;
}
#endif

TCgReturnCode CgxCpuSleep(U32 milliSeconds)
{
	set_current_state(TASK_INTERRUPTIBLE);
	schedule_timeout (milliSeconds);
	return ECgOk;
}
#ifndef CG_HAS_CPU_TICK
	TCgReturnCode CgxCpuTick(U32 * apTickMSec)
	{
		struct timespec t = current_kernel_time();
		*apTickMSec = t.tv_sec * 1000 + t.tv_nsec / 1000000;
		return ECgOk;
	}
#endif

/** \endcond */