2026-03-12 20:39:28 +00:00
|
|
|
#ifndef KERNEL_VM_CONTROLLER_H_
|
|
|
|
|
#define KERNEL_VM_CONTROLLER_H_
|
|
|
|
|
|
|
|
|
|
#include <kernel/locks.h>
|
|
|
|
|
#include <kernel/object.h>
|
|
|
|
|
#include <mango/types.h>
|
|
|
|
|
|
|
|
|
|
struct thread;
|
|
|
|
|
struct equeue;
|
|
|
|
|
struct vm_object;
|
|
|
|
|
|
|
|
|
|
enum page_request_status {
|
|
|
|
|
PAGE_REQUEST_PENDING = 0,
|
|
|
|
|
PAGE_REQUEST_IN_PROGRESS,
|
|
|
|
|
PAGE_REQUEST_COMPLETE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct vm_controller {
|
|
|
|
|
struct object vc_base;
|
|
|
|
|
/* tree of struct vm_objects bound to this controller, keyed with the
|
2026-03-14 22:39:14 +00:00
|
|
|
* equeue_key_t specified when the object(s) were created. */
|
2026-03-12 20:39:28 +00:00
|
|
|
struct btree vc_objects;
|
|
|
|
|
/* tree of pending page requests */
|
|
|
|
|
struct btree vc_requests;
|
2026-03-14 22:39:14 +00:00
|
|
|
/* the equeue to send async page requests to */
|
|
|
|
|
struct equeue *vc_eq;
|
|
|
|
|
equeue_key_t vc_eq_key;
|
|
|
|
|
/* the number of page requests queued with status PAGE_REQUEST_PENDING.
|
|
|
|
|
* used to assert/clear VM_CONTROLLER_SIGNAL_REQUEST_RECEIVED */
|
|
|
|
|
size_t vc_requests_waiting;
|
2026-03-12 20:39:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct page_request {
|
|
|
|
|
uint64_t req_id;
|
2026-03-14 22:39:14 +00:00
|
|
|
unsigned int req_type;
|
2026-03-12 20:39:28 +00:00
|
|
|
enum page_request_status req_status;
|
|
|
|
|
kern_status_t req_result;
|
2026-03-14 22:39:14 +00:00
|
|
|
spin_lock_t req_lock;
|
2026-03-12 20:39:28 +00:00
|
|
|
struct vm_object *req_object;
|
|
|
|
|
struct thread *req_sender;
|
|
|
|
|
struct btree_node req_node;
|
|
|
|
|
off_t req_offset;
|
|
|
|
|
size_t req_length;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern kern_status_t vm_controller_type_init(void);
|
|
|
|
|
extern struct vm_controller *vm_controller_cast(struct object *obj);
|
|
|
|
|
|
|
|
|
|
extern struct vm_controller *vm_controller_create(void);
|
|
|
|
|
|
|
|
|
|
extern kern_status_t vm_controller_recv(
|
|
|
|
|
struct vm_controller *ctrl,
|
|
|
|
|
equeue_packet_page_request_t *out);
|
|
|
|
|
extern kern_status_t vm_controller_recv_async(
|
|
|
|
|
struct vm_controller *ctrl,
|
2026-03-14 22:39:14 +00:00
|
|
|
struct equeue *eq,
|
|
|
|
|
equeue_key_t key);
|
2026-03-12 20:39:28 +00:00
|
|
|
|
|
|
|
|
extern kern_status_t vm_controller_create_object(
|
|
|
|
|
struct vm_controller *ctrl,
|
|
|
|
|
const char *name,
|
|
|
|
|
size_t name_len,
|
|
|
|
|
equeue_key_t key,
|
|
|
|
|
size_t data_len,
|
|
|
|
|
vm_prot_t prot,
|
|
|
|
|
struct vm_object **out);
|
|
|
|
|
extern kern_status_t vm_controller_detach_object(
|
|
|
|
|
struct vm_controller *ctrl,
|
|
|
|
|
struct vm_object *vmo);
|
2026-03-14 22:39:14 +00:00
|
|
|
extern kern_status_t vm_controller_supply_pages(
|
|
|
|
|
struct vm_controller *ctrl,
|
|
|
|
|
struct vm_object *dst,
|
|
|
|
|
off_t dst_offset,
|
|
|
|
|
struct vm_object *src,
|
|
|
|
|
off_t src_offset,
|
|
|
|
|
size_t count);
|
2026-03-12 20:39:28 +00:00
|
|
|
|
|
|
|
|
extern kern_status_t vm_controller_send_request(
|
|
|
|
|
struct vm_controller *ctrl,
|
2026-03-14 22:39:14 +00:00
|
|
|
struct page_request *req,
|
|
|
|
|
unsigned long *irq_flags);
|
2026-03-12 20:39:28 +00:00
|
|
|
|
|
|
|
|
DEFINE_OBJECT_LOCK_FUNCTION(vm_controller, vc_base)
|
|
|
|
|
|
|
|
|
|
#endif
|