aboutsummaryrefslogtreecommitdiff
path: root/include/linux/guest_shm.h
blob: da89b3a7f684a438688b3bfc55862bc9982d0109 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * Copyright 2018, QNX Software Systems Limited (“QSS”).
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Additional Patent Grant
 *
 * QSS hereby grants to you a perpetual, worldwide, non-exclusive,
 * no-charge, irrevocable (except as stated in this section) patent
 * license to make, have made, use, offer to sell, sell, import,
 * transfer, and otherwise run, modify and propagate the contents of this
 * header file (“Implementation”) , where such license applies
 * only to those patent claims, both currently owned by QSS and
 * acquired in the future, licensable by QSS that are necessarily
 * infringed by this Implementation. This grant does
 * not include claims that would be infringed only as a consequence of
 * further modification of this Implementation. If you or your agent or
 * exclusive licensee institute or order or agree to the institution of
 * patent litigation against any entity (including a cross-claim or
 * counterclaim in a lawsuit) alleging that this Implementation constitutes
 * direct or contributory patent infringement, or inducement of patent
 * infringement, then any patent rights granted to you under this license for
 * this Implementation shall terminate as of the date such litigation is filed.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 */

/**
 * @file
 * definitions guest shared memory device
 */

#ifndef _QVM_GUEST_SHM_H
#define _QVM_GUEST_SHM_H

#ifdef __linux__
#include <linux/types.h>
#else
#include <stdint.h>
#endif

/*
 * Temporary VID definition until the updated <pci/pci_id.h> propogates around
 */
#define PCI_VID_BlackBerry_QNX	0x1C05

#define PCI_DID_QNX_GUEST_SHM	0x0001

/** status of last creation request */
enum guest_shm_status {
	GSS_OK,					/**< creation succeeded */
	GSS_UNKNOWN_FAILURE,	/**< creation failed for an unknown reason */
	GSS_NOMEM,				/**< creation failed due to lack of memory */
	GSS_CLIENT_MAX,			/**< creation failed due to region already being used by the maximum number of guests */
	GSS_ILLEGAL_NAME,		/**< creation failed due to illegal region name */
	GSS_NO_PERMISSION,		/**< creation failed due to lack of permission */
	GSS_DOES_NOT_EXIST,		/**< A find request failed */
};

/** Maximum number of clients allowed to connect to a shared memory region */
#define GUEST_SHM_MAX_CLIENTS	16

/** Maximum length allowed for region name */
#define GUEST_SHM_MAX_NAME	32

/** Signature value to verify that vdev is present */
#define GUEST_SHM_SIGNATURE 0x4d534732474d5651


/** Register layout for factory registers */
struct guest_shm_factory {
	uint64_t		signature; /**< == GUEST_SHM_SIGNATURE (R/O) */
	uint64_t		shmem;	/**< shared memory paddr (R/O) */
	uint32_t		vector;	/**< interrupt vector number (R/O) */
	uint32_t		status; /**< status of last creation (R/O) */
	uint32_t		size;	/**< requested size in 4K pages, write causes creation */
	char			name[GUEST_SHM_MAX_NAME];	/**< name of shared memory region */
	uint32_t		find;	/**< find an existing shared memory connection */
};

/** Register layout for a region control page */
struct guest_shm_control {
	uint32_t		status;	/**< lower 16 bits: pending notification bitset, upper 16 bits: current active clients (R/O) */
	uint32_t		idx;	/**< connection index for this client (R/O) */
	uint32_t		notify;	/**< write a bitset of clients to notify */
	uint32_t		detach; /**< write here to detach from the shared memory region */
};


static inline void
guest_shm_create(volatile struct guest_shm_factory *const __factory, unsigned const __size) {
	/* Surround the size assignment with memory barriers so that
	 * the compiler doesn't try to shift the assignment before/after
	 * necessary bits (e.g. setting the name of the region) */
	asm volatile( "" ::: "memory");
	__factory->size = __size;
	asm volatile( "" ::: "memory");
}


static inline void
guest_shm_find(volatile struct guest_shm_factory *const __factory, unsigned const __find_num) {
	/* Surround the find assignment with memory barriers so that
	 * the compiler doesn't try to shift the assignment before/after
	 * necessary bits (e.g. setting the name of the region) */
	asm volatile( "" ::: "memory");
	__factory->find = __find_num;
	asm volatile( "" ::: "memory");
}

#endif

#if defined(__QNXNTO__) && defined(__USESRCVERSION)
#include <sys/srcversion.h>
__SRCVERSION("$URL$ $Rev$")
#endif