userimask.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Support for hardware-assisted userspace interrupt masking.
  3. *
  4. * Copyright (C) 2010 Paul Mundt
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #define pr_fmt(fmt) "intc: " fmt
  11. #include <linux/errno.h>
  12. #include <linux/device.h>
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <linux/stat.h>
  16. #include <linux/sizes.h>
  17. #include "internals.h"
  18. static void __iomem *uimask;
  19. static ssize_t
  20. show_intc_userimask(struct device *dev,
  21. struct device_attribute *attr, char *buf)
  22. {
  23. return sprintf(buf, "%d\n", (__raw_readl(uimask) >> 4) & 0xf);
  24. }
  25. static ssize_t
  26. store_intc_userimask(struct device *dev,
  27. struct device_attribute *attr,
  28. const char *buf, size_t count)
  29. {
  30. unsigned long level;
  31. int ret;
  32. ret = kstrtoul(buf, 10, &level);
  33. if (ret != 0)
  34. return ret;
  35. /*
  36. * Minimal acceptable IRQ levels are in the 2 - 16 range, but
  37. * these are chomped so as to not interfere with normal IRQs.
  38. *
  39. * Level 1 is a special case on some CPUs in that it's not
  40. * directly settable, but given that USERIMASK cuts off below a
  41. * certain level, we don't care about this limitation here.
  42. * Level 0 on the other hand equates to user masking disabled.
  43. *
  44. * We use the default priority level as a cut off so that only
  45. * special case opt-in IRQs can be mangled.
  46. */
  47. if (level >= intc_get_dfl_prio_level())
  48. return -EINVAL;
  49. __raw_writel(0xa5 << 24 | level << 4, uimask);
  50. return count;
  51. }
  52. static DEVICE_ATTR(userimask, S_IRUSR | S_IWUSR,
  53. show_intc_userimask, store_intc_userimask);
  54. static int __init userimask_sysdev_init(void)
  55. {
  56. struct device *dev_root;
  57. int ret = 0;
  58. if (unlikely(!uimask))
  59. return -ENXIO;
  60. dev_root = bus_get_dev_root(&intc_subsys);
  61. if (dev_root) {
  62. ret = device_create_file(dev_root, &dev_attr_userimask);
  63. put_device(dev_root);
  64. }
  65. return ret;
  66. }
  67. late_initcall(userimask_sysdev_init);
  68. int register_intc_userimask(unsigned long addr)
  69. {
  70. if (unlikely(uimask))
  71. return -EBUSY;
  72. uimask = ioremap(addr, SZ_4K);
  73. if (unlikely(!uimask))
  74. return -ENOMEM;
  75. pr_info("userimask support registered for levels 0 -> %d\n",
  76. intc_get_dfl_prio_level() - 1);
  77. return 0;
  78. }