vm_mgr.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef _GH_VM_MGR_H
  6. #define _GH_VM_MGR_H
  7. #include <linux/gunyah_rsc_mgr.h>
  8. #include <linux/gunyah_vm_mgr.h>
  9. #include <linux/list.h>
  10. #include <linux/kref.h>
  11. #include <linux/miscdevice.h>
  12. #include <linux/mutex.h>
  13. #include <linux/rwsem.h>
  14. #include <linux/wait.h>
  15. #include <uapi/linux/gunyah.h>
  16. long gh_dev_vm_mgr_ioctl(struct gh_rm *rm, unsigned int cmd, unsigned long arg);
  17. enum gh_vm_mem_share_type {
  18. VM_MEM_SHARE,
  19. VM_MEM_LEND,
  20. };
  21. struct gh_vm_mem {
  22. struct list_head list;
  23. enum gh_vm_mem_share_type share_type;
  24. struct gh_rm_mem_parcel parcel;
  25. __u64 guest_phys_addr;
  26. struct page **pages;
  27. unsigned long npages;
  28. };
  29. struct gh_vm {
  30. u16 vmid;
  31. struct gh_rm *rm;
  32. struct device *parent;
  33. enum gh_rm_vm_auth_mechanism auth;
  34. struct gh_vm_dtb_config dtb_config;
  35. struct gh_vm_firmware_config fw_config;
  36. struct notifier_block nb;
  37. enum gh_rm_vm_status vm_status;
  38. wait_queue_head_t vm_status_wait;
  39. struct rw_semaphore status_lock;
  40. struct gh_vm_exit_info exit_info;
  41. struct work_struct free_work;
  42. struct kref kref;
  43. struct mm_struct *mm; /* userspace tied to this vm */
  44. struct mutex mm_lock;
  45. struct list_head memory_mappings;
  46. struct mutex fn_lock;
  47. struct list_head functions;
  48. struct mutex resources_lock;
  49. struct list_head resources;
  50. struct list_head resource_tickets;
  51. struct rb_root mmio_handler_root;
  52. struct rw_semaphore mmio_handler_lock;
  53. };
  54. int gh_vm_mem_alloc(struct gh_vm *ghvm, struct gh_userspace_memory_region *region, bool lend);
  55. void gh_vm_mem_reclaim(struct gh_vm *ghvm);
  56. struct gh_vm_mem *gh_vm_mem_find_by_addr(struct gh_vm *ghvm, u64 guest_phys_addr, u32 size);
  57. int gh_vm_mmio_write(struct gh_vm *ghvm, u64 addr, u32 len, u64 data);
  58. #endif