'\" te .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] .TH DEVMAP_DEVMEM_SETUP 9F "July 13, 2024" .SH NAME devmap_devmem_setup, devmap_umem_setup \- set driver memory mapping parameters .SH SYNOPSIS .nf #include #include \fBint\fR \fBdevmap_devmem_setup\fR(\fBdevmap_cookie_t\fR \fIdhp\fR, \fBdev_info_t *\fR\fIdip\fR, \fBstruct devmap_callback_ctl *\fR\fIcallbackops\fR, \fBuint_t\fR \fIrnumber\fR, \fBoffset_t\fR \fIroff\fR, \fBsize_t\fR \fIlen\fR, \fBuint_t\fR \fImaxprot\fR, \fBuint_t\fR \fIflags\fR, \fBconst ddi_device_acc_attr_t *\fR\fIaccattrp\fR); .fi .LP .nf \fBint\fR \fBdevmap_umem_setup\fR(\fBdevmap_cookie_t\fR \fIdhp\fR, \fBdev_info_t *\fR\fIdip\fR, \fBstruct devmap_callback_ctl *\fR\fIcallbackops\fR, \fBddi_umem_cookie_t\fR \fIcookie\fR, \fBoffset_t\fR \fIkoff\fR, \fBsize_t\fR \fIlen\fR, \fBuint_t\fR \fImaxprot\fR, \fBuint_t\fR \fIflags\fR, \fBconst ddi_device_acc_attr_t *\fR\fIaccattrp\fR); .fi .SH INTERFACE LEVEL illumos DDI specific (illumos DDI). .SH PARAMETERS \fBdevmap_devmem_setup()\fR parameters: .sp .ne 2 .na \fB\fIdhp\fR\fR .ad .RS 15n An opaque mapping handle that the system uses to describe the mapping. .RE .sp .ne 2 .na \fB\fIdip\fR\fR .ad .RS 15n Pointer to the device's \fBdev_info\fR structure. .RE .sp .ne 2 .na \fB\fIcallbackops\fR\fR .ad .RS 15n Pointer to a \fBdevmap_callback_ctl\fR(9S) structure. The structure contains pointers to device driver-supplied functions that manage events on the device mapping. The framework will copy the structure to the system private memory. .RE .sp .ne 2 .na \fB\fIrnumber\fR\fR .ad .RS 15n Index number to the register address space set. .RE .sp .ne 2 .na \fB\fIroff\fR\fR .ad .RS 15n Offset into the register address space. .RE .sp .ne 2 .na \fB\fIlen\fR\fR .ad .RS 15n Length (in bytes) of the mapping to be mapped. .RE .sp .ne 2 .na \fB\fImaxprot\fR\fR .ad .RS 15n Maximum protection flag possible for attempted mapping. Some combinations of possible settings are: .sp .ne 2 .na \fB\fBPROT_READ\fR\fR .ad .RS 14n Read access is allowed. .RE .sp .ne 2 .na \fB\fBPROT_WRITE\fR\fR .ad .RS 14n Write access is allowed. .RE .sp .ne 2 .na \fB\fBPROT_EXEC\fR\fR .ad .RS 14n Execute access is allowed. .RE .sp .ne 2 .na \fB\fBPROT_USER\fR\fR .ad .RS 14n User-level access is allowed. The mapping is done as a result of a \fBmmap\fR(2) system call. .RE .sp .ne 2 .na \fB\fBPROT_ALL\fR\fR .ad .RS 14n All access is allowed. .RE .RE .sp .ne 2 .na \fB\fIflags\fR\fR .ad .RS 15n Used to determine the cache attribute. .sp Possible values of the cache attribute are: .sp .ne 2 .na \fB\fBIOMEM_DATA_CACHED\fR\fR .ad .RS 28n The CPU can cache the data it fetches and push it to memory at a later time. This is the default attribute that is used if no cache attributes are specified. .RE .sp .ne 2 .na \fB\fBIOMEM_DATA_UC_WR_COMBINE\fR\fR .ad .RS 28n The CPU never caches the data, but writes can occur out of order or can be combined. Reordering is implied. .sp If \fBIOMEM_DATA_UC_WR_COMBINE\fR is specified but not supported, \fBIOMEM_DATA_UNCACHED\fR is used instead. .RE .sp .ne 2 .na \fB\fBIOMEM_DATA_UNCACHED\fR\fR .ad .RS 28n The CPU never caches data, but has uncacheable access to memory. Strict ordering is implied. .RE The cache attributes are mutually exclusive. Any combination of the values leads to a failure. On the SPARC architecture, only \fBIOMEM_DATA_CACHED\fR is meaningful. Others lead to a failure. .RE .sp .ne 2 .na \fB\fIaccattrp\fR\fR .ad .RS 15n Pointer to a \fBddi_device_acc_attr()\fR structure of the device. See \fBddi_device_acc_attr\fR(9S). The value in \fBdevacc_attr_dataorder\fR is ignored in the current release. The value in \fBdevacc_attr_endian_flags\fR is meaningful on the SPARC architecture only. .RE .sp .LP \fBdevmap_umem_setup()\fR parameters: .sp .ne 2 .na \fB\fIdhp\fR\fR .ad .RS 15n An opaque data structure that the system uses to describe the mapping. .RE .sp .ne 2 .na \fB\fIdip\fR\fR .ad .RS 15n Pointer to the device's \fBdev_info\fR structure. .RE .sp .ne 2 .na \fB\fIcallbackops\fR\fR .ad .RS 15n Pointer to a \fBdevmap_callback_ctl\fR(9S) structure. The structure contains pointers to device driver-supplied functions that manage events on the device mapping. .RE .sp .ne 2 .na \fB\fIcookie\fR\fR .ad .RS 15n A kernel memory \fIcookie\fR (see \fBddi_umem_alloc\fR(9F)). .RE .sp .ne 2 .na \fB\fIkoff\fR\fR .ad .RS 15n Offset into the kernel memory defined by \fIcookie\fR. .RE .sp .ne 2 .na \fB\fIlen\fR\fR .ad .RS 15n Length (in bytes) of the mapping to be mapped. .RE .sp .ne 2 .na \fB\fImaxprot\fR\fR .ad .RS 15n Maximum protection flag possible for attempted mapping. Some combinations of possible settings are: .sp .ne 2 .na \fB\fBPROT_READ\fR\fR .ad .RS 14n Read access is allowed. .RE .sp .ne 2 .na \fB\fBPROT_WRITE\fR\fR .ad .RS 14n Write access is allowed. .RE .sp .ne 2 .na \fB\fBPROT_EXEC\fR\fR .ad .RS 14n Execute access is allowed. .RE .sp .ne 2 .na \fB\fBPROT_USER\fR\fR .ad .RS 14n User-level access is allowed (the mapping is being done as a result of a \fBmmap\fR(2) system call). .RE .sp .ne 2 .na \fB\fBPROT_ALL\fR\fR .ad .RS 14n All access is allowed. .RE .RE .sp .ne 2 .na \fB\fIflags\fR\fR .ad .RS 15n Must be set to \fB0\fR. .RE .sp .ne 2 .na \fB\fIaccattrp\fR\fR .ad .RS 15n Pointer to a \fBddi_device_acc_attr\fR(9S) structure. Ignored in the current release. Reserved for future use. .RE .SH DESCRIPTION The \fBdevmap_devmem_setup()\fR and \fBdevmap_umem_setup()\fR functions are used in the \fBdevmap\fR(9E) entry point to pass mapping parameters from the driver to the system. .sp .LP The \fIdhp\fR argument specifies a device mapping handle that the system uses to store all mapping parameters of a physical contiguous memory. The system copies the data pointed to by \fIcallbackops\fR to a system private memory. This allows the driver to free the data after returning from either \fBdevmap_devmem_setup()\fR or \fBdevmap_umem_setup()\fR. The driver is notified of user events on the mappings via the entry points defined by \fBdevmap_callback_ctl\fR(9S). The driver is notified of the following user events: .sp .ne 2 .na \fBMapping Setup\fR .ad .RS 17n User has called \fBmmap\fR(2) to create a mapping to the device memory. .RE .sp .ne 2 .na \fBAccess\fR .ad .RS 17n User has accessed an address in the mapping that has no translations. .RE .sp .ne 2 .na \fBDuplication\fR .ad .RS 17n User has duplicated the mapping. Mappings are duplicated when the process calls \fBfork\fR(2). .RE .sp .ne 2 .na \fBUnmapping\fR .ad .RS 17n User has called \fBmunmap\fR(2) on the mapping or is exiting, \fBexit\fR(2). .RE .sp .LP See \fBdevmap_map\fR(9E), \fBdevmap_access\fR(9E), \fBdevmap_dup\fR(9E), and \fBdevmap_unmap\fR(9E) for details on these entry points. .sp .LP By specifying a valid \fIcallbackops\fR to the system, device drivers can manage events on a device mapping. For example, the \fBdevmap_access\fR(9E) entry point allows the drivers to perform context switching by unloading the mappings of other processes and to load the mapping of the calling process. Device drivers may specify \fINULL\fR to \fIcallbackops\fR which means the drivers do not want to be notified by the system. .sp .LP The maximum protection allowed for the mapping is specified in \fImaxprot\fR. \fIaccattrp\fR defines the device access attributes. See \fBddi_device_acc_attr\fR(9S) for more details. .sp .LP \fBdevmap_devmem_setup()\fR is used for device memory to map in the register set given by \fIrnumber\fR and the offset into the register address space given by \fIroff\fR. The system uses \fIrnumber\fR and \fIroff\fR to go up the device tree to get the physical address that corresponds to \fIroff\fR. The range to be affected is defined by \fIlen\fR and \fIroff\fR. The range from \fIroff\fR to \fIroff\fR \fI+\fR \fIlen\fR must be a physical contiguous memory and page aligned. .sp .LP Drivers use \fBdevmap_umem_setup()\fR for kernel memory to map in the kernel memory described by \fIcookie\fR and the offset into the kernel memory space given by \fIkoff\fR. \fIcookie\fR is a kernel memory pointer obtained from \fBddi_umem_alloc\fR(9F). If \fIcookie\fR is \fINULL,\fR \fBdevmap_umem_setup()\fR returns \fB-1.\fR The range to be affected is defined by \fIlen\fR and \fIkoff\fR. The range from \fIkoff\fR to \fIkoff\fR \fI+\fR \fIlen\fR must be within the limits of the kernel memory described by \fIkoff\fR \fI+\fR \fIlen\fR and must be page aligned. .sp .LP Drivers use \fBdevmap_umem_setup()\fR to export the kernel memory allocated by \fBddi_umem_alloc\fR(9F) to user space. The system selects a user virtual address that is aligned with the kernel virtual address being mapped to avoid cache incoherence if the mapping is not \fBMAP_FIXED.\fR .SH RETURN VALUES .ne 2 .na \fB\fB0\fR\fR .ad .RS 6n Successful completion. .RE .sp .ne 2 .na \fB\fB-1\fR\fR .ad .RS 6n An error occurred. .RE .SH CONTEXT \fBdevmap_devmem_setup()\fR and \fBdevmap_umem_setup()\fR can be called from user, kernel, and interrupt context. .SH SEE ALSO .BR exit (2), .BR fork (2), .BR mmap (2), .BR munmap (2), .BR devmap (9E), .BR ddi_umem_alloc (9F), .BR ddi_device_acc_attr (9S), .BR devmap_callback_ctl (9S) .sp .LP \fIWriting Device Drivers\fR