gio.c revision 1.2 1 /* $NetBSD: gio.c,v 1.2 2002/03/13 13:12:27 simonb 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 struct cfattach gio_ca = {
56 sizeof(struct gio_softc), gio_match, gio_attach
57 };
58
59 static int
60 gio_match(parent, match, aux)
61 struct device *parent;
62 struct cfdata *match;
63 void *aux;
64 {
65 struct giobus_attach_args *gba = aux;
66
67 if (strcmp(gba->gba_busname, match->cf_driver->cd_name) != 0)
68 return 0;
69
70 return 1;
71 }
72
73 static void
74 gio_attach(parent, self, aux)
75 struct device *parent;
76 struct device *self;
77 void *aux;
78 {
79 struct gio_attach_args ga;
80
81 printf("\n");
82
83 config_search(gio_search, self, &ga);
84 }
85
86 static int
87 gio_print(aux, pnp)
88 void *aux;
89 const char *pnp;
90 {
91 struct gio_attach_args *ga = aux;
92
93 if (pnp != 0)
94 return QUIET;
95
96 if (ga->ga_slot != GIOCF_SLOT_DEFAULT)
97 printf(" slot %d", ga->ga_slot);
98 if (ga->ga_addr != GIOCF_ADDR_DEFAULT)
99 printf(" addr 0x%x", ga->ga_addr);
100
101 return UNCONF;
102 }
103
104 static int
105 gio_search(parent, cf, aux)
106 struct device *parent;
107 struct cfdata *cf;
108 void *aux;
109 {
110 struct gio_attach_args *ga = aux;
111
112 do {
113 ga->ga_slot = cf->cf_loc[GIOCF_SLOT];
114 ga->ga_addr = cf->cf_loc[GIOCF_ADDR];
115 ga->ga_iot = 0;
116 ga->ga_ioh = MIPS_PHYS_TO_KSEG1(ga->ga_addr);
117 if ((*cf->cf_attach->ca_match)(parent, cf, ga) > 0)
118 config_attach(parent, cf, ga, gio_print);
119 } while (cf->cf_fstate == FSTATE_STAR);
120
121 return 0;
122 }
123