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