37
37
#include "amdgpu_gmc.h"
38
38
#include "amdgpu_xgmi.h"
39
39
#include "amdgpu_dma_buf.h"
40
- #include "amdgpu_res_cursor.h"
41
40
42
41
/**
43
42
* DOC: GPUVM
@@ -1583,7 +1582,7 @@ static int amdgpu_vm_update_ptes(struct amdgpu_vm_update_params *params,
1583
1582
* @last: last mapped entry
1584
1583
* @flags: flags for the entries
1585
1584
* @offset: offset into nodes and pages_addr
1586
- * @res: ttm_resource to map
1585
+ * @nodes: array of drm_mm_nodes with the MC addresses
1587
1586
* @pages_addr: DMA addresses to use for mapping
1588
1587
* @fence: optional resulting fence
1589
1588
*
@@ -1598,13 +1597,13 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
1598
1597
bool unlocked , struct dma_resv * resv ,
1599
1598
uint64_t start , uint64_t last ,
1600
1599
uint64_t flags , uint64_t offset ,
1601
- struct ttm_resource * res ,
1600
+ struct drm_mm_node * nodes ,
1602
1601
dma_addr_t * pages_addr ,
1603
1602
struct dma_fence * * fence )
1604
1603
{
1605
1604
struct amdgpu_vm_update_params params ;
1606
- struct amdgpu_res_cursor cursor ;
1607
1605
enum amdgpu_sync_mode sync_mode ;
1606
+ uint64_t pfn ;
1608
1607
int r ;
1609
1608
1610
1609
memset (& params , 0 , sizeof (params ));
@@ -1622,6 +1621,14 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
1622
1621
else
1623
1622
sync_mode = AMDGPU_SYNC_EXPLICIT ;
1624
1623
1624
+ pfn = offset >> PAGE_SHIFT ;
1625
+ if (nodes ) {
1626
+ while (pfn >= nodes -> size ) {
1627
+ pfn -= nodes -> size ;
1628
+ ++ nodes ;
1629
+ }
1630
+ }
1631
+
1625
1632
amdgpu_vm_eviction_lock (vm );
1626
1633
if (vm -> evicting ) {
1627
1634
r = - EBUSY ;
@@ -1640,17 +1647,23 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
1640
1647
if (r )
1641
1648
goto error_unlock ;
1642
1649
1643
- amdgpu_res_first (res , offset , (last - start + 1 ) * AMDGPU_GPU_PAGE_SIZE ,
1644
- & cursor );
1645
- while (cursor .remaining ) {
1650
+ do {
1646
1651
uint64_t tmp , num_entries , addr ;
1647
1652
1648
- num_entries = cursor .size >> AMDGPU_GPU_PAGE_SHIFT ;
1653
+
1654
+ num_entries = last - start + 1 ;
1655
+ if (nodes ) {
1656
+ addr = nodes -> start << PAGE_SHIFT ;
1657
+ num_entries = min ((nodes -> size - pfn ) *
1658
+ AMDGPU_GPU_PAGES_IN_CPU_PAGE , num_entries );
1659
+ } else {
1660
+ addr = 0 ;
1661
+ }
1662
+
1649
1663
if (pages_addr ) {
1650
1664
bool contiguous = true;
1651
1665
1652
1666
if (num_entries > AMDGPU_GPU_PAGES_IN_CPU_PAGE ) {
1653
- uint64_t pfn = cursor .start >> PAGE_SHIFT ;
1654
1667
uint64_t count ;
1655
1668
1656
1669
contiguous = pages_addr [pfn + 1 ] ==
@@ -1670,28 +1683,31 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
1670
1683
}
1671
1684
1672
1685
if (!contiguous ) {
1673
- addr = cursor . start ;
1686
+ addr = pfn << PAGE_SHIFT ;
1674
1687
params .pages_addr = pages_addr ;
1675
1688
} else {
1676
- addr = pages_addr [cursor . start >> PAGE_SHIFT ];
1689
+ addr = pages_addr [pfn ];
1677
1690
params .pages_addr = NULL ;
1678
1691
}
1679
1692
1680
1693
} else if (flags & (AMDGPU_PTE_VALID | AMDGPU_PTE_PRT )) {
1681
- addr = bo_adev -> vm_manager .vram_base_offset +
1682
- cursor .start ;
1683
- } else {
1684
- addr = 0 ;
1694
+ addr += bo_adev -> vm_manager .vram_base_offset ;
1695
+ addr += pfn << PAGE_SHIFT ;
1685
1696
}
1686
1697
1687
1698
tmp = start + num_entries ;
1688
1699
r = amdgpu_vm_update_ptes (& params , start , tmp , addr , flags );
1689
1700
if (r )
1690
1701
goto error_unlock ;
1691
1702
1692
- amdgpu_res_next (& cursor , num_entries * AMDGPU_GPU_PAGE_SIZE );
1703
+ pfn += num_entries / AMDGPU_GPU_PAGES_IN_CPU_PAGE ;
1704
+ if (nodes && nodes -> size == pfn ) {
1705
+ pfn = 0 ;
1706
+ ++ nodes ;
1707
+ }
1693
1708
start = tmp ;
1694
- };
1709
+
1710
+ } while (unlikely (start != last + 1 ));
1695
1711
1696
1712
r = vm -> update_funcs -> commit (& params , fence );
1697
1713
@@ -1720,6 +1736,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
1720
1736
struct amdgpu_bo_va_mapping * mapping ;
1721
1737
dma_addr_t * pages_addr = NULL ;
1722
1738
struct ttm_resource * mem ;
1739
+ struct drm_mm_node * nodes ;
1723
1740
struct dma_fence * * last_update ;
1724
1741
struct dma_resv * resv ;
1725
1742
uint64_t flags ;
@@ -1728,6 +1745,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
1728
1745
1729
1746
if (clear || !bo ) {
1730
1747
mem = NULL ;
1748
+ nodes = NULL ;
1731
1749
resv = vm -> root .base .bo -> tbo .base .resv ;
1732
1750
} else {
1733
1751
struct drm_gem_object * obj = & bo -> tbo .base ;
@@ -1742,6 +1760,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
1742
1760
bo = gem_to_amdgpu_bo (gobj );
1743
1761
}
1744
1762
mem = & bo -> tbo .mem ;
1763
+ nodes = mem -> mm_node ;
1745
1764
if (mem -> mem_type == TTM_PL_TT )
1746
1765
pages_addr = bo -> tbo .ttm -> dma_address ;
1747
1766
}
@@ -1790,7 +1809,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
1790
1809
r = amdgpu_vm_bo_update_mapping (adev , bo_adev , vm , false, false,
1791
1810
resv , mapping -> start ,
1792
1811
mapping -> last , update_flags ,
1793
- mapping -> offset , mem ,
1812
+ mapping -> offset , nodes ,
1794
1813
pages_addr , last_update );
1795
1814
if (r )
1796
1815
return r ;
0 commit comments