ipa_mem.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2019-2024 Linaro Ltd.
  4. */
  5. #ifndef _IPA_MEM_H_
  6. #define _IPA_MEM_H_
  7. #include <linux/types.h>
  8. struct platform_device;
  9. struct ipa;
  10. struct ipa_mem_data;
  11. /**
  12. * DOC: IPA Local Memory
  13. *
  14. * The IPA has a block of shared memory, divided into regions used for
  15. * specific purposes.
  16. *
  17. * The regions within the shared block are bounded by an offset (relative to
  18. * the "ipa-shared" memory range) and size found in the IPA_SHARED_MEM_SIZE
  19. * register.
  20. *
  21. * Each region is optionally preceded by one or more 32-bit "canary" values.
  22. * These are meant to detect out-of-range writes (if they become corrupted).
  23. * A given region (such as a filter or routing table) has the same number
  24. * of canaries for all IPA hardware versions. Still, the number used is
  25. * defined in the config data, allowing for generic handling of regions.
  26. *
  27. * The set of memory regions is defined in configuration data. They are
  28. * subject to these constraints:
  29. * - a zero offset and zero size represents and undefined region
  30. * - a region's size does not include space for its "canary" values
  31. * - a region's offset is defined to be *past* all "canary" values
  32. * - offset must be large enough to account for all canaries
  33. * - a region's size may be zero, but may still have canaries
  34. * - all offsets must be 8-byte aligned
  35. * - most sizes must be a multiple of 8
  36. * - modem memory size must be a multiple of 4
  37. * - the microcontroller ring offset must be a multiple of 1024
  38. */
  39. /* The maximum allowed size for any memory region */
  40. #define IPA_MEM_MAX (2 * PAGE_SIZE)
  41. /* IPA-resident memory region ids */
  42. enum ipa_mem_id {
  43. IPA_MEM_UC_SHARED, /* 0 canaries */
  44. IPA_MEM_UC_INFO, /* 0 canaries */
  45. IPA_MEM_V4_FILTER_HASHED, /* 2 canaries */
  46. IPA_MEM_V4_FILTER, /* 2 canaries */
  47. IPA_MEM_V6_FILTER_HASHED, /* 2 canaries */
  48. IPA_MEM_V6_FILTER, /* 2 canaries */
  49. IPA_MEM_V4_ROUTE_HASHED, /* 2 canaries */
  50. IPA_MEM_V4_ROUTE, /* 2 canaries */
  51. IPA_MEM_V6_ROUTE_HASHED, /* 2 canaries */
  52. IPA_MEM_V6_ROUTE, /* 2 canaries */
  53. IPA_MEM_MODEM_HEADER, /* 2 canaries */
  54. IPA_MEM_AP_HEADER, /* 0 canaries, optional */
  55. IPA_MEM_MODEM_PROC_CTX, /* 2 canaries */
  56. IPA_MEM_AP_PROC_CTX, /* 0 canaries */
  57. IPA_MEM_MODEM, /* 0/2 canaries */
  58. IPA_MEM_UC_EVENT_RING, /* 1 canary, optional */
  59. IPA_MEM_PDN_CONFIG, /* 0/2 canaries (IPA v4.0+) */
  60. IPA_MEM_STATS_QUOTA_MODEM, /* 2/4 canaries (IPA v4.0+) */
  61. IPA_MEM_STATS_QUOTA_AP, /* 0 canaries, optional (IPA v4.0+) */
  62. IPA_MEM_STATS_TETHERING, /* 0 canaries, optional (IPA v4.0+) */
  63. IPA_MEM_STATS_DROP, /* 0 canaries, optional (IPA v4.0+) */
  64. /* The next 7 filter and route statistics regions are optional */
  65. IPA_MEM_STATS_V4_FILTER, /* 0 canaries (IPA v4.0-v4.2) */
  66. IPA_MEM_STATS_V6_FILTER, /* 0 canaries (IPA v4.0-v4.2) */
  67. IPA_MEM_STATS_V4_ROUTE, /* 0 canaries (IPA v4.0-v4.2) */
  68. IPA_MEM_STATS_V6_ROUTE, /* 0 canaries (IPA v4.0-v4.2) */
  69. IPA_MEM_AP_V4_FILTER, /* 2 canaries (IPA v5.0) */
  70. IPA_MEM_AP_V6_FILTER, /* 0 canaries (IPA v5.0) */
  71. IPA_MEM_STATS_FILTER_ROUTE, /* 0 canaries (IPA v4.5+) */
  72. IPA_MEM_NAT_TABLE, /* 4 canaries, optional (IPA v4.5+) */
  73. IPA_MEM_END_MARKER, /* 1 canary (not a real region) */
  74. IPA_MEM_COUNT, /* Number of regions (not an index) */
  75. };
  76. /**
  77. * struct ipa_mem - IPA local memory region description
  78. * @id: memory region identifier
  79. * @offset: offset in IPA memory space to base of the region
  80. * @size: size in bytes base of the region
  81. * @canary_count: Number of 32-bit "canary" values that precede region
  82. */
  83. struct ipa_mem {
  84. enum ipa_mem_id id;
  85. u32 offset;
  86. u16 size;
  87. u16 canary_count;
  88. };
  89. const struct ipa_mem *ipa_mem_find(struct ipa *ipa, enum ipa_mem_id mem_id);
  90. int ipa_mem_config(struct ipa *ipa);
  91. void ipa_mem_deconfig(struct ipa *ipa);
  92. int ipa_mem_setup(struct ipa *ipa); /* No ipa_mem_teardown() needed */
  93. int ipa_mem_zero_modem(struct ipa *ipa);
  94. int ipa_mem_init(struct ipa *ipa, struct platform_device *pdev,
  95. const struct ipa_mem_data *mem_data);
  96. void ipa_mem_exit(struct ipa *ipa);
  97. #endif /* _IPA_MEM_H_ */