ANDROID: ion: Use nents, orig_nents in struct sg_table correctly
The header file linux/scatterlist.h defines the members nents and
orig_nents of struct sg_table as follows:
unsigned int nents; /* number of mapped entries */
unsigned int orig_nents; /* original size of list */
orig_nents describes the number of SG segments in virtual address space
and is related to the members page_link, offset and length in struct
scatterlist.
When passed to dma_map_sg, multiple SG segments might get merged into
fewer (often times just one) segments in dma address space. The
potentially smaller number of those segments in dma address space is
supposed to be stored in the nents member of struct sg_table.
Previously, ion code assumed that multiple SG segments are always merged
into a single virtually contiguous SG segment. However, that might not
always be true if the IOMMU layer cannot merge adjacent SG segments due
to alignment issues.
Fix this by using orig_nents instead of nents in most places and by
assigning the return value of dma_map_sg to the nents member. This way,
device drivers have access to the correct number of mapped entries and
don't have to assume that there is exactly one entry.
Bug: 162258084
Signed-off-by:
Daniel Mentz <danielmentz@google.com>
Change-Id: If9b38cfb27fa1d1e9184068c7676425a134b8e97
Loading
Please sign in to comment