Catch FreeBSD up to the pcie gart changes. Required minor modification to

radeon_cp.c to use a drm_local_map_t-type mapping (drm_core_ioremap
    rather than drm_ioremap), which contains private device mapping
    information on BSD. I also changed the ati_pcigart interface to use
    "void *" for pointers to kva rather than "unsigned long". While PCIGART
    support appears to be broken on FreeBSD currently, I think this is not
    new, and BusType PCI remains working on my r100 in Linux.
main
Eric Anholt 2005-11-08 02:38:01 +00:00
parent 145b23b552
commit 1a256df480
6 changed files with 59 additions and 43 deletions

View File

@ -35,21 +35,19 @@
#define ATI_MAX_PCIGART_PAGES 8192 /* 32 MB aperture, 4K pages */ #define ATI_MAX_PCIGART_PAGES 8192 /* 32 MB aperture, 4K pages */
#define ATI_PCIGART_TABLE_SIZE 32768 #define ATI_PCIGART_TABLE_SIZE 32768
int drm_ati_pcigart_init(drm_device_t *dev, unsigned long *addr, int drm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
dma_addr_t *bus_addr, int is_pcie)
{ {
unsigned long pages; unsigned long pages;
u32 *pci_gart = 0, page_base; u32 *pci_gart = NULL, page_base;
int i, j; int i, j;
*addr = 0;
*bus_addr = 0;
if (dev->sg == NULL) { if (dev->sg == NULL) {
DRM_ERROR( "no scatter/gather memory!\n" ); DRM_ERROR( "no scatter/gather memory!\n" );
return 0; return 0;
} }
if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
/* GART table in system memory */
dev->sg->dmah = drm_pci_alloc(dev, ATI_PCIGART_TABLE_SIZE, 0, dev->sg->dmah = drm_pci_alloc(dev, ATI_PCIGART_TABLE_SIZE, 0,
0xfffffffful); 0xfffffffful);
if (dev->sg->dmah == NULL) { if (dev->sg->dmah == NULL) {
@ -57,9 +55,13 @@ int drm_ati_pcigart_init(drm_device_t *dev, unsigned long *addr,
return 0; return 0;
} }
*addr = (long)dev->sg->dmah->vaddr; gart_info->addr = (void *)dev->sg->dmah->vaddr;
*bus_addr = dev->sg->dmah->busaddr; gart_info->bus_addr = dev->sg->dmah->busaddr;
pci_gart = (u32 *)dev->sg->dmah->vaddr; pci_gart = (u32 *)dev->sg->dmah->vaddr;
} else {
/* GART table in framebuffer memory */
pci_gart = gart_info->addr;
}
pages = DRM_MIN(dev->sg->pages, ATI_MAX_PCIGART_PAGES); pages = DRM_MIN(dev->sg->pages, ATI_MAX_PCIGART_PAGES);
@ -71,12 +73,9 @@ int drm_ati_pcigart_init(drm_device_t *dev, unsigned long *addr,
page_base = (u32) dev->sg->busaddr[i]; page_base = (u32) dev->sg->busaddr[i];
for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) { for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
if (is_pcie) { if (gart_info->is_pcie)
*pci_gart = (cpu_to_le32(page_base)>>8) | 0xc; *pci_gart = (cpu_to_le32(page_base) >> 8) | 0xc;
DRM_DEBUG("PCIE: %d %08X %08X to %p\n", i, else
page_base, (cpu_to_le32(page_base)>>8)|0xc,
pci_gart);
} else
*pci_gart = cpu_to_le32(page_base); *pci_gart = cpu_to_le32(page_base);
pci_gart++; pci_gart++;
page_base += ATI_PCIGART_PAGE_SIZE; page_base += ATI_PCIGART_PAGE_SIZE;
@ -88,8 +87,7 @@ int drm_ati_pcigart_init(drm_device_t *dev, unsigned long *addr,
return 1; return 1;
} }
int drm_ati_pcigart_cleanup(drm_device_t *dev, unsigned long addr, int drm_ati_pcigart_cleanup(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
dma_addr_t bus_addr)
{ {
if (dev->sg == NULL) { if (dev->sg == NULL) {
DRM_ERROR( "no scatter/gather memory!\n" ); DRM_ERROR( "no scatter/gather memory!\n" );

View File

@ -622,6 +622,18 @@ typedef struct drm_vbl_sig {
int pid; int pid;
} drm_vbl_sig_t; } drm_vbl_sig_t;
/* location of GART table */
#define DRM_ATI_GART_MAIN 1
#define DRM_ATI_GART_FB 2
typedef struct ati_pcigart_info {
int gart_table_location;
int is_pcie;
void *addr;
dma_addr_t bus_addr;
drm_local_map_t mapping;
} drm_ati_pcigart_info;
struct drm_driver_info { struct drm_driver_info {
int (*load)(struct drm_device *, unsigned long flags); int (*load)(struct drm_device *, unsigned long flags);
int (*firstopen)(struct drm_device *); int (*firstopen)(struct drm_device *);
@ -907,10 +919,10 @@ extern int drm_sysctl_cleanup(drm_device_t *dev);
#endif /* __FreeBSD__ */ #endif /* __FreeBSD__ */
/* ATI PCIGART support (ati_pcigart.c) */ /* ATI PCIGART support (ati_pcigart.c) */
int drm_ati_pcigart_init(drm_device_t *dev, unsigned long *addr, int drm_ati_pcigart_init(drm_device_t *dev,
dma_addr_t *bus_addr, int is_pcie); drm_ati_pcigart_info *gart_info);
int drm_ati_pcigart_cleanup(drm_device_t *dev, unsigned long addr, int drm_ati_pcigart_cleanup(drm_device_t *dev,
dma_addr_t bus_addr); drm_ati_pcigart_info *gart_info);
/* Locking IOCTL support (drm_drv.c) */ /* Locking IOCTL support (drm_drv.c) */
int drm_lock(DRM_IOCTL_ARGS); int drm_lock(DRM_IOCTL_ARGS);

View File

@ -52,7 +52,7 @@
# define ATI_MAX_PCIGART_PAGES 8192 /**< 32 MB aperture, 4K pages */ # define ATI_MAX_PCIGART_PAGES 8192 /**< 32 MB aperture, 4K pages */
# define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */ # define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */
static unsigned long drm_ati_alloc_pcigart_table(void) static void *drm_ati_alloc_pcigart_table(void)
{ {
unsigned long address; unsigned long address;
struct page *page; struct page *page;
@ -72,29 +72,29 @@ static unsigned long drm_ati_alloc_pcigart_table(void)
} }
DRM_DEBUG("%s: returning 0x%08lx\n", __FUNCTION__, address); DRM_DEBUG("%s: returning 0x%08lx\n", __FUNCTION__, address);
return address; return (void *)address;
} }
static void drm_ati_free_pcigart_table(unsigned long address) static void drm_ati_free_pcigart_table(void *address)
{ {
struct page *page; struct page *page;
int i; int i;
DRM_DEBUG("%s\n", __FUNCTION__); DRM_DEBUG("%s\n", __FUNCTION__);
page = virt_to_page(address); page = virt_to_page((unsigned long)address);
for (i = 0; i < ATI_PCIGART_TABLE_PAGES; i++, page++) { for (i = 0; i < ATI_PCIGART_TABLE_PAGES; i++, page++) {
__put_page(page); __put_page(page);
ClearPageReserved(page); ClearPageReserved(page);
} }
free_pages(address, ATI_PCIGART_TABLE_ORDER); free_pages((unsigned long)address, ATI_PCIGART_TABLE_ORDER);
} }
int drm_ati_pcigart_init(drm_device_t * dev, drm_ati_pcigart_info *gart_info) int drm_ati_pcigart_init(drm_device_t * dev, drm_ati_pcigart_info *gart_info)
{ {
drm_sg_mem_t *entry = dev->sg; drm_sg_mem_t *entry = dev->sg;
unsigned long address = 0; void *address = NULL;
unsigned long pages; unsigned long pages;
u32 *pci_gart, page_base, bus_address = 0; u32 *pci_gart, page_base, bus_address = 0;
int i, j, ret = 0; int i, j, ret = 0;
@ -119,7 +119,7 @@ int drm_ati_pcigart_init(drm_device_t * dev, drm_ati_pcigart_info *gart_info)
goto done; goto done;
} }
bus_address = pci_map_single(dev->pdev, (void *)address, bus_address = pci_map_single(dev->pdev, address,
ATI_PCIGART_TABLE_PAGES * PAGE_SIZE, ATI_PCIGART_TABLE_PAGES * PAGE_SIZE,
PCI_DMA_TODEVICE); PCI_DMA_TODEVICE);
if (bus_address == 0) { if (bus_address == 0) {
@ -133,7 +133,7 @@ int drm_ati_pcigart_init(drm_device_t * dev, drm_ati_pcigart_info *gart_info)
{ {
address = gart_info->addr; address = gart_info->addr;
bus_address = gart_info->bus_addr; bus_address = gart_info->bus_addr;
DRM_DEBUG("PCI: Gart Table: VRAM %08X mapped at %08lX\n", bus_address, address); DRM_DEBUG("PCI: Gart Table: VRAM %08X mapped at %08lX\n", bus_address, (unsigned long)address);
} }
pci_gart = (u32 *) address; pci_gart = (u32 *) address;
@ -152,7 +152,7 @@ int drm_ati_pcigart_init(drm_device_t * dev, drm_ati_pcigart_info *gart_info)
if (entry->busaddr[i] == 0) { if (entry->busaddr[i] == 0) {
DRM_ERROR("unable to map PCIGART pages!\n"); DRM_ERROR("unable to map PCIGART pages!\n");
drm_ati_pcigart_cleanup(dev, gart_info); drm_ati_pcigart_cleanup(dev, gart_info);
address = 0; address = NULL;
bus_address = 0; bus_address = 0;
goto done; goto done;
} }

View File

@ -529,8 +529,9 @@ typedef struct drm_vbl_sig {
typedef struct ati_pcigart_info { typedef struct ati_pcigart_info {
int gart_table_location; int gart_table_location;
int is_pcie; int is_pcie;
unsigned long addr; void *addr;
dma_addr_t bus_addr; dma_addr_t bus_addr;
drm_local_map_t mapping;
} drm_ati_pcigart_info; } drm_ati_pcigart_info;
/** /**

View File

@ -559,7 +559,8 @@ static int r128_do_init_cce(drm_device_t * dev, drm_r128_init_t * init)
if (dev_priv->is_pci) { if (dev_priv->is_pci) {
#endif #endif
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.addr = dev_priv->gart_info.bus_addr = 0; dev_priv->gart_info.addr = NULL;
dev_priv->gart_info.bus_addr = 0;
dev_priv->gart_info.is_pcie = 0; dev_priv->gart_info.is_pcie = 0;
if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) { if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) {
DRM_ERROR("failed to init PCI GART!\n"); DRM_ERROR("failed to init PCI GART!\n");

View File

@ -1541,16 +1541,20 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
/* if we have an offset set from userspace */ /* if we have an offset set from userspace */
if (dev_priv->pcigart_offset) { if (dev_priv->pcigart_offset) {
dev_priv->gart_info.bus_addr = dev_priv->pcigart_offset + dev_priv->fb_location; dev_priv->gart_info.bus_addr = dev_priv->pcigart_offset + dev_priv->fb_location;
dev_priv->gart_info.addr = (unsigned long)drm_ioremap(dev_priv->gart_info.bus_addr, RADEON_PCIGART_TABLE_SIZE, dev); dev_priv->gart_info.mapping.offset = dev_priv->gart_info.bus_addr;
dev_priv->gart_info.mapping.size = RADEON_PCIGART_TABLE_SIZE;
drm_core_ioremap(&dev_priv->gart_info.mapping, dev);
dev_priv->gart_info.addr = dev_priv->gart_info.mapping.handle;
dev_priv->gart_info.is_pcie = !!(dev_priv->flags & CHIP_IS_PCIE); dev_priv->gart_info.is_pcie = !!(dev_priv->flags & CHIP_IS_PCIE);
dev_priv->gart_info.gart_table_location = DRM_ATI_GART_FB; dev_priv->gart_info.gart_table_location = DRM_ATI_GART_FB;
DRM_DEBUG("Setting phys_pci_gart to %08lX %08lX\n", dev_priv->gart_info.addr, dev_priv->pcigart_offset); DRM_DEBUG("Setting phys_pci_gart to %p %08lX\n", dev_priv->gart_info.addr, dev_priv->pcigart_offset);
} }
else { else {
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.addr = dev_priv->gart_info.bus_addr= 0; dev_priv->gart_info.addr = NULL;
dev_priv->gart_info.bus_addr = 0;
if (dev_priv->flags & CHIP_IS_PCIE) if (dev_priv->flags & CHIP_IS_PCIE)
{ {
DRM_ERROR("Cannot use PCI Express without GART in FB memory\n"); DRM_ERROR("Cannot use PCI Express without GART in FB memory\n");
@ -1618,7 +1622,7 @@ static int radeon_do_cleanup_cp(drm_device_t * dev)
if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB) if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB)
{ {
drm_ioremapfree((void *)dev_priv->gart_info.addr, RADEON_PCIGART_TABLE_SIZE, dev); drm_core_ioremapfree(&dev_priv->gart_info.mapping, dev);
dev_priv->gart_info.addr = 0; dev_priv->gart_info.addr = 0;
} }
} }