Home | History | Annotate | Line # | Download | only in marvell
gtvar.h revision 1.1
      1 /*	$NetBSD: gtvar.h,v 1.1 2003/03/05 22:08:23 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 	vaddr_t gt_vbase;		/* mapped GT base address */
     53 #if 0
     54 	vaddr_t gt_iobat_vbase;		/* I/O BAT virtual base */
     55 	paddr_t gt_iobat_pbase;		/* I/O BAT physical base */
     56 	vsize_t gt_iobat_mask;		/* I/O BAT mask (signif. bits only) */
     57 #endif
     58 	struct pci_chipset *gt_pcis[GTPCI_NBUS];
     59 	bus_dma_tag_t gt_dmat;
     60 	bus_space_tag_t gt_memt;
     61 	bus_space_tag_t gt_pci0_memt;
     62 	bus_space_tag_t gt_pci0_iot;
     63 	bus_space_tag_t gt_pci1_memt;
     64 	bus_space_tag_t gt_pci1_iot;
     65 };
     66 
     67 struct gt_attach_args {
     68 	const char *ga_name;		/* class name of device */
     69 	bus_dma_tag_t ga_dmat;		/* dma tag */
     70 	bus_space_tag_t ga_memt;	/* GT bus space tag */
     71 	int ga_unit;			/* instance of ga_name */
     72 };
     73 
     74 #ifdef _KERNEL
     75 #include "locators.h"
     76 
     77 #ifdef DEBUG
     78 extern int gtpci_debug;
     79 #endif
     80 
     81 /*
     82  * Locators for GT private devices, as specified to config.
     83  */
     84 #define gtcf_dev		cf_loc[GTCF_DEV]
     85 #define	GT_UNK_DEV		GTCF_DEV_DEFAULT	/* wcarded 'dev' */
     86 
     87 #define gtcf_function		cf_loc[GTCF_FUNCTION]
     88 #define	GT_UNK_FUNCTION		GTCF_FUNCTION_DEFAULT	/* wcarded 'function' */
     89 
     90 void	gt_attach_common(struct gt_softc *);
     91 uint32_t gt_read_mpp(void);
     92 int	gt_cfprint (void *, const char *);
     93 
     94 void	gtpci_config(struct gt_softc *, int,
     95 		     bus_space_tag_t, bus_space_tag_t, bus_dma_tag_t);
     96 void	gteth_config (struct gt_softc *, int);
     97 void	gtmpsc_config (struct gt_softc *, int);
     98 
     99 /* int     gt_bs_extent_init(struct discovery_bus_space *, char *);  AKB */
    100 int	gt_mii_read (struct device *, struct device *, int, int);
    101 void	gt_mii_write (struct device *, struct device *, int, int, int);
    102 int	gtget_macaddr(struct gt_softc *gt, int function, char *enaddr);
    103 void	gtpci_config_bus(struct pci_chipset *pc, int busno);
    104 void	gt_setup(struct device *gt);
    105 void	gt_watchdog_service(void);
    106 
    107 #define	gt_read(a,b)	gt_read_4(a,b)
    108 #define	gt_write(a,b,c)	gt_write_4(a,b,c)
    109 
    110 static __inline uint32_t
    111 gt_read_4(struct device *dv, bus_addr_t off)
    112 {
    113 	struct gt_softc *gt = (struct gt_softc *) dv;
    114 	uint32_t rv;
    115 
    116 	__asm __volatile("eieio; lwbrx %0,%1,%2; eieio;"
    117 	    : "=r"(rv)
    118 	    : "b"(gt->gt_vbase), "r"(off));
    119 
    120 	return rv;
    121 }
    122 
    123 static __inline void
    124 gt_write_4(struct device *dv, bus_addr_t off, uint32_t v)
    125 {
    126 	struct gt_softc *gt = (struct gt_softc *) dv;
    127 
    128 	__asm __volatile("eieio; stwbrx %0,%1,%2; eieio;"
    129 	    ::	"r"(v), "b"(gt->gt_vbase), "r"(off));
    130 }
    131 
    132 #if defined(__powerpc__)
    133 static volatile inline int atomic_add(volatile int *p, int v);
    134 
    135 static volatile inline int
    136 atomic_add(volatile int *p, int	v)
    137 {
    138 	int	rv;
    139 	int	rtmp;
    140 
    141 	__asm __volatile(
    142 	"1:	lwarx	%0,0,%2\n"
    143 	"	add	%1,%3,%0\n"
    144 	"	stwcx.	%1,0,%2\n"
    145 	"	bne-	1b\n"
    146 	"	sync"
    147 			: "=&r"(rv), "=&r"(rtmp)
    148 			: "r"(p), "r"(v)
    149 			: "cc");
    150 
    151 	return rv;
    152 }
    153 
    154 #endif /* __powerpc__ */
    155 
    156 #endif /* _KERNEL */
    157 
    158 #endif /* _DISCOVERY_DEV_GTVAR_H_ */
    159