From 72cfc797b51e59ecf8a2787c6a176838241cc94b Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 14 Jun 2005 22:34:11 +0000 Subject: =?UTF-8?q?Adds=20support=20for=20PCI=20cards=20to=20MGA=20DRM=20T?= =?UTF-8?q?his=20patch=20adds=20serveral=20new=20ioctls=20and=20a=20new=20?= =?UTF-8?q?query=20to=20get=5Fparam=20query=20to=20=20=20=20=20support=20P?= =?UTF-8?q?CI=20MGA=20cards.=20Two=20ioctls=20were=20added=20to=20implemen?= =?UTF-8?q?t=20interrupt=20based=20waiting.=20With=20this=20=20=20=20=20ch?= =?UTF-8?q?ange,=20the=20client-side=20driver=20no=20longer=20needs=20to?= =?UTF-8?q?=20map=20the=20primary=20DMA=20=20=20=20=20region=20or=20the=20?= =?UTF-8?q?MMIO=20region.=20Previously,=20end-of-frame=20waiting=20was=20d?= =?UTF-8?q?one=20by=20=20=20=20=20busy=20waiting=20in=20the=20client-side?= =?UTF-8?q?=20driver=20until=20one=20of=20the=20MMIO=20registers=20=20=20?= =?UTF-8?q?=20=20(the=20current=20DMA=20pointer)=20matched=20a=20pointer?= =?UTF-8?q?=20to=20the=20end=20of=20primary=20DMA=20=20=20=20=20space.=20B?= =?UTF-8?q?y=20using=20interrupts,=20the=20busy=20waiting=20and=20the=20ex?= =?UTF-8?q?tra=20mappings=20are=20=20=20=20=20removed.=20A=20third=20ioctl?= =?UTF-8?q?=20was=20added=20to=20bootstrap=20DMA.=20This=20ioctl,=20which?= =?UTF-8?q?=20is=20used=20by=20the=20=20=20=20=20X-server,=20moves=20a=20*?= =?UTF-8?q?LOT*=20of=20code=20from=20the=20X-server=20into=20the=20kernel.?= =?UTF-8?q?=20This=20=20=20=20=20allows=20the=20kernel=20to=20do=20whateve?= =?UTF-8?q?r=20needs=20to=20be=20done=20to=20setup=20DMA=20buffers.=20=20?= =?UTF-8?q?=20=20=20The=20entire=20process=20and=20the=20locations=20of=20?= =?UTF-8?q?the=20buffers=20are=20hidden=20from=20=20=20=20=20user-mode.=20?= =?UTF-8?q?Additionally,=20a=20get=5Fparam=20query=20was=20added=20to=20di?= =?UTF-8?q?fferentiate=20between=20G4x0=20=20=20=20=20cards=20and=20G550?= =?UTF-8?q?=20cards.=20A=20gap=20was=20left=20in=20the=20numbering=20seque?= =?UTF-8?q?nce=20so=20that,=20=20=20=20=20if=20needed,=20G450=20cards=20co?= =?UTF-8?q?uld=20be=20distinguished=20from=20G400=20cards.=20According=20?= =?UTF-8?q?=20=20=20=20to=20Ville=20Syrj=C3=A4l=C3=A4,=20the=20G4x0=20card?= =?UTF-8?q?s=20and=20the=20G550=20cards=20handle=20=20=20=20=20anisotropic?= =?UTF-8?q?=20filtering=20differently.=20This=20seems=20the=20most=20compa?= =?UTF-8?q?tible=20way=20=20=20=20=20to=20let=20the=20client-side=20driver?= =?UTF-8?q?=20know=20which=20card=20it's=20own.=20Doing=20this=20very=20?= =?UTF-8?q?=20=20=20=20small=20change=20now=20eliminates=20the=20need=20to?= =?UTF-8?q?=20bump=20the=20DRM=20minor=20version=20=20=20=20=20twice.=20ht?= =?UTF-8?q?tp://marc.theaimsgroup.com/=3Fl=3Ddri-devel&m=3D106625815319773?= =?UTF-8?q?&w=3D2=20A=20number=20of=20ioctl=20handlers=20in=20linux-core?= =?UTF-8?q?=20were=20also=20modified=20so=20that=20they=20=20=20=20=20coul?= =?UTF-8?q?d=20be=20called=20in-kernel.=20In=20these=20cases,=20the=20in-k?= =?UTF-8?q?ernel=20callable=20=20=20=20=20version=20kept=20the=20existing?= =?UTF-8?q?=20name=20(e.g.,=20drm=5Fagp=5Facquire)=20and=20the=20ioctl=20?= =?UTF-8?q?=20=20=20=20handler=20added=20=5Fioctl=20to=20the=20name=20(e.g?= =?UTF-8?q?.,=20drm=5Fagp=5Facquire=5Fioctl).=20This=20patch=20also=20repl?= =?UTF-8?q?aces=20the=20drm=5Fagp=5Fdo=5Frelease=20function=20with=20=20?= =?UTF-8?q?=20=20=20drm=5Fagp=5Frelease.=20drm=5Fagp=5Frelease=20(drm=5Fco?= =?UTF-8?q?re=5Fagp=5Frelease=20in=20the=20previous=20=20=20=20=20patch)?= =?UTF-8?q?=20is=20very=20similar=20to=20drm=5Fagp=5Fdo=5Frelease,=20and?= =?UTF-8?q?=20I=20saw=20no=20reason=20to=20=20=20=20=20have=20both.=20This?= =?UTF-8?q?=20commit=20*breaks=20the=20build*=20on=20BSD.=20Eric=20said=20?= =?UTF-8?q?that=20he=20would=20make=20the=20=20=20=20=20required=20updates?= =?UTF-8?q?=20to=20the=20BSD=20side=20soon.=20Xorg=20bug:=203259=20Reviewe?= =?UTF-8?q?d=20by:=20Eric=20Anholt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared-core/mga_dma.c | 550 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 509 insertions(+), 41 deletions(-) (limited to 'shared-core/mga_dma.c') diff --git a/shared-core/mga_dma.c b/shared-core/mga_dma.c index 4c0be4cc..998886d6 100644 --- a/shared-core/mga_dma.c +++ b/shared-core/mga_dma.c @@ -23,18 +23,21 @@ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. - * - * Authors: - * Rickard E. (Rik) Faith - * Jeff Hartmann - * Keith Whitwell - * - * Rewritten by: - * Gareth Hughes + */ + +/** + * \file mga_dma.c + * DMA support for MGA G200 / G400. + * + * \author Rickard E. (Rik) Faith + * \author Jeff Hartmann + * \author Keith Whitwell + * \author Gareth Hughes */ #include "drmP.h" #include "drm.h" +#include "drm_sarea.h" #include "mga_drm.h" #include "mga_drv.h" @@ -148,7 +151,7 @@ void mga_do_dma_flush(drm_mga_private_t * dev_priv) DRM_DEBUG(" space = 0x%06x\n", primary->space); mga_flush_write_combine(); - MGA_WRITE(MGA_PRIMEND, tail | MGA_PAGPXFER); + MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access); DRM_DEBUG("done.\n"); } @@ -188,7 +191,7 @@ void mga_do_dma_wrap_start(drm_mga_private_t * dev_priv) DRM_DEBUG(" space = 0x%06x\n", primary->space); mga_flush_write_combine(); - MGA_WRITE(MGA_PRIMEND, tail | MGA_PAGPXFER); + MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access); set_bit(0, &primary->wrapped); DRM_DEBUG("done.\n"); @@ -405,6 +408,405 @@ int mga_driver_preinit(drm_device_t *dev, unsigned long flags) return 0; } +/** + * Bootstrap the driver for AGP DMA. + * + * \todo + * Investigate whether there is any benifit to storing the WARP microcode in + * AGP memory. If not, the microcode may as well always be put in PCI + * memory. + * + * \todo + * This routine needs to set dma_bs->agp_mode to the mode actually configured + * in the hardware. Looking just at the Linux AGP driver code, I don't see + * an easy way to determine this. + * + * \sa mga_do_dma_bootstrap, mga_do_pci_dma_bootstrap + */ +static int mga_do_agp_dma_bootstrap(drm_device_t * dev, + drm_mga_dma_bootstrap_t * dma_bs) +{ + drm_mga_private_t * const dev_priv = (drm_mga_private_t *) dev->dev_private; + const unsigned int warp_size = mga_warp_microcode_size(dev_priv); + int err; + unsigned offset; + const unsigned secondary_size = dma_bs->secondary_bin_count + * dma_bs->secondary_bin_size; + const unsigned agp_size = (dma_bs->agp_size << 20); + drm_buf_desc_t req; + drm_agp_mode_t mode; + drm_agp_info_t info; + + + /* Acquire AGP. */ + err = drm_agp_acquire(dev); + if (err) { + DRM_ERROR("Unable to acquire AGP\n"); + return err; + } + + err = drm_agp_info(dev, &info); + if (err) { + DRM_ERROR("Unable to get AGP info\n"); + return err; + } + + mode.mode = (info.mode & ~0x07) | dma_bs->agp_mode; + err = drm_agp_enable(dev, mode); + if (err) { + DRM_ERROR("Unable to enable AGP (mode = 0x%lx)\n", mode.mode); + return err; + } + + + /* In addition to the usual AGP mode configuration, the G200 AGP cards + * need to have the AGP mode "manually" set. + */ + + if (dev_priv->chipset == MGA_CARD_TYPE_G200) { + if (mode.mode & 0x02) { + MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_ENABLE); + } + else { + MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_DISABLE); + } + } + + + /* Allocate and bind AGP memory. */ + dev_priv->agp_pages = agp_size / PAGE_SIZE; + dev_priv->agp_mem = drm_alloc_agp( dev_priv->agp_pages, 0 ); + if (dev_priv->agp_mem == NULL) { + dev_priv->agp_pages = 0; + DRM_ERROR("Unable to allocate %uMB AGP memory\n", + dma_bs->agp_size); + return DRM_ERR(ENOMEM); + } + + err = drm_bind_agp( dev_priv->agp_mem, 0 ); + if (err) { + DRM_ERROR("Unable to bind AGP memory\n"); + return err; + } + + offset = 0; + err = drm_addmap( dev, offset, warp_size, + _DRM_AGP, _DRM_READ_ONLY, & dev_priv->warp ); + if (err) { + DRM_ERROR("Unable to map WARP microcode\n"); + return err; + } + + offset += warp_size; + err = drm_addmap( dev, offset, dma_bs->primary_size, + _DRM_AGP, _DRM_READ_ONLY, & dev_priv->primary ); + if (err) { + DRM_ERROR("Unable to map primary DMA region\n"); + return err; + } + + offset += dma_bs->primary_size; + err = drm_addmap( dev, offset, secondary_size, + _DRM_AGP, 0, & dev->agp_buffer_map ); + if (err) { + DRM_ERROR("Unable to map secondary DMA region\n"); + return err; + } + + (void) memset( &req, 0, sizeof(req) ); + req.count = dma_bs->secondary_bin_count; + req.size = dma_bs->secondary_bin_size; + req.flags = _DRM_AGP_BUFFER; + req.agp_start = offset; + + err = drm_addbufs_agp( dev, & req ); + if (err) { + DRM_ERROR("Unable to add secondary DMA buffers\n"); + return err; + } + + offset += secondary_size; + err = drm_addmap( dev, offset, agp_size - offset, + _DRM_AGP, 0, & dev_priv->agp_textures ); + if (err) { + DRM_ERROR("Unable to map AGP texture region\n"); + return err; + } + + drm_core_ioremap(dev_priv->warp, dev); + drm_core_ioremap(dev_priv->primary, dev); + drm_core_ioremap(dev->agp_buffer_map, dev); + + if (!dev_priv->warp->handle || + !dev_priv->primary->handle || !dev->agp_buffer_map->handle) { + DRM_ERROR("failed to ioremap agp regions! (%p, %p, %p)\n", + dev_priv->warp->handle, dev_priv->primary->handle, + dev->agp_buffer_map->handle); + return DRM_ERR(ENOMEM); + } + + dev_priv->dma_access = MGA_PAGPXFER; + dev_priv->wagp_enable = MGA_WAGP_ENABLE; + + DRM_INFO("Initialized card for AGP DMA.\n"); + return 0; +} + +/** + * Create a "fake" drm_map_t for a pre-mapped range of PCI consistent memory. + * + * Unlike \c drm_addmap, this function just creates a \c drm_map_t wrapper for + * a block of PCI consistent memory. \c drm_addmap, basically, converts a bus + * address to a virtual address. However, \c drm_pci_alloc gives both the bus + * address and the virtual address for the memory region. Not only is there + * no need to map it again, but mapping it again will cause problems. + * + * \param dmah DRM DMA handle returned by \c drm_pci_alloc. + * \param map_ptr Location to store a pointer to the \c drm_map_t. + * + * \returns + * On success, zero is returned. Otherwise and error code suitable for + * returning from an ioctl is returned. + */ +static int mga_fake_addmap(drm_dma_handle_t * dmah, drm_map_t ** map_ptr) +{ + drm_map_t * map; + + + map = drm_alloc(sizeof(drm_map_t), DRM_MEM_DRIVER); + if (map == NULL) { + return DRM_ERR(ENOMEM); + } + + map->offset = dmah->busaddr; + map->size = dmah->size; + map->type = _DRM_CONSISTENT; + map->flags = _DRM_READ_ONLY; + map->handle = dmah->vaddr; + map->mtrr = 0; + + *map_ptr = map; + + return 0; +} + +/** + * Bootstrap the driver for PCI DMA. + * + * \todo + * The algorithm for decreasing the size of the primary DMA buffer could be + * better. The size should be rounded up to the nearest page size, then + * decrease the request size by a single page each pass through the loop. + * + * \todo + * Determine whether the maximum address passed to drm_pci_alloc is correct. + * The same goes for drm_addbufs_pci. + * + * \sa mga_do_dma_bootstrap, mga_do_agp_dma_bootstrap + */ +static int mga_do_pci_dma_bootstrap(drm_device_t * dev, + drm_mga_dma_bootstrap_t * dma_bs) +{ + drm_mga_private_t * const dev_priv = (drm_mga_private_t *) dev->dev_private; + const unsigned int warp_size = mga_warp_microcode_size(dev_priv); + unsigned int primary_size; + unsigned int bin_count; + int err; + drm_buf_desc_t req; + + + if (dev->dma == NULL) { + DRM_ERROR("dev->dma is NULL\n"); + return DRM_ERR(EFAULT); + } + + + /* The WARP microcode base address must be 256-byte aligned. + */ + dev_priv->warp_dmah = drm_pci_alloc(dev, warp_size, 0x100, 0x7fffffff); + err = mga_fake_addmap(dev_priv->warp_dmah, & dev_priv->warp); + if (err) { + DRM_ERROR("Unable to map WARP microcode\n"); + return err; + } + + + /* Other than the bottom two bits being used to encode other + * information, there don't appear to be any restrictions on the + * alignment of the primary or secondary DMA buffers. + */ + + dev_priv->primary_dmah = NULL; + for ( primary_size = dma_bs->primary_size + ; primary_size != 0 + ; primary_size >>= 1 ) { + dev_priv->primary_dmah = drm_pci_alloc(dev, primary_size, + 0x04, 0x7fffffff); + if (dev_priv->primary_dmah != NULL) { + break; + } + } + + if (dev_priv->primary_dmah == NULL) { + DRM_ERROR("Unable to allocate primary DMA region\n"); + return DRM_ERR(ENOMEM); + } + + if (dev_priv->primary_dmah->size != dma_bs->primary_size) { + DRM_INFO("Primary DMA buffer size reduced from %u to %u.\n", + dma_bs->primary_size, + (unsigned) dev_priv->primary_dmah->size); + dma_bs->primary_size = dev_priv->primary_dmah->size; + } + + err = mga_fake_addmap(dev_priv->primary_dmah, & dev_priv->primary); + if (err) { + DRM_ERROR("Unable to map primary DMA region\n"); + return err; + } + + + for ( bin_count = dma_bs->secondary_bin_count + ; bin_count > 0 + ; bin_count-- ) { + (void) memset( &req, 0, sizeof(req) ); + req.count = bin_count; + req.size = dma_bs->secondary_bin_size; + + err = drm_addbufs_pci( dev, & req ); + if (!err) { + break; + } + } + + if (bin_count == 0) { + DRM_ERROR("Unable to add secondary DMA buffers\n"); + return err; + } + + if (bin_count != dma_bs->secondary_bin_count) { + DRM_INFO("Secondary PCI DMA buffer bin count reduced from %u " + "to %u.\n", dma_bs->secondary_bin_count, bin_count); + + dma_bs->secondary_bin_count = bin_count; + } + + dev_priv->dma_access = 0; + dev_priv->wagp_enable = 0; + + dma_bs->agp_mode = 0; + + DRM_INFO("Initialized card for PCI DMA.\n"); + return 0; +} + + +static int mga_do_dma_bootstrap(drm_device_t * dev, + drm_mga_dma_bootstrap_t * dma_bs) +{ + const int is_agp = (dma_bs->agp_mode != 0) && drm_device_is_agp(dev); + int err; + drm_mga_private_t * const dev_priv = + (drm_mga_private_t *) dev->dev_private; + + + dev_priv->used_new_dma_init = 1; + + /* The first steps are the same for both PCI and AGP based DMA. Map + * the cards MMIO registers and map a status page. + */ + err = drm_addmap( dev, dev_priv->mmio_base, dev_priv->mmio_size, + _DRM_REGISTERS, _DRM_READ_ONLY, & dev_priv->mmio ); + if (err) { + DRM_ERROR("Unable to map MMIO region\n"); + return err; + } + + + err = drm_addmap( dev, 0, SAREA_MAX, _DRM_SHM, + _DRM_READ_ONLY | _DRM_LOCKED | _DRM_KERNEL, + & dev_priv->status ); + if (err) { + DRM_ERROR("Unable to map status region\n"); + return err; + } + + + /* The DMA initialization procedure is slightly different for PCI and + * AGP cards. AGP cards just allocate a large block of AGP memory and + * carve off portions of it for internal uses. The remaining memory + * is returned to user-mode to be used for AGP textures. + */ + + if (is_agp) { + err = mga_do_agp_dma_bootstrap(dev, dma_bs); + } + + /* If we attempted to initialize the card for AGP DMA but failed, + * clean-up any mess that may have been created. + */ + + if (err) { + mga_do_cleanup_dma(dev); + } + + + /* Not only do we want to try and initialized PCI cards for PCI DMA, + * but we also try to initialized AGP cards that could not be + * initialized for AGP DMA. This covers the case where we have an AGP + * card in a system with an unsupported AGP chipset. In that case the + * card will be detected as AGP, but we won't be able to allocate any + * AGP memory, etc. + */ + + if (!is_agp || err) { + err = mga_do_pci_dma_bootstrap(dev, dma_bs); + } + + + return err; +} + +int mga_dma_bootstrap(DRM_IOCTL_ARGS) +{ + DRM_DEVICE; + drm_mga_dma_bootstrap_t bootstrap; + int err; + + + DRM_COPY_FROM_USER_IOCTL(bootstrap, + (drm_mga_dma_bootstrap_t __user *) data, + sizeof(bootstrap)); + + err = mga_do_dma_bootstrap(dev, & bootstrap); + if (! err) { + static const int modes[] = { 0, 1, 2, 2, 4, 4, 4, 4 }; + const drm_mga_private_t * const dev_priv = + (drm_mga_private_t *) dev->dev_private; + + if (dev_priv->agp_textures != NULL) { + bootstrap.texture_handle = dev_priv->agp_textures->offset; + bootstrap.texture_size = dev_priv->agp_textures->size; + } + else { + bootstrap.texture_handle = 0; + bootstrap.texture_size = 0; + } + + bootstrap.agp_mode = modes[ bootstrap.agp_mode & 0x07 ]; + if (DRM_COPY_TO_USER( (void __user *) data, & bootstrap, + sizeof(bootstrap))) { + err = DRM_ERR(EFAULT); + } + } + else { + mga_do_cleanup_dma(dev); + } + + return err; +} + + static int mga_do_init_dma(drm_device_t * dev, drm_mga_init_t * init) { drm_mga_private_t *dev_priv; @@ -443,42 +845,47 @@ static int mga_do_init_dma(drm_device_t * dev, drm_mga_init_t * init) return DRM_ERR(EINVAL); } - dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset); - if (!dev_priv->mmio) { - DRM_ERROR("failed to find mmio region!\n"); - return DRM_ERR(EINVAL); - } - dev_priv->status = drm_core_findmap(dev, init->status_offset); - if (!dev_priv->status) { - DRM_ERROR("failed to find status page!\n"); - return DRM_ERR(EINVAL); - } - dev_priv->warp = drm_core_findmap(dev, init->warp_offset); - if (!dev_priv->warp) { - DRM_ERROR("failed to find warp microcode region!\n"); - return DRM_ERR(EINVAL); - } - dev_priv->primary = drm_core_findmap(dev, init->primary_offset); - if (!dev_priv->primary) { - DRM_ERROR("failed to find primary dma region!\n"); - return DRM_ERR(EINVAL); - } - dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset); - if (!dev->agp_buffer_map) { - DRM_ERROR("failed to find dma buffer region!\n"); - return DRM_ERR(EINVAL); + if (! dev_priv->used_new_dma_init) { + dev_priv->status = drm_core_findmap(dev, init->status_offset); + if (!dev_priv->status) { + DRM_ERROR("failed to find status page!\n"); + return DRM_ERR(EINVAL); + } + dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset); + if (!dev_priv->mmio) { + DRM_ERROR("failed to find mmio region!\n"); + return DRM_ERR(EINVAL); + } + dev_priv->warp = drm_core_findmap(dev, init->warp_offset); + if (!dev_priv->warp) { + DRM_ERROR("failed to find warp microcode region!\n"); + return DRM_ERR(EINVAL); + } + dev_priv->primary = drm_core_findmap(dev, init->primary_offset); + if (!dev_priv->primary) { + DRM_ERROR("failed to find primary dma region!\n"); + return DRM_ERR(EINVAL); + } + dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset); + if (!dev->agp_buffer_map) { + DRM_ERROR("failed to find dma buffer region!\n"); + return DRM_ERR(EINVAL); + } + + drm_core_ioremap(dev_priv->warp, dev); + drm_core_ioremap(dev_priv->primary, dev); + drm_core_ioremap(dev->agp_buffer_map, dev); } dev_priv->sarea_priv = (drm_mga_sarea_t *) ((u8 *) dev_priv->sarea->handle + init->sarea_priv_offset); - drm_core_ioremap(dev_priv->warp, dev); - drm_core_ioremap(dev_priv->primary, dev); - drm_core_ioremap(dev->agp_buffer_map, dev); - if (!dev_priv->warp->handle || - !dev_priv->primary->handle || !dev->agp_buffer_map->handle) { + !dev_priv->primary->handle || + ((dev_priv->dma_access != 0) && + ((dev->agp_buffer_map == NULL) || + (dev->agp_buffer_map->handle == NULL)))) { DRM_ERROR("failed to ioremap agp regions!\n"); return DRM_ERR(ENOMEM); } @@ -538,6 +945,7 @@ static int mga_do_init_dma(drm_device_t * dev, drm_mga_init_t * init) static int mga_do_cleanup_dma(drm_device_t * dev) { + int err = 0; DRM_DEBUG("\n"); /* Make sure interrupts are disabled here because the uninstall ioctl @@ -550,13 +958,73 @@ static int mga_do_cleanup_dma(drm_device_t * dev) if (dev->dev_private) { drm_mga_private_t *dev_priv = dev->dev_private; - if (dev_priv->warp != NULL) + if ((dev_priv->warp != NULL) + && (dev_priv->mmio->type != _DRM_CONSISTENT)) drm_core_ioremapfree(dev_priv->warp, dev); - if (dev_priv->primary != NULL) + + if ((dev_priv->primary != NULL) + && (dev_priv->primary->type != _DRM_CONSISTENT)) drm_core_ioremapfree(dev_priv->primary, dev); + if (dev->agp_buffer_map != NULL) drm_core_ioremapfree(dev->agp_buffer_map, dev); + if (dev_priv->used_new_dma_init) { + if (dev_priv->warp != NULL) { + drm_rmmap(dev, (void *) dev_priv->warp->offset); + } + + if (dev_priv->primary != NULL) { + if (dev_priv->primary->type != _DRM_CONSISTENT) { + drm_rmmap(dev, (void *) dev_priv->primary->offset); + } + else { + drm_free(dev_priv->primary, sizeof(drm_map_t), DRM_MEM_DRIVER); + } + } + + if (dev_priv->warp_dmah != NULL) { + drm_pci_free(dev, dev_priv->warp_dmah); + dev_priv->warp_dmah = NULL; + } + + if (dev_priv->primary_dmah != NULL) { + drm_pci_free(dev, dev_priv->primary_dmah); + dev_priv->primary_dmah = NULL; + } + + if (dev_priv->mmio != NULL) { + drm_rmmap(dev, (void *) dev_priv->mmio->offset); + } + + if (dev_priv->status != NULL) { + drm_rmmap(dev, (void *) dev_priv->status->offset); + } + + if (dev_priv->agp_mem != NULL) { + if (dev->agp_buffer_map != NULL) { + drm_rmmap(dev, (void *) dev->agp_buffer_map->offset); + } + + if (dev_priv->agp_textures != NULL) { + drm_rmmap(dev, (void *) dev_priv->agp_textures->offset); + dev_priv->agp_textures = NULL; + } + + drm_unbind_agp(dev_priv->agp_mem); + + drm_free_agp(dev_priv->agp_mem, dev_priv->agp_pages); + dev_priv->agp_pages = 0; + dev_priv->agp_mem = NULL; + } + + if ((dev->agp != NULL) && dev->agp->acquired) { + err = drm_agp_release(dev); + } + + dev_priv->used_new_dma_init = 0; + } + dev_priv->warp = NULL; dev_priv->primary = NULL; dev_priv->mmio = NULL; -- cgit v1.2.3