upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / media / video / samsung / mfc5x / mfc_shm.c
1 /*
2  * linux/drivers/media/video/samsung/mfc5x/mfc_shm.c
3  *
4  * Copyright (c) 2010 Samsung Electronics Co., Ltd.
5  *              http://www.samsung.com/
6  *
7  * Shared memory interface file for Samsung MFC (Multi Function Codec - FIMV) driver
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include <linux/io.h>
15 #ifdef CONFIG_ARCH_S5PV210
16 #include <linux/dma-mapping.h>
17 #endif
18
19 #include "mfc_inst.h"
20 #include "mfc_mem.h"
21 #include "mfc_buf.h"
22 #include "mfc_log.h"
23
24 int init_shm(struct mfc_inst_ctx *ctx)
25 {
26         struct mfc_alloc_buffer *alloc;
27
28         alloc = _mfc_alloc_buf(ctx, MFC_SHM_SIZE, ALIGN_4B, MBT_SHM | PORT_A);
29
30         if (alloc != NULL) {
31                 ctx->shm = alloc->addr;
32                 ctx->shmofs = mfc_mem_base_ofs(alloc->real);
33
34                 memset((void *)ctx->shm, 0, MFC_SHM_SIZE);
35
36                 mfc_mem_cache_clean((void *)ctx->shm, MFC_SHM_SIZE);
37
38                 return 0;
39         }
40
41         mfc_err("failed alloc shared memory buffer\n");
42
43         ctx->shm = NULL;
44         ctx->shmofs = 0;
45
46         return -1;
47 }
48
49 void write_shm(struct mfc_inst_ctx *ctx, unsigned int data, unsigned int offset)
50 {
51         writel(data, (ctx->shm + offset));
52
53 #if defined(CONFIG_ARCH_S5PV210)
54         dma_cache_maint((void *)(ctx->shm + offset), 4, DMA_TO_DEVICE);
55 #elif defined(CONFIG_CPU_S5PV310)
56         mfc_mem_cache_clean((void *)((unsigned int)(ctx->shm) + offset), 4);
57 #endif
58 }
59
60 unsigned int read_shm(struct mfc_inst_ctx *ctx, unsigned int offset)
61 {
62 #if defined(CONFIG_ARCH_S5PV210)
63         dma_cache_maint((void *)(ctx->shm + offset), 4, DMA_FROM_DEVICE);
64 #elif defined(CONFIG_CPU_S5PV310)
65         mfc_mem_cache_inv((void *)((unsigned int)(ctx->shm) + offset), 4);
66 #endif
67         return readl(ctx->shm + offset);
68 }
69