summaryrefslogtreecommitdiffstats
path: root/arch/powerpc
diff options
context:
space:
mode:
authorGavin Shan <gwshan@linux.vnet.ibm.com>2016-05-04 22:04:16 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2016-05-11 07:54:22 -0400
commit2b923ed1bd96cc471bb0f0eddfed6ae4753d717b (patch)
treee4263dd6fa6e6b93488dea5e5f192620fe82f9af /arch/powerpc
parent801846d1deff943114f6f468b21386247b008321 (diff)
powerpc/powernv/ioda1: Improve DMA32 segment track
In current implementation, the DMA32 segments required by one specific PE isn't calculated with the information hold in the PE independently. It conflicts with the PCI hotplug design: PE centralized, meaning the PE's DMA32 segments should be calculated from the information hold in the PE independently. This introduces an array (@dma32_segmap) for every PHB to track the DMA32 segmeng usage. Besides, this moves the logic calculating PE's consumed DMA32 segments to pnv_pci_ioda1_setup_dma_pe() so that PE's DMA32 segments are calculated/allocated from the information hold in the PE (DMA32 weight). Also the logic is improved: we try to allocate as much DMA32 segments as we can. It's acceptable that number of DMA32 segments less than the expected number are allocated. Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com> Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'arch/powerpc')
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c115
-rw-r--r--arch/powerpc/platforms/powernv/pci.h7
2 files changed, 66 insertions, 56 deletions
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 30c825a8c06c..98879a042fa3 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -2011,27 +2011,62 @@ static unsigned int pnv_pci_ioda_pe_dma_weight(struct pnv_ioda_pe *pe)
2011} 2011}
2012 2012
2013static void pnv_pci_ioda1_setup_dma_pe(struct pnv_phb *phb, 2013static void pnv_pci_ioda1_setup_dma_pe(struct pnv_phb *phb,
2014 struct pnv_ioda_pe *pe, 2014 struct pnv_ioda_pe *pe)
2015 unsigned int base,
2016 unsigned int segs)
2017{ 2015{
2018 2016
2019 struct page *tce_mem = NULL; 2017 struct page *tce_mem = NULL;
2020 struct iommu_table *tbl; 2018 struct iommu_table *tbl;
2021 unsigned int tce32_segsz, i; 2019 unsigned int weight, total_weight = 0;
2020 unsigned int tce32_segsz, base, segs, avail, i;
2022 int64_t rc; 2021 int64_t rc;
2023 void *addr; 2022 void *addr;
2024 2023
2025 /* XXX FIXME: Handle 64-bit only DMA devices */ 2024 /* XXX FIXME: Handle 64-bit only DMA devices */
2026 /* XXX FIXME: Provide 64-bit DMA facilities & non-4K TCE tables etc.. */ 2025 /* XXX FIXME: Provide 64-bit DMA facilities & non-4K TCE tables etc.. */
2027 /* XXX FIXME: Allocate multi-level tables on PHB3 */ 2026 /* XXX FIXME: Allocate multi-level tables on PHB3 */
2027 weight = pnv_pci_ioda_pe_dma_weight(pe);
2028 if (!weight)
2029 return;
2030
2031 pci_walk_bus(phb->hose->bus, pnv_pci_ioda_dev_dma_weight,
2032 &total_weight);
2033 segs = (weight * phb->ioda.dma32_count) / total_weight;
2034 if (!segs)
2035 segs = 1;
2028 2036
2037 /*
2038 * Allocate contiguous DMA32 segments. We begin with the expected
2039 * number of segments. With one more attempt, the number of DMA32
2040 * segments to be allocated is decreased by one until one segment
2041 * is allocated successfully.
2042 */
2043 do {
2044 for (base = 0; base <= phb->ioda.dma32_count - segs; base++) {
2045 for (avail = 0, i = base; i < base + segs; i++) {
2046 if (phb->ioda.dma32_segmap[i] ==
2047 IODA_INVALID_PE)
2048 avail++;
2049 }
2050
2051 if (avail == segs)
2052 goto found;
2053 }
2054 } while (--segs);
2055
2056 if (!segs) {
2057 pe_warn(pe, "No available DMA32 segments\n");
2058 return;
2059 }
2060
2061found:
2029 tbl = pnv_pci_table_alloc(phb->hose->node); 2062 tbl = pnv_pci_table_alloc(phb->hose->node);
2030 iommu_register_group(&pe->table_group, phb->hose->global_number, 2063 iommu_register_group(&pe->table_group, phb->hose->global_number,
2031 pe->pe_number); 2064 pe->pe_number);
2032 pnv_pci_link_table_and_group(phb->hose->node, 0, tbl, &pe->table_group); 2065 pnv_pci_link_table_and_group(phb->hose->node, 0, tbl, &pe->table_group);
2033 2066
2034 /* Grab a 32-bit TCE table */ 2067 /* Grab a 32-bit TCE table */
2068 pe_info(pe, "DMA weight %d (%d), assigned (%d) %d DMA32 segments\n",
2069 weight, total_weight, base, segs);
2035 pe_info(pe, " Setting up 32-bit TCE table at %08x..%08x\n", 2070 pe_info(pe, " Setting up 32-bit TCE table at %08x..%08x\n",
2036 base * PNV_IODA1_DMA32_SEGSIZE, 2071 base * PNV_IODA1_DMA32_SEGSIZE,
2037 (base + segs) * PNV_IODA1_DMA32_SEGSIZE - 1); 2072 (base + segs) * PNV_IODA1_DMA32_SEGSIZE - 1);
@@ -2068,6 +2103,10 @@ static void pnv_pci_ioda1_setup_dma_pe(struct pnv_phb *phb,
2068 } 2103 }
2069 } 2104 }
2070 2105
2106 /* Setup DMA32 segment mapping */
2107 for (i = base; i < base + segs; i++)
2108 phb->ioda.dma32_segmap[i] = pe->pe_number;
2109
2071 /* Setup linux iommu table */ 2110 /* Setup linux iommu table */
2072 pnv_pci_setup_iommu_table(tbl, addr, tce32_segsz * segs, 2111 pnv_pci_setup_iommu_table(tbl, addr, tce32_segsz * segs,
2073 base * PNV_IODA1_DMA32_SEGSIZE, 2112 base * PNV_IODA1_DMA32_SEGSIZE,
@@ -2542,73 +2581,34 @@ static void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb,
2542static void pnv_ioda_setup_dma(struct pnv_phb *phb) 2581static void pnv_ioda_setup_dma(struct pnv_phb *phb)
2543{ 2582{
2544 struct pci_controller *hose = phb->hose; 2583 struct pci_controller *hose = phb->hose;
2545 unsigned int weight, total_weight, dma_pe_count;
2546 unsigned int residual, remaining, segs, base;
2547 struct pnv_ioda_pe *pe; 2584 struct pnv_ioda_pe *pe;
2548 2585 unsigned int weight;
2549 total_weight = 0;
2550 pci_walk_bus(phb->hose->bus, pnv_pci_ioda_dev_dma_weight,
2551 &total_weight);
2552
2553 dma_pe_count = 0;
2554 list_for_each_entry(pe, &phb->ioda.pe_list, list) {
2555 weight = pnv_pci_ioda_pe_dma_weight(pe);
2556 if (weight > 0)
2557 dma_pe_count++;
2558 }
2559 2586
2560 /* If we have more PE# than segments available, hand out one 2587 /* If we have more PE# than segments available, hand out one
2561 * per PE until we run out and let the rest fail. If not, 2588 * per PE until we run out and let the rest fail. If not,
2562 * then we assign at least one segment per PE, plus more based 2589 * then we assign at least one segment per PE, plus more based
2563 * on the amount of devices under that PE 2590 * on the amount of devices under that PE
2564 */ 2591 */
2565 if (dma_pe_count > phb->ioda.tce32_count) 2592 pr_info("PCI: Domain %04x has %d available 32-bit DMA segments\n",
2566 residual = 0; 2593 hose->global_number, phb->ioda.dma32_count);
2567 else
2568 residual = phb->ioda.tce32_count - dma_pe_count;
2569
2570 pr_info("PCI: Domain %04x has %ld available 32-bit DMA segments\n",
2571 hose->global_number, phb->ioda.tce32_count);
2572 pr_info("PCI: %d PE# for a total weight of %d\n",
2573 dma_pe_count, total_weight);
2574 2594
2575 pnv_pci_ioda_setup_opal_tce_kill(phb); 2595 pnv_pci_ioda_setup_opal_tce_kill(phb);
2576 2596
2577 /* Walk our PE list and configure their DMA segments, hand them 2597 /* Walk our PE list and configure their DMA segments */
2578 * out one base segment plus any residual segments based on
2579 * weight
2580 */
2581 remaining = phb->ioda.tce32_count;
2582 base = 0;
2583 list_for_each_entry(pe, &phb->ioda.pe_list, list) { 2598 list_for_each_entry(pe, &phb->ioda.pe_list, list) {
2584 weight = pnv_pci_ioda_pe_dma_weight(pe); 2599 weight = pnv_pci_ioda_pe_dma_weight(pe);
2585 if (!weight) 2600 if (!weight)
2586 continue; 2601 continue;
2587 2602
2588 if (!remaining) {
2589 pe_warn(pe, "No DMA32 resources available\n");
2590 continue;
2591 }
2592 segs = 1;
2593 if (residual) {
2594 segs += ((weight * residual) + (total_weight / 2)) /
2595 total_weight;
2596 if (segs > remaining)
2597 segs = remaining;
2598 }
2599
2600 /* 2603 /*
2601 * For IODA2 compliant PHB3, we needn't care about the weight. 2604 * For IODA2 compliant PHB3, we needn't care about the weight.
2602 * The all available 32-bits DMA space will be assigned to 2605 * The all available 32-bits DMA space will be assigned to
2603 * the specific PE. 2606 * the specific PE.
2604 */ 2607 */
2605 if (phb->type == PNV_PHB_IODA1) { 2608 if (phb->type == PNV_PHB_IODA1) {
2606 pe_info(pe, "DMA weight %d, assigned %d DMA32 segments\n", 2609 pnv_pci_ioda1_setup_dma_pe(phb, pe);
2607 weight, segs);
2608 pnv_pci_ioda1_setup_dma_pe(phb, pe, base, segs);
2609 } else if (phb->type == PNV_PHB_IODA2) { 2610 } else if (phb->type == PNV_PHB_IODA2) {
2610 pe_info(pe, "Assign DMA32 space\n"); 2611 pe_info(pe, "Assign DMA32 space\n");
2611 segs = 0;
2612 pnv_pci_ioda2_setup_dma_pe(phb, pe); 2612 pnv_pci_ioda2_setup_dma_pe(phb, pe);
2613 } else if (phb->type == PNV_PHB_NPU) { 2613 } else if (phb->type == PNV_PHB_NPU) {
2614 /* 2614 /*
@@ -2618,9 +2618,6 @@ static void pnv_ioda_setup_dma(struct pnv_phb *phb)
2618 * as the PHB3 TVT. 2618 * as the PHB3 TVT.
2619 */ 2619 */
2620 } 2620 }
2621
2622 remaining -= segs;
2623 base += segs;
2624 } 2621 }
2625} 2622}
2626 2623
@@ -3327,7 +3324,8 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
3327{ 3324{
3328 struct pci_controller *hose; 3325 struct pci_controller *hose;
3329 struct pnv_phb *phb; 3326 struct pnv_phb *phb;
3330 unsigned long size, m64map_off, m32map_off, pemap_off, iomap_off = 0; 3327 unsigned long size, m64map_off, m32map_off, pemap_off;
3328 unsigned long iomap_off = 0, dma32map_off = 0;
3331 const __be64 *prop64; 3329 const __be64 *prop64;
3332 const __be32 *prop32; 3330 const __be32 *prop32;
3333 int len; 3331 int len;
@@ -3413,6 +3411,10 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
3413 phb->ioda.io_segsize = phb->ioda.io_size / phb->ioda.total_pe_num; 3411 phb->ioda.io_segsize = phb->ioda.io_size / phb->ioda.total_pe_num;
3414 phb->ioda.io_pci_base = 0; /* XXX calculate this ? */ 3412 phb->ioda.io_pci_base = 0; /* XXX calculate this ? */
3415 3413
3414 /* Calculate how many 32-bit TCE segments we have */
3415 phb->ioda.dma32_count = phb->ioda.m32_pci_base /
3416 PNV_IODA1_DMA32_SEGSIZE;
3417
3416 /* Allocate aux data & arrays. We don't have IO ports on PHB3 */ 3418 /* Allocate aux data & arrays. We don't have IO ports on PHB3 */
3417 size = _ALIGN_UP(phb->ioda.total_pe_num / 8, sizeof(unsigned long)); 3419 size = _ALIGN_UP(phb->ioda.total_pe_num / 8, sizeof(unsigned long));
3418 m64map_off = size; 3420 m64map_off = size;
@@ -3422,6 +3424,9 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
3422 if (phb->type == PNV_PHB_IODA1) { 3424 if (phb->type == PNV_PHB_IODA1) {
3423 iomap_off = size; 3425 iomap_off = size;
3424 size += phb->ioda.total_pe_num * sizeof(phb->ioda.io_segmap[0]); 3426 size += phb->ioda.total_pe_num * sizeof(phb->ioda.io_segmap[0]);
3427 dma32map_off = size;
3428 size += phb->ioda.dma32_count *
3429 sizeof(phb->ioda.dma32_segmap[0]);
3425 } 3430 }
3426 pemap_off = size; 3431 pemap_off = size;
3427 size += phb->ioda.total_pe_num * sizeof(struct pnv_ioda_pe); 3432 size += phb->ioda.total_pe_num * sizeof(struct pnv_ioda_pe);
@@ -3437,6 +3442,10 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
3437 phb->ioda.io_segmap = aux + iomap_off; 3442 phb->ioda.io_segmap = aux + iomap_off;
3438 for (segno = 0; segno < phb->ioda.total_pe_num; segno++) 3443 for (segno = 0; segno < phb->ioda.total_pe_num; segno++)
3439 phb->ioda.io_segmap[segno] = IODA_INVALID_PE; 3444 phb->ioda.io_segmap[segno] = IODA_INVALID_PE;
3445
3446 phb->ioda.dma32_segmap = aux + dma32map_off;
3447 for (segno = 0; segno < phb->ioda.dma32_count; segno++)
3448 phb->ioda.dma32_segmap[segno] = IODA_INVALID_PE;
3440 } 3449 }
3441 phb->ioda.pe_array = aux + pemap_off; 3450 phb->ioda.pe_array = aux + pemap_off;
3442 set_bit(phb->ioda.reserved_pe_idx, phb->ioda.pe_alloc); 3451 set_bit(phb->ioda.reserved_pe_idx, phb->ioda.pe_alloc);
@@ -3445,7 +3454,7 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
3445 mutex_init(&phb->ioda.pe_list_mutex); 3454 mutex_init(&phb->ioda.pe_list_mutex);
3446 3455
3447 /* Calculate how many 32-bit TCE segments we have */ 3456 /* Calculate how many 32-bit TCE segments we have */
3448 phb->ioda.tce32_count = phb->ioda.m32_pci_base / 3457 phb->ioda.dma32_count = phb->ioda.m32_pci_base /
3449 PNV_IODA1_DMA32_SEGSIZE; 3458 PNV_IODA1_DMA32_SEGSIZE;
3450 3459
3451#if 0 /* We should really do that ... */ 3460#if 0 /* We should really do that ... */
diff --git a/arch/powerpc/platforms/powernv/pci.h b/arch/powerpc/platforms/powernv/pci.h
index 117cfcd653e3..14d93911391d 100644
--- a/arch/powerpc/platforms/powernv/pci.h
+++ b/arch/powerpc/platforms/powernv/pci.h
@@ -142,6 +142,10 @@ struct pnv_phb {
142 unsigned int *m32_segmap; 142 unsigned int *m32_segmap;
143 unsigned int *io_segmap; 143 unsigned int *io_segmap;
144 144
145 /* DMA32 segment maps - IODA1 only */
146 unsigned int dma32_count;
147 unsigned int *dma32_segmap;
148
145 /* IRQ chip */ 149 /* IRQ chip */
146 int irq_chip_init; 150 int irq_chip_init;
147 struct irq_chip irq_chip; 151 struct irq_chip irq_chip;
@@ -158,9 +162,6 @@ struct pnv_phb {
158 */ 162 */
159 unsigned char pe_rmap[0x10000]; 163 unsigned char pe_rmap[0x10000];
160 164
161 /* 32-bit TCE tables allocation */
162 unsigned long tce32_count;
163
164 /* TCE cache invalidate registers (physical and 165 /* TCE cache invalidate registers (physical and
165 * remapped) 166 * remapped)
166 */ 167 */