summaryrefslogtreecommitdiff
path: root/arch/arm/plat-omap/include/syslink/sysmemmgr.h
blob: 34c3b4182288c95a86c70871ace7453a33be4177 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 *  sysmemmgr.h
 *
 *  Manager for the Slave system memory. Slave system level memory is allocated
 *  through this module.
 *
 *  Copyright (C) 2009 Texas Instruments, Inc.
 *
 *  This package is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 *  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 *  WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 *  PURPOSE.
 */


#ifndef _SYSTEMMEMORYMANAGER_H_
#define _SYSTEMMEMORYMANAGER_H_


/*!
 *  @def    SYSMEMMGR_MODULEID
 *  @brief  Module identifier for System memory manager.
 */
#define SYSMEMMGR_MODULEID		(0xb53d)

/*!
 *  @def    SYSMEMMGR_STATUSCODEBASE
 *  @brief  Error code base for system memory manager module.
 */
#define SYSMEMMGR_STATUSCODEBASE	(SYSMEMMGR_MODULEID << 12u)

/*!
 *  @def    SYSMEMMGR_MAKE_ERROR
 *  @brief  Macro to make error code.
 */
#define SYSMEMMGR_MAKE_ERROR(x)		((int)(0x80000000 + \
						(SYSMEMMGR_STATUSCODEBASE + \
						(x))))

/*!
 *  @def    SYSMEMMGR_MAKE_SUCCESS
 *  @brief  Macro to make success code.
 */
#define SYSMEMMGR_MAKE_SUCCESS(x)	(SYSMEMMGR_STATUSCODEBASE + (x))

/*!
 *  @def    SYSMEMMGR_E_CREATEALLOCATOR
 *  @brief  Static allocator creation failed.
 */
#define SYSMEMMGR_E_CREATEALLOCATOR	SYSMEMMGR_MAKE_ERROR(1)

/*!
 *  @def    SYSMEMMGR_E_CREATELOCK
 *  @brief  Mutex lock creation failed.
 */
#define SYSMEMMGR_E_CREATELOCK		SYSMEMMGR_MAKE_ERROR(2)

/*!
 *  @def    SYSMEMMGR_E_INVALIDSTATE
 *  @brief  Module is not initialized.
 */
#define SYSMEMMGR_E_INVALIDSTATE	SYSMEMMGR_MAKE_ERROR(3)

/*!
 *  @def    SYSMEMMGR_E_INVALIDARG
 *  @brief  Argument passed to a function is invalid.
 */
#define SYSMEMMGR_E_INVALIDARG		SYSMEMMGR_MAKE_ERROR(4)

/*!
 *  @def    SYSMEMMGR_E_BPAFREE
 *  @brief  Freeing to buddy allocator failed.
 */
#define SYSMEMMGR_E_BPAFREE		SYSMEMMGR_MAKE_ERROR(5)

/*!
 *  @def    SYSMEMMGR_E_MEMORY
 *  @brief  Memory allocation failed.
 */
#define SYSMEMMGR_E_MEMORY		SYSMEMMGR_MAKE_ERROR(6)

/*!
 *  @def    SYSMEMMGR_SUCCESS
 *  @brief  Operation successful.
 */
#define SYSMEMMGR_SUCCESS		SYSMEMMGR_MAKE_SUCCESS(0)

/*!
 *  @def    SYSMEMMGR_S_ALREADYSETUP
 *  @brief  Module already initialized.
 */
#define SYSMEMMGR_S_ALREADYSETUP	SYSMEMMGR_MAKE_SUCCESS(1)

/*!
 *  @def    SYSMEMMGR_S_DRVALREADYOPENED
 *  @brief  Internal OS Driver is already opened.
 */
#define SYSMEMMGR_S_DRVALREADYOPENED	SYSMEMMGR_MAKE_SUCCESS(2)

/*!
 *  @brief  Configuration data structure of system memory manager.
 */
struct sysmemmgr_config {
	u32 sizeof_valloc;
	/* Total size for virtual memory allocation */
	u32 sizeof_palloc;
	/* Total size for physical memory allocation */
	u32 static_phys_base_addr;
	/* Physical address of static memory region */
	u32 static_virt_base_addr;
	/* Virtual  address of static memory region */
	u32 static_mem_size;
	/* size of static memory region */
	u32 page_size;
	/* Page size */
	u32 event_no;
	/* Event number to be used */
};

/*!
 *  @brief  Flag used for allocating memory blocks.
 */
enum sysmemmgr_allocflag {
	sysmemmgr_allocflag_uncached = 0u,
	/* Flag used for allocating uncacheable block */
	sysmemmgr_allocflag_cached = 1u,
	/* Flag used for allocating cacheable block */
	sysmemmgr_allocflag_physical = 2u,
	/* Flag used for allocating physically contiguous block */
	sysmemmgr_allocflag_virtual = 3u,
	/* Flag used for allocating virtually contiguous block */
	sysmemmgr_allocflag_dma = 4u
	/* Flag used for allocating DMAable (physically contiguous) block */
};

/*!
 *  @brief  Flag used for translating address.
 */
enum sysmemmgr_xltflag {
	sysmemmgr_xltflag_kvirt2phys = 0x0001u,
	/* Flag used for converting Kernel virtual address to physical
	 *  address */
	sysmemmgr_xltflag_kvirt2uvirt = 0x0002u,
	/* Flag used for converting Kernel virtual address to user virtual
	 *  address */
	sysmemmgr_xltflag_uvirt2phys = 0x0003u,
	/* Flag used for converting user virtual address to physical address */
	sysmemmgr_xltflag_uvirt2kvirt = 0x0004u,
	/* Flag used for converting user virtual address to Kernel virtual
	 *  address */
	sysmemmgr_xltflag_phys2kvirt = 0x0005u,
	/* Flag used for converting physical address to user virtual address */
	sysmemmgr_xltflag_phys2uvirt = 0x0006u
	/* Flag used for converting physical address to Kernel virtual
	 *  address */
};


/* Function prototypes */
void sysmemmgr_get_config(struct sysmemmgr_config *config);

int sysmemmgr_setup(struct sysmemmgr_config *params);

int sysmemmgr_destroy(void);

int sysmemmgr_attach(u16 slave_id);

void *sysmemmgr_alloc(u32 size, enum sysmemmgr_allocflag flag);

int sysmemmgr_free(void *blk, u32 size, enum sysmemmgr_allocflag flag);

void *sysmemmgr_translate(void *srcAddr, enum sysmemmgr_xltflag flag);


#endif /* _SYSTEMMEMORYMANAGER_H_ */