xref: /openbsd-src/sys/arch/amd64/pci/pcib.c (revision 06a6f48edf3c78a50a2b34d9da7d066e27884447)
1*06a6f48eSmpi /*	$OpenBSD: pcib.c,v 1.7 2022/02/21 11:03:39 mpi Exp $	*/
2aff9e93dSderaadt /*	$NetBSD: pcib.c,v 1.6 1997/06/06 23:29:16 thorpej Exp $	*/
3aff9e93dSderaadt 
4aff9e93dSderaadt /*-
5aff9e93dSderaadt  * Copyright (c) 1996 The NetBSD Foundation, Inc.
6aff9e93dSderaadt  * All rights reserved.
7aff9e93dSderaadt  *
8aff9e93dSderaadt  * This code is derived from software contributed to The NetBSD Foundation
9aff9e93dSderaadt  * by Jason R. Thorpe.
10aff9e93dSderaadt  *
11aff9e93dSderaadt  * Redistribution and use in source and binary forms, with or without
12aff9e93dSderaadt  * modification, are permitted provided that the following conditions
13aff9e93dSderaadt  * are met:
14aff9e93dSderaadt  * 1. Redistributions of source code must retain the above copyright
15aff9e93dSderaadt  *    notice, this list of conditions and the following disclaimer.
16aff9e93dSderaadt  * 2. Redistributions in binary form must reproduce the above copyright
17aff9e93dSderaadt  *    notice, this list of conditions and the following disclaimer in the
18aff9e93dSderaadt  *    documentation and/or other materials provided with the distribution.
19aff9e93dSderaadt  *
20aff9e93dSderaadt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21aff9e93dSderaadt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22aff9e93dSderaadt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23aff9e93dSderaadt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24aff9e93dSderaadt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25aff9e93dSderaadt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26aff9e93dSderaadt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27aff9e93dSderaadt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28aff9e93dSderaadt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29aff9e93dSderaadt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30aff9e93dSderaadt  * POSSIBILITY OF SUCH DAMAGE.
31aff9e93dSderaadt  */
32aff9e93dSderaadt 
33aff9e93dSderaadt #include <sys/param.h>
34aff9e93dSderaadt #include <sys/systm.h>
35aff9e93dSderaadt #include <sys/device.h>
36aff9e93dSderaadt 
37aff9e93dSderaadt #include <machine/bus.h>
38aff9e93dSderaadt #include <dev/isa/isavar.h>
39aff9e93dSderaadt 
40aff9e93dSderaadt #include <dev/pci/pcivar.h>
41aff9e93dSderaadt #include <dev/pci/pcireg.h>
42aff9e93dSderaadt 
43aff9e93dSderaadt #include <dev/pci/pcidevs.h>
44aff9e93dSderaadt 
45aff9e93dSderaadt #include "isa.h"
46aff9e93dSderaadt 
47aff9e93dSderaadt int	pcibmatch(struct device *, void *, void *);
48aff9e93dSderaadt void	pcibattach(struct device *, struct device *, void *);
49aff9e93dSderaadt void	pcib_callback(struct device *);
50aff9e93dSderaadt int	pcib_print(void *, const char *);
51aff9e93dSderaadt 
52*06a6f48eSmpi const struct cfattach pcib_ca = {
53c06fda6dSderaadt 	sizeof(struct device), pcibmatch, pcibattach
54aff9e93dSderaadt };
55aff9e93dSderaadt 
56aff9e93dSderaadt struct cfdriver pcib_cd = {
57aff9e93dSderaadt 	NULL, "pcib", DV_DULL
58aff9e93dSderaadt };
59aff9e93dSderaadt 
60aff9e93dSderaadt int
pcibmatch(struct device * parent,void * match,void * aux)612bb6026aSjsg pcibmatch(struct device *parent, void *match, void *aux)
62aff9e93dSderaadt {
63aff9e93dSderaadt 	struct pci_attach_args *pa = aux;
64aff9e93dSderaadt 
65aff9e93dSderaadt 	switch (PCI_VENDOR(pa->pa_id)) {
66aff9e93dSderaadt 	case PCI_VENDOR_INTEL:
67aff9e93dSderaadt 		switch (PCI_PRODUCT(pa->pa_id)) {
68aff9e93dSderaadt 		case PCI_PRODUCT_INTEL_SIO:
69aff9e93dSderaadt 		case PCI_PRODUCT_INTEL_82371MX:
70aff9e93dSderaadt 		case PCI_PRODUCT_INTEL_82371AB_ISA:
71aff9e93dSderaadt 		case PCI_PRODUCT_INTEL_82440MX_ISA:
72aff9e93dSderaadt 			/* The above bridges mis-identify themselves */
73aff9e93dSderaadt 			return (1);
74aff9e93dSderaadt 		}
756ad20415Sjsg 		break;
76aff9e93dSderaadt 	case PCI_VENDOR_SIS:
77aff9e93dSderaadt 		switch (PCI_PRODUCT(pa->pa_id)) {
78aff9e93dSderaadt 		case PCI_PRODUCT_SIS_85C503:
79aff9e93dSderaadt 			/* mis-identifies itself as a miscellaneous prehistoric */
80aff9e93dSderaadt 			return (1);
81aff9e93dSderaadt 		}
826ad20415Sjsg 		break;
83aff9e93dSderaadt 	case PCI_VENDOR_VIATECH:
84aff9e93dSderaadt 		switch (PCI_PRODUCT(pa->pa_id)) {
85aff9e93dSderaadt 		case PCI_PRODUCT_VIATECH_VT82C686A_SMB:
86aff9e93dSderaadt 			/* mis-identifies itself as a ISA bridge */
87aff9e93dSderaadt 			return (0);
88aff9e93dSderaadt 		}
896ad20415Sjsg 		break;
90aff9e93dSderaadt 	}
91aff9e93dSderaadt 
92aff9e93dSderaadt 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
93aff9e93dSderaadt 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA)
94aff9e93dSderaadt 		return (1);
95aff9e93dSderaadt 
96aff9e93dSderaadt 	return (0);
97aff9e93dSderaadt }
98aff9e93dSderaadt 
99aff9e93dSderaadt void
pcibattach(struct device * parent,struct device * self,void * aux)1002bb6026aSjsg pcibattach(struct device *parent, struct device *self, void *aux)
101aff9e93dSderaadt {
102aff9e93dSderaadt 	/*
103aff9e93dSderaadt 	 * Cannot attach isa bus now; must postpone for various reasons
104aff9e93dSderaadt 	 */
105aff9e93dSderaadt 	printf("\n");
106aff9e93dSderaadt 
107aff9e93dSderaadt 	config_defer(self, pcib_callback);
108aff9e93dSderaadt }
109aff9e93dSderaadt 
110aff9e93dSderaadt void
pcib_callback(struct device * self)1112bb6026aSjsg pcib_callback(struct device *self)
112aff9e93dSderaadt {
113aff9e93dSderaadt 	struct isabus_attach_args iba;
114aff9e93dSderaadt 
115aff9e93dSderaadt 	/*
116aff9e93dSderaadt 	 * Attach the ISA bus behind this bridge.
117aff9e93dSderaadt 	 */
118aff9e93dSderaadt 	memset(&iba, 0, sizeof(iba));
119aff9e93dSderaadt 	iba.iba_busname = "isa";
120aff9e93dSderaadt 	iba.iba_iot = X86_BUS_SPACE_IO;
121aff9e93dSderaadt 	iba.iba_memt = X86_BUS_SPACE_MEM;
122aff9e93dSderaadt #if NISADMA > 0
123aff9e93dSderaadt 	iba.iba_dmat = &isa_bus_dma_tag;
124aff9e93dSderaadt #endif
125aff9e93dSderaadt 	config_found(self, &iba, pcib_print);
126aff9e93dSderaadt }
127aff9e93dSderaadt 
128aff9e93dSderaadt int
pcib_print(void * aux,const char * pnp)1292bb6026aSjsg pcib_print(void *aux, const char *pnp)
130aff9e93dSderaadt {
131aff9e93dSderaadt 	/* Only ISAs can attach to pcib's; easy. */
132aff9e93dSderaadt 	if (pnp)
133aff9e93dSderaadt 		printf("isa at %s", pnp);
134aff9e93dSderaadt 	return (UNCONF);
135aff9e93dSderaadt }
136