Merge commit '37e84ab74e939caf52150fc3352081786ecc0c29' into merges
[unleashed.git] / include / sys / ramdisk.h
blob0c7c406167d049b8ad6ef12eeed638db17eae12a
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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>
31 #include <sys/time.h>
32 #include <sys/vtoc.h>
33 #include <sys/dkio.h>
34 #include <sys/vnode.h>
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
41 * /dev names:
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) \
78 { \
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) \
88 { \
89 char *str = strstr((name), ",raw"); \
90 if (str != NULL) \
91 *str = '\0'; \
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.
104 * ioctl usage:
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
119 * ramdiskadm(8).
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 */
129 struct rd_ioctl {
130 char ri_name[RD_NAME_LEN + 1];
131 char _ri_pad[RD_NAME_PAD];
132 uint64_t ri_size;
135 #if defined(_KERNEL)
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
141 * ramdisk.conf.
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
151 * ramdisk.conf.
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 */
174 typedef struct {
175 uint64_t phys; /* Phys addr of range */
176 uint64_t size; /* Size of range */
177 } rd_existing_t;
179 struct rd_ops;
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 */
203 page_t **rd_ppa;
206 * The virtual address passed in when the ramdisk was created. This
207 * is only used by virtual OBP-created ramdisks.
209 caddr_t rd_obp_virt;
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;
221 struct vtoc rd_vtoc;
222 struct dk_cinfo rd_ci;
224 * Kstat stuff.
226 kmutex_t rd_kstat_lock;
227 kstat_t *rd_kstat;
228 } rd_devstate_t;
230 extern int is_pseudo_device(dev_info_t *);
232 #endif
234 #ifdef __cplusplus
236 #endif
238 #endif /* _SYS_RAMDISK_H */