Wed Jul 24 02:47:50 2013 UTC ()
Omit __drm_pci_free.  Use kmem for drm_dma_handles now that we can.


(riastradh)
diff -r1.1.2.3 -r1.1.2.4 src/sys/external/bsd/drm2/drm/drm_memory.c

cvs diff -r1.1.2.3 -r1.1.2.4 src/sys/external/bsd/drm2/drm/drm_memory.c (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/drm/drm_memory.c 2013/07/24 02:47:19 1.1.2.3
+++ src/sys/external/bsd/drm2/drm/drm_memory.c 2013/07/24 02:47:50 1.1.2.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: drm_memory.c,v 1.1.2.3 2013/07/24 02:47:19 riastradh Exp $ */ 1/* $NetBSD: drm_memory.c,v 1.1.2.4 2013/07/24 02:47:50 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_memory.c,v 1.1.2.3 2013/07/24 02:47:19 riastradh Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: drm_memory.c,v 1.1.2.4 2013/07/24 02:47:50 riastradh Exp $");
34 34
35/* XXX Cargo-culted from the old drm_memory.c. */ 35/* XXX Cargo-culted from the old drm_memory.c. */
36 36
37#ifdef _KERNEL_OPT 37#ifdef _KERNEL_OPT
38#include "agp_i810.h" 38#include "agp_i810.h"
39#include "genfb.h" 39#include "genfb.h"
40#else 40#else
41#define NAGP_I810 1 /* XXX WTF? */ 41#define NAGP_I810 1 /* XXX WTF? */
42#define NGENFB 0 /* XXX WTF? */ 42#define NGENFB 0 /* XXX WTF? */
43#endif 43#endif
44 44
45#include <sys/bus.h> 45#include <sys/bus.h>
46 46
@@ -230,31 +230,29 @@ drm_iounmap(struct drm_device *dev, stru @@ -230,31 +230,29 @@ drm_iounmap(struct drm_device *dev, stru
230 * by ioctls with the drm global mutex held. 230 * by ioctls with the drm global mutex held.
231 * 231 *
232 * XXX Error information is lost because this returns NULL on failure, 232 * XXX Error information is lost because this returns NULL on failure,
233 * not even an error embedded in a pointer. 233 * not even an error embedded in a pointer.
234 */ 234 */
235struct drm_dma_handle * 235struct drm_dma_handle *
236drm_pci_alloc(struct drm_device *dev, size_t size, size_t align) 236drm_pci_alloc(struct drm_device *dev, size_t size, size_t align)
237{ 237{
238 int nsegs; 238 int nsegs;
239 int error; 239 int error;
240 240
241 /* 241 /*
242 * Allocate a drm_dma_handle record. 242 * Allocate a drm_dma_handle record.
243 * 
244 * XXX Must use kzalloc because callers pass this to kfree, not 
245 * necessarily to drm_pci_free. Whattakludge. 
246 */ 243 */
247 struct drm_dma_handle *const dmah = kzalloc(sizeof(*dmah), GFP_ATOMIC); 244 struct drm_dma_handle *const dmah = kmem_alloc(sizeof(*dmah),
 245 KM_NOSLEEP);
248 if (dmah == NULL) { 246 if (dmah == NULL) {
249 error = -ENOMEM; 247 error = -ENOMEM;
250 goto out; 248 goto out;
251 } 249 }
252 dmah->dmah_tag = dev->dmat; 250 dmah->dmah_tag = dev->dmat;
253 251
254 /* 252 /*
255 * Allocate the requested amount of DMA-safe memory. 253 * Allocate the requested amount of DMA-safe memory.
256 */ 254 */
257 /* XXX errno NetBSD->Linux */ 255 /* XXX errno NetBSD->Linux */
258 error = -bus_dmamem_alloc(dmah->dmah_tag, size, align, 0, 256 error = -bus_dmamem_alloc(dmah->dmah_tag, size, align, 0,
259 &dmah->dmah_seg, 1, &nsegs, BUS_DMA_NOWAIT); 257 &dmah->dmah_seg, 1, &nsegs, BUS_DMA_NOWAIT);
260 if (error) 258 if (error)
@@ -298,42 +296,32 @@ drm_pci_alloc(struct drm_device *dev, si @@ -298,42 +296,32 @@ drm_pci_alloc(struct drm_device *dev, si
298 /* Record the bus address for convenient reference. */ 296 /* Record the bus address for convenient reference. */
299 dmah->busaddr = dmah->dmah_map->dm_segs[0].ds_addr; 297 dmah->busaddr = dmah->dmah_map->dm_segs[0].ds_addr;
300 298
301 /* Zero the DMA buffer. XXX Yikes! Is this necessary? */ 299 /* Zero the DMA buffer. XXX Yikes! Is this necessary? */
302 memset(dmah->vaddr, 0, size); 300 memset(dmah->vaddr, 0, size);
303 301
304 /* Success! */ 302 /* Success! */
305 return dmah; 303 return dmah;
306 304
307fail3: bus_dmamap_destroy(dmah->dmah_tag, dmah->dmah_map); 305fail3: bus_dmamap_destroy(dmah->dmah_tag, dmah->dmah_map);
308fail2: bus_dmamem_unmap(dmah->dmah_tag, dmah->vaddr, dmah->size); 306fail2: bus_dmamem_unmap(dmah->dmah_tag, dmah->vaddr, dmah->size);
309fail1: bus_dmamem_free(dmah->dmah_tag, &dmah->dmah_seg, 1); 307fail1: bus_dmamem_free(dmah->dmah_tag, &dmah->dmah_seg, 1);
310fail0: dmah->dmah_tag = NULL; /* XXX paranoia */ 308fail0: dmah->dmah_tag = NULL; /* XXX paranoia */
311 kfree(dmah); 309 kmem_free(dmah, sizeof(*dmah));
312out: DRM_DEBUG("drm_pci_alloc failed: %d\n", error); 310out: DRM_DEBUG("drm_pci_alloc failed: %d\n", error);
313 return NULL; 311 return NULL;
314} 312}
315 313
316/* 314/*
317 * Release the bus DMA mappings and memory in dmah. 315 * Release the bus DMA mappings and memory in dmah, and deallocate it.
318 */ 316 */
319void 317void
320__drm_pci_free(struct drm_device *dev, struct drm_dma_handle *dmah) 318drm_pci_free(struct drm_device *dev, struct drm_dma_handle *dmah)
321{ 319{
322 320
323 bus_dmamap_unload(dmah->dmah_tag, dmah->dmah_map); 321 bus_dmamap_unload(dmah->dmah_tag, dmah->dmah_map);
324 bus_dmamap_destroy(dmah->dmah_tag, dmah->dmah_map); 322 bus_dmamap_destroy(dmah->dmah_tag, dmah->dmah_map);
325 bus_dmamem_unmap(dmah->dmah_tag, dmah->vaddr, dmah->size); 323 bus_dmamem_unmap(dmah->dmah_tag, dmah->vaddr, dmah->size);
326 bus_dmamem_free(dmah->dmah_tag, &dmah->dmah_seg, 1); 324 bus_dmamem_free(dmah->dmah_tag, &dmah->dmah_seg, 1);
327 dmah->dmah_tag = NULL; /* XXX paranoia */ 325 dmah->dmah_tag = NULL; /* XXX paranoia */
328} 326 kmem_free(dmah, sizeof(*dmah));
329 
330/* 
331 * Release the bus DMA mappings and memory in dmah, and deallocate it. 
332 */ 
333void 
334drm_pci_free(struct drm_device *dev, struct drm_dma_handle *dmah) 
335{ 
336 
337 __drm_pci_free(dev, dmah); 
338 kfree(dmah); 
339} 327}