upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / usb / host / s3c-otg / s3c-otg-hcdi-memory.h
1 /****************************************************************************
2  *  (C) Copyright 2008 Samsung Electronics Co., Ltd., All rights reserved
3  *
4  * @file   s3c-otg-hcdi-memory.h
5  * @brief  header of s3c-otg-hcdi-memory \n
6  * @version
7  *  -# Jun 9,2008 v1.0 by SeungSoo Yang (ss1.yang@samsung.com) \n
8  *        : Creating the initial version of this code \n
9  *  -# Jul 15,2008 v1.2 by SeungSoo Yang (ss1.yang@samsung.com) \n
10  *        : Optimizing for performance \n
11  * @see None
12  ****************************************************************************/
13 /****************************************************************************
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27  ****************************************************************************/
28
29 #ifndef _S3C_OTG_HCDI_MEMORY_H_
30 #define _S3C_OTG_HCDI_MEMORY_H_
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36
37 #include "s3c-otg-common-common.h"
38 #include "s3c-otg-hcdi-debug.h"
39
40 #include <linux/kernel.h>
41 #include <linux/slab.h>
42 #include <linux/mm.h>
43 /**
44  * @enum otg_mem_alloc_flag
45  *
46  * @brief enumeration for flag of memory allocation
47  */
48 typedef
49 enum otg_mem_alloc_flag
50 {
51     USB_MEM_SYNC, USB_MEM_ASYNC, USB_MEM_DMA
52 }otg_mem_alloc_flag_t;
53 //---------------------------------------------------------------------------------------
54
55 /*
56 inline  int     otg_mem_alloc(void ** addr_pp, u16 byte_size, otg_mem_alloc_flag_t type);
57 inline  int     otg_mem_copy(void * to_addr_p, void * from_addr_p, u16 byte_size);
58 //inline        int     otg_mem_free(void * addr_p);
59 inline  int     otg_mem_set(void * addr_p, char value, u16 byte_size);
60 */
61
62 /**
63  * int  otg_mem_alloc(void ** addr_pp, u16 byte_size, u8 ubType);
64  *
65  * @brief allocating momory specified
66  *
67  * @param  [inout] addr_pp : address to be assigned
68  *         [in] byte_size : size of memory
69  *         [in] type : otg_mem_alloc_flag_t type
70  *
71  * @return USB_ERR_SUCCESS : If success \n
72  *                 USB_ERR_FAIL : If call fail \n
73  */
74 static  inline  int
75 otg_mem_alloc (
76         void ** addr_pp,
77         u16 byte_size,
78         otg_mem_alloc_flag_t type
79 )
80 {
81         gfp_t flags;
82         otg_dbg(OTG_DBG_OTGHCDI_MEM, "otg_mem_alloc \n");
83
84         switch(type) {
85         case USB_MEM_SYNC:
86                 flags = GFP_KERNEL;
87                 break;
88         case USB_MEM_ASYNC:
89                 flags = GFP_ATOMIC;
90                 break;
91         case USB_MEM_DMA:
92                 flags = GFP_DMA;
93                 break;
94         default:
95                 otg_err(OTG_DBG_OTGHCDI_MEM,
96                         "not proper otg_mem_alloc_flag_t in otg_mem_alloc \n");
97                 return USB_ERR_FAIL;
98         }
99
100         *addr_pp = kmalloc((size_t)byte_size, flags);
101         if(*addr_pp == 0) {
102                 otg_err(OTG_DBG_OTGHCDI_MEM,
103                         "kmalloc failed\n");
104                 return USB_ERR_FAIL;
105         }
106         return USB_ERR_SUCCESS;
107 }
108 //-------------------------------------------------------------------------------
109
110 /**
111  * int  otg_mem_copy(void * to_addr_p, void * from_addr_p, u16 byte_size);
112  *
113  * @brief memory copy
114  *
115  * @param  [in] to_addr_p : target address
116  *         [in] from_addr_p : source address
117  *         [in] byte_size : size
118  *
119  * @return USB_ERR_SUCCESS : If success \n
120  *             USB_ERR_FAIL : If call fail \n
121  */
122 static  inline  int
123 otg_mem_copy
124 (
125         void * to_addr_p,
126         void * from_addr_p,
127         u16 byte_size
128 )
129 {
130         otg_dbg(OTG_DBG_OTGHCDI_MEM,
131                 "otg_mem_copy \n");
132
133         memcpy(to_addr_p, from_addr_p, (size_t)byte_size);
134
135         return USB_ERR_SUCCESS;
136 }
137 //-------------------------------------------------------------------------------
138
139 /**
140  * int  otg_mem_free(void * addr_p);
141  *
142  * @brief de-allocating memory
143  *
144  * @param  [in] addr_p : target address to be de-allocated
145  *
146  * @return USB_ERR_SUCCESS : If success \n
147  *             USB_ERR_FAIL : If call fail \n
148  */
149 static  inline  int
150 otg_mem_free(void * addr_p)
151 {
152         otg_dbg(OTG_DBG_OTGHCDI_MEM,
153                 "otg_mem_free \n");
154         kfree(addr_p);
155         return USB_ERR_SUCCESS;
156 }
157
158 //-------------------------------------------------------------------------------
159
160 /**
161  * int  otg_mem_set(void * addr_p, char value, u16 byte_size)
162  *
163  * @brief writing a value to memory
164  *
165  * @param  [in] addr_p : target address
166  *         [in] value : value to be written
167  *         [in] byte_size : size
168  *
169  * @return USB_ERR_SUCCESS : If success \n
170  *                 USB_ERR_FAIL : If call fail \n
171  */
172 static  inline  int
173 otg_mem_set
174 (
175         void * addr_p,
176         char value,
177         u16 byte_size
178 )
179 {
180         otg_dbg(OTG_DBG_OTGHCDI_MEM,
181                 "otg_mem_set \n");
182         memset(addr_p, value, (size_t)byte_size);
183         return USB_ERR_SUCCESS;
184 }
185 //-------------------------------------------------------------------------------
186
187
188 #ifdef __cplusplus
189 }
190 #endif
191 #endif /* _S3C_OTG_HCDI_MEMORY_H_ */