MODULE_AUTHOR("Kitae KIM <kt920.kim@samsung.com");
MODULE_LICENSE("GPL2");
-#define CODEC_LOG(log_level, fmt, ...) \
- printk(log_level "[%s][%d]: " fmt, DEVICE_NAME, __LINE__, ##__VA_ARGS__)
+#ifndef CODEC_DEBUG
+#define CODEC_LOG(fmt, ...) \
+ printk(KERN_DEBUG "[%s][%d]: " fmt, DEVICE_NAME, __LINE__, ##__VA_ARGS__)
+#else
+#define CODEC_LOG(fmt, ...)
+#endif
#define NEWCODEC_IRQ_SHARED_TASK 0x1f
#define NEWCODEC_IRQ_FIXED_TASK 0x2f
{
int32_t value;
- CODEC_LOG(KERN_DEBUG, "shared_bh func.\n");
+ CODEC_LOG("shared_bh func.\n");
do {
value = readl(newcodec->ioaddr + CODEC_CMD_GET_SHARED_QUEUE);
- CODEC_LOG(KERN_DEBUG, "file value of head task: %x.\n", value);
+ CODEC_LOG("file value of head task: %x.\n", value);
if (value) {
newcodec_add_task(&newcodec->req_task, value);
} else {
- CODEC_LOG(KERN_DEBUG, "there is no available task\n");
+ CODEC_LOG("there is no available task\n");
}
} while (value);
}
static void newcodec_shared_bh(struct newcodec_device *dev)
{
- CODEC_LOG(KERN_DEBUG, "request bottom-half operation.\n");
+ CODEC_LOG("request bottom-half operation.\n");
queue_work(newcodec_bh_workqueue, &newcodec_shared_bh_work);
}
{
uint32_t value;
- CODEC_LOG(KERN_DEBUG, "fixed_bh func.\n");
+ CODEC_LOG("fixed_bh func.\n");
do {
value = readl(newcodec->ioaddr + CODEC_CMD_GET_FIXED_QUEUE);
- CODEC_LOG(KERN_DEBUG, "file value of head task: %x.\n", value);
+ CODEC_LOG("file value of head task: %x.\n", value);
if (value) {
newcodec_add_task(&newcodec->irq_task, value);
} else {
- CODEC_LOG(KERN_DEBUG, "there is no available task\n");
+ CODEC_LOG("there is no available task\n");
}
} while (value);
+
+ mutex_unlock(&newcodec_mutex);
}
static void newcodec_fixed_bh(struct newcodec_device *dev)
{
- CODEC_LOG(KERN_DEBUG, "request bottom-half operation.\n");
+ CODEC_LOG("request bottom-half operation.\n");
queue_work(newcodec_bh_workqueue, &newcodec_fixed_bh_work);
}
temp = kzalloc(sizeof(struct newcodec_task), GFP_KERNEL);
if (!temp) {
- CODEC_LOG(KERN_ERR, "Failed to allocate memory.\n");
+ printk(KERN_ERR "Failed to allocate memory.\n");
return;
}
- CODEC_LOG(KERN_DEBUG, "add task. file: %x\n", file);
+ CODEC_LOG("add task. file: %x\n", file);
temp->id = file;
INIT_LIST_HEAD(&temp->entry);
list_for_each_safe(pos, temp, head) {
node = list_entry(pos, struct newcodec_task, entry);
if (node && node->id == value) {
- CODEC_LOG(KERN_DEBUG, "release task resource. :%x\n", node->id);
+ CODEC_LOG("release task resource. :%x\n", node->id);
list_del(pos);
kfree(node);
}
struct newcodec_mmapmgr *mem_mgr;
mem_mgr = &newcodec->mem_mgr[newcodec->mmapmgr_idx];
- CODEC_LOG(KERN_DEBUG, "[file: %x] mem index: %d\n",
+ CODEC_LOG("[file: %x] mem index: %d\n",
file, newcodec->mmapmgr_idx);
if ((used_mem_size + req_mem_size) < NEWCODEC_FIXED_DEV_MEM_MAX) {
} else {
mem_mgr->id = file;
mem_mgr->offset = NEWCODEC_FIXED_DEV_MEM_MAX;
-
mem_info->type = CODEC_SHARED_DEVICE_MEM;
}
}
return 0;
-// return ret;
}
switch (cmd) {
case CODEC_CMD_ADD_TASK_QUEUE:
- CODEC_LOG(KERN_DEBUG, "add task into req_task.\n");
+ CODEC_LOG("add task into req_task.\n");
newcodec_add_task(&newcodec->req_task, (int32_t)file);
break;
case CODEC_CMD_REMOVE_TASK_QUEUE:
head_task =
list_first_entry(&newcodec->req_task, struct newcodec_task, entry);
if (!head_task) {
- CODEC_LOG(KERN_DEBUG, "[file: %p] head_task is NULL\n", file);
+ CODEC_LOG("[file: %p] head_task is NULL\n", file);
} else {
- CODEC_LOG(KERN_DEBUG,
- "[file: %p] head_task of req: %x into old_task\n",
+ CODEC_LOG("[file: %p] head_task of req: %x into old_task\n",
file, head_task->id);
mutex_lock(&newcodec_mutex);
list_move_tail(&head_task->entry, &newcodec->old_task);
mutex_unlock(&newcodec_mutex);
- CODEC_LOG(KERN_DEBUG, "release old_task resource.\n");
+ CODEC_LOG("release old_task resource.\n");
newcodec_release_task_entry(&newcodec->old_task, (int32_t)file);
}
}
{
struct newcodec_task *head_task = NULL;
- CODEC_LOG(KERN_DEBUG, "[file: %p] COPY_TO_DEV_MEM\n", file);
+ CODEC_LOG("[file: %p] COPY_TO_DEV_MEM\n", file);
mutex_lock(&newcodec_mutex);
if (!list_empty(&newcodec->req_task)) {
mutex_unlock(&newcodec_mutex);
head_task =
list_first_entry(&newcodec->req_task, struct newcodec_task, entry);
if (!head_task) {
- CODEC_LOG(KERN_DEBUG, "[file: %p] head_task is NULL\n", file);
+ CODEC_LOG("[file: %p] head_task is NULL\n", file);
value = CODEC_MEM_LOCK;
break;
}
- CODEC_LOG(KERN_DEBUG, "[file: %p] COPY_TO head_task: %x\n", file, head_task->id);
+ CODEC_LOG("[file: %p] COPY_TO head_task: %x\n", file, head_task->id);
if (head_task->id != (int32_t)file) {
- CODEC_LOG(KERN_DEBUG, "[file: %p] different file btw head and file\n", file);
+ CODEC_LOG("[file: %p] different file btw head and file\n", file);
value = CODEC_MEM_LOCK;
} else {
- CODEC_LOG(KERN_DEBUG, "[file: %p] handle head_task: %x\n", file, head_task->id);
- CODEC_LOG(KERN_DEBUG, "[file: %p] COPY_TO_DEV is accept.\n", file);
+ CODEC_LOG("[file: %p] handle head_task: %x\n", file, head_task->id);
+ CODEC_LOG("[file: %p] COPY_TO_DEV is accept.\n", file);
value = CODEC_MEM_UNLOCK;
}
} else {
mutex_unlock(&newcodec_mutex);
- CODEC_LOG(KERN_DEBUG, "[file: %p] COPY_TO_DEV_MEM req_task is empty\n", file);
+ CODEC_LOG("[file: %p] COPY_TO_DEV_MEM req_task is empty\n", file);
value = CODEC_MEM_LOCK;
}
if (copy_to_user((void *)arg, &value, sizeof(int))) {
- CODEC_LOG(KERN_ERR, "ioctl: failed to copy data to user.\n");
+ printk(KERN_ERR "ioctl: failed to copy data to user.\n");
ret = -EIO;
}
}
{
struct newcodec_task *head_task = NULL;
- CODEC_LOG(KERN_DEBUG, "[file: %p] COPY_FROM_DEV_MEM\n", file);
+ CODEC_LOG("[file: %p] COPY_FROM_DEV_MEM\n", file);
mutex_lock(&newcodec_mutex);
if (!list_empty(&newcodec->req_task)) {
list_first_entry(&newcodec->req_task, struct newcodec_task, entry))) {
value = CODEC_MEM_LOCK;
if (copy_to_user((void *)arg, &value, sizeof(int))) {
- CODEC_LOG(KERN_DEBUG,
- "ioctl: failed to copy data to user.\n");
+ printk(KERN_ERR "ioctl: failed to copy data to user.\n");
ret = -EIO;
}
break;
}
- CODEC_LOG(KERN_DEBUG,
- "[file: %p] COPY_FROM head_task: %x\n",
+ CODEC_LOG("[file: %p] COPY_FROM head_task: %x\n",
file, head_task->id);
if (head_task->id != (int32_t)file) {
- CODEC_LOG(KERN_DEBUG,
- "[file: %p] different file btw head and file\n", file);
+ CODEC_LOG("[file: %p] different file btw head and file\n", file);
value = CODEC_MEM_LOCK;
} else {
- CODEC_LOG(KERN_DEBUG,
- "[file: %p] pop data %x from codec_wq.\n",
+ CODEC_LOG("[file: %p] pop data %x from codec_wq.\n",
file, head_task->id);
value = CODEC_MEM_UNLOCK;
}
} else {
mutex_unlock(&newcodec_mutex);
- CODEC_LOG(KERN_DEBUG,
- "[file: %p] COPY_FROM_DEV_MEM req_task is empty\n", file);
+ CODEC_LOG("[file: %p] COPY_FROM_DEV_MEM req_task is empty\n", file);
value = CODEC_MEM_LOCK;
}
if (copy_to_user((void *)arg, &value, sizeof(int))) {
- CODEC_LOG(KERN_DEBUG, "ioctl: failed to copy data to user.\n");
+ printk(KERN_ERR "ioctl: failed to copy data to user.\n");
ret = -EIO;
}
}
struct codec_mem_info mem_info;
if (copy_from_user(&mem_info, (void *)arg, sizeof(mem_info))) {
- CODEC_LOG(KERN_DEBUG, "ioctl: failed to copy data to user\n");
+ printk(KERN_ERR "ioctl: failed to copy data to user\n");
ret = -EIO;
break;
}
- CODEC_LOG(KERN_DEBUG, "request memory size: %d\n", mem_info.index);
+ CODEC_LOG("request memory size: %d\n", mem_info.index);
newcodec_manage_dev_mem(&mem_info, (int32_t)file);
if (copy_to_user((void *)arg, &mem_info, sizeof(mem_info))) {
- CODEC_LOG(KERN_DEBUG,
- "ioctl: failed to copy data to user.\n");
+ printk(KERN_ERR "ioctl: failed to copy data to user.\n");
ret = -EIO;
}
}
struct codec_mem_info mem_info;
if (copy_from_user(&mem_info, (void *)arg, sizeof(mem_info))) {
- CODEC_LOG(KERN_DEBUG, "ioctl: failed to copy data to user\n");
+ printk(KERN_ERR "ioctl: failed to copy data to user\n");
ret = -EIO;
break;
}
- CODEC_LOG(KERN_DEBUG, "release memory size: %d\n", mem_info.index);
+ CODEC_LOG("release memory size: %d\n", mem_info.index);
mem_mgr = &newcodec->mem_mgr[mem_info.index];
if (mem_mgr->id == (int32_t)file &&
}
}
break;
+#if 0
case CODEC_CMD_WAIT_TASK_QUEUE:
{
value = CODEC_MEM_LOCK;
+ mutex_lock(&newcodec_mutex);
if (!list_empty(&newcodec->irq_task)) {
+#if 0
struct newcodec_task *head_task = NULL;
head_task =
list_first_entry(&newcodec->irq_task, struct newcodec_task, entry);
if (!head_task) {
- CODEC_LOG(KERN_DEBUG,
- "[file: %p] head_task is NULL\n", file);
+ CODEC_LOG("[file: %p] head_task is NULL\n", file);
} else {
- CODEC_LOG(KERN_DEBUG,
- "[file: %p] head_task id: %x\n", file, head_task->id);
+ CODEC_LOG("[file: %p] head_task id: %x\n", file, head_task->id);
if (head_task->id == (int32_t)file) {
value = CODEC_MEM_UNLOCK;
list_del(&head_task->entry);
kfree(head_task);
}
}
+#endif
+#if 1
+ {
+ struct list_head *pos, *temp;
+ struct newcodec_task *node;
+
+ list_for_each_safe(pos, temp, &newcodec->irq_task) {
+ node = list_entry(pos, struct newcodec_task, entry);
+ if (node->id == (int32_t)file) {
+ value = CODEC_MEM_UNLOCK;
+ CODEC_LOG("The task_id is done. %x\n", node->id);
+ list_del(pos);
+ kfree(node);
+ }
+ }
+ }
+#endif
+ mutex_unlock(&newcodec_mutex);
} else {
- CODEC_LOG(KERN_DEBUG, "[file: %p] irq_task is empty\n", file);
+ mutex_unlock(&newcodec_mutex);
+ CODEC_LOG("[file: %p] irq_task is empty\n", file);
}
if (copy_to_user((void *)arg, &value, sizeof(int))) {
- CODEC_LOG(KERN_ERR, "ioctl: failed to copy data to user\n");
+ printk(KERN_ERR "ioctl: failed to copy data to user\n");
ret = -EIO;
}
}
break;
+#endif
+#if 1
+ case CODEC_CMD_WAIT_TASK_QUEUE:
+ {
+// printk(KERN_INFO "wait_event\n");
+ mutex_lock(&newcodec_mutex);
+
+ {
+ struct list_head *pos, *temp;
+ struct newcodec_task *node;
+
+ list_for_each_safe(pos, temp, &newcodec->irq_task) {
+ node = list_entry(pos, struct newcodec_task, entry);
+ if (node->id == (int32_t)file) {
+ CODEC_LOG("The task_id is done. %x\n", node->id);
+ list_del(pos);
+ kfree(node);
+ } else {
+ }
+ }
+ }
+
+// printk(KERN_INFO "wake_up_event\n");
+ mutex_unlock(&newcodec_mutex);
+ }
+ break;
+#endif
case CODEC_CMD_GET_VERSION:
case CODEC_CMD_GET_CONTEXT_INDEX:
value = readl(newcodec->ioaddr + cmd);
if (copy_to_user((void *)arg, &value, sizeof(int))) {
- CODEC_LOG(KERN_ERR, "ioctl: failed to copy data to user\n");
+ printk(KERN_ERR "ioctl: failed to copy data to user\n");
ret = -EIO;
}
break;
default:
- CODEC_LOG(KERN_DEBUG, "no available command.");
+ CODEC_LOG("no available command.");
break;
}
static ssize_t newcodec_read(struct file *file, char __user *buf,
size_t count, loff_t *fops)
{
- CODEC_LOG(KERN_DEBUG, "do nothing in the read operation.\n");
+ CODEC_LOG("do nothing in the read operation.\n");
return 0;
}
struct codec_param param_info;
if (!newcodec) {
- CODEC_LOG(KERN_ERR, "failed to get codec device info\n");
+ printk(KERN_ERR "failed to get codec device info\n");
return -EINVAL;
}
memset (¶m_info, 0x00, sizeof(struct codec_param));
if (copy_from_user(¶m_info, buf, sizeof(struct codec_param))) {
- CODEC_LOG(KERN_ERR,
+ printk(KERN_ERR
"failed to get codec parameter info from user\n");
return -EIO;
}
if (param_info.api_index == CODEC_ELEMENT_QUERY) {
writel((int32_t)param_info.api_index,
newcodec->ioaddr + CODEC_CMD_API_INDEX);
+ mutex_unlock(&newcodec_mutex);
} else {
writel((int32_t)file,
newcodec->ioaddr + CODEC_CMD_FILE_INDEX);
head_task =
list_first_entry(&newcodec->req_task, struct newcodec_task, entry);
if (!head_task) {
- CODEC_LOG(KERN_DEBUG, "[file: %p] head_task is NULL\n", file);
+ CODEC_LOG("[file: %p] head_task is NULL\n", file);
} else {
- CODEC_LOG(KERN_DEBUG, "move head_task: %x into old_task\n", head_task->id);
+ CODEC_LOG("move head_task: %x into old_task\n", head_task->id);
list_move_tail(&head_task->entry, &newcodec->old_task);
}
}
}
}
- mutex_unlock(&newcodec_mutex);
+// mutex_unlock(&newcodec_mutex);
return 0;
}
size = vm->vm_end - vm->vm_start;
if (size > newcodec->mem_size) {
- CODEC_LOG(KERN_ERR, "over mapping size\n");
+ printk(KERN_ERR "over mapping size\n");
return -EINVAL;
}
off = vm->vm_pgoff << PAGE_SHIFT;
ret = remap_pfn_range(vm, vm->vm_start, phys_addr,
size, vm->vm_page_prot);
if (ret < 0) {
- CODEC_LOG(KERN_ERR, "failed to remap page range\n");
+ printk(KERN_ERR "failed to remap page range\n");
return -EAGAIN;
}
spin_lock_irqsave(&dev->lock, flags);
if (val == NEWCODEC_IRQ_SHARED_TASK) {
- CODEC_LOG(KERN_DEBUG, "handle shared_task irq\n");
+ CODEC_LOG("handle shared_task irq\n");
newcodec_shared_bh(dev);
} else if (val == NEWCODEC_IRQ_FIXED_TASK) {
- CODEC_LOG(KERN_DEBUG, "handle fixed_task irq\n");
+ CODEC_LOG("handle fixed_task irq\n");
newcodec_fixed_bh(dev);
}
static int newcodec_open(struct inode *inode, struct file *file)
{
- CODEC_LOG(KERN_DEBUG, "open! struct file:%p\n", file);
+ CODEC_LOG("open! struct file:%p\n", file);
/* register interrupt handler */
if (request_irq(newcodec->dev->irq, newcodec_irq_handler,
IRQF_SHARED, DEVICE_NAME, newcodec)) {
- CODEC_LOG(KERN_ERR, "failed to register irq handle\n");
+ printk(KERN_ERR "failed to register irq handle\n");
return -EBUSY;
}
{
/* free irq */
if (newcodec->dev->irq) {
- CODEC_LOG(KERN_DEBUG, "free registered irq\n");
+ CODEC_LOG("free registered irq\n");
free_irq(newcodec->dev->irq, newcodec);
}
/* free old_task resource */
- CODEC_LOG(KERN_DEBUG, "release old_task resource.\n");
+ CODEC_LOG("release old_task resource.\n");
newcodec_release_task_entry(&newcodec->old_task, (int32_t)file);
- CODEC_LOG(KERN_DEBUG, "release req_task resource.\n");
+ CODEC_LOG("release req_task resource.\n");
newcodec_release_task_entry(&newcodec->req_task, (int32_t)file);
- CODEC_LOG(KERN_DEBUG, "release irq_task resource.\n");
+ CODEC_LOG("release irq_task resource.\n");
newcodec_release_task_entry(&newcodec->irq_task, (int32_t)file);
#if 0
list_for_each_safe(pos, temp, &newcodec->old_task) {
node = list_entry(pos, struct newcodec_task, entry);
if (node->id == (int32_t)file) {
- CODEC_LOG(KERN_DEBUG,
- "release old_task resource. :%x\n", node->id);
+ CODEC_LOG("release old_task resource. :%x\n", node->id);
list_del(pos);
kfree(node);
}
list_for_each_safe(pos, temp, &newcodec->req_task) {
node = list_entry(pos, struct newcodec_task, entry);
if (node->id == (int32_t)file) {
- CODEC_LOG(KERN_DEBUG, "release req_task resource. :%x\n", node->id);
+ CODEC_LOG("release req_task resource. :%x\n", node->id);
list_del(pos);
kfree(node);
}
newcodec = kzalloc(sizeof(struct newcodec_device), GFP_KERNEL);
if (!newcodec) {
- CODEC_LOG(KERN_ERR, "Failed to allocate memory for codec.\n");
+ printk(KERN_ERR "Failed to allocate memory for codec.\n");
return -EIO;
}
newcodec->dev = pci_dev;
kzalloc(sizeof(struct newcodec_mmapmgr) *
newcodec->mmapmgr_size, GFP_KERNEL);
if (!newcodec->mem_mgr) {
- CODEC_LOG(KERN_ERR, "Failed to allocate memory.\n");
+ printk(KERN_ERR "Failed to allocate memory.\n");
return -EIO;
}
spin_lock_init(&newcodec->lock);
if ((ret = pci_enable_device(pci_dev))) {
- CODEC_LOG(KERN_ERR, "pci_enable_device failed\n");
+ printk(KERN_ERR "pci_enable_device failed\n");
return ret;
}
newcodec->mem_start = pci_resource_start(pci_dev, 0);
newcodec->mem_size = pci_resource_len(pci_dev, 0);
if (!newcodec->mem_start) {
- CODEC_LOG(KERN_ERR, "pci_resource_start failed\n");
+ printk(KERN_ERR "pci_resource_start failed\n");
pci_disable_device(pci_dev);
return -ENODEV;
}
if (!request_mem_region(newcodec->mem_start,
newcodec->mem_size,
DEVICE_NAME)) {
- CODEC_LOG(KERN_ERR, "request_mem_region failed\n");
+ printk(KERN_ERR "request_mem_region failed\n");
pci_disable_device(pci_dev);
return -EINVAL;
}
newcodec->io_start = pci_resource_start(pci_dev, 1);
newcodec->io_size = pci_resource_len(pci_dev, 1);
if (!newcodec->io_start) {
- CODEC_LOG(KERN_ERR, "pci_resource_start failed\n");
+ printk(KERN_ERR "pci_resource_start failed\n");
release_mem_region(newcodec->mem_start, newcodec->mem_size);
pci_disable_device(pci_dev);
return -ENODEV;
if (!request_mem_region(newcodec->io_start,
newcodec->io_size,
DEVICE_NAME)) {
- CODEC_LOG(KERN_ERR, "request_io_region failed\n");
+ printk(KERN_ERR "request_io_region failed\n");
release_mem_region(newcodec->mem_start, newcodec->mem_size);
pci_disable_device(pci_dev);
return -EINVAL;
newcodec->ioaddr = ioremap_nocache(newcodec->io_start, newcodec->io_size);
if (!newcodec->ioaddr) {
- CODEC_LOG(KERN_ERR, "ioremap failed\n");
+ printk(KERN_ERR "ioremap failed\n");
release_mem_region(newcodec->io_start, newcodec->io_size);
release_mem_region(newcodec->mem_start, newcodec->mem_size);
pci_disable_device(pci_dev);
ret = misc_register(&codec_dev);
if (ret) {
- CODEC_LOG(KERN_ERR, "cannot register codec as misc\n");
+ printk(KERN_ERR "cannot register codec as misc\n");
iounmap(newcodec->ioaddr);
release_mem_region(newcodec->io_start, newcodec->io_size);
release_mem_region(newcodec->mem_start, newcodec->mem_size);
newcodec_bh_workqueue = create_workqueue ("newcodec");
if (!newcodec_bh_workqueue) {
- CODEC_LOG(KERN_ERR, "failed to allocate workqueue\n");
+ printk(KERN_ERR "failed to allocate workqueue\n");
return -ENOMEM;
}