xref: /OK3568_Linux_fs/kernel/drivers/sh/intc/irqdomain.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * IRQ domain support for SH INTC subsystem
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (C) 2012  Paul Mundt
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * This file is subject to the terms and conditions of the GNU General Public
7*4882a593Smuzhiyun  * License.  See the file "COPYING" in the main directory of this archive
8*4882a593Smuzhiyun  * for more details.
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun #define pr_fmt(fmt) "intc: " fmt
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/irqdomain.h>
13*4882a593Smuzhiyun #include <linux/sh_intc.h>
14*4882a593Smuzhiyun #include <linux/export.h>
15*4882a593Smuzhiyun #include "internals.h"
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /**
18*4882a593Smuzhiyun  * intc_irq_domain_evt_xlate() - Generic xlate for vectored IRQs.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * This takes care of exception vector to hwirq translation through
21*4882a593Smuzhiyun  * by way of evt2irq() translation.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * Note: For platforms that use a flat vector space without INTEVT this
24*4882a593Smuzhiyun  * basically just mimics irq_domain_xlate_onecell() by way of a nopped
25*4882a593Smuzhiyun  * out evt2irq() implementation.
26*4882a593Smuzhiyun  */
intc_evt_xlate(struct irq_domain * d,struct device_node * ctrlr,const u32 * intspec,unsigned int intsize,unsigned long * out_hwirq,unsigned int * out_type)27*4882a593Smuzhiyun static int intc_evt_xlate(struct irq_domain *d, struct device_node *ctrlr,
28*4882a593Smuzhiyun 			  const u32 *intspec, unsigned int intsize,
29*4882a593Smuzhiyun 			  unsigned long *out_hwirq, unsigned int *out_type)
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun 	if (WARN_ON(intsize < 1))
32*4882a593Smuzhiyun 		return -EINVAL;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun 	*out_hwirq = evt2irq(intspec[0]);
35*4882a593Smuzhiyun 	*out_type = IRQ_TYPE_NONE;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	return 0;
38*4882a593Smuzhiyun }
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun static const struct irq_domain_ops intc_evt_ops = {
41*4882a593Smuzhiyun 	.xlate		= intc_evt_xlate,
42*4882a593Smuzhiyun };
43*4882a593Smuzhiyun 
intc_irq_domain_init(struct intc_desc_int * d,struct intc_hw_desc * hw)44*4882a593Smuzhiyun void __init intc_irq_domain_init(struct intc_desc_int *d,
45*4882a593Smuzhiyun 				 struct intc_hw_desc *hw)
46*4882a593Smuzhiyun {
47*4882a593Smuzhiyun 	unsigned int irq_base, irq_end;
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun 	/*
50*4882a593Smuzhiyun 	 * Quick linear revmap check
51*4882a593Smuzhiyun 	 */
52*4882a593Smuzhiyun 	irq_base = evt2irq(hw->vectors[0].vect);
53*4882a593Smuzhiyun 	irq_end = evt2irq(hw->vectors[hw->nr_vectors - 1].vect);
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 	/*
56*4882a593Smuzhiyun 	 * Linear domains have a hard-wired assertion that IRQs start at
57*4882a593Smuzhiyun 	 * 0 in order to make some performance optimizations. Lamely
58*4882a593Smuzhiyun 	 * restrict the linear case to these conditions here, taking the
59*4882a593Smuzhiyun 	 * tree penalty for linear cases with non-zero hwirq bases.
60*4882a593Smuzhiyun 	 */
61*4882a593Smuzhiyun 	if (irq_base == 0 && irq_end == (irq_base + hw->nr_vectors - 1))
62*4882a593Smuzhiyun 		d->domain = irq_domain_add_linear(NULL, hw->nr_vectors,
63*4882a593Smuzhiyun 						  &intc_evt_ops, NULL);
64*4882a593Smuzhiyun 	else
65*4882a593Smuzhiyun 		d->domain = irq_domain_add_tree(NULL, &intc_evt_ops, NULL);
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	BUG_ON(!d->domain);
68*4882a593Smuzhiyun }
69