xref: /netbsd/sys/arch/sgimips/gio/gio.c (revision c4a72b64)
1 /*	$NetBSD: gio.c,v 1.8 2002/11/09 18:55:45 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 2000 Soren S. Jorvang
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *          This product includes software developed for the
18  *          NetBSD Project.  See http://www.netbsd.org/ for
19  *          information about NetBSD.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #include "opt_ddb.h"
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 
41 #include <sgimips/gio/gioreg.h>
42 #include <sgimips/gio/giovar.h>
43 
44 #include "locators.h"
45 
46 struct gio_softc {
47 	struct	device sc_dev;
48 };
49 
50 static int	gio_match(struct device *, struct cfdata *, void *);
51 static void	gio_attach(struct device *, struct device *, void *);
52 static int	gio_print(void *, const char *);
53 static int	gio_search(struct device *, struct cfdata *, void *);
54 
55 CFATTACH_DECL(gio, sizeof(struct gio_softc),
56     gio_match, gio_attach, NULL, NULL);
57 
58 static int
59 gio_match(parent, match, aux)
60 	struct device *parent;
61 	struct cfdata *match;
62 	void *aux;
63 {
64 	struct giobus_attach_args *gba = aux;
65 
66 	if (strcmp(gba->gba_busname, match->cf_name) != 0)
67 		return 0;
68 
69 	return 1;
70 }
71 
72 static void
73 gio_attach(parent, self, aux)
74 	struct device *parent;
75 	struct device *self;
76 	void *aux;
77 {
78 	struct gio_attach_args ga;
79 
80 	printf("\n");
81 
82 	config_search(gio_search, self, &ga);
83 }
84 
85 static int
86 gio_print(aux, pnp)
87 	void *aux;
88 	const char *pnp;
89 {
90 	struct gio_attach_args *ga = aux;
91 
92 	if (pnp != 0)
93 		return QUIET;
94 
95 	if (ga->ga_slot != GIOCF_SLOT_DEFAULT)
96 		printf(" slot %d", ga->ga_slot);
97 	if (ga->ga_addr != (uint32_t) GIOCF_ADDR_DEFAULT)
98 		printf(" addr 0x%x", ga->ga_addr);
99 
100 	return UNCONF;
101 }
102 
103 static int
104 gio_search(parent, cf, aux)
105 	struct device *parent;
106 	struct cfdata *cf;
107 	void *aux;
108 {
109 	struct gio_attach_args *ga = aux;
110 
111 	do {
112 		ga->ga_slot = cf->cf_loc[GIOCF_SLOT];
113 		ga->ga_addr = cf->cf_loc[GIOCF_ADDR];
114 		ga->ga_iot = 0;
115 		ga->ga_ioh = MIPS_PHYS_TO_KSEG1(ga->ga_addr);
116 		if (config_match(parent, cf, ga) > 0)
117 			config_attach(parent, cf, ga, gio_print);
118 	} while (cf->cf_fstate == FSTATE_STAR);
119 
120 	return 0;
121 }
122