0053-MIPS-ralink-add-illegal-access-driver.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. From 69a5834d0a90588578df9689530fc8f3ab8ef59a Mon Sep 17 00:00:00 2001
  2. From: John Crispin <[email protected]>
  3. Date: Thu, 16 May 2013 23:28:23 +0200
  4. Subject: [PATCH 53/79] MIPS: ralink: add illegal access driver
  5. Signed-off-by: John Crispin <[email protected]>
  6. ---
  7. arch/mips/ralink/Makefile | 2 +-
  8. arch/mips/ralink/ill_acc.c | 87 ++++++++++++++++++++++++++++++++++++++++++++
  9. 2 files changed, 88 insertions(+), 1 deletion(-)
  10. create mode 100644 arch/mips/ralink/ill_acc.c
  11. diff --git a/arch/mips/ralink/Makefile b/arch/mips/ralink/Makefile
  12. index 5fa6129..55a5bfc 100644
  13. --- a/arch/mips/ralink/Makefile
  14. +++ b/arch/mips/ralink/Makefile
  15. @@ -6,7 +6,7 @@
  16. # Copyright (C) 2009-2011 Gabor Juhos <[email protected]>
  17. # Copyright (C) 2013 John Crispin <[email protected]>
  18. -obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o timer.o
  19. +obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o timer.o ill_acc.o
  20. obj-$(CONFIG_SOC_RT288X) += rt288x.o
  21. obj-$(CONFIG_SOC_RT305X) += rt305x.o
  22. diff --git a/arch/mips/ralink/ill_acc.c b/arch/mips/ralink/ill_acc.c
  23. new file mode 100644
  24. index 0000000..4a3f696
  25. --- /dev/null
  26. +++ b/arch/mips/ralink/ill_acc.c
  27. @@ -0,0 +1,87 @@
  28. +/*
  29. + * This program is free software; you can redistribute it and/or modify it
  30. + * under the terms of the GNU General Public License version 2 as published
  31. + * by the Free Software Foundation.
  32. + *
  33. + * Copyright (C) 2013 John Crispin <[email protected]>
  34. + */
  35. +
  36. +#include <linux/interrupt.h>
  37. +#include <linux/of_platform.h>
  38. +#include <linux/of_irq.h>
  39. +
  40. +#include <asm/mach-ralink/ralink_regs.h>
  41. +
  42. +#define REG_ILL_ACC_ADDR 0x10
  43. +#define REG_ILL_ACC_TYPE 0x14
  44. +
  45. +#define ILL_INT_STATUS BIT(31)
  46. +#define ILL_ACC_WRITE BIT(30)
  47. +#define ILL_ACC_LEN_M 0xff
  48. +#define ILL_ACC_OFF_M 0xf
  49. +#define ILL_ACC_OFF_S 16
  50. +#define ILL_ACC_ID_M 0x7
  51. +#define ILL_ACC_ID_S 8
  52. +
  53. +#define DRV_NAME "ill_acc"
  54. +
  55. +static const char *ill_acc_ids[] = {
  56. + "cpu", "dma", "ppe", "pdma rx","pdma tx", "pci/e", "wmac", "usb",
  57. +};
  58. +
  59. +static irqreturn_t ill_acc_irq_handler(int irq, void *_priv)
  60. +{
  61. + struct device *dev = (struct device *) _priv;
  62. + u32 addr = rt_memc_r32(REG_ILL_ACC_ADDR);
  63. + u32 type = rt_memc_r32(REG_ILL_ACC_TYPE);
  64. +
  65. + dev_err(dev, "illegal %s access from %s - addr:0x%08x offset:%d len:%d\n",
  66. + (type & ILL_ACC_WRITE) ? ("write") : ("read"),
  67. + ill_acc_ids[(type >> ILL_ACC_ID_S) & ILL_ACC_ID_M],
  68. + addr, (type >> ILL_ACC_OFF_S) & ILL_ACC_OFF_M,
  69. + type & ILL_ACC_LEN_M);
  70. +
  71. + rt_memc_w32(REG_ILL_ACC_TYPE, REG_ILL_ACC_TYPE);
  72. +
  73. + return IRQ_HANDLED;
  74. +}
  75. +
  76. +static int __init ill_acc_of_setup(void)
  77. +{
  78. + struct platform_device *pdev;
  79. + struct device_node *np;
  80. + int irq;
  81. +
  82. + /* somehow this driver breaks on RT5350 */
  83. + if (of_machine_is_compatible("ralink,rt5350-soc"))
  84. + return -EINVAL;
  85. +
  86. + np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-memc");
  87. + if (!np)
  88. + return -EINVAL;
  89. +
  90. + pdev = of_find_device_by_node(np);
  91. + if (!pdev) {
  92. + pr_err("%s: failed to lookup pdev\n", np->name);
  93. + return -EINVAL;
  94. + }
  95. +
  96. + irq = irq_of_parse_and_map(np, 0);
  97. + if (!irq) {
  98. + dev_err(&pdev->dev, "failed to get irq\n");
  99. + return -EINVAL;
  100. + }
  101. +
  102. + if (request_irq(irq, ill_acc_irq_handler, 0, "ill_acc", &pdev->dev)) {
  103. + dev_err(&pdev->dev, "failed to request irq\n");
  104. + return -EINVAL;
  105. + }
  106. +
  107. + rt_memc_w32(ILL_INT_STATUS, REG_ILL_ACC_TYPE);
  108. +
  109. + dev_info(&pdev->dev, "irq registered\n");
  110. +
  111. + return 0;
  112. +}
  113. +
  114. +arch_initcall(ill_acc_of_setup);
  115. --
  116. 1.7.10.4