xrp_address_map.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * xrp_address_map: CPU->DSP physical address translator
  3. *
  4. * Copyright (c) 2017 Cadence Design Systems, Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  21. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. * Alternatively you can use and distribute this file under the terms of
  26. * the GNU General Public License version 2 or later.
  27. */
  28. #ifndef XRP_ADDRESS_MAP_H
  29. #define XRP_ADDRESS_MAP_H
  30. #include <linux/types.h>
  31. #define XRP_NO_TRANSLATION ((u32)~0ul)
  32. struct xrp_address_map_entry {
  33. phys_addr_t src_addr;
  34. u32 dst_addr;
  35. u32 size;
  36. };
  37. struct xrp_address_map {
  38. unsigned n;
  39. struct xrp_address_map_entry *entry;
  40. };
  41. int xrp_init_address_map(struct device *dev,
  42. struct xrp_address_map *map);
  43. void xrp_free_address_map(struct xrp_address_map *map);
  44. struct xrp_address_map_entry *
  45. xrp_get_address_mapping(const struct xrp_address_map *map, phys_addr_t addr);
  46. u32 xrp_translate_to_dsp(const struct xrp_address_map *map, phys_addr_t addr);
  47. phys_addr_t xrp_translate_dsp_to_host(const struct xrp_address_map *map,u32 addr);
  48. static inline int xrp_compare_address(phys_addr_t addr,
  49. const struct xrp_address_map_entry *entry)
  50. {
  51. if (addr < entry->src_addr)
  52. return -1;
  53. if (addr - entry->src_addr < entry->size)
  54. return 0;
  55. return 1;
  56. }
  57. static inline int xrp_compare_dev_address(phys_addr_t addr,
  58. const struct xrp_address_map_entry *entry)
  59. {
  60. if (addr < entry->dst_addr)
  61. return -1;
  62. if (addr - entry->dst_addr < entry->size)
  63. return 0;
  64. return 1;
  65. }
  66. #endif