Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 83027
b: refs/heads/master
c: 681cc5c
h: refs/heads/master
i:
  83025: 746daca
  83023: d0807f5
v: v3
  • Loading branch information
FUJITA Tomonori authored and Linus Torvalds committed Feb 5, 2008
1 parent e1d8e1d commit e34aeef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 59fc67dedb46c29442989e52af39da67aea52512
refs/heads/master: 681cc5cd3efbeafca6386114070e0bfb5012e249
41 changes: 35 additions & 6 deletions trunk/lib/swiotlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ address_needs_mapping(struct device *hwdev, dma_addr_t addr)
return (addr & ~mask) != 0;
}

static inline unsigned int is_span_boundary(unsigned int index,
unsigned int nslots,
unsigned long offset_slots,
unsigned long max_slots)
{
unsigned long offset = (offset_slots + index) & (max_slots - 1);
return offset + nslots > max_slots;
}

/*
* Allocates bounce buffer and returns its kernel virtual address.
*/
Expand All @@ -292,6 +301,16 @@ map_single(struct device *hwdev, char *buffer, size_t size, int dir)
char *dma_addr;
unsigned int nslots, stride, index, wrap;
int i;
unsigned long start_dma_addr;
unsigned long mask;
unsigned long offset_slots;
unsigned long max_slots;

mask = dma_get_seg_boundary(hwdev);
start_dma_addr = virt_to_bus(io_tlb_start) & mask;

offset_slots = ALIGN(start_dma_addr, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
max_slots = ALIGN(mask + 1, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;

/*
* For mappings greater than a page, we limit the stride (and
Expand All @@ -311,10 +330,17 @@ map_single(struct device *hwdev, char *buffer, size_t size, int dir)
*/
spin_lock_irqsave(&io_tlb_lock, flags);
{
wrap = index = ALIGN(io_tlb_index, stride);

index = ALIGN(io_tlb_index, stride);
if (index >= io_tlb_nslabs)
wrap = index = 0;
index = 0;

while (is_span_boundary(index, nslots, offset_slots,
max_slots)) {
index += stride;
if (index >= io_tlb_nslabs)
index = 0;
}
wrap = index;

do {
/*
Expand All @@ -341,9 +367,12 @@ map_single(struct device *hwdev, char *buffer, size_t size, int dir)

goto found;
}
index += stride;
if (index >= io_tlb_nslabs)
index = 0;
do {
index += stride;
if (index >= io_tlb_nslabs)
index = 0;
} while (is_span_boundary(index, nslots, offset_slots,
max_slots));
} while (index != wrap);

spin_unlock_irqrestore(&io_tlb_lock, flags);
Expand Down

0 comments on commit e34aeef

Please sign in to comment.