1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/* $NetBSD: uni-n.c,v 1.13 2022/12/28 07:18:29 macallan Exp $ */
/*-
* Copyright (C) 2005 Michael Lorenz.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* a driver to match the uni_n node in OF's device tree and attach its children
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uni-n.c,v 1.13 2022/12/28 07:18:29 macallan Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_pci.h>
#include <machine/autoconf.h>
#include "fcu.h"
static void uni_n_attach(device_t, device_t, void *);
static int uni_n_match(device_t, cfdata_t, void *);
static int uni_n_print(void *, const char *);
struct uni_n_softc {
device_t sc_dev;
struct powerpc_bus_space sc_memt;
int sc_node;
};
CFATTACH_DECL_NEW(uni_n, sizeof(struct uni_n_softc),
uni_n_match, uni_n_attach, NULL, NULL);
#if NFCU > 0
/* storage for CPUID SEEPROM contents found on some G5 */
static uint8_t eeprom[2][160];
#endif
static const char *skiplist[] = {
"openpic",
"chrp,open-pic",
"open-pic",
"mpic",
"dart",
"u3-dart",
"u4-dart",
NULL
};
int
uni_n_match(device_t parent, cfdata_t cf, void *aux)
{
struct confargs *ca = aux;
char compat[32];
if ((strcmp(ca->ca_name, "uni-n") != 0) &&
(strcmp(ca->ca_name, "u4") != 0) &&
(strcmp(ca->ca_name, "u3") != 0))
return 0;
memset(compat, 0, sizeof(compat));
#if 0
OF_getprop(ca->ca_node, "compatible", compat, sizeof(compat));
if (strcmp(compat, "uni-north") != 0)
return 0;
#endif
return 1;
}
/*
* Attach all the sub-devices we can find
*/
void
uni_n_attach(device_t parent, device_t self, void *aux)
{
struct uni_n_softc *sc = device_private(self);
struct confargs *our_ca = aux;
struct confargs ca;
int node, child, namelen;
#if NFCU > 0
int cpuid;
#endif
u_int reg[20];
int intr[6];
char name[32];
sc->sc_dev = self;
node = our_ca->ca_node;
sc->sc_node = node;
printf(" address 0x%08x\n",
our_ca->ca_reg[our_ca->ca_nreg > 8 ? 1 : 0]);
#if NFCU > 0
/*
* zero out eeprom blocks, then see if we have valid data
* doing this here because the EEPROMs are dangling from our i2c bus
* but we can get all the data just from looking at the properties
*/
memset(eeprom, 0, sizeof(eeprom));
cpuid = OF_finddevice("/u3/i2c/cpuid@a0");
OF_getprop(cpuid, "cpuid", eeprom[0], sizeof(eeprom[0]));
if (eeprom[0][1] != 0)
aprint_normal_dev(self, "found EEPROM data for CPU 0\n");
cpuid = OF_finddevice("/u3/i2c/cpuid@a2");
OF_getprop(cpuid, "cpuid", eeprom[1], sizeof(eeprom[1]));
if (eeprom[1][1] != 0)
aprint_normal_dev(self, "found EEPROM data for CPU 1\n");
#endif
memset(&sc->sc_memt, 0, sizeof(struct powerpc_bus_space));
sc->sc_memt.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE;
if (ofwoea_map_space(RANGE_TYPE_MACIO, RANGE_MEM, node, &sc->sc_memt,
"uni-n mem-space") != 0) {
panic("Can't init uni-n mem tag");
}
devhandle_t selfh = device_handle(self);
for (child = OF_child(node); child; child = OF_peer(child)) {
if (of_compatible(child, skiplist)) continue;
namelen = OF_getprop(child, "name", name, sizeof(name));
if (namelen < 0)
continue;
if (namelen >= sizeof(name))
continue;
name[namelen] = 0;
ca.ca_name = name;
ca.ca_node = child;
ca.ca_tag = &sc->sc_memt;
ca.ca_nreg = OF_getprop(child, "reg", reg, sizeof(reg));
ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
sizeof(intr));
if (ca.ca_nintr == -1)
ca.ca_nintr = OF_getprop(child, "interrupts", intr,
sizeof(intr));
ca.ca_reg = reg;
ca.ca_intr = intr;
config_found(self, &ca, uni_n_print,
CFARGS(.devhandle = devhandle_from_of(selfh, child)));
}
}
int
uni_n_print(void *aux, const char *uni_n)
{
struct confargs *ca = aux;
if (uni_n)
aprint_normal("%s at %s", ca->ca_name, uni_n);
if (ca->ca_nreg > 0)
aprint_normal(" address 0x%x", ca->ca_reg[0]);
return UNCONF;
}
#if NFCU > 0
int
get_cpuid(int cpu, uint8_t *buf)
{
if ((cpu < 0) || (cpu > 1)) return -1;
if (eeprom[cpu][1] == 0) return 0;
memcpy(buf, eeprom[cpu], sizeof(eeprom[cpu]));
return sizeof(eeprom[cpu]);
}
#endif
|