4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
27 #ifndef _SYS_RAMDISK_H
28 #define _SYS_RAMDISK_H
30 #include <sys/types.h>
34 #include <sys/vnode.h>
42 * /dev/ramdiskctl - control device
43 * /dev/ramdisk/<name> - block devices
44 * /dev/rramdisk/<name> - character devices
46 #define RD_DRIVER_NAME "ramdisk"
47 #define RD_BLOCK_NAME RD_DRIVER_NAME
48 #define RD_CHAR_NAME "r" RD_DRIVER_NAME
50 #define RD_CTL_NODE "ctl"
51 #define RD_CTL_NAME RD_DRIVER_NAME RD_CTL_NODE
54 * Minor number 0 is reserved for the controlling device. All other ramdisks
55 * are assigned minor numbers 1..rd_max_disks. The minor number is used as
56 * an index into the 'rd_devstate' structures.
58 #define RD_CTL_MINOR 0
61 * Maximum number of ramdisks supported by this driver.
63 #define RD_MAX_DISKS 1024
66 * Properties exported by the driver.
68 #define NBLOCKS_PROP_NAME "Nblocks"
69 #define SIZE_PROP_NAME "Size"
72 * Strip any "ramdisk-" prefix from the name of OBP-created ramdisks.
74 #define RD_OBP_PFXSTR "ramdisk-"
75 #define RD_OBP_PFXLEN (sizeof (RD_OBP_PFXSTR) - 1)
77 #define RD_STRIP_PREFIX(newname, oldname) \
79 char *onm = oldname; \
80 newname = strncmp(onm, RD_OBP_PFXSTR, RD_OBP_PFXLEN) == 0 ? \
81 (onm + RD_OBP_PFXLEN) : onm; \
85 * Strip any ",raw" suffix from the name of pseudo ramdisk devices.
87 #define RD_STRIP_SUFFIX(name) \
89 char *str = strstr((name), ",raw"); \
95 * Interface between the ramdisk(7D) driver and ramdiskadm(8). Use is:
97 * fd = open("/dev/ramdiskctl", O_RDWR | O_EXCL);
99 * 'ramdiskctl' must be opened exclusively. Access is controlled by permissions
100 * on the device, which is 0644 by default. Write-access is required for the
101 * allocation and deletion of ramdisks, but only read-access is required for
102 * the remaining ioctls which simply return information.
106 * struct rd_ioctl ri;
108 * strlcpy(ri.ri_name, "somediskname", sizeof (ri.ri_name));
109 * ri.ri_size = somedisksize;
110 * ioctl(fd, RD_CREATE_DISK, &ri);
112 * strlcpy(ri.ri_name, "somediskname", sizeof (ri.ri_name));
113 * ioctl(fd, RD_DELETE_DISK, &ri);
115 * (only ramdisks created using the RD_CREATE_DISK ioctl can be deleted
116 * by the RD_DELETE_DISK ioctl).
118 * Note that these ioctls are completely private, and only for the use of
121 #define RD_IOC_BASE (('R' << 16) | ('D' << 8))
123 #define RD_CREATE_DISK (RD_IOC_BASE | 0x01)
124 #define RD_DELETE_DISK (RD_IOC_BASE | 0x02)
126 #define RD_NAME_LEN 32 /* Max length of ramdisk name */
127 #define RD_NAME_PAD 7 /* Pad ri_name to 8-bytes */
130 char ri_name
[RD_NAME_LEN
+ 1];
131 char _ri_pad
[RD_NAME_PAD
];
138 * We limit the maximum number of active ramdisk devices to 32, tuneable
139 * up to a maximum of 1023. Minor 0 is always reserved for the controlling
140 * device. You can change this by setting a value for 'max_disks' in
143 #define RD_DFLT_DISKS 32
146 * The maximum amount of memory that can be consumed before starving the
147 * kernel depends loosely on the number of cpus, the speed of those cpus,
148 * and other hardware characteristics, and is thus highly machine-dependent.
149 * The default value of 'rd_percent_physmem' is 25% of physical memory,
150 * but this can be changed by setting a value for 'percent_physmem' in
153 #define RD_DEFAULT_PERCENT_PHYSMEM 25
156 * Maximum size of a physical transfer?
158 #define RD_DEFAULT_MAXPHYS (63 * 1024) /* '126b' */
161 * A physical OBP-created ramdisk consists of one or more physical address
162 * ranges; these are described by the 'existing' property, whose value
163 * is a (corresponding) number of {phys,size} pairs.
165 * A virtual OBP-created ramdisk consists of exactly one virtual address
166 * range; this is described by the 'address' and 'size' properties.
168 #define OBP_EXISTING_PROP_NAME "existing"
169 #define OBP_ADDRESS_PROP_NAME "address"
170 #define OBP_SIZE_PROP_NAME "size"
172 #define RD_EXISTING_PROP_NAME "existing" /* for x86 */
175 uint64_t phys
; /* Phys addr of range */
176 uint64_t size
; /* Size of range */
182 * The entire state of each ramdisk device. The rd_dip field will reference
183 * the actual devinfo for real OBP-created ramdisks, or the generic devinfo
184 * 'rd_dip' for pseudo ramdisk devices.
186 typedef struct rd_devstate
{
187 kmutex_t rd_device_lock
; /* Per device lock */
188 char rd_name
[RD_NAME_LEN
+ 1];
189 dev_info_t
*rd_dip
; /* My devinfo handle */
190 minor_t rd_minor
; /* Full minor number */
191 size_t rd_size
; /* Size in bytes */
193 const struct rd_ops
*rd_ops
;
196 * {rd_nexisting, rd_existing} and {rd_npages, rd_ppa} are
197 * mutually exclusive; the former describe an physical OBP-created
198 * ramdisk, the latter a 'pseudo' ramdisk.
200 uint_t rd_nexisting
; /* # 'existing' structs */
201 rd_existing_t
*rd_existing
;
202 pgcnt_t rd_npages
; /* # physical pages */
206 * The virtual address passed in when the ramdisk was created. This
207 * is only used by virtual OBP-created ramdisks.
212 * Fields to count opens/closes of the ramdisk.
214 uint32_t rd_blk_open
;
215 uint32_t rd_chr_open
;
216 uint32_t rd_lyr_open_cnt
;
218 * Fields to maintain a faked geometry of the disk.
220 struct dk_geom rd_dkg
;
222 struct dk_cinfo rd_ci
;
226 kmutex_t rd_kstat_lock
;
230 extern int is_pseudo_device(dev_info_t
*);
238 #endif /* _SYS_RAMDISK_H */