4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * Processor interface at the driver level.
8 * Copyright (C) 2005-2006 Texas Instruments, Inc.
10 * This package is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 /* ------------------------------------ Host OS */
20 #include <linux/dma-mapping.h>
21 #include <linux/scatterlist.h>
22 #include <dspbridge/host_os.h>
24 /* ----------------------------------- DSP/BIOS Bridge */
25 #include <dspbridge/std.h>
26 #include <dspbridge/dbdefs.h>
28 /* ----------------------------------- Trace & Debug */
29 #include <dspbridge/dbc.h>
31 /* ----------------------------------- OS Adaptation Layer */
32 #include <dspbridge/cfg.h>
33 #include <dspbridge/list.h>
34 #include <dspbridge/ntfy.h>
35 #include <dspbridge/sync.h>
36 /* ----------------------------------- Bridge Driver */
37 #include <dspbridge/dspdefs.h>
38 #include <dspbridge/dspdeh.h>
39 /* ----------------------------------- Platform Manager */
40 #include <dspbridge/cod.h>
41 #include <dspbridge/dev.h>
42 #include <dspbridge/procpriv.h>
43 #include <dspbridge/dmm.h>
45 /* ----------------------------------- Resource Manager */
46 #include <dspbridge/mgr.h>
47 #include <dspbridge/node.h>
48 #include <dspbridge/nldr.h>
49 #include <dspbridge/rmm.h>
51 /* ----------------------------------- Others */
52 #include <dspbridge/dbdcd.h>
53 #include <dspbridge/msg.h>
54 #include <dspbridge/dspioctl.h>
55 #include <dspbridge/drv.h>
57 /* ----------------------------------- This */
58 #include <dspbridge/proc.h>
59 #include <dspbridge/pwr.h>
61 #include <dspbridge/resourcecleanup.h>
62 /* ----------------------------------- Defines, Data Structures, Typedefs */
63 #define MAXCMDLINELEN 255
64 #define PROC_ENVPROCID "PROC_ID=%d"
65 #define MAXPROCIDLEN (8 + 5)
66 #define PROC_DFLT_TIMEOUT 10000 /* Time out in milliseconds */
67 #define PWR_TIMEOUT 500 /* Sleep/wake timout in msec */
68 #define EXTEND "_EXT_END" /* Extmem end addr in DSP binary */
70 #define DSP_CACHE_LINE 128
72 #define BUFMODE_MASK (3 << 14)
74 /* Buffer modes from DSP perspective */
75 #define RBUF 0x4000 /* Input buffer */
76 #define WBUF 0x8000 /* Output Buffer */
78 extern struct device *bridge;
80 /* ----------------------------------- Globals */
82 /* The proc_object structure. */
84 struct list_head link; /* Link to next proc_object */
85 struct dev_object *hdev_obj; /* Device this PROC represents */
86 u32 process; /* Process owning this Processor */
87 struct mgr_object *hmgr_obj; /* Manager Object Handle */
88 u32 attach_count; /* Processor attach count */
89 u32 processor_id; /* Processor number */
90 u32 utimeout; /* Time out count */
91 enum dsp_procstate proc_state; /* Processor state */
92 u32 ul_unit; /* DDSP unit number */
93 bool is_already_attached; /*
94 * True if the Device below has
97 struct ntfy_object *ntfy_obj; /* Manages notifications */
98 /* Bridge Context Handle */
99 struct bridge_dev_context *hbridge_context;
100 /* Function interface to Bridge driver */
101 struct bridge_drv_interface *intf_fxns;
103 struct list_head proc_list;
108 DEFINE_MUTEX(proc_lock); /* For critical sections */
110 /* ----------------------------------- Function Prototypes */
111 static int proc_monitor(struct proc_object *proc_obj);
112 static s32 get_envp_count(char **envp);
113 static char **prepend_envp(char **new_envp, char **envp, s32 envp_elems,
114 s32 cnew_envp, char *sz_var);
116 /* remember mapping information */
117 static struct dmm_map_object *add_mapping_info(struct process_context *pr_ctxt,
118 u32 mpu_addr, u32 dsp_addr, u32 size)
120 struct dmm_map_object *map_obj;
122 u32 num_usr_pgs = size / PG_SIZE4K;
124 pr_debug("%s: adding map info: mpu_addr 0x%x virt 0x%x size 0x%x\n",
128 map_obj = kzalloc(sizeof(struct dmm_map_object), GFP_KERNEL);
130 pr_err("%s: kzalloc failed\n", __func__);
133 INIT_LIST_HEAD(&map_obj->link);
135 map_obj->pages = kcalloc(num_usr_pgs, sizeof(struct page *),
137 if (!map_obj->pages) {
138 pr_err("%s: kzalloc failed\n", __func__);
143 map_obj->mpu_addr = mpu_addr;
144 map_obj->dsp_addr = dsp_addr;
145 map_obj->size = size;
146 map_obj->num_usr_pgs = num_usr_pgs;
148 spin_lock(&pr_ctxt->dmm_map_lock);
149 list_add(&map_obj->link, &pr_ctxt->dmm_map_list);
150 spin_unlock(&pr_ctxt->dmm_map_lock);
155 static int match_exact_map_obj(struct dmm_map_object *map_obj,
156 u32 dsp_addr, u32 size)
158 if (map_obj->dsp_addr == dsp_addr && map_obj->size != size)
159 pr_err("%s: addr match (0x%x), size don't (0x%x != 0x%x)\n",
160 __func__, dsp_addr, map_obj->size, size);
162 return map_obj->dsp_addr == dsp_addr &&
163 map_obj->size == size;
166 static void remove_mapping_information(struct process_context *pr_ctxt,
167 u32 dsp_addr, u32 size)
169 struct dmm_map_object *map_obj;
171 pr_debug("%s: looking for virt 0x%x size 0x%x\n", __func__,
174 spin_lock(&pr_ctxt->dmm_map_lock);
175 list_for_each_entry(map_obj, &pr_ctxt->dmm_map_list, link) {
176 pr_debug("%s: candidate: mpu_addr 0x%x virt 0x%x size 0x%x\n",
182 if (match_exact_map_obj(map_obj, dsp_addr, size)) {
183 pr_debug("%s: match, deleting map info\n", __func__);
184 list_del(&map_obj->link);
185 kfree(map_obj->dma_info.sg);
186 kfree(map_obj->pages);
190 pr_debug("%s: candidate didn't match\n", __func__);
193 pr_err("%s: failed to find given map info\n", __func__);
195 spin_unlock(&pr_ctxt->dmm_map_lock);
198 static int match_containing_map_obj(struct dmm_map_object *map_obj,
199 u32 mpu_addr, u32 size)
201 u32 map_obj_end = map_obj->mpu_addr + map_obj->size;
203 return mpu_addr >= map_obj->mpu_addr &&
204 mpu_addr + size <= map_obj_end;
207 static struct dmm_map_object *find_containing_mapping(
208 struct process_context *pr_ctxt,
209 u32 mpu_addr, u32 size)
211 struct dmm_map_object *map_obj;
212 pr_debug("%s: looking for mpu_addr 0x%x size 0x%x\n", __func__,
215 spin_lock(&pr_ctxt->dmm_map_lock);
216 list_for_each_entry(map_obj, &pr_ctxt->dmm_map_list, link) {
217 pr_debug("%s: candidate: mpu_addr 0x%x virt 0x%x size 0x%x\n",
222 if (match_containing_map_obj(map_obj, mpu_addr, size)) {
223 pr_debug("%s: match!\n", __func__);
227 pr_debug("%s: no match!\n", __func__);
232 spin_unlock(&pr_ctxt->dmm_map_lock);
236 static int find_first_page_in_cache(struct dmm_map_object *map_obj,
237 unsigned long mpu_addr)
239 u32 mapped_base_page = map_obj->mpu_addr >> PAGE_SHIFT;
240 u32 requested_base_page = mpu_addr >> PAGE_SHIFT;
241 int pg_index = requested_base_page - mapped_base_page;
243 if (pg_index < 0 || pg_index >= map_obj->num_usr_pgs) {
244 pr_err("%s: failed (got %d)\n", __func__, pg_index);
248 pr_debug("%s: first page is %d\n", __func__, pg_index);
252 static inline struct page *get_mapping_page(struct dmm_map_object *map_obj,
255 pr_debug("%s: looking for pg_i %d, num_usr_pgs: %d\n", __func__,
256 pg_i, map_obj->num_usr_pgs);
258 if (pg_i < 0 || pg_i >= map_obj->num_usr_pgs) {
259 pr_err("%s: requested pg_i %d is out of mapped range\n",
264 return map_obj->pages[pg_i];
268 * ======== proc_attach ========
270 * Prepare for communication with a particular DSP processor, and return
271 * a handle to the processor object.
274 proc_attach(u32 processor_id,
275 OPTIONAL CONST struct dsp_processorattrin *attr_in,
276 void **ph_processor, struct process_context *pr_ctxt)
279 struct dev_object *hdev_obj;
280 struct proc_object *p_proc_object = NULL;
281 struct mgr_object *hmgr_obj = NULL;
282 struct drv_object *hdrv_obj = NULL;
285 DBC_REQUIRE(refs > 0);
286 DBC_REQUIRE(ph_processor != NULL);
288 if (pr_ctxt->hprocessor) {
289 *ph_processor = pr_ctxt->hprocessor;
293 /* Get the Driver and Manager Object Handles */
294 status = cfg_get_object((u32 *) &hdrv_obj, REG_DRV_OBJECT);
295 if (DSP_SUCCEEDED(status))
296 status = cfg_get_object((u32 *) &hmgr_obj, REG_MGR_OBJECT);
298 if (DSP_SUCCEEDED(status)) {
299 /* Get the Device Object */
300 status = drv_get_dev_object(processor_id, hdrv_obj, &hdev_obj);
302 if (DSP_SUCCEEDED(status))
303 status = dev_get_dev_type(hdev_obj, &dev_type);
305 if (DSP_FAILED(status))
308 /* If we made it this far, create the Proceesor object: */
309 p_proc_object = kzalloc(sizeof(struct proc_object), GFP_KERNEL);
310 /* Fill out the Processor Object: */
311 if (p_proc_object == NULL) {
315 p_proc_object->hdev_obj = hdev_obj;
316 p_proc_object->hmgr_obj = hmgr_obj;
317 p_proc_object->processor_id = dev_type;
318 /* Store TGID instead of process handle */
319 p_proc_object->process = current->tgid;
321 INIT_LIST_HEAD(&p_proc_object->proc_list);
324 p_proc_object->utimeout = attr_in->utimeout;
326 p_proc_object->utimeout = PROC_DFLT_TIMEOUT;
328 status = dev_get_intf_fxns(hdev_obj, &p_proc_object->intf_fxns);
329 if (DSP_SUCCEEDED(status)) {
330 status = dev_get_bridge_context(hdev_obj,
331 &p_proc_object->hbridge_context);
332 if (DSP_FAILED(status))
333 kfree(p_proc_object);
335 kfree(p_proc_object);
337 if (DSP_FAILED(status))
340 /* Create the Notification Object */
341 /* This is created with no event mask, no notify mask
342 * and no valid handle to the notification. They all get
343 * filled up when proc_register_notify is called */
344 p_proc_object->ntfy_obj = kmalloc(sizeof(struct ntfy_object),
346 if (p_proc_object->ntfy_obj)
347 ntfy_init(p_proc_object->ntfy_obj);
351 if (DSP_SUCCEEDED(status)) {
352 /* Insert the Processor Object into the DEV List.
353 * Return handle to this Processor Object:
354 * Find out if the Device is already attached to a
355 * Processor. If so, return AlreadyAttached status */
356 lst_init_elem(&p_proc_object->link);
357 status = dev_insert_proc_object(p_proc_object->hdev_obj,
360 is_already_attached);
361 if (DSP_SUCCEEDED(status)) {
362 if (p_proc_object->is_already_attached)
365 if (p_proc_object->ntfy_obj) {
366 ntfy_delete(p_proc_object->ntfy_obj);
367 kfree(p_proc_object->ntfy_obj);
370 kfree(p_proc_object);
372 if (DSP_SUCCEEDED(status)) {
373 *ph_processor = (void *)p_proc_object;
374 pr_ctxt->hprocessor = *ph_processor;
375 (void)proc_notify_clients(p_proc_object,
376 DSP_PROCESSORATTACH);
379 /* Don't leak memory if DSP_FAILED */
380 kfree(p_proc_object);
383 DBC_ENSURE((status == -EPERM && *ph_processor == NULL) ||
384 (DSP_SUCCEEDED(status) && p_proc_object) ||
385 (status == 0 && p_proc_object));
390 static int get_exec_file(struct cfg_devnode *dev_node_obj,
391 struct dev_object *hdev_obj,
392 u32 size, char *exec_file)
397 dev_get_dev_type(hdev_obj, (u8 *) &dev_type);
398 if (dev_type == DSP_UNIT) {
399 return cfg_get_exec_file(dev_node_obj, size, exec_file);
400 } else if (dev_type == IVA_UNIT) {
402 len = strlen(iva_img);
403 strncpy(exec_file, iva_img, len + 1);
411 * ======== proc_auto_start ======== =
413 * A Particular device gets loaded with the default image
414 * if the AutoStart flag is set.
416 * hdev_obj: Handle to the Device
418 * 0: On Successful Loading
419 * -EPERM General Failure
424 int proc_auto_start(struct cfg_devnode *dev_node_obj,
425 struct dev_object *hdev_obj)
428 struct proc_object *p_proc_object;
429 char sz_exec_file[MAXCMDLINELEN];
431 struct mgr_object *hmgr_obj = NULL;
434 DBC_REQUIRE(refs > 0);
435 DBC_REQUIRE(dev_node_obj != NULL);
436 DBC_REQUIRE(hdev_obj != NULL);
438 /* Create a Dummy PROC Object */
439 status = cfg_get_object((u32 *) &hmgr_obj, REG_MGR_OBJECT);
440 if (DSP_FAILED(status))
443 p_proc_object = kzalloc(sizeof(struct proc_object), GFP_KERNEL);
444 if (p_proc_object == NULL) {
448 p_proc_object->hdev_obj = hdev_obj;
449 p_proc_object->hmgr_obj = hmgr_obj;
450 status = dev_get_intf_fxns(hdev_obj, &p_proc_object->intf_fxns);
451 if (DSP_SUCCEEDED(status))
452 status = dev_get_bridge_context(hdev_obj,
453 &p_proc_object->hbridge_context);
454 if (DSP_FAILED(status))
457 /* Stop the Device, put it into standby mode */
458 status = proc_stop(p_proc_object);
460 if (DSP_FAILED(status))
463 /* Get the default executable for this board... */
464 dev_get_dev_type(hdev_obj, (u8 *) &dev_type);
465 p_proc_object->processor_id = dev_type;
466 status = get_exec_file(dev_node_obj, hdev_obj, sizeof(sz_exec_file),
468 if (DSP_SUCCEEDED(status)) {
469 argv[0] = sz_exec_file;
471 /* ...and try to load it: */
472 status = proc_load(p_proc_object, 1, (CONST char **)argv, NULL);
473 if (DSP_SUCCEEDED(status))
474 status = proc_start(p_proc_object);
476 kfree(p_proc_object->psz_last_coff);
477 p_proc_object->psz_last_coff = NULL;
479 kfree(p_proc_object);
485 * ======== proc_ctrl ========
487 * Pass control information to the GPP device driver managing the
490 * This will be an OEM-only function, and not part of the DSP/BIOS Bridge
491 * application developer's API.
492 * Call the bridge_dev_ctrl fxn with the Argument. This is a Synchronous
493 * Operation. arg can be null.
495 int proc_ctrl(void *hprocessor, u32 dw_cmd, IN struct dsp_cbdata * arg)
498 struct proc_object *p_proc_object = hprocessor;
501 DBC_REQUIRE(refs > 0);
504 /* intercept PWR deep sleep command */
505 if (dw_cmd == BRDIOCTL_DEEPSLEEP) {
506 timeout = arg->cb_data;
507 status = pwr_sleep_dsp(PWR_DEEPSLEEP, timeout);
509 /* intercept PWR emergency sleep command */
510 else if (dw_cmd == BRDIOCTL_EMERGENCYSLEEP) {
511 timeout = arg->cb_data;
512 status = pwr_sleep_dsp(PWR_EMERGENCYDEEPSLEEP, timeout);
513 } else if (dw_cmd == PWR_DEEPSLEEP) {
514 /* timeout = arg->cb_data; */
515 status = pwr_sleep_dsp(PWR_DEEPSLEEP, timeout);
517 /* intercept PWR wake commands */
518 else if (dw_cmd == BRDIOCTL_WAKEUP) {
519 timeout = arg->cb_data;
520 status = pwr_wake_dsp(timeout);
521 } else if (dw_cmd == PWR_WAKEUP) {
522 /* timeout = arg->cb_data; */
523 status = pwr_wake_dsp(timeout);
525 if (DSP_SUCCEEDED((*p_proc_object->intf_fxns->pfn_dev_cntrl)
526 (p_proc_object->hbridge_context, dw_cmd,
540 * ======== proc_detach ========
542 * Destroys the Processor Object. Removes the notification from the Dev
545 int proc_detach(struct process_context *pr_ctxt)
548 struct proc_object *p_proc_object = NULL;
550 DBC_REQUIRE(refs > 0);
552 p_proc_object = (struct proc_object *)pr_ctxt->hprocessor;
555 /* Notify the Client */
556 ntfy_notify(p_proc_object->ntfy_obj, DSP_PROCESSORDETACH);
557 /* Remove the notification memory */
558 if (p_proc_object->ntfy_obj) {
559 ntfy_delete(p_proc_object->ntfy_obj);
560 kfree(p_proc_object->ntfy_obj);
563 kfree(p_proc_object->psz_last_coff);
564 p_proc_object->psz_last_coff = NULL;
565 /* Remove the Proc from the DEV List */
566 (void)dev_remove_proc_object(p_proc_object->hdev_obj,
567 (u32) p_proc_object);
568 /* Free the Processor Object */
569 kfree(p_proc_object);
570 pr_ctxt->hprocessor = NULL;
579 * ======== proc_enum_nodes ========
581 * Enumerate and get configuration information about nodes allocated
582 * on a DSP processor.
584 int proc_enum_nodes(void *hprocessor, void **node_tab,
585 IN u32 node_tab_size, OUT u32 *pu_num_nodes,
586 OUT u32 *pu_allocated)
589 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
590 struct node_mgr *hnode_mgr = NULL;
592 DBC_REQUIRE(refs > 0);
593 DBC_REQUIRE(node_tab != NULL || node_tab_size == 0);
594 DBC_REQUIRE(pu_num_nodes != NULL);
595 DBC_REQUIRE(pu_allocated != NULL);
598 if (DSP_SUCCEEDED(dev_get_node_manager(p_proc_object->hdev_obj,
601 status = node_enum_nodes(hnode_mgr, node_tab,
614 /* Cache operation against kernel address instead of users */
615 static int build_dma_sg(struct dmm_map_object *map_obj, unsigned long start,
616 ssize_t len, int pg_i)
619 unsigned long offset;
622 struct scatterlist *sg = map_obj->dma_info.sg;
625 page = get_mapping_page(map_obj, pg_i);
627 pr_err("%s: no page for %08lx\n", __func__, start);
630 } else if (IS_ERR(page)) {
631 pr_err("%s: err page for %08lx(%lu)\n", __func__, start,
637 offset = start & ~PAGE_MASK;
638 rest = min_t(ssize_t, PAGE_SIZE - offset, len);
640 sg_set_page(&sg[i], page, rest, offset);
647 if (i != map_obj->dma_info.num_pages) {
648 pr_err("%s: bad number of sg iterations\n", __func__);
657 static int memory_regain_ownership(struct dmm_map_object *map_obj,
658 unsigned long start, ssize_t len, enum dma_data_direction dir)
661 unsigned long first_data_page = start >> PAGE_SHIFT;
662 unsigned long last_data_page = ((u32)(start + len - 1) >> PAGE_SHIFT);
663 /* calculating the number of pages this area spans */
664 unsigned long num_pages = last_data_page - first_data_page + 1;
665 struct bridge_dma_map_info *dma_info = &map_obj->dma_info;
670 if (dma_info->dir != dir || dma_info->num_pages != num_pages) {
671 pr_err("%s: dma info doesn't match given params\n", __func__);
675 dma_unmap_sg(bridge, dma_info->sg, num_pages, dma_info->dir);
677 pr_debug("%s: dma_map_sg unmapped\n", __func__);
681 map_obj->dma_info.sg = NULL;
687 /* Cache operation against kernel address instead of users */
688 static int memory_give_ownership(struct dmm_map_object *map_obj,
689 unsigned long start, ssize_t len, enum dma_data_direction dir)
691 int pg_i, ret, sg_num;
692 struct scatterlist *sg;
693 unsigned long first_data_page = start >> PAGE_SHIFT;
694 unsigned long last_data_page = ((u32)(start + len - 1) >> PAGE_SHIFT);
695 /* calculating the number of pages this area spans */
696 unsigned long num_pages = last_data_page - first_data_page + 1;
698 pg_i = find_first_page_in_cache(map_obj, start);
700 pr_err("%s: failed to find first page in cache\n", __func__);
705 sg = kcalloc(num_pages, sizeof(*sg), GFP_KERNEL);
707 pr_err("%s: kcalloc failed\n", __func__);
712 sg_init_table(sg, num_pages);
714 /* cleanup a previous sg allocation */
715 /* this may happen if application doesn't signal for e/o DMA */
716 kfree(map_obj->dma_info.sg);
718 map_obj->dma_info.sg = sg;
719 map_obj->dma_info.dir = dir;
720 map_obj->dma_info.num_pages = num_pages;
722 ret = build_dma_sg(map_obj, start, len, pg_i);
726 sg_num = dma_map_sg(bridge, sg, num_pages, dir);
728 pr_err("%s: dma_map_sg failed: %d\n", __func__, sg_num);
733 pr_debug("%s: dma_map_sg mapped %d elements\n", __func__, sg_num);
734 map_obj->dma_info.sg_num = sg_num;
740 map_obj->dma_info.sg = NULL;
745 int proc_begin_dma(void *hprocessor, void *pmpu_addr, u32 ul_size,
746 enum dma_data_direction dir)
748 /* Keep STATUS here for future additions to this function */
750 struct process_context *pr_ctxt = (struct process_context *) hprocessor;
751 struct dmm_map_object *map_obj;
753 DBC_REQUIRE(refs > 0);
760 pr_debug("%s: addr 0x%x, size 0x%x, type %d\n", __func__,
764 /* find requested memory are in cached mapping information */
765 map_obj = find_containing_mapping(pr_ctxt, (u32) pmpu_addr, ul_size);
767 pr_err("%s: find_containing_mapping failed\n", __func__);
772 if (memory_give_ownership(map_obj, (u32) pmpu_addr, ul_size, dir)) {
773 pr_err("%s: InValid address parameters %p %x\n",
774 __func__, pmpu_addr, ul_size);
783 int proc_end_dma(void *hprocessor, void *pmpu_addr, u32 ul_size,
784 enum dma_data_direction dir)
786 /* Keep STATUS here for future additions to this function */
788 struct process_context *pr_ctxt = (struct process_context *) hprocessor;
789 struct dmm_map_object *map_obj;
791 DBC_REQUIRE(refs > 0);
798 pr_debug("%s: addr 0x%x, size 0x%x, type %d\n", __func__,
802 /* find requested memory are in cached mapping information */
803 map_obj = find_containing_mapping(pr_ctxt, (u32) pmpu_addr, ul_size);
805 pr_err("%s: find_containing_mapping failed\n", __func__);
810 if (memory_regain_ownership(map_obj, (u32) pmpu_addr, ul_size, dir)) {
811 pr_err("%s: InValid address parameters %p %x\n",
812 __func__, pmpu_addr, ul_size);
822 * ======== proc_flush_memory ========
826 int proc_flush_memory(void *hprocessor, void *pmpu_addr,
827 u32 ul_size, u32 ul_flags)
829 enum dma_data_direction dir = DMA_BIDIRECTIONAL;
831 return proc_begin_dma(hprocessor, pmpu_addr, ul_size, dir);
835 * ======== proc_invalidate_memory ========
837 * Invalidates the memory specified
839 int proc_invalidate_memory(void *hprocessor, void *pmpu_addr, u32 size)
841 enum dma_data_direction dir = DMA_FROM_DEVICE;
843 return proc_begin_dma(hprocessor, pmpu_addr, size, dir);
847 * ======== proc_get_resource_info ========
849 * Enumerate the resources currently available on a processor.
851 int proc_get_resource_info(void *hprocessor, u32 resource_type,
852 OUT struct dsp_resourceinfo *resource_info,
853 u32 resource_info_size)
856 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
857 struct node_mgr *hnode_mgr = NULL;
858 struct nldr_object *nldr_obj = NULL;
859 struct rmm_target_obj *rmm = NULL;
860 struct io_mgr *hio_mgr = NULL; /* IO manager handle */
862 DBC_REQUIRE(refs > 0);
863 DBC_REQUIRE(resource_info != NULL);
864 DBC_REQUIRE(resource_info_size >= sizeof(struct dsp_resourceinfo));
866 if (!p_proc_object) {
870 switch (resource_type) {
871 case DSP_RESOURCE_DYNDARAM:
872 case DSP_RESOURCE_DYNSARAM:
873 case DSP_RESOURCE_DYNEXTERNAL:
874 case DSP_RESOURCE_DYNSRAM:
875 status = dev_get_node_manager(p_proc_object->hdev_obj,
882 status = node_get_nldr_obj(hnode_mgr, &nldr_obj);
883 if (DSP_SUCCEEDED(status)) {
884 status = nldr_get_rmm_manager(nldr_obj, &rmm);
887 (enum dsp_memtype)resource_type,
888 (struct dsp_memstat *)
889 &(resource_info->result.
897 case DSP_RESOURCE_PROCLOAD:
898 status = dev_get_io_mgr(p_proc_object->hdev_obj, &hio_mgr);
901 p_proc_object->intf_fxns->
902 pfn_io_get_proc_load(hio_mgr,
903 (struct dsp_procloadstat *)
904 &(resource_info->result.
918 * ======== proc_exit ========
920 * Decrement reference count, and free resources when reference count is
925 DBC_REQUIRE(refs > 0);
929 DBC_ENSURE(refs >= 0);
933 * ======== proc_get_dev_object ========
935 * Return the Dev Object handle for a given Processor.
938 int proc_get_dev_object(void *hprocessor,
939 struct dev_object **device_obj)
942 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
944 DBC_REQUIRE(refs > 0);
945 DBC_REQUIRE(device_obj != NULL);
948 *device_obj = p_proc_object->hdev_obj;
955 DBC_ENSURE((DSP_SUCCEEDED(status) && *device_obj != NULL) ||
956 (DSP_FAILED(status) && *device_obj == NULL));
962 * ======== proc_get_state ========
964 * Report the state of the specified DSP processor.
966 int proc_get_state(void *hprocessor,
967 OUT struct dsp_processorstate *proc_state_obj,
971 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
974 DBC_REQUIRE(refs > 0);
975 DBC_REQUIRE(proc_state_obj != NULL);
976 DBC_REQUIRE(state_info_size >= sizeof(struct dsp_processorstate));
979 /* First, retrieve BRD state information */
980 status = (*p_proc_object->intf_fxns->pfn_brd_status)
981 (p_proc_object->hbridge_context, &brd_status);
982 if (DSP_SUCCEEDED(status)) {
983 switch (brd_status) {
985 proc_state_obj->proc_state = PROC_STOPPED;
987 case BRD_SLEEP_TRANSITION:
988 case BRD_DSP_HIBERNATION:
991 proc_state_obj->proc_state = PROC_RUNNING;
994 proc_state_obj->proc_state = PROC_LOADED;
997 proc_state_obj->proc_state = PROC_ERROR;
1000 proc_state_obj->proc_state = 0xFF;
1008 dev_dbg(bridge, "%s, results: status: 0x%x proc_state_obj: 0x%x\n",
1009 __func__, status, proc_state_obj->proc_state);
1014 * ======== proc_get_trace ========
1016 * Retrieve the current contents of the trace buffer, located on the
1017 * Processor. Predefined symbols for the trace buffer must have been
1018 * configured into the DSP executable.
1020 * We support using the symbols SYS_PUTCBEG and SYS_PUTCEND to define a
1021 * trace buffer, only. Treat it as an undocumented feature.
1022 * This call is destructive, meaning the processor is placed in the monitor
1023 * state as a result of this function.
1025 int proc_get_trace(void *hprocessor, u8 * pbuf, u32 max_size)
1033 * ======== proc_init ========
1035 * Initialize PROC's private state, keeping a reference count on each call
1037 bool proc_init(void)
1041 DBC_REQUIRE(refs >= 0);
1046 DBC_ENSURE((ret && (refs > 0)) || (!ret && (refs >= 0)));
1052 * ======== proc_load ========
1054 * Reset a processor and load a new base program image.
1055 * This will be an OEM-only function, and not part of the DSP/BIOS Bridge
1056 * application developer's API.
1058 int proc_load(void *hprocessor, IN CONST s32 argc_index,
1059 IN CONST char **user_args, IN CONST char **user_envp)
1062 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1063 struct io_mgr *hio_mgr; /* IO manager handle */
1064 struct msg_mgr *hmsg_mgr;
1065 struct cod_manager *cod_mgr; /* Code manager handle */
1066 char *pargv0; /* temp argv[0] ptr */
1067 char **new_envp; /* Updated envp[] array. */
1068 char sz_proc_id[MAXPROCIDLEN]; /* Size of "PROC_ID=<n>" */
1069 s32 envp_elems; /* Num elements in envp[]. */
1070 s32 cnew_envp; /* " " in new_envp[] */
1071 s32 nproc_id = 0; /* Anticipate MP version. */
1072 struct dcd_manager *hdcd_handle;
1073 struct dmm_object *dmm_mgr;
1077 struct drv_data *drv_datap = dev_get_drvdata(bridge);
1079 #ifdef OPT_LOAD_TIME_INSTRUMENTATION
1084 #if defined(CONFIG_TIDSPBRIDGE_DVFS) && !defined(CONFIG_CPU_FREQ)
1085 struct dspbridge_platform_data *pdata =
1086 omap_dspbridge_dev->dev.platform_data;
1089 DBC_REQUIRE(refs > 0);
1090 DBC_REQUIRE(argc_index > 0);
1091 DBC_REQUIRE(user_args != NULL);
1093 #ifdef OPT_LOAD_TIME_INSTRUMENTATION
1094 do_gettimeofday(&tv1);
1096 if (!p_proc_object) {
1100 dev_get_cod_mgr(p_proc_object->hdev_obj, &cod_mgr);
1105 status = proc_stop(hprocessor);
1106 if (DSP_FAILED(status))
1109 /* Place the board in the monitor state. */
1110 status = proc_monitor(hprocessor);
1111 if (DSP_FAILED(status))
1114 /* Save ptr to original argv[0]. */
1115 pargv0 = (char *)user_args[0];
1116 /*Prepend "PROC_ID=<nproc_id>"to envp array for target. */
1117 envp_elems = get_envp_count((char **)user_envp);
1118 cnew_envp = (envp_elems ? (envp_elems + 1) : (envp_elems + 2));
1119 new_envp = kzalloc(cnew_envp * sizeof(char **), GFP_KERNEL);
1121 status = snprintf(sz_proc_id, MAXPROCIDLEN, PROC_ENVPROCID,
1124 dev_dbg(bridge, "%s: Proc ID string overflow\n",
1129 prepend_envp(new_envp, (char **)user_envp,
1130 envp_elems, cnew_envp, sz_proc_id);
1131 /* Get the DCD Handle */
1132 status = mgr_get_dcd_handle(p_proc_object->hmgr_obj,
1133 (u32 *) &hdcd_handle);
1134 if (DSP_SUCCEEDED(status)) {
1135 /* Before proceeding with new load,
1136 * check if a previously registered COFF
1138 * If yes, unregister nodes in previously
1139 * registered COFF. If any error occurred,
1140 * set previously registered COFF to NULL. */
1141 if (p_proc_object->psz_last_coff != NULL) {
1143 dcd_auto_unregister(hdcd_handle,
1146 /* Regardless of auto unregister status,
1147 * free previously allocated
1149 kfree(p_proc_object->psz_last_coff);
1150 p_proc_object->psz_last_coff = NULL;
1153 /* On success, do cod_open_base() */
1154 status = cod_open_base(cod_mgr, (char *)user_args[0],
1160 if (DSP_SUCCEEDED(status)) {
1161 /* Auto-register data base */
1162 /* Get the DCD Handle */
1163 status = mgr_get_dcd_handle(p_proc_object->hmgr_obj,
1164 (u32 *) &hdcd_handle);
1165 if (DSP_SUCCEEDED(status)) {
1166 /* Auto register nodes in specified COFF
1167 * file. If registration did not fail,
1168 * (status = 0 or -EACCES)
1169 * save the name of the COFF file for
1170 * de-registration in the future. */
1172 dcd_auto_register(hdcd_handle,
1173 (char *)user_args[0]);
1174 if (status == -EACCES)
1177 if (DSP_FAILED(status)) {
1180 DBC_ASSERT(p_proc_object->psz_last_coff ==
1182 /* Allocate memory for pszLastCoff */
1183 p_proc_object->psz_last_coff =
1184 kzalloc((strlen(user_args[0]) +
1186 /* If memory allocated, save COFF file name */
1187 if (p_proc_object->psz_last_coff) {
1188 strncpy(p_proc_object->psz_last_coff,
1189 (char *)user_args[0],
1190 (strlen((char *)user_args[0]) +
1196 /* Update shared memory address and size */
1197 if (DSP_SUCCEEDED(status)) {
1198 /* Create the message manager. This must be done
1199 * before calling the IOOnLoaded function. */
1200 dev_get_msg_mgr(p_proc_object->hdev_obj, &hmsg_mgr);
1202 status = msg_create(&hmsg_mgr, p_proc_object->hdev_obj,
1203 (msg_onexit) node_on_exit);
1204 DBC_ASSERT(DSP_SUCCEEDED(status));
1205 dev_set_msg_mgr(p_proc_object->hdev_obj, hmsg_mgr);
1208 if (DSP_SUCCEEDED(status)) {
1209 /* Set the Device object's message manager */
1210 status = dev_get_io_mgr(p_proc_object->hdev_obj, &hio_mgr);
1212 status = (*p_proc_object->intf_fxns->pfn_io_on_loaded)
1217 if (DSP_SUCCEEDED(status)) {
1218 /* Now, attempt to load an exec: */
1220 /* Boost the OPP level to Maximum level supported by baseport */
1221 #if defined(CONFIG_TIDSPBRIDGE_DVFS) && !defined(CONFIG_CPU_FREQ)
1222 if (pdata->cpu_set_freq)
1223 (*pdata->cpu_set_freq) (pdata->mpu_speed[VDD1_OPP5]);
1225 status = cod_load_base(cod_mgr, argc_index, (char **)user_args,
1227 p_proc_object->hdev_obj, NULL);
1228 if (DSP_FAILED(status)) {
1229 if (status == -EBADF) {
1230 dev_dbg(bridge, "%s: Failure to Load the EXE\n",
1233 if (status == -ESPIPE) {
1234 pr_err("%s: Couldn't parse the file\n",
1238 /* Requesting the lowest opp supported */
1239 #if defined(CONFIG_TIDSPBRIDGE_DVFS) && !defined(CONFIG_CPU_FREQ)
1240 if (pdata->cpu_set_freq)
1241 (*pdata->cpu_set_freq) (pdata->mpu_speed[VDD1_OPP1]);
1245 if (DSP_SUCCEEDED(status)) {
1246 /* Update the Processor status to loaded */
1247 status = (*p_proc_object->intf_fxns->pfn_brd_set_state)
1248 (p_proc_object->hbridge_context, BRD_LOADED);
1249 if (DSP_SUCCEEDED(status)) {
1250 p_proc_object->proc_state = PROC_LOADED;
1251 if (p_proc_object->ntfy_obj)
1252 proc_notify_clients(p_proc_object,
1253 DSP_PROCESSORSTATECHANGE);
1256 if (DSP_SUCCEEDED(status)) {
1257 status = proc_get_processor_id(hprocessor, &proc_id);
1258 if (proc_id == DSP_UNIT) {
1259 /* Use all available DSP address space after EXTMEM
1261 if (DSP_SUCCEEDED(status))
1262 status = cod_get_sym_value(cod_mgr, EXTEND,
1265 /* Reset DMM structs and add an initial free chunk */
1266 if (DSP_SUCCEEDED(status)) {
1268 dev_get_dmm_mgr(p_proc_object->hdev_obj,
1271 /* Set dw_ext_end to DMM START u8
1274 (dw_ext_end + 1) * DSPWORDSIZE;
1275 /* DMM memory is from EXT_END */
1276 status = dmm_create_tables(dmm_mgr,
1285 /* Restore the original argv[0] */
1287 user_args[0] = pargv0;
1288 if (DSP_SUCCEEDED(status)) {
1289 if (DSP_SUCCEEDED((*p_proc_object->intf_fxns->pfn_brd_status)
1290 (p_proc_object->hbridge_context, &brd_state))) {
1291 pr_info("%s: Processor Loaded %s\n", __func__, pargv0);
1292 kfree(drv_datap->base_img);
1293 drv_datap->base_img = kmalloc(strlen(pargv0) + 1,
1295 if (drv_datap->base_img)
1296 strncpy(drv_datap->base_img, pargv0,
1297 strlen(pargv0) + 1);
1300 DBC_ASSERT(brd_state == BRD_LOADED);
1305 if (DSP_FAILED(status))
1306 pr_err("%s: Processor failed to load\n", __func__);
1308 DBC_ENSURE((DSP_SUCCEEDED(status)
1309 && p_proc_object->proc_state == PROC_LOADED)
1310 || DSP_FAILED(status));
1311 #ifdef OPT_LOAD_TIME_INSTRUMENTATION
1312 do_gettimeofday(&tv2);
1313 if (tv2.tv_usec < tv1.tv_usec) {
1314 tv2.tv_usec += 1000000;
1317 dev_dbg(bridge, "%s: time to load %d sec and %d usec\n", __func__,
1318 tv2.tv_sec - tv1.tv_sec, tv2.tv_usec - tv1.tv_usec);
1324 * ======== proc_map ========
1326 * Maps a MPU buffer to DSP address space.
1328 int proc_map(void *hprocessor, void *pmpu_addr, u32 ul_size,
1329 void *req_addr, void **pp_map_addr, u32 ul_map_attr,
1330 struct process_context *pr_ctxt)
1334 struct dmm_object *dmm_mgr;
1337 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1338 struct dmm_map_object *map_obj;
1341 #ifdef CONFIG_TIDSPBRIDGE_CACHE_LINE_CHECK
1342 if ((ul_map_attr & BUFMODE_MASK) != RBUF) {
1343 if (!IS_ALIGNED((u32)pmpu_addr, DSP_CACHE_LINE) ||
1344 !IS_ALIGNED(ul_size, DSP_CACHE_LINE)) {
1345 pr_err("%s: not aligned: 0x%x (%d)\n", __func__,
1346 (u32)pmpu_addr, ul_size);
1352 /* Calculate the page-aligned PA, VA and size */
1353 va_align = PG_ALIGN_LOW((u32) req_addr, PG_SIZE4K);
1354 pa_align = PG_ALIGN_LOW((u32) pmpu_addr, PG_SIZE4K);
1355 size_align = PG_ALIGN_HIGH(ul_size + (u32) pmpu_addr - pa_align,
1358 if (!p_proc_object) {
1362 /* Critical section */
1363 mutex_lock(&proc_lock);
1364 dmm_get_handle(p_proc_object, &dmm_mgr);
1366 status = dmm_map_memory(dmm_mgr, va_align, size_align);
1370 /* Add mapping to the page tables. */
1371 if (DSP_SUCCEEDED(status)) {
1373 /* Mapped address = MSB of VA | LSB of PA */
1374 tmp_addr = (va_align | ((u32) pmpu_addr & (PG_SIZE4K - 1)));
1375 /* mapped memory resource tracking */
1376 map_obj = add_mapping_info(pr_ctxt, pa_align, tmp_addr,
1381 status = (*p_proc_object->intf_fxns->pfn_brd_mem_map)
1382 (p_proc_object->hbridge_context, pa_align, va_align,
1383 size_align, ul_map_attr, map_obj->pages);
1385 if (DSP_SUCCEEDED(status)) {
1386 /* Mapped address = MSB of VA | LSB of PA */
1387 *pp_map_addr = (void *) tmp_addr;
1389 remove_mapping_information(pr_ctxt, tmp_addr, size_align);
1390 dmm_un_map_memory(dmm_mgr, va_align, &size_align);
1392 mutex_unlock(&proc_lock);
1394 if (DSP_FAILED(status))
1398 dev_dbg(bridge, "%s: hprocessor %p, pmpu_addr %p, ul_size %x, "
1399 "req_addr %p, ul_map_attr %x, pp_map_addr %p, va_align %x, "
1400 "pa_align %x, size_align %x status 0x%x\n", __func__,
1401 hprocessor, pmpu_addr, ul_size, req_addr, ul_map_attr,
1402 pp_map_addr, va_align, pa_align, size_align, status);
1408 * ======== proc_register_notify ========
1410 * Register to be notified of specific processor events.
1412 int proc_register_notify(void *hprocessor, u32 event_mask,
1413 u32 notify_type, struct dsp_notification
1417 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1418 struct deh_mgr *hdeh_mgr;
1420 DBC_REQUIRE(hnotification != NULL);
1421 DBC_REQUIRE(refs > 0);
1423 /* Check processor handle */
1424 if (!p_proc_object) {
1428 /* Check if event mask is a valid processor related event */
1429 if (event_mask & ~(DSP_PROCESSORSTATECHANGE | DSP_PROCESSORATTACH |
1430 DSP_PROCESSORDETACH | DSP_PROCESSORRESTART |
1431 DSP_MMUFAULT | DSP_SYSERROR | DSP_PWRERROR |
1435 /* Check if notify type is valid */
1436 if (notify_type != DSP_SIGNALEVENT)
1439 if (DSP_SUCCEEDED(status)) {
1440 /* If event mask is not DSP_SYSERROR, DSP_MMUFAULT,
1441 * or DSP_PWRERROR then register event immediately. */
1443 ~(DSP_SYSERROR | DSP_MMUFAULT | DSP_PWRERROR |
1445 status = ntfy_register(p_proc_object->ntfy_obj,
1446 hnotification, event_mask,
1448 /* Special case alert, special case alert!
1449 * If we're trying to *deregister* (i.e. event_mask
1450 * is 0), a DSP_SYSERROR or DSP_MMUFAULT notification,
1451 * we have to deregister with the DEH manager.
1452 * There's no way to know, based on event_mask which
1453 * manager the notification event was registered with,
1454 * so if we're trying to deregister and ntfy_register
1455 * failed, we'll give the deh manager a shot.
1457 if ((event_mask == 0) && DSP_FAILED(status)) {
1459 dev_get_deh_mgr(p_proc_object->hdev_obj,
1462 bridge_deh_register_notify(hdeh_mgr,
1468 status = dev_get_deh_mgr(p_proc_object->hdev_obj,
1471 bridge_deh_register_notify(hdeh_mgr,
1483 * ======== proc_reserve_memory ========
1485 * Reserve a virtually contiguous region of DSP address space.
1487 int proc_reserve_memory(void *hprocessor, u32 ul_size,
1489 struct process_context *pr_ctxt)
1491 struct dmm_object *dmm_mgr;
1493 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1494 struct dmm_rsv_object *rsv_obj;
1496 if (!p_proc_object) {
1501 status = dmm_get_handle(p_proc_object, &dmm_mgr);
1507 status = dmm_reserve_memory(dmm_mgr, ul_size, (u32 *) pp_rsv_addr);
1512 * A successful reserve should be followed by insertion of rsv_obj
1513 * into dmm_rsv_list, so that reserved memory resource tracking
1516 rsv_obj = kmalloc(sizeof(struct dmm_rsv_object), GFP_KERNEL);
1518 rsv_obj->dsp_reserved_addr = (u32) *pp_rsv_addr;
1519 spin_lock(&pr_ctxt->dmm_rsv_lock);
1520 list_add(&rsv_obj->link, &pr_ctxt->dmm_rsv_list);
1521 spin_unlock(&pr_ctxt->dmm_rsv_lock);
1525 dev_dbg(bridge, "%s: hprocessor: 0x%p ul_size: 0x%x pp_rsv_addr: 0x%p "
1526 "status 0x%x\n", __func__, hprocessor,
1527 ul_size, pp_rsv_addr, status);
1532 * ======== proc_start ========
1534 * Start a processor running.
1536 int proc_start(void *hprocessor)
1539 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1540 struct cod_manager *cod_mgr; /* Code manager handle */
1541 u32 dw_dsp_addr; /* Loaded code's entry point. */
1544 DBC_REQUIRE(refs > 0);
1545 if (!p_proc_object) {
1549 /* Call the bridge_brd_start */
1550 if (p_proc_object->proc_state != PROC_LOADED) {
1554 status = dev_get_cod_mgr(p_proc_object->hdev_obj, &cod_mgr);
1560 status = cod_get_entry(cod_mgr, &dw_dsp_addr);
1561 if (DSP_FAILED(status))
1564 status = (*p_proc_object->intf_fxns->pfn_brd_start)
1565 (p_proc_object->hbridge_context, dw_dsp_addr);
1566 if (DSP_FAILED(status))
1569 /* Call dev_create2 */
1570 status = dev_create2(p_proc_object->hdev_obj);
1571 if (DSP_SUCCEEDED(status)) {
1572 p_proc_object->proc_state = PROC_RUNNING;
1573 /* Deep sleep switces off the peripheral clocks.
1574 * we just put the DSP CPU in idle in the idle loop.
1575 * so there is no need to send a command to DSP */
1577 if (p_proc_object->ntfy_obj) {
1578 proc_notify_clients(p_proc_object,
1579 DSP_PROCESSORSTATECHANGE);
1582 /* Failed to Create Node Manager and DISP Object
1583 * Stop the Processor from running. Put it in STOPPED State */
1584 (void)(*p_proc_object->intf_fxns->
1585 pfn_brd_stop) (p_proc_object->hbridge_context);
1586 p_proc_object->proc_state = PROC_STOPPED;
1589 if (DSP_SUCCEEDED(status)) {
1590 if (DSP_SUCCEEDED((*p_proc_object->intf_fxns->pfn_brd_status)
1591 (p_proc_object->hbridge_context, &brd_state))) {
1592 pr_info("%s: dsp in running state\n", __func__);
1593 DBC_ASSERT(brd_state != BRD_HIBERNATION);
1596 pr_err("%s: Failed to start the dsp\n", __func__);
1600 DBC_ENSURE((DSP_SUCCEEDED(status) && p_proc_object->proc_state ==
1601 PROC_RUNNING) || DSP_FAILED(status));
1606 * ======== proc_stop ========
1608 * Stop a processor running.
1610 int proc_stop(void *hprocessor)
1613 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1614 struct msg_mgr *hmsg_mgr;
1615 struct node_mgr *hnode_mgr;
1617 u32 node_tab_size = 1;
1619 u32 nodes_allocated = 0;
1622 DBC_REQUIRE(refs > 0);
1623 if (!p_proc_object) {
1627 /* check if there are any running nodes */
1628 status = dev_get_node_manager(p_proc_object->hdev_obj, &hnode_mgr);
1629 if (DSP_SUCCEEDED(status) && hnode_mgr) {
1630 status = node_enum_nodes(hnode_mgr, &hnode, node_tab_size,
1631 &num_nodes, &nodes_allocated);
1632 if ((status == -EINVAL) || (nodes_allocated > 0)) {
1633 pr_err("%s: Can't stop device, active nodes = %d \n",
1634 __func__, nodes_allocated);
1638 /* Call the bridge_brd_stop */
1639 /* It is OK to stop a device that does n't have nodes OR not started */
1641 (*p_proc_object->intf_fxns->
1642 pfn_brd_stop) (p_proc_object->hbridge_context);
1643 if (DSP_SUCCEEDED(status)) {
1644 dev_dbg(bridge, "%s: processor in standby mode\n", __func__);
1645 p_proc_object->proc_state = PROC_STOPPED;
1646 /* Destory the Node Manager, msg_ctrl Manager */
1647 if (DSP_SUCCEEDED(dev_destroy2(p_proc_object->hdev_obj))) {
1648 /* Destroy the msg_ctrl by calling msg_delete */
1649 dev_get_msg_mgr(p_proc_object->hdev_obj, &hmsg_mgr);
1651 msg_delete(hmsg_mgr);
1652 dev_set_msg_mgr(p_proc_object->hdev_obj, NULL);
1656 intf_fxns->pfn_brd_status) (p_proc_object->
1659 DBC_ASSERT(brd_state == BRD_STOPPED);
1662 pr_err("%s: Failed to stop the processor\n", __func__);
1670 * ======== proc_un_map ========
1672 * Removes a MPU buffer mapping from the DSP address space.
1674 int proc_un_map(void *hprocessor, void *map_addr,
1675 struct process_context *pr_ctxt)
1678 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1679 struct dmm_object *dmm_mgr;
1683 va_align = PG_ALIGN_LOW((u32) map_addr, PG_SIZE4K);
1684 if (!p_proc_object) {
1689 status = dmm_get_handle(hprocessor, &dmm_mgr);
1695 /* Critical section */
1696 mutex_lock(&proc_lock);
1698 * Update DMM structures. Get the size to unmap.
1699 * This function returns error if the VA is not mapped
1701 status = dmm_un_map_memory(dmm_mgr, (u32) va_align, &size_align);
1702 /* Remove mapping from the page tables. */
1703 if (DSP_SUCCEEDED(status)) {
1704 status = (*p_proc_object->intf_fxns->pfn_brd_mem_un_map)
1705 (p_proc_object->hbridge_context, va_align, size_align);
1708 mutex_unlock(&proc_lock);
1709 if (DSP_FAILED(status))
1713 * A successful unmap should be followed by removal of map_obj
1714 * from dmm_map_list, so that mapped memory resource tracking
1717 remove_mapping_information(pr_ctxt, (u32) map_addr, size_align);
1720 dev_dbg(bridge, "%s: hprocessor: 0x%p map_addr: 0x%p status: 0x%x\n",
1721 __func__, hprocessor, map_addr, status);
1726 * ======== proc_un_reserve_memory ========
1728 * Frees a previously reserved region of DSP address space.
1730 int proc_un_reserve_memory(void *hprocessor, void *prsv_addr,
1731 struct process_context *pr_ctxt)
1733 struct dmm_object *dmm_mgr;
1735 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1736 struct dmm_rsv_object *rsv_obj;
1738 if (!p_proc_object) {
1743 status = dmm_get_handle(p_proc_object, &dmm_mgr);
1749 status = dmm_un_reserve_memory(dmm_mgr, (u32) prsv_addr);
1754 * A successful unreserve should be followed by removal of rsv_obj
1755 * from dmm_rsv_list, so that reserved memory resource tracking
1758 spin_lock(&pr_ctxt->dmm_rsv_lock);
1759 list_for_each_entry(rsv_obj, &pr_ctxt->dmm_rsv_list, link) {
1760 if (rsv_obj->dsp_reserved_addr == (u32) prsv_addr) {
1761 list_del(&rsv_obj->link);
1766 spin_unlock(&pr_ctxt->dmm_rsv_lock);
1769 dev_dbg(bridge, "%s: hprocessor: 0x%p prsv_addr: 0x%p status: 0x%x\n",
1770 __func__, hprocessor, prsv_addr, status);
1775 * ======== = proc_monitor ======== ==
1777 * Place the Processor in Monitor State. This is an internal
1778 * function and a requirement before Processor is loaded.
1779 * This does a bridge_brd_stop, dev_destroy2 and bridge_brd_monitor.
1780 * In dev_destroy2 we delete the node manager.
1782 * p_proc_object: Pointer to Processor Object
1784 * 0: Processor placed in monitor mode.
1785 * !0: Failed to place processor in monitor mode.
1787 * Valid Processor Handle
1789 * Success: ProcObject state is PROC_IDLE
1791 static int proc_monitor(struct proc_object *proc_obj)
1793 int status = -EPERM;
1794 struct msg_mgr *hmsg_mgr;
1797 DBC_REQUIRE(refs > 0);
1798 DBC_REQUIRE(proc_obj);
1800 /* This is needed only when Device is loaded when it is
1801 * already 'ACTIVE' */
1802 /* Destory the Node Manager, msg_ctrl Manager */
1803 if (DSP_SUCCEEDED(dev_destroy2(proc_obj->hdev_obj))) {
1804 /* Destroy the msg_ctrl by calling msg_delete */
1805 dev_get_msg_mgr(proc_obj->hdev_obj, &hmsg_mgr);
1807 msg_delete(hmsg_mgr);
1808 dev_set_msg_mgr(proc_obj->hdev_obj, NULL);
1811 /* Place the Board in the Monitor State */
1812 if (DSP_SUCCEEDED((*proc_obj->intf_fxns->pfn_brd_monitor)
1813 (proc_obj->hbridge_context))) {
1815 if (DSP_SUCCEEDED((*proc_obj->intf_fxns->pfn_brd_status)
1816 (proc_obj->hbridge_context, &brd_state)))
1817 DBC_ASSERT(brd_state == BRD_IDLE);
1820 DBC_ENSURE((DSP_SUCCEEDED(status) && brd_state == BRD_IDLE) ||
1821 DSP_FAILED(status));
1826 * ======== get_envp_count ========
1828 * Return the number of elements in the envp array, including the
1829 * terminating NULL element.
1831 static s32 get_envp_count(char **envp)
1838 ret += 1; /* Include the terminating NULL in the count. */
1845 * ======== prepend_envp ========
1847 * Prepend an environment variable=value pair to the new envp array, and
1848 * copy in the existing var=value pairs in the old envp array.
1850 static char **prepend_envp(char **new_envp, char **envp, s32 envp_elems,
1851 s32 cnew_envp, char *sz_var)
1853 char **pp_envp = new_envp;
1855 DBC_REQUIRE(new_envp);
1857 /* Prepend new environ var=value string */
1858 *new_envp++ = sz_var;
1860 /* Copy user's environment into our own. */
1861 while (envp_elems--)
1862 *new_envp++ = *envp++;
1864 /* Ensure NULL terminates the new environment strings array. */
1865 if (envp_elems == 0)
1872 * ======== proc_notify_clients ========
1874 * Notify the processor the events.
1876 int proc_notify_clients(void *proc, u32 events)
1879 struct proc_object *p_proc_object = (struct proc_object *)proc;
1881 DBC_REQUIRE(p_proc_object);
1882 DBC_REQUIRE(IS_VALID_PROC_EVENT(events));
1883 DBC_REQUIRE(refs > 0);
1884 if (!p_proc_object) {
1889 ntfy_notify(p_proc_object->ntfy_obj, events);
1895 * ======== proc_notify_all_clients ========
1897 * Notify the processor the events. This includes notifying all clients
1898 * attached to a particulat DSP.
1900 int proc_notify_all_clients(void *proc, u32 events)
1903 struct proc_object *p_proc_object = (struct proc_object *)proc;
1905 DBC_REQUIRE(IS_VALID_PROC_EVENT(events));
1906 DBC_REQUIRE(refs > 0);
1908 if (!p_proc_object) {
1913 dev_notify_clients(p_proc_object->hdev_obj, events);
1920 * ======== proc_get_processor_id ========
1922 * Retrieves the processor ID.
1924 int proc_get_processor_id(void *proc, u32 * proc_id)
1927 struct proc_object *p_proc_object = (struct proc_object *)proc;
1930 *proc_id = p_proc_object->processor_id;