xref: /netbsd-src/sys/arch/prep/pci/pceb.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1*c7fb772bSthorpej /*	$NetBSD: pceb.c,v 1.8 2021/08/07 16:19:03 thorpej Exp $	*/
2b19f0d31Sgarbled 
3b19f0d31Sgarbled /*-
4b19f0d31Sgarbled  * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
5b19f0d31Sgarbled  * All rights reserved.
6b19f0d31Sgarbled  *
7b19f0d31Sgarbled  * This code is derived from software contributed to The NetBSD Foundation
8b19f0d31Sgarbled  * by Jason R. Thorpe.
9b19f0d31Sgarbled  *
10b19f0d31Sgarbled  * Redistribution and use in source and binary forms, with or without
11b19f0d31Sgarbled  * modification, are permitted provided that the following conditions
12b19f0d31Sgarbled  * are met:
13b19f0d31Sgarbled  * 1. Redistributions of source code must retain the above copyright
14b19f0d31Sgarbled  *    notice, this list of conditions and the following disclaimer.
15b19f0d31Sgarbled  * 2. Redistributions in binary form must reproduce the above copyright
16b19f0d31Sgarbled  *    notice, this list of conditions and the following disclaimer in the
17b19f0d31Sgarbled  *    documentation and/or other materials provided with the distribution.
18b19f0d31Sgarbled  *
19b19f0d31Sgarbled  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20b19f0d31Sgarbled  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21b19f0d31Sgarbled  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22b19f0d31Sgarbled  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23b19f0d31Sgarbled  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24b19f0d31Sgarbled  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25b19f0d31Sgarbled  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26b19f0d31Sgarbled  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27b19f0d31Sgarbled  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28b19f0d31Sgarbled  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29b19f0d31Sgarbled  * POSSIBILITY OF SUCH DAMAGE.
30b19f0d31Sgarbled  */
31b19f0d31Sgarbled 
32b19f0d31Sgarbled #include <sys/cdefs.h>
33*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: pceb.c,v 1.8 2021/08/07 16:19:03 thorpej Exp $");
34b19f0d31Sgarbled 
35b19f0d31Sgarbled #include <sys/types.h>
36b19f0d31Sgarbled #include <sys/param.h>
37b19f0d31Sgarbled #include <sys/systm.h>
38b19f0d31Sgarbled #include <sys/device.h>
39b19f0d31Sgarbled 
405a5fb3acSdyoung #include <sys/bus.h>
41b19f0d31Sgarbled 
42b19f0d31Sgarbled #include <dev/isa/isavar.h>
43b19f0d31Sgarbled #include <dev/eisa/eisavar.h>
44b19f0d31Sgarbled 
45b19f0d31Sgarbled #include <dev/pci/pcivar.h>
46b19f0d31Sgarbled #include <dev/pci/pcireg.h>
47b19f0d31Sgarbled 
48b19f0d31Sgarbled #include <dev/pci/pcidevs.h>
49b19f0d31Sgarbled 
50b19f0d31Sgarbled #include "eisa.h"
51b19f0d31Sgarbled #include "isa.h"
52b19f0d31Sgarbled 
53ec1797c1Smatt int	pcebmatch(device_t, cfdata_t, void *);
54ec1797c1Smatt void	pcebattach(device_t, device_t, void *);
55b19f0d31Sgarbled 
56ec1797c1Smatt CFATTACH_DECL_NEW(pceb, 0,
57b19f0d31Sgarbled     pcebmatch, pcebattach, NULL, NULL);
58b19f0d31Sgarbled 
59ec1797c1Smatt void	pceb_callback(device_t);
60b19f0d31Sgarbled 
61b19f0d31Sgarbled union pceb_attach_args {
62b19f0d31Sgarbled 	const char *ea_name;			/* XXX should be common */
63b19f0d31Sgarbled 	struct isabus_attach_args ea_iba;
64b19f0d31Sgarbled 	struct eisabus_attach_args ea_eba;
65b19f0d31Sgarbled };
66b19f0d31Sgarbled 
67b19f0d31Sgarbled int
pcebmatch(device_t parent,cfdata_t match,void * aux)68ec1797c1Smatt pcebmatch(device_t parent, cfdata_t match, void *aux)
69b19f0d31Sgarbled {
70b19f0d31Sgarbled 	struct pci_attach_args *pa = aux;
71b19f0d31Sgarbled 
72b19f0d31Sgarbled 	/*
73b19f0d31Sgarbled 	 * Match anything which claims to be PCI-EISA bridge.
74b19f0d31Sgarbled 	 */
75b19f0d31Sgarbled 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
76b19f0d31Sgarbled 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_EISA)
77b19f0d31Sgarbled 		return (1);
78b19f0d31Sgarbled 
79b19f0d31Sgarbled 	/*
80b19f0d31Sgarbled 	 * Match some known PCI-EISA bridges explicitly.
81b19f0d31Sgarbled 	 * XXX this is probably not necessary, should be matched by above
82b19f0d31Sgarbled 	 * condition
83b19f0d31Sgarbled 	 */
84b19f0d31Sgarbled 	switch (PCI_VENDOR(pa->pa_id)) {
85b19f0d31Sgarbled 	case PCI_VENDOR_INTEL:
86b19f0d31Sgarbled 		switch (PCI_PRODUCT(pa->pa_id)) {
87b19f0d31Sgarbled 		case PCI_PRODUCT_INTEL_PCEB:
88b19f0d31Sgarbled 			return (1);
89b19f0d31Sgarbled 		}
90b19f0d31Sgarbled 		break;
91b19f0d31Sgarbled 	}
92b19f0d31Sgarbled 
93b19f0d31Sgarbled 	return (0);
94b19f0d31Sgarbled }
95b19f0d31Sgarbled 
96b19f0d31Sgarbled void
pcebattach(device_t parent,device_t self,void * aux)97ec1797c1Smatt pcebattach(device_t parent, device_t self, void *aux)
98b19f0d31Sgarbled {
99b19f0d31Sgarbled 	struct pci_attach_args *pa = aux;
100b19f0d31Sgarbled 	char devinfo[256];
101b19f0d31Sgarbled 	int error;
102b19f0d31Sgarbled 
103d974db0aSgarbled 	aprint_normal("\n");
104b19f0d31Sgarbled 
105b19f0d31Sgarbled 	/*
106b19f0d31Sgarbled 	 * Just print out a description and defer configuration
107b19f0d31Sgarbled 	 * until all PCI devices have been attached.
108b19f0d31Sgarbled 	 */
109b19f0d31Sgarbled 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
11005b09539Smatt 	aprint_normal_dev(self, "%s (rev. 0x%02x)\n", devinfo,
111b19f0d31Sgarbled 	    PCI_REVISION(pa->pa_class));
112b19f0d31Sgarbled 
113b19f0d31Sgarbled 	prep_eisa_io_space_tag.pbs_extent = prep_io_space_tag.pbs_extent;
114b19f0d31Sgarbled 	error = bus_space_init(&prep_eisa_io_space_tag, "eisa-ioport", NULL, 0);
115b19f0d31Sgarbled 	if (error)
116b19f0d31Sgarbled 		panic("prep_bus_space_init: can't init eisa io tag");
117b19f0d31Sgarbled 
118b19f0d31Sgarbled 	prep_eisa_mem_space_tag.pbs_extent = prep_mem_space_tag.pbs_extent;
119b19f0d31Sgarbled 	error = bus_space_init(&prep_eisa_mem_space_tag, "eisa-iomem", NULL, 0);
120b19f0d31Sgarbled 	if (error)
121b19f0d31Sgarbled 		panic("prep_bus_space_init: can't init eisa mem tag");
122b19f0d31Sgarbled 
123b19f0d31Sgarbled 	config_defer(self, pceb_callback);
124b19f0d31Sgarbled }
125b19f0d31Sgarbled 
126b19f0d31Sgarbled void
pceb_callback(device_t self)127ec1797c1Smatt pceb_callback(device_t self)
128b19f0d31Sgarbled {
129b19f0d31Sgarbled 	union pceb_attach_args ea;
130b19f0d31Sgarbled 
131b19f0d31Sgarbled 	/*
132b19f0d31Sgarbled 	 * Attach the EISA bus behind this bridge.
133b19f0d31Sgarbled 	 */
134b19f0d31Sgarbled 	memset(&ea, 0, sizeof(ea));
135b19f0d31Sgarbled 	ea.ea_eba.eba_iot = &prep_eisa_io_space_tag;
136b19f0d31Sgarbled 	ea.ea_eba.eba_memt = &prep_eisa_mem_space_tag;
137b19f0d31Sgarbled #if NEISA > 0
138b19f0d31Sgarbled 	ea.ea_eba.eba_dmat = &eisa_bus_dma_tag;
139b19f0d31Sgarbled #endif
1402685996bSthorpej 	config_found(self, &ea.ea_eba, eisabusprint,
141*c7fb772bSthorpej 	    CFARGS(.iattr = "eisabus"));
142b19f0d31Sgarbled 
143b19f0d31Sgarbled 	/*
144b19f0d31Sgarbled 	 * Attach the ISA bus behind this bridge.
145b19f0d31Sgarbled 	 */
146b19f0d31Sgarbled 	memset(&ea, 0, sizeof(ea));
147d974db0aSgarbled 	ea.ea_iba.iba_iot = &genppc_isa_io_space_tag;
148d974db0aSgarbled 	ea.ea_iba.iba_memt = &genppc_isa_mem_space_tag;
149b19f0d31Sgarbled #if NISA > 0
150b19f0d31Sgarbled 	ea.ea_iba.iba_dmat = &isa_bus_dma_tag;
151b19f0d31Sgarbled #endif
1522685996bSthorpej 	config_found(self, &ea.ea_iba, isabusprint,
153*c7fb772bSthorpej 	    CFARGS(.iattr = "isabus"));
154b19f0d31Sgarbled }
155