xref: /netbsd-src/sys/arch/ibmnws/pci/pci_machdep.c (revision e4a54b419380e8bfc795d2267f19740e07784a2f)
1*e4a54b41Snonaka /*	$NetBSD: pci_machdep.c,v 1.10 2016/10/19 00:08:41 nonaka Exp $	*/
23dc55c12Smatt 
33dc55c12Smatt /*
43dc55c12Smatt  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
53dc55c12Smatt  * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
63dc55c12Smatt  *
73dc55c12Smatt  * Redistribution and use in source and binary forms, with or without
83dc55c12Smatt  * modification, are permitted provided that the following conditions
93dc55c12Smatt  * are met:
103dc55c12Smatt  * 1. Redistributions of source code must retain the above copyright
113dc55c12Smatt  *    notice, this list of conditions and the following disclaimer.
123dc55c12Smatt  * 2. Redistributions in binary form must reproduce the above copyright
133dc55c12Smatt  *    notice, this list of conditions and the following disclaimer in the
143dc55c12Smatt  *    documentation and/or other materials provided with the distribution.
153dc55c12Smatt  * 3. All advertising materials mentioning features or use of this software
163dc55c12Smatt  *    must display the following acknowledgement:
173dc55c12Smatt  *	This product includes software developed by Charles M. Hannum.
183dc55c12Smatt  * 4. The name of the author may not be used to endorse or promote products
193dc55c12Smatt  *    derived from this software without specific prior written permission.
203dc55c12Smatt  *
213dc55c12Smatt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223dc55c12Smatt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
233dc55c12Smatt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
243dc55c12Smatt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
253dc55c12Smatt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
263dc55c12Smatt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
273dc55c12Smatt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
283dc55c12Smatt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
293dc55c12Smatt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
303dc55c12Smatt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
313dc55c12Smatt  */
323dc55c12Smatt 
333dc55c12Smatt /*
343dc55c12Smatt  * Machine-specific functions for PCI autoconfiguration.
353dc55c12Smatt  *
363dc55c12Smatt  * On PCs, there are two methods of generating PCI configuration cycles.
373dc55c12Smatt  * We try to detect the appropriate mechanism for this machine and set
383dc55c12Smatt  * up a few function pointers to access the correct method directly.
393dc55c12Smatt  */
403dc55c12Smatt 
413dc55c12Smatt #include <sys/types.h>
423dc55c12Smatt #include <sys/param.h>
433dc55c12Smatt #include <sys/time.h>
443dc55c12Smatt #include <sys/systm.h>
453dc55c12Smatt #include <sys/errno.h>
463dc55c12Smatt #include <sys/extent.h>
473dc55c12Smatt #include <sys/device.h>
483dc55c12Smatt 
493dc55c12Smatt #include <uvm/uvm_extern.h>
503dc55c12Smatt 
513dc55c12Smatt #define _POWERPC_BUS_DMA_PRIVATE
52a0a8f335Sdyoung #include <sys/bus.h>
533dc55c12Smatt #include <machine/intr.h>
543dc55c12Smatt 
553dc55c12Smatt #include <dev/isa/isavar.h>
563dc55c12Smatt 
573dc55c12Smatt #include <dev/pci/pcivar.h>
583dc55c12Smatt #include <dev/pci/pcireg.h>
593dc55c12Smatt #include <dev/pci/pcidevs.h>
603dc55c12Smatt #include <dev/pci/pciconf.h>
613dc55c12Smatt 
62d974db0aSgarbled void
ibmnws_pci_get_chipset_tag_indirect(pci_chipset_tag_t pc)63d974db0aSgarbled ibmnws_pci_get_chipset_tag_indirect(pci_chipset_tag_t pc)
64d974db0aSgarbled {
65d974db0aSgarbled 
66d974db0aSgarbled 	pc->pc_conf_v = (void *)pc;
67d974db0aSgarbled 
68d974db0aSgarbled 	pc->pc_attach_hook = genppc_pci_indirect_attach_hook;
69d974db0aSgarbled 	pc->pc_bus_maxdevs = ibmnws_pci_bus_maxdevs;
70d974db0aSgarbled 	pc->pc_make_tag = genppc_pci_indirect_make_tag;
71d974db0aSgarbled 	pc->pc_conf_read = genppc_pci_indirect_conf_read;
72d974db0aSgarbled 	pc->pc_conf_write = genppc_pci_indirect_conf_write;
73d974db0aSgarbled 
74d974db0aSgarbled 	pc->pc_intr_v = (void *)pc;
75d974db0aSgarbled 
76d974db0aSgarbled 	pc->pc_intr_map = genppc_pci_intr_map;
77d974db0aSgarbled 	pc->pc_intr_string = genppc_pci_intr_string;
78d974db0aSgarbled 	pc->pc_intr_evcnt = genppc_pci_intr_evcnt;
79d974db0aSgarbled 	pc->pc_intr_establish = genppc_pci_intr_establish;
80d974db0aSgarbled 	pc->pc_intr_disestablish = genppc_pci_intr_disestablish;
81dd2488a8Smatt 	pc->pc_intr_setattr = genppc_pci_intr_setattr;
82*e4a54b41Snonaka 	pc->pc_intr_type = genppc_pci_intr_type;
83*e4a54b41Snonaka 	pc->pc_intr_alloc = genppc_pci_intr_alloc;
84*e4a54b41Snonaka 	pc->pc_intr_release = genppc_pci_intr_release;
85*e4a54b41Snonaka 	pc->pc_intx_alloc = genppc_pci_intx_alloc;
86*e4a54b41Snonaka 
87*e4a54b41Snonaka 	pc->pc_msi_v = (void *)pc;
88*e4a54b41Snonaka 	genppc_pci_chipset_msi_init(pc);
89*e4a54b41Snonaka 
90*e4a54b41Snonaka 	pc->pc_msix_v = (void *)pc;
91*e4a54b41Snonaka 	genppc_pci_chipset_msix_init(pc);
92d974db0aSgarbled 
93d974db0aSgarbled 	pc->pc_conf_interrupt = genppc_pci_conf_interrupt;
94d974db0aSgarbled 	pc->pc_decompose_tag = genppc_pci_indirect_decompose_tag;
95d974db0aSgarbled 	pc->pc_conf_hook = ibmnws_pci_conf_hook;
96d974db0aSgarbled 
974a40b014Smatt 	pc->pc_addr = mapiodev(PCI_MODE1_ADDRESS_REG, 4, false);
984a40b014Smatt 	pc->pc_data = mapiodev(PCI_MODE1_DATA_REG, 4, false);
99d974db0aSgarbled 	pc->pc_bus = 0;
100d974db0aSgarbled 	pc->pc_node = 0;
101d974db0aSgarbled 	pc->pc_memt = 0;
102d974db0aSgarbled 	pc->pc_iot = 0;
103d974db0aSgarbled }
1043dc55c12Smatt 
1053dc55c12Smatt int
ibmnws_pci_bus_maxdevs(void * v,int busno)1064f2934afSmatt ibmnws_pci_bus_maxdevs(void *v, int busno)
1073dc55c12Smatt {
1083dc55c12Smatt 
1093dc55c12Smatt 	/*
1103dc55c12Smatt 	 * Bus number is irrelevant.  Configuration Mechanism 1 is in
1113dc55c12Smatt 	 * use, can have devices 0-32 (i.e. the `normal' range).
1123dc55c12Smatt 	 */
1133dc55c12Smatt 	return (32);
1143dc55c12Smatt }
1153dc55c12Smatt 
1163dc55c12Smatt int
ibmnws_pci_conf_hook(void * v,int bus,int dev,int func,pcireg_t id)117dd2488a8Smatt ibmnws_pci_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
1183dc55c12Smatt {
1193dc55c12Smatt 
1203dc55c12Smatt 	/*
1213dc55c12Smatt 	 * The P9100 board found in some IBM machines cannot be
1223dc55c12Smatt 	 * over-configured.
1233dc55c12Smatt 	 */
1243dc55c12Smatt 	if (PCI_VENDOR(id) == PCI_VENDOR_WEITEK &&
1253dc55c12Smatt 	    PCI_PRODUCT(id) == PCI_PRODUCT_WEITEK_P9100)
1263dc55c12Smatt 		return 0;
1273dc55c12Smatt 
12884308388Sgdamore 	return (PCI_CONF_DEFAULT);
1293dc55c12Smatt }
130