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*c6939658Ssl108498 * Common Development and Distribution License (the "License"). 6*c6939658Ssl108498 * 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*c6939658Ssl108498 * Copyright 2006 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_DDIDEVMAP_H 277c478bd9Sstevel@tonic-gate #define _SYS_DDIDEVMAP_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifdef __cplusplus 327c478bd9Sstevel@tonic-gate extern "C" { 337c478bd9Sstevel@tonic-gate #endif 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef _KERNEL 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #include <sys/mman.h> 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate struct devmap_info { 407c478bd9Sstevel@tonic-gate size_t length; /* and this length */ 417c478bd9Sstevel@tonic-gate size_t page_size; /* pte page size selected by framework */ 427c478bd9Sstevel@tonic-gate size_t offset; /* optimal page size based on this offset */ 437c478bd9Sstevel@tonic-gate ushort_t valid_flag; /* flag to indicate the validity of data */ 447c478bd9Sstevel@tonic-gate uchar_t byte_order; /* the endian characteristics of the mapping */ 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate /* 477c478bd9Sstevel@tonic-gate * describes order in which the CPU will reference data. 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate uchar_t data_order; 507c478bd9Sstevel@tonic-gate }; 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate typedef void * ddi_umem_cookie_t; 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * umem callback function vector for drivers 567c478bd9Sstevel@tonic-gate * 577c478bd9Sstevel@tonic-gate * NOTE: IMPORTANT! When umem_lockmemory is called with a valid 587c478bd9Sstevel@tonic-gate * umem_callback_ops and DDI_UMEMLOCK_LONGTERM set, the 'cleanup' 597c478bd9Sstevel@tonic-gate * callback function may be called AFTER a call to ddi_umem_lock. 607c478bd9Sstevel@tonic-gate * It is the users responsibility to make sure that ddi_umem_lock is 617c478bd9Sstevel@tonic-gate * called ONLY once for each ddi_umem_lock/umem_lockmemory cookie. 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate #define UMEM_CALLBACK_VERSION 1 647c478bd9Sstevel@tonic-gate struct umem_callback_ops { 657c478bd9Sstevel@tonic-gate int cbo_umem_callback_version; /* version number */ 667c478bd9Sstevel@tonic-gate void (*cbo_umem_lock_cleanup)(ddi_umem_cookie_t *); 677c478bd9Sstevel@tonic-gate }; 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate struct ddi_umem_cookie { 707c478bd9Sstevel@tonic-gate size_t size; /* size of allocation */ 717c478bd9Sstevel@tonic-gate caddr_t cvaddr; /* cookie virtual address. */ 727c478bd9Sstevel@tonic-gate /* KMEM - kvaddr returned from ddi_umem_alloc() */ 737c478bd9Sstevel@tonic-gate /* For LOCKEDUMEM - user address of backing store */ 747c478bd9Sstevel@tonic-gate /* For TRASH_UMEM - unused */ 757c478bd9Sstevel@tonic-gate kmutex_t lock; 767c478bd9Sstevel@tonic-gate uint_t type; /* see below for umem_cookie types */ 777c478bd9Sstevel@tonic-gate /* 787c478bd9Sstevel@tonic-gate * Following 4 members are used for UMEM_LOCKED cookie type 797c478bd9Sstevel@tonic-gate */ 807c478bd9Sstevel@tonic-gate page_t **pparray; /* shadow list from as_pagelock */ 817c478bd9Sstevel@tonic-gate void *procp; /* user process owning backing store */ 827c478bd9Sstevel@tonic-gate struct as *asp; /* as ptr for use by ddi_umem_unlock */ 837c478bd9Sstevel@tonic-gate enum seg_rw s_flags; /* flags used during pagelock/fault */ 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * locked indicates underlying memory locked for KMEM_PAGEABLE 867c478bd9Sstevel@tonic-gate * locked is a count of for how many pages this has been locked 877c478bd9Sstevel@tonic-gate */ 887c478bd9Sstevel@tonic-gate uint_t locked; 897c478bd9Sstevel@tonic-gate struct umem_callback_ops callbacks; 907c478bd9Sstevel@tonic-gate /* 917c478bd9Sstevel@tonic-gate * cook_refcnt used in UMEM_LOCKED type 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate ulong_t cook_refcnt; /* cookie reference count */ 947c478bd9Sstevel@tonic-gate struct ddi_umem_cookie *unl_forw; /* list ptr for unlock cookies */ 95*c6939658Ssl108498 void *reserved; /* unused */ 967c478bd9Sstevel@tonic-gate }; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate typedef struct as *ddi_as_handle_t; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate /* 1027c478bd9Sstevel@tonic-gate * type of umem_cookie: 1037c478bd9Sstevel@tonic-gate * pageable memory allocated from segkp segment driver 1047c478bd9Sstevel@tonic-gate * non-pageable memory allocated from kmem_getpages() 1057c478bd9Sstevel@tonic-gate * locked umem allocated from ddi_umem_lock 1067c478bd9Sstevel@tonic-gate * trash umem maps all user virtual addresses to a common trash page 1077c478bd9Sstevel@tonic-gate */ 1087c478bd9Sstevel@tonic-gate #define KMEM_PAGEABLE 0x100 /* un-locked kernel memory */ 1097c478bd9Sstevel@tonic-gate #define KMEM_NON_PAGEABLE 0x200 /* locked kernel memeory */ 1107c478bd9Sstevel@tonic-gate #define UMEM_LOCKED 0x400 /* locked user process memeory */ 1117c478bd9Sstevel@tonic-gate #define UMEM_TRASH 0x800 /* trash page mapping */ 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate typedef struct __devmap_pmem_cookie *devmap_pmem_cookie_t; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate typedef void *devmap_cookie_t; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate struct devmap_callback_ctl { 1187c478bd9Sstevel@tonic-gate int devmap_rev; /* devmap_callback_ctl version number */ 1197c478bd9Sstevel@tonic-gate int (*devmap_map)(devmap_cookie_t dhp, dev_t dev, uint_t flags, 1207c478bd9Sstevel@tonic-gate offset_t off, size_t len, void **pvtp); 1217c478bd9Sstevel@tonic-gate int (*devmap_access)(devmap_cookie_t dhp, void *pvtp, offset_t off, 1227c478bd9Sstevel@tonic-gate size_t len, uint_t type, uint_t rw); 1237c478bd9Sstevel@tonic-gate int (*devmap_dup)(devmap_cookie_t dhp, void *pvtp, 1247c478bd9Sstevel@tonic-gate devmap_cookie_t new_dhp, void **new_pvtp); 1257c478bd9Sstevel@tonic-gate void (*devmap_unmap)(devmap_cookie_t dhp, void *pvtp, offset_t off, 1267c478bd9Sstevel@tonic-gate size_t len, devmap_cookie_t new_dhp1, 1277c478bd9Sstevel@tonic-gate void **new_pvtp1, devmap_cookie_t new_dhp2, 1287c478bd9Sstevel@tonic-gate void **new_pvtp2); 1297c478bd9Sstevel@tonic-gate }; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate struct devmap_softlock { 1327c478bd9Sstevel@tonic-gate ulong_t id; /* handle grouping id */ 1337c478bd9Sstevel@tonic-gate dev_t dev; /* Device to which we are mapping */ 1347c478bd9Sstevel@tonic-gate struct devmap_softlock *next; 1357c478bd9Sstevel@tonic-gate kmutex_t lock; 1367c478bd9Sstevel@tonic-gate kcondvar_t cv; 1377c478bd9Sstevel@tonic-gate int refcnt; /* Number of threads with mappings */ 1387c478bd9Sstevel@tonic-gate ssize_t softlocked; 1397c478bd9Sstevel@tonic-gate }; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate struct devmap_ctx { 1427c478bd9Sstevel@tonic-gate ulong_t id; /* handle grouping id */ 1437c478bd9Sstevel@tonic-gate dev_info_t *dip; /* Device info struct for tracing context */ 1447c478bd9Sstevel@tonic-gate struct devmap_ctx *next; 1457c478bd9Sstevel@tonic-gate kmutex_t lock; 1467c478bd9Sstevel@tonic-gate kcondvar_t cv; 1477c478bd9Sstevel@tonic-gate int refcnt; /* Number of threads with mappings */ 1487c478bd9Sstevel@tonic-gate uint_t oncpu; /* this context is running on a cpu */ 1497c478bd9Sstevel@tonic-gate timeout_id_t timeout; /* Timeout ID */ 1507c478bd9Sstevel@tonic-gate }; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate /* 1537c478bd9Sstevel@tonic-gate * Fault information passed to the driver fault handling routine. 1547c478bd9Sstevel@tonic-gate * The DEVMAP_LOCK and DEVMAP_UNLOCK are used by software 1557c478bd9Sstevel@tonic-gate * to lock and unlock pages for physical I/O. 1567c478bd9Sstevel@tonic-gate */ 1577c478bd9Sstevel@tonic-gate enum devmap_fault_type { 1587c478bd9Sstevel@tonic-gate DEVMAP_ACCESS, /* invalid page */ 1597c478bd9Sstevel@tonic-gate DEVMAP_PROT, /* protection fault */ 1607c478bd9Sstevel@tonic-gate DEVMAP_LOCK, /* software requested locking */ 1617c478bd9Sstevel@tonic-gate DEVMAP_UNLOCK /* software requested unlocking */ 1627c478bd9Sstevel@tonic-gate }; 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate /* 1657c478bd9Sstevel@tonic-gate * seg_rw gives the access type for a fault operation 1667c478bd9Sstevel@tonic-gate */ 1677c478bd9Sstevel@tonic-gate enum devmap_rw { 1687c478bd9Sstevel@tonic-gate DEVMAP_OTHER, /* unknown or not touched */ 1697c478bd9Sstevel@tonic-gate DEVMAP_READ, /* read access attempted */ 1707c478bd9Sstevel@tonic-gate DEVMAP_WRITE, /* write access attempted */ 1717c478bd9Sstevel@tonic-gate DEVMAP_EXEC, /* execution access attempted */ 1727c478bd9Sstevel@tonic-gate DEVMAP_CREATE /* create if page doesn't exist */ 1737c478bd9Sstevel@tonic-gate }; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate typedef struct devmap_handle { 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate /* 1787c478bd9Sstevel@tonic-gate * physical offset at the beginning of mapping. 1797c478bd9Sstevel@tonic-gate */ 1807c478bd9Sstevel@tonic-gate offset_t dh_roff; 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate /* 1837c478bd9Sstevel@tonic-gate * user offset at the beginning of mapping. 1847c478bd9Sstevel@tonic-gate */ 1857c478bd9Sstevel@tonic-gate offset_t dh_uoff; 1867c478bd9Sstevel@tonic-gate size_t dh_len; /* length of mapping */ 1877c478bd9Sstevel@tonic-gate dev_t dh_dev; /* dev_t for this mapping */ 1887c478bd9Sstevel@tonic-gate caddr_t dh_cvaddr; /* cookie virtual address */ 1897c478bd9Sstevel@tonic-gate caddr_t dh_uvaddr; /* user address within dh_seg */ 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * Lock protects fields that can change during remap 1937c478bd9Sstevel@tonic-gate * dh_roff, dh_cookie, dh_flags, dh_mmulevel, dh_maxprot, 1947c478bd9Sstevel@tonic-gate * dh_pfn, dh_hat_attr 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate kmutex_t dh_lock; 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate /* 1997c478bd9Sstevel@tonic-gate * to sync. faults for remap and unlocked kvaddr. 2007c478bd9Sstevel@tonic-gate */ 2017c478bd9Sstevel@tonic-gate struct seg *dh_seg; /* segment created for this mapping */ 2027c478bd9Sstevel@tonic-gate void *dh_pvtp; /* device mapping private data */ 2037c478bd9Sstevel@tonic-gate struct devmap_handle *dh_next; 2047c478bd9Sstevel@tonic-gate struct devmap_softlock *dh_softlock; 2057c478bd9Sstevel@tonic-gate struct devmap_ctx *dh_ctx; 2067c478bd9Sstevel@tonic-gate ddi_umem_cookie_t dh_cookie; /* kmem cookie */ 2077c478bd9Sstevel@tonic-gate devmap_pmem_cookie_t dh_pcookie; /* pmem cookie */ 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate /* 2107c478bd9Sstevel@tonic-gate * protection flag possible for attempted mapping. 2117c478bd9Sstevel@tonic-gate */ 2127c478bd9Sstevel@tonic-gate uint_t dh_prot; 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate /* 2157c478bd9Sstevel@tonic-gate * Current maximum protection flag for attempted mapping. 2167c478bd9Sstevel@tonic-gate * This controls how dh_prot can be changed in segdev_setprot 2177c478bd9Sstevel@tonic-gate * See dh_orig_maxprot below also 2187c478bd9Sstevel@tonic-gate */ 2197c478bd9Sstevel@tonic-gate uint_t dh_maxprot; 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate /* 2227c478bd9Sstevel@tonic-gate * mmu level corresponds to the Max page size can be use for 2237c478bd9Sstevel@tonic-gate * the mapping. 2247c478bd9Sstevel@tonic-gate */ 2257c478bd9Sstevel@tonic-gate uint_t dh_mmulevel; 2267c478bd9Sstevel@tonic-gate uint_t dh_flags; /* see defines below */ 2277c478bd9Sstevel@tonic-gate pfn_t dh_pfn; /* pfn corresponds to dh_reg_off */ 2287c478bd9Sstevel@tonic-gate uint_t dh_hat_attr; 2297c478bd9Sstevel@tonic-gate clock_t dh_timeout_length; 2307c478bd9Sstevel@tonic-gate struct devmap_callback_ctl dh_callbackops; 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate /* 2337c478bd9Sstevel@tonic-gate * orig_maxprot is what the original mmap set maxprot to. 2347c478bd9Sstevel@tonic-gate * This is never modified once it is setup during mmap(2) 2357c478bd9Sstevel@tonic-gate * This is different from the current dh_maxprot which can 2367c478bd9Sstevel@tonic-gate * be changed in devmap_*_setup/remap 2377c478bd9Sstevel@tonic-gate */ 2387c478bd9Sstevel@tonic-gate uint_t dh_orig_maxprot; 2397c478bd9Sstevel@tonic-gate } devmap_handle_t; 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate /* 2447c478bd9Sstevel@tonic-gate * define for devmap_rev 2457c478bd9Sstevel@tonic-gate */ 2467c478bd9Sstevel@tonic-gate #define DEVMAP_OPS_REV 1 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate /* 2497c478bd9Sstevel@tonic-gate * defines for devmap_*_setup flag, called by drivers 2507c478bd9Sstevel@tonic-gate */ 2517c478bd9Sstevel@tonic-gate #define DEVMAP_DEFAULTS 0x00 2527c478bd9Sstevel@tonic-gate #define DEVMAP_MAPPING_INVALID 0x01 /* mapping is invalid */ 2537c478bd9Sstevel@tonic-gate #define DEVMAP_ALLOW_REMAP 0x02 /* allow remap */ 2547c478bd9Sstevel@tonic-gate #define DEVMAP_USE_PAGESIZE 0x04 /* use pagesize for mmu load */ 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate /* flags used by drivers */ 2577c478bd9Sstevel@tonic-gate #define DEVMAP_SETUP_FLAGS \ 2587c478bd9Sstevel@tonic-gate (DEVMAP_MAPPING_INVALID | DEVMAP_ALLOW_REMAP | DEVMAP_USE_PAGESIZE) 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate /* 2617c478bd9Sstevel@tonic-gate * defines for dh_flags, these are used internally in devmap 2627c478bd9Sstevel@tonic-gate */ 2637c478bd9Sstevel@tonic-gate #define DEVMAP_SETUP_DONE 0x100 /* mapping setup is done */ 2647c478bd9Sstevel@tonic-gate #define DEVMAP_LOCK_INITED 0x200 /* locks are initailized */ 2657c478bd9Sstevel@tonic-gate #define DEVMAP_LOCKED 0x800 /* dhp is locked. */ 2667c478bd9Sstevel@tonic-gate #define DEVMAP_FLAG_LARGE 0x1000 /* cal. optimal pgsize */ 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate /* 2697c478bd9Sstevel@tonic-gate * Flags to pass to ddi_umem_alloc and ddi_umem_iosetup 2707c478bd9Sstevel@tonic-gate */ 2717c478bd9Sstevel@tonic-gate #define DDI_UMEM_SLEEP 0x0 2727c478bd9Sstevel@tonic-gate #define DDI_UMEM_NOSLEEP 0x01 2737c478bd9Sstevel@tonic-gate #define DDI_UMEM_PAGEABLE 0x02 2747c478bd9Sstevel@tonic-gate #define DDI_UMEM_TRASH 0x04 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate /* 2777c478bd9Sstevel@tonic-gate * Flags to pass to ddi_umem_lock to indicate expected access pattern 2787c478bd9Sstevel@tonic-gate * DDI_UMEMLOCK_READ implies the memory being locked will be read 2797c478bd9Sstevel@tonic-gate * (e.g., data read from memory is written out to the disk or network) 2807c478bd9Sstevel@tonic-gate * DDI_UMEMLOCK_WRITE implies the memory being locked will be written 2817c478bd9Sstevel@tonic-gate * (e.g., data from the disk or network is written to memory) 2827c478bd9Sstevel@tonic-gate * Both flags may be set in the call to ddi_umem_lock, 2837c478bd9Sstevel@tonic-gate * Note that this corresponds to the VM subsystem definition of read/write 2847c478bd9Sstevel@tonic-gate * and also correspond to the prots set in devmap 2857c478bd9Sstevel@tonic-gate * When doing I/O, B_READ/B_WRITE are used which have exactly the opposite 2867c478bd9Sstevel@tonic-gate * meaning. Be careful when using it both for I/O and devmap 2877c478bd9Sstevel@tonic-gate * 2887c478bd9Sstevel@tonic-gate * 2897c478bd9Sstevel@tonic-gate */ 2907c478bd9Sstevel@tonic-gate #define DDI_UMEMLOCK_READ 0x01 2917c478bd9Sstevel@tonic-gate #define DDI_UMEMLOCK_WRITE 0x02 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate #endif 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate #endif /* _SYS_DDIDEVMAP_H */ 298