+ void *addr = mmap(0, bo->total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd,
+ gem_map.offset);
+
+ vma->length = bo->total_size;
+
+ if (bo->use_flags & BO_USE_RENDERSCRIPT) {
+ priv = calloc(1, sizeof(*priv));
+ priv->cached_addr = calloc(1, bo->total_size);
+ priv->gem_addr = addr;
+ vma->priv = priv;
+ addr = priv->cached_addr;
+ }
+
+ return addr;
+}
+
+static int mediatek_bo_unmap(struct bo *bo, struct vma *vma)
+{
+ if (vma->priv) {
+ struct mediatek_private_map_data *priv = vma->priv;
+ vma->addr = priv->gem_addr;
+ free(priv->cached_addr);
+ free(priv);
+ vma->priv = NULL;
+ }
+
+ return munmap(vma->addr, vma->length);
+}
+
+static int mediatek_bo_invalidate(struct bo *bo, struct mapping *mapping)
+{
+ if (mapping->vma->priv) {
+ struct mediatek_private_map_data *priv = mapping->vma->priv;
+ memcpy(priv->cached_addr, priv->gem_addr, bo->total_size);
+ }
+
+ return 0;
+}
+
+static int mediatek_bo_flush(struct bo *bo, struct mapping *mapping)
+{
+ struct mediatek_private_map_data *priv = mapping->vma->priv;
+ if (priv && (mapping->vma->map_flags & BO_MAP_WRITE))
+ memcpy(priv->gem_addr, priv->cached_addr, bo->total_size);