2013-08-13 11:56:54 +02:00
/*
* Copyright 2013 Advanced Micro Devices , Inc .
*
* Permission is hereby granted , free of charge , to any person obtaining a
* copy of this software and associated documentation files ( the " Software " ) ,
* to deal in the Software without restriction , including without limitation
* the rights to use , copy , modify , merge , publish , distribute , sublicense ,
* and / or sell copies of the Software , and to permit persons to whom the
* Software is furnished to do so , subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software .
*
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
* IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL
* THE COPYRIGHT HOLDER ( S ) OR AUTHOR ( S ) BE LIABLE FOR ANY CLAIM , DAMAGES OR
* OTHER LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE ,
* ARISING FROM , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE .
*
* Authors : Alex Deucher
*/
# include <drm/drmP.h>
# include "radeon.h"
# include "radeon_asic.h"
# include "rv770d.h"
/**
* rv770_copy_dma - copy pages using the DMA engine
*
* @ rdev : radeon_device pointer
* @ src_offset : src GPU address
* @ dst_offset : dst GPU address
* @ num_gpu_pages : number of GPU pages to xfer
2014-09-04 20:01:53 +02:00
* @ resv : reservation object to sync to
2013-08-13 11:56:54 +02:00
*
* Copy GPU paging using the DMA engine ( r7xx ) .
* Used by the radeon ttm implementation to move pages if
* registered as the asic copy callback .
*/
2014-09-04 20:01:53 +02:00
struct radeon_fence * rv770_copy_dma ( struct radeon_device * rdev ,
uint64_t src_offset , uint64_t dst_offset ,
unsigned num_gpu_pages ,
struct reservation_object * resv )
2013-08-13 11:56:54 +02:00
{
2014-09-04 20:01:53 +02:00
struct radeon_fence * fence ;
2014-11-19 14:01:22 +01:00
struct radeon_sync sync ;
2013-08-13 11:56:54 +02:00
int ring_index = rdev - > asic - > copy . dma_ring_index ;
struct radeon_ring * ring = & rdev - > ring [ ring_index ] ;
u32 size_in_dw , cur_size_in_dw ;
int i , num_loops ;
int r = 0 ;
2014-11-19 14:01:22 +01:00
radeon_sync_create ( & sync ) ;
2013-08-13 11:56:54 +02:00
size_in_dw = ( num_gpu_pages < < RADEON_GPU_PAGE_SHIFT ) / 4 ;
num_loops = DIV_ROUND_UP ( size_in_dw , 0xFFFF ) ;
r = radeon_ring_lock ( rdev , ring , num_loops * 5 + 8 ) ;
if ( r ) {
DRM_ERROR ( " radeon: moving bo (%d). \n " , r ) ;
2014-11-19 14:01:22 +01:00
radeon_sync_free ( rdev , & sync , NULL ) ;
2014-09-04 20:01:53 +02:00
return ERR_PTR ( r ) ;
2013-08-13 11:56:54 +02:00
}
2014-11-19 14:01:22 +01:00
radeon_sync_resv ( rdev , & sync , resv , false ) ;
radeon_sync_rings ( rdev , & sync , ring - > idx ) ;
2013-08-13 11:56:54 +02:00
for ( i = 0 ; i < num_loops ; i + + ) {
cur_size_in_dw = size_in_dw ;
if ( cur_size_in_dw > 0xFFFF )
cur_size_in_dw = 0xFFFF ;
size_in_dw - = cur_size_in_dw ;
radeon_ring_write ( ring , DMA_PACKET ( DMA_PACKET_COPY , 0 , 0 , cur_size_in_dw ) ) ;
radeon_ring_write ( ring , dst_offset & 0xfffffffc ) ;
radeon_ring_write ( ring , src_offset & 0xfffffffc ) ;
radeon_ring_write ( ring , upper_32_bits ( dst_offset ) & 0xff ) ;
radeon_ring_write ( ring , upper_32_bits ( src_offset ) & 0xff ) ;
src_offset + = cur_size_in_dw * 4 ;
dst_offset + = cur_size_in_dw * 4 ;
}
2014-09-04 20:01:53 +02:00
r = radeon_fence_emit ( rdev , & fence , ring - > idx ) ;
2013-08-13 11:56:54 +02:00
if ( r ) {
radeon_ring_unlock_undo ( rdev , ring ) ;
2014-11-19 14:01:22 +01:00
radeon_sync_free ( rdev , & sync , NULL ) ;
2014-09-04 20:01:53 +02:00
return ERR_PTR ( r ) ;
2013-08-13 11:56:54 +02:00
}
2014-08-18 17:34:55 +09:00
radeon_ring_unlock_commit ( rdev , ring , false ) ;
2014-11-19 14:01:22 +01:00
radeon_sync_free ( rdev , & sync , fence ) ;
2013-08-13 11:56:54 +02:00
2014-09-04 20:01:53 +02:00
return fence ;
2013-08-13 11:56:54 +02:00
}