xref: /illumos-gate/usr/src/uts/sun4u/io/pci/pci_fm.c (revision 1f4c6dbc)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
500d0963fSdilpreet  * Common Development and Distribution License (the "License").
600d0963fSdilpreet  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2200d0963fSdilpreet  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
26*1f4c6dbcSPeter Tribble /*
27*1f4c6dbcSPeter Tribble  * Copyright 2019 Peter Tribble.
28*1f4c6dbcSPeter Tribble  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
327c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
337c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
347c478bd9Sstevel@tonic-gate #include <sys/async.h>
357c478bd9Sstevel@tonic-gate #include <sys/membar.h>
367c478bd9Sstevel@tonic-gate #include <sys/spl.h>
377c478bd9Sstevel@tonic-gate #include <sys/iommu.h>
387c478bd9Sstevel@tonic-gate #include <sys/pci/pci_obj.h>
397c478bd9Sstevel@tonic-gate #include <sys/fm/util.h>
407c478bd9Sstevel@tonic-gate #include <sys/fm/io/pci.h>
417c478bd9Sstevel@tonic-gate #include <sys/fm/io/ddi.h>
427c478bd9Sstevel@tonic-gate #include <sys/fm/io/sun4upci.h>
437c478bd9Sstevel@tonic-gate #include <sys/fm/protocol.h>
447c478bd9Sstevel@tonic-gate #include <sys/intr.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * The routines below are generic sun4u PCI interfaces to support
507c478bd9Sstevel@tonic-gate  * Fault Management.
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * pci_dma_check, pci_acc_check, pci_handle_lookup are functions used
537c478bd9Sstevel@tonic-gate  * to associate a captured PCI address to a particular dma/acc handle.
547c478bd9Sstevel@tonic-gate  *
557c478bd9Sstevel@tonic-gate  * pci_fm_acc_setup, pci_fm_init_child, pci_fm_create,
567c478bd9Sstevel@tonic-gate  * pci_fm_destroy are constructors/destructors used to setup and teardown
577c478bd9Sstevel@tonic-gate  * necessary resources.
587c478bd9Sstevel@tonic-gate  *
597c478bd9Sstevel@tonic-gate  * pci_bus_enter, pci_bus_exit are registered via busops and are used to
607c478bd9Sstevel@tonic-gate  * provide exclusive access to the PCI bus.
617c478bd9Sstevel@tonic-gate  *
627c478bd9Sstevel@tonic-gate  * pci_err_callback is the registered callback for PCI which is called
637c478bd9Sstevel@tonic-gate  * by the CPU code when it detects a UE/TO/BERR.
647c478bd9Sstevel@tonic-gate  *
657c478bd9Sstevel@tonic-gate  * pbm_ereport_post is used by the PBM code to generically report all
667c478bd9Sstevel@tonic-gate  * PBM errors.
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * Function used to setup access functions depending on level of desired
727c478bd9Sstevel@tonic-gate  * protection.
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate void
pci_fm_acc_setup(ddi_map_req_t * mp,dev_info_t * rdip)757c478bd9Sstevel@tonic-gate pci_fm_acc_setup(ddi_map_req_t *mp, dev_info_t *rdip)
767c478bd9Sstevel@tonic-gate {
777c478bd9Sstevel@tonic-gate 	uchar_t fflag;
787c478bd9Sstevel@tonic-gate 	ddi_acc_hdl_t *hp;
797c478bd9Sstevel@tonic-gate 	ddi_acc_impl_t *ap;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	hp = mp->map_handlep;
827c478bd9Sstevel@tonic-gate 	ap = (ddi_acc_impl_t *)hp->ah_platform_private;
837c478bd9Sstevel@tonic-gate 	fflag = ap->ahi_common.ah_acc.devacc_attr_access;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	if (mp->map_op == DDI_MO_MAP_LOCKED) {
867c478bd9Sstevel@tonic-gate 		ndi_fmc_insert(rdip, ACC_HANDLE, (void *)hp, NULL);
877c478bd9Sstevel@tonic-gate 		switch (fflag) {
887c478bd9Sstevel@tonic-gate 		case DDI_FLAGERR_ACC:
897c478bd9Sstevel@tonic-gate 			ap->ahi_get8 = i_ddi_prot_get8;
907c478bd9Sstevel@tonic-gate 			ap->ahi_get16 = i_ddi_prot_get16;
917c478bd9Sstevel@tonic-gate 			ap->ahi_get32 = i_ddi_prot_get32;
927c478bd9Sstevel@tonic-gate 			ap->ahi_get64 = i_ddi_prot_get64;
937c478bd9Sstevel@tonic-gate 			ap->ahi_put8 = i_ddi_prot_put8;
947c478bd9Sstevel@tonic-gate 			ap->ahi_put16 = i_ddi_prot_put16;
957c478bd9Sstevel@tonic-gate 			ap->ahi_put32 = i_ddi_prot_put32;
967c478bd9Sstevel@tonic-gate 			ap->ahi_put64 = i_ddi_prot_put64;
977c478bd9Sstevel@tonic-gate 			ap->ahi_rep_get8 = i_ddi_prot_rep_get8;
987c478bd9Sstevel@tonic-gate 			ap->ahi_rep_get16 = i_ddi_prot_rep_get16;
997c478bd9Sstevel@tonic-gate 			ap->ahi_rep_get32 = i_ddi_prot_rep_get32;
1007c478bd9Sstevel@tonic-gate 			ap->ahi_rep_get64 = i_ddi_prot_rep_get64;
1017c478bd9Sstevel@tonic-gate 			ap->ahi_rep_put8 = i_ddi_prot_rep_put8;
1027c478bd9Sstevel@tonic-gate 			ap->ahi_rep_put16 = i_ddi_prot_rep_put16;
1037c478bd9Sstevel@tonic-gate 			ap->ahi_rep_put32 = i_ddi_prot_rep_put32;
1047c478bd9Sstevel@tonic-gate 			ap->ahi_rep_put64 = i_ddi_prot_rep_put64;
1057c478bd9Sstevel@tonic-gate 			break;
1067c478bd9Sstevel@tonic-gate 		case DDI_CAUTIOUS_ACC :
1077c478bd9Sstevel@tonic-gate 			ap->ahi_get8 = i_ddi_caut_get8;
1087c478bd9Sstevel@tonic-gate 			ap->ahi_get16 = i_ddi_caut_get16;
1097c478bd9Sstevel@tonic-gate 			ap->ahi_get32 = i_ddi_caut_get32;
1107c478bd9Sstevel@tonic-gate 			ap->ahi_get64 = i_ddi_caut_get64;
1117c478bd9Sstevel@tonic-gate 			ap->ahi_put8 = i_ddi_caut_put8;
1127c478bd9Sstevel@tonic-gate 			ap->ahi_put16 = i_ddi_caut_put16;
1137c478bd9Sstevel@tonic-gate 			ap->ahi_put32 = i_ddi_caut_put32;
1147c478bd9Sstevel@tonic-gate 			ap->ahi_put64 = i_ddi_caut_put64;
1157c478bd9Sstevel@tonic-gate 			ap->ahi_rep_get8 = i_ddi_caut_rep_get8;
1167c478bd9Sstevel@tonic-gate 			ap->ahi_rep_get16 = i_ddi_caut_rep_get16;
1177c478bd9Sstevel@tonic-gate 			ap->ahi_rep_get32 = i_ddi_caut_rep_get32;
1187c478bd9Sstevel@tonic-gate 			ap->ahi_rep_get64 = i_ddi_caut_rep_get64;
1197c478bd9Sstevel@tonic-gate 			ap->ahi_rep_put8 = i_ddi_caut_rep_put8;
1207c478bd9Sstevel@tonic-gate 			ap->ahi_rep_put16 = i_ddi_caut_rep_put16;
1217c478bd9Sstevel@tonic-gate 			ap->ahi_rep_put32 = i_ddi_caut_rep_put32;
1227c478bd9Sstevel@tonic-gate 			ap->ahi_rep_put64 = i_ddi_caut_rep_put64;
1237c478bd9Sstevel@tonic-gate 			break;
1247c478bd9Sstevel@tonic-gate 		default:
1257c478bd9Sstevel@tonic-gate 			break;
1267c478bd9Sstevel@tonic-gate 		}
1277c478bd9Sstevel@tonic-gate 	} else if (mp->map_op == DDI_MO_UNMAP) {
1287c478bd9Sstevel@tonic-gate 		ndi_fmc_remove(rdip, ACC_HANDLE, (void *)hp);
1297c478bd9Sstevel@tonic-gate 	}
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate  * Function used to initialize FMA for our children nodes. Called
1347c478bd9Sstevel@tonic-gate  * through pci busops when child node calls ddi_fm_init.
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate /* ARGSUSED */
1377c478bd9Sstevel@tonic-gate int
pci_fm_init_child(dev_info_t * dip,dev_info_t * tdip,int cap,ddi_iblock_cookie_t * ibc)1387c478bd9Sstevel@tonic-gate pci_fm_init_child(dev_info_t *dip, dev_info_t *tdip, int cap,
1397c478bd9Sstevel@tonic-gate     ddi_iblock_cookie_t *ibc)
1407c478bd9Sstevel@tonic-gate {
1417c478bd9Sstevel@tonic-gate 	pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	ASSERT(ibc != NULL);
14400d0963fSdilpreet 	*ibc = pci_p->pci_fm_ibc;
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	return (pci_p->pci_fm_cap);
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate  * Lock accesses to the pci bus, to be able to protect against bus errors.
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate void
pci_bus_enter(dev_info_t * dip,ddi_acc_handle_t handle)1537c478bd9Sstevel@tonic-gate pci_bus_enter(dev_info_t *dip, ddi_acc_handle_t handle)
1547c478bd9Sstevel@tonic-gate {
1557c478bd9Sstevel@tonic-gate 	pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
1567c478bd9Sstevel@tonic-gate 	pbm_t *pbm_p = pci_p->pci_pbm_p;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	membar_sync();
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	mutex_enter(&pbm_p->pbm_pokefault_mutex);
1617c478bd9Sstevel@tonic-gate 	pbm_p->pbm_excl_handle = handle;
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate /*
1657c478bd9Sstevel@tonic-gate  * Unlock access to bus and clear errors before exiting.
1667c478bd9Sstevel@tonic-gate  */
1677c478bd9Sstevel@tonic-gate /* ARGSUSED */
1687c478bd9Sstevel@tonic-gate void
pci_bus_exit(dev_info_t * dip,ddi_acc_handle_t handle)1697c478bd9Sstevel@tonic-gate pci_bus_exit(dev_info_t *dip, ddi_acc_handle_t handle)
1707c478bd9Sstevel@tonic-gate {
1717c478bd9Sstevel@tonic-gate 	pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
1727c478bd9Sstevel@tonic-gate 	pbm_t *pbm_p = pci_p->pci_pbm_p;
1737c478bd9Sstevel@tonic-gate 	ddi_fm_error_t derr;
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&pbm_p->pbm_pokefault_mutex));
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	membar_sync();
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	mutex_enter(&pci_p->pci_common_p->pci_fm_mutex);
1807c478bd9Sstevel@tonic-gate 	ddi_fm_acc_err_get(pbm_p->pbm_excl_handle, &derr, DDI_FME_VERSION);
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	if (derr.fme_status == DDI_FM_OK) {
1837c478bd9Sstevel@tonic-gate 		if (pci_check_error(pci_p) != 0) {
1847c478bd9Sstevel@tonic-gate 			(void) pci_pbm_err_handler(pci_p->pci_dip, &derr,
185*1f4c6dbcSPeter Tribble 			    (const void *)pci_p, PCI_BUS_EXIT_CALL);
1867c478bd9Sstevel@tonic-gate 		}
1877c478bd9Sstevel@tonic-gate 	}
1887c478bd9Sstevel@tonic-gate 	mutex_exit(&pci_p->pci_common_p->pci_fm_mutex);
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	pbm_p->pbm_excl_handle = NULL;
1917c478bd9Sstevel@tonic-gate 	mutex_exit(&pbm_p->pbm_pokefault_mutex);
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate /*
1957c478bd9Sstevel@tonic-gate  * PCI error callback which is registered with our parent to call
1967c478bd9Sstevel@tonic-gate  * for PCI logging when the CPU traps due to BERR/TO/UE.
1977c478bd9Sstevel@tonic-gate  */
1987c478bd9Sstevel@tonic-gate int
pci_err_callback(dev_info_t * dip,ddi_fm_error_t * derr,const void * impl_data)1997c478bd9Sstevel@tonic-gate pci_err_callback(dev_info_t *dip, ddi_fm_error_t *derr,
2007c478bd9Sstevel@tonic-gate     const void *impl_data)
2017c478bd9Sstevel@tonic-gate {
2027c478bd9Sstevel@tonic-gate 	pci_t *pci_p = (pci_t *)impl_data;
2037c478bd9Sstevel@tonic-gate 	pci_common_t *cmn_p = pci_p->pci_common_p;
2047c478bd9Sstevel@tonic-gate 	ecc_t *ecc_p = cmn_p->pci_common_ecc_p;
2057c478bd9Sstevel@tonic-gate 	ecc_errstate_t ecc_err;
2067c478bd9Sstevel@tonic-gate 	int fatal = 0;
2077c478bd9Sstevel@tonic-gate 	int nonfatal = 0;
2087c478bd9Sstevel@tonic-gate 	int unknown = 0;
2097c478bd9Sstevel@tonic-gate 	int ret = DDI_FM_OK;
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	bzero(&ecc_err, sizeof (ecc_err));
2127c478bd9Sstevel@tonic-gate 	mutex_enter(&cmn_p->pci_fm_mutex);
2137c478bd9Sstevel@tonic-gate 	/*
2147c478bd9Sstevel@tonic-gate 	 * Check and log ecc and pbm errors
2157c478bd9Sstevel@tonic-gate 	 */
2167c478bd9Sstevel@tonic-gate 	ecc_err.ecc_ii_p = ecc_p->ecc_ue;
2177c478bd9Sstevel@tonic-gate 	ecc_err.ecc_ena = derr->fme_ena;
2187c478bd9Sstevel@tonic-gate 	ecc_err.ecc_caller = PCI_TRAP_CALL;
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	if ((ret = ecc_err_handler(&ecc_err)) == DDI_FM_FATAL)
2217c478bd9Sstevel@tonic-gate 		fatal++;
2227c478bd9Sstevel@tonic-gate 	else if (ret == DDI_FM_NONFATAL)
2237c478bd9Sstevel@tonic-gate 		nonfatal++;
2247c478bd9Sstevel@tonic-gate 	else if (ret == DDI_FM_UNKNOWN)
2257c478bd9Sstevel@tonic-gate 		unknown++;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	if (pci_check_error(pci_p) != 0) {
2287c478bd9Sstevel@tonic-gate 		int err = pci_pbm_err_handler(pci_p->pci_dip, derr,
229*1f4c6dbcSPeter Tribble 		    (const void *)pci_p, PCI_TRAP_CALL);
2307c478bd9Sstevel@tonic-gate 		if (err == DDI_FM_FATAL)
2317c478bd9Sstevel@tonic-gate 			fatal++;
2327c478bd9Sstevel@tonic-gate 		else if (err == DDI_FM_NONFATAL)
2337c478bd9Sstevel@tonic-gate 			nonfatal++;
2347c478bd9Sstevel@tonic-gate 		else if (err == DDI_FM_UNKNOWN)
2357c478bd9Sstevel@tonic-gate 			unknown++;
2367c478bd9Sstevel@tonic-gate 	}
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 	mutex_exit(&cmn_p->pci_fm_mutex);
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 	if (fatal)
2417c478bd9Sstevel@tonic-gate 		return (DDI_FM_FATAL);
2427c478bd9Sstevel@tonic-gate 	else if (nonfatal)
2437c478bd9Sstevel@tonic-gate 		return (DDI_FM_NONFATAL);
2447c478bd9Sstevel@tonic-gate 	else if (unknown)
2457c478bd9Sstevel@tonic-gate 		return (DDI_FM_UNKNOWN);
2467c478bd9Sstevel@tonic-gate 	else
2477c478bd9Sstevel@tonic-gate 		return (DDI_FM_OK);
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate void
pci_fm_create(pci_t * pci_p)2517c478bd9Sstevel@tonic-gate pci_fm_create(pci_t *pci_p)
2527c478bd9Sstevel@tonic-gate {
2537c478bd9Sstevel@tonic-gate 	pci_common_t *cmn_p = pci_p->pci_common_p;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	/*
2567c478bd9Sstevel@tonic-gate 	 * PCI detected ECC errorq, to schedule async handling
2577c478bd9Sstevel@tonic-gate 	 * of ECC errors and logging.
2587c478bd9Sstevel@tonic-gate 	 * The errorq is created here but destroyed when _fini is called
2597c478bd9Sstevel@tonic-gate 	 * for the pci module.
2607c478bd9Sstevel@tonic-gate 	 */
2617c478bd9Sstevel@tonic-gate 	if (pci_ecc_queue == NULL) {
2627c478bd9Sstevel@tonic-gate 		pci_ecc_queue = errorq_create("pci_ecc_queue",
263*1f4c6dbcSPeter Tribble 		    (errorq_func_t)ecc_err_drain,
264*1f4c6dbcSPeter Tribble 		    (void *)pci_p->pci_ecc_p,
265*1f4c6dbcSPeter Tribble 		    ECC_MAX_ERRS, sizeof (ecc_errstate_t),
266*1f4c6dbcSPeter Tribble 		    PIL_2, ERRORQ_VITAL);
2677c478bd9Sstevel@tonic-gate 		if (pci_ecc_queue == NULL)
2687c478bd9Sstevel@tonic-gate 			panic("failed to create required system error queue");
2697c478bd9Sstevel@tonic-gate 	}
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 	/*
27200d0963fSdilpreet 	 * Initialize pci_target_queue for FMA handling of pci errors.
2737c478bd9Sstevel@tonic-gate 	 */
27400d0963fSdilpreet 	pci_targetq_init();
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate 	/*
2777c478bd9Sstevel@tonic-gate 	 * Initialize FMA support
2787c478bd9Sstevel@tonic-gate 	 */
279*1f4c6dbcSPeter Tribble 	pci_p->pci_fm_cap = DDI_FM_EREPORT_CAPABLE |
280*1f4c6dbcSPeter Tribble 	    DDI_FM_ACCCHK_CAPABLE | DDI_FM_DMACHK_CAPABLE |
281*1f4c6dbcSPeter Tribble 	    DDI_FM_ERRCB_CAPABLE;
2827c478bd9Sstevel@tonic-gate 	/*
2837c478bd9Sstevel@tonic-gate 	 * Call parent to get it's capablity
2847c478bd9Sstevel@tonic-gate 	 */
2857c478bd9Sstevel@tonic-gate 	ddi_fm_init(pci_p->pci_dip, &pci_p->pci_fm_cap,
286*1f4c6dbcSPeter Tribble 	    &pci_p->pci_fm_ibc);
2877c478bd9Sstevel@tonic-gate 	/*
2887c478bd9Sstevel@tonic-gate 	 * Need to be ereport and error handler cabable
2897c478bd9Sstevel@tonic-gate 	 */
2907c478bd9Sstevel@tonic-gate 	ASSERT((pci_p->pci_fm_cap & DDI_FM_ERRCB_CAPABLE) &&
2917c478bd9Sstevel@tonic-gate 	    (pci_p->pci_fm_cap & DDI_FM_EREPORT_CAPABLE));
2927c478bd9Sstevel@tonic-gate 	/*
2937c478bd9Sstevel@tonic-gate 	 * Initialize error handling mutex.
2947c478bd9Sstevel@tonic-gate 	 */
2957c478bd9Sstevel@tonic-gate 	if (cmn_p->pci_common_refcnt == 0) {
2967c478bd9Sstevel@tonic-gate 		mutex_init(&cmn_p->pci_fm_mutex, NULL, MUTEX_DRIVER,
297*1f4c6dbcSPeter Tribble 		    (void *)pci_p->pci_fm_ibc);
2987c478bd9Sstevel@tonic-gate 	}
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	/*
3017c478bd9Sstevel@tonic-gate 	 * Register error callback with our parent.
3027c478bd9Sstevel@tonic-gate 	 */
303*1f4c6dbcSPeter Tribble 	ddi_fm_handler_register(pci_p->pci_dip, pci_err_callback, pci_p);
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate void
pci_fm_destroy(pci_t * pci_p)3087c478bd9Sstevel@tonic-gate pci_fm_destroy(pci_t *pci_p)
3097c478bd9Sstevel@tonic-gate {
3107c478bd9Sstevel@tonic-gate 	pci_common_t *cmn_p = pci_p->pci_common_p;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	/* schizo non-shared objects */
3137c478bd9Sstevel@tonic-gate 	ddi_fm_handler_unregister(pci_p->pci_dip);
3147c478bd9Sstevel@tonic-gate 	ddi_fm_fini(pci_p->pci_dip);
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	if (cmn_p->pci_common_refcnt != 0)
3177c478bd9Sstevel@tonic-gate 		return;
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	mutex_destroy(&cmn_p->pci_fm_mutex);
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate /*
3237c478bd9Sstevel@tonic-gate  * Function used to post PCI block module specific ereports.
3247c478bd9Sstevel@tonic-gate  */
3257c478bd9Sstevel@tonic-gate void
pbm_ereport_post(dev_info_t * dip,uint64_t ena,pbm_errstate_t * pbm_err)3267c478bd9Sstevel@tonic-gate pbm_ereport_post(dev_info_t *dip, uint64_t ena, pbm_errstate_t *pbm_err)
3277c478bd9Sstevel@tonic-gate {
3287c478bd9Sstevel@tonic-gate 	char buf[FM_MAX_CLASS];
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, FM_MAX_CLASS, "%s.%s",
3317c478bd9Sstevel@tonic-gate 	    pbm_err->pbm_bridge_type, pbm_err->pbm_err_class);
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	ena = ena ? ena : fm_ena_generate(0, FM_ENA_FMT1);
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	ddi_fm_ereport_post(dip, buf, ena, DDI_NOSLEEP,
3367c478bd9Sstevel@tonic-gate 	    FM_VERSION, DATA_TYPE_UINT8, 0,
3377c478bd9Sstevel@tonic-gate 	    PCI_CONFIG_STATUS, DATA_TYPE_UINT16, pbm_err->pbm_pci.pci_cfg_stat,
3387c478bd9Sstevel@tonic-gate 	    PCI_CONFIG_COMMAND, DATA_TYPE_UINT16, pbm_err->pbm_pci.pci_cfg_comm,
3397c478bd9Sstevel@tonic-gate 	    PCI_PBM_CSR, DATA_TYPE_UINT64, pbm_err->pbm_ctl_stat,
3407c478bd9Sstevel@tonic-gate 	    PCI_PBM_AFSR, DATA_TYPE_UINT64, pbm_err->pbm_afsr,
3417c478bd9Sstevel@tonic-gate 	    PCI_PBM_AFAR, DATA_TYPE_UINT64, pbm_err->pbm_afar,
3427c478bd9Sstevel@tonic-gate 	    PCI_PBM_SLOT, DATA_TYPE_UINT64, pbm_err->pbm_err_sl,
3437c478bd9Sstevel@tonic-gate 	    PCI_PBM_VALOG, DATA_TYPE_UINT64, pbm_err->pbm_va_log,
3447c478bd9Sstevel@tonic-gate 	    NULL);
3457c478bd9Sstevel@tonic-gate }
346