if (mentry->tag == paddr) {
log_debug("Used map from %lx to %p\n", (ulong)paddr,
mentry->ptr);
+ mentry->refcnt++;
return mentry->ptr;
}
}
mentry = find_tag(ptr);
if (mentry) {
- list_del(&mentry->sibling_node);
- log_debug("Removed map from %p to %lx\n", ptr,
- (ulong)mentry->tag);
- free(mentry);
+ if (!--mentry->refcnt) {
+ list_del(&mentry->sibling_node);
+ log_debug("Removed map from %p to %lx\n", ptr,
+ (ulong)mentry->tag);
+ free(mentry);
+ }
} else {
log_warning("Address not mapped: %p\n", ptr);
}
}
mentry->tag = state->next_tag++;
mentry->ptr = (void *)ptr;
+ mentry->refcnt = 0;
list_add_tail(&mentry->sibling_node, &state->mapmem_head);
log_debug("Added map from %p to %lx\n", ptr,
(ulong)mentry->tag);
}
+ mentry->refcnt++;
+
/*
* Return the tag as the address to use. A later call to map_sysmem()
* will return ptr
* be returned, just as it would for a normal sandbox address.
*
* @tag: Address tag (a value which U-Boot uses to refer to the address)
+ * @refcnt: Number of references to this tag
* @ptr: Associated pointer for that tag
+ * @sibling_node: Next node
*/
struct sandbox_mapmem_entry {
ulong tag;
+ uint refcnt;
void *ptr;
struct list_head sibling_node;
};