blob: 2deb80bdc9f9d5800316c92b5e4af4f3c77ff79e (
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*/
#ifndef _MEM_BUF_H
#define _MEM_BUF_H
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/haven/hh_rm_drv.h>
#include <linux/types.h>
#include <uapi/linux/mem-buf.h>
/**
* Private definitions; they are just here since the tracepoint logic needs
* these definitions. Drivers should not use these.
*/
/**
* enum mem_buf_msg_type: Message types used by the membuf driver for
* communication.
* @MEM_BUF_ALLOC_REQ: The message is an allocation request from another VM to
* the receiving VM
* @MEM_BUF_ALLOC_RESP: The message is a response from a remote VM to an
* allocation request issued by the receiving VM
* @MEM_BUF_ALLOC_RELINQUISH: The message is a notification from another VM
* that the receiving VM can reclaim the memory.
*/
enum mem_buf_msg_type {
MEM_BUF_ALLOC_REQ,
MEM_BUF_ALLOC_RESP,
MEM_BUF_ALLOC_RELINQUISH,
MEM_BUF_ALLOC_REQ_MAX,
};
/**
* struct mem_buf_msg_hdr: The header for all membuf messages
* @txn_id: The transaction ID for the message. This field is only meaningful
* for request/response type of messages.
* @msg_type: The type of message.
*/
struct mem_buf_msg_hdr {
u32 txn_id;
u32 msg_type;
} __packed;
/**
* struct mem_buf_alloc_req: The message format for a memory allocation request
* to another VM.
* @hdr: Message header
* @size: The size of the memory allocation to be performed on the remote VM.
* @src_mem_type: The type of memory that the remote VM should allocate.
* @acl_desc: A HH ACL descriptor that describes the VMIDs that will be
* accessing the memory, as well as what permissions each VMID will have.
*
* NOTE: Certain memory types require additional information for the remote VM
* to interpret. That information should be concatenated with this structure
* prior to sending the allocation request to the remote VM. For example,
* with memory type ION, the allocation request message will consist of this
* structure, as well as the mem_buf_ion_alloc_data structure.
*/
struct mem_buf_alloc_req {
struct mem_buf_msg_hdr hdr;
u64 size;
u32 src_mem_type;
struct hh_acl_desc acl_desc;
} __packed;
/**
* struct mem_buf_ion_alloc_data: Represents the data needed to perform
* an ION allocation on a remote VM.
* @heap_id: The ID of the heap to allocate from
*/
struct mem_buf_ion_alloc_data {
u32 heap_id;
} __packed;
/**
* struct mem_buf_alloc_resp: The message format for a memory allocation
* request response.
* @hdr: Message header
* @ret: Return code from remote VM
* @hdl: The memparcel handle associated with the memory allocated to the
* receiving VM. This field is only meaningful if the allocation on the remote
* VM was carried out successfully, as denoted by @ret.
*/
struct mem_buf_alloc_resp {
struct mem_buf_msg_hdr hdr;
s32 ret;
u32 hdl;
} __packed;
/**
* struct mem_buf_alloc_relinquish: The message format for a notification
* that the current VM has relinquished access to the memory lent to it by
* another VM.
* @hdr: Message header
* @hdl: The memparcel handle associated with the memory.
*/
struct mem_buf_alloc_relinquish {
struct mem_buf_msg_hdr hdr;
u32 hdl;
} __packed;
/* Public definitions */
/**
* struct mem_buf_allocation_data - Data structure that contains information
* about a memory buffer allocation request.
* @size: The size (in bytes) of the memory to be requested from a remote VM
* @nr_acl_entries: The number of ACL entries in @acl_list
* @acl_list: A list of VMID and permission pairs that describe what VMIDs will
* have access to the memory, and with what permissions
* @src_mem_type: The type of memory that the remote VM should allocate
* (e.g. ION memory)
* @src_data: A pointer to memory type specific data that the remote VM may need
* when performing an allocation (e.g. ION memory allocations require a heap ID)
* @dst_mem_type: The type of memory that the native VM wants (e.g. ION memory)
* @dst_data: A pointer to memory type specific data that the native VM may
* need when adding the memory from the remote VM (e.g. ION memory requires a
* heap ID to add the memory to).
*/
struct mem_buf_allocation_data {
size_t size;
unsigned int nr_acl_entries;
struct acl_entry *acl_list;
enum mem_buf_mem_type src_mem_type;
void *src_data;
enum mem_buf_mem_type dst_mem_type;
void *dst_data;
};
#if IS_ENABLED(CONFIG_QCOM_MEM_BUF)
void *mem_buf_alloc(struct mem_buf_allocation_data *alloc_data);
int mem_buf_get_fd(void *membuf_desc);
void mem_buf_put(void *membuf_desc);
void *mem_buf_get(int fd);
#else
static inline void *mem_buf_alloc(struct mem_buf_allocation_data *alloc_data)
{
return ERR_PTR(-ENODEV);
}
static inline int mem_buf_get_fd(void *membuf_desc)
{
return -ENODEV;
}
static inline void mem_buf_put(void *membuf_desc)
{
}
static inline void *mem_buf_get(int fd)
{
return ERR_PTR(-ENODEV);
}
#endif /* CONFIG_QCOM_MEM_BUF */
#endif /* _MEM_BUF_H */
|