Lines Matching refs:mem
78 struct mm_iommu_table_group_mem_t *mem; in mm_iommu_get() local
87 list_for_each_entry_rcu(mem, ¤t->mm->context.iommu_group_mem_list, in mm_iommu_get()
89 if ((mem->ua == ua) && (mem->entries == entries)) { in mm_iommu_get()
90 ++mem->used; in mm_iommu_get()
91 *pmem = mem; in mm_iommu_get()
96 if ((mem->ua < (ua + (entries << PAGE_SHIFT))) && in mm_iommu_get()
97 (ua < (mem->ua + in mm_iommu_get()
98 (mem->entries << PAGE_SHIFT)))) { in mm_iommu_get()
111 mem = kzalloc(sizeof(*mem), GFP_KERNEL); in mm_iommu_get()
112 if (!mem) { in mm_iommu_get()
117 mem->hpas = vzalloc(entries * sizeof(mem->hpas[0])); in mm_iommu_get()
118 if (!mem->hpas) { in mm_iommu_get()
119 kfree(mem); in mm_iommu_get()
129 mem->hpas[j] >> PAGE_SHIFT)); in mm_iommu_get()
130 vfree(mem->hpas); in mm_iommu_get()
131 kfree(mem); in mm_iommu_get()
136 mem->hpas[i] = page_to_pfn(page) << PAGE_SHIFT; in mm_iommu_get()
139 atomic64_set(&mem->mapped, 1); in mm_iommu_get()
140 mem->used = 1; in mm_iommu_get()
141 mem->ua = ua; in mm_iommu_get()
142 mem->entries = entries; in mm_iommu_get()
143 *pmem = mem; in mm_iommu_get()
145 list_add_rcu(&mem->next, ¤t->mm->context.iommu_group_mem_list); in mm_iommu_get()
157 static void mm_iommu_unpin(struct mm_iommu_table_group_mem_t *mem) in mm_iommu_unpin() argument
162 for (i = 0; i < mem->entries; ++i) { in mm_iommu_unpin()
163 if (!mem->hpas[i]) in mm_iommu_unpin()
166 page = pfn_to_page(mem->hpas[i] >> PAGE_SHIFT); in mm_iommu_unpin()
171 mem->hpas[i] = 0; in mm_iommu_unpin()
175 static void mm_iommu_do_free(struct mm_iommu_table_group_mem_t *mem) in mm_iommu_do_free() argument
178 mm_iommu_unpin(mem); in mm_iommu_do_free()
179 vfree(mem->hpas); in mm_iommu_do_free()
180 kfree(mem); in mm_iommu_do_free()
185 struct mm_iommu_table_group_mem_t *mem = container_of(head, in mm_iommu_free() local
188 mm_iommu_do_free(mem); in mm_iommu_free()
191 static void mm_iommu_release(struct mm_iommu_table_group_mem_t *mem) in mm_iommu_release() argument
193 list_del_rcu(&mem->next); in mm_iommu_release()
194 mm_iommu_adjust_locked_vm(current->mm, mem->entries, false); in mm_iommu_release()
195 call_rcu(&mem->rcu, mm_iommu_free); in mm_iommu_release()
198 long mm_iommu_put(struct mm_iommu_table_group_mem_t *mem) in mm_iommu_put() argument
207 if (mem->used == 0) { in mm_iommu_put()
212 --mem->used; in mm_iommu_put()
214 if (mem->used) in mm_iommu_put()
218 if (atomic_cmpxchg(&mem->mapped, 1, 0) != 1) { in mm_iommu_put()
219 ++mem->used; in mm_iommu_put()
225 mm_iommu_release(mem); in mm_iommu_put()
237 struct mm_iommu_table_group_mem_t *mem, *ret = NULL; in mm_iommu_lookup() local
239 list_for_each_entry_rcu(mem, in mm_iommu_lookup()
242 if ((mem->ua <= ua) && in mm_iommu_lookup()
243 (ua + size <= mem->ua + in mm_iommu_lookup()
244 (mem->entries << PAGE_SHIFT))) { in mm_iommu_lookup()
245 ret = mem; in mm_iommu_lookup()
257 struct mm_iommu_table_group_mem_t *mem, *ret = NULL; in mm_iommu_find() local
259 list_for_each_entry_rcu(mem, in mm_iommu_find()
262 if ((mem->ua == ua) && (mem->entries == entries)) { in mm_iommu_find()
263 ret = mem; in mm_iommu_find()
272 long mm_iommu_ua_to_hpa(struct mm_iommu_table_group_mem_t *mem, in mm_iommu_ua_to_hpa() argument
275 const long entry = (ua - mem->ua) >> PAGE_SHIFT; in mm_iommu_ua_to_hpa()
276 u64 *va = &mem->hpas[entry]; in mm_iommu_ua_to_hpa()
278 if (entry >= mem->entries) in mm_iommu_ua_to_hpa()
287 long mm_iommu_mapped_inc(struct mm_iommu_table_group_mem_t *mem) in mm_iommu_mapped_inc() argument
289 if (atomic64_inc_not_zero(&mem->mapped)) in mm_iommu_mapped_inc()
297 void mm_iommu_mapped_dec(struct mm_iommu_table_group_mem_t *mem) in mm_iommu_mapped_dec() argument
299 atomic64_add_unless(&mem->mapped, -1, 1); in mm_iommu_mapped_dec()
310 struct mm_iommu_table_group_mem_t *mem, *tmp; in mm_iommu_cleanup() local
312 list_for_each_entry_safe(mem, tmp, &ctx->iommu_group_mem_list, next) { in mm_iommu_cleanup()
313 list_del_rcu(&mem->next); in mm_iommu_cleanup()
314 mm_iommu_do_free(mem); in mm_iommu_cleanup()