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