Skip to content

Commit 3ba3a73

Browse files
aikmpe
authored andcommitted
powerpc/powernv/ioda2: Fix calculation for memory allocated for TCE table
The existing code stores the amount of memory allocated for a TCE table. At the moment it uses @offset which is a virtual offset in the TCE table which is only correct for a one level tables and it does not include memory allocated for intermediate levels. When multilevel TCE table is requested, WARN_ON in tce_iommu_create_table() prints a warning. This adds an additional counter to pnv_pci_ioda2_table_do_alloc_pages() to count actually allocated memory. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent c5dfd65 commit 3ba3a73

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

arch/powerpc/platforms/powernv/pci-ioda.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ static void pnv_pci_ioda_setup_opal_tce_kill(struct pnv_phb *phb)
22202220

22212221
static __be64 *pnv_pci_ioda2_table_do_alloc_pages(int nid, unsigned shift,
22222222
unsigned levels, unsigned long limit,
2223-
unsigned long *current_offset)
2223+
unsigned long *current_offset, unsigned long *total_allocated)
22242224
{
22252225
struct page *tce_mem = NULL;
22262226
__be64 *addr, *tmp;
@@ -2236,6 +2236,7 @@ static __be64 *pnv_pci_ioda2_table_do_alloc_pages(int nid, unsigned shift,
22362236
}
22372237
addr = page_address(tce_mem);
22382238
memset(addr, 0, allocated);
2239+
*total_allocated += allocated;
22392240

22402241
--levels;
22412242
if (!levels) {
@@ -2245,7 +2246,7 @@ static __be64 *pnv_pci_ioda2_table_do_alloc_pages(int nid, unsigned shift,
22452246

22462247
for (i = 0; i < entries; ++i) {
22472248
tmp = pnv_pci_ioda2_table_do_alloc_pages(nid, shift,
2248-
levels, limit, current_offset);
2249+
levels, limit, current_offset, total_allocated);
22492250
if (!tmp)
22502251
break;
22512252

@@ -2267,7 +2268,7 @@ static long pnv_pci_ioda2_table_alloc_pages(int nid, __u64 bus_offset,
22672268
struct iommu_table *tbl)
22682269
{
22692270
void *addr;
2270-
unsigned long offset = 0, level_shift;
2271+
unsigned long offset = 0, level_shift, total_allocated = 0;
22712272
const unsigned window_shift = ilog2(window_size);
22722273
unsigned entries_shift = window_shift - page_shift;
22732274
unsigned table_shift = max_t(unsigned, entries_shift + 3, PAGE_SHIFT);
@@ -2286,7 +2287,7 @@ static long pnv_pci_ioda2_table_alloc_pages(int nid, __u64 bus_offset,
22862287

22872288
/* Allocate TCE table */
22882289
addr = pnv_pci_ioda2_table_do_alloc_pages(nid, level_shift,
2289-
levels, tce_table_size, &offset);
2290+
levels, tce_table_size, &offset, &total_allocated);
22902291

22912292
/* addr==NULL means that the first level allocation failed */
22922293
if (!addr)
@@ -2308,7 +2309,7 @@ static long pnv_pci_ioda2_table_alloc_pages(int nid, __u64 bus_offset,
23082309
page_shift);
23092310
tbl->it_level_size = 1ULL << (level_shift - 3);
23102311
tbl->it_indirect_levels = levels - 1;
2311-
tbl->it_allocated_size = offset;
2312+
tbl->it_allocated_size = total_allocated;
23122313

23132314
pr_devel("Created TCE table: ws=%08llx ts=%lx @%08llx\n",
23142315
window_size, tce_table_size, bus_offset);

0 commit comments

Comments
 (0)