This source file includes following definitions.
- agp_remap
- drm_free_agp
- drm_bind_agp
- drm_unbind_agp
- agp_remap
- drm_legacy_ioremap
- drm_legacy_ioremap_wc
- drm_legacy_ioremapfree
- drm_need_swiotlb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 #include <linux/export.h>
37 #include <linux/highmem.h>
38 #include <linux/pci.h>
39 #include <linux/vmalloc.h>
40 #include <xen/xen.h>
41
42 #include <drm/drm_agpsupport.h>
43 #include <drm/drm_device.h>
44
45 #include "drm_legacy.h"
46
47 #if IS_ENABLED(CONFIG_AGP)
48
49 #ifdef HAVE_PAGE_AGP
50 # include <asm/agp.h>
51 #else
52 # ifdef __powerpc__
53 # define PAGE_AGP pgprot_noncached_wc(PAGE_KERNEL)
54 # else
55 # define PAGE_AGP PAGE_KERNEL
56 # endif
57 #endif
58
59 static void *agp_remap(unsigned long offset, unsigned long size,
60 struct drm_device *dev)
61 {
62 unsigned long i, num_pages =
63 PAGE_ALIGN(size) / PAGE_SIZE;
64 struct drm_agp_mem *agpmem;
65 struct page **page_map;
66 struct page **phys_page_map;
67 void *addr;
68
69 size = PAGE_ALIGN(size);
70
71 #ifdef __alpha__
72 offset -= dev->hose->mem_space->start;
73 #endif
74
75 list_for_each_entry(agpmem, &dev->agp->memory, head)
76 if (agpmem->bound <= offset
77 && (agpmem->bound + (agpmem->pages << PAGE_SHIFT)) >=
78 (offset + size))
79 break;
80 if (&agpmem->head == &dev->agp->memory)
81 return NULL;
82
83
84
85
86
87
88
89 page_map = vmalloc(array_size(num_pages, sizeof(struct page *)));
90 if (!page_map)
91 return NULL;
92
93 phys_page_map = (agpmem->memory->pages + (offset - agpmem->bound) / PAGE_SIZE);
94 for (i = 0; i < num_pages; ++i)
95 page_map[i] = phys_page_map[i];
96 addr = vmap(page_map, num_pages, VM_IOREMAP, PAGE_AGP);
97 vfree(page_map);
98
99 return addr;
100 }
101
102
103 void drm_free_agp(struct agp_memory *handle, int pages)
104 {
105 agp_free_memory(handle);
106 }
107
108
109 int drm_bind_agp(struct agp_memory *handle, unsigned int start)
110 {
111 return agp_bind_memory(handle, start);
112 }
113
114
115 int drm_unbind_agp(struct agp_memory *handle)
116 {
117 return agp_unbind_memory(handle);
118 }
119
120 #else
121 static inline void *agp_remap(unsigned long offset, unsigned long size,
122 struct drm_device *dev)
123 {
124 return NULL;
125 }
126
127 #endif
128
129 void drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev)
130 {
131 if (dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
132 map->handle = agp_remap(map->offset, map->size, dev);
133 else
134 map->handle = ioremap(map->offset, map->size);
135 }
136 EXPORT_SYMBOL(drm_legacy_ioremap);
137
138 void drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
139 {
140 if (dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
141 map->handle = agp_remap(map->offset, map->size, dev);
142 else
143 map->handle = ioremap_wc(map->offset, map->size);
144 }
145 EXPORT_SYMBOL(drm_legacy_ioremap_wc);
146
147 void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
148 {
149 if (!map->handle || !map->size)
150 return;
151
152 if (dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
153 vunmap(map->handle);
154 else
155 iounmap(map->handle);
156 }
157 EXPORT_SYMBOL(drm_legacy_ioremapfree);
158
159 bool drm_need_swiotlb(int dma_bits)
160 {
161 struct resource *tmp;
162 resource_size_t max_iomem = 0;
163
164
165
166
167
168
169
170
171
172
173 if (xen_pv_domain())
174 return true;
175
176
177
178
179
180 if (mem_encrypt_active())
181 return true;
182
183 for (tmp = iomem_resource.child; tmp; tmp = tmp->sibling) {
184 max_iomem = max(max_iomem, tmp->end);
185 }
186
187 return max_iomem > ((u64)1 << dma_bits);
188 }
189 EXPORT_SYMBOL(drm_need_swiotlb);