Home | History | Annotate | Line # | Download | only in marvell
mvsoc_intr.c revision 1.4
      1  1.4  jakllsch /*	$NetBSD: mvsoc_intr.c,v 1.4 2012/07/22 17:14:18 jakllsch Exp $	*/
      2  1.1  kiyohara /*
      3  1.1  kiyohara  * Copyright (c) 2010 KIYOHARA Takashi
      4  1.1  kiyohara  * All rights reserved.
      5  1.1  kiyohara  *
      6  1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
      7  1.1  kiyohara  * modification, are permitted provided that the following conditions
      8  1.1  kiyohara  * are met:
      9  1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     10  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     11  1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     14  1.1  kiyohara  *
     15  1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  1.1  kiyohara  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  1.1  kiyohara  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18  1.1  kiyohara  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     19  1.1  kiyohara  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20  1.1  kiyohara  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21  1.1  kiyohara  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1  kiyohara  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     23  1.1  kiyohara  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     24  1.1  kiyohara  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.1  kiyohara  * POSSIBILITY OF SUCH DAMAGE.
     26  1.1  kiyohara  */
     27  1.1  kiyohara 
     28  1.1  kiyohara #include <sys/cdefs.h>
     29  1.4  jakllsch __KERNEL_RCSID(0, "$NetBSD: mvsoc_intr.c,v 1.4 2012/07/22 17:14:18 jakllsch Exp $");
     30  1.1  kiyohara 
     31  1.1  kiyohara #define _INTR_PRIVATE
     32  1.1  kiyohara 
     33  1.1  kiyohara #include <sys/param.h>
     34  1.1  kiyohara #include <sys/proc.h>
     35  1.1  kiyohara 
     36  1.1  kiyohara #include <machine/intr.h>
     37  1.1  kiyohara 
     38  1.1  kiyohara #include <arm/cpu.h>
     39  1.1  kiyohara #include <arm/pic/picvar.h>
     40  1.1  kiyohara #include <arm/marvell/mvsocreg.h>
     41  1.1  kiyohara #include <arm/marvell/mvsocvar.h>
     42  1.1  kiyohara 
     43  1.1  kiyohara 
     44  1.1  kiyohara static void mvsoc_bridge_pic_unblock_irqs(struct pic_softc *, size_t, uint32_t);
     45  1.1  kiyohara static void mvsoc_bridge_pic_block_irqs(struct pic_softc *, size_t, uint32_t);
     46  1.1  kiyohara static int mvsoc_bridge_pic_find_pending_irqs(struct pic_softc *);
     47  1.1  kiyohara static void mvsoc_bridge_pic_establish_irq(struct pic_softc *,
     48  1.1  kiyohara 					   struct intrsource *);
     49  1.1  kiyohara static void mvsoc_bridge_pic_source_name(struct pic_softc *, int, char *,
     50  1.1  kiyohara 					 size_t);
     51  1.1  kiyohara 
     52  1.1  kiyohara static const char * const sources[] = {
     53  1.1  kiyohara     "CPUSelfInt",      "CPUTimer0IntReq", "CPUTimer1IntReq", "CPUWDTimerIntReq",
     54  1.1  kiyohara     "AccessErr",       "Bit64Err",
     55  1.1  kiyohara };
     56  1.1  kiyohara 
     57  1.1  kiyohara static struct pic_ops mvsoc_bridge_picops = {
     58  1.1  kiyohara 	.pic_unblock_irqs = mvsoc_bridge_pic_unblock_irqs,
     59  1.1  kiyohara 	.pic_block_irqs = mvsoc_bridge_pic_block_irqs,
     60  1.1  kiyohara 	.pic_find_pending_irqs = mvsoc_bridge_pic_find_pending_irqs,
     61  1.1  kiyohara 	.pic_establish_irq = mvsoc_bridge_pic_establish_irq,
     62  1.1  kiyohara 	.pic_source_name = mvsoc_bridge_pic_source_name,
     63  1.1  kiyohara };
     64  1.1  kiyohara 
     65  1.1  kiyohara struct pic_softc mvsoc_bridge_pic = {
     66  1.1  kiyohara 	.pic_ops = &mvsoc_bridge_picops,
     67  1.1  kiyohara 	.pic_maxsources = MVSOC_MLMB_MLMBI_NIRQ,
     68  1.1  kiyohara 	.pic_name = "mvsoc_bridge",
     69  1.1  kiyohara };
     70  1.1  kiyohara 
     71  1.1  kiyohara 
     72  1.1  kiyohara void
     73  1.1  kiyohara mvsoc_irq_handler(void *frame)
     74  1.1  kiyohara {
     75  1.1  kiyohara 	struct cpu_info * const ci = curcpu();
     76  1.1  kiyohara 	const int oldipl = ci->ci_cpl;
     77  1.1  kiyohara 	const uint32_t oldipl_mask = __BIT(oldipl);
     78  1.1  kiyohara 	int ipl_mask = 0;
     79  1.1  kiyohara 
     80  1.2      matt 	ci->ci_data.cpu_nintr++;
     81  1.1  kiyohara 
     82  1.1  kiyohara 	ipl_mask = find_pending_irqs();
     83  1.1  kiyohara 
     84  1.1  kiyohara 	/*
     85  1.1  kiyohara 	 * Record the pending_ipls and deliver them if we can.
     86  1.1  kiyohara 	 */
     87  1.1  kiyohara 	if ((ipl_mask & ~oldipl_mask) > oldipl_mask)
     88  1.1  kiyohara 		pic_do_pending_ints(I32_bit, oldipl, frame);
     89  1.1  kiyohara }
     90  1.1  kiyohara 
     91  1.1  kiyohara /*
     92  1.1  kiyohara  * Mbus-L to Mbus bridge
     93  1.1  kiyohara  */
     94  1.1  kiyohara 
     95  1.1  kiyohara void *
     96  1.1  kiyohara mvsoc_bridge_intr_establish(int ih, int ipl, int (*ih_func)(void *), void *arg)
     97  1.1  kiyohara {
     98  1.1  kiyohara 
     99  1.4  jakllsch 	return intr_establish(mvsoc_bridge_pic.pic_irqbase + ih, ipl,
    100  1.4  jakllsch 	    IST_LEVEL_HIGH, ih_func, arg);
    101  1.1  kiyohara }
    102  1.1  kiyohara 
    103  1.1  kiyohara /* ARGSUSED */
    104  1.1  kiyohara static void
    105  1.1  kiyohara mvsoc_bridge_pic_unblock_irqs(struct pic_softc *pic, size_t irqbase,
    106  1.1  kiyohara 			      uint32_t irq_mask)
    107  1.1  kiyohara {
    108  1.1  kiyohara 
    109  1.1  kiyohara 	write_mlmbreg(MVSOC_MLMB_MLMBICR,
    110  1.1  kiyohara 	    read_mlmbreg(MVSOC_MLMB_MLMBICR) & ~irq_mask);
    111  1.1  kiyohara 	write_mlmbreg(MVSOC_MLMB_MLMBIMR,
    112  1.1  kiyohara 	    read_mlmbreg(MVSOC_MLMB_MLMBIMR) | irq_mask);
    113  1.1  kiyohara }
    114  1.1  kiyohara 
    115  1.1  kiyohara /* ARGSUSED */
    116  1.1  kiyohara static void
    117  1.1  kiyohara mvsoc_bridge_pic_block_irqs(struct pic_softc *pic, size_t irqbase,
    118  1.1  kiyohara 			    uint32_t irq_mask)
    119  1.1  kiyohara {
    120  1.1  kiyohara 
    121  1.1  kiyohara 	write_mlmbreg(MVSOC_MLMB_MLMBIMR,
    122  1.1  kiyohara 	    read_mlmbreg(MVSOC_MLMB_MLMBIMR) & ~irq_mask);
    123  1.1  kiyohara }
    124  1.1  kiyohara 
    125  1.1  kiyohara static int
    126  1.1  kiyohara mvsoc_bridge_pic_find_pending_irqs(struct pic_softc *pic)
    127  1.1  kiyohara {
    128  1.1  kiyohara 	uint32_t pending;
    129  1.1  kiyohara 
    130  1.1  kiyohara 	pending =
    131  1.1  kiyohara 	    read_mlmbreg(MVSOC_MLMB_MLMBICR) & read_mlmbreg(MVSOC_MLMB_MLMBIMR);
    132  1.3  jakllsch 
    133  1.1  kiyohara 	if (pending == 0)
    134  1.1  kiyohara 		return 0;
    135  1.3  jakllsch 
    136  1.3  jakllsch 	return pic_mark_pending_sources(pic, 0, pending);
    137  1.1  kiyohara }
    138  1.1  kiyohara 
    139  1.1  kiyohara /* ARGSUSED */
    140  1.1  kiyohara static void
    141  1.1  kiyohara mvsoc_bridge_pic_establish_irq(struct pic_softc *pic, struct intrsource *is)
    142  1.1  kiyohara {
    143  1.1  kiyohara 	/* Nothing */
    144  1.1  kiyohara }
    145  1.1  kiyohara 
    146  1.1  kiyohara static void
    147  1.1  kiyohara mvsoc_bridge_pic_source_name(struct pic_softc *pic, int irq, char *buf,
    148  1.1  kiyohara 			     size_t len)
    149  1.1  kiyohara {
    150  1.1  kiyohara 
    151  1.1  kiyohara 	strlcpy(buf, sources[irq], len);
    152  1.1  kiyohara }
    153