Re: [PATCHv2 2/3] iovmm: add superpages support to fixed da address

From: Felipe Contreras
Date: Sun Oct 10 2010 - 11:22:37 EST


On Tue, Oct 5, 2010 at 12:02 AM, Fernando Guzman Lugo <x0095840@xxxxxx> wrote:
> This patch adds superpages support to fixed ad address
> inside iommu_kmap function.
>
> Signed-off-by: Fernando Guzman Lugo <x0095840@xxxxxx>
> ---
> Âarch/arm/plat-omap/iovmm.c | Â 61 ++++++++++++++++++++++++++-----------------
> Â1 files changed, 37 insertions(+), 24 deletions(-)
>
> diff --git a/arch/arm/plat-omap/iovmm.c b/arch/arm/plat-omap/iovmm.c
> index 34f0012..8006a19 100644
> --- a/arch/arm/plat-omap/iovmm.c
> +++ b/arch/arm/plat-omap/iovmm.c
> @@ -87,27 +87,37 @@ static size_t sgtable_len(const struct sg_table *sgt)
> Â}
> Â#define sgtable_ok(x) Â(!!sgtable_len(x))
>
> +
> +static unsigned max_alignment(u32 addr)
> +{
> + Â Â Â int i;
> + Â Â Â unsigned pagesize[] = { SZ_16M, SZ_1M, SZ_64K, SZ_4K, };
> + Â Â Â for (i = 0; i < ARRAY_SIZE(pagesize) && addr & (pagesize[i] - 1); i++)
> + Â Â Â Â Â Â Â ;
> + Â Â Â return (i < ARRAY_SIZE(pagesize)) ? pagesize[i] : 0;
> +}
> +
> +

I don't think those extra spaces make sense.

> Â/*
> Â* calculate the optimal number sg elements from total bytes based on
> Â* iommu superpages
> Â*/
> -static unsigned int sgtable_nents(size_t bytes)
> +static unsigned int sgtable_nents(size_t bytes, u32 da, u32 pa)
> Â{
> - Â Â Â int i;
> - Â Â Â unsigned int nr_entries;
> - Â Â Â const unsigned long pagesize[] = { SZ_16M, SZ_1M, SZ_64K, SZ_4K, };
> + Â Â Â unsigned int nr_entries = 0, ent_sz;

How about s/unsigned int/unsigned/?

>
> Â Â Â Âif (!IS_ALIGNED(bytes, PAGE_SIZE)) {
> Â Â Â Â Â Â Â Âpr_err("%s: wrong size %08x\n", __func__, bytes);
> Â Â Â Â Â Â Â Âreturn 0;
> Â Â Â Â}
>
> - Â Â Â nr_entries = 0;
> - Â Â Â for (i = 0; i < ARRAY_SIZE(pagesize); i++) {
> - Â Â Â Â Â Â Â if (bytes >= pagesize[i]) {
> - Â Â Â Â Â Â Â Â Â Â Â nr_entries += (bytes / pagesize[i]);
> - Â Â Â Â Â Â Â Â Â Â Â bytes %= pagesize[i];
> - Â Â Â Â Â Â Â }
> + Â Â Â while (bytes) {
> + Â Â Â Â Â Â Â ent_sz = max_alignment(da | pa);
> + Â Â Â Â Â Â Â ent_sz = min(ent_sz, (unsigned)iopgsz_max(bytes));
> + Â Â Â Â Â Â Â nr_entries++;
> + Â Â Â Â Â Â Â da += ent_sz;
> + Â Â Â Â Â Â Â pa += ent_sz;
> + Â Â Â Â Â Â Â bytes -= ent_sz;
> Â Â Â Â}
> Â Â Â ÂBUG_ON(bytes);
>
> @@ -115,7 +125,8 @@ static unsigned int sgtable_nents(size_t bytes)
> Â}
>
> Â/* allocate and initialize sg_table header(a kind of 'superblock') */
> -static struct sg_table *sgtable_alloc(const size_t bytes, u32 flags)
> +static struct sg_table *sgtable_alloc(const size_t bytes, u32 flags,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â u32 da, u32 pa)
> Â{
> Â Â Â Âunsigned int nr_entries;
> Â Â Â Âint err;
> @@ -127,9 +138,8 @@ static struct sg_table *sgtable_alloc(const size_t bytes, u32 flags)
> Â Â Â Âif (!IS_ALIGNED(bytes, PAGE_SIZE))
> Â Â Â Â Â Â Â Âreturn ERR_PTR(-EINVAL);
>
> - Â Â Â /* FIXME: IOVMF_DA_FIXED should support 'superpages' */
> - Â Â Â if ((flags & IOVMF_LINEAR) && (flags & IOVMF_DA_ANON)) {
> - Â Â Â Â Â Â Â nr_entries = sgtable_nents(bytes);
> + Â Â Â if (flags & IOVMF_LINEAR) {
> + Â Â Â Â Â Â Â nr_entries = sgtable_nents(bytes, da, pa);
> Â Â Â Â Â Â Â Âif (!nr_entries)
> Â Â Â Â Â Â Â Â Â Â Â Âreturn ERR_PTR(-EINVAL);
> Â Â Â Â} else
> @@ -409,7 +419,8 @@ static inline void sgtable_drain_vmalloc(struct sg_table *sgt)
> Â Â Â ÂBUG_ON(!sgt);
> Â}
>
> -static void sgtable_fill_kmalloc(struct sg_table *sgt, u32 pa, size_t len)
> +static void sgtable_fill_kmalloc(struct sg_table *sgt, u32 pa, u32 da,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â size_t len)
> Â{
> Â Â Â Âunsigned int i;
> Â Â Â Âstruct scatterlist *sg;
> @@ -420,7 +431,8 @@ static void sgtable_fill_kmalloc(struct sg_table *sgt, u32 pa, size_t len)
> Â Â Â Âfor_each_sg(sgt->sgl, sg, sgt->nents, i) {
> Â Â Â Â Â Â Â Âsize_t bytes;
>
> - Â Â Â Â Â Â Â bytes = iopgsz_max(len);
> + Â Â Â Â Â Â Â bytes = max_alignment(da | pa);
> + Â Â Â Â Â Â Â bytes = min(bytes, (size_t)iopgsz_max(len));

Why the size_t casting?

Otherwise:
Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>

--
Felipe Contreras
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/