Wed Jul 24 03:27:52 2013 UTC ()
Use kmem for drm_sg_mem records in local drm_scatter.c.


(riastradh)
diff -r1.1.2.1 -r1.1.2.2 src/sys/external/bsd/drm2/drm/drm_scatter.c

cvs diff -r1.1.2.1 -r1.1.2.2 src/sys/external/bsd/drm2/drm/drm_scatter.c (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/drm/drm_scatter.c 2013/07/24 02:46:33 1.1.2.1
+++ src/sys/external/bsd/drm2/drm/drm_scatter.c 2013/07/24 03:27:52 1.1.2.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: drm_scatter.c,v 1.1.2.1 2013/07/24 02:46:33 riastradh Exp $ */ 1/* $NetBSD: drm_scatter.c,v 1.1.2.2 2013/07/24 03:27:52 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell. 8 * by Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: drm_scatter.c,v 1.1.2.1 2013/07/24 02:46:33 riastradh Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: drm_scatter.c,v 1.1.2.2 2013/07/24 03:27:52 riastradh Exp $");
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/bus.h> 36#include <sys/bus.h>
37#include <sys/errno.h> 37#include <sys/errno.h>
38#include <sys/systm.h> 38#include <sys/systm.h>
39 39
40#include <linux/slab.h> 40#include <linux/slab.h>
41 41
42#include <drm/drmP.h> 42#include <drm/drmP.h>
43 43
44static int drm_sg_alloc_mem(struct drm_device *, size_t, 44static int drm_sg_alloc_mem(struct drm_device *, size_t,
45 struct drm_sg_mem **); 45 struct drm_sg_mem **);
46 46
@@ -121,27 +121,28 @@ drm_sg_alloc_mem(struct drm_device *dev, @@ -121,27 +121,28 @@ drm_sg_alloc_mem(struct drm_device *dev,
121 int error; 121 int error;
122 122
123 KASSERT(drm_core_check_feature(dev, DRIVER_SG)); 123 KASSERT(drm_core_check_feature(dev, DRIVER_SG));
124 124
125 KASSERT(size <= (size_t)0xffffffffUL); /* XXX 32-bit sizes only? */ 125 KASSERT(size <= (size_t)0xffffffffUL); /* XXX 32-bit sizes only? */
126 const size_t nbytes = round_page(size); 126 const size_t nbytes = round_page(size);
127 const size_t npages = nbytes >> PAGE_SHIFT; 127 const size_t npages = nbytes >> PAGE_SHIFT;
128 KASSERT(npages <= (size_t)INT_MAX); 128 KASSERT(npages <= (size_t)INT_MAX);
129 129
130 /* 130 /*
131 * Allocate a drm_sg_mem record. 131 * Allocate a drm_sg_mem record.
132 */ 132 */
133 struct drm_sg_mem *const sg = 133 struct drm_sg_mem *const sg =
134 kzalloc(offsetof(struct drm_sg_mem, sg_segs[npages]), GFP_ATOMIC); 134 kmem_zalloc(offsetof(struct drm_sg_mem, sg_segs[npages]),
 135 KM_NOSLEEP);
135 if (sg == NULL) 136 if (sg == NULL)
136 return -ENOMEM; 137 return -ENOMEM;
137 sg->sg_tag = dev->dmat; 138 sg->sg_tag = dev->dmat;
138 sg->sg_nsegs_max = (unsigned int)npages; 139 sg->sg_nsegs_max = (unsigned int)npages;
139 140
140 /* 141 /*
141 * Allocate the requested amount of DMA-safe memory. 142 * Allocate the requested amount of DMA-safe memory.
142 */ 143 */
143 KASSERT(sg->sg_nsegs_max <= (unsigned int)INT_MAX); 144 KASSERT(sg->sg_nsegs_max <= (unsigned int)INT_MAX);
144 /* XXX errno NetBSD->Linux */ 145 /* XXX errno NetBSD->Linux */
145 error = -bus_dmamem_alloc(sg->sg_tag, nbytes, PAGE_SIZE, 0, 146 error = -bus_dmamem_alloc(sg->sg_tag, nbytes, PAGE_SIZE, 0,
146 sg->sg_segs, (int)sg->sg_nsegs_max, &nsegs, BUS_DMA_NOWAIT); 147 sg->sg_segs, (int)sg->sg_nsegs_max, &nsegs, BUS_DMA_NOWAIT);
147 if (error) 148 if (error)
@@ -205,15 +206,15 @@ fail0: sg->sg_tag = NULL; /* XXX paranoi @@ -205,15 +206,15 @@ fail0: sg->sg_tag = NULL; /* XXX paranoi
205 return error; 206 return error;
206} 207}
207 208
208void 209void
209drm_sg_cleanup(struct drm_sg_mem *sg) 210drm_sg_cleanup(struct drm_sg_mem *sg)
210{ 211{
211 212
212 bus_dmamap_unload(sg->sg_tag, sg->sg_map); 213 bus_dmamap_unload(sg->sg_tag, sg->sg_map);
213 bus_dmamap_destroy(sg->sg_tag, sg->sg_map); 214 bus_dmamap_destroy(sg->sg_tag, sg->sg_map);
214 bus_dmamem_unmap(sg->sg_tag, sg->virtual, sg->sg_size); 215 bus_dmamem_unmap(sg->sg_tag, sg->virtual, sg->sg_size);
215 KASSERT(sg->sg_nsegs <= (unsigned int)INT_MAX); 216 KASSERT(sg->sg_nsegs <= (unsigned int)INT_MAX);
216 bus_dmamem_free(sg->sg_tag, sg->sg_segs, (int)sg->sg_nsegs); 217 bus_dmamem_free(sg->sg_tag, sg->sg_segs, (int)sg->sg_nsegs);
217 sg->sg_tag = NULL; /* XXX paranoia */ 218 sg->sg_tag = NULL; /* XXX paranoia */
218 kfree(sg); 219 kmem_free(sg, offsetof(struct drm_sg_mem, sg_segs[sg->sg_nsegs_max]));
219} 220}