k3-psil.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
  4. * Author: Peter Ujfalusi <[email protected]>
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/device.h>
  8. #include <linux/init.h>
  9. #include <linux/mutex.h>
  10. #include <linux/of.h>
  11. #include <linux/sys_soc.h>
  12. #include "k3-psil-priv.h"
  13. static DEFINE_MUTEX(ep_map_mutex);
  14. static const struct psil_ep_map *soc_ep_map;
  15. static const struct soc_device_attribute k3_soc_devices[] = {
  16. { .family = "AM65X", .data = &am654_ep_map },
  17. { .family = "J721E", .data = &j721e_ep_map },
  18. { .family = "J7200", .data = &j7200_ep_map },
  19. { .family = "AM64X", .data = &am64_ep_map },
  20. { .family = "J721S2", .data = &j721s2_ep_map },
  21. { .family = "AM62X", .data = &am62_ep_map },
  22. { /* sentinel */ }
  23. };
  24. struct psil_endpoint_config *psil_get_ep_config(u32 thread_id)
  25. {
  26. int i;
  27. mutex_lock(&ep_map_mutex);
  28. if (!soc_ep_map) {
  29. const struct soc_device_attribute *soc;
  30. soc = soc_device_match(k3_soc_devices);
  31. if (soc) {
  32. soc_ep_map = soc->data;
  33. } else {
  34. pr_err("PSIL: No compatible machine found for map\n");
  35. mutex_unlock(&ep_map_mutex);
  36. return ERR_PTR(-ENOTSUPP);
  37. }
  38. pr_debug("%s: Using map for %s\n", __func__, soc_ep_map->name);
  39. }
  40. mutex_unlock(&ep_map_mutex);
  41. if (thread_id & K3_PSIL_DST_THREAD_ID_OFFSET && soc_ep_map->dst) {
  42. /* check in destination thread map */
  43. for (i = 0; i < soc_ep_map->dst_count; i++) {
  44. if (soc_ep_map->dst[i].thread_id == thread_id)
  45. return &soc_ep_map->dst[i].ep_config;
  46. }
  47. }
  48. thread_id &= ~K3_PSIL_DST_THREAD_ID_OFFSET;
  49. if (soc_ep_map->src) {
  50. for (i = 0; i < soc_ep_map->src_count; i++) {
  51. if (soc_ep_map->src[i].thread_id == thread_id)
  52. return &soc_ep_map->src[i].ep_config;
  53. }
  54. }
  55. return ERR_PTR(-ENOENT);
  56. }
  57. EXPORT_SYMBOL_GPL(psil_get_ep_config);
  58. int psil_set_new_ep_config(struct device *dev, const char *name,
  59. struct psil_endpoint_config *ep_config)
  60. {
  61. struct psil_endpoint_config *dst_ep_config;
  62. struct of_phandle_args dma_spec;
  63. u32 thread_id;
  64. int index;
  65. if (!dev || !dev->of_node)
  66. return -EINVAL;
  67. index = of_property_match_string(dev->of_node, "dma-names", name);
  68. if (index < 0)
  69. return index;
  70. if (of_parse_phandle_with_args(dev->of_node, "dmas", "#dma-cells",
  71. index, &dma_spec))
  72. return -ENOENT;
  73. thread_id = dma_spec.args[0];
  74. dst_ep_config = psil_get_ep_config(thread_id);
  75. if (IS_ERR(dst_ep_config)) {
  76. pr_err("PSIL: thread ID 0x%04x not defined in map\n",
  77. thread_id);
  78. of_node_put(dma_spec.np);
  79. return PTR_ERR(dst_ep_config);
  80. }
  81. memcpy(dst_ep_config, ep_config, sizeof(*dst_ep_config));
  82. of_node_put(dma_spec.np);
  83. return 0;
  84. }
  85. EXPORT_SYMBOL_GPL(psil_set_new_ep_config);