[Nouveau] [PATCH v5] drm/nouveau: map pages using DMA API

2014-08-05 Thread Ben Skeggs
On Mon, Aug 4, 2014 at 5:32 PM, Daniel Vetter  wrote:
> On Thu, Jul 31, 2014 at 06:09:42PM +0900, Alexandre Courbot wrote:
>> The DMA API is the recommended way to map pages no matter what the
>> underlying bus is. Use the DMA functions for page mapping and remove
>> currently existing wrappers.
>>
>> Signed-off-by: Alexandre Courbot 
>> Cc: Daniel Vetter 
>> ---
>> Changes since v4:
>> - Patch against the Nouveau tree instead of the kernel
>> - Separated this patch from the rest of the series since it can be
>>   merged alone
>> - Replaced all pci_map invokations with dma_map. As Daniel pointed
>>   out, using the PCI API is deprecated:
>> Documentation/DMA-API-HOWTO.txt:
>>
>> "Note that the DMA API works with any bus independent of the underlying
>> microprocessor architecture. You should use the DMA API rather than the
>> bus-specific DMA API, i.e., use the dma_map_*() interfaces rather than the
>> pci_map_*() interfaces."
>> - As a result, removed the page mapping wrappers which have become
>>   unneeded.
>
> Acked-by: Daniel Vetter 
Merged, finally.  Thanks :)

