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