Skip to content

Commit 2ca73c5

Browse files
LeoBrasmpe
authored andcommitted
powerpc/pseries/iommu: Allow DDW windows starting at 0x00
enable_ddw() currently returns the address of the DMA window, which is considered invalid if has the value 0x00. Also, it only considers valid an address returned from find_existing_ddw if it's not 0x00. Changing this behavior makes sense, given the users of enable_ddw() only need to know if direct mapping is possible. It can also allow a DMA window starting at 0x00 to be used. This will be helpful for using a DDW with indirect mapping, as the window address will be different than 0x00, but it will not map the whole partition. Signed-off-by: Leonardo Bras <[email protected]> Reviewed-by: Alexey Kardashevskiy <[email protected]> Reviewed-by: Frederic Barrat <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 92a2321 commit 2ca73c5

File tree

1 file changed

+18
-18
lines changed
  • arch/powerpc/platforms/pseries

1 file changed

+18
-18
lines changed

arch/powerpc/platforms/pseries/iommu.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -853,25 +853,26 @@ static void remove_ddw(struct device_node *np, bool remove_prop)
853853
np, ret);
854854
}
855855

856-
static u64 find_existing_ddw(struct device_node *pdn, int *window_shift)
856+
static bool find_existing_ddw(struct device_node *pdn, u64 *dma_addr, int *window_shift)
857857
{
858858
struct direct_window *window;
859859
const struct dynamic_dma_window_prop *direct64;
860-
u64 dma_addr = 0;
860+
bool found = false;
861861

862862
spin_lock(&direct_window_list_lock);
863863
/* check if we already created a window and dupe that config if so */
864864
list_for_each_entry(window, &direct_window_list, list) {
865865
if (window->device == pdn) {
866866
direct64 = window->prop;
867-
dma_addr = be64_to_cpu(direct64->dma_base);
867+
*dma_addr = be64_to_cpu(direct64->dma_base);
868868
*window_shift = be32_to_cpu(direct64->window_shift);
869+
found = true;
869870
break;
870871
}
871872
}
872873
spin_unlock(&direct_window_list_lock);
873874

874-
return dma_addr;
875+
return found;
875876
}
876877

877878
static struct direct_window *ddw_list_new_entry(struct device_node *pdn,
@@ -1161,20 +1162,20 @@ static int iommu_get_page_shift(u32 query_page_size)
11611162
* pdn: the parent pe node with the ibm,dma_window property
11621163
* Future: also check if we can remap the base window for our base page size
11631164
*
1164-
* returns the dma offset for use by the direct mapped DMA code.
1165+
* returns true if can map all pages (direct mapping), false otherwise..
11651166
*/
1166-
static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
1167+
static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn)
11671168
{
11681169
int len = 0, ret;
11691170
int max_ram_len = order_base_2(ddw_memory_hotplug_max());
11701171
struct ddw_query_response query;
11711172
struct ddw_create_response create;
11721173
int page_shift;
1173-
u64 dma_addr;
11741174
struct device_node *dn;
11751175
u32 ddw_avail[DDW_APPLICABLE_SIZE];
11761176
struct direct_window *window;
11771177
struct property *win64;
1178+
bool ddw_enabled = false;
11781179
struct dynamic_dma_window_prop *ddwprop;
11791180
struct failed_ddw_pdn *fpdn;
11801181
bool default_win_removed = false;
@@ -1186,9 +1187,10 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
11861187

11871188
mutex_lock(&direct_window_init_mutex);
11881189

1189-
dma_addr = find_existing_ddw(pdn, &len);
1190-
if (dma_addr != 0)
1190+
if (find_existing_ddw(pdn, &dev->dev.archdata.dma_offset, &len)) {
1191+
ddw_enabled = true;
11911192
goto out_unlock;
1193+
}
11921194

11931195
/*
11941196
* If we already went through this for a previous function of
@@ -1342,7 +1344,8 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
13421344
list_add(&window->list, &direct_window_list);
13431345
spin_unlock(&direct_window_list_lock);
13441346

1345-
dma_addr = be64_to_cpu(ddwprop->dma_base);
1347+
dev->dev.archdata.dma_offset = be64_to_cpu(ddwprop->dma_base);
1348+
ddw_enabled = true;
13461349
goto out_unlock;
13471350

13481351
out_free_window:
@@ -1374,10 +1377,10 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
13741377
* as RAM, then we failed to create a window to cover persistent
13751378
* memory and need to set the DMA limit.
13761379
*/
1377-
if (pmem_present && dma_addr && (len == max_ram_len))
1378-
dev->dev.bus_dma_limit = dma_addr + (1ULL << len);
1380+
if (pmem_present && ddw_enabled && (len == max_ram_len))
1381+
dev->dev.bus_dma_limit = dev->dev.archdata.dma_offset + (1ULL << len);
13791382

1380-
return dma_addr;
1383+
return ddw_enabled;
13811384
}
13821385

13831386
static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev)
@@ -1456,11 +1459,8 @@ static bool iommu_bypass_supported_pSeriesLP(struct pci_dev *pdev, u64 dma_mask)
14561459
break;
14571460
}
14581461

1459-
if (pdn && PCI_DN(pdn)) {
1460-
pdev->dev.archdata.dma_offset = enable_ddw(pdev, pdn);
1461-
if (pdev->dev.archdata.dma_offset)
1462-
return true;
1463-
}
1462+
if (pdn && PCI_DN(pdn))
1463+
return enable_ddw(pdev, pdn);
14641464

14651465
return false;
14661466
}

0 commit comments

Comments
 (0)