+int drv_bo_munmap(struct bo *bo, struct vma *vma)
+{
+ return munmap(vma->addr, vma->length);
+}
+
+int drv_mapping_destroy(struct bo *bo)
+{
+ int ret;
+ size_t plane;
+ struct mapping *mapping;
+ uint32_t idx;
+
+ /*
+ * This function is called right before the buffer is destroyed. It will free any mappings
+ * associated with the buffer.
+ */
+
+ idx = 0;
+ for (plane = 0; plane < bo->num_planes; plane++) {
+ while (idx < drv_array_size(bo->drv->mappings)) {
+ mapping = (struct mapping *)drv_array_at_idx(bo->drv->mappings, idx);
+ if (mapping->vma->handle != bo->handles[plane].u32) {
+ idx++;
+ continue;
+ }
+
+ if (!--mapping->vma->refcount) {
+ ret = bo->drv->backend->bo_unmap(bo, mapping->vma);
+ if (ret) {
+ drv_log("munmap failed\n");
+ return ret;
+ }
+
+ free(mapping->vma);
+ }
+
+ /* This shrinks and shifts the array, so don't increment idx. */
+ drv_array_remove(bo->drv->mappings, idx);
+ }
+ }
+
+ return 0;
+}
+
+int drv_get_prot(uint32_t map_flags)
+{
+ return (BO_MAP_WRITE & map_flags) ? PROT_WRITE | PROT_READ : PROT_READ;
+}
+