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