0103-MIPS-ralink-add-illegal-access-driver.patch 3.0 KB

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