1
0

synopGMAC_plat.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. /*
  13. * File : synopGMAC_plat.c
  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. #include "synopGMAC_plat.h"
  36. #include "synopGMAC_Dev.h"
  37. #include <rthw.h>
  38. #include <rtthread.h>
  39. extern void flush_cache(unsigned long start_addr, unsigned long size);
  40. dma_addr_t __attribute__((weak)) gmac_dmamap(unsigned long va,u32 size)
  41. {
  42. return VA_TO_PA (va);
  43. //return UNCACHED_TO_PHYS(va);
  44. }
  45. /**
  46. * This is a wrapper function for Memory allocation routine. In linux Kernel
  47. * it it kmalloc function
  48. * @param[in] bytes in bytes to allocate
  49. */
  50. void *plat_alloc_memory(u32 bytes)
  51. {
  52. //return (void*)malloc((size_t)bytes, M_DEVBUF, M_DONTWAIT);
  53. void *buf = (void*)rt_malloc((u32)bytes);
  54. flush_cache((unsigned long)buf, bytes);
  55. return buf;
  56. }
  57. /**
  58. * This is a wrapper function for consistent dma-able Memory allocation routine.
  59. * In linux Kernel, it depends on pci dev structure
  60. * @param[in] bytes in bytes to allocate
  61. */
  62. //void *plat_alloc_consistent_dmaable_memory(struct synopGMACdevice *dev, u32 size, u32 *addr)
  63. void *plat_alloc_consistent_dmaable_memory(synopGMACdevice *pcidev, u32 size, u32 *addr)
  64. {
  65. void *buf;
  66. buf = (void*)rt_malloc((u32)(size+16));
  67. //CPU_IOFlushDCache( buf,size, SYNC_W);
  68. unsigned long i = (unsigned long)buf;
  69. // rt_kprintf("size = %d\n", size);
  70. // rt_kprintf("bufaddr = %p\n", buf);
  71. // rt_kprintf("i%%16 == %d\n", i%16);
  72. if(i%16 == 8){
  73. i += 8;
  74. }
  75. else if(i%16 == 4){
  76. i += 12;
  77. }
  78. else if(i%16 == 12){
  79. i += 4;
  80. }
  81. flush_cache(i, size);
  82. *addr =gmac_dmamap(i, size);
  83. buf = (unsigned char *)CACHED_TO_UNCACHED(i);
  84. // rt_kprintf("bufaddr = %p\n", buf);
  85. return buf;
  86. }
  87. /**
  88. * This is a wrapper function for freeing consistent dma-able Memory.
  89. * In linux Kernel, it depends on pci dev structure
  90. * @param[in] bytes in bytes to allocate
  91. */
  92. //void plat_free_consistent_dmaable_memory(void * addr)
  93. void plat_free_consistent_dmaable_memory(synopGMACdevice *pcidev, u32 size, void * addr,u32 dma_addr)
  94. {
  95. rt_free((void*)PHYS_TO_CACHED(UNCACHED_TO_PHYS(addr)));
  96. return;
  97. }
  98. /**
  99. * This is a wrapper function for Memory free routine. In linux Kernel
  100. * it it kfree function
  101. * @param[in] buffer pointer to be freed
  102. */
  103. void plat_free_memory(void *buffer)
  104. {
  105. rt_free(buffer);
  106. return ;
  107. }
  108. dma_addr_t plat_dma_map_single(void *hwdev, void *ptr,
  109. u32 size)
  110. {
  111. unsigned long addr = (unsigned long) ptr;
  112. //CPU_IOFlushDCache(addr,size, direction);
  113. flush_cache(addr, size);
  114. return gmac_dmamap(addr, size);
  115. }
  116. /**
  117. * This is a wrapper function for platform dependent delay
  118. * Take care while passing the argument to this function
  119. * @param[in] buffer pointer to be freed
  120. */
  121. void plat_delay(u32 delay)
  122. {
  123. while (delay--);
  124. return;
  125. }