18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * IRQ domain support for SH INTC subsystem
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2012  Paul Mundt
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
78c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
88c2ecf20Sopenharmony_ci * for more details.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci#define pr_fmt(fmt) "intc: " fmt
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/irqdomain.h>
138c2ecf20Sopenharmony_ci#include <linux/sh_intc.h>
148c2ecf20Sopenharmony_ci#include <linux/export.h>
158c2ecf20Sopenharmony_ci#include "internals.h"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/**
188c2ecf20Sopenharmony_ci * intc_irq_domain_evt_xlate() - Generic xlate for vectored IRQs.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci * This takes care of exception vector to hwirq translation through
218c2ecf20Sopenharmony_ci * by way of evt2irq() translation.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * Note: For platforms that use a flat vector space without INTEVT this
248c2ecf20Sopenharmony_ci * basically just mimics irq_domain_xlate_onecell() by way of a nopped
258c2ecf20Sopenharmony_ci * out evt2irq() implementation.
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_cistatic int intc_evt_xlate(struct irq_domain *d, struct device_node *ctrlr,
288c2ecf20Sopenharmony_ci			  const u32 *intspec, unsigned int intsize,
298c2ecf20Sopenharmony_ci			  unsigned long *out_hwirq, unsigned int *out_type)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	if (WARN_ON(intsize < 1))
328c2ecf20Sopenharmony_ci		return -EINVAL;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	*out_hwirq = evt2irq(intspec[0]);
358c2ecf20Sopenharmony_ci	*out_type = IRQ_TYPE_NONE;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	return 0;
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic const struct irq_domain_ops intc_evt_ops = {
418c2ecf20Sopenharmony_ci	.xlate		= intc_evt_xlate,
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_civoid __init intc_irq_domain_init(struct intc_desc_int *d,
458c2ecf20Sopenharmony_ci				 struct intc_hw_desc *hw)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	unsigned int irq_base, irq_end;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	/*
508c2ecf20Sopenharmony_ci	 * Quick linear revmap check
518c2ecf20Sopenharmony_ci	 */
528c2ecf20Sopenharmony_ci	irq_base = evt2irq(hw->vectors[0].vect);
538c2ecf20Sopenharmony_ci	irq_end = evt2irq(hw->vectors[hw->nr_vectors - 1].vect);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	/*
568c2ecf20Sopenharmony_ci	 * Linear domains have a hard-wired assertion that IRQs start at
578c2ecf20Sopenharmony_ci	 * 0 in order to make some performance optimizations. Lamely
588c2ecf20Sopenharmony_ci	 * restrict the linear case to these conditions here, taking the
598c2ecf20Sopenharmony_ci	 * tree penalty for linear cases with non-zero hwirq bases.
608c2ecf20Sopenharmony_ci	 */
618c2ecf20Sopenharmony_ci	if (irq_base == 0 && irq_end == (irq_base + hw->nr_vectors - 1))
628c2ecf20Sopenharmony_ci		d->domain = irq_domain_add_linear(NULL, hw->nr_vectors,
638c2ecf20Sopenharmony_ci						  &intc_evt_ops, NULL);
648c2ecf20Sopenharmony_ci	else
658c2ecf20Sopenharmony_ci		d->domain = irq_domain_add_tree(NULL, &intc_evt_ops, NULL);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	BUG_ON(!d->domain);
688c2ecf20Sopenharmony_ci}
69