10d63ce2bSvenki /* 20d63ce2bSvenki * CDDL HEADER START 30d63ce2bSvenki * 40d63ce2bSvenki * The contents of this file are subject to the terms of the 50d63ce2bSvenki * Common Development and Distribution License (the "License"). 60d63ce2bSvenki * You may not use this file except in compliance with the License. 70d63ce2bSvenki * 80d63ce2bSvenki * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90d63ce2bSvenki * or http://www.opensolaris.org/os/licensing. 100d63ce2bSvenki * See the License for the specific language governing permissions 110d63ce2bSvenki * and limitations under the License. 120d63ce2bSvenki * 130d63ce2bSvenki * When distributing Covered Code, include this CDDL HEADER in each 140d63ce2bSvenki * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150d63ce2bSvenki * If applicable, add the following below this CDDL HEADER, with the 160d63ce2bSvenki * fields enclosed by brackets "[]" replaced with your own identifying 170d63ce2bSvenki * information: Portions Copyright [yyyy] [name of copyright owner] 180d63ce2bSvenki * 190d63ce2bSvenki * CDDL HEADER END 200d63ce2bSvenki */ 210d63ce2bSvenki 220d63ce2bSvenki /* 230d63ce2bSvenki * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 240d63ce2bSvenki * Use is subject to license terms. 250d63ce2bSvenki */ 260d63ce2bSvenki 270d63ce2bSvenki #pragma ident "%Z%%M% %I% %E% SMI" 280d63ce2bSvenki 290d63ce2bSvenki #include <sys/types.h> 300d63ce2bSvenki #include <errno.h> 310d63ce2bSvenki #include <malloc.h> 320d63ce2bSvenki #include <mdesc.h> 330d63ce2bSvenki #include <pri.h> 340d63ce2bSvenki #include "priplugin.h" 350d63ce2bSvenki 360d63ce2bSvenki static void pri_free(void *bufp, size_t size); 37a90d965dSfw157321 static uint64_t *md_bufp = NULL; 38*d2b9c676Sfw157321 static uint64_t *new_md_bufp; 390d63ce2bSvenki 40*d2b9c676Sfw157321 int 41*d2b9c676Sfw157321 pri_devinit(uint64_t *tok) 420d63ce2bSvenki { 43*d2b9c676Sfw157321 int status; 440d63ce2bSvenki 45*d2b9c676Sfw157321 new_md_bufp = NULL; 46*d2b9c676Sfw157321 status = 0; 47a90d965dSfw157321 if (pri_get(PRI_WAITGET, tok, &new_md_bufp, malloc, pri_free) == 480d63ce2bSvenki (ssize_t)-1) { 490d63ce2bSvenki pri_debug(LOG_NOTICE, "pri_devinit: can'r read from " 500d63ce2bSvenki "the PRI: %d\n", errno); 51*d2b9c676Sfw157321 status = -1; 520d63ce2bSvenki } 53a90d965dSfw157321 if (new_md_bufp == NULL) { 540d63ce2bSvenki pri_debug(LOG_NOTICE, "pri_devinit: pri_get returned " 550d63ce2bSvenki "NULL buffer!\n"); 56*d2b9c676Sfw157321 status = -1; 570d63ce2bSvenki } 58*d2b9c676Sfw157321 return (status); 59*d2b9c676Sfw157321 } 60*d2b9c676Sfw157321 61*d2b9c676Sfw157321 md_t * 62*d2b9c676Sfw157321 pri_bufinit(md_t *mdp) 63*d2b9c676Sfw157321 { 64*d2b9c676Sfw157321 65a90d965dSfw157321 if (mdp) 66a90d965dSfw157321 md_fini(mdp); 67a90d965dSfw157321 if (md_bufp) 68a90d965dSfw157321 free(md_bufp); 69a90d965dSfw157321 md_bufp = new_md_bufp; 700d63ce2bSvenki 71*d2b9c676Sfw157321 pri_debug(LOG_NOTICE, "pri_bufinit: done reading PRI\n"); 720d63ce2bSvenki 730d63ce2bSvenki /* 740d63ce2bSvenki * The PRI and the MD use the same data format so they can be 750d63ce2bSvenki * parsed by the same functions. 760d63ce2bSvenki */ 770d63ce2bSvenki if (md_bufp) { 780d63ce2bSvenki mdp = md_init_intern(md_bufp, malloc, pri_free); 790d63ce2bSvenki if (mdp == NULL) { 80*d2b9c676Sfw157321 pri_debug(LOG_NOTICE, "pri_bufinit: md_init_intern " 810d63ce2bSvenki "failed\n"); 820d63ce2bSvenki free(md_bufp); 830d63ce2bSvenki md_bufp = NULL; 840d63ce2bSvenki } else { 85*d2b9c676Sfw157321 pri_debug(LOG_NOTICE, "pri_bufinit: mdi_init_intern " 860d63ce2bSvenki "completed successfully\n"); 870d63ce2bSvenki } 880d63ce2bSvenki } else 890d63ce2bSvenki mdp = NULL; 900d63ce2bSvenki 91*d2b9c676Sfw157321 pri_debug(LOG_NOTICE, "pri_bufinit: returning\n"); 920d63ce2bSvenki 930d63ce2bSvenki return (mdp); 940d63ce2bSvenki } 950d63ce2bSvenki 960d63ce2bSvenki /*ARGSUSED*/ 970d63ce2bSvenki static void 980d63ce2bSvenki pri_free(void *bufp, size_t size) 990d63ce2bSvenki { 1000d63ce2bSvenki if (bufp) 1010d63ce2bSvenki free(bufp); 1020d63ce2bSvenki } 1030d63ce2bSvenki 1040d63ce2bSvenki void 1050d63ce2bSvenki pri_devfini(md_t *mdp) 1060d63ce2bSvenki { 1070d63ce2bSvenki if (mdp) 1080d63ce2bSvenki (void) md_fini(mdp); 1090d63ce2bSvenki 1100d63ce2bSvenki if (md_bufp) 1110d63ce2bSvenki free(md_bufp); 1120d63ce2bSvenki md_bufp = NULL; 1130d63ce2bSvenki } 114