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