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