mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-10 21:07:02 +09:00
swiotlb: Move alloc_size to swiotlb_find_slots
Rename find_slots to swiotlb_find_slots and move the maintenance of alloc_size to it for better code reusability later. Signed-off-by: Claire Chang <tientzu@chromium.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Tested-by: Stefano Stabellini <sstabellini@kernel.org> Tested-by: Will Deacon <will@kernel.org> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
This commit is contained in:
committed by
Konrad Rzeszutek Wilk
parent
903cd0f315
commit
36f7b2f3ca
@@ -430,8 +430,8 @@ static unsigned int wrap_index(struct io_tlb_mem *mem, unsigned int index)
|
|||||||
* Find a suitable number of IO TLB entries size that will fit this request and
|
* Find a suitable number of IO TLB entries size that will fit this request and
|
||||||
* allocate a buffer from that IO TLB pool.
|
* allocate a buffer from that IO TLB pool.
|
||||||
*/
|
*/
|
||||||
static int find_slots(struct device *dev, phys_addr_t orig_addr,
|
static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr,
|
||||||
size_t alloc_size)
|
size_t alloc_size)
|
||||||
{
|
{
|
||||||
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
|
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
|
||||||
unsigned long boundary_mask = dma_get_seg_boundary(dev);
|
unsigned long boundary_mask = dma_get_seg_boundary(dev);
|
||||||
@@ -442,6 +442,7 @@ static int find_slots(struct device *dev, phys_addr_t orig_addr,
|
|||||||
dma_get_min_align_mask(dev) & ~(IO_TLB_SIZE - 1);
|
dma_get_min_align_mask(dev) & ~(IO_TLB_SIZE - 1);
|
||||||
unsigned int nslots = nr_slots(alloc_size), stride;
|
unsigned int nslots = nr_slots(alloc_size), stride;
|
||||||
unsigned int index, wrap, count = 0, i;
|
unsigned int index, wrap, count = 0, i;
|
||||||
|
unsigned int offset = swiotlb_align_offset(dev, orig_addr);
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
BUG_ON(!nslots);
|
BUG_ON(!nslots);
|
||||||
@@ -486,8 +487,11 @@ not_found:
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
found:
|
found:
|
||||||
for (i = index; i < index + nslots; i++)
|
for (i = index; i < index + nslots; i++) {
|
||||||
mem->slots[i].list = 0;
|
mem->slots[i].list = 0;
|
||||||
|
mem->slots[i].alloc_size =
|
||||||
|
alloc_size - (offset + ((i - index) << IO_TLB_SHIFT));
|
||||||
|
}
|
||||||
for (i = index - 1;
|
for (i = index - 1;
|
||||||
io_tlb_offset(i) != IO_TLB_SEGSIZE - 1 &&
|
io_tlb_offset(i) != IO_TLB_SEGSIZE - 1 &&
|
||||||
mem->slots[i].list; i--)
|
mem->slots[i].list; i--)
|
||||||
@@ -528,7 +532,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
|
|||||||
return (phys_addr_t)DMA_MAPPING_ERROR;
|
return (phys_addr_t)DMA_MAPPING_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = find_slots(dev, orig_addr, alloc_size + offset);
|
index = swiotlb_find_slots(dev, orig_addr, alloc_size + offset);
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
if (!(attrs & DMA_ATTR_NO_WARN))
|
if (!(attrs & DMA_ATTR_NO_WARN))
|
||||||
dev_warn_ratelimited(dev,
|
dev_warn_ratelimited(dev,
|
||||||
@@ -542,11 +546,8 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
|
|||||||
* This is needed when we sync the memory. Then we sync the buffer if
|
* This is needed when we sync the memory. Then we sync the buffer if
|
||||||
* needed.
|
* needed.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < nr_slots(alloc_size + offset); i++) {
|
for (i = 0; i < nr_slots(alloc_size + offset); i++)
|
||||||
mem->slots[index + i].orig_addr = slot_addr(orig_addr, i);
|
mem->slots[index + i].orig_addr = slot_addr(orig_addr, i);
|
||||||
mem->slots[index + i].alloc_size =
|
|
||||||
alloc_size - (i << IO_TLB_SHIFT);
|
|
||||||
}
|
|
||||||
tlb_addr = slot_addr(mem->start, index) + offset;
|
tlb_addr = slot_addr(mem->start, index) + offset;
|
||||||
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
|
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
|
||||||
(dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL))
|
(dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL))
|
||||||
|
|||||||
Reference in New Issue
Block a user