vha_plat_dt_example.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*!
  2. *****************************************************************************
  3. *
  4. * @File vha_plat_dt_example.c
  5. * ---------------------------------------------------------------------------
  6. *
  7. * Copyright (c) Imagination Technologies Ltd.
  8. *
  9. * The contents of this file are subject to the MIT license as set out below.
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a
  12. * copy of this software and associated documentation files (the "Software"),
  13. * to deal in the Software without restriction, including without limitation
  14. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. * and/or sell copies of the Software, and to permit persons to whom the
  16. * Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included in
  19. * all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. * THE SOFTWARE.
  28. *
  29. * Alternatively, the contents of this file may be used under the terms of the
  30. * GNU General Public License Version 2 ("GPL")in which case the provisions of
  31. * GPL are applicable instead of those above.
  32. *
  33. * If you wish to allow use of your version of this file only under the terms
  34. * of GPL, and not to allow others to use your version of this file under the
  35. * terms of the MIT license, indicate your decision by deleting the provisions
  36. * above and replace them with the notice and other provisions required by GPL
  37. * as set out in the file called "GPLHEADER" included in this distribution. If
  38. * you do not delete the provisions above, a recipient may use your version of
  39. * this file under the terms of either the MIT license or GPL.
  40. *
  41. * This License is also included in this distribution in the file called
  42. * "MIT_COPYING".
  43. *
  44. *****************************************************************************/
  45. #include <linux/module.h>
  46. #include <linux/gfp.h>
  47. #include <linux/device.h>
  48. #include <linux/dma-mapping.h>
  49. #include <linux/of.h>
  50. #include <img_mem_man.h>
  51. #include "vha_plat.h"
  52. #include "vha_plat_dt.h"
  53. const struct of_device_id vha_plat_dt_of_ids[] = {
  54. { .compatible = VHA_PLAT_DT_OF_ID },
  55. { }
  56. };
  57. static struct heap_config example_heap_configs[] = {
  58. {
  59. .type = IMG_MEM_HEAP_TYPE_UNIFIED,
  60. .options.unified = {
  61. .gfp_type = GFP_KERNEL | __GFP_ZERO,
  62. },
  63. .to_dev_addr = NULL,
  64. },
  65. {
  66. .type = IMG_MEM_HEAP_TYPE_DMABUF,
  67. .to_dev_addr = NULL,
  68. },
  69. {
  70. .type = IMG_MEM_HEAP_TYPE_ANONYMOUS,
  71. .to_dev_addr = NULL,
  72. },
  73. };
  74. /*
  75. * IO hooks.
  76. * NOTE: customer may want to use spinlock to avoid
  77. * problems with multi threaded IO access
  78. */
  79. uint64_t vha_plat_read64(void *addr)
  80. {
  81. return readq((volatile void __iomem *)addr);
  82. }
  83. void vha_plat_write64(void *addr, uint64_t val)
  84. {
  85. writeq(val, (volatile void __iomem *)addr);
  86. }
  87. int vha_plat_dt_hw_init(struct platform_device *pdev)
  88. {
  89. struct device *dev = &pdev->dev;
  90. int ret;
  91. uint64_t dma_mask;
  92. dev_dbg(dev, "%s dma_get_mask : %#llx\n", __func__, dma_get_mask(dev));
  93. if (dev->dma_mask) {
  94. dev_info(dev, "%s dev->dma_mask : %p : %#llx\n",
  95. __func__, dev->dma_mask, *dev->dma_mask);
  96. } else {
  97. dev_info(dev, "%s mask unset, setting coherent\n", __func__);
  98. dev->dma_mask = &dev->coherent_dma_mask;
  99. }
  100. /* Try alternative dma_mask setting from device tree */
  101. if (!of_property_read_u64(pdev->dev.of_node, "dma-mask",
  102. (uint64_t *)&dma_mask)) {
  103. dev_info(dev, "%s forcing custom mask from DT : %#llx\n",
  104. __func__, dma_mask);
  105. } else {
  106. /* If alternative mask not defined in
  107. * DT -> "dma-mask" property, use the default one (32bit) */
  108. dma_mask = dma_get_mask(dev);
  109. }
  110. ret = dma_set_mask(dev, dma_mask);
  111. if (ret) {
  112. dev_err(dev, "%s failed to set dma mask\n", __func__);
  113. return ret;
  114. }
  115. /* Put any vendor related code:
  116. * get clock domain, voltage regulator, set clock rate, etc */
  117. return 0;
  118. }
  119. /* return platform global heaps */
  120. void vha_plat_dt_get_heaps(struct heap_config **heap_configs, int *num_heaps)
  121. {
  122. *heap_configs = example_heap_configs;
  123. *num_heaps = sizeof(example_heap_configs)/sizeof(struct heap_config);
  124. }
  125. void vha_plat_dt_hw_destroy(struct platform_device *pdev)
  126. {
  127. /* Put any vendor related code:
  128. * put clock domain, voltage regulator, etc */
  129. }
  130. int vha_plat_dt_hw_suspend(struct platform_device *pdev)
  131. {
  132. /* This is the place where vendor specific code shall be called:
  133. * eg. turn off voltage regulator/disable power domain */
  134. return 0;
  135. }
  136. int vha_plat_dt_hw_resume(struct platform_device *pdev)
  137. {
  138. /* This is the place where vendor specific code shall be called:
  139. * eg. turn on voltage regulator/enable power domain */
  140. return 0;
  141. }
  142. MODULE_DEVICE_TABLE(of, vha_plat_dt_of_ids);