Skip to content

Commit 5faa04c

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu/amd: Use roundup_pow_two() instead of get_order()
If x >= PAGE_SIZE then: 1 << (get_order(x) + PAGE_SHIFT) == roundup_pow_two() Inline this into the only caller, compute the size of the HW device table in terms of 4K pages which matches the HW definition. Tested-by: Alejandro Jimenez <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent e874c66 commit 5faa04c

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

drivers/iommu/amd/init.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,6 @@ static void init_translation_status(struct amd_iommu *iommu)
243243
iommu->flags |= AMD_IOMMU_FLAG_TRANS_PRE_ENABLED;
244244
}
245245

246-
static inline unsigned long tbl_size(int entry_size, int last_bdf)
247-
{
248-
unsigned shift = PAGE_SHIFT +
249-
get_order((last_bdf + 1) * entry_size);
250-
251-
return 1UL << shift;
252-
}
253-
254246
int amd_iommu_get_num_iommus(void)
255247
{
256248
return amd_iommus_present;
@@ -1595,7 +1587,9 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id,
15951587

15961588
pci_seg->last_bdf = last_bdf;
15971589
DUMP_printk("PCI segment : 0x%0x, last bdf : 0x%04x\n", id, last_bdf);
1598-
pci_seg->dev_table_size = tbl_size(DEV_TABLE_ENTRY_SIZE, last_bdf);
1590+
pci_seg->dev_table_size =
1591+
max(roundup_pow_of_two((last_bdf + 1) * DEV_TABLE_ENTRY_SIZE),
1592+
SZ_4K);
15991593

16001594
pci_seg->id = id;
16011595
init_llist_head(&pci_seg->dev_data_list);

0 commit comments

Comments
 (0)