5 * \author Gareth Hughes <gareth@valinux.com>
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
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.
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
)
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
;
50 DRM_DEBUG("%d order\n", order
);
52 address
= __get_free_pages(GFP_KERNEL
| __GFP_COMP
,
58 page
= virt_to_page(address
);
60 gart_info
->table_handle
= drm_pci_alloc(dev
, gart_info
->table_size
,
62 gart_info
->table_mask
);
63 if (gart_info
->table_handle
== NULL
)
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
;
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
)
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
88 int num_pages
= 1 << order
;
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
);
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
;
108 <<<<<<< HEAD
:drivers
/char/drm
/ati_pcigart
.c
110 int num_pages
, max_pages
;
113 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/drm
/ati_pcigart
.c
115 /* we need to support large memory configurations */
117 DRM_ERROR("no scatter/gather memory!\n");
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
;
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
,
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
])
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
;
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
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
;
173 <<<<<<< HEAD
:drivers
/char/drm
/ati_pcigart
.c
174 u32
*pci_gart
, page_base
, bus_address
= 0;
176 u32
*pci_gart
, page_base
;
177 dma_addr_t bus_address
= 0;
178 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/drm
/ati_pcigart
.c
180 <<<<<<< HEAD
:drivers
/char/drm
/ati_pcigart
.c
183 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/drm
/ati_pcigart
.c
185 <<<<<<< HEAD
:drivers
/char/drm
/ati_pcigart
.c
188 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/drm
/ati_pcigart
.c
191 DRM_ERROR("no scatter/gather memory!\n");
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
);
205 ret
= drm_ati_alloc_pcigart_table(dev
, gart_info
);
207 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/drm
/ati_pcigart
.c
208 DRM_ERROR("cannot allocate PCI GART page!\n");
212 <<<<<<< HEAD
:drivers
/char/drm
/ati_pcigart
.c
214 DRM_ERROR("PCI device unknown!\n");
218 bus_address
= pci_map_single(dev
->pdev
, address
,
219 num_pages
* PAGE_SIZE
,
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
);
230 address
= gart_info
->table_handle
->vaddr
;
231 bus_address
= gart_info
->table_handle
->busaddr
;
232 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/drm
/ati_pcigart
.c
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
,
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
);
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);
268 case DRM_ATI_GART_PCIE
:
269 *pci_gart
= cpu_to_le32((page_base
>> 8) | 0xc);
272 case DRM_ATI_GART_PCI
:
273 *pci_gart
= cpu_to_le32(page_base
);
277 page_base
+= ATI_PCIGART_PAGE_SIZE
;
283 #if defined(__i386__) || defined(__x86_64__)
290 gart_info
->addr
= address
;
291 gart_info
->bus_addr
= bus_address
;
294 EXPORT_SYMBOL(drm_ati_pcigart_init
);