tegra20-mc.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Tegra20 Memory Controller
  3. *
  4. * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/ratelimit.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/io.h>
  25. #define DRV_NAME "tegra20-mc"
  26. #define MC_INTSTATUS 0x0
  27. #define MC_INTMASK 0x4
  28. #define MC_INT_ERR_SHIFT 6
  29. #define MC_INT_ERR_MASK (0x1f << MC_INT_ERR_SHIFT)
  30. #define MC_INT_DECERR_EMEM BIT(MC_INT_ERR_SHIFT)
  31. #define MC_INT_INVALID_GART_PAGE BIT(MC_INT_ERR_SHIFT + 1)
  32. #define MC_INT_SECURITY_VIOLATION BIT(MC_INT_ERR_SHIFT + 2)
  33. #define MC_INT_ARBITRATION_EMEM BIT(MC_INT_ERR_SHIFT + 3)
  34. #define MC_GART_ERROR_REQ 0x30
  35. #define MC_DECERR_EMEM_OTHERS_STATUS 0x58
  36. #define MC_SECURITY_VIOLATION_STATUS 0x74
  37. #define SECURITY_VIOLATION_TYPE BIT(30) /* 0=TRUSTZONE, 1=CARVEOUT */
  38. #define MC_CLIENT_ID_MASK 0x3f
  39. #define NUM_MC_REG_BANKS 2
  40. struct tegra20_mc {
  41. void __iomem *regs[NUM_MC_REG_BANKS];
  42. struct device *dev;
  43. };
  44. static inline u32 mc_readl(struct tegra20_mc *mc, u32 offs)
  45. {
  46. u32 val = 0;
  47. if (offs < 0x24)
  48. val = readl(mc->regs[0] + offs);
  49. if (offs < 0x400)
  50. val = readl(mc->regs[1] + offs - 0x3c);
  51. return val;
  52. }
  53. static inline void mc_writel(struct tegra20_mc *mc, u32 val, u32 offs)
  54. {
  55. if (offs < 0x24) {
  56. writel(val, mc->regs[0] + offs);
  57. return;
  58. }
  59. if (offs < 0x400) {
  60. writel(val, mc->regs[1] + offs - 0x3c);
  61. return;
  62. }
  63. }
  64. static const char * const tegra20_mc_client[] = {
  65. "cbr_display0a",
  66. "cbr_display0ab",
  67. "cbr_display0b",
  68. "cbr_display0bb",
  69. "cbr_display0c",
  70. "cbr_display0cb",
  71. "cbr_display1b",
  72. "cbr_display1bb",
  73. "cbr_eppup",
  74. "cbr_g2pr",
  75. "cbr_g2sr",
  76. "cbr_mpeunifbr",
  77. "cbr_viruv",
  78. "csr_avpcarm7r",
  79. "csr_displayhc",
  80. "csr_displayhcb",
  81. "csr_fdcdrd",
  82. "csr_g2dr",
  83. "csr_host1xdmar",
  84. "csr_host1xr",
  85. "csr_idxsrd",
  86. "csr_mpcorer",
  87. "csr_mpe_ipred",
  88. "csr_mpeamemrd",
  89. "csr_mpecsrd",
  90. "csr_ppcsahbdmar",
  91. "csr_ppcsahbslvr",
  92. "csr_texsrd",
  93. "csr_vdebsevr",
  94. "csr_vdember",
  95. "csr_vdemcer",
  96. "csr_vdetper",
  97. "cbw_eppu",
  98. "cbw_eppv",
  99. "cbw_eppy",
  100. "cbw_mpeunifbw",
  101. "cbw_viwsb",
  102. "cbw_viwu",
  103. "cbw_viwv",
  104. "cbw_viwy",
  105. "ccw_g2dw",
  106. "csw_avpcarm7w",
  107. "csw_fdcdwr",
  108. "csw_host1xw",
  109. "csw_ispw",
  110. "csw_mpcorew",
  111. "csw_mpecswr",
  112. "csw_ppcsahbdmaw",
  113. "csw_ppcsahbslvw",
  114. "csw_vdebsevw",
  115. "csw_vdembew",
  116. "csw_vdetpmw",
  117. };
  118. static void tegra20_mc_decode(struct tegra20_mc *mc, int n)
  119. {
  120. u32 addr, req;
  121. const char *client = "Unknown";
  122. int idx, cid;
  123. const struct reg_info {
  124. u32 offset;
  125. u32 write_bit; /* 0=READ, 1=WRITE */
  126. int cid_shift;
  127. char *message;
  128. } reg[] = {
  129. {
  130. .offset = MC_DECERR_EMEM_OTHERS_STATUS,
  131. .write_bit = 31,
  132. .message = "MC_DECERR",
  133. },
  134. {
  135. .offset = MC_GART_ERROR_REQ,
  136. .cid_shift = 1,
  137. .message = "MC_GART_ERR",
  138. },
  139. {
  140. .offset = MC_SECURITY_VIOLATION_STATUS,
  141. .write_bit = 31,
  142. .message = "MC_SECURITY_ERR",
  143. },
  144. };
  145. idx = n - MC_INT_ERR_SHIFT;
  146. if ((idx < 0) || (idx >= ARRAY_SIZE(reg))) {
  147. dev_err_ratelimited(mc->dev, "Unknown interrupt status %08lx\n",
  148. BIT(n));
  149. return;
  150. }
  151. req = mc_readl(mc, reg[idx].offset);
  152. cid = (req >> reg[idx].cid_shift) & MC_CLIENT_ID_MASK;
  153. if (cid < ARRAY_SIZE(tegra20_mc_client))
  154. client = tegra20_mc_client[cid];
  155. addr = mc_readl(mc, reg[idx].offset + sizeof(u32));
  156. dev_err_ratelimited(mc->dev, "%s (0x%08x): 0x%08x %s (%s %s)\n",
  157. reg[idx].message, req, addr, client,
  158. (req & BIT(reg[idx].write_bit)) ? "write" : "read",
  159. (reg[idx].offset == MC_SECURITY_VIOLATION_STATUS) ?
  160. ((req & SECURITY_VIOLATION_TYPE) ?
  161. "carveout" : "trustzone") : "");
  162. }
  163. static const struct of_device_id tegra20_mc_of_match[] __devinitconst = {
  164. { .compatible = "nvidia,tegra20-mc", },
  165. {},
  166. };
  167. static irqreturn_t tegra20_mc_isr(int irq, void *data)
  168. {
  169. u32 stat, mask, bit;
  170. struct tegra20_mc *mc = data;
  171. stat = mc_readl(mc, MC_INTSTATUS);
  172. mask = mc_readl(mc, MC_INTMASK);
  173. mask &= stat;
  174. if (!mask)
  175. return IRQ_NONE;
  176. while ((bit = ffs(mask)) != 0)
  177. tegra20_mc_decode(mc, bit - 1);
  178. mc_writel(mc, stat, MC_INTSTATUS);
  179. return IRQ_HANDLED;
  180. }
  181. static int __devinit tegra20_mc_probe(struct platform_device *pdev)
  182. {
  183. struct resource *irq;
  184. struct tegra20_mc *mc;
  185. int i, err;
  186. u32 intmask;
  187. mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL);
  188. if (!mc)
  189. return -ENOMEM;
  190. mc->dev = &pdev->dev;
  191. for (i = 0; i < ARRAY_SIZE(mc->regs); i++) {
  192. struct resource *res;
  193. res = platform_get_resource(pdev, IORESOURCE_MEM, i);
  194. if (!res)
  195. return -ENODEV;
  196. mc->regs[i] = devm_request_and_ioremap(&pdev->dev, res);
  197. if (!mc->regs[i])
  198. return -EBUSY;
  199. }
  200. irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  201. if (!irq)
  202. return -ENODEV;
  203. err = devm_request_irq(&pdev->dev, irq->start, tegra20_mc_isr,
  204. IRQF_SHARED, dev_name(&pdev->dev), mc);
  205. if (err)
  206. return -ENODEV;
  207. platform_set_drvdata(pdev, mc);
  208. intmask = MC_INT_INVALID_GART_PAGE |
  209. MC_INT_DECERR_EMEM | MC_INT_SECURITY_VIOLATION;
  210. mc_writel(mc, intmask, MC_INTMASK);
  211. return 0;
  212. }
  213. static struct platform_driver tegra20_mc_driver = {
  214. .probe = tegra20_mc_probe,
  215. .driver = {
  216. .name = DRV_NAME,
  217. .owner = THIS_MODULE,
  218. .of_match_table = tegra20_mc_of_match,
  219. },
  220. };
  221. module_platform_driver(tegra20_mc_driver);
  222. MODULE_AUTHOR("Hiroshi DOYU <hdoyu@nvidia.com>");
  223. MODULE_DESCRIPTION("Tegra20 MC driver");
  224. MODULE_LICENSE("GPL v2");
  225. MODULE_ALIAS("platform:" DRV_NAME);