dpaa_sys.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Copyright 2008 - 2016 Freescale Semiconductor, Inc.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are met:
  5. * * Redistributions of source code must retain the above copyright
  6. * notice, this list of conditions and the following disclaimer.
  7. * * Redistributions in binary form must reproduce the above copyright
  8. * notice, this list of conditions and the following disclaimer in the
  9. * documentation and/or other materials provided with the distribution.
  10. * * Neither the name of Freescale Semiconductor nor the
  11. * names of its contributors may be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. * ALTERNATIVELY, this software may be distributed under the terms of the
  15. * GNU General Public License ("GPL") as published by the Free Software
  16. * Foundation, either version 2 of that License or (at your option) any
  17. * later version.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  20. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef __DPAA_SYS_H
  31. #define __DPAA_SYS_H
  32. #include <linux/cpu.h>
  33. #include <linux/slab.h>
  34. #include <linux/module.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/kthread.h>
  37. #include <linux/vmalloc.h>
  38. #include <linux/platform_device.h>
  39. #include <linux/of_reserved_mem.h>
  40. #include <linux/prefetch.h>
  41. #include <linux/genalloc.h>
  42. #include <asm/cacheflush.h>
  43. /* For 2-element tables related to cache-inhibited and cache-enabled mappings */
  44. #define DPAA_PORTAL_CE 0
  45. #define DPAA_PORTAL_CI 1
  46. #if (L1_CACHE_BYTES != 32) && (L1_CACHE_BYTES != 64)
  47. #error "Unsupported Cacheline Size"
  48. #endif
  49. static inline void dpaa_flush(void *p)
  50. {
  51. #ifdef CONFIG_PPC
  52. flush_dcache_range((unsigned long)p, (unsigned long)p+64);
  53. #elif defined(CONFIG_ARM32)
  54. __cpuc_flush_dcache_area(p, 64);
  55. #elif defined(CONFIG_ARM64)
  56. __flush_dcache_area(p, 64);
  57. #endif
  58. }
  59. #define dpaa_invalidate(p) dpaa_flush(p)
  60. #define dpaa_zero(p) memset(p, 0, 64)
  61. static inline void dpaa_touch_ro(void *p)
  62. {
  63. #if (L1_CACHE_BYTES == 32)
  64. prefetch(p+32);
  65. #endif
  66. prefetch(p);
  67. }
  68. /* Commonly used combo */
  69. static inline void dpaa_invalidate_touch_ro(void *p)
  70. {
  71. dpaa_invalidate(p);
  72. dpaa_touch_ro(p);
  73. }
  74. #ifdef CONFIG_FSL_DPAA_CHECKING
  75. #define DPAA_ASSERT(x) WARN_ON(!(x))
  76. #else
  77. #define DPAA_ASSERT(x)
  78. #endif
  79. /* cyclic helper for rings */
  80. static inline u8 dpaa_cyc_diff(u8 ringsize, u8 first, u8 last)
  81. {
  82. /* 'first' is included, 'last' is excluded */
  83. if (first <= last)
  84. return last - first;
  85. return ringsize + last - first;
  86. }
  87. /* Offset applied to genalloc pools due to zero being an error return */
  88. #define DPAA_GENALLOC_OFF 0x80000000
  89. #endif /* __DPAA_SYS_H */