Home | History | Annotate | Line # | Download | only in marvell
gtpci.c revision 1.21
      1  1.21    cegger /*	$NetBSD: gtpci.c,v 1.21 2009/05/12 14:30:25 cegger Exp $	*/
      2   1.1      matt 
      3   1.1      matt /*
      4   1.1      matt  * Copyright (c) 2002 Allegro Networks, Inc., Wasabi Systems, Inc.
      5   1.1      matt  * All rights reserved.
      6   1.1      matt  *
      7   1.1      matt  * Redistribution and use in source and binary forms, with or without
      8   1.1      matt  * modification, are permitted provided that the following conditions
      9   1.1      matt  * are met:
     10   1.1      matt  * 1. Redistributions of source code must retain the above copyright
     11   1.1      matt  *    notice, this list of conditions and the following disclaimer.
     12   1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     14   1.1      matt  *    documentation and/or other materials provided with the distribution.
     15   1.1      matt  * 3. All advertising materials mentioning features or use of this software
     16   1.1      matt  *    must display the following acknowledgement:
     17   1.1      matt  *      This product includes software developed for the NetBSD Project by
     18   1.1      matt  *      Allegro Networks, Inc., and Wasabi Systems, Inc.
     19   1.1      matt  * 4. The name of Allegro Networks, Inc. may not be used to endorse
     20   1.1      matt  *    or promote products derived from this software without specific prior
     21   1.1      matt  *    written permission.
     22   1.1      matt  * 5. The name of Wasabi Systems, Inc. may not be used to endorse
     23   1.1      matt  *    or promote products derived from this software without specific prior
     24   1.1      matt  *    written permission.
     25   1.1      matt  *
     26   1.1      matt  * THIS SOFTWARE IS PROVIDED BY ALLEGRO NETWORKS, INC. AND
     27   1.1      matt  * WASABI SYSTEMS, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     28   1.1      matt  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
     29   1.1      matt  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     30   1.1      matt  * IN NO EVENT SHALL EITHER ALLEGRO NETWORKS, INC. OR WASABI SYSTEMS, INC.
     31   1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32   1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33   1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34   1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35   1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36   1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37   1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     38   1.1      matt  */
     39  1.10     lukem 
     40  1.10     lukem #include <sys/cdefs.h>
     41  1.21    cegger __KERNEL_RCSID(0, "$NetBSD: gtpci.c,v 1.21 2009/05/12 14:30:25 cegger Exp $");
     42   1.1      matt 
     43   1.1      matt #include "opt_marvell.h"
     44   1.1      matt #include <sys/param.h>
     45   1.1      matt #include <sys/device.h>
     46   1.1      matt #include <sys/extent.h>
     47   1.1      matt #include <sys/malloc.h>
     48   1.1      matt #include <lib/libkern/libkern.h>
     49   1.1      matt 
     50   1.1      matt #define _BUS_SPACE_PRIVATE
     51   1.1      matt #define _BUS_DMA_PRIVATE
     52  1.16        ad #include <sys/bus.h>
     53  1.16        ad #include <sys/intr.h>
     54   1.1      matt 
     55   1.1      matt #include <dev/pci/pcireg.h>
     56   1.1      matt #include <dev/pci/pcivar.h>
     57   1.1      matt #include <dev/pci/pciconf.h>
     58   1.1      matt #include <dev/marvell/gtreg.h>
     59   1.1      matt #include <dev/marvell/gtvar.h>
     60   1.1      matt #include <dev/marvell/gtintrreg.h>
     61   1.1      matt #include <dev/marvell/gtpcireg.h>
     62   1.1      matt #include <dev/marvell/gtpcivar.h>
     63   1.1      matt 
     64   1.1      matt static int	gtpci_error_intr(void *);
     65   1.1      matt 
     66   1.5      matt static void	gtpci_bus_init(struct gtpci_chipset *);
     67   1.5      matt 
     68  1.21    cegger static void	gtpci_bus_attach_hook(device_t, device_t,
     69   1.1      matt 		    struct pcibus_attach_args *);
     70   1.1      matt static int	gtpci_bus_maxdevs(pci_chipset_tag_t, int);
     71   1.1      matt 
     72   1.1      matt static const char *
     73   1.1      matt 		gtpci_intr_string(pci_chipset_tag_t, pci_intr_handle_t);
     74   1.1      matt static const struct evcnt *
     75   1.1      matt 		gtpci_intr_evcnt(pci_chipset_tag_t, pci_intr_handle_t);
     76   1.1      matt static void	*gtpci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t,
     77   1.1      matt 		    int, int (*)(void *), void *);
     78   1.1      matt static void	gtpci_intr_disestablish(pci_chipset_tag_t, void *);
     79   1.1      matt 
     80   1.1      matt #ifdef DEBUG
     81   1.1      matt int gtpci_debug = 0;
     82   1.1      matt #endif
     83   1.1      matt 
     84   1.1      matt struct gtpci_softc {
     85   1.1      matt 	struct device gtpci_dev;
     86   1.2      matt 	struct gtpci_chipset gtpci_gtpc;
     87   1.1      matt };
     88   1.1      matt 
     89   1.1      matt static int gtpci_cfprint(void *, const char *);
     90  1.21    cegger static int gtpci_match(device_t, cfdata_t, void *);
     91  1.21    cegger static void gtpci_attach(device_t, device_t, void *);
     92   1.1      matt 
     93   1.1      matt CFATTACH_DECL(gtpci, sizeof(struct gtpci_softc),
     94   1.1      matt     gtpci_match, gtpci_attach, NULL, NULL);
     95   1.1      matt 
     96   1.1      matt extern struct cfdriver gtpci_cd;
     97   1.1      matt 
     98   1.1      matt const struct pci_chipset_functions gtpci_functions = {
     99   1.1      matt 	gtpci_bus_attach_hook,
    100   1.1      matt 	gtpci_bus_maxdevs,
    101   1.1      matt 	gtpci_md_bus_devorder,
    102   1.1      matt 
    103   1.1      matt 	gtpci_make_tag,
    104   1.1      matt 	gtpci_decompose_tag,
    105   1.1      matt 
    106   1.1      matt 	gtpci_conf_read,
    107   1.1      matt 	gtpci_conf_write,
    108   1.1      matt 	gtpci_md_conf_hook,
    109   1.1      matt 	gtpci_md_conf_interrupt,
    110   1.1      matt 
    111   1.1      matt 	gtpci_md_intr_map,
    112   1.1      matt 	gtpci_intr_string,
    113   1.1      matt 	gtpci_intr_evcnt,
    114   1.1      matt 	gtpci_intr_establish,
    115   1.1      matt 	gtpci_intr_disestablish
    116   1.1      matt };
    117   1.1      matt 
    118   1.6      matt static const int pci_irqs[2][3] = {
    119   1.6      matt     { IRQ_PCI0_0, IRQ_PCI0_1, IRQ_PCI0_2 },
    120   1.6      matt     { IRQ_PCI1_0, IRQ_PCI1_1, IRQ_PCI1_2 },
    121   1.6      matt };
    122   1.6      matt 
    123   1.6      matt static const struct pci_init {
    124   1.6      matt 	int bar_regno;
    125   1.6      matt 	u_int32_t bar_enable;
    126   1.6      matt  	bus_addr_t low_decode;
    127   1.6      matt 	bus_addr_t high_decode;
    128   1.6      matt 	bus_addr_t barsize;
    129   1.6      matt 	bus_addr_t accctl_high;
    130   1.6      matt 	bus_addr_t accctl_low;
    131   1.6      matt 	bus_addr_t accctl_top;
    132   1.6      matt } pci_initinfo[2][4] = {
    133   1.6      matt     	{
    134   1.6      matt 		{
    135   1.6      matt 			0x10,			PCI_BARE_SCS0En,
    136   1.6      matt 			GT_SCS0_Low_Decode,	GT_SCS0_High_Decode,
    137   1.6      matt 			PCI_SCS0_BAR_SIZE(0),
    138   1.6      matt 			PCI_ACCESS_CONTROL_BASE_HIGH(0, 0),
    139   1.6      matt 			PCI_ACCESS_CONTROL_BASE_LOW(0, 0),
    140   1.6      matt 			PCI_ACCESS_CONTROL_TOP(0, 0),
    141   1.6      matt 		}, {
    142   1.6      matt 			0x14,			PCI_BARE_SCS1En,
    143   1.6      matt 			GT_SCS1_Low_Decode,	GT_SCS1_High_Decode,
    144   1.6      matt 			PCI_SCS1_BAR_SIZE(0),
    145   1.6      matt 			PCI_ACCESS_CONTROL_BASE_HIGH(0, 1),
    146   1.6      matt 			PCI_ACCESS_CONTROL_BASE_LOW(0, 1),
    147   1.6      matt 			PCI_ACCESS_CONTROL_TOP(0, 1),
    148   1.6      matt 		}, {
    149   1.6      matt 			0x18,			PCI_BARE_SCS2En,
    150   1.6      matt 			GT_SCS2_Low_Decode,	GT_SCS2_High_Decode,
    151   1.6      matt 			PCI_SCS2_BAR_SIZE(0),
    152   1.6      matt 			PCI_ACCESS_CONTROL_BASE_HIGH(0, 2),
    153   1.6      matt 			PCI_ACCESS_CONTROL_BASE_LOW(0, 2),
    154   1.6      matt 			PCI_ACCESS_CONTROL_TOP(0, 2),
    155   1.6      matt 		}, {
    156   1.6      matt 			0x1c,			PCI_BARE_SCS3En,
    157   1.6      matt 			GT_SCS3_Low_Decode,	GT_SCS3_High_Decode,
    158   1.6      matt 			PCI_SCS3_BAR_SIZE(0),
    159   1.6      matt 			PCI_ACCESS_CONTROL_BASE_HIGH(0, 3),
    160   1.6      matt 			PCI_ACCESS_CONTROL_BASE_LOW(0, 3),
    161   1.6      matt 			PCI_ACCESS_CONTROL_TOP(0, 3),
    162   1.6      matt 		},
    163   1.6      matt 	}, {
    164   1.6      matt 		{
    165   1.6      matt 			0x10,			PCI_BARE_SCS0En,
    166   1.6      matt 			GT_SCS0_Low_Decode,	GT_SCS0_High_Decode,
    167   1.6      matt 			PCI_SCS0_BAR_SIZE(1),
    168   1.6      matt 			PCI_ACCESS_CONTROL_BASE_HIGH(1, 0),
    169   1.6      matt 			PCI_ACCESS_CONTROL_BASE_LOW(1, 0),
    170   1.6      matt 			PCI_ACCESS_CONTROL_TOP(1, 0),
    171   1.6      matt 		}, {
    172   1.6      matt 			0x14,			PCI_BARE_SCS1En,
    173   1.6      matt 			GT_SCS1_Low_Decode,	GT_SCS1_High_Decode,
    174   1.6      matt 			PCI_SCS1_BAR_SIZE(1),
    175   1.6      matt 			PCI_ACCESS_CONTROL_BASE_HIGH(1, 1),
    176   1.6      matt 			PCI_ACCESS_CONTROL_BASE_LOW(1, 1),
    177   1.6      matt 			PCI_ACCESS_CONTROL_TOP(1, 1),
    178   1.6      matt 		}, {
    179   1.6      matt 			0x18,			PCI_BARE_SCS2En,
    180   1.6      matt 			GT_SCS2_Low_Decode,	GT_SCS2_High_Decode,
    181   1.6      matt 			PCI_SCS2_BAR_SIZE(1),
    182   1.6      matt 			PCI_ACCESS_CONTROL_BASE_HIGH(1, 2),
    183   1.6      matt 			PCI_ACCESS_CONTROL_BASE_LOW(1, 2),
    184   1.6      matt 			PCI_ACCESS_CONTROL_TOP(1, 2),
    185   1.6      matt 		}, {
    186   1.6      matt 			0x1c,			PCI_BARE_SCS3En,
    187   1.6      matt 			GT_SCS3_Low_Decode,	GT_SCS3_High_Decode,
    188   1.6      matt 			PCI_SCS3_BAR_SIZE(1),
    189   1.6      matt 			PCI_ACCESS_CONTROL_BASE_HIGH(1, 3),
    190   1.6      matt 			PCI_ACCESS_CONTROL_BASE_LOW(1, 3),
    191   1.6      matt 			PCI_ACCESS_CONTROL_TOP(1, 3),
    192   1.6      matt 		},
    193   1.6      matt 	}
    194   1.6      matt };
    195   1.6      matt 
    196   1.1      matt int
    197  1.21    cegger gtpci_match(device_t parent, cfdata_t self, void *aux)
    198   1.1      matt {
    199  1.14   thorpej 	struct gt_softc * const gt = device_private(parent);
    200   1.2      matt 	struct gt_attach_args * const ga = aux;
    201   1.1      matt 
    202   1.2      matt 	return GT_PCIOK(gt, ga, &gtpci_cd);
    203   1.1      matt }
    204   1.1      matt 
    205   1.1      matt int
    206   1.1      matt gtpci_cfprint(void *aux, const char *pnp)
    207   1.1      matt {
    208   1.1      matt 	struct pcibus_attach_args *pba = (struct pcibus_attach_args *) aux;
    209  1.12     perry 
    210   1.1      matt 	if (pnp)
    211   1.2      matt 		aprint_normal("pci at %s", pnp);
    212   1.1      matt 
    213   1.2      matt 	aprint_normal(" bus %d", pba->pba_bus);
    214   1.1      matt 
    215   1.1      matt 	return (UNCONF);
    216   1.1      matt }
    217   1.1      matt 
    218   1.1      matt void
    219  1.21    cegger gtpci_attach(device_t parent, device_t self, void *aux)
    220   1.1      matt {
    221   1.1      matt 	struct pcibus_attach_args pba;
    222   1.2      matt 	struct gt_attach_args * const ga = aux;
    223  1.14   thorpej 	struct gt_softc * const gt = device_private(parent);
    224  1.14   thorpej 	struct gtpci_softc * const gtp = device_private(self);
    225   1.2      matt 	struct gtpci_chipset * const gtpc = &gtp->gtpci_gtpc;
    226   1.2      matt 	struct pci_chipset * const pc = &gtpc->gtpc_pc;
    227   1.2      matt 	const int busno = ga->ga_unit;
    228   1.1      matt 	uint32_t data;
    229   1.1      matt 
    230   1.2      matt 	GT_PCIFOUND(gt, ga);
    231   1.1      matt 
    232   1.1      matt 	pc->pc_funcs = &gtpci_functions;
    233   1.1      matt 	pc->pc_parent = self;
    234   1.1      matt 
    235   1.2      matt 	gtpc->gtpc_busno = busno;
    236   1.2      matt 	gtpc->gtpc_cfgaddr = PCI_CONFIG_ADDR(busno);
    237   1.2      matt 	gtpc->gtpc_cfgdata = PCI_CONFIG_DATA(busno);
    238   1.2      matt 	gtpc->gtpc_syncreg = PCI_SYNC_REG(busno);
    239   1.2      matt 	gtpc->gtpc_gt_memt = ga->ga_memt;
    240   1.2      matt 	gtpc->gtpc_gt_memh = ga->ga_memh;
    241   1.1      matt 
    242   1.6      matt 	/*
    243   1.6      matt 	 * Let's find out where we are located.
    244   1.6      matt 	 */
    245   1.6      matt 	data = gtpci_read(gtpc, PCI_P2P_CONFIGURATION(gtpc->gtpc_busno));
    246   1.6      matt 	gtpc->gtpc_self = gtpci_make_tag(&gtpc->gtpc_pc,
    247   1.6      matt 		PCI_P2PCFG_BusNum_GET(data), PCI_P2PCFG_DevNum_GET(data), 0);
    248   1.6      matt 
    249   1.6      matt 
    250   1.1      matt 	switch (busno) {
    251   1.1      matt 	case 0:
    252   1.2      matt 		gtpc->gtpc_io_bs = gt->gt_pci0_iot;
    253   1.2      matt 		gtpc->gtpc_mem_bs = gt->gt_pci0_memt;
    254   1.9       scw 		gtpc->gtpc_host = gt->gt_pci0_host;
    255   1.1      matt 		break;
    256   1.1      matt 	case 1:
    257   1.2      matt 		gtpc->gtpc_io_bs = gt->gt_pci1_iot;
    258   1.2      matt 		gtpc->gtpc_mem_bs = gt->gt_pci1_memt;
    259   1.9       scw 		gtpc->gtpc_host = gt->gt_pci1_host;
    260   1.1      matt 		break;
    261   1.1      matt 	default:
    262   1.1      matt 		break;
    263   1.1      matt 	}
    264   1.1      matt 
    265   1.2      matt 	/*
    266   1.2      matt 	 * If no bus_spaces exist, then it's been disabled.
    267   1.2      matt 	 */
    268   1.2      matt 	if (gtpc->gtpc_io_bs == NULL && gtpc->gtpc_mem_bs == NULL) {
    269   1.2      matt 		aprint_normal(": disabled\n");
    270   1.2      matt 		return;
    271   1.2      matt 	}
    272   1.2      matt 
    273   1.2      matt 	aprint_normal("\n");
    274   1.2      matt 
    275   1.6      matt 	/*
    276   1.6      matt 	 * clear any pre-existing error interrupt(s)
    277   1.6      matt 	 * clear latched pci error registers
    278   1.6      matt 	 * establish ISRs for PCI errors
    279   1.6      matt 	 * enable PCI error interrupts
    280   1.6      matt 	 */
    281   1.9       scw 	gtpci_write(gtpc, PCI_ERROR_MASK(gtpc->gtpc_busno), 0);
    282   1.6      matt 	gtpci_write(gtpc, PCI_ERROR_CAUSE(gtpc->gtpc_busno), 0);
    283   1.6      matt 	(void)gtpci_read(gtpc, PCI_ERROR_DATA_LOW(gtpc->gtpc_busno));
    284   1.6      matt 	(void)gtpci_read(gtpc, PCI_ERROR_DATA_HIGH(gtpc->gtpc_busno));
    285   1.6      matt 	(void)gtpci_read(gtpc, PCI_ERROR_COMMAND(gtpc->gtpc_busno));
    286   1.6      matt 	(void)gtpci_read(gtpc, PCI_ERROR_ADDRESS_HIGH(gtpc->gtpc_busno));
    287   1.6      matt 	(void)gtpci_read(gtpc, PCI_ERROR_ADDRESS_LOW(gtpc->gtpc_busno));
    288   1.9       scw 	if (gtpc->gtpc_host) {
    289   1.9       scw 		intr_establish(pci_irqs[gtpc->gtpc_busno][0], IST_LEVEL,
    290  1.17        ad 		    IPL_VM, gtpci_error_intr, pc);
    291   1.9       scw 		intr_establish(pci_irqs[gtpc->gtpc_busno][1], IST_LEVEL,
    292  1.17        ad 		    IPL_VM, gtpci_error_intr, pc);
    293   1.9       scw 		intr_establish(pci_irqs[gtpc->gtpc_busno][2], IST_LEVEL,
    294  1.17        ad 		    IPL_VM, gtpci_error_intr, pc);
    295  1.19        he 		aprint_normal_dev(pc->pc_parent, "%s%d error interrupts at irqs %s, %s, %s\n",
    296  1.18    cegger 		    "pci", busno,
    297   1.9       scw 		    intr_string(pci_irqs[gtpc->gtpc_busno][0]),
    298   1.9       scw 		    intr_string(pci_irqs[gtpc->gtpc_busno][1]),
    299   1.9       scw 		    intr_string(pci_irqs[gtpc->gtpc_busno][2]));
    300   1.9       scw 		gtpci_write(gtpc, PCI_ERROR_MASK(gtpc->gtpc_busno),
    301   1.9       scw 		    PCI_SERRMSK_ALL_ERRS);
    302   1.9       scw 	}
    303   1.6      matt 
    304   1.6      matt 	/*
    305   1.6      matt 	 * Fill in the pci_bus_attach_args
    306   1.6      matt 	 */
    307   1.1      matt 	pba.pba_pc = pc;
    308   1.1      matt 	pba.pba_bus = 0;
    309   1.2      matt 	pba.pba_iot = gtpc->gtpc_io_bs;
    310   1.2      matt 	pba.pba_memt = gtpc->gtpc_mem_bs;
    311   1.1      matt 	pba.pba_dmat = gt->gt_dmat;
    312   1.2      matt 	pba.pba_flags = 0;
    313   1.2      matt 	if (pba.pba_iot != NULL)
    314   1.2      matt 		pba.pba_flags |= PCI_FLAGS_IO_ENABLED;
    315   1.2      matt 	if (pba.pba_memt != NULL)
    316   1.2      matt 		pba.pba_flags |= PCI_FLAGS_MEM_ENABLED;
    317   1.1      matt 
    318   1.2      matt 	data = gtpci_read(gtpc, PCI_COMMAND(gtpc->gtpc_busno));
    319   1.1      matt 	if (data & PCI_CMD_MRdMul)
    320   1.1      matt 		pba.pba_flags |= PCI_FLAGS_MRM_OKAY;
    321   1.1      matt 	if (data & PCI_CMD_MRdLine)
    322   1.1      matt 		pba.pba_flags |= PCI_FLAGS_MRL_OKAY;
    323   1.1      matt 	pba.pba_flags |= PCI_FLAGS_MWI_OKAY;
    324   1.1      matt 
    325   1.1      matt 	gt_watchdog_service();
    326   1.6      matt 	/*
    327   1.6      matt 	 * Configure the pci bus.
    328   1.6      matt 	 */
    329  1.11  drochner 	config_found_ia(self, "pcibus", &pba, gtpci_cfprint);
    330   1.1      matt 
    331   1.1      matt 	gt_watchdog_service();
    332   1.1      matt 
    333   1.1      matt }
    334   1.1      matt 
    335   1.1      matt void
    336   1.5      matt gtpci_bus_init(struct gtpci_chipset *gtpc)
    337   1.5      matt {
    338   1.6      matt 	const struct pci_init *pi;
    339   1.6      matt 	uint32_t data, datal, datah;
    340   1.5      matt 	pcireg_t pcidata;
    341   1.6      matt 	int i;
    342   1.5      matt 
    343   1.5      matt 	/*
    344   1.5      matt 	 * disable all BARs to start.
    345   1.5      matt 	 */
    346   1.5      matt 	gtpci_write(gtpc, PCI_BASE_ADDR_REGISTERS_ENABLE(gtpc->gtpc_busno),
    347   1.5      matt 	    0xffffffff);
    348   1.5      matt 
    349   1.8       scw #ifndef GT_PCI0_EXT_ARBITER
    350   1.8       scw #define	GT_PCI0_EXT_ARBITER 0
    351   1.8       scw #endif
    352   1.8       scw #ifndef GT_PCI1_EXT_ARBITER
    353   1.8       scw #define	GT_PCI1_EXT_ARBITER 0
    354   1.8       scw #endif
    355   1.8       scw 
    356   1.9       scw 	if (gtpc->gtpc_host &&
    357   1.9       scw 	    ((!GT_PCI0_EXT_ARBITER && gtpc->gtpc_busno == 0) ||
    358   1.9       scw 	     (!GT_PCI1_EXT_ARBITER && gtpc->gtpc_busno == 1))) {
    359   1.8       scw 		/*
    360   1.8       scw 		 * Enable internal arbiter
    361   1.8       scw 		 */
    362   1.8       scw 		data = gtpci_read(gtpc, PCI_ARBITER_CONTROL(gtpc->gtpc_busno));
    363   1.8       scw 		data |= PCI_ARBCTL_EN;
    364   1.8       scw 		gtpci_write(gtpc, PCI_ARBITER_CONTROL(gtpc->gtpc_busno), data);
    365   1.8       scw 	} else {
    366   1.8       scw 		/*
    367   1.8       scw 		 * Make sure the internal arbiter is disabled
    368   1.8       scw 		 */
    369   1.8       scw 		gtpci_write(gtpc, PCI_ARBITER_CONTROL(gtpc->gtpc_busno), 0);
    370   1.8       scw 	}
    371   1.5      matt 
    372   1.5      matt 	/*
    373   1.5      matt 	 * Make the GT reflects reality.
    374   1.6      matt 	 * We always enable internal memory.
    375   1.5      matt 	 */
    376   1.9       scw 	if (gtpc->gtpc_host) {
    377   1.9       scw 		pcidata = gtpci_conf_read(&gtpc->gtpc_pc, gtpc->gtpc_self,
    378   1.9       scw 		    0x20) & 0xfff;
    379   1.9       scw 		gtpci_conf_write(&gtpc->gtpc_pc, gtpc->gtpc_self, 0x20,
    380   1.9       scw 		    GT_LowAddr_GET(gtpci_read(gtpc, GT_Internal_Decode)) |
    381   1.9       scw 		    pcidata);
    382   1.9       scw 	}
    383   1.6      matt 	data = PCI_BARE_IntMemEn;
    384   1.6      matt 
    385   1.7      matt 	for (i = 0, pi = pci_initinfo[gtpc->gtpc_busno]; i < 4; i++, pi++)
    386   1.6      matt 		gtpci_write(gtpc, pi->barsize, 0);
    387   1.5      matt 
    388   1.9       scw 	if (gtpc->gtpc_host) {
    389   1.9       scw 		/*
    390   1.9       scw 		 * Enable bus master access (needed for config access).
    391   1.9       scw 		 */
    392   1.9       scw 		pcidata = gtpci_conf_read(&gtpc->gtpc_pc, gtpc->gtpc_self,
    393   1.9       scw 		    PCI_COMMAND_STATUS_REG);
    394   1.9       scw 		pcidata |= PCI_COMMAND_MASTER_ENABLE;
    395   1.9       scw 		gtpci_conf_write(&gtpc->gtpc_pc, gtpc->gtpc_self,
    396   1.9       scw 		    PCI_COMMAND_STATUS_REG, pcidata);
    397   1.9       scw 	}
    398   1.5      matt 
    399   1.5      matt 	/*
    400   1.5      matt 	 * Map each SCS BAR to correspond to each SDRAM decode register.
    401   1.5      matt 	 */
    402   1.7      matt 	for (i = 0, pi = pci_initinfo[gtpc->gtpc_busno]; i < 4; i++, pi++) {
    403   1.6      matt 		datal = gtpci_read(gtpc, pi->low_decode);
    404   1.6      matt 		datah = gtpci_read(gtpc, pi->high_decode);
    405   1.6      matt 		pcidata = gtpci_conf_read(&gtpc->gtpc_pc, gtpc->gtpc_self,
    406   1.6      matt 		    pi->bar_regno);
    407   1.6      matt 		gtpci_write(gtpc, pi->accctl_high, 0);
    408   1.6      matt 		if (datal < datah) {
    409   1.6      matt 			datal &= 0xfff;
    410   1.6      matt 			pcidata &= 0xfff;
    411   1.6      matt 			pcidata |= datal << 20;
    412   1.6      matt 			data |= pi->bar_enable;
    413   1.6      matt 			datah -= datal;
    414   1.6      matt 			datal |= PCI_ACCCTLBASEL_PrefetchEn|
    415   1.6      matt 			    PCI_ACCCTLBASEL_RdPrefetch|
    416   1.6      matt 			    PCI_ACCCTLBASEL_RdLinePrefetch|
    417   1.6      matt 			    PCI_ACCCTLBASEL_RdMulPrefetch|
    418   1.6      matt 			    PCI_ACCCTLBASEL_WBurst_8_QW|
    419   1.6      matt 			    PCI_ACCCTLBASEL_PCISwap_NoSwap;
    420   1.6      matt 			gtpci_write(gtpc, pi->accctl_low, datal);
    421   1.6      matt 		} else {
    422   1.6      matt 			pcidata &= 0xfff;
    423   1.6      matt 			datal = 0xfff|PCI_ACCCTLBASEL_PCISwap_NoSwap;
    424   1.6      matt 			datah = 0;
    425   1.6      matt 		}
    426   1.6      matt 		gtpci_write(gtpc, pi->barsize,
    427   1.6      matt 		    datah ? ((datah << 20) | 0xff000) : 0);
    428   1.9       scw 		if (gtpc->gtpc_host) {
    429   1.9       scw 			gtpci_conf_write(&gtpc->gtpc_pc, gtpc->gtpc_self,
    430   1.9       scw 			    pi->bar_regno, pcidata);
    431   1.9       scw 		}
    432   1.6      matt 		gtpci_write(gtpc, pi->accctl_low, datal);
    433   1.6      matt 		gtpci_write(gtpc, pi->accctl_top, datah);
    434   1.5      matt 	}
    435   1.5      matt 
    436   1.5      matt 	/*
    437   1.5      matt 	 * Now re-enable those BARs that are real.
    438   1.5      matt 	 */
    439   1.5      matt 	gtpci_write(gtpc, PCI_BASE_ADDR_REGISTERS_ENABLE(gtpc->gtpc_busno),
    440   1.6      matt 	    ~data);
    441   1.5      matt 
    442   1.9       scw 	if (gtpc->gtpc_host) {
    443   1.9       scw 		/*
    444   1.9       scw 		 * Enable I/O and memory (bus master is already enabled) access.
    445   1.9       scw 		 */
    446   1.9       scw 		pcidata = gtpci_conf_read(&gtpc->gtpc_pc, gtpc->gtpc_self,
    447   1.9       scw 		    PCI_COMMAND_STATUS_REG);
    448   1.9       scw 		pcidata |= PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE;
    449   1.9       scw 		gtpci_conf_write(&gtpc->gtpc_pc, gtpc->gtpc_self,
    450   1.9       scw 		    PCI_COMMAND_STATUS_REG, pcidata);
    451   1.9       scw 	}
    452   1.5      matt }
    453   1.5      matt 
    454   1.5      matt void
    455  1.21    cegger gtpci_bus_attach_hook(device_t parent, device_t self,
    456   1.1      matt 	struct pcibus_attach_args *pba)
    457   1.1      matt {
    458   1.5      matt 	struct gtpci_chipset *gtpc = (struct gtpci_chipset *) pba->pba_pc;
    459   1.5      matt 	uint32_t data;
    460   1.6      matt #if defined(DEBUG)
    461   1.1      matt 	pcitag_t tag;
    462   1.6      matt 	int bus, dev;
    463   1.6      matt 	int i;
    464   1.5      matt #endif
    465   1.1      matt 
    466   1.5      matt 	if (gtpc->gtpc_pc.pc_parent != parent)
    467   1.1      matt 		return;
    468   1.1      matt 
    469   1.2      matt 	data = gtpci_read(gtpc, PCI_MODE(gtpc->gtpc_busno));
    470   1.2      matt 	aprint_normal(": id %d%s%s%s%s%s%s%s%s",
    471   1.1      matt 		PCI_MODE_PciID_GET(data),
    472   1.1      matt 		(data & PCI_MODE_Pci64) ? ", 64bit" : "",
    473   1.1      matt 		(data & PCI_MODE_ExpRom) ? ", Expansion Rom" : "",
    474   1.1      matt 		(data & PCI_MODE_VPD) ? ", VPD" : "",
    475   1.1      matt 		(data & PCI_MODE_MSI) ? ", MSI" : "",
    476   1.1      matt 		(data & PCI_MODE_PMG) ? ", PMG" : "",
    477   1.1      matt 		(data & PCI_MODE_HotSwap) ? ", HotSwap" : "",
    478   1.1      matt 		(data & PCI_MODE_BIST) ? ", BIST" : "",
    479   1.1      matt 		(data & PCI_MODE_PRst) ? "" : ", PRst");
    480   1.1      matt 
    481   1.3      matt #if 0
    482   1.1      matt 	while ((data & PCI_MODE_PRst) == 0) {
    483   1.3      matt 		DELAY(10);
    484   1.2      matt 		data = gtpci_read(gtpc, PCI_MODE(gtpc->gtpc_busno));
    485   1.3      matt 		aprint_normal(".");
    486   1.1      matt 	}
    487   1.3      matt #endif
    488   1.1      matt 
    489   1.5      matt 	gtpci_bus_init(gtpc);
    490   1.5      matt 	gtpci_bus_configure(gtpc);
    491   1.6      matt 
    492   1.6      matt 	data = gtpci_read(gtpc, PCI_COMMAND(gtpc->gtpc_busno));
    493   1.6      matt 	if (data & (PCI_CMD_MSwapEn|PCI_CMD_SSwapEn)) {
    494  1.18    cegger 		aprint_normal("\n");
    495  1.18    cegger 		aprint_normal_dev(self, "");
    496   1.6      matt 		if (data & PCI_CMD_MSwapEn) {
    497   1.6      matt 			switch (data & (PCI_CMD_MWordSwap|PCI_CMD_MByteSwap)) {
    498   1.6      matt 			case PCI_CMD_MWordSwap:
    499   1.6      matt 				aprint_normal(" mswap=w"); break;
    500   1.6      matt 			case PCI_CMD_MByteSwap:
    501   1.6      matt 				aprint_normal(" mswap=b"); break;
    502   1.6      matt 			case PCI_CMD_MWordSwap|PCI_CMD_MByteSwap:
    503   1.6      matt 				aprint_normal(" mswap=b+w"); break;
    504   1.6      matt 			case 0:
    505   1.6      matt 				aprint_normal(" mswap=none"); break;
    506   1.6      matt 			}
    507   1.6      matt 		}
    508   1.6      matt 
    509   1.6      matt 		if (data & PCI_CMD_SSwapEn) {
    510   1.6      matt 			switch (data & (PCI_CMD_SWordSwap|PCI_CMD_SByteSwap)) {
    511   1.6      matt 			case PCI_CMD_SWordSwap:
    512   1.6      matt 				aprint_normal(" sswap=w"); break;
    513   1.6      matt 			case PCI_CMD_SByteSwap:
    514   1.6      matt 				aprint_normal(" sswap=b"); break;
    515   1.6      matt 			case PCI_CMD_SWordSwap|PCI_CMD_SByteSwap:
    516   1.6      matt 				aprint_normal(" sswap=b+w"); break;
    517   1.6      matt 			case 0:
    518   1.6      matt 				aprint_normal(" sswap=none"); break;
    519   1.6      matt 			}
    520   1.6      matt 		}
    521   1.6      matt 	}
    522   1.6      matt 
    523   1.6      matt #if defined(DEBUG)
    524   1.6      matt 	if (gtpci_debug == 0)
    525   1.6      matt 		return;
    526  1.12     perry 
    527   1.2      matt 	data = gtpci_read(gtpc, PCI_BASE_ADDR_REGISTERS_ENABLE(gtpc->gtpc_busno));
    528  1.18    cegger 	aprint_normal("\n");
    529  1.18    cegger 	aprint_normal_dev(self, "BARs enabled: %#x", data);
    530   1.1      matt 
    531  1.18    cegger 	aprint_normal("\n");
    532  1.18    cegger 	aprint_normal_dev(self, "0:0:0\n");
    533   1.2      matt 	aprint_normal("   %sSCS0=%#010x",
    534   1.1      matt 		(data & 1) ? "-" : "+",
    535   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, gtpc->gtpc_self, 0x10));
    536   1.2      matt 	aprint_normal("/%#010x", gtpci_read(gtpc,
    537   1.6      matt 		PCI_SCS0_BAR_SIZE(gtpc->gtpc_busno)));
    538   1.2      matt 	aprint_normal("  remap %#010x\n",
    539   1.2      matt 		gtpci_read(gtpc, PCI_SCS0_BASE_ADDR_REMAP(gtpc->gtpc_busno)));
    540   1.1      matt 
    541   1.2      matt 	aprint_normal("   %sSCS1=%#010x",
    542   1.1      matt 		(data & 2) ? "-" : "+",
    543   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, gtpc->gtpc_self, 0x14));
    544   1.2      matt 	aprint_normal("/%#010x",
    545   1.6      matt 		gtpci_read(gtpc, PCI_SCS1_BAR_SIZE(gtpc->gtpc_busno)));
    546   1.2      matt 	aprint_normal("  remap %#010x\n",
    547   1.2      matt 		gtpci_read(gtpc, PCI_SCS1_BASE_ADDR_REMAP(gtpc->gtpc_busno)));
    548   1.1      matt 
    549   1.2      matt 	aprint_normal("   %sSCS2=%#010x",
    550   1.1      matt 		(data & 4) ? "-" : "+",
    551   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, gtpc->gtpc_self, 0x18));
    552   1.2      matt 	aprint_normal("/%#010x",
    553   1.6      matt 		gtpci_read(gtpc, PCI_SCS2_BAR_SIZE(gtpc->gtpc_busno)));
    554   1.2      matt 	aprint_normal("  remap %#010x\n",
    555   1.2      matt 		gtpci_read(gtpc, PCI_SCS2_BASE_ADDR_REMAP(gtpc->gtpc_busno)));
    556   1.1      matt 
    557   1.2      matt 	aprint_normal("   %sSCS3=%#010x",
    558   1.1      matt 		(data & 8) ? "-" : "+",
    559   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, gtpc->gtpc_self, 0x1c));
    560   1.2      matt 	aprint_normal("/%#010x",
    561   1.6      matt 		gtpci_read(gtpc, PCI_SCS3_BAR_SIZE(gtpc->gtpc_busno)));
    562   1.2      matt 	aprint_normal("  remap %#010x\n",
    563   1.2      matt 		gtpci_read(gtpc, PCI_SCS3_BASE_ADDR_REMAP(gtpc->gtpc_busno)));
    564   1.1      matt 
    565   1.2      matt 	aprint_normal("   %sIMem=%#010x",
    566   1.1      matt 		(data & PCI_BARE_IntMemEn) ? "-" : "+",
    567   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, gtpc->gtpc_self, 0x20));
    568   1.2      matt 	aprint_normal("\n");
    569   1.2      matt 	aprint_normal("    %sIIO=%#010x",
    570   1.1      matt 		(data & PCI_BARE_IntIOEn) ? "-" : "+",
    571   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, gtpc->gtpc_self, 0x24));
    572   1.2      matt 	aprint_normal("\n");
    573   1.6      matt 
    574   1.6      matt 	gtpci_decompose_tag(&gtpc->gtpc_pc, gtpc->gtpc_self, &bus, &dev, NULL);
    575   1.6      matt 	tag = gtpci_make_tag(&gtpc->gtpc_pc, bus, dev, 1);
    576   1.2      matt 	aprint_normal("    %sCS0=%#010x",
    577   1.1      matt 		(data & PCI_BARE_CS0En) ? "-" : "+",
    578   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, tag, 0x10));
    579   1.2      matt 	aprint_normal("/%#010x",
    580   1.6      matt 		gtpci_read(gtpc, PCI_CS0_BAR_SIZE(gtpc->gtpc_busno)));
    581   1.2      matt 	aprint_normal("  remap %#010x\n",
    582   1.2      matt 		gtpci_read(gtpc, PCI_CS0_BASE_ADDR_REMAP(gtpc->gtpc_busno)));
    583   1.1      matt 
    584   1.2      matt 	aprint_normal("    %sCS1=%#010x",
    585   1.1      matt 		(data & PCI_BARE_CS1En) ? "-" : "+",
    586   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, tag, 0x14));
    587   1.2      matt 	aprint_normal("/%#010x",
    588   1.6      matt 		gtpci_read(gtpc, PCI_CS1_BAR_SIZE(gtpc->gtpc_busno)));
    589   1.2      matt 	aprint_normal("  remap %#010x\n",
    590   1.2      matt 		gtpci_read(gtpc, PCI_CS1_BASE_ADDR_REMAP(gtpc->gtpc_busno)));
    591   1.1      matt 
    592   1.2      matt 	aprint_normal("    %sCS2=%#010x",
    593   1.1      matt 		(data & PCI_BARE_CS2En) ? "-" : "+",
    594   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, tag, 0x18));
    595   1.2      matt 	aprint_normal("/%#010x",
    596   1.6      matt 		gtpci_read(gtpc, PCI_CS2_BAR_SIZE(gtpc->gtpc_busno)));
    597   1.2      matt 	aprint_normal("  remap %#010x\n",
    598   1.2      matt 		gtpci_read(gtpc, PCI_CS2_BASE_ADDR_REMAP(gtpc->gtpc_busno)));
    599   1.1      matt 
    600   1.2      matt 	aprint_normal("    %sCS3=%#010x",
    601   1.1      matt 		(data & PCI_BARE_CS3En) ? "-" : "+",
    602   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, tag, 0x1c));
    603   1.2      matt 	aprint_normal("/%#010x",
    604   1.6      matt 		gtpci_read(gtpc, PCI_CS3_BAR_SIZE(gtpc->gtpc_busno)));
    605   1.2      matt 	aprint_normal("  remap %#010x\n",
    606   1.2      matt 		gtpci_read(gtpc, PCI_CS3_BASE_ADDR_REMAP(gtpc->gtpc_busno)));
    607   1.1      matt 
    608   1.2      matt 	aprint_normal(" %sBootCS=%#010x",
    609   1.1      matt 		(data & PCI_BARE_BootCSEn) ? "-" : "+",
    610   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, tag, 0x20));
    611   1.2      matt 	aprint_normal("/%#010x",
    612   1.6      matt 		gtpci_read(gtpc, PCI_BOOTCS_BAR_SIZE(gtpc->gtpc_busno)));
    613   1.2      matt 	aprint_normal("  remap %#010x\n",
    614   1.2      matt 		gtpci_read(gtpc, PCI_BOOTCS_ADDR_REMAP(gtpc->gtpc_busno)));
    615   1.1      matt 
    616   1.6      matt 	tag = gtpci_make_tag(&gtpc->gtpc_pc, bus, tag, 2);
    617   1.2      matt 	aprint_normal("  %sP2PM0=%#010x",
    618   1.1      matt 		(data & PCI_BARE_P2PMem0En) ? "-" : "+",
    619   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, tag, 0x10));
    620   1.2      matt 	aprint_normal("/%#010x",
    621   1.6      matt 		gtpci_read(gtpc, PCI_P2P_MEM0_BAR_SIZE(gtpc->gtpc_busno)));
    622   1.2      matt 	aprint_normal("  remap %#010x.%#010x\n",
    623   1.2      matt 		gtpci_read(gtpc, PCI_P2P_MEM0_BASE_ADDR_REMAP_HIGH(gtpc->gtpc_busno)),
    624   1.2      matt 		gtpci_read(gtpc, PCI_P2P_MEM0_BASE_ADDR_REMAP_LOW(gtpc->gtpc_busno)));
    625   1.1      matt 
    626   1.2      matt 	aprint_normal("  %sP2PM1=%#010x",
    627   1.1      matt 		(data & PCI_BARE_P2PMem1En) ? "-" : "+",
    628   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, tag, 0x14));
    629   1.2      matt 	aprint_normal("/%#010x",
    630   1.6      matt 		gtpci_read(gtpc, PCI_P2P_MEM1_BAR_SIZE(gtpc->gtpc_busno)));
    631   1.2      matt 	aprint_normal("  remap %#010x.%#010x\n",
    632   1.2      matt 		gtpci_read(gtpc, PCI_P2P_MEM1_BASE_ADDR_REMAP_HIGH(gtpc->gtpc_busno)),
    633   1.2      matt 		gtpci_read(gtpc, PCI_P2P_MEM1_BASE_ADDR_REMAP_LOW(gtpc->gtpc_busno)));
    634   1.1      matt 
    635   1.2      matt 	aprint_normal("  %sP2PIO=%#010x",
    636   1.1      matt 		(data & PCI_BARE_P2PIOEn) ? "-" : "+",
    637   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, tag, 0x18));
    638   1.2      matt 	aprint_normal("/%#010x",
    639   1.6      matt 		gtpci_read(gtpc, PCI_P2P_IO_BAR_SIZE(gtpc->gtpc_busno)));
    640   1.2      matt 	aprint_normal("  remap %#010x\n",
    641   1.2      matt 		gtpci_read(gtpc, PCI_P2P_IO_BASE_ADDR_REMAP(gtpc->gtpc_busno)));
    642   1.1      matt 
    643   1.2      matt 	aprint_normal("    %sCPU=%#010x",
    644   1.1      matt 		(data & PCI_BARE_CPUEn) ? "-" : "+",
    645   1.6      matt 		gtpci_conf_read(&gtpc->gtpc_pc, tag, 0x1c));
    646   1.2      matt 	aprint_normal("/%#010x",
    647   1.6      matt 		gtpci_read(gtpc, PCI_CPU_BAR_SIZE(gtpc->gtpc_busno)));
    648   1.2      matt 	aprint_normal("  remap %#010x\n",
    649   1.2      matt 		gtpci_read(gtpc, PCI_CPU_BASE_ADDR_REMAP(gtpc->gtpc_busno)));
    650   1.1      matt 
    651   1.1      matt 	for (i = 0; i < 8; i++) {
    652  1.18    cegger 		aprint_normal("\n");
    653  1.18    cegger 		aprint_normal_dev("Access Control %d: ", device_xname(self), i);
    654   1.6      matt 		data = gtpci_read(gtpc,
    655   1.6      matt 		    PCI_ACCESS_CONTROL_BASE_HIGH(gtpc->gtpc_busno, i));
    656   1.6      matt 		if (data)
    657   1.6      matt 			aprint_normal("base=0x%08x.", data);
    658   1.6      matt 		else
    659   1.6      matt 			aprint_normal("base=0x");
    660   1.6      matt 		data = gtpci_read(gtpc,
    661   1.6      matt 			PCI_ACCESS_CONTROL_BASE_LOW(gtpc->gtpc_busno, i));
    662   1.6      matt 		printf("%08x cfg=0x%08x", data << 20, data & ~0xfff);
    663   1.6      matt 		aprint_normal(" top=0x%03x00000",
    664   1.6      matt 		    gtpci_read(gtpc,
    665   1.6      matt 			PCI_ACCESS_CONTROL_TOP(gtpc->gtpc_busno, i)));
    666   1.1      matt 	}
    667   1.1      matt #endif
    668   1.1      matt }
    669   1.1      matt 
    670   1.1      matt static const char * const gtpci_error_strings[] = PCI_IC_SEL_Strings;
    671   1.1      matt 
    672   1.1      matt int
    673   1.1      matt gtpci_error_intr(void *arg)
    674   1.1      matt {
    675   1.1      matt 	pci_chipset_tag_t pc = arg;
    676   1.2      matt 	struct gtpci_chipset *gtpc = (struct gtpci_chipset *)pc;
    677   1.1      matt 	uint32_t cause, mask, errmask;
    678   1.1      matt 	u_int32_t alo, ahi, dlo, dhi, cmd;
    679   1.1      matt 	int i;
    680   1.1      matt 
    681   1.2      matt 	cause = gtpci_read(gtpc, PCI_ERROR_CAUSE(gtpc->gtpc_busno));
    682   1.2      matt 	errmask = gtpci_read(gtpc, PCI_ERROR_MASK(gtpc->gtpc_busno));
    683   1.6      matt 	cause &= errmask | 0xf8000000;
    684   1.2      matt 	gtpci_write(gtpc, PCI_ERROR_CAUSE(gtpc->gtpc_busno), ~cause);
    685   1.1      matt 	printf("%s: pci%d error: cause=%#x mask=%#x",
    686  1.18    cegger 		device_xname(pc->pc_parent), gtpc->gtpc_busno, cause, errmask);
    687   1.6      matt 	if ((cause & 0xf8000000) == 0) {
    688   1.1      matt 		printf(" ?\n");
    689   1.1      matt 		return 0;
    690   1.1      matt 	}
    691   1.1      matt 
    692   1.1      matt 	for (i = 0, mask = 1; i <= 26; i++, mask += mask)
    693   1.1      matt 		if (mask & cause)
    694   1.1      matt 			printf(" %s", gtpci_error_strings[i]);
    695   1.1      matt 
    696   1.1      matt 	/*
    697   1.1      matt 	 * "no new data is latched until the PCI Error Low Address
    698   1.1      matt 	 * register is read.  This means that PCI Error Low Address
    699   1.1      matt 	 * register must be the last register read by the interrupt
    700   1.1      matt 	 * handler."
    701   1.1      matt 	 */
    702   1.2      matt 	dlo = gtpci_read(gtpc, PCI_ERROR_DATA_LOW(gtpc->gtpc_busno));
    703   1.2      matt 	dhi = gtpci_read(gtpc, PCI_ERROR_DATA_HIGH(gtpc->gtpc_busno));
    704   1.2      matt 	cmd = gtpci_read(gtpc, PCI_ERROR_COMMAND(gtpc->gtpc_busno));
    705   1.2      matt 	ahi = gtpci_read(gtpc, PCI_ERROR_ADDRESS_HIGH(gtpc->gtpc_busno));
    706   1.2      matt 	alo = gtpci_read(gtpc, PCI_ERROR_ADDRESS_LOW(gtpc->gtpc_busno));
    707   1.6      matt 	printf("\n%s: pci%d error: %s cmd=%#x",
    708  1.18    cegger 		device_xname(pc->pc_parent), gtpc->gtpc_busno,
    709   1.6      matt 		gtpci_error_strings[PCI_IC_SEL_GET(cause)], cmd);
    710   1.6      matt 	if (dhi == 0)
    711   1.6      matt 		printf(" data=%08x", dlo);
    712   1.6      matt 	else
    713   1.6      matt 		printf(" data=%08x.%08x", dhi, dlo);
    714   1.6      matt 	if (ahi == 0)
    715   1.6      matt 		printf(" address=%08x\n", alo);
    716   1.6      matt 	else
    717   1.6      matt 		printf(" address=%08x.%08x\n", ahi, alo);
    718   1.1      matt 
    719   1.1      matt #if defined(DEBUG) && defined(DDB)
    720   1.6      matt 	if (gtpci_debug > 1)
    721   1.1      matt 		Debugger();
    722   1.1      matt #endif
    723   1.1      matt 	return 1;
    724   1.1      matt }
    725   1.1      matt 
    726   1.1      matt 
    727   1.1      matt #if 0
    728   1.1      matt void
    729   1.1      matt gtpci_bs_region_add(pci_chipset_tag_t pc, struct discovery_bus_space *bs,
    730   1.1      matt 	struct gt_softc *gt, bus_addr_t lo, bus_addr_t hi)
    731   1.1      matt {
    732   1.1      matt 	/* See how I/O space is configured.  Read the base and top
    733   1.1      matt 	 * registers.
    734   1.1      matt 	 */
    735   1.1      matt 	paddr_t pbasel, pbaseh;
    736   1.1      matt 	uint32_t datal, datah;
    737   1.1      matt 
    738   1.2      matt 	datal = gtpci_read(gtpc, lo);
    739   1.2      matt 	datah = gtpci_read(gtpc, hi);
    740   1.1      matt 	pbasel = GT_LowAddr_GET(datal);
    741   1.1      matt 	pbaseh = GT_HighAddr_GET(datah);
    742   1.1      matt 	/*
    743   1.1      matt 	 * If the start is greater than the end, ignore the region.
    744   1.1      matt  	 */
    745   1.1      matt 	if (pbaseh < pbasel)
    746   1.1      matt 		return;
    747   1.1      matt 	if ((pbasel & gt->gt_iobat_mask) == gt->gt_iobat_pbase
    748   1.1      matt 	    && (pbaseh & gt->gt_iobat_mask) == gt->gt_iobat_pbase) {
    749   1.1      matt 		bs->bs_regions[bs->bs_nregion].br_vbase =
    750   1.1      matt 			gt->gt_iobat_vbase + (pbasel & ~gt->gt_iobat_mask);
    751   1.1      matt 	}
    752   1.1      matt 	bs->bs_regions[bs->bs_nregion].br_pbase = pbasel;
    753   1.1      matt 	if (bs->bs_flags & _BUS_SPACE_RELATIVE) {
    754   1.1      matt 		bs->bs_regions[bs->bs_nregion].br_start = 0;
    755   1.1      matt 		bs->bs_regions[bs->bs_nregion].br_end = pbaseh - pbasel;
    756   1.1      matt 	} else {
    757   1.1      matt 		bs->bs_regions[bs->bs_nregion].br_start = pbasel;
    758   1.1      matt 		bs->bs_regions[bs->bs_nregion].br_end = pbaseh;
    759   1.1      matt 	}
    760   1.1      matt 	bs->bs_nregion++;
    761   1.1      matt }
    762   1.1      matt #endif
    763   1.1      matt 
    764   1.1      matt /*
    765   1.1      matt  * Internal functions.
    766   1.1      matt  */
    767   1.1      matt int
    768   1.1      matt gtpci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
    769   1.1      matt {
    770   1.1      matt 	return 32;
    771   1.1      matt }
    772   1.1      matt 
    773   1.1      matt pcitag_t
    774   1.1      matt gtpci_make_tag(pci_chipset_tag_t pc, int busno, int devno, int funcno)
    775   1.1      matt {
    776   1.1      matt 	return PCI_CFG_MAKE_TAG(busno, devno, funcno, 0);
    777   1.1      matt }
    778   1.1      matt 
    779   1.1      matt void
    780   1.1      matt gtpci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag,
    781   1.1      matt 		    int *bp, int *dp, int *fp)
    782   1.1      matt {
    783   1.1      matt 	if (bp != NULL)
    784   1.1      matt 		*bp = PCI_CFG_GET_BUSNO(tag);
    785   1.1      matt 	if (dp != NULL)
    786   1.1      matt 		*dp = PCI_CFG_GET_DEVNO(tag);
    787   1.1      matt 	if (fp != NULL)
    788   1.1      matt 		*fp = PCI_CFG_GET_FUNCNO(tag);
    789   1.1      matt }
    790   1.1      matt 
    791   1.1      matt pcireg_t
    792   1.1      matt gtpci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int regno)
    793   1.1      matt {
    794   1.2      matt 	struct gtpci_chipset *gtpc = (struct gtpci_chipset *)pc;
    795   1.1      matt #ifdef DIAGNOSTIC
    796   1.6      matt 	if ((regno & 3) || (regno & ~0xff))
    797   1.1      matt 		panic("gtpci_conf_read: bad regno %#x\n", regno);
    798   1.1      matt #endif
    799   1.2      matt 	gtpci_write(gtpc, gtpc->gtpc_cfgaddr, (int) tag | regno);
    800   1.2      matt 	return gtpci_read(gtpc, gtpc->gtpc_cfgdata);
    801   1.1      matt }
    802   1.1      matt 
    803   1.1      matt void
    804   1.1      matt gtpci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int regno, pcireg_t data)
    805   1.1      matt {
    806   1.2      matt 	struct gtpci_chipset *gtpc = (struct gtpci_chipset *)pc;
    807   1.1      matt #ifdef DIAGNOSTIC
    808   1.6      matt 	if ((regno & 3) || (regno & ~0xff))
    809   1.1      matt 		panic("gtpci_conf_write: bad regno %#x\n", regno);
    810   1.1      matt #endif
    811   1.2      matt 	gtpci_write(gtpc, gtpc->gtpc_cfgaddr, (int) tag | regno);
    812   1.2      matt 	gtpci_write(gtpc, gtpc->gtpc_cfgdata, data);
    813   1.1      matt }
    814   1.1      matt 
    815   1.1      matt const char *
    816   1.1      matt gtpci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t pih)
    817   1.1      matt {
    818   1.1      matt 	return intr_string(pih);
    819   1.1      matt }
    820   1.1      matt 
    821   1.1      matt const struct evcnt *
    822   1.1      matt gtpci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t pih)
    823   1.1      matt {
    824   1.1      matt 	return intr_evcnt(pih);
    825   1.1      matt }
    826   1.1      matt 
    827   1.1      matt void *
    828   1.1      matt gtpci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t pih,
    829   1.1      matt     int ipl, int (*handler)(void *), void *arg)
    830   1.1      matt {
    831   1.1      matt 	return intr_establish(pih, IST_LEVEL, ipl, handler, arg);
    832   1.1      matt }
    833   1.1      matt 
    834   1.1      matt void
    835   1.1      matt gtpci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
    836   1.1      matt {
    837   1.1      matt 	intr_disestablish(cookie);
    838   1.1      matt }
    839