Home | History | Annotate | Line # | Download | only in ingenic
intr.c revision 1.1
      1  1.1  macallan /*	$NetBSD: intr.c,v 1.1 2014/12/06 14:26:40 macallan Exp $ */
      2  1.1  macallan 
      3  1.1  macallan /*-
      4  1.1  macallan  * Copyright (c) 2014 Michael Lorenz
      5  1.1  macallan  * All rights reserved.
      6  1.1  macallan  *
      7  1.1  macallan  * Redistribution and use in source and binary forms, with or without
      8  1.1  macallan  * modification, are permitted provided that the following conditions
      9  1.1  macallan  * are met:
     10  1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     11  1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     12  1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  macallan  *    documentation and/or other materials provided with the distribution.
     15  1.1  macallan  *
     16  1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  macallan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  macallan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  macallan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  macallan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  macallan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  macallan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  macallan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  macallan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  macallan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  macallan  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  macallan  */
     28  1.1  macallan 
     29  1.1  macallan #include <sys/cdefs.h>
     30  1.1  macallan __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.1 2014/12/06 14:26:40 macallan Exp $");
     31  1.1  macallan 
     32  1.1  macallan #define __INTR_PRIVATE
     33  1.1  macallan 
     34  1.1  macallan #include <sys/param.h>
     35  1.1  macallan #include <sys/cpu.h>
     36  1.1  macallan #include <sys/device.h>
     37  1.1  macallan #include <sys/kernel.h>
     38  1.1  macallan #include <sys/systm.h>
     39  1.1  macallan #include <sys/timetc.h>
     40  1.1  macallan 
     41  1.1  macallan #include <mips/locore.h>
     42  1.1  macallan #include <machine/intr.h>
     43  1.1  macallan 
     44  1.1  macallan #include <mips/ingenic/ingenic_regs.h>
     45  1.1  macallan 
     46  1.1  macallan extern void ingenic_clockintr(uint32_t);
     47  1.1  macallan extern void ingenic_puts(const char *);
     48  1.1  macallan 
     49  1.1  macallan /*
     50  1.1  macallan  * This is a mask of bits to clear in the SR when we go to a
     51  1.1  macallan  * given hardware interrupt priority level.
     52  1.1  macallan  */
     53  1.1  macallan static const struct ipl_sr_map ingenic_ipl_sr_map = {
     54  1.1  macallan     .sr_bits = {
     55  1.1  macallan 	[IPL_NONE] =		0,
     56  1.1  macallan 	[IPL_SOFTCLOCK] =	MIPS_SOFT_INT_MASK_0,
     57  1.1  macallan 	[IPL_SOFTNET] =		MIPS_SOFT_INT_MASK_0 | MIPS_SOFT_INT_MASK_1,
     58  1.1  macallan 	[IPL_VM] =
     59  1.1  macallan 	    MIPS_SOFT_INT_MASK_0 | MIPS_SOFT_INT_MASK_1 |
     60  1.1  macallan 	    MIPS_INT_MASK_0 |
     61  1.1  macallan 	    MIPS_INT_MASK_3 |
     62  1.1  macallan 	    MIPS_INT_MASK_4 |
     63  1.1  macallan 	    MIPS_INT_MASK_5,
     64  1.1  macallan 	[IPL_SCHED] =
     65  1.1  macallan 	    MIPS_SOFT_INT_MASK_0 | MIPS_SOFT_INT_MASK_1 |
     66  1.1  macallan 	    MIPS_INT_MASK_0 |
     67  1.1  macallan 	    MIPS_INT_MASK_1 |
     68  1.1  macallan 	    MIPS_INT_MASK_2 |
     69  1.1  macallan 	    MIPS_INT_MASK_3 |
     70  1.1  macallan 	    MIPS_INT_MASK_4 |
     71  1.1  macallan 	    MIPS_INT_MASK_5,
     72  1.1  macallan 	[IPL_DDB] =		MIPS_INT_MASK,
     73  1.1  macallan 	[IPL_HIGH] =            MIPS_INT_MASK,
     74  1.1  macallan     },
     75  1.1  macallan };
     76  1.1  macallan 
     77  1.1  macallan //#define INGENIC_DEBUG
     78  1.1  macallan void
     79  1.1  macallan evbmips_intr_init(void)
     80  1.1  macallan {
     81  1.1  macallan 	uint32_t reg;
     82  1.1  macallan 
     83  1.1  macallan 	ipl_sr_map = ingenic_ipl_sr_map;
     84  1.1  macallan 
     85  1.1  macallan 	/* mask all peripheral IRQs */
     86  1.1  macallan 	writereg(JZ_ICMR0, 0xffffffff);
     87  1.1  macallan 	writereg(JZ_ICMR1, 0xffffffff);
     88  1.1  macallan 
     89  1.1  macallan 	/* allow mailbox and peripheral interrupts to core 0 only */
     90  1.1  macallan 	reg = MFC0(12, 4);	/* reset entry and interrupts */
     91  1.1  macallan 	reg &= 0xffff0000;
     92  1.1  macallan 	reg |= REIM_IRQ0_M | REIM_MIRQ0_M | REIM_MIRQ1_M;
     93  1.1  macallan 	MTC0(reg, 12, 4);
     94  1.1  macallan }
     95  1.1  macallan 
     96  1.1  macallan void
     97  1.1  macallan evbmips_iointr(int ipl, vaddr_t pc, uint32_t ipending)
     98  1.1  macallan {
     99  1.1  macallan 	uint32_t id;
    100  1.1  macallan #ifdef INGENIC_DEBUG
    101  1.1  macallan 	char buffer[256];
    102  1.1  macallan 
    103  1.1  macallan 	snprintf(buffer, 256, "pending: %08x CR %08x\n", ipending, MFC0(MIPS_COP_0_CAUSE, 0));
    104  1.1  macallan 	ingenic_puts(buffer);
    105  1.1  macallan #endif
    106  1.1  macallan 	/* see which core we're on */
    107  1.1  macallan 	id = MFC0(15, 1) & 7;
    108  1.1  macallan 
    109  1.1  macallan 	/*
    110  1.1  macallan 	 * XXX
    111  1.1  macallan 	 * the manual counts the softint bits as INT0 and INT1, out headers
    112  1.1  macallan 	 * don't so everything here looks off by two
    113  1.1  macallan 	 */
    114  1.1  macallan 	if (ipending & MIPS_INT_MASK_1) {
    115  1.1  macallan 		/*
    116  1.1  macallan 		 * this is a mailbox interrupt / IPI
    117  1.1  macallan 		 * for now just print the message and clear it
    118  1.1  macallan 		 */
    119  1.1  macallan 		uint32_t reg;
    120  1.1  macallan 
    121  1.1  macallan 		/* read pending IPIs */
    122  1.1  macallan 		reg = MFC0(12, 3);
    123  1.1  macallan 		if (id == 0) {
    124  1.1  macallan 			if (reg & CS_MIRQ0_P) {
    125  1.1  macallan 
    126  1.1  macallan #ifdef INGENIC_DEBUG
    127  1.1  macallan 				snprintf(buffer, 256, "IPI for core 0, msg %08x\n",
    128  1.1  macallan 				    MFC0(CP0_CORE_MBOX, 0));
    129  1.1  macallan 				ingenic_puts(buffer);
    130  1.1  macallan #endif
    131  1.1  macallan 				reg &= (~CS_MIRQ0_P);
    132  1.1  macallan 				/* clear it */
    133  1.1  macallan 				MTC0(reg, 12, 3);
    134  1.1  macallan 			}
    135  1.1  macallan 		} else if (id == 1) {
    136  1.1  macallan 			if (reg & CS_MIRQ1_P) {
    137  1.1  macallan #ifdef INGENIC_DEBUG
    138  1.1  macallan 				snprintf(buffer, 256, "IPI for core 1, msg %08x\n",
    139  1.1  macallan 				    MFC0(CP0_CORE_MBOX, 1));
    140  1.1  macallan 				ingenic_puts(buffer);
    141  1.1  macallan #endif
    142  1.1  macallan 				reg &= ( 7 - CS_MIRQ1_P);
    143  1.1  macallan 				/* clear it */
    144  1.1  macallan 				MTC0(reg, 12, 3);
    145  1.1  macallan 			}
    146  1.1  macallan 		}
    147  1.1  macallan 	}
    148  1.1  macallan 	if (ipending & MIPS_INT_MASK_2) {
    149  1.1  macallan 		/* this is a timer interrupt */
    150  1.1  macallan 		ingenic_clockintr(id);
    151  1.1  macallan 		ingenic_puts("INT2\n");
    152  1.1  macallan 	}
    153  1.1  macallan 	if (ipending & MIPS_INT_MASK_0) {
    154  1.1  macallan 		/* peripheral interrupt */
    155  1.1  macallan 
    156  1.1  macallan 		/*
    157  1.1  macallan 		 * XXX
    158  1.1  macallan 		 * OS timer interrupts are supposed to show up as INT2 as well
    159  1.1  macallan 		 * but I haven't seen them there so for now we just weed them
    160  1.1  macallan 		 * out right here.
    161  1.1  macallan 		 * The idea is to allow peripheral interrupts on both cores but
    162  1.1  macallan 		 * block INT0 on core1 so it would see only timer interrupts
    163  1.1  macallan 		 * and IPIs. If that doesn't work we'll have to send an IPI to
    164  1.1  macallan 		 * core1 for each timer tick.
    165  1.1  macallan 		 */
    166  1.1  macallan 		if (readreg(JZ_ICPR0) & 0x08000000)
    167  1.1  macallan 			ingenic_clockintr(id);
    168  1.1  macallan 		KASSERT(id == 0);
    169  1.1  macallan 	}
    170  1.1  macallan }
    171