13941Svenki /* 23941Svenki * CDDL HEADER START 33941Svenki * 43941Svenki * The contents of this file are subject to the terms of the 53941Svenki * Common Development and Distribution License (the "License"). 63941Svenki * You may not use this file except in compliance with the License. 73941Svenki * 83941Svenki * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 93941Svenki * or http://www.opensolaris.org/os/licensing. 103941Svenki * See the License for the specific language governing permissions 113941Svenki * and limitations under the License. 123941Svenki * 133941Svenki * When distributing Covered Code, include this CDDL HEADER in each 143941Svenki * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 153941Svenki * If applicable, add the following below this CDDL HEADER, with the 163941Svenki * fields enclosed by brackets "[]" replaced with your own identifying 173941Svenki * information: Portions Copyright [yyyy] [name of copyright owner] 183941Svenki * 193941Svenki * CDDL HEADER END 203941Svenki */ 213941Svenki 223941Svenki /* 233941Svenki * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 243941Svenki * Use is subject to license terms. 253941Svenki */ 263941Svenki 273941Svenki #pragma ident "%Z%%M% %I% %E% SMI" 283941Svenki 293941Svenki #include <sys/types.h> 303941Svenki #include <errno.h> 313941Svenki #include <malloc.h> 323941Svenki #include <mdesc.h> 333941Svenki #include <pri.h> 343941Svenki #include "priplugin.h" 353941Svenki 363941Svenki static void pri_free(void *bufp, size_t size); 37*4669Sfw157321 static uint64_t *md_bufp = NULL; 383941Svenki 393941Svenki md_t * 40*4669Sfw157321 pri_devinit(uint64_t *tok, md_t *mdp) 413941Svenki { 42*4669Sfw157321 uint64_t *new_md_bufp; 433941Svenki 443941Svenki 45*4669Sfw157321 if (pri_get(PRI_WAITGET, tok, &new_md_bufp, malloc, pri_free) == 46*4669Sfw157321 (ssize_t)-1) { 47*4669Sfw157321 pri_debug(LOG_NOTICE, "pri_devinit: can'r read from " 48*4669Sfw157321 "the PRI: %d\n", errno); 493941Svenki } 50*4669Sfw157321 if (new_md_bufp == NULL) { 51*4669Sfw157321 pri_debug(LOG_NOTICE, "pri_devinit: pri_get returned" 52*4669Sfw157321 "NULL buffer!\n"); 53*4669Sfw157321 } 54*4669Sfw157321 if (mdp) 55*4669Sfw157321 md_fini(mdp); 56*4669Sfw157321 if (md_bufp) 57*4669Sfw157321 free(md_bufp); 58*4669Sfw157321 md_bufp = new_md_bufp; 593941Svenki 603941Svenki pri_debug(LOG_NOTICE, "pri_devinit: done reading PRI\n"); 613941Svenki 623941Svenki /* 633941Svenki * The PRI and the MD use the same data format so they can be 643941Svenki * parsed by the same functions. 653941Svenki */ 663941Svenki if (md_bufp) { 673941Svenki mdp = md_init_intern(md_bufp, malloc, pri_free); 683941Svenki if (mdp == NULL) { 693941Svenki pri_debug(LOG_NOTICE, "pri_devinit: md_init_intern " 703941Svenki "failed\n"); 713941Svenki free(md_bufp); 723941Svenki md_bufp = NULL; 733941Svenki } else { 743941Svenki pri_debug(LOG_NOTICE, "pri_devinit: mdi_init_intern " 753941Svenki "completed successfully\n"); 763941Svenki } 773941Svenki } else 783941Svenki mdp = NULL; 793941Svenki 803941Svenki pri_debug(LOG_NOTICE, "pri_devinit: returning\n"); 813941Svenki 823941Svenki return (mdp); 833941Svenki } 843941Svenki 853941Svenki /*ARGSUSED*/ 863941Svenki static void 873941Svenki pri_free(void *bufp, size_t size) 883941Svenki { 893941Svenki if (bufp) 903941Svenki free(bufp); 913941Svenki } 923941Svenki 933941Svenki void 943941Svenki pri_devfini(md_t *mdp) 953941Svenki { 963941Svenki if (mdp) 973941Svenki (void) md_fini(mdp); 983941Svenki 993941Svenki if (md_bufp) 1003941Svenki free(md_bufp); 1013941Svenki md_bufp = NULL; 102*4669Sfw157321 pri_fini(); 1033941Svenki } 104