xref: /titanic_44/usr/src/uts/sun4/io/rootnex.c (revision 321502cd0930b1eb6d4805e17f16234f3e3ff4b2)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * sun4 root nexus driver
31  */
32 
33 #include <sys/conf.h>
34 #include <sys/modctl.h>
35 #include <sys/ddi_subrdefs.h>
36 #include <sys/sunndi.h>
37 #include <sys/vmsystm.h>
38 #include <sys/async.h>
39 #include <sys/intr.h>
40 #include <sys/ndifm.h>
41 #include <vm/seg_dev.h>
42 #include <vm/seg_kmem.h>
43 #include <sys/ontrap.h>
44 
45 /* Useful debugging Stuff */
46 #include <sys/nexusdebug.h>
47 #define	ROOTNEX_MAP_DEBUG		0x1
48 #define	ROOTNEX_INTR_DEBUG		0x2
49 
50 /*
51  * config information
52  */
53 
54 static int
55 rootnex_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
56     off_t offset, off_t len, caddr_t *vaddrp);
57 
58 static int
59 rootnex_intr_ops(dev_info_t *, dev_info_t *, ddi_intr_op_t,
60     ddi_intr_handle_impl_t *, void *);
61 
62 static int
63 rootnex_map_fault(dev_info_t *dip, dev_info_t *rdip,
64     struct hat *hat, struct seg *seg, caddr_t addr,
65     struct devpage *dp, pfn_t pfn, uint_t prot, uint_t lock);
66 
67 static int
68 rootnex_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *);
69 
70 static int
71 rootnex_busop_fminit(dev_info_t *dip, dev_info_t *tdip, int tcap,
72     ddi_iblock_cookie_t *ibc);
73 
74 static void
75 rootnex_fm_init(dev_info_t *);
76 
77 static int
78 rootnex_ctlops_peekpoke(ddi_ctl_enum_t, peekpoke_ctlops_t *, void *result);
79 
80 /*
81  * Defined in $KARCH/io/mach_rootnex.c
82  */
83 int rootnex_add_intr_impl(dev_info_t *dip, dev_info_t *rdip,
84     ddi_intr_handle_impl_t *hdlp);
85 #pragma weak rootnex_add_intr_impl
86 
87 int rootnex_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip,
88     ddi_intr_handle_impl_t *hdlp);
89 #pragma weak rootnex_remove_intr_impl
90 
91 int rootnex_get_intr_pri(dev_info_t *dip, dev_info_t *rdip,
92     ddi_intr_handle_impl_t *hdlp);
93 #pragma weak rootnex_get_intr_pri
94 
95 int rootnex_name_child_impl(dev_info_t *child, char *name, int namelen);
96 #pragma weak rootnex_name_child_impl
97 
98 int rootnex_ctl_initchild_impl(dev_info_t *dip);
99 #pragma weak rootnex_initchild_impl
100 
101 void rootnex_ctl_uninitchild_impl(dev_info_t *dip);
102 #pragma weak rootnex_uninitchild_impl
103 
104 int rootnex_ctl_reportdev_impl(dev_info_t *dev);
105 #pragma weak rootnex_reportdev_impl
106 
107 static struct cb_ops rootnex_cb_ops = {
108 	nodev,		/* open */
109 	nodev,		/* close */
110 	nodev,		/* strategy */
111 	nodev,		/* print */
112 	nodev,		/* dump */
113 	nodev,		/* read */
114 	nodev,		/* write */
115 	nodev,		/* ioctl */
116 	nodev,		/* devmap */
117 	nodev,		/* mmap */
118 	nodev,		/* segmap */
119 	nochpoll,	/* chpoll */
120 	ddi_prop_op,	/* cb_prop_op */
121 	NULL,		/* struct streamtab */
122 	D_NEW | D_MP | D_HOTPLUG,	/* compatibility flags */
123 	CB_REV,		/* Rev */
124 	nodev,		/* cb_aread */
125 	nodev		/* cb_awrite */
126 };
127 
128 static struct bus_ops rootnex_bus_ops = {
129 	BUSO_REV,
130 	rootnex_map,
131 	NULL,
132 	NULL,
133 	NULL,
134 	rootnex_map_fault,
135 	ddi_no_dma_map,		/* no rootnex_dma_map- now in sysio nexus */
136 	ddi_no_dma_allochdl,
137 	ddi_no_dma_freehdl,
138 	ddi_no_dma_bindhdl,
139 	ddi_no_dma_unbindhdl,
140 	ddi_no_dma_flush,
141 	ddi_no_dma_win,
142 	ddi_no_dma_mctl,	/* no rootnex_dma_mctl- now in sysio nexus */
143 	rootnex_ctlops,
144 	ddi_bus_prop_op,
145 	i_ddi_rootnex_get_eventcookie,
146 	i_ddi_rootnex_add_eventcall,
147 	i_ddi_rootnex_remove_eventcall,
148 	i_ddi_rootnex_post_event,
149 	NULL,			/* bus_intr_ctl */
150 	NULL,			/* bus_config */
151 	NULL,			/* bus_unconfig */
152 	rootnex_busop_fminit,	/* bus_fm_init */
153 	NULL,			/* bus_fm_fini */
154 	NULL,			/* bus_fm_access_enter */
155 	NULL,			/* bus_fm_access_fini */
156 	NULL,			/* bus_power */
157 	rootnex_intr_ops	/* bus_intr_op */
158 };
159 
160 static int rootnex_attach(dev_info_t *devi, ddi_attach_cmd_t cmd);
161 static int rootnex_detach(dev_info_t *devi, ddi_detach_cmd_t cmd);
162 
163 static struct dev_ops rootnex_ops = {
164 	DEVO_REV,
165 	0,		/* refcnt */
166 	ddi_no_info,	/* info */
167 	nulldev,
168 	nulldev,	/* probe */
169 	rootnex_attach,
170 	rootnex_detach,
171 	nodev,		/* reset */
172 	&rootnex_cb_ops,
173 	&rootnex_bus_ops
174 };
175 
176 
177 extern uint_t	root_phys_addr_lo_mask;
178 extern uint_t	root_phys_addr_hi_mask;
179 extern struct mod_ops mod_driverops;
180 extern struct dev_ops rootnex_ops;
181 extern struct cpu cpu0;
182 extern ddi_iblock_cookie_t rootnex_err_ibc;
183 
184 
185 /*
186  * Add statically defined root properties to this list...
187  */
188 static const int pagesize = PAGESIZE;
189 static const int mmu_pagesize = MMU_PAGESIZE;
190 static const int mmu_pageoffset = MMU_PAGEOFFSET;
191 
192 struct prop_def {
193 	char *prop_name;
194 	caddr_t prop_value;
195 };
196 
197 static struct prop_def root_props[] = {
198 	{ "PAGESIZE",		(caddr_t)&pagesize },
199 	{ "MMU_PAGESIZE",	(caddr_t)&mmu_pagesize},
200 	{ "MMU_PAGEOFFSET",	(caddr_t)&mmu_pageoffset},
201 };
202 
203 static vmem_t	*rootnex_regspec_arena;
204 
205 #define	NROOT_PROPS	(sizeof (root_props) / sizeof (struct prop_def))
206 
207 
208 
209 /*
210  * Module linkage information for the kernel.
211  */
212 
213 static struct modldrv modldrv = {
214 	&mod_driverops,	/* Type of module.  This one is a nexus driver */
215 	"sun4 root nexus %I%",
216 	&rootnex_ops,	/* Driver ops */
217 };
218 
219 static struct modlinkage modlinkage = {
220 	MODREV_1, (void *)&modldrv, NULL
221 };
222 
223 int
224 _init(void)
225 {
226 	return (mod_install(&modlinkage));
227 }
228 
229 int
230 _fini(void)
231 {
232 	return (EBUSY);
233 }
234 
235 int
236 _info(struct modinfo *modinfop)
237 {
238 	return (mod_info(&modlinkage, modinfop));
239 }
240 
241 /*
242  * rootnex_attach:
243  *
244  *	attach the root nexus.
245  */
246 static void add_root_props(dev_info_t *);
247 
248 /*ARGSUSED*/
249 static int
250 rootnex_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
251 {
252 	int length;
253 	char *valuep = NULL;
254 
255 	/*
256 	 * Only do these functions when the driver is acting as the
257 	 * root nexus, not when it is driving a memory controller.
258 	 */
259 	if (ddi_root_node() == devi) {
260 		rootnex_fm_init(devi);
261 		add_root_props(devi);
262 		i_ddi_rootnex_init_events(devi);
263 		rootnex_regspec_arena = vmem_create("regspec",
264 		    (void *)PIOMAPBASE, PIOMAPSIZE, MMU_PAGESIZE, NULL, NULL,
265 		    NULL, 0, VM_SLEEP);
266 	}
267 
268 	if (ddi_prop_op(DDI_DEV_T_ANY, devi, PROP_LEN_AND_VAL_ALLOC,
269 	    DDI_PROP_DONTPASS, "banner-name", (caddr_t)&valuep,
270 	    &length) == DDI_PROP_SUCCESS) {
271 		cmn_err(CE_CONT, "?root nexus = %s\n", valuep);
272 		kmem_free(valuep, length);
273 	}
274 	/*
275 	 * Add a no-suspend-resume property so that NDI
276 	 * does not attempt to suspend/resume the rootnex
277 	 * (or any of its aliases) node.
278 	 */
279 	(void) ddi_prop_update_string(DDI_DEV_T_NONE, devi,
280 	    "pm-hardware-state", "no-suspend-resume");
281 
282 	return (DDI_SUCCESS);
283 }
284 
285 /*ARGSUSED*/
286 static int
287 rootnex_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
288 {
289 	return (DDI_SUCCESS);
290 }
291 
292 static void
293 add_root_props(dev_info_t *devi)
294 {
295 	int i;
296 	struct prop_def *rpp;
297 
298 	/*
299 	 * Note that this for loop works because all of the
300 	 * properties in root_prop are integers
301 	 */
302 	for (i = 0, rpp = root_props; i < NROOT_PROPS; ++i, ++rpp) {
303 		(void) e_ddi_prop_update_int(DDI_DEV_T_NONE, devi,
304 		    rpp->prop_name, *((int *)rpp->prop_value));
305 	}
306 
307 	/*
308 	 * Create the root node "boolean" property
309 	 * corresponding to addressing type supported in the root node:
310 	 *
311 	 * Choices are:
312 	 *	"relative-addressing" (OBP PROMS)
313 	 *	"generic-addressing"  (SunMon -- pseudo OBP/DDI)
314 	 */
315 
316 	(void) e_ddi_prop_update_int(DDI_DEV_T_NONE, devi,
317 	    DDI_RELATIVE_ADDRESSING, 1);
318 
319 	/*
320 	 * Create fault management capability property
321 	 */
322 	(void) e_ddi_prop_update_int(DDI_DEV_T_NONE, devi, "fm-capable",
323 	    ddi_fm_capable(devi));
324 }
325 
326 static int
327 rootnex_map_regspec(ddi_map_req_t *mp, caddr_t *vaddrp, uint_t mapping_attr)
328 {
329 	uint64_t base;
330 	caddr_t kaddr;
331 	pgcnt_t npages;
332 	pfn_t 	pfn;
333 	uint_t 	pgoffset;
334 	struct regspec *rp = mp->map_obj.rp;
335 	ddi_acc_hdl_t *hp;
336 
337 	base = (uint64_t)rp->regspec_addr & (~MMU_PAGEOFFSET); /* base addr */
338 
339 	/*
340 	 * Take the bustype and addr and convert it to a
341 	 * page frame number.
342 	 */
343 	pfn =  mmu_btop(((uint64_t)(rp->regspec_bustype &
344 	    root_phys_addr_hi_mask) << 32) | base);
345 
346 	/*
347 	 * Do a quick sanity check to make sure we are in I/O space.
348 	 */
349 	if (pf_is_memory(pfn))
350 		return (DDI_ME_INVAL);
351 
352 	if (rp->regspec_size == 0) {
353 		DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map_regspec: zero "
354 		    "regspec_size\n"));
355 		return (DDI_ME_INVAL);
356 	}
357 
358 	if (mp->map_flags & DDI_MF_DEVICE_MAPPING)
359 		*vaddrp = (caddr_t)pfn;
360 	else {
361 		pgoffset = (ulong_t)rp->regspec_addr & MMU_PAGEOFFSET;
362 		npages = mmu_btopr(rp->regspec_size + pgoffset);
363 
364 		DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map_regspec: Mapping "
365 		    "%lu pages physical %x.%lx ", npages, rp->regspec_bustype,
366 		    base));
367 
368 		if ((kaddr = vmem_alloc(rootnex_regspec_arena,
369 		    ptob(npages), VM_NOSLEEP)) == NULL)
370 			return (DDI_ME_NORESOURCES);
371 
372 		/*
373 		 * Now map in the pages we've allocated...
374 		 */
375 		hat_devload(kas.a_hat, kaddr, ptob(npages), pfn,
376 		    mp->map_prot | mapping_attr, HAT_LOAD_LOCK);
377 
378 		*vaddrp = kaddr + pgoffset;
379 
380 		hp = mp->map_handlep;
381 		if (hp) {
382 			hp->ah_pfn = pfn;
383 			hp->ah_pnum = npages;
384 		}
385 	}
386 
387 	DPRINTF(ROOTNEX_MAP_DEBUG, ("at virtual 0x%p\n", *vaddrp));
388 	return (0);
389 }
390 
391 static int
392 rootnex_unmap_regspec(ddi_map_req_t *mp, caddr_t *vaddrp)
393 {
394 	caddr_t addr = *vaddrp;
395 	pgcnt_t npages;
396 	uint_t  pgoffset;
397 	caddr_t base;
398 	struct regspec *rp;
399 
400 	if (mp->map_flags & DDI_MF_DEVICE_MAPPING)
401 		return (0);
402 
403 	rp = mp->map_obj.rp;
404 	pgoffset = (uintptr_t)addr & MMU_PAGEOFFSET;
405 
406 	if (rp->regspec_size == 0) {
407 		DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_unmap_regspec: "
408 		    "zero regspec_size\n"));
409 		return (DDI_ME_INVAL);
410 	}
411 
412 	base = addr - pgoffset;
413 	npages = mmu_btopr(rp->regspec_size + pgoffset);
414 	hat_unload(kas.a_hat, base, ptob(npages), HAT_UNLOAD_UNLOCK);
415 	vmem_free(rootnex_regspec_arena, base, ptob(npages));
416 
417 	/*
418 	 * Destroy the pointer - the mapping has logically gone
419 	 */
420 	*vaddrp = (caddr_t)0;
421 
422 	return (0);
423 }
424 
425 static int
426 rootnex_map_handle(ddi_map_req_t *mp)
427 {
428 	ddi_acc_hdl_t *hp;
429 	uint_t hat_flags;
430 	register struct regspec *rp;
431 
432 	/*
433 	 * Set up the hat_flags for the mapping.
434 	 */
435 	hp = mp->map_handlep;
436 
437 	switch (hp->ah_acc.devacc_attr_endian_flags) {
438 	case DDI_NEVERSWAP_ACC:
439 		hat_flags = HAT_NEVERSWAP | HAT_STRICTORDER;
440 		break;
441 	case DDI_STRUCTURE_BE_ACC:
442 		hat_flags = HAT_STRUCTURE_BE;
443 		break;
444 	case DDI_STRUCTURE_LE_ACC:
445 		hat_flags = HAT_STRUCTURE_LE;
446 		break;
447 	default:
448 		return (DDI_REGS_ACC_CONFLICT);
449 	}
450 
451 	switch (hp->ah_acc.devacc_attr_dataorder) {
452 	case DDI_STRICTORDER_ACC:
453 		break;
454 	case DDI_UNORDERED_OK_ACC:
455 		hat_flags |= HAT_UNORDERED_OK;
456 		break;
457 	case DDI_MERGING_OK_ACC:
458 		hat_flags |= HAT_MERGING_OK;
459 		break;
460 	case DDI_LOADCACHING_OK_ACC:
461 		hat_flags |= HAT_LOADCACHING_OK;
462 		break;
463 	case DDI_STORECACHING_OK_ACC:
464 		hat_flags |= HAT_STORECACHING_OK;
465 		break;
466 	default:
467 		return (DDI_FAILURE);
468 	}
469 
470 	rp = mp->map_obj.rp;
471 	if (rp->regspec_size == 0)
472 		return (DDI_ME_INVAL);
473 
474 	hp->ah_hat_flags = hat_flags;
475 	hp->ah_pfn = mmu_btop((ulong_t)rp->regspec_addr & (~MMU_PAGEOFFSET));
476 	hp->ah_pnum = mmu_btopr(rp->regspec_size +
477 	    (ulong_t)rp->regspec_addr & MMU_PAGEOFFSET);
478 	return (DDI_SUCCESS);
479 }
480 
481 static int
482 rootnex_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
483     off_t offset, off_t len, caddr_t *vaddrp)
484 {
485 	struct regspec *rp, tmp_reg;
486 	ddi_map_req_t mr = *mp;		/* Get private copy of request */
487 	int error;
488 	uint_t mapping_attr;
489 	ddi_acc_hdl_t *hp = NULL;
490 
491 	mp = &mr;
492 
493 	switch (mp->map_op)  {
494 	case DDI_MO_MAP_LOCKED:
495 	case DDI_MO_UNMAP:
496 	case DDI_MO_MAP_HANDLE:
497 		break;
498 	default:
499 		DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: unimplemented map "
500 		    "op %d.", mp->map_op));
501 		return (DDI_ME_UNIMPLEMENTED);
502 	}
503 
504 	if (mp->map_flags & DDI_MF_USER_MAPPING)  {
505 		DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: unimplemented map "
506 		    "type: user."));
507 		return (DDI_ME_UNIMPLEMENTED);
508 	}
509 
510 	/*
511 	 * First, if given an rnumber, convert it to a regspec...
512 	 * (Presumably, this is on behalf of a child of the root node?)
513 	 */
514 
515 	if (mp->map_type == DDI_MT_RNUMBER)  {
516 
517 		int rnumber = mp->map_obj.rnumber;
518 
519 		rp = i_ddi_rnumber_to_regspec(rdip, rnumber);
520 		if (rp == (struct regspec *)0)  {
521 			DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: Out of "
522 			    "range rnumber <%d>, device <%s>", rnumber,
523 			    ddi_get_name(rdip)));
524 			return (DDI_ME_RNUMBER_RANGE);
525 		}
526 
527 		/*
528 		 * Convert the given ddi_map_req_t from rnumber to regspec...
529 		 */
530 
531 		mp->map_type = DDI_MT_REGSPEC;
532 		mp->map_obj.rp = rp;
533 	}
534 
535 	/*
536 	 * Adjust offset and length corresponding to called values...
537 	 * XXX: A non-zero length means override the one in the regspec
538 	 * XXX: regardless of what's in the parent's range?.
539 	 */
540 
541 	tmp_reg = *(mp->map_obj.rp);		/* Preserve underlying data */
542 	rp = mp->map_obj.rp = &tmp_reg;		/* Use tmp_reg in request */
543 
544 	rp->regspec_addr += (uint_t)offset;
545 	if (len != 0)
546 		rp->regspec_size = (uint_t)len;
547 
548 	/*
549 	 * Apply any parent ranges at this level, if applicable.
550 	 * (This is where nexus specific regspec translation takes place.
551 	 * Use of this function is implicit agreement that translation is
552 	 * provided via ddi_apply_range.)
553 	 */
554 
555 	DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: applying range of parent "
556 	    "<%s> to child <%s>...\n", ddi_get_name(dip), ddi_get_name(rdip)));
557 
558 	if ((error = i_ddi_apply_range(dip, rdip, mp->map_obj.rp)) != 0)
559 		return (error);
560 
561 	switch (mp->map_op)  {
562 	case DDI_MO_MAP_LOCKED:
563 
564 		/*
565 		 * Set up the locked down kernel mapping to the regspec...
566 		 */
567 
568 		/*
569 		 * If we were passed an access handle we need to determine
570 		 * the "endian-ness" of the mapping and fill in the handle.
571 		 */
572 		if (mp->map_handlep) {
573 			hp = mp->map_handlep;
574 			switch (hp->ah_acc.devacc_attr_endian_flags) {
575 			case DDI_NEVERSWAP_ACC:
576 				mapping_attr = HAT_NEVERSWAP | HAT_STRICTORDER;
577 				break;
578 			case DDI_STRUCTURE_BE_ACC:
579 				mapping_attr = HAT_STRUCTURE_BE;
580 				break;
581 			case DDI_STRUCTURE_LE_ACC:
582 				mapping_attr = HAT_STRUCTURE_LE;
583 				break;
584 			default:
585 				return (DDI_REGS_ACC_CONFLICT);
586 			}
587 
588 			switch (hp->ah_acc.devacc_attr_dataorder) {
589 			case DDI_STRICTORDER_ACC:
590 				break;
591 			case DDI_UNORDERED_OK_ACC:
592 				mapping_attr |= HAT_UNORDERED_OK;
593 				break;
594 			case DDI_MERGING_OK_ACC:
595 				mapping_attr |= HAT_MERGING_OK;
596 				break;
597 			case DDI_LOADCACHING_OK_ACC:
598 				mapping_attr |= HAT_LOADCACHING_OK;
599 				break;
600 			case DDI_STORECACHING_OK_ACC:
601 				mapping_attr |= HAT_STORECACHING_OK;
602 				break;
603 			default:
604 				return (DDI_REGS_ACC_CONFLICT);
605 			}
606 		} else {
607 			mapping_attr = HAT_NEVERSWAP | HAT_STRICTORDER;
608 		}
609 
610 		/*
611 		 * Set up the mapping.
612 		 */
613 		error = rootnex_map_regspec(mp, vaddrp, mapping_attr);
614 
615 		/*
616 		 * Fill in the access handle if needed.
617 		 */
618 		if (hp) {
619 			hp->ah_addr = *vaddrp;
620 			hp->ah_hat_flags = mapping_attr;
621 			if (error == 0)
622 				impl_acc_hdl_init(hp);
623 		}
624 		return (error);
625 
626 	case DDI_MO_UNMAP:
627 
628 		/*
629 		 * Release mapping...
630 		 */
631 
632 		return (rootnex_unmap_regspec(mp, vaddrp));
633 
634 	case DDI_MO_MAP_HANDLE:
635 		return (rootnex_map_handle(mp));
636 
637 	}
638 
639 	return (DDI_ME_UNIMPLEMENTED);
640 }
641 
642 static int
643 rootnex_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
644     ddi_intr_handle_impl_t *hdlp, void *result)
645 {
646 	int	ret = DDI_SUCCESS;
647 
648 	DPRINTF(ROOTNEX_INTR_DEBUG, ("rootnex_intr_ops: rdip=%s%d "
649 	    "intr_op 0x%x hdlp 0x%p\n", ddi_driver_name(rdip),
650 	    ddi_get_instance(rdip), intr_op, hdlp));
651 
652 	switch (intr_op) {
653 	case DDI_INTROP_GETCAP:
654 		*(int *)result = DDI_INTR_FLAG_LEVEL;
655 		break;
656 	case DDI_INTROP_SETCAP:
657 		ret = DDI_ENOTSUP;
658 		break;
659 	case DDI_INTROP_ALLOC:
660 		*(int *)result = hdlp->ih_scratch1;
661 		break;
662 	case DDI_INTROP_FREE:
663 		break;
664 	case DDI_INTROP_GETPRI:
665 		*(int *)result = rootnex_get_intr_pri(dip, rdip, hdlp);
666 		break;
667 	case DDI_INTROP_SETPRI:
668 		break;
669 	case DDI_INTROP_ADDISR:
670 		ret = rootnex_add_intr_impl(dip, rdip, hdlp);
671 		break;
672 	case DDI_INTROP_REMISR:
673 		ret = rootnex_remove_intr_impl(dip, rdip, hdlp);
674 		break;
675 	case DDI_INTROP_ENABLE:
676 	case DDI_INTROP_DISABLE:
677 		break;
678 	case DDI_INTROP_NINTRS:
679 	case DDI_INTROP_NAVAIL:
680 		*(int *)result = i_ddi_get_intx_nintrs(rdip);
681 		break;
682 	case DDI_INTROP_SUPPORTED_TYPES:
683 		/* Root nexus driver supports only fixed interrupts */
684 		*(int *)result = i_ddi_get_intx_nintrs(rdip) ?
685 		    DDI_INTR_TYPE_FIXED : 0;
686 		break;
687 	default:
688 		ret = DDI_ENOTSUP;
689 		break;
690 	}
691 
692 	return (ret);
693 }
694 
695 
696 /*
697  * Shorthand defines
698  */
699 
700 #define	DMAOBJ_PP_PP	dmao_obj.pp_obj.pp_pp
701 #define	DMAOBJ_PP_OFF	dmao_ogj.pp_obj.pp_offset
702 #define	ALO		dma_lim->dlim_addr_lo
703 #define	AHI		dma_lim->dlim_addr_hi
704 #define	OBJSIZE		dmareq->dmar_object.dmao_size
705 #define	ORIGVADDR	dmareq->dmar_object.dmao_obj.virt_obj.v_addr
706 #define	RED		((mp->dmai_rflags & DDI_DMA_REDZONE)? 1 : 0)
707 #define	DIRECTION	(mp->dmai_rflags & DDI_DMA_RDWR)
708 
709 /*
710  * rootnex_map_fault:
711  *
712  *	fault in mappings for requestors
713  */
714 
715 /*ARGSUSED*/
716 static int
717 rootnex_map_fault(dev_info_t *dip, dev_info_t *rdip,
718     struct hat *hat, struct seg *seg, caddr_t addr,
719     struct devpage *dp, pfn_t pfn, uint_t prot, uint_t lock)
720 {
721 	extern struct seg_ops segdev_ops;
722 
723 	DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map_fault: address <%p> "
724 	    "pfn <%lx>", addr, pfn));
725 	DPRINTF(ROOTNEX_MAP_DEBUG, (" Seg <%s>\n",
726 	    seg->s_ops == &segdev_ops ? "segdev" :
727 	    seg == &kvseg ? "segkmem" : "NONE!"));
728 
729 	/*
730 	 * This is all terribly broken, but it is a start
731 	 *
732 	 * XXX	Note that this test means that segdev_ops
733 	 *	must be exported from seg_dev.c.
734 	 * XXX	What about devices with their own segment drivers?
735 	 */
736 	if (seg->s_ops == &segdev_ops) {
737 		register struct segdev_data *sdp =
738 		    (struct segdev_data *)seg->s_data;
739 
740 		if (hat == NULL) {
741 			/*
742 			 * This is one plausible interpretation of
743 			 * a null hat i.e. use the first hat on the
744 			 * address space hat list which by convention is
745 			 * the hat of the system MMU.  At alternative
746 			 * would be to panic .. this might well be better ..
747 			 */
748 			ASSERT(AS_READ_HELD(seg->s_as, &seg->s_as->a_lock));
749 			hat = seg->s_as->a_hat;
750 			cmn_err(CE_NOTE, "rootnex_map_fault: nil hat");
751 		}
752 		hat_devload(hat, addr, MMU_PAGESIZE, pfn, prot | sdp->hat_attr,
753 		    (lock ? HAT_LOAD_LOCK : HAT_LOAD));
754 	} else if (seg == &kvseg && dp == (struct devpage *)0) {
755 		hat_devload(kas.a_hat, addr, MMU_PAGESIZE, pfn, prot,
756 		    HAT_LOAD_LOCK);
757 	} else
758 		return (DDI_FAILURE);
759 	return (DDI_SUCCESS);
760 }
761 
762 /*
763  * Name a child of rootnex
764  *
765  * This may be called multiple times, independent of initchild calls.
766  */
767 int
768 rootnex_name_child(dev_info_t *child, char *name, int namelen)
769 {
770 	return (rootnex_name_child_impl(child, name, namelen));
771 }
772 
773 
774 static int
775 rootnex_ctl_initchild(dev_info_t *dip)
776 {
777 	return (rootnex_ctl_initchild_impl(dip));
778 }
779 
780 
781 int
782 rootnex_ctl_uninitchild(dev_info_t *dip)
783 {
784 	extern void impl_free_ddi_ppd(dev_info_t *);
785 
786 	rootnex_ctl_uninitchild_impl(dip);
787 
788 	/*
789 	 * strip properties and convert node to prototype form
790 	 */
791 	impl_free_ddi_ppd(dip);
792 	ddi_set_name_addr(dip, NULL);
793 	impl_rem_dev_props(dip);
794 	return (DDI_SUCCESS);
795 }
796 
797 
798 static int
799 rootnex_ctl_reportdev(dev_info_t *dev)
800 {
801 	return (rootnex_ctl_reportdev_impl(dev));
802 }
803 
804 
805 static int
806 rootnex_ctlops_peekpoke(ddi_ctl_enum_t cmd, peekpoke_ctlops_t *in_args,
807     void *result)
808 {
809 	int err = DDI_SUCCESS;
810 	on_trap_data_t otd;
811 
812 	/* No safe access except for peek/poke is supported. */
813 	if (in_args->handle != NULL)
814 		return (DDI_FAILURE);
815 
816 	/* Set up protected environment. */
817 	if (!on_trap(&otd, OT_DATA_ACCESS)) {
818 		uintptr_t tramp = otd.ot_trampoline;
819 
820 		if (cmd == DDI_CTLOPS_POKE) {
821 			otd.ot_trampoline = (uintptr_t)&poke_fault;
822 			err = do_poke(in_args->size, (void *)in_args->dev_addr,
823 			    (void *)in_args->host_addr);
824 		} else {
825 			otd.ot_trampoline = (uintptr_t)&peek_fault;
826 			err = do_peek(in_args->size, (void *)in_args->dev_addr,
827 			    (void *)in_args->host_addr);
828 			result = (void *)in_args->host_addr;
829 		}
830 		otd.ot_trampoline = tramp;
831 	} else
832 		err = DDI_FAILURE;
833 
834 	/* Take down protected environment. */
835 	no_trap();
836 
837 	return (err);
838 }
839 
840 /*ARGSUSED*/
841 static int
842 rootnex_ctlops(dev_info_t *dip, dev_info_t *rdip,
843     ddi_ctl_enum_t ctlop, void *arg, void *result)
844 {
845 	register int n, *ptr;
846 	register struct ddi_parent_private_data *pdp;
847 
848 	static boolean_t reserved_msg_printed = B_FALSE;
849 
850 	switch (ctlop) {
851 	case DDI_CTLOPS_DMAPMAPC:
852 		return (DDI_FAILURE);
853 
854 	case DDI_CTLOPS_BTOP:
855 		/*
856 		 * Convert byte count input to physical page units.
857 		 * (byte counts that are not a page-size multiple
858 		 * are rounded down)
859 		 */
860 		*(ulong_t *)result = btop(*(ulong_t *)arg);
861 		return (DDI_SUCCESS);
862 
863 	case DDI_CTLOPS_PTOB:
864 		/*
865 		 * Convert size in physical pages to bytes
866 		 */
867 		*(ulong_t *)result = ptob(*(ulong_t *)arg);
868 		return (DDI_SUCCESS);
869 
870 	case DDI_CTLOPS_BTOPR:
871 		/*
872 		 * Convert byte count input to physical page units
873 		 * (byte counts that are not a page-size multiple
874 		 * are rounded up)
875 		 */
876 		*(ulong_t *)result = btopr(*(ulong_t *)arg);
877 		return (DDI_SUCCESS);
878 
879 	case DDI_CTLOPS_INITCHILD:
880 		return (rootnex_ctl_initchild((dev_info_t *)arg));
881 
882 	case DDI_CTLOPS_UNINITCHILD:
883 		return (rootnex_ctl_uninitchild((dev_info_t *)arg));
884 
885 	case DDI_CTLOPS_REPORTDEV:
886 		return (rootnex_ctl_reportdev(rdip));
887 
888 	case DDI_CTLOPS_IOMIN:
889 		/*
890 		 * Nothing to do here but reflect back..
891 		 */
892 		return (DDI_SUCCESS);
893 
894 	case DDI_CTLOPS_REGSIZE:
895 	case DDI_CTLOPS_NREGS:
896 		break;
897 
898 	case DDI_CTLOPS_SIDDEV:
899 		if (ndi_dev_is_prom_node(rdip))
900 			return (DDI_SUCCESS);
901 		if (ndi_dev_is_persistent_node(rdip))
902 			return (DDI_SUCCESS);
903 		return (DDI_FAILURE);
904 
905 	case DDI_CTLOPS_POWER: {
906 		return ((*pm_platform_power)((power_req_t *)arg));
907 	}
908 
909 	case DDI_CTLOPS_RESERVED0: /* Was DDI_CTLOPS_NINTRS, obsolete */
910 	case DDI_CTLOPS_RESERVED1: /* Was DDI_CTLOPS_POKE_INIT, obsolete */
911 	case DDI_CTLOPS_RESERVED2: /* Was DDI_CTLOPS_POKE_FLUSH, obsolete */
912 	case DDI_CTLOPS_RESERVED3: /* Was DDI_CTLOPS_POKE_FINI, obsolete */
913 	case DDI_CTLOPS_RESERVED4: /* Was DDI_CTLOPS_INTR_HILEVEL, obsolete */
914 	case DDI_CTLOPS_RESERVED5: /* Was DDI_CTLOPS_XLATE_INTRS, obsolete */
915 		if (!reserved_msg_printed) {
916 			reserved_msg_printed = B_TRUE;
917 			cmn_err(CE_WARN, "Failing ddi_ctlops call(s) for "
918 			    "1 or more reserved/obsolete operations.");
919 		}
920 		return (DDI_FAILURE);
921 
922 	case DDI_CTLOPS_POKE:
923 	case DDI_CTLOPS_PEEK:
924 		return (rootnex_ctlops_peekpoke(ctlop, (peekpoke_ctlops_t *)arg,
925 		    result));
926 
927 	default:
928 		return (DDI_FAILURE);
929 	}
930 
931 	/*
932 	 * The rest are for "hardware" properties
933 	 */
934 	if ((pdp = ddi_get_parent_data(rdip)) == NULL)
935 		return (DDI_FAILURE);
936 
937 	if (ctlop == DDI_CTLOPS_NREGS) {
938 		ptr = (int *)result;
939 		*ptr = pdp->par_nreg;
940 	} else {	/* ctlop == DDI_CTLOPS_REGSIZE */
941 		off_t *size = (off_t *)result;
942 
943 		ptr = (int *)arg;
944 		n = *ptr;
945 		if (n >= pdp->par_nreg) {
946 			return (DDI_FAILURE);
947 		}
948 		*size = (off_t)pdp->par_reg[n].regspec_size;
949 	}
950 	return (DDI_SUCCESS);
951 }
952 
953 /* ARGSUSED */
954 int
955 rootnex_busop_fminit(dev_info_t *dip, dev_info_t *tdip, int cap,
956     ddi_iblock_cookie_t *ibc)
957 {
958 	*ibc = rootnex_err_ibc;
959 	return (ddi_system_fmcap | DDI_FM_ACCCHK_CAPABLE |
960 	    DDI_FM_DMACHK_CAPABLE);
961 }
962 
963 static void
964 rootnex_fm_init(dev_info_t *dip)
965 {
966 	int fmcap;
967 
968 	/* Minimum fm capability level for sun4u platforms */
969 	ddi_system_fmcap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE;
970 
971 	fmcap = ddi_system_fmcap;
972 
973 	/*
974 	 * Initialize ECC error handling
975 	 */
976 	rootnex_err_ibc = (ddi_iblock_cookie_t)PIL_15;
977 	ddi_fm_init(dip, &fmcap, &rootnex_err_ibc);
978 }
979