Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / char / drm / ati_pcigart.c
blobd47336a93d02d74996521951d0ea00e51ab5f921
1 /**
2 * \file ati_pcigart.c
3 * ATI PCI GART support
5 * \author Gareth Hughes <gareth@valinux.com>
6 */
8 /*
9 * Created: Wed Dec 13 21:52:19 2000 by gareth@valinux.com
11 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
12 * All Rights Reserved.
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
21 * The above copyright notice and this permission notice (including the next
22 * paragraph) shall be included in all copies or substantial portions of the
23 * Software.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
29 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31 * DEALINGS IN THE SOFTWARE.
34 #include "drmP.h"
36 # define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */
38 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
39 static void *drm_ati_alloc_pcigart_table(int order)
40 =======
41 static int drm_ati_alloc_pcigart_table(struct drm_device *dev,
42 struct drm_ati_pcigart_info *gart_info)
43 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
45 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
46 unsigned long address;
47 struct page *page;
48 int i;
50 DRM_DEBUG("%d order\n", order);
52 address = __get_free_pages(GFP_KERNEL | __GFP_COMP,
53 order);
54 if (address == 0UL) {
55 return NULL;
58 page = virt_to_page(address);
59 =======
60 gart_info->table_handle = drm_pci_alloc(dev, gart_info->table_size,
61 PAGE_SIZE,
62 gart_info->table_mask);
63 if (gart_info->table_handle == NULL)
64 return -ENOMEM;
65 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
67 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
68 for (i = 0; i < order; i++, page++)
69 SetPageReserved(page);
71 DRM_DEBUG("returning 0x%08lx\n", address);
72 return (void *)address;
73 =======
74 return 0;
75 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
78 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
79 static void drm_ati_free_pcigart_table(void *address, int order)
80 =======
81 static void drm_ati_free_pcigart_table(struct drm_device *dev,
82 struct drm_ati_pcigart_info *gart_info)
83 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
85 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
86 struct page *page;
87 int i;
88 int num_pages = 1 << order;
89 DRM_DEBUG("\n");
91 page = virt_to_page((unsigned long)address);
93 for (i = 0; i < num_pages; i++, page++)
94 ClearPageReserved(page);
96 free_pages((unsigned long)address, order);
97 =======
98 drm_pci_free(dev, gart_info->table_handle);
99 gart_info->table_handle = NULL;
100 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
103 int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info)
105 struct drm_sg_mem *entry = dev->sg;
106 unsigned long pages;
107 int i;
108 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
109 int order;
110 int num_pages, max_pages;
111 =======
112 int max_pages;
113 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
115 /* we need to support large memory configurations */
116 if (!entry) {
117 DRM_ERROR("no scatter/gather memory!\n");
118 return 0;
121 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
122 order = drm_order((gart_info->table_size + (PAGE_SIZE-1)) / PAGE_SIZE);
123 num_pages = 1 << order;
125 =======
126 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
127 if (gart_info->bus_addr) {
128 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
129 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
130 pci_unmap_single(dev->pdev, gart_info->bus_addr,
131 num_pages * PAGE_SIZE,
132 PCI_DMA_TODEVICE);
134 =======
135 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
137 max_pages = (gart_info->table_size / sizeof(u32));
138 pages = (entry->pages <= max_pages)
139 ? entry->pages : max_pages;
141 for (i = 0; i < pages; i++) {
142 if (!entry->busaddr[i])
143 break;
144 pci_unmap_single(dev->pdev, entry->busaddr[i],
145 PAGE_SIZE, PCI_DMA_TODEVICE);
148 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN)
149 gart_info->bus_addr = 0;
152 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
153 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN
154 && gart_info->addr) {
155 drm_ati_free_pcigart_table(gart_info->addr, order);
156 gart_info->addr = NULL;
157 =======
158 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN &&
159 gart_info->table_handle) {
160 drm_ati_free_pcigart_table(dev, gart_info);
161 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
164 return 1;
166 EXPORT_SYMBOL(drm_ati_pcigart_cleanup);
168 int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info)
170 struct drm_sg_mem *entry = dev->sg;
171 void *address = NULL;
172 unsigned long pages;
173 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
174 u32 *pci_gart, page_base, bus_address = 0;
175 =======
176 u32 *pci_gart, page_base;
177 dma_addr_t bus_address = 0;
178 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
179 int i, j, ret = 0;
180 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
181 int order;
182 =======
183 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
184 int max_pages;
185 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
186 int num_pages;
187 =======
188 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
190 if (!entry) {
191 DRM_ERROR("no scatter/gather memory!\n");
192 goto done;
195 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
196 DRM_DEBUG("PCI: no table in VRAM: using normal RAM\n");
198 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
199 order = drm_order((gart_info->table_size +
200 (PAGE_SIZE-1)) / PAGE_SIZE);
201 num_pages = 1 << order;
202 address = drm_ati_alloc_pcigart_table(order);
203 if (!address) {
204 =======
205 ret = drm_ati_alloc_pcigart_table(dev, gart_info);
206 if (ret) {
207 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
208 DRM_ERROR("cannot allocate PCI GART page!\n");
209 goto done;
212 <<<<<<< HEAD:drivers/char/drm/ati_pcigart.c
213 if (!dev->pdev) {
214 DRM_ERROR("PCI device unknown!\n");
215 goto done;
218 bus_address = pci_map_single(dev->pdev, address,
219 num_pages * PAGE_SIZE,
220 PCI_DMA_TODEVICE);
221 if (bus_address == 0) {
222 DRM_ERROR("unable to map PCIGART pages!\n");
223 order = drm_order((gart_info->table_size +
224 (PAGE_SIZE-1)) / PAGE_SIZE);
225 drm_ati_free_pcigart_table(address, order);
226 address = NULL;
227 goto done;
229 =======
230 address = gart_info->table_handle->vaddr;
231 bus_address = gart_info->table_handle->busaddr;
232 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/ati_pcigart.c
233 } else {
234 address = gart_info->addr;
235 bus_address = gart_info->bus_addr;
236 DRM_DEBUG("PCI: Gart Table: VRAM %08X mapped at %08lX\n",
237 bus_address, (unsigned long)address);
240 pci_gart = (u32 *) address;
242 max_pages = (gart_info->table_size / sizeof(u32));
243 pages = (entry->pages <= max_pages)
244 ? entry->pages : max_pages;
246 memset(pci_gart, 0, max_pages * sizeof(u32));
248 for (i = 0; i < pages; i++) {
249 /* we need to support large memory configurations */
250 entry->busaddr[i] = pci_map_single(dev->pdev,
251 page_address(entry->
252 pagelist[i]),
253 PAGE_SIZE, PCI_DMA_TODEVICE);
254 if (entry->busaddr[i] == 0) {
255 DRM_ERROR("unable to map PCIGART pages!\n");
256 drm_ati_pcigart_cleanup(dev, gart_info);
257 address = NULL;
258 bus_address = 0;
259 goto done;
261 page_base = (u32) entry->busaddr[i];
263 for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
264 switch(gart_info->gart_reg_if) {
265 case DRM_ATI_GART_IGP:
266 *pci_gart = cpu_to_le32((page_base) | 0xc);
267 break;
268 case DRM_ATI_GART_PCIE:
269 *pci_gart = cpu_to_le32((page_base >> 8) | 0xc);
270 break;
271 default:
272 case DRM_ATI_GART_PCI:
273 *pci_gart = cpu_to_le32(page_base);
274 break;
276 pci_gart++;
277 page_base += ATI_PCIGART_PAGE_SIZE;
281 ret = 1;
283 #if defined(__i386__) || defined(__x86_64__)
284 wbinvd();
285 #else
286 mb();
287 #endif
289 done:
290 gart_info->addr = address;
291 gart_info->bus_addr = bus_address;
292 return ret;
294 EXPORT_SYMBOL(drm_ati_pcigart_init);