Home | History | Annotate | Line # | Download | only in marvell
mvsoc_intr.c revision 1.5.2.1
      1  1.5.2.1       tls /*	$NetBSD: mvsoc_intr.c,v 1.5.2.1 2013/06/23 06:20:00 tls 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.5.2.1       tls __KERNEL_RCSID(0, "$NetBSD: mvsoc_intr.c,v 1.5.2.1 2013/06/23 06:20:00 tls 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.5.2.1       tls #include "opt_mvsoc.h"
     44  1.5.2.1       tls 
     45  1.5.2.1       tls #if defined(ARMADAXP)
     46  1.5.2.1       tls extern void armadaxp_handle_irq(void *);
     47  1.5.2.1       tls #endif
     48  1.5.2.1       tls 
     49      1.5      matt int (*find_pending_irqs)(void);
     50      1.1  kiyohara 
     51      1.1  kiyohara static void mvsoc_bridge_pic_unblock_irqs(struct pic_softc *, size_t, uint32_t);
     52      1.1  kiyohara static void mvsoc_bridge_pic_block_irqs(struct pic_softc *, size_t, uint32_t);
     53      1.1  kiyohara static int mvsoc_bridge_pic_find_pending_irqs(struct pic_softc *);
     54      1.1  kiyohara static void mvsoc_bridge_pic_establish_irq(struct pic_softc *,
     55      1.1  kiyohara 					   struct intrsource *);
     56      1.1  kiyohara static void mvsoc_bridge_pic_source_name(struct pic_softc *, int, char *,
     57      1.1  kiyohara 					 size_t);
     58      1.1  kiyohara 
     59      1.1  kiyohara static const char * const sources[] = {
     60      1.1  kiyohara     "CPUSelfInt",      "CPUTimer0IntReq", "CPUTimer1IntReq", "CPUWDTimerIntReq",
     61      1.1  kiyohara     "AccessErr",       "Bit64Err",
     62      1.1  kiyohara };
     63      1.1  kiyohara 
     64      1.1  kiyohara static struct pic_ops mvsoc_bridge_picops = {
     65      1.1  kiyohara 	.pic_unblock_irqs = mvsoc_bridge_pic_unblock_irqs,
     66      1.1  kiyohara 	.pic_block_irqs = mvsoc_bridge_pic_block_irqs,
     67      1.1  kiyohara 	.pic_find_pending_irqs = mvsoc_bridge_pic_find_pending_irqs,
     68      1.1  kiyohara 	.pic_establish_irq = mvsoc_bridge_pic_establish_irq,
     69      1.1  kiyohara 	.pic_source_name = mvsoc_bridge_pic_source_name,
     70      1.1  kiyohara };
     71      1.1  kiyohara 
     72      1.1  kiyohara struct pic_softc mvsoc_bridge_pic = {
     73      1.1  kiyohara 	.pic_ops = &mvsoc_bridge_picops,
     74      1.1  kiyohara 	.pic_maxsources = MVSOC_MLMB_MLMBI_NIRQ,
     75      1.1  kiyohara 	.pic_name = "mvsoc_bridge",
     76      1.1  kiyohara };
     77      1.1  kiyohara 
     78      1.1  kiyohara 
     79      1.1  kiyohara void
     80      1.1  kiyohara mvsoc_irq_handler(void *frame)
     81      1.1  kiyohara {
     82      1.1  kiyohara 	struct cpu_info * const ci = curcpu();
     83  1.5.2.1       tls #if defined(ARMADAXP)
     84  1.5.2.1       tls 	ci->ci_data.cpu_nintr++;
     85  1.5.2.1       tls 	armadaxp_handle_irq(frame);
     86  1.5.2.1       tls #else
     87      1.1  kiyohara 	const int oldipl = ci->ci_cpl;
     88      1.1  kiyohara 	const uint32_t oldipl_mask = __BIT(oldipl);
     89      1.1  kiyohara 	int ipl_mask = 0;
     90      1.1  kiyohara 
     91      1.2      matt 	ci->ci_data.cpu_nintr++;
     92      1.1  kiyohara 
     93      1.1  kiyohara 	ipl_mask = find_pending_irqs();
     94      1.1  kiyohara 
     95      1.1  kiyohara 	/*
     96      1.1  kiyohara 	 * Record the pending_ipls and deliver them if we can.
     97      1.1  kiyohara 	 */
     98      1.1  kiyohara 	if ((ipl_mask & ~oldipl_mask) > oldipl_mask)
     99      1.1  kiyohara 		pic_do_pending_ints(I32_bit, oldipl, frame);
    100  1.5.2.1       tls #endif
    101      1.1  kiyohara }
    102      1.1  kiyohara 
    103      1.1  kiyohara /*
    104      1.1  kiyohara  * Mbus-L to Mbus bridge
    105      1.1  kiyohara  */
    106      1.1  kiyohara 
    107      1.1  kiyohara void *
    108      1.1  kiyohara mvsoc_bridge_intr_establish(int ih, int ipl, int (*ih_func)(void *), void *arg)
    109      1.1  kiyohara {
    110      1.1  kiyohara 
    111      1.4  jakllsch 	return intr_establish(mvsoc_bridge_pic.pic_irqbase + ih, ipl,
    112      1.4  jakllsch 	    IST_LEVEL_HIGH, ih_func, arg);
    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_unblock_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_MLMBICR,
    122      1.1  kiyohara 	    read_mlmbreg(MVSOC_MLMB_MLMBICR) & ~irq_mask);
    123      1.1  kiyohara 	write_mlmbreg(MVSOC_MLMB_MLMBIMR,
    124      1.1  kiyohara 	    read_mlmbreg(MVSOC_MLMB_MLMBIMR) | irq_mask);
    125      1.1  kiyohara }
    126      1.1  kiyohara 
    127      1.1  kiyohara /* ARGSUSED */
    128      1.1  kiyohara static void
    129      1.1  kiyohara mvsoc_bridge_pic_block_irqs(struct pic_softc *pic, size_t irqbase,
    130      1.1  kiyohara 			    uint32_t irq_mask)
    131      1.1  kiyohara {
    132      1.1  kiyohara 
    133      1.1  kiyohara 	write_mlmbreg(MVSOC_MLMB_MLMBIMR,
    134      1.1  kiyohara 	    read_mlmbreg(MVSOC_MLMB_MLMBIMR) & ~irq_mask);
    135      1.1  kiyohara }
    136      1.1  kiyohara 
    137      1.1  kiyohara static int
    138      1.1  kiyohara mvsoc_bridge_pic_find_pending_irqs(struct pic_softc *pic)
    139      1.1  kiyohara {
    140      1.1  kiyohara 	uint32_t pending;
    141      1.1  kiyohara 
    142      1.1  kiyohara 	pending =
    143      1.1  kiyohara 	    read_mlmbreg(MVSOC_MLMB_MLMBICR) & read_mlmbreg(MVSOC_MLMB_MLMBIMR);
    144      1.3  jakllsch 
    145      1.1  kiyohara 	if (pending == 0)
    146      1.1  kiyohara 		return 0;
    147      1.3  jakllsch 
    148      1.3  jakllsch 	return pic_mark_pending_sources(pic, 0, pending);
    149      1.1  kiyohara }
    150      1.1  kiyohara 
    151      1.1  kiyohara /* ARGSUSED */
    152      1.1  kiyohara static void
    153      1.1  kiyohara mvsoc_bridge_pic_establish_irq(struct pic_softc *pic, struct intrsource *is)
    154      1.1  kiyohara {
    155      1.1  kiyohara 	/* Nothing */
    156      1.1  kiyohara }
    157      1.1  kiyohara 
    158      1.1  kiyohara static void
    159      1.1  kiyohara mvsoc_bridge_pic_source_name(struct pic_softc *pic, int irq, char *buf,
    160      1.1  kiyohara 			     size_t len)
    161      1.1  kiyohara {
    162      1.1  kiyohara 
    163      1.1  kiyohara 	strlcpy(buf, sources[irq], len);
    164      1.1  kiyohara }
    165