[PATCH 13/14] drm/ttm: isolate dma data from ttm_tt V3

Jerome Glisse j.glisse at gmail.com
Tue Nov 15 16:35:54 PST 2011


On Tue, Nov 15, 2011 at 4:07 PM, Konrad Rzeszutek Wilk
<konrad.wilk at oracle.com> wrote:
> On Fri, Nov 11, 2011 at 05:47:48PM -0500, j.glisse at gmail.com wrote:
>> From: Jerome Glisse <jglisse at redhat.com>
>>
>> Move dma data to a superset ttm_dma_tt structure which herit
>
> inherit
>
>> from ttm_tt. This allow driver that don't use dma functionalities
>> to not have to waste memory for it.
>>
>> V2 Rebase on top of no memory account changes (where/when is my
>>    delorean when i need it ?)
>> V3 Make sure page list is initialized empty
>>
>> Signed-off-by: Jerome Glisse <jglisse at redhat.com>
>> Reviewed-by: Thomas Hellstrom <thellstrom at vmware.com>
> .. snip..
>
>> +void ttm_tt_fini(struct ttm_tt *ttm)
>> +{
>> +     drm_free_large(ttm->pages);
>> +     ttm->pages = NULL;
>> +}
>> +EXPORT_SYMBOL(ttm_tt_fini);
>> +
>> +int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev,
>> +             unsigned long size, uint32_t page_flags,
>> +             struct page *dummy_read_page)
>> +{
>> +     struct ttm_tt *ttm = &ttm_dma->ttm;
>> +
>> +     ttm->bdev = bdev;
>> +     ttm->glob = bdev->glob;
>> +     ttm->num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
>> +     ttm->caching_state = tt_cached;
>> +     ttm->page_flags = page_flags;
>> +     ttm->dummy_read_page = dummy_read_page;
>> +     ttm->state = tt_unpopulated;
>> +
>> +     INIT_LIST_HEAD(&ttm_dma->pages_list);
>> +     ttm_dma_tt_alloc_page_directory(ttm_dma);
>> +     if (!ttm->pages || !ttm_dma->dma_address) {
>> +             ttm_tt_destroy(ttm);
>> +             printk(KERN_ERR TTM_PFX "Failed allocating page table\n");
>> +             return -ENOMEM;
>> +     }
>> +     return 0;
>> +}
>> +EXPORT_SYMBOL(ttm_dma_tt_init);
>
> EXPORT_SYMBOL_GPL ?
>
>> +
>> +void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma)
>> +{
>> +     struct ttm_tt *ttm = &ttm_dma->ttm;
>> +
>> +     drm_free_large(ttm->pages);
>> +     ttm->pages = NULL;
>> +     drm_free_large(ttm_dma->dma_address);
>> +     ttm_dma->dma_address = NULL;
>> +}
>> +EXPORT_SYMBOL(ttm_dma_tt_fini);
>> +
>
> EXPORT_SYMBOL_GPL?
>
>
>>  void ttm_tt_unbind(struct ttm_tt *ttm)
>>  {
>>       int ret;
>> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
>> index 3986d74..1e2c0fb 100644
>> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
>> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
>> @@ -168,6 +168,7 @@ static void vmw_ttm_destroy(struct ttm_tt *ttm)
>>  {
>>       struct vmw_ttm_tt *vmw_be = container_of(ttm, struct vmw_ttm_tt, ttm);
>>
>> +     ttm_tt_fini(ttm);
>>       kfree(vmw_be);
>>  }
>>
>> @@ -191,6 +192,7 @@ struct ttm_tt *vmw_ttm_tt_create(struct ttm_bo_device *bdev,
>>       vmw_be->dev_priv = container_of(bdev, struct vmw_private, bdev);
>>
>>       if (ttm_tt_init(&vmw_be->ttm, bdev, size, page_flags, dummy_read_page)) {
>> +             kfree(vmw_be);
>>               return NULL;
>>       }
>>
>> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
>> index beef9ab..89caa48 100644
>> --- a/include/drm/ttm/ttm_bo_driver.h
>> +++ b/include/drm/ttm/ttm_bo_driver.h
>> @@ -104,7 +104,6 @@ enum ttm_caching_state {
>>   * @caching_state: The current caching state of the pages.
>>   * @state: The current binding state of the pages.
>>   * @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32)
>> - * @alloc_list: used by some page allocation backend
>>   *
>>   * This is a structure holding the pages, caching- and aperture binding
>>   * status for a buffer object that isn't backed by fixed (VRAM / AGP)
>> @@ -127,8 +126,23 @@ struct ttm_tt {
>>               tt_unbound,
>>               tt_unpopulated,
>>       } state;
>> +};
>> +
>> +/**
>> + * struct ttm_dma_tt
>> + *
>> + * @ttm: Base ttm_tt struct.
>> + * @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32)
>
> Not anymore (the TTM_PAGE_FLAG_DMA32 comment).
>
>> + * @pages_list: used by some page allocation backend
>> + *
>> + * This is a structure holding the pages, caching- and aperture binding
>> + * status for a buffer object that isn't backed by fixed (VRAM / AGP)
>> + * memory.
>> + */
>> +struct ttm_dma_tt {
>> +     struct ttm_tt ttm;
>>       dma_addr_t *dma_address;
>> -     struct list_head alloc_list;
>> +     struct list_head pages_list;
>>  };
>>
>>  #define TTM_MEMTYPE_FLAG_FIXED         (1 << 0)      /* Fixed (on-card) PCI memory */
>> @@ -595,6 +609,19 @@ ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask)
>>  extern int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev,
>>                       unsigned long size, uint32_t page_flags,
>>                       struct page *dummy_read_page);
>> +extern int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev,
>> +                        unsigned long size, uint32_t page_flags,
>> +                        struct page *dummy_read_page);
>> +
>> +/**
>> + * ttm_tt_fini
>> + *
>> + * @ttm: The struct ttm_tt.
>> + *
>> + * Free memory of ttm_tt structu
>
> structure
>> + */
>> +extern void ttm_tt_fini(struct ttm_tt *ttm);
>> +extern void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
>
>
> .. snip..
>>   * Initialize pool allocator.
>>   */
>>  int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages);
>> @@ -107,8 +78,8 @@ void ttm_dma_page_alloc_fini(void);
>>   */
>>  extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
>>
>> -int ttm_dma_populate(struct ttm_tt *ttm, struct device *dev);
>> -extern void ttm_dma_unpopulate(struct ttm_tt *ttm, struct device *dev);
>> +int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
>> +extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
>>
>>  #else
>>  static inline int ttm_dma_page_alloc_init(struct ttm_mem_global *glob,
>
> You are missing changes to the static implementations in case CONFIG_SWIOTLB is not set.
>

Actually i don't think i miss anything
ttm_dma_populate/ttm_dma_unpopulate is conditional on CONFIG_SWIOTLB
in both radeon and nouveau. So i should be fine. Or did i miss
something else ?

Cheers,
Jerome


More information about the dri-devel mailing list