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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* sun4u specific DDI implementation
*/
#include <sys/bootconf.h>
#include <sys/conf.h>
#include <sys/ddi_subrdefs.h>
#include <sys/ethernet.h>
#include <sys/idprom.h>
#include <sys/machsystm.h>
#include <sys/promif.h>
#include <sys/prom_plat.h>
#include <sys/sunndi.h>
#include <sys/systeminfo.h>
#include <sys/fpu/fpusystm.h>
#include <sys/vm.h>
#include <sys/fs/dv_node.h>
#include <sys/fs/snode.h>
/*
* Favored drivers of this implementation
* architecture. These drivers MUST be present for
* the system to boot at all.
*/
char *impl_module_list[] = {
"rootnex",
"options",
"sad", /* Referenced via init_tbl[] */
"pseudo",
"clone",
"scsi_vhci",
(char *)0
};
/*
* These strings passed to not_serviced in locore.s
*/
const char busname_ovec[] = "onboard ";
const char busname_svec[] = "SBus ";
const char busname_vec[] = "";
static uint64_t *intr_map_reg[32];
/*
* Forward declarations
*/
static int getlongprop_buf();
static int get_boardnum(int nid, dev_info_t *par);
/*
* Check the status of the device node passed as an argument.
*
* if ((status is OKAY) || (status is DISABLED))
* return DDI_SUCCESS
* else
* print a warning and return DDI_FAILURE
*/
/*ARGSUSED*/
int
check_status(int id, char *buf, dev_info_t *parent)
{
char status_buf[64];
char devtype_buf[OBP_MAXPROPNAME];
char board_buf[32];
char path[OBP_MAXPATHLEN];
int boardnum;
int retval = DDI_FAILURE;
extern int status_okay(int, char *, int);
/*
* is the status okay?
*/
if (status_okay(id, status_buf, sizeof (status_buf)))
return (DDI_SUCCESS);
/*
* a status property indicating bad memory will be associated
* with a node which has a "device_type" property with a value of
* "memory-controller". in this situation, return DDI_SUCCESS
*/
if (getlongprop_buf(id, OBP_DEVICETYPE, devtype_buf,
sizeof (devtype_buf)) > 0) {
if (strcmp(devtype_buf, "memory-controller") == 0)
retval = DDI_SUCCESS;
}
/*
* get the full OBP pathname of this node
*/
if (prom_phandle_to_path((phandle_t)id, path, sizeof (path)) < 0)
cmn_err(CE_WARN, "prom_phandle_to_path(%d) failed", id);
/*
* get the board number, if one exists
*/
if ((boardnum = get_boardnum(id, parent)) >= 0)
(void) sprintf(board_buf, " on board %d", boardnum);
else
board_buf[0] = '\0';
/*
* print the status property information
*/
cmn_err(CE_WARN, "status '%s' for '%s'%s",
status_buf, path, board_buf);
return (retval);
}
/*
* determine the board number associated with this nodeid
*/
static int
get_boardnum(int nid, dev_info_t *par)
{
int board_num;
if (prom_getprop((pnode_t)nid, OBP_BOARDNUM,
(caddr_t)&board_num) != -1)
return (board_num);
/*
* Look at current node and up the parent chain
* till we find a node with an OBP_BOARDNUM.
*/
while (par) {
nid = ddi_get_nodeid(par);
if (prom_getprop((pnode_t)nid, OBP_BOARDNUM,
(caddr_t)&board_num) != -1)
return (board_num);
par = ddi_get_parent(par);
}
return (-1);
}
/*
* Note that this routine does not take into account the endianness
* of the host or the device (or PROM) when retrieving properties.
*/
static int
getlongprop_buf(int id, char *name, char *buf, int maxlen)
{
int size;
size = prom_getproplen((pnode_t)id, name);
if (size <= 0 || (size > maxlen - 1))
return (-1);
if (-1 == prom_getprop((pnode_t)id, name, buf))
return (-1);
/*
* Workaround for bugid 1085575 - OBP may return a "name" property
* without null terminating the string with '\0'. When this occurs,
* append a '\0' and return (size + 1).
*/
if (strcmp("name", name) == 0) {
if (buf[size - 1] != '\0') {
buf[size] = '\0';
size += 1;
}
}
return (size);
}
/*
* Routines to set/get UPA slave only device interrupt mapping registers.
* set_intr_mapping_reg() is called by the UPA master to register the address
* of an interrupt mapping register. The upa id is that of the master. If
* this routine is called on behalf of a slave device, the framework
* determines the upa id of the slave based on that supplied by the master.
*
* get_intr_mapping_reg() is called by the UPA nexus driver on behalf
* of a child device to get and program the interrupt mapping register of
* one of it's child nodes. It uses the upa id of the child device to
* index into a table of mapping registers. If the routine is called on
* behalf of a slave device and the mapping register has not been set,
* the framework determines the devinfo node of the corresponding master
* nexus which owns the mapping register of the slave and installs that
* driver. The device driver which owns the mapping register must call
* set_intr_mapping_reg() in its attach routine to register the slaves
* mapping register with the system.
*/
void
set_intr_mapping_reg(int upaid, uint64_t *addr, int slave)
{
int affin_upaid;
/* For UPA master devices, set the mapping reg addr and we're done */
if (slave == 0) {
intr_map_reg[upaid] = addr;
return;
}
/*
* If we get here, we're adding an entry for a UPA slave only device.
* The UPA id of the device which has affinity with that requesting,
* will be the device with the same UPA id minus the slave number.
* If the affin_upaid is negative, silently return to the caller.
*/
if ((affin_upaid = upaid - slave) < 0)
return;
/*
* Load the address of the mapping register in the correct slot
* for the slave device.
*/
intr_map_reg[affin_upaid] = addr;
}
uint64_t *
get_intr_mapping_reg(int upaid, int slave)
{
int affin_upaid;
dev_info_t *affin_dip;
uint64_t *addr = intr_map_reg[upaid];
/* If we're a UPA master, or we have a valid mapping register. */
if (!slave || addr != NULL)
return (addr);
/*
* We only get here if we're a UPA slave only device whose interrupt
* mapping register has not been set.
* We need to try and install the nexus whose physical address
* space is where the slaves mapping register resides. They
* should call set_intr_mapping_reg() in their xxattach() to register
* the mapping register with the system.
*/
/*
* We don't know if a single- or multi-interrupt proxy is fielding
* our UPA slave interrupt, we must check both cases.
* Start out by assuming the multi-interrupt case.
* We assume that single- and multi- interrupters are not
* overlapping in UPA portid space.
*/
affin_upaid = upaid | 3;
/*
* We start looking for the multi-interrupter affinity node.
* We know it's ONLY a child of the root node since the root
* node defines UPA space.
*/
for (affin_dip = ddi_get_child(ddi_root_node()); affin_dip;
affin_dip = ddi_get_next_sibling(affin_dip))
if (ddi_prop_get_int(DDI_DEV_T_ANY, affin_dip,
DDI_PROP_DONTPASS, "upa-portid", -1) == affin_upaid)
break;
if (affin_dip) {
if (i_ddi_attach_node_hierarchy(affin_dip) == DDI_SUCCESS) {
/* try again to get the mapping register. */
addr = intr_map_reg[upaid];
}
}
/*
* If we still don't have a mapping register try single -interrupter
* case.
*/
if (addr == NULL) {
affin_upaid = upaid | 1;
for (affin_dip = ddi_get_child(ddi_root_node()); affin_dip;
affin_dip = ddi_get_next_sibling(affin_dip))
if (ddi_prop_get_int(DDI_DEV_T_ANY, affin_dip,
DDI_PROP_DONTPASS, "upa-portid", -1) == affin_upaid)
break;
if (affin_dip) {
if (i_ddi_attach_node_hierarchy(affin_dip)
== DDI_SUCCESS) {
/* try again to get the mapping register. */
addr = intr_map_reg[upaid];
}
}
}
return (addr);
}
static struct upa_dma_pfns {
pfn_t hipfn;
pfn_t lopfn;
} upa_dma_pfn_array[MAX_UPA];
static int upa_dma_pfn_ndx = 0;
/*
* Certain UPA busses cannot accept dma transactions from any other source
* except for memory due to livelock conditions in their hardware. (e.g. sbus
* and PCI). These routines allow devices or busses on the UPA to register
* a physical address block within it's own register space where DMA can be
* performed. Currently, the FFB is the only such device which supports
* device DMA on the UPA.
*/
void
pf_set_dmacapable(pfn_t hipfn, pfn_t lopfn)
{
int i = upa_dma_pfn_ndx;
upa_dma_pfn_ndx++;
upa_dma_pfn_array[i].hipfn = hipfn;
upa_dma_pfn_array[i].lopfn = lopfn;
}
void
pf_unset_dmacapable(pfn_t pfn)
{
int i;
for (i = 0; i < upa_dma_pfn_ndx; i++) {
if (pfn <= upa_dma_pfn_array[i].hipfn &&
pfn >= upa_dma_pfn_array[i].lopfn) {
upa_dma_pfn_array[i].hipfn =
upa_dma_pfn_array[upa_dma_pfn_ndx - 1].hipfn;
upa_dma_pfn_array[i].lopfn =
upa_dma_pfn_array[upa_dma_pfn_ndx - 1].lopfn;
upa_dma_pfn_ndx--;
break;
}
}
}
/*
* This routine should only be called using a pfn that is known to reside
* in IO space. The function pf_is_memory() can be used to determine this.
*/
int
pf_is_dmacapable(pfn_t pfn)
{
int i, j;
/* If the caller passed in a memory pfn, return true. */
if (pf_is_memory(pfn))
return (1);
for (i = upa_dma_pfn_ndx, j = 0; j < i; j++)
if (pfn <= upa_dma_pfn_array[j].hipfn &&
pfn >= upa_dma_pfn_array[j].lopfn)
return (1);
return (0);
}
/*
* Find cpu_id corresponding to the dip of a CPU device node
*/
int
dip_to_cpu_id(dev_info_t *dip, processorid_t *cpu_id)
{
pnode_t nodeid;
int i;
nodeid = (pnode_t)ddi_get_nodeid(dip);
for (i = 0; i < NCPU; i++) {
if (cpunodes[i].nodeid == nodeid) {
*cpu_id = i;
return (DDI_SUCCESS);
}
}
return (DDI_FAILURE);
}
/* ARGSUSED */
void
translate_devid(dev_info_t *dip)
{
}
|