forked from luck/tmp_suning_uos_patched
swiotlb: factor out a nr_slots helper
commit: c32a77fd18780a5192dfb6eec69f239faebf28fd Factor out a helper to find the number of slots for a given size. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Jianxiong Gao <jxgao@google.com> Tested-by: Jianxiong Gao <jxgao@google.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Jianxiong Gao <jxgao@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
1bbcc985d1
commit
1f2ef5a0f7
|
@ -178,6 +178,11 @@ static inline unsigned long io_tlb_offset(unsigned long val)
|
||||||
return val & (IO_TLB_SEGSIZE - 1);
|
return val & (IO_TLB_SEGSIZE - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline unsigned long nr_slots(u64 val)
|
||||||
|
{
|
||||||
|
return DIV_ROUND_UP(val, IO_TLB_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Early SWIOTLB allocation may be too early to allow an architecture to
|
* Early SWIOTLB allocation may be too early to allow an architecture to
|
||||||
* perform the desired operations. This function allows the architecture to
|
* perform the desired operations. This function allows the architecture to
|
||||||
|
@ -477,20 +482,20 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr,
|
||||||
|
|
||||||
tbl_dma_addr &= mask;
|
tbl_dma_addr &= mask;
|
||||||
|
|
||||||
offset_slots = ALIGN(tbl_dma_addr, IO_TLB_SIZE) >> IO_TLB_SHIFT;
|
offset_slots = nr_slots(tbl_dma_addr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Carefully handle integer overflow which can occur when mask == ~0UL.
|
* Carefully handle integer overflow which can occur when mask == ~0UL.
|
||||||
*/
|
*/
|
||||||
max_slots = mask + 1
|
max_slots = mask + 1
|
||||||
? ALIGN(mask + 1, IO_TLB_SIZE) >> IO_TLB_SHIFT
|
? nr_slots(mask + 1)
|
||||||
: 1UL << (BITS_PER_LONG - IO_TLB_SHIFT);
|
: 1UL << (BITS_PER_LONG - IO_TLB_SHIFT);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For mappings greater than or equal to a page, we limit the stride
|
* For mappings greater than or equal to a page, we limit the stride
|
||||||
* (and hence alignment) to a page size.
|
* (and hence alignment) to a page size.
|
||||||
*/
|
*/
|
||||||
nslots = ALIGN(alloc_size, IO_TLB_SIZE) >> IO_TLB_SHIFT;
|
nslots = nr_slots(alloc_size);
|
||||||
if (alloc_size >= PAGE_SIZE)
|
if (alloc_size >= PAGE_SIZE)
|
||||||
stride = (1 << (PAGE_SHIFT - IO_TLB_SHIFT));
|
stride = (1 << (PAGE_SHIFT - IO_TLB_SHIFT));
|
||||||
else
|
else
|
||||||
|
@ -586,7 +591,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr,
|
||||||
enum dma_data_direction dir, unsigned long attrs)
|
enum dma_data_direction dir, unsigned long attrs)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int i, count, nslots = ALIGN(alloc_size, IO_TLB_SIZE) >> IO_TLB_SHIFT;
|
int i, count, nslots = nr_slots(alloc_size);
|
||||||
int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT;
|
int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT;
|
||||||
phys_addr_t orig_addr = io_tlb_orig_addr[index];
|
phys_addr_t orig_addr = io_tlb_orig_addr[index];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user