32 __get_cached_rbnode(
struct iova_domain *iovad,
unsigned long *limit_pfn)
39 struct iova *curr_iova =
41 *limit_pfn = curr_iova->
pfn_lo - 1;
47 __cached_rbnode_insert_update(
struct iova_domain *iovad,
48 unsigned long limit_pfn,
struct iova *
new)
58 struct iova *cached_iova;
82 iova_get_pad_size(
int size,
unsigned int limit_pfn)
88 pad_size = (limit_pfn + 1) % (1 << order);
93 static int __alloc_and_insert_iova_range(
struct iova_domain *iovad,
94 unsigned long size,
unsigned long limit_pfn,
95 struct iova *
new,
bool size_aligned)
99 unsigned long saved_pfn;
100 unsigned int pad_size = 0;
104 saved_pfn = limit_pfn;
105 curr = __get_cached_rbnode(iovad, &limit_pfn);
110 if (limit_pfn < curr_iova->
pfn_lo)
112 else if (limit_pfn < curr_iova->
pfn_hi)
113 goto adjust_limit_pfn;
116 pad_size = iova_get_pad_size(size, limit_pfn);
117 if ((curr_iova->
pfn_hi + size + pad_size) <= limit_pfn)
121 limit_pfn = curr_iova->
pfn_lo - 1;
129 pad_size = iova_get_pad_size(size, limit_pfn);
137 new->pfn_lo = limit_pfn - (size +
pad_size) + 1;
138 new->pfn_hi =
new->pfn_lo + size - 1;
150 entry = &iovad->
rbroot.rb_node;
158 if (new->pfn_lo < this->pfn_lo)
159 entry = &((*entry)->rb_left);
160 else if (new->pfn_lo > this->pfn_lo)
161 entry = &((*entry)->rb_right);
167 rb_link_node(&new->node, parent, entry);
170 __cached_rbnode_insert_update(iovad, saved_pfn,
new);
187 if (iova->
pfn_lo < this->pfn_lo)
188 new = &((*new)->rb_left);
189 else if (iova->
pfn_lo > this->pfn_lo)
190 new = &((*new)->rb_right);
195 rb_link_node(&iova->
node, parent,
new);
212 unsigned long limit_pfn,
215 struct iova *new_iova;
226 size = __roundup_pow_of_two(size);
228 ret = __alloc_and_insert_iova_range(iovad, size, limit_pfn,
229 new_iova, size_aligned);
253 node = iovad->
rbroot.rb_node;
255 struct iova *iova =
container_of(node,
struct iova, node);
258 if ((pfn >= iova->
pfn_lo) && (pfn <= iova->pfn_hi)) {
269 if (pfn < iova->pfn_lo)
271 else if (pfn > iova->
pfn_lo)
291 __cached_rbnode_delete_update(iovad, iova);
307 struct iova *iova =
find_iova(iovad, pfn);
326 struct iova *iova =
container_of(node,
struct iova, node);
336 unsigned long pfn_lo,
unsigned long pfn_hi)
338 struct iova *iova =
container_of(node,
struct iova, node);
340 if ((pfn_lo <= iova->pfn_hi) && (pfn_hi >= iova->
pfn_lo))
347 unsigned long pfn_lo,
unsigned long pfn_hi)
357 iova_insert_rbtree(&iovad->
rbroot, iova);
362 __adjust_overlap_range(
struct iova *iova,
363 unsigned long *pfn_lo,
unsigned long *pfn_hi)
365 if (*pfn_lo < iova->pfn_lo)
367 if (*pfn_hi > iova->
pfn_hi)
368 *pfn_lo = iova->
pfn_hi + 1;
381 unsigned long pfn_lo,
unsigned long pfn_hi)
386 unsigned int overlap = 0;
390 if (__is_range_overlap(node, pfn_lo, pfn_hi)) {
392 __adjust_overlap_range(iova, &pfn_lo, &pfn_hi);
393 if ((pfn_lo >= iova->
pfn_lo) &&
394 (pfn_hi <= iova->pfn_hi))
405 iova = __insert_new_range(iovad, pfn_lo, pfn_hi);
427 struct iova *iova =
container_of(node,
struct iova, node);
428 struct iova *new_iova;