4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * The Communication Memory Management(CMM) module provides shared memory
7 * management services for DSP/BIOS Bridge data streaming and messaging.
8 * Multiple shared memory segments can be registered with CMM. Memory is
9 * coelesced back to the appropriate pool when a buffer is freed.
11 * The CMM_Xlator[xxx] functions are used for node messaging and data
12 * streaming address translation to perform zero-copy inter-processor
13 * data transfer(GPP<->DSP). A "translator" object is created for a node or
14 * stream object that contains per thread virtual address information. This
15 * translator info is used at runtime to perform SM address translation
16 * to/from the DSP address space.
19 * cmm_xlator_alloc_buf - Used by Node and Stream modules for SM address
22 * Copyright (C) 2008 Texas Instruments, Inc.
24 * This package is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License version 2 as
26 * published by the Free Software Foundation.
28 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
30 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
36 #include <dspbridge/devdefs.h>
38 #include <dspbridge/cmmdefs.h>
39 #include <dspbridge/host_os.h>
42 * ======== cmm_calloc_buf ========
44 * Allocate memory buffers that can be used for data streaming or
47 * hcmm_mgr: Cmm Mgr handle.
48 * usize: Number of bytes to allocate.
49 * pattr: Attributes of memory to allocate.
50 * pp_buf_va: Address of where to place VA.
52 * Pointer to a zero'd block of SM memory;
53 * NULL if memory couldn't be allocated,
54 * or if byte_size == 0,
59 * The returned pointer, if not NULL, points to a valid memory block of
63 extern void *cmm_calloc_buf(struct cmm_object *hcmm_mgr,
64 u32 usize, struct cmm_attrs *pattrs,
68 * ======== cmm_create ========
70 * Create a communication memory manager object.
72 * ph_cmm_mgr: Location to store a communication manager handle on
74 * hdev_obj: Handle to a device object.
75 * mgr_attrts: Comm mem manager attributes.
78 * -ENOMEM: Insufficient memory for requested resources.
79 * -EPERM: Failed to initialize critical sect sync object.
82 * cmm_init(void) called.
84 * mgr_attrts->min_block_size >= 4 bytes.
88 extern int cmm_create(struct cmm_object **ph_cmm_mgr,
89 struct dev_object *hdev_obj,
90 const struct cmm_mgrattrs *mgr_attrts);
93 * ======== cmm_destroy ========
95 * Destroy the communication memory manager object.
97 * hcmm_mgr: Cmm Mgr handle.
98 * force: Force deallocation of all cmm memory immediately if set TRUE.
99 * If FALSE, and outstanding allocations will return -EPERM
102 * 0: CMM object & resources deleted.
103 * -EPERM: Unable to free CMM object due to outstanding allocation.
104 * -EFAULT: Unable to free CMM due to bad handle.
106 * CMM is initialized.
109 * Memory resources used by Cmm Mgr are freed.
111 extern int cmm_destroy(struct cmm_object *hcmm_mgr, bool force);
114 * ======== cmm_exit ========
116 * Discontinue usage of module. Cleanup CMM module if CMM cRef reaches zero.
122 * CMM is initialized.
125 extern void cmm_exit(void);
128 * ======== cmm_free_buf ========
130 * Free the given buffer.
132 * hcmm_mgr: Cmm Mgr handle.
133 * pbuf: Pointer to memory allocated by cmm_calloc_buf().
134 * ul_seg_id: SM segment Id used in CMM_Calloc() attrs.
135 * Set to 0 to use default segment.
145 extern int cmm_free_buf(struct cmm_object *hcmm_mgr,
146 void *buf_pa, u32 ul_seg_id);
149 * ======== cmm_get_handle ========
151 * Return the handle to the cmm mgr for the given device obj.
153 * hprocessor: Handle to a Processor.
154 * ph_cmm_mgr: Location to store the shared memory mgr handle on
158 * 0: Cmm Mgr opaque handle returned.
159 * -EFAULT: Invalid handle.
165 extern int cmm_get_handle(void *hprocessor,
166 struct cmm_object **ph_cmm_mgr);
169 * ======== cmm_get_info ========
171 * Return the current SM and VM utilization information.
173 * hcmm_mgr: Handle to a Cmm Mgr.
174 * cmm_info_obj: Location to store the Cmm information on output.
178 * -EFAULT: Invalid handle.
179 * -EINVAL Invalid input argument.
184 extern int cmm_get_info(struct cmm_object *hcmm_mgr,
185 struct cmm_info *cmm_info_obj);
188 * ======== cmm_init ========
190 * Initializes private state of CMM module.
193 * TRUE if initialized; FALSE if error occurred.
198 extern bool cmm_init(void);
201 * ======== cmm_register_gppsm_seg ========
203 * Register a block of SM with the CMM.
205 * hcmm_mgr: Handle to a Cmm Mgr.
206 * lpGPPBasePA: GPP Base Physical address.
207 * ul_size: Size in GPP bytes.
208 * dsp_addr_offset GPP PA to DSP PA Offset.
209 * c_factor: Add offset if CMM_ADDTODSPPA, sub if CMM_SUBFROMDSPPA.
210 * dw_dsp_base: DSP virtual base byte address.
211 * ul_dsp_size: Size of DSP segment in bytes.
212 * sgmt_id: Address to store segment Id.
216 * -EFAULT: Invalid hcmm_mgr handle.
217 * -EINVAL: Invalid input argument.
218 * -EPERM: Unable to register.
219 * - On success *sgmt_id is a valid SM segment ID.
223 * dw_gpp_base_pa != 0
224 * c_factor = CMM_ADDTODSPPA || c_factor = CMM_SUBFROMDSPPA
228 extern int cmm_register_gppsm_seg(struct cmm_object *hcmm_mgr,
229 unsigned int dw_gpp_base_pa,
233 unsigned int dw_dsp_base,
235 u32 *sgmt_id, u32 gpp_base_va);
238 * ======== cmm_un_register_gppsm_seg ========
240 * Unregister the given memory segment that was previously registered
241 * by cmm_register_gppsm_seg.
243 * hcmm_mgr: Handle to a Cmm Mgr.
244 * ul_seg_id Segment identifier returned by cmm_register_gppsm_seg.
247 * -EFAULT: Invalid handle.
248 * -EINVAL: Invalid ul_seg_id.
249 * -EPERM: Unable to unregister for unknown reason.
254 extern int cmm_un_register_gppsm_seg(struct cmm_object *hcmm_mgr,
258 * ======== cmm_xlator_alloc_buf ========
260 * Allocate the specified SM buffer and create a local memory descriptor.
261 * Place on the descriptor on the translator's HaQ (Host Alloc'd Queue).
263 * xlator: Handle to a Xlator object.
264 * va_buf: Virtual address ptr(client context)
265 * pa_size: Size of SM memory to allocate.
267 * Ptr to valid physical address(Pa) of pa_size bytes, NULL if failed.
274 extern void *cmm_xlator_alloc_buf(struct cmm_xlatorobject *xlator,
275 void *va_buf, u32 pa_size);
278 * ======== cmm_xlator_create ========
280 * Create a translator(xlator) object used for process specific Va<->Pa
281 * address translation. Node messaging and streams use this to perform
282 * inter-processor(GPP<->DSP) zero-copy data transfer.
284 * xlator: Address to place handle to a new Xlator handle.
285 * hcmm_mgr: Handle to Cmm Mgr associated with this translator.
286 * xlator_attrs: Translator attributes used for the client NODE or STREAM.
289 * -EINVAL: Bad input Attrs.
290 * -ENOMEM: Insufficient memory(local) for requested resources.
294 * xlator_attrs != NULL
298 extern int cmm_xlator_create(struct cmm_xlatorobject **xlator,
299 struct cmm_object *hcmm_mgr,
300 struct cmm_xlatorattrs *xlator_attrs);
303 * ======== cmm_xlator_free_buf ========
305 * Free SM buffer and descriptor.
306 * Does not free client process VM.
308 * xlator: handle to translator.
309 * buf_va Virtual address of PA to free.
312 * -EFAULT: Bad translator handle.
317 extern int cmm_xlator_free_buf(struct cmm_xlatorobject *xlator,
321 * ======== cmm_xlator_info ========
323 * Set/Get process specific "translator" address info.
324 * This is used to perform fast virtaul address translation
325 * for shared memory buffers between the GPP and DSP.
327 * xlator: handle to translator.
328 * paddr: Virtual base address of segment.
329 * ul_size: Size in bytes.
330 * segm_id: Segment identifier of SM segment(s)
331 * set_info Set xlator fields if TRUE, else return base addr
334 * -EFAULT: Bad translator handle.
342 extern int cmm_xlator_info(struct cmm_xlatorobject *xlator,
344 u32 ul_size, u32 segm_id, bool set_info);
347 * ======== cmm_xlator_translate ========
349 * Perform address translation VA<->PA for the specified stream or
350 * message shared memory buffer.
352 * xlator: handle to translator.
353 * paddr address of buffer to translate.
354 * xtype Type of address xlation. CMM_PA2VA or CMM_VA2PA.
356 * Valid address on success, else NULL.
360 * xtype >= CMM_VA2PA) && (xtype <= CMM_DSPPA2PA)
364 extern void *cmm_xlator_translate(struct cmm_xlatorobject *xlator,
365 void *paddr, enum cmm_xlatetype xtype);