12be6bb0cSPaul Mundt /* 22be6bb0cSPaul Mundt * Support for hardware-assisted userspace interrupt masking. 32be6bb0cSPaul Mundt * 42be6bb0cSPaul Mundt * Copyright (C) 2010 Paul Mundt 52be6bb0cSPaul Mundt * 62be6bb0cSPaul Mundt * This file is subject to the terms and conditions of the GNU General Public 72be6bb0cSPaul Mundt * License. See the file "COPYING" in the main directory of this archive 82be6bb0cSPaul Mundt * for more details. 92be6bb0cSPaul Mundt */ 102be6bb0cSPaul Mundt #define pr_fmt(fmt) "intc: " fmt 112be6bb0cSPaul Mundt 122be6bb0cSPaul Mundt #include <linux/errno.h> 13f4e73bfcSKay Sievers #include <linux/device.h> 142be6bb0cSPaul Mundt #include <linux/init.h> 152be6bb0cSPaul Mundt #include <linux/io.h> 16a102a088SNobuhiro Iwamatsu #include <linux/stat.h> 1787dfb311SMasahiro Yamada #include <linux/sizes.h> 182be6bb0cSPaul Mundt #include "internals.h" 192be6bb0cSPaul Mundt 202be6bb0cSPaul Mundt static void __iomem *uimask; 212be6bb0cSPaul Mundt 222be6bb0cSPaul Mundt static ssize_t 23f4e73bfcSKay Sievers show_intc_userimask(struct device *dev, 24f4e73bfcSKay Sievers struct device_attribute *attr, char *buf) 252be6bb0cSPaul Mundt { 262be6bb0cSPaul Mundt return sprintf(buf, "%d\n", (__raw_readl(uimask) >> 4) & 0xf); 272be6bb0cSPaul Mundt } 282be6bb0cSPaul Mundt 292be6bb0cSPaul Mundt static ssize_t 30f4e73bfcSKay Sievers store_intc_userimask(struct device *dev, 31f4e73bfcSKay Sievers struct device_attribute *attr, 322be6bb0cSPaul Mundt const char *buf, size_t count) 332be6bb0cSPaul Mundt { 342be6bb0cSPaul Mundt unsigned long level; 352be6bb0cSPaul Mundt 362be6bb0cSPaul Mundt level = simple_strtoul(buf, NULL, 10); 372be6bb0cSPaul Mundt 382be6bb0cSPaul Mundt /* 392be6bb0cSPaul Mundt * Minimal acceptable IRQ levels are in the 2 - 16 range, but 402be6bb0cSPaul Mundt * these are chomped so as to not interfere with normal IRQs. 412be6bb0cSPaul Mundt * 422be6bb0cSPaul Mundt * Level 1 is a special case on some CPUs in that it's not 432be6bb0cSPaul Mundt * directly settable, but given that USERIMASK cuts off below a 442be6bb0cSPaul Mundt * certain level, we don't care about this limitation here. 452be6bb0cSPaul Mundt * Level 0 on the other hand equates to user masking disabled. 462be6bb0cSPaul Mundt * 472be6bb0cSPaul Mundt * We use the default priority level as a cut off so that only 482be6bb0cSPaul Mundt * special case opt-in IRQs can be mangled. 492be6bb0cSPaul Mundt */ 502be6bb0cSPaul Mundt if (level >= intc_get_dfl_prio_level()) 512be6bb0cSPaul Mundt return -EINVAL; 522be6bb0cSPaul Mundt 532be6bb0cSPaul Mundt __raw_writel(0xa5 << 24 | level << 4, uimask); 542be6bb0cSPaul Mundt 552be6bb0cSPaul Mundt return count; 562be6bb0cSPaul Mundt } 572be6bb0cSPaul Mundt 58f4e73bfcSKay Sievers static DEVICE_ATTR(userimask, S_IRUSR | S_IWUSR, 592be6bb0cSPaul Mundt show_intc_userimask, store_intc_userimask); 602be6bb0cSPaul Mundt 612be6bb0cSPaul Mundt 622be6bb0cSPaul Mundt static int __init userimask_sysdev_init(void) 632be6bb0cSPaul Mundt { 64*93c42c0bSGreg Kroah-Hartman struct device *dev_root; 65*93c42c0bSGreg Kroah-Hartman int ret = 0; 66*93c42c0bSGreg Kroah-Hartman 672be6bb0cSPaul Mundt if (unlikely(!uimask)) 682be6bb0cSPaul Mundt return -ENXIO; 692be6bb0cSPaul Mundt 70*93c42c0bSGreg Kroah-Hartman dev_root = bus_get_dev_root(&intc_subsys); 71*93c42c0bSGreg Kroah-Hartman if (dev_root) { 72*93c42c0bSGreg Kroah-Hartman ret = device_create_file(dev_root, &dev_attr_userimask); 73*93c42c0bSGreg Kroah-Hartman put_device(dev_root); 74*93c42c0bSGreg Kroah-Hartman } 75*93c42c0bSGreg Kroah-Hartman return ret; 762be6bb0cSPaul Mundt } 772be6bb0cSPaul Mundt late_initcall(userimask_sysdev_init); 782be6bb0cSPaul Mundt 792be6bb0cSPaul Mundt int register_intc_userimask(unsigned long addr) 802be6bb0cSPaul Mundt { 812be6bb0cSPaul Mundt if (unlikely(uimask)) 822be6bb0cSPaul Mundt return -EBUSY; 832be6bb0cSPaul Mundt 844bdc0d67SChristoph Hellwig uimask = ioremap(addr, SZ_4K); 852be6bb0cSPaul Mundt if (unlikely(!uimask)) 862be6bb0cSPaul Mundt return -ENOMEM; 872be6bb0cSPaul Mundt 882be6bb0cSPaul Mundt pr_info("userimask support registered for levels 0 -> %d\n", 892be6bb0cSPaul Mundt intc_get_dfl_prio_level() - 1); 902be6bb0cSPaul Mundt 912be6bb0cSPaul Mundt return 0; 922be6bb0cSPaul Mundt } 93