1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1999-2000 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * s1394.c 31*7c478bd9Sstevel@tonic-gate * 1394 Services Layer Initialization and Cleanup Routines 32*7c478bd9Sstevel@tonic-gate * The routines do all initialization and cleanup for the Sevices Layer 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #include <sys/conf.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/tnf_probe.h> 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #include <sys/1394/t1394.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/1394/s1394.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/1394/h1394.h> 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate /* Driver State Pointer */ 47*7c478bd9Sstevel@tonic-gate s1394_state_t *s1394_statep; 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate /* Module Driver Info */ 50*7c478bd9Sstevel@tonic-gate static struct modlmisc s1394_modlmisc = { 51*7c478bd9Sstevel@tonic-gate &mod_miscops, 52*7c478bd9Sstevel@tonic-gate "IEEE 1394 Services Library 1.0" 53*7c478bd9Sstevel@tonic-gate }; 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate /* Module Linkage */ 56*7c478bd9Sstevel@tonic-gate static struct modlinkage s1394_modlinkage = { 57*7c478bd9Sstevel@tonic-gate MODREV_1, 58*7c478bd9Sstevel@tonic-gate &s1394_modlmisc, 59*7c478bd9Sstevel@tonic-gate NULL 60*7c478bd9Sstevel@tonic-gate }; 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate static int s1394_init(); 63*7c478bd9Sstevel@tonic-gate static void s1394_fini(); 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate #ifndef NPROBE 66*7c478bd9Sstevel@tonic-gate extern int tnf_mod_load(void); 67*7c478bd9Sstevel@tonic-gate extern int tnf_mod_unload(struct modlinkage *mlp); 68*7c478bd9Sstevel@tonic-gate #endif 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate int 71*7c478bd9Sstevel@tonic-gate _init() 72*7c478bd9Sstevel@tonic-gate { 73*7c478bd9Sstevel@tonic-gate int status; 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate #ifndef NPROBE 76*7c478bd9Sstevel@tonic-gate (void) tnf_mod_load(); 77*7c478bd9Sstevel@tonic-gate #endif 78*7c478bd9Sstevel@tonic-gate status = s1394_init(); 79*7c478bd9Sstevel@tonic-gate if (status != 0) { 80*7c478bd9Sstevel@tonic-gate TNF_PROBE_1(_init_error, S1394_TNF_SL_ERROR, "", 81*7c478bd9Sstevel@tonic-gate tnf_string, msg, "s1394: failed in s1394_init"); 82*7c478bd9Sstevel@tonic-gate #ifndef NPROBE 83*7c478bd9Sstevel@tonic-gate (void) tnf_mod_unload(&s1394_modlinkage); 84*7c478bd9Sstevel@tonic-gate #endif 85*7c478bd9Sstevel@tonic-gate return (status); 86*7c478bd9Sstevel@tonic-gate } 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate status = mod_install(&s1394_modlinkage); 89*7c478bd9Sstevel@tonic-gate if (status != 0) { 90*7c478bd9Sstevel@tonic-gate TNF_PROBE_1(_init_error, S1394_TNF_SL_ERROR, "", 91*7c478bd9Sstevel@tonic-gate tnf_string, msg, "s1394: failed in mod_install"); 92*7c478bd9Sstevel@tonic-gate #ifndef NPROBE 93*7c478bd9Sstevel@tonic-gate (void) tnf_mod_unload(&s1394_modlinkage); 94*7c478bd9Sstevel@tonic-gate #endif 95*7c478bd9Sstevel@tonic-gate } 96*7c478bd9Sstevel@tonic-gate return (status); 97*7c478bd9Sstevel@tonic-gate } 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate int 100*7c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 101*7c478bd9Sstevel@tonic-gate { 102*7c478bd9Sstevel@tonic-gate return (mod_info(&s1394_modlinkage, modinfop)); 103*7c478bd9Sstevel@tonic-gate } 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate int 106*7c478bd9Sstevel@tonic-gate _fini() 107*7c478bd9Sstevel@tonic-gate { 108*7c478bd9Sstevel@tonic-gate int status; 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate status = mod_remove(&s1394_modlinkage); 111*7c478bd9Sstevel@tonic-gate if (status != 0) { 112*7c478bd9Sstevel@tonic-gate TNF_PROBE_1(_fini_error, S1394_TNF_SL_ERROR, "", 113*7c478bd9Sstevel@tonic-gate tnf_string, msg, "s1394: failed in mod_remove"); 114*7c478bd9Sstevel@tonic-gate return (status); 115*7c478bd9Sstevel@tonic-gate } 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate s1394_fini(); 118*7c478bd9Sstevel@tonic-gate #ifndef NPROBE 119*7c478bd9Sstevel@tonic-gate (void) tnf_mod_unload(&s1394_modlinkage); 120*7c478bd9Sstevel@tonic-gate #endif 121*7c478bd9Sstevel@tonic-gate return (status); 122*7c478bd9Sstevel@tonic-gate } 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate /* 125*7c478bd9Sstevel@tonic-gate * s1394_init() 126*7c478bd9Sstevel@tonic-gate * initializes the 1394 Software Framework's structures, i.e. the HAL list 127*7c478bd9Sstevel@tonic-gate * and associated mutex. 128*7c478bd9Sstevel@tonic-gate */ 129*7c478bd9Sstevel@tonic-gate static int 130*7c478bd9Sstevel@tonic-gate s1394_init() 131*7c478bd9Sstevel@tonic-gate { 132*7c478bd9Sstevel@tonic-gate TNF_PROBE_0_DEBUG(s1394_init_enter, S1394_TNF_SL_STACK, ""); 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate s1394_statep = kmem_zalloc(sizeof (s1394_state_t), KM_SLEEP); 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate s1394_statep->hal_head = NULL; 137*7c478bd9Sstevel@tonic-gate s1394_statep->hal_tail = NULL; 138*7c478bd9Sstevel@tonic-gate mutex_init(&s1394_statep->hal_list_mutex, NULL, MUTEX_DRIVER, NULL); 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate TNF_PROBE_0_DEBUG(s1394_init_exit, S1394_TNF_SL_STACK, ""); 141*7c478bd9Sstevel@tonic-gate return (0); 142*7c478bd9Sstevel@tonic-gate } 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate /* 145*7c478bd9Sstevel@tonic-gate * s1394_fini() 146*7c478bd9Sstevel@tonic-gate * cleans up the 1394 Software Framework's structures that were allocated 147*7c478bd9Sstevel@tonic-gate * in s1394_init(). 148*7c478bd9Sstevel@tonic-gate */ 149*7c478bd9Sstevel@tonic-gate static void 150*7c478bd9Sstevel@tonic-gate s1394_fini() 151*7c478bd9Sstevel@tonic-gate { 152*7c478bd9Sstevel@tonic-gate TNF_PROBE_0_DEBUG(s1394_fini_enter, S1394_TNF_SL_STACK, ""); 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate mutex_destroy(&s1394_statep->hal_list_mutex); 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate kmem_free(s1394_statep, sizeof (s1394_state_t)); 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate TNF_PROBE_0_DEBUG(s1394_fini_exit, S1394_TNF_SL_STACK, ""); 159*7c478bd9Sstevel@tonic-gate } 160