]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
powerpc/pseries/iommu: Use memory@ nodes in max RAM address calculation
authorAlexey Kardashevskiy <aik@ozlabs.ru>
Wed, 19 Dec 2018 08:52:18 +0000 (19:52 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 21 Dec 2018 05:20:46 +0000 (16:20 +1100)
We might have memory@ nodes with "linux,usable-memory" set to zero
(for example, to replicate powernv's behaviour for GPU coherent memory)
which means that the memory needs an extra initialization but since
it can be used afterwards, the pseries platform will try mapping it
for DMA so the DMA window needs to cover those memory regions too;
if the window cannot cover new memory regions, the memory onlining fails.

This walks through the memory nodes to find the highest RAM address to
let a huge DMA window cover that too in case this memory gets onlined
later.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/platforms/pseries/iommu.c

index 06f02960b4392386375b5b4d87eb604cf7465438..cbcc8ceddd87a729241504ee906beac91625a484 100644 (file)
@@ -964,6 +964,37 @@ struct failed_ddw_pdn {
 
 static LIST_HEAD(failed_ddw_pdn_list);
 
+static phys_addr_t ddw_memory_hotplug_max(void)
+{
+       phys_addr_t max_addr = memory_hotplug_max();
+       struct device_node *memory;
+
+       for_each_node_by_type(memory, "memory") {
+               unsigned long start, size;
+               int ranges, n_mem_addr_cells, n_mem_size_cells, len;
+               const __be32 *memcell_buf;
+
+               memcell_buf = of_get_property(memory, "reg", &len);
+               if (!memcell_buf || len <= 0)
+                       continue;
+
+               n_mem_addr_cells = of_n_addr_cells(memory);
+               n_mem_size_cells = of_n_size_cells(memory);
+
+               /* ranges in cell */
+               ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells);
+
+               start = of_read_number(memcell_buf, n_mem_addr_cells);
+               memcell_buf += n_mem_addr_cells;
+               size = of_read_number(memcell_buf, n_mem_size_cells);
+               memcell_buf += n_mem_size_cells;
+
+               max_addr = max_t(phys_addr_t, max_addr, start + size);
+       }
+
+       return max_addr;
+}
+
 /*
  * If the PE supports dynamic dma windows, and there is space for a table
  * that can map all pages in a linear offset, then setup such a table,
@@ -1053,7 +1084,7 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
        }
        /* verify the window * number of ptes will map the partition */
        /* check largest block * page size > max memory hotplug addr */
-       max_addr = memory_hotplug_max();
+       max_addr = ddw_memory_hotplug_max();
        if (query.largest_available_block < (max_addr >> page_shift)) {
                dev_dbg(&dev->dev, "can't map partition max 0x%llx with %u "
                          "%llu-sized pages\n", max_addr,  query.largest_available_block,