OpenCores
URL https://opencores.org/ocsvn/pcie_ds_dma/pcie_ds_dma/trunk

Subversion Repositories pcie_ds_dma

[/] [pcie_ds_dma/] [trunk/] [soft/] [linux/] [driver/] [pexdrv/] [ioctlrw.c] - Blame information for rev 28

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dsmv
 
2
#include <linux/kernel.h>
3
#define __NO_VERSION__
4
#include <linux/module.h>
5
#include <linux/types.h>
6
#include <linux/ioport.h>
7
#include <linux/pci.h>
8
#include <linux/pagemap.h>
9
#include <linux/interrupt.h>
10
#include <linux/proc_fs.h>
11
//#include <linux/atomic.h>
12
#include <asm/io.h>
13
 
14
#include "pexmodule.h"
15
#include "pexioctl.h"
16
#include "hardware.h"
17
#include "ambpexregs.h"
18 6 v.karak
#include "brd_info.h"
19 2 dsmv
 
20
//--------------------------------------------------------------------
21
 
22
int ioctl_board_info(struct pex_device *brd, unsigned long arg)
23
{
24
    struct board_info bi;
25
    int error = 0;
26
 
27
    down(&brd->m_BoardSem);
28
 
29
    dbg_msg(dbg_trace, "%s(): get board information\n", __FUNCTION__);
30
 
31
    memset(&bi, 0, sizeof(struct board_info));
32
 
33
    bi.PhysAddress[0] = brd->m_BAR0.physical_address;
34
    bi.VirtAddress[0] = brd->m_BAR0.virtual_address;
35
    bi.Size[0] = brd->m_BAR0.size;
36
 
37
    bi.PhysAddress[1] = brd->m_BAR1.physical_address;
38
    bi.VirtAddress[1] = brd->m_BAR1.virtual_address;
39
    bi.Size[1] = brd->m_BAR1.size;
40
 
41
    bi.InterruptLevel = 0;
42
    bi.InterruptVector = brd->m_Interrupt;
43
    bi.vendor_id = brd->m_pci->vendor;
44
    bi.device_id = brd->m_pci->device;
45
 
46
    if(copy_to_user((void*)arg, &bi, sizeof(struct board_info))) {
47
        err_msg(err_trace, "%s(): Error copy board info to user space\n", __FUNCTION__);
48
        error = -EINVAL;
49
    }
50
 
51
    up(&brd->m_BoardSem);
52
 
53
    return error;
54
}
55
 
56
//--------------------------------------------------------------------
57
 
58
int ioctl_memory_alloc(struct pex_device *brd, unsigned long arg)
59
{
60
    struct memory_block mb = {0};
61
    dma_addr_t dma_handle = {0};
62
    int error = 0;
63
    int i = 0;
64
 
65
    down(&brd->m_BoardSem);
66
 
67
    if(copy_from_user((void*)&mb, (void*)arg, sizeof(struct memory_block))) {
68
        err_msg(err_trace, "%s(): Error copy block descriptor from user space\n", __FUNCTION__);
69
        error = -EINVAL;
70
        goto do_exit;
71
    }
72
 
73
    if(mb.size == 0) {
74
        err_msg(err_trace, "%s(): Invalid block size.\n", __FUNCTION__);
75
        goto do_exit;
76
    }
77
 
78
    mb.virt = allocate_memory_block(brd, mb.size, &dma_handle);
79
        if(!mb.virt) {
80
            err_msg(err_trace, "%s(): Error allocate block %d.\n", __FUNCTION__, i);
81
            error = -ENOMEM;
82
            goto do_exit;
83
        }
84
        mb.phys = dma_handle;
85
 
86
    if(copy_to_user((void*)arg, &mb, sizeof(struct memory_block))) {
87
        err_msg(err_trace, "%s(): Error copy block descriptor to user space\n", __FUNCTION__);
88
        error = -EINVAL;
89
    }
90
 
91
do_exit:
92
    up(&brd->m_BoardSem);
93
 
94
    return error;
95
}
96
 
97
//--------------------------------------------------------------------
98
 
99
int ioctl_memory_free(struct pex_device *brd, unsigned long arg)
100
{
101
    struct memory_block mb = {0};
102
    int error = 0;
103
    int i = 0;
104
 
105
    down(&brd->m_BoardSem);
106
 
107
    if(copy_from_user((void*)&mb, (void*)arg, sizeof(struct memory_block))) {
108
        err_msg(err_trace, "%s(): Error copy block descriptor from user space\n", __FUNCTION__);
109
        error = -EINVAL;
110
        goto do_exit;
111
    }
112
 
113
    if(mb.size == 0 || mb.phys == 0 || mb.virt == 0) {
114
        err_msg(err_trace, "%s(): Invalid block parameters.\n", __FUNCTION__);
115
        goto do_exit;
116
    }
117
 
118
    error = free_memory_block(brd, mb);
119
    if(error < 0) {
120
        err_msg(err_trace, "%s(): Error free block %d.\n", __FUNCTION__, i);
121
        goto do_exit;
122
    }
123
 
124
do_exit:
125
    up(&brd->m_BoardSem);
126
 
127
    return error;
128
}
129
 
