drm: update PCIGART support from CVS

In order to work on FreeBSD the gart needed to use a local mapping
This patch moves the mainline to the new code and aligns some comment
changes

From: Eric Anholt <anholt@freebsd.org>
Signed-off-by: Dave Airlie <airlied@linux.ie>

authored by Dave Airlie and committed by Dave Airlie f26c473c 0a406877

+43 -38
+11 -12
drivers/char/drm/ati_pcigart.c
··· 52 # define ATI_MAX_PCIGART_PAGES 8192 /**< 32 MB aperture, 4K pages */ 53 # define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */ 54 55 - static unsigned long drm_ati_alloc_pcigart_table(void) 56 { 57 unsigned long address; 58 struct page *page; ··· 72 } 73 74 DRM_DEBUG("%s: returning 0x%08lx\n", __FUNCTION__, address); 75 - return address; 76 } 77 78 - static void drm_ati_free_pcigart_table(unsigned long address) 79 { 80 struct page *page; 81 int i; 82 DRM_DEBUG("%s\n", __FUNCTION__); 83 84 - page = virt_to_page(address); 85 86 for (i = 0; i < ATI_PCIGART_TABLE_PAGES; i++, page++) { 87 __put_page(page); 88 ClearPageReserved(page); 89 } 90 91 - free_pages(address, ATI_PCIGART_TABLE_ORDER); 92 } 93 94 - int drm_ati_pcigart_cleanup(drm_device_t * dev, 95 - drm_ati_pcigart_info * gart_info) 96 { 97 drm_sg_mem_t *entry = dev->sg; 98 unsigned long pages; ··· 135 136 EXPORT_SYMBOL(drm_ati_pcigart_cleanup); 137 138 - int drm_ati_pcigart_init(drm_device_t * dev, drm_ati_pcigart_info * gart_info) 139 { 140 drm_sg_mem_t *entry = dev->sg; 141 - unsigned long address = 0; 142 unsigned long pages; 143 u32 *pci_gart, page_base, bus_address = 0; 144 int i, j, ret = 0; ··· 162 goto done; 163 } 164 165 - bus_address = pci_map_single(dev->pdev, (void *)address, 166 ATI_PCIGART_TABLE_PAGES * 167 PAGE_SIZE, PCI_DMA_TODEVICE); 168 if (bus_address == 0) { ··· 175 address = gart_info->addr; 176 bus_address = gart_info->bus_addr; 177 DRM_DEBUG("PCI: Gart Table: VRAM %08X mapped at %08lX\n", 178 - bus_address, address); 179 } 180 181 pci_gart = (u32 *) address; ··· 194 if (entry->busaddr[i] == 0) { 195 DRM_ERROR("unable to map PCIGART pages!\n"); 196 drm_ati_pcigart_cleanup(dev, gart_info); 197 - address = 0; 198 bus_address = 0; 199 goto done; 200 }
··· 52 # define ATI_MAX_PCIGART_PAGES 8192 /**< 32 MB aperture, 4K pages */ 53 # define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */ 54 55 + static void *drm_ati_alloc_pcigart_table(void) 56 { 57 unsigned long address; 58 struct page *page; ··· 72 } 73 74 DRM_DEBUG("%s: returning 0x%08lx\n", __FUNCTION__, address); 75 + return (void *)address; 76 } 77 78 + static void drm_ati_free_pcigart_table(void *address) 79 { 80 struct page *page; 81 int i; 82 DRM_DEBUG("%s\n", __FUNCTION__); 83 84 + page = virt_to_page((unsigned long)address); 85 86 for (i = 0; i < ATI_PCIGART_TABLE_PAGES; i++, page++) { 87 __put_page(page); 88 ClearPageReserved(page); 89 } 90 91 + free_pages((unsigned long)address, ATI_PCIGART_TABLE_ORDER); 92 } 93 94 + int drm_ati_pcigart_cleanup(drm_device_t *dev, drm_ati_pcigart_info *gart_info) 95 { 96 drm_sg_mem_t *entry = dev->sg; 97 unsigned long pages; ··· 136 137 EXPORT_SYMBOL(drm_ati_pcigart_cleanup); 138 139 + int drm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info) 140 { 141 drm_sg_mem_t *entry = dev->sg; 142 + void *address = NULL; 143 unsigned long pages; 144 u32 *pci_gart, page_base, bus_address = 0; 145 int i, j, ret = 0; ··· 163 goto done; 164 } 165 166 + bus_address = pci_map_single(dev->pdev, address, 167 ATI_PCIGART_TABLE_PAGES * 168 PAGE_SIZE, PCI_DMA_TODEVICE); 169 if (bus_address == 0) { ··· 176 address = gart_info->addr; 177 bus_address = gart_info->bus_addr; 178 DRM_DEBUG("PCI: Gart Table: VRAM %08X mapped at %08lX\n", 179 + bus_address, (unsigned long)address); 180 } 181 182 pci_gart = (u32 *) address; ··· 195 if (entry->busaddr[i] == 0) { 196 DRM_ERROR("unable to map PCIGART pages!\n"); 197 drm_ati_pcigart_cleanup(dev, gart_info); 198 + address = NULL; 199 bus_address = 0; 200 goto done; 201 }
+2 -1
drivers/char/drm/drmP.h
··· 522 typedef struct ati_pcigart_info { 523 int gart_table_location; 524 int is_pcie; 525 - unsigned long addr; 526 dma_addr_t bus_addr; 527 } drm_ati_pcigart_info; 528 529 /**
··· 522 typedef struct ati_pcigart_info { 523 int gart_table_location; 524 int is_pcie; 525 + void *addr; 526 dma_addr_t bus_addr; 527 + drm_local_map_t mapping; 528 } drm_ati_pcigart_info; 529 530 /**
+9 -6
drivers/char/drm/r128_cce.c
··· 1 - /* r128_cce.c -- ATI Rage 128 driver -*- linux-c -*- 2 * Created: Wed Apr 5 19:24:19 2000 by kevin@precisioninsight.com 3 - * 4 * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas. 5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 6 * All Rights Reserved. ··· 560 if (dev_priv->is_pci) { 561 #endif 562 dev_priv->gart_info.gart_table_location = DRM_ATI_GART_MAIN; 563 - dev_priv->gart_info.addr = dev_priv->gart_info.bus_addr = 0; 564 dev_priv->gart_info.is_pcie = 0; 565 if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) { 566 DRM_ERROR("failed to init PCI GART!\n"); ··· 603 drm_core_ioremapfree(dev_priv->cce_ring, dev); 604 if (dev_priv->ring_rptr != NULL) 605 drm_core_ioremapfree(dev_priv->ring_rptr, dev); 606 - if (dev->agp_buffer_map != NULL) 607 drm_core_ioremapfree(dev->agp_buffer_map, dev); 608 } else 609 #endif 610 { 611 if (dev_priv->gart_info.bus_addr) 612 if (!drm_ati_pcigart_cleanup(dev, 613 - &dev_priv-> 614 - gart_info)) 615 DRM_ERROR 616 ("failed to cleanup PCI GART!\n"); 617 }
··· 1 + /* r128_cce.c -- ATI Rage 128 driver -*- linux-c -*- 2 * Created: Wed Apr 5 19:24:19 2000 by kevin@precisioninsight.com 3 + */ 4 + /* 5 * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas. 6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 7 * All Rights Reserved. ··· 559 if (dev_priv->is_pci) { 560 #endif 561 dev_priv->gart_info.gart_table_location = DRM_ATI_GART_MAIN; 562 + dev_priv->gart_info.addr = NULL; 563 + dev_priv->gart_info.bus_addr = 0; 564 dev_priv->gart_info.is_pcie = 0; 565 if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) { 566 DRM_ERROR("failed to init PCI GART!\n"); ··· 601 drm_core_ioremapfree(dev_priv->cce_ring, dev); 602 if (dev_priv->ring_rptr != NULL) 603 drm_core_ioremapfree(dev_priv->ring_rptr, dev); 604 + if (dev->agp_buffer_map != NULL) { 605 drm_core_ioremapfree(dev->agp_buffer_map, dev); 606 + dev->agp_buffer_map = NULL; 607 + } 608 } else 609 #endif 610 { 611 if (dev_priv->gart_info.bus_addr) 612 if (!drm_ati_pcigart_cleanup(dev, 613 + &dev_priv->gart_info)) 614 DRM_ERROR 615 ("failed to cleanup PCI GART!\n"); 616 }
+2 -2
drivers/char/drm/r128_drm.h
··· 1 /* r128_drm.h -- Public header for the r128 driver -*- linux-c -*- 2 * Created: Wed Apr 5 19:24:19 2000 by kevin@precisioninsight.com 3 - * 4 - * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas. 5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 6 * All rights reserved. 7 *
··· 1 /* r128_drm.h -- Public header for the r128 driver -*- linux-c -*- 2 * Created: Wed Apr 5 19:24:19 2000 by kevin@precisioninsight.com 3 + */ 4 + /* Copyright 2000 Precision Insight, Inc., Cedar Park, Texas. 5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 6 * All rights reserved. 7 *
+2 -2
drivers/char/drm/r128_drv.h
··· 1 /* r128_drv.h -- Private header for r128 driver -*- linux-c -*- 2 * Created: Mon Dec 13 09:51:11 1999 by faith@precisioninsight.com 3 - * 4 - * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 6 * All rights reserved. 7 *
··· 1 /* r128_drv.h -- Private header for r128 driver -*- linux-c -*- 2 * Created: Mon Dec 13 09:51:11 1999 by faith@precisioninsight.com 3 + */ 4 + /* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 6 * All rights reserved. 7 *
+2 -2
drivers/char/drm/r128_irq.c
··· 1 - /* r128_irq.c -- IRQ handling for radeon -*- linux-c -*- 2 - * 3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. 4 * 5 * The Weather Channel (TM) funded Tungsten Graphics to develop the
··· 1 + /* r128_irq.c -- IRQ handling for radeon -*- linux-c -*- */ 2 + /* 3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. 4 * 5 * The Weather Channel (TM) funded Tungsten Graphics to develop the
+2 -2
drivers/char/drm/r128_state.c
··· 1 /* r128_state.c -- State support for r128 -*- linux-c -*- 2 * Created: Thu Jan 27 02:53:43 2000 by gareth@valinux.com 3 - * 4 - * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 5 * All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a
··· 1 /* r128_state.c -- State support for r128 -*- linux-c -*- 2 * Created: Thu Jan 27 02:53:43 2000 by gareth@valinux.com 3 + */ 4 + /* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 5 * All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a
+13 -11
drivers/char/drm/radeon_cp.c
··· 1 - /* radeon_cp.c -- CP support for Radeon -*- linux-c -*- 2 - * 3 * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas. 4 * Copyright 2000 VA Linux Systems, Inc., Fremont, California. 5 * All Rights Reserved. ··· 1561 if (dev_priv->pcigart_offset) { 1562 dev_priv->gart_info.bus_addr = 1563 dev_priv->pcigart_offset + dev_priv->fb_location; 1564 dev_priv->gart_info.addr = 1565 - (unsigned long)drm_ioremap(dev_priv->gart_info. 1566 - bus_addr, 1567 - RADEON_PCIGART_TABLE_SIZE, 1568 - dev); 1569 1570 dev_priv->gart_info.is_pcie = 1571 !!(dev_priv->flags & CHIP_IS_PCIE); 1572 dev_priv->gart_info.gart_table_location = 1573 DRM_ATI_GART_FB; 1574 1575 - DRM_DEBUG("Setting phys_pci_gart to %08lX %08lX\n", 1576 dev_priv->gart_info.addr, 1577 dev_priv->pcigart_offset); 1578 } else { 1579 dev_priv->gart_info.gart_table_location = 1580 DRM_ATI_GART_MAIN; 1581 - dev_priv->gart_info.addr = 1582 - dev_priv->gart_info.bus_addr = 0; 1583 if (dev_priv->flags & CHIP_IS_PCIE) { 1584 DRM_ERROR 1585 ("Cannot use PCI Express without GART in FB memory\n"); ··· 1644 DRM_ERROR("failed to cleanup PCI GART!\n"); 1645 1646 if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB) { 1647 - drm_ioremapfree((void *)dev_priv->gart_info.addr, 1648 - RADEON_PCIGART_TABLE_SIZE, dev); 1649 dev_priv->gart_info.addr = 0; 1650 } 1651 }
··· 1 + /* radeon_cp.c -- CP support for Radeon -*- linux-c -*- */ 2 + /* 3 * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas. 4 * Copyright 2000 VA Linux Systems, Inc., Fremont, California. 5 * All Rights Reserved. ··· 1561 if (dev_priv->pcigart_offset) { 1562 dev_priv->gart_info.bus_addr = 1563 dev_priv->pcigart_offset + dev_priv->fb_location; 1564 + dev_priv->gart_info.mapping.offset = 1565 + dev_priv->gart_info.bus_addr; 1566 + dev_priv->gart_info.mapping.size = 1567 + RADEON_PCIGART_TABLE_SIZE; 1568 + 1569 + drm_core_ioremap(&dev_priv->gart_info.mapping, dev); 1570 dev_priv->gart_info.addr = 1571 + dev_priv->gart_info.mapping.handle; 1572 1573 dev_priv->gart_info.is_pcie = 1574 !!(dev_priv->flags & CHIP_IS_PCIE); 1575 dev_priv->gart_info.gart_table_location = 1576 DRM_ATI_GART_FB; 1577 1578 + DRM_DEBUG("Setting phys_pci_gart to %p %08lX\n", 1579 dev_priv->gart_info.addr, 1580 dev_priv->pcigart_offset); 1581 } else { 1582 dev_priv->gart_info.gart_table_location = 1583 DRM_ATI_GART_MAIN; 1584 + dev_priv->gart_info.addr = NULL; 1585 + dev_priv->gart_info.bus_addr = 0; 1586 if (dev_priv->flags & CHIP_IS_PCIE) { 1587 DRM_ERROR 1588 ("Cannot use PCI Express without GART in FB memory\n"); ··· 1641 DRM_ERROR("failed to cleanup PCI GART!\n"); 1642 1643 if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB) { 1644 + drm_core_ioremapfree(&dev_priv->gart_info.mapping, dev); 1645 dev_priv->gart_info.addr = 0; 1646 } 1647 }