xref: /titanic_52/usr/src/uts/sun4/io/px/px.c (revision 00d1d19828f3122eb24ae7a68175ba64744f8366)
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  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * SPARC Host to PCI Express nexus driver
28  */
29 
30 #include <sys/types.h>
31 #include <sys/conf.h>		/* nulldev */
32 #include <sys/stat.h>		/* devctl */
33 #include <sys/kmem.h>
34 #include <sys/sunddi.h>
35 #include <sys/sunndi.h>
36 #include <sys/ddi_subrdefs.h>
37 #include <sys/spl.h>
38 #include <sys/epm.h>
39 #include <sys/iommutsb.h>
40 #include "px_obj.h"
41 #include <sys/hotplug/pci/pcie_hp.h>
42 #include <sys/pci_tools.h>
43 #include "px_tools_ext.h"
44 #include <sys/pcie_pwr.h>
45 #include <sys/pci_cfgacc.h>
46 
47 /*LINTLIBRARY*/
48 
49 /*
50  * function prototypes for dev ops routines:
51  */
52 static int px_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
53 static int px_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
54 static int px_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
55 	void *arg, void **result);
56 static int px_cb_attach(px_t *);
57 static void px_cb_detach(px_t *);
58 static int px_pwr_setup(dev_info_t *dip);
59 static void px_pwr_teardown(dev_info_t *dip);
60 static void px_set_mps(px_t *px_p);
61 
62 extern void pci_cfgacc_acc(pci_cfgacc_req_t *);
63 extern int pcie_max_mps;
64 extern void (*pci_cfgacc_acc_p)(pci_cfgacc_req_t *);
65 /*
66  * bus ops and dev ops structures:
67  */
68 static struct bus_ops px_bus_ops = {
69 	BUSO_REV,
70 	px_map,
71 	0,
72 	0,
73 	0,
74 	i_ddi_map_fault,
75 	px_dma_setup,
76 	px_dma_allochdl,
77 	px_dma_freehdl,
78 	px_dma_bindhdl,
79 	px_dma_unbindhdl,
80 	px_lib_dma_sync,
81 	px_dma_win,
82 	px_dma_ctlops,
83 	px_ctlops,
84 	ddi_bus_prop_op,
85 	ndi_busop_get_eventcookie,
86 	ndi_busop_add_eventcall,
87 	ndi_busop_remove_eventcall,
88 	ndi_post_event,
89 	NULL,
90 	NULL,			/* (*bus_config)(); */
91 	NULL,			/* (*bus_unconfig)(); */
92 	px_fm_init_child,	/* (*bus_fm_init)(); */
93 	NULL,			/* (*bus_fm_fini)(); */
94 	px_bus_enter,		/* (*bus_fm_access_enter)(); */
95 	px_bus_exit,		/* (*bus_fm_access_fini)(); */
96 	pcie_bus_power,		/* (*bus_power)(); */
97 	px_intr_ops,		/* (*bus_intr_op)(); */
98 	pcie_hp_common_ops	/* (*bus_hp_op)(); */
99 };
100 
101 extern struct cb_ops px_cb_ops;
102 
103 static struct dev_ops px_ops = {
104 	DEVO_REV,
105 	0,
106 	px_info,
107 	nulldev,
108 	0,
109 	px_attach,
110 	px_detach,
111 	nodev,
112 	&px_cb_ops,
113 	&px_bus_ops,
114 	nulldev,
115 	ddi_quiesce_not_needed,		/* quiesce */
116 };
117 
118 /*
119  * module definitions:
120  */
121 #include <sys/modctl.h>
122 extern struct mod_ops mod_driverops;
123 
124 static struct modldrv modldrv = {
125 	&mod_driverops, 			/* Type of module - driver */
126 #if defined(sun4u)
127 	"Sun4u Host to PCIe nexus driver",	/* Name of module. */
128 #elif defined(sun4v)
129 	"Sun4v Host to PCIe nexus driver",	/* Name of module. */
130 #endif
131 	&px_ops,				/* driver ops */
132 };
133 
134 static struct modlinkage modlinkage = {
135 	MODREV_1, (void *)&modldrv, NULL
136 };
137 
138 /* driver soft state */
139 void *px_state_p;
140 
141 int
142 _init(void)
143 {
144 	int e;
145 
146 	/*
147 	 * Initialize per-px bus soft state pointer.
148 	 */
149 	e = ddi_soft_state_init(&px_state_p, sizeof (px_t), 1);
150 	if (e != DDI_SUCCESS)
151 		return (e);
152 
153 	/*
154 	 * Install the module.
155 	 */
156 	e = mod_install(&modlinkage);
157 	if (e != DDI_SUCCESS)
158 		ddi_soft_state_fini(&px_state_p);
159 	return (e);
160 }
161 
162 int
163 _fini(void)
164 {
165 	int e;
166 
167 	/*
168 	 * Remove the module.
169 	 */
170 	e = mod_remove(&modlinkage);
171 	if (e != DDI_SUCCESS)
172 		return (e);
173 
174 	/* Free px soft state */
175 	ddi_soft_state_fini(&px_state_p);
176 
177 	return (e);
178 }
179 
180 int
181 _info(struct modinfo *modinfop)
182 {
183 	return (mod_info(&modlinkage, modinfop));
184 }
185 
186 /* ARGSUSED */
187 static int
188 px_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
189 {
190 	minor_t	minor = getminor((dev_t)arg);
191 	int	instance = PCI_MINOR_NUM_TO_INSTANCE(minor);
192 	px_t	*px_p = INST_TO_STATE(instance);
193 	int	ret = DDI_SUCCESS;
194 
195 	switch (infocmd) {
196 	case DDI_INFO_DEVT2INSTANCE:
197 		*result = (void *)(intptr_t)instance;
198 		break;
199 	case DDI_INFO_DEVT2DEVINFO:
200 		if (px_p == NULL) {
201 			ret = DDI_FAILURE;
202 			break;
203 		}
204 
205 		*result = (void *)px_p->px_dip;
206 		break;
207 	default:
208 		ret = DDI_FAILURE;
209 		break;
210 	}
211 
212 	return (ret);
213 }
214 
215 /* device driver entry points */
216 /*
217  * attach entry point:
218  */
219 /*ARGSUSED*/
220 static int
221 px_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
222 {
223 	px_t		*px_p;	/* per bus state pointer */
224 	int		instance = DIP_TO_INST(dip);
225 	int		ret = DDI_SUCCESS;
226 	devhandle_t	dev_hdl = NULL;
227 	pcie_hp_regops_t regops;
228 	pcie_bus_t	*bus_p;
229 
230 	switch (cmd) {
231 	case DDI_ATTACH:
232 		DBG(DBG_ATTACH, dip, "DDI_ATTACH\n");
233 
234 		/* See pci_cfgacc.c */
235 		pci_cfgacc_acc_p = pci_cfgacc_acc;
236 
237 		/*
238 		 * Allocate and get the per-px soft state structure.
239 		 */
240 		if (ddi_soft_state_zalloc(px_state_p, instance)
241 		    != DDI_SUCCESS) {
242 			cmn_err(CE_WARN, "%s%d: can't allocate px state",
243 			    ddi_driver_name(dip), instance);
244 			goto err_bad_px_softstate;
245 		}
246 		px_p = INST_TO_STATE(instance);
247 		px_p->px_dip = dip;
248 		mutex_init(&px_p->px_mutex, NULL, MUTEX_DRIVER, NULL);
249 		px_p->px_soft_state = PCI_SOFT_STATE_CLOSED;
250 
251 		(void) ddi_prop_update_string(DDI_DEV_T_NONE, dip,
252 		    "device_type", "pciex");
253 
254 		/* Initialize px_dbg for high pil printing */
255 		px_dbg_attach(dip, &px_p->px_dbg_hdl);
256 		pcie_rc_init_bus(dip);
257 
258 		/*
259 		 * Get key properties of the pci bridge node and
260 		 * determine it's type (psycho, schizo, etc ...).
261 		 */
262 		if (px_get_props(px_p, dip) == DDI_FAILURE)
263 			goto err_bad_px_prop;
264 
265 		if (px_lib_dev_init(dip, &dev_hdl) != DDI_SUCCESS)
266 			goto err_bad_dev_init;
267 
268 		/* Initialize device handle */
269 		px_p->px_dev_hdl = dev_hdl;
270 
271 		/* Cache the BDF of the root port nexus */
272 		px_p->px_bdf = px_lib_get_bdf(px_p);
273 
274 		/*
275 		 * Initialize interrupt block.  Note that this
276 		 * initialize error handling for the PEC as well.
277 		 */
278 		if ((ret = px_ib_attach(px_p)) != DDI_SUCCESS)
279 			goto err_bad_ib;
280 
281 		if (px_cb_attach(px_p) != DDI_SUCCESS)
282 			goto err_bad_cb;
283 
284 		/*
285 		 * Start creating the modules.
286 		 * Note that attach() routines should
287 		 * register and enable their own interrupts.
288 		 */
289 
290 		if ((px_mmu_attach(px_p)) != DDI_SUCCESS)
291 			goto err_bad_mmu;
292 
293 		if ((px_msiq_attach(px_p)) != DDI_SUCCESS)
294 			goto err_bad_msiq;
295 
296 		if ((px_msi_attach(px_p)) != DDI_SUCCESS)
297 			goto err_bad_msi;
298 
299 		if ((px_pec_attach(px_p)) != DDI_SUCCESS)
300 			goto err_bad_pec;
301 
302 		if ((px_dma_attach(px_p)) != DDI_SUCCESS)
303 			goto err_bad_dma; /* nothing to uninitialize on DMA */
304 
305 		if ((px_fm_attach(px_p)) != DDI_SUCCESS)
306 			goto err_bad_dma;
307 
308 		/*
309 		 * All of the error handlers have been registered
310 		 * by now so it's time to activate the interrupt.
311 		 */
312 		if ((ret = px_err_add_intr(&px_p->px_fault)) != DDI_SUCCESS)
313 			goto err_bad_intr;
314 
315 		if (px_lib_hotplug_init(dip, (void *)&regops) == DDI_SUCCESS) {
316 			pcie_bus_t	*bus_p = PCIE_DIP2BUS(dip);
317 
318 			bus_p->bus_hp_sup_modes |= PCIE_NATIVE_HP_MODE;
319 		}
320 
321 		(void) px_set_mps(px_p);
322 
323 		if (pcie_init(dip, (caddr_t)&regops) != DDI_SUCCESS)
324 			goto err_bad_hotplug;
325 
326 		(void) pcie_hpintr_enable(dip);
327 
328 		if (pxtool_init(dip) != DDI_SUCCESS)
329 			goto err_bad_pcitool_node;
330 
331 		/*
332 		 * power management setup. Even if it fails, attach will
333 		 * succeed as this is a optional feature. Since we are
334 		 * always at full power, this is not critical.
335 		 */
336 		if (pwr_common_setup(dip) != DDI_SUCCESS) {
337 			DBG(DBG_PWR, dip, "pwr_common_setup failed\n");
338 		} else if (px_pwr_setup(dip) != DDI_SUCCESS) {
339 			DBG(DBG_PWR, dip, "px_pwr_setup failed \n");
340 			pwr_common_teardown(dip);
341 		}
342 
343 		/*
344 		 * add cpr callback
345 		 */
346 		px_cpr_add_callb(px_p);
347 
348 		/*
349 		 * do fabric sync in case we don't need to wait for
350 		 * any bridge driver to be ready
351 		 */
352 		(void) px_lib_fabric_sync(dip);
353 
354 		ddi_report_dev(dip);
355 
356 		px_p->px_state = PX_ATTACHED;
357 
358 		/*
359 		 * save base addr in bus_t for pci_cfgacc_xxx(), this
360 		 * depends of px structure being properly initialized.
361 		 */
362 		bus_p = PCIE_DIP2BUS(dip);
363 		bus_p->bus_cfgacc_base = px_lib_get_cfgacc_base(dip);
364 
365 		/*
366 		 * Partially populate bus_t for all devices in this fabric
367 		 * for device type macros to work.
368 		 */
369 		/*
370 		 * Populate bus_t for all devices in this fabric, after FMA
371 		 * is initializated, so that config access errors could
372 		 * trigger panic.
373 		 */
374 		pcie_fab_init_bus(dip, PCIE_BUS_ALL);
375 
376 		DBG(DBG_ATTACH, dip, "attach success\n");
377 		break;
378 
379 err_bad_pcitool_node:
380 		(void) pcie_hpintr_disable(dip);
381 		(void) pcie_uninit(dip);
382 err_bad_hotplug:
383 		(void) px_lib_hotplug_uninit(dip);
384 		px_err_rem_intr(&px_p->px_fault);
385 err_bad_intr:
386 		px_fm_detach(px_p);
387 err_bad_dma:
388 		px_pec_detach(px_p);
389 err_bad_pec:
390 		px_msi_detach(px_p);
391 err_bad_msi:
392 		px_msiq_detach(px_p);
393 err_bad_msiq:
394 		px_mmu_detach(px_p);
395 err_bad_mmu:
396 		px_cb_detach(px_p);
397 err_bad_cb:
398 		px_ib_detach(px_p);
399 err_bad_ib:
400 		if (px_lib_dev_fini(dip) != DDI_SUCCESS) {
401 			DBG(DBG_ATTACH, dip, "px_lib_dev_fini failed\n");
402 		}
403 err_bad_dev_init:
404 		px_free_props(px_p);
405 err_bad_px_prop:
406 		pcie_rc_fini_bus(dip);
407 		px_dbg_detach(dip, &px_p->px_dbg_hdl);
408 		mutex_destroy(&px_p->px_mutex);
409 		ddi_soft_state_free(px_state_p, instance);
410 err_bad_px_softstate:
411 		ret = DDI_FAILURE;
412 		break;
413 
414 	case DDI_RESUME:
415 		DBG(DBG_ATTACH, dip, "DDI_RESUME\n");
416 
417 		px_p = INST_TO_STATE(instance);
418 
419 		mutex_enter(&px_p->px_mutex);
420 
421 		/* suspend might have not succeeded */
422 		if (px_p->px_state != PX_SUSPENDED) {
423 			DBG(DBG_ATTACH, px_p->px_dip,
424 			    "instance NOT suspended\n");
425 			ret = DDI_FAILURE;
426 			break;
427 		}
428 
429 		px_msiq_resume(px_p);
430 		px_lib_resume(dip);
431 		(void) pcie_pwr_resume(dip);
432 		px_p->px_state = PX_ATTACHED;
433 
434 		mutex_exit(&px_p->px_mutex);
435 
436 		break;
437 	default:
438 		DBG(DBG_ATTACH, dip, "unsupported attach op\n");
439 		ret = DDI_FAILURE;
440 		break;
441 	}
442 
443 	return (ret);
444 }
445 
446 /*
447  * detach entry point:
448  */
449 /*ARGSUSED*/
450 static int
451 px_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
452 {
453 	int		instance = ddi_get_instance(dip);
454 	px_t		*px_p = INST_TO_STATE(instance);
455 	pcie_bus_t	*bus_p = PCIE_DIP2BUS(dip);
456 	int		ret;
457 
458 	/*
459 	 * Make sure we are currently attached
460 	 */
461 	if (px_p->px_state != PX_ATTACHED) {
462 		DBG(DBG_DETACH, dip, "Instance not attached\n");
463 		return (DDI_FAILURE);
464 	}
465 
466 	mutex_enter(&px_p->px_mutex);
467 
468 	switch (cmd) {
469 	case DDI_DETACH:
470 		DBG(DBG_DETACH, dip, "DDI_DETACH\n");
471 
472 		/*
473 		 * remove cpr callback
474 		 */
475 		px_cpr_rem_callb(px_p);
476 
477 		(void) pcie_hpintr_disable(dip);
478 
479 		if (PCIE_IS_PCIE_HOTPLUG_ENABLED(bus_p))
480 			(void) px_lib_hotplug_uninit(dip);
481 
482 		if (pcie_uninit(dip) != DDI_SUCCESS) {
483 			mutex_exit(&px_p->px_mutex);
484 			return (DDI_FAILURE);
485 		}
486 
487 		/* Destroy bus_t for the whole fabric */
488 		pcie_fab_fini_bus(dip, PCIE_BUS_ALL);
489 
490 		/*
491 		 * things which used to be done in obj_destroy
492 		 * are now in-lined here.
493 		 */
494 
495 		px_p->px_state = PX_DETACHED;
496 
497 		pxtool_uninit(dip);
498 
499 		px_err_rem_intr(&px_p->px_fault);
500 		px_fm_detach(px_p);
501 		px_pec_detach(px_p);
502 		px_pwr_teardown(dip);
503 		pwr_common_teardown(dip);
504 		px_msi_detach(px_p);
505 		px_msiq_detach(px_p);
506 		px_mmu_detach(px_p);
507 		px_cb_detach(px_p);
508 		px_ib_detach(px_p);
509 		if (px_lib_dev_fini(dip) != DDI_SUCCESS) {
510 			DBG(DBG_DETACH, dip, "px_lib_dev_fini failed\n");
511 		}
512 
513 		/*
514 		 * Free the px soft state structure and the rest of the
515 		 * resources it's using.
516 		 */
517 		px_free_props(px_p);
518 		pcie_rc_fini_bus(dip);
519 		px_dbg_detach(dip, &px_p->px_dbg_hdl);
520 		mutex_exit(&px_p->px_mutex);
521 		mutex_destroy(&px_p->px_mutex);
522 
523 		px_p->px_dev_hdl = NULL;
524 		ddi_soft_state_free(px_state_p, instance);
525 
526 		return (DDI_SUCCESS);
527 
528 	case DDI_SUSPEND:
529 		if (pcie_pwr_suspend(dip) != DDI_SUCCESS) {
530 			mutex_exit(&px_p->px_mutex);
531 			return (DDI_FAILURE);
532 		}
533 		if ((ret = px_lib_suspend(dip)) == DDI_SUCCESS)
534 			px_p->px_state = PX_SUSPENDED;
535 		mutex_exit(&px_p->px_mutex);
536 
537 		return (ret);
538 
539 	default:
540 		DBG(DBG_DETACH, dip, "unsupported detach op\n");
541 		mutex_exit(&px_p->px_mutex);
542 		return (DDI_FAILURE);
543 	}
544 }
545 
546 int
547 px_cb_attach(px_t *px_p)
548 {
549 	px_fault_t	*fault_p = &px_p->px_cb_fault;
550 	dev_info_t	*dip = px_p->px_dip;
551 	sysino_t	sysino;
552 
553 	if (px_lib_intr_devino_to_sysino(dip,
554 	    px_p->px_inos[PX_INTR_XBC], &sysino) != DDI_SUCCESS)
555 		return (DDI_FAILURE);
556 
557 	fault_p->px_fh_dip = dip;
558 	fault_p->px_fh_sysino = sysino;
559 	fault_p->px_err_func = px_err_cb_intr;
560 	fault_p->px_intr_ino = px_p->px_inos[PX_INTR_XBC];
561 
562 	return (px_cb_add_intr(fault_p));
563 }
564 
565 void
566 px_cb_detach(px_t *px_p)
567 {
568 	px_cb_rem_intr(&px_p->px_cb_fault);
569 }
570 
571 /*
572  * power management related initialization specific to px
573  * called by px_attach()
574  */
575 static int
576 px_pwr_setup(dev_info_t *dip)
577 {
578 	pcie_pwr_t *pwr_p;
579 	int instance = ddi_get_instance(dip);
580 	px_t *px_p = INST_TO_STATE(instance);
581 	ddi_intr_handle_impl_t hdl;
582 
583 	ASSERT(PCIE_PMINFO(dip));
584 	pwr_p = PCIE_NEXUS_PMINFO(dip);
585 	ASSERT(pwr_p);
586 
587 	/*
588 	 * indicate support LDI (Layered Driver Interface)
589 	 * Create the property, if it is not already there
590 	 */
591 	if (!ddi_prop_exists(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS,
592 	    DDI_KERNEL_IOCTL)) {
593 		if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP,
594 		    DDI_KERNEL_IOCTL, NULL, 0) != DDI_PROP_SUCCESS) {
595 			DBG(DBG_PWR, dip, "can't create kernel ioctl prop\n");
596 			return (DDI_FAILURE);
597 		}
598 	}
599 	/* No support for device PM. We are always at full power */
600 	pwr_p->pwr_func_lvl = PM_LEVEL_D0;
601 
602 	mutex_init(&px_p->px_l23ready_lock, NULL, MUTEX_DRIVER,
603 	    DDI_INTR_PRI(px_pwr_pil));
604 	cv_init(&px_p->px_l23ready_cv, NULL, CV_DRIVER, NULL);
605 
606 	/* Initialize handle */
607 	bzero(&hdl, sizeof (ddi_intr_handle_impl_t));
608 	hdl.ih_cb_arg1 = px_p;
609 	hdl.ih_ver = DDI_INTR_VERSION;
610 	hdl.ih_state = DDI_IHDL_STATE_ALLOC;
611 	hdl.ih_dip = dip;
612 	hdl.ih_pri = px_pwr_pil;
613 
614 	/* Add PME_TO_ACK message handler */
615 	hdl.ih_cb_func = (ddi_intr_handler_t *)px_pmeq_intr;
616 	if (px_add_msiq_intr(dip, dip, &hdl, MSG_REC,
617 	    (msgcode_t)PCIE_PME_ACK_MSG, -1,
618 	    &px_p->px_pm_msiq_id) != DDI_SUCCESS) {
619 		DBG(DBG_PWR, dip, "px_pwr_setup: couldn't add "
620 		    " PME_TO_ACK intr\n");
621 		goto pwr_setup_err1;
622 	}
623 	px_lib_msg_setmsiq(dip, PCIE_PME_ACK_MSG, px_p->px_pm_msiq_id);
624 	px_lib_msg_setvalid(dip, PCIE_PME_ACK_MSG, PCIE_MSG_VALID);
625 
626 	if (px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
627 	    px_msiqid_to_devino(px_p, px_p->px_pm_msiq_id), px_pwr_pil,
628 	    PX_INTR_STATE_ENABLE, MSG_REC, PCIE_PME_ACK_MSG) != DDI_SUCCESS) {
629 		DBG(DBG_PWR, dip, "px_pwr_setup: PME_TO_ACK update interrupt"
630 		    " state failed\n");
631 		goto px_pwrsetup_err_state;
632 	}
633 
634 	return (DDI_SUCCESS);
635 
636 px_pwrsetup_err_state:
637 	px_lib_msg_setvalid(dip, PCIE_PME_ACK_MSG, PCIE_MSG_INVALID);
638 	(void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, PCIE_PME_ACK_MSG,
639 	    px_p->px_pm_msiq_id);
640 pwr_setup_err1:
641 	mutex_destroy(&px_p->px_l23ready_lock);
642 	cv_destroy(&px_p->px_l23ready_cv);
643 
644 	return (DDI_FAILURE);
645 }
646 
647 /*
648  * undo whatever is done in px_pwr_setup. called by px_detach()
649  */
650 static void
651 px_pwr_teardown(dev_info_t *dip)
652 {
653 	int instance = ddi_get_instance(dip);
654 	px_t *px_p = INST_TO_STATE(instance);
655 	ddi_intr_handle_impl_t	hdl;
656 
657 	if (!PCIE_PMINFO(dip) || !PCIE_NEXUS_PMINFO(dip))
658 		return;
659 
660 	/* Initialize handle */
661 	bzero(&hdl, sizeof (ddi_intr_handle_impl_t));
662 	hdl.ih_ver = DDI_INTR_VERSION;
663 	hdl.ih_state = DDI_IHDL_STATE_ALLOC;
664 	hdl.ih_dip = dip;
665 	hdl.ih_pri = px_pwr_pil;
666 
667 	px_lib_msg_setvalid(dip, PCIE_PME_ACK_MSG, PCIE_MSG_INVALID);
668 	(void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, PCIE_PME_ACK_MSG,
669 	    px_p->px_pm_msiq_id);
670 
671 	(void) px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
672 	    px_msiqid_to_devino(px_p, px_p->px_pm_msiq_id), px_pwr_pil,
673 	    PX_INTR_STATE_DISABLE, MSG_REC, PCIE_PME_ACK_MSG);
674 
675 	px_p->px_pm_msiq_id = (msiqid_t)-1;
676 
677 	cv_destroy(&px_p->px_l23ready_cv);
678 	mutex_destroy(&px_p->px_l23ready_lock);
679 }
680 
681 /* bus driver entry points */
682 
683 /*
684  * bus map entry point:
685  *
686  * 	if map request is for an rnumber
687  *		get the corresponding regspec from device node
688  * 	build a new regspec in our parent's format
689  *	build a new map_req with the new regspec
690  *	call up the tree to complete the mapping
691  */
692 int
693 px_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
694 	off_t off, off_t len, caddr_t *addrp)
695 {
696 	px_t *px_p = DIP_TO_STATE(dip);
697 	struct regspec p_regspec;
698 	ddi_map_req_t p_mapreq;
699 	int reglen, rval, r_no;
700 	pci_regspec_t reloc_reg, *rp = &reloc_reg;
701 
702 	DBG(DBG_MAP, dip, "rdip=%s%d:",
703 	    ddi_driver_name(rdip), ddi_get_instance(rdip));
704 
705 	if (mp->map_flags & DDI_MF_USER_MAPPING)
706 		return (DDI_ME_UNIMPLEMENTED);
707 
708 	switch (mp->map_type) {
709 	case DDI_MT_REGSPEC:
710 		reloc_reg = *(pci_regspec_t *)mp->map_obj.rp;	/* dup whole */
711 		break;
712 
713 	case DDI_MT_RNUMBER:
714 		r_no = mp->map_obj.rnumber;
715 		DBG(DBG_MAP | DBG_CONT, dip, " r#=%x", r_no);
716 
717 		if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS,
718 		    "reg", (caddr_t)&rp, &reglen) != DDI_SUCCESS)
719 			return (DDI_ME_RNUMBER_RANGE);
720 
721 		if (r_no < 0 || r_no >= reglen / sizeof (pci_regspec_t)) {
722 			kmem_free(rp, reglen);
723 			return (DDI_ME_RNUMBER_RANGE);
724 		}
725 		rp += r_no;
726 		break;
727 
728 	default:
729 		return (DDI_ME_INVAL);
730 	}
731 	DBG(DBG_MAP | DBG_CONT, dip, "\n");
732 
733 	if ((rp->pci_phys_hi & PCI_REG_ADDR_M) == PCI_ADDR_CONFIG) {
734 		/*
735 		 * There may be a need to differentiate between PCI
736 		 * and PCI-Ex devices so the following range check is
737 		 * done correctly, depending on the implementation of
738 		 * pcieb bridge nexus driver.
739 		 */
740 		if ((off >= PCIE_CONF_HDR_SIZE) ||
741 		    (len > PCIE_CONF_HDR_SIZE) ||
742 		    (off + len > PCIE_CONF_HDR_SIZE))
743 			return (DDI_ME_INVAL);
744 		/*
745 		 * the following function returning a DDI_FAILURE assumes
746 		 * that there are no virtual config space access services
747 		 * defined in this layer. Otherwise it is availed right
748 		 * here and we return.
749 		 */
750 		rval = px_lib_map_vconfig(dip, mp, off, rp, addrp);
751 		if (rval == DDI_SUCCESS)
752 			goto done;
753 	}
754 
755 	/*
756 	 * No virtual config space services or we are mapping
757 	 * a region of memory mapped config/IO/memory space, so proceed
758 	 * to the parent.
759 	 */
760 
761 	/* relocate within 64-bit pci space through "assigned-addresses" */
762 	if (rval = px_reloc_reg(dip, rdip, px_p, rp))
763 		goto done;
764 
765 	if (len)	/* adjust regspec according to mapping request */
766 		rp->pci_size_low = len;	/* MIN ? */
767 	rp->pci_phys_low += off;
768 
769 	/* translate relocated pci regspec into parent space through "ranges" */
770 	if (rval = px_xlate_reg(px_p, rp, &p_regspec))
771 		goto done;
772 
773 	p_mapreq = *mp;		/* dup the whole structure */
774 	p_mapreq.map_type = DDI_MT_REGSPEC;
775 	p_mapreq.map_obj.rp = &p_regspec;
776 	px_lib_map_attr_check(&p_mapreq);
777 	rval = ddi_map(dip, &p_mapreq, 0, 0, addrp);
778 
779 	if (rval == DDI_SUCCESS) {
780 		/*
781 		 * Set-up access functions for FM access error capable drivers.
782 		 */
783 		if (DDI_FM_ACC_ERR_CAP(ddi_fm_capable(rdip)))
784 			px_fm_acc_setup(mp, rdip, rp);
785 	}
786 
787 done:
788 	if (mp->map_type == DDI_MT_RNUMBER)
789 		kmem_free(rp - r_no, reglen);
790 
791 	return (rval);
792 }
793 
794 /*
795  * bus dma map entry point
796  * return value:
797  *	DDI_DMA_PARTIAL_MAP	 1
798  *	DDI_DMA_MAPOK		 0
799  *	DDI_DMA_MAPPED		 0
800  *	DDI_DMA_NORESOURCES	-1
801  *	DDI_DMA_NOMAPPING	-2
802  *	DDI_DMA_TOOBIG		-3
803  */
804 int
805 px_dma_setup(dev_info_t *dip, dev_info_t *rdip, ddi_dma_req_t *dmareq,
806 	ddi_dma_handle_t *handlep)
807 {
808 	px_t *px_p = DIP_TO_STATE(dip);
809 	px_mmu_t *mmu_p = px_p->px_mmu_p;
810 	ddi_dma_impl_t *mp;
811 	int ret;
812 
813 	DBG(DBG_DMA_MAP, dip, "mapping - rdip=%s%d type=%s\n",
814 	    ddi_driver_name(rdip), ddi_get_instance(rdip),
815 	    handlep ? "alloc" : "advisory");
816 
817 	if (!(mp = px_dma_lmts2hdl(dip, rdip, mmu_p, dmareq)))
818 		return (DDI_DMA_NORESOURCES);
819 	if (mp == (ddi_dma_impl_t *)DDI_DMA_NOMAPPING)
820 		return (DDI_DMA_NOMAPPING);
821 	if (ret = px_dma_type(px_p, dmareq, mp))
822 		goto freehandle;
823 	if (ret = px_dma_pfn(px_p, dmareq, mp))
824 		goto freehandle;
825 
826 	switch (PX_DMA_TYPE(mp)) {
827 	case PX_DMAI_FLAGS_DVMA:	/* LINTED E_EQUALITY_NOT_ASSIGNMENT */
828 		if ((ret = px_dvma_win(px_p, dmareq, mp)) || !handlep)
829 			goto freehandle;
830 		if (!PX_DMA_CANCACHE(mp)) {	/* try fast track */
831 			if (PX_DMA_CANFAST(mp)) {
832 				if (!px_dvma_map_fast(mmu_p, mp))
833 					break;
834 			/* LINTED E_NOP_ELSE_STMT */
835 			} else {
836 				PX_DVMA_FASTTRAK_PROF(mp);
837 			}
838 		}
839 		if (ret = px_dvma_map(mp, dmareq, mmu_p))
840 			goto freehandle;
841 		break;
842 	case PX_DMAI_FLAGS_PTP:	/* LINTED E_EQUALITY_NOT_ASSIGNMENT */
843 		if ((ret = px_dma_physwin(px_p, dmareq, mp)) || !handlep)
844 			goto freehandle;
845 		break;
846 	case PX_DMAI_FLAGS_BYPASS:
847 	default:
848 		cmn_err(CE_PANIC, "%s%d: px_dma_setup: bad dma type 0x%x",
849 		    ddi_driver_name(rdip), ddi_get_instance(rdip),
850 		    PX_DMA_TYPE(mp));
851 		/*NOTREACHED*/
852 	}
853 	*handlep = (ddi_dma_handle_t)mp;
854 	mp->dmai_flags |= PX_DMAI_FLAGS_INUSE;
855 	px_dump_dma_handle(DBG_DMA_MAP, dip, mp);
856 
857 	return ((mp->dmai_nwin == 1) ? DDI_DMA_MAPPED : DDI_DMA_PARTIAL_MAP);
858 freehandle:
859 	if (ret == DDI_DMA_NORESOURCES)
860 		px_dma_freemp(mp); /* don't run_callback() */
861 	else
862 		(void) px_dma_freehdl(dip, rdip, (ddi_dma_handle_t)mp);
863 	return (ret);
864 }
865 
866 
867 /*
868  * bus dma alloc handle entry point:
869  */
870 int
871 px_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attrp,
872 	int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep)
873 {
874 	px_t *px_p = DIP_TO_STATE(dip);
875 	ddi_dma_impl_t *mp;
876 	int rval;
877 
878 	DBG(DBG_DMA_ALLOCH, dip, "rdip=%s%d\n",
879 	    ddi_driver_name(rdip), ddi_get_instance(rdip));
880 
881 	if (attrp->dma_attr_version != DMA_ATTR_V0)
882 		return (DDI_DMA_BADATTR);
883 
884 	if (!(mp = px_dma_allocmp(dip, rdip, waitfp, arg)))
885 		return (DDI_DMA_NORESOURCES);
886 
887 	/*
888 	 * Save requestor's information
889 	 */
890 	mp->dmai_attr	= *attrp; /* whole object - augmented later  */
891 	*PX_DEV_ATTR(mp)	= *attrp; /* whole object - device orig attr */
892 	DBG(DBG_DMA_ALLOCH, dip, "mp=%p\n", mp);
893 
894 	/* check and convert dma attributes to handle parameters */
895 	if (rval = px_dma_attr2hdl(px_p, mp)) {
896 		px_dma_freehdl(dip, rdip, (ddi_dma_handle_t)mp);
897 		*handlep = NULL;
898 		return (rval);
899 	}
900 	*handlep = (ddi_dma_handle_t)mp;
901 	return (DDI_SUCCESS);
902 }
903 
904 
905 /*
906  * bus dma free handle entry point:
907  */
908 /*ARGSUSED*/
909 int
910 px_dma_freehdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle)
911 {
912 	DBG(DBG_DMA_FREEH, dip, "rdip=%s%d mp=%p\n",
913 	    ddi_driver_name(rdip), ddi_get_instance(rdip), handle);
914 	px_dma_freemp((ddi_dma_impl_t *)handle);
915 
916 	if (px_kmem_clid) {
917 		DBG(DBG_DMA_FREEH, dip, "run handle callback\n");
918 		ddi_run_callback(&px_kmem_clid);
919 	}
920 	return (DDI_SUCCESS);
921 }
922 
923 
924 /*
925  * bus dma bind handle entry point:
926  */
927 int
928 px_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip,
929 	ddi_dma_handle_t handle, ddi_dma_req_t *dmareq,
930 	ddi_dma_cookie_t *cookiep, uint_t *ccountp)
931 {
932 	px_t *px_p = DIP_TO_STATE(dip);
933 	px_mmu_t *mmu_p = px_p->px_mmu_p;
934 	ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
935 	int ret;
936 
937 	DBG(DBG_DMA_BINDH, dip, "rdip=%s%d mp=%p dmareq=%p\n",
938 	    ddi_driver_name(rdip), ddi_get_instance(rdip), mp, dmareq);
939 
940 	if (mp->dmai_flags & PX_DMAI_FLAGS_INUSE)
941 		return (DDI_DMA_INUSE);
942 
943 	ASSERT((mp->dmai_flags & ~PX_DMAI_FLAGS_PRESERVE) == 0);
944 	mp->dmai_flags |= PX_DMAI_FLAGS_INUSE;
945 
946 	if (ret = px_dma_type(px_p, dmareq, mp))
947 		goto err;
948 	if (ret = px_dma_pfn(px_p, dmareq, mp))
949 		goto err;
950 
951 	switch (PX_DMA_TYPE(mp)) {
952 	case PX_DMAI_FLAGS_DVMA:
953 		if (ret = px_dvma_win(px_p, dmareq, mp))
954 			goto map_err;
955 		if (!PX_DMA_CANCACHE(mp)) {	/* try fast track */
956 			if (PX_DMA_CANFAST(mp)) {
957 				if (!px_dvma_map_fast(mmu_p, mp))
958 					goto mapped; /*LINTED E_NOP_ELSE_STMT*/
959 			} else {
960 				PX_DVMA_FASTTRAK_PROF(mp);
961 			}
962 		}
963 		if (ret = px_dvma_map(mp, dmareq, mmu_p))
964 			goto map_err;
965 mapped:
966 		*ccountp = 1;
967 		MAKE_DMA_COOKIE(cookiep, mp->dmai_mapping, mp->dmai_size);
968 		break;
969 	case PX_DMAI_FLAGS_BYPASS:
970 	case PX_DMAI_FLAGS_PTP:
971 		if (ret = px_dma_physwin(px_p, dmareq, mp))
972 			goto map_err;
973 		*ccountp = PX_WINLST(mp)->win_ncookies;
974 		*cookiep =
975 		    *(ddi_dma_cookie_t *)(PX_WINLST(mp) + 1); /* wholeobj */
976 		break;
977 	default:
978 		cmn_err(CE_PANIC, "%s%d: px_dma_bindhdl(%p): bad dma type",
979 		    ddi_driver_name(rdip), ddi_get_instance(rdip), mp);
980 		/*NOTREACHED*/
981 	}
982 	DBG(DBG_DMA_BINDH, dip, "cookie %" PRIx64 "+%x\n",
983 	    cookiep->dmac_address, cookiep->dmac_size);
984 	px_dump_dma_handle(DBG_DMA_MAP, dip, mp);
985 
986 	/* insert dma handle into FMA cache */
987 	if (mp->dmai_attr.dma_attr_flags & DDI_DMA_FLAGERR)
988 		mp->dmai_error.err_cf = px_err_dma_hdl_check;
989 
990 	return (mp->dmai_nwin == 1 ? DDI_DMA_MAPPED : DDI_DMA_PARTIAL_MAP);
991 map_err:
992 	px_dma_freepfn(mp);
993 err:
994 	mp->dmai_flags &= PX_DMAI_FLAGS_PRESERVE;
995 	return (ret);
996 }
997 
998 
999 /*
1000  * bus dma unbind handle entry point:
1001  */
1002 /*ARGSUSED*/
1003 int
1004 px_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle)
1005 {
1006 	ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
1007 	px_t *px_p = DIP_TO_STATE(dip);
1008 	px_mmu_t *mmu_p = px_p->px_mmu_p;
1009 
1010 	DBG(DBG_DMA_UNBINDH, dip, "rdip=%s%d, mp=%p\n",
1011 	    ddi_driver_name(rdip), ddi_get_instance(rdip), handle);
1012 	if ((mp->dmai_flags & PX_DMAI_FLAGS_INUSE) == 0) {
1013 		DBG(DBG_DMA_UNBINDH, dip, "handle not inuse\n");
1014 		return (DDI_FAILURE);
1015 	}
1016 
1017 	mp->dmai_error.err_cf = NULL;
1018 
1019 	/*
1020 	 * Here if the handle is using the iommu.  Unload all the iommu
1021 	 * translations.
1022 	 */
1023 	switch (PX_DMA_TYPE(mp)) {
1024 	case PX_DMAI_FLAGS_DVMA:
1025 		px_mmu_unmap_window(mmu_p, mp);
1026 		px_dvma_unmap(mmu_p, mp);
1027 		px_dma_freepfn(mp);
1028 		break;
1029 	case PX_DMAI_FLAGS_BYPASS:
1030 	case PX_DMAI_FLAGS_PTP:
1031 		px_dma_freewin(mp);
1032 		break;
1033 	default:
1034 		cmn_err(CE_PANIC, "%s%d: px_dma_unbindhdl:bad dma type %p",
1035 		    ddi_driver_name(rdip), ddi_get_instance(rdip), mp);
1036 		/*NOTREACHED*/
1037 	}
1038 	if (mmu_p->mmu_dvma_clid != 0) {
1039 		DBG(DBG_DMA_UNBINDH, dip, "run dvma callback\n");
1040 		ddi_run_callback(&mmu_p->mmu_dvma_clid);
1041 	}
1042 	if (px_kmem_clid) {
1043 		DBG(DBG_DMA_UNBINDH, dip, "run handle callback\n");
1044 		ddi_run_callback(&px_kmem_clid);
1045 	}
1046 	mp->dmai_flags &= PX_DMAI_FLAGS_PRESERVE;
1047 
1048 	return (DDI_SUCCESS);
1049 }
1050 
1051 /*
1052  * bus dma win entry point:
1053  */
1054 int
1055 px_dma_win(dev_info_t *dip, dev_info_t *rdip,
1056 	ddi_dma_handle_t handle, uint_t win, off_t *offp,
1057 	size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp)
1058 {
1059 	ddi_dma_impl_t	*mp = (ddi_dma_impl_t *)handle;
1060 	int		ret;
1061 
1062 	DBG(DBG_DMA_WIN, dip, "rdip=%s%d\n",
1063 	    ddi_driver_name(rdip), ddi_get_instance(rdip));
1064 
1065 	px_dump_dma_handle(DBG_DMA_WIN, dip, mp);
1066 	if (win >= mp->dmai_nwin) {
1067 		DBG(DBG_DMA_WIN, dip, "%x out of range\n", win);
1068 		return (DDI_FAILURE);
1069 	}
1070 
1071 	switch (PX_DMA_TYPE(mp)) {
1072 	case PX_DMAI_FLAGS_DVMA:
1073 		if (win != PX_DMA_CURWIN(mp)) {
1074 			px_t *px_p = DIP_TO_STATE(dip);
1075 			px_mmu_t *mmu_p = px_p->px_mmu_p;
1076 			px_mmu_unmap_window(mmu_p, mp);
1077 
1078 			/* map_window sets dmai_mapping/size/offset */
1079 			px_mmu_map_window(mmu_p, mp, win);
1080 			if ((ret = px_mmu_map_window(mmu_p,
1081 			    mp, win)) != DDI_SUCCESS)
1082 				return (ret);
1083 		}
1084 		if (cookiep)
1085 			MAKE_DMA_COOKIE(cookiep, mp->dmai_mapping,
1086 			    mp->dmai_size);
1087 		if (ccountp)
1088 			*ccountp = 1;
1089 		break;
1090 	case PX_DMAI_FLAGS_PTP:
1091 	case PX_DMAI_FLAGS_BYPASS: {
1092 		int i;
1093 		ddi_dma_cookie_t *ck_p;
1094 		px_dma_win_t *win_p = mp->dmai_winlst;
1095 
1096 		for (i = 0; i < win; win_p = win_p->win_next, i++) {};
1097 		ck_p = (ddi_dma_cookie_t *)(win_p + 1);
1098 		*cookiep = *ck_p;
1099 		mp->dmai_offset = win_p->win_offset;
1100 		mp->dmai_size   = win_p->win_size;
1101 		mp->dmai_mapping = ck_p->dmac_laddress;
1102 		mp->dmai_cookie = ck_p + 1;
1103 		win_p->win_curseg = 0;
1104 		if (ccountp)
1105 			*ccountp = win_p->win_ncookies;
1106 		}
1107 		break;
1108 	default:
1109 		cmn_err(CE_WARN, "%s%d: px_dma_win:bad dma type 0x%x",
1110 		    ddi_driver_name(rdip), ddi_get_instance(rdip),
1111 		    PX_DMA_TYPE(mp));
1112 		return (DDI_FAILURE);
1113 	}
1114 	if (cookiep)
1115 		DBG(DBG_DMA_WIN, dip,
1116 		    "cookie - dmac_address=%x dmac_size=%x\n",
1117 		    cookiep->dmac_address, cookiep->dmac_size);
1118 	if (offp)
1119 		*offp = (off_t)mp->dmai_offset;
1120 	if (lenp)
1121 		*lenp = mp->dmai_size;
1122 	return (DDI_SUCCESS);
1123 }
1124 
1125 #ifdef	DEBUG
1126 static char *px_dmactl_str[] = {
1127 	"DDI_DMA_FREE",
1128 	"DDI_DMA_SYNC",
1129 	"DDI_DMA_HTOC",
1130 	"DDI_DMA_KVADDR",
1131 	"DDI_DMA_MOVWIN",
1132 	"DDI_DMA_REPWIN",
1133 	"DDI_DMA_GETERR",
1134 	"DDI_DMA_COFF",
1135 	"DDI_DMA_NEXTWIN",
1136 	"DDI_DMA_NEXTSEG",
1137 	"DDI_DMA_SEGTOC",
1138 	"DDI_DMA_RESERVE",
1139 	"DDI_DMA_RELEASE",
1140 	"DDI_DMA_RESETH",
1141 	"DDI_DMA_CKSYNC",
1142 	"DDI_DMA_IOPB_ALLOC",
1143 	"DDI_DMA_IOPB_FREE",
1144 	"DDI_DMA_SMEM_ALLOC",
1145 	"DDI_DMA_SMEM_FREE",
1146 	"DDI_DMA_SET_SBUS64"
1147 };
1148 #endif	/* DEBUG */
1149 
1150 /*
1151  * bus dma control entry point:
1152  */
1153 /*ARGSUSED*/
1154 int
1155 px_dma_ctlops(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle,
1156 	enum ddi_dma_ctlops cmd, off_t *offp, size_t *lenp, caddr_t *objp,
1157 	uint_t cache_flags)
1158 {
1159 	ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
1160 
1161 #ifdef	DEBUG
1162 	DBG(DBG_DMA_CTL, dip, "%s: rdip=%s%d\n", px_dmactl_str[cmd],
1163 	    ddi_driver_name(rdip), ddi_get_instance(rdip));
1164 #endif	/* DEBUG */
1165 
1166 	switch (cmd) {
1167 	case DDI_DMA_FREE:
1168 		(void) px_dma_unbindhdl(dip, rdip, handle);
1169 		(void) px_dma_freehdl(dip, rdip, handle);
1170 		return (DDI_SUCCESS);
1171 	case DDI_DMA_RESERVE: {
1172 		px_t *px_p = DIP_TO_STATE(dip);
1173 		return (px_fdvma_reserve(dip, rdip, px_p,
1174 		    (ddi_dma_req_t *)offp, (ddi_dma_handle_t *)objp));
1175 		}
1176 	case DDI_DMA_RELEASE: {
1177 		px_t *px_p = DIP_TO_STATE(dip);
1178 		return (px_fdvma_release(dip, px_p, mp));
1179 		}
1180 	default:
1181 		break;
1182 	}
1183 
1184 	switch (PX_DMA_TYPE(mp)) {
1185 	case PX_DMAI_FLAGS_DVMA:
1186 		return (px_dvma_ctl(dip, rdip, mp, cmd, offp, lenp, objp,
1187 		    cache_flags));
1188 	case PX_DMAI_FLAGS_PTP:
1189 	case PX_DMAI_FLAGS_BYPASS:
1190 		return (px_dma_ctl(dip, rdip, mp, cmd, offp, lenp, objp,
1191 		    cache_flags));
1192 	default:
1193 		cmn_err(CE_PANIC, "%s%d: px_dma_ctlops(%x):bad dma type %x",
1194 		    ddi_driver_name(rdip), ddi_get_instance(rdip), cmd,
1195 		    mp->dmai_flags);
1196 		/*NOTREACHED*/
1197 	}
1198 	return (0);
1199 }
1200 
1201 /*
1202  * control ops entry point:
1203  *
1204  * Requests handled completely:
1205  *	DDI_CTLOPS_INITCHILD	see init_child() for details
1206  *	DDI_CTLOPS_UNINITCHILD
1207  *	DDI_CTLOPS_REPORTDEV	see report_dev() for details
1208  *	DDI_CTLOPS_IOMIN	cache line size if streaming otherwise 1
1209  *	DDI_CTLOPS_REGSIZE
1210  *	DDI_CTLOPS_NREGS
1211  *	DDI_CTLOPS_DVMAPAGESIZE
1212  *	DDI_CTLOPS_POKE
1213  *	DDI_CTLOPS_PEEK
1214  *
1215  * All others passed to parent.
1216  */
1217 int
1218 px_ctlops(dev_info_t *dip, dev_info_t *rdip,
1219 	ddi_ctl_enum_t op, void *arg, void *result)
1220 {
1221 	px_t *px_p = DIP_TO_STATE(dip);
1222 	struct detachspec *ds;
1223 	struct attachspec *as;
1224 
1225 	switch (op) {
1226 	case DDI_CTLOPS_INITCHILD:
1227 		return (px_init_child(px_p, (dev_info_t *)arg));
1228 
1229 	case DDI_CTLOPS_UNINITCHILD:
1230 		return (px_uninit_child(px_p, (dev_info_t *)arg));
1231 
1232 	case DDI_CTLOPS_ATTACH:
1233 		if (!pcie_is_child(dip, rdip))
1234 			return (DDI_SUCCESS);
1235 
1236 		as = (struct attachspec *)arg;
1237 		switch (as->when) {
1238 		case DDI_PRE:
1239 			if (as->cmd == DDI_ATTACH) {
1240 				DBG(DBG_PWR, dip, "PRE_ATTACH for %s@%d\n",
1241 				    ddi_driver_name(rdip),
1242 				    ddi_get_instance(rdip));
1243 				return (pcie_pm_hold(dip));
1244 			}
1245 			if (as->cmd == DDI_RESUME) {
1246 				DBG(DBG_PWR, dip, "PRE_RESUME for %s@%d\n",
1247 				    ddi_driver_name(rdip),
1248 				    ddi_get_instance(rdip));
1249 
1250 				pcie_clear_errors(rdip);
1251 			}
1252 			return (DDI_SUCCESS);
1253 
1254 		case DDI_POST:
1255 			DBG(DBG_PWR, dip, "POST_ATTACH for %s@%d\n",
1256 			    ddi_driver_name(rdip), ddi_get_instance(rdip));
1257 			if (as->cmd == DDI_ATTACH &&
1258 			    as->result != DDI_SUCCESS) {
1259 				/*
1260 				 * Attach failed for the child device. The child
1261 				 * driver may have made PM calls before the
1262 				 * attach failed. pcie_pm_remove_child() should
1263 				 * cleanup PM state and holds (if any)
1264 				 * associated with the child device.
1265 				 */
1266 				return (pcie_pm_remove_child(dip, rdip));
1267 			}
1268 
1269 			if (as->result == DDI_SUCCESS)
1270 				pf_init(rdip, (void *)px_p->px_fm_ibc, as->cmd);
1271 
1272 			(void) pcie_postattach_child(rdip);
1273 
1274 			return (DDI_SUCCESS);
1275 		default:
1276 			break;
1277 		}
1278 		break;
1279 
1280 	case DDI_CTLOPS_DETACH:
1281 		if (!pcie_is_child(dip, rdip))
1282 			return (DDI_SUCCESS);
1283 
1284 		ds = (struct detachspec *)arg;
1285 		switch (ds->when) {
1286 		case DDI_POST:
1287 			if (ds->cmd == DDI_DETACH &&
1288 			    ds->result == DDI_SUCCESS) {
1289 				DBG(DBG_PWR, dip, "POST_DETACH for %s@%d\n",
1290 				    ddi_driver_name(rdip),
1291 				    ddi_get_instance(rdip));
1292 				return (pcie_pm_remove_child(dip, rdip));
1293 			}
1294 			return (DDI_SUCCESS);
1295 		case DDI_PRE:
1296 			pf_fini(rdip, ds->cmd);
1297 			return (DDI_SUCCESS);
1298 		default:
1299 			break;
1300 		}
1301 		break;
1302 
1303 	case DDI_CTLOPS_REPORTDEV:
1304 		if (ddi_get_parent(rdip) == dip)
1305 			return (px_report_dev(rdip));
1306 
1307 		(void) px_lib_fabric_sync(rdip);
1308 		return (DDI_SUCCESS);
1309 
1310 	case DDI_CTLOPS_IOMIN:
1311 		return (DDI_SUCCESS);
1312 
1313 	case DDI_CTLOPS_REGSIZE:
1314 		*((off_t *)result) = px_get_reg_set_size(rdip, *((int *)arg));
1315 		return (*((off_t *)result) == 0 ? DDI_FAILURE : DDI_SUCCESS);
1316 
1317 	case DDI_CTLOPS_NREGS:
1318 		*((uint_t *)result) = px_get_nreg_set(rdip);
1319 		return (DDI_SUCCESS);
1320 
1321 	case DDI_CTLOPS_DVMAPAGESIZE:
1322 		*((ulong_t *)result) = MMU_PAGE_SIZE;
1323 		return (DDI_SUCCESS);
1324 
1325 	case DDI_CTLOPS_POKE:	/* platform dependent implementation. */
1326 		return (px_lib_ctlops_poke(dip, rdip,
1327 		    (peekpoke_ctlops_t *)arg));
1328 
1329 	case DDI_CTLOPS_PEEK:	/* platform dependent implementation. */
1330 		return (px_lib_ctlops_peek(dip, rdip,
1331 		    (peekpoke_ctlops_t *)arg, result));
1332 
1333 	case DDI_CTLOPS_POWER:
1334 	default:
1335 		break;
1336 	}
1337 
1338 	/*
1339 	 * Now pass the request up to our parent.
1340 	 */
1341 	DBG(DBG_CTLOPS, dip, "passing request to parent: rdip=%s%d\n",
1342 	    ddi_driver_name(rdip), ddi_get_instance(rdip));
1343 	return (ddi_ctlops(dip, rdip, op, arg, result));
1344 }
1345 
1346 /* ARGSUSED */
1347 int
1348 px_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
1349     ddi_intr_handle_impl_t *hdlp, void *result)
1350 {
1351 	int	intr_types, ret = DDI_SUCCESS;
1352 	px_t	*px_p = DIP_TO_STATE(dip);
1353 
1354 	DBG(DBG_INTROPS, dip, "px_intr_ops: rdip=%s%d\n",
1355 	    ddi_driver_name(rdip), ddi_get_instance(rdip));
1356 
1357 	/* Process DDI_INTROP_SUPPORTED_TYPES request here */
1358 	if (intr_op == DDI_INTROP_SUPPORTED_TYPES) {
1359 		*(int *)result = i_ddi_get_intx_nintrs(rdip) ?
1360 		    DDI_INTR_TYPE_FIXED : 0;
1361 
1362 		if ((pci_msi_get_supported_type(rdip,
1363 		    &intr_types)) == DDI_SUCCESS) {
1364 			/*
1365 			 * Double check supported interrupt types vs.
1366 			 * what the host bridge supports.
1367 			 */
1368 			*(int *)result |= intr_types;
1369 		}
1370 
1371 		*(int *)result &= px_p->px_supp_intr_types;
1372 		return (*(int *)result ? DDI_SUCCESS : DDI_FAILURE);
1373 	}
1374 
1375 	/*
1376 	 * PCI-E nexus driver supports fixed, MSI and MSI-X interrupts.
1377 	 * Return failure if interrupt type is not supported.
1378 	 */
1379 	switch (hdlp->ih_type) {
1380 	case DDI_INTR_TYPE_FIXED:
1381 		ret = px_intx_ops(dip, rdip, intr_op, hdlp, result);
1382 		break;
1383 	case DDI_INTR_TYPE_MSI:
1384 	case DDI_INTR_TYPE_MSIX:
1385 		ret = px_msix_ops(dip, rdip, intr_op, hdlp, result);
1386 		break;
1387 	default:
1388 		ret = DDI_ENOTSUP;
1389 		break;
1390 	}
1391 
1392 	return (ret);
1393 }
1394 
1395 static void
1396 px_set_mps(px_t *px_p)
1397 {
1398 	dev_info_t	*dip;
1399 	pcie_bus_t	*bus_p;
1400 	int		max_supported;
1401 
1402 	dip = px_p->px_dip;
1403 	bus_p = PCIE_DIP2BUS(dip);
1404 
1405 	bus_p->bus_mps = -1;
1406 
1407 	if (pcie_root_port(dip) == DDI_FAILURE) {
1408 		if (px_lib_get_root_complex_mps(px_p, dip,
1409 		    &max_supported) < 0) {
1410 
1411 			DBG(DBG_MPS, dip, "MPS:  Can not get RC MPS\n");
1412 			return;
1413 		}
1414 
1415 		DBG(DBG_MPS, dip, "MPS: Root Complex MPS Cap of = %x\n",
1416 		    max_supported);
1417 
1418 		if (pcie_max_mps < max_supported)
1419 			max_supported = pcie_max_mps;
1420 
1421 		(void) pcie_get_fabric_mps(dip, ddi_get_child(dip),
1422 		    &max_supported);
1423 
1424 		bus_p->bus_mps = max_supported;
1425 
1426 		(void) px_lib_set_root_complex_mps(px_p, dip, bus_p->bus_mps);
1427 
1428 		DBG(DBG_MPS, dip, "MPS: Root Complex MPS Set to = %x\n",
1429 		    bus_p->bus_mps);
1430 	}
1431 }
1432