Home | History | Annotate | Line # | Download | only in dev
gt.c revision 1.2
      1  1.2  thorpej /*	$NetBSD: gt.c,v 1.2 2002/05/16 01:01:36 thorpej Exp $	*/
      2  1.1   simonb 
      3  1.1   simonb /*
      4  1.1   simonb  * Copyright 2002 Wasabi Systems, Inc.
      5  1.1   simonb  * All rights reserved.
      6  1.1   simonb  *
      7  1.1   simonb  * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
      8  1.1   simonb  *
      9  1.1   simonb  * Redistribution and use in source and binary forms, with or without
     10  1.1   simonb  * modification, are permitted provided that the following conditions
     11  1.1   simonb  * are met:
     12  1.1   simonb  * 1. Redistributions of source code must retain the above copyright
     13  1.1   simonb  *    notice, this list of conditions and the following disclaimer.
     14  1.1   simonb  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1   simonb  *    notice, this list of conditions and the following disclaimer in the
     16  1.1   simonb  *    documentation and/or other materials provided with the distribution.
     17  1.1   simonb  * 3. All advertising materials mentioning features or use of this software
     18  1.1   simonb  *    must display the following acknowledgement:
     19  1.1   simonb  *      This product includes software developed for the NetBSD Project by
     20  1.1   simonb  *      Wasabi Systems, Inc.
     21  1.1   simonb  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1   simonb  *    or promote products derived from this software without specific prior
     23  1.1   simonb  *    written permission.
     24  1.1   simonb  *
     25  1.1   simonb  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1   simonb  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1   simonb  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1   simonb  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1   simonb  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1   simonb  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1   simonb  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1   simonb  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1   simonb  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1   simonb  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1   simonb  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1   simonb  */
     37  1.1   simonb 
     38  1.1   simonb #include <sys/param.h>
     39  1.1   simonb #include <sys/systm.h>
     40  1.1   simonb #include <sys/device.h>
     41  1.1   simonb 
     42  1.1   simonb #include <dev/pci/pcivar.h>
     43  1.1   simonb 
     44  1.1   simonb #include <evbmips/malta/maltareg.h>
     45  1.1   simonb #include <evbmips/malta/maltavar.h>
     46  1.1   simonb 
     47  1.1   simonb #include <evbmips/malta/dev/gtreg.h>
     48  1.1   simonb #include <evbmips/malta/dev/gtvar.h>
     49  1.1   simonb 
     50  1.1   simonb #include "pci.h"
     51  1.1   simonb 
     52  1.1   simonb /*
     53  1.1   simonb  * Galileo systems (so far) are always single-processor, so this is sufficient.
     54  1.1   simonb  */
     55  1.1   simonb #define	PCI_CONF_LOCK(s)	(s) = splhigh()
     56  1.1   simonb #define	PCI_CONF_UNLOCK(s)	splx((s))
     57  1.1   simonb 
     58  1.1   simonb static void	gt_attach_hook(struct device *, struct device *,
     59  1.1   simonb 		    struct pcibus_attach_args *);
     60  1.1   simonb static int	gt_bus_maxdevs(void *, int);
     61  1.1   simonb static pcitag_t	gt_make_tag(void *, int, int, int);
     62  1.1   simonb static void	gt_decompose_tag(void *, pcitag_t, int *, int *, int *);
     63  1.1   simonb static pcireg_t	gt_conf_read(void *, pcitag_t, int);
     64  1.1   simonb static void	gt_conf_write(void *, pcitag_t, int, pcireg_t);
     65  1.1   simonb 
     66  1.1   simonb void
     67  1.1   simonb gt_pci_init(pci_chipset_tag_t pc, struct gt_config *mcp)
     68  1.1   simonb {
     69  1.1   simonb 
     70  1.1   simonb 	pc->pc_conf_v = mcp;
     71  1.1   simonb 	pc->pc_attach_hook = gt_attach_hook;
     72  1.1   simonb 	pc->pc_bus_maxdevs = gt_bus_maxdevs;
     73  1.1   simonb 	pc->pc_make_tag = gt_make_tag;
     74  1.1   simonb 	pc->pc_decompose_tag = gt_decompose_tag;
     75  1.1   simonb 	pc->pc_conf_read = gt_conf_read;
     76  1.1   simonb 	pc->pc_conf_write = gt_conf_write;
     77  1.1   simonb }
     78  1.1   simonb 
     79  1.1   simonb static void
     80  1.1   simonb gt_attach_hook(struct device *parent, struct device *self,
     81  1.1   simonb     struct pcibus_attach_args *pba)
     82  1.1   simonb {
     83  1.1   simonb 
     84  1.1   simonb 	/* Nothing to do... */
     85  1.1   simonb }
     86  1.1   simonb 
     87  1.1   simonb static int	gt_match(struct device *, struct cfdata *, void *);
     88  1.1   simonb static void	gt_attach(struct device *, struct device *, void *);
     89  1.1   simonb static int	gt_print(void *aux, const char *pnp);
     90  1.1   simonb 
     91  1.1   simonb struct cfattach gt_ca = {
     92  1.1   simonb 	sizeof(struct device), gt_match, gt_attach
     93  1.1   simonb };
     94  1.1   simonb 
     95  1.1   simonb static int
     96  1.1   simonb gt_match(parent, match, aux)
     97  1.1   simonb 	struct device *parent;
     98  1.1   simonb 	struct cfdata *match;
     99  1.1   simonb 	void *aux;
    100  1.1   simonb {
    101  1.1   simonb 	return 1;
    102  1.1   simonb }
    103  1.1   simonb 
    104  1.1   simonb static void
    105  1.1   simonb gt_attach(parent, self, aux)
    106  1.1   simonb 	struct device *parent;
    107  1.1   simonb 	struct device *self;
    108  1.1   simonb 	void *aux;
    109  1.1   simonb {
    110  1.1   simonb 	struct malta_config *mcp = &malta_configuration;
    111  1.1   simonb 	struct pcibus_attach_args pba;
    112  1.1   simonb 
    113  1.1   simonb 	printf("\n");
    114  1.1   simonb 
    115  1.1   simonb #if NPCI > 0
    116  1.1   simonb 	pba.pba_busname = "pci";
    117  1.1   simonb 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    118  1.1   simonb 	pba.pba_bus = 0;
    119  1.2  thorpej 	pba.pba_bridgetag = NULL;
    120  1.1   simonb 	pba.pba_iot = &mcp->mc_iot;
    121  1.1   simonb 	pba.pba_memt = &mcp->mc_memt;
    122  1.1   simonb 	pba.pba_dmat = &mcp->mc_pci_dmat;	/* pci_bus_dma_tag */
    123  1.1   simonb 	//pba.pba_dmat = &pci_bus_dma_tag;
    124  1.1   simonb 	pba.pba_pc = &mcp->mc_pc;
    125  1.1   simonb 
    126  1.1   simonb 	config_found(self, &pba, gt_print);
    127  1.1   simonb #endif
    128  1.1   simonb 	return;
    129  1.1   simonb }
    130  1.1   simonb 
    131  1.1   simonb static int
    132  1.1   simonb gt_print(aux, pnp)
    133  1.1   simonb 	void *aux;
    134  1.1   simonb 	const char *pnp;
    135  1.1   simonb {
    136  1.1   simonb 	/* XXX */
    137  1.1   simonb 	return 0;
    138  1.1   simonb }
    139  1.1   simonb 
    140  1.1   simonb static int
    141  1.1   simonb gt_bus_maxdevs(void *v, int busno)
    142  1.1   simonb {
    143  1.1   simonb 
    144  1.1   simonb 	/* The galileo has problems accessing device 31. */
    145  1.1   simonb 	if (busno == 0)
    146  1.1   simonb 		return (31);
    147  1.1   simonb 	return (32);
    148  1.1   simonb }
    149  1.1   simonb 
    150  1.1   simonb static pcitag_t
    151  1.1   simonb gt_make_tag(void *v, int b, int d, int f)
    152  1.1   simonb {
    153  1.1   simonb 
    154  1.1   simonb 	return ((b << 16) | (d << 11) | (f << 8));
    155  1.1   simonb }
    156  1.1   simonb 
    157  1.1   simonb static void
    158  1.1   simonb gt_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
    159  1.1   simonb {
    160  1.1   simonb 
    161  1.1   simonb 	if (bp != NULL)
    162  1.1   simonb 		*bp = (tag >> 16) & 0xff;
    163  1.1   simonb 	if (dp != NULL)
    164  1.1   simonb 		*dp = (tag >> 11) & 0x1f;
    165  1.1   simonb 	if (fp != NULL)
    166  1.1   simonb 		*fp = (tag >> 8) & 0x7;
    167  1.1   simonb }
    168  1.1   simonb 
    169  1.1   simonb static pcireg_t
    170  1.1   simonb gt_conf_read(void *v, pcitag_t tag, int offset)
    171  1.1   simonb {
    172  1.1   simonb 	pcireg_t data;
    173  1.1   simonb 	int bus, dev, func, s;
    174  1.1   simonb 
    175  1.1   simonb 	gt_decompose_tag(NULL /* XXX */, tag, &bus, &dev, &func);
    176  1.1   simonb 
    177  1.1   simonb 	/* The galileo has problems accessing device 31. */
    178  1.1   simonb 	if (bus == 0 && dev == 31)
    179  1.1   simonb 		return ((pcireg_t) -1);
    180  1.1   simonb 
    181  1.1   simonb 	/* XXX: no support for bus > 0 yet */
    182  1.1   simonb 	if (bus > 0)
    183  1.1   simonb 		return ((pcireg_t) -1);
    184  1.1   simonb 
    185  1.1   simonb 	PCI_CONF_LOCK(s);
    186  1.1   simonb 
    187  1.1   simonb 	/* Clear cause register bits. */
    188  1.1   simonb 	GT_REGVAL(GT_INTR_CAUSE) = 0;
    189  1.1   simonb 
    190  1.1   simonb 	GT_REGVAL(GT_PCI0_CFG_ADDR) = (1 << 31) | tag | offset;
    191  1.1   simonb 	data = GT_REGVAL(GT_PCI0_CFG_DATA);
    192  1.1   simonb 
    193  1.1   simonb 	/* Check for master abort. */
    194  1.1   simonb 	if (GT_REGVAL(GT_INTR_CAUSE) & (GTIC_MASABORT0 | GTIC_TARABORT0))
    195  1.1   simonb 		data = (pcireg_t) -1;
    196  1.1   simonb 
    197  1.1   simonb 	PCI_CONF_UNLOCK(s);
    198  1.1   simonb 
    199  1.1   simonb 	return (data);
    200  1.1   simonb }
    201  1.1   simonb 
    202  1.1   simonb static void
    203  1.1   simonb gt_conf_write(void *v, pcitag_t tag, int offset, pcireg_t data)
    204  1.1   simonb {
    205  1.1   simonb 	int bus, dev, func, s;
    206  1.1   simonb 
    207  1.1   simonb 	gt_decompose_tag(NULL /* XXX */, tag, &bus, &dev, &func);
    208  1.1   simonb 
    209  1.1   simonb 	/* The galileo has problems accessing device 31. */
    210  1.1   simonb 	if (bus == 0 && dev == 31)
    211  1.1   simonb 		return;
    212  1.1   simonb 
    213  1.1   simonb 	/* XXX: no support for bus > 0 yet */
    214  1.1   simonb 	if (bus > 0)
    215  1.1   simonb 		return;
    216  1.1   simonb 
    217  1.1   simonb 	PCI_CONF_LOCK(s);
    218  1.1   simonb 
    219  1.1   simonb 	/* Clear cause register bits. */
    220  1.1   simonb 	GT_REGVAL(GT_INTR_CAUSE) = 0;
    221  1.1   simonb 
    222  1.1   simonb 	GT_REGVAL(GT_PCI0_CFG_ADDR) = (1 << 31) | tag | offset;
    223  1.1   simonb 	GT_REGVAL(GT_PCI0_CFG_DATA) = data;
    224  1.1   simonb 
    225  1.1   simonb 	PCI_CONF_UNLOCK(s);
    226  1.1   simonb }
    227