userimask.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/sysdev.h>
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <asm/sizes.h>
  16. #include "internals.h"
  17. static void __iomem *uimask;
  18. static ssize_t
  19. show_intc_userimask(struct sysdev_class *cls,
  20. struct sysdev_class_attribute *attr, char *buf)
  21. {
  22. return sprintf(buf, "%d\n", (__raw_readl(uimask) >> 4) & 0xf);
  23. }
  24. static ssize_t
  25. store_intc_userimask(struct sysdev_class *cls,
  26. struct sysdev_class_attribute *attr,
  27. const char *buf, size_t count)
  28. {
  29. unsigned long level;
  30. level = simple_strtoul(buf, NULL, 10);
  31. /*
  32. * Minimal acceptable IRQ levels are in the 2 - 16 range, but
  33. * these are chomped so as to not interfere with normal IRQs.
  34. *
  35. * Level 1 is a special case on some CPUs in that it's not
  36. * directly settable, but given that USERIMASK cuts off below a
  37. * certain level, we don't care about this limitation here.
  38. * Level 0 on the other hand equates to user masking disabled.
  39. *
  40. * We use the default priority level as a cut off so that only
  41. * special case opt-in IRQs can be mangled.
  42. */
  43. if (level >= intc_get_dfl_prio_level())
  44. return -EINVAL;
  45. __raw_writel(0xa5 << 24 | level << 4, uimask);
  46. return count;
  47. }
  48. static SYSDEV_CLASS_ATTR(userimask, S_IRUSR | S_IWUSR,
  49. show_intc_userimask, store_intc_userimask);
  50. static int __init userimask_sysdev_init(void)
  51. {
  52. if (unlikely(!uimask))
  53. return -ENXIO;
  54. return sysdev_class_create_file(&intc_sysdev_class, &attr_userimask);
  55. }
  56. late_initcall(userimask_sysdev_init);
  57. int register_intc_userimask(unsigned long addr)
  58. {
  59. if (unlikely(uimask))
  60. return -EBUSY;
  61. uimask = ioremap_nocache(addr, SZ_4K);
  62. if (unlikely(!uimask))
  63. return -ENOMEM;
  64. pr_info("userimask support registered for levels 0 -> %d\n",
  65. intc_get_dfl_prio_level() - 1);
  66. return 0;
  67. }