unsigned long pages,
unsigned long dma_mask,
unsigned long boundary_size,
- unsigned long align_mask)
+ unsigned long align_mask,
+ bool trylock)
{
unsigned long offset, limit, flags;
dma_addr_t address;
limit = iommu_device_max_index(APERTURE_RANGE_PAGES, offset,
dma_mask >> PAGE_SHIFT);
- spin_lock_irqsave(&range->bitmap_lock, flags);
+ if (trylock) {
+ if (!spin_trylock_irqsave(&range->bitmap_lock, flags))
+ return -1;
+ } else {
+ spin_lock_irqsave(&range->bitmap_lock, flags);
+ }
+
address = iommu_area_alloc(range->bitmap, limit, range->next_bit,
pages, offset, boundary_size, align_mask);
if (address == -1) {
{
unsigned long boundary_size, mask;
unsigned long address = -1;
+ bool first = true;
u32 start, i;
preempt_disable();
mask = dma_get_seg_boundary(dev);
+again:
start = this_cpu_read(*dom->next_index);
/* Sanity check - is it really necessary? */
address = dma_ops_aperture_alloc(dom, range, pages,
dma_mask, boundary_size,
- align_mask);
+ align_mask, first);
if (address != -1) {
address = range->offset + (address << PAGE_SHIFT);
this_cpu_write(*dom->next_index, index);
}
}
+ if (address == -1 && first) {
+ first = false;
+ goto again;
+ }
+
preempt_enable();
return address;