<div dir="ltr"><div dir="ltr">On Wed, 29 Jul 2020 at 06:33, Ruhl, Michael J <<a href="mailto:michael.j.ruhl@intel.com">michael.j.ruhl@intel.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">>-----Original Message-----<br>
>From: Ben Skeggs <<a href="mailto:skeggsb@gmail.com" target="_blank">skeggsb@gmail.com</a>><br>
>Sent: Tuesday, July 28, 2020 4:16 PM<br>
>To: Ruhl, Michael J <<a href="mailto:michael.j.ruhl@intel.com" target="_blank">michael.j.ruhl@intel.com</a>><br>
>Cc: Dave Airlie <<a href="mailto:airlied@gmail.com" target="_blank">airlied@gmail.com</a>>; <a href="mailto:dri-devel@lists.freedesktop.org" target="_blank">dri-devel@lists.freedesktop.org</a>;<br>
><a href="mailto:bskeggs@redhat.com" target="_blank">bskeggs@redhat.com</a><br>
>Subject: Re: [PATCH] nouveau: use ttm populate mapping functions. (v2)<br>
><br>
>On Wed, 29 Jul 2020 at 02:08, Ruhl, Michael J <<a href="mailto:michael.j.ruhl@intel.com" target="_blank">michael.j.ruhl@intel.com</a>><br>
>wrote:<br>
>><br>
>> >-----Original Message-----<br>
>> >From: dri-devel <<a href="mailto:dri-devel-bounces@lists.freedesktop.org" target="_blank">dri-devel-bounces@lists.freedesktop.org</a>> On Behalf Of<br>
>> >Dave Airlie<br>
>> >Sent: Monday, July 27, 2020 11:26 PM<br>
>> >To: <a href="mailto:dri-devel@lists.freedesktop.org" target="_blank">dri-devel@lists.freedesktop.org</a><br>
>> >Cc: <a href="mailto:bskeggs@redhat.com" target="_blank">bskeggs@redhat.com</a><br>
>> >Subject: [PATCH] nouveau: use ttm populate mapping functions. (v2)<br>
>> ><br>
>> >From: Dave Airlie <<a href="mailto:airlied@redhat.com" target="_blank">airlied@redhat.com</a>><br>
>> ><br>
>> >Instead of rolling driver copies of them.<br>
>> ><br>
>> >v2: cleanup return handling (Ben)<br>
>> >Signed-off-by: Dave Airlie <<a href="mailto:airlied@redhat.com" target="_blank">airlied@redhat.com</a>><br>
>> >---<br>
>> > drivers/gpu/drm/nouveau/nouveau_bo.c | 38 ++--------------------------<br>
>> > 1 file changed, 2 insertions(+), 36 deletions(-)<br>
>> ><br>
>> >diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c<br>
>> >b/drivers/gpu/drm/nouveau/nouveau_bo.c<br>
>> >index 7806278dce57..6ef5085c9a91 100644<br>
>> >--- a/drivers/gpu/drm/nouveau/nouveau_bo.c<br>
>> >+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c<br>
>> >@@ -1231,8 +1231,6 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm,<br>
>> >struct ttm_operation_ctx *ctx)<br>
>> >       struct ttm_dma_tt *ttm_dma = (void *)ttm;<br>
>> >       struct nouveau_drm *drm;<br>
>> >       struct device *dev;<br>
>> >-      unsigned i;<br>
>> >-      int r;<br>
>> >       bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);<br>
>> ><br>
>> >       if (ttm->state != tt_unpopulated)<br>
>> >@@ -1260,31 +1258,7 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm,<br>
>> >struct ttm_operation_ctx *ctx)<br>
>> >               return ttm_dma_populate((void *)ttm, dev, ctx);<br>
>> >       }<br>
>> > #endif<br>
>> >-<br>
>> >-      r = ttm_pool_populate(ttm, ctx);<br>
>> >-      if (r) {<br>
>> >-              return r;<br>
>> >-      }<br>
>> >-<br>
>> >-      for (i = 0; i < ttm->num_pages; i++) {<br>
>> >-              dma_addr_t addr;<br>
>> >-<br>
>> >-              addr = dma_map_page(dev, ttm->pages[i], 0, PAGE_SIZE,<br>
>> >-                                  DMA_BIDIRECTIONAL);<br>
>> >-<br>
>> >-              if (dma_mapping_error(dev, addr)) {<br>
>> >-                      while (i--) {<br>
>> >-                              dma_unmap_page(dev, ttm_dma-<br>
>> >>dma_address[i],<br>
>> >-                                             PAGE_SIZE,<br>
>> >DMA_BIDIRECTIONAL);<br>
>> >-                              ttm_dma->dma_address[i] = 0;<br>
>> >-                      }<br>
>> >-                      ttm_pool_unpopulate(ttm);<br>
>> >-                      return -EFAULT;<br>
>> >-              }<br>
>> >-<br>
>> >-              ttm_dma->dma_address[i] = addr;<br>
>> >-      }<br>
>> >-      return 0;<br>
>> >+      return ttm_populate_and_map_pages(dev, ttm_dma, ctx);<br>
>><br>
>> This is not a completely straight code replacement.<br>
>><br>
>> ttm_populate_and_map_pages() also has code to deal with pages that are<br>
>> contiguous (consolidates them).<br>
>><br>
>> Is it possible that the nouveau HW can't handle a contiguous buffer larger<br>
>> than PAG_SIZE?<br>
>I think it's fine.  The function appears to consolidate the pages for<br>
>the dma_map_page() call, but otherwise leave dma_address[] in<br>
>PAGE_SIZE chunks, I don't believe anything else in the driver will<br>
>care.<br>
<br>
Ahh..  I misread it.   This is limiting the calls to dma_map_page().  Instead<br>
of calling it for each page, just do it for the first one...<br>
<br>
Thanks for setting me straight. 😊<br>
<br>
Reviewed-by: Michael J. Ruhl <<a href="mailto:michael.j.ruhl@intel.com" target="_blank">michael.j.ruhl@intel.com</a>><br></blockquote><div>Thanks for the review!  I've got the patch in my tree.</div><div><br></div><div>Ben.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Mike<br>
<br>
<br>
>Ben.<br>
><br>
>><br>
>> Thanks,<br>
>><br>
>> Mike<br>
>><br>
>> > }<br>
>> ><br>
>> > static void<br>
>> >@@ -1293,7 +1267,6 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)<br>
>> >       struct ttm_dma_tt *ttm_dma = (void *)ttm;<br>
>> >       struct nouveau_drm *drm;<br>
>> >       struct device *dev;<br>
>> >-      unsigned i;<br>
>> >       bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);<br>
>> ><br>
>> >       if (slave)<br>
>> >@@ -1316,14 +1289,7 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt<br>
>*ttm)<br>
>> >       }<br>
>> > #endif<br>
>> ><br>
>> >-      for (i = 0; i < ttm->num_pages; i++) {<br>
>> >-              if (ttm_dma->dma_address[i]) {<br>
>> >-                      dma_unmap_page(dev, ttm_dma->dma_address[i],<br>
>> >PAGE_SIZE,<br>
>> >-                                     DMA_BIDIRECTIONAL);<br>
>> >-              }<br>
>> >-      }<br>
>> >-<br>
>> >-      ttm_pool_unpopulate(ttm);<br>
>> >+      ttm_unmap_and_unpopulate_pages(dev, ttm_dma);<br>
>> > }<br>
>> ><br>
>> > void<br>
>> >--<br>
>> >2.26.2<br>
>> ><br>
>> >_______________________________________________<br>
>> >dri-devel mailing list<br>
>> ><a href="mailto:dri-devel@lists.freedesktop.org" target="_blank">dri-devel@lists.freedesktop.org</a><br>
>> ><a href="https://lists.freedesktop.org/mailman/listinfo/dri-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/dri-devel</a><br>
>> _______________________________________________<br>
>> dri-devel mailing list<br>
>> <a href="mailto:dri-devel@lists.freedesktop.org" target="_blank">dri-devel@lists.freedesktop.org</a><br>
>> <a href="https://lists.freedesktop.org/mailman/listinfo/dri-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/dri-devel</a><br>
</blockquote></div></div>