drm_scatter.c (158682) | drm_scatter.c (182080) |
---|---|
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 */ | |
3/*- 4 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 5 * All Rights Reserved. 6 * 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, --- 14 unchanged lines hidden (view full) --- 25 * 26 * Authors: 27 * Gareth Hughes <gareth@valinux.com> 28 * Eric Anholt <anholt@FreeBSD.org> 29 * 30 */ 31 32#include <sys/cdefs.h> | 1/*- 2 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 3 * All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, --- 14 unchanged lines hidden (view full) --- 23 * 24 * Authors: 25 * Gareth Hughes <gareth@valinux.com> 26 * Eric Anholt <anholt@FreeBSD.org> 27 * 28 */ 29 30#include <sys/cdefs.h> |
33__FBSDID("$FreeBSD: head/sys/dev/drm/drm_scatter.c 158682 2006-05-17 06:29:36Z anholt $"); | 31__FBSDID("$FreeBSD: head/sys/dev/drm/drm_scatter.c 182080 2008-08-23 20:59:12Z rnoland $"); |
34 | 32 |
33/** @file drm_scatter.c 34 * Allocation of memory for scatter-gather mappings by the graphics chip. 35 * 36 * The memory allocated here is then made into an aperture in the card 37 * by drm_ati_pcigart_init(). 38 */ 39 |
|
35#include "dev/drm/drmP.h" 36 37#define DEBUG_SCATTER 0 38 39void drm_sg_cleanup(drm_sg_mem_t *entry) 40{ 41 free((void *)entry->handle, M_DRM); 42 free(entry->busaddr, M_DRM); 43 free(entry, M_DRM); 44} 45 | 40#include "dev/drm/drmP.h" 41 42#define DEBUG_SCATTER 0 43 44void drm_sg_cleanup(drm_sg_mem_t *entry) 45{ 46 free((void *)entry->handle, M_DRM); 47 free(entry->busaddr, M_DRM); 48 free(entry, M_DRM); 49} 50 |
46int drm_sg_alloc(DRM_IOCTL_ARGS) | 51int drm_sg_alloc(struct drm_device * dev, drm_scatter_gather_t * request) |
47{ | 52{ |
48 DRM_DEVICE; 49 drm_scatter_gather_t request; | |
50 drm_sg_mem_t *entry; 51 unsigned long pages; 52 int i; 53 | 53 drm_sg_mem_t *entry; 54 unsigned long pages; 55 int i; 56 |
54 DRM_DEBUG( "%s\n", __FUNCTION__ ); 55 | |
56 if ( dev->sg ) 57 return EINVAL; 58 | 57 if ( dev->sg ) 58 return EINVAL; 59 |
59 DRM_COPY_FROM_USER_IOCTL(request, (drm_scatter_gather_t *)data, 60 sizeof(request) ); 61 | |
62 entry = malloc(sizeof(*entry), M_DRM, M_WAITOK | M_ZERO); 63 if ( !entry ) 64 return ENOMEM; 65 | 60 entry = malloc(sizeof(*entry), M_DRM, M_WAITOK | M_ZERO); 61 if ( !entry ) 62 return ENOMEM; 63 |
66 pages = round_page(request.size) / PAGE_SIZE; 67 DRM_DEBUG( "sg size=%ld pages=%ld\n", request.size, pages ); | 64 pages = round_page(request->size) / PAGE_SIZE; 65 DRM_DEBUG( "sg size=%ld pages=%ld\n", request->size, pages ); |
68 69 entry->pages = pages; 70 71 entry->busaddr = malloc(pages * sizeof(*entry->busaddr), M_DRM, 72 M_WAITOK | M_ZERO); 73 if ( !entry->busaddr ) { 74 drm_sg_cleanup(entry); 75 return ENOMEM; --- 8 unchanged lines hidden (view full) --- 84 85 for (i = 0; i < pages; i++) { 86 entry->busaddr[i] = vtophys(entry->handle + i * PAGE_SIZE); 87 } 88 89 DRM_DEBUG( "sg alloc handle = %08lx\n", entry->handle ); 90 91 entry->virtual = (void *)entry->handle; | 66 67 entry->pages = pages; 68 69 entry->busaddr = malloc(pages * sizeof(*entry->busaddr), M_DRM, 70 M_WAITOK | M_ZERO); 71 if ( !entry->busaddr ) { 72 drm_sg_cleanup(entry); 73 return ENOMEM; --- 8 unchanged lines hidden (view full) --- 82 83 for (i = 0; i < pages; i++) { 84 entry->busaddr[i] = vtophys(entry->handle + i * PAGE_SIZE); 85 } 86 87 DRM_DEBUG( "sg alloc handle = %08lx\n", entry->handle ); 88 89 entry->virtual = (void *)entry->handle; |
92 request.handle = entry->handle; | 90 request->handle = entry->handle; |
93 | 91 |
94 DRM_COPY_TO_USER_IOCTL( (drm_scatter_gather_t *)data, 95 request, 96 sizeof(request) ); 97 | |
98 DRM_LOCK(); 99 if (dev->sg) { 100 DRM_UNLOCK(); 101 drm_sg_cleanup(entry); 102 return EINVAL; 103 } 104 dev->sg = entry; 105 DRM_UNLOCK(); 106 107 return 0; 108} 109 | 92 DRM_LOCK(); 93 if (dev->sg) { 94 DRM_UNLOCK(); 95 drm_sg_cleanup(entry); 96 return EINVAL; 97 } 98 dev->sg = entry; 99 DRM_UNLOCK(); 100 101 return 0; 102} 103 |
110int drm_sg_free(DRM_IOCTL_ARGS) | 104int drm_sg_alloc_ioctl(struct drm_device *dev, void *data, 105 struct drm_file *file_priv) |
111{ | 106{ |
112 DRM_DEVICE; 113 drm_scatter_gather_t request; 114 drm_sg_mem_t *entry; | 107 drm_scatter_gather_t *request = data; 108 int ret; |
115 | 109 |
116 DRM_COPY_FROM_USER_IOCTL( request, (drm_scatter_gather_t *)data, 117 sizeof(request) ); | 110 DRM_DEBUG( "%s\n", __FUNCTION__ ); |
118 | 111 |
112 ret = drm_sg_alloc(dev, request); 113 return ret; 114} 115 116int drm_sg_free(struct drm_device *dev, void *data, struct drm_file *file_priv) 117{ 118 drm_scatter_gather_t *request = data; 119 drm_sg_mem_t *entry; 120 |
|
119 DRM_LOCK(); 120 entry = dev->sg; 121 dev->sg = NULL; 122 DRM_UNLOCK(); 123 | 121 DRM_LOCK(); 122 entry = dev->sg; 123 dev->sg = NULL; 124 DRM_UNLOCK(); 125 |
124 if ( !entry || entry->handle != request.handle ) | 126 if ( !entry || entry->handle != request->handle ) |
125 return EINVAL; 126 127 DRM_DEBUG( "sg free virtual = 0x%lx\n", entry->handle ); 128 129 drm_sg_cleanup(entry); 130 131 return 0; 132} | 127 return EINVAL; 128 129 DRM_DEBUG( "sg free virtual = 0x%lx\n", entry->handle ); 130 131 drm_sg_cleanup(entry); 132 133 return 0; 134} |