Home | History | Annotate | Line # | Download | only in ev64260
gt_mainbus.c revision 1.8
      1  1.8   scw /*	$NetBSD: gt_mainbus.c,v 1.8 2003/06/12 19:21:09 scw Exp $	*/
      2  1.1  matt 
      3  1.1  matt /*
      4  1.1  matt  * Copyright (c) 2002 Wasabi Systems, Inc.
      5  1.1  matt  * All rights reserved.
      6  1.1  matt  *
      7  1.1  matt  * Written by Allen Briggs for Wasabi Systems, Inc.
      8  1.1  matt  *
      9  1.1  matt  * Redistribution and use in source and binary forms, with or without
     10  1.1  matt  * modification, are permitted provided that the following conditions
     11  1.1  matt  * are met:
     12  1.1  matt  * 1. Redistributions of source code must retain the above copyright
     13  1.1  matt  *    notice, this list of conditions and the following disclaimer.
     14  1.1  matt  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  matt  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  matt  *    documentation and/or other materials provided with the distribution.
     17  1.1  matt  * 3. All advertising materials mentioning features or use of this software
     18  1.1  matt  *    must display the following acknowledgement:
     19  1.1  matt  *      This product includes software developed for the NetBSD Project by
     20  1.1  matt  *      Wasabi Systems, Inc.
     21  1.1  matt  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1  matt  *    or promote products derived from this software without specific prior
     23  1.1  matt  *    written permission.
     24  1.1  matt  *
     25  1.1  matt  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1  matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1  matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1  matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1  matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1  matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1  matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1  matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1  matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1  matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1  matt  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1  matt  */
     37  1.1  matt 
     38  1.7  matt #include "opt_ev64260.h"
     39  1.1  matt #include <sys/types.h>
     40  1.1  matt #include <sys/param.h>
     41  1.1  matt #include <sys/device.h>
     42  1.1  matt #include <sys/extent.h>
     43  1.1  matt #include <sys/malloc.h>
     44  1.1  matt 
     45  1.1  matt #define _POWERPC_BUS_DMA_PRIVATE
     46  1.1  matt #include <machine/bus.h>
     47  1.1  matt 
     48  1.3  matt #include "opt_pci.h"
     49  1.1  matt #include <dev/pci/pcivar.h>
     50  1.1  matt #include <dev/pci/pciconf.h>
     51  1.1  matt 
     52  1.1  matt #include "opt_marvell.h"
     53  1.1  matt #include <dev/marvell/gtreg.h>
     54  1.1  matt #include <dev/marvell/gtvar.h>
     55  1.1  matt #include <dev/marvell/gtpcireg.h>
     56  1.1  matt #include <dev/marvell/gtpcivar.h>
     57  1.1  matt 
     58  1.3  matt extern struct powerpc_bus_space gt_mem_bs_tag;
     59  1.3  matt extern struct powerpc_bus_space gt_pci0_mem_bs_tag;
     60  1.3  matt extern struct powerpc_bus_space gt_pci0_io_bs_tag;
     61  1.3  matt extern struct powerpc_bus_space gt_pci1_mem_bs_tag;
     62  1.3  matt extern struct powerpc_bus_space gt_pci1_io_bs_tag;
     63  1.1  matt 
     64  1.1  matt struct powerpc_bus_dma_tag gt_bus_dma_tag = {
     65  1.1  matt 	0,			/* _bounce_thresh */
     66  1.1  matt 	_bus_dmamap_create,
     67  1.1  matt 	_bus_dmamap_destroy,
     68  1.1  matt 	_bus_dmamap_load,
     69  1.1  matt 	_bus_dmamap_load_mbuf,
     70  1.1  matt 	_bus_dmamap_load_uio,
     71  1.1  matt 	_bus_dmamap_load_raw,
     72  1.1  matt 	_bus_dmamap_unload,
     73  1.1  matt 	_bus_dmamap_sync,
     74  1.1  matt 	_bus_dmamem_alloc,
     75  1.1  matt 	_bus_dmamem_free,
     76  1.1  matt 	_bus_dmamem_map,
     77  1.1  matt 	_bus_dmamem_unmap,
     78  1.1  matt 	_bus_dmamem_mmap,
     79  1.1  matt };
     80  1.1  matt 
     81  1.7  matt const int gtpci_skipmask[2] = {
     82  1.7  matt #ifdef PCI0_SKIPMASK
     83  1.7  matt 	PCI0_SKIPMASK,
     84  1.7  matt #else
     85  1.7  matt 	0,
     86  1.7  matt #endif
     87  1.7  matt #ifdef PCI1_SKIPMASK
     88  1.7  matt 	PCI1_SKIPMASK,
     89  1.7  matt #else
     90  1.7  matt 	0,
     91  1.7  matt #endif
     92  1.7  matt };
     93  1.7  matt 
     94  1.1  matt static int	gt_match(struct device *, struct cfdata *, void *);
     95  1.1  matt static void	gt_attach(struct device *, struct device *, void *);
     96  1.1  matt 
     97  1.1  matt CFATTACH_DECL(gt, sizeof(struct gt_softc), gt_match, gt_attach, NULL, NULL);
     98  1.1  matt 
     99  1.1  matt extern struct cfdriver gt_cd;
    100  1.4  matt extern bus_space_handle_t gt_memh;
    101  1.1  matt 
    102  1.1  matt static int gt_found;
    103  1.1  matt 
    104  1.1  matt int
    105  1.1  matt gt_match(struct device *parent, struct cfdata *cf, void *aux)
    106  1.1  matt {
    107  1.4  matt 	const char **busname = aux;
    108  1.1  matt 
    109  1.4  matt 	if (strcmp(*busname, gt_cd.cd_name) != 0)
    110  1.1  matt 		return 0;
    111  1.1  matt 
    112  1.1  matt 	if (gt_found)
    113  1.1  matt 		return 0;
    114  1.1  matt 
    115  1.1  matt 	return 1;
    116  1.1  matt }
    117  1.1  matt 
    118  1.1  matt void
    119  1.1  matt gt_attach(struct device *parent, struct device *self, void *aux)
    120  1.1  matt {
    121  1.1  matt 	struct gt_softc *gt = (struct gt_softc *) self;
    122  1.1  matt 
    123  1.1  matt 	gt->gt_dmat = &gt_bus_dma_tag;
    124  1.3  matt 	gt->gt_memt = &gt_mem_bs_tag;
    125  1.6  matt 	gt->gt_pci0_memt = &gt_pci0_mem_bs_tag;
    126  1.6  matt 	gt->gt_pci0_iot =  &gt_pci0_io_bs_tag;
    127  1.8   scw 	gt->gt_pci0_host = TRUE;
    128  1.6  matt 	gt->gt_pci1_memt = &gt_pci1_mem_bs_tag;
    129  1.6  matt 	gt->gt_pci1_iot =  &gt_pci1_io_bs_tag;
    130  1.8   scw 	gt->gt_pci1_host = TRUE;
    131  1.1  matt 
    132  1.4  matt 	gt->gt_memh = gt_memh;
    133  1.1  matt 
    134  1.6  matt #if 0
    135  1.3  matt 	GT_DecodeAddr_SET(gt, GT_PCI0_IO_Low_Decode,
    136  1.3  matt 	    gt_pci0_io_bs_tag.pbs_offset + gt_pci0_io_bs_tag.pbs_base);
    137  1.3  matt 	GT_DecodeAddr_SET(gt, GT_PCI0_IO_High_Decode,
    138  1.3  matt 	    gt_pci0_io_bs_tag.pbs_offset + gt_pci0_io_bs_tag.pbs_limit - 1);
    139  1.3  matt 
    140  1.3  matt 	GT_DecodeAddr_SET(gt, GT_PCI1_IO_Low_Decode,
    141  1.3  matt 	    gt_pci1_io_bs_tag.pbs_offset + gt_pci1_io_bs_tag.pbs_base);
    142  1.3  matt 	GT_DecodeAddr_SET(gt, GT_PCI1_IO_High_Decode,
    143  1.3  matt 	    gt_pci1_io_bs_tag.pbs_offset + gt_pci1_io_bs_tag.pbs_limit - 1);
    144  1.3  matt 
    145  1.3  matt 	GT_DecodeAddr_SET(gt, GT_PCI0_Mem0_Low_Decode,
    146  1.3  matt 	    gt_pci0_mem_bs_tag.pbs_offset + gt_pci0_mem_bs_tag.pbs_base);
    147  1.3  matt 	GT_DecodeAddr_SET(gt, GT_PCI0_Mem0_High_Decode,
    148  1.3  matt 	    gt_pci1_mem_bs_tag.pbs_offset + gt_pci1_mem_bs_tag.pbs_limit - 1);
    149  1.3  matt 
    150  1.3  matt 	GT_DecodeAddr_SET(gt, GT_PCI1_Mem0_Low_Decode,
    151  1.3  matt 	    gt_pci1_mem_bs_tag.pbs_offset + gt_pci1_mem_bs_tag.pbs_base);
    152  1.3  matt 	GT_DecodeAddr_SET(gt, GT_PCI1_Mem0_High_Decode,
    153  1.3  matt 	    gt_pci1_mem_bs_tag.pbs_offset + gt_pci1_mem_bs_tag.pbs_limit - 1);
    154  1.1  matt #endif
    155  1.4  matt 
    156  1.4  matt 	gt_attach_common(gt);
    157  1.1  matt }
    158  1.1  matt 
    159  1.1  matt void
    160  1.6  matt gtpci_bus_configure(struct gtpci_chipset *gtpc)
    161  1.1  matt {
    162  1.3  matt #ifdef PCI_NETBSD_CONFIGURE
    163  1.1  matt 	struct extent *ioext, *memext;
    164  1.7  matt #if 0
    165  1.7  matt 	extern int pci_conf_debug;
    166  1.7  matt 	pci_conf_debug = 1;
    167  1.7  matt #endif
    168  1.1  matt 
    169  1.6  matt 	switch (gtpc->gtpc_busno) {
    170  1.1  matt 	case 0:
    171  1.3  matt 		ioext  = extent_create("pci0-io",  0x00000600, 0x0000ffff,
    172  1.3  matt 		    M_DEVBUF, NULL, 0, EX_NOWAIT);
    173  1.3  matt 		memext = extent_create("pci0-mem",
    174  1.3  matt 		    gt_pci0_mem_bs_tag.pbs_base,
    175  1.3  matt 		    gt_pci0_mem_bs_tag.pbs_limit-1,
    176  1.3  matt 		    M_DEVBUF, NULL, 0, EX_NOWAIT);
    177  1.1  matt 		break;
    178  1.1  matt 	case 1:
    179  1.3  matt 		ioext  = extent_create("pci1-io",  0x00000600, 0x0000ffff,
    180  1.3  matt 		    M_DEVBUF, NULL, 0, EX_NOWAIT);
    181  1.3  matt 		memext = extent_create("pci1-mem",
    182  1.3  matt 		    gt_pci1_mem_bs_tag.pbs_base,
    183  1.3  matt 		    gt_pci1_mem_bs_tag.pbs_limit-1,
    184  1.3  matt 		    M_DEVBUF, NULL, 0, EX_NOWAIT);
    185  1.1  matt 		break;
    186  1.1  matt 	}
    187  1.1  matt 
    188  1.6  matt 	pci_configure_bus(&gtpc->gtpc_pc, ioext, memext, NULL, 0, 32);
    189  1.1  matt 
    190  1.1  matt 	extent_destroy(ioext);
    191  1.1  matt 	extent_destroy(memext);
    192  1.3  matt #endif /* PCI_NETBSD_CONFIGURE */
    193  1.3  matt }
    194  1.3  matt 
    195  1.3  matt void
    196  1.3  matt gtpci_md_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin,
    197  1.3  matt 	int swiz, int *iline)
    198  1.3  matt {
    199  1.3  matt #ifdef PCI_NETBSD_CONFIGURE
    200  1.4  matt 	struct gtpci_chipset *gtpc = (struct gtpci_chipset *)pc;
    201  1.7  matt 	int line = (gtpc->gtpc_busno == 0 ? PCI0_GPPINTS : PCI1_GPPINTS);
    202  1.7  matt 	*iline = (line >> (8 * ((pin + swiz - 1) & 3))) & 0xff;
    203  1.7  matt 	if (*iline != 0xff)
    204  1.7  matt 		*iline += IRQ_GPP_BASE;
    205  1.3  matt #endif /* PCI_NETBSD_CONFIGURE */
    206  1.1  matt }
    207  1.1  matt 
    208  1.1  matt void
    209  1.1  matt gtpci_md_bus_devorder(pci_chipset_tag_t pc, int busno, char devs[])
    210  1.1  matt {
    211  1.7  matt 	struct gtpci_chipset *gtpc = (struct gtpci_chipset *)pc;
    212  1.7  matt 	int dev;
    213  1.1  matt 
    214  1.6  matt 	/*
    215  1.6  matt 	 * Don't bother probing the GT itself.
    216  1.6  matt 	 */
    217  1.7  matt 	for (dev = 0; dev < 32; dev++) {
    218  1.7  matt                 if (PCI_CFG_GET_BUSNO(gtpc->gtpc_self) == busno &&
    219  1.7  matt 		    (PCI_CFG_GET_DEVNO(gtpc->gtpc_self) == dev ||
    220  1.7  matt 			(gtpci_skipmask[gtpc->gtpc_busno] & (1 << dev))))
    221  1.7  matt 			continue;
    222  1.7  matt 
    223  1.7  matt 		*devs++ = dev;
    224  1.7  matt 	}
    225  1.1  matt 	*devs = -1;
    226  1.1  matt }
    227  1.1  matt 
    228  1.1  matt int
    229  1.1  matt gtpci_md_conf_hook(pci_chipset_tag_t pc, int bus, int dev, int func,
    230  1.1  matt 	pcireg_t id)
    231  1.1  matt {
    232  1.6  matt 	if (bus == 0 && dev == 0)	/* don't configure GT */
    233  1.1  matt 		return 0;
    234  1.1  matt 
    235  1.7  matt 	return PCI_CONF_ALL;
    236  1.1  matt }
    237  1.1  matt 
    238  1.1  matt int
    239  1.1  matt gtpci_md_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    240  1.1  matt {
    241  1.1  matt 	int	pin = pa->pa_intrpin;
    242  1.1  matt 	int	line = pa->pa_intrline;
    243  1.1  matt 
    244  1.7  matt 	if (pin > 4 || line >= NIRQ) {
    245  1.1  matt 		printf("pci_intr_map: bad interrupt pin %d\n", pin);
    246  1.1  matt 		*ihp = -1;
    247  1.1  matt 		return 1;
    248  1.1  matt 	}
    249  1.1  matt 
    250  1.1  matt 	*ihp = line;
    251  1.1  matt 	return 0;
    252  1.1  matt }
    253