Lines Matching full:region

155     VFIORegion *region = opaque;  in vfio_region_write()  local
156 VFIODevice *vbasedev = region->vbasedev; in vfio_region_write()
182 if (pwrite(vbasedev->fd, &buf, size, region->fd_offset + addr) != size) { in vfio_region_write()
183 error_report("%s(%s:region%d+0x%"HWADDR_PRIx", 0x%"PRIx64 in vfio_region_write()
185 __func__, vbasedev->name, region->nr, in vfio_region_write()
189 trace_vfio_region_write(vbasedev->name, region->nr, addr, data, size); in vfio_region_write()
205 VFIORegion *region = opaque; in vfio_region_read() local
206 VFIODevice *vbasedev = region->vbasedev; in vfio_region_read()
215 if (pread(vbasedev->fd, &buf, size, region->fd_offset + addr) != size) { in vfio_region_read()
216 error_report("%s(%s:region%d+0x%"HWADDR_PRIx", %d) failed: %m", in vfio_region_read()
217 __func__, vbasedev->name, region->nr, in vfio_region_read()
239 trace_vfio_region_read(vbasedev->name, region->nr, addr, size, data); in vfio_region_read()
308 static int vfio_setup_region_sparse_mmaps(VFIORegion *region, in vfio_setup_region_sparse_mmaps() argument
322 trace_vfio_region_sparse_mmap_header(region->vbasedev->name, in vfio_setup_region_sparse_mmaps()
323 region->nr, sparse->nr_areas); in vfio_setup_region_sparse_mmaps()
325 region->mmaps = g_new0(VFIOMmap, sparse->nr_areas); in vfio_setup_region_sparse_mmaps()
332 region->mmaps[j].offset = sparse->areas[i].offset; in vfio_setup_region_sparse_mmaps()
333 region->mmaps[j].size = sparse->areas[i].size; in vfio_setup_region_sparse_mmaps()
338 region->nr_mmaps = j; in vfio_setup_region_sparse_mmaps()
339 region->mmaps = g_realloc(region->mmaps, j * sizeof(VFIOMmap)); in vfio_setup_region_sparse_mmaps()
344 int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *region, in vfio_region_setup() argument
355 region->vbasedev = vbasedev; in vfio_region_setup()
356 region->flags = info->flags; in vfio_region_setup()
357 region->size = info->size; in vfio_region_setup()
358 region->fd_offset = info->offset; in vfio_region_setup()
359 region->nr = index; in vfio_region_setup()
361 if (region->size) { in vfio_region_setup()
362 region->mem = g_new0(MemoryRegion, 1); in vfio_region_setup()
363 memory_region_init_io(region->mem, obj, &vfio_region_ops, in vfio_region_setup()
364 region, name, region->size); in vfio_region_setup()
367 region->flags & VFIO_REGION_INFO_FLAG_MMAP) { in vfio_region_setup()
369 ret = vfio_setup_region_sparse_mmaps(region, info); in vfio_region_setup()
372 region->nr_mmaps = 1; in vfio_region_setup()
373 region->mmaps = g_new0(VFIOMmap, region->nr_mmaps); in vfio_region_setup()
374 region->mmaps[0].offset = 0; in vfio_region_setup()
375 region->mmaps[0].size = region->size; in vfio_region_setup()
381 region->flags, region->fd_offset, region->size); in vfio_region_setup()
385 static void vfio_subregion_unmap(VFIORegion *region, int index) in vfio_subregion_unmap() argument
387 trace_vfio_region_unmap(memory_region_name(&region->mmaps[index].mem), in vfio_subregion_unmap()
388 region->mmaps[index].offset, in vfio_subregion_unmap()
389 region->mmaps[index].offset + in vfio_subregion_unmap()
390 region->mmaps[index].size - 1); in vfio_subregion_unmap()
391 memory_region_del_subregion(region->mem, &region->mmaps[index].mem); in vfio_subregion_unmap()
392 munmap(region->mmaps[index].mmap, region->mmaps[index].size); in vfio_subregion_unmap()
393 object_unparent(OBJECT(&region->mmaps[index].mem)); in vfio_subregion_unmap()
394 region->mmaps[index].mmap = NULL; in vfio_subregion_unmap()
397 int vfio_region_mmap(VFIORegion *region) in vfio_region_mmap() argument
402 if (!region->mem) { in vfio_region_mmap()
406 prot |= region->flags & VFIO_REGION_INFO_FLAG_READ ? PROT_READ : 0; in vfio_region_mmap()
407 prot |= region->flags & VFIO_REGION_INFO_FLAG_WRITE ? PROT_WRITE : 0; in vfio_region_mmap()
409 for (i = 0; i < region->nr_mmaps; i++) { in vfio_region_mmap()
410 size_t align = MIN(1ULL << ctz64(region->mmaps[i].size), 1 * GiB); in vfio_region_mmap()
421 * the region size here can exceed host memory, therefore we manually in vfio_region_mmap()
424 map_base = mmap(0, region->mmaps[i].size + align, PROT_NONE, in vfio_region_mmap()
433 munmap(map_align + region->mmaps[i].size, in vfio_region_mmap()
436 region->mmaps[i].mmap = mmap(map_align, region->mmaps[i].size, prot, in vfio_region_mmap()
438 region->vbasedev->fd, in vfio_region_mmap()
439 region->fd_offset + in vfio_region_mmap()
440 region->mmaps[i].offset); in vfio_region_mmap()
441 if (region->mmaps[i].mmap == MAP_FAILED) { in vfio_region_mmap()
447 memory_region_name(region->mem), i); in vfio_region_mmap()
448 memory_region_init_ram_device_ptr(&region->mmaps[i].mem, in vfio_region_mmap()
449 memory_region_owner(region->mem), in vfio_region_mmap()
450 name, region->mmaps[i].size, in vfio_region_mmap()
451 region->mmaps[i].mmap); in vfio_region_mmap()
453 memory_region_add_subregion(region->mem, region->mmaps[i].offset, in vfio_region_mmap()
454 &region->mmaps[i].mem); in vfio_region_mmap()
456 trace_vfio_region_mmap(memory_region_name(&region->mmaps[i].mem), in vfio_region_mmap()
457 region->mmaps[i].offset, in vfio_region_mmap()
458 region->mmaps[i].offset + in vfio_region_mmap()
459 region->mmaps[i].size - 1); in vfio_region_mmap()
465 trace_vfio_region_mmap_fault(memory_region_name(region->mem), i, in vfio_region_mmap()
466 region->fd_offset + region->mmaps[i].offset, in vfio_region_mmap()
467 region->fd_offset + region->mmaps[i].offset + in vfio_region_mmap()
468 region->mmaps[i].size - 1, ret); in vfio_region_mmap()
470 region->mmaps[i].mmap = NULL; in vfio_region_mmap()
473 vfio_subregion_unmap(region, i); in vfio_region_mmap()
479 void vfio_region_unmap(VFIORegion *region) in vfio_region_unmap() argument
483 if (!region->mem) { in vfio_region_unmap()
487 for (i = 0; i < region->nr_mmaps; i++) { in vfio_region_unmap()
488 if (region->mmaps[i].mmap) { in vfio_region_unmap()
489 vfio_subregion_unmap(region, i); in vfio_region_unmap()
494 void vfio_region_exit(VFIORegion *region) in vfio_region_exit() argument
498 if (!region->mem) { in vfio_region_exit()
502 for (i = 0; i < region->nr_mmaps; i++) { in vfio_region_exit()
503 if (region->mmaps[i].mmap) { in vfio_region_exit()
504 memory_region_del_subregion(region->mem, &region->mmaps[i].mem); in vfio_region_exit()
508 trace_vfio_region_exit(region->vbasedev->name, region->nr); in vfio_region_exit()
511 void vfio_region_finalize(VFIORegion *region) in vfio_region_finalize() argument
515 if (!region->mem) { in vfio_region_finalize()
519 for (i = 0; i < region->nr_mmaps; i++) { in vfio_region_finalize()
520 if (region->mmaps[i].mmap) { in vfio_region_finalize()
521 munmap(region->mmaps[i].mmap, region->mmaps[i].size); in vfio_region_finalize()
522 object_unparent(OBJECT(&region->mmaps[i].mem)); in vfio_region_finalize()
526 object_unparent(OBJECT(region->mem)); in vfio_region_finalize()
528 g_free(region->mem); in vfio_region_finalize()
529 g_free(region->mmaps); in vfio_region_finalize()
531 trace_vfio_region_finalize(region->vbasedev->name, region->nr); in vfio_region_finalize()
533 region->mem = NULL; in vfio_region_finalize()
534 region->mmaps = NULL; in vfio_region_finalize()
535 region->nr_mmaps = 0; in vfio_region_finalize()
536 region->size = 0; in vfio_region_finalize()
537 region->flags = 0; in vfio_region_finalize()
538 region->nr = 0; in vfio_region_finalize()
541 void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled) in vfio_region_mmaps_set_enabled() argument
545 if (!region->mem) { in vfio_region_mmaps_set_enabled()
549 for (i = 0; i < region->nr_mmaps; i++) { in vfio_region_mmaps_set_enabled()
550 if (region->mmaps[i].mmap) { in vfio_region_mmaps_set_enabled()
551 memory_region_set_enabled(&region->mmaps[i].mem, enabled); in vfio_region_mmaps_set_enabled()
555 trace_vfio_region_mmaps_set_enabled(memory_region_name(region->mem), in vfio_region_mmaps_set_enabled()
621 bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type) in vfio_has_region_cap() argument
626 if (!vfio_get_region_info(vbasedev, region, &info)) { in vfio_has_region_cap()