2 .\" Copyright (c) 1996, Sun Microsystems, Inc. All Rights Reserved
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH DEVMAP_CONTEXTMGT 9E "Jan 16, 1997"
8 devmap_contextmgt \- driver callback function for context management
13 #include <sys/sunddi.h>
17 \fBint\fR \fBdevmap_contextmgt\fR(\fBdevmap_cookie_t\fR \fIdhp\fR, \fBvoid *\fR\fIpvtp\fR,
18 \fBoffset_t\fR \fIoff\fR, \fBsize_t\fR \fIlen\fR, \fBuint_t\fR \fItype\fR, \fBuint_t\fR \fIrw\fR);
24 Solaris DDI specific (Solaris DDI).
32 An opaque mapping handle that the system uses to describe the mapping.
41 Driver private mapping data.
50 User offset within the logical device memory at which the access begins.
59 Length (in bytes) of the memory being accessed.
68 Type of access operation. Possible values are:
72 \fB\fBDEVMAP_ACCESS\fR \fR
81 \fB\fBDEVMAP_LOCK\fR \fR
84 Lock the memory being accessed.
90 \fB\fBDEVMAP_UNLOCK\fR \fR
93 Unlock the memory being accessed.
104 Direction of access. Possible values are:
108 \fB\fBDEVMAP_READ\fR \fR
111 Read access attempted.
117 \fB\fBDEVMAP_WRITE\fR \fR
120 Write access attempted.
128 \fBdevmap_contextmgt()\fR is a driver-supplied function that performs device
129 context switching on a mapping. Device drivers pass \fBdevmap_contextmgt()\fR
130 as an argument to \fBdevmap_do_ctxmgt\fR(9F) in the \fBdevmap_access\fR(9E)
131 entry point. The system will call \fBdevmap_contextmgt()\fR when memory is
132 accessed. The system expects \fBdevmap_contextmgt()\fR to load the memory
133 address translations of the mapping by calling \fBdevmap_load\fR(9F) before
137 \fIdhp\fR uniquely identifies the mapping and is used as an argument to
138 \fBdevmap_load\fR(9F) to validate the mapping. \fIoff\fR and \fIlen\fR define
139 the range to be affected by the operations in \fBdevmap_contextmgt()\fR.
142 The driver must check if there is already a mapping established at \fIoff\fR
143 that needs to be unloaded. If a mapping exists at \fIoff\fR,
144 \fBdevmap_contextmgt()\fR must call \fBdevmap_unload\fR(9F) on the current
145 mapping. \fBdevmap_unload\fR(9F) must be followed by \fBdevmap_load()\fR on the
146 mapping that generated this call to \fBdevmap_contextmgt()\fR.
147 \fBdevmap_unload\fR(9F) unloads the current mapping so that a call to
148 \fBdevmap_access\fR(9E), which causes the system to call
149 \fBdevmap_contextmgt()\fR, will be generated the next time the mapping is
153 \fIpvtp\fR is a pointer to the driver's private mapping data that was allocated
154 and initialized in the \fBdevmap_map\fR(9E) entry point. \fItype\fR defines the
155 type of operation that device drivers should perform on the memory object. If
156 \fItype\fR is either \fBDEVMAP_LOCK\fR or \fBDEVMAP_UNLOCK\fR, the length
157 passed to either \fBdevmap_unload\fR(9F) or \fBdevmap_load\fR(9F) must be same
158 as \fIlen\fR. \fIrw\fR specifies the access direction on the memory object.
161 A non-zero return value from \fBdevmap_contextmgt()\fR will be returned to
162 \fBdevmap_access\fR(9E) and will cause the corresponding operation to fail. The
163 failure may result in a \fBSIGSEGV\fR or \fBSIGBUS\fR signal being delivered to
172 Successful completion.
186 \fBExample 1 \fRmanaging a device context
189 The following shows an example of managing a device context.
194 struct xxcontext cur_ctx;
196 xxdevmap_contextmgt(devmap_cookie_t dhp, void *pvtp, offset_t off,
197 size_t len, uint_t type, uint_t rw)
199 devmap_cookie_t cur_dhp;
201 struct xxpvtdata *pvp = (struct xxpvtdata *)pvtp;
202 struct xx_softc *softc = pvp->softc;
205 mutex_enter(&softc->mutex);
208 * invalidate the translations of current context before
211 if (cur_ctx != NULL && cur_ctx != pvp->ctx) {
214 if ((err = devmap_unload(cur_dhp, off, len)) != 0)
217 /* Switch device context - device dependent*/
219 /* Make handle the new current mapping */
223 * Load the address translations of the calling context.
225 err = devmap_load(pvp->dhp, off, len, type, rw);
227 mutex_exit(&softc->mutex);
237 \fBdevmap_access\fR(9E), \fBdevmap_do_ctxmgt\fR(9F) \fBdevmap_load\fR(9F),
238 \fBdevmap_unload\fR(9F)
241 \fIWriting Device Drivers\fR