aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/shost/shost_mem.h
blob: ecbbed2b3d903bfd4229914b8882cd1e2790fade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/****************************************************************************
 *  (C) Copyright 2008 Samsung Electronics Co., Ltd., All rights reserved
 *
 * @file   s3c-otg-hcdi-memory.h
 * @brief  header of s3c-otg-hcdi-memory \n
 * @version
 *  -# Jun 9,2008 v1.0 by SeungSoo Yang (ss1.yang@samsung.com) \n
 *	  : Creating the initial version of this code \n
 *  -# Jul 15,2008 v1.2 by SeungSoo Yang (ss1.yang@samsung.com) \n
 *	  : Optimizing for performance \n
 * @see None
 ****************************************************************************/
/****************************************************************************
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ****************************************************************************/

#ifndef _S3C_OTG_HCDI_MEMORY_H_
#define _S3C_OTG_HCDI_MEMORY_H_


#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/mm.h>

/**
 * @enum otg_mem_alloc_flag
 *
 * @brief enumeration for flag of memory allocation
 */
enum otg_mem_type {
	USB_MEM_SYNC,
	USB_MEM_ASYNC,
	USB_MEM_DMA
};

/**
 * int	otg_mem_alloc(void ** addr_pp, u16 byte_size, u8 ubType);
 *
 * @brief allocating momory specified
 *
 * @param  [inout] addr_pp : address to be assigned
 *         [in] byte_size : size of memory
 *         [in] type : enum otg_mem_type
 *
 * @return USB_ERR_SUCCESS : If success \n
 *		   USB_ERR_FAIL : If call fail \n
 */
static	inline	int
otg_mem_alloc(void **addr_pp, u16 byte_size,
		enum otg_mem_type type)
{
	gfp_t flags;
	otg_dbg(OTG_DBG_OTGHCDI_MEM, "otg_mem_alloc\n");

	switch (type) {
	case USB_MEM_SYNC:
		flags = GFP_KERNEL;
		break;
	case USB_MEM_ASYNC:
		flags = GFP_ATOMIC;
		break;
	case USB_MEM_DMA:
		flags = GFP_DMA;
		break;
	default:
		otg_err(OTG_DBG_OTGHCDI_MEM,
			"not proper enum otg_mem_type\n");
		return USB_ERR_FAIL;
	}

	*addr_pp = kmalloc((size_t)byte_size, flags);

	if (*addr_pp == 0) {
		otg_err(OTG_DBG_OTGHCDI_MEM, "kmalloc failed\n");
		return USB_ERR_FAIL;
	}
	return USB_ERR_SUCCESS;
}

/**
 * int	otg_mem_copy(void *to_addr_p, void *from_addr_p, u16 byte_size);
 *
 * @brief memory copy
 *
 * @param  [in] to_addr_p : target address
 *         [in] from_addr_p : source address
 *         [in] byte_size : size
 *
 * @return USB_ERR_SUCCESS : If success \n
 *	       USB_ERR_FAIL : If call fail \n
 */
static	inline	int
otg_mem_copy(void *to_addr_p,
		void *from_addr_p, u16 byte_size)
{
	otg_dbg(OTG_DBG_OTGHCDI_MEM, "otg_mem_copy\n");

	memcpy(to_addr_p, from_addr_p, (size_t)byte_size);

	return USB_ERR_SUCCESS;
}

/**
 * int	otg_mem_free(void * addr_p);
 *
 * @brief de-allocating memory
 *
 * @param  [in] addr_p : target address to be de-allocated
 *
 * @return USB_ERR_SUCCESS : If success \n
 *	       USB_ERR_FAIL : If call fail \n
 */
static	inline	int
otg_mem_free(void *addr_p)
{
	otg_dbg(OTG_DBG_OTGHCDI_MEM, "otg_mem_free\n");
	kfree(addr_p);
	return USB_ERR_SUCCESS;
}


/**
 * int	otg_mem_set(void *addr_p, char value, u16 byte_size)
 *
 * @brief writing a value to memory
 *
 * @param  [in] addr_p : target address
 *         [in] value : value to be written
 *         [in] byte_size : size
 *
 * @return USB_ERR_SUCCESS : If success \n
 *		   USB_ERR_FAIL : If call fail \n
 */
static	inline	int
otg_mem_set(void *addr_p, char value, u16 byte_size)
{
	otg_dbg(OTG_DBG_OTGHCDI_MEM, "otg_mem_set\n");
	memset(addr_p, value, (size_t)byte_size);
	return USB_ERR_SUCCESS;
}


#endif /* _S3C_OTG_HCDI_MEMORY_H_ */