summaryrefslogtreecommitdiff
path: root/drivers/dsp/syslink/omap_notify/notify_driver.c
blob: c6c399605dd425cd4f612411921f03e2ceb58850 (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
/*
 * notify_driver.c
 *
 * Syslink driver support for OMAP Processors.
 *
 * Copyright (C) 2008-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.
 */

#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/uaccess.h>
#include <linux/spinlock.h>
#include <linux/io.h>
#include <asm/pgtable.h>

#include <syslink/gt.h>
#include <syslink/notify.h>
#include <syslink/notify_driver.h>
#include <syslink/notifydefs.h>
#include <syslink/atomic_linux.h>


/* Function to register driver with the Notify module. */
int notify_register_driver(u16 remote_proc_id,
			u16 line_id,
			struct notify_driver_fxn_table *fxn_table,
			struct notify_driver_object **driver_handle)
{
	int status = NOTIFY_S_SUCCESS;
	struct notify_driver_object *drv_handle = NULL;

	if (WARN_ON(atomic_cmpmask_and_lt(&(notify_state.ref_count),
			NOTIFY_MAKE_MAGICSTAMP(0),
			NOTIFY_MAKE_MAGICSTAMP(1)) == true)) {
		status = NOTIFY_E_INVALIDSTATE;
		goto exit;
	}
	if (WARN_ON(fxn_table == NULL)) {
		status = NOTIFY_E_INVALIDARG;
		goto exit;
	}
	if (WARN_ON(remote_proc_id >= multiproc_get_num_processors())) {
		status = NOTIFY_E_INVALIDARG;
		goto exit;
	}
	if (WARN_ON(line_id >= NOTIFY_MAX_INTLINES)) {
		status = NOTIFY_E_INVALIDARG;
		goto exit;
	}
	if (WARN_ON(driver_handle == NULL)) {
		status = NOTIFY_E_INVALIDARG;
		goto exit;
	}

	*driver_handle = NULL;
	if (mutex_lock_interruptible(notify_state.gate_handle) != 0)
		WARN_ON(1);
	drv_handle = &(notify_state.drivers[remote_proc_id][line_id]);
	if (drv_handle->is_init == NOTIFY_DRIVERINITSTATUS_DONE) {
		status = NOTIFY_E_ALREADYEXISTS;
		mutex_unlock(notify_state.gate_handle);
		goto exit;
	}
	mutex_unlock(notify_state.gate_handle);
	WARN_ON(status < 0);

	/*Complete registration of the driver. */
	memcpy(&(drv_handle->fxn_table), fxn_table,
				sizeof(struct notify_driver_fxn_table));
	drv_handle->notify_handle = NULL; /* Initialize to NULL. */
	drv_handle->is_init = NOTIFY_DRIVERINITSTATUS_DONE;
	*driver_handle = drv_handle;

exit:
	return status;
}
EXPORT_SYMBOL(notify_register_driver);

/* Function to unregister driver with the Notify module. */
int notify_unregister_driver(struct notify_driver_object *drv_handle)
{
	int status = NOTIFY_E_FAIL;
	s32 key;

	if (WARN_ON(atomic_cmpmask_and_lt(&(notify_state.ref_count),
			NOTIFY_MAKE_MAGICSTAMP(0),
			NOTIFY_MAKE_MAGICSTAMP(1)) == true)) {
		status = NOTIFY_E_INVALIDSTATE;
		goto exit;
	}
	if (WARN_ON(drv_handle == NULL)) {
		status = NOTIFY_E_INVALIDARG;
		goto exit;
	}

	key = mutex_lock_interruptible(notify_state.gate_handle);
	if (key)
		goto exit;

	/* Unregister the driver. */
	drv_handle->is_init = NOTIFY_DRIVERINITSTATUS_NOTDONE;
	mutex_unlock(notify_state.gate_handle);
	status = NOTIFY_S_SUCCESS;

exit:
	return status;
}
EXPORT_SYMBOL(notify_unregister_driver);

/* Function to set the Notify object handle maintained within the
 * Notify module. */
int notify_set_driver_handle(u16 remote_proc_id, u16 line_id,
				struct notify_object *handle)
{
	s32 status = NOTIFY_S_SUCCESS;

	/* Handle can be set to NULL */
	if (WARN_ON(atomic_cmpmask_and_lt(&(notify_state.ref_count),
			NOTIFY_MAKE_MAGICSTAMP(0),
			NOTIFY_MAKE_MAGICSTAMP(1)) == true)) {
		status = NOTIFY_E_INVALIDSTATE;
		goto exit;
	}
	if (WARN_ON(remote_proc_id >= multiproc_get_num_processors())) {
		status = NOTIFY_E_INVALIDARG;
		goto exit;
	}
	if (WARN_ON(line_id >= NOTIFY_MAX_INTLINES)) {
		status = NOTIFY_E_INVALIDARG;
		goto exit;
	}

	notify_state.drivers[remote_proc_id][line_id].notify_handle = handle;

exit:
	return status;
}
EXPORT_SYMBOL(notify_set_driver_handle);


/* Function to find and return the driver handle maintained within
 * the Notify module. */
struct notify_driver_object *notify_get_driver_handle(u16 remote_proc_id,
					u16 line_id)
{
	struct notify_driver_object *handle = NULL;
	s32 status = NOTIFY_S_SUCCESS;

	if (WARN_ON(atomic_cmpmask_and_lt(&(notify_state.ref_count),
			NOTIFY_MAKE_MAGICSTAMP(0),
			NOTIFY_MAKE_MAGICSTAMP(1)) == true)) {
		status = NOTIFY_E_INVALIDSTATE;
		goto exit;
	}
	if (WARN_ON(remote_proc_id >= multiproc_get_num_processors())) {
		status = NOTIFY_E_INVALIDARG;
		goto exit;
	}
	if (WARN_ON(line_id >= NOTIFY_MAX_INTLINES)) {
		status = NOTIFY_E_INVALIDARG;
		goto exit;
	}

	handle = &(notify_state.drivers[remote_proc_id][line_id]);
	/* Check whether the driver handle slot is occupied. */
	if (handle->is_init == NOTIFY_DRIVERINITSTATUS_NOTDONE)
		handle = NULL;

exit:
	if (status < 0) {
		pr_err("notify_get_driver_handle failed! "
			"status = 0x%x\n", status);
	}
	return handle;
}
EXPORT_SYMBOL(notify_get_driver_handle);