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
|
/* Copyright (c) 2008-2010, Advanced Micro Devices. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
*/
#include "gsl.h"
//////////////////////////////////////////////////////////////////////////////
// macros
//////////////////////////////////////////////////////////////////////////////
#define GSL_INTRID_VALIDATE(id) (((id) < 0) || ((id) >= GSL_INTR_COUNT))
//////////////////////////////////////////////////////////////////////////////
// functions
//////////////////////////////////////////////////////////////////////////////
static const gsl_intrblock_reg_t *
kgsl_intr_id2block(gsl_intrid_t id)
{
const gsl_intrblock_reg_t *block;
int i;
// interrupt id to hw block
for (i = 0; i < GSL_INTR_BLOCK_COUNT; i++)
{
block = &gsl_cfg_intrblock_reg[i];
if (block->first_id <= id && id <= block->last_id)
{
return (block);
}
}
return (NULL);
}
//----------------------------------------------------------------------------
void
kgsl_intr_decode(gsl_device_t *device, gsl_intrblock_t block_id)
{
const gsl_intrblock_reg_t *block = &gsl_cfg_intrblock_reg[block_id];
gsl_intrid_t id;
unsigned int status;
// read the block's interrupt status bits
device->ftbl.device_regread(device, block->status_reg, &status);
// mask off any interrupts which are disabled
status &= device->intr.enabled[block->id];
// acknowledge the block's interrupts
device->ftbl.device_regwrite(device, block->clear_reg, status);
// loop through the block's masks, determine which interrupt bits are active, and call callback (or TODO queue DPC)
for (id = block->first_id; id <= block->last_id; id++)
{
if (status & gsl_cfg_intr_mask[id])
{
device->intr.handler[id].callback(id, device->intr.handler[id].cookie);
}
}
}
//----------------------------------------------------------------------------
KGSL_API void
kgsl_intr_isr()
{
gsl_deviceid_t device_id;
gsl_device_t *device;
// loop through the devices, and call device specific isr
for (device_id = (gsl_deviceid_t)(GSL_DEVICE_ANY + 1); device_id <= GSL_DEVICE_MAX; device_id++)
{
device = &gsl_driver.device[device_id-1]; // device_id is 1 based
if (device->intr.flags & GSL_FLAGS_INITIALIZED)
{
kgsl_device_active(device);
device->ftbl.intr_isr(device);
}
}
}
//----------------------------------------------------------------------------
int kgsl_intr_init(gsl_device_t *device)
{
if (device->ftbl.intr_isr == NULL)
{
return (GSL_FAILURE_BADPARAM);
}
if (device->intr.flags & GSL_FLAGS_INITIALIZED)
{
return (GSL_SUCCESS);
}
device->intr.device = device;
device->intr.flags |= GSL_FLAGS_INITIALIZED;
// os_interrupt_setcallback(YAMATO_INTR, kgsl_intr_isr);
// os_interrupt_enable(YAMATO_INTR);
return (GSL_SUCCESS);
}
//----------------------------------------------------------------------------
int kgsl_intr_close(gsl_device_t *device)
{
const gsl_intrblock_reg_t *block;
int i, id;
if (device->intr.flags & GSL_FLAGS_INITIALIZED)
{
// check if there are any enabled interrupts lingering around
for (i = 0; i < GSL_INTR_BLOCK_COUNT; i++)
{
if (device->intr.enabled[i])
{
block = &gsl_cfg_intrblock_reg[i];
// loop through the block's masks, disable interrupts which active
for (id = block->first_id; id <= block->last_id; id++)
{
if (device->intr.enabled[i] & gsl_cfg_intr_mask[id])
{
kgsl_intr_disable(&device->intr, (gsl_intrid_t)id);
}
}
}
}
kos_memset(&device->intr, 0, sizeof(gsl_intr_t));
}
return (GSL_SUCCESS);
}
//----------------------------------------------------------------------------
int kgsl_intr_enable(gsl_intr_t *intr, gsl_intrid_t id)
{
const gsl_intrblock_reg_t *block;
unsigned int mask;
unsigned int enabled;
if (GSL_INTRID_VALIDATE(id))
{
return (GSL_FAILURE_BADPARAM);
}
if (intr->handler[id].callback == NULL)
{
return (GSL_FAILURE_NOTINITIALIZED);
}
block = kgsl_intr_id2block(id);
if (block == NULL)
{
return (GSL_FAILURE_SYSTEMERROR);
}
mask = gsl_cfg_intr_mask[id];
enabled = intr->enabled[block->id];
if (mask && !(enabled & mask))
{
intr->evnt[id] = kos_event_create(0);
enabled |= mask;
intr->enabled[block->id] = enabled;
intr->device->ftbl.device_regwrite(intr->device, block->mask_reg, enabled);
}
return (GSL_SUCCESS);
}
//----------------------------------------------------------------------------
int kgsl_intr_disable(gsl_intr_t *intr, gsl_intrid_t id)
{
const gsl_intrblock_reg_t *block;
unsigned int mask;
unsigned int enabled;
if (GSL_INTRID_VALIDATE(id))
{
return (GSL_FAILURE_BADPARAM);
}
if (intr->handler[id].callback == NULL)
{
return (GSL_FAILURE_NOTINITIALIZED);
}
block = kgsl_intr_id2block(id);
if (block == NULL)
{
return (GSL_FAILURE_SYSTEMERROR);
}
mask = gsl_cfg_intr_mask[id];
enabled = intr->enabled[block->id];
if (enabled & mask)
{
enabled &= ~mask;
intr->enabled[block->id] = enabled;
intr->device->ftbl.device_regwrite(intr->device, block->mask_reg, enabled);
kos_event_signal(intr->evnt[id]); // wake up waiting threads before destroying the event
kos_event_destroy(intr->evnt[id]);
intr->evnt[id] = 0;
}
return (GSL_SUCCESS);
}
//----------------------------------------------------------------------------
int
kgsl_intr_attach(gsl_intr_t *intr, gsl_intrid_t id, gsl_intr_callback_t callback, void *cookie)
{
if (GSL_INTRID_VALIDATE(id) || callback == NULL)
{
return (GSL_FAILURE_BADPARAM);
}
if (intr->handler[id].callback != NULL)
{
if (intr->handler[id].callback == callback && intr->handler[id].cookie == cookie)
{
return (GSL_FAILURE_ALREADYINITIALIZED);
}
else
{
return (GSL_FAILURE_NOMOREAVAILABLE);
}
}
intr->handler[id].callback = callback;
intr->handler[id].cookie = cookie;
return (GSL_SUCCESS);
}
//----------------------------------------------------------------------------
int
kgsl_intr_detach(gsl_intr_t *intr, gsl_intrid_t id)
{
if (GSL_INTRID_VALIDATE(id))
{
return (GSL_FAILURE_BADPARAM);
}
if (intr->handler[id].callback == NULL)
{
return (GSL_FAILURE_NOTINITIALIZED);
}
kgsl_intr_disable(intr, id);
intr->handler[id].callback = NULL;
intr->handler[id].cookie = NULL;
return (GSL_SUCCESS);
}
//----------------------------------------------------------------------------
int
kgsl_intr_isenabled(gsl_intr_t *intr, gsl_intrid_t id)
{
int status = GSL_FAILURE;
const gsl_intrblock_reg_t *block = kgsl_intr_id2block(id);
if (block != NULL)
{
// check if interrupt is enabled
if (intr->enabled[block->id] & gsl_cfg_intr_mask[id])
{
status = GSL_SUCCESS;
}
}
return (status);
}
|