xref: /onnv-gate/usr/src/uts/common/sys/ddidevmap.h (revision 12400:64b0dca82c21)
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
52768Ssl108498  * Common Development and Distribution License (the "License").
62768Ssl108498  * 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*12400Sgerald.jelinek@sun.com  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #ifndef	_SYS_DDIDEVMAP_H
260Sstevel@tonic-gate #define	_SYS_DDIDEVMAP_H
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #ifdef	__cplusplus
290Sstevel@tonic-gate extern "C" {
300Sstevel@tonic-gate #endif
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifdef	_KERNEL
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include <sys/mman.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate struct devmap_info {
370Sstevel@tonic-gate 	size_t	length;		/* and this length */
380Sstevel@tonic-gate 	size_t	page_size;	/* pte page size selected by framework */
390Sstevel@tonic-gate 	size_t	offset;		/* optimal page size based on this offset */
400Sstevel@tonic-gate 	ushort_t valid_flag;	/* flag to indicate the validity of data */
410Sstevel@tonic-gate 	uchar_t	byte_order;	/* the  endian characteristics of the mapping */
420Sstevel@tonic-gate 
430Sstevel@tonic-gate 	/*
440Sstevel@tonic-gate 	 * describes  order in which the CPU will reference data.
450Sstevel@tonic-gate 	 */
460Sstevel@tonic-gate 	uchar_t	data_order;
470Sstevel@tonic-gate };
480Sstevel@tonic-gate 
490Sstevel@tonic-gate typedef void * ddi_umem_cookie_t;
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate  * umem callback function vector for drivers
530Sstevel@tonic-gate  *
540Sstevel@tonic-gate  * NOTE: IMPORTANT!  When umem_lockmemory is called with a valid
550Sstevel@tonic-gate  * umem_callback_ops and DDI_UMEMLOCK_LONGTERM set, the 'cleanup'
560Sstevel@tonic-gate  * callback function may be called AFTER a call to ddi_umem_lock.
570Sstevel@tonic-gate  * It is the users responsibility to make sure that ddi_umem_lock is
580Sstevel@tonic-gate  * called ONLY once for each ddi_umem_lock/umem_lockmemory cookie.
590Sstevel@tonic-gate  */
600Sstevel@tonic-gate #define	UMEM_CALLBACK_VERSION 1
610Sstevel@tonic-gate struct umem_callback_ops {
620Sstevel@tonic-gate 	int	cbo_umem_callback_version;	/* version number */
630Sstevel@tonic-gate 	void (*cbo_umem_lock_cleanup)(ddi_umem_cookie_t *);
640Sstevel@tonic-gate };
650Sstevel@tonic-gate 
660Sstevel@tonic-gate struct ddi_umem_cookie {
670Sstevel@tonic-gate 	size_t	size;	/* size of allocation */
680Sstevel@tonic-gate 	caddr_t	cvaddr;	/* cookie virtual address. */
690Sstevel@tonic-gate 			/* KMEM - kvaddr returned from ddi_umem_alloc() */
700Sstevel@tonic-gate 			/* For LOCKEDUMEM - user address of backing store */
710Sstevel@tonic-gate 			/* For TRASH_UMEM - unused */
720Sstevel@tonic-gate 	kmutex_t	lock;
730Sstevel@tonic-gate 	uint_t		type;	/* see below for umem_cookie types */
740Sstevel@tonic-gate 	/*
750Sstevel@tonic-gate 	 * Following 4 members are used for UMEM_LOCKED cookie type
760Sstevel@tonic-gate 	 */
770Sstevel@tonic-gate 	page_t		**pparray;	/* shadow list from as_pagelock */
780Sstevel@tonic-gate 	void		*procp;		/* user process owning backing store */
790Sstevel@tonic-gate 	struct as	*asp;		/* as ptr for use by ddi_umem_unlock */
800Sstevel@tonic-gate 	enum seg_rw	s_flags;	/* flags used during pagelock/fault */
810Sstevel@tonic-gate 	/*
820Sstevel@tonic-gate 	 * locked indicates underlying memory locked for KMEM_PAGEABLE
830Sstevel@tonic-gate 	 * locked is a count of for how many pages this has been locked
840Sstevel@tonic-gate 	 */
850Sstevel@tonic-gate 	uint_t		locked;
860Sstevel@tonic-gate 	struct umem_callback_ops callbacks;
870Sstevel@tonic-gate 	/*
880Sstevel@tonic-gate 	 * cook_refcnt used in UMEM_LOCKED type
890Sstevel@tonic-gate 	 */
900Sstevel@tonic-gate 	ulong_t		cook_refcnt;	/* cookie reference count */
910Sstevel@tonic-gate 	struct ddi_umem_cookie *unl_forw;   /* list ptr for unlock cookies */
92*12400Sgerald.jelinek@sun.com 	ulong_t		upd_max_lock_rctl;  /* track max-locked mem rctl? */
930Sstevel@tonic-gate };
940Sstevel@tonic-gate 
950Sstevel@tonic-gate typedef struct as *ddi_as_handle_t;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 
980Sstevel@tonic-gate /*
990Sstevel@tonic-gate  * type of umem_cookie:
1000Sstevel@tonic-gate  *    pageable memory allocated from segkp segment driver
1010Sstevel@tonic-gate  *    non-pageable memory allocated from kmem_getpages()
1020Sstevel@tonic-gate  *    locked umem allocated from ddi_umem_lock
1030Sstevel@tonic-gate  *    trash umem maps all user virtual addresses to a common trash page
1040Sstevel@tonic-gate  */
1050Sstevel@tonic-gate #define	KMEM_PAGEABLE		0x100	/* un-locked kernel memory */
1060Sstevel@tonic-gate #define	KMEM_NON_PAGEABLE	0x200	/* locked kernel memeory */
1070Sstevel@tonic-gate #define	UMEM_LOCKED		0x400	/* locked user process memeory */
1080Sstevel@tonic-gate #define	UMEM_TRASH		0x800	/* trash page mapping */
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate typedef struct __devmap_pmem_cookie *devmap_pmem_cookie_t;
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate typedef void *devmap_cookie_t;
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate struct devmap_callback_ctl {
1150Sstevel@tonic-gate 	int	devmap_rev;		/* devmap_callback_ctl version number */
1160Sstevel@tonic-gate 	int	(*devmap_map)(devmap_cookie_t dhp, dev_t dev, uint_t flags,
1170Sstevel@tonic-gate 				offset_t off, size_t len, void **pvtp);
1180Sstevel@tonic-gate 	int	(*devmap_access)(devmap_cookie_t dhp, void *pvtp, offset_t off,
1190Sstevel@tonic-gate 				size_t len, uint_t type, uint_t rw);
1200Sstevel@tonic-gate 	int	(*devmap_dup)(devmap_cookie_t dhp, void *pvtp,
1210Sstevel@tonic-gate 				devmap_cookie_t new_dhp, void **new_pvtp);
1220Sstevel@tonic-gate 	void	(*devmap_unmap)(devmap_cookie_t dhp, void *pvtp, offset_t off,
1230Sstevel@tonic-gate 				size_t len, devmap_cookie_t new_dhp1,
1240Sstevel@tonic-gate 				void **new_pvtp1, devmap_cookie_t new_dhp2,
1250Sstevel@tonic-gate 				void **new_pvtp2);
1260Sstevel@tonic-gate };
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate struct devmap_softlock {
1290Sstevel@tonic-gate 	ulong_t		id;	/* handle grouping id */
1300Sstevel@tonic-gate 	dev_t		dev; /* Device to which we are mapping */
1310Sstevel@tonic-gate 	struct		devmap_softlock	*next;
1320Sstevel@tonic-gate 	kmutex_t	lock;
1330Sstevel@tonic-gate 	kcondvar_t	cv;
1340Sstevel@tonic-gate 	int		refcnt;	/* Number of threads with mappings */
1350Sstevel@tonic-gate 	ssize_t		softlocked;
1360Sstevel@tonic-gate };
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate struct devmap_ctx {
1390Sstevel@tonic-gate 	ulong_t		id; /* handle grouping id */
1400Sstevel@tonic-gate 	dev_info_t	*dip; /* Device info struct for tracing context */
1410Sstevel@tonic-gate 	struct devmap_ctx *next;
1420Sstevel@tonic-gate 	kmutex_t	lock;
1430Sstevel@tonic-gate 	kcondvar_t	cv;
1440Sstevel@tonic-gate 	int		refcnt; /* Number of threads with mappings */
1450Sstevel@tonic-gate 	uint_t		oncpu; /* this context is running on a cpu */
1460Sstevel@tonic-gate 	timeout_id_t	timeout; /* Timeout ID */
1470Sstevel@tonic-gate };
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate /*
1500Sstevel@tonic-gate  * Fault information passed to the driver fault handling routine.
1510Sstevel@tonic-gate  * The DEVMAP_LOCK and DEVMAP_UNLOCK are used by software
1520Sstevel@tonic-gate  * to lock and unlock pages for physical I/O.
1530Sstevel@tonic-gate  */
1540Sstevel@tonic-gate enum devmap_fault_type {
1550Sstevel@tonic-gate 	DEVMAP_ACCESS,		/* invalid page */
1560Sstevel@tonic-gate 	DEVMAP_PROT,		/* protection fault */
1570Sstevel@tonic-gate 	DEVMAP_LOCK,		/* software requested locking */
1580Sstevel@tonic-gate 	DEVMAP_UNLOCK		/* software requested unlocking */
1590Sstevel@tonic-gate };
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /*
1620Sstevel@tonic-gate  * seg_rw gives the access type for a fault operation
1630Sstevel@tonic-gate  */
1640Sstevel@tonic-gate enum devmap_rw {
1650Sstevel@tonic-gate 	DEVMAP_OTHER,		/* unknown or not touched */
1660Sstevel@tonic-gate 	DEVMAP_READ,		/* read access attempted */
1670Sstevel@tonic-gate 	DEVMAP_WRITE,		/* write access attempted */
1680Sstevel@tonic-gate 	DEVMAP_EXEC,		/* execution access attempted */
1690Sstevel@tonic-gate 	DEVMAP_CREATE		/* create if page doesn't exist */
1700Sstevel@tonic-gate };
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate typedef struct devmap_handle {
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 	/*
1750Sstevel@tonic-gate 	 * physical offset at the beginning of mapping.
1760Sstevel@tonic-gate 	 */
1770Sstevel@tonic-gate 	offset_t	dh_roff;
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate 	/*
1800Sstevel@tonic-gate 	 * user offset at the beginning of mapping.
1810Sstevel@tonic-gate 	 */
1820Sstevel@tonic-gate 	offset_t	dh_uoff;
1830Sstevel@tonic-gate 	size_t		dh_len;		/* length of mapping */
1840Sstevel@tonic-gate 	dev_t		dh_dev;		/* dev_t for this mapping */
1850Sstevel@tonic-gate 	caddr_t		dh_cvaddr;  /* cookie virtual address */
1860Sstevel@tonic-gate 	caddr_t		dh_uvaddr;  /* user address within dh_seg */
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 	/*
1890Sstevel@tonic-gate 	 * Lock protects fields that can change during remap
1900Sstevel@tonic-gate 	 * dh_roff, dh_cookie, dh_flags, dh_mmulevel, dh_maxprot,
1910Sstevel@tonic-gate 	 * dh_pfn, dh_hat_attr
1920Sstevel@tonic-gate 	 */
1930Sstevel@tonic-gate 	kmutex_t	dh_lock;
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate 	/*
1960Sstevel@tonic-gate 	 * to sync. faults for remap and unlocked kvaddr.
1970Sstevel@tonic-gate 	 */
1980Sstevel@tonic-gate 	struct seg		*dh_seg; /* segment created for this mapping */
1990Sstevel@tonic-gate 	void			*dh_pvtp; /* device mapping private data */
2000Sstevel@tonic-gate 	struct devmap_handle	*dh_next;
2010Sstevel@tonic-gate 	struct devmap_softlock	*dh_softlock;
2020Sstevel@tonic-gate 	struct devmap_ctx	*dh_ctx;
2030Sstevel@tonic-gate 	ddi_umem_cookie_t	dh_cookie;	/* kmem cookie */
2040Sstevel@tonic-gate 	devmap_pmem_cookie_t	dh_pcookie;	/* pmem cookie */
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate 	/*
2070Sstevel@tonic-gate 	 * protection flag possible for attempted mapping.
2080Sstevel@tonic-gate 	 */
2090Sstevel@tonic-gate 	uint_t		dh_prot;
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate 	/*
2120Sstevel@tonic-gate 	 * Current maximum protection flag for attempted mapping.
2130Sstevel@tonic-gate 	 * This controls how dh_prot can be changed in segdev_setprot
2140Sstevel@tonic-gate 	 * See dh_orig_maxprot below also
2150Sstevel@tonic-gate 	 */
2160Sstevel@tonic-gate 	uint_t		dh_maxprot;
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate 	/*
2190Sstevel@tonic-gate 	 * mmu level corresponds to the Max page size can be use for
2200Sstevel@tonic-gate 	 * the mapping.
2210Sstevel@tonic-gate 	 */
2220Sstevel@tonic-gate 	uint_t		dh_mmulevel;
2230Sstevel@tonic-gate 	uint_t		dh_flags;   /* see defines below */
2240Sstevel@tonic-gate 	pfn_t		dh_pfn;		/* pfn corresponds to dh_reg_off */
2250Sstevel@tonic-gate 	uint_t		dh_hat_attr;
2260Sstevel@tonic-gate 	clock_t		dh_timeout_length;
2270Sstevel@tonic-gate 	struct devmap_callback_ctl dh_callbackops;
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate 	/*
2300Sstevel@tonic-gate 	 * orig_maxprot is what the original mmap set maxprot to.
2310Sstevel@tonic-gate 	 * This is never modified once it is setup during mmap(2)
2320Sstevel@tonic-gate 	 * This is different from the current dh_maxprot which can
2330Sstevel@tonic-gate 	 * be changed in devmap_*_setup/remap
2340Sstevel@tonic-gate 	 */
2350Sstevel@tonic-gate 	uint_t		dh_orig_maxprot;
2360Sstevel@tonic-gate } devmap_handle_t;
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate #endif	/* _KERNEL */
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate /*
2410Sstevel@tonic-gate  * define for devmap_rev
2420Sstevel@tonic-gate  */
2430Sstevel@tonic-gate #define	DEVMAP_OPS_REV 1
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate /*
2460Sstevel@tonic-gate  * defines for devmap_*_setup flag, called by drivers
2470Sstevel@tonic-gate  */
2480Sstevel@tonic-gate #define	DEVMAP_DEFAULTS			0x00
2490Sstevel@tonic-gate #define	DEVMAP_MAPPING_INVALID		0x01 	/* mapping is invalid */
2500Sstevel@tonic-gate #define	DEVMAP_ALLOW_REMAP		0x02	/* allow remap */
2510Sstevel@tonic-gate #define	DEVMAP_USE_PAGESIZE		0x04	/* use pagesize for mmu load */
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate /* flags used by drivers */
2540Sstevel@tonic-gate #define	DEVMAP_SETUP_FLAGS	\
2550Sstevel@tonic-gate 	(DEVMAP_MAPPING_INVALID | DEVMAP_ALLOW_REMAP | DEVMAP_USE_PAGESIZE)
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate /*
2580Sstevel@tonic-gate  * defines for dh_flags, these are used internally in devmap
2590Sstevel@tonic-gate  */
2600Sstevel@tonic-gate #define	DEVMAP_SETUP_DONE		0x100	/* mapping setup is done */
2610Sstevel@tonic-gate #define	DEVMAP_LOCK_INITED		0x200	/* locks are initailized */
2620Sstevel@tonic-gate #define	DEVMAP_LOCKED			0x800	/* dhp is locked. */
2630Sstevel@tonic-gate #define	DEVMAP_FLAG_LARGE		0x1000  /* cal. optimal pgsize */
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate /*
2660Sstevel@tonic-gate  * Flags to pass to ddi_umem_alloc and ddi_umem_iosetup
2670Sstevel@tonic-gate  */
2680Sstevel@tonic-gate #define	DDI_UMEM_SLEEP		0x0
2690Sstevel@tonic-gate #define	DDI_UMEM_NOSLEEP	0x01
2700Sstevel@tonic-gate #define	DDI_UMEM_PAGEABLE	0x02
2710Sstevel@tonic-gate #define	DDI_UMEM_TRASH		0x04
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate /*
2740Sstevel@tonic-gate  * Flags to pass to ddi_umem_lock to indicate expected access pattern
2750Sstevel@tonic-gate  * DDI_UMEMLOCK_READ implies the memory being locked will be read
2760Sstevel@tonic-gate  * (e.g., data read from memory is written out to the disk or network)
2770Sstevel@tonic-gate  * DDI_UMEMLOCK_WRITE implies the memory being locked will be written
2780Sstevel@tonic-gate  * (e.g., data from the disk or network is written to memory)
2790Sstevel@tonic-gate  * Both flags may be set in the call to ddi_umem_lock,
2800Sstevel@tonic-gate  * Note that this corresponds to the VM subsystem definition of read/write
2810Sstevel@tonic-gate  * and also correspond to the prots set in devmap
2820Sstevel@tonic-gate  * When doing I/O, B_READ/B_WRITE are used which have exactly the opposite
2830Sstevel@tonic-gate  * meaning. Be careful when using it both for I/O and devmap
2840Sstevel@tonic-gate  *
2850Sstevel@tonic-gate  *
2860Sstevel@tonic-gate  */
2870Sstevel@tonic-gate #define	DDI_UMEMLOCK_READ	0x01
2880Sstevel@tonic-gate #define	DDI_UMEMLOCK_WRITE	0x02
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate #ifdef	__cplusplus
2910Sstevel@tonic-gate }
2920Sstevel@tonic-gate #endif
2930Sstevel@tonic-gate 
2940Sstevel@tonic-gate #endif	/* _SYS_DDIDEVMAP_H */
295