mirror of
https://gitlab.freedesktop.org/mesa/drm.git
synced 2025-12-20 17:30:09 +01:00
drm/pcigart: fix the pci gart to use the drm_pci wrapper.
This is the correct fix for the RS690 and hopefully the dma coherent work. For now we limit everybody to a 32-bit DMA mask but it is possible for RS690 to use a 40-bit DMA mask for the GART table itself, and the PCIE cards can use 40-bits for the table entries. Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
parent
1a2d8c4bfa
commit
1f96e9a982
6 changed files with 30 additions and 82 deletions
|
|
@ -34,51 +34,23 @@
|
||||||
#include "drmP.h"
|
#include "drmP.h"
|
||||||
|
|
||||||
# define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */
|
# define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */
|
||||||
|
static int drm_ati_alloc_pcigart_table(struct drm_device *dev,
|
||||||
static void *drm_ati_alloc_pcigart_table(int order)
|
struct drm_ati_pcigart_info *gart_info)
|
||||||
{
|
{
|
||||||
unsigned long address;
|
gart_info->table_handle = drm_pci_alloc(dev, gart_info->table_size,
|
||||||
struct page *page;
|
PAGE_SIZE,
|
||||||
int i;
|
gart_info->table_mask);
|
||||||
|
if (gart_info->table_handle == NULL)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
DRM_DEBUG("%d order\n", order);
|
return 0;
|
||||||
|
|
||||||
address = __get_free_pages(GFP_KERNEL | __GFP_COMP | __GFP_DMA32,
|
|
||||||
order);
|
|
||||||
if (address == 0UL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
page = virt_to_page(address);
|
|
||||||
|
|
||||||
for (i = 0; i < order; i++, page++) {
|
|
||||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
|
|
||||||
get_page(page);
|
|
||||||
#endif
|
|
||||||
SetPageReserved(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
DRM_DEBUG("returning 0x%08lx\n", address);
|
|
||||||
return (void *)address;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drm_ati_free_pcigart_table(void *address, int order)
|
static void drm_ati_free_pcigart_table(struct drm_device *dev,
|
||||||
|
struct drm_ati_pcigart_info *gart_info)
|
||||||
{
|
{
|
||||||
struct page *page;
|
drm_pci_free(dev, gart_info->table_handle);
|
||||||
int i;
|
gart_info->table_handle = NULL;
|
||||||
int num_pages = 1 << order;
|
|
||||||
DRM_DEBUG("\n");
|
|
||||||
|
|
||||||
page = virt_to_page((unsigned long)address);
|
|
||||||
|
|
||||||
for (i = 0; i < num_pages; i++, page++) {
|
|
||||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
|
|
||||||
__put_page(page);
|
|
||||||
#endif
|
|
||||||
ClearPageReserved(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
free_pages((unsigned long)address, order);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info)
|
int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info)
|
||||||
|
|
@ -86,8 +58,7 @@ int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info
|
||||||
struct drm_sg_mem *entry = dev->sg;
|
struct drm_sg_mem *entry = dev->sg;
|
||||||
unsigned long pages;
|
unsigned long pages;
|
||||||
int i;
|
int i;
|
||||||
int order;
|
int max_pages;
|
||||||
int num_pages, max_pages;
|
|
||||||
|
|
||||||
/* we need to support large memory configurations */
|
/* we need to support large memory configurations */
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
|
|
@ -95,15 +66,7 @@ int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
order = drm_order((gart_info->table_size + (PAGE_SIZE-1)) / PAGE_SIZE);
|
|
||||||
num_pages = 1 << order;
|
|
||||||
|
|
||||||
if (gart_info->bus_addr) {
|
if (gart_info->bus_addr) {
|
||||||
if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
|
|
||||||
pci_unmap_single(dev->pdev, gart_info->bus_addr,
|
|
||||||
num_pages * PAGE_SIZE,
|
|
||||||
PCI_DMA_TODEVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
max_pages = (gart_info->table_size / sizeof(u32));
|
max_pages = (gart_info->table_size / sizeof(u32));
|
||||||
pages = (entry->pages <= max_pages)
|
pages = (entry->pages <= max_pages)
|
||||||
|
|
@ -122,10 +85,9 @@ int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info
|
||||||
|
|
||||||
|
|
||||||
if (gart_info->gart_table_location == DRM_ATI_GART_MAIN
|
if (gart_info->gart_table_location == DRM_ATI_GART_MAIN
|
||||||
&& gart_info->addr) {
|
&& gart_info->table_handle) {
|
||||||
|
|
||||||
drm_ati_free_pcigart_table(gart_info->addr, order);
|
drm_ati_free_pcigart_table(dev, gart_info);
|
||||||
gart_info->addr = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -140,9 +102,7 @@ int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *ga
|
||||||
u32 *pci_gart, page_base;
|
u32 *pci_gart, page_base;
|
||||||
dma_addr_t bus_address = 0;
|
dma_addr_t bus_address = 0;
|
||||||
int i, j, ret = 0;
|
int i, j, ret = 0;
|
||||||
int order;
|
|
||||||
int max_pages;
|
int max_pages;
|
||||||
int num_pages;
|
|
||||||
|
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
DRM_ERROR("no scatter/gather memory!\n");
|
DRM_ERROR("no scatter/gather memory!\n");
|
||||||
|
|
@ -152,31 +112,14 @@ int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *ga
|
||||||
if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
|
if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
|
||||||
DRM_DEBUG("PCI: no table in VRAM: using normal RAM\n");
|
DRM_DEBUG("PCI: no table in VRAM: using normal RAM\n");
|
||||||
|
|
||||||
order = drm_order((gart_info->table_size +
|
ret = drm_ati_alloc_pcigart_table(dev, gart_info);
|
||||||
(PAGE_SIZE-1)) / PAGE_SIZE);
|
if (ret) {
|
||||||
num_pages = 1 << order;
|
|
||||||
address = drm_ati_alloc_pcigart_table(order);
|
|
||||||
if (!address) {
|
|
||||||
DRM_ERROR("cannot allocate PCI GART page!\n");
|
DRM_ERROR("cannot allocate PCI GART page!\n");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dev->pdev) {
|
address = gart_info->table_handle->vaddr;
|
||||||
DRM_ERROR("PCI device unknown!\n");
|
bus_address = gart_info->table_handle->busaddr;
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
bus_address = pci_map_single(dev->pdev, address,
|
|
||||||
num_pages * PAGE_SIZE,
|
|
||||||
PCI_DMA_TODEVICE);
|
|
||||||
if (bus_address == 0) {
|
|
||||||
DRM_ERROR("unable to map PCIGART pages!\n");
|
|
||||||
order = drm_order((gart_info->table_size +
|
|
||||||
(PAGE_SIZE-1)) / PAGE_SIZE);
|
|
||||||
drm_ati_free_pcigart_table(address, order);
|
|
||||||
address = NULL;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
address = gart_info->addr;
|
address = gart_info->addr;
|
||||||
bus_address = gart_info->bus_addr;
|
bus_address = gart_info->bus_addr;
|
||||||
|
|
@ -225,12 +168,6 @@ int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *ga
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gart_info->gart_table_location == DRM_ATI_GART_MAIN)
|
|
||||||
dma_sync_single_for_device(&dev->pdev->dev,
|
|
||||||
bus_address,
|
|
||||||
max_pages * sizeof(u32),
|
|
||||||
PCI_DMA_TODEVICE);
|
|
||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
#if defined(__i386__) || defined(__x86_64__)
|
#if defined(__i386__) || defined(__x86_64__)
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
#include <linux/smp_lock.h> /* For (un)lock_kernel */
|
#include <linux/smp_lock.h> /* For (un)lock_kernel */
|
||||||
|
#include <linux/dma-mapping.h>
|
||||||
#include <linux/mm.h>
|
#include <linux/mm.h>
|
||||||
#include <linux/pagemap.h>
|
#include <linux/pagemap.h>
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
|
||||||
|
|
@ -596,6 +597,9 @@ struct drm_ati_pcigart_info {
|
||||||
int gart_reg_if;
|
int gart_reg_if;
|
||||||
void *addr;
|
void *addr;
|
||||||
dma_addr_t bus_addr;
|
dma_addr_t bus_addr;
|
||||||
|
dma_addr_t table_mask;
|
||||||
|
dma_addr_t member_mask;
|
||||||
|
struct drm_dma_handle *table_handle;
|
||||||
drm_local_map_t mapping;
|
drm_local_map_t mapping;
|
||||||
int table_size;
|
int table_size;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -339,4 +339,8 @@ extern void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type,
|
||||||
#define flush_agp_mappings() do {} while(0)
|
#define flush_agp_mappings() do {} while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DMA_BIT_MASK
|
||||||
|
#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ int xgi_pcie_heap_init(struct xgi_info * info)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info->gart_info.table_mask = DMA_BIT_MASK(32);
|
||||||
info->gart_info.gart_table_location = DRM_ATI_GART_MAIN;
|
info->gart_info.gart_table_location = DRM_ATI_GART_MAIN;
|
||||||
info->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
|
info->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
|
||||||
info->gart_info.table_size = info->dev->sg->pages * sizeof(u32);
|
info->gart_info.table_size = info->dev->sg->pages * sizeof(u32);
|
||||||
|
|
|
||||||
|
|
@ -558,6 +558,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
|
||||||
#if __OS_HAS_AGP
|
#if __OS_HAS_AGP
|
||||||
if (dev_priv->is_pci) {
|
if (dev_priv->is_pci) {
|
||||||
#endif
|
#endif
|
||||||
|
dev_priv->gart_info.table_mask = DMA_BIT_MASK(32);
|
||||||
dev_priv->gart_info.gart_table_location = DRM_ATI_GART_MAIN;
|
dev_priv->gart_info.gart_table_location = DRM_ATI_GART_MAIN;
|
||||||
dev_priv->gart_info.table_size = R128_PCIGART_TABLE_SIZE;
|
dev_priv->gart_info.table_size = R128_PCIGART_TABLE_SIZE;
|
||||||
dev_priv->gart_info.addr = NULL;
|
dev_priv->gart_info.addr = NULL;
|
||||||
|
|
|
||||||
|
|
@ -1819,6 +1819,7 @@ static int radeon_do_init_cp(struct drm_device * dev, drm_radeon_init_t * init)
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
dev_priv->gart_info.table_mask = DMA_BIT_MASK(32);
|
||||||
/* if we have an offset set from userspace */
|
/* if we have an offset set from userspace */
|
||||||
if (dev_priv->pcigart_offset_set) {
|
if (dev_priv->pcigart_offset_set) {
|
||||||
dev_priv->gart_info.bus_addr =
|
dev_priv->gart_info.bus_addr =
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue