pci_machdep.c revision 1.10
11.10Ssommerfe/*	$NetBSD: pci_machdep.c,v 1.10 2000/12/28 22:59:09 sommerfeld 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.1Ssoren
281.1Ssoren#include <sys/types.h>
291.1Ssoren#include <sys/param.h>
301.1Ssoren#include <sys/time.h>
311.1Ssoren#include <sys/systm.h>
321.1Ssoren#include <sys/errno.h>
331.1Ssoren#include <sys/device.h>
341.1Ssoren
351.1Ssoren#define _COBALT_BUS_DMA_PRIVATE
361.1Ssoren#include <machine/bus.h>
371.4Ssoren#include <machine/intr.h>
381.1Ssoren
391.1Ssoren#include <dev/pci/pcivar.h>
401.1Ssoren#include <dev/pci/pcireg.h>
411.1Ssoren#include <dev/pci/pcidevs.h>
421.1Ssoren
431.1Ssoren/*
441.1Ssoren * PCI doesn't have any special needs; just use
451.1Ssoren * the generic versions of these functions.
461.1Ssoren */
471.1Ssorenstruct cobalt_bus_dma_tag pci_bus_dma_tag = {
481.1Ssoren	_bus_dmamap_create,
491.1Ssoren	_bus_dmamap_destroy,
501.1Ssoren	_bus_dmamap_load,
511.1Ssoren	_bus_dmamap_load_mbuf,
521.1Ssoren	_bus_dmamap_load_uio,
531.1Ssoren	_bus_dmamap_load_raw,
541.1Ssoren	_bus_dmamap_unload,
551.1Ssoren	_bus_dmamap_sync,
561.1Ssoren	_bus_dmamem_alloc,
571.1Ssoren	_bus_dmamem_free,
581.1Ssoren	_bus_dmamem_map,
591.1Ssoren	_bus_dmamem_unmap,
601.1Ssoren	_bus_dmamem_mmap,
611.1Ssoren};
621.1Ssoren
631.1Ssorenvoid
641.1Ssorenpci_attach_hook(parent, self, pba)
651.1Ssoren	struct device *parent, *self;
661.1Ssoren	struct pcibus_attach_args *pba;
671.1Ssoren{
681.1Ssoren	/* XXX */
691.1Ssoren
701.1Ssoren	return;
711.1Ssoren}
721.1Ssoren
731.1Ssorenint
741.1Ssorenpci_bus_maxdevs(pc, busno)
751.1Ssoren	pci_chipset_tag_t pc;
761.1Ssoren	int busno;
771.1Ssoren{
781.6Ssoren	return 32;
791.1Ssoren}
801.1Ssoren
811.1Ssorenpcitag_t
821.1Ssorenpci_make_tag(pc, bus, device, function)
831.1Ssoren	pci_chipset_tag_t pc;
841.1Ssoren	int bus, device, function;
851.1Ssoren{
861.1Ssoren	return (bus << 16) | (device << 11) | (function << 8);
871.1Ssoren}
881.1Ssoren
891.1Ssorenvoid
901.1Ssorenpci_decompose_tag(pc, tag, bp, dp, fp)
911.1Ssoren	pci_chipset_tag_t pc;
921.1Ssoren	pcitag_t tag;
931.1Ssoren	int *bp, *dp, *fp;
941.1Ssoren{
951.1Ssoren	if (bp != NULL)
961.1Ssoren		*bp = (tag >> 16) & 0xff;
971.1Ssoren	if (dp != NULL)
981.1Ssoren		*dp = (tag >> 11) & 0x1f;
991.1Ssoren	if (fp != NULL)
1001.1Ssoren		*fp = (tag >> 8) & 0x07;
1011.1Ssoren}
1021.1Ssoren
1031.1Ssoren#define PCI_CFG_ADDR	((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x14000cf8))
1041.1Ssoren#define PCI_CFG_DATA	((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x14000cfc))
1051.1Ssoren
1061.1Ssorenpcireg_t
1071.1Ssorenpci_conf_read(pc, tag, reg)
1081.1Ssoren	pci_chipset_tag_t pc;
1091.1Ssoren	pcitag_t tag;
1101.1Ssoren	int reg;
1111.1Ssoren{
1121.1Ssoren	pcireg_t data;
1131.6Ssoren	int bus, dev, func;
1141.6Ssoren
1151.6Ssoren	pci_decompose_tag(pc, tag, &bus, &dev, &func);
1161.6Ssoren
1171.6Ssoren	/*
1181.6Ssoren	 * 2700 hardware wedges on accesses to device 6.
1191.6Ssoren	 */
1201.6Ssoren	if (bus == 0 && dev == 6)
1211.6Ssoren		return 0;
1221.6Ssoren	/*
1231.6Ssoren	 * 2800 hardware wedges on accesses to device 31.
1241.6Ssoren	 */
1251.6Ssoren	if (bus == 0 && dev == 31)
1261.6Ssoren		return 0;
1271.1Ssoren
1281.1Ssoren	*PCI_CFG_ADDR = 0x80000000 | tag | reg;
1291.1Ssoren	data = *PCI_CFG_DATA;
1301.1Ssoren	*PCI_CFG_ADDR = 0;
1311.1Ssoren
1321.1Ssoren	return data;
1331.1Ssoren}
1341.1Ssoren
1351.1Ssorenvoid
1361.1Ssorenpci_conf_write(pc, tag, reg, data)
1371.1Ssoren	pci_chipset_tag_t pc;
1381.1Ssoren	pcitag_t tag;
1391.1Ssoren	int reg;
1401.1Ssoren	pcireg_t data;
1411.1Ssoren{
1421.1Ssoren	*PCI_CFG_ADDR = 0x80000000 | tag | reg;
1431.1Ssoren	*PCI_CFG_DATA = data;
1441.1Ssoren	*PCI_CFG_ADDR = 0;
1451.1Ssoren
1461.1Ssoren	return;
1471.1Ssoren}
1481.1Ssoren
1491.1Ssorenint
1501.10Ssommerfepci_intr_map(pa, ihp)
1511.10Ssommerfe	struct pci_attach_args *pa;
1521.1Ssoren	pci_intr_handle_t *ihp;
1531.1Ssoren{
1541.10Ssommerfe	pci_chipset_tag_t pc = pa->pa_pc;
1551.10Ssommerfe	pcitag_t intrtag = pc->pa_intrtag;
1561.10Ssommerfe	int pin = pa->pa_intrpin;
1571.10Ssommerfe	int line = pa->pa_intrline;
1581.5Ssoren	int bus, dev, func;
1591.1Ssoren
1601.5Ssoren	pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
1611.5Ssoren
1621.5Ssoren	/*
1631.5Ssoren	 * The interrupt lines of the two Tulips are connected
1641.5Ssoren	 * directly to the CPU.
1651.5Ssoren	 */
1661.5Ssoren
1671.5Ssoren	if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A)
1681.5Ssoren		*ihp = 16 + 1;
1691.5Ssoren	else if (bus == 0 && dev == 12 && pin == PCI_INTERRUPT_PIN_A)
1701.5Ssoren		*ihp = 16 + 2;
1711.5Ssoren	else
1721.5Ssoren		*ihp = line;
1731.1Ssoren
1741.1Ssoren	return 0;
1751.1Ssoren}
1761.1Ssoren
1771.1Ssorenconst char *
1781.1Ssorenpci_intr_string(pc, ih)
1791.1Ssoren	pci_chipset_tag_t pc;
1801.1Ssoren	pci_intr_handle_t ih;
1811.1Ssoren{
1821.4Ssoren	static char irqstr[8];
1831.4Ssoren
1841.5Ssoren	if (ih >= 16)
1851.5Ssoren		sprintf(irqstr, "level %d", ih - 16);
1861.4Ssoren	else
1871.4Ssoren		sprintf(irqstr, "irq %d", ih);
1881.1Ssoren
1891.1Ssoren	return irqstr;
1901.7Scgd}
1911.7Scgd
1921.7Scgdconst struct evcnt *
1931.7Scgdpci_intr_evcnt(pc, ih)
1941.7Scgd	pci_chipset_tag_t pc;
1951.7Scgd	pci_intr_handle_t ih;
1961.7Scgd{
1971.7Scgd
1981.7Scgd	/* XXX for now, no evcnt parent reported */
1991.7Scgd	return NULL;
2001.1Ssoren}
2011.1Ssoren
2021.1Ssorenvoid *
2031.1Ssorenpci_intr_establish(pc, ih, level, func, arg)
2041.1Ssoren	pci_chipset_tag_t pc;
2051.1Ssoren	pci_intr_handle_t ih;
2061.1Ssoren	int level, (*func)(void *);
2071.1Ssoren	void *arg;
2081.1Ssoren{
2091.5Ssoren	if (ih >= 16)
2101.5Ssoren		return cpu_intr_establish(ih - 16, level, func, arg);
2111.4Ssoren	else
2121.4Ssoren		return icu_intr_establish(ih, IST_LEVEL, level, func, arg);
2131.1Ssoren}
2141.1Ssoren
2151.1Ssorenvoid
2161.1Ssorenpci_intr_disestablish(pc, cookie)
2171.1Ssoren	pci_chipset_tag_t pc;
2181.1Ssoren	void *cookie;
2191.1Ssoren{
2201.1Ssoren	panic("pci_intr_disestablish: not implemented");
2211.1Ssoren
2221.1Ssoren	return;
2231.1Ssoren}
224