Copyright (c) 1996, 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]
#include <sys/ddi.h> #include <sys/sunddi.h> int devmap_setup(dev_t dev, offset_t off, ddi_as_handle_t as, caddr_t *addrp, size_tlen, uint_t prot, uint_t maxprot, uint_t flags, cred_t *cred);
int ddi_devmap_segmap(dev_t dev, off_t off, ddi_as_handle_t as, caddr_t *addrp, off_tlen, uint_t prot, uint_t maxprot, uint_t flags, cred_t *cred);
Device whose memory is to be mapped.
User offset within the logical device memory at which the mapping begins.
An opaque data structure that describes the address space into which the device memory should be mapped.
Pointer to the starting address in the address space into which the device memory should be mapped.
Length (in bytes) of the memory to be mapped.
A bit field that specifies the protections. Some possible settings combinations are: PROT_READ
Read access is desired.
Write access is desired.
Execute access is desired.
User-level access is desired (the mapping is being done as a result of a mmap(2) system call).
All access is desired.
Maximum protection flag possible for attempted mapping; the PROT_WRITE bit may be masked out if the user opened the special file read-only.
Flags indicating type of mapping. The following flags can be specified: MAP_PRIVATE
Changes are private.
Changes should be shared.
The user specified an address in *addrp rather than letting the system choose an address.
Pointer to the user credential structure.
use an optimal MMU pagesize to minimize address translations,
conserve kernel resources,
receive callbacks to manage events on the mapping,
export kernel memory to applications,
set up device contexts for the user mapping if the device requires context switching,
assign device access attributes to the user mapping, or
change the maximum protection for the mapping.
devmap_setup() must be called in the segmap(9E) entry point to establish the mapping for the application. ddi_devmap_segmap() can be called in, or be used as, the segmap(9E) entry point. The differences between devmap_setup() and ddi_devmap_segmap() are in the data type used for off and len.
When setting up the mapping, devmap_setup() and ddi_devmap_segmap() call the devmap(9E) entry point to validate the range to be mapped. The devmap(9E) entry point also translates the logical offset (as seen by the application) to the corresponding physical offset within the device address space. If the driver does not provide its own devmap(9E) entry point, EINVAL will be returned to the mmap(2) system call.
Successful completion.
An error occurred. The return value of devmap_setup() and ddi_devmap_segmap() should be used directly in the segmap(9E) entry point.
Writing Device Drivers