1 /*******************************************************************************
2 Copyright (C) Marvell International Ltd. and its affiliates
4 This software file (the "File") is owned and distributed by Marvell
5 International Ltd. and/or its affiliates ("Marvell") under the following
6 alternative licensing terms. Once you have made an election to distribute the
7 File under one of the following license alternatives, please (i) delete this
8 introductory statement regarding license alternatives, (ii) delete the two
9 license alternatives that you have not elected to use and (iii) preserve the
10 Marvell copyright notice above.
13 ********************************************************************************
14 Marvell GPL License Option
16 If you received this File from Marvell, you may opt to use, redistribute and/or
17 modify this File in accordance with the terms and conditions of the General
18 Public License Version 2, June 1991 (the "GPL License"), a copy of which is
19 available along with the File in the license.txt file or by writing to the Free
20 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
21 on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
23 THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
24 WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
25 DISCLAIMED. The GPL License provides additional details about this warranty
27 *******************************************************************************/
33 /* for kernel space */
34 #include <linux/autoconf.h>
35 #include <linux/interrupt.h>
36 #include <linux/stddef.h>
37 #include <linux/kernel.h>
38 #include <linux/init.h>
39 #include <linux/errno.h>
40 #include <linux/reboot.h>
41 #include <linux/pci.h>
42 #include <linux/kdev_t.h>
43 #include <linux/major.h>
44 #include <linux/blkdev.h>
45 #include <linux/console.h>
46 #include <linux/delay.h>
47 #include <linux/seq_file.h>
48 #include <linux/string.h>
49 #include <linux/slab.h>
50 #include <linux/kernel.h>
51 #include <linux/string.h>
52 #include <linux/slab.h>
55 #include <asm/system.h>
56 #include <asm/pgtable.h>
58 #include <asm/hardirq.h>
62 #include <linux/random.h>
64 #include "dbg-trace.h"
66 extern void mv_early_printk(char *fmt
,...);
68 #define MV_ASM __asm__ __volatile__
70 #define MV_TRC_REC TRC_REC
71 #define mvOsPrintf printk
72 #define mvOsEarlyPrintf mv_early_printk
73 #define mvOsOutput printk
74 #define mvOsSPrintf sprintf
75 #define mvOsMalloc(_size_) kmalloc(_size_,GFP_ATOMIC)
76 #define mvOsFree kfree
77 #define mvOsMemcpy memcpy
78 #define mvOsSleep(_mils_) mdelay(_mils_)
79 #define mvOsTaskLock()
80 #define mvOsTaskUnlock()
81 #define strtol simple_strtoul
82 #define mvOsDelay(x) mdelay(x)
83 #define mvOsUDelay(x) udelay(x)
84 #define mvCopyFromOs copy_from_user
85 #define mvCopyToOs copy_to_user
92 #define mvOsAssert(cond)
94 #define mvOsAssert(cond) { do { if(!(cond)) { BUG(); } }while(0); }
95 #endif /* MV_NDEBUG */
97 #else /* __KERNEL__ */
99 /* for user space applications */
105 #define INLINE inline
106 #define mvOsPrintf printf
107 #define mvOsOutput printf
108 #define mvOsMalloc(_size_) malloc(_size_)
109 #define mvOsFree free
110 #define mvOsAssert(cond) assert(cond)
112 #endif /* __KERNEL__ */
113 #define mvOsIoVirtToPhy(pDev, pVirtAddr) \
114 pci_map_single( (pDev), (pVirtAddr), 0, PCI_DMA_BIDIRECTIONAL )
116 #define mvOsCacheClear(pDev, p, size ) \
117 pci_map_single( (pDev), (p), (size), PCI_DMA_BIDIRECTIONAL)
119 #define mvOsCacheFlush(pDev, p, size ) \
120 pci_map_single( (pDev), (p), (size), PCI_DMA_TODEVICE)
122 #define mvOsCacheInvalidate(pDev, p, size) \
123 pci_map_single( (pDev), (p), (size), PCI_DMA_FROMDEVICE )
125 #define mvOsCacheUnmap(pDev, phys, size) \
126 pci_unmap_single( (pDev), (dma_addr_t)(phys), (size), PCI_DMA_FROMDEVICE )
129 #define CPU_PHY_MEM(x) (MV_U32)x
130 #define CPU_MEMIO_CACHED_ADDR(x) (void*)x
131 #define CPU_MEMIO_UNCACHED_ADDR(x) (void*)x
134 /* CPU architecture dependent 32, 16, 8 bit read/write IO addresses */
135 #define MV_MEMIO32_WRITE(addr, data) \
136 ((*((volatile unsigned int*)(addr))) = ((unsigned int)(data)))
138 #define MV_MEMIO32_READ(addr) \
139 ((*((volatile unsigned int*)(addr))))
141 #define MV_MEMIO16_WRITE(addr, data) \
142 ((*((volatile unsigned short*)(addr))) = ((unsigned short)(data)))
144 #define MV_MEMIO16_READ(addr) \
145 ((*((volatile unsigned short*)(addr))))
147 #define MV_MEMIO8_WRITE(addr, data) \
148 ((*((volatile unsigned char*)(addr))) = ((unsigned char)(data)))
150 #define MV_MEMIO8_READ(addr) \
151 ((*((volatile unsigned char*)(addr))))
154 /* No Fast Swap implementation (in assembler) for ARM */
155 #define MV_32BIT_LE_FAST(val) MV_32BIT_LE(val)
156 #define MV_16BIT_LE_FAST(val) MV_16BIT_LE(val)
157 #define MV_32BIT_BE_FAST(val) MV_32BIT_BE(val)
158 #define MV_16BIT_BE_FAST(val) MV_16BIT_BE(val)
160 /* 32 and 16 bit read/write in big/little endian mode */
162 /* 16bit write in little endian mode */
163 #define MV_MEMIO_LE16_WRITE(addr, data) \
164 MV_MEMIO16_WRITE(addr, MV_16BIT_LE_FAST(data))
166 /* 16bit read in little endian mode */
167 static __inline MV_U16
MV_MEMIO_LE16_READ(MV_U32 addr
)
171 data
= (MV_U16
)MV_MEMIO16_READ(addr
);
173 return (MV_U16
)MV_16BIT_LE_FAST(data
);
176 /* 32bit write in little endian mode */
177 #define MV_MEMIO_LE32_WRITE(addr, data) \
178 MV_MEMIO32_WRITE(addr, MV_32BIT_LE_FAST(data))
180 /* 32bit read in little endian mode */
181 static __inline MV_U32
MV_MEMIO_LE32_READ(MV_U32 addr
)
185 data
= (MV_U32
)MV_MEMIO32_READ(addr
);
187 return (MV_U32
)MV_32BIT_LE_FAST(data
);
190 static __inline
void mvOsBCopy(char* srcAddr
, char* dstAddr
, int byteCount
)
192 while(byteCount
!= 0)
201 static INLINE MV_U64
mvOsDivMod64(MV_U64 divided
, MV_U64 divisor
, MV_U64
* modulu
)
208 while(divided
>= divisor
)
219 #if defined(MV_BRIDGE_SYNC_REORDER)
220 extern MV_U32
*mvUncachedParam
;
222 static __inline
void mvOsBridgeReorderWA(void)
224 volatile MV_U32 val
= 0;
226 val
= mvUncachedParam
[0];
232 #define MV_FL_8_READ MV_MEMIO8_READ
233 #define MV_FL_16_READ MV_MEMIO_LE16_READ
234 #define MV_FL_32_READ MV_MEMIO_LE32_READ
235 #define MV_FL_8_DATA_READ MV_MEMIO8_READ
236 #define MV_FL_16_DATA_READ MV_MEMIO16_READ
237 #define MV_FL_32_DATA_READ MV_MEMIO32_READ
238 #define MV_FL_8_WRITE MV_MEMIO8_WRITE
239 #define MV_FL_16_WRITE MV_MEMIO_LE16_WRITE
240 #define MV_FL_32_WRITE MV_MEMIO_LE32_WRITE
241 #define MV_FL_8_DATA_WRITE MV_MEMIO8_WRITE
242 #define MV_FL_16_DATA_WRITE MV_MEMIO16_WRITE
243 #define MV_FL_32_DATA_WRITE MV_MEMIO32_WRITE
246 /* CPU cache information */
247 #define CPU_I_CACHE_LINE_SIZE 32 /* 2do: replace 32 with linux core macro */
248 #define CPU_D_CACHE_LINE_SIZE 32 /* 2do: replace 32 with linux core macro */
250 #ifdef CONFIG_L2_CACHE_ENABLE
251 /* Data cache flush one line */
252 #define mvOsCacheLineFlushInv(handle, addr) \
254 __asm__ __volatile__ ("mcr p15, 0, %0, c7, c14, 1" : : "r" (addr));\
255 __asm__ __volatile__ ("mcr p15, 1, %0, c15, c10, 1" : : "r" (addr));\
256 __asm__ __volatile__ ("mcr p15, 0, r0, c7, c10, 4"); \
261 /* Data cache flush one line */
262 #define mvOsCacheLineFlushInv(handle, addr) \
264 __asm__ __volatile__ ("mcr p15, 0, %0, c7, c14, 1" : : "r" (addr));\
265 __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" : : "r" (addr)); \
269 #ifdef CONFIG_L2_CACHE_ENABLE
270 #define mvOsCacheLineInv(handle,addr) \
272 __asm__ __volatile__ ("mcr p15, 0, %0, c7, c6, 1" : : "r" (addr)); \
273 __asm__ __volatile__ ("mcr p15, 1, %0, c15, c11, 1" : : "r" (addr)); \
276 #define mvOsCacheLineInv(handle,addr) \
278 __asm__ __volatile__ ("mcr p15, 0, %0, c7, c6, 1" : : "r" (addr)); \
282 #ifdef CONFIG_L2_CACHE_ENABLE
283 /* Data cache flush one line */
284 #define mvOsCacheLineFlush(handle, addr) \
286 __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 1" : : "r" (addr));\
287 __asm__ __volatile__ ("mcr p15, 1, %0, c15, c9, 1" : : "r" (addr));\
288 __asm__ __volatile__ ("mcr p15, 0, r0, c7, c10, 4"); \
292 /* Data cache flush one line */
293 #define mvOsCacheLineFlush(handle, addr) \
295 __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 1" : : "r" (addr));\
296 __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" : : "r" (addr)); \
300 static __inline
void mvOsPrefetch(const void *ptr
)
302 #ifdef CONFIG_USE_DSP
303 __asm__
__volatile__(
315 #define CPU_PIPE_FLUSH
321 /* register manipulations */
323 /******************************************************************************
324 * This debug function enable the write of each register that u-boot access to
325 * to an array in the DRAM, the function record only MV_REG_WRITE access.
326 * The function could not be operate when booting from flash.
327 * In order to print the array we use the printreg command.
328 ******************************************************************************/
329 /* #define REG_DEBUG */
330 #if defined(REG_DEBUG)
331 extern int reg_arry
[2048][2];
332 extern int reg_arry_index
;
335 /* Marvell controller register read/write macros */
336 #define MV_REG_VALUE(offset) \
337 (MV_MEMIO32_READ((INTER_REGS_BASE | (offset))))
339 #define MV_REG_READ(offset) \
340 (MV_MEMIO_LE32_READ(INTER_REGS_BASE | (offset)))
342 #if defined(REG_DEBUG)
343 #define MV_REG_WRITE(offset, val) \
344 MV_MEMIO_LE32_WRITE((INTER_REGS_BASE | (offset)), (val)); \
346 reg_arry[reg_arry_index][0] = (INTER_REGS_BASE | (offset));\
347 reg_arry[reg_arry_index][1] = (val);\
351 #define MV_REG_WRITE(offset, val) \
352 MV_MEMIO_LE32_WRITE((INTER_REGS_BASE | (offset)), (val));
355 #define MV_REG_BYTE_READ(offset) \
356 (MV_MEMIO8_READ((INTER_REGS_BASE | (offset))))
358 #if defined(REG_DEBUG)
359 #define MV_REG_BYTE_WRITE(offset, val) \
360 MV_MEMIO8_WRITE((INTER_REGS_BASE | (offset)), (val)); \
362 reg_arry[reg_arry_index][0] = (INTER_REGS_BASE | (offset));\
363 reg_arry[reg_arry_index][1] = (val);\
367 #define MV_REG_BYTE_WRITE(offset, val) \
368 MV_MEMIO8_WRITE((INTER_REGS_BASE | (offset)), (val))
371 #if defined(REG_DEBUG)
372 #define MV_REG_BIT_SET(offset, bitMask) \
373 (MV_MEMIO32_WRITE((INTER_REGS_BASE | (offset)), \
374 (MV_MEMIO32_READ(INTER_REGS_BASE | (offset)) | \
375 MV_32BIT_LE_FAST(bitMask)))); \
377 reg_arry[reg_arry_index][0] = (INTER_REGS_BASE | (offset));\
378 reg_arry[reg_arry_index][1] = (MV_MEMIO32_READ(INTER_REGS_BASE | (offset)));\
382 #define MV_REG_BIT_SET(offset, bitMask) \
383 (MV_MEMIO32_WRITE((INTER_REGS_BASE | (offset)), \
384 (MV_MEMIO32_READ(INTER_REGS_BASE | (offset)) | \
385 MV_32BIT_LE_FAST(bitMask))))
388 #if defined(REG_DEBUG)
389 #define MV_REG_BIT_RESET(offset,bitMask) \
390 (MV_MEMIO32_WRITE((INTER_REGS_BASE | (offset)), \
391 (MV_MEMIO32_READ(INTER_REGS_BASE | (offset)) & \
392 MV_32BIT_LE_FAST(~bitMask)))); \
394 reg_arry[reg_arry_index][0] = (INTER_REGS_BASE | (offset));\
395 reg_arry[reg_arry_index][1] = (MV_MEMIO32_READ(INTER_REGS_BASE | (offset)));\
399 #define MV_REG_BIT_RESET(offset,bitMask) \
400 (MV_MEMIO32_WRITE((INTER_REGS_BASE | (offset)), \
401 (MV_MEMIO32_READ(INTER_REGS_BASE | (offset)) & \
402 MV_32BIT_LE_FAST(~bitMask))))
407 /* ARM architecture APIs */
408 MV_U32
mvOsCpuRevGet (MV_VOID
);
409 MV_U32
mvOsCpuPartGet (MV_VOID
);
410 MV_U32
mvOsCpuArchGet (MV_VOID
);
411 MV_U32
mvOsCpuVarGet (MV_VOID
);
412 MV_U32
mvOsCpuAsciiGet (MV_VOID
);
415 void* mvOsIoCachedMalloc( void* osHandle
, MV_U32 size
, MV_ULONG
* pPhyAddr
, MV_U32
*memHandle
);
416 void* mvOsIoUncachedMalloc( void* osHandle
, MV_U32 size
, MV_ULONG
* pPhyAddr
, MV_U32
*memHandle
);
417 void mvOsIoUncachedFree( void* osHandle
, MV_U32 size
, MV_ULONG phyAddr
, void* pVirtAddr
, MV_U32 memHandle
);
418 void mvOsIoCachedFree( void* osHandle
, MV_U32 size
, MV_ULONG phyAddr
, void* pVirtAddr
, MV_U32 memHandle
);
421 #endif /* _MV_OS_LNX_H_ */
This page took 0.067293 seconds and 5 git commands to generate.