summaryrefslogtreecommitdiff
path: root/drivers/dsp/syslink/multicore_ipc/transportshm_setup.c
blob: a348c03f6b04aad622383551bddf90fb9f0ab0e9 (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
/*
 *  transportshm_setup.c
 *
 *  Shared Memory Transport setup 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.
 */

/* Standard headers */
#include <linux/types.h>

/* Utilities headers */
#include <linux/string.h>
#include <linux/slab.h>

/* Syslink headers */
#include <syslink/atomic_linux.h>
/* Module level headers */
#include <multiproc.h>
#include <sharedregion.h>
#include <nameserver.h>
#include <gatepeterson.h>
#include <notify.h>
#include <messageq.h>
#include <listmp.h>
#include <gatemp.h>
#include <transportshm.h>
#include <transportshm_setup.h>

/* =============================================================================
 * Structures & Enums
 * =============================================================================
 */
/* structure for transportshm_setup module state */
struct transportshm_setup_module_object {
	void *handles[MULTIPROC_MAXPROCESSORS];
	/* Store a handle per remote proc */
};


/* =============================================================================
 *  Globals
 * =============================================================================
 */
static struct transportshm_setup_module_object transportshm_setup_state = {
	.handles[0] = NULL
};

/* Pointer to the transportshm_setup module state */
static struct transportshm_setup_module_object *transportshm_setup_module =
						&transportshm_setup_state;


/* =============================================================================
 *  Functions
 * =============================================================================
 */
/*
 * =========== transportshm_setup_attach ===========
 * Function that will be called in messageq_attach.  Creates a
 * transportshm object for a given processor
 */
int transportshm_setup_attach(u16 remote_proc_id, u32 *shared_addr)
{
	s32 status = 0;
	struct transportshm_params params;
	void *handle;

	BUG_ON(remote_proc_id >= MULTIPROC_MAXPROCESSORS);

	if (WARN_ON(unlikely(shared_addr == NULL))) {
		status = -EINVAL;
		goto exit;
	}

	/* Init the transport parameters */
	transportshm_params_init(&params);
	params.gate = gatemp_get_default_remote();
	params.shared_addr = shared_addr;

	/* Make sure notify driver has been created */
	if (unlikely(notify_is_registered(remote_proc_id, 0) == false)) {
		status = TRANSPORTSHM_E_FAIL;
		goto exit;
	}

	if (multiproc_self() < remote_proc_id) {
		handle = transportshm_create(remote_proc_id, &params);
		if (unlikely(handle == NULL)) {
			status = TRANSPORTSHM_E_FAIL;
			goto exit;
		}

		transportshm_setup_module->handles[remote_proc_id] = handle;
	} else {
		status = transportshm_open_by_addr(params.shared_addr, &handle);
		if (status < 0)
			goto exit;

		transportshm_setup_module->handles[remote_proc_id] = handle;
	}

exit:
	if (status < 0)
		pr_err("transportshm_setup_attach failed! status "
			"= 0x%x", status);
	return status;
}

/*
 * =========== transportshm_setup_detach ===========
 * Function that will be called in messageq_detach.  Deletes a
 * transportshm object created by transportshm_setup_attach.
 */
int transportshm_setup_detach(u16 remote_proc_id)
{
	int status = 0;
	void *handle = NULL;

	if (WARN_ON(remote_proc_id >= MULTIPROC_MAXPROCESSORS)) {
		status = -EINVAL;
		goto exit;
	}

	handle = transportshm_setup_module->handles[remote_proc_id];
	if (WARN_ON(unlikely(handle == NULL))) {
		status = -EINVAL;
		goto exit;
	}

	if (multiproc_self() < remote_proc_id) {
		/* Delete the transport */
		status = transportshm_delete(&handle);
		if (unlikely(status < 0)) {
			status = TRANSPORTSHM_E_FAIL;
			goto exit;
		}
		transportshm_setup_module->handles[remote_proc_id] = NULL;
	} else {
		status = transportshm_close(&handle);
		if (unlikely(status < 0)) {
			status = TRANSPORTSHM_E_FAIL;
			goto exit;
		}
		transportshm_setup_module->handles[remote_proc_id] = NULL;
	}

exit:
	if (status < 0)
		pr_err("transportshm_setup_detach failed! status "
			"= 0x%x", status);
	return status;
}


/*
 * =========== transportshm_setup_shared_mem_req ===========
 * Function that returns the amount of shared memory required
 */
u32 transportshm_setup_shared_mem_req(u32 *shared_addr)
{
	u32 mem_req = 0x0;
	int status = 0;
	struct transportshm_params params;

	/* Don't do anything if only 1 processor in system */
	if (likely(multiproc_get_num_processors() != 1)) {
		BUG_ON(shared_addr == NULL);

		if (unlikely(shared_addr == NULL)) {
			status = -EINVAL;
			goto exit;
		}

		transportshm_params_init(&params);
		params.shared_addr = shared_addr;

		mem_req += transportshm_shared_mem_req(&params);
	}

exit:
	if (status < 0)
		pr_err("transportshm_setup_shared_mem_req failed! "
			"status = 0x%x", status);
	return mem_req;
}

/* Determines if a transport has been registered to a remote processor */
bool transportshm_setup_is_registered(u16 remote_proc_id)
{
	bool registered;

	registered = (transportshm_setup_module->handles[remote_proc_id] !=
				NULL);

	return registered;
}