synopGMAC_plat.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**\file
  2. * This file defines the wrapper for the platform/OS related functions
  3. * The function definitions needs to be modified according to the platform
  4. * and the Operating system used.
  5. * This file should be handled with greatest care while porting the driver
  6. * to a different platform running different operating system other than
  7. * Linux 2.6.xx.
  8. * \internal
  9. * ----------------------------REVISION HISTORY-----------------------------
  10. * Synopsys 01/Aug/2007 Created
  11. */
  12. #include "synopGMAC_plat.h"
  13. #include "synopGMAC_Dev.h"
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. extern void flush_cache(unsigned long start_addr, unsigned long size);
  17. dma_addr_t __attribute__((weak)) gmac_dmamap(unsigned long va,u32 size)
  18. {
  19. return VA_TO_PA (va);
  20. //return UNCACHED_TO_PHYS(va);
  21. }
  22. /**
  23. * This is a wrapper function for Memory allocation routine. In linux Kernel
  24. * it it kmalloc function
  25. * @param[in] bytes in bytes to allocate
  26. */
  27. void *plat_alloc_memory(u32 bytes)
  28. {
  29. //return (void*)malloc((size_t)bytes, M_DEVBUF, M_DONTWAIT);
  30. void *buf = (void*)rt_malloc((u32)bytes);
  31. flush_cache((unsigned long)buf, bytes);
  32. return buf;
  33. }
  34. /**
  35. * This is a wrapper function for consistent dma-able Memory allocation routine.
  36. * In linux Kernel, it depends on pci dev structure
  37. * @param[in] bytes in bytes to allocate
  38. */
  39. //void *plat_alloc_consistent_dmaable_memory(struct synopGMACdevice *dev, u32 size, u32 *addr)
  40. void *plat_alloc_consistent_dmaable_memory(synopGMACdevice *pcidev, u32 size, u32 *addr)
  41. {
  42. void *buf;
  43. buf = (void*)rt_malloc((u32)(size+16));
  44. //CPU_IOFlushDCache( buf,size, SYNC_W);
  45. unsigned long i = (unsigned long)buf;
  46. // rt_kprintf("size = %d\n", size);
  47. // rt_kprintf("bufaddr = %p\n", buf);
  48. // rt_kprintf("i%%16 == %d\n", i%16);
  49. if(i%16 == 8){
  50. i += 8;
  51. }
  52. else if(i%16 == 4){
  53. i += 12;
  54. }
  55. else if(i%16 == 12){
  56. i += 4;
  57. }
  58. flush_cache(i, size);
  59. *addr =gmac_dmamap(i, size);
  60. buf = (unsigned char *)CACHED_TO_UNCACHED(i);
  61. // rt_kprintf("bufaddr = %p\n", buf);
  62. return buf;
  63. }
  64. /**
  65. * This is a wrapper function for freeing consistent dma-able Memory.
  66. * In linux Kernel, it depends on pci dev structure
  67. * @param[in] bytes in bytes to allocate
  68. */
  69. //void plat_free_consistent_dmaable_memory(void * addr)
  70. void plat_free_consistent_dmaable_memory(synopGMACdevice *pcidev, u32 size, void * addr,u32 dma_addr)
  71. {
  72. rt_free((void*)PHYS_TO_CACHED(UNCACHED_TO_PHYS(addr)));
  73. return;
  74. }
  75. /**
  76. * This is a wrapper function for Memory free routine. In linux Kernel
  77. * it it kfree function
  78. * @param[in] buffer pointer to be freed
  79. */
  80. void plat_free_memory(void *buffer)
  81. {
  82. rt_free(buffer);
  83. return ;
  84. }
  85. dma_addr_t plat_dma_map_single(void *hwdev, void *ptr,
  86. u32 size)
  87. {
  88. unsigned long addr = (unsigned long) ptr;
  89. //CPU_IOFlushDCache(addr,size, direction);
  90. flush_cache(addr, size);
  91. return gmac_dmamap(addr, size);
  92. }
  93. /**
  94. * This is a wrapper function for platform dependent delay
  95. * Take care while passing the argument to this function
  96. * @param[in] buffer pointer to be freed
  97. */
  98. void plat_delay(u32 delay)
  99. {
  100. while (delay--);
  101. return;
  102. }