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 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_RAMDISK_H 28*7c478bd9Sstevel@tonic-gate #define _SYS_RAMDISK_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/time.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/vtoc.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/dkio.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 39*7c478bd9Sstevel@tonic-gate extern "C" { 40*7c478bd9Sstevel@tonic-gate #endif 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /* 43*7c478bd9Sstevel@tonic-gate * /dev names: 44*7c478bd9Sstevel@tonic-gate * /dev/ramdiskctl - control device 45*7c478bd9Sstevel@tonic-gate * /dev/ramdisk/<name> - block devices 46*7c478bd9Sstevel@tonic-gate * /dev/rramdisk/<name> - character devices 47*7c478bd9Sstevel@tonic-gate */ 48*7c478bd9Sstevel@tonic-gate #define RD_DRIVER_NAME "ramdisk" 49*7c478bd9Sstevel@tonic-gate #define RD_BLOCK_NAME RD_DRIVER_NAME 50*7c478bd9Sstevel@tonic-gate #define RD_CHAR_NAME "r" RD_DRIVER_NAME 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate #define RD_CTL_NODE "ctl" 53*7c478bd9Sstevel@tonic-gate #define RD_CTL_NAME RD_DRIVER_NAME RD_CTL_NODE 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate /* 56*7c478bd9Sstevel@tonic-gate * Minor number 0 is reserved for the controlling device. All other ramdisks 57*7c478bd9Sstevel@tonic-gate * are assigned minor numbers 1..rd_max_disks. The minor number is used as 58*7c478bd9Sstevel@tonic-gate * an index into the 'rd_devstate' structures. 59*7c478bd9Sstevel@tonic-gate */ 60*7c478bd9Sstevel@tonic-gate #define RD_CTL_MINOR 0 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate /* 63*7c478bd9Sstevel@tonic-gate * Maximum number of ramdisks supported by this driver. 64*7c478bd9Sstevel@tonic-gate */ 65*7c478bd9Sstevel@tonic-gate #define RD_MAX_DISKS 1024 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate /* 68*7c478bd9Sstevel@tonic-gate * Properties exported by the driver. 69*7c478bd9Sstevel@tonic-gate */ 70*7c478bd9Sstevel@tonic-gate #define NBLOCKS_PROP_NAME "Nblocks" 71*7c478bd9Sstevel@tonic-gate #define SIZE_PROP_NAME "Size" 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate /* 74*7c478bd9Sstevel@tonic-gate * Strip any "ramdisk-" prefix from the name of OBP-created ramdisks. 75*7c478bd9Sstevel@tonic-gate */ 76*7c478bd9Sstevel@tonic-gate #define RD_OBP_PFXSTR "ramdisk-" 77*7c478bd9Sstevel@tonic-gate #define RD_OBP_PFXLEN (sizeof (RD_OBP_PFXSTR) - 1) 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate #define RD_STRIP_PREFIX(newname, oldname) \ 80*7c478bd9Sstevel@tonic-gate { \ 81*7c478bd9Sstevel@tonic-gate char *onm = oldname; \ 82*7c478bd9Sstevel@tonic-gate newname = strncmp(onm, RD_OBP_PFXSTR, RD_OBP_PFXLEN) == 0 ? \ 83*7c478bd9Sstevel@tonic-gate (onm + RD_OBP_PFXLEN) : onm; \ 84*7c478bd9Sstevel@tonic-gate } 85*7c478bd9Sstevel@tonic-gate 86*7c478bd9Sstevel@tonic-gate /* 87*7c478bd9Sstevel@tonic-gate * Strip any ",raw" suffix from the name of pseudo ramdisk devices. 88*7c478bd9Sstevel@tonic-gate */ 89*7c478bd9Sstevel@tonic-gate #define RD_STRIP_SUFFIX(name) \ 90*7c478bd9Sstevel@tonic-gate { \ 91*7c478bd9Sstevel@tonic-gate char *str = strstr((name), ",raw"); \ 92*7c478bd9Sstevel@tonic-gate if (str != NULL) \ 93*7c478bd9Sstevel@tonic-gate *str = '\0'; \ 94*7c478bd9Sstevel@tonic-gate } 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate /* 97*7c478bd9Sstevel@tonic-gate * Interface between the ramdisk(7D) driver and ramdiskadm(1M). Use is: 98*7c478bd9Sstevel@tonic-gate * 99*7c478bd9Sstevel@tonic-gate * fd = open("/dev/ramdiskctl", O_RDWR | O_EXCL); 100*7c478bd9Sstevel@tonic-gate * 101*7c478bd9Sstevel@tonic-gate * 'ramdiskctl' must be opened exclusively. Access is controlled by permissions 102*7c478bd9Sstevel@tonic-gate * on the device, which is 0644 by default. Write-access is required for the 103*7c478bd9Sstevel@tonic-gate * allocation and deletion of ramdisks, but only read-access is required for 104*7c478bd9Sstevel@tonic-gate * the remaining ioctls which simply return information. 105*7c478bd9Sstevel@tonic-gate * 106*7c478bd9Sstevel@tonic-gate * ioctl usage: 107*7c478bd9Sstevel@tonic-gate * 108*7c478bd9Sstevel@tonic-gate * struct rd_ioctl ri; 109*7c478bd9Sstevel@tonic-gate * 110*7c478bd9Sstevel@tonic-gate * strlcpy(ri.ri_name, "somediskname", sizeof (ri.ri_name)); 111*7c478bd9Sstevel@tonic-gate * ri.ri_size = somedisksize; 112*7c478bd9Sstevel@tonic-gate * ioctl(fd, RD_CREATE_DISK, &ri); 113*7c478bd9Sstevel@tonic-gate * 114*7c478bd9Sstevel@tonic-gate * strlcpy(ri.ri_name, "somediskname", sizeof (ri.ri_name)); 115*7c478bd9Sstevel@tonic-gate * ioctl(fd, RD_DELETE_DISK, &ri); 116*7c478bd9Sstevel@tonic-gate * 117*7c478bd9Sstevel@tonic-gate * (only ramdisks created using the RD_CREATE_DISK ioctl can be deleted 118*7c478bd9Sstevel@tonic-gate * by the RD_DELETE_DISK ioctl). 119*7c478bd9Sstevel@tonic-gate * 120*7c478bd9Sstevel@tonic-gate * Note that these ioctls are completely private, and only for the use of 121*7c478bd9Sstevel@tonic-gate * ramdiskadm(1M). 122*7c478bd9Sstevel@tonic-gate */ 123*7c478bd9Sstevel@tonic-gate #define RD_IOC_BASE (('R' << 16) | ('D' << 8)) 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate #define RD_CREATE_DISK (RD_IOC_BASE | 0x01) 126*7c478bd9Sstevel@tonic-gate #define RD_DELETE_DISK (RD_IOC_BASE | 0x02) 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate #define RD_NAME_LEN 32 /* Max length of ramdisk name */ 129*7c478bd9Sstevel@tonic-gate #define RD_NAME_PAD 7 /* Pad ri_name to 8-bytes */ 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate struct rd_ioctl { 132*7c478bd9Sstevel@tonic-gate char ri_name[RD_NAME_LEN + 1]; 133*7c478bd9Sstevel@tonic-gate char _ri_pad[RD_NAME_PAD]; 134*7c478bd9Sstevel@tonic-gate uint64_t ri_size; 135*7c478bd9Sstevel@tonic-gate }; 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate /* 140*7c478bd9Sstevel@tonic-gate * We limit the maximum number of active ramdisk devices to 32, tuneable 141*7c478bd9Sstevel@tonic-gate * up to a maximum of 1023. Minor 0 is always reserved for the controlling 142*7c478bd9Sstevel@tonic-gate * device. You can change this by setting a value for 'max_disks' in 143*7c478bd9Sstevel@tonic-gate * ramdisk.conf. 144*7c478bd9Sstevel@tonic-gate */ 145*7c478bd9Sstevel@tonic-gate #define RD_DFLT_DISKS 32 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate /* 148*7c478bd9Sstevel@tonic-gate * The maximum amount of memory that can be consumed before starving the 149*7c478bd9Sstevel@tonic-gate * kernel depends loosely on the number of cpus, the speed of those cpus, 150*7c478bd9Sstevel@tonic-gate * and other hardware characteristics, and is thus highly machine-dependent. 151*7c478bd9Sstevel@tonic-gate * The default value of 'rd_percent_physmem' is 25% of physical memory, 152*7c478bd9Sstevel@tonic-gate * but this can be changed by setting a value for 'percent_physmem' in 153*7c478bd9Sstevel@tonic-gate * ramdisk.conf. 154*7c478bd9Sstevel@tonic-gate */ 155*7c478bd9Sstevel@tonic-gate #define RD_DEFAULT_PERCENT_PHYSMEM 25 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate /* 158*7c478bd9Sstevel@tonic-gate * Maximum size of a physical transfer? 159*7c478bd9Sstevel@tonic-gate */ 160*7c478bd9Sstevel@tonic-gate #define RD_DEFAULT_MAXPHYS (63 * 1024) /* '126b' */ 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate /* 163*7c478bd9Sstevel@tonic-gate * A real OBP-created ramdisk consists of one or more physical address 164*7c478bd9Sstevel@tonic-gate * ranges; these are described by the 'existing' property, whose value 165*7c478bd9Sstevel@tonic-gate * is a (corresponding) number of {phys,size} pairs. 166*7c478bd9Sstevel@tonic-gate */ 167*7c478bd9Sstevel@tonic-gate #define RD_EXISTING_PROP_NAME "existing" 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate typedef struct { 170*7c478bd9Sstevel@tonic-gate uint64_t phys; /* Phys addr of range */ 171*7c478bd9Sstevel@tonic-gate uint64_t size; /* Size of range */ 172*7c478bd9Sstevel@tonic-gate } rd_existing_t; 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate #define RD_WINDOW_NOT_MAPPED 1 /* Valid window is on page boundary */ 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate /* 178*7c478bd9Sstevel@tonic-gate * The entire state of each ramdisk device. The rd_dip field will reference 179*7c478bd9Sstevel@tonic-gate * the actual devinfo for real OBP-created ramdisks, or the generic devinfo 180*7c478bd9Sstevel@tonic-gate * 'rd_dip' for pseudo ramdisk devices. 181*7c478bd9Sstevel@tonic-gate */ 182*7c478bd9Sstevel@tonic-gate typedef struct rd_devstate { 183*7c478bd9Sstevel@tonic-gate kmutex_t rd_device_lock; /* Per device lock */ 184*7c478bd9Sstevel@tonic-gate char rd_name[RD_NAME_LEN + 1]; 185*7c478bd9Sstevel@tonic-gate dev_info_t *rd_dip; /* My devinfo handle */ 186*7c478bd9Sstevel@tonic-gate minor_t rd_minor; /* Full minor number */ 187*7c478bd9Sstevel@tonic-gate size_t rd_size; /* Size in bytes */ 188*7c478bd9Sstevel@tonic-gate /* 189*7c478bd9Sstevel@tonic-gate * {rd_nexisting, rd_existing} and {rd_npages, rd_ppa} are 190*7c478bd9Sstevel@tonic-gate * mutually exclusive; the former describe an OBP-created 191*7c478bd9Sstevel@tonic-gate * ramdisk, the latter a 'pseudo' ramdisk. 192*7c478bd9Sstevel@tonic-gate */ 193*7c478bd9Sstevel@tonic-gate uint_t rd_nexisting; /* # 'existing' structs */ 194*7c478bd9Sstevel@tonic-gate rd_existing_t *rd_existing; 195*7c478bd9Sstevel@tonic-gate pgcnt_t rd_npages; /* # physical pages */ 196*7c478bd9Sstevel@tonic-gate page_t **rd_ppa; 197*7c478bd9Sstevel@tonic-gate /* 198*7c478bd9Sstevel@tonic-gate * Fields describing a virtual window onto the physical ramdisk, 199*7c478bd9Sstevel@tonic-gate * giving the offset within the ramdisk of the window, its size, 200*7c478bd9Sstevel@tonic-gate * and its virtual address (in the kernel heap). 201*7c478bd9Sstevel@tonic-gate */ 202*7c478bd9Sstevel@tonic-gate offset_t rd_window_base; 203*7c478bd9Sstevel@tonic-gate uint64_t rd_window_size; 204*7c478bd9Sstevel@tonic-gate caddr_t rd_window_virt; 205*7c478bd9Sstevel@tonic-gate /* 206*7c478bd9Sstevel@tonic-gate * Fields to count opens/closes of the ramdisk. 207*7c478bd9Sstevel@tonic-gate */ 208*7c478bd9Sstevel@tonic-gate uint32_t rd_blk_open; 209*7c478bd9Sstevel@tonic-gate uint32_t rd_chr_open; 210*7c478bd9Sstevel@tonic-gate uint32_t rd_lyr_open_cnt; 211*7c478bd9Sstevel@tonic-gate /* 212*7c478bd9Sstevel@tonic-gate * Fields to maintain a faked geometry of the disk. 213*7c478bd9Sstevel@tonic-gate */ 214*7c478bd9Sstevel@tonic-gate struct dk_geom rd_dkg; 215*7c478bd9Sstevel@tonic-gate struct vtoc rd_vtoc; 216*7c478bd9Sstevel@tonic-gate struct dk_cinfo rd_ci; 217*7c478bd9Sstevel@tonic-gate /* 218*7c478bd9Sstevel@tonic-gate * Kstat stuff. 219*7c478bd9Sstevel@tonic-gate */ 220*7c478bd9Sstevel@tonic-gate kmutex_t rd_kstat_lock; 221*7c478bd9Sstevel@tonic-gate kstat_t *rd_kstat; 222*7c478bd9Sstevel@tonic-gate } rd_devstate_t; 223*7c478bd9Sstevel@tonic-gate 224*7c478bd9Sstevel@tonic-gate extern int is_pseudo_device(dev_info_t *); 225*7c478bd9Sstevel@tonic-gate 226*7c478bd9Sstevel@tonic-gate #endif 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 229*7c478bd9Sstevel@tonic-gate } 230*7c478bd9Sstevel@tonic-gate #endif 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate #endif /* _SYS_RAMDISK_H */ 233