pci_machdep.c revision 1.21
11.21Stsutsui/*	$NetBSD: pci_machdep.c,v 1.21 2006/04/09 01:24:05 tsutsui Exp $	*/
21.1Ssoren
31.1Ssoren/*
41.1Ssoren * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
51.1Ssoren *
61.1Ssoren * Redistribution and use in source and binary forms, with or without
71.1Ssoren * modification, are permitted provided that the following conditions
81.1Ssoren * are met:
91.1Ssoren * 1. Redistributions of source code must retain the above copyright
101.1Ssoren *    notice, this list of conditions, and the following disclaimer.
111.1Ssoren * 2. Redistributions in binary form must reproduce the above copyright
121.1Ssoren *    notice, this list of conditions and the following disclaimer in the
131.1Ssoren *    documentation and/or other materials provided with the distribution.
141.1Ssoren *
151.1Ssoren * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
161.1Ssoren * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171.1Ssoren * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
181.1Ssoren * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
191.1Ssoren * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201.1Ssoren * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
211.1Ssoren * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221.1Ssoren * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
231.1Ssoren * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241.1Ssoren * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251.1Ssoren * SUCH DAMAGE.
261.1Ssoren */
271.13Slukem
281.13Slukem#include <sys/cdefs.h>
291.21Stsutsui__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.21 2006/04/09 01:24:05 tsutsui Exp $");
301.1Ssoren
311.1Ssoren#include <sys/types.h>
321.1Ssoren#include <sys/param.h>
331.1Ssoren#include <sys/time.h>
341.1Ssoren#include <sys/systm.h>
351.1Ssoren#include <sys/errno.h>
361.1Ssoren#include <sys/device.h>
371.17Stsutsui#include <sys/extent.h>
381.1Ssoren
391.1Ssoren#define _COBALT_BUS_DMA_PRIVATE
401.1Ssoren#include <machine/bus.h>
411.4Ssoren#include <machine/intr.h>
421.1Ssoren
431.1Ssoren#include <dev/pci/pcivar.h>
441.1Ssoren#include <dev/pci/pcireg.h>
451.1Ssoren#include <dev/pci/pcidevs.h>
461.17Stsutsui#include <dev/pci/pciconf.h>
471.1Ssoren
481.16Stsutsui#include <cobalt/dev/gtreg.h>
491.16Stsutsui
501.1Ssoren/*
511.1Ssoren * PCI doesn't have any special needs; just use
521.1Ssoren * the generic versions of these functions.
531.1Ssoren */
541.1Ssorenstruct cobalt_bus_dma_tag pci_bus_dma_tag = {
551.14Stsutsui	_bus_dmamap_create,
561.1Ssoren	_bus_dmamap_destroy,
571.1Ssoren	_bus_dmamap_load,
581.1Ssoren	_bus_dmamap_load_mbuf,
591.1Ssoren	_bus_dmamap_load_uio,
601.1Ssoren	_bus_dmamap_load_raw,
611.1Ssoren	_bus_dmamap_unload,
621.1Ssoren	_bus_dmamap_sync,
631.1Ssoren	_bus_dmamem_alloc,
641.1Ssoren	_bus_dmamem_free,
651.1Ssoren	_bus_dmamem_map,
661.1Ssoren	_bus_dmamem_unmap,
671.1Ssoren	_bus_dmamem_mmap,
681.1Ssoren};
691.1Ssoren
701.1Ssorenvoid
711.20Stsutsuipci_attach_hook(struct device *parent, struct device *self,
721.20Stsutsui    struct pcibus_attach_args *pba)
731.1Ssoren{
741.1Ssoren	/* XXX */
751.1Ssoren
761.1Ssoren	return;
771.1Ssoren}
781.1Ssoren
791.1Ssorenint
801.20Stsutsuipci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
811.1Ssoren{
821.20Stsutsui
831.6Ssoren	return 32;
841.1Ssoren}
851.1Ssoren
861.1Ssorenpcitag_t
871.20Stsutsuipci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
881.1Ssoren{
891.20Stsutsui
901.1Ssoren	return (bus << 16) | (device << 11) | (function << 8);
911.1Ssoren}
921.1Ssoren
931.1Ssorenvoid
941.20Stsutsuipci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
951.1Ssoren{
961.20Stsutsui
971.1Ssoren	if (bp != NULL)
981.1Ssoren		*bp = (tag >> 16) & 0xff;
991.1Ssoren	if (dp != NULL)
1001.1Ssoren		*dp = (tag >> 11) & 0x1f;
1011.1Ssoren	if (fp != NULL)
1021.1Ssoren		*fp = (tag >> 8) & 0x07;
1031.1Ssoren}
1041.1Ssoren
1051.1Ssorenpcireg_t
1061.20Stsutsuipci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
1071.1Ssoren{
1081.1Ssoren	pcireg_t data;
1091.6Ssoren	int bus, dev, func;
1101.14Stsutsui
1111.6Ssoren	pci_decompose_tag(pc, tag, &bus, &dev, &func);
1121.6Ssoren
1131.6Ssoren	/*
1141.6Ssoren	 * 2700 hardware wedges on accesses to device 6.
1151.6Ssoren	 */
1161.6Ssoren	if (bus == 0 && dev == 6)
1171.6Ssoren		return 0;
1181.6Ssoren	/*
1191.6Ssoren	 * 2800 hardware wedges on accesses to device 31.
1201.6Ssoren	 */
1211.6Ssoren	if (bus == 0 && dev == 31)
1221.6Ssoren		return 0;
1231.1Ssoren
1241.16Stsutsui	bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR,
1251.21Stsutsui	    PCICFG_ENABLE | tag | reg);
1261.16Stsutsui	data = bus_space_read_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_DATA);
1271.16Stsutsui	bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 0);
1281.1Ssoren
1291.1Ssoren	return data;
1301.1Ssoren}
1311.1Ssoren
1321.1Ssorenvoid
1331.20Stsutsuipci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
1341.1Ssoren{
1351.1Ssoren
1361.16Stsutsui	bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR,
1371.21Stsutsui	    PCICFG_ENABLE | tag | reg);
1381.16Stsutsui	bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_DATA, data);
1391.16Stsutsui	bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 0);
1401.1Ssoren}
1411.1Ssoren
1421.1Ssorenint
1431.20Stsutsuipci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
1441.1Ssoren{
1451.10Ssommerfe	pci_chipset_tag_t pc = pa->pa_pc;
1461.11Stsutsui	pcitag_t intrtag = pa->pa_intrtag;
1471.10Ssommerfe	int pin = pa->pa_intrpin;
1481.10Ssommerfe	int line = pa->pa_intrline;
1491.5Ssoren	int bus, dev, func;
1501.1Ssoren
1511.5Ssoren	pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
1521.5Ssoren
1531.5Ssoren	/*
1541.5Ssoren	 * The interrupt lines of the two Tulips are connected
1551.5Ssoren	 * directly to the CPU.
1561.5Ssoren	 */
1571.5Ssoren
1581.5Ssoren	if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A)
1591.5Ssoren		*ihp = 16 + 1;
1601.5Ssoren	else if (bus == 0 && dev == 12 && pin == PCI_INTERRUPT_PIN_A)
1611.5Ssoren		*ihp = 16 + 2;
1621.5Ssoren	else
1631.5Ssoren		*ihp = line;
1641.1Ssoren
1651.1Ssoren	return 0;
1661.1Ssoren}
1671.1Ssoren
1681.1Ssorenconst char *
1691.20Stsutsuipci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih)
1701.1Ssoren{
1711.4Ssoren	static char irqstr[8];
1721.4Ssoren
1731.5Ssoren	if (ih >= 16)
1741.5Ssoren		sprintf(irqstr, "level %d", ih - 16);
1751.4Ssoren	else
1761.4Ssoren		sprintf(irqstr, "irq %d", ih);
1771.1Ssoren
1781.1Ssoren	return irqstr;
1791.7Scgd}
1801.7Scgd
1811.7Scgdconst struct evcnt *
1821.20Stsutsuipci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
1831.7Scgd{
1841.7Scgd
1851.7Scgd	/* XXX for now, no evcnt parent reported */
1861.7Scgd	return NULL;
1871.1Ssoren}
1881.1Ssoren
1891.1Ssorenvoid *
1901.20Stsutsuipci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
1911.20Stsutsui    int (*func)(void *), void *arg)
1921.1Ssoren{
1931.20Stsutsui
1941.5Ssoren	if (ih >= 16)
1951.5Ssoren		return cpu_intr_establish(ih - 16, level, func, arg);
1961.4Ssoren	else
1971.4Ssoren		return icu_intr_establish(ih, IST_LEVEL, level, func, arg);
1981.1Ssoren}
1991.1Ssoren
2001.1Ssorenvoid
2011.20Stsutsuipci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
2021.1Ssoren{
2031.20Stsutsui
2041.12Saugustss	/* Try both, only the valid one will disestablish. */
2051.12Saugustss	cpu_intr_disestablish(cookie);
2061.12Saugustss	icu_intr_disestablish(cookie);
2071.1Ssoren}
2081.17Stsutsui
2091.17Stsutsuivoid
2101.17Stsutsuipci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin, int swiz,
2111.17Stsutsui    int *iline)
2121.17Stsutsui{
2131.17Stsutsui
2141.17Stsutsui	/* not yet... */
2151.17Stsutsui}
2161.17Stsutsui
2171.17Stsutsuiint
2181.17Stsutsuipci_conf_hook(pci_chipset_tag_t pc, int bus, int dev, int func, pcireg_t id)
2191.17Stsutsui{
2201.17Stsutsui
2211.17Stsutsui	/* Don't configure the bridge and PCI probe. */
2221.17Stsutsui	if (PCI_VENDOR(id) == PCI_VENDOR_GALILEO &&
2231.17Stsutsui	    PCI_PRODUCT(id) == PCI_PRODUCT_GALILEO_GT64011)
2241.17Stsutsui	        return 0;
2251.17Stsutsui
2261.17Stsutsui	/* Don't configure device 9 */
2271.17Stsutsui	if (dev == 9)
2281.17Stsutsui		return 0;
2291.17Stsutsui
2301.19Sgdamore	return PCI_CONF_DEFAULT & ~(PCI_COMMAND_SERR_ENABLE |
2311.19Sgdamore	    PCI_COMMAND_PARITY_ENABLE);
2321.17Stsutsui}
233