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 #include <linux/types.h>
20 /* ------------------------------------ Host OS */
21 #include <linux/dma-mapping.h>
22 #include <linux/scatterlist.h>
23 #include <dspbridge/host_os.h>
25 /* ----------------------------------- DSP/BIOS Bridge */
26 #include <dspbridge/dbdefs.h>
28 /* ----------------------------------- Trace & Debug */
29 #include <dspbridge/dbc.h>
31 /* ----------------------------------- OS Adaptation Layer */
32 #include <dspbridge/list.h>
33 #include <dspbridge/ntfy.h>
34 #include <dspbridge/sync.h>
35 /* ----------------------------------- Bridge Driver */
36 #include <dspbridge/dspdefs.h>
37 #include <dspbridge/dspdeh.h>
38 /* ----------------------------------- Platform Manager */
39 #include <dspbridge/cod.h>
40 #include <dspbridge/dev.h>
41 #include <dspbridge/procpriv.h>
42 #include <dspbridge/dmm.h>
44 /* ----------------------------------- Resource Manager */
45 #include <dspbridge/mgr.h>
46 #include <dspbridge/node.h>
47 #include <dspbridge/nldr.h>
48 #include <dspbridge/rmm.h>
50 /* ----------------------------------- Others */
51 #include <dspbridge/dbdcd.h>
52 #include <dspbridge/msg.h>
53 #include <dspbridge/dspioctl.h>
54 #include <dspbridge/drv.h>
56 /* ----------------------------------- This */
57 #include <dspbridge/proc.h>
58 #include <dspbridge/pwr.h>
60 #include <dspbridge/resourcecleanup.h>
61 /* ----------------------------------- Defines, Data Structures, Typedefs */
62 #define MAXCMDLINELEN 255
63 #define PROC_ENVPROCID "PROC_ID=%d"
64 #define MAXPROCIDLEN (8 + 5)
65 #define PROC_DFLT_TIMEOUT 10000 /* Time out in milliseconds */
66 #define PWR_TIMEOUT 500 /* Sleep/wake timout in msec */
67 #define EXTEND "_EXT_END" /* Extmem end addr in DSP binary */
69 #define DSP_CACHE_LINE 128
71 #define BUFMODE_MASK (3 << 14)
73 /* Buffer modes from DSP perspective */
74 #define RBUF 0x4000 /* Input buffer */
75 #define WBUF 0x8000 /* Output Buffer */
77 extern struct device *bridge;
79 /* ----------------------------------- Globals */
81 /* The proc_object structure. */
83 struct list_head link; /* Link to next proc_object */
84 struct dev_object *hdev_obj; /* Device this PROC represents */
85 u32 process; /* Process owning this Processor */
86 struct mgr_object *hmgr_obj; /* Manager Object Handle */
87 u32 attach_count; /* Processor attach count */
88 u32 processor_id; /* Processor number */
89 u32 utimeout; /* Time out count */
90 enum dsp_procstate proc_state; /* Processor state */
91 u32 ul_unit; /* DDSP unit number */
92 bool is_already_attached; /*
93 * True if the Device below has
96 struct ntfy_object *ntfy_obj; /* Manages notifications */
97 /* Bridge Context Handle */
98 struct bridge_dev_context *hbridge_context;
99 /* Function interface to Bridge driver */
100 struct bridge_drv_interface *intf_fxns;
102 struct list_head proc_list;
107 DEFINE_MUTEX(proc_lock); /* For critical sections */
109 /* ----------------------------------- Function Prototypes */
110 static int proc_monitor(struct proc_object *proc_obj);
111 static s32 get_envp_count(char **envp);
112 static char **prepend_envp(char **new_envp, char **envp, s32 envp_elems,
113 s32 cnew_envp, char *sz_var);
115 /* remember mapping information */
116 static struct dmm_map_object *add_mapping_info(struct process_context *pr_ctxt,
117 u32 mpu_addr, u32 dsp_addr, u32 size)
119 struct dmm_map_object *map_obj;
121 u32 num_usr_pgs = size / PG_SIZE4K;
123 pr_debug("%s: adding map info: mpu_addr 0x%x virt 0x%x size 0x%x\n",
127 map_obj = kzalloc(sizeof(struct dmm_map_object), GFP_KERNEL);
129 pr_err("%s: kzalloc failed\n", __func__);
132 INIT_LIST_HEAD(&map_obj->link);
134 map_obj->pages = kcalloc(num_usr_pgs, sizeof(struct page *),
136 if (!map_obj->pages) {
137 pr_err("%s: kzalloc failed\n", __func__);
142 map_obj->mpu_addr = mpu_addr;
143 map_obj->dsp_addr = dsp_addr;
144 map_obj->size = size;
145 map_obj->num_usr_pgs = num_usr_pgs;
147 spin_lock(&pr_ctxt->dmm_map_lock);
148 list_add(&map_obj->link, &pr_ctxt->dmm_map_list);
149 spin_unlock(&pr_ctxt->dmm_map_lock);
154 static int match_exact_map_obj(struct dmm_map_object *map_obj,
155 u32 dsp_addr, u32 size)
157 if (map_obj->dsp_addr == dsp_addr && map_obj->size != size)
158 pr_err("%s: addr match (0x%x), size don't (0x%x != 0x%x)\n",
159 __func__, dsp_addr, map_obj->size, size);
161 return map_obj->dsp_addr == dsp_addr &&
162 map_obj->size == size;
165 static void remove_mapping_information(struct process_context *pr_ctxt,
166 u32 dsp_addr, u32 size)
168 struct dmm_map_object *map_obj;
170 pr_debug("%s: looking for virt 0x%x size 0x%x\n", __func__,
173 spin_lock(&pr_ctxt->dmm_map_lock);
174 list_for_each_entry(map_obj, &pr_ctxt->dmm_map_list, link) {
175 pr_debug("%s: candidate: mpu_addr 0x%x virt 0x%x size 0x%x\n",
181 if (match_exact_map_obj(map_obj, dsp_addr, size)) {
182 pr_debug("%s: match, deleting map info\n", __func__);
183 list_del(&map_obj->link);
184 kfree(map_obj->dma_info.sg);
185 kfree(map_obj->pages);
189 pr_debug("%s: candidate didn't match\n", __func__);
192 pr_err("%s: failed to find given map info\n", __func__);
194 spin_unlock(&pr_ctxt->dmm_map_lock);
197 static int match_containing_map_obj(struct dmm_map_object *map_obj,
198 u32 mpu_addr, u32 size)
200 u32 map_obj_end = map_obj->mpu_addr + map_obj->size;
202 return mpu_addr >= map_obj->mpu_addr &&
203 mpu_addr + size <= map_obj_end;
206 static struct dmm_map_object *find_containing_mapping(
207 struct process_context *pr_ctxt,
208 u32 mpu_addr, u32 size)
210 struct dmm_map_object *map_obj;
211 pr_debug("%s: looking for mpu_addr 0x%x size 0x%x\n", __func__,
214 spin_lock(&pr_ctxt->dmm_map_lock);
215 list_for_each_entry(map_obj, &pr_ctxt->dmm_map_list, link) {
216 pr_debug("%s: candidate: mpu_addr 0x%x virt 0x%x size 0x%x\n",
221 if (match_containing_map_obj(map_obj, mpu_addr, size)) {
222 pr_debug("%s: match!\n", __func__);
226 pr_debug("%s: no match!\n", __func__);
231 spin_unlock(&pr_ctxt->dmm_map_lock);
235 static int find_first_page_in_cache(struct dmm_map_object *map_obj,
236 unsigned long mpu_addr)
238 u32 mapped_base_page = map_obj->mpu_addr >> PAGE_SHIFT;
239 u32 requested_base_page = mpu_addr >> PAGE_SHIFT;
240 int pg_index = requested_base_page - mapped_base_page;
242 if (pg_index < 0 || pg_index >= map_obj->num_usr_pgs) {
243 pr_err("%s: failed (got %d)\n", __func__, pg_index);
247 pr_debug("%s: first page is %d\n", __func__, pg_index);
251 static inline struct page *get_mapping_page(struct dmm_map_object *map_obj,
254 pr_debug("%s: looking for pg_i %d, num_usr_pgs: %d\n", __func__,
255 pg_i, map_obj->num_usr_pgs);
257 if (pg_i < 0 || pg_i >= map_obj->num_usr_pgs) {
258 pr_err("%s: requested pg_i %d is out of mapped range\n",
263 return map_obj->pages[pg_i];
267 * ======== proc_attach ========
269 * Prepare for communication with a particular DSP processor, and return
270 * a handle to the processor object.
273 proc_attach(u32 processor_id,
274 const struct dsp_processorattrin *attr_in,
275 void **ph_processor, struct process_context *pr_ctxt)
278 struct dev_object *hdev_obj;
279 struct proc_object *p_proc_object = NULL;
280 struct mgr_object *hmgr_obj = NULL;
281 struct drv_object *hdrv_obj = NULL;
282 struct drv_data *drv_datap = dev_get_drvdata(bridge);
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 if (!drv_datap || !drv_datap->drv_object || !drv_datap->mgr_object) {
296 pr_err("%s: Failed to get object handles\n", __func__);
298 hdrv_obj = drv_datap->drv_object;
299 hmgr_obj = drv_datap->mgr_object;
303 /* Get the Device Object */
304 status = drv_get_dev_object(processor_id, hdrv_obj, &hdev_obj);
307 status = dev_get_dev_type(hdev_obj, &dev_type);
312 /* If we made it this far, create the Proceesor object: */
313 p_proc_object = kzalloc(sizeof(struct proc_object), GFP_KERNEL);
314 /* Fill out the Processor Object: */
315 if (p_proc_object == NULL) {
319 p_proc_object->hdev_obj = hdev_obj;
320 p_proc_object->hmgr_obj = hmgr_obj;
321 p_proc_object->processor_id = dev_type;
322 /* Store TGID instead of process handle */
323 p_proc_object->process = current->tgid;
325 INIT_LIST_HEAD(&p_proc_object->proc_list);
328 p_proc_object->utimeout = attr_in->utimeout;
330 p_proc_object->utimeout = PROC_DFLT_TIMEOUT;
332 status = dev_get_intf_fxns(hdev_obj, &p_proc_object->intf_fxns);
334 status = dev_get_bridge_context(hdev_obj,
335 &p_proc_object->hbridge_context);
337 kfree(p_proc_object);
339 kfree(p_proc_object);
344 /* Create the Notification Object */
345 /* This is created with no event mask, no notify mask
346 * and no valid handle to the notification. They all get
347 * filled up when proc_register_notify is called */
348 p_proc_object->ntfy_obj = kmalloc(sizeof(struct ntfy_object),
350 if (p_proc_object->ntfy_obj)
351 ntfy_init(p_proc_object->ntfy_obj);
356 /* Insert the Processor Object into the DEV List.
357 * Return handle to this Processor Object:
358 * Find out if the Device is already attached to a
359 * Processor. If so, return AlreadyAttached status */
360 lst_init_elem(&p_proc_object->link);
361 status = dev_insert_proc_object(p_proc_object->hdev_obj,
364 is_already_attached);
366 if (p_proc_object->is_already_attached)
369 if (p_proc_object->ntfy_obj) {
370 ntfy_delete(p_proc_object->ntfy_obj);
371 kfree(p_proc_object->ntfy_obj);
374 kfree(p_proc_object);
377 *ph_processor = (void *)p_proc_object;
378 pr_ctxt->hprocessor = *ph_processor;
379 (void)proc_notify_clients(p_proc_object,
380 DSP_PROCESSORATTACH);
383 /* Don't leak memory if status is failed */
384 kfree(p_proc_object);
387 DBC_ENSURE((status == -EPERM && *ph_processor == NULL) ||
388 (!status && p_proc_object) ||
389 (status == 0 && p_proc_object));
394 static int get_exec_file(struct cfg_devnode *dev_node_obj,
395 struct dev_object *hdev_obj,
396 u32 size, char *exec_file)
400 struct drv_data *drv_datap = dev_get_drvdata(bridge);
402 dev_get_dev_type(hdev_obj, (u8 *) &dev_type);
407 if (dev_type == DSP_UNIT) {
408 if (!drv_datap || !drv_datap->base_img)
411 if (strlen(drv_datap->base_img) > size)
414 strcpy(exec_file, drv_datap->base_img);
415 } else if (dev_type == IVA_UNIT && iva_img) {
416 len = strlen(iva_img);
417 strncpy(exec_file, iva_img, len + 1);
426 * ======== proc_auto_start ======== =
428 * A Particular device gets loaded with the default image
429 * if the AutoStart flag is set.
431 * hdev_obj: Handle to the Device
433 * 0: On Successful Loading
434 * -EPERM General Failure
439 int proc_auto_start(struct cfg_devnode *dev_node_obj,
440 struct dev_object *hdev_obj)
443 struct proc_object *p_proc_object;
444 char sz_exec_file[MAXCMDLINELEN];
446 struct mgr_object *hmgr_obj = NULL;
447 struct drv_data *drv_datap = dev_get_drvdata(bridge);
450 DBC_REQUIRE(refs > 0);
451 DBC_REQUIRE(dev_node_obj != NULL);
452 DBC_REQUIRE(hdev_obj != NULL);
454 /* Create a Dummy PROC Object */
455 if (!drv_datap || !drv_datap->mgr_object) {
457 pr_err("%s: Failed to retrieve the object handle\n", __func__);
460 hmgr_obj = drv_datap->mgr_object;
463 p_proc_object = kzalloc(sizeof(struct proc_object), GFP_KERNEL);
464 if (p_proc_object == NULL) {
468 p_proc_object->hdev_obj = hdev_obj;
469 p_proc_object->hmgr_obj = hmgr_obj;
470 status = dev_get_intf_fxns(hdev_obj, &p_proc_object->intf_fxns);
472 status = dev_get_bridge_context(hdev_obj,
473 &p_proc_object->hbridge_context);
477 /* Stop the Device, put it into standby mode */
478 status = proc_stop(p_proc_object);
483 /* Get the default executable for this board... */
484 dev_get_dev_type(hdev_obj, (u8 *) &dev_type);
485 p_proc_object->processor_id = dev_type;
486 status = get_exec_file(dev_node_obj, hdev_obj, sizeof(sz_exec_file),
489 argv[0] = sz_exec_file;
491 /* ...and try to load it: */
492 status = proc_load(p_proc_object, 1, (const char **)argv, NULL);
494 status = proc_start(p_proc_object);
496 kfree(p_proc_object->psz_last_coff);
497 p_proc_object->psz_last_coff = NULL;
499 kfree(p_proc_object);
505 * ======== proc_ctrl ========
507 * Pass control information to the GPP device driver managing the
510 * This will be an OEM-only function, and not part of the DSP/BIOS Bridge
511 * application developer's API.
512 * Call the bridge_dev_ctrl fxn with the Argument. This is a Synchronous
513 * Operation. arg can be null.
515 int proc_ctrl(void *hprocessor, u32 dw_cmd, struct dsp_cbdata * arg)
518 struct proc_object *p_proc_object = hprocessor;
521 DBC_REQUIRE(refs > 0);
524 /* intercept PWR deep sleep command */
525 if (dw_cmd == BRDIOCTL_DEEPSLEEP) {
526 timeout = arg->cb_data;
527 status = pwr_sleep_dsp(PWR_DEEPSLEEP, timeout);
529 /* intercept PWR emergency sleep command */
530 else if (dw_cmd == BRDIOCTL_EMERGENCYSLEEP) {
531 timeout = arg->cb_data;
532 status = pwr_sleep_dsp(PWR_EMERGENCYDEEPSLEEP, timeout);
533 } else if (dw_cmd == PWR_DEEPSLEEP) {
534 /* timeout = arg->cb_data; */
535 status = pwr_sleep_dsp(PWR_DEEPSLEEP, timeout);
537 /* intercept PWR wake commands */
538 else if (dw_cmd == BRDIOCTL_WAKEUP) {
539 timeout = arg->cb_data;
540 status = pwr_wake_dsp(timeout);
541 } else if (dw_cmd == PWR_WAKEUP) {
542 /* timeout = arg->cb_data; */
543 status = pwr_wake_dsp(timeout);
545 if (!((*p_proc_object->intf_fxns->pfn_dev_cntrl)
546 (p_proc_object->hbridge_context, dw_cmd,
560 * ======== proc_detach ========
562 * Destroys the Processor Object. Removes the notification from the Dev
565 int proc_detach(struct process_context *pr_ctxt)
568 struct proc_object *p_proc_object = NULL;
570 DBC_REQUIRE(refs > 0);
572 p_proc_object = (struct proc_object *)pr_ctxt->hprocessor;
575 /* Notify the Client */
576 ntfy_notify(p_proc_object->ntfy_obj, DSP_PROCESSORDETACH);
577 /* Remove the notification memory */
578 if (p_proc_object->ntfy_obj) {
579 ntfy_delete(p_proc_object->ntfy_obj);
580 kfree(p_proc_object->ntfy_obj);
583 kfree(p_proc_object->psz_last_coff);
584 p_proc_object->psz_last_coff = NULL;
585 /* Remove the Proc from the DEV List */
586 (void)dev_remove_proc_object(p_proc_object->hdev_obj,
587 (u32) p_proc_object);
588 /* Free the Processor Object */
589 kfree(p_proc_object);
590 pr_ctxt->hprocessor = NULL;
599 * ======== proc_enum_nodes ========
601 * Enumerate and get configuration information about nodes allocated
602 * on a DSP processor.
604 int proc_enum_nodes(void *hprocessor, void **node_tab,
605 u32 node_tab_size, u32 *pu_num_nodes,
609 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
610 struct node_mgr *hnode_mgr = NULL;
612 DBC_REQUIRE(refs > 0);
613 DBC_REQUIRE(node_tab != NULL || node_tab_size == 0);
614 DBC_REQUIRE(pu_num_nodes != NULL);
615 DBC_REQUIRE(pu_allocated != NULL);
618 if (!(dev_get_node_manager(p_proc_object->hdev_obj,
621 status = node_enum_nodes(hnode_mgr, node_tab,
634 /* Cache operation against kernel address instead of users */
635 static int build_dma_sg(struct dmm_map_object *map_obj, unsigned long start,
636 ssize_t len, int pg_i)
639 unsigned long offset;
642 struct scatterlist *sg = map_obj->dma_info.sg;
645 page = get_mapping_page(map_obj, pg_i);
647 pr_err("%s: no page for %08lx\n", __func__, start);
650 } else if (IS_ERR(page)) {
651 pr_err("%s: err page for %08lx(%lu)\n", __func__, start,
657 offset = start & ~PAGE_MASK;
658 rest = min_t(ssize_t, PAGE_SIZE - offset, len);
660 sg_set_page(&sg[i], page, rest, offset);
667 if (i != map_obj->dma_info.num_pages) {
668 pr_err("%s: bad number of sg iterations\n", __func__);
677 static int memory_regain_ownership(struct dmm_map_object *map_obj,
678 unsigned long start, ssize_t len, enum dma_data_direction dir)
681 unsigned long first_data_page = start >> PAGE_SHIFT;
682 unsigned long last_data_page = ((u32)(start + len - 1) >> PAGE_SHIFT);
683 /* calculating the number of pages this area spans */
684 unsigned long num_pages = last_data_page - first_data_page + 1;
685 struct bridge_dma_map_info *dma_info = &map_obj->dma_info;
690 if (dma_info->dir != dir || dma_info->num_pages != num_pages) {
691 pr_err("%s: dma info doesn't match given params\n", __func__);
695 dma_unmap_sg(bridge, dma_info->sg, num_pages, dma_info->dir);
697 pr_debug("%s: dma_map_sg unmapped\n", __func__);
701 map_obj->dma_info.sg = NULL;
707 /* Cache operation against kernel address instead of users */
708 static int memory_give_ownership(struct dmm_map_object *map_obj,
709 unsigned long start, ssize_t len, enum dma_data_direction dir)
711 int pg_i, ret, sg_num;
712 struct scatterlist *sg;
713 unsigned long first_data_page = start >> PAGE_SHIFT;
714 unsigned long last_data_page = ((u32)(start + len - 1) >> PAGE_SHIFT);
715 /* calculating the number of pages this area spans */
716 unsigned long num_pages = last_data_page - first_data_page + 1;
718 pg_i = find_first_page_in_cache(map_obj, start);
720 pr_err("%s: failed to find first page in cache\n", __func__);
725 sg = kcalloc(num_pages, sizeof(*sg), GFP_KERNEL);
727 pr_err("%s: kcalloc failed\n", __func__);
732 sg_init_table(sg, num_pages);
734 /* cleanup a previous sg allocation */
735 /* this may happen if application doesn't signal for e/o DMA */
736 kfree(map_obj->dma_info.sg);
738 map_obj->dma_info.sg = sg;
739 map_obj->dma_info.dir = dir;
740 map_obj->dma_info.num_pages = num_pages;
742 ret = build_dma_sg(map_obj, start, len, pg_i);
746 sg_num = dma_map_sg(bridge, sg, num_pages, dir);
748 pr_err("%s: dma_map_sg failed: %d\n", __func__, sg_num);
753 pr_debug("%s: dma_map_sg mapped %d elements\n", __func__, sg_num);
754 map_obj->dma_info.sg_num = sg_num;
760 map_obj->dma_info.sg = NULL;
765 int proc_begin_dma(void *hprocessor, void *pmpu_addr, u32 ul_size,
766 enum dma_data_direction dir)
768 /* Keep STATUS here for future additions to this function */
770 struct process_context *pr_ctxt = (struct process_context *) hprocessor;
771 struct dmm_map_object *map_obj;
773 DBC_REQUIRE(refs > 0);
780 pr_debug("%s: addr 0x%x, size 0x%x, type %d\n", __func__,
784 /* find requested memory are in cached mapping information */
785 map_obj = find_containing_mapping(pr_ctxt, (u32) pmpu_addr, ul_size);
787 pr_err("%s: find_containing_mapping failed\n", __func__);
792 if (memory_give_ownership(map_obj, (u32) pmpu_addr, ul_size, dir)) {
793 pr_err("%s: InValid address parameters %p %x\n",
794 __func__, pmpu_addr, ul_size);
803 int proc_end_dma(void *hprocessor, void *pmpu_addr, u32 ul_size,
804 enum dma_data_direction dir)
806 /* Keep STATUS here for future additions to this function */
808 struct process_context *pr_ctxt = (struct process_context *) hprocessor;
809 struct dmm_map_object *map_obj;
811 DBC_REQUIRE(refs > 0);
818 pr_debug("%s: addr 0x%x, size 0x%x, type %d\n", __func__,
822 /* find requested memory are in cached mapping information */
823 map_obj = find_containing_mapping(pr_ctxt, (u32) pmpu_addr, ul_size);
825 pr_err("%s: find_containing_mapping failed\n", __func__);
830 if (memory_regain_ownership(map_obj, (u32) pmpu_addr, ul_size, dir)) {
831 pr_err("%s: InValid address parameters %p %x\n",
832 __func__, pmpu_addr, ul_size);
842 * ======== proc_flush_memory ========
846 int proc_flush_memory(void *hprocessor, void *pmpu_addr,
847 u32 ul_size, u32 ul_flags)
849 enum dma_data_direction dir = DMA_BIDIRECTIONAL;
851 return proc_begin_dma(hprocessor, pmpu_addr, ul_size, dir);
855 * ======== proc_invalidate_memory ========
857 * Invalidates the memory specified
859 int proc_invalidate_memory(void *hprocessor, void *pmpu_addr, u32 size)
861 enum dma_data_direction dir = DMA_FROM_DEVICE;
863 return proc_begin_dma(hprocessor, pmpu_addr, size, dir);
867 * ======== proc_get_resource_info ========
869 * Enumerate the resources currently available on a processor.
871 int proc_get_resource_info(void *hprocessor, u32 resource_type,
872 struct dsp_resourceinfo *resource_info,
873 u32 resource_info_size)
876 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
877 struct node_mgr *hnode_mgr = NULL;
878 struct nldr_object *nldr_obj = NULL;
879 struct rmm_target_obj *rmm = NULL;
880 struct io_mgr *hio_mgr = NULL; /* IO manager handle */
882 DBC_REQUIRE(refs > 0);
883 DBC_REQUIRE(resource_info != NULL);
884 DBC_REQUIRE(resource_info_size >= sizeof(struct dsp_resourceinfo));
886 if (!p_proc_object) {
890 switch (resource_type) {
891 case DSP_RESOURCE_DYNDARAM:
892 case DSP_RESOURCE_DYNSARAM:
893 case DSP_RESOURCE_DYNEXTERNAL:
894 case DSP_RESOURCE_DYNSRAM:
895 status = dev_get_node_manager(p_proc_object->hdev_obj,
902 status = node_get_nldr_obj(hnode_mgr, &nldr_obj);
904 status = nldr_get_rmm_manager(nldr_obj, &rmm);
907 (enum dsp_memtype)resource_type,
908 (struct dsp_memstat *)
909 &(resource_info->result.
917 case DSP_RESOURCE_PROCLOAD:
918 status = dev_get_io_mgr(p_proc_object->hdev_obj, &hio_mgr);
921 p_proc_object->intf_fxns->
922 pfn_io_get_proc_load(hio_mgr,
923 (struct dsp_procloadstat *)
924 &(resource_info->result.
938 * ======== proc_exit ========
940 * Decrement reference count, and free resources when reference count is
945 DBC_REQUIRE(refs > 0);
949 DBC_ENSURE(refs >= 0);
953 * ======== proc_get_dev_object ========
955 * Return the Dev Object handle for a given Processor.
958 int proc_get_dev_object(void *hprocessor,
959 struct dev_object **device_obj)
962 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
964 DBC_REQUIRE(refs > 0);
965 DBC_REQUIRE(device_obj != NULL);
968 *device_obj = p_proc_object->hdev_obj;
975 DBC_ENSURE((!status && *device_obj != NULL) ||
976 (status && *device_obj == NULL));
982 * ======== proc_get_state ========
984 * Report the state of the specified DSP processor.
986 int proc_get_state(void *hprocessor,
987 struct dsp_processorstate *proc_state_obj,
991 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
994 DBC_REQUIRE(refs > 0);
995 DBC_REQUIRE(proc_state_obj != NULL);
996 DBC_REQUIRE(state_info_size >= sizeof(struct dsp_processorstate));
999 /* First, retrieve BRD state information */
1000 status = (*p_proc_object->intf_fxns->pfn_brd_status)
1001 (p_proc_object->hbridge_context, &brd_status);
1003 switch (brd_status) {
1005 proc_state_obj->proc_state = PROC_STOPPED;
1007 case BRD_SLEEP_TRANSITION:
1008 case BRD_DSP_HIBERNATION:
1011 proc_state_obj->proc_state = PROC_RUNNING;
1014 proc_state_obj->proc_state = PROC_LOADED;
1017 proc_state_obj->proc_state = PROC_ERROR;
1020 proc_state_obj->proc_state = 0xFF;
1028 dev_dbg(bridge, "%s, results: status: 0x%x proc_state_obj: 0x%x\n",
1029 __func__, status, proc_state_obj->proc_state);
1034 * ======== proc_get_trace ========
1036 * Retrieve the current contents of the trace buffer, located on the
1037 * Processor. Predefined symbols for the trace buffer must have been
1038 * configured into the DSP executable.
1040 * We support using the symbols SYS_PUTCBEG and SYS_PUTCEND to define a
1041 * trace buffer, only. Treat it as an undocumented feature.
1042 * This call is destructive, meaning the processor is placed in the monitor
1043 * state as a result of this function.
1045 int proc_get_trace(void *hprocessor, u8 * pbuf, u32 max_size)
1053 * ======== proc_init ========
1055 * Initialize PROC's private state, keeping a reference count on each call
1057 bool proc_init(void)
1061 DBC_REQUIRE(refs >= 0);
1066 DBC_ENSURE((ret && (refs > 0)) || (!ret && (refs >= 0)));
1072 * ======== proc_load ========
1074 * Reset a processor and load a new base program image.
1075 * This will be an OEM-only function, and not part of the DSP/BIOS Bridge
1076 * application developer's API.
1078 int proc_load(void *hprocessor, const s32 argc_index,
1079 const char **user_args, const char **user_envp)
1082 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1083 struct io_mgr *hio_mgr; /* IO manager handle */
1084 struct msg_mgr *hmsg_mgr;
1085 struct cod_manager *cod_mgr; /* Code manager handle */
1086 char *pargv0; /* temp argv[0] ptr */
1087 char **new_envp; /* Updated envp[] array. */
1088 char sz_proc_id[MAXPROCIDLEN]; /* Size of "PROC_ID=<n>" */
1089 s32 envp_elems; /* Num elements in envp[]. */
1090 s32 cnew_envp; /* " " in new_envp[] */
1091 s32 nproc_id = 0; /* Anticipate MP version. */
1092 struct dcd_manager *hdcd_handle;
1093 struct dmm_object *dmm_mgr;
1097 struct drv_data *drv_datap = dev_get_drvdata(bridge);
1099 #ifdef OPT_LOAD_TIME_INSTRUMENTATION
1104 #if defined(CONFIG_TIDSPBRIDGE_DVFS) && !defined(CONFIG_CPU_FREQ)
1105 struct dspbridge_platform_data *pdata =
1106 omap_dspbridge_dev->dev.platform_data;
1109 DBC_REQUIRE(refs > 0);
1110 DBC_REQUIRE(argc_index > 0);
1111 DBC_REQUIRE(user_args != NULL);
1113 #ifdef OPT_LOAD_TIME_INSTRUMENTATION
1114 do_gettimeofday(&tv1);
1116 if (!p_proc_object) {
1120 dev_get_cod_mgr(p_proc_object->hdev_obj, &cod_mgr);
1125 status = proc_stop(hprocessor);
1129 /* Place the board in the monitor state. */
1130 status = proc_monitor(hprocessor);
1134 /* Save ptr to original argv[0]. */
1135 pargv0 = (char *)user_args[0];
1136 /*Prepend "PROC_ID=<nproc_id>"to envp array for target. */
1137 envp_elems = get_envp_count((char **)user_envp);
1138 cnew_envp = (envp_elems ? (envp_elems + 1) : (envp_elems + 2));
1139 new_envp = kzalloc(cnew_envp * sizeof(char **), GFP_KERNEL);
1141 status = snprintf(sz_proc_id, MAXPROCIDLEN, PROC_ENVPROCID,
1144 dev_dbg(bridge, "%s: Proc ID string overflow\n",
1149 prepend_envp(new_envp, (char **)user_envp,
1150 envp_elems, cnew_envp, sz_proc_id);
1151 /* Get the DCD Handle */
1152 status = mgr_get_dcd_handle(p_proc_object->hmgr_obj,
1153 (u32 *) &hdcd_handle);
1155 /* Before proceeding with new load,
1156 * check if a previously registered COFF
1158 * If yes, unregister nodes in previously
1159 * registered COFF. If any error occurred,
1160 * set previously registered COFF to NULL. */
1161 if (p_proc_object->psz_last_coff != NULL) {
1163 dcd_auto_unregister(hdcd_handle,
1166 /* Regardless of auto unregister status,
1167 * free previously allocated
1169 kfree(p_proc_object->psz_last_coff);
1170 p_proc_object->psz_last_coff = NULL;
1173 /* On success, do cod_open_base() */
1174 status = cod_open_base(cod_mgr, (char *)user_args[0],
1181 /* Auto-register data base */
1182 /* Get the DCD Handle */
1183 status = mgr_get_dcd_handle(p_proc_object->hmgr_obj,
1184 (u32 *) &hdcd_handle);
1186 /* Auto register nodes in specified COFF
1187 * file. If registration did not fail,
1188 * (status = 0 or -EACCES)
1189 * save the name of the COFF file for
1190 * de-registration in the future. */
1192 dcd_auto_register(hdcd_handle,
1193 (char *)user_args[0]);
1194 if (status == -EACCES)
1200 DBC_ASSERT(p_proc_object->psz_last_coff ==
1202 /* Allocate memory for pszLastCoff */
1203 p_proc_object->psz_last_coff =
1204 kzalloc((strlen(user_args[0]) +
1206 /* If memory allocated, save COFF file name */
1207 if (p_proc_object->psz_last_coff) {
1208 strncpy(p_proc_object->psz_last_coff,
1209 (char *)user_args[0],
1210 (strlen((char *)user_args[0]) +
1216 /* Update shared memory address and size */
1218 /* Create the message manager. This must be done
1219 * before calling the IOOnLoaded function. */
1220 dev_get_msg_mgr(p_proc_object->hdev_obj, &hmsg_mgr);
1222 status = msg_create(&hmsg_mgr, p_proc_object->hdev_obj,
1223 (msg_onexit) node_on_exit);
1224 DBC_ASSERT(!status);
1225 dev_set_msg_mgr(p_proc_object->hdev_obj, hmsg_mgr);
1229 /* Set the Device object's message manager */
1230 status = dev_get_io_mgr(p_proc_object->hdev_obj, &hio_mgr);
1232 status = (*p_proc_object->intf_fxns->pfn_io_on_loaded)
1238 /* Now, attempt to load an exec: */
1240 /* Boost the OPP level to Maximum level supported by baseport */
1241 #if defined(CONFIG_TIDSPBRIDGE_DVFS) && !defined(CONFIG_CPU_FREQ)
1242 if (pdata->cpu_set_freq)
1243 (*pdata->cpu_set_freq) (pdata->mpu_speed[VDD1_OPP5]);
1245 status = cod_load_base(cod_mgr, argc_index, (char **)user_args,
1247 p_proc_object->hdev_obj, NULL);
1249 if (status == -EBADF) {
1250 dev_dbg(bridge, "%s: Failure to Load the EXE\n",
1253 if (status == -ESPIPE) {
1254 pr_err("%s: Couldn't parse the file\n",
1258 /* Requesting the lowest opp supported */
1259 #if defined(CONFIG_TIDSPBRIDGE_DVFS) && !defined(CONFIG_CPU_FREQ)
1260 if (pdata->cpu_set_freq)
1261 (*pdata->cpu_set_freq) (pdata->mpu_speed[VDD1_OPP1]);
1266 /* Update the Processor status to loaded */
1267 status = (*p_proc_object->intf_fxns->pfn_brd_set_state)
1268 (p_proc_object->hbridge_context, BRD_LOADED);
1270 p_proc_object->proc_state = PROC_LOADED;
1271 if (p_proc_object->ntfy_obj)
1272 proc_notify_clients(p_proc_object,
1273 DSP_PROCESSORSTATECHANGE);
1277 status = proc_get_processor_id(hprocessor, &proc_id);
1278 if (proc_id == DSP_UNIT) {
1279 /* Use all available DSP address space after EXTMEM
1282 status = cod_get_sym_value(cod_mgr, EXTEND,
1285 /* Reset DMM structs and add an initial free chunk */
1288 dev_get_dmm_mgr(p_proc_object->hdev_obj,
1291 /* Set dw_ext_end to DMM START u8
1294 (dw_ext_end + 1) * DSPWORDSIZE;
1295 /* DMM memory is from EXT_END */
1296 status = dmm_create_tables(dmm_mgr,
1305 /* Restore the original argv[0] */
1307 user_args[0] = pargv0;
1309 if (!((*p_proc_object->intf_fxns->pfn_brd_status)
1310 (p_proc_object->hbridge_context, &brd_state))) {
1311 pr_info("%s: Processor Loaded %s\n", __func__, pargv0);
1312 kfree(drv_datap->base_img);
1313 drv_datap->base_img = kmalloc(strlen(pargv0) + 1,
1315 if (drv_datap->base_img)
1316 strncpy(drv_datap->base_img, pargv0,
1317 strlen(pargv0) + 1);
1320 DBC_ASSERT(brd_state == BRD_LOADED);
1326 pr_err("%s: Processor failed to load\n", __func__);
1327 proc_stop(p_proc_object);
1330 && p_proc_object->proc_state == PROC_LOADED)
1332 #ifdef OPT_LOAD_TIME_INSTRUMENTATION
1333 do_gettimeofday(&tv2);
1334 if (tv2.tv_usec < tv1.tv_usec) {
1335 tv2.tv_usec += 1000000;
1338 dev_dbg(bridge, "%s: time to load %d sec and %d usec\n", __func__,
1339 tv2.tv_sec - tv1.tv_sec, tv2.tv_usec - tv1.tv_usec);
1345 * ======== proc_map ========
1347 * Maps a MPU buffer to DSP address space.
1349 int proc_map(void *hprocessor, void *pmpu_addr, u32 ul_size,
1350 void *req_addr, void **pp_map_addr, u32 ul_map_attr,
1351 struct process_context *pr_ctxt)
1355 struct dmm_object *dmm_mgr;
1358 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1359 struct dmm_map_object *map_obj;
1362 #ifdef CONFIG_TIDSPBRIDGE_CACHE_LINE_CHECK
1363 if ((ul_map_attr & BUFMODE_MASK) != RBUF) {
1364 if (!IS_ALIGNED((u32)pmpu_addr, DSP_CACHE_LINE) ||
1365 !IS_ALIGNED(ul_size, DSP_CACHE_LINE)) {
1366 pr_err("%s: not aligned: 0x%x (%d)\n", __func__,
1367 (u32)pmpu_addr, ul_size);
1373 /* Calculate the page-aligned PA, VA and size */
1374 va_align = PG_ALIGN_LOW((u32) req_addr, PG_SIZE4K);
1375 pa_align = PG_ALIGN_LOW((u32) pmpu_addr, PG_SIZE4K);
1376 size_align = PG_ALIGN_HIGH(ul_size + (u32) pmpu_addr - pa_align,
1379 if (!p_proc_object) {
1383 /* Critical section */
1384 mutex_lock(&proc_lock);
1385 dmm_get_handle(p_proc_object, &dmm_mgr);
1387 status = dmm_map_memory(dmm_mgr, va_align, size_align);
1391 /* Add mapping to the page tables. */
1394 /* Mapped address = MSB of VA | LSB of PA */
1395 tmp_addr = (va_align | ((u32) pmpu_addr & (PG_SIZE4K - 1)));
1396 /* mapped memory resource tracking */
1397 map_obj = add_mapping_info(pr_ctxt, pa_align, tmp_addr,
1402 status = (*p_proc_object->intf_fxns->pfn_brd_mem_map)
1403 (p_proc_object->hbridge_context, pa_align, va_align,
1404 size_align, ul_map_attr, map_obj->pages);
1407 /* Mapped address = MSB of VA | LSB of PA */
1408 *pp_map_addr = (void *) tmp_addr;
1410 remove_mapping_information(pr_ctxt, tmp_addr, size_align);
1411 dmm_un_map_memory(dmm_mgr, va_align, &size_align);
1413 mutex_unlock(&proc_lock);
1419 dev_dbg(bridge, "%s: hprocessor %p, pmpu_addr %p, ul_size %x, "
1420 "req_addr %p, ul_map_attr %x, pp_map_addr %p, va_align %x, "
1421 "pa_align %x, size_align %x status 0x%x\n", __func__,
1422 hprocessor, pmpu_addr, ul_size, req_addr, ul_map_attr,
1423 pp_map_addr, va_align, pa_align, size_align, status);
1429 * ======== proc_register_notify ========
1431 * Register to be notified of specific processor events.
1433 int proc_register_notify(void *hprocessor, u32 event_mask,
1434 u32 notify_type, struct dsp_notification
1438 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1439 struct deh_mgr *hdeh_mgr;
1441 DBC_REQUIRE(hnotification != NULL);
1442 DBC_REQUIRE(refs > 0);
1444 /* Check processor handle */
1445 if (!p_proc_object) {
1449 /* Check if event mask is a valid processor related event */
1450 if (event_mask & ~(DSP_PROCESSORSTATECHANGE | DSP_PROCESSORATTACH |
1451 DSP_PROCESSORDETACH | DSP_PROCESSORRESTART |
1452 DSP_MMUFAULT | DSP_SYSERROR | DSP_PWRERROR |
1456 /* Check if notify type is valid */
1457 if (notify_type != DSP_SIGNALEVENT)
1461 /* If event mask is not DSP_SYSERROR, DSP_MMUFAULT,
1462 * or DSP_PWRERROR then register event immediately. */
1464 ~(DSP_SYSERROR | DSP_MMUFAULT | DSP_PWRERROR |
1466 status = ntfy_register(p_proc_object->ntfy_obj,
1467 hnotification, event_mask,
1469 /* Special case alert, special case alert!
1470 * If we're trying to *deregister* (i.e. event_mask
1471 * is 0), a DSP_SYSERROR or DSP_MMUFAULT notification,
1472 * we have to deregister with the DEH manager.
1473 * There's no way to know, based on event_mask which
1474 * manager the notification event was registered with,
1475 * so if we're trying to deregister and ntfy_register
1476 * failed, we'll give the deh manager a shot.
1478 if ((event_mask == 0) && status) {
1480 dev_get_deh_mgr(p_proc_object->hdev_obj,
1483 bridge_deh_register_notify(hdeh_mgr,
1489 status = dev_get_deh_mgr(p_proc_object->hdev_obj,
1492 bridge_deh_register_notify(hdeh_mgr,
1504 * ======== proc_reserve_memory ========
1506 * Reserve a virtually contiguous region of DSP address space.
1508 int proc_reserve_memory(void *hprocessor, u32 ul_size,
1510 struct process_context *pr_ctxt)
1512 struct dmm_object *dmm_mgr;
1514 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1515 struct dmm_rsv_object *rsv_obj;
1517 if (!p_proc_object) {
1522 status = dmm_get_handle(p_proc_object, &dmm_mgr);
1528 status = dmm_reserve_memory(dmm_mgr, ul_size, (u32 *) pp_rsv_addr);
1533 * A successful reserve should be followed by insertion of rsv_obj
1534 * into dmm_rsv_list, so that reserved memory resource tracking
1537 rsv_obj = kmalloc(sizeof(struct dmm_rsv_object), GFP_KERNEL);
1539 rsv_obj->dsp_reserved_addr = (u32) *pp_rsv_addr;
1540 spin_lock(&pr_ctxt->dmm_rsv_lock);
1541 list_add(&rsv_obj->link, &pr_ctxt->dmm_rsv_list);
1542 spin_unlock(&pr_ctxt->dmm_rsv_lock);
1546 dev_dbg(bridge, "%s: hprocessor: 0x%p ul_size: 0x%x pp_rsv_addr: 0x%p "
1547 "status 0x%x\n", __func__, hprocessor,
1548 ul_size, pp_rsv_addr, status);
1553 * ======== proc_start ========
1555 * Start a processor running.
1557 int proc_start(void *hprocessor)
1560 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1561 struct cod_manager *cod_mgr; /* Code manager handle */
1562 u32 dw_dsp_addr; /* Loaded code's entry point. */
1565 DBC_REQUIRE(refs > 0);
1566 if (!p_proc_object) {
1570 /* Call the bridge_brd_start */
1571 if (p_proc_object->proc_state != PROC_LOADED) {
1575 status = dev_get_cod_mgr(p_proc_object->hdev_obj, &cod_mgr);
1581 status = cod_get_entry(cod_mgr, &dw_dsp_addr);
1585 status = (*p_proc_object->intf_fxns->pfn_brd_start)
1586 (p_proc_object->hbridge_context, dw_dsp_addr);
1590 /* Call dev_create2 */
1591 status = dev_create2(p_proc_object->hdev_obj);
1593 p_proc_object->proc_state = PROC_RUNNING;
1594 /* Deep sleep switces off the peripheral clocks.
1595 * we just put the DSP CPU in idle in the idle loop.
1596 * so there is no need to send a command to DSP */
1598 if (p_proc_object->ntfy_obj) {
1599 proc_notify_clients(p_proc_object,
1600 DSP_PROCESSORSTATECHANGE);
1603 /* Failed to Create Node Manager and DISP Object
1604 * Stop the Processor from running. Put it in STOPPED State */
1605 (void)(*p_proc_object->intf_fxns->
1606 pfn_brd_stop) (p_proc_object->hbridge_context);
1607 p_proc_object->proc_state = PROC_STOPPED;
1611 if (!((*p_proc_object->intf_fxns->pfn_brd_status)
1612 (p_proc_object->hbridge_context, &brd_state))) {
1613 pr_info("%s: dsp in running state\n", __func__);
1614 DBC_ASSERT(brd_state != BRD_HIBERNATION);
1617 pr_err("%s: Failed to start the dsp\n", __func__);
1618 proc_stop(p_proc_object);
1622 DBC_ENSURE((!status && p_proc_object->proc_state ==
1623 PROC_RUNNING) || status);
1628 * ======== proc_stop ========
1630 * Stop a processor running.
1632 int proc_stop(void *hprocessor)
1635 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1636 struct msg_mgr *hmsg_mgr;
1637 struct node_mgr *hnode_mgr;
1639 u32 node_tab_size = 1;
1641 u32 nodes_allocated = 0;
1644 DBC_REQUIRE(refs > 0);
1645 if (!p_proc_object) {
1649 /* check if there are any running nodes */
1650 status = dev_get_node_manager(p_proc_object->hdev_obj, &hnode_mgr);
1651 if (!status && hnode_mgr) {
1652 status = node_enum_nodes(hnode_mgr, &hnode, node_tab_size,
1653 &num_nodes, &nodes_allocated);
1654 if ((status == -EINVAL) || (nodes_allocated > 0)) {
1655 pr_err("%s: Can't stop device, active nodes = %d \n",
1656 __func__, nodes_allocated);
1660 /* Call the bridge_brd_stop */
1661 /* It is OK to stop a device that does n't have nodes OR not started */
1663 (*p_proc_object->intf_fxns->
1664 pfn_brd_stop) (p_proc_object->hbridge_context);
1666 dev_dbg(bridge, "%s: processor in standby mode\n", __func__);
1667 p_proc_object->proc_state = PROC_STOPPED;
1668 /* Destory the Node Manager, msg_ctrl Manager */
1669 if (!(dev_destroy2(p_proc_object->hdev_obj))) {
1670 /* Destroy the msg_ctrl by calling msg_delete */
1671 dev_get_msg_mgr(p_proc_object->hdev_obj, &hmsg_mgr);
1673 msg_delete(hmsg_mgr);
1674 dev_set_msg_mgr(p_proc_object->hdev_obj, NULL);
1676 if (!((*p_proc_object->
1677 intf_fxns->pfn_brd_status) (p_proc_object->
1680 DBC_ASSERT(brd_state == BRD_STOPPED);
1683 pr_err("%s: Failed to stop the processor\n", __func__);
1691 * ======== proc_un_map ========
1693 * Removes a MPU buffer mapping from the DSP address space.
1695 int proc_un_map(void *hprocessor, void *map_addr,
1696 struct process_context *pr_ctxt)
1699 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1700 struct dmm_object *dmm_mgr;
1704 va_align = PG_ALIGN_LOW((u32) map_addr, PG_SIZE4K);
1705 if (!p_proc_object) {
1710 status = dmm_get_handle(hprocessor, &dmm_mgr);
1716 /* Critical section */
1717 mutex_lock(&proc_lock);
1719 * Update DMM structures. Get the size to unmap.
1720 * This function returns error if the VA is not mapped
1722 status = dmm_un_map_memory(dmm_mgr, (u32) va_align, &size_align);
1723 /* Remove mapping from the page tables. */
1725 status = (*p_proc_object->intf_fxns->pfn_brd_mem_un_map)
1726 (p_proc_object->hbridge_context, va_align, size_align);
1729 mutex_unlock(&proc_lock);
1734 * A successful unmap should be followed by removal of map_obj
1735 * from dmm_map_list, so that mapped memory resource tracking
1738 remove_mapping_information(pr_ctxt, (u32) map_addr, size_align);
1741 dev_dbg(bridge, "%s: hprocessor: 0x%p map_addr: 0x%p status: 0x%x\n",
1742 __func__, hprocessor, map_addr, status);
1747 * ======== proc_un_reserve_memory ========
1749 * Frees a previously reserved region of DSP address space.
1751 int proc_un_reserve_memory(void *hprocessor, void *prsv_addr,
1752 struct process_context *pr_ctxt)
1754 struct dmm_object *dmm_mgr;
1756 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1757 struct dmm_rsv_object *rsv_obj;
1759 if (!p_proc_object) {
1764 status = dmm_get_handle(p_proc_object, &dmm_mgr);
1770 status = dmm_un_reserve_memory(dmm_mgr, (u32) prsv_addr);
1775 * A successful unreserve should be followed by removal of rsv_obj
1776 * from dmm_rsv_list, so that reserved memory resource tracking
1779 spin_lock(&pr_ctxt->dmm_rsv_lock);
1780 list_for_each_entry(rsv_obj, &pr_ctxt->dmm_rsv_list, link) {
1781 if (rsv_obj->dsp_reserved_addr == (u32) prsv_addr) {
1782 list_del(&rsv_obj->link);
1787 spin_unlock(&pr_ctxt->dmm_rsv_lock);
1790 dev_dbg(bridge, "%s: hprocessor: 0x%p prsv_addr: 0x%p status: 0x%x\n",
1791 __func__, hprocessor, prsv_addr, status);
1796 * ======== = proc_monitor ======== ==
1798 * Place the Processor in Monitor State. This is an internal
1799 * function and a requirement before Processor is loaded.
1800 * This does a bridge_brd_stop, dev_destroy2 and bridge_brd_monitor.
1801 * In dev_destroy2 we delete the node manager.
1803 * p_proc_object: Pointer to Processor Object
1805 * 0: Processor placed in monitor mode.
1806 * !0: Failed to place processor in monitor mode.
1808 * Valid Processor Handle
1810 * Success: ProcObject state is PROC_IDLE
1812 static int proc_monitor(struct proc_object *proc_obj)
1814 int status = -EPERM;
1815 struct msg_mgr *hmsg_mgr;
1818 DBC_REQUIRE(refs > 0);
1819 DBC_REQUIRE(proc_obj);
1821 /* This is needed only when Device is loaded when it is
1822 * already 'ACTIVE' */
1823 /* Destory the Node Manager, msg_ctrl Manager */
1824 if (!dev_destroy2(proc_obj->hdev_obj)) {
1825 /* Destroy the msg_ctrl by calling msg_delete */
1826 dev_get_msg_mgr(proc_obj->hdev_obj, &hmsg_mgr);
1828 msg_delete(hmsg_mgr);
1829 dev_set_msg_mgr(proc_obj->hdev_obj, NULL);
1832 /* Place the Board in the Monitor State */
1833 if (!((*proc_obj->intf_fxns->pfn_brd_monitor)
1834 (proc_obj->hbridge_context))) {
1836 if (!((*proc_obj->intf_fxns->pfn_brd_status)
1837 (proc_obj->hbridge_context, &brd_state)))
1838 DBC_ASSERT(brd_state == BRD_IDLE);
1841 DBC_ENSURE((!status && brd_state == BRD_IDLE) ||
1847 * ======== get_envp_count ========
1849 * Return the number of elements in the envp array, including the
1850 * terminating NULL element.
1852 static s32 get_envp_count(char **envp)
1859 ret += 1; /* Include the terminating NULL in the count. */
1866 * ======== prepend_envp ========
1868 * Prepend an environment variable=value pair to the new envp array, and
1869 * copy in the existing var=value pairs in the old envp array.
1871 static char **prepend_envp(char **new_envp, char **envp, s32 envp_elems,
1872 s32 cnew_envp, char *sz_var)
1874 char **pp_envp = new_envp;
1876 DBC_REQUIRE(new_envp);
1878 /* Prepend new environ var=value string */
1879 *new_envp++ = sz_var;
1881 /* Copy user's environment into our own. */
1882 while (envp_elems--)
1883 *new_envp++ = *envp++;
1885 /* Ensure NULL terminates the new environment strings array. */
1886 if (envp_elems == 0)
1893 * ======== proc_notify_clients ========
1895 * Notify the processor the events.
1897 int proc_notify_clients(void *proc, u32 events)
1900 struct proc_object *p_proc_object = (struct proc_object *)proc;
1902 DBC_REQUIRE(p_proc_object);
1903 DBC_REQUIRE(is_valid_proc_event(events));
1904 DBC_REQUIRE(refs > 0);
1905 if (!p_proc_object) {
1910 ntfy_notify(p_proc_object->ntfy_obj, events);
1916 * ======== proc_notify_all_clients ========
1918 * Notify the processor the events. This includes notifying all clients
1919 * attached to a particulat DSP.
1921 int proc_notify_all_clients(void *proc, u32 events)
1924 struct proc_object *p_proc_object = (struct proc_object *)proc;
1926 DBC_REQUIRE(is_valid_proc_event(events));
1927 DBC_REQUIRE(refs > 0);
1929 if (!p_proc_object) {
1934 dev_notify_clients(p_proc_object->hdev_obj, events);
1941 * ======== proc_get_processor_id ========
1943 * Retrieves the processor ID.
1945 int proc_get_processor_id(void *proc, u32 * proc_id)
1948 struct proc_object *p_proc_object = (struct proc_object *)proc;
1951 *proc_id = p_proc_object->processor_id;