Lines Matching +full:group +full:- +full:index +full:- +full:shift
1 // SPDX-License-Identifier: GPL-2.0+
22 struct pci_controller *hose = phb->hose; in pnv_ioda_parse_tce_sizes()
23 struct device_node *dn = hose->dn; in pnv_ioda_parse_tce_sizes()
28 count = of_property_count_u32_elems(dn, "ibm,supported-tce-sizes"); in pnv_ioda_parse_tce_sizes()
39 rc = of_property_read_u32_index(dn, "ibm,supported-tce-sizes", in pnv_ioda_parse_tce_sizes()
52 tbl->it_blocksize = 16; in pnv_pci_setup_iommu_table()
53 tbl->it_base = (unsigned long)tce_mem; in pnv_pci_setup_iommu_table()
54 tbl->it_page_shift = page_shift; in pnv_pci_setup_iommu_table()
55 tbl->it_offset = dma_offset >> tbl->it_page_shift; in pnv_pci_setup_iommu_table()
56 tbl->it_index = 0; in pnv_pci_setup_iommu_table()
57 tbl->it_size = tce_size >> 3; in pnv_pci_setup_iommu_table()
58 tbl->it_busno = 0; in pnv_pci_setup_iommu_table()
59 tbl->it_type = TCE_PCI; in pnv_pci_setup_iommu_table()
62 static __be64 *pnv_alloc_tce_level(int nid, unsigned int shift) in pnv_alloc_tce_level() argument
68 shift - PAGE_SHIFT); in pnv_alloc_tce_level()
70 pr_err("Failed to allocate a TCE memory, level shift=%d\n", in pnv_alloc_tce_level()
71 shift); in pnv_alloc_tce_level()
75 memset(addr, 0, 1UL << shift); in pnv_alloc_tce_level()
85 __be64 *tmp = user ? tbl->it_userspace : (__be64 *) tbl->it_base; in pnv_tce()
86 int level = tbl->it_indirect_levels; in pnv_tce()
87 const long shift = ilog2(tbl->it_level_size); in pnv_tce() local
88 unsigned long mask = (tbl->it_level_size - 1) << (level * shift); in pnv_tce()
91 int n = (idx & mask) >> (level * shift); in pnv_tce()
100 tmp2 = pnv_alloc_tce_level(tbl->it_nid, in pnv_tce()
101 ilog2(tbl->it_level_size) + 3); in pnv_tce()
110 ilog2(tbl->it_level_size) + 3, 1); in pnv_tce()
117 mask >>= shift; in pnv_tce()
118 --level; in pnv_tce()
124 int pnv_tce_build(struct iommu_table *tbl, long index, long npages, in pnv_tce_build() argument
129 u64 rpn = __pa(uaddr) >> tbl->it_page_shift; in pnv_tce_build()
137 ((rpn + i) << tbl->it_page_shift); in pnv_tce_build()
138 unsigned long idx = index - tbl->it_offset + i; in pnv_tce_build()
147 int pnv_tce_xchg(struct iommu_table *tbl, long index, in pnv_tce_xchg() argument
152 unsigned long idx = index - tbl->it_offset; in pnv_tce_xchg()
168 return -ENOMEM; in pnv_tce_xchg()
181 __be64 *pnv_tce_useraddrptr(struct iommu_table *tbl, long index, bool alloc) in pnv_tce_useraddrptr() argument
183 if (WARN_ON_ONCE(!tbl->it_userspace)) in pnv_tce_useraddrptr()
186 return pnv_tce(tbl, true, index - tbl->it_offset, alloc); in pnv_tce_useraddrptr()
190 void pnv_tce_free(struct iommu_table *tbl, long index, long npages) in pnv_tce_free() argument
195 unsigned long idx = index - tbl->it_offset + i; in pnv_tce_free()
202 i |= tbl->it_level_size - 1; in pnv_tce_free()
206 unsigned long pnv_tce_get(struct iommu_table *tbl, long index) in pnv_tce_get() argument
208 __be64 *ptce = pnv_tce(tbl, false, index - tbl->it_offset, false); in pnv_tce_get()
233 levels - 1); in pnv_pci_ioda2_table_do_free_pages()
242 const unsigned long size = tbl->it_indirect_levels ? in pnv_pci_ioda2_table_free_pages()
243 tbl->it_level_size : tbl->it_size; in pnv_pci_ioda2_table_free_pages()
245 if (!tbl->it_size) in pnv_pci_ioda2_table_free_pages()
248 pnv_pci_ioda2_table_do_free_pages((__be64 *)tbl->it_base, size, in pnv_pci_ioda2_table_free_pages()
249 tbl->it_indirect_levels); in pnv_pci_ioda2_table_free_pages()
250 if (tbl->it_userspace) { in pnv_pci_ioda2_table_free_pages()
251 pnv_pci_ioda2_table_do_free_pages(tbl->it_userspace, size, in pnv_pci_ioda2_table_free_pages()
252 tbl->it_indirect_levels); in pnv_pci_ioda2_table_free_pages()
256 static __be64 *pnv_pci_ioda2_table_do_alloc_pages(int nid, unsigned int shift, in pnv_pci_ioda2_table_do_alloc_pages() argument
261 unsigned long allocated = 1UL << shift; in pnv_pci_ioda2_table_do_alloc_pages()
262 unsigned int entries = 1UL << (shift - 3); in pnv_pci_ioda2_table_do_alloc_pages()
265 addr = pnv_alloc_tce_level(nid, shift); in pnv_pci_ioda2_table_do_alloc_pages()
268 --levels; in pnv_pci_ioda2_table_do_alloc_pages()
275 tmp = pnv_pci_ioda2_table_do_alloc_pages(nid, shift, in pnv_pci_ioda2_table_do_alloc_pages()
298 unsigned int entries_shift = window_shift - page_shift; in pnv_pci_ioda2_table_alloc_pages()
304 return -EINVAL; in pnv_pci_ioda2_table_alloc_pages()
307 return -EINVAL; in pnv_pci_ioda2_table_alloc_pages()
310 entries_shift = (entries_shift + levels - 1) / levels; in pnv_pci_ioda2_table_alloc_pages()
314 if ((level_shift - 3) * levels + page_shift >= 55) in pnv_pci_ioda2_table_alloc_pages()
315 return -EINVAL; in pnv_pci_ioda2_table_alloc_pages()
323 return -ENOMEM; in pnv_pci_ioda2_table_alloc_pages()
349 tbl->it_level_size = 1ULL << (level_shift - 3); in pnv_pci_ioda2_table_alloc_pages()
350 tbl->it_indirect_levels = levels - 1; in pnv_pci_ioda2_table_alloc_pages()
351 tbl->it_userspace = uas; in pnv_pci_ioda2_table_alloc_pages()
352 tbl->it_nid = nid; in pnv_pci_ioda2_table_alloc_pages()
355 window_size, tce_table_size, bus_offset, tbl->it_base, in pnv_pci_ioda2_table_alloc_pages()
356 tbl->it_userspace, 1, levels); in pnv_pci_ioda2_table_alloc_pages()
362 1ULL << (level_shift - 3), levels - 1); in pnv_pci_ioda2_table_alloc_pages()
365 1ULL << (level_shift - 3), levels - 1); in pnv_pci_ioda2_table_alloc_pages()
367 return -ENOMEM; in pnv_pci_ioda2_table_alloc_pages()
380 /* Remove link to a group from table's list of attached groups */ in pnv_pci_unlink_table_and_group()
384 list_for_each_entry_rcu(tgl, &tbl->it_group_list, next) { in pnv_pci_unlink_table_and_group()
385 if (tgl->table_group == table_group) { in pnv_pci_unlink_table_and_group()
386 list_del_rcu(&tgl->next); in pnv_pci_unlink_table_and_group()
400 if (table_group->tables[i] == tbl) { in pnv_pci_unlink_table_and_group()
402 table_group->tables[i] = NULL; in pnv_pci_unlink_table_and_group()
417 return -EINVAL; in pnv_pci_link_table_and_group()
422 return -ENOMEM; in pnv_pci_link_table_and_group()
424 tgl->table_group = table_group; in pnv_pci_link_table_and_group()
425 list_add_rcu(&tgl->next, &tbl->it_group_list); in pnv_pci_link_table_and_group()
427 table_group->tables[num] = iommu_tce_table_get(tbl); in pnv_pci_link_table_and_group()