summaryrefslogtreecommitdiff
path: root/bsd-core
AgeCommit message (Collapse)Author
2005-11-06Re-disable the via driver while it's broken on BSD.Eric Anholt
2005-09-30Add support to turn writeback off via radeon module optionDave Airlie
2005-09-12Fix the spelling of DRM_AUTH so that the bsd core stuff builds again. NextEric Anholt
up is pcigart.
2005-09-03convert ioctl flags to use flags instead of separate intsDave Airlie
2005-08-26- Don't try to allocate mappings of less than a PAGE_SIZE in MGA DMA code.Eric Anholt
- Comment out the "is this mapping/bufs in allocated AGP" bits in BSD because they break mga (which uses AGP allocation that doesn't track entries). It's not a security issue when we still have the related ioctls marked root-only. - Apply some power-of-two alignment restrictions to hopefully avoid some panicing in bad cases of drm_pci_alloc() on FreeBSD. - Add verbosity to some error handling that I found useful while debugging.
2005-08-26Previously, drm_get_resource_start() and drm_get_resource_len() wouldEric Anholt
allocate the resource RF_ACTIVE, pull out the appropriate value, and return it. However, allocating large framebuffers RF_ACTIVE would run the system out of KVA, and this also left open the possibility of the resource getting moved after getting the offset. Instead, when either of these are called, allocate the resource if it isn't allocated already (non-RF_ACTIVE) and store it in the DRM device, to be cleaned up on lastclose.
2005-08-26Fix a lack of parenthesis in macro usage that showed up with INVARIANTSEric Anholt
turned on, i.e. in a kernel build.
2005-08-26[1] Fix BSD DRM for the nonroot changes. [2] Don't attempt to acquire theEric Anholt
DMA lock in a non-DMA driver, as it will be uninitialized. Submitted by: [1] jkim (minor changes by me)
2005-08-17add agp buffer tokenDave Airlie
2005-08-15Port the VIA DRM to FreeBSD. Original patch by Jake, with some cleanup byEric Anholt
me to match other drivers and avoid ifdeffing. The linux via_drv.c will be moved from shared-core to linux-core soon by repocopy. Submitted by: Jake Burkholder <jake@FreeBSD.org> Tested by: unichrome
2005-08-12Fix build after linux-side checkin of master/root-only split. Still onlyEric Anholt
cares about root on the BSD side, but should be secure.
2005-08-05Rename the driver hooks in the DRM to something a little moreEric Anholt
understandable: preinit -> load postinit -> (removed) presetup -> firstopen postsetup -> (removed) open_helper -> open prerelease -> preclose free_filp_priv -> postclose pretakedown -> lastclose postcleanup -> unload release -> reclaim_buffers_locked version -> (removed) postinit and version were replaced with generic code in the Linux DRM (drivers now set their version numbers and description in the driver structure, like on BSD). postsetup wasn't used at all. Fixes the savage hooks for initializing and tearing down mappings at the right times. Testing involved at least starting X, running glxgears, killing glxgears, exiting X, and repeating. Tested on: FreeBSD (g200, g400, r200, r128) Linux (r200, savage4)
2005-08-04Fix the MGA driver on BSD by passing in the proper chipset flags to theEric Anholt
driver's preinit routine, and by using DRM_COPY_TO_USER_IOCTL when copying out to an ioctl's data pointer. Pulled from the latest version of my drm-hook-rename.diff and only compile-tested after that.
2005-07-27Correct a couple of descriptions of files in comments (were justEric Anholt
copy'n'pasted). Submitted by: jkim
2005-07-27Link in the savage files from shared-core.Eric Anholt
Submitted by: jkim
2005-07-20Add latest r300 support from r300.sf.net CVS. Patch submitted by volodya,Eric Anholt
with BSD fix from jkim and the r300_reg.h license from Nicolai Haehnle. Big thanks to everyone involved!
2005-06-29Get the BSD DRM compiling again after MGA and mapping changes. Note thatEric Anholt
i915 has been disabled for the moment, rather than working around linux-specific code in the shared dir.
2005-06-14Adds support for PCI cards to MGA DRMIan Romanick
This patch adds serveral new ioctls and a new query to get_param query to support PCI MGA cards. Two ioctls were added to implement interrupt based waiting. With this change, the client-side driver no longer needs to map the primary DMA region or the MMIO region. Previously, end-of-frame waiting was done by busy waiting in the client-side driver until one of the MMIO registers (the current DMA pointer) matched a pointer to the end of primary DMA space. By using interrupts, the busy waiting and the extra mappings are removed. A third ioctl was added to bootstrap DMA. This ioctl, which is used by the X-server, moves a *LOT* of code from the X-server into the kernel. This allows the kernel to do whatever needs to be done to setup DMA buffers. The entire process and the locations of the buffers are hidden from user-mode. Additionally, a get_param query was added to differentiate between G4x0 cards and G550 cards. A gap was left in the numbering sequence so that, if needed, G450 cards could be distinguished from G400 cards. According to Ville Syrjälä, the G4x0 cards and the G550 cards handle anisotropic filtering differently. This seems the most compatible way to let the client-side driver know which card it's own. Doing this very small change now eliminates the need to bump the DRM minor version twice. http://marc.theaimsgroup.com/?l=dri-devel&m=106625815319773&w=2 A number of ioctl handlers in linux-core were also modified so that they could be called in-kernel. In these cases, the in-kernel callable version kept the existing name (e.g., drm_agp_acquire) and the ioctl handler added _ioctl to the name (e.g., drm_agp_acquire_ioctl). This patch also replaces the drm_agp_do_release function with drm_agp_release. drm_agp_release (drm_core_agp_release in the previous patch) is very similar to drm_agp_do_release, and I saw no reason to have both. This commit *breaks the build* on BSD. Eric said that he would make the required updates to the BSD side soon. Xorg bug: 3259 Reviewed by: Eric Anholt
2005-06-09Completely re-initialize DMA settingsIan Romanick
There were two problems. First, the 'warp' and 'primary' pointers weren't cleared, so mga_do_cleanup_dma, which gets called multiple times, would try to ioremapfree them multiple times. This resulted in the new error messages to syslog. The second problem was the, since the dev_private structure isn't reallocated and cleaned out in mga_do_init_dma, when the server is reloaded idle-waits would wait for impossible values. I have given this patch some more riggorous testing. This includes: - Load module, start server, run GL app, stop server, unload module. - Load module, start server, run GL app, stop server, unload module, reload module, restart server, run GL app. - Load module, start server, run GL app, stop server, restart server, run GL app, stop server, unload module. In all three cases, everything worked as expected. Please let me know if there are any further regressions with this patch. Xorg bug: 3408 Reported by: Chris Rankin
2005-06-06Add a few more bits of Tonnerre's NetBSD port (Still need to deal with theEric Anholt
device attachment).
2005-05-27Modify drm_driver::device_is_agp to return a tri-state value to indicateIan Romanick
that a device absolutely is, absolutely is not, or may or may not be AGP. Modify the i915 DRM to use this to force all i9x5 devices to be "AGP" (even the PCI-e devices). Reported by: Lukas Hejtmanek
2005-05-21Change the MGA initialization and cleanup a bit. The dev_private structureIan Romanick
is now allocated (and partially filled in) by the new mga_driver_preinit function. This allows the driver to detect the type of card (i.e., G200 class vs. G400 class) on its own. The chipset value passed to mga_dma_init is now ignored. This same technique is used by the radeon DRM. As a result of this, mga_driver_pretakedown was converted to mga_driver_postcleanup. This routine gets called in some other places than might be expected, and it sets the dev_private pointer to NULL. That little gem took over an hour to track down. :(
2005-05-16Added device_is_agp callback to drm_driver. This function is called by theIan Romanick
platform-specific drm_device_is_agp function. Added implementation of this function the the Linux-specific portion of the MGA driver to detect PCI G450 cards. Added code to the Linux-specific portion of the generic DRM layer to not initialize AGP infrastructure if the card is not AGP (this matches what already existed in BSD). Bumped the driver date and the driver patch-level for MGA. This mostly fixes bugzilla #3248. The BSD side still needs an implementation of mga_driver_device_is_agp.
2005-04-26Convert NOMAN to the new preferred spelling NO_MAN to quiet warnings.Eric Anholt
2005-04-26Convert BSD code to mostly use bus_dma, the dma abstraction for dealingEric Anholt
with IOMMUs and such. There is one usage of the forbidden vtophys() left in drm_scatter.c which will be fixed up soon. This required a KPI change for drm_pci_alloc/free() to return/use a drm_dma_handle_t that keeps track of os-specific bits, rather than just passing around the vaddr/busaddr/size. Submitted by: Tonnerre Lombard (partially) Tested on: FreeBSD: Rage128 AGP/PCI Linux: Savage4 AGP/PCI
2005-04-24Fix a panic on startup with non-initmapping drivers by assigning theEric Anholt
drm_ioremap return value to the map handle again. Submitted by: Tor Egge, tegge at freebsd dot org
2005-04-16Use /*- to begin license blocks in BSD code to reduce diffs against FreeBSDEric Anholt
CVS.
2005-04-13Fix build on FreeBSD-current, thanks to jhb@.Eric Anholt
2005-02-19Merge r1.26 from FreeBSD: Now that mem(4) is a kernel module, we need toEric Anholt
depend on it.
2005-02-14Use fuword32 for DRM_GET_USER_UNCHECKED when available. May help on 64-bitEric Anholt
platforms. Submitted by: Jung-uk Kim, jkim at niksun dot com
2005-02-14Use the proper API to get PCI vendor/device number for a dev.Eric Anholt
PR: ports/76879 Submitted by: Alex, lesha at intercaf dot ru.
2005-02-13Fix bad copy'n'pastage of copyrights -- don't disclaim anything for VAEric Anholt
Linux or PI in my copyrights when I should be doing it for myself.
2005-02-13Add the first bits necessary for a port of savage to FreeBSD. More toEric Anholt
follow later.
2005-02-08Close a race which could allow for privilege escalation by users with DRIEric Anholt
privileges on Radeon hardware. Essentially, a malicious program could submit a packet containing an offset (possibly in main memory) to be rendered from/to, while a separate thread switched that offset in userspace rapidly between a valid value and an invalid one. radeon_check_and_fixup_offset() would pull the offset in from user space, check it, and spit it back out to user space to be copied in later by the emit code. It would sometimes catch the bad value, but sometimes the malicious program could modify it after the check and get an invalid offset rendered from/to. Fix this by allocating a temporary buffer and copying the data in at once. While here, make the cliprects stuff not do the VERIFYAREA_READ and COPY_FROM_USER_UNCHECKED gymnastics, avoiding a lock order reversal on FreeBSD. Performance impact is negligible -- no difference on r200 to ~1% improvement on rv200 in quake3 tests (P4 1Ghz, demofour at 1024x768, n=4 or 5).
2005-02-07Restore a debugging message to DRM_DEBUG instead of DRM_ERROR.Eric Anholt
2005-02-07Remove some annoying trailing whitespace.Eric Anholt
2005-02-05- Implement drm_initmap, and extend it with the resource number to helpEric Anholt
FreeBSD. Add drm_get_resource_{start|len} so linux-specific stuff doesn't need to be in shared code. - Fix mach64 build by using __DECONST to work around passing a const pointer to useracc, which is unfortunately not marked const. - Get rid of a lot of maplist code by not having dev->maplist be a pointer, and by sticking the link entries directly in drm_local_map_t rather than having a separate structure for the linked list. - Factor out map uninit and removal into its own routine, rather than duplicating in both drm_takedown() and drm_rmmap(). - Hook up more driver functions, and correct FreeBSD-specific bits of radeon_cp.c, making radeon work. - Baby steps towards using bus_space as we should.
2005-01-17Add detection of whether the device is AGP by walking the capabilitiesEric Anholt
list.
2004-12-15Use SYSCTL_ADD_OID macro instead of calling function directly.Eric Anholt
Submitted by: reffie@FreeBSD.org
2004-11-07Refine the locking of the DRM. Most significant is covering the driverEric Anholt
ioctls with dev_lock, which is a major step toward being able to remove Giant. Covers some new pieces (dev->unique*) in the core, and avoids one call down into system internals with the drm lock held, which is usually bad (FreeBSD LOR #23, #27).
2004-11-07Don't link in files which no longer exist.Eric Anholt
2004-11-07Now that the memory debug code is gone, and all 3 BSDs have M_ZERO, stopEric Anholt
using drm_alloc/drm_free in the core and instead use plain malloc/free.
2004-11-06Add the drm Makefile and update .cvsignores.Eric Anholt
2004-11-06Convert more drivers for bsd-core, moving the ioctl definitions to sharedEric Anholt
code. Remove the "drv" from sisdrv, as it's unnecessary. Use the drm_pci functions in i915 instead of per-os implementations of the same. Avoid whitespace within fields in drm_pciids.txt (one of the r300 definitions), since it breaks the bsd pciids script. Tested on sis, mga, r128. i915 needs more work.
2004-11-06Remove some core stuff that ended up being unnecessary.Eric Anholt
2004-11-06Get r128 basically working: Hook up the driver's dma ioctl, use the properEric Anholt
offset into the driver ioctl array, and don't make the ctx bitmap conditional.
2004-11-06Move the lock/unlock ioctls to a more logical place, in drm_lock.c.Eric Anholt
2004-11-06Connect up r128_ioctls in driver config.Eric Anholt
2004-11-06Hook the debug output up to a sysctl, so you can choose to enable atEric Anholt
runtime.
2004-11-06Add file missed in last commit: Commit first pieces of port to OpenBSD,Eric Anholt
done by Martin Lexa (martin at martinlexa dot cz). Now that we've got porting for all three major BSDs (and the fourth being very similar to FreeBSD), move the mostly-duplication drm_os_* files into drmP.h. Remove some cruft from linux heritage and from pieces of the DRM that have since been removed. Note that things are still not quite working for even FreeBSD, but these are first steps at cleanup, and just a WIP checkpoint.
span class="hl opt">(struct vm_area_struct *vma, struct fault_data *data); struct page * get_nopage_retry(void) { if (atomic_read(&drm_np_retry.present) == 0) { struct page *page = alloc_page(GFP_KERNEL); if (!page) return NOPAGE_OOM; spin_lock(&drm_np_retry.lock); drm_np_retry.dummy_page = page; atomic_set(&drm_np_retry.present,1); spin_unlock(&drm_np_retry.lock); } get_page(drm_np_retry.dummy_page); return drm_np_retry.dummy_page; } void free_nopage_retry(void) { if (atomic_read(&drm_np_retry.present) == 1) { spin_lock(&drm_np_retry.lock); __free_page(drm_np_retry.dummy_page); drm_np_retry.dummy_page = NULL; atomic_set(&drm_np_retry.present, 0); spin_unlock(&drm_np_retry.lock); } } struct page *drm_bo_vm_nopage(struct vm_area_struct *vma, unsigned long address, int *type) { struct fault_data data; if (type) *type = VM_FAULT_MINOR; data.address = address; data.vma = vma; drm_bo_vm_fault(vma, &data); switch (data.type) { case VM_FAULT_OOM: return NOPAGE_OOM; case VM_FAULT_SIGBUS: return NOPAGE_SIGBUS; default: break; } return NOPAGE_REFAULT; } #endif #if !defined(DRM_FULL_MM_COMPAT) && \ ((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)) || \ (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19))) static int drm_pte_is_clear(struct vm_area_struct *vma, unsigned long addr) { struct mm_struct *mm = vma->vm_mm; int ret = 1; pte_t *pte; pmd_t *pmd; pud_t *pud; pgd_t *pgd; spin_lock(&mm->page_table_lock); pgd = pgd_offset(mm, addr); if (pgd_none(*pgd)) goto unlock; pud = pud_offset(pgd, addr); if (pud_none(*pud)) goto unlock; pmd = pmd_offset(pud, addr); if (pmd_none(*pmd)) goto unlock; pte = pte_offset_map(pmd, addr); if (!pte) goto unlock; ret = pte_none(*pte); pte_unmap(pte); unlock: spin_unlock(&mm->page_table_lock); return ret; } static int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn) { int ret; if (!drm_pte_is_clear(vma, addr)) return -EBUSY; ret = io_remap_pfn_range(vma, addr, pfn, PAGE_SIZE, vma->vm_page_prot); return ret; } static struct page *drm_bo_vm_fault(struct vm_area_struct *vma, struct fault_data *data) { unsigned long address = data->address; drm_buffer_object_t *bo = (drm_buffer_object_t *) vma->vm_private_data; unsigned long page_offset; struct page *page = NULL; drm_ttm_t *ttm; drm_device_t *dev; unsigned long pfn; int err; unsigned long bus_base; unsigned long bus_offset; unsigned long bus_size; mutex_lock(&bo->mutex); err = drm_bo_wait(bo, 0, 1, 0); if (err) { data->type = (err == -EAGAIN) ? VM_FAULT_MINOR : VM_FAULT_SIGBUS; goto out_unlock; } /* * If buffer happens to be in a non-mappable location, * move it to a mappable. */ if (!(bo->mem.flags & DRM_BO_FLAG_MAPPABLE)) { unsigned long _end = jiffies + 3*DRM_HZ; uint32_t new_mask = bo->mem.mask | DRM_BO_FLAG_MAPPABLE | DRM_BO_FLAG_FORCE_MAPPABLE; do { err = drm_bo_move_buffer(bo, new_mask, 0, 0); } while((err == -EAGAIN) && !time_after_eq(jiffies, _end)); if (err) { DRM_ERROR("Timeout moving buffer to mappable location.\n"); data->type = VM_FAULT_SIGBUS; goto out_unlock; } } if (address > vma->vm_end) { data->type = VM_FAULT_SIGBUS; goto out_unlock; } dev = bo->dev; err = drm_bo_pci_offset(dev, &bo->mem, &bus_base, &bus_offset, &bus_size); if (err) { data->type = VM_FAULT_SIGBUS; goto out_unlock; } page_offset = (address - vma->vm_start) >> PAGE_SHIFT; if (bus_size) { drm_mem_type_manager_t *man = &dev->bm.man[bo->mem.mem_type]; pfn = ((bus_base + bus_offset) >> PAGE_SHIFT) + page_offset; vma->vm_page_prot = drm_io_prot(man->drm_bus_maptype, vma); } else { ttm = bo->ttm; drm_ttm_fixup_caching(ttm); page = drm_ttm_get_page(ttm, page_offset); if (!page) { data->type = VM_FAULT_OOM; goto out_unlock; } pfn = page_to_pfn(page); vma->vm_page_prot = (bo->mem.flags & DRM_BO_FLAG_CACHED) ? vm_get_page_prot(vma->vm_flags) : drm_io_prot(_DRM_TTM, vma); } err = vm_insert_pfn(vma, address, pfn); if (!err || err == -EBUSY) data->type = VM_FAULT_MINOR; else data->type = VM_FAULT_OOM; out_unlock: mutex_unlock(&bo->mutex); return NULL; } #endif #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)) && \ !defined(DRM_FULL_MM_COMPAT) /** */ unsigned long drm_bo_vm_nopfn(struct vm_area_struct * vma, unsigned long address) { struct fault_data data; data.address = address; (void) drm_bo_vm_fault(vma, &data); if (data.type == VM_FAULT_OOM) return NOPFN_OOM; else if (data.type == VM_FAULT_SIGBUS) return NOPFN_SIGBUS; /* * pfn already set. */ return 0; } #endif #ifdef DRM_ODD_MM_COMPAT /* * VM compatibility code for 2.6.15-2.6.18. This code implements a complicated * workaround for a single BUG statement in do_no_page in these versions. The * tricky thing is that we need to take the mmap_sem in exclusive mode for _all_ * vmas mapping the ttm, before dev->struct_mutex is taken. The way we do this is to * check first take the dev->struct_mutex, and then trylock all mmap_sems. If this * fails for a single mmap_sem, we have to release all sems and the dev->struct_mutex, * release the cpu and retry. We also need to keep track of all vmas mapping the ttm. * phew. */ typedef struct p_mm_entry { struct list_head head; struct mm_struct *mm; atomic_t refcount; int locked; } p_mm_entry_t; typedef struct vma_entry { struct list_head head; struct vm_area_struct *vma; } vma_entry_t; struct page *drm_bo_vm_nopage(struct vm_area_struct *vma, unsigned long address, int *type) { drm_buffer_object_t *bo = (drm_buffer_object_t *) vma->vm_private_data; unsigned long page_offset; struct page *page; drm_ttm_t *ttm; drm_device_t *dev; mutex_lock(&bo->mutex); if (type) *type = VM_FAULT_MINOR; if (address > vma->vm_end) { page = NOPAGE_SIGBUS; goto out_unlock; } dev = bo->dev; if (drm_mem_reg_is_pci(dev, &bo->mem)) { DRM_ERROR("Invalid compat nopage.\n"); page = NOPAGE_SIGBUS; goto out_unlock; } ttm = bo->ttm; drm_ttm_fixup_caching(ttm); page_offset = (address - vma->vm_start) >> PAGE_SHIFT; page = drm_ttm_get_page(ttm, page_offset); if (!page) { page = NOPAGE_OOM; goto out_unlock; } get_page(page); out_unlock: mutex_unlock(&bo->mutex); return page; } int drm_bo_map_bound(struct vm_area_struct *vma) { drm_buffer_object_t *bo = (drm_buffer_object_t *)vma->vm_private_data; int ret = 0; unsigned long bus_base; unsigned long bus_offset; unsigned long bus_size; ret = drm_bo_pci_offset(bo->dev, &bo->mem, &bus_base, &bus_offset, &bus_size); BUG_ON(ret); if (bus_size) { drm_mem_type_manager_t *man = &bo->dev->bm.man[bo->mem.mem_type]; unsigned long pfn = (bus_base + bus_offset) >> PAGE_SHIFT; pgprot_t pgprot = drm_io_prot(man->drm_bus_maptype, vma); ret = io_remap_pfn_range(vma, vma->vm_start, pfn, vma->vm_end - vma->vm_start, pgprot); } return ret; } int drm_bo_add_vma(drm_buffer_object_t * bo, struct vm_area_struct *vma) { p_mm_entry_t *entry, *n_entry; vma_entry_t *v_entry; struct mm_struct *mm = vma->vm_mm; v_entry = drm_ctl_alloc(sizeof(*v_entry), DRM_MEM_BUFOBJ); if (!v_entry) { DRM_ERROR("Allocation of vma pointer entry failed\n"); return -ENOMEM; } v_entry->vma = vma; list_add_tail(&v_entry->head, &bo->vma_list); list_for_each_entry(entry, &bo->p_mm_list, head) { if (mm == entry->mm) { atomic_inc(&entry->refcount); return 0; } else if ((unsigned long)mm < (unsigned long)entry->mm) ; } n_entry = drm_ctl_alloc(sizeof(*n_entry), DRM_MEM_BUFOBJ); if (!n_entry) { DRM_ERROR("Allocation of process mm pointer entry failed\n"); return -ENOMEM; } INIT_LIST_HEAD(&n_entry->head); n_entry->mm = mm; n_entry->locked = 0; atomic_set(&n_entry->refcount, 0); list_add_tail(&n_entry->head, &entry->head); return 0; } void drm_bo_delete_vma(drm_buffer_object_t * bo, struct vm_area_struct *vma) { p_mm_entry_t *entry, *n; vma_entry_t *v_entry, *v_n; int found = 0; struct mm_struct *mm = vma->vm_mm; list_for_each_entry_safe(v_entry, v_n, &bo->vma_list, head) { if (v_entry->vma == vma) { found = 1; list_del(&v_entry->head); drm_ctl_free(v_entry, sizeof(*v_entry), DRM_MEM_BUFOBJ); break; } } BUG_ON(!found); list_for_each_entry_safe(entry, n, &bo->p_mm_list, head) { if (mm == entry->mm) { if (atomic_add_negative(-1, &entry->refcount)) { list_del(&entry->head); BUG_ON(entry->locked); drm_ctl_free(entry, sizeof(*entry), DRM_MEM_BUFOBJ); } return; } } BUG_ON(1); } int drm_bo_lock_kmm(drm_buffer_object_t * bo) { p_mm_entry_t *entry; int lock_ok = 1; list_for_each_entry(entry, &bo->p_mm_list, head) { BUG_ON(entry->locked); if (!down_write_trylock(&entry->mm->mmap_sem)) { lock_ok = 0; break; } entry->locked = 1; } if (lock_ok) return 0; list_for_each_entry(entry, &bo->p_mm_list, head) { if (!entry->locked) break; up_write(&entry->mm->mmap_sem); entry->locked = 0; } /* * Possible deadlock. Try again. Our callers should handle this * and restart. */ return -EAGAIN; } void drm_bo_unlock_kmm(drm_buffer_object_t * bo) { p_mm_entry_t *entry; list_for_each_entry(entry, &bo->p_mm_list, head) { BUG_ON(!entry->locked); up_write(&entry->mm->mmap_sem); entry->locked = 0; } } int drm_bo_remap_bound(drm_buffer_object_t *bo) { vma_entry_t *v_entry; int ret = 0; if (drm_mem_reg_is_pci(bo->dev, &bo->mem)) { list_for_each_entry(v_entry, &bo->vma_list, head) { ret = drm_bo_map_bound(v_entry->vma); if (ret) break; } } return ret; } void drm_bo_finish_unmap(drm_buffer_object_t *bo) { vma_entry_t *v_entry; list_for_each_entry(v_entry, &bo->vma_list, head) { v_entry->vma->vm_flags &= ~VM_PFNMAP; } } #endif #ifdef DRM_IDR_COMPAT_FN /* only called when idp->lock is held */ static void __free_layer(struct idr *idp, struct idr_layer *p) { p->ary[0] = idp->id_free; idp->id_free = p; idp->id_free_cnt++; } static void free_layer(struct idr *idp, struct idr_layer *p) { unsigned long flags; /* * Depends on the return element being zeroed. */ spin_lock_irqsave(&idp->lock, flags); __free_layer(idp, p); spin_unlock_irqrestore(&idp->lock, flags); } /** * idr_for_each - iterate through all stored pointers * @idp: idr handle * @fn: function to be called for each pointer * @data: data passed back to callback function * * Iterate over the pointers registered with the given idr. The * callback function will be called for each pointer currently * registered, passing the id, the pointer and the data pointer passed * to this function. It is not safe to modify the idr tree while in * the callback, so functions such as idr_get_new and idr_remove are * not allowed. * * We check the return of @fn each time. If it returns anything other * than 0, we break out and return that value. * * The caller must serialize idr_find() vs idr_get_new() and idr_remove(). */ int idr_for_each(struct idr *idp, int (*fn)(int id, void *p, void *data), void *data) { int n, id, max, error = 0; struct idr_layer *p; struct idr_layer *pa[MAX_LEVEL]; struct idr_layer **paa = &pa[0]; n = idp->layers * IDR_BITS; p = idp->top; max = 1 << n; id = 0; while (id < max) { while (n > 0 && p) { n -= IDR_BITS; *paa++ = p; p = p->ary[(id >> n) & IDR_MASK]; } if (p) { error = fn(id, (void *)p, data); if (error) break; } id += 1 << n; while (n < fls(id)) { n += IDR_BITS; p = *--paa; } } return error; } EXPORT_SYMBOL(idr_for_each); /** * idr_remove_all - remove all ids from the given idr tree * @idp: idr handle * * idr_destroy() only frees up unused, cached idp_layers, but this * function will remove all id mappings and leave all idp_layers * unused. * * A typical clean-up sequence for objects stored in an idr tree, will * use idr_for_each() to free all objects, if necessay, then * idr_remove_all() to remove all ids, and idr_destroy() to free * up the cached idr_layers. */ void idr_remove_all(struct idr *idp) { int n, id, max, error = 0; struct idr_layer *p; struct idr_layer *pa[MAX_LEVEL]; struct idr_layer **paa = &pa[0]; n = idp->layers * IDR_BITS; p = idp->top; max = 1 << n; id = 0; while (id < max && !error) { while (n > IDR_BITS && p) { n -= IDR_BITS; *paa++ = p; p = p->ary[(id >> n) & IDR_MASK]; } id += 1 << n; while (n < fls(id)) { if (p) { memset(p, 0, sizeof *p); free_layer(idp, p); } n += IDR_BITS; p = *--paa; } } idp->top = NULL; idp->layers = 0; } EXPORT_SYMBOL(idr_remove_all); #endif