hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/arch/powerpc/platforms/powernv/pci-ioda-tce.c
....@@ -17,6 +17,34 @@
1717 #include <asm/tce.h>
1818 #include "pci.h"
1919
20
+unsigned long pnv_ioda_parse_tce_sizes(struct pnv_phb *phb)
21
+{
22
+ struct pci_controller *hose = phb->hose;
23
+ struct device_node *dn = hose->dn;
24
+ unsigned long mask = 0;
25
+ int i, rc, count;
26
+ u32 val;
27
+
28
+ count = of_property_count_u32_elems(dn, "ibm,supported-tce-sizes");
29
+ if (count <= 0) {
30
+ mask = SZ_4K | SZ_64K;
31
+ /* Add 16M for POWER8 by default */
32
+ if (cpu_has_feature(CPU_FTR_ARCH_207S) &&
33
+ !cpu_has_feature(CPU_FTR_ARCH_300))
34
+ mask |= SZ_16M | SZ_256M;
35
+ return mask;
36
+ }
37
+
38
+ for (i = 0; i < count; i++) {
39
+ rc = of_property_read_u32_index(dn, "ibm,supported-tce-sizes",
40
+ i, &val);
41
+ if (rc == 0)
42
+ mask |= 1ULL << val;
43
+ }
44
+
45
+ return mask;
46
+}
47
+
2048 void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
2149 void *tce_mem, u64 tce_size,
2250 u64 dma_offset, unsigned int page_shift)
....@@ -138,7 +166,7 @@
138166 if (!ptce) {
139167 ptce = pnv_tce(tbl, false, idx, alloc);
140168 if (!ptce)
141
- return alloc ? H_HARDWARE : H_TOO_HARD;
169
+ return -ENOMEM;
142170 }
143171
144172 if (newtce & TCE_PCI_WRITE)
....@@ -340,14 +368,6 @@
340368 return -ENOMEM;
341369 }
342370
343
-static void pnv_iommu_table_group_link_free(struct rcu_head *head)
344
-{
345
- struct iommu_table_group_link *tgl = container_of(head,
346
- struct iommu_table_group_link, rcu);
347
-
348
- kfree(tgl);
349
-}
350
-
351371 void pnv_pci_unlink_table_and_group(struct iommu_table *tbl,
352372 struct iommu_table_group *table_group)
353373 {
....@@ -363,7 +383,7 @@
363383 list_for_each_entry_rcu(tgl, &tbl->it_group_list, next) {
364384 if (tgl->table_group == table_group) {
365385 list_del_rcu(&tgl->next);
366
- call_rcu(&tgl->rcu, pnv_iommu_table_group_link_free);
386
+ kfree_rcu(tgl, rcu);
367387 found = true;
368388 break;
369389 }
....@@ -375,6 +395,7 @@
375395 found = false;
376396 for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) {
377397 if (table_group->tables[i] == tbl) {
398
+ iommu_tce_table_put(tbl);
378399 table_group->tables[i] = NULL;
379400 found = true;
380401 break;
....@@ -400,7 +421,7 @@
400421 tgl->table_group = table_group;
401422 list_add_rcu(&tgl->next, &tbl->it_group_list);
402423
403
- table_group->tables[num] = tbl;
424
+ table_group->tables[num] = iommu_tce_table_get(tbl);
404425
405426 return 0;
406427 }