130
//--------------------------------------------------------------------
131
 
132
int ioctl_stub_alloc(struct pex_device *brd, unsigned long arg)
133
{
134
/*
135
    struct stub_descriptor stub = {0};
136
    struct dma_channel *dma = NULL;
137
    void *cpu_addr = NULL;
138
    dma_addr_t dma_handle = {0};
139
    int locked = 0;
140
    int error = -EINVAL;
141
 
142
    down(&brd->m_BoardSem);
143
 
144
    if(copy_from_user((void*)&stub, (void*)arg, sizeof(struct stub_descriptor))) {
145
        err_msg(err_trace, "%s(): Error copy stub descriptor from user space\n", __FUNCTION__);
146
        error = -EINVAL;
147
        goto do_exit;
148
    }
149
 
150
    if(stub.dma_channel >= MAX_NUMBER_OF_DMACHANNELS) {
151
        err_msg(err_trace, "%s(): Invalid DMA channel number.\n", __FUNCTION__);
152
        error = -EINVAL;
153
        goto do_exit;
154
    }
155
 
156
    dma = &brd->m_DMA[stub.dma_channel];
157
 
158
    spin_lock(&dma->m_MemListLock);
159
 
160
    cpu_addr = dma_alloc_coherent(&dma->m_pci->dev, PAGE_SIZE, &dma_handle, GFP_KERNEL);
161
    if(!cpu_addr) {
162
        err_msg(err_trace, "%s(): Error allocate physical memory for stub.\n", __FUNCTION__);
163
        error = -ENOMEM;
164
        goto do_unlock;
165
    }
166
 
167
    dma->m_MemStub.dma_handle = dma_handle;
168
    dma->m_MemStub.cpu_addr = cpu_addr;
169
    dma->m_MemStub.size = PAGE_SIZE;
170
 
171
    stub.stub.phys = dma_handle;
172
    stub.stub.size = PAGE_SIZE;
173
    stub.stub.virt = NULL;
174
 
175
    locked = lock_pages(dma->m_MemStub.cpu_addr, dma->m_MemStub.size);
176
 
177
    dbg_msg(dbg_trace, "%s(): PA = 0x%zx, VA = %p, SZ = 0x%zx, PAGES = %d\n",
178
            __FUNCTION__, (size_t)dma->m_MemStub.dma_handle, dma->m_MemStub.cpu_addr, dma->m_MemStub.size, locked );
179
 
180
    if(copy_to_user((void*)arg, &stub, sizeof(struct stub_descriptor))) {
181
        err_msg(err_trace, "%s(): Error copy stub descriptor to user space\n", __FUNCTION__);
182
        error = -EINVAL;
183
        goto do_free_mem;
184
    }
185
 
186
    spin_unlock(&dma->m_MemListLock);
187
 
188
    return 0;
189
 
190
do_free_mem:
191
    dma_free_coherent(&dma->m_pci->dev, PAGE_SIZE, cpu_addr, dma_handle);
192
 
193
do_unlock:
194
    spin_unlock(&dma->m_MemListLock);
195
 
196
do_exit:
197
    up(&brd->m_BoardSem);
198
 
199
    return error;
200
*/
201
    return -ENOSYS;
202
}
203
 
204
//--------------------------------------------------------------------
205
 
206
int ioctl_stub_free(struct pex_device *brd, unsigned long arg)
207
{
208
    down(&brd->m_BoardSem);
209
 
210
    dbg_msg(err_trace, "%s(): ioctl not implemented.\n", __FUNCTION__);
211
 
212
    up(&brd->m_BoardSem);
213
 
214
    return -ENOSYS;
215
}
216
 
217
//--------------------------------------------------------------------
218
 
