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