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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 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 * PX Fault Management Architecture support 31 * Minimal implementation for now. Needs to be filled out later 32 */ 33 #include <sys/types.h> 34 #include <sys/sunndi.h> 35 #include "px_obj.h" 36 37 static int px_fm_err_callback(dev_info_t *, ddi_fm_error_t *, const void *); 38 39 int 40 px_fm_attach(px_t *px_p) 41 { 42 px_p->px_fm_cap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE | 43 DDI_FM_ACCCHK_CAPABLE; 44 45 ddi_fm_init(px_p->px_dip, &px_p->px_fm_cap, &px_p->px_fm_ibc); 46 47 ddi_fm_handler_register(px_p->px_dip, px_fm_err_callback, px_p); 48 return (DDI_SUCCESS); 49 } 50 51 void 52 px_fm_detach(px_t *px_p) 53 { 54 ddi_fm_fini(px_p->px_dip); 55 } 56 57 /* 58 * Function used to setup access functions depending on level of desired 59 * protection. 60 */ 61 void 62 px_fm_acc_setup(ddi_map_req_t *mp, dev_info_t *rdip) 63 { 64 uchar_t fflag; 65 ddi_acc_hdl_t *hp; 66 ddi_acc_impl_t *ap; 67 68 hp = mp->map_handlep; 69 ap = (ddi_acc_impl_t *)hp->ah_platform_private; 70 fflag = ap->ahi_common.ah_acc.devacc_attr_access; 71 72 if (mp->map_op == DDI_MO_MAP_LOCKED) { 73 ndi_fmc_insert(rdip, ACC_HANDLE, (void *)hp, NULL); 74 switch (fflag) { 75 case DDI_FLAGERR_ACC: 76 ap->ahi_get8 = i_ddi_prot_get8; 77 ap->ahi_get16 = i_ddi_prot_get16; 78 ap->ahi_get32 = i_ddi_prot_get32; 79 ap->ahi_get64 = i_ddi_prot_get64; 80 ap->ahi_put8 = i_ddi_prot_put8; 81 ap->ahi_put16 = i_ddi_prot_put16; 82 ap->ahi_put32 = i_ddi_prot_put32; 83 ap->ahi_put64 = i_ddi_prot_put64; 84 ap->ahi_rep_get8 = i_ddi_prot_rep_get8; 85 ap->ahi_rep_get16 = i_ddi_prot_rep_get16; 86 ap->ahi_rep_get32 = i_ddi_prot_rep_get32; 87 ap->ahi_rep_get64 = i_ddi_prot_rep_get64; 88 ap->ahi_rep_put8 = i_ddi_prot_rep_put8; 89 ap->ahi_rep_put16 = i_ddi_prot_rep_put16; 90 ap->ahi_rep_put32 = i_ddi_prot_rep_put32; 91 ap->ahi_rep_put64 = i_ddi_prot_rep_put64; 92 break; 93 case DDI_CAUTIOUS_ACC : 94 ap->ahi_get8 = i_ddi_caut_get8; 95 ap->ahi_get16 = i_ddi_caut_get16; 96 ap->ahi_get32 = i_ddi_caut_get32; 97 ap->ahi_get64 = i_ddi_caut_get64; 98 ap->ahi_put8 = i_ddi_caut_put8; 99 ap->ahi_put16 = i_ddi_caut_put16; 100 ap->ahi_put32 = i_ddi_caut_put32; 101 ap->ahi_put64 = i_ddi_caut_put64; 102 ap->ahi_rep_get8 = i_ddi_caut_rep_get8; 103 ap->ahi_rep_get16 = i_ddi_caut_rep_get16; 104 ap->ahi_rep_get32 = i_ddi_caut_rep_get32; 105 ap->ahi_rep_get64 = i_ddi_caut_rep_get64; 106 ap->ahi_rep_put8 = i_ddi_caut_rep_put8; 107 ap->ahi_rep_put16 = i_ddi_caut_rep_put16; 108 ap->ahi_rep_put32 = i_ddi_caut_rep_put32; 109 ap->ahi_rep_put64 = i_ddi_caut_rep_put64; 110 break; 111 default: 112 break; 113 } 114 } else if (mp->map_op == DDI_MO_UNMAP) { 115 ndi_fmc_remove(rdip, ACC_HANDLE, (void *)hp); 116 } 117 } 118 119 /* 120 * Function used to initialize FMA for our children nodes. Called 121 * through pci busops when child node calls ddi_fm_init. 122 */ 123 /*ARGSUSED*/ 124 int 125 px_fm_init_child(dev_info_t *dip, dev_info_t *cdip, int cap, 126 ddi_iblock_cookie_t *ibc_p) 127 { 128 px_t *px_p = DIP_TO_STATE(dip); 129 130 ASSERT(ibc_p != NULL); 131 *ibc_p = px_p->px_fm_ibc; 132 133 return (px_p->px_fm_cap); 134 } 135 136 /* 137 * Error callback. 138 * Just call error handler for now. 139 */ 140 /*ARGSUSED*/ 141 static int 142 px_fm_err_callback(dev_info_t *dip, ddi_fm_error_t *derr, const void *impl_data) 143 { 144 return (px_fm_err_handler(dip, derr, impl_data)); 145 } 146 147 /* 148 * Error handler. 149 * Just pass error on to parent handler for now. 150 */ 151 /*ARGSUSED*/ 152 int 153 px_fm_err_handler(dev_info_t *rdip, ddi_fm_error_t *derr, const void *impl_data) 154 { 155 px_t *px_p = (px_t *)impl_data; 156 157 /* 158 * status comes in through derr->fme_flag and 159 * ((ddi_acc_impl_t *)(derr->fme_acc_handle))->ahi_err->err_expected 160 * 161 * XXX Handling to be filled in by FMA putback. 162 * 163 * Can only call ndi_fm_handler_dispatch with a dip of a device 164 * initialized with FMA. 165 */ 166 167 return (ndi_fm_handler_dispatch(px_p->px_dip, 168 ((derr->fme_acc_handle != NULL) ? rdip : NULL), derr)); 169 } 170