2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
8 /* drm_scatter.h -- IOCTLs to manage scatter/gather memory -*- linux-c -*-
9 * Created: Mon Dec 18 23:20:54 2000 by gareth@valinux.com */
11 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
12 * All Rights Reserved.
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
21 * The above copyright notice and this permission notice (including the next
22 * paragraph) shall be included in all copies or substantial portions of the
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
29 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31 * DEALINGS IN THE SOFTWARE.
34 * Gareth Hughes <gareth@valinux.com>
35 * Eric Anholt <anholt@FreeBSD.org>
41 #include <sys/gfx_private.h>
44 #define DEBUG_SCATTER 0
47 #define ScatterHandle(x) (unsigned int)((x >> 32) + (x & ((1L << 32) - 1)))
49 #define ScatterHandle(x) (unsigned int)(x)
53 drm_sg_cleanup(drm_device_t
*dev
, drm_sg_mem_t
*entry
)
55 int pages
= entry
->pages
;
58 kmem_free(entry
->busaddr
, sizeof (*entry
->busaddr
) * pages
);
59 entry
->busaddr
= NULL
;
62 ASSERT(entry
->umem_cookie
== NULL
);
65 drm_pci_free(dev
, entry
->dmah_sg
);
66 entry
->dmah_sg
= NULL
;
69 if (entry
->dmah_gart
) {
70 drm_pci_free(dev
, entry
->dmah_gart
);
71 entry
->dmah_gart
= NULL
;
75 drm_free(entry
, sizeof (drm_sg_mem_t
), DRM_MEM_SGLISTS
);
82 drm_sg_alloc(DRM_IOCTL_ARGS
)
87 drm_dma_handle_t
*dmah
;
88 drm_scatter_gather_t request
;
90 DRM_DEBUG("%s\n", "drm_sg_alloc");
95 #ifdef _MULTI_DATAMODEL
96 if (ddi_model_convert_from(mode
& FMODELS
) == DDI_MODEL_ILP32
) {
97 drm_scatter_gather_32_t request32
;
99 DRM_COPYFROM_WITH_RETURN(&request32
, (void *)data
,
101 request
.size
= request32
.size
;
102 request
.handle
= request32
.handle
;
105 DRM_COPYFROM_WITH_RETURN(&request
, (void *)data
,
108 pages
= btopr(request
.size
);
109 DRM_DEBUG("sg size=%ld pages=%ld\n", request
.size
, pages
);
110 entry
= kmem_zalloc(sizeof (*entry
), KM_SLEEP
);
111 entry
->pages
= (int)pages
;
112 dmah
= drm_pci_alloc(dev
, ptob(pages
), 4096, 0xfffffffful
, pages
);
115 entry
->busaddr
= (void *)kmem_zalloc(sizeof (*entry
->busaddr
) *
118 entry
->handle
= ScatterHandle((unsigned long)dmah
->vaddr
);
119 entry
->virtual = (void *)dmah
->vaddr
;
120 request
.handle
= entry
->handle
;
121 entry
->dmah_sg
= dmah
;
122 #ifdef _MULTI_DATAMODEL
123 if (ddi_model_convert_from(mode
& FMODELS
) == DDI_MODEL_ILP32
) {
124 drm_scatter_gather_32_t data32
;
126 data32
.size
= (uint32_t)request
.size
;
127 data32
.handle
= (uint32_t)request
.handle
;
129 DRM_COPYTO_WITH_RETURN((void *)data
, &data32
,
133 DRM_COPYTO_WITH_RETURN((void *)data
, &request
,
139 drm_sg_cleanup(dev
, entry
);
148 drm_sg_cleanup(dev
, entry
);
154 drm_sg_free(DRM_IOCTL_ARGS
)
157 drm_scatter_gather_t request
;
160 #ifdef _MULTI_DATAMODEL
161 if (ddi_model_convert_from(mode
& FMODELS
) == DDI_MODEL_ILP32
) {
162 drm_scatter_gather_32_t request32
;
164 DRM_COPYFROM_WITH_RETURN(&request32
, (void *)data
,
166 request
.size
= request32
.size
;
167 request
.handle
= request32
.handle
;
170 DRM_COPYFROM_WITH_RETURN(&request
, (void *)data
,
178 if (!entry
|| entry
->handle
!= request
.handle
)
181 drm_sg_cleanup(dev
, entry
);