1*c7fb772bSthorpej /* $NetBSD: pceb.c,v 1.26 2021/08/07 16:18:55 thorpej Exp $ */
2e56b1d0bSthorpej
3e56b1d0bSthorpej /*-
4e56b1d0bSthorpej * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
5e56b1d0bSthorpej * All rights reserved.
6e56b1d0bSthorpej *
7e56b1d0bSthorpej * This code is derived from software contributed to The NetBSD Foundation
8e56b1d0bSthorpej * by Jason R. Thorpe.
9e56b1d0bSthorpej *
10e56b1d0bSthorpej * Redistribution and use in source and binary forms, with or without
11e56b1d0bSthorpej * modification, are permitted provided that the following conditions
12e56b1d0bSthorpej * are met:
13e56b1d0bSthorpej * 1. Redistributions of source code must retain the above copyright
14e56b1d0bSthorpej * notice, this list of conditions and the following disclaimer.
15e56b1d0bSthorpej * 2. Redistributions in binary form must reproduce the above copyright
16e56b1d0bSthorpej * notice, this list of conditions and the following disclaimer in the
17e56b1d0bSthorpej * documentation and/or other materials provided with the distribution.
18e56b1d0bSthorpej *
19e56b1d0bSthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20e56b1d0bSthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21e56b1d0bSthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22e56b1d0bSthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23e56b1d0bSthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24e56b1d0bSthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25e56b1d0bSthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26e56b1d0bSthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27e56b1d0bSthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28e56b1d0bSthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29e56b1d0bSthorpej * POSSIBILITY OF SUCH DAMAGE.
30e56b1d0bSthorpej */
31e56b1d0bSthorpej
3295c969f2Slukem #include <sys/cdefs.h>
33*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: pceb.c,v 1.26 2021/08/07 16:18:55 thorpej Exp $");
3495c969f2Slukem
35e56b1d0bSthorpej #include <sys/types.h>
36e56b1d0bSthorpej #include <sys/param.h>
37e56b1d0bSthorpej #include <sys/systm.h>
38e56b1d0bSthorpej #include <sys/device.h>
39e56b1d0bSthorpej
40f5b064eeSdyoung #include <sys/bus.h>
41e56b1d0bSthorpej
42e56b1d0bSthorpej #include <dev/isa/isavar.h>
43e56b1d0bSthorpej #include <dev/eisa/eisavar.h>
44e56b1d0bSthorpej
45e56b1d0bSthorpej #include <dev/pci/pcivar.h>
46e56b1d0bSthorpej #include <dev/pci/pcireg.h>
47e56b1d0bSthorpej
48e56b1d0bSthorpej #include <dev/pci/pcidevs.h>
49e56b1d0bSthorpej
50e56b1d0bSthorpej #include "eisa.h"
51e56b1d0bSthorpej #include "isa.h"
52e56b1d0bSthorpej
53ed38b748Sxtraeme int pcebmatch(device_t , cfdata_t, void *);
54ed38b748Sxtraeme void pcebattach(device_t, device_t, void *);
55e56b1d0bSthorpej
56ed38b748Sxtraeme CFATTACH_DECL_NEW(pceb, 0, pcebmatch, pcebattach, NULL, NULL);
57e56b1d0bSthorpej
58ed38b748Sxtraeme void pceb_callback(device_t);
59e56b1d0bSthorpej
60e56b1d0bSthorpej union pceb_attach_args {
61e56b1d0bSthorpej const char *ea_name; /* XXX should be common */
62e56b1d0bSthorpej struct isabus_attach_args ea_iba;
63e56b1d0bSthorpej struct eisabus_attach_args ea_eba;
64e56b1d0bSthorpej };
65e56b1d0bSthorpej
66e56b1d0bSthorpej int
pcebmatch(device_t parent,cfdata_t match,void * aux)67ed38b748Sxtraeme pcebmatch(device_t parent, cfdata_t match, void *aux)
68e56b1d0bSthorpej {
69e56b1d0bSthorpej struct pci_attach_args *pa = aux;
70e56b1d0bSthorpej
71e56b1d0bSthorpej /*
721677351fSjdolecek * Match anything which claims to be PCI-EISA bridge.
731677351fSjdolecek */
741677351fSjdolecek if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
751677351fSjdolecek PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_EISA)
761677351fSjdolecek return (1);
771677351fSjdolecek
781677351fSjdolecek /*
791677351fSjdolecek * Match some known PCI-EISA bridges explicitly.
801677351fSjdolecek * XXX this is probably not necessary, should be matched by above
811677351fSjdolecek * condition
82e56b1d0bSthorpej */
83e56b1d0bSthorpej switch (PCI_VENDOR(pa->pa_id)) {
84e56b1d0bSthorpej case PCI_VENDOR_INTEL:
85e56b1d0bSthorpej switch (PCI_PRODUCT(pa->pa_id)) {
86e56b1d0bSthorpej case PCI_PRODUCT_INTEL_PCEB:
87e56b1d0bSthorpej return (1);
88e56b1d0bSthorpej }
89e56b1d0bSthorpej break;
90e56b1d0bSthorpej }
91e56b1d0bSthorpej
92e56b1d0bSthorpej return (0);
93e56b1d0bSthorpej }
94e56b1d0bSthorpej
95e56b1d0bSthorpej void
pcebattach(device_t parent,device_t self,void * aux)96ed38b748Sxtraeme pcebattach(device_t parent, device_t self, void *aux)
97e56b1d0bSthorpej {
98e56b1d0bSthorpej struct pci_attach_args *pa = aux;
99e56b1d0bSthorpej char devinfo[256];
100e56b1d0bSthorpej
101a9beff95Sthorpej aprint_naive("\n");
102a9beff95Sthorpej aprint_normal("\n");
103e56b1d0bSthorpej
104e56b1d0bSthorpej /*
10502182100Sthorpej * Just print out a description and defer configuration
10602182100Sthorpej * until all PCI devices have been attached.
107e56b1d0bSthorpej */
10861230437Sitojun pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
109ee63fe0aScegger aprint_normal_dev(self, "%s (rev. 0x%02x)\n", devinfo,
110e56b1d0bSthorpej PCI_REVISION(pa->pa_class));
111e56b1d0bSthorpej
11202182100Sthorpej config_defer(self, pceb_callback);
113e56b1d0bSthorpej }
114e56b1d0bSthorpej
115e56b1d0bSthorpej void
pceb_callback(device_t self)116ed38b748Sxtraeme pceb_callback(device_t self)
117e56b1d0bSthorpej {
118e56b1d0bSthorpej union pceb_attach_args ea;
119e56b1d0bSthorpej
120e56b1d0bSthorpej /*
121e56b1d0bSthorpej * Attach the EISA bus behind this bridge.
122e56b1d0bSthorpej */
123584757c0Sperry memset(&ea, 0, sizeof(ea));
12430b2d68dSdyoung ea.ea_eba.eba_iot = x86_bus_space_io;
12530b2d68dSdyoung ea.ea_eba.eba_memt = x86_bus_space_mem;
126e56b1d0bSthorpej #if NEISA > 0
127e56b1d0bSthorpej ea.ea_eba.eba_dmat = &eisa_bus_dma_tag;
128e56b1d0bSthorpej #endif
1292685996bSthorpej config_found(self, &ea.ea_eba, eisabusprint,
130*c7fb772bSthorpej CFARGS(.iattr = "eisabus"));
131e56b1d0bSthorpej
132e56b1d0bSthorpej /*
133e56b1d0bSthorpej * Attach the ISA bus behind this bridge.
134e56b1d0bSthorpej */
135584757c0Sperry memset(&ea, 0, sizeof(ea));
13630b2d68dSdyoung ea.ea_iba.iba_iot = x86_bus_space_io;
13730b2d68dSdyoung ea.ea_iba.iba_memt = x86_bus_space_mem;
138e56b1d0bSthorpej #if NISA > 0
139e56b1d0bSthorpej ea.ea_iba.iba_dmat = &isa_bus_dma_tag;
140e56b1d0bSthorpej #endif
1412685996bSthorpej config_found(self, &ea.ea_iba, isabusprint,
142*c7fb772bSthorpej CFARGS(.iattr = "isabus"));
143e56b1d0bSthorpej }
144