2 .\" Copyright 1989 AT&T
3 .\" Copyright (c) 1995, Sun Microsystems, Inc. All Rights Reserved
4 .\" 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.
5 .\" 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.
6 .\" 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]
7 .TH SEGMAP 9E "Jan 14, 1997"
9 segmap \- map device memory into user space
13 #include <sys/types.h>
15 #include <sys/param.h>
18 #include <sys/sunddi.h>
22 \fBint prefix\fR\fBsegmap\fR(\fBdev_t\fR \fIdev\fR, \fBoff_t\fR \fIoff\fR, \fBstruct as *\fR\fIasp\fR, \fBcaddr_t *\fR\fIaddrp\fR,
23 \fBoff_t\fR \fIlen\fR, \fBunsigned int\fR \fIprot\fR, \fBunsigned int\fR \fImaxprot\fR, \fBunsigned int\fR \fIflags\fR,
24 \fBcred_t *\fR\fIcred_p\fR);
30 Architecture independent level 2 (DKI only).
38 Device whose memory is to be mapped.
47 Offset within device memory at which mapping begins.
56 Pointer to the address space into which the device memory should be mapped.
65 Pointer to the address in the address space to which the device memory should
75 Length (in bytes) of the memory to be mapped.
84 A bit field that specifies the protections. Possible settings are:
88 \fB\fBPROT_READ\fR \fR
91 Read access is desired.
97 \fB\fBPROT_WRITE\fR \fR
100 Write access is desired.
106 \fB\fBPROT_EXEC\fR \fR
109 Execute access is desired.
115 \fB\fBPROT_USER\fR \fR
118 User-level access is desired (the mapping is being done as a result of a
119 \fBmmap\fR(2) system call).
125 \fB\fBPROT_ALL\fR \fR
128 All access is desired.
139 Maximum protection flag possible for attempted mapping; the \fBPROT_WRITE\fR
140 bit may be masked out if the user opened the special file read-only.
149 Flags indicating type of mapping. Possible values are (other bits may be set):
153 \fB\fBMAP_SHARED\fR \fR
156 Changes should be shared.
162 \fB\fBMAP_PRIVATE\fR \fR
176 Pointer to the user credentials structure.
182 The \fBsegmap()\fR entry point is an optional routine for character drivers
183 that support memory mapping. The \fBmmap\fR(2) system call, when applied to a
184 character special file, allows device memory to be mapped into user space for
185 direct access by the user application.
188 Typically, a character driver that needs to support the \fBmmap\fR(2) system
189 call supplies either an \fBdevmap\fR(9E) entry point, or both an
190 \fBdevmap\fR(9E) and a \fBsegmap()\fR entry point routine (see the
191 \fBdevmap\fR(9E) reference page). If no \fBsegmap()\fR entry point is provided
192 for the driver, \fBdevmap_setup\fR(9F) is used as a default.
195 A driver for a memory-mapped device would provide a \fBsegmap()\fR entry point
201 needs to maintain a separate context for each user mapping. See
202 \fBdevmap_setup\fR(9F) for details.
208 needs to assign device access attributes to the user mapping.
212 The responsibilities of a \fBsegmap()\fR entry point are:
217 Verify that the range, defined by \fIoffset\fR and \fIlen\fR, to be mapped is
218 valid for the device. Typically, this task is performed by calling the
219 \fBdevmap\fR(9E) entry point. Note that if you are using
220 \fBddi_devmap_segmap\fR(9F) or \fBdevmap_setup\fR(9F) to set up the mapping, it
221 will call your \fBdevmap\fR(9E) entry point for you to validate the range to be
228 Assign device access attributes to the mapping. See
229 \fBddi_devmap_segmap\fR(9F), and \fBddi_device_acc_attr\fR(9S) for details.
235 Set up device contexts for the user mapping if your device requires context
236 switching. See \fBdevmap_setup\fR(9F) for details.
242 Perform the mapping with \fBddi_devmap_segmap\fR(9F), or \fBdevmap_setup\fR(9F)
243 and return the status if it fails.
248 The \fBsegmap()\fR routine should return \fB0\fR if the driver is successful
249 in performing the memory map of its device address space into the specified
253 The \fBsegmap()\fR must return an error number on failure. For example, valid
254 error numbers would be \fBENXIO\fR if the offset/length pair specified exceeds
255 the limits of the device memory, or \fBEINVAL\fR if the driver detects an
256 invalid type of mapping attempted.
259 If one of the mapping routines \fBddi_devmap_segmap()\fR or
260 \fBdevmap_setup()\fRfails, you must return the error number returned by the
265 \fBmmap\fR(2), \fBdevmap\fR(9E), \fBdevmap_setup\fR(9F),
266 \fBddi_devmap_segmap\fR(9F), \fBddi_device_acc_attr\fR(9S)
269 \fIWriting Device Drivers\fR