@@ -69,6 +69,8 @@ static struct iommu_table *iommu_pseries_alloc_table(int node)
6969 return tbl ;
7070}
7171
72+ static phys_addr_t pseries_ddw_max_ram ;
73+
7274#ifdef CONFIG_IOMMU_API
7375static struct iommu_table_group_ops spapr_tce_table_group_ops ;
7476#endif
@@ -1285,15 +1287,19 @@ static LIST_HEAD(failed_ddw_pdn_list);
12851287
12861288static phys_addr_t ddw_memory_hotplug_max (void )
12871289{
1288- resource_size_t max_addr ;
1290+ resource_size_t max_addr = memory_hotplug_max ();
1291+ struct device_node * memory ;
12891292
1290- #if defined( CONFIG_NUMA ) && defined( CONFIG_MEMORY_HOTPLUG )
1291- max_addr = hot_add_drconf_memory_max () ;
1292- #else
1293- max_addr = memblock_end_of_DRAM ();
1294- #endif
1293+ for_each_node_by_type ( memory , "memory" ) {
1294+ struct resource res ;
1295+
1296+ if ( of_address_to_resource ( memory , 0 , & res ))
1297+ continue ;
12951298
1296- return max_addr ;
1299+ max_addr = max_t (resource_size_t , max_addr , res .end + 1 );
1300+ }
1301+
1302+ return max_addr ;
12971303}
12981304
12991305/*
@@ -1446,7 +1452,7 @@ static struct property *ddw_property_create(const char *propname, u32 liobn, u64
14461452static bool enable_ddw (struct pci_dev * dev , struct device_node * pdn , u64 dma_mask )
14471453{
14481454 int len = 0 , ret ;
1449- int max_ram_len = order_base_2 (ddw_memory_hotplug_max () );
1455+ int max_ram_len = order_base_2 (pseries_ddw_max_ram );
14501456 struct ddw_query_response query ;
14511457 struct ddw_create_response create ;
14521458 int page_shift ;
@@ -1668,7 +1674,7 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn, u64 dma_mas
16681674
16691675 if (direct_mapping ) {
16701676 /* DDW maps the whole partition, so enable direct DMA mapping */
1671- ret = walk_system_ram_range (0 , ddw_memory_hotplug_max () >> PAGE_SHIFT ,
1677+ ret = walk_system_ram_range (0 , pseries_ddw_max_ram >> PAGE_SHIFT ,
16721678 win64 -> value , tce_setrange_multi_pSeriesLP_walk );
16731679 if (ret ) {
16741680 dev_info (& dev -> dev , "failed to map DMA window for %pOF: %d\n" ,
@@ -2423,15 +2429,15 @@ static int iommu_mem_notifier(struct notifier_block *nb, unsigned long action,
24232429
24242430 /* This notifier can get called when onlining persistent memory as well.
24252431 * TCEs are not pre-mapped for persistent memory. Persistent memory will
2426- * always be above ddw_memory_hotplug_max()
2432+ * always be above pseries_ddw_max_ram
24272433 */
24282434
24292435 switch (action ) {
24302436 case MEM_GOING_ONLINE :
24312437 spin_lock (& dma_win_list_lock );
24322438 list_for_each_entry (window , & dma_win_list , list ) {
24332439 if (window -> direct && (arg -> start_pfn << PAGE_SHIFT ) <
2434- ddw_memory_hotplug_max () ) {
2440+ pseries_ddw_max_ram ) {
24352441 ret |= tce_setrange_multi_pSeriesLP (arg -> start_pfn ,
24362442 arg -> nr_pages , window -> prop );
24372443 }
@@ -2444,7 +2450,7 @@ static int iommu_mem_notifier(struct notifier_block *nb, unsigned long action,
24442450 spin_lock (& dma_win_list_lock );
24452451 list_for_each_entry (window , & dma_win_list , list ) {
24462452 if (window -> direct && (arg -> start_pfn << PAGE_SHIFT ) <
2447- ddw_memory_hotplug_max () ) {
2453+ pseries_ddw_max_ram ) {
24482454 ret |= tce_clearrange_multi_pSeriesLP (arg -> start_pfn ,
24492455 arg -> nr_pages , window -> prop );
24502456 }
@@ -2532,6 +2538,14 @@ void __init iommu_init_early_pSeries(void)
25322538 register_memory_notifier (& iommu_mem_nb );
25332539
25342540 set_pci_dma_ops (& dma_iommu_ops );
2541+
2542+ /* During init determine the max memory an LPAR can have and set it. This
2543+ * will be used for pre-mapping RAM in DDW. memblock_end_of_DRAM() can
2544+ * change during the running of LPAR - daxctl can add pmemory as
2545+ * "system-ram". This memory range should not be pre-mapped in DDW since
2546+ * the address of pmemory can be much higher than the DDW size.
2547+ */
2548+ pseries_ddw_max_ram = ddw_memory_hotplug_max ();
25352549}
25362550
25372551static int __init disable_multitce (char * str )
0 commit comments