2 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Gareth Hughes <gareth@valinux.com>
27 * $DragonFly: src/sys/dev/drm/ati_pcigart.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
30 /** @file ati_pcigart.c
31 * Implementation of ATI's PCIGART, which provides an aperture in card virtual
32 * address space with addresses remapped to system memory.
37 #define ATI_PCIGART_PAGE_SIZE 4096 /* PCI GART page size */
39 int drm_ati_pcigart_init(drm_device_t *dev, struct drm_ati_pcigart_info *gart_info)
42 u32 *pci_gart = NULL, page_base;
45 if (dev->sg == NULL) {
46 DRM_ERROR( "no scatter/gather memory!\n" );
50 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
51 /* GART table in system memory */
52 dev->sg->dmah = drm_pci_alloc(dev, gart_info->table_size, 0,
54 if (dev->sg->dmah == NULL) {
55 DRM_ERROR("cannot allocate PCI GART table!\n");
59 gart_info->addr = (void *)dev->sg->dmah->vaddr;
60 gart_info->bus_addr = dev->sg->dmah->busaddr;
61 pci_gart = (u32 *)dev->sg->dmah->vaddr;
63 /* GART table in framebuffer memory */
64 pci_gart = gart_info->addr;
67 pages = DRM_MIN(dev->sg->pages, gart_info->table_size / sizeof(u32));
69 bzero(pci_gart, gart_info->table_size);
71 KASSERT(PAGE_SIZE >= ATI_PCIGART_PAGE_SIZE, ("page size too small"));
73 for ( i = 0 ; i < pages ; i++ ) {
74 page_base = (u32) dev->sg->busaddr[i];
76 for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
77 switch(gart_info->gart_reg_if) {
78 case DRM_ATI_GART_IGP:
79 *pci_gart = cpu_to_le32(page_base | 0xc);
81 case DRM_ATI_GART_PCIE:
82 *pci_gart = cpu_to_le32((page_base >> 8) | 0xc);
85 *pci_gart = cpu_to_le32(page_base);
89 page_base += ATI_PCIGART_PAGE_SIZE;
98 int drm_ati_pcigart_cleanup(drm_device_t *dev, struct drm_ati_pcigart_info *gart_info)
100 if (dev->sg == NULL) {
101 DRM_ERROR( "no scatter/gather memory!\n" );
105 drm_pci_free(dev, dev->sg->dmah);