uni-n.c revision 1.7 1 1.7 macallan /* $NetBSD: uni-n.c,v 1.7 2017/09/15 21:33:52 macallan Exp $ */
2 1.1 macallan
3 1.1 macallan /*-
4 1.1 macallan * Copyright (C) 2005 Michael Lorenz.
5 1.1 macallan *
6 1.1 macallan * Redistribution and use in source and binary forms, with or without
7 1.1 macallan * modification, are permitted provided that the following conditions
8 1.1 macallan * are met:
9 1.1 macallan * 1. Redistributions of source code must retain the above copyright
10 1.1 macallan * notice, this list of conditions and the following disclaimer.
11 1.1 macallan * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 macallan * notice, this list of conditions and the following disclaimer in the
13 1.1 macallan * documentation and/or other materials provided with the distribution.
14 1.1 macallan * 3. The name of the author may not be used to endorse or promote products
15 1.1 macallan * derived from this software without specific prior written permission.
16 1.1 macallan *
17 1.1 macallan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 macallan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 macallan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 macallan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 macallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 macallan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 macallan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 macallan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 macallan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 1.1 macallan * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 macallan */
28 1.1 macallan
29 1.1 macallan /*
30 1.1 macallan * a driver to match the uni_n node in OF's device tree and attach its children
31 1.1 macallan */
32 1.1 macallan
33 1.1 macallan #include <sys/cdefs.h>
34 1.7 macallan __KERNEL_RCSID(0, "$NetBSD: uni-n.c,v 1.7 2017/09/15 21:33:52 macallan Exp $");
35 1.1 macallan
36 1.1 macallan #include <sys/param.h>
37 1.1 macallan #include <sys/systm.h>
38 1.1 macallan #include <sys/kernel.h>
39 1.1 macallan #include <sys/device.h>
40 1.1 macallan
41 1.1 macallan #include <dev/ofw/openfirm.h>
42 1.7 macallan #include <dev/ofw/ofw_pci.h>
43 1.1 macallan
44 1.1 macallan #include <machine/autoconf.h>
45 1.1 macallan
46 1.5 matt static void uni_n_attach(device_t, device_t, void *);
47 1.5 matt static int uni_n_match(device_t, cfdata_t, void *);
48 1.1 macallan static int uni_n_print(void *, const char *);
49 1.1 macallan
50 1.1 macallan struct uni_n_softc {
51 1.6 macallan device_t sc_dev;
52 1.7 macallan struct powerpc_bus_space sc_memt;
53 1.1 macallan int sc_node;
54 1.1 macallan };
55 1.1 macallan
56 1.6 macallan CFATTACH_DECL_NEW(uni_n, sizeof(struct uni_n_softc),
57 1.1 macallan uni_n_match, uni_n_attach, NULL, NULL);
58 1.1 macallan
59 1.1 macallan int
60 1.5 matt uni_n_match(device_t parent, cfdata_t cf, void *aux)
61 1.1 macallan {
62 1.1 macallan struct confargs *ca = aux;
63 1.1 macallan char compat[32];
64 1.7 macallan if ((strcmp(ca->ca_name, "uni-n") != 0) &&
65 1.7 macallan (strcmp(ca->ca_name, "u4") != 0))
66 1.1 macallan return 0;
67 1.1 macallan
68 1.1 macallan memset(compat, 0, sizeof(compat));
69 1.7 macallan #if 0
70 1.1 macallan OF_getprop(ca->ca_node, "compatible", compat, sizeof(compat));
71 1.1 macallan if (strcmp(compat, "uni-north") != 0)
72 1.1 macallan return 0;
73 1.7 macallan #endif
74 1.1 macallan return 1;
75 1.1 macallan }
76 1.1 macallan
77 1.1 macallan /*
78 1.1 macallan * Attach all the sub-devices we can find
79 1.1 macallan */
80 1.1 macallan void
81 1.5 matt uni_n_attach(device_t parent, device_t self, void *aux)
82 1.1 macallan {
83 1.5 matt struct uni_n_softc *sc = device_private(self);
84 1.1 macallan struct confargs *our_ca = aux;
85 1.1 macallan struct confargs ca;
86 1.1 macallan int node, child, namelen;
87 1.1 macallan u_int reg[20];
88 1.1 macallan int intr[6];
89 1.1 macallan char name[32];
90 1.1 macallan
91 1.6 macallan sc->sc_dev = self;
92 1.7 macallan node = our_ca->ca_node;
93 1.1 macallan sc->sc_node = node;
94 1.1 macallan printf(" address 0x%08x\n",our_ca->ca_reg[0]);
95 1.7 macallan
96 1.7 macallan memset(&sc->sc_memt, 0, sizeof(struct powerpc_bus_space));
97 1.7 macallan sc->sc_memt.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE;
98 1.7 macallan if (ofwoea_map_space(RANGE_TYPE_MACIO, RANGE_MEM, node, &sc->sc_memt,
99 1.7 macallan "uni-n mem-space") != 0) {
100 1.7 macallan panic("Can't init uni-n mem tag");
101 1.7 macallan }
102 1.7 macallan
103 1.1 macallan for (child = OF_child(node); child; child = OF_peer(child)) {
104 1.1 macallan namelen = OF_getprop(child, "name", name, sizeof(name));
105 1.1 macallan if (namelen < 0)
106 1.1 macallan continue;
107 1.1 macallan if (namelen >= sizeof(name))
108 1.1 macallan continue;
109 1.1 macallan
110 1.1 macallan name[namelen] = 0;
111 1.1 macallan ca.ca_name = name;
112 1.1 macallan ca.ca_node = child;
113 1.7 macallan ca.ca_tag = &sc->sc_memt;
114 1.1 macallan ca.ca_nreg = OF_getprop(child, "reg", reg, sizeof(reg));
115 1.1 macallan ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
116 1.1 macallan sizeof(intr));
117 1.1 macallan if (ca.ca_nintr == -1)
118 1.1 macallan ca.ca_nintr = OF_getprop(child, "interrupts", intr,
119 1.1 macallan sizeof(intr));
120 1.1 macallan
121 1.1 macallan ca.ca_reg = reg;
122 1.1 macallan ca.ca_intr = intr;
123 1.1 macallan config_found(self, &ca, uni_n_print);
124 1.1 macallan }
125 1.1 macallan }
126 1.1 macallan
127 1.1 macallan int
128 1.3 dsl uni_n_print(void *aux, const char *uni_n)
129 1.1 macallan {
130 1.1 macallan struct confargs *ca = aux;
131 1.1 macallan if (uni_n)
132 1.1 macallan aprint_normal("%s at %s", ca->ca_name, uni_n);
133 1.1 macallan
134 1.1 macallan if (ca->ca_nreg > 0)
135 1.1 macallan aprint_normal(" address 0x%x", ca->ca_reg[0]);
136 1.1 macallan
137 1.1 macallan return UNCONF;
138 1.1 macallan }
139