synopGMAC_plat.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /**\file
  2. * This file serves as the wrapper for the platform/OS dependent functions
  3. * It is needed to modify these functions accordingly based on the platform and the
  4. * OS. Whenever the synopsys GMAC driver ported on to different platform, this file
  5. * should be handled at most care.
  6. * The corresponding function definitions for non-inline functions are available in
  7. * synopGMAC_plat.c file.
  8. * \internal
  9. * -------------------------------------REVISION HISTORY---------------------------
  10. * Synopsys 01/Aug/2007 Created
  11. */
  12. #ifndef SYNOP_GMAC_PLAT_H
  13. #define SYNOP_GMAC_PLAT_H 1
  14. /* sw
  15. #include <linux/kernel.h>
  16. #include <asm/io.h>
  17. #include <linux/gfp.h>
  18. #include <linux/slab.h>
  19. #include <linux/pci.h>
  20. */
  21. #include "types.h"
  22. #include "debug.h"
  23. //#include "mii.h"
  24. //#include "GMAC_Pmon.h"
  25. //#include "synopGMAC_Host.h"
  26. #include <rtthread.h>
  27. //sw: copy the type define into here
  28. #define IOCTL_READ_REGISTER SIOCDEVPRIVATE+1
  29. #define IOCTL_WRITE_REGISTER SIOCDEVPRIVATE+2
  30. #define IOCTL_READ_IPSTRUCT SIOCDEVPRIVATE+3
  31. #define IOCTL_READ_RXDESC SIOCDEVPRIVATE+4
  32. #define IOCTL_READ_TXDESC SIOCDEVPRIVATE+5
  33. #define IOCTL_POWER_DOWN SIOCDEVPRIVATE+6
  34. #define SYNOP_GMAC0 1
  35. typedef int bool;
  36. //typedef unsigned long dma_addr_t;
  37. //sw
  38. /* write/read MMIO register */
  39. #define writeb(val, addr) (*(volatile u8*)(addr) = (val))
  40. #define writew(val, addr) (*(volatile u16*)(addr) = (val))
  41. #define writel(val, addr) (*(volatile u32*)(addr) = (val))
  42. #define readb(addr) (*(volatile u8*)(addr))
  43. #define readw(addr) (*(volatile u16*)(addr))
  44. #define readl(addr) (*(volatile u32*)(addr))
  45. #define KUSEG_ADDR 0x0
  46. #define CACHED_MEMORY_ADDR 0x80000000
  47. #define UNCACHED_MEMORY_ADDR 0xa0000000
  48. #define KSEG2_ADDR 0xc0000000
  49. #define MAX_MEM_ADDR 0xbe000000
  50. #define RESERVED_ADDR 0xbfc80000
  51. #define CACHED_TO_PHYS(x) ((unsigned)(x) & 0x7fffffff)
  52. #define PHYS_TO_CACHED(x) ((unsigned)(x) | CACHED_MEMORY_ADDR)
  53. #define UNCACHED_TO_PHYS(x) ((unsigned)(x) & 0x1fffffff)
  54. #define PHYS_TO_UNCACHED(x) ((unsigned)(x) | UNCACHED_MEMORY_ADDR)
  55. #define VA_TO_CINDEX(x) ((unsigned)(x) & 0xffffff | CACHED_MEMORY_ADDR)
  56. #define CACHED_TO_UNCACHED(x) (PHYS_TO_UNCACHED(CACHED_TO_PHYS(x)))
  57. #define VA_TO_PA(x) UNCACHED_TO_PHYS(x)
  58. /* sw
  59. #define TR0(fmt, args...) printk(KERN_CRIT "SynopGMAC: " fmt, ##args)
  60. #ifdef DEBUG
  61. #undef TR
  62. # define TR(fmt, args...) printk(KERN_CRIT "SynopGMAC: " fmt, ##args)
  63. #else
  64. # define TR(fmt, args...) // not debugging: nothing
  65. #endif
  66. */
  67. /*
  68. #define TR0(fmt, args...) printf("SynopGMAC: " fmt, ##args)
  69. */
  70. /*
  71. #ifdef DEBUG
  72. #undef TR
  73. # define TR(fmt, args...) printf("SynopGMAC: " fmt, ##args)
  74. #else
  75. //# define TR(fmt, args...) // not debugging: nothing
  76. #define TR(fmt, args...) printf("SynopGMAC: " fmt, ##args)
  77. #endif
  78. */
  79. //sw: nothing to display
  80. #define TR0(fmt, args...) rt_kprintf(fmt, ##args)
  81. #define TR(fmt, args...) rt_kprintf(fmt, ##args)
  82. //#define TR rt_kprintf
  83. //typedef int bool;
  84. enum synopGMAC_boolean
  85. {
  86. false = 0,
  87. true = 1
  88. };
  89. #define DEFAULT_DELAY_VARIABLE 10
  90. #define DEFAULT_LOOP_VARIABLE 10000
  91. /* There are platform related endian conversions
  92. *
  93. */
  94. #define LE32_TO_CPU __le32_to_cpu
  95. #define BE32_TO_CPU __be32_to_cpu
  96. #define CPU_TO_LE32 __cpu_to_le32
  97. /* Error Codes */
  98. #define ESYNOPGMACNOERR 0
  99. #define ESYNOPGMACNOMEM 1
  100. #define ESYNOPGMACPHYERR 2
  101. #define ESYNOPGMACBUSY 3
  102. struct Network_interface_data
  103. {
  104. u32 unit;
  105. u32 addr;
  106. u32 data;
  107. };
  108. /**
  109. * These are the wrapper function prototypes for OS/platform related routines
  110. */
  111. void * plat_alloc_memory(u32 );
  112. void plat_free_memory(void *);
  113. //void * plat_alloc_consistent_dmaable_memory(struct pci_dev *, u32, u32 *);
  114. //void plat_free_consistent_dmaable_memory (struct pci_dev *, u32, void *, u32);
  115. void plat_delay(u32);
  116. /**
  117. * The Low level function to read register contents from Hardware.
  118. *
  119. * @param[in] pointer to the base of register map
  120. * @param[in] Offset from the base
  121. * \return Returns the register contents
  122. */
  123. static u32 synopGMACReadReg(u32 RegBase, u32 RegOffset)
  124. {
  125. u32 addr;
  126. u32 data;
  127. addr = RegBase + (u32)RegOffset;
  128. #if 0 //__mips >= 3 && __mips != 32
  129. __asm __volatile(
  130. ".set\tnoreorder\n\t"
  131. ".set\tmips3\n\t"
  132. "ld $8,%1\n\t"
  133. "lw $9,0x0($8)\n\t"
  134. "nop\n\t"
  135. "nop\n\t"
  136. "sw $9,%0\n\t"
  137. ".set\tmips0\n\t"
  138. :"=m"(data)
  139. :"m"(addr)
  140. :"memory","$8","$9"
  141. );
  142. #else
  143. data = *(volatile u32 *)addr;
  144. #endif
  145. #if SYNOP_REG_DEBUG
  146. TR("%s RegBase = 0x%08x RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, (u32)RegBase, RegOffset, data );
  147. #endif
  148. // rt_kprintf("%s RegBase = 0x%08x RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, (u32)RegBase, RegOffset, data );
  149. return data;
  150. }
  151. /**
  152. * The Low level function to write to a register in Hardware.
  153. *
  154. * @param[in] pointer to the base of register map
  155. * @param[in] Offset from the base
  156. * @param[in] Data to be written
  157. * \return void
  158. */
  159. static void synopGMACWriteReg(u32 RegBase, u32 RegOffset, u32 RegData )
  160. {
  161. u32 addr;
  162. addr = RegBase + (u32)RegOffset;
  163. // rt_kprintf("%s RegBase = 0x%08x RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__,(u32) RegBase, RegOffset, RegData );
  164. #if SYNOP_REG_DEBUG
  165. TR("%s RegBase = 0x%08x RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__,(u32) RegBase, RegOffset, RegData );
  166. #endif
  167. // writel(RegData,(void *)addr);
  168. //printf("GMAC addr = 0x%lx \n",addr);
  169. #if 0 //__mips >= 3 && __mips != 32
  170. __asm __volatile(
  171. ".set\tnoreorder\n\t"
  172. ".set\tmips3\n\t"
  173. "lw $9,%0\n\t"
  174. "ld $8,%1\n\t"
  175. "sw $9,0x0($8)\n\t"
  176. ".set\tmips0\n\t"
  177. :
  178. :"m"(RegData),"m"(addr)
  179. :"memory","$8","$9"
  180. );
  181. #else
  182. *(volatile u32 *)addr = RegData;
  183. #endif
  184. if(addr == 0xbfe1100c)
  185. DEBUG_MES("regdata = %08x\n", RegData);
  186. return;
  187. }
  188. /**
  189. * The Low level function to set bits of a register in Hardware.
  190. *
  191. * @param[in] pointer to the base of register map
  192. * @param[in] Offset from the base
  193. * @param[in] Bit mask to set bits to logical 1
  194. * \return void
  195. */
  196. static void synopGMACSetBits(u32 RegBase, u32 RegOffset, u32 BitPos)
  197. {
  198. //u64 addr = (u64)RegBase + (u64)RegOffset;
  199. u32 data;
  200. data = synopGMACReadReg(RegBase, RegOffset);
  201. data |= BitPos;
  202. synopGMACWriteReg(RegBase, RegOffset, data);
  203. // writel(data,(void *)addr);
  204. #if SYNOP_REG_DEBUG
  205. TR("%s !!!!!!!!!!!!! RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, RegOffset, data );
  206. #endif
  207. return;
  208. }
  209. /**
  210. * The Low level function to clear bits of a register in Hardware.
  211. *
  212. * @param[in] pointer to the base of register map
  213. * @param[in] Offset from the base
  214. * @param[in] Bit mask to clear bits to logical 0
  215. * \return void
  216. */
  217. static void synopGMACClearBits(u32 RegBase, u32 RegOffset, u32 BitPos)
  218. {
  219. u32 data;
  220. data = synopGMACReadReg(RegBase, RegOffset);
  221. data &= (~BitPos);
  222. synopGMACWriteReg(RegBase, RegOffset, data);
  223. #if SYNOP_REG_DEBUG
  224. TR("%s !!!!!!!!!!!!! RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, RegOffset, data );
  225. #endif
  226. return;
  227. }
  228. /**
  229. * The Low level function to Check the setting of the bits.
  230. *
  231. * @param[in] pointer to the base of register map
  232. * @param[in] Offset from the base
  233. * @param[in] Bit mask to set bits to logical 1
  234. * \return returns TRUE if set to '1' returns FALSE if set to '0'. Result undefined there are no bit set in the BitPos argument.
  235. *
  236. */
  237. static bool synopGMACCheckBits(u32 RegBase, u32 RegOffset, u32 BitPos)
  238. {
  239. u32 data;
  240. data = synopGMACReadReg(RegBase, RegOffset);
  241. data &= BitPos;
  242. if(data) return true;
  243. else return false;
  244. }
  245. #endif