synopGMAC_plat.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. /*
  13. * File : synopGMAC_plat.h
  14. * This file is part of RT-Thread RTOS
  15. * COPYRIGHT (C) chinesebear
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License along
  28. * with this program; if not, write to the Free Software Foundation, Inc.,
  29. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  30. *
  31. * Change Logs:
  32. * Date Author Notes
  33. * 2017-08-24 chinesebear first version
  34. */
  35. #ifndef SYNOP_GMAC_PLAT_H
  36. #define SYNOP_GMAC_PLAT_H 1
  37. /* sw
  38. #include <linux/kernel.h>
  39. #include <asm/io.h>
  40. #include <linux/gfp.h>
  41. #include <linux/slab.h>
  42. #include <linux/pci.h>
  43. */
  44. #include "synopGMAC_types.h"
  45. #include "synopGMAC_debug.h"
  46. //#include "mii.h"
  47. //#include "GMAC_Pmon.h"
  48. //#include "synopGMAC_Host.h"
  49. #include <rtthread.h>
  50. //sw: copy the type define into here
  51. #define IOCTL_READ_REGISTER SIOCDEVPRIVATE+1
  52. #define IOCTL_WRITE_REGISTER SIOCDEVPRIVATE+2
  53. #define IOCTL_READ_IPSTRUCT SIOCDEVPRIVATE+3
  54. #define IOCTL_READ_RXDESC SIOCDEVPRIVATE+4
  55. #define IOCTL_READ_TXDESC SIOCDEVPRIVATE+5
  56. #define IOCTL_POWER_DOWN SIOCDEVPRIVATE+6
  57. #define SYNOP_GMAC0 1
  58. typedef int bool;
  59. //typedef unsigned long dma_addr_t;
  60. //sw
  61. /* write/read MMIO register */
  62. #define writeb(val, addr) (*(volatile u8*)(addr) = (val))
  63. #define writew(val, addr) (*(volatile u16*)(addr) = (val))
  64. #define writel(val, addr) (*(volatile u32*)(addr) = (val))
  65. #define readb(addr) (*(volatile u8*)(addr))
  66. #define readw(addr) (*(volatile u16*)(addr))
  67. #define readl(addr) (*(volatile u32*)(addr))
  68. #define KUSEG_ADDR 0x0
  69. #define CACHED_MEMORY_ADDR 0x80000000
  70. #define UNCACHED_MEMORY_ADDR 0xa0000000
  71. #define KSEG2_ADDR 0xc0000000
  72. #define MAX_MEM_ADDR 0xbe000000
  73. #define RESERVED_ADDR 0xbfc80000
  74. #define CACHED_TO_PHYS(x) ((unsigned)(x) & 0x7fffffff)
  75. #define PHYS_TO_CACHED(x) ((unsigned)(x) | CACHED_MEMORY_ADDR)
  76. #define UNCACHED_TO_PHYS(x) ((unsigned)(x) & 0x1fffffff)
  77. #define PHYS_TO_UNCACHED(x) ((unsigned)(x) | UNCACHED_MEMORY_ADDR)
  78. #define VA_TO_CINDEX(x) ((unsigned)(x) & 0xffffff | CACHED_MEMORY_ADDR)
  79. #define CACHED_TO_UNCACHED(x) (PHYS_TO_UNCACHED(CACHED_TO_PHYS(x)))
  80. #define VA_TO_PA(x) UNCACHED_TO_PHYS(x)
  81. /* sw
  82. #define TR0(fmt, args...) printk(KERN_CRIT "SynopGMAC: " fmt, ##args)
  83. #ifdef DEBUG
  84. #undef TR
  85. # define TR(fmt, args...) printk(KERN_CRIT "SynopGMAC: " fmt, ##args)
  86. #else
  87. # define TR(fmt, args...) // not debugging: nothing
  88. #endif
  89. */
  90. /*
  91. #define TR0(fmt, args...) printf("SynopGMAC: " fmt, ##args)
  92. */
  93. /*
  94. #ifdef DEBUG
  95. #undef TR
  96. # define TR(fmt, args...) printf("SynopGMAC: " fmt, ##args)
  97. #else
  98. //# define TR(fmt, args...) // not debugging: nothing
  99. #define TR(fmt, args...) printf("SynopGMAC: " fmt, ##args)
  100. #endif
  101. */
  102. //sw: nothing to display
  103. #define TR0(fmt, args...) //rt_kprintf(fmt, ##args)
  104. #define TR(fmt, args...) //rt_kprintf(fmt, ##args)
  105. //#define TR rt_kprintf
  106. //typedef int bool;
  107. enum synopGMAC_boolean
  108. {
  109. false = 0,
  110. true = 1
  111. };
  112. #define DEFAULT_DELAY_VARIABLE 10
  113. #define DEFAULT_LOOP_VARIABLE 10000
  114. /* There are platform related endian conversions
  115. *
  116. */
  117. #define LE32_TO_CPU __le32_to_cpu
  118. #define BE32_TO_CPU __be32_to_cpu
  119. #define CPU_TO_LE32 __cpu_to_le32
  120. /* Error Codes */
  121. #define ESYNOPGMACNOERR 0
  122. #define ESYNOPGMACNOMEM 1
  123. #define ESYNOPGMACPHYERR 2
  124. #define ESYNOPGMACBUSY 3
  125. struct Network_interface_data
  126. {
  127. u32 unit;
  128. u32 addr;
  129. u32 data;
  130. };
  131. /**
  132. * These are the wrapper function prototypes for OS/platform related routines
  133. */
  134. void * plat_alloc_memory(u32 );
  135. void plat_free_memory(void *);
  136. //void * plat_alloc_consistent_dmaable_memory(struct pci_dev *, u32, u32 *);
  137. //void plat_free_consistent_dmaable_memory (struct pci_dev *, u32, void *, u32);
  138. void plat_delay(u32);
  139. /**
  140. * The Low level function to read register contents from Hardware.
  141. *
  142. * @param[in] pointer to the base of register map
  143. * @param[in] Offset from the base
  144. * \return Returns the register contents
  145. */
  146. static u32 synopGMACReadReg(u32 RegBase, u32 RegOffset)
  147. {
  148. u32 addr;
  149. u32 data;
  150. addr = RegBase + (u32)RegOffset;
  151. data = *(volatile u32 *)addr;
  152. #if SYNOP_REG_DEBUG
  153. TR("%s RegBase = 0x%08x RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, (u32)RegBase, RegOffset, data );
  154. #endif
  155. // rt_kprintf("%s RegBase = 0x%08x RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, (u32)RegBase, RegOffset, data );
  156. return data;
  157. }
  158. /**
  159. * The Low level function to write to a register in Hardware.
  160. *
  161. * @param[in] pointer to the base of register map
  162. * @param[in] Offset from the base
  163. * @param[in] Data to be written
  164. * \return void
  165. */
  166. static void synopGMACWriteReg(u32 RegBase, u32 RegOffset, u32 RegData )
  167. {
  168. u32 addr;
  169. addr = RegBase + (u32)RegOffset;
  170. // rt_kprintf("%s RegBase = 0x%08x RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__,(u32) RegBase, RegOffset, RegData );
  171. #if SYNOP_REG_DEBUG
  172. TR("%s RegBase = 0x%08x RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__,(u32) RegBase, RegOffset, RegData );
  173. #endif
  174. *(volatile u32 *)addr = RegData;
  175. if(addr == 0xbfe1100c)
  176. DEBUG_MES("regdata = %08x\n", RegData);
  177. return;
  178. }
  179. /**
  180. * The Low level function to set bits of a register in Hardware.
  181. *
  182. * @param[in] pointer to the base of register map
  183. * @param[in] Offset from the base
  184. * @param[in] Bit mask to set bits to logical 1
  185. * \return void
  186. */
  187. static void synopGMACSetBits(u32 RegBase, u32 RegOffset, u32 BitPos)
  188. {
  189. //u64 addr = (u64)RegBase + (u64)RegOffset;
  190. u32 data;
  191. data = synopGMACReadReg(RegBase, RegOffset);
  192. data |= BitPos;
  193. synopGMACWriteReg(RegBase, RegOffset, data);
  194. // writel(data,(void *)addr);
  195. #if SYNOP_REG_DEBUG
  196. TR("%s !!!!!!!!!!!!! RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, RegOffset, data );
  197. #endif
  198. return;
  199. }
  200. /**
  201. * The Low level function to clear bits of a register in Hardware.
  202. *
  203. * @param[in] pointer to the base of register map
  204. * @param[in] Offset from the base
  205. * @param[in] Bit mask to clear bits to logical 0
  206. * \return void
  207. */
  208. static void synopGMACClearBits(u32 RegBase, u32 RegOffset, u32 BitPos)
  209. {
  210. u32 data;
  211. data = synopGMACReadReg(RegBase, RegOffset);
  212. data &= (~BitPos);
  213. synopGMACWriteReg(RegBase, RegOffset, data);
  214. #if SYNOP_REG_DEBUG
  215. TR("%s !!!!!!!!!!!!! RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, RegOffset, data );
  216. #endif
  217. return;
  218. }
  219. /**
  220. * The Low level function to Check the setting of the bits.
  221. *
  222. * @param[in] pointer to the base of register map
  223. * @param[in] Offset from the base
  224. * @param[in] Bit mask to set bits to logical 1
  225. * \return returns TRUE if set to '1' returns FALSE if set to '0'. Result undefined there are no bit set in the BitPos argument.
  226. *
  227. */
  228. static bool synopGMACCheckBits(u32 RegBase, u32 RegOffset, u32 BitPos)
  229. {
  230. u32 data;
  231. data = synopGMACReadReg(RegBase, RegOffset);
  232. data &= BitPos;
  233. if(data) return true;
  234. else return false;
  235. }
  236. #endif