提交 7d55524d 编写于 作者: O Omar Ramirez Luna 提交者: Greg Kroah-Hartman

staging: ti dspbridge: add resource manager

Add TI's DSP Bridge resource manager driver sources
Signed-off-by: NOmar Ramirez Luna <omar.ramirez@ti.com>
Signed-off-by: NKanigeri, Hari <h-kanigeri2@ti.com>
Signed-off-by: NAmeya Palande <ameya.palande@nokia.com>
Signed-off-by: NGuzman Lugo, Fernando <fernando.lugo@ti.com>
Signed-off-by: NHebbar, Shivananda <x0hebbar@ti.com>
Signed-off-by: NRamos Falcon, Ernesto <ernesto@ti.com>
Signed-off-by: NFelipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: NAnna, Suman <s-anna@ti.com>
Signed-off-by: NGupta, Ramesh <grgupta@ti.com>
Signed-off-by: NGomez Castellanos, Ivan <ivan.gomez@ti.com>
Signed-off-by: NAndy Shevchenko <ext-andriy.shevchenko@nokia.com>
Signed-off-by: NArmando Uribe De Leon <x0095078@ti.com>
Signed-off-by: NDeepak Chitriki <deepak.chitriki@ti.com>
Signed-off-by: NMenon, Nishanth <nm@ti.com>
Signed-off-by: NPhil Carmody <ext-phil.2.carmody@nokia.com>
Signed-off-by: NOhad Ben-Cohen <ohad@wizery.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 c4ca3d5a
此差异已折叠。
此差异已折叠。
此差异已折叠。
/*
* drv_interface.c
*
* DSP-BIOS Bridge driver support functions for TI OMAP processors.
*
* DSP/BIOS Bridge driver interface.
*
* Copyright (C) 2005-2006 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* ----------------------------------- Host OS */
#include <dspbridge/host_os.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#ifdef MODULE
#include <linux/module.h>
#endif
#include <linux/device.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
#include <linux/cdev.h>
/* ----------------------------------- DSP/BIOS Bridge */
#include <dspbridge/std.h>
#include <dspbridge/dbdefs.h>
/* ----------------------------------- Trace & Debug */
#include <dspbridge/dbc.h>
/* ----------------------------------- OS Adaptation Layer */
#include <dspbridge/services.h>
#include <dspbridge/clk.h>
#include <dspbridge/sync.h>
/* ----------------------------------- Platform Manager */
#include <dspbridge/dspapi-ioctl.h>
#include <dspbridge/dspapi.h>
#include <dspbridge/dspdrv.h>
/* ----------------------------------- Resource Manager */
#include <dspbridge/pwr.h>
/* ----------------------------------- This */
#include <drv_interface.h>
#include <dspbridge/cfg.h>
#include <dspbridge/resourcecleanup.h>
#include <dspbridge/chnl.h>
#include <dspbridge/proc.h>
#include <dspbridge/dev.h>
#include <dspbridge/drvdefs.h>
#include <dspbridge/drv.h>
#ifdef CONFIG_BRIDGE_DVFS
#include <mach-omap2/omap3-opp.h>
#endif
#define BRIDGE_NAME "C6410"
/* ----------------------------------- Globals */
#define DRIVER_NAME "DspBridge"
#define DSPBRIDGE_VERSION "0.3"
s32 dsp_debug;
struct platform_device *omap_dspbridge_dev;
struct device *bridge;
/* This is a test variable used by Bridge to test different sleep states */
s32 dsp_test_sleepstate;
static struct cdev bridge_cdev;
static struct class *bridge_class;
static u32 driver_context;
static s32 driver_major;
static char *base_img;
char *iva_img;
static s32 shm_size = 0x500000; /* 5 MB */
static int tc_wordswapon; /* Default value is always false */
#ifdef CONFIG_BRIDGE_RECOVERY
#define REC_TIMEOUT 5000 /*recovery timeout in msecs */
static atomic_t bridge_cref; /* number of bridge open handles */
static struct workqueue_struct *bridge_rec_queue;
static struct work_struct bridge_recovery_work;
static DECLARE_COMPLETION(bridge_comp);
static DECLARE_COMPLETION(bridge_open_comp);
static bool recover;
#endif
#ifdef CONFIG_PM
struct omap34_xx_bridge_suspend_data {
int suspended;
wait_queue_head_t suspend_wq;
};
static struct omap34_xx_bridge_suspend_data bridge_suspend_data;
static int omap34_xxbridge_suspend_lockout(struct omap34_xx_bridge_suspend_data
*s, struct file *f)
{
if ((s)->suspended) {
if ((f)->f_flags & O_NONBLOCK)
return -EPERM;
wait_event_interruptible((s)->suspend_wq, (s)->suspended == 0);
}
return 0;
}
#endif
module_param(dsp_debug, int, 0);
MODULE_PARM_DESC(dsp_debug, "Wait after loading DSP image. default = false");
module_param(dsp_test_sleepstate, int, 0);
MODULE_PARM_DESC(dsp_test_sleepstate, "DSP Sleep state = 0");
module_param(base_img, charp, 0);
MODULE_PARM_DESC(base_img, "DSP base image, default = NULL");
module_param(shm_size, int, 0);
MODULE_PARM_DESC(shm_size, "shm size, default = 4 MB, minimum = 64 KB");
module_param(tc_wordswapon, int, 0);
MODULE_PARM_DESC(tc_wordswapon, "TC Word Swap Option. default = 0");
MODULE_AUTHOR("Texas Instruments");
MODULE_LICENSE("GPL");
MODULE_VERSION(DSPBRIDGE_VERSION);
static char *driver_name = DRIVER_NAME;
static const struct file_operations bridge_fops = {
.open = bridge_open,
.release = bridge_release,
.unlocked_ioctl = bridge_ioctl,
.mmap = bridge_mmap,
};
#ifdef CONFIG_PM
static u32 time_out = 1000;
#ifdef CONFIG_BRIDGE_DVFS
s32 dsp_max_opps = VDD1_OPP5;
#endif
/* Maximum Opps that can be requested by IVA */
/*vdd1 rate table */
#ifdef CONFIG_BRIDGE_DVFS
const struct omap_opp vdd1_rate_table_bridge[] = {
{0, 0, 0},
/*OPP1 */
{S125M, VDD1_OPP1, 0},
/*OPP2 */
{S250M, VDD1_OPP2, 0},
/*OPP3 */
{S500M, VDD1_OPP3, 0},
/*OPP4 */
{S550M, VDD1_OPP4, 0},
/*OPP5 */
{S600M, VDD1_OPP5, 0},
};
#endif
#endif
struct dspbridge_platform_data *omap_dspbridge_pdata;
u32 vdd1_dsp_freq[6][4] = {
{0, 0, 0, 0},
/*OPP1 */
{0, 90000, 0, 86000},
/*OPP2 */
{0, 180000, 80000, 170000},
/*OPP3 */
{0, 360000, 160000, 340000},
/*OPP4 */
{0, 396000, 325000, 376000},
/*OPP5 */
{0, 430000, 355000, 430000},
};
#ifdef CONFIG_BRIDGE_RECOVERY
static void bridge_recover(struct work_struct *work)
{
struct dev_object *dev;
struct cfg_devnode *dev_node;
if (atomic_read(&bridge_cref)) {
INIT_COMPLETION(bridge_comp);
while (!wait_for_completion_timeout(&bridge_comp,
msecs_to_jiffies(REC_TIMEOUT)))
pr_info("%s:%d handle(s) still opened\n",
__func__, atomic_read(&bridge_cref));
}
dev = dev_get_first();
dev_get_dev_node(dev, &dev_node);
if (!dev_node || DSP_FAILED(proc_auto_start(dev_node, dev)))
pr_err("DSP could not be restarted\n");
recover = false;
complete_all(&bridge_open_comp);
}
void bridge_recover_schedule(void)
{
INIT_COMPLETION(bridge_open_comp);
recover = true;
queue_work(bridge_rec_queue, &bridge_recovery_work);
}
#endif
#ifdef CONFIG_BRIDGE_DVFS
static int dspbridge_scale_notification(struct notifier_block *op,
unsigned long val, void *ptr)
{
struct dspbridge_platform_data *pdata =
omap_dspbridge_dev->dev.platform_data;
if (CPUFREQ_POSTCHANGE == val && pdata->dsp_get_opp)
pwr_pm_post_scale(PRCM_VDD1, pdata->dsp_get_opp());
return 0;
}
static struct notifier_block iva_clk_notifier = {
.notifier_call = dspbridge_scale_notification,
NULL,
};
#endif
/**
* omap3_bridge_startup() - perform low lever initializations
* @pdev: pointer to platform device
*
* Initializes recovery, PM and DVFS required data, before calling
* clk and memory init routines.
*/
static int omap3_bridge_startup(struct platform_device *pdev)
{
struct dspbridge_platform_data *pdata = pdev->dev.platform_data;
struct drv_data *drv_datap = NULL;
u32 phys_membase, phys_memsize;
int err;
#ifdef CONFIG_BRIDGE_RECOVERY
bridge_rec_queue = create_workqueue("bridge_rec_queue");
INIT_WORK(&bridge_recovery_work, bridge_recover);
INIT_COMPLETION(bridge_comp);
#endif
#ifdef CONFIG_PM
/* Initialize the wait queue */
bridge_suspend_data.suspended = 0;
init_waitqueue_head(&bridge_suspend_data.suspend_wq);
#ifdef CONFIG_BRIDGE_DVFS
for (i = 0; i < 6; i++)
pdata->mpu_speed[i] = vdd1_rate_table_bridge[i].rate;
err = cpufreq_register_notifier(&iva_clk_notifier,
CPUFREQ_TRANSITION_NOTIFIER);
if (err)
pr_err("%s: clk_notifier_register failed for iva2_ck\n",
__func__);
#endif
#endif
dsp_clk_init();
services_init();
drv_datap = kzalloc(sizeof(struct drv_data), GFP_KERNEL);
if (!drv_datap) {
err = -ENOMEM;
goto err1;
}
drv_datap->shm_size = shm_size;
drv_datap->tc_wordswapon = tc_wordswapon;
if (base_img) {
drv_datap->base_img = kmalloc(strlen(base_img) + 1, GFP_KERNEL);
if (!drv_datap->base_img) {
err = -ENOMEM;
goto err2;
}
strncpy(drv_datap->base_img, base_img, strlen(base_img) + 1);
}
dev_set_drvdata(bridge, drv_datap);
if (shm_size < 0x10000) { /* 64 KB */
err = -EINVAL;
pr_err("%s: shm size must be at least 64 KB\n", __func__);
goto err3;
}
dev_dbg(bridge, "%s: requested shm_size = 0x%x\n", __func__, shm_size);
phys_membase = pdata->phys_mempool_base;
phys_memsize = pdata->phys_mempool_size;
if (phys_membase > 0 && phys_memsize > 0)
mem_ext_phys_pool_init(phys_membase, phys_memsize);
if (tc_wordswapon)
dev_dbg(bridge, "%s: TC Word Swap is enabled\n", __func__);
driver_context = dsp_init(&err);
if (err) {
pr_err("DSP Bridge driver initialization failed\n");
goto err4;
}
return 0;
err4:
mem_ext_phys_pool_release();
err3:
kfree(drv_datap->base_img);
err2:
kfree(drv_datap);
err1:
#ifdef CONFIG_BRIDGE_DVFS
cpufreq_unregister_notifier(&iva_clk_notifier,
CPUFREQ_TRANSITION_NOTIFIER);
#endif
dsp_clk_exit();
services_exit();
return err;
}
static int __devinit omap34_xx_bridge_probe(struct platform_device *pdev)
{
int err;
dev_t dev = 0;
#ifdef CONFIG_BRIDGE_DVFS
int i = 0;
#endif
omap_dspbridge_dev = pdev;
/* Global bridge device */
bridge = &omap_dspbridge_dev->dev;
/* Bridge low level initializations */
err = omap3_bridge_startup(pdev);
if (err)
goto err1;
/* use 2.6 device model */
err = alloc_chrdev_region(&dev, 0, 1, driver_name);
if (err) {
pr_err("%s: Can't get major %d\n", __func__, driver_major);
goto err1;
}
cdev_init(&bridge_cdev, &bridge_fops);
bridge_cdev.owner = THIS_MODULE;
err = cdev_add(&bridge_cdev, dev, 1);
if (err) {
pr_err("%s: Failed to add bridge device\n", __func__);
goto err2;
}
/* udev support */
bridge_class = class_create(THIS_MODULE, "ti_bridge");
if (IS_ERR(bridge_class)) {
pr_err("%s: Error creating bridge class\n", __func__);
goto err3;
}
driver_major = MAJOR(dev);
device_create(bridge_class, NULL, MKDEV(driver_major, 0),
NULL, "DspBridge");
pr_info("DSP Bridge driver loaded\n");
return 0;
err3:
cdev_del(&bridge_cdev);
err2:
unregister_chrdev_region(dev, 1);
err1:
return err;
}
static int __devexit omap34_xx_bridge_remove(struct platform_device *pdev)
{
dev_t devno;
bool ret;
int status = 0;
void *hdrv_obj = NULL;
status = cfg_get_object((u32 *) &hdrv_obj, REG_DRV_OBJECT);
if (DSP_FAILED(status))
goto func_cont;
#ifdef CONFIG_BRIDGE_DVFS
if (cpufreq_unregister_notifier(&iva_clk_notifier,
CPUFREQ_TRANSITION_NOTIFIER))
pr_err("%s: cpufreq_unregister_notifier failed for iva2_ck\n",
__func__);
#endif /* #ifdef CONFIG_BRIDGE_DVFS */
if (driver_context) {
/* Put the DSP in reset state */
ret = dsp_deinit(driver_context);
driver_context = 0;
DBC_ASSERT(ret == true);
}
func_cont:
mem_ext_phys_pool_release();
dsp_clk_exit();
services_exit();
devno = MKDEV(driver_major, 0);
cdev_del(&bridge_cdev);
unregister_chrdev_region(devno, 1);
if (bridge_class) {
/* remove the device from sysfs */
device_destroy(bridge_class, MKDEV(driver_major, 0));
class_destroy(bridge_class);
}
return 0;
}
#ifdef CONFIG_PM
static int BRIDGE_SUSPEND(struct platform_device *pdev, pm_message_t state)
{
u32 status;
u32 command = PWR_EMERGENCYDEEPSLEEP;
status = pwr_sleep_dsp(command, time_out);
if (DSP_FAILED(status))
return -1;
bridge_suspend_data.suspended = 1;
return 0;
}
static int BRIDGE_RESUME(struct platform_device *pdev)
{
u32 status;
status = pwr_wake_dsp(time_out);
if (DSP_FAILED(status))
return -1;
bridge_suspend_data.suspended = 0;
wake_up(&bridge_suspend_data.suspend_wq);
return 0;
}
#else
#define BRIDGE_SUSPEND NULL
#define BRIDGE_RESUME NULL
#endif
static struct platform_driver bridge_driver = {
.driver = {
.name = BRIDGE_NAME,
},
.probe = omap34_xx_bridge_probe,
.remove = __devexit_p(omap34_xx_bridge_remove),
.suspend = BRIDGE_SUSPEND,
.resume = BRIDGE_RESUME,
};
static int __init bridge_init(void)
{
return platform_driver_register(&bridge_driver);
}
static void __exit bridge_exit(void)
{
platform_driver_unregister(&bridge_driver);
}
/*
* This function is called when an application opens handle to the
* bridge driver.
*/
static int bridge_open(struct inode *ip, struct file *filp)
{
int status = 0;
struct process_context *pr_ctxt = NULL;
/*
* Allocate a new process context and insert it into global
* process context list.
*/
#ifdef CONFIG_BRIDGE_RECOVERY
if (recover) {
if (filp->f_flags & O_NONBLOCK ||
wait_for_completion_interruptible(&bridge_open_comp))
return -EBUSY;
}
#endif
pr_ctxt = kzalloc(sizeof(struct process_context), GFP_KERNEL);
if (pr_ctxt) {
pr_ctxt->res_state = PROC_RES_ALLOCATED;
spin_lock_init(&pr_ctxt->dmm_map_lock);
INIT_LIST_HEAD(&pr_ctxt->dmm_map_list);
spin_lock_init(&pr_ctxt->dmm_rsv_lock);
INIT_LIST_HEAD(&pr_ctxt->dmm_rsv_list);
mutex_init(&pr_ctxt->node_mutex);
mutex_init(&pr_ctxt->strm_mutex);
} else {
status = -ENOMEM;
}
filp->private_data = pr_ctxt;
#ifdef CONFIG_BRIDGE_RECOVERY
if (!status)
atomic_inc(&bridge_cref);
#endif
return status;
}
/*
* This function is called when an application closes handle to the bridge
* driver.
*/
static int bridge_release(struct inode *ip, struct file *filp)
{
int status = 0;
struct process_context *pr_ctxt;
if (!filp->private_data) {
status = -EIO;
goto err;
}
pr_ctxt = filp->private_data;
flush_signals(current);
drv_remove_all_resources(pr_ctxt);
proc_detach(pr_ctxt);
kfree(pr_ctxt);
filp->private_data = NULL;
err:
#ifdef CONFIG_BRIDGE_RECOVERY
if (!atomic_dec_return(&bridge_cref))
complete(&bridge_comp);
#endif
return status;
}
/* This function provides IO interface to the bridge driver. */
static long bridge_ioctl(struct file *filp, unsigned int code,
unsigned long args)
{
int status;
u32 retval = 0;
union Trapped_Args buf_in;
DBC_REQUIRE(filp != NULL);
#ifdef CONFIG_BRIDGE_RECOVERY
if (recover) {
status = -EIO;
goto err;
}
#endif
#ifdef CONFIG_PM
status = omap34_xxbridge_suspend_lockout(&bridge_suspend_data, filp);
if (status != 0)
return status;
#endif
if (!filp->private_data) {
status = -EIO;
goto err;
}
status = copy_from_user(&buf_in, (union Trapped_Args *)args,
sizeof(union Trapped_Args));
if (!status) {
status = api_call_dev_ioctl(code, &buf_in, &retval,
filp->private_data);
if (DSP_SUCCEEDED(status)) {
status = retval;
} else {
dev_dbg(bridge, "%s: IOCTL Failed, code: 0x%x "
"status 0x%x\n", __func__, code, status);
status = -1;
}
}
err:
return status;
}
/* This function maps kernel space memory to user space memory. */
static int bridge_mmap(struct file *filp, struct vm_area_struct *vma)
{
u32 offset = vma->vm_pgoff << PAGE_SHIFT;
u32 status;
DBC_ASSERT(vma->vm_start < vma->vm_end);
vma->vm_flags |= VM_RESERVED | VM_IO;
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
dev_dbg(bridge, "%s: vm filp %p offset %x start %lx end %lx page_prot "
"%lx flags %lx\n", __func__, filp, offset,
vma->vm_start, vma->vm_end, vma->vm_page_prot, vma->vm_flags);
status = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
vma->vm_end - vma->vm_start,
vma->vm_page_prot);
if (status != 0)
status = -EAGAIN;
return status;
}
/* To remove all process resources before removing the process from the
* process context list */
int drv_remove_all_resources(void *hPCtxt)
{
int status = 0;
struct process_context *ctxt = (struct process_context *)hPCtxt;
drv_remove_all_strm_res_elements(ctxt);
drv_remove_all_node_res_elements(ctxt);
drv_remove_all_dmm_res_elements(ctxt);
ctxt->res_state = PROC_RES_FREED;
return status;
}
/* Bridge driver initialization and de-initialization functions */
module_init(bridge_init);
module_exit(bridge_exit);
/*
* drv_interface.h
*
* DSP-BIOS Bridge driver support functions for TI OMAP processors.
*
* Copyright (C) 2005-2006 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef _DRV_INTERFACE_H_
#define _DRV_INTERFACE_H_
/* Prototypes for all functions in this bridge */
static int __init bridge_init(void); /* Initialize bridge */
static void __exit bridge_exit(void); /* Opposite of initialize */
static int bridge_open(struct inode *, struct file *); /* Open */
static int bridge_release(struct inode *, struct file *); /* Release */
static long bridge_ioctl(struct file *, unsigned int, unsigned long);
static int bridge_mmap(struct file *filp, struct vm_area_struct *vma);
#endif /* ifndef _DRV_INTERFACE_H_ */
/*
* dspdrv.c
*
* DSP-BIOS Bridge driver support functions for TI OMAP processors.
*
* Interface to allocate and free bridge resources.
*
* Copyright (C) 2005-2006 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* ----------------------------------- Host OS */
#include <dspbridge/host_os.h>
/* ----------------------------------- DSP/BIOS Bridge */
#include <dspbridge/std.h>
#include <dspbridge/dbdefs.h>
/* ----------------------------------- Trace & Debug */
#include <dspbridge/dbc.h>
/* ----------------------------------- OS Adaptation Layer */
#include <dspbridge/cfg.h>
/* ----------------------------------- Platform Manager */
#include <dspbridge/drv.h>
#include <dspbridge/dev.h>
#include <dspbridge/dspapi.h>
/* ----------------------------------- Resource Manager */
#include <dspbridge/mgr.h>
/* ----------------------------------- This */
#include <dspbridge/dspdrv.h>
/*
* ======== dsp_init ========
* Allocates bridge resources. Loads a base image onto DSP, if specified.
*/
u32 dsp_init(OUT u32 *init_status)
{
char dev_node[MAXREGPATHLENGTH] = "TIOMAP1510";
int status = -EPERM;
struct drv_object *drv_obj = NULL;
u32 device_node;
u32 device_node_string;
if (!api_init())
goto func_cont;
status = drv_create(&drv_obj);
if (DSP_FAILED(status)) {
api_exit();
goto func_cont;
}
/* End drv_create */
/* Request Resources */
status = drv_request_resources((u32) &dev_node, &device_node_string);
if (DSP_SUCCEEDED(status)) {
/* Attempt to Start the Device */
status = dev_start_device((struct cfg_devnode *)
device_node_string);
if (DSP_FAILED(status))
(void)drv_release_resources
((u32) device_node_string, drv_obj);
} else {
dev_dbg(bridge, "%s: drv_request_resources Failed\n", __func__);
status = -EPERM;
}
/* Unwind whatever was loaded */
if (DSP_FAILED(status)) {
/* irrespective of the status of dev_remove_device we conitinue
* unloading. Get the Driver Object iterate through and remove.
* Reset the status to E_FAIL to avoid going through
* api_init_complete2. */
for (device_node = drv_get_first_dev_extension();
device_node != 0;
device_node = drv_get_next_dev_extension(device_node)) {
(void)dev_remove_device((struct cfg_devnode *)
device_node);
(void)drv_release_resources((u32) device_node, drv_obj);
}
/* Remove the Driver Object */
(void)drv_destroy(drv_obj);
drv_obj = NULL;
api_exit();
dev_dbg(bridge, "%s: Logical device failed init\n", __func__);
} /* Unwinding the loaded drivers */
func_cont:
/* Attempt to Start the Board */
if (DSP_SUCCEEDED(status)) {
/* BRD_AutoStart could fail if the dsp execuetable is not the
* correct one. We should not propagate that error
* into the device loader. */
(void)api_init_complete2();
} else {
dev_dbg(bridge, "%s: Failed\n", __func__);
} /* End api_init_complete2 */
DBC_ENSURE((DSP_SUCCEEDED(status) && drv_obj != NULL) ||
(DSP_FAILED(status) && drv_obj == NULL));
*init_status = status;
/* Return the Driver Object */
return (u32) drv_obj;
}
/*
* ======== dsp_deinit ========
* Frees the resources allocated for bridge.
*/
bool dsp_deinit(u32 deviceContext)
{
bool ret = true;
u32 device_node;
struct mgr_object *mgr_obj = NULL;
while ((device_node = drv_get_first_dev_extension()) != 0) {
(void)dev_remove_device((struct cfg_devnode *)device_node);
(void)drv_release_resources((u32) device_node,
(struct drv_object *)deviceContext);
}
(void)drv_destroy((struct drv_object *)deviceContext);
/* Get the Manager Object from Registry
* MGR Destroy will unload the DCD dll */
if (DSP_SUCCEEDED(cfg_get_object((u32 *) &mgr_obj, REG_MGR_OBJECT)))
(void)mgr_destroy(mgr_obj);
api_exit();
return ret;
}
/*
* mgr.c
*
* DSP-BIOS Bridge driver support functions for TI OMAP processors.
*
* Implementation of Manager interface to the device object at the
* driver level. This queries the NDB data base and retrieves the
* data about Node and Processor.
*
* Copyright (C) 2005-2006 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* ----------------------------------- DSP/BIOS Bridge */
#include <dspbridge/std.h>
#include <dspbridge/dbdefs.h>
/* ----------------------------------- Trace & Debug */
#include <dspbridge/dbc.h>
/* ----------------------------------- OS Adaptation Layer */
#include <dspbridge/cfg.h>
#include <dspbridge/sync.h>
/* ----------------------------------- Others */
#include <dspbridge/dbdcd.h>
#include <dspbridge/drv.h>
#include <dspbridge/dev.h>
/* ----------------------------------- This */
#include <dspbridge/mgr.h>
/* ----------------------------------- Defines, Data Structures, Typedefs */
#define ZLDLLNAME ""
struct mgr_object {
struct dcd_manager *hdcd_mgr; /* Proc/Node data manager */
};
/* ----------------------------------- Globals */
static u32 refs;
/*
* ========= mgr_create =========
* Purpose:
* MGR Object gets created only once during driver Loading.
*/
int mgr_create(OUT struct mgr_object **phMgrObject,
struct cfg_devnode *dev_node_obj)
{
int status = 0;
struct mgr_object *pmgr_obj = NULL;
DBC_REQUIRE(phMgrObject != NULL);
DBC_REQUIRE(refs > 0);
pmgr_obj = kzalloc(sizeof(struct mgr_object), GFP_KERNEL);
if (pmgr_obj) {
status = dcd_create_manager(ZLDLLNAME, &pmgr_obj->hdcd_mgr);
if (DSP_SUCCEEDED(status)) {
/* If succeeded store the handle in the MGR Object */
status = cfg_set_object((u32) pmgr_obj, REG_MGR_OBJECT);
if (DSP_SUCCEEDED(status)) {
*phMgrObject = pmgr_obj;
} else {
dcd_destroy_manager(pmgr_obj->hdcd_mgr);
kfree(pmgr_obj);
}
} else {
/* failed to Create DCD Manager */
kfree(pmgr_obj);
}
} else {
status = -ENOMEM;
}
DBC_ENSURE(DSP_FAILED(status) || pmgr_obj);
return status;
}
/*
* ========= mgr_destroy =========
* This function is invoked during bridge driver unloading.Frees MGR object.
*/
int mgr_destroy(struct mgr_object *hmgr_obj)
{
int status = 0;
struct mgr_object *pmgr_obj = (struct mgr_object *)hmgr_obj;
DBC_REQUIRE(refs > 0);
DBC_REQUIRE(hmgr_obj);
/* Free resources */
if (hmgr_obj->hdcd_mgr)
dcd_destroy_manager(hmgr_obj->hdcd_mgr);
kfree(pmgr_obj);
/* Update the Registry with NULL for MGR Object */
(void)cfg_set_object(0, REG_MGR_OBJECT);
return status;
}
/*
* ======== mgr_enum_node_info ========
* Enumerate and get configuration information about nodes configured
* in the node database.
*/
int mgr_enum_node_info(u32 node_id, OUT struct dsp_ndbprops *pndb_props,
u32 undb_props_size, OUT u32 *pu_num_nodes)
{
int status = 0;
struct dsp_uuid node_uuid, temp_uuid;
u32 temp_index = 0;
u32 node_index = 0;
struct dcd_genericobj gen_obj;
struct mgr_object *pmgr_obj = NULL;
DBC_REQUIRE(pndb_props != NULL);
DBC_REQUIRE(pu_num_nodes != NULL);
DBC_REQUIRE(undb_props_size >= sizeof(struct dsp_ndbprops));
DBC_REQUIRE(refs > 0);
*pu_num_nodes = 0;
/* Get The Manager Object from the Registry */
status = cfg_get_object((u32 *) &pmgr_obj, REG_MGR_OBJECT);
if (DSP_FAILED(status))
goto func_cont;
DBC_ASSERT(pmgr_obj);
/* Forever loop till we hit failed or no more items in the
* Enumeration. We will exit the loop other than 0; */
while (status == 0) {
status = dcd_enumerate_object(temp_index++, DSP_DCDNODETYPE,
&temp_uuid);
if (status == 0) {
node_index++;
if (node_id == (node_index - 1))
node_uuid = temp_uuid;
}
}
if (DSP_SUCCEEDED(status)) {
if (node_id > (node_index - 1)) {
status = -EINVAL;
} else {
status = dcd_get_object_def(pmgr_obj->hdcd_mgr,
(struct dsp_uuid *)
&node_uuid, DSP_DCDNODETYPE,
&gen_obj);
if (DSP_SUCCEEDED(status)) {
/* Get the Obj def */
*pndb_props =
gen_obj.obj_data.node_obj.ndb_props;
*pu_num_nodes = node_index;
}
}
}
func_cont:
DBC_ENSURE((DSP_SUCCEEDED(status) && *pu_num_nodes > 0) ||
(DSP_FAILED(status) && *pu_num_nodes == 0));
return status;
}
/*
* ======== mgr_enum_processor_info ========
* Enumerate and get configuration information about available
* DSP processors.
*/
int mgr_enum_processor_info(u32 processor_id,
OUT struct dsp_processorinfo *
processor_info, u32 processor_info_size,
OUT u8 *pu_num_procs)
{
int status = 0;
int status1 = 0;
int status2 = 0;
struct dsp_uuid temp_uuid;
u32 temp_index = 0;
u32 proc_index = 0;
struct dcd_genericobj gen_obj;
struct mgr_object *pmgr_obj = NULL;
struct mgr_processorextinfo *ext_info;
struct dev_object *hdev_obj;
struct drv_object *hdrv_obj;
u8 dev_type;
struct cfg_devnode *dev_node;
bool proc_detect = false;
DBC_REQUIRE(processor_info != NULL);
DBC_REQUIRE(pu_num_procs != NULL);
DBC_REQUIRE(processor_info_size >= sizeof(struct dsp_processorinfo));
DBC_REQUIRE(refs > 0);
*pu_num_procs = 0;
status = cfg_get_object((u32 *) &hdrv_obj, REG_DRV_OBJECT);
if (DSP_SUCCEEDED(status)) {
status = drv_get_dev_object(processor_id, hdrv_obj, &hdev_obj);
if (DSP_SUCCEEDED(status)) {
status = dev_get_dev_type(hdev_obj, (u8 *) &dev_type);
status = dev_get_dev_node(hdev_obj, &dev_node);
if (dev_type != DSP_UNIT)
status = -EPERM;
if (DSP_SUCCEEDED(status))
processor_info->processor_type = DSPTYPE64;
}
}
if (DSP_FAILED(status))
goto func_end;
/* Get The Manager Object from the Registry */
if (DSP_FAILED(cfg_get_object((u32 *) &pmgr_obj, REG_MGR_OBJECT))) {
dev_dbg(bridge, "%s: Failed to get MGR Object\n", __func__);
goto func_end;
}
DBC_ASSERT(pmgr_obj);
/* Forever loop till we hit no more items in the
* Enumeration. We will exit the loop other than 0; */
while (status1 == 0) {
status1 = dcd_enumerate_object(temp_index++,
DSP_DCDPROCESSORTYPE,
&temp_uuid);
if (status1 != 0)
break;
proc_index++;
/* Get the Object properties to find the Device/Processor
* Type */
if (proc_detect != false)
continue;
status2 = dcd_get_object_def(pmgr_obj->hdcd_mgr,
(struct dsp_uuid *)&temp_uuid,
DSP_DCDPROCESSORTYPE, &gen_obj);
if (DSP_SUCCEEDED(status2)) {
/* Get the Obj def */
if (processor_info_size <
sizeof(struct mgr_processorextinfo)) {
*processor_info = gen_obj.obj_data.proc_info;
} else {
/* extended info */
ext_info = (struct mgr_processorextinfo *)
processor_info;
*ext_info = gen_obj.obj_data.ext_proc_obj;
}
dev_dbg(bridge, "%s: Got proctype from DCD %x\n",
__func__, processor_info->processor_type);
/* See if we got the needed processor */
if (dev_type == DSP_UNIT) {
if (processor_info->processor_type ==
DSPPROCTYPE_C64)
proc_detect = true;
} else if (dev_type == IVA_UNIT) {
if (processor_info->processor_type ==
IVAPROCTYPE_ARM7)
proc_detect = true;
}
/* User applciatiuons aonly check for chip type, so
* this clumsy overwrite */
processor_info->processor_type = DSPTYPE64;
} else {
dev_dbg(bridge, "%s: Failed to get DCD processor info "
"%x\n", __func__, status2);
status = -EPERM;
}
}
*pu_num_procs = proc_index;
if (proc_detect == false) {
dev_dbg(bridge, "%s: Failed to get proc info from DCD, so use "
"CFG registry\n", __func__);
processor_info->processor_type = DSPTYPE64;
}
func_end:
return status;
}
/*
* ======== mgr_exit ========
* Decrement reference count, and free resources when reference count is
* 0.
*/
void mgr_exit(void)
{
DBC_REQUIRE(refs > 0);
refs--;
if (refs == 0)
dcd_exit();
DBC_ENSURE(refs >= 0);
}
/*
* ======== mgr_get_dcd_handle ========
* Retrieves the MGR handle. Accessor Function.
*/
int mgr_get_dcd_handle(struct mgr_object *hMGRHandle,
OUT u32 *phDCDHandle)
{
int status = -EPERM;
struct mgr_object *pmgr_obj = (struct mgr_object *)hMGRHandle;
DBC_REQUIRE(refs > 0);
DBC_REQUIRE(phDCDHandle != NULL);
*phDCDHandle = (u32) NULL;
if (pmgr_obj) {
*phDCDHandle = (u32) pmgr_obj->hdcd_mgr;
status = 0;
}
DBC_ENSURE((DSP_SUCCEEDED(status) && *phDCDHandle != (u32) NULL) ||
(DSP_FAILED(status) && *phDCDHandle == (u32) NULL));
return status;
}
/*
* ======== mgr_init ========
* Initialize MGR's private state, keeping a reference count on each call.
*/
bool mgr_init(void)
{
bool ret = true;
bool init_dcd = false;
DBC_REQUIRE(refs >= 0);
if (refs == 0) {
init_dcd = dcd_init(); /* DCD Module */
if (!init_dcd)
ret = false;
}
if (ret)
refs++;
DBC_ENSURE((ret && (refs > 0)) || (!ret && (refs >= 0)));
return ret;
}
/*
* ======== mgr_wait_for_bridge_events ========
* Block on any Bridge event(s)
*/
int mgr_wait_for_bridge_events(struct dsp_notification **anotifications,
u32 count, OUT u32 *pu_index,
u32 utimeout)
{
int status;
struct sync_object *sync_events[MAX_EVENTS];
u32 i;
DBC_REQUIRE(count < MAX_EVENTS);
for (i = 0; i < count; i++)
sync_events[i] = anotifications[i]->handle;
status = sync_wait_on_multiple_events(sync_events, count, utimeout,
pu_index);
return status;
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
/*
* pwr.c
*
* DSP-BIOS Bridge driver support functions for TI OMAP processors.
*
* PWR API for controlling DSP power states.
*
* Copyright (C) 2005-2006 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* ----------------------------------- Host OS */
#include <dspbridge/host_os.h>
/* ----------------------------------- This */
#include <dspbridge/pwr.h>
/* ----------------------------------- Resource Manager */
#include <dspbridge/devdefs.h>
#include <dspbridge/drv.h>
/* ----------------------------------- Platform Manager */
#include <dspbridge/dev.h>
/* ----------------------------------- Link Driver */
#include <dspbridge/dspioctl.h>
/*
* ======== pwr_sleep_dsp ========
* Send command to DSP to enter sleep state.
*/
int pwr_sleep_dsp(IN CONST u32 sleepCode, IN CONST u32 timeout)
{
struct bridge_drv_interface *intf_fxns;
struct bridge_dev_context *dw_context;
int status = -EPERM;
struct dev_object *hdev_obj = NULL;
u32 ioctlcode = 0;
u32 arg = timeout;
for (hdev_obj = (struct dev_object *)drv_get_first_dev_object();
hdev_obj != NULL;
hdev_obj =
(struct dev_object *)drv_get_next_dev_object((u32) hdev_obj)) {
if (DSP_FAILED(dev_get_bridge_context(hdev_obj,
(struct bridge_dev_context **)
&dw_context))) {
continue;
}
if (DSP_FAILED(dev_get_intf_fxns(hdev_obj,
(struct bridge_drv_interface **)
&intf_fxns))) {
continue;
}
if (sleepCode == PWR_DEEPSLEEP)
ioctlcode = BRDIOCTL_DEEPSLEEP;
else if (sleepCode == PWR_EMERGENCYDEEPSLEEP)
ioctlcode = BRDIOCTL_EMERGENCYSLEEP;
else
status = -EINVAL;
if (status != -EINVAL) {
status = (*intf_fxns->pfn_dev_cntrl) (dw_context,
ioctlcode,
(void *)&arg);
}
}
return status;
}
/*
* ======== pwr_wake_dsp ========
* Send command to DSP to wake it from sleep.
*/
int pwr_wake_dsp(IN CONST u32 timeout)
{
struct bridge_drv_interface *intf_fxns;
struct bridge_dev_context *dw_context;
int status = -EPERM;
struct dev_object *hdev_obj = NULL;
u32 arg = timeout;
for (hdev_obj = (struct dev_object *)drv_get_first_dev_object();
hdev_obj != NULL;
hdev_obj = (struct dev_object *)drv_get_next_dev_object
((u32) hdev_obj)) {
if (DSP_SUCCEEDED(dev_get_bridge_context(hdev_obj,
(struct bridge_dev_context
**)&dw_context))) {
if (DSP_SUCCEEDED
(dev_get_intf_fxns
(hdev_obj,
(struct bridge_drv_interface **)&intf_fxns))) {
status =
(*intf_fxns->pfn_dev_cntrl) (dw_context,
BRDIOCTL_WAKEUP,
(void *)&arg);
}
}
}
return status;
}
/*
* ======== pwr_pm_pre_scale========
* Sends pre-notification message to DSP.
*/
int pwr_pm_pre_scale(IN u16 voltage_domain, u32 level)
{
struct bridge_drv_interface *intf_fxns;
struct bridge_dev_context *dw_context;
int status = -EPERM;
struct dev_object *hdev_obj = NULL;
u32 arg[2];
arg[0] = voltage_domain;
arg[1] = level;
for (hdev_obj = (struct dev_object *)drv_get_first_dev_object();
hdev_obj != NULL;
hdev_obj = (struct dev_object *)drv_get_next_dev_object
((u32) hdev_obj)) {
if (DSP_SUCCEEDED(dev_get_bridge_context(hdev_obj,
(struct bridge_dev_context
**)&dw_context))) {
if (DSP_SUCCEEDED
(dev_get_intf_fxns
(hdev_obj,
(struct bridge_drv_interface **)&intf_fxns))) {
status =
(*intf_fxns->pfn_dev_cntrl) (dw_context,
BRDIOCTL_PRESCALE_NOTIFY,
(void *)&arg);
}
}
}
return status;
}
/*
* ======== pwr_pm_post_scale========
* Sends post-notification message to DSP.
*/
int pwr_pm_post_scale(IN u16 voltage_domain, u32 level)
{
struct bridge_drv_interface *intf_fxns;
struct bridge_dev_context *dw_context;
int status = -EPERM;
struct dev_object *hdev_obj = NULL;
u32 arg[2];
arg[0] = voltage_domain;
arg[1] = level;
for (hdev_obj = (struct dev_object *)drv_get_first_dev_object();
hdev_obj != NULL;
hdev_obj = (struct dev_object *)drv_get_next_dev_object
((u32) hdev_obj)) {
if (DSP_SUCCEEDED(dev_get_bridge_context(hdev_obj,
(struct bridge_dev_context
**)&dw_context))) {
if (DSP_SUCCEEDED
(dev_get_intf_fxns
(hdev_obj,
(struct bridge_drv_interface **)&intf_fxns))) {
status =
(*intf_fxns->pfn_dev_cntrl) (dw_context,
BRDIOCTL_POSTSCALE_NOTIFY,
(void *)&arg);
}
}
}
return status;
}
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册