1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1994, by Sun Microsytems, Inc. 24*0Sstevel@tonic-gate */ 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate #ifndef _TNF_BUF_H 27*0Sstevel@tonic-gate #define _TNF_BUF_H 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #ifdef _KERNEL 32*0Sstevel@tonic-gate #include <sys/tnf_com.h> 33*0Sstevel@tonic-gate #else /* _KERNEL */ 34*0Sstevel@tonic-gate #include <tnf/com.h> 35*0Sstevel@tonic-gate #endif 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate #ifdef __cplusplus 38*0Sstevel@tonic-gate extern "C" { 39*0Sstevel@tonic-gate #endif 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate /* 42*0Sstevel@tonic-gate * Size of the file header and forwarding pointer (directory) area combined. 43*0Sstevel@tonic-gate * Tag and data blocks start this many bytes into the file. 44*0Sstevel@tonic-gate * 45*0Sstevel@tonic-gate * The kernel uses a smaller directory area, and uses the saved space 46*0Sstevel@tonic-gate * as block pool reserved for tag allocations. 47*0Sstevel@tonic-gate */ 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate #ifdef _KERNEL 50*0Sstevel@tonic-gate #define TNFW_B_FW_ZONE 0x4000 51*0Sstevel@tonic-gate #define TNFW_B_TAG_RESERVE 0xc000 52*0Sstevel@tonic-gate #else 53*0Sstevel@tonic-gate #define TNFW_B_FW_ZONE 0x10000 54*0Sstevel@tonic-gate #define TNFW_B_TAG_RESERVE 0x8000 55*0Sstevel@tonic-gate #endif 56*0Sstevel@tonic-gate #define TNFW_B_DATA_BLOCK_BEGIN (TNFW_B_FW_ZONE + TNFW_B_TAG_RESERVE) 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate /* 59*0Sstevel@tonic-gate * CAUTION: do not change integer values of TNF_ALLOC_REUSABLE or 60*0Sstevel@tonic-gate * TNF_ALLOC_FIXED 61*0Sstevel@tonic-gate */ 62*0Sstevel@tonic-gate enum tnf_alloc_mode { 63*0Sstevel@tonic-gate TNF_ALLOC_REUSABLE = 0, 64*0Sstevel@tonic-gate TNF_ALLOC_FIXED 65*0Sstevel@tonic-gate }; 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate typedef struct { 68*0Sstevel@tonic-gate tnf_uint32_t magic; 69*0Sstevel@tonic-gate tnf_file_header_t com; 70*0Sstevel@tonic-gate struct { 71*0Sstevel@tonic-gate uint_t hi; 72*0Sstevel@tonic-gate uint_t lo[2]; 73*0Sstevel@tonic-gate } next_alloc; 74*0Sstevel@tonic-gate uint_t next_tag_alloc; 75*0Sstevel@tonic-gate uint_t next_fw_alloc; 76*0Sstevel@tonic-gate } tnf_buf_file_header_t; 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate typedef struct tnfw_b_pos TNFW_B_POS; 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate struct tnfw_b_pos { 81*0Sstevel@tonic-gate tnf_block_header_t *tnfw_w_block; 82*0Sstevel@tonic-gate tnf_block_header_t *tnfw_w_uncommitted; 83*0Sstevel@tonic-gate short tnfw_w_write_off; 84*0Sstevel@tonic-gate }; 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate typedef struct { 87*0Sstevel@tonic-gate boolean_t tnfw_w_initialized; 88*0Sstevel@tonic-gate struct tnfw_b_pos tnfw_w_pos; 89*0Sstevel@tonic-gate struct tnfw_b_pos tnfw_w_tag_pos; 90*0Sstevel@tonic-gate int tnfw_w_gen_shift; 91*0Sstevel@tonic-gate int tnfw_w_block_shift; 92*0Sstevel@tonic-gate pid_t tnfw_w_pid; 93*0Sstevel@tonic-gate u_long tnfw_w_block_size; 94*0Sstevel@tonic-gate #ifdef TNFWB_MAY_RELEASE_A_LOCK 95*0Sstevel@tonic-gate u_long tnfw_w_generation; 96*0Sstevel@tonic-gate boolean_t tnfw_w_a_lock_released; 97*0Sstevel@tonic-gate #endif 98*0Sstevel@tonic-gate } TNFW_B_WCB; 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate typedef enum { 101*0Sstevel@tonic-gate TNFW_B_OK, 102*0Sstevel@tonic-gate TNFW_B_NOTCONN, 103*0Sstevel@tonic-gate TNFW_B_ACKPHT, 104*0Sstevel@tonic-gate TNFW_B_NO_ALLOC, 105*0Sstevel@tonic-gate TNFW_B_NO_SPACE, 106*0Sstevel@tonic-gate TNFW_B_BAD_BLOCK_SIZE, 107*0Sstevel@tonic-gate TNFW_B_BAD_BLOCK_COUNT, 108*0Sstevel@tonic-gate TNFW_B_RECORD_TOO_BIG 109*0Sstevel@tonic-gate } TNFW_B_STATUS; 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate typedef enum { 112*0Sstevel@tonic-gate TNFW_B_RUNNING = 0, 113*0Sstevel@tonic-gate TNFW_B_NOBUFFER, 114*0Sstevel@tonic-gate TNFW_B_FORKED, 115*0Sstevel@tonic-gate TNFW_B_BROKEN 116*0Sstevel@tonic-gate } TNFW_B_STATE; 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate /* 119*0Sstevel@tonic-gate * The STOPPED bit may be or-ed into the state field. 120*0Sstevel@tonic-gate */ 121*0Sstevel@tonic-gate #define TNFW_B_STOPPED 16 122*0Sstevel@tonic-gate #define TNFW_B_SET_STOPPED(state) ((state) |= TNFW_B_STOPPED) 123*0Sstevel@tonic-gate #define TNFW_B_UNSET_STOPPED(state) ((state) &= ~TNFW_B_STOPPED) 124*0Sstevel@tonic-gate #define TNFW_B_IS_STOPPED(state) ((state) & TNFW_B_STOPPED) 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate typedef struct { 128*0Sstevel@tonic-gate TNFW_B_STATE tnf_state; 129*0Sstevel@tonic-gate volatile char *tnf_buffer; 130*0Sstevel@tonic-gate int (*tnf_init_callback)(void); 131*0Sstevel@tonic-gate void (*tnf_fork_callback)(void); 132*0Sstevel@tonic-gate pid_t tnf_pid; 133*0Sstevel@tonic-gate } TNFW_B_CONTROL; 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate extern TNFW_B_CONTROL *_tnfw_b_control; 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate /* 138*0Sstevel@tonic-gate * structure exported by buffering layer - guaranteed to be filled 139*0Sstevel@tonic-gate * after tnfw_b_init_buffer is called. 140*0Sstevel@tonic-gate */ 141*0Sstevel@tonic-gate typedef struct { 142*0Sstevel@tonic-gate char * fw_file_header; 143*0Sstevel@tonic-gate char * fw_block_header; 144*0Sstevel@tonic-gate char * fw_root; 145*0Sstevel@tonic-gate } tnf_buf_header_t; 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate extern tnf_buf_header_t *_tnf_buf_headers_p; 148*0Sstevel@tonic-gate 149*0Sstevel@tonic-gate /* 150*0Sstevel@tonic-gate * External interface 151*0Sstevel@tonic-gate */ 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate #define TNFW_B_GIVEBACK(wcb, new_pos) \ 154*0Sstevel@tonic-gate ((wcb)->tnfw_w_pos.tnfw_w_write_off = \ 155*0Sstevel@tonic-gate (((char *)(new_pos) - (char *)((wcb)->tnfw_w_pos.tnfw_w_block) + 7) \ 156*0Sstevel@tonic-gate & ~7), *(int *)(new_pos) = 0) 157*0Sstevel@tonic-gate 158*0Sstevel@tonic-gate TNFW_B_STATUS tnfw_b_init_buffer(char *, int, int, boolean_t); 159*0Sstevel@tonic-gate TNFW_B_STATUS tnfw_b_connect(TNFW_B_WCB *, volatile char *); 160*0Sstevel@tonic-gate void * tnfw_b_alloc(TNFW_B_WCB *, size_t, enum tnf_alloc_mode); 161*0Sstevel@tonic-gate TNFW_B_STATUS tnfw_b_xcommit(TNFW_B_WCB *); 162*0Sstevel@tonic-gate TNFW_B_STATUS tnfw_b_xabort(TNFW_B_WCB *); 163*0Sstevel@tonic-gate tnf_uint32_t *tnfw_b_fw_alloc(TNFW_B_WCB *); 164*0Sstevel@tonic-gate void tnfw_b_release_block(TNFW_B_WCB *); 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate /* Declare lock routines written in assembly language. */ 167*0Sstevel@tonic-gate extern int tnfw_b_get_lock(tnf_byte_lock_t *); 168*0Sstevel@tonic-gate extern void tnfw_b_clear_lock(tnf_byte_lock_t *); 169*0Sstevel@tonic-gate extern u_long tnfw_b_atomic_swap(uint_t *, u_long); 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate #ifdef __cplusplus 172*0Sstevel@tonic-gate } 173*0Sstevel@tonic-gate #endif 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate #endif /* _TNF_BUF_H */ 176