17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*986fd29aSsetje * Common Development and Distribution License (the "License"). 6*986fd29aSsetje * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*986fd29aSsetje * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_RAMDISK_H 277c478bd9Sstevel@tonic-gate #define _SYS_RAMDISK_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <sys/time.h> 337c478bd9Sstevel@tonic-gate #include <sys/vtoc.h> 347c478bd9Sstevel@tonic-gate #include <sys/dkio.h> 357c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #ifdef __cplusplus 387c478bd9Sstevel@tonic-gate extern "C" { 397c478bd9Sstevel@tonic-gate #endif 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* 427c478bd9Sstevel@tonic-gate * /dev names: 437c478bd9Sstevel@tonic-gate * /dev/ramdiskctl - control device 447c478bd9Sstevel@tonic-gate * /dev/ramdisk/<name> - block devices 457c478bd9Sstevel@tonic-gate * /dev/rramdisk/<name> - character devices 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate #define RD_DRIVER_NAME "ramdisk" 487c478bd9Sstevel@tonic-gate #define RD_BLOCK_NAME RD_DRIVER_NAME 497c478bd9Sstevel@tonic-gate #define RD_CHAR_NAME "r" RD_DRIVER_NAME 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #define RD_CTL_NODE "ctl" 527c478bd9Sstevel@tonic-gate #define RD_CTL_NAME RD_DRIVER_NAME RD_CTL_NODE 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * Minor number 0 is reserved for the controlling device. All other ramdisks 567c478bd9Sstevel@tonic-gate * are assigned minor numbers 1..rd_max_disks. The minor number is used as 577c478bd9Sstevel@tonic-gate * an index into the 'rd_devstate' structures. 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate #define RD_CTL_MINOR 0 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* 627c478bd9Sstevel@tonic-gate * Maximum number of ramdisks supported by this driver. 637c478bd9Sstevel@tonic-gate */ 647c478bd9Sstevel@tonic-gate #define RD_MAX_DISKS 1024 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * Properties exported by the driver. 687c478bd9Sstevel@tonic-gate */ 697c478bd9Sstevel@tonic-gate #define NBLOCKS_PROP_NAME "Nblocks" 707c478bd9Sstevel@tonic-gate #define SIZE_PROP_NAME "Size" 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * Strip any "ramdisk-" prefix from the name of OBP-created ramdisks. 747c478bd9Sstevel@tonic-gate */ 757c478bd9Sstevel@tonic-gate #define RD_OBP_PFXSTR "ramdisk-" 767c478bd9Sstevel@tonic-gate #define RD_OBP_PFXLEN (sizeof (RD_OBP_PFXSTR) - 1) 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate #define RD_STRIP_PREFIX(newname, oldname) \ 797c478bd9Sstevel@tonic-gate { \ 807c478bd9Sstevel@tonic-gate char *onm = oldname; \ 817c478bd9Sstevel@tonic-gate newname = strncmp(onm, RD_OBP_PFXSTR, RD_OBP_PFXLEN) == 0 ? \ 827c478bd9Sstevel@tonic-gate (onm + RD_OBP_PFXLEN) : onm; \ 837c478bd9Sstevel@tonic-gate } 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate /* 867c478bd9Sstevel@tonic-gate * Strip any ",raw" suffix from the name of pseudo ramdisk devices. 877c478bd9Sstevel@tonic-gate */ 887c478bd9Sstevel@tonic-gate #define RD_STRIP_SUFFIX(name) \ 897c478bd9Sstevel@tonic-gate { \ 907c478bd9Sstevel@tonic-gate char *str = strstr((name), ",raw"); \ 917c478bd9Sstevel@tonic-gate if (str != NULL) \ 927c478bd9Sstevel@tonic-gate *str = '\0'; \ 937c478bd9Sstevel@tonic-gate } 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* 967c478bd9Sstevel@tonic-gate * Interface between the ramdisk(7D) driver and ramdiskadm(1M). Use is: 977c478bd9Sstevel@tonic-gate * 987c478bd9Sstevel@tonic-gate * fd = open("/dev/ramdiskctl", O_RDWR | O_EXCL); 997c478bd9Sstevel@tonic-gate * 1007c478bd9Sstevel@tonic-gate * 'ramdiskctl' must be opened exclusively. Access is controlled by permissions 1017c478bd9Sstevel@tonic-gate * on the device, which is 0644 by default. Write-access is required for the 1027c478bd9Sstevel@tonic-gate * allocation and deletion of ramdisks, but only read-access is required for 1037c478bd9Sstevel@tonic-gate * the remaining ioctls which simply return information. 1047c478bd9Sstevel@tonic-gate * 1057c478bd9Sstevel@tonic-gate * ioctl usage: 1067c478bd9Sstevel@tonic-gate * 1077c478bd9Sstevel@tonic-gate * struct rd_ioctl ri; 1087c478bd9Sstevel@tonic-gate * 1097c478bd9Sstevel@tonic-gate * strlcpy(ri.ri_name, "somediskname", sizeof (ri.ri_name)); 1107c478bd9Sstevel@tonic-gate * ri.ri_size = somedisksize; 1117c478bd9Sstevel@tonic-gate * ioctl(fd, RD_CREATE_DISK, &ri); 1127c478bd9Sstevel@tonic-gate * 1137c478bd9Sstevel@tonic-gate * strlcpy(ri.ri_name, "somediskname", sizeof (ri.ri_name)); 1147c478bd9Sstevel@tonic-gate * ioctl(fd, RD_DELETE_DISK, &ri); 1157c478bd9Sstevel@tonic-gate * 1167c478bd9Sstevel@tonic-gate * (only ramdisks created using the RD_CREATE_DISK ioctl can be deleted 1177c478bd9Sstevel@tonic-gate * by the RD_DELETE_DISK ioctl). 1187c478bd9Sstevel@tonic-gate * 1197c478bd9Sstevel@tonic-gate * Note that these ioctls are completely private, and only for the use of 1207c478bd9Sstevel@tonic-gate * ramdiskadm(1M). 1217c478bd9Sstevel@tonic-gate */ 1227c478bd9Sstevel@tonic-gate #define RD_IOC_BASE (('R' << 16) | ('D' << 8)) 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate #define RD_CREATE_DISK (RD_IOC_BASE | 0x01) 1257c478bd9Sstevel@tonic-gate #define RD_DELETE_DISK (RD_IOC_BASE | 0x02) 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate #define RD_NAME_LEN 32 /* Max length of ramdisk name */ 1287c478bd9Sstevel@tonic-gate #define RD_NAME_PAD 7 /* Pad ri_name to 8-bytes */ 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate struct rd_ioctl { 1317c478bd9Sstevel@tonic-gate char ri_name[RD_NAME_LEN + 1]; 1327c478bd9Sstevel@tonic-gate char _ri_pad[RD_NAME_PAD]; 1337c478bd9Sstevel@tonic-gate uint64_t ri_size; 1347c478bd9Sstevel@tonic-gate }; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate /* 1397c478bd9Sstevel@tonic-gate * We limit the maximum number of active ramdisk devices to 32, tuneable 1407c478bd9Sstevel@tonic-gate * up to a maximum of 1023. Minor 0 is always reserved for the controlling 1417c478bd9Sstevel@tonic-gate * device. You can change this by setting a value for 'max_disks' in 1427c478bd9Sstevel@tonic-gate * ramdisk.conf. 1437c478bd9Sstevel@tonic-gate */ 1447c478bd9Sstevel@tonic-gate #define RD_DFLT_DISKS 32 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate /* 1477c478bd9Sstevel@tonic-gate * The maximum amount of memory that can be consumed before starving the 1487c478bd9Sstevel@tonic-gate * kernel depends loosely on the number of cpus, the speed of those cpus, 1497c478bd9Sstevel@tonic-gate * and other hardware characteristics, and is thus highly machine-dependent. 1507c478bd9Sstevel@tonic-gate * The default value of 'rd_percent_physmem' is 25% of physical memory, 1517c478bd9Sstevel@tonic-gate * but this can be changed by setting a value for 'percent_physmem' in 1527c478bd9Sstevel@tonic-gate * ramdisk.conf. 1537c478bd9Sstevel@tonic-gate */ 1547c478bd9Sstevel@tonic-gate #define RD_DEFAULT_PERCENT_PHYSMEM 25 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate /* 1577c478bd9Sstevel@tonic-gate * Maximum size of a physical transfer? 1587c478bd9Sstevel@tonic-gate */ 1597c478bd9Sstevel@tonic-gate #define RD_DEFAULT_MAXPHYS (63 * 1024) /* '126b' */ 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate /* 1627c478bd9Sstevel@tonic-gate * A real OBP-created ramdisk consists of one or more physical address 1637c478bd9Sstevel@tonic-gate * ranges; these are described by the 'existing' property, whose value 1647c478bd9Sstevel@tonic-gate * is a (corresponding) number of {phys,size} pairs. 1657c478bd9Sstevel@tonic-gate */ 166*986fd29aSsetje #define OBP_EXISTING_PROP_NAME "existing" 167*986fd29aSsetje #define OBP_ADDRESS_PROP_NAME "address" 168*986fd29aSsetje #define OBP_SIZE_PROP_NAME "size" 169*986fd29aSsetje 170*986fd29aSsetje #define RD_EXISTING_PROP_NAME "existing" /* for x86 */ 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate typedef struct { 1737c478bd9Sstevel@tonic-gate uint64_t phys; /* Phys addr of range */ 1747c478bd9Sstevel@tonic-gate uint64_t size; /* Size of range */ 1757c478bd9Sstevel@tonic-gate } rd_existing_t; 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate #define RD_WINDOW_NOT_MAPPED 1 /* Valid window is on page boundary */ 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate /* 1817c478bd9Sstevel@tonic-gate * The entire state of each ramdisk device. The rd_dip field will reference 1827c478bd9Sstevel@tonic-gate * the actual devinfo for real OBP-created ramdisks, or the generic devinfo 1837c478bd9Sstevel@tonic-gate * 'rd_dip' for pseudo ramdisk devices. 1847c478bd9Sstevel@tonic-gate */ 1857c478bd9Sstevel@tonic-gate typedef struct rd_devstate { 1867c478bd9Sstevel@tonic-gate kmutex_t rd_device_lock; /* Per device lock */ 1877c478bd9Sstevel@tonic-gate char rd_name[RD_NAME_LEN + 1]; 1887c478bd9Sstevel@tonic-gate dev_info_t *rd_dip; /* My devinfo handle */ 1897c478bd9Sstevel@tonic-gate minor_t rd_minor; /* Full minor number */ 1907c478bd9Sstevel@tonic-gate size_t rd_size; /* Size in bytes */ 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * {rd_nexisting, rd_existing} and {rd_npages, rd_ppa} are 1937c478bd9Sstevel@tonic-gate * mutually exclusive; the former describe an OBP-created 1947c478bd9Sstevel@tonic-gate * ramdisk, the latter a 'pseudo' ramdisk. 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate uint_t rd_nexisting; /* # 'existing' structs */ 1977c478bd9Sstevel@tonic-gate rd_existing_t *rd_existing; 1987c478bd9Sstevel@tonic-gate pgcnt_t rd_npages; /* # physical pages */ 1997c478bd9Sstevel@tonic-gate page_t **rd_ppa; 2007c478bd9Sstevel@tonic-gate /* 2017c478bd9Sstevel@tonic-gate * Fields describing a virtual window onto the physical ramdisk, 2027c478bd9Sstevel@tonic-gate * giving the offset within the ramdisk of the window, its size, 2037c478bd9Sstevel@tonic-gate * and its virtual address (in the kernel heap). 2047c478bd9Sstevel@tonic-gate */ 205*986fd29aSsetje uint_t rd_window_obp; /* using OBP's vaddr */ 2067c478bd9Sstevel@tonic-gate offset_t rd_window_base; 2077c478bd9Sstevel@tonic-gate uint64_t rd_window_size; 2087c478bd9Sstevel@tonic-gate caddr_t rd_window_virt; 2097c478bd9Sstevel@tonic-gate /* 2107c478bd9Sstevel@tonic-gate * Fields to count opens/closes of the ramdisk. 2117c478bd9Sstevel@tonic-gate */ 2127c478bd9Sstevel@tonic-gate uint32_t rd_blk_open; 2137c478bd9Sstevel@tonic-gate uint32_t rd_chr_open; 2147c478bd9Sstevel@tonic-gate uint32_t rd_lyr_open_cnt; 2157c478bd9Sstevel@tonic-gate /* 2167c478bd9Sstevel@tonic-gate * Fields to maintain a faked geometry of the disk. 2177c478bd9Sstevel@tonic-gate */ 2187c478bd9Sstevel@tonic-gate struct dk_geom rd_dkg; 2197c478bd9Sstevel@tonic-gate struct vtoc rd_vtoc; 2207c478bd9Sstevel@tonic-gate struct dk_cinfo rd_ci; 2217c478bd9Sstevel@tonic-gate /* 2227c478bd9Sstevel@tonic-gate * Kstat stuff. 2237c478bd9Sstevel@tonic-gate */ 2247c478bd9Sstevel@tonic-gate kmutex_t rd_kstat_lock; 2257c478bd9Sstevel@tonic-gate kstat_t *rd_kstat; 2267c478bd9Sstevel@tonic-gate } rd_devstate_t; 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate extern int is_pseudo_device(dev_info_t *); 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate #endif 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate #endif 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate #endif /* _SYS_RAMDISK_H */ 237