summaryrefslogtreecommitdiff
path: root/drivers/dsp/syslink/procmgr/processor.c
blob: 34a2d252b3f7145a1d3cc42d4265790ee31bd767 (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
 * processor.c
 *
 * Syslink driver support functions for TI OMAP processors.
 *
 * Copyright (C) 2009-2010 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.
 */

#include <linux/types.h>
#include <linux/module.h>

/* Module level headers */
#include "procdefs.h"
#include "processor.h"



/* =========================================
 * Functions called by ProcMgr
 * =========================================
 */
/*
 * Function to attach to the Processor.
 *
 * This function calls into the specific Processor implementation
 * to attach to it.
 * This function is called from the ProcMgr attach function, and
 * hence is used to perform any activities that may be required
 * once the slave is powered up.
 * Depending on the type of Processor, this function may or may not
 * perform any activities.
 */
inline int processor_attach(void *handle,
				struct processor_attach_params *params)
{
	int retval = 0;
	struct processor_object *proc_handle =
				(struct processor_object *)handle;

	BUG_ON(handle == NULL);
	BUG_ON(params == NULL);
	BUG_ON(proc_handle->proc_fxn_table.attach == NULL);

	proc_handle->boot_mode = params->params->boot_mode;
	retval = proc_handle->proc_fxn_table.attach(handle, params);

	if (proc_handle->boot_mode == PROC_MGR_BOOTMODE_BOOT)
		proc_handle->state = PROC_MGR_STATE_POWERED;
	else if (proc_handle->boot_mode == PROC_MGR_BOOTMODE_NOLOAD)
		proc_handle->state = PROC_MGR_STATE_LOADED;
	else if (proc_handle->boot_mode == PROC_MGR_BOOTMODE_NOBOOT)
		proc_handle->state = PROC_MGR_STATE_RUNNNING;
	return retval;
}


/*
 * Function to detach from the Processor.
 *
 * This function calls into the specific Processor implementation
 * to detach from it.
 * This function is called from the ProcMgr detach function, and
 * hence is useful to perform any activities that may be required
 * before the slave is powered down.
 * Depending on the type of Processor, this function may or may not
 * perform any activities.
 */
inline int processor_detach(void *handle)
{
	int retval = 0;
	struct processor_object *proc_handle =
					(struct processor_object *)handle;

	BUG_ON(handle == NULL);
	BUG_ON(proc_handle->proc_fxn_table.detach == NULL);

	retval = proc_handle->proc_fxn_table.detach(handle);
	/* For all boot modes, at the end of detach, the Processor is in
	* unknown state.
	*/
	proc_handle->state = PROC_MGR_STATE_UNKNOWN;
	return retval;
}


/*
 * Function to read from the slave processor's memory.
 *
 * This function calls into the specific Processor implementation
 * to read from the slave processor's memory. It reads from the
 * specified address in the processor's address space and copies
 * the required number of bytes into the specified buffer.
 * It returns the number of bytes actually read in the num_bytes
 * parameter.
 * Depending on the processor implementation, it may result in
 * reading from shared memory or across a peripheral physical
 * connectivity.
 * The handle specifies the specific Processor instance to be used.
 */
inline int processor_read(void *handle, u32 proc_addr,
			u32 *num_bytes, void *buffer)
{
	int retval = 0;
	struct processor_object *proc_handle =
				(struct processor_object *)handle;

	BUG_ON(handle == NULL);
	BUG_ON(proc_addr == 0);
	BUG_ON(num_bytes == 0);
	BUG_ON(buffer == NULL);
	BUG_ON(proc_handle->proc_fxn_table.read == NULL);

	retval = proc_handle->proc_fxn_table.read(handle, proc_addr,
						num_bytes, buffer);
	return retval;
}


/*
 * Function to write into the slave processor's memory.
 *
 * This function calls into the specific Processor implementation
 * to write into the slave processor's memory. It writes into the
 * specified address in the processor's address space and copies
 * the required number of bytes from the specified buffer.
 * It returns the number of bytes actually written in the num_bytes
 * parameter.
 * Depending on the processor implementation, it may result in
 * writing into shared memory or across a peripheral physical
 * connectivity.
 * The handle specifies the specific Processor instance to be used.
 */
inline int processor_write(void *handle, u32 proc_addr, u32 *num_bytes,
							void *buffer)
{
	int retval = 0;
	struct processor_object *proc_handle =
				(struct processor_object *)handle;
	BUG_ON(handle == NULL);
	BUG_ON(proc_addr == 0);
	BUG_ON(num_bytes == 0);
	BUG_ON(buffer == NULL);
	BUG_ON(proc_handle->proc_fxn_table.write == NULL);

	retval = proc_handle->proc_fxn_table.write(handle, proc_addr,
						num_bytes, buffer);
	return retval;
}


/*
 * Function to get the current state of the slave Processor.
 *
 * This function gets the state of the slave processor as
 * maintained on the master Processor state machine. It does not
 * go to the slave processor to get its actual state at the time
 * when this API is called.
 */
enum proc_mgr_state processor_get_state(void *handle)
{
	struct processor_object *proc_handle =
				(struct processor_object *)handle;

	BUG_ON(handle == NULL);

	return proc_handle->state;
}


/*
 * Function to set the current state of the slave Processor
 * to specified value.
 *
 * This function is used to set the state of the processor to the
 * value as specified. This function may be used by external
 * entities that affect the state of the slave processor, such as
 * PwrMgr, error handler, or ProcMgr.
 */
void processor_set_state(void *handle, enum proc_mgr_state state)
{
	struct processor_object *proc_handle =
				(struct processor_object *)handle;

	BUG_ON(handle == NULL);
	proc_handle->state = state;
}


/*
 * Function to perform device-dependent operations.
 *
 * This function calls into the specific Processor implementation
 * to perform device dependent control operations. The control
 * operations supported by the device are exposed directly by the
 * specific implementation of the Processor interface. These
 * commands and their specific argument types are used with this
 * function.
 */
inline int processor_control(void *handle, int cmd, void *arg)
{
	int retval = 0;
	struct processor_object *proc_handle =
				(struct processor_object *)handle;

	BUG_ON(handle == NULL);
	BUG_ON(proc_handle->proc_fxn_table.control == NULL);

	retval = proc_handle->proc_fxn_table.control(handle, cmd, arg);
	return retval;
}


/*
 * Function to translate between two types of address spaces.
 *
 * This function translates addresses between two types of address
 * spaces. The destination and source address types are indicated
 * through parameters specified in this function.
 */
inline int processor_translate_addr(void *handle, void **dst_addr,
		enum proc_mgr_addr_type dst_addr_type, void *src_addr,
		enum proc_mgr_addr_type src_addr_type)
{
	int retval = 0;
	struct processor_object *proc_handle =
					(struct processor_object *)handle;

	BUG_ON(handle == NULL);
	BUG_ON(dst_addr == NULL);
	BUG_ON(src_addr == NULL);
	BUG_ON(dst_addr_type >= PROC_MGR_ADDRTYPE_ENDVALUE);
	BUG_ON(src_addr_type >= PROC_MGR_ADDRTYPE_ENDVALUE);
	BUG_ON(proc_handle->proc_fxn_table.translateAddr == NULL);

	retval = proc_handle->proc_fxn_table.translateAddr(handle,
			dst_addr, dst_addr_type, src_addr, src_addr_type);
	return retval;
}


/*
 * Function that registers for notification when the slave
 * processor transitions to any of the states specified.
 *
 * This function allows the user application to register for
 * changes in processor state and take actions accordingly.

 */
inline int processor_register_notify(void *handle, proc_mgr_callback_fxn fxn,
				void *args, enum proc_mgr_state state[])
{
	int retval = 0;

	BUG_ON(handle == NULL);
	BUG_ON(fxn == NULL);

	/* TODO: TBD: To be implemented. */
	return retval;
}

/*
 * Function that returns the proc instance mem info
 */
int processor_get_proc_info(void *handle, struct proc_mgr_proc_info *procinfo)
{
	struct processor_object *proc_handle =
				(struct processor_object *)handle;
	int retval;
	retval = proc_handle->proc_fxn_table.procinfo(proc_handle, procinfo);
	return retval;
}

/*
 * Function that returns the address translations
 */
int processor_virt_to_phys(void *handle, u32 da, u32 *mapped_entries,
						u32 num_of_entries)
{
	struct processor_object *proc_handle =
				(struct processor_object *)handle;
	int retval;
	retval = proc_handle->proc_fxn_table.virt_to_phys(handle, da,
				mapped_entries, num_of_entries);
	return retval;
}