219
int ioctl_set_mem(struct pex_device *brd, unsigned long arg)
220
{
221
    int error = 0;
222
    u32 i = 0;
223
    u32 AdmNumber = 0;
224
    u32 TetrNumber = 0;
225
    u32 Address = 0;
226
    u32 tmpSize = 0;
227
    struct CDmaChannel *dma = NULL;
228
    AMB_MEM_DMA_CHANNEL MemDscr = {0};
229
    PAMB_MEM_DMA_CHANNEL pKernMemDscr = NULL;
230
    PAMB_MEM_DMA_CHANNEL pUserMemDscr = &MemDscr;
231
 
232
    down(&brd->m_BoardSem);
233
 
234
    dbg_msg(dbg_trace, "%s(): Started\n", __FUNCTION__);
235
 
236
    if( copy_from_user((void *)pUserMemDscr, (void *)arg, sizeof(AMB_MEM_DMA_CHANNEL))) {
237
        err_msg(err_trace, "%s(): Error copy descriptor from user space\n", __FUNCTION__);
238
        error = -EFAULT;
239
        goto do_exit;
240
    }
241
 
242
    tmpSize = sizeof(AMB_MEM_DMA_CHANNEL)+(pUserMemDscr->BlockCnt-1)*sizeof(void*);
243
 
244
    pKernMemDscr = kzalloc(tmpSize, GFP_KERNEL);
245
    if(!pKernMemDscr) {
246
        err_msg(err_trace, "%s(): Error allocate descriptor in kernel space\n", __FUNCTION__);
247
        error = -ENOMEM;
248
        goto do_free_mem;
249
    }
250
 
251
    memcpy(pKernMemDscr, pUserMemDscr, tmpSize);
252
 
253
    if(pKernMemDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS) {
254
        err_msg(err_trace, "%s(): Invalid DMA channel number\n", __FUNCTION__);
255
        error = -EINVAL;
256
        goto do_free_mem;
257
    }
258
 
259
    if(!(brd->m_DmaChanMask & (1 << pKernMemDscr->DmaChanNum))) {
260
        err_msg(err_trace, "%s(): Invalid stream number\n", __FUNCTION__);
261
        error = -EINVAL;
262
        goto do_free_mem;
263
    }
264
 
265
    i = pKernMemDscr->DmaChanNum;
266
    dma = brd->m_DmaChannel[i];
267
 
268
    dbg_msg(dbg_trace, "%s(): 1\n", __FUNCTION__);
269
 
270
    error = SetDmaDirection(dma, pKernMemDscr->Direction);
271
    if(error != 0) {
272
        err_msg(err_trace, "%s(): Error in SetDmaDirection()\n", __FUNCTION__);
273
        error = -EINVAL;
274
        goto do_free_mem;
275
    }
276
 
277
    dbg_msg(dbg_trace, "%s(): 2\n", __FUNCTION__);
278
 
279
    Adjust(dma,0);
280
 
281
    dbg_msg(dbg_trace, "%s(): 3\n", __FUNCTION__);
282
 
283
    pKernMemDscr->BlockSize = (pKernMemDscr->BlockSize >> 12) << 12;
284
    if(!pKernMemDscr->BlockSize) {
285
        err_msg(err_trace, "%s(): BlockSize is zero\n", __FUNCTION__);
286
        error = -EINVAL;
287
        goto do_free_mem;
288
    }
289
 
290
    AdmNumber = pKernMemDscr->LocalAddr >> 16;
291
    TetrNumber = pKernMemDscr->LocalAddr & 0xff;
292
    Address = AdmNumber*ADM_SIZE + TetrNumber*TETRAD_SIZE + TRDadr_DATA*REG_SIZE;
293
 
294 19 dsmv
    //SetDmaLocalAddress(dma, Address);
295
    //SetAdmTetr(dma, AdmNumber, TetrNumber);
296
    //error = SetDmaMode(brd, i, AdmNumber, TetrNumber);
297 2 dsmv
 
298
    dbg_msg(dbg_trace, "%s(): 4\n", __FUNCTION__);
299
 
300
    error = RequestMemory( dma, pKernMemDscr->pBlock, pKernMemDscr->BlockSize,
301
                            (u32*)&pKernMemDscr->BlockCnt, &pKernMemDscr->pStub, pKernMemDscr->MemType );
302
    if(error < 0) {
303
        err_msg(err_trace, "%s(): Error in RequestMemory()\n", __FUNCTION__);
304
        error = -ENOMEM;
305
        goto do_free_mem;
306
    }
307
 
308
    dbg_msg(dbg_trace, "%s(): 5\n", __FUNCTION__);
309
 
310
    if(copy_to_user((void*)arg, (void*)pKernMemDscr, tmpSize)) {
311
        err_msg(err_trace, "%s(): Error copy descriptor to user space\n", __FUNCTION__);
312
        error = -EFAULT;
313
    }
314
 
315
do_free_mem:
316
    kfree(pKernMemDscr);
317
 
318
do_exit:
319
    up(&brd->m_BoardSem);
320
 
321
    return error;
322
}
323
 
324
//--------------------------------------------------------------------
325
 
