Skip to content

Commit dc825b1

Browse files
committed
sh: intc: IRQ auto-distribution support.
This implements support for hardware-managed IRQ balancing as implemented by SH-X3 cores (presently only hooked up for SH7786, but can probably be carried over to other SH-X3 cores, too). CPUs need to specify their distribution register along with the mask definitions, as these follow the same format. Peripheral IRQs that don't opt out of balancing will be automatically distributed at the whim of the hardware block, while each CPU needs to verify whether it is handling the IRQ or not, especially before clearing the mask. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent fecf066 commit dc825b1

6 files changed

Lines changed: 244 additions & 79 deletions

File tree

‎arch/sh/include/asm/irq.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
#define NR_IRQS 256
1212
#define NR_IRQS_LEGACY 8 /* Legacy external IRQ0-7 */
1313

14+
/*
15+
* This is a special IRQ number for indicating that no IRQ has been
16+
* triggered and to simply ignore the IRQ dispatch. This is a special
17+
* case that can happen with IRQ auto-distribution when multiple CPUs
18+
* are woken up and signalled in parallel.
19+
*/
20+
#define NO_IRQ_IGNORE ((unsigned int)-1)
21+
1422
/*
1523
* Convert back and forth between INTEVT and IRQ values.
1624
*/
@@ -53,6 +61,14 @@ extern void irq_ctx_exit(int cpu);
5361
# define irq_ctx_exit(cpu) do { } while (0)
5462
#endif
5563

64+
#ifdef CONFIG_INTC_BALANCING
65+
extern unsigned int irq_lookup(unsigned int irq);
66+
extern void irq_finish(unsigned int irq);
67+
#else
68+
#define irq_lookup(irq) (irq)
69+
#define irq_finish(irq) do { } while (0)
70+
#endif
71+
5672
#include <asm-generic/irq.h>
5773
#ifdef CONFIG_CPU_SH5
5874
#include <cpu/irq.h>

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,14 @@ static struct platform_device *sh7786_devices[] __initdata = {
573573
&usb_ohci_device,
574574
};
575575

576-
577576
/*
578577
* Please call this function if your platform board
579578
* use external clock for USB
580579
* */
581580
#define USBCTL0 0xffe70858
582581
#define CLOCK_MODE_MASK 0xffffff7f
583582
#define EXT_CLOCK_MODE 0x00000080
583+
584584
void __init sh7786_usb_use_exclock(void)
585585
{
586586
u32 val = __raw_readl(USBCTL0) & CLOCK_MODE_MASK;
@@ -598,6 +598,7 @@ void __init sh7786_usb_use_exclock(void)
598598
#define PLL_ENB 0x00000002
599599
#define PHY_RST 0x00000004
600600
#define ACT_PLL_STATUS 0xc0000000
601+
601602
static void __init sh7786_usb_setup(void)
602603
{
603604
int i = 1000000;
@@ -753,9 +754,19 @@ static struct intc_vect vectors[] __initdata = {
753754
#define INTMSK2 0xfe410068
754755
#define INTMSKCLR2 0xfe41006c
755756

757+
#define INTDISTCR0 0xfe4100b0
758+
#define INTDISTCR1 0xfe4100b4
759+
#define INTACK 0xfe4100b8
760+
#define INTACKCLR 0xfe4100bc
761+
#define INT2DISTCR0 0xfe410900
762+
#define INT2DISTCR1 0xfe410904
763+
#define INT2DISTCR2 0xfe410908
764+
#define INT2DISTCR3 0xfe41090c
765+
756766
static struct intc_mask_reg mask_registers[] __initdata = {
757767
{ CnINTMSK0, CnINTMSKCLR0, 32,
758-
{ IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7 } },
768+
{ IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7 },
769+
INTC_SMP_BALANCING(INTDISTCR0) },
759770
{ INTMSK2, INTMSKCLR2, 32,
760771
{ IRL0_LLLL, IRL0_LLLH, IRL0_LLHL, IRL0_LLHH,
761772
IRL0_LHLL, IRL0_LHLH, IRL0_LHHL, IRL0_LHHH,
@@ -767,7 +778,8 @@ static struct intc_mask_reg mask_registers[] __initdata = {
767778
IRL4_HHLL, IRL4_HHLH, IRL4_HHHL, 0, } },
768779
{ CnINT2MSKR0, CnINT2MSKCR0 , 32,
769780
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
770-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, WDT } },
781+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, WDT },
782+
INTC_SMP_BALANCING(INT2DISTCR0) },
771783
{ CnINT2MSKR1, CnINT2MSKCR1, 32,
772784
{ TMU0_0, TMU0_1, TMU0_2, TMU0_3, TMU1_0, TMU1_1, TMU1_2, 0,
773785
DMAC0_0, DMAC0_1, DMAC0_2, DMAC0_3, DMAC0_4, DMAC0_5, DMAC0_6,
@@ -776,14 +788,14 @@ static struct intc_mask_reg mask_registers[] __initdata = {
776788
HPB_0, HPB_1, HPB_2,
777789
SCIF0_0, SCIF0_1, SCIF0_2, SCIF0_3,
778790
SCIF1,
779-
TMU2, TMU3, 0, } },
791+
TMU2, TMU3, 0, }, INTC_SMP_BALANCING(INT2DISTCR1) },
780792
{ CnINT2MSKR2, CnINT2MSKCR2, 32,
781793
{ 0, 0, SCIF2, SCIF3, SCIF4, SCIF5,
782794
Eth_0, Eth_1,
783795
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
784796
PCIeC0_0, PCIeC0_1, PCIeC0_2,
785797
PCIeC1_0, PCIeC1_1, PCIeC1_2,
786-
USB, 0, 0 } },
798+
USB, 0, 0 }, INTC_SMP_BALANCING(INT2DISTCR2) },
787799
{ CnINT2MSKR3, CnINT2MSKCR3, 32,
788800
{ 0, 0, 0, 0, 0, 0,
789801
I2C0, I2C1,
@@ -792,7 +804,7 @@ static struct intc_mask_reg mask_registers[] __initdata = {
792804
HAC0, HAC1,
793805
FLCTL, 0,
794806
HSPI, GPIO0, GPIO1, Thermal,
795-
0, 0, 0, 0, 0, 0, 0, 0 } },
807+
0, 0, 0, 0, 0, 0, 0, 0 }, INTC_SMP_BALANCING(INT2DISTCR3) },
796808
};
797809