>
>>
>>  drm/nouveau_bo.c   | 22 --
>>  lib/core/os.h  |  8 
>>  nvkm/engine/device/base.c  | 25 -
>>  nvkm/include/core/device.h |  6 --
>>  nvkm/subdev/fb/nv50.c  |  7 +--
>>  nvkm/subdev/fb/nvc0.c  |  7 +--
>>  6 files changed, 30 insertions(+), 45 deletions(-)
>>
>> diff --git a/drm/nouveau_bo.c b/drm/nouveau_bo.c
>> index 4db886f9f793..e4f2071c46c3 100644
>> --- a/drm/nouveau_bo.c
>> +++ b/drm/nouveau_bo.c
>> @@ -1340,6 +1340,7 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
>>   struct nouveau_drm *drm;
>>   struct nouveau_device *device;
>>   struct drm_device *dev;
>> + struct device *pdev;
>>   unsigned i;
>>   int r;
>>   bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
>> @@ -1358,6 +1359,7 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
>>   drm = nouveau_bdev(ttm->bdev);
>>   device = nv_device(drm->device);
>>   dev = drm->dev;
>> + pdev = nv_device_base(device);
>>
>>  #if __OS_HAS_AGP
>>   if (drm->agp.stat == ENABLED) {
>> @@ -1377,17 +1379,22 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
>>   }
>>
>>   for (i = 0; i < ttm->num_pages; i++) {
>> - ttm_dma->dma_address[i] = nv_device_map_page(device,
>> -  ttm->pages[i]);
>> - if (!ttm_dma->dma_address[i]) {
>> + dma_addr_t addr;
>> +
>> + addr = dma_map_page(pdev, ttm->pages[i], 0, PAGE_SIZE,
>> + DMA_BIDIRECTIONAL);
>> +
>> + if (dma_mapping_error(pdev, addr)) {
>>   while (--i) {
>> - nv_device_unmap_page(device,
>> -  ttm_dma->dma_address[i]);
>> + dma_unmap_page(pdev, ttm_dma->dma_address[i],
>> +PAGE_SIZE, DMA_BIDIRECTIONAL);
>>   ttm_dma->dma_address[i] = 0;
>>   }
>>   ttm_pool_unpopulate(ttm);
>>   return -EFAULT;
>>   }
>> +
>> + ttm_dma->dma_address[i] = addr;
>>   }
>>   return 0;
>>  }
>> @@ -1399,6 +1406,7 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
>>   struct nouveau_drm *drm;
>>   struct nouveau_device *device;
>>   struct drm_device *dev;
>> + struct device *pdev;
>>   unsigned i;
>>   bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
>>
>> @@ -1408,6 +1416,7 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
>>   drm = nouveau_bdev(ttm->bdev);
>>   device = nv_device(drm->device);
>>   dev = drm->dev;
>> + pdev = nv_device_base(device);
>>
>>  #if __OS_HAS_AGP
>>   if (drm->agp.stat == ENABLED) {
>> @@ -1425,7 +1434,8 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
>>
>>   for (i = 0; i < ttm->num_pages; i++) {
>>   if (ttm_dma->dma_address[i]) {
>> - nv_device_unmap_page(device, ttm_dma->dma_address[i]);
>> + dma_unmap_page(pdev, ttm_dma->dma_address[i], 
>> PAGE_SIZE,
>> +DMA_BIDIRECTIONAL);
>>   }
>>   }
>>
>> diff --git a/lib/core/os.h b/lib/core/os.h
>> index 5f4f04fbff3d..596e083ffb36 100644
>> --- a/lib/core/os.h
>> +++ b/lib/core/os.h
>> @@ -644,7 +644,7 @@ dma_free_coherent(struct device *dev, size_t sz, void 
>> *vaddr, dma_addr_t bus)
>>   
>> */
>>  #include 
>>
>> -#define PCI_DMA_BIDIRECTIONAL 1
>> +#define DMA_BIDIRECTIONAL 1
>>
>>  #define PCI_CAP_ID_AGP 0x02
>>
>> @@ -688,7 +688,7 @@ pci_resource_len(struct pci_dev *pdev, int bar)
>>  }
>>
>>  static inline dma_addr_t
>> -pci_map_page(struct pci_dev *pdev, struct page *page, int offset,

[PATCH v5] drm/nouveau: map pages using DMA API

2014-08-04 Thread Daniel Vetter
On Thu, Jul 31, 2014 at 06:09:42PM +0900, Alexandre Courbot wrote:
> The DMA API is the recommended way to map pages no matter what the
> underlying bus is. Use the DMA functions for page mapping and remove
> currently existing wrappers.
> 
> Signed-off-by: Alexandre Courbot 
> Cc: Daniel Vetter 
> ---
> Changes since v4:
> - Patch against the Nouveau tree instead of the kernel
> - Separated this patch from the rest of the series since it can be
>   merged alone
> - Replaced all pci_map invokations with dma_map. As Daniel pointed
>   out, using the PCI API is deprecated:
> Documentation/DMA-API-HOWTO.txt:
> 
> "Note that the DMA API works with any bus independent of the underlying
> microprocessor architecture. You should use the DMA API rather than the
> bus-specific DMA API, i.e., use the dma_map_*() interfaces rather than the
> pci_map_*() interfaces."
> - As a result, removed the page mapping wrappers which have become
>   unneeded.

Acked-by: Daniel Vetter 

> 
>  drm/nouveau_bo.c   | 22 --
>  lib/core/os.h  |  8 
>  nvkm/engine/device/base.c  | 25 -
>  nvkm/include/core/device.h |  6 --
>  nvkm/subdev/fb/nv50.c  |  7 +--
>  nvkm/subdev/fb/nvc0.c  |  7 +--
>  6 files changed, 30 insertions(+), 45 deletions(-)
> 
> diff --git a/drm/nouveau_bo.c b/drm/nouveau_bo.c
> index 4db886f9f793..e4f2071c46c3 100644
> --- a/drm/nouveau_bo.c
> +++ b/drm/nouveau_bo.c
> @@ -1340,6 +1340,7 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
>   struct nouveau_drm *drm;
>   struct nouveau_device *device;
>   struct drm_device *dev;
> + struct device *pdev;
>   unsigned i;
>   int r;
>   bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
> @@ -1358,6 +1359,7 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
>   drm = nouveau_bdev(ttm->bdev);
>   device = nv_device(drm->device);
>   dev = drm->dev;
> + pdev = nv_device_base(device);
>  
>  #if __OS_HAS_AGP
>   if (drm->agp.stat == ENABLED) {
> @@ -1377,17 +1379,22 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
>   }
>  
>   for (i = 0; i < ttm->num_pages; i++) {
> - ttm_dma->dma_address[i] = nv_device_map_page(device,
> -  ttm->pages[i]);
> - if (!ttm_dma->dma_address[i]) {
> + dma_addr_t addr;
> +
> + addr = dma_map_page(pdev, ttm->pages[i], 0, PAGE_SIZE,
> + DMA_BIDIRECTIONAL);
> +
> + if (dma_mapping_error(pdev, addr)) {
>   while (--i) {
> - nv_device_unmap_page(device,
> -  ttm_dma->dma_address[i]);
> + dma_unmap_page(pdev, ttm_dma->dma_address[i],
> +PAGE_SIZE, DMA_BIDIRECTIONAL);
>   ttm_dma->dma_address[i] = 0;
>   }
>   ttm_pool_unpopulate(ttm);
>   return -EFAULT;
>   }
> +
> + ttm_dma->dma_address[i] = addr;
>   }
>   return 0;
>  }
> @@ -1399,6 +1406,7 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
>   struct nouveau_drm *drm;
>   struct nouveau_device *device;
>   struct drm_device *dev;
> + struct device *pdev;
>   unsigned i;
>   bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
>  
> @@ -1408,6 +1416,7 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
>   drm = nouveau_bdev(ttm->bdev);
>   device = nv_device(drm->device);
>   dev = drm->dev;
> + pdev = nv_device_base(device);
>  
>  #if __OS_HAS_AGP
>   if (drm->agp.stat == ENABLED) {
> @@ -1425,7 +1434,8 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
>  
>   for (i = 0; i < ttm->num_pages; i++) {
>   if (ttm_dma->dma_address[i]) {
> - nv_device_unmap_page(device, ttm_dma->dma_address[i]);
> + dma_unmap_page(pdev, ttm_dma->dma_address[i], PAGE_SIZE,
> +DMA_BIDIRECTIONAL);
>   }
>   }
>  
> diff --git a/lib/core/os.h b/lib/core/os.h
> index 5f4f04fbff3d..596e083ffb36 100644
> --- a/lib/core/os.h
> +++ b/lib/core/os.h
> @@ -644,7 +644,7 @@ dma_free_coherent(struct device *dev, size_t sz, void 
> *vaddr, dma_addr_t bus)
>   
> */
>  #include 
>  
> -#define PCI_DMA_BIDIRECTIONAL 1
> +#define DMA_BIDIRECTIONAL 1
>  
>  #define PCI_CAP_ID_AGP 0x02
>  
> @@ -688,7 +688,7 @@ pci_resource_len(struct pci_dev *pdev, int bar)
>  }
>  
>  static inline dma_addr_t
> -pci_map_page(struct pci_dev *pdev, struct page *page, int offset,
> +dma_map_page(struct device *pdev, struct page *page, int offset,
>int length, unsigned flags)
>  {
>   return 0;
> @@ -696,13 +696,13 @@ pci_map_page(struct pci_dev *pdev,