326
int ioctl_free_mem(struct pex_device *brd, size_t arg)
327
{
328
    u32 i = 0;
329
    int error = 0;
330
    AMB_MEM_DMA_CHANNEL MemDscr = {0};
331
    PAMB_MEM_DMA_CHANNEL pMemDscr = &MemDscr;
332
 
333
    down(&brd->m_BoardSem);
334
 
335
    if( copy_from_user((void *)pMemDscr, (void *)arg, sizeof(AMB_MEM_DMA_CHANNEL))) {
336
        err_msg(err_trace, "%s(): Error copy descriptor from user space\n", __FUNCTION__);
337
        error = -EFAULT;
338
        goto do_exit;
339
    }
340
 
341
    if(pMemDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS) {
342
        err_msg(err_trace, "%s(): Invalid DMA channel number\n", __FUNCTION__);
343
        error = -EINVAL;
344
        goto do_exit;
345
    }
346
 
347
    i = pMemDscr->DmaChanNum;
348
    ReleaseMemory(brd->m_DmaChannel[i]);
349
 
350
    if(copy_to_user (( void *)arg, (void *)&MemDscr, sizeof(AMB_MEM_DMA_CHANNEL) + (pMemDscr->BlockCnt - 1) * sizeof(void*) )) {
351
        err_msg(err_trace, "%s(): Error copy descriptor to user space\n", __FUNCTION__);
352
        error = -EFAULT;
353
        goto do_exit;
354
    }
355
 
356
do_exit:
357
    up(&brd->m_BoardSem);
358
 
359
    return error;
360
}
361
 
362
//--------------------------------------------------------------------
363
 
364
int ioctl_start_mem(struct pex_device *brd, size_t arg)
365
{
366
    int Status = -EINVAL;
367
    AMB_START_DMA_CHANNEL StartDscr;
368
    PAMB_START_DMA_CHANNEL pStartDscr = &StartDscr;
369
 
370 19 dsmv
    printk("<0>ioctl_start_mem: Entered.\n");
371 2 dsmv
    down(&brd->m_BoardSem);
372
 
373
    if( copy_from_user((void *)&StartDscr, (void *)arg, sizeof(AMB_START_DMA_CHANNEL))) {
374
        err_msg(err_trace, "%s(): Error copy data from userspace\n", __FUNCTION__ );
375
        up(&brd->m_BoardSem);
376
        return -EFAULT;
377
    }
378
 
379
    if(pStartDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS) {
380
        printk("<0>%s(): too large stream number\n", __FUNCTION__);
381
        up(&brd->m_BoardSem);
382
        return -EINVAL;
383
    }
384
 
385
    if(!(brd->m_DmaChanMask & (1 << pStartDscr->DmaChanNum))) {
386
        printk("<0>%s(): invalid stream number\n", __FUNCTION__);
387
        up(&brd->m_BoardSem);
388
        return -EINVAL;
389
    }
390
 
391
    Status = StartDmaTransfer(brd->m_DmaChannel[pStartDscr->DmaChanNum], pStartDscr->IsCycling);
392
    Status = HwStartDmaTransfer(brd, pStartDscr->DmaChanNum);
393
 
394
    up(&brd->m_BoardSem);
395 19 dsmv
    printk("<0>ioctl_start_mem: exit Status=0x%.8X \n", Status );
396 2 dsmv
 
397
    return Status;
398
}
399
 
400
//--------------------------------------------------------------------
401
 
402
int ioctl_stop_mem(struct pex_device *brd, size_t arg)
403
{
404
    int Status = -EINVAL;
405
    u32 i;
406
    AMB_STATE_DMA_CHANNEL StopDscr;
407
    PAMB_STATE_DMA_CHANNEL pStopDscr = &StopDscr;
408
 
409
    down(&brd->m_BoardSem);
410
 
411
    // get the user buffer
412
    if( copy_from_user((void *)&StopDscr, (void *)arg, sizeof(AMB_STATE_DMA_CHANNEL))) {
413
        err_msg(err_trace, "%s(): Error copy data from userspace\n", __FUNCTION__ );
414
        up(&brd->m_BoardSem);
415
        return -EFAULT;
416
    }
417
 
418
    //printk("<0>IoctlStopMem: Entered.\n");
419
 
420
    if(pStopDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS)
421
    {
422
        printk("<0>IoctlStopMem: too large stream number\n");
423
        up(&brd->m_BoardSem);
424
        return -EINVAL;
425
    }
426
 
427
    i = pStopDscr->DmaChanNum;
428
    if(pStopDscr->Timeout)
429
        Status = WaitBlockEndEvent(brd->m_DmaChannel[i], pStopDscr->Timeout);
430
    else
431
        Status = 0;
432
    /*
433
        PIRP CurrentIrp = m_DmaChannel[i].GetQueueIrp();
434
        if(CurrentIrp)
435
                CancelIrp(CurrentIrp, WambpIrpCancelCallback);
436
*/
437
    HwCompleteDmaTransfer(brd, i);
438
    //FreezeState(brd->m_DmaChannel[i]);
439
    GetState( brd->m_DmaChannel[i], (u32*)&pStopDscr->BlockNum,
440
              (u32*)&pStopDscr->BlockCntTotal, (u32*)&pStopDscr->OffsetInBlock,
441
              (u32*)&pStopDscr->DmaChanState);
442
 
443
    if(copy_to_user (( void *)arg, (void *)&StopDscr, sizeof(AMB_STATE_DMA_CHANNEL))) {
444
        err_msg(err_trace, "%s(): Error copy data to userspace\n", __FUNCTION__ );
445
        up(&brd->m_BoardSem);
446
        return -EFAULT;
447
    }
448
 
449
    up(&brd->m_BoardSem);
450
 
451
    return Status;
452
}
453
 
