10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51618Srie * Common Development and Distribution License (the "License"). 61618Srie * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211618Srie 220Sstevel@tonic-gate /* 23*9273SAli.Bahrami@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* 280Sstevel@tonic-gate * String conversion routine for hardware capabilities types. 290Sstevel@tonic-gate */ 300Sstevel@tonic-gate #include <strings.h> 310Sstevel@tonic-gate #include <stdio.h> 320Sstevel@tonic-gate #include <elfcap.h> 331976Sab196087 #include "cap_msg.h" 340Sstevel@tonic-gate #include "_conv.h" 350Sstevel@tonic-gate 36*9273SAli.Bahrami@Sun.COM const conv_ds_t ** 37*9273SAli.Bahrami@Sun.COM conv_cap_tag_strings(Conv_fmt_flags_t fmt_flags) 380Sstevel@tonic-gate { 39*9273SAli.Bahrami@Sun.COM static const Msg tags_cf[] = { 40*9273SAli.Bahrami@Sun.COM MSG_CA_SUNW_NULL_CF, MSG_CA_SUNW_HW_1_CF, 41*9273SAli.Bahrami@Sun.COM MSG_CA_SUNW_SF_1_CF 42*9273SAli.Bahrami@Sun.COM }; 43*9273SAli.Bahrami@Sun.COM static const Msg tags_nf[] = { 44*9273SAli.Bahrami@Sun.COM MSG_CA_SUNW_NULL_NF, MSG_CA_SUNW_HW_1_NF, 45*9273SAli.Bahrami@Sun.COM MSG_CA_SUNW_SF_1_NF 46*9273SAli.Bahrami@Sun.COM }; 47*9273SAli.Bahrami@Sun.COM static const conv_ds_msg_t ds_tags_cf = { 48*9273SAli.Bahrami@Sun.COM CONV_DS_MSG_INIT(ELFCLASSNONE, tags_cf) }; 49*9273SAli.Bahrami@Sun.COM static const conv_ds_msg_t ds_tags_nf = { 50*9273SAli.Bahrami@Sun.COM CONV_DS_MSG_INIT(ELFCLASSNONE, tags_nf) }; 515088Sab196087 52*9273SAli.Bahrami@Sun.COM static const conv_ds_t *ds_cf[] = { CONV_DS_ADDR(ds_tags_cf), NULL }; 53*9273SAli.Bahrami@Sun.COM static const conv_ds_t *ds_nf[] = { CONV_DS_ADDR(ds_tags_nf), NULL }; 540Sstevel@tonic-gate 550Sstevel@tonic-gate 56*9273SAli.Bahrami@Sun.COM return ((CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF) ? 57*9273SAli.Bahrami@Sun.COM ds_nf : ds_cf); 58*9273SAli.Bahrami@Sun.COM } 59*9273SAli.Bahrami@Sun.COM 60*9273SAli.Bahrami@Sun.COM conv_iter_ret_t 61*9273SAli.Bahrami@Sun.COM conv_iter_cap_tags(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 62*9273SAli.Bahrami@Sun.COM void *uvalue) 63*9273SAli.Bahrami@Sun.COM { 64*9273SAli.Bahrami@Sun.COM return (conv_iter_ds(ELFOSABI_NONE, EM_NONE, 65*9273SAli.Bahrami@Sun.COM conv_cap_tag_strings(fmt_flags), func, uvalue)); 660Sstevel@tonic-gate } 670Sstevel@tonic-gate 68*9273SAli.Bahrami@Sun.COM /* 69*9273SAli.Bahrami@Sun.COM * Given an array of elfcap_desc_t, and a count, call the specified 70*9273SAli.Bahrami@Sun.COM * iteration for each value in the array. 71*9273SAli.Bahrami@Sun.COM */ 72*9273SAli.Bahrami@Sun.COM static conv_iter_ret_t 73*9273SAli.Bahrami@Sun.COM conv_iter_elfcap(const elfcap_desc_t *cdp, uint_t cnum, 74*9273SAli.Bahrami@Sun.COM Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, void *uvalue) 750Sstevel@tonic-gate { 76*9273SAli.Bahrami@Sun.COM const char *str; 77*9273SAli.Bahrami@Sun.COM 78*9273SAli.Bahrami@Sun.COM fmt_flags = CONV_TYPE_FMT_ALT(fmt_flags); 790Sstevel@tonic-gate 80*9273SAli.Bahrami@Sun.COM for (; cnum-- > 0; cdp++) { 81*9273SAli.Bahrami@Sun.COM /* 82*9273SAli.Bahrami@Sun.COM * Skip "reserved" bits. These are unassigned bits in the 83*9273SAli.Bahrami@Sun.COM * middle of the assigned range. 84*9273SAli.Bahrami@Sun.COM */ 85*9273SAli.Bahrami@Sun.COM if (cdp->c_val == 0) 86*9273SAli.Bahrami@Sun.COM continue; 870Sstevel@tonic-gate 88*9273SAli.Bahrami@Sun.COM switch (fmt_flags) { 89*9273SAli.Bahrami@Sun.COM default: 90*9273SAli.Bahrami@Sun.COM str = cdp->c_full.s_str; 91*9273SAli.Bahrami@Sun.COM break; 92*9273SAli.Bahrami@Sun.COM case CONV_FMT_ALT_CFNP: 93*9273SAli.Bahrami@Sun.COM str = cdp->c_uc.s_str; 94*9273SAli.Bahrami@Sun.COM break; 95*9273SAli.Bahrami@Sun.COM case CONV_FMT_ALT_NF: 96*9273SAli.Bahrami@Sun.COM str = cdp->c_lc.s_str; 97*9273SAli.Bahrami@Sun.COM break; 98*9273SAli.Bahrami@Sun.COM } 990Sstevel@tonic-gate 100*9273SAli.Bahrami@Sun.COM if ((* func)(str, cdp->c_val, uvalue) == CONV_ITER_DONE) 101*9273SAli.Bahrami@Sun.COM return (CONV_ITER_DONE); 102*9273SAli.Bahrami@Sun.COM } 103*9273SAli.Bahrami@Sun.COM 104*9273SAli.Bahrami@Sun.COM return (CONV_ITER_CONT); 1050Sstevel@tonic-gate } 1060Sstevel@tonic-gate 107*9273SAli.Bahrami@Sun.COM /* 108*9273SAli.Bahrami@Sun.COM * Iterate the strings for CA_SUNW_HW1 109*9273SAli.Bahrami@Sun.COM */ 110*9273SAli.Bahrami@Sun.COM conv_iter_ret_t 111*9273SAli.Bahrami@Sun.COM conv_iter_cap_val_hw1(Half mach, Conv_fmt_flags_t fmt_flags, 112*9273SAli.Bahrami@Sun.COM conv_iter_cb_t func, void *uvalue) 1130Sstevel@tonic-gate { 114*9273SAli.Bahrami@Sun.COM if ((mach == EM_386) || (mach == EM_486) || 115*9273SAli.Bahrami@Sun.COM (mach == EM_AMD64) || (mach == CONV_MACH_ALL)) 116*9273SAli.Bahrami@Sun.COM if (conv_iter_elfcap(elfcap_getdesc_hw1_386(), 117*9273SAli.Bahrami@Sun.COM ELFCAP_NUM_HW1_386, fmt_flags, func, uvalue) == 118*9273SAli.Bahrami@Sun.COM CONV_ITER_DONE) 119*9273SAli.Bahrami@Sun.COM return (CONV_ITER_DONE); 1200Sstevel@tonic-gate 121*9273SAli.Bahrami@Sun.COM if ((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) || 122*9273SAli.Bahrami@Sun.COM (mach == EM_SPARCV9) || (mach == CONV_MACH_ALL)) 123*9273SAli.Bahrami@Sun.COM if (conv_iter_elfcap(elfcap_getdesc_hw1_sparc(), 124*9273SAli.Bahrami@Sun.COM ELFCAP_NUM_HW1_SPARC, fmt_flags, func, uvalue) == 125*9273SAli.Bahrami@Sun.COM CONV_ITER_DONE) 126*9273SAli.Bahrami@Sun.COM return (CONV_ITER_DONE); 127*9273SAli.Bahrami@Sun.COM 128*9273SAli.Bahrami@Sun.COM return (CONV_ITER_CONT); 1290Sstevel@tonic-gate } 1300Sstevel@tonic-gate 131*9273SAli.Bahrami@Sun.COM /* 132*9273SAli.Bahrami@Sun.COM * Iterate the strings for CA_SUNW_SF1 133*9273SAli.Bahrami@Sun.COM */ 134*9273SAli.Bahrami@Sun.COM conv_iter_ret_t 135*9273SAli.Bahrami@Sun.COM conv_iter_cap_val_sf1(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 136*9273SAli.Bahrami@Sun.COM void *uvalue) 1370Sstevel@tonic-gate { 138*9273SAli.Bahrami@Sun.COM return (conv_iter_elfcap(elfcap_getdesc_sf1(), ELFCAP_NUM_SF1, 139*9273SAli.Bahrami@Sun.COM fmt_flags, func, uvalue)); 1400Sstevel@tonic-gate } 141