2018-05-24 13:33:33 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017-2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HW_VIRTIO_VHOST_USER_H
|
|
|
|
#define HW_VIRTIO_VHOST_USER_H
|
|
|
|
|
|
|
|
#include "chardev/char-fe.h"
|
2018-05-24 13:33:34 +03:00
|
|
|
#include "hw/virtio/virtio.h"
|
|
|
|
|
2022-03-21 18:30:37 +03:00
|
|
|
/**
|
|
|
|
* VhostUserHostNotifier - notifier information for one queue
|
|
|
|
* @rcu: rcu_head for cleanup
|
|
|
|
* @mr: memory region of notifier
|
|
|
|
* @addr: current mapped address
|
|
|
|
* @unmap_addr: address to be un-mapped
|
|
|
|
* @idx: virtioqueue index
|
|
|
|
*
|
|
|
|
* The VhostUserHostNotifier entries are re-used. When an old mapping
|
|
|
|
* is to be released it is moved to @unmap_addr and @addr is replaced.
|
|
|
|
* Once the RCU process has completed the unmap @unmap_addr is
|
|
|
|
* cleared.
|
|
|
|
*/
|
2018-05-24 13:33:34 +03:00
|
|
|
typedef struct VhostUserHostNotifier {
|
2022-02-07 10:19:29 +03:00
|
|
|
struct rcu_head rcu;
|
2018-05-24 13:33:34 +03:00
|
|
|
MemoryRegion mr;
|
|
|
|
void *addr;
|
2022-02-07 10:19:29 +03:00
|
|
|
void *unmap_addr;
|
2022-03-21 18:30:37 +03:00
|
|
|
int idx;
|
2018-05-24 13:33:34 +03:00
|
|
|
} VhostUserHostNotifier;
|
2018-05-24 13:33:33 +03:00
|
|
|
|
2022-03-21 18:30:37 +03:00
|
|
|
/**
|
|
|
|
* VhostUserState - shared state for all vhost-user devices
|
|
|
|
* @chr: the character backend for the socket
|
|
|
|
* @notifiers: GPtrArray of @VhostUserHostnotifier
|
|
|
|
* @memory_slots:
|
|
|
|
*/
|
2018-05-24 13:33:33 +03:00
|
|
|
typedef struct VhostUserState {
|
|
|
|
CharBackend *chr;
|
2022-03-21 18:30:37 +03:00
|
|
|
GPtrArray *notifiers;
|
2020-05-21 08:00:32 +03:00
|
|
|
int memory_slots;
|
2022-03-21 18:30:36 +03:00
|
|
|
bool supports_config;
|
2018-05-24 13:33:33 +03:00
|
|
|
} VhostUserState;
|
|
|
|
|
2022-03-21 18:30:37 +03:00
|
|
|
/**
|
|
|
|
* vhost_user_init() - initialise shared vhost_user state
|
|
|
|
* @user: allocated area for storing shared state
|
|
|
|
* @chr: the chardev for the vhost socket
|
|
|
|
* @errp: error handle
|
|
|
|
*
|
|
|
|
* User can either directly g_new() space for the state or embed
|
|
|
|
* VhostUserState in their larger device structure and just point to
|
|
|
|
* it.
|
|
|
|
*
|
|
|
|
* Return: true on success, false on error while setting errp.
|
|
|
|
*/
|
2019-03-08 17:04:45 +03:00
|
|
|
bool vhost_user_init(VhostUserState *user, CharBackend *chr, Error **errp);
|
2022-03-21 18:30:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* vhost_user_cleanup() - cleanup state
|
|
|
|
* @user: ptr to use state
|
|
|
|
*
|
|
|
|
* Cleans up shared state and notifiers, callee is responsible for
|
|
|
|
* freeing the @VhostUserState memory itself.
|
|
|
|
*/
|
2018-05-24 13:33:33 +03:00
|
|
|
void vhost_user_cleanup(VhostUserState *user);
|
|
|
|
|
|
|
|
#endif
|