0005-MIPS-ralink-add-illegal-access-driver.patch 3.1 KB

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