1 /* drm_scatter.h -- IOCTLs to manage scatter/gather memory -*- linux-c -*-
2 * Created: Mon Dec 18 23:20:54 2000 by gareth@valinux.com */
4 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
27 * Gareth Hughes <gareth@valinux.com>
28 * Eric Anholt <anholt@FreeBSD.org>
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "dev/drm/drmP.h"
37 #define DEBUG_SCATTER 0
39 void drm_sg_cleanup(drm_sg_mem_t *entry)
41 free((void *)entry->handle, M_DRM);
42 free(entry->busaddr, M_DRM);
46 int drm_sg_alloc(DRM_IOCTL_ARGS)
49 drm_scatter_gather_t request;
54 DRM_DEBUG( "%s\n", __FUNCTION__ );
59 DRM_COPY_FROM_USER_IOCTL(request, (drm_scatter_gather_t *)data,
62 entry = malloc(sizeof(*entry), M_DRM, M_WAITOK | M_ZERO);
66 pages = round_page(request.size) / PAGE_SIZE;
67 DRM_DEBUG( "sg size=%ld pages=%ld\n", request.size, pages );
71 entry->busaddr = malloc(pages * sizeof(*entry->busaddr), M_DRM,
73 if ( !entry->busaddr ) {
74 drm_sg_cleanup(entry);
78 entry->handle = (long)malloc(pages << PAGE_SHIFT, M_DRM,
80 if (entry->handle == 0) {
81 drm_sg_cleanup(entry);
85 for (i = 0; i < pages; i++) {
86 entry->busaddr[i] = vtophys(entry->handle + i * PAGE_SIZE);
89 DRM_DEBUG( "sg alloc handle = %08lx\n", entry->handle );
91 request.handle = entry->handle;
93 DRM_COPY_TO_USER_IOCTL( (drm_scatter_gather_t *)data,
100 drm_sg_cleanup(entry);
109 int drm_sg_free(DRM_IOCTL_ARGS)
112 drm_scatter_gather_t request;
115 DRM_COPY_FROM_USER_IOCTL( request, (drm_scatter_gather_t *)data,
123 if ( !entry || entry->handle != request.handle )
126 DRM_DEBUG( "sg free virtual = 0x%lx\n", entry->handle );
128 drm_sg_cleanup(entry);