xref: /netbsd/sys/arch/algor/dev/bonito_mainbus.c (revision 6550d01e)
1 /*	$NetBSD: bonito_mainbus.c,v 1.11 2008/04/28 20:23:10 martin Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 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: bonito_mainbus.c,v 1.11 2008/04/28 20:23:10 martin Exp $");
34 
35 #include "opt_algor_p6032.h"
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/conf.h>
40 #include <sys/reboot.h>
41 #include <sys/device.h>
42 
43 #include <machine/bus.h>
44 #include <machine/autoconf.h>
45 
46 #include <mips/bonito/bonitoreg.h>
47 
48 #ifdef ALGOR_P6032
49 #include <algor/algor/algor_p6032var.h>
50 #endif
51 
52 struct bonito_softc {
53 	struct device sc_dev;
54 	struct bonito_config *sc_bonito;
55 };
56 
57 int	bonito_mainbus_match(struct device *, struct cfdata *, void *);
58 void	bonito_mainbus_attach(struct device *, struct device *, void *);
59 
60 CFATTACH_DECL(bonito_mainbus, sizeof(struct bonito_softc),
61     bonito_mainbus_match, bonito_mainbus_attach, NULL, NULL);
62 extern struct cfdriver bonito_cd;
63 
64 int
65 bonito_mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
66 {
67 	struct mainbus_attach_args *ma = aux;
68 
69 	if (strcmp(ma->ma_name, bonito_cd.cd_name) == 0)
70 		return (1);
71 
72 	return (0);
73 }
74 
75 void
76 bonito_mainbus_attach(struct device *parent, struct device *self, void *aux)
77 {
78 	struct bonito_softc *sc = (void *) self;
79 	struct pcibus_attach_args pba;
80 	struct bonito_config *bc;
81 	pcireg_t rev;
82 
83 	/*
84 	 * There is only one PCI controller on an Algorithmics board.
85 	 */
86 #if defined(ALGOR_P6032)
87 	bc = &p6032_configuration.ac_bonito;
88 #endif
89 	sc->sc_bonito = bc;
90 
91 	rev = PCI_REVISION(REGVAL(BONITO_PCICLASS));
92 
93 	printf(": BONITO Memory and PCI controller, %s rev. %d.%d\n",
94 	    BONITO_REV_FPGA(rev) ? "FPGA" : "ASIC",
95 	    BONITO_REV_MAJOR(rev), BONITO_REV_MINOR(rev));
96 
97 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
98 	pba.pba_bus = 0;
99 	pba.pba_bridgetag = NULL;
100 
101 #if defined(ALGOR_P6032)
102 	    {
103 		struct p6032_config *acp = &p6032_configuration;
104 
105 		pba.pba_iot = &acp->ac_iot;
106 		pba.pba_memt = &acp->ac_memt;
107 		pba.pba_dmat = &acp->ac_pci_dmat;
108 		pba.pba_dmat64 = NULL;
109 		pba.pba_pc = &acp->ac_pc;
110 	    }
111 #endif /* ALGOR_P6032 */
112 
113 	(void) config_found_ia(self, "pcibus", &pba, pcibusprint);
114 }
115