1 /* ati_pcigart.h -- ATI PCI GART support -*- linux-c -*-
2 * Created: Wed Dec 13 21:52:19 2000 by gareth@valinux.com
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
28 * Gareth Hughes <gareth@valinux.com>
34 #define ATI_PCIGART_PAGE_SIZE 4096 /* PCI GART page size */
36 int drm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
39 u32 *pci_gart = NULL, page_base;
42 if (dev->sg == NULL) {
43 DRM_ERROR( "no scatter/gather memory!\n" );
47 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
48 /* GART table in system memory */
49 dev->sg->dmah = drm_pci_alloc(dev, gart_info->table_size, 0,
51 if (dev->sg->dmah == NULL) {
52 DRM_ERROR("cannot allocate PCI GART table!\n");
56 gart_info->addr = (void *)dev->sg->dmah->vaddr;
57 gart_info->bus_addr = dev->sg->dmah->busaddr;
58 pci_gart = (u32 *)dev->sg->dmah->vaddr;
60 /* GART table in framebuffer memory */
61 pci_gart = gart_info->addr;
64 pages = DRM_MIN(dev->sg->pages, gart_info->table_size / sizeof(u32));
66 bzero(pci_gart, gart_info->table_size);
68 KASSERT(PAGE_SIZE >= ATI_PCIGART_PAGE_SIZE, ("page size too small"));
70 for ( i = 0 ; i < pages ; i++ ) {
71 page_base = (u32) dev->sg->busaddr[i];
73 for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
74 switch(gart_info->gart_reg_if) {
75 case DRM_ATI_GART_IGP:
76 *pci_gart = cpu_to_le32(page_base | 0xc);
78 case DRM_ATI_GART_PCIE:
79 *pci_gart = cpu_to_le32((page_base >> 8) | 0xc);
82 *pci_gart = cpu_to_le32(page_base);
86 page_base += ATI_PCIGART_PAGE_SIZE;
95 int drm_ati_pcigart_cleanup(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
97 if (dev->sg == NULL) {
98 DRM_ERROR( "no scatter/gather memory!\n" );
102 drm_pci_free(dev, dev->sg->dmah);