Home | History | Annotate | Line # | Download | only in marvell
pic_discovery.c revision 1.5.6.1
      1  1.5.6.1       mrg /*	$NetBSD: pic_discovery.c,v 1.5.6.1 2012/02/18 07:32:56 mrg Exp $	*/
      2      1.2   garbled 
      3      1.2   garbled /*
      4      1.2   garbled  * Copyright (c) 2002 Allegro Networks, Inc., Wasabi Systems, Inc.
      5      1.2   garbled  * All rights reserved.
      6      1.2   garbled  *
      7      1.2   garbled  * Redistribution and use in source and binary forms, with or without
      8      1.2   garbled  * modification, are permitted provided that the following conditions
      9      1.2   garbled  * are met:
     10      1.2   garbled  * 1. Redistributions of source code must retain the above copyright
     11      1.2   garbled  *    notice, this list of conditions and the following disclaimer.
     12      1.2   garbled  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.2   garbled  *    notice, this list of conditions and the following disclaimer in the
     14      1.2   garbled  *    documentation and/or other materials provided with the distribution.
     15      1.2   garbled  * 3. All advertising materials mentioning features or use of this software
     16      1.2   garbled  *    must display the following acknowledgement:
     17      1.2   garbled  *      This product includes software developed for the NetBSD Project by
     18      1.2   garbled  *      Allegro Networks, Inc., and Wasabi Systems, Inc.
     19      1.2   garbled  * 4. The name of Allegro Networks, Inc. may not be used to endorse
     20      1.2   garbled  *    or promote products derived from this software without specific prior
     21      1.2   garbled  *    written permission.
     22      1.2   garbled  * 5. The name of Wasabi Systems, Inc. may not be used to endorse
     23      1.2   garbled  *    or promote products derived from this software without specific prior
     24      1.2   garbled  *    written permission.
     25      1.2   garbled  *
     26      1.2   garbled  * THIS SOFTWARE IS PROVIDED BY ALLEGRO NETWORKS, INC. AND
     27      1.2   garbled  * WASABI SYSTEMS, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     28      1.2   garbled  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
     29      1.2   garbled  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     30      1.2   garbled  * IN NO EVENT SHALL EITHER ALLEGRO NETWORKS, INC. OR WASABI SYSTEMS, INC.
     31      1.2   garbled  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32      1.2   garbled  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33      1.2   garbled  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34      1.2   garbled  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35      1.2   garbled  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36      1.2   garbled  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37      1.2   garbled  * POSSIBILITY OF SUCH DAMAGE.
     38      1.2   garbled  */
     39      1.2   garbled 
     40      1.2   garbled #include <sys/cdefs.h>
     41  1.5.6.1       mrg __KERNEL_RCSID(0, "$NetBSD: pic_discovery.c,v 1.5.6.1 2012/02/18 07:32:56 mrg Exp $");
     42      1.2   garbled 
     43      1.2   garbled #include <sys/param.h>
     44      1.3  kiyohara #include <sys/bus.h>
     45  1.5.6.1       mrg #include <sys/kmem.h>
     46      1.4      matt #include <sys/intr.h>
     47      1.3  kiyohara 
     48      1.2   garbled #include <powerpc/pic/picvar.h>
     49      1.3  kiyohara 
     50      1.2   garbled #include <dev/marvell/gtvar.h>
     51      1.2   garbled #include <dev/marvell/gtintrreg.h>
     52      1.3  kiyohara #include <dev/marvell/gtintrvar.h>
     53      1.2   garbled 
     54      1.2   garbled 
     55      1.5      matt __CTASSERT(sizeof(imask_t) == sizeof(uint64_t));
     56      1.5      matt 
     57      1.3  kiyohara struct discovery_gpp_pic_ops;
     58      1.2   garbled 
     59      1.2   garbled struct discovery_pic_ops {
     60      1.3  kiyohara 	struct pic_ops pic;
     61      1.3  kiyohara 	union {
     62      1.3  kiyohara 		uint64_t mask64;
     63      1.3  kiyohara 		uint32_t mask32[2];
     64      1.3  kiyohara 	} _mask;
     65      1.3  kiyohara #define enable_mask		_mask.mask64
     66      1.3  kiyohara #define enable_mask_high	_mask.mask32[1]
     67      1.3  kiyohara #define enable_mask_low		_mask.mask32[0]
     68      1.2   garbled };
     69      1.3  kiyohara struct discovery_gpp_pic_ops {
     70      1.3  kiyohara 	struct pic_ops pic;
     71      1.2   garbled 
     72      1.3  kiyohara 	int gpp_base;
     73      1.2   garbled };
     74      1.2   garbled 
     75      1.2   garbled 
     76      1.3  kiyohara static void discovery_enable_irq(struct pic_ops *, int, int);
     77      1.3  kiyohara static void discovery_disable_irq(struct pic_ops *, int);
     78      1.3  kiyohara static int discovery_get_irq(struct pic_ops *, int);
     79      1.3  kiyohara static void discovery_ack_irq(struct pic_ops *, int);
     80      1.3  kiyohara 
     81      1.3  kiyohara static void discovery_gpp_enable_irq(struct pic_ops *, int, int);
     82      1.3  kiyohara static void discovery_gpp_disable_irq(struct pic_ops *, int);
     83      1.3  kiyohara static int discovery_gpp_get_irq(struct pic_ops *, int);
     84      1.3  kiyohara static void discovery_gpp_ack_irq(struct pic_ops *, int);
     85      1.3  kiyohara 
     86      1.3  kiyohara 
     87      1.3  kiyohara struct pic_ops *
     88  1.5.6.1       mrg setup_discovery_pic(void)
     89      1.3  kiyohara {
     90      1.3  kiyohara 	struct discovery_pic_ops *discovery;
     91      1.3  kiyohara 	struct pic_ops *pic;
     92      1.3  kiyohara 
     93  1.5.6.1       mrg 	discovery = kmem_alloc(sizeof(*discovery), KM_SLEEP);
     94      1.3  kiyohara 	KASSERT(discovery != NULL);
     95      1.3  kiyohara 
     96      1.3  kiyohara 	pic = &discovery->pic;
     97      1.3  kiyohara 	pic->pic_numintrs = 64;
     98      1.3  kiyohara 	pic->pic_cookie = (void *)NULL;			/* set later */
     99      1.3  kiyohara 	pic->pic_enable_irq = discovery_enable_irq;
    100      1.3  kiyohara 	pic->pic_reenable_irq = discovery_enable_irq;
    101      1.3  kiyohara 	pic->pic_disable_irq = discovery_disable_irq;
    102      1.3  kiyohara 	pic->pic_get_irq = discovery_get_irq;
    103      1.3  kiyohara 	pic->pic_ack_irq = discovery_ack_irq;
    104      1.3  kiyohara 	pic->pic_establish_irq = dummy_pic_establish_intr;
    105      1.3  kiyohara 	pic->pic_finish_setup = NULL;
    106      1.3  kiyohara 	strcpy(pic->pic_name, "discovery");
    107      1.3  kiyohara 	pic_add(pic);
    108      1.2   garbled 
    109      1.3  kiyohara 	discovery->enable_mask = 0;
    110      1.2   garbled 
    111      1.3  kiyohara 	return pic;
    112      1.2   garbled }
    113      1.2   garbled 
    114      1.2   garbled static void
    115      1.3  kiyohara discovery_enable_irq(struct pic_ops *pic, int irq, int type)
    116      1.2   garbled {
    117      1.3  kiyohara 	struct discovery_pic_ops *discovery = (struct discovery_pic_ops *)pic;
    118      1.2   garbled 
    119      1.3  kiyohara 	discovery->enable_mask |= (1 << irq);
    120      1.3  kiyohara 	discovery_enable_intr(pic->pic_cookie, irq);
    121      1.2   garbled }
    122      1.2   garbled 
    123      1.2   garbled static void
    124      1.3  kiyohara discovery_disable_irq(struct pic_ops *pic, int irq)
    125      1.2   garbled {
    126      1.3  kiyohara 	struct discovery_pic_ops *discovery = (struct discovery_pic_ops *)pic;
    127      1.2   garbled 
    128      1.3  kiyohara 	discovery->enable_mask &= ~(1 << irq);
    129      1.3  kiyohara 	discovery_disable_intr(pic->pic_cookie, irq);
    130      1.2   garbled }
    131      1.2   garbled 
    132      1.3  kiyohara static int
    133      1.3  kiyohara discovery_get_irq(struct pic_ops *pic, int mode)
    134      1.2   garbled {
    135      1.3  kiyohara 	struct discovery_pic_ops *discovery = (struct discovery_pic_ops *)pic;
    136      1.3  kiyohara 	uint32_t cause;
    137      1.3  kiyohara 	int irq, base, msk;
    138      1.3  kiyohara 
    139      1.3  kiyohara 	cause = discovery_mic_low(pic->pic_cookie) & discovery->enable_mask_low;
    140      1.3  kiyohara 	if (cause)
    141      1.3  kiyohara 		base = 0;
    142      1.3  kiyohara 	else {
    143      1.3  kiyohara 		cause = discovery_mic_high(pic->pic_cookie);
    144      1.3  kiyohara 		cause &= discovery->enable_mask_high;
    145      1.3  kiyohara 		if (!cause)
    146      1.3  kiyohara 			return 255;
    147      1.3  kiyohara 		base = 32;
    148      1.3  kiyohara 	}
    149      1.3  kiyohara 	for (irq = base, msk = 0x00000001; !(cause & msk); irq++, msk <<= 1);
    150      1.2   garbled 
    151      1.3  kiyohara 	return irq;
    152      1.2   garbled }
    153      1.2   garbled 
    154      1.2   garbled static void
    155      1.3  kiyohara discovery_ack_irq(struct pic_ops *pic, int irq)
    156      1.2   garbled {
    157      1.3  kiyohara 
    158      1.3  kiyohara 	/* nothing */
    159      1.2   garbled }
    160      1.2   garbled 
    161      1.3  kiyohara 
    162      1.3  kiyohara struct pic_ops *
    163      1.3  kiyohara setup_discovery_gpp_pic(void *discovery, int gpp_base)
    164      1.2   garbled {
    165      1.3  kiyohara 	struct discovery_gpp_pic_ops *discovery_gpp;
    166      1.3  kiyohara 	struct pic_ops *pic;
    167      1.3  kiyohara 
    168  1.5.6.1       mrg 	discovery_gpp = kmem_alloc(sizeof(*discovery_gpp), KM_SLEEP);
    169      1.3  kiyohara 	KASSERT(discovery_gpp != NULL);
    170      1.2   garbled 
    171      1.3  kiyohara 	pic = &discovery_gpp->pic;
    172      1.3  kiyohara 	pic->pic_numintrs = 32;
    173      1.3  kiyohara 	pic->pic_cookie = discovery;
    174      1.3  kiyohara 	pic->pic_enable_irq = discovery_gpp_enable_irq;
    175      1.3  kiyohara 	pic->pic_reenable_irq = discovery_gpp_enable_irq;
    176      1.3  kiyohara 	pic->pic_disable_irq = discovery_gpp_disable_irq;
    177      1.3  kiyohara 	pic->pic_get_irq = discovery_gpp_get_irq;
    178      1.3  kiyohara 	pic->pic_ack_irq = discovery_gpp_ack_irq;
    179      1.3  kiyohara 	pic->pic_establish_irq = dummy_pic_establish_intr;
    180      1.3  kiyohara 	pic->pic_finish_setup = NULL;
    181      1.3  kiyohara 	strcpy(pic->pic_name, "discovery_gpp");
    182      1.3  kiyohara 	pic_add(pic);
    183      1.2   garbled 
    184      1.3  kiyohara 	discovery_gpp->gpp_base = gpp_base;
    185      1.2   garbled 
    186      1.3  kiyohara 	return pic;
    187      1.2   garbled }
    188      1.2   garbled 
    189      1.2   garbled static void
    190      1.3  kiyohara discovery_gpp_enable_irq(struct pic_ops *pic, int irq, int type)
    191      1.2   garbled {
    192      1.3  kiyohara 	struct discovery_gpp_pic_ops *discovery_gpp =
    193      1.3  kiyohara 	    (struct discovery_gpp_pic_ops *)pic;
    194      1.3  kiyohara 	struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
    195      1.2   garbled 
    196      1.3  kiyohara 	discovery_gpp_enable_intr(discovery->pic.pic_cookie,
    197      1.3  kiyohara 	    discovery_gpp->gpp_base + irq);
    198      1.2   garbled }
    199      1.2   garbled 
    200      1.2   garbled static void
    201      1.3  kiyohara discovery_gpp_disable_irq(struct pic_ops *pic, int irq)
    202      1.2   garbled {
    203      1.3  kiyohara 	struct discovery_gpp_pic_ops *discovery_gpp =
    204      1.3  kiyohara 	    (struct discovery_gpp_pic_ops *)pic;
    205      1.3  kiyohara 	struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
    206      1.2   garbled 
    207      1.3  kiyohara 	discovery_gpp_disable_intr(discovery->pic.pic_cookie,
    208      1.3  kiyohara 	    discovery_gpp->gpp_base + irq);
    209      1.2   garbled }
    210      1.2   garbled 
    211      1.3  kiyohara static int
    212      1.3  kiyohara discovery_gpp_get_irq(struct pic_ops *pic, int mode)
    213      1.2   garbled {
    214      1.3  kiyohara 	struct discovery_gpp_pic_ops *discovery_gpp =
    215      1.3  kiyohara 	    (struct discovery_gpp_pic_ops *)pic;
    216      1.3  kiyohara 	struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
    217      1.3  kiyohara 	uint32_t cause, mask;
    218      1.3  kiyohara 	int irq, msk, base;
    219      1.2   garbled 
    220      1.3  kiyohara 	cause = discovery_gpp_cause(discovery->pic.pic_cookie);
    221      1.3  kiyohara 	mask = discovery_gpp_mask(discovery->pic.pic_cookie);
    222      1.3  kiyohara 
    223      1.3  kiyohara 	base = discovery_gpp->gpp_base;
    224      1.3  kiyohara 	cause &= (mask & (0xff << base));
    225      1.3  kiyohara 	if (!cause)
    226      1.3  kiyohara 		return 255;
    227      1.2   garbled 
    228      1.3  kiyohara 	for (irq = base, msk = (1 << base); !(cause & msk); irq++, msk <<= 1);
    229      1.2   garbled 
    230      1.3  kiyohara 	return irq;
    231      1.2   garbled }
    232      1.2   garbled 
    233      1.2   garbled static void
    234      1.3  kiyohara discovery_gpp_ack_irq(struct pic_ops *pic, int irq)
    235      1.2   garbled {
    236      1.3  kiyohara 	struct discovery_gpp_pic_ops *discovery_gpp =
    237      1.3  kiyohara 	    (struct discovery_gpp_pic_ops *)pic;
    238      1.3  kiyohara 	struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
    239      1.2   garbled 
    240      1.3  kiyohara 	discovery_gpp_clear_cause(discovery->pic.pic_cookie,
    241      1.3  kiyohara 	    discovery_gpp->gpp_base + irq);
    242      1.2   garbled }
    243