10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*5648Ssetje * Common Development and Distribution License (the "License"). 6*5648Ssetje * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*5648Ssetje * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_RAMDISK_H 270Sstevel@tonic-gate #define _SYS_RAMDISK_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #include <sys/types.h> 320Sstevel@tonic-gate #include <sys/time.h> 330Sstevel@tonic-gate #include <sys/vtoc.h> 340Sstevel@tonic-gate #include <sys/dkio.h> 350Sstevel@tonic-gate #include <sys/vnode.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate #ifdef __cplusplus 380Sstevel@tonic-gate extern "C" { 390Sstevel@tonic-gate #endif 400Sstevel@tonic-gate 410Sstevel@tonic-gate /* 420Sstevel@tonic-gate * /dev names: 430Sstevel@tonic-gate * /dev/ramdiskctl - control device 440Sstevel@tonic-gate * /dev/ramdisk/<name> - block devices 450Sstevel@tonic-gate * /dev/rramdisk/<name> - character devices 460Sstevel@tonic-gate */ 470Sstevel@tonic-gate #define RD_DRIVER_NAME "ramdisk" 480Sstevel@tonic-gate #define RD_BLOCK_NAME RD_DRIVER_NAME 490Sstevel@tonic-gate #define RD_CHAR_NAME "r" RD_DRIVER_NAME 500Sstevel@tonic-gate 510Sstevel@tonic-gate #define RD_CTL_NODE "ctl" 520Sstevel@tonic-gate #define RD_CTL_NAME RD_DRIVER_NAME RD_CTL_NODE 530Sstevel@tonic-gate 540Sstevel@tonic-gate /* 550Sstevel@tonic-gate * Minor number 0 is reserved for the controlling device. All other ramdisks 560Sstevel@tonic-gate * are assigned minor numbers 1..rd_max_disks. The minor number is used as 570Sstevel@tonic-gate * an index into the 'rd_devstate' structures. 580Sstevel@tonic-gate */ 590Sstevel@tonic-gate #define RD_CTL_MINOR 0 600Sstevel@tonic-gate 610Sstevel@tonic-gate /* 620Sstevel@tonic-gate * Maximum number of ramdisks supported by this driver. 630Sstevel@tonic-gate */ 640Sstevel@tonic-gate #define RD_MAX_DISKS 1024 650Sstevel@tonic-gate 660Sstevel@tonic-gate /* 670Sstevel@tonic-gate * Properties exported by the driver. 680Sstevel@tonic-gate */ 690Sstevel@tonic-gate #define NBLOCKS_PROP_NAME "Nblocks" 700Sstevel@tonic-gate #define SIZE_PROP_NAME "Size" 710Sstevel@tonic-gate 720Sstevel@tonic-gate /* 730Sstevel@tonic-gate * Strip any "ramdisk-" prefix from the name of OBP-created ramdisks. 740Sstevel@tonic-gate */ 750Sstevel@tonic-gate #define RD_OBP_PFXSTR "ramdisk-" 760Sstevel@tonic-gate #define RD_OBP_PFXLEN (sizeof (RD_OBP_PFXSTR) - 1) 770Sstevel@tonic-gate 780Sstevel@tonic-gate #define RD_STRIP_PREFIX(newname, oldname) \ 790Sstevel@tonic-gate { \ 800Sstevel@tonic-gate char *onm = oldname; \ 810Sstevel@tonic-gate newname = strncmp(onm, RD_OBP_PFXSTR, RD_OBP_PFXLEN) == 0 ? \ 820Sstevel@tonic-gate (onm + RD_OBP_PFXLEN) : onm; \ 830Sstevel@tonic-gate } 840Sstevel@tonic-gate 850Sstevel@tonic-gate /* 860Sstevel@tonic-gate * Strip any ",raw" suffix from the name of pseudo ramdisk devices. 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate #define RD_STRIP_SUFFIX(name) \ 890Sstevel@tonic-gate { \ 900Sstevel@tonic-gate char *str = strstr((name), ",raw"); \ 910Sstevel@tonic-gate if (str != NULL) \ 920Sstevel@tonic-gate *str = '\0'; \ 930Sstevel@tonic-gate } 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* 960Sstevel@tonic-gate * Interface between the ramdisk(7D) driver and ramdiskadm(1M). Use is: 970Sstevel@tonic-gate * 980Sstevel@tonic-gate * fd = open("/dev/ramdiskctl", O_RDWR | O_EXCL); 990Sstevel@tonic-gate * 1000Sstevel@tonic-gate * 'ramdiskctl' must be opened exclusively. Access is controlled by permissions 1010Sstevel@tonic-gate * on the device, which is 0644 by default. Write-access is required for the 1020Sstevel@tonic-gate * allocation and deletion of ramdisks, but only read-access is required for 1030Sstevel@tonic-gate * the remaining ioctls which simply return information. 1040Sstevel@tonic-gate * 1050Sstevel@tonic-gate * ioctl usage: 1060Sstevel@tonic-gate * 1070Sstevel@tonic-gate * struct rd_ioctl ri; 1080Sstevel@tonic-gate * 1090Sstevel@tonic-gate * strlcpy(ri.ri_name, "somediskname", sizeof (ri.ri_name)); 1100Sstevel@tonic-gate * ri.ri_size = somedisksize; 1110Sstevel@tonic-gate * ioctl(fd, RD_CREATE_DISK, &ri); 1120Sstevel@tonic-gate * 1130Sstevel@tonic-gate * strlcpy(ri.ri_name, "somediskname", sizeof (ri.ri_name)); 1140Sstevel@tonic-gate * ioctl(fd, RD_DELETE_DISK, &ri); 1150Sstevel@tonic-gate * 1160Sstevel@tonic-gate * (only ramdisks created using the RD_CREATE_DISK ioctl can be deleted 1170Sstevel@tonic-gate * by the RD_DELETE_DISK ioctl). 1180Sstevel@tonic-gate * 1190Sstevel@tonic-gate * Note that these ioctls are completely private, and only for the use of 1200Sstevel@tonic-gate * ramdiskadm(1M). 1210Sstevel@tonic-gate */ 1220Sstevel@tonic-gate #define RD_IOC_BASE (('R' << 16) | ('D' << 8)) 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate #define RD_CREATE_DISK (RD_IOC_BASE | 0x01) 1250Sstevel@tonic-gate #define RD_DELETE_DISK (RD_IOC_BASE | 0x02) 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate #define RD_NAME_LEN 32 /* Max length of ramdisk name */ 1280Sstevel@tonic-gate #define RD_NAME_PAD 7 /* Pad ri_name to 8-bytes */ 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate struct rd_ioctl { 1310Sstevel@tonic-gate char ri_name[RD_NAME_LEN + 1]; 1320Sstevel@tonic-gate char _ri_pad[RD_NAME_PAD]; 1330Sstevel@tonic-gate uint64_t ri_size; 1340Sstevel@tonic-gate }; 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate #if defined(_KERNEL) 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate /* 1390Sstevel@tonic-gate * We limit the maximum number of active ramdisk devices to 32, tuneable 1400Sstevel@tonic-gate * up to a maximum of 1023. Minor 0 is always reserved for the controlling 1410Sstevel@tonic-gate * device. You can change this by setting a value for 'max_disks' in 1420Sstevel@tonic-gate * ramdisk.conf. 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate #define RD_DFLT_DISKS 32 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate /* 1470Sstevel@tonic-gate * The maximum amount of memory that can be consumed before starving the 1480Sstevel@tonic-gate * kernel depends loosely on the number of cpus, the speed of those cpus, 1490Sstevel@tonic-gate * and other hardware characteristics, and is thus highly machine-dependent. 1500Sstevel@tonic-gate * The default value of 'rd_percent_physmem' is 25% of physical memory, 1510Sstevel@tonic-gate * but this can be changed by setting a value for 'percent_physmem' in 1520Sstevel@tonic-gate * ramdisk.conf. 1530Sstevel@tonic-gate */ 1540Sstevel@tonic-gate #define RD_DEFAULT_PERCENT_PHYSMEM 25 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate /* 1570Sstevel@tonic-gate * Maximum size of a physical transfer? 1580Sstevel@tonic-gate */ 1590Sstevel@tonic-gate #define RD_DEFAULT_MAXPHYS (63 * 1024) /* '126b' */ 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate /* 1620Sstevel@tonic-gate * A real OBP-created ramdisk consists of one or more physical address 1630Sstevel@tonic-gate * ranges; these are described by the 'existing' property, whose value 1640Sstevel@tonic-gate * is a (corresponding) number of {phys,size} pairs. 1650Sstevel@tonic-gate */ 166*5648Ssetje #define OBP_EXISTING_PROP_NAME "existing" 167*5648Ssetje #define OBP_ADDRESS_PROP_NAME "address" 168*5648Ssetje #define OBP_SIZE_PROP_NAME "size" 169*5648Ssetje 170*5648Ssetje #define RD_EXISTING_PROP_NAME "existing" /* for x86 */ 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate typedef struct { 1730Sstevel@tonic-gate uint64_t phys; /* Phys addr of range */ 1740Sstevel@tonic-gate uint64_t size; /* Size of range */ 1750Sstevel@tonic-gate } rd_existing_t; 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate #define RD_WINDOW_NOT_MAPPED 1 /* Valid window is on page boundary */ 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate /* 1810Sstevel@tonic-gate * The entire state of each ramdisk device. The rd_dip field will reference 1820Sstevel@tonic-gate * the actual devinfo for real OBP-created ramdisks, or the generic devinfo 1830Sstevel@tonic-gate * 'rd_dip' for pseudo ramdisk devices. 1840Sstevel@tonic-gate */ 1850Sstevel@tonic-gate typedef struct rd_devstate { 1860Sstevel@tonic-gate kmutex_t rd_device_lock; /* Per device lock */ 1870Sstevel@tonic-gate char rd_name[RD_NAME_LEN + 1]; 1880Sstevel@tonic-gate dev_info_t *rd_dip; /* My devinfo handle */ 1890Sstevel@tonic-gate minor_t rd_minor; /* Full minor number */ 1900Sstevel@tonic-gate size_t rd_size; /* Size in bytes */ 1910Sstevel@tonic-gate /* 1920Sstevel@tonic-gate * {rd_nexisting, rd_existing} and {rd_npages, rd_ppa} are 1930Sstevel@tonic-gate * mutually exclusive; the former describe an OBP-created 1940Sstevel@tonic-gate * ramdisk, the latter a 'pseudo' ramdisk. 1950Sstevel@tonic-gate */ 1960Sstevel@tonic-gate uint_t rd_nexisting; /* # 'existing' structs */ 1970Sstevel@tonic-gate rd_existing_t *rd_existing; 1980Sstevel@tonic-gate pgcnt_t rd_npages; /* # physical pages */ 1990Sstevel@tonic-gate page_t **rd_ppa; 2000Sstevel@tonic-gate /* 2010Sstevel@tonic-gate * Fields describing a virtual window onto the physical ramdisk, 2020Sstevel@tonic-gate * giving the offset within the ramdisk of the window, its size, 2030Sstevel@tonic-gate * and its virtual address (in the kernel heap). 2040Sstevel@tonic-gate */ 205*5648Ssetje uint_t rd_window_obp; /* using OBP's vaddr */ 2060Sstevel@tonic-gate offset_t rd_window_base; 2070Sstevel@tonic-gate uint64_t rd_window_size; 2080Sstevel@tonic-gate caddr_t rd_window_virt; 2090Sstevel@tonic-gate /* 2100Sstevel@tonic-gate * Fields to count opens/closes of the ramdisk. 2110Sstevel@tonic-gate */ 2120Sstevel@tonic-gate uint32_t rd_blk_open; 2130Sstevel@tonic-gate uint32_t rd_chr_open; 2140Sstevel@tonic-gate uint32_t rd_lyr_open_cnt; 2150Sstevel@tonic-gate /* 2160Sstevel@tonic-gate * Fields to maintain a faked geometry of the disk. 2170Sstevel@tonic-gate */ 2180Sstevel@tonic-gate struct dk_geom rd_dkg; 2190Sstevel@tonic-gate struct vtoc rd_vtoc; 2200Sstevel@tonic-gate struct dk_cinfo rd_ci; 2210Sstevel@tonic-gate /* 2220Sstevel@tonic-gate * Kstat stuff. 2230Sstevel@tonic-gate */ 2240Sstevel@tonic-gate kmutex_t rd_kstat_lock; 2250Sstevel@tonic-gate kstat_t *rd_kstat; 2260Sstevel@tonic-gate } rd_devstate_t; 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate extern int is_pseudo_device(dev_info_t *); 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate #endif 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate #ifdef __cplusplus 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate #endif 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate #endif /* _SYS_RAMDISK_H */ 237