Remove bogus checks after kmalloc(M_WAITOK) which never returns NULL.
[dragonfly.git] / sys / dev / drm / drm_scatter.h
blobad92f5f333972456b5f64b3d654be78f111ac5a0
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.
5 * All Rights Reserved.
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
16 * Software.
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.
26 * Authors:
27 * Gareth Hughes <gareth@valinux.com>
29 * $FreeBSD: src/sys/dev/drm/drm_scatter.h,v 1.4.2.1 2003/04/26 07:05:28 anholt Exp $
30 * $DragonFly: src/sys/dev/drm/Attic/drm_scatter.h,v 1.5 2008/01/06 16:55:49 swildner Exp $
33 #include "dev/drm/drmP.h"
35 #define DEBUG_SCATTER 0
37 #if __REALLY_HAVE_SG
39 void DRM(sg_cleanup)( drm_sg_mem_t *entry )
41 kfree( entry->virtual, DRM(M_DRM) );
43 DRM(free)( entry->busaddr,
44 entry->pages * sizeof(*entry->busaddr),
45 DRM_MEM_PAGES );
46 DRM(free)( entry,
47 sizeof(*entry),
48 DRM_MEM_SGLISTS );
51 int DRM(sg_alloc)( DRM_IOCTL_ARGS )
53 DRM_DEVICE;
54 drm_scatter_gather_t request;
55 drm_sg_mem_t *entry;
56 unsigned long pages;
58 DRM_DEBUG( "%s\n", __func__ );
60 if ( dev->sg )
61 return EINVAL;
63 DRM_COPY_FROM_USER_IOCTL(request, (drm_scatter_gather_t *)data,
64 sizeof(request) );
66 entry = DRM(alloc)( sizeof(*entry), DRM_MEM_SGLISTS );
67 if ( !entry )
68 return ENOMEM;
70 bzero( entry, sizeof(*entry) );
72 pages = round_page(request.size) / PAGE_SIZE;
73 DRM_DEBUG( "sg size=%ld pages=%ld\n", request.size, pages );
75 entry->pages = pages;
77 entry->busaddr = DRM(alloc)( pages * sizeof(*entry->busaddr),
78 DRM_MEM_PAGES );
79 if ( !entry->busaddr ) {
80 DRM(free)( entry,
81 sizeof(*entry),
82 DRM_MEM_SGLISTS );
83 return ENOMEM;
85 bzero( (void *)entry->busaddr, pages * sizeof(*entry->busaddr) );
87 entry->virtual = kmalloc( pages << PAGE_SHIFT, DRM(M_DRM), M_WAITOK );
88 bzero( entry->virtual, pages << PAGE_SHIFT );
90 entry->handle = (unsigned long)entry->virtual;
92 DRM_DEBUG( "sg alloc handle = %08lx\n", entry->handle );
93 DRM_DEBUG( "sg alloc virtual = %p\n", entry->virtual );
95 request.handle = entry->handle;
97 DRM_COPY_TO_USER_IOCTL( (drm_scatter_gather_t *)data,
98 request,
99 sizeof(request) );
101 dev->sg = entry;
103 return 0;
105 DRM(sg_cleanup)( entry );
106 return ENOMEM;
109 int DRM(sg_free)( DRM_IOCTL_ARGS )
111 DRM_DEVICE;
112 drm_scatter_gather_t request;
113 drm_sg_mem_t *entry;
115 DRM_COPY_FROM_USER_IOCTL( request, (drm_scatter_gather_t *)data,
116 sizeof(request) );
118 entry = dev->sg;
119 dev->sg = NULL;
121 if ( !entry || entry->handle != request.handle )
122 return EINVAL;
124 DRM_DEBUG( "sg free virtual = %p\n", entry->virtual );
126 DRM(sg_cleanup)( entry );
128 return 0;
131 #else /* __REALLY_HAVE_SG */
133 int DRM(sg_alloc)( DRM_IOCTL_ARGS )
135 return DRM_ERR(EINVAL);
137 int DRM(sg_free)( DRM_IOCTL_ARGS )
139 return DRM_ERR(EINVAL);
142 #endif