35 #include <linux/slab.h>
38 #define DEBUG_SCATTER 0
40 static inline void *drm_vmalloc_dma(
unsigned long size)
42 #if defined(__powerpc__) && defined(CONFIG_NOT_COHERENT_CACHE)
54 for (i = 0; i < entry->pages; i++) {
55 page = entry->pagelist[
i];
57 ClearPageReserved(page);
60 vfree(entry->virtual);
62 kfree(entry->busaddr);
63 kfree(entry->pagelist);
68 # define ScatterHandle(x) (unsigned int)((x >> 32) + (x & ((1L << 32) - 1)))
70 # define ScatterHandle(x) (unsigned int)(x)
75 struct drm_sg_mem *
entry;
80 if (!drm_core_check_feature(dev, DRIVER_SG))
91 DRM_DEBUG(
"size=%ld pages=%ld\n", request->
size, pages);
94 entry->pagelist = kcalloc(pages,
sizeof(*entry->pagelist),
GFP_KERNEL);
95 if (!entry->pagelist) {
100 entry->busaddr = kcalloc(pages,
sizeof(*entry->busaddr),
GFP_KERNEL);
101 if (!entry->busaddr) {
102 kfree(entry->pagelist);
107 entry->virtual = drm_vmalloc_dma(pages <<
PAGE_SHIFT);
108 if (!entry->virtual) {
109 kfree(entry->busaddr);
110 kfree(entry->pagelist);
120 entry->handle =
ScatterHandle((
unsigned long)entry->virtual);
122 DRM_DEBUG(
"handle = %08lx\n", entry->handle);
123 DRM_DEBUG(
"virtual = %p\n", entry->virtual);
125 for (i = (
unsigned long)entry->virtual, j = 0; j < pages;
128 if (!entry->pagelist[j])
130 SetPageReserved(entry->pagelist[j]);
133 request->
handle = entry->handle;
144 for (i = 0; i <
pages; i++) {
153 tmp = (
unsigned long *)((
u8 *) entry->virtual +
158 if (*tmp != 0xcafebabe && error == 0) {
160 DRM_ERROR(
"Scatter allocation error, "
161 "pagelist does not match "
162 "virtual mapping\n");
173 DRM_ERROR(
"Scatter allocation matches pagelist\n");
185 struct drm_file *file_priv)
194 struct drm_file *file_priv)
197 struct drm_sg_mem *
entry;
199 if (!drm_core_check_feature(dev, DRIVER_SG))
205 if (!entry || entry->handle != request->
handle)
208 DRM_DEBUG(
"virtual = %p\n", entry->virtual);