798810
static struct intc_prio_reg prio_registers[] __initdata = {
@@ -910,6 +922,18 @@ static DECLARE_INTC_DESC(intc_desc_irl4567, "sh7786-irl4567", vectors_irl4567,
910922
#define INTC_INTMSKCLR2 INTMSKCLR2
911923
#define INTC_USERIMASK 0xfe411000
912924

925+
#ifdef CONFIG_INTC_BALANCING
926+
unsigned int irq_lookup(unsigned int irq)
927+
{
928+
return __raw_readl(INTACK) & 1 ? irq : NO_IRQ_IGNORE;
929+
}
930+
931+
void irq_finish(unsigned int irq)
932+
{
933+
__raw_writel(irq2evt(irq), INTACKCLR);
934+
}
935+
#endif
936+
913937
void __init plat_irq_setup(void)
914938
{
915939
/* disable IRQ3-0 + IRQ7-4 */

‎arch/sh/kernel/irq.c‎

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,14 @@ union irq_ctx {
113113

114114
static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
115115
static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
116-
#endif
117116

118-
asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
117+
static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
118+
static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
119+
120+
static inline void handle_one_irq(unsigned int irq)
119121
{
120-
struct pt_regs *old_regs = set_irq_regs(regs);
121-
#ifdef CONFIG_IRQSTACKS
122122
union irq_ctx *curctx, *irqctx;
123-
#endif
124-
125-
irq_enter();
126-
irq = irq_demux(irq);
127123

128-
#ifdef CONFIG_IRQSTACKS
129124
curctx = (union irq_ctx *)current_thread_info();
130125
irqctx = hardirq_ctx[smp_processor_id()];
131126

@@ -164,20 +159,9 @@ asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
164159
"r5", "r6", "r7", "r8", "t", "pr"
165160
);
166161
} else
167-
#endif
168162
generic_handle_irq(irq);
169-
170-
irq_exit();
171-
172-
set_irq_regs(old_regs);
173-
return 1;
174163
}
175164

176-
#ifdef CONFIG_IRQSTACKS
177-
static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
178-
179-
static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
180-
181165
/*
182166
* allocate per-cpu stacks for hardirq and for softirq processing
183167
*/
@@ -257,8 +241,33 @@ asmlinkage void do_softirq(void)
257241

258242
local_irq_restore(flags);
259243
}
244+
#else
245+
static inline void handle_one_irq(unsigned int irq)
246+
{
247+
generic_handle_irq(irq);
248+
}
260249
#endif
261250

251+
asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
252+
{
253+
struct pt_regs *old_regs = set_irq_regs(regs);
254+
255+
irq_enter();
256+
257+
irq = irq_demux(irq_lookup(irq));
258+
259+
if (irq != NO_IRQ_IGNORE) {
260+
handle_one_irq(irq);
261+
irq_finish(irq);
262+
}
263+
264+
irq_exit();
265+
266+
set_irq_regs(old_regs);
267+
268+
return IRQ_HANDLED;
269+
}
270+
262271
void __init init_IRQ(void)
263272
{
264273
plat_irq_setup();

‎drivers/sh/Kconfig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ config INTC_USERIMASK
1111
drivers that are using special priority levels.
1212

1313
If in doubt, say N.
14+
15+
config INTC_BALANCING
16+
bool "Hardware IRQ balancing support"
17+
depends on SMP && SUPERH && CPU_SUBTYPE_SH7786
18+
help
19+
This enables support for IRQ auto-distribution mode on SH-X3
20+
SMP parts. All of the balancing and CPU wakeup decisions are
21+
taken care of automatically by hardware for distributed
22+
vectors.
23+
24+
If in doubt, say N.

0 commit comments

Comments
 (0)