summaryrefslogtreecommitdiff
path: root/drivers/dsp/syslink/procmgr/processor.c
blob: 4548d12ad967cb7f432b5272037733436a38ed64 (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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/*
 * 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 start the processor.
 *
 * This function calls into the specific Processor implementation
 * to start the slave processor running.
 * This function starts the slave processor running, in most
 * devices, by programming its entry point into the boot location
 * of the slave processor and releasing it from reset.
 * The handle specifies the specific Processor instance to be used.
 *
 *  @param  handle void * to the Processor object
 *  @param  entryPt	Entry point of the file loaded on the slave Processor
 *
 *  @sa	 Processor_stop
 */
inline int processor_start(void *handle, u32 entry_pt,
				struct processor_start_params *params)
{
	int retval = 0;
	struct processor_object *proc_handle =
					(struct processor_object *)handle;

	BUG_ON(handle == NULL);
	/* entryPt may be 0 for some devices. Cannot check for valid/invalid. */
	BUG_ON(params == NULL);
	BUG_ON(proc_handle->proc_fxn_table.start == NULL);
	retval = proc_handle->proc_fxn_table.start(handle, entry_pt, params);

	if ((proc_handle->boot_mode == PROC_MGR_BOOTMODE_BOOT)
		|| (proc_handle->boot_mode == PROC_MGR_BOOTMODE_NOLOAD))
		proc_handle->state = PROC_MGR_STATE_RUNNNING;

	return retval;
}


/*
 * Function to stop the processor.
 *
 * This function calls into the specific Processor implementation
 * to stop the slave processor.
 * This function stops the slave processor running, in most
 * devices, by placing it in reset.
 * The handle specifies the specific Processor instance to be used.
 */
inline int processor_stop(void *handle,
				struct processor_stop_params *params)
{
	int retval = 0;
	struct processor_object *proc_handle =
					(struct processor_object *)handle;

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

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

	if ((proc_handle->boot_mode == PROC_MGR_BOOTMODE_BOOT)
	||  (proc_handle->boot_mode == PROC_MGR_BOOTMODE_NOLOAD))
		proc_handle->state = PROC_MGR_STATE_RESET;

	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 to map address to slave address space.
 *
 * This function maps the provided slave address to a host address
 * and returns the mapped address and size.
 */
inline int processor_map(void *handle, u32 proc_addr, u32 size,
			u32 *mapped_addr, u32 *mapped_size, u32 map_attribs)
{
	int retval = 0;
	struct processor_object *proc_handle =
				(struct processor_object *)handle;

	BUG_ON(handle == NULL);
	BUG_ON(proc_addr == 0);
	BUG_ON(size == 0);
	BUG_ON(mapped_addr == NULL);
	BUG_ON(mapped_size == NULL);
	BUG_ON(proc_handle->proc_fxn_table.map == NULL);

	retval = proc_handle->proc_fxn_table.map(handle, proc_addr,
			size, mapped_addr, mapped_size, map_attribs);
	return retval;
}

/*
 * Function to unmap address to slave address space.
 *
 * This function unmap the provided slave address
 */
inline int processor_unmap(void *handle, u32 mapped_addr)
{
	int retval = 0;
	struct processor_object *proc_handle =
				(struct processor_object *)handle;

	retval = proc_handle->proc_fxn_table.unmap(handle, mapped_addr);
	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;
}