1*c7fb772bSthorpej /* $NetBSD: pcmb.c,v 1.22 2021/08/07 16:18:55 thorpej Exp $ */
2b53fce84Sjdolecek
3b53fce84Sjdolecek /*-
4b53fce84Sjdolecek * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
5b53fce84Sjdolecek * All rights reserved.
6b53fce84Sjdolecek *
7b53fce84Sjdolecek * This code is derived from software contributed to The NetBSD Foundation
8b53fce84Sjdolecek * by Jason R. Thorpe and Jaromir Dolecek.
9b53fce84Sjdolecek *
10b53fce84Sjdolecek * Redistribution and use in source and binary forms, with or without
11b53fce84Sjdolecek * modification, are permitted provided that the following conditions
12b53fce84Sjdolecek * are met:
13b53fce84Sjdolecek * 1. Redistributions of source code must retain the above copyright
14b53fce84Sjdolecek * notice, this list of conditions and the following disclaimer.
15b53fce84Sjdolecek * 2. Redistributions in binary form must reproduce the above copyright
16b53fce84Sjdolecek * notice, this list of conditions and the following disclaimer in the
17b53fce84Sjdolecek * documentation and/or other materials provided with the distribution.
18b53fce84Sjdolecek *
19b53fce84Sjdolecek * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20b53fce84Sjdolecek * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21b53fce84Sjdolecek * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22b53fce84Sjdolecek * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23b53fce84Sjdolecek * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24b53fce84Sjdolecek * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25b53fce84Sjdolecek * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26b53fce84Sjdolecek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27b53fce84Sjdolecek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28b53fce84Sjdolecek * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29b53fce84Sjdolecek * POSSIBILITY OF SUCH DAMAGE.
30b53fce84Sjdolecek */
31b53fce84Sjdolecek
32b53fce84Sjdolecek /*
33b53fce84Sjdolecek * "Driver" for PCI-MCA Bridges.
34b53fce84Sjdolecek */
35b53fce84Sjdolecek
3695c969f2Slukem #include <sys/cdefs.h>
37*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: pcmb.c,v 1.22 2021/08/07 16:18:55 thorpej Exp $");
3895c969f2Slukem
39b53fce84Sjdolecek #include <sys/types.h>
40b53fce84Sjdolecek #include <sys/param.h>
41b53fce84Sjdolecek #include <sys/systm.h>
42b53fce84Sjdolecek #include <sys/device.h>
43f5b064eeSdyoung #include <sys/bus.h>
44b53fce84Sjdolecek
45b53fce84Sjdolecek #include <dev/mca/mcavar.h>
46b53fce84Sjdolecek
47b53fce84Sjdolecek #include <dev/pci/pcivar.h>
48b53fce84Sjdolecek #include <dev/pci/pcireg.h>
49b53fce84Sjdolecek
50b53fce84Sjdolecek #include <dev/pci/pcidevs.h>
51b53fce84Sjdolecek
52b53fce84Sjdolecek #include "mca.h"
53b53fce84Sjdolecek
54ed38b748Sxtraeme int pcmbmatch(device_t, cfdata_t, void *);
55ed38b748Sxtraeme void pcmbattach(device_t, device_t, void *);
56b53fce84Sjdolecek
57ed38b748Sxtraeme CFATTACH_DECL_NEW(pcmb, 0, pcmbmatch, pcmbattach, NULL, NULL);
58b53fce84Sjdolecek
59ed38b748Sxtraeme void pcmb_callback(device_t);
60b53fce84Sjdolecek
61b53fce84Sjdolecek int
pcmbmatch(device_t parent,cfdata_t match,void * aux)62ed38b748Sxtraeme pcmbmatch(device_t parent, cfdata_t match, void *aux)
63b53fce84Sjdolecek {
64b53fce84Sjdolecek struct pci_attach_args *pa = aux;
65b53fce84Sjdolecek
66b53fce84Sjdolecek /*
676402f68dSjdolecek * Match anything which claims to be PCI-MCA bridge.
68b53fce84Sjdolecek */
696402f68dSjdolecek if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE
706402f68dSjdolecek && PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_MC)
71b53fce84Sjdolecek return (1);
72b53fce84Sjdolecek
73b53fce84Sjdolecek return (0);
74b53fce84Sjdolecek }
75b53fce84Sjdolecek
76b53fce84Sjdolecek void
pcmbattach(device_t parent,device_t self,void * aux)77ed38b748Sxtraeme pcmbattach(device_t parent, device_t self, void *aux)
78b53fce84Sjdolecek {
79b53fce84Sjdolecek struct pci_attach_args *pa = aux;
80b53fce84Sjdolecek char devinfo[256];
81b53fce84Sjdolecek
82a9beff95Sthorpej aprint_naive("\n");
83a9beff95Sthorpej aprint_normal("\n");
84b53fce84Sjdolecek
85b53fce84Sjdolecek /*
86b53fce84Sjdolecek * Just print out a description and defer configuration
87b53fce84Sjdolecek * until all PCI devices have been attached.
88b53fce84Sjdolecek */
8961230437Sitojun pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
90ee63fe0aScegger aprint_normal_dev(self, "%s (rev. 0x%02x)\n", devinfo,
91b53fce84Sjdolecek PCI_REVISION(pa->pa_class));
92b53fce84Sjdolecek
93b53fce84Sjdolecek config_defer(self, pcmb_callback);
94b53fce84Sjdolecek }
95b53fce84Sjdolecek
96b53fce84Sjdolecek void
pcmb_callback(device_t self)97ed38b748Sxtraeme pcmb_callback(device_t self)
98b53fce84Sjdolecek {
9946289e1fSdrochner struct mcabus_attach_args ma;
100b53fce84Sjdolecek
101b53fce84Sjdolecek /*
102b53fce84Sjdolecek * Attach MCA bus behind this bridge.
103b53fce84Sjdolecek */
10430b2d68dSdyoung ma.mba_iot = x86_bus_space_io;
10530b2d68dSdyoung ma.mba_memt = x86_bus_space_mem;
106b53fce84Sjdolecek #if NMCA > 0
10746289e1fSdrochner ma.mba_dmat = &mca_bus_dma_tag;
108b53fce84Sjdolecek #endif
10946289e1fSdrochner ma.mba_mc = NULL;
11046289e1fSdrochner ma.mba_bus = 0;
111*c7fb772bSthorpej config_found(self, &ma, mcabusprint, CFARGS_NONE);
112b53fce84Sjdolecek }
113