xref: /illumos-gate/usr/src/uts/i86pc/io/gfx_private/gfxp_devmap.c (revision 7b93957c241820af312fd1aad1e23e305a8dabbf)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/debug.h>
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/time.h>
33 #include <sys/buf.h>
34 #include <sys/errno.h>
35 #include <sys/systm.h>
36 #include <sys/conf.h>
37 #include <sys/signal.h>
38 #include <vm/page.h>
39 #include <vm/as.h>
40 #include <vm/hat.h>
41 #include <vm/seg.h>
42 #include <vm/seg_dev.h>
43 #include <vm/hat_i86.h>
44 #include <sys/ddi.h>
45 #include <sys/devops.h>
46 #include <sys/sunddi.h>
47 #include <sys/ddi_impldefs.h>
48 #include <sys/fs/snode.h>
49 #include <sys/pci.h>
50 #include <sys/vmsystm.h>
51 #include "gfx_private.h"
52 
53 /*
54  * Create a dummy ddi_umem_cookie given to gfxp_devmap_umem_setup().
55  */
56 ddi_umem_cookie_t
57 gfxp_umem_cookie_init(caddr_t kva, size_t size)
58 {
59 	struct ddi_umem_cookie *umem_cookie;
60 
61 	umem_cookie = kmem_zalloc(sizeof (struct ddi_umem_cookie), KM_SLEEP);
62 
63 	if (umem_cookie == NULL)
64 		return (NULL);
65 
66 	umem_cookie->cvaddr = kva;
67 	umem_cookie->type = KMEM_NON_PAGEABLE;
68 	umem_cookie->size = size;
69 
70 	return ((ddi_umem_cookie_t *)umem_cookie);
71 }
72 
73 void
74 gfxp_umem_cookie_destroy(ddi_umem_cookie_t cookie)
75 {
76 	kmem_free(cookie, sizeof (struct ddi_umem_cookie));
77 }
78 
79 /*
80  * called by driver devmap routine to pass kernel virtual address mapping
81  * info to the framework.
82  */
83 /*ARGSUSED*/
84 int
85 gfxp_devmap_umem_setup(devmap_cookie_t dhc, dev_info_t *dip,
86     struct devmap_callback_ctl *callbackops, ddi_umem_cookie_t cookie,
87     offset_t off, size_t len, uint_t maxprot, uint_t flags,
88     ddi_device_acc_attr_t *accattrp)
89 {
90 	uint_t l_flags = flags & ~IOMEM_DATA_MASK; /* clear cache attrs */
91 	int e;
92 
93 	/*
94 	 * Set an appropriate attribute from devacc_attr_dataorder
95 	 * to keep compatibility. The cache attributes are igonred
96 	 * if specified.
97 	 */
98 	if (accattrp != NULL) {
99 		if (accattrp->devacc_attr_dataorder == DDI_STRICTORDER_ACC) {
100 			l_flags |= IOMEM_DATA_UNCACHED;
101 		} else if (accattrp->devacc_attr_dataorder ==
102 		    DDI_MERGING_OK_ACC) {
103 			l_flags |= IOMEM_DATA_UC_WR_COMBINE;
104 		} else {
105 			l_flags |= IOMEM_DATA_CACHED;
106 		}
107 	}
108 
109 	e = devmap_umem_setup(dhc, dip, callbackops, cookie, off, len, maxprot,
110 	    l_flags, accattrp);
111 	return (e);
112 }
113