454
//--------------------------------------------------------------------
455
 
456
int ioctl_state_mem(struct pex_device *brd, size_t arg)
457
{
458
    int Status = -EINVAL;
459
    u32 i=0;
460
    AMB_STATE_DMA_CHANNEL StateDscr;
461
    PAMB_STATE_DMA_CHANNEL pStateDscr = &StateDscr;
462
 
463
    down(&brd->m_BoardSem);
464
 
465
    // get the user buffer
466
    if( copy_from_user((void *)&StateDscr, (void *)arg, sizeof(AMB_STATE_DMA_CHANNEL))) {
467
        err_msg(err_trace, "%s(): Error copy data from userspace\n", __FUNCTION__ );
468
        up(&brd->m_BoardSem);
469
        return -EFAULT;
470
    }
471
 
472
    //printk("<0>IoctlStateMem: Entered.\n");
473
 
474
    if(pStateDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS)
475
    {
476
        printk("<0>IoctlStateMem: too large stream number\n");
477
        up(&brd->m_BoardSem);
478
        return -EINVAL;
479
    }
480
 
481
    i = pStateDscr->DmaChanNum;
482
    if(pStateDscr->Timeout)
483
        Status = WaitBlockEndEvent(brd->m_DmaChannel[i], pStateDscr->Timeout);
484
    else
485
        Status = 0;
486
 
487
    //FreezeState(brd->m_DmaChannel[i]);
488
    GetState(brd->m_DmaChannel[i],      (u32*)&pStateDscr->BlockNum,
489
             (u32*)&pStateDscr->BlockCntTotal,
490
             (u32*)&pStateDscr->OffsetInBlock,
491
             (u32*)&pStateDscr->DmaChanState);
492
 
493
    if(copy_to_user (( void *)arg, (void *)&StateDscr, sizeof(AMB_STATE_DMA_CHANNEL))) {
494
        err_msg(err_trace, "%s(): Error copy data to userspace\n", __FUNCTION__ );
495
        up(&brd->m_BoardSem);
496
        return -EFAULT;
497
    }
498
 
499
    up(&brd->m_BoardSem);
500
 
501
    return Status;
502
}
503
 
504
//--------------------------------------------------------------------
505
 
506
int ioctl_set_dir_mem(struct pex_device *brd, size_t arg)
507
{
508
    int Status = -EINVAL;
509
    u32 i;
510
    AMB_SET_DMA_CHANNEL MemDscr;
511
    PAMB_SET_DMA_CHANNEL pMemDscr = &MemDscr;
512
 
513 19 dsmv
    printk("<0>IoctlSetDirMem: Entered.\n");
514 2 dsmv
    down(&brd->m_BoardSem);
515
 
516
    // get the user buffer
517
    if( copy_from_user((void *)&MemDscr, (void *)arg, sizeof(AMB_SET_DMA_CHANNEL))) {
518
        err_msg(err_trace, "%s(): Error copy data from userspace\n", __FUNCTION__ );
519
        up(&brd->m_BoardSem);
520
        return -EFAULT;
521
    }
522
 
523
    if(pMemDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS)
524
    {
525
        printk("<0>IoctlSetDirMem: too large stream number\n");
526
        up(&brd->m_BoardSem);
527
        return -EINVAL;
528
    }
529
 
530
    i = pMemDscr->DmaChanNum;
531
    Status = SetDmaDirection(brd->m_DmaChannel[i], pMemDscr->Param);
532
 
533
    up(&brd->m_BoardSem);
534
 
535
    return Status;
536
}
537
 
538
//--------------------------------------------------------------------
539
 
