4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * sun4u specific DDI implementation
30 #include <sys/bootconf.h>
32 #include <sys/ddi_subrdefs.h>
33 #include <sys/ethernet.h>
34 #include <sys/idprom.h>
35 #include <sys/machsystm.h>
36 #include <sys/promif.h>
37 #include <sys/prom_plat.h>
38 #include <sys/sunndi.h>
39 #include <sys/systeminfo.h>
40 #include <sys/fpu/fpusystm.h>
42 #include <sys/fs/dv_node.h>
43 #include <sys/fs/snode.h>
46 * Favored drivers of this implementation
47 * architecture. These drivers MUST be present for
48 * the system to boot at all.
50 char *impl_module_list
[] = {
53 "sad", /* Referenced via init_tbl[] */
61 * These strings passed to not_serviced in locore.s
63 const char busname_ovec
[] = "onboard ";
64 const char busname_svec
[] = "SBus ";
65 const char busname_vec
[] = "";
68 static uint64_t *intr_map_reg
[32];
71 * Forward declarations
73 static int getlongprop_buf();
74 static int get_boardnum(int nid
, dev_info_t
*par
);
77 * Check the status of the device node passed as an argument.
79 * if ((status is OKAY) || (status is DISABLED))
82 * print a warning and return DDI_FAILURE
86 check_status(int id
, char *buf
, dev_info_t
*parent
)
89 char devtype_buf
[OBP_MAXPROPNAME
];
91 char path
[OBP_MAXPATHLEN
];
93 int retval
= DDI_FAILURE
;
94 extern int status_okay(int, char *, int);
99 if (status_okay(id
, status_buf
, sizeof (status_buf
)))
100 return (DDI_SUCCESS
);
103 * a status property indicating bad memory will be associated
104 * with a node which has a "device_type" property with a value of
105 * "memory-controller". in this situation, return DDI_SUCCESS
107 if (getlongprop_buf(id
, OBP_DEVICETYPE
, devtype_buf
,
108 sizeof (devtype_buf
)) > 0) {
109 if (strcmp(devtype_buf
, "memory-controller") == 0)
110 retval
= DDI_SUCCESS
;
114 * get the full OBP pathname of this node
116 if (prom_phandle_to_path((phandle_t
)id
, path
, sizeof (path
)) < 0)
117 cmn_err(CE_WARN
, "prom_phandle_to_path(%d) failed", id
);
120 * get the board number, if one exists
122 if ((boardnum
= get_boardnum(id
, parent
)) >= 0)
123 (void) sprintf(board_buf
, " on board %d", boardnum
);
128 * print the status property information
130 cmn_err(CE_WARN
, "status '%s' for '%s'%s",
131 status_buf
, path
, board_buf
);
136 * determine the board number associated with this nodeid
139 get_boardnum(int nid
, dev_info_t
*par
)
143 if (prom_getprop((pnode_t
)nid
, OBP_BOARDNUM
,
144 (caddr_t
)&board_num
) != -1)
148 * Look at current node and up the parent chain
149 * till we find a node with an OBP_BOARDNUM.
152 nid
= ddi_get_nodeid(par
);
154 if (prom_getprop((pnode_t
)nid
, OBP_BOARDNUM
,
155 (caddr_t
)&board_num
) != -1)
158 par
= ddi_get_parent(par
);
164 * Note that this routine does not take into account the endianness
165 * of the host or the device (or PROM) when retrieving properties.
168 getlongprop_buf(int id
, char *name
, char *buf
, int maxlen
)
172 size
= prom_getproplen((pnode_t
)id
, name
);
173 if (size
<= 0 || (size
> maxlen
- 1))
176 if (-1 == prom_getprop((pnode_t
)id
, name
, buf
))
180 * Workaround for bugid 1085575 - OBP may return a "name" property
181 * without null terminating the string with '\0'. When this occurs,
182 * append a '\0' and return (size + 1).
184 if (strcmp("name", name
) == 0) {
185 if (buf
[size
- 1] != '\0') {
195 * Routines to set/get UPA slave only device interrupt mapping registers.
196 * set_intr_mapping_reg() is called by the UPA master to register the address
197 * of an interrupt mapping register. The upa id is that of the master. If
198 * this routine is called on behalf of a slave device, the framework
199 * determines the upa id of the slave based on that supplied by the master.
201 * get_intr_mapping_reg() is called by the UPA nexus driver on behalf
202 * of a child device to get and program the interrupt mapping register of
203 * one of it's child nodes. It uses the upa id of the child device to
204 * index into a table of mapping registers. If the routine is called on
205 * behalf of a slave device and the mapping register has not been set,
206 * the framework determines the devinfo node of the corresponding master
207 * nexus which owns the mapping register of the slave and installs that
208 * driver. The device driver which owns the mapping register must call
209 * set_intr_mapping_reg() in its attach routine to register the slaves
210 * mapping register with the system.
213 set_intr_mapping_reg(int upaid
, uint64_t *addr
, int slave
)
217 /* For UPA master devices, set the mapping reg addr and we're done */
219 intr_map_reg
[upaid
] = addr
;
224 * If we get here, we're adding an entry for a UPA slave only device.
225 * The UPA id of the device which has affinity with that requesting,
226 * will be the device with the same UPA id minus the slave number.
227 * If the affin_upaid is negative, silently return to the caller.
229 if ((affin_upaid
= upaid
- slave
) < 0)
233 * Load the address of the mapping register in the correct slot
234 * for the slave device.
236 intr_map_reg
[affin_upaid
] = addr
;
240 get_intr_mapping_reg(int upaid
, int slave
)
243 dev_info_t
*affin_dip
;
244 uint64_t *addr
= intr_map_reg
[upaid
];
246 /* If we're a UPA master, or we have a valid mapping register. */
247 if (!slave
|| addr
!= NULL
)
251 * We only get here if we're a UPA slave only device whose interrupt
252 * mapping register has not been set.
253 * We need to try and install the nexus whose physical address
254 * space is where the slaves mapping register resides. They
255 * should call set_intr_mapping_reg() in their xxattach() to register
256 * the mapping register with the system.
260 * We don't know if a single- or multi-interrupt proxy is fielding
261 * our UPA slave interrupt, we must check both cases.
262 * Start out by assuming the multi-interrupt case.
263 * We assume that single- and multi- interrupters are not
264 * overlapping in UPA portid space.
267 affin_upaid
= upaid
| 3;
270 * We start looking for the multi-interrupter affinity node.
271 * We know it's ONLY a child of the root node since the root
272 * node defines UPA space.
274 for (affin_dip
= ddi_get_child(ddi_root_node()); affin_dip
;
275 affin_dip
= ddi_get_next_sibling(affin_dip
))
276 if (ddi_prop_get_int(DDI_DEV_T_ANY
, affin_dip
,
277 DDI_PROP_DONTPASS
, "upa-portid", -1) == affin_upaid
)
281 if (i_ddi_attach_node_hierarchy(affin_dip
) == DDI_SUCCESS
) {
282 /* try again to get the mapping register. */
283 addr
= intr_map_reg
[upaid
];
288 * If we still don't have a mapping register try single -interrupter
293 affin_upaid
= upaid
| 1;
295 for (affin_dip
= ddi_get_child(ddi_root_node()); affin_dip
;
296 affin_dip
= ddi_get_next_sibling(affin_dip
))
297 if (ddi_prop_get_int(DDI_DEV_T_ANY
, affin_dip
,
298 DDI_PROP_DONTPASS
, "upa-portid", -1) == affin_upaid
)
302 if (i_ddi_attach_node_hierarchy(affin_dip
)
304 /* try again to get the mapping register. */
305 addr
= intr_map_reg
[upaid
];
313 static struct upa_dma_pfns
{
316 } upa_dma_pfn_array
[MAX_UPA
];
318 static int upa_dma_pfn_ndx
= 0;
321 * Certain UPA busses cannot accept dma transactions from any other source
322 * except for memory due to livelock conditions in their hardware. (e.g. sbus
323 * and PCI). These routines allow devices or busses on the UPA to register
324 * a physical address block within it's own register space where DMA can be
325 * performed. Currently, the FFB is the only such device which supports
326 * device DMA on the UPA.
329 pf_set_dmacapable(pfn_t hipfn
, pfn_t lopfn
)
331 int i
= upa_dma_pfn_ndx
;
335 upa_dma_pfn_array
[i
].hipfn
= hipfn
;
336 upa_dma_pfn_array
[i
].lopfn
= lopfn
;
340 pf_unset_dmacapable(pfn_t pfn
)
344 for (i
= 0; i
< upa_dma_pfn_ndx
; i
++) {
345 if (pfn
<= upa_dma_pfn_array
[i
].hipfn
&&
346 pfn
>= upa_dma_pfn_array
[i
].lopfn
) {
347 upa_dma_pfn_array
[i
].hipfn
=
348 upa_dma_pfn_array
[upa_dma_pfn_ndx
- 1].hipfn
;
349 upa_dma_pfn_array
[i
].lopfn
=
350 upa_dma_pfn_array
[upa_dma_pfn_ndx
- 1].lopfn
;
358 * This routine should only be called using a pfn that is known to reside
359 * in IO space. The function pf_is_memory() can be used to determine this.
362 pf_is_dmacapable(pfn_t pfn
)
366 /* If the caller passed in a memory pfn, return true. */
367 if (pf_is_memory(pfn
))
370 for (i
= upa_dma_pfn_ndx
, j
= 0; j
< i
; j
++)
371 if (pfn
<= upa_dma_pfn_array
[j
].hipfn
&&
372 pfn
>= upa_dma_pfn_array
[j
].lopfn
)
380 * Find cpu_id corresponding to the dip of a CPU device node
383 dip_to_cpu_id(dev_info_t
*dip
, processorid_t
*cpu_id
)
388 nodeid
= (pnode_t
)ddi_get_nodeid(dip
);
389 for (i
= 0; i
< NCPU
; i
++) {
390 if (cpunodes
[i
].nodeid
== nodeid
) {
392 return (DDI_SUCCESS
);
395 return (DDI_FAILURE
);
400 translate_devid(dev_info_t
*dip
)