Skip to content

Commit 43b8774

Browse files
committed
sh: intc: userimask support.
This adds support for hardware-assisted userspace irq masking for special priority levels. Due to the SR.IMASK interactivity, only some platforms implement this in hardware (including but not limited to SH-4A interrupt controllers, and ARM-based SH-Mobile CPUs). Each CPU needs to wire this up on its own, for now only SH7786 is wired up as an example. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 12129fe commit 43b8774

5 files changed

Lines changed: 94 additions & 2 deletions

File tree

‎arch/sh/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,8 @@ config GUSA_RB
732732
LLSC, this should be more efficient than the other alternative of
733733
disabling interrupts around the atomic sequence.
734734

735+
source "drivers/sh/Kconfig"
736+
735737
endmenu
736738

737739
menu "Boot options"

‎arch/sh/kernel/cpu/sh4a/setup-sh7786.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/mm.h>
2222
#include <linux/dma-mapping.h>
2323
#include <linux/sh_timer.h>
24+
#include <linux/sh_intc.h>
2425
#include <cpu/dma-register.h>
2526
#include <asm/mmzone.h>
2627
#include <asm/dmaengine.h>
@@ -907,6 +908,7 @@ static DECLARE_INTC_DESC(intc_desc_irl4567, "sh7786-irl4567", vectors_irl4567,
907908
#define INTC_INTMSK2 INTMSK2
908909
#define INTC_INTMSKCLR1 CnINTMSKCLR1
909910
#define INTC_INTMSKCLR2 INTMSKCLR2
911+
#define INTC_USERIMASK 0xfe411000
910912

911913
void __init plat_irq_setup(void)
912914
{
@@ -921,6 +923,7 @@ void __init plat_irq_setup(void)
921923
__raw_writel(__raw_readl(INTC_ICR0) & ~0x00c00000, INTC_ICR0);
922924

923925
register_intc_controller(&intc_desc);
926+
register_intc_userimask(INTC_USERIMASK);
924927
}
925928

926929
void __init plat_irq_setup_pins(int mode)

‎drivers/sh/Kconfig‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
config INTC_USERIMASK
2+
bool "Userspace interrupt masking support"
3+
depends on ARCH_SHMOBILE || (SUPERH && CPU_SH4A)
4+
help
5+
This enables support for hardware-assisted userspace hardirq
6+
masking.
7+
8+
SH-4A and newer interrupt blocks all support a special shadowed
9+
page with all non-masking registers obscured when mapped in to
10+
userspace. This is primarily for use by userspace device
11+
drivers that are using special priority levels.
12+
13+
If in doubt, say N.

‎drivers/sh/intc.c‎

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/topology.h>
2828
#include <linux/bitmap.h>
2929
#include <linux/cpumask.h>
30+
#include <asm/sizes.h>
3031

3132
#define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \
3233
((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \
@@ -94,7 +95,8 @@ static DEFINE_SPINLOCK(vector_lock);
9495
#define SMP_NR(d, x) 1
9596
#endif
9697

97-
static unsigned int intc_prio_level[NR_IRQS]; /* for now */
98+
static unsigned int intc_prio_level[NR_IRQS]; /* for now */
99+
static unsigned int default_prio_level = 2; /* 2 - 16 */
98100
static unsigned long ack_handle[NR_IRQS];
99101

100102
static inline struct intc_desc_int *get_intc_desc(unsigned int irq)
@@ -787,7 +789,7 @@ static void __init intc_register_irq(struct intc_desc *desc,
787789
/* set priority level
788790
* - this needs to be at least 2 for 5-bit priorities on 7780
789791
*/
790-
intc_prio_level[irq] = 2;
792+
intc_prio_level[irq] = default_prio_level;
791793

792794
/* enable secondary masking method if present */
793795
if (data[!primary])
@@ -1037,6 +1039,64 @@ int __init register_intc_controller(struct intc_desc *desc)
10371039
return -ENOMEM;
10381040
}
10391041

1042+
#ifdef CONFIG_INTC_USERIMASK
1043+
static void __iomem *uimask;
1044+
1045+
int register_intc_userimask(unsigned long addr)
1046+
{
1047+
if (unlikely(uimask))
1048+
return -EBUSY;
1049+
1050+
uimask = ioremap_nocache(addr, SZ_4K);
1051+
if (unlikely(!uimask))
1052+
return -ENOMEM;
1053+
1054+
pr_info("intc: userimask support registered for levels 0 -> %d\n",
1055+
default_prio_level - 1);
1056+
1057+
return 0;
1058+
}
1059+
1060+
static ssize_t
1061+
show_intc_userimask(struct sysdev_class *cls,
1062+
struct sysdev_class_attribute *attr, char *buf)
1063+
{
1064+
return sprintf(buf, "%d\n", (__raw_readl(uimask) >> 4) & 0xf);
1065+
}
1066+
1067+
static ssize_t
1068+
store_intc_userimask(struct sysdev_class *cls,
1069+
struct sysdev_class_attribute *attr,
1070+
const char *buf, size_t count)
1071+
{
1072+
unsigned long level;
1073+
1074+
level = simple_strtoul(buf, NULL, 10);
1075+
1076+
/*
1077+
* Minimal acceptable IRQ levels are in the 2 - 16 range, but
1078+
* these are chomped so as to not interfere with normal IRQs.
1079+
*
1080+
* Level 1 is a special case on some CPUs in that it's not
1081+
* directly settable, but given that USERIMASK cuts off below a
1082+
* certain level, we don't care about this limitation here.
1083+
* Level 0 on the other hand equates to user masking disabled.
1084+
*
1085+
* We use default_prio_level as a cut off so that only special
1086+
* case opt-in IRQs can be mangled.
1087+
*/
1088+
if (level >= default_prio_level)
1089+
return -EINVAL;
1090+
1091+
__raw_writel(0xa5 << 24 | level << 4, uimask);
1092+
1093+
return count;
1094+
}
1095+
1096+
static SYSDEV_CLASS_ATTR(userimask, S_IRUSR | S_IWUSR,
1097+
show_intc_userimask, store_intc_userimask);
1098+
#endif
1099+
10401100
static ssize_t
10411101
show_intc_name(struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
10421102
{
@@ -1108,6 +1168,11 @@ static int __init register_intc_sysdevs(void)
11081168
int id = 0;
11091169

11101170
error = sysdev_class_register(&intc_sysdev_class);
1171+
#ifdef CONFIG_INTC_USERIMASK
1172+
if (!error && uimask)
1173+
error = sysdev_class_create_file(&intc_sysdev_class,
1174+
&attr_userimask);
1175+
#endif
11111176
if (!error) {
11121177
list_for_each_entry(d, &intc_list, list) {
11131178
d->sysdev.id = id;

‎include/linux/sh_intc.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ struct intc_desc symbol __initdata = { \
9999
int __init register_intc_controller(struct intc_desc *desc);
100100
int intc_set_priority(unsigned int irq, unsigned int prio);
101101

102+
#ifdef CONFIG_INTC_USERIMASK
103+
int register_intc_userimask(unsigned long addr);
104+
#else
105+
static inline int register_intc_userimask(unsigned long addr)
106+
{
107+
return 0;
108+
}
109+
#endif
110+
102111
int reserve_irq_vector(unsigned int irq);
103112
void reserve_irq_legacy(void);
104113

0 commit comments

Comments
 (0)