540
int ioctl_set_src_mem(struct pex_device *brd, size_t arg)
541
{
542
    int Status = -EINVAL;
543
    u32 i;
544
    u32 AdmNumber = 0;
545
    u32 TetrNumber = 0;
546
    u32 Address = 0;
547
    AMB_SET_DMA_CHANNEL MemDscr;
548
    PAMB_SET_DMA_CHANNEL pMemDscr = &MemDscr;
549
 
550 19 dsmv
    printk("<0>IoctlSetSrcMem: Entered.\n");
551 2 dsmv
    down(&brd->m_BoardSem);
552
 
553
    // get the user buffer
554
    if( copy_from_user((void *)&MemDscr, (void *)arg, sizeof(AMB_SET_DMA_CHANNEL))) {
555
        err_msg(err_trace, "%s(): Error copy data from userspace\n", __FUNCTION__ );
556
        up(&brd->m_BoardSem);
557
        return -EFAULT;
558
    }
559
 
560
    if(pMemDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS)
561
    {
562
        printk("<0>IoctlSetSrcMem: too large stream number\n");
563
        up(&brd->m_BoardSem);
564
        return -EINVAL;
565
    }
566
 
567
    i = pMemDscr->DmaChanNum;
568 19 dsmv
    //AdmNumber = pMemDscr->Param >> 16;
569
    //TetrNumber = pMemDscr->Param & 0xff;
570
    //Address = AdmNumber * ADM_SIZE + TetrNumber * TETRAD_SIZE + TRDadr_DATA * REG_SIZE;
571
 
572
    AdmNumber=0;
573
    TetrNumber=0;
574
    Address = pMemDscr->Param;
575 2 dsmv
    SetDmaLocalAddress(brd->m_DmaChannel[i], Address);
576
    SetAdmTetr(brd->m_DmaChannel[i], AdmNumber, TetrNumber);
577 19 dsmv
    //Status = SetDmaMode(brd, i, AdmNumber, TetrNumber);
578
    Status=0;
579 2 dsmv
 
580
    up(&brd->m_BoardSem);
581
 
582
    return Status;
583
}
584
 
585
//--------------------------------------------------------------------
586
 
587
int ioctl_set_drq_mem(struct pex_device *brd, size_t arg)
588
{
589
    int Status = -EINVAL;
590
    u32 i;
591
    u32 AdmNum = 0;
592
    u32 TetrNum = 0;
593
    AMB_SET_DMA_CHANNEL MemDscr;
594
    PAMB_SET_DMA_CHANNEL pMemDscr = &MemDscr;
595
 
596
    down(&brd->m_BoardSem);
597
 
598
    //printk("<0>IoctlSetSrcMem: Entered.\n");
599
 
600
    // get the user buffer
601
    if( copy_from_user((void *)&MemDscr, (void *)arg, sizeof(AMB_SET_DMA_CHANNEL))) {
602
        err_msg(err_trace, "%s(): Error copy data from userspace\n", __FUNCTION__ );
603
        up(&brd->m_BoardSem);
604
        return -EFAULT;
605
    }
606
 
607
    if(pMemDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS)
608
    {
609
        printk("<0>IoctlSetDrqMem: too large stream number\n");
610
        up(&brd->m_BoardSem);
611
        return -EINVAL;
612
    }
613
 
614
    i = pMemDscr->DmaChanNum;
615
    AdmNum = GetAdmNum( brd->m_DmaChannel[i] );
616
    TetrNum = GetTetrNum( brd->m_DmaChannel[i] );
617
    Status = SetDrqFlag( brd, AdmNum, TetrNum, pMemDscr->Param );
618
 
619
    up(&brd->m_BoardSem);
620
 
621
    return Status;
622
}
623
 
624
//--------------------------------------------------------------------
625
 
626
int ioctl_adjust(struct pex_device *brd, size_t arg)
627
{
628
    u32 i;
629
    AMB_SET_DMA_CHANNEL MemDscr;
630
    PAMB_SET_DMA_CHANNEL pMemDscr = &MemDscr;
631
 
632
    down(&brd->m_BoardSem);
633
 
634
    //printk("<0>%s()\n", __FUNCTION__);
635
 
636
    if( copy_from_user((void *)&MemDscr, (void *)arg, sizeof(AMB_SET_DMA_CHANNEL))) {
637
        err_msg(err_trace, "%s(): Error copy data from userspace\n", __FUNCTION__ );
638
        up(&brd->m_BoardSem);
639
        return -EFAULT;
640
    }
641
 
642
    if(pMemDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS)
643
    {
644
        printk("<0>IoctlSetDrqMem: too large stream number\n");
645
        up(&brd->m_BoardSem);
646
        return -EINVAL;
647
    }
648
    if(!(brd->m_DmaChanMask & (1 << pMemDscr->DmaChanNum)))
649
    {
650
        printk("<0>%s(): invalid stream number\n", __FUNCTION__);
651
        up(&brd->m_BoardSem);
652
        return -EINVAL;
653
    }
654
 
655
    i = pMemDscr->DmaChanNum;
656
    Adjust(brd->m_DmaChannel[i], pMemDscr->Param);
657
 
658
    up(&brd->m_BoardSem);
659
 
660
    return 0;
661
}
662
 
