pcmb.c revision 1.17
1/*	$NetBSD: pcmb.c,v 1.17 2008/04/28 20:23:25 martin 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 and Jaromir Dolecek.
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/*
33 * "Driver" for PCI-MCA Bridges.
34 */
35
36#include <sys/cdefs.h>
37__KERNEL_RCSID(0, "$NetBSD: pcmb.c,v 1.17 2008/04/28 20:23:25 martin Exp $");
38
39#include <sys/types.h>
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/device.h>
43
44#include <machine/bus.h>
45
46#include <dev/mca/mcavar.h>
47
48#include <dev/pci/pcivar.h>
49#include <dev/pci/pcireg.h>
50
51#include <dev/pci/pcidevs.h>
52
53#include "mca.h"
54
55int	pcmbmatch(struct device *, struct cfdata *, void *);
56void	pcmbattach(struct device *, struct device *, void *);
57
58CFATTACH_DECL(pcmb, sizeof(struct device),
59    pcmbmatch, pcmbattach, NULL, NULL);
60
61void	pcmb_callback(struct device *);
62
63int
64pcmbmatch(struct device *parent, struct cfdata *match,
65    void *aux)
66{
67	struct pci_attach_args *pa = aux;
68
69	/*
70	 * Match anything which claims to be PCI-MCA bridge.
71	 */
72	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE
73	    && PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_MC)
74		return (1);
75
76	return (0);
77}
78
79void
80pcmbattach(struct device *parent, struct device *self, void *aux)
81{
82	struct pci_attach_args *pa = aux;
83	char devinfo[256];
84
85	aprint_naive("\n");
86	aprint_normal("\n");
87
88	/*
89	 * Just print out a description and defer configuration
90	 * until all PCI devices have been attached.
91	 */
92	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
93	aprint_normal_dev(self, "%s (rev. 0x%02x)\n", devinfo,
94	    PCI_REVISION(pa->pa_class));
95
96	config_defer(self, pcmb_callback);
97}
98
99void
100pcmb_callback(struct device *self)
101{
102	struct mcabus_attach_args ma;
103
104	/*
105	 * Attach MCA bus behind this bridge.
106	 */
107	ma.mba_iot = X86_BUS_SPACE_IO;
108	ma.mba_memt = X86_BUS_SPACE_MEM;
109#if NMCA > 0
110	ma.mba_dmat = &mca_bus_dma_tag;
111#endif
112	ma.mba_mc = NULL;
113	ma.mba_bus = 0;
114	config_found_ia(self, "mcabus", &ma, mcabusprint);
115}
116