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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
/*
* cmm.h
*
* DSP-BIOS Bridge driver support functions for TI OMAP processors.
*
* The Communication Memory Management(CMM) module provides shared memory
* management services for DSP/BIOS Bridge data streaming and messaging.
* Multiple shared memory segments can be registered with CMM. Memory is
* coelesced back to the appropriate pool when a buffer is freed.
*
* The CMM_Xlator[xxx] functions are used for node messaging and data
* streaming address translation to perform zero-copy inter-processor
* data transfer(GPP<->DSP). A "translator" object is created for a node or
* stream object that contains per thread virtual address information. This
* translator info is used at runtime to perform SM address translation
* to/from the DSP address space.
*
* Notes:
* cmm_xlator_alloc_buf - Used by Node and Stream modules for SM address
* translation.
*
* Copyright (C) 2008 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef CMM_
#define CMM_
#include <dspbridge/devdefs.h>
#include <dspbridge/cmmdefs.h>
#include <dspbridge/host_os.h>
/*
* ======== cmm_calloc_buf ========
* Purpose:
* Allocate memory buffers that can be used for data streaming or
* messaging.
* Parameters:
* hcmm_mgr: Cmm Mgr handle.
* usize: Number of bytes to allocate.
* pattr: Attributes of memory to allocate.
* pp_buf_va: Address of where to place VA.
* Returns:
* Pointer to a zero'd block of SM memory;
* NULL if memory couldn't be allocated,
* or if byte_size == 0,
* Requires:
* Valid hcmm_mgr.
* CMM initialized.
* Ensures:
* The returned pointer, if not NULL, points to a valid memory block of
* the size requested.
*
*/
extern void *cmm_calloc_buf(struct cmm_object *hcmm_mgr,
u32 usize, struct cmm_attrs *pattrs,
OUT void **pp_buf_va);
/*
* ======== cmm_create ========
* Purpose:
* Create a communication memory manager object.
* Parameters:
* ph_cmm_mgr: Location to store a communication manager handle on
* output.
* hdev_obj: Handle to a device object.
* mgr_attrts: Comm mem manager attributes.
* Returns:
* 0: Success;
* -ENOMEM: Insufficient memory for requested resources.
* -EPERM: Failed to initialize critical sect sync object.
*
* Requires:
* cmm_init(void) called.
* ph_cmm_mgr != NULL.
* mgr_attrts->ul_min_block_size >= 4 bytes.
* Ensures:
*
*/
extern int cmm_create(OUT struct cmm_object **ph_cmm_mgr,
struct dev_object *hdev_obj,
const struct cmm_mgrattrs *mgr_attrts);
/*
* ======== cmm_destroy ========
* Purpose:
* Destroy the communication memory manager object.
* Parameters:
* hcmm_mgr: Cmm Mgr handle.
* force: Force deallocation of all cmm memory immediately if set TRUE.
* If FALSE, and outstanding allocations will return -EPERM
* status.
* Returns:
* 0: CMM object & resources deleted.
* -EPERM: Unable to free CMM object due to outstanding allocation.
* -EFAULT: Unable to free CMM due to bad handle.
* Requires:
* CMM is initialized.
* hcmm_mgr != NULL.
* Ensures:
* Memory resources used by Cmm Mgr are freed.
*/
extern int cmm_destroy(struct cmm_object *hcmm_mgr, bool force);
/*
* ======== cmm_exit ========
* Purpose:
* Discontinue usage of module. Cleanup CMM module if CMM cRef reaches zero.
* Parameters:
* n/a
* Returns:
* n/a
* Requires:
* CMM is initialized.
* Ensures:
*/
extern void cmm_exit(void);
/*
* ======== cmm_free_buf ========
* Purpose:
* Free the given buffer.
* Parameters:
* hcmm_mgr: Cmm Mgr handle.
* pbuf: Pointer to memory allocated by cmm_calloc_buf().
* ul_seg_id: SM segment Id used in CMM_Calloc() attrs.
* Set to 0 to use default segment.
* Returns:
* 0
* -EPERM
* Requires:
* CMM initialized.
* buf_pa != NULL
* Ensures:
*
*/
extern int cmm_free_buf(struct cmm_object *hcmm_mgr,
void *buf_pa, u32 ul_seg_id);
/*
* ======== cmm_get_handle ========
* Purpose:
* Return the handle to the cmm mgr for the given device obj.
* Parameters:
* hprocessor: Handle to a Processor.
* ph_cmm_mgr: Location to store the shared memory mgr handle on
* output.
*
* Returns:
* 0: Cmm Mgr opaque handle returned.
* -EFAULT: Invalid handle.
* Requires:
* ph_cmm_mgr != NULL
* hdev_obj != NULL
* Ensures:
*/
extern int cmm_get_handle(void *hprocessor,
OUT struct cmm_object **ph_cmm_mgr);
/*
* ======== cmm_get_info ========
* Purpose:
* Return the current SM and VM utilization information.
* Parameters:
* hcmm_mgr: Handle to a Cmm Mgr.
* cmm_info_obj: Location to store the Cmm information on output.
*
* Returns:
* 0: Success.
* -EFAULT: Invalid handle.
* -EINVAL Invalid input argument.
* Requires:
* Ensures:
*
*/
extern int cmm_get_info(struct cmm_object *hcmm_mgr,
OUT struct cmm_info *cmm_info_obj);
/*
* ======== cmm_init ========
* Purpose:
* Initializes private state of CMM module.
* Parameters:
* Returns:
* TRUE if initialized; FALSE if error occured.
* Requires:
* Ensures:
* CMM initialized.
*/
extern bool cmm_init(void);
/*
* ======== cmm_register_gppsm_seg ========
* Purpose:
* Register a block of SM with the CMM.
* Parameters:
* hcmm_mgr: Handle to a Cmm Mgr.
* lpGPPBasePA: GPP Base Physical address.
* ul_size: Size in GPP bytes.
* dsp_addr_offset GPP PA to DSP PA Offset.
* c_factor: Add offset if CMM_ADDTODSPPA, sub if CMM_SUBFROMDSPPA.
* dw_dsp_base: DSP virtual base byte address.
* ul_dsp_size: Size of DSP segment in bytes.
* sgmt_id: Address to store segment Id.
*
* Returns:
* 0: Success.
* -EFAULT: Invalid hcmm_mgr handle.
* -EINVAL: Invalid input argument.
* -EPERM: Unable to register.
* - On success *sgmt_id is a valid SM segment ID.
* Requires:
* ul_size > 0
* sgmt_id != NULL
* dw_gpp_base_pa != 0
* c_factor = CMM_ADDTODSPPA || c_factor = CMM_SUBFROMDSPPA
* Ensures:
*
*/
extern int cmm_register_gppsm_seg(struct cmm_object *hcmm_mgr,
unsigned int dw_gpp_base_pa,
u32 ul_size,
u32 dsp_addr_offset,
s8 c_factor,
unsigned int dw_dsp_base,
u32 ul_dsp_size,
u32 *sgmt_id, u32 gpp_base_va);
/*
* ======== cmm_un_register_gppsm_seg ========
* Purpose:
* Unregister the given memory segment that was previously registered
* by cmm_register_gppsm_seg.
* Parameters:
* hcmm_mgr: Handle to a Cmm Mgr.
* ul_seg_id Segment identifier returned by cmm_register_gppsm_seg.
* Returns:
* 0: Success.
* -EFAULT: Invalid handle.
* -EINVAL: Invalid ul_seg_id.
* -EPERM: Unable to unregister for unknown reason.
* Requires:
* Ensures:
*
*/
extern int cmm_un_register_gppsm_seg(struct cmm_object *hcmm_mgr,
u32 ul_seg_id);
/*
* ======== cmm_xlator_alloc_buf ========
* Purpose:
* Allocate the specified SM buffer and create a local memory descriptor.
* Place on the descriptor on the translator's HaQ (Host Alloc'd Queue).
* Parameters:
* xlator: Handle to a Xlator object.
* va_buf: Virtual address ptr(client context)
* pa_size: Size of SM memory to allocate.
* Returns:
* Ptr to valid physical address(Pa) of pa_size bytes, NULL if failed.
* Requires:
* va_buf != 0.
* pa_size != 0.
* Ensures:
*
*/
extern void *cmm_xlator_alloc_buf(struct cmm_xlatorobject *xlator,
void *va_buf, u32 pa_size);
/*
* ======== cmm_xlator_create ========
* Purpose:
* Create a translator(xlator) object used for process specific Va<->Pa
* address translation. Node messaging and streams use this to perform
* inter-processor(GPP<->DSP) zero-copy data transfer.
* Parameters:
* xlator: Address to place handle to a new Xlator handle.
* hcmm_mgr: Handle to Cmm Mgr associated with this translator.
* xlator_attrs: Translator attributes used for the client NODE or STREAM.
* Returns:
* 0: Success.
* -EINVAL: Bad input Attrs.
* -ENOMEM: Insufficient memory(local) for requested resources.
* Requires:
* xlator != NULL
* hcmm_mgr != NULL
* xlator_attrs != NULL
* Ensures:
*
*/
extern int cmm_xlator_create(OUT struct cmm_xlatorobject **xlator,
struct cmm_object *hcmm_mgr,
struct cmm_xlatorattrs *xlator_attrs);
/*
* ======== cmm_xlator_delete ========
* Purpose:
* Delete translator resources
* Parameters:
* xlator: handle to translator.
* force: force = TRUE will free XLators SM buffers/dscriptrs.
* Returns:
* 0: Success.
* -EFAULT: Bad translator handle.
* -EPERM: Unable to free translator resources.
* Requires:
* refs > 0
* Ensures:
*
*/
extern int cmm_xlator_delete(struct cmm_xlatorobject *xlator,
bool force);
/*
* ======== cmm_xlator_free_buf ========
* Purpose:
* Free SM buffer and descriptor.
* Does not free client process VM.
* Parameters:
* xlator: handle to translator.
* buf_va Virtual address of PA to free.
* Returns:
* 0: Success.
* -EFAULT: Bad translator handle.
* Requires:
* Ensures:
*
*/
extern int cmm_xlator_free_buf(struct cmm_xlatorobject *xlator,
void *buf_va);
/*
* ======== cmm_xlator_info ========
* Purpose:
* Set/Get process specific "translator" address info.
* This is used to perform fast virtaul address translation
* for shared memory buffers between the GPP and DSP.
* Parameters:
* xlator: handle to translator.
* paddr: Virtual base address of segment.
* ul_size: Size in bytes.
* segm_id: Segment identifier of SM segment(s)
* set_info Set xlator fields if TRUE, else return base addr
* Returns:
* 0: Success.
* -EFAULT: Bad translator handle.
* Requires:
* (refs > 0)
* (paddr != NULL)
* (ul_size > 0)
* Ensures:
*
*/
extern int cmm_xlator_info(struct cmm_xlatorobject *xlator,
OUT u8 **paddr,
u32 ul_size, u32 segm_id, bool set_info);
/*
* ======== cmm_xlator_translate ========
* Purpose:
* Perform address translation VA<->PA for the specified stream or
* message shared memory buffer.
* Parameters:
* xlator: handle to translator.
* paddr address of buffer to translate.
* xtype Type of address xlation. CMM_PA2VA or CMM_VA2PA.
* Returns:
* Valid address on success, else NULL.
* Requires:
* refs > 0
* paddr != NULL
* xtype >= CMM_VA2PA) && (xtype <= CMM_DSPPA2PA)
* Ensures:
*
*/
extern void *cmm_xlator_translate(struct cmm_xlatorobject *xlator,
void *paddr, enum cmm_xlatetype xtype);
#endif /* CMM_ */
|