public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Michel Thierry <michel.thierry@intel.com>
To: Mika Kuoppala <mika.kuoppala@linux.intel.com>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 14/21] drm/i915/gtt: Make scratch page i915_page_dma compatible
Date: Wed, 24 Jun 2015 15:59:35 +0100	[thread overview]
Message-ID: <558AC5D7.4080307@intel.com> (raw)
In-Reply-To: <87zj46dx7v.fsf@gaia.fi.intel.com>

On 6/11/2015 5:30 PM, Mika Kuoppala wrote:
> Michel Thierry <michel.thierry@intel.com> writes:
>
>> On 5/22/2015 6:05 PM, Mika Kuoppala wrote:
>>> Lay out scratch page structure in similar manner than other
>>> paging structures. This allows us to use the same tools for
>>> setup and teardown.
>>>
>>> Signed-off-by: Mika Kuoppala <mika.kuoppala@intel.com>
>>> ---
>>>    drivers/gpu/drm/i915/i915_gem_gtt.c | 89 ++++++++++++++++++++-----------------
>>>    drivers/gpu/drm/i915/i915_gem_gtt.h |  9 ++--
>>>    2 files changed, 54 insertions(+), 44 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
>>> index 4f9a000..43fa543 100644
>>> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
>>> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
>>> @@ -301,11 +301,12 @@ static gen6_pte_t iris_pte_encode(dma_addr_t addr,
>>>           return pte;
>>>    }
>>>
>>> -static int setup_page_dma(struct drm_device *dev, struct i915_page_dma *p)
>>> +static int __setup_page_dma(struct drm_device *dev,
>>> +                           struct i915_page_dma *p, gfp_t flags)
>>>    {
>>>           struct device *device = &dev->pdev->dev;
>>>
>>> -       p->page = alloc_page(GFP_KERNEL);
>>> +       p->page = alloc_page(flags);
>>>           if (!p->page)
>>>                   return -ENOMEM;
>>>
>>> @@ -320,6 +321,11 @@ static int setup_page_dma(struct drm_device *dev, struct i915_page_dma *p)
>>>           return 0;
>>>    }
>>>
>>> +static int setup_page_dma(struct drm_device *dev, struct i915_page_dma *p)
>>> +{
>>> +       return __setup_page_dma(dev, p, GFP_KERNEL);
>>> +}
>>> +
>>>    static void cleanup_page_dma(struct drm_device *dev, struct i915_page_dma *p)
>>>    {
>>>           if (WARN_ON(!p->page))
>>> @@ -388,7 +394,8 @@ static void gen8_initialize_pt(struct i915_address_space *vm,
>>>    {
>>>           gen8_pte_t scratch_pte;
>>>
>>> -       scratch_pte = gen8_pte_encode(vm->scratch.addr, I915_CACHE_LLC, true);
>>> +       scratch_pte = gen8_pte_encode(px_dma(vm->scratch_page),
>>> +                                     I915_CACHE_LLC, true);
>>>
>>>           fill_px(vm->dev, pt, scratch_pte);
>>>    }
>>> @@ -515,7 +522,7 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm,
>>>           unsigned num_entries = length >> PAGE_SHIFT;
>>>           unsigned last_pte, i;
>>>
>>> -       scratch_pte = gen8_pte_encode(ppgtt->base.scratch.addr,
>>> +       scratch_pte = gen8_pte_encode(px_dma(ppgtt->base.scratch_page),
>>>                                         I915_CACHE_LLC, use_scratch);
>>>
>>>           while (num_entries) {
>>> @@ -1021,7 +1028,7 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m)
>>>           uint32_t  pte, pde, temp;
>>>           uint32_t start = ppgtt->base.start, length = ppgtt->base.total;
>>>
>>> -       scratch_pte = vm->pte_encode(vm->scratch.addr, I915_CACHE_LLC, true, 0);
>>> +       scratch_pte = vm->pte_encode(px_dma(vm->scratch_page), I915_CACHE_LLC, true, 0);
>>>
>>>           gen6_for_each_pde(unused, &ppgtt->pd, start, length, temp, pde) {
>>>                   u32 expected;
>>> @@ -1256,7 +1263,8 @@ static void gen6_ppgtt_clear_range(struct i915_address_space *vm,
>>>           unsigned first_pte = first_entry % GEN6_PTES;
>>>           unsigned last_pte, i;
>>>
>>> -       scratch_pte = vm->pte_encode(vm->scratch.addr, I915_CACHE_LLC, true, 0);
>>> +       scratch_pte = vm->pte_encode(px_dma(vm->scratch_page),
>>> +                                    I915_CACHE_LLC, true, 0);
>>>
>>>           while (num_entries) {
>>>                   last_pte = first_pte + num_entries;
>>> @@ -1314,9 +1322,10 @@ static void gen6_initialize_pt(struct i915_address_space *vm,
>>>    {
>>>           gen6_pte_t scratch_pte;
>>>
>>> -       WARN_ON(vm->scratch.addr == 0);
>>> +       WARN_ON(px_dma(vm->scratch_page) == 0);
>>>
>>> -       scratch_pte = vm->pte_encode(vm->scratch.addr, I915_CACHE_LLC, true, 0);
>>> +       scratch_pte = vm->pte_encode(px_dma(vm->scratch_page),
>>> +                                    I915_CACHE_LLC, true, 0);
>>>
>>>           fill32_px(vm->dev, pt, scratch_pte);
>>>    }
>>> @@ -1553,13 +1562,14 @@ static int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
>>>           struct drm_i915_private *dev_priv = dev->dev_private;
>>>
>>>           ppgtt->base.dev = dev;
>>> -       ppgtt->base.scratch = dev_priv->gtt.base.scratch;
>>> +       ppgtt->base.scratch_page = dev_priv->gtt.base.scratch_page;
>>>
>>>           if (INTEL_INFO(dev)->gen < 8)
>>>                   return gen6_ppgtt_init(ppgtt);
>>>           else
>>>                   return gen8_ppgtt_init(ppgtt);
>>>    }
>>> +
>>>    int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
>>>    {
>>>           struct drm_i915_private *dev_priv = dev->dev_private;
>>> @@ -1874,7 +1884,7 @@ static void gen8_ggtt_clear_range(struct i915_address_space *vm,
>>>                    first_entry, num_entries, max_entries))
>>>                   num_entries = max_entries;
>>>
>>> -       scratch_pte = gen8_pte_encode(vm->scratch.addr,
>>> +       scratch_pte = gen8_pte_encode(px_dma(vm->scratch_page),
>>>                                         I915_CACHE_LLC,
>>>                                         use_scratch);
>>>           for (i = 0; i < num_entries; i++)
>>> @@ -1900,7 +1910,8 @@ static void gen6_ggtt_clear_range(struct i915_address_space *vm,
>>>                    first_entry, num_entries, max_entries))
>>>                   num_entries = max_entries;
>>>
>>> -       scratch_pte = vm->pte_encode(vm->scratch.addr, I915_CACHE_LLC, use_scratch, 0);
>>> +       scratch_pte = vm->pte_encode(px_dma(vm->scratch_page),
>>> +                                    I915_CACHE_LLC, use_scratch, 0);
>>>
>>>           for (i = 0; i < num_entries; i++)
>>>                   iowrite32(scratch_pte, &gtt_base[i]);
>>> @@ -2157,42 +2168,40 @@ void i915_global_gtt_cleanup(struct drm_device *dev)
>>>           vm->cleanup(vm);
>>>    }
>>>
>>> -static int setup_scratch_page(struct drm_device *dev)
>>> +static int alloc_scratch_page(struct i915_address_space *vm)
>>>    {
>>> -       struct drm_i915_private *dev_priv = dev->dev_private;
>>> -       struct page *page;
>>> -       dma_addr_t dma_addr;
>>> +       struct i915_page_scratch *sp;
>>> +       int ret;
>>> +
>>> +       WARN_ON(vm->scratch_page);
>>>
>>> -       page = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
>>> -       if (page == NULL)
>>> +       sp = kzalloc(sizeof(*sp), GFP_KERNEL);
>>> +       if (sp == NULL)
>>>                   return -ENOMEM;
>>> -       set_pages_uc(page, 1);
>>>
>>> -#ifdef CONFIG_INTEL_IOMMU
>>> -       dma_addr = pci_map_page(dev->pdev, page, 0, PAGE_SIZE,
>>> -                               PCI_DMA_BIDIRECTIONAL);
>>> -       if (pci_dma_mapping_error(dev->pdev, dma_addr)) {
>>> -               __free_page(page);
>>> -               return -EINVAL;
>>> +       ret = __setup_page_dma(vm->dev, px_base(sp), GFP_DMA32 | __GFP_ZERO);
>>> +       if (ret) {
>>> +               kfree(sp);
>>> +               return ret;
>>>           }
>>> -#else
>>> -       dma_addr = page_to_phys(page);
>>> -#endif
>>
>> Should we keep a no-iommu option?
>> This seems to have been added for gen6 (gtt).
>>
>
> The dma_map_page should do the right thing with and
> without iommu. I really don't understand why we
> would need the no-iommu option.
>
> If there is no iommu, we get nommu_map_page()
> which is effectively page_to_phys().

Thanks for clear this up.

Reviewed-by: Michel Thierry <michel.thierry@intel.com>

>
> -Mika
>
>
>>> -       dev_priv->gtt.base.scratch.page = page;
>>> -       dev_priv->gtt.base.scratch.addr = dma_addr;
>>> +
>>> +       set_pages_uc(px_page(sp), 1);
>>> +
>>> +       vm->scratch_page = sp;
>>>
>>>           return 0;
>>>    }
>>>
>>> -static void teardown_scratch_page(struct drm_device *dev)
>>> +static void free_scratch_page(struct i915_address_space *vm)
>>>    {
>>> -       struct drm_i915_private *dev_priv = dev->dev_private;
>>> -       struct page *page = dev_priv->gtt.base.scratch.page;
>>> +       struct i915_page_scratch *sp = vm->scratch_page;
>>>
>>> -       set_pages_wb(page, 1);
>>> -       pci_unmap_page(dev->pdev, dev_priv->gtt.base.scratch.addr,
>>> -                      PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
>>> -       __free_page(page);
>>> +       set_pages_wb(px_page(sp), 1);
>>> +
>>> +       cleanup_px(vm->dev, sp);
>>> +       kfree(sp);
>>> +
>>> +       vm->scratch_page = NULL;
>>>    }
>>>
>>>    static unsigned int gen6_get_total_gtt_size(u16 snb_gmch_ctl)
>>> @@ -2300,7 +2309,7 @@ static int ggtt_probe_common(struct drm_device *dev,
>>>                   return -ENOMEM;
>>>           }
>>>
>>> -       ret = setup_scratch_page(dev);
>>> +       ret = alloc_scratch_page(&dev_priv->gtt.base);
>>>           if (ret) {
>>>                   DRM_ERROR("Scratch setup failed\n");
>>>                   /* iounmap will also get called at remove, but meh */
>>> @@ -2479,7 +2488,7 @@ static void gen6_gmch_remove(struct i915_address_space *vm)
>>>           struct i915_gtt *gtt = container_of(vm, struct i915_gtt, base);
>>>
>>>           iounmap(gtt->gsm);
>>> -       teardown_scratch_page(vm->dev);
>>> +       free_scratch_page(vm);
>>>    }
>>>
>>>    static int i915_gmch_probe(struct drm_device *dev,
>>> @@ -2543,13 +2552,13 @@ int i915_gem_gtt_init(struct drm_device *dev)
>>>                   dev_priv->gtt.base.cleanup = gen6_gmch_remove;
>>>           }
>>>
>>> +       gtt->base.dev = dev;
>>> +
>>>           ret = gtt->gtt_probe(dev, &gtt->base.total, &gtt->stolen_size,
>>>                                &gtt->mappable_base, &gtt->mappable_end);
>>>           if (ret)
>>>                   return ret;
>>>
>>> -       gtt->base.dev = dev;
>>> -
>>>           /* GMADR is the PCI mmio aperture into the global GTT. */
>>>           DRM_INFO("Memory usable by graphics device = %lluM\n",
>>>                    gtt->base.total >> 20);
>>> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
>>> index 006b839..1fd4041 100644
>>> --- a/drivers/gpu/drm/i915/i915_gem_gtt.h
>>> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
>>> @@ -217,6 +217,10 @@ struct i915_page_dma {
>>>    #define px_page(px) (px_base(px)->page)
>>>    #define px_dma(px) (px_base(px)->daddr)
>>>
>>> +struct i915_page_scratch {
>>> +       struct i915_page_dma base;
>>> +};
>>> +
>>>    struct i915_page_table {
>>>           struct i915_page_dma base;
>>>
>>> @@ -243,10 +247,7 @@ struct i915_address_space {
>>>           u64 start;              /* Start offset always 0 for dri2 */
>>>           u64 total;              /* size addr space maps (ex. 2GB for ggtt) */
>>>
>>> -       struct {
>>> -               dma_addr_t addr;
>>> -               struct page *page;
>>> -       } scratch;
>>> +       struct i915_page_scratch *scratch_page;
>>>
>>>           /**
>>>            * List of objects currently involved in rendering.
>>> --
>>> 1.9.1
>>>
>>> _______________________________________________
>>> Intel-gfx mailing list
>>> Intel-gfx@lists.freedesktop.org
>>> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
>>>
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2015-06-24 14:59 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-22 17:04 [PATCH 00/21] ppgtt cleanups / scratch merge (V2) Mika Kuoppala
2015-05-22 17:04 ` [PATCH 01/21] drm/i915/gtt: Mark TLBS dirty for gen8+ Mika Kuoppala
2015-06-01 14:51   ` Joonas Lahtinen
2015-06-11 17:37     ` Mika Kuoppala
2015-06-23 11:10       ` Joonas Lahtinen
2015-06-01 15:52   ` Michel Thierry
2015-05-22 17:04 ` [PATCH 02/21] drm/i915/gtt: Workaround for HW preload not flushing pdps Mika Kuoppala
2015-05-29 11:05   ` Michel Thierry
2015-05-29 12:53     ` Michel Thierry
2015-06-10 11:42       ` Michel Thierry
2015-06-11  7:31         ` Dave Gordon
2015-06-11 10:46           ` Michel Thierry
2015-06-11 13:57           ` Mika Kuoppala
2015-08-11  5:05             ` Zhiyuan Lv
2015-08-12  7:56               ` Michel Thierry
2015-08-12 15:09                 ` Dave Gordon
2015-08-13  9:36                   ` Zhiyuan Lv
2015-08-13  9:54                     ` Michel Thierry
2015-08-13  9:08                 ` Zhiyuan Lv
2015-08-13 10:12                   ` Michel Thierry
2015-08-13 11:42                     ` Dave Gordon
2015-08-13 12:03                       ` Dave Gordon
2015-08-13 14:56                         ` Zhiyuan Lv
2015-05-22 17:04 ` [PATCH 03/21] drm/i915/gtt: Check va range against vm size Mika Kuoppala
2015-06-01 15:33   ` Joonas Lahtinen
2015-06-11 14:23     ` Mika Kuoppala
2015-06-24 14:48       ` Michel Thierry
2015-05-22 17:04 ` [PATCH 04/21] drm/i915/gtt: Allow >= 4GB sizes for vm Mika Kuoppala
2015-05-26  7:15   ` Daniel Vetter
2015-06-11 17:38     ` Mika Kuoppala
2015-05-22 17:04 ` [PATCH 05/21] drm/i915/gtt: Don't leak scratch page on mapping error Mika Kuoppala
2015-06-01 15:02   ` Joonas Lahtinen
2015-06-15 10:13     ` Daniel Vetter
2015-05-22 17:04 ` [PATCH 06/21] drm/i915/gtt: Remove _single from page table allocator Mika Kuoppala
2015-06-02  9:53   ` Joonas Lahtinen
2015-06-02  9:56   ` Michel Thierry
2015-06-15 10:14     ` Daniel Vetter
2015-05-22 17:05 ` [PATCH 07/21] drm/i915/gtt: Introduce i915_page_dir_dma_addr Mika Kuoppala
2015-06-02 10:11   ` Michel Thierry
2015-05-22 17:05 ` [PATCH 08/21] drm/i915/gtt: Introduce struct i915_page_dma Mika Kuoppala
2015-06-02 12:39   ` Michel Thierry
2015-06-11 17:48     ` Mika Kuoppala
2015-06-22 14:05       ` Michel Thierry
2015-05-22 17:05 ` [PATCH 09/21] drm/i915/gtt: Rename unmap_and_free_px to free_px Mika Kuoppala
2015-06-02 13:08   ` Michel Thierry
2015-06-11 17:48     ` Mika Kuoppala
2015-06-22 14:09       ` Michel Thierry
2015-06-22 14:43         ` Daniel Vetter
2015-05-22 17:05 ` [PATCH 10/21] drm/i915/gtt: Remove superfluous free_pd with gen6/7 Mika Kuoppala
2015-06-02 14:07   ` Michel Thierry
2015-05-22 17:05 ` [PATCH 11/21] drm/i915/gtt: Introduce fill_page_dma() Mika Kuoppala
2015-06-02 14:51   ` Michel Thierry
2015-06-02 15:01     ` Ville Syrjälä
2015-06-15 10:16       ` Daniel Vetter
2015-06-11 17:50     ` Mika Kuoppala
2015-06-24 15:05       ` Michel Thierry
2015-05-22 17:05 ` [PATCH 12/21] drm/i915/gtt: Introduce kmap|kunmap for dma page Mika Kuoppala
2015-06-03 10:55   ` Michel Thierry
2015-06-11 17:50     ` Mika Kuoppala
2015-06-24 15:06       ` Michel Thierry
2015-05-22 17:05 ` [PATCH 13/21] drm/i915/gtt: Use macros to access dma mapped pages Mika Kuoppala
2015-06-03 10:57   ` Michel Thierry
2015-05-22 17:05 ` [PATCH 14/21] drm/i915/gtt: Make scratch page i915_page_dma compatible Mika Kuoppala
2015-06-03 13:44   ` Michel Thierry
2015-06-11 16:30     ` Mika Kuoppala
2015-06-24 14:59       ` Michel Thierry [this message]
2015-05-22 17:05 ` [PATCH 15/21] drm/i915/gtt: Fill scratch page Mika Kuoppala
2015-05-27 18:12   ` Tomas Elf
2015-06-01 15:53     ` Chris Wilson
2015-06-04 11:08       ` Tomas Elf
2015-06-04 11:24         ` Chris Wilson
2015-06-11 16:37     ` Mika Kuoppala
2015-06-03 14:03   ` Michel Thierry
2015-05-22 17:05 ` [PATCH 16/21] drm/i915/gtt: Pin vma during virtual address allocation Mika Kuoppala
2015-06-03 14:27   ` Michel Thierry
2015-05-22 17:05 ` [PATCH 17/21] drm/i915/gtt: Cleanup page directory encoding Mika Kuoppala
2015-06-03 14:58   ` Michel Thierry
2015-05-22 17:05 ` [PATCH 18/21] drm/i915/gtt: Move scratch_pd and scratch_pt into vm area Mika Kuoppala
2015-06-03 16:46   ` Michel Thierry
2015-05-22 17:05 ` [PATCH 19/21] drm/i915/gtt: One instance of scratch page table/directory Mika Kuoppala
2015-06-03 16:57   ` Michel Thierry
2015-05-22 17:05 ` [PATCH 20/21] drm/i915/gtt: Use nonatomic bitmap ops Mika Kuoppala
2015-06-03 17:07   ` Michel Thierry
2015-05-22 17:05 ` [PATCH 21/21] drm/i915/gtt: Reorder page alloc/free/init functions Mika Kuoppala
2015-06-03 17:14   ` Michel Thierry
2015-06-11 17:52     ` Mika Kuoppala

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=558AC5D7.4080307@intel.com \
    --to=michel.thierry@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=mika.kuoppala@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox