Home | History | Annotate | Line # | Download | only in marvell
gtvar.h revision 1.2
      1 /*	$NetBSD: gtvar.h,v 1.2 2003/03/16 07:05:34 matt 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 /*
     41  * gtvar.h -- placeholder for GT system controller driver
     42  */
     43 #ifndef _DISCOVERY_DEV_GTVAR_H_
     44 #define	_DISCOVERY_DEV_GTVAR_H_
     45 
     46 #include <sys/systm.h>
     47 
     48 #define	GTPCI_NBUS 2
     49 
     50 struct gt_softc {
     51 	struct device gt_dev;
     52 	bus_dma_tag_t gt_dmat;
     53 	bus_space_tag_t gt_memt;	/* the GT itself */
     54 	bus_space_tag_t gt_pci0_memt;	/* PCI0 mem space */
     55 	bus_space_tag_t gt_pci0_iot;	/* PCI0 i/o space */
     56 	bus_space_tag_t gt_pci1_memt;	/* PCI1 mem space */
     57 	bus_space_tag_t gt_pci1_iot;	/* PCI1 i/o space */
     58 
     59 	bus_space_handle_t gt_memh;	/* to access the GT registers */
     60 	int gt_childmask;		/* what children are present */
     61 };
     62 
     63 #define	GT_CHILDOK(gt, ga, cd, pos, max) \
     64 	(((ga)->ga_unit) < (max) &&  \
     65 	    !((gt)->gt_childmask & (1 << (((ga)->ga_unit) + (pos)))) && \
     66 	    !strcmp((ga)->ga_name, (cd)->cd_name))
     67 
     68 #define	GT_MPSCOK(gt, ga, cd)		GT_CHILDOK((gt), (ga), (cd), 0, 2)
     69 #define	GT_PCIOK(gt, ga, cd)		GT_CHILDOK((gt), (ga), (cd), 2, 2)
     70 #define	GT_ETHEROK(gt, ga, cd)		GT_CHILDOK((gt), (ga), (cd), 4, 3)
     71 #define	GT_OBIOOK(gt, ga, cd)		GT_CHILDOK((gt), (ga), (cd), 7, 5)
     72 
     73 #define	GT_CHILDFOUND(gt, ga, pos) \
     74 	((void)(((gt)->gt_childmask |= (1 << (((ga)->ga_unit) + (pos))))))
     75 
     76 #define	GT_MPSCFOUND(gt, ga)		GT_CHILDFOUND((gt), (ga), 0)
     77 #define	GT_PCIFOUND(gt, ga)		GT_CHILDFOUND((gt), (ga), 2)
     78 #define	GT_ETHERFOUND(gt, ga)		GT_CHILDFOUND((gt), (ga), 4)
     79 #define	GT_OBIOFOUND(gt, ga)		GT_CHILDFOUND((gt), (ga), 7)
     80 
     81 struct gt_attach_args {
     82 	const char *ga_name;		/* class name of device */
     83 	bus_dma_tag_t ga_dmat;		/* dma tag */
     84 	bus_space_tag_t ga_memt;	/* GT bus space tag */
     85 	bus_space_handle_t ga_memh;	/* GT bus space handle */
     86 	int ga_unit;			/* instance of ga_name */
     87 };
     88 
     89 struct obio_attach_args {
     90 	const char *oa_name;		/* call name of device */
     91 	bus_space_tag_t oa_memt;	/* bus space tag */
     92 	bus_addr_t oa_offset;		/* offset (absolute) to device */
     93 	bus_size_t oa_size;		/* size (strided) of device */
     94 	int oa_irq;			/* irq */
     95 };
     96 
     97 #ifdef _KERNEL
     98 #include "locators.h"
     99 
    100 #ifdef DEBUG
    101 extern int gtpci_debug;
    102 #endif
    103 
    104 /*
    105  * Locators for GT private devices, as specified to config.
    106  */
    107 #define	gtcf_unit		cf_loc[GTCF_UNIT]
    108 #define	GT_UNK_UNIT		GTCF_UNIT_DEFAULT	/* wcarded 'function' */
    109 
    110 #define	obiocf_offset		cf_loc[OBIOCF_OFFSET]
    111 #define	OBIO_UNK_OFFSET		OBIOCF_OFFSET_DEFAULT	/* wcarded 'offset' */
    112 
    113 #define	obiocf_size		cf_loc[OBIOCF_SIZE]
    114 #define	OBIO_UNK_SIZE		OBIOCF_SIZE_DEFAULT	/* wcarded 'size' */
    115 
    116 #define	obiocf_irq		cf_loc[OBIOCF_IRQ]
    117 #define	OBIO_UNK_IRQ		OBIOCF_IRQ_DEFAULT	/* wcarded 'irq' */
    118 
    119 void	gt_attach_common(struct gt_softc *);
    120 uint32_t gt_read_mpp(void);
    121 int	gt_cfprint (void *, const char *);
    122 
    123 struct pci_chipset;
    124 
    125 void	gtpci_config_bus(struct pci_chipset *, int);
    126 
    127 /* int     gt_bs_extent_init(struct discovery_bus_space *, char *);  AKB */
    128 int	gt_mii_read (struct device *, struct device *, int, int);
    129 void	gt_mii_write (struct device *, struct device *, int, int, int);
    130 int	gtget_macaddr(struct gt_softc *,int, char *);
    131 void	gt_watchdog_service(void);
    132 
    133 #define	gt_read(gt,o) \
    134 	bus_space_read_4((gt)->gt_memt, (gt)->gt_memh, (o))
    135 #define	gt_write(gt,o,v) \
    136 	bus_space_write_4((gt)->gt_memt, (gt)->gt_memh, (o), (v))
    137 
    138 #if defined(__powerpc__)
    139 static __inline volatile int
    140 atomic_add(volatile int *p, int	v)
    141 {
    142 	int	rv;
    143 	int	rtmp;
    144 
    145 	__asm __volatile(
    146 	"1:	lwarx	%0,0,%2\n"
    147 	"	add	%1,%3,%0\n"
    148 	"	stwcx.	%1,0,%2\n"
    149 	"	bne-	1b\n"
    150 	"	sync"
    151 			: "=&r"(rv), "=&r"(rtmp)
    152 			: "r"(p), "r"(v)
    153 			: "cc");
    154 
    155 	return rv;
    156 }
    157 
    158 #endif /* __powerpc__ */
    159 
    160 #endif /* _KERNEL */
    161 
    162 #endif /* _DISCOVERY_DEV_GTVAR_H_ */
    163