Home | History | Annotate | Line # | Download | only in marvell
      1 /*	$NetBSD: mvsoc_intr.c,v 1.9 2014/02/22 16:14:38 martin 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.9 2014/02/22 16:14:38 martin Exp $");
     30 
     31 #include "opt_mvsoc.h"
     32 
     33 #define _INTR_PRIVATE
     34 
     35 #include <sys/param.h>
     36 #include <sys/proc.h>
     37 
     38 #include <machine/intr.h>
     39 
     40 #include <arm/armreg.h>
     41 #include <arm/cpu.h>
     42 #include <arm/pic/picvar.h>
     43 #include <arm/marvell/mvsocreg.h>
     44 #include <arm/marvell/mvsocvar.h>
     45 
     46 
     47 int (*find_pending_irqs)(void);
     48 
     49 static void mvsoc_bridge_pic_unblock_irqs(struct pic_softc *, size_t, uint32_t);
     50 static void mvsoc_bridge_pic_block_irqs(struct pic_softc *, size_t, uint32_t);
     51 static int mvsoc_bridge_pic_find_pending_irqs(struct pic_softc *);
     52 static void mvsoc_bridge_pic_establish_irq(struct pic_softc *,
     53 					   struct intrsource *);
     54 static void mvsoc_bridge_pic_source_name(struct pic_softc *, int, char *,
     55 					 size_t);
     56 
     57 static const char * const sources[] = {
     58     "CPUSelfInt",      "CPUTimer0IntReq", "CPUTimer1IntReq", "CPUWDTimerIntReq",
     59     "AccessErr",       "Bit64Err",
     60 };
     61 
     62 static struct pic_ops mvsoc_bridge_picops = {
     63 	.pic_unblock_irqs = mvsoc_bridge_pic_unblock_irqs,
     64 	.pic_block_irqs = mvsoc_bridge_pic_block_irqs,
     65 	.pic_find_pending_irqs = mvsoc_bridge_pic_find_pending_irqs,
     66 	.pic_establish_irq = mvsoc_bridge_pic_establish_irq,
     67 	.pic_source_name = mvsoc_bridge_pic_source_name,
     68 };
     69 
     70 struct pic_softc mvsoc_bridge_pic = {
     71 	.pic_ops = &mvsoc_bridge_picops,
     72 	.pic_maxsources = MVSOC_MLMB_MLMBI_NIRQ,
     73 	.pic_name = "mvsoc_bridge",
     74 };
     75 
     76 
     77 void
     78 mvsoc_irq_handler(void *frame)
     79 {
     80 	struct cpu_info * const ci = curcpu();
     81 	const int oldipl = ci->ci_cpl;
     82 	const uint32_t oldipl_mask = __BIT(oldipl);
     83 	int ipl_mask = 0;
     84 
     85 	ci->ci_data.cpu_nintr++;
     86 
     87 	ipl_mask = find_pending_irqs();
     88 
     89 	/*
     90 	 * Record the pending_ipls and deliver them if we can.
     91 	 */
     92 	if ((ipl_mask & ~oldipl_mask) > oldipl_mask)
     93 		pic_do_pending_ints(I32_bit, oldipl, frame);
     94 }
     95 
     96 /*
     97  * Mbus-L to Mbus bridge
     98  */
     99 
    100 void *
    101 mvsoc_bridge_intr_establish(int ih, int ipl, int (*ih_func)(void *), void *arg)
    102 {
    103 
    104 	return intr_establish(mvsoc_bridge_pic.pic_irqbase + ih, ipl,
    105 	    IST_LEVEL_HIGH, ih_func, arg);
    106 }
    107 
    108 /* ARGSUSED */
    109 static void
    110 mvsoc_bridge_pic_unblock_irqs(struct pic_softc *pic, size_t irqbase,
    111 			      uint32_t irq_mask)
    112 {
    113 
    114 	write_mlmbreg(MVSOC_MLMB_MLMBICR,
    115 	    read_mlmbreg(MVSOC_MLMB_MLMBICR) & ~irq_mask);
    116 	write_mlmbreg(MVSOC_MLMB_MLMBIMR,
    117 	    read_mlmbreg(MVSOC_MLMB_MLMBIMR) | irq_mask);
    118 }
    119 
    120 /* ARGSUSED */
    121 static void
    122 mvsoc_bridge_pic_block_irqs(struct pic_softc *pic, size_t irqbase,
    123 			    uint32_t irq_mask)
    124 {
    125 
    126 	write_mlmbreg(MVSOC_MLMB_MLMBIMR,
    127 	    read_mlmbreg(MVSOC_MLMB_MLMBIMR) & ~irq_mask);
    128 }
    129 
    130 static int
    131 mvsoc_bridge_pic_find_pending_irqs(struct pic_softc *pic)
    132 {
    133 	uint32_t pending;
    134 
    135 	pending =
    136 	    read_mlmbreg(MVSOC_MLMB_MLMBICR) & read_mlmbreg(MVSOC_MLMB_MLMBIMR);
    137 
    138 	if (pending == 0)
    139 		return 0;
    140 
    141 	return pic_mark_pending_sources(pic, 0, pending);
    142 }
    143 
    144 /* ARGSUSED */
    145 static void
    146 mvsoc_bridge_pic_establish_irq(struct pic_softc *pic, struct intrsource *is)
    147 {
    148 	/* Nothing */
    149 }
    150 
    151 static void
    152 mvsoc_bridge_pic_source_name(struct pic_softc *pic, int irq, char *buf,
    153 			     size_t len)
    154 {
    155 
    156 	strlcpy(buf, sources[irq], len);
    157 }
    158