663
//--------------------------------------------------------------------
664
 
665
int ioctl_done(struct pex_device *brd, size_t arg)
666
{
667
    int Status = -EINVAL;
668
    u32 i;
669
    u32 done_flag;
670
    AMB_SET_DMA_CHANNEL MemDscr;
671
    PAMB_SET_DMA_CHANNEL pMemDscr = &MemDscr;
672
 
673
    down(&brd->m_BoardSem);
674
 
675
    //printk("<0>%s()\n", __FUNCTION__);
676
 
677
    // get the user buffer
678
    if( copy_from_user((void *)&MemDscr, (void *)arg, sizeof(AMB_SET_DMA_CHANNEL))) {
679
        err_msg(err_trace, "%s(): Error copy data from userspace\n", __FUNCTION__ );
680
        up(&brd->m_BoardSem);
681
        return -EFAULT;
682
    }
683
 
684
    if(pMemDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS)
685
    {
686
        printk("<0>IoctlSetDrqMem: too large stream number\n");
687
        up(&brd->m_BoardSem);
688
        return -EINVAL;
689
    }
690
    if(!(brd->m_DmaChanMask & (1 << pMemDscr->DmaChanNum)))
691
    {
692
        printk("<0>%s(): invalid stream number\n", __FUNCTION__);
693
        up(&brd->m_BoardSem);
694
        return -EINVAL;
695
    }
696
 
697
    i = pMemDscr->DmaChanNum;
698
    done_flag = SetDoneBlock(brd->m_DmaChannel[i], pMemDscr->Param);
699
    if(done_flag)
700
        Status = Done(brd, i);
701
 
702
    up(&brd->m_BoardSem);
703
 
704
    return 0;
705
}
706
 
707
//--------------------------------------------------------------------
708
 
709
int ioctl_reset_fifo(struct pex_device *brd, size_t arg)
710
{
711
    int Status = -EINVAL;
712
    AMB_SET_DMA_CHANNEL MemDscr;
713
    PAMB_SET_DMA_CHANNEL pMemDscr = &MemDscr;
714
 
715
    down(&brd->m_BoardSem);
716
 
717
    // get the user buffer
718
    if( copy_from_user((void *)&MemDscr, (void *)arg, sizeof(AMB_SET_DMA_CHANNEL))) {
719
        err_msg(err_trace, "%s(): Error copy data from userspace\n", __FUNCTION__ );
720
        up(&brd->m_BoardSem);
721
        return -EFAULT;
722
    }
723
 
724
    if(pMemDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS)
725
    {
726
        printk("<0>%s(): too large stream number\n", __FUNCTION__);
727
        up(&brd->m_BoardSem);
728
        return -EINVAL;
729
    }
730
    if(!(brd->m_DmaChanMask & (1 << pMemDscr->DmaChanNum)))
731
    {
732
        printk("<0>%s(): invalid stream number\n", __FUNCTION__);
733
        up(&brd->m_BoardSem);
734
        return -EINVAL;
735
    }
736
 
737
    Status = ResetFifo(brd, pMemDscr->DmaChanNum);
738
 
739
    up(&brd->m_BoardSem);
740
 
741
    return Status;
742
}
743
 
744
//--------------------------------------------------------------------
745
 
746
int ioctl_get_dma_channel_info(struct pex_device *brd, size_t arg)
747
{
748
    AMB_GET_DMA_INFO DmaInfo = {0};
749
 
750
    down(&brd->m_BoardSem);
751
 
752
    // get the user buffer
753
    if( copy_from_user((void *)&DmaInfo, (void *)arg, sizeof(AMB_GET_DMA_INFO))) {
754
        err_msg(err_trace, "%s(): Error copy data from userspace\n", __FUNCTION__ );
755
        up(&brd->m_BoardSem);
756
        return -EFAULT;
757
    }
758
 
759
    if(DmaInfo.DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS)
760
    {
761
        printk("<0>%s(): too large stream number\n", __FUNCTION__);
762
        up(&brd->m_BoardSem);
763
        return -EINVAL;
764
    }
765
    if(!(brd->m_DmaChanMask & (1 << DmaInfo.DmaChanNum)))
766
    {
767
        printk("<0>%s(): invalid stream number\n", __FUNCTION__);
768
        up(&brd->m_BoardSem);
769
        return -EINVAL;
770
    }
771
 
772
    DmaInfo.Direction = brd->m_DmaDir[DmaInfo.DmaChanNum];
773
    DmaInfo.FifoSize = brd->m_DmaFifoSize[DmaInfo.DmaChanNum];
774
    DmaInfo.MaxDmaSize = brd->m_MaxDmaSize[DmaInfo.DmaChanNum];
775
 
776
    if(copy_to_user (( void *)arg, (void *)&DmaInfo, sizeof(AMB_GET_DMA_INFO))) {
777
                err_msg(err_trace, "%s(): Error copy data to userspace\n", __FUNCTION__ );
778
        up(&brd->m_BoardSem);
779
        return -EFAULT;
780
    }
781
 
782
    up(&brd->m_BoardSem);
783
 
784
    return 0;
785
}
786
 
