xref: /titanic_44/usr/src/uts/sun4/io/rootnex.c (revision 587032cf0967234b39ccb50adca936a367841063)
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 2005 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 	ulong_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 = (ulong_t)rp->regspec_addr & (~MMU_PAGEOFFSET); /* base addr */
338 
339 	/*
340 	 * Take the bustype and the physical page base within the
341 	 * bus space and turn it into a 28 bit page frame number.
342 	 */
343 
344 	pfn = BUSTYPE_TO_PFN(((rp->regspec_bustype) & root_phys_addr_hi_mask),
345 	    mmu_btop(base));
346 
347 
348 	/*
349 	 * Do a quick sanity check to make sure we are in I/O space.
350 	 */
351 	if (pf_is_memory(pfn))
352 		return (DDI_ME_INVAL);
353 
354 	if (rp->regspec_size == 0) {
355 		DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map_regspec: zero "
356 		    "regspec_size\n"));
357 		return (DDI_ME_INVAL);
358 	}
359 
360 	if (mp->map_flags & DDI_MF_DEVICE_MAPPING)
361 		*vaddrp = (caddr_t)pfn;
362 	else {
363 		pgoffset = (ulong_t)rp->regspec_addr & MMU_PAGEOFFSET;
364 		npages = mmu_btopr(rp->regspec_size + pgoffset);
365 
366 		DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map_regspec: Mapping "
367 		    "%lu pages physical %x.%lx ", npages, rp->regspec_bustype,
368 		    base));
369 
370 		if ((kaddr = vmem_alloc(rootnex_regspec_arena,
371 		    ptob(npages), VM_NOSLEEP)) == NULL)
372 			return (DDI_ME_NORESOURCES);
373 
374 		/*
375 		 * Now map in the pages we've allocated...
376 		 */
377 		hat_devload(kas.a_hat, kaddr, ptob(npages), pfn,
378 		    mp->map_prot | mapping_attr, HAT_LOAD_LOCK);
379 
380 		*vaddrp = kaddr + pgoffset;
381 
382 		hp = mp->map_handlep;
383 		if (hp) {
384 			hp->ah_pfn = pfn;
385 			hp->ah_pnum = npages;
386 		}
387 	}
388 
389 	DPRINTF(ROOTNEX_MAP_DEBUG, ("at virtual 0x%p\n", *vaddrp));
390 	return (0);
391 }
392 
393 static int
394 rootnex_unmap_regspec(ddi_map_req_t *mp, caddr_t *vaddrp)
395 {
396 	caddr_t addr = *vaddrp;
397 	pgcnt_t npages;
398 	uint_t  pgoffset;
399 	caddr_t base;
400 	struct regspec *rp;
401 
402 	if (mp->map_flags & DDI_MF_DEVICE_MAPPING)
403 		return (0);
404 
405 	rp = mp->map_obj.rp;
406 	pgoffset = (uintptr_t)addr & MMU_PAGEOFFSET;
407 
408 	if (rp->regspec_size == 0) {
409 		DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_unmap_regspec: "
410 		    "zero regspec_size\n"));
411 		return (DDI_ME_INVAL);
412 	}
413 
414 	base = addr - pgoffset;
415 	npages = mmu_btopr(rp->regspec_size + pgoffset);
416 	hat_unload(kas.a_hat, base, ptob(npages), HAT_UNLOAD_UNLOCK);
417 	vmem_free(rootnex_regspec_arena, base, ptob(npages));
418 
419 	/*
420 	 * Destroy the pointer - the mapping has logically gone
421 	 */
422 	*vaddrp = (caddr_t)0;
423 
424 	return (0);
425 }
426 
427 static int
428 rootnex_map_handle(ddi_map_req_t *mp)
429 {
430 	ddi_acc_hdl_t *hp;
431 	uint_t hat_flags;
432 	register struct regspec *rp;
433 
434 	/*
435 	 * Set up the hat_flags for the mapping.
436 	 */
437 	hp = mp->map_handlep;
438 
439 	switch (hp->ah_acc.devacc_attr_endian_flags) {
440 	case DDI_NEVERSWAP_ACC:
441 		hat_flags = HAT_NEVERSWAP | HAT_STRICTORDER;
442 		break;
443 	case DDI_STRUCTURE_BE_ACC:
444 		hat_flags = HAT_STRUCTURE_BE;
445 		break;
446 	case DDI_STRUCTURE_LE_ACC:
447 		hat_flags = HAT_STRUCTURE_LE;
448 		break;
449 	default:
450 		return (DDI_REGS_ACC_CONFLICT);
451 	}
452 
453 	switch (hp->ah_acc.devacc_attr_dataorder) {
454 	case DDI_STRICTORDER_ACC:
455 		break;
456 	case DDI_UNORDERED_OK_ACC:
457 		hat_flags |= HAT_UNORDERED_OK;
458 		break;
459 	case DDI_MERGING_OK_ACC:
460 		hat_flags |= HAT_MERGING_OK;
461 		break;
462 	case DDI_LOADCACHING_OK_ACC:
463 		hat_flags |= HAT_LOADCACHING_OK;
464 		break;
465 	case DDI_STORECACHING_OK_ACC:
466 		hat_flags |= HAT_STORECACHING_OK;
467 		break;
468 	default:
469 		return (DDI_FAILURE);
470 	}
471 
472 	rp = mp->map_obj.rp;
473 	if (rp->regspec_size == 0)
474 		return (DDI_ME_INVAL);
475 
476 	hp->ah_hat_flags = hat_flags;
477 	hp->ah_pfn = mmu_btop((ulong_t)rp->regspec_addr & (~MMU_PAGEOFFSET));
478 	hp->ah_pnum = mmu_btopr(rp->regspec_size +
479 	    (ulong_t)rp->regspec_addr & MMU_PAGEOFFSET);
480 	return (DDI_SUCCESS);
481 }
482 
483 static int
484 rootnex_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
485     off_t offset, off_t len, caddr_t *vaddrp)
486 {
487 	struct regspec *rp, tmp_reg;
488 	ddi_map_req_t mr = *mp;		/* Get private copy of request */
489 	int error;
490 	uint_t mapping_attr;
491 	ddi_acc_hdl_t *hp = NULL;
492 
493 	mp = &mr;
494 
495 	switch (mp->map_op)  {
496 	case DDI_MO_MAP_LOCKED:
497 	case DDI_MO_UNMAP:
498 	case DDI_MO_MAP_HANDLE:
499 		break;
500 	default:
501 		DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: unimplemented map "
502 		    "op %d.", mp->map_op));
503 		return (DDI_ME_UNIMPLEMENTED);
504 	}
505 
506 	if (mp->map_flags & DDI_MF_USER_MAPPING)  {
507 		DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: unimplemented map "
508 		    "type: user."));
509 		return (DDI_ME_UNIMPLEMENTED);
510 	}
511 
512 	/*
513 	 * First, if given an rnumber, convert it to a regspec...
514 	 * (Presumably, this is on behalf of a child of the root node?)
515 	 */
516 
517 	if (mp->map_type == DDI_MT_RNUMBER)  {
518 
519 		int rnumber = mp->map_obj.rnumber;
520 
521 		rp = i_ddi_rnumber_to_regspec(rdip, rnumber);
522 		if (rp == (struct regspec *)0)  {
523 			DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: Out of "
524 			    "range rnumber <%d>, device <%s>", rnumber,
525 			    ddi_get_name(rdip)));
526 			return (DDI_ME_RNUMBER_RANGE);
527 		}
528 
529 		/*
530 		 * Convert the given ddi_map_req_t from rnumber to regspec...
531 		 */
532 
533 		mp->map_type = DDI_MT_REGSPEC;
534 		mp->map_obj.rp = rp;
535 	}
536 
537 	/*
538 	 * Adjust offset and length corresponding to called values...
539 	 * XXX: A non-zero length means override the one in the regspec
540 	 * XXX: regardless of what's in the parent's range?.
541 	 */
542 
543 	tmp_reg = *(mp->map_obj.rp);		/* Preserve underlying data */
544 	rp = mp->map_obj.rp = &tmp_reg;		/* Use tmp_reg in request */
545 
546 	rp->regspec_addr += (uint_t)offset;
547 	if (len != 0)
548 		rp->regspec_size = (uint_t)len;
549 
550 	/*
551 	 * Apply any parent ranges at this level, if applicable.
552 	 * (This is where nexus specific regspec translation takes place.
553 	 * Use of this function is implicit agreement that translation is
554 	 * provided via ddi_apply_range.)
555 	 */
556 
557 	DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: applying range of parent "
558 	    "<%s> to child <%s>...\n", ddi_get_name(dip), ddi_get_name(rdip)));
559 
560 	if ((error = i_ddi_apply_range(dip, rdip, mp->map_obj.rp)) != 0)
561 		return (error);
562 
563 	switch (mp->map_op)  {
564 	case DDI_MO_MAP_LOCKED:
565 
566 		/*
567 		 * Set up the locked down kernel mapping to the regspec...
568 		 */
569 
570 		/*
571 		 * If we were passed an access handle we need to determine
572 		 * the "endian-ness" of the mapping and fill in the handle.
573 		 */
574 		if (mp->map_handlep) {
575 			hp = mp->map_handlep;
576 			switch (hp->ah_acc.devacc_attr_endian_flags) {
577 			case DDI_NEVERSWAP_ACC:
578 				mapping_attr = HAT_NEVERSWAP | HAT_STRICTORDER;
579 				break;
580 			case DDI_STRUCTURE_BE_ACC:
581 				mapping_attr = HAT_STRUCTURE_BE;
582 				break;
583 			case DDI_STRUCTURE_LE_ACC:
584 				mapping_attr = HAT_STRUCTURE_LE;
585 				break;
586 			default:
587 				return (DDI_REGS_ACC_CONFLICT);
588 			}
589 
590 			switch (hp->ah_acc.devacc_attr_dataorder) {
591 			case DDI_STRICTORDER_ACC:
592 				break;
593 			case DDI_UNORDERED_OK_ACC:
594 				mapping_attr |= HAT_UNORDERED_OK;
595 				break;
596 			case DDI_MERGING_OK_ACC:
597 				mapping_attr |= HAT_MERGING_OK;
598 				break;
599 			case DDI_LOADCACHING_OK_ACC:
600 				mapping_attr |= HAT_LOADCACHING_OK;
601 				break;
602 			case DDI_STORECACHING_OK_ACC:
603 				mapping_attr |= HAT_STORECACHING_OK;
604 				break;
605 			default:
606 				return (DDI_REGS_ACC_CONFLICT);
607 			}
608 		} else {
609 			mapping_attr = HAT_NEVERSWAP | HAT_STRICTORDER;
610 		}
611 
612 		/*
613 		 * Set up the mapping.
614 		 */
615 		error = rootnex_map_regspec(mp, vaddrp, mapping_attr);
616 
617 		/*
618 		 * Fill in the access handle if needed.
619 		 */
620 		if (hp) {
621 			hp->ah_addr = *vaddrp;
622 			hp->ah_hat_flags = mapping_attr;
623 			if (error == 0)
624 				impl_acc_hdl_init(hp);
625 		}
626 		return (error);
627 
628 	case DDI_MO_UNMAP:
629 
630 		/*
631 		 * Release mapping...
632 		 */
633 
634 		return (rootnex_unmap_regspec(mp, vaddrp));
635 
636 	case DDI_MO_MAP_HANDLE:
637 		return (rootnex_map_handle(mp));
638 
639 	}
640 
641 	return (DDI_ME_UNIMPLEMENTED);
642 }
643 
644 static int
645 rootnex_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
646     ddi_intr_handle_impl_t *hdlp, void *result)
647 {
648 	int	ret = DDI_SUCCESS;
649 
650 	DPRINTF(ROOTNEX_INTR_DEBUG, ("rootnex_intr_ops: rdip=%s%d "
651 	    "intr_op 0x%x hdlp 0x%p\n", ddi_driver_name(rdip),
652 	    ddi_get_instance(rdip), intr_op, hdlp));
653 
654 	switch (intr_op) {
655 	case DDI_INTROP_GETCAP:
656 		*(int *)result = DDI_INTR_FLAG_LEVEL;
657 		break;
658 	case DDI_INTROP_SETCAP:
659 		ret = DDI_ENOTSUP;
660 		break;
661 	case DDI_INTROP_ALLOC:
662 		*(int *)result = hdlp->ih_scratch1;
663 		break;
664 	case DDI_INTROP_FREE:
665 		break;
666 	case DDI_INTROP_GETPRI:
667 		*(int *)result = rootnex_get_intr_pri(dip, rdip, hdlp);
668 		break;
669 	case DDI_INTROP_SETPRI:
670 		break;
671 	case DDI_INTROP_ADDISR:
672 		ret = rootnex_add_intr_impl(dip, rdip, hdlp);
673 		break;
674 	case DDI_INTROP_REMISR:
675 		ret = rootnex_remove_intr_impl(dip, rdip, hdlp);
676 		break;
677 	case DDI_INTROP_ENABLE:
678 	case DDI_INTROP_DISABLE:
679 		break;
680 	case DDI_INTROP_NINTRS:
681 	case DDI_INTROP_NAVAIL:
682 		*(int *)result = i_ddi_get_nintrs(rdip);
683 		break;
684 	case DDI_INTROP_SUPPORTED_TYPES:
685 		/* Root nexus driver supports only fixed interrupts */
686 		*(int *)result = i_ddi_get_nintrs(rdip) ?
687 		    DDI_INTR_TYPE_FIXED : 0;
688 		break;
689 	default:
690 		ret = DDI_ENOTSUP;
691 		break;
692 	}
693 
694 	return (ret);
695 }
696 
697 
698 /*
699  * Shorthand defines
700  */
701 
702 #define	DMAOBJ_PP_PP	dmao_obj.pp_obj.pp_pp
703 #define	DMAOBJ_PP_OFF	dmao_ogj.pp_obj.pp_offset
704 #define	ALO		dma_lim->dlim_addr_lo
705 #define	AHI		dma_lim->dlim_addr_hi
706 #define	OBJSIZE		dmareq->dmar_object.dmao_size
707 #define	ORIGVADDR	dmareq->dmar_object.dmao_obj.virt_obj.v_addr
708 #define	RED		((mp->dmai_rflags & DDI_DMA_REDZONE)? 1 : 0)
709 #define	DIRECTION	(mp->dmai_rflags & DDI_DMA_RDWR)
710 
711 /*
712  * rootnex_map_fault:
713  *
714  *	fault in mappings for requestors
715  */
716 
717 /*ARGSUSED*/
718 static int
719 rootnex_map_fault(dev_info_t *dip, dev_info_t *rdip,
720     struct hat *hat, struct seg *seg, caddr_t addr,
721     struct devpage *dp, pfn_t pfn, uint_t prot, uint_t lock)
722 {
723 	extern struct seg_ops segdev_ops;
724 
725 	DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map_fault: address <%p> "
726 	    "pfn <%lx>", addr, pfn));
727 	DPRINTF(ROOTNEX_MAP_DEBUG, (" Seg <%s>\n",
728 	    seg->s_ops == &segdev_ops ? "segdev" :
729 	    seg == &kvseg ? "segkmem" : "NONE!"));
730 
731 	/*
732 	 * This is all terribly broken, but it is a start
733 	 *
734 	 * XXX	Note that this test means that segdev_ops
735 	 *	must be exported from seg_dev.c.
736 	 * XXX	What about devices with their own segment drivers?
737 	 */
738 	if (seg->s_ops == &segdev_ops) {
739 		register struct segdev_data *sdp =
740 		    (struct segdev_data *)seg->s_data;
741 
742 		if (hat == NULL) {
743 			/*
744 			 * This is one plausible interpretation of
745 			 * a null hat i.e. use the first hat on the
746 			 * address space hat list which by convention is
747 			 * the hat of the system MMU.  At alternative
748 			 * would be to panic .. this might well be better ..
749 			 */
750 			ASSERT(AS_READ_HELD(seg->s_as, &seg->s_as->a_lock));
751 			hat = seg->s_as->a_hat;
752 			cmn_err(CE_NOTE, "rootnex_map_fault: nil hat");
753 		}
754 		hat_devload(hat, addr, MMU_PAGESIZE, pfn, prot | sdp->hat_attr,
755 		    (lock ? HAT_LOAD_LOCK : HAT_LOAD));
756 	} else if (seg == &kvseg && dp == (struct devpage *)0) {
757 		hat_devload(kas.a_hat, addr, MMU_PAGESIZE, pfn, prot,
758 		    HAT_LOAD_LOCK);
759 	} else
760 		return (DDI_FAILURE);
761 	return (DDI_SUCCESS);
762 }
763 
764 /*
765  * Name a child of rootnex
766  *
767  * This may be called multiple times, independent of initchild calls.
768  */
769 int
770 rootnex_name_child(dev_info_t *child, char *name, int namelen)
771 {
772 	return (rootnex_name_child_impl(child, name, namelen));
773 }
774 
775 
776 static int
777 rootnex_ctl_initchild(dev_info_t *dip)
778 {
779 	return (rootnex_ctl_initchild_impl(dip));
780 }
781 
782 
783 int
784 rootnex_ctl_uninitchild(dev_info_t *dip)
785 {
786 	extern void impl_free_ddi_ppd(dev_info_t *);
787 
788 	rootnex_ctl_uninitchild_impl(dip);
789 
790 	/*
791 	 * strip properties and convert node to prototype form
792 	 */
793 	impl_free_ddi_ppd(dip);
794 	ddi_set_name_addr(dip, NULL);
795 	impl_rem_dev_props(dip);
796 	return (DDI_SUCCESS);
797 }
798 
799 
800 static int
801 rootnex_ctl_reportdev(dev_info_t *dev)
802 {
803 	return (rootnex_ctl_reportdev_impl(dev));
804 }
805 
806 
807 static int
808 rootnex_ctlops_peekpoke(ddi_ctl_enum_t cmd, peekpoke_ctlops_t *in_args,
809     void *result)
810 {
811 	int err = DDI_SUCCESS;
812 	on_trap_data_t otd;
813 
814 	/* No safe access except for peek/poke is supported. */
815 	if (in_args->handle != NULL)
816 		return (DDI_FAILURE);
817 
818 	/* Set up protected environment. */
819 	if (!on_trap(&otd, OT_DATA_ACCESS)) {
820 		uintptr_t tramp = otd.ot_trampoline;
821 
822 		if (cmd == DDI_CTLOPS_POKE) {
823 			otd.ot_trampoline = (uintptr_t)&poke_fault;
824 			err = do_poke(in_args->size, (void *)in_args->dev_addr,
825 			    (void *)in_args->host_addr);
826 		} else {
827 			otd.ot_trampoline = (uintptr_t)&peek_fault;
828 			err = do_peek(in_args->size, (void *)in_args->dev_addr,
829 			    (void *)in_args->host_addr);
830 			result = (void *)in_args->host_addr;
831 		}
832 		otd.ot_trampoline = tramp;
833 	} else
834 		err = DDI_FAILURE;
835 
836 	/* Take down protected environment. */
837 	no_trap();
838 
839 	return (err);
840 }
841 
842 /*ARGSUSED*/
843 static int
844 rootnex_ctlops(dev_info_t *dip, dev_info_t *rdip,
845     ddi_ctl_enum_t ctlop, void *arg, void *result)
846 {
847 	register int n, *ptr;
848 	register struct ddi_parent_private_data *pdp;
849 
850 	static boolean_t reserved_msg_printed = B_FALSE;
851 
852 	switch (ctlop) {
853 	case DDI_CTLOPS_DMAPMAPC:
854 		return (DDI_FAILURE);
855 
856 	case DDI_CTLOPS_BTOP:
857 		/*
858 		 * Convert byte count input to physical page units.
859 		 * (byte counts that are not a page-size multiple
860 		 * are rounded down)
861 		 */
862 		*(ulong_t *)result = btop(*(ulong_t *)arg);
863 		return (DDI_SUCCESS);
864 
865 	case DDI_CTLOPS_PTOB:
866 		/*
867 		 * Convert size in physical pages to bytes
868 		 */
869 		*(ulong_t *)result = ptob(*(ulong_t *)arg);
870 		return (DDI_SUCCESS);
871 
872 	case DDI_CTLOPS_BTOPR:
873 		/*
874 		 * Convert byte count input to physical page units
875 		 * (byte counts that are not a page-size multiple
876 		 * are rounded up)
877 		 */
878 		*(ulong_t *)result = btopr(*(ulong_t *)arg);
879 		return (DDI_SUCCESS);
880 
881 	case DDI_CTLOPS_INITCHILD:
882 		return (rootnex_ctl_initchild((dev_info_t *)arg));
883 
884 	case DDI_CTLOPS_UNINITCHILD:
885 		return (rootnex_ctl_uninitchild((dev_info_t *)arg));
886 
887 	case DDI_CTLOPS_REPORTDEV:
888 		return (rootnex_ctl_reportdev(rdip));
889 
890 	case DDI_CTLOPS_IOMIN:
891 		/*
892 		 * Nothing to do here but reflect back..
893 		 */
894 		return (DDI_SUCCESS);
895 
896 	case DDI_CTLOPS_REGSIZE:
897 	case DDI_CTLOPS_NREGS:
898 		break;
899 
900 	case DDI_CTLOPS_SIDDEV:
901 		if (ndi_dev_is_prom_node(rdip))
902 			return (DDI_SUCCESS);
903 		if (ndi_dev_is_persistent_node(rdip))
904 			return (DDI_SUCCESS);
905 		return (DDI_FAILURE);
906 
907 	case DDI_CTLOPS_POWER: {
908 		return ((*pm_platform_power)((power_req_t *)arg));
909 	}
910 
911 	case DDI_CTLOPS_RESERVED0: /* Was DDI_CTLOPS_NINTRS, obsolete */
912 	case DDI_CTLOPS_RESERVED1: /* Was DDI_CTLOPS_POKE_INIT, obsolete */
913 	case DDI_CTLOPS_RESERVED2: /* Was DDI_CTLOPS_POKE_FLUSH, obsolete */
914 	case DDI_CTLOPS_RESERVED3: /* Was DDI_CTLOPS_POKE_FINI, obsolete */
915 	case DDI_CTLOPS_RESERVED4: /* Was DDI_CTLOPS_INTR_HILEVEL, obsolete */
916 	case DDI_CTLOPS_RESERVED5: /* Was DDI_CTLOPS_XLATE_INTRS, obsolete */
917 		if (!reserved_msg_printed) {
918 			reserved_msg_printed = B_TRUE;
919 			cmn_err(CE_WARN, "Failing ddi_ctlops call(s) for "
920 			    "1 or more reserved/obsolete operations.");
921 		}
922 		return (DDI_FAILURE);
923 
924 	case DDI_CTLOPS_POKE:
925 	case DDI_CTLOPS_PEEK:
926 		return (rootnex_ctlops_peekpoke(ctlop, (peekpoke_ctlops_t *)arg,
927 		    result));
928 
929 	default:
930 		return (DDI_FAILURE);
931 	}
932 
933 	/*
934 	 * The rest are for "hardware" properties
935 	 */
936 	if ((pdp = ddi_get_parent_data(rdip)) == NULL)
937 		return (DDI_FAILURE);
938 
939 	if (ctlop == DDI_CTLOPS_NREGS) {
940 		ptr = (int *)result;
941 		*ptr = pdp->par_nreg;
942 	} else {	/* ctlop == DDI_CTLOPS_REGSIZE */
943 		off_t *size = (off_t *)result;
944 
945 		ptr = (int *)arg;
946 		n = *ptr;
947 		if (n >= pdp->par_nreg) {
948 			return (DDI_FAILURE);
949 		}
950 		*size = (off_t)pdp->par_reg[n].regspec_size;
951 	}
952 	return (DDI_SUCCESS);
953 }
954 
955 /* ARGSUSED */
956 int
957 rootnex_busop_fminit(dev_info_t *dip, dev_info_t *tdip, int cap,
958     ddi_iblock_cookie_t *ibc)
959 {
960 	*ibc = rootnex_err_ibc;
961 	return (ddi_system_fmcap | DDI_FM_ACCCHK_CAPABLE |
962 	    DDI_FM_DMACHK_CAPABLE);
963 }
964 
965 static void
966 rootnex_fm_init(dev_info_t *dip)
967 {
968 	int fmcap;
969 
970 	/* Minimum fm capability level for sun4u platforms */
971 	ddi_system_fmcap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE;
972 
973 	fmcap = ddi_system_fmcap;
974 
975 	/*
976 	 * Initialize ECC error handling
977 	 */
978 	rootnex_err_ibc = (ddi_iblock_cookie_t)PIL_15;
979 	ddi_fm_init(dip, &fmcap, &rootnex_err_ibc);
980 }
981