Message ID | 1516111004-10247-2-git-send-email-thellstrom@vmware.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Am 16.01.2018 um 14:56 schrieb Thomas Hellstrom: > Use helpers to perform the kmap_atomic_prot() functionality to > a) Avoid in-function ifdefs that violate the kernel coding policy, > b) Facilitate exporting the functionality. > > This commit should not change any functionality. > > Cc: Christian König <christian.koenig@amd.com> > Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Christian König <christian.koenig@amd.com> > --- > drivers/gpu/drm/ttm/ttm_bo_util.c | 64 +++++++++++++++++++-------------------- > 1 file changed, 31 insertions(+), 33 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c > index 153de1b..6d6d939 100644 > --- a/drivers/gpu/drm/ttm/ttm_bo_util.c > +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c > @@ -255,6 +255,33 @@ static int ttm_copy_io_page(void *dst, void *src, unsigned long page) > return 0; > } > > +#ifdef CONFIG_X86 > +#define __ttm_kmap_atomic_prot(__page, __prot) kmap_atomic_prot(__page, __prot) > +#define __ttm_kunmap_atomic(__addr) kunmap_atomic(__addr) > +#else > +#define __ttm_kmap_atomic_prot(__page, __prot) vmap(&__page, 1, 0, __prot) > +#define __ttm_kunmap_atomic(__addr) vunmap(__addr) > +#endif > + > +static void *ttm_kmap_atomic_prot(struct page *page, > + pgprot_t prot) > +{ > + if (pgprot_val(prot) == pgprot_val(PAGE_KERNEL)) > + return kmap_atomic(page); > + else > + return __ttm_kmap_atomic_prot(page, prot); > +} > + > + > +static void ttm_kunmap_atomic_prot(void *addr, > + pgprot_t prot) > +{ > + if (pgprot_val(prot) == pgprot_val(PAGE_KERNEL)) > + kunmap_atomic(addr); > + else > + __ttm_kunmap_atomic(addr); > +} > + > static int ttm_copy_io_ttm_page(struct ttm_tt *ttm, void *src, > unsigned long page, > pgprot_t prot) > @@ -266,28 +293,13 @@ static int ttm_copy_io_ttm_page(struct ttm_tt *ttm, void *src, > return -ENOMEM; > > src = (void *)((unsigned long)src + (page << PAGE_SHIFT)); > - > -#ifdef CONFIG_X86 > - dst = kmap_atomic_prot(d, prot); > -#else > - if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) > - dst = vmap(&d, 1, 0, prot); > - else > - dst = kmap(d); > -#endif > + dst = ttm_kmap_atomic_prot(d, prot); > if (!dst) > return -ENOMEM; > > memcpy_fromio(dst, src, PAGE_SIZE); > > -#ifdef CONFIG_X86 > - kunmap_atomic(dst); > -#else > - if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) > - vunmap(dst); > - else > - kunmap(d); > -#endif > + ttm_kunmap_atomic_prot(dst, prot); > > return 0; > } > @@ -303,27 +315,13 @@ static int ttm_copy_ttm_io_page(struct ttm_tt *ttm, void *dst, > return -ENOMEM; > > dst = (void *)((unsigned long)dst + (page << PAGE_SHIFT)); > -#ifdef CONFIG_X86 > - src = kmap_atomic_prot(s, prot); > -#else > - if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) > - src = vmap(&s, 1, 0, prot); > - else > - src = kmap(s); > -#endif > + src = ttm_kmap_atomic_prot(s, prot); > if (!src) > return -ENOMEM; > > memcpy_toio(dst, src, PAGE_SIZE); > > -#ifdef CONFIG_X86 > - kunmap_atomic(src); > -#else > - if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) > - vunmap(src); > - else > - kunmap(s); > -#endif > + ttm_kunmap_atomic_prot(src, prot); > > return 0; > }
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index 153de1b..6d6d939 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -255,6 +255,33 @@ static int ttm_copy_io_page(void *dst, void *src, unsigned long page) return 0; } +#ifdef CONFIG_X86 +#define __ttm_kmap_atomic_prot(__page, __prot) kmap_atomic_prot(__page, __prot) +#define __ttm_kunmap_atomic(__addr) kunmap_atomic(__addr) +#else +#define __ttm_kmap_atomic_prot(__page, __prot) vmap(&__page, 1, 0, __prot) +#define __ttm_kunmap_atomic(__addr) vunmap(__addr) +#endif + +static void *ttm_kmap_atomic_prot(struct page *page, + pgprot_t prot) +{ + if (pgprot_val(prot) == pgprot_val(PAGE_KERNEL)) + return kmap_atomic(page); + else + return __ttm_kmap_atomic_prot(page, prot); +} + + +static void ttm_kunmap_atomic_prot(void *addr, + pgprot_t prot) +{ + if (pgprot_val(prot) == pgprot_val(PAGE_KERNEL)) + kunmap_atomic(addr); + else + __ttm_kunmap_atomic(addr); +} + static int ttm_copy_io_ttm_page(struct ttm_tt *ttm, void *src, unsigned long page, pgprot_t prot) @@ -266,28 +293,13 @@ static int ttm_copy_io_ttm_page(struct ttm_tt *ttm, void *src, return -ENOMEM; src = (void *)((unsigned long)src + (page << PAGE_SHIFT)); - -#ifdef CONFIG_X86 - dst = kmap_atomic_prot(d, prot); -#else - if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) - dst = vmap(&d, 1, 0, prot); - else - dst = kmap(d); -#endif + dst = ttm_kmap_atomic_prot(d, prot); if (!dst) return -ENOMEM; memcpy_fromio(dst, src, PAGE_SIZE); -#ifdef CONFIG_X86 - kunmap_atomic(dst); -#else - if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) - vunmap(dst); - else - kunmap(d); -#endif + ttm_kunmap_atomic_prot(dst, prot); return 0; } @@ -303,27 +315,13 @@ static int ttm_copy_ttm_io_page(struct ttm_tt *ttm, void *dst, return -ENOMEM; dst = (void *)((unsigned long)dst + (page << PAGE_SHIFT)); -#ifdef CONFIG_X86 - src = kmap_atomic_prot(s, prot); -#else - if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) - src = vmap(&s, 1, 0, prot); - else - src = kmap(s); -#endif + src = ttm_kmap_atomic_prot(s, prot); if (!src) return -ENOMEM; memcpy_toio(dst, src, PAGE_SIZE); -#ifdef CONFIG_X86 - kunmap_atomic(src); -#else - if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) - vunmap(src); - else - kunmap(s); -#endif + ttm_kunmap_atomic_prot(src, prot); return 0; }
Use helpers to perform the kmap_atomic_prot() functionality to a) Avoid in-function ifdefs that violate the kernel coding policy, b) Facilitate exporting the functionality. This commit should not change any functionality. Cc: Christian König <christian.koenig@amd.com> Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> --- drivers/gpu/drm/ttm/ttm_bo_util.c | 64 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 33 deletions(-)