787
//--------------------------------------------------------------------
788
 
789
int ioctl_wait_dma_buffer(struct pex_device *brd, size_t arg)
790
{
791
    int Status = -EINVAL;
792
    u32 i=0;
793
    AMB_STATE_DMA_CHANNEL StateDscr;
794
    PAMB_STATE_DMA_CHANNEL pStateDscr = &StateDscr;
795
 
796
    down ( &brd->m_BoardSem );
797
 
798
    // get the user buffer
799
    if( copy_from_user((void *)&StateDscr, (void *)arg, sizeof(AMB_STATE_DMA_CHANNEL))) {
800
                err_msg(err_trace, "%s(): Error copy data from userspace\n", __FUNCTION__ );
801
        up(&brd->m_BoardSem);
802
        return -EFAULT;
803
    }
804
 
805
    //printk("<0>%s(): DMA %d\n", __FUNCTION__, pStateDscr->DmaChanNum);
806
 
807
    if(pStateDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS)
808
    {
809
        printk("<0>%s(): too large stream number\n", __FUNCTION__);
810
        up(&brd->m_BoardSem);
811
        return -EINVAL;
812
    }
813
 
814
    i = pStateDscr->DmaChanNum;
815
 
816
    Status = WaitBufferEndEvent(brd->m_DmaChannel[i], pStateDscr->Timeout);
817
 
818
    GetState(brd->m_DmaChannel[i],      (u32*)&pStateDscr->BlockNum,
819
             (u32*)&pStateDscr->BlockCntTotal,
820
             (u32*)&pStateDscr->OffsetInBlock,
821
             (u32*)&pStateDscr->DmaChanState);
822
 
823
    if(copy_to_user (( void *)arg, (void *)&StateDscr, sizeof(AMB_STATE_DMA_CHANNEL))) {
824
                err_msg(err_trace, "%s(): Error copy data to userspace\n", __FUNCTION__ );
825
        up(&brd->m_BoardSem);
826
        return -EFAULT;
827
    }
828
 
829
    up(&brd->m_BoardSem);
830
 
831
    return Status;
832
}
833
 
834
//--------------------------------------------------------------------
835
 
836
int ioctl_wait_dma_block(struct pex_device *brd, size_t arg)
837
{
838
    int Status = -EINVAL;
839
    u32 i=0;
840
    AMB_STATE_DMA_CHANNEL StateDscr;
841
    PAMB_STATE_DMA_CHANNEL pStateDscr = &StateDscr;
842
 
843
    down ( &brd->m_BoardSem );
844
 
845
    // get the user buffer
846
    if( copy_from_user((void *)&StateDscr, (void *)arg, sizeof(AMB_STATE_DMA_CHANNEL))) {
847
        err_msg(err_trace, "%s(): Error copy data from userspace\n", __FUNCTION__ );
848
        up(&brd->m_BoardSem);
849
        return -EFAULT;
850
    }
851
 
852
    printk("<0>%s(): DMA %d\n", __FUNCTION__, pStateDscr->DmaChanNum);
853
 
854
    if(pStateDscr->DmaChanNum >= MAX_NUMBER_OF_DMACHANNELS)
855
    {
856
        printk("<0>%s(): too large stream number\n", __FUNCTION__);
857
        up(&brd->m_BoardSem);
858
        return -EINVAL;
859
    }
860
 
861
    i = pStateDscr->DmaChanNum;
862
 
863
    Status = WaitBlockEndEvent(brd->m_DmaChannel[i], pStateDscr->Timeout);
864
 
865
    GetState(brd->m_DmaChannel[i],      (u32*)&pStateDscr->BlockNum,
866
             (u32*)&pStateDscr->BlockCntTotal,
867
             (u32*)&pStateDscr->OffsetInBlock,
868
             (u32*)&pStateDscr->DmaChanState);
869
 
870
    if(copy_to_user (( void *)arg, (void *)&StateDscr, sizeof(AMB_STATE_DMA_CHANNEL))) {
871
        err_msg(err_trace, "%s(): Error copy data to userspace\n", __FUNCTION__ );
872
        up(&brd->m_BoardSem);
873
        return -EFAULT;
874
    }
875
 
876
    up(&brd->m_BoardSem);
877
 
878
    return Status;
879
}
880
 
881
//--------------------------------------------------------------------
882
 
883
 
884
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.