tegra264.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2025, NVIDIA CORPORATION. All rights reserved.
  4. */
  5. #include <dt-bindings/memory/nvidia,tegra264.h>
  6. #include <linux/interconnect.h>
  7. #include <linux/of_device.h>
  8. #include <linux/tegra-icc.h>
  9. #include <soc/tegra/bpmp.h>
  10. #include <soc/tegra/mc.h>
  11. #include "mc.h"
  12. #include "tegra264-bwmgr.h"
  13. /*
  14. * MC Client entries are sorted in the increasing order of the
  15. * override and security register offsets.
  16. */
  17. static const struct tegra_mc_client tegra264_mc_clients[] = {
  18. {
  19. .id = TEGRA264_MEMORY_CLIENT_HDAR,
  20. .name = "hdar",
  21. .bpmp_id = TEGRA264_BWMGR_HDA,
  22. .type = TEGRA_ICC_ISO_AUDIO,
  23. }, {
  24. .id = TEGRA264_MEMORY_CLIENT_HDAW,
  25. .name = "hdaw",
  26. .bpmp_id = TEGRA264_BWMGR_HDA,
  27. .type = TEGRA_ICC_ISO_AUDIO,
  28. }, {
  29. .id = TEGRA264_MEMORY_CLIENT_MGBE0R,
  30. .name = "mgbe0r",
  31. .bpmp_id = TEGRA264_BWMGR_EQOS,
  32. .type = TEGRA_ICC_NISO,
  33. }, {
  34. .id = TEGRA264_MEMORY_CLIENT_MGBE0W,
  35. .name = "mgbe0w",
  36. .bpmp_id = TEGRA264_BWMGR_EQOS,
  37. .type = TEGRA_ICC_NISO,
  38. }, {
  39. .id = TEGRA264_MEMORY_CLIENT_MGBE1R,
  40. .name = "mgbe1r",
  41. .bpmp_id = TEGRA264_BWMGR_EQOS,
  42. .type = TEGRA_ICC_NISO,
  43. }, {
  44. .id = TEGRA264_MEMORY_CLIENT_MGBE1W,
  45. .name = "mgbe1w",
  46. .bpmp_id = TEGRA264_BWMGR_EQOS,
  47. .type = TEGRA_ICC_NISO,
  48. }, {
  49. .id = TEGRA264_MEMORY_CLIENT_SDMMC0R,
  50. .name = "sdmmc0r",
  51. .bpmp_id = TEGRA264_BWMGR_SDMMC_1,
  52. .type = TEGRA_ICC_NISO,
  53. }, {
  54. .id = TEGRA264_MEMORY_CLIENT_SDMMC0W,
  55. .name = "sdmmc0w",
  56. .bpmp_id = TEGRA264_BWMGR_SDMMC_1,
  57. .type = TEGRA_ICC_NISO,
  58. }, {
  59. .id = TEGRA264_MEMORY_CLIENT_VICR,
  60. .name = "vicr",
  61. .bpmp_id = TEGRA264_BWMGR_VIC,
  62. .type = TEGRA_ICC_NISO,
  63. }, {
  64. .id = TEGRA264_MEMORY_CLIENT_VICW,
  65. .name = "vicw",
  66. .bpmp_id = TEGRA264_BWMGR_VIC,
  67. .type = TEGRA_ICC_NISO,
  68. }, {
  69. .id = TEGRA264_MEMORY_CLIENT_APER,
  70. .name = "aper",
  71. .bpmp_id = TEGRA264_BWMGR_APE,
  72. .type = TEGRA_ICC_ISO_AUDIO,
  73. }, {
  74. .id = TEGRA264_MEMORY_CLIENT_APEW,
  75. .name = "apew",
  76. .bpmp_id = TEGRA264_BWMGR_APE,
  77. .type = TEGRA_ICC_ISO_AUDIO,
  78. }, {
  79. .id = TEGRA264_MEMORY_CLIENT_APEDMAR,
  80. .name = "apedmar",
  81. .bpmp_id = TEGRA264_BWMGR_APEDMA,
  82. .type = TEGRA_ICC_ISO_AUDIO,
  83. }, {
  84. .id = TEGRA264_MEMORY_CLIENT_APEDMAW,
  85. .name = "apedmaw",
  86. .bpmp_id = TEGRA264_BWMGR_APEDMA,
  87. .type = TEGRA_ICC_ISO_AUDIO,
  88. }, {
  89. .id = TEGRA264_MEMORY_CLIENT_VIFALCONR,
  90. .name = "vifalconr",
  91. .bpmp_id = TEGRA264_BWMGR_VIFAL,
  92. .type = TEGRA_ICC_ISO_VIFAL,
  93. }, {
  94. .id = TEGRA264_MEMORY_CLIENT_VIFALCONW,
  95. .name = "vifalconw",
  96. .bpmp_id = TEGRA264_BWMGR_VIFAL,
  97. .type = TEGRA_ICC_ISO_VIFAL,
  98. }, {
  99. .id = TEGRA264_MEMORY_CLIENT_RCER,
  100. .name = "rcer",
  101. .bpmp_id = TEGRA264_BWMGR_RCE,
  102. .type = TEGRA_ICC_NISO,
  103. }, {
  104. .id = TEGRA264_MEMORY_CLIENT_RCEW,
  105. .name = "rcew",
  106. .bpmp_id = TEGRA264_BWMGR_RCE,
  107. .type = TEGRA_ICC_NISO,
  108. }, {
  109. .id = TEGRA264_MEMORY_CLIENT_PCIE0W,
  110. .name = "pcie0w",
  111. .bpmp_id = TEGRA264_BWMGR_PCIE_0,
  112. .type = TEGRA_ICC_NISO,
  113. }, {
  114. .id = TEGRA264_MEMORY_CLIENT_PCIE1R,
  115. .name = "pcie1r",
  116. .bpmp_id = TEGRA264_BWMGR_PCIE_1,
  117. .type = TEGRA_ICC_NISO,
  118. }, {
  119. .id = TEGRA264_MEMORY_CLIENT_PCIE1W,
  120. .name = "pcie1w",
  121. .bpmp_id = TEGRA264_BWMGR_PCIE_1,
  122. .type = TEGRA_ICC_NISO,
  123. }, {
  124. .id = TEGRA264_MEMORY_CLIENT_PCIE2AR,
  125. .name = "pcie2ar",
  126. .bpmp_id = TEGRA264_BWMGR_PCIE_2,
  127. .type = TEGRA_ICC_NISO,
  128. }, {
  129. .id = TEGRA264_MEMORY_CLIENT_PCIE2AW,
  130. .name = "pcie2aw",
  131. .bpmp_id = TEGRA264_BWMGR_PCIE_2,
  132. .type = TEGRA_ICC_NISO,
  133. }, {
  134. .id = TEGRA264_MEMORY_CLIENT_PCIE3R,
  135. .name = "pcie3r",
  136. .bpmp_id = TEGRA264_BWMGR_PCIE_3,
  137. .type = TEGRA_ICC_NISO,
  138. }, {
  139. .id = TEGRA264_MEMORY_CLIENT_PCIE3W,
  140. .name = "pcie3w",
  141. .bpmp_id = TEGRA264_BWMGR_PCIE_3,
  142. .type = TEGRA_ICC_NISO,
  143. }, {
  144. .id = TEGRA264_MEMORY_CLIENT_PCIE4R,
  145. .name = "pcie4r",
  146. .bpmp_id = TEGRA264_BWMGR_PCIE_4,
  147. .type = TEGRA_ICC_NISO,
  148. }, {
  149. .id = TEGRA264_MEMORY_CLIENT_PCIE4W,
  150. .name = "pcie4w",
  151. .bpmp_id = TEGRA264_BWMGR_PCIE_4,
  152. .type = TEGRA_ICC_NISO,
  153. }, {
  154. .id = TEGRA264_MEMORY_CLIENT_PCIE5R,
  155. .name = "pcie5r",
  156. .bpmp_id = TEGRA264_BWMGR_PCIE_5,
  157. .type = TEGRA_ICC_NISO,
  158. }, {
  159. .id = TEGRA264_MEMORY_CLIENT_PCIE5W,
  160. .name = "pcie5w",
  161. .bpmp_id = TEGRA264_BWMGR_PCIE_5,
  162. .type = TEGRA_ICC_NISO,
  163. }, {
  164. .id = TEGRA264_MEMORY_CLIENT_GPUR02MC,
  165. .name = "gpur02mc",
  166. .bpmp_id = TEGRA264_BWMGR_GPU,
  167. .type = TEGRA_ICC_NISO,
  168. }, {
  169. .id = TEGRA264_MEMORY_CLIENT_GPUW02MC,
  170. .name = "gpuw02mc",
  171. .bpmp_id = TEGRA264_BWMGR_GPU,
  172. .type = TEGRA_ICC_NISO,
  173. }, {
  174. .id = TEGRA264_MEMORY_CLIENT_NVDECSRD2MC,
  175. .name = "nvdecsrd2mc",
  176. .bpmp_id = TEGRA264_BWMGR_NVDEC,
  177. .type = TEGRA_ICC_NISO,
  178. }, {
  179. .id = TEGRA264_MEMORY_CLIENT_NVDECSWR2MC,
  180. .name = "nvdecswr2mc",
  181. .bpmp_id = TEGRA264_BWMGR_NVDEC,
  182. .type = TEGRA_ICC_NISO,
  183. },
  184. };
  185. /*
  186. * tegra264_mc_icc_set() - Pass MC client info to the BPMP-FW
  187. * @src: ICC node for Memory Controller's (MC) Client
  188. * @dst: ICC node for Memory Controller (MC)
  189. *
  190. * Passing the current request info from the MC to the BPMP-FW where
  191. * LA and PTSA registers are accessed and the final EMC freq is set
  192. * based on client_id, type, latency and bandwidth.
  193. * icc_set_bw() makes set_bw calls for both MC and EMC providers in
  194. * sequence. Both the calls are protected by 'mutex_lock(&icc_lock)'.
  195. * So, the data passed won't be updated by concurrent set calls from
  196. * other clients.
  197. */
  198. static int tegra264_mc_icc_set(struct icc_node *src, struct icc_node *dst)
  199. {
  200. struct tegra_mc *mc = icc_provider_to_tegra_mc(dst->provider);
  201. struct mrq_bwmgr_int_request bwmgr_req = { 0 };
  202. struct mrq_bwmgr_int_response bwmgr_resp = { 0 };
  203. const struct tegra_mc_client *pclient = src->data;
  204. struct tegra_bpmp_message msg;
  205. int ret;
  206. /*
  207. * Same Src and Dst node will happen during boot from icc_node_add().
  208. * This can be used to pre-initialize and set bandwidth for all clients
  209. * before their drivers are loaded. We are skipping this case as for us,
  210. * the pre-initialization already happened in Bootloader(MB2) and BPMP-FW.
  211. */
  212. if (src->id == dst->id)
  213. return 0;
  214. if (!mc->bwmgr_mrq_supported)
  215. return 0;
  216. if (!mc->bpmp) {
  217. dev_err(mc->dev, "BPMP reference NULL\n");
  218. return -ENOENT;
  219. }
  220. if (pclient->type == TEGRA_ICC_NISO)
  221. bwmgr_req.bwmgr_calc_set_req.niso_bw = src->avg_bw;
  222. else
  223. bwmgr_req.bwmgr_calc_set_req.iso_bw = src->avg_bw;
  224. bwmgr_req.bwmgr_calc_set_req.client_id = pclient->bpmp_id;
  225. bwmgr_req.cmd = CMD_BWMGR_INT_CALC_AND_SET;
  226. bwmgr_req.bwmgr_calc_set_req.mc_floor = src->peak_bw;
  227. bwmgr_req.bwmgr_calc_set_req.floor_unit = BWMGR_INT_UNIT_KBPS;
  228. memset(&msg, 0, sizeof(msg));
  229. msg.mrq = MRQ_BWMGR_INT;
  230. msg.tx.data = &bwmgr_req;
  231. msg.tx.size = sizeof(bwmgr_req);
  232. msg.rx.data = &bwmgr_resp;
  233. msg.rx.size = sizeof(bwmgr_resp);
  234. ret = tegra_bpmp_transfer(mc->bpmp, &msg);
  235. if (ret < 0) {
  236. dev_err(mc->dev, "BPMP transfer failed: %d\n", ret);
  237. goto error;
  238. }
  239. if (msg.rx.ret < 0) {
  240. pr_err("failed to set bandwidth for %u: %d\n",
  241. bwmgr_req.bwmgr_calc_set_req.client_id, msg.rx.ret);
  242. ret = -EINVAL;
  243. }
  244. error:
  245. return ret;
  246. }
  247. static int tegra264_mc_icc_aggregate(struct icc_node *node, u32 tag, u32 avg_bw,
  248. u32 peak_bw, u32 *agg_avg, u32 *agg_peak)
  249. {
  250. struct icc_provider *p = node->provider;
  251. struct tegra_mc *mc = icc_provider_to_tegra_mc(p);
  252. if (!mc->bwmgr_mrq_supported)
  253. return 0;
  254. *agg_avg += avg_bw;
  255. *agg_peak = max(*agg_peak, peak_bw);
  256. return 0;
  257. }
  258. static int tegra264_mc_icc_get_init_bw(struct icc_node *node, u32 *avg, u32 *peak)
  259. {
  260. *avg = 0;
  261. *peak = 0;
  262. return 0;
  263. }
  264. static const struct tegra_mc_icc_ops tegra264_mc_icc_ops = {
  265. .xlate = tegra_mc_icc_xlate,
  266. .aggregate = tegra264_mc_icc_aggregate,
  267. .get_bw = tegra264_mc_icc_get_init_bw,
  268. .set = tegra264_mc_icc_set,
  269. };
  270. const struct tegra_mc_soc tegra264_mc_soc = {
  271. .num_clients = ARRAY_SIZE(tegra264_mc_clients),
  272. .clients = tegra264_mc_clients,
  273. .num_address_bits = 40,
  274. .num_channels = 16,
  275. .client_id_mask = 0x1ff,
  276. .intmask = MC_INT_DECERR_ROUTE_SANITY |
  277. MC_INT_DECERR_GENERALIZED_CARVEOUT | MC_INT_DECERR_MTS |
  278. MC_INT_SECERR_SEC | MC_INT_DECERR_VPR |
  279. MC_INT_SECURITY_VIOLATION | MC_INT_DECERR_EMEM,
  280. .has_addr_hi_reg = true,
  281. .ops = &tegra186_mc_ops,
  282. .icc_ops = &tegra264_mc_icc_ops,
  283. .ch_intmask = 0x0000ff00,
  284. .global_intstatus_channel_shift = 8,
  285. /*
  286. * Additionally, there are lite carveouts but those are not currently
  287. * supported.
  288. */
  289. .num_carveouts = 32,
  290. };