xref: /netbsd/sys/arch/cobalt/cobalt/mainbus.c (revision c4a72b64)
1 /*	$NetBSD: mainbus.c,v 1.5 2002/10/02 05:07:43 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions, and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/device.h>
31 
32 #include <dev/pci/pcivar.h>
33 
34 #include <mips/cpuregs.h>
35 
36 #include <machine/autoconf.h>
37 
38 #include "locators.h"
39 #include "pci.h"
40 
41 static int	mainbus_match(struct device *, struct cfdata *, void *);
42 static void	mainbus_attach(struct device *, struct device *, void *);
43 static int	mainbus_search(struct device *, struct cfdata *, void *);
44 int		mainbus_print(void *, const char *);
45 
46 CFATTACH_DECL(mainbus, sizeof(struct device),
47     mainbus_match, mainbus_attach, NULL, NULL);
48 
49 static int
50 mainbus_match(parent, match, aux)
51 	struct device *parent;
52 	struct cfdata *match;
53 	void *aux;
54 {
55 	return 1;
56 }
57 
58 static void
59 mainbus_attach(parent, self, aux)
60 	struct device *parent;
61 	struct device *self;
62 	void *aux;
63 {
64 	struct mainbus_attach_args *ma = aux;
65 
66 	/*
67 	 * XXX Check for Qube/RaQ 1 vs. 2.
68 	 */
69 
70 	printf("\n");
71 
72 	config_search(mainbus_search, self, ma);
73 }
74 
75 static int
76 mainbus_search(parent, cf, aux)
77 	struct device *parent;
78 	struct cfdata *cf;
79 	void *aux;
80 {
81 	struct mainbus_attach_args *ma = aux;
82 
83 	do {
84 		ma->ma_addr = cf->cf_loc[MAINBUSCF_ADDR];
85 		ma->ma_iot = 0;
86 		ma->ma_ioh = MIPS_PHYS_TO_KSEG1(ma->ma_addr);
87 		ma->ma_level = cf->cf_loc[MAINBUSCF_LEVEL];
88 		if (config_match(parent, cf, ma) > 0)
89 			config_attach(parent, cf, ma, mainbus_print);
90 	} while (cf->cf_fstate == FSTATE_STAR);
91 
92 	return 0;
93 }
94 
95 int
96 mainbus_print(aux, pnp)
97 	void *aux;
98 	const char *pnp;
99 {
100 	struct mainbus_attach_args *ma = aux;
101 
102 	if (pnp != 0)
103 		return QUIET;
104 
105 	if (ma->ma_addr != MAINBUSCF_ADDR_DEFAULT)
106 		printf(" addr 0x%lx", ma->ma_addr);
107 	if (ma->ma_level != MAINBUSCF_LEVEL_DEFAULT)
108 		printf(" level %d", ma->ma_level);
109 
110 	return UNCONF;
111 }
112