From: Kitae Kim Date: Wed, 29 Aug 2012 13:10:14 +0000 (+0900) Subject: [Title] change a way to use device memory of codec module and souce clean-up X-Git-Tag: 2.2.1_release^2~88^2~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=357cf535cec0ad003f4df80ee5fafb0e3b62aa00;p=sdk%2Femulator%2Femulator-kernel.git [Title] change a way to use device memory of codec module and souce clean-up [Type] enhancement [Module] emulator / codec [Priority] Major [CQ#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- diff --git a/drivers/maru/maru_codec.c b/drivers/maru/maru_codec.c index 35d04ebcdbb7..aeecb0642204 100644 --- a/drivers/maru/maru_codec.c +++ b/drivers/maru/maru_codec.c @@ -52,18 +52,16 @@ MODULE_DESCRIPTION("Virtual Codec Device Driver"); MODULE_AUTHOR("Kitae KIM availableMem == 0) + svcodec->availableMem = 1; + else + svcodec->availableMem = -1; + + } else if (cmd == EMUL_UNLOCK_MEM_REGION) { + svcodec->availableMem = 0; + } else { + CODEC_LOG(KERN_ERR, "there is no command.\n"); + } + + if (copy_to_user((void *)arg, + &svcodec->availableMem, + sizeof(int))) + CODEC_LOG(KERN_ERR, "failed to copy data to user\n"); + + mutex_unlock(&codec_mutex); + + return 0; +} + static ssize_t svcodec_read(struct file *file, char __user *buf, size_t count, loff_t *fops) { @@ -143,61 +169,19 @@ static ssize_t svcodec_write(struct file *file, const char __user *buf, CODEC_LOG(KERN_ERR, "failed to get codec parameter info from user\n"); - - if (paramInfo.apiIndex == EMUL_GET_MMAP_INDEX) { - int i = 0; - int max_size = USABLE_MMAP_MAX_SIZE; - int *mmapIndex = (int *)paramInfo.ret; - uint8_t *useMmapSize = &svcodec->useMmap[max_size]; - - CODEC_LOG(KERN_DEBUG, "before available useMmap count:%d\n", - (max_size - *useMmapSize)); - - for (; i < max_size; i++) { - if (svcodec->useMmap[i] == 1) { - svcodec->useMmap[i] = 0; - (*useMmapSize)++; - file->private_data = &svcodec->useMmap[i]; - CODEC_LOG(KERN_DEBUG, - "useMmap[%d]=%d\n", i, svcodec->useMmap[i]); - CODEC_LOG(KERN_DEBUG, - "file:%p private_data:%p\n", - file, file->private_data); - CODEC_LOG(KERN_DEBUG, - "after available useMmap count:%d\n", - (max_size - *useMmapSize)); - CODEC_LOG(KERN_DEBUG, - "return %d as the index of mmap\n", i); - break; - } - } - - if (i == max_size) { - CODEC_LOG(KERN_DEBUG, - "Usable mmap is none! struct file:%p\n", file); - i = -1; - } - - if (copy_to_user((void *)mmapIndex, &i, sizeof(int))) - CODEC_LOG(KERN_ERR, - "failed to copy the index value to user.\n"); - mutex_unlock(&codec_mutex); - return 0; - } - - if (paramInfo.apiIndex == EMUL_AVCODEC_ALLOC_CONTEXT) + if (paramInfo.api_index == EMUL_AVCODEC_ALLOC_CONTEXT) writel((uint32_t)file, svcodec->ioaddr + CODEC_FILE_INDEX); - writel((uint32_t)paramInfo.ctxIndex, + writel((uint32_t)paramInfo.ctx_index, svcodec->ioaddr + CODEC_CONTEXT_INDEX); - writel((uint32_t)paramInfo.mmapOffset, + writel((uint32_t)paramInfo.mmap_offset, svcodec->ioaddr + CODEC_MMAP_OFFSET); - writel((uint32_t)paramInfo.apiIndex, + writel((uint32_t)paramInfo.api_index, svcodec->ioaddr + CODEC_API_INDEX); /* wait decoding or encoding job */ - if (paramInfo.apiIndex >= EMUL_AVCODEC_DECODE_VIDEO && - paramInfo.apiIndex <= EMUL_AVCODEC_ENCODE_AUDIO) { + if (paramInfo.api_index >= EMUL_AVCODEC_DECODE_VIDEO && + paramInfo.api_index <= EMUL_AVCODEC_ENCODE_AUDIO) { wait_event_interruptible(svcodec->codec_wq, svcodec->sleep_flag != 0); svcodec->sleep_flag = 0; @@ -243,14 +227,15 @@ static irqreturn_t svcodec_irq_handler (int irq, void *dev_id) int val = 0; unsigned long flags; +/* spin_lock_irqsave(&dev->lock, flags); */ + val = readl(dev->ioaddr + CODEC_QUERY_STATE); if (!(val & CODEC_IRQ)) { - CODEC_LOG(KERN_DEBUG, "this irq is not for this module.\n"); + spin_unlock_irqrestore(&dev->lock, flags); return IRQ_NONE; } spin_lock_irqsave(&dev->lock, flags); - CODEC_LOG(KERN_DEBUG, "irq is for this module.\n"); dev->sleep_flag = 1; wake_up_interruptible(&dev->codec_wq); @@ -262,14 +247,11 @@ static irqreturn_t svcodec_irq_handler (int irq, void *dev_id) static int svcodec_open(struct inode *inode, struct file *file) { - int i, max_size = USABLE_MMAP_MAX_SIZE; - mutex_lock(&codec_mutex); CODEC_LOG(KERN_DEBUG, "open! struct file:%p\n", file); svcodec->sleep_flag = 0; - CODEC_LOG(KERN_DEBUG, "register irq handler\n"); /* register interrupt handler */ if (request_irq(svcodec->dev->irq, svcodec_irq_handler, IRQF_SHARED, DRIVER_NAME, svcodec)) { @@ -277,15 +259,6 @@ static int svcodec_open(struct inode *inode, struct file *file) return -EBUSY; } - /* reset useMmap array */ - if (svcodec->useMmap[max_size] == 0) { - for (i = 0; i < max_size; i++) { - svcodec->useMmap[i] = 1; - CODEC_LOG(KERN_DEBUG, "reset useMmap[%d]=%d\n", - i, svcodec->useMmap[i]); - } - } - try_module_get(THIS_MODULE); mutex_unlock(&codec_mutex); @@ -294,9 +267,6 @@ static int svcodec_open(struct inode *inode, struct file *file) static int svcodec_release(struct inode *inode, struct file *file) { - int max_size = USABLE_MMAP_MAX_SIZE; - uint8_t *useMmap; - mutex_lock(&codec_mutex); /* free irq */ @@ -304,29 +274,12 @@ static int svcodec_release(struct inode *inode, struct file *file) CODEC_LOG(KERN_DEBUG, "free registered irq\n"); free_irq(svcodec->dev->irq, svcodec); } + svcodec->availableMem = 0; - /* manage codec context */ - useMmap = (uint8_t *)file->private_data; - CODEC_LOG(KERN_DEBUG, - "close! struct file:%p, priv_data:%p\n", file, useMmap); - - if (file && file->private_data) { - if (svcodec->useMmap[max_size] > 0) - (svcodec->useMmap[max_size])--; - *useMmap = 1; - CODEC_LOG(KERN_DEBUG, "available useMmap count:%d\n", - (max_size - svcodec->useMmap[max_size])); - - /* notify closing codec device of qemu. */ + /* notify closing codec device of qemu. */ + if (file) writel((uint32_t)file, svcodec->ioaddr + CODEC_CLOSED); - } -#ifdef CODEC_DEBUG - int i; - for (i = 0; i < max_size; i++) - CODEC_LOG(KERN_DEBUG, "useMmap[%d]=%d\n", - i, svcodec->useMmap[i]); -#endif module_put(THIS_MODULE); mutex_unlock(&codec_mutex); @@ -335,12 +288,13 @@ static int svcodec_release(struct inode *inode, struct file *file) /* define file opertion for CODEC */ const struct file_operations svcodec_fops = { - .owner = THIS_MODULE, - .read = svcodec_read, - .write = svcodec_write, - .open = svcodec_open, - .mmap = svcodec_mmap, - .release = svcodec_release, + .owner = THIS_MODULE, + .read = svcodec_read, + .write = svcodec_write, + .unlocked_ioctl = svcodec_ioctl, + .open = svcodec_open, + .mmap = svcodec_mmap, + .release = svcodec_release, }; static int __devinit svcodec_probe(struct pci_dev *pci_dev,