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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc2/] [or1ksim/] [peripheral/] [dma.c] - Blame information for rev 1467

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

Line No. Rev Author Line
1 212 erez
/* dma.c -- Simulation of DMA
2 503 erez
   Copyright (C) 2001 by Erez Volk, erez@opencores.org
3 212 erez
 
4 503 erez
   This file is part of OpenRISC 1000 Architectural Simulator.
5 235 erez
 
6 503 erez
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 2 of the License, or
9
   (at your option) any later version.
10 235 erez
 
11 503 erez
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15 212 erez
 
16 503 erez
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 235 erez
*/
20 212 erez
 
21
/*
22
 * This simulation of the DMA core is not meant to be full.
23
 * It is written only to allow simulating the Ethernet core.
24
 * Of course, if anyone feels like perfecting it, feel free...
25
 */
26
 
27 1308 phoenix
#include <string.h>
28
 
29 1350 nogj
#include "config.h"
30
 
31
#ifdef HAVE_INTTYPES_H
32
#include <inttypes.h>
33
#endif
34
 
35
#include "port.h"
36
#include "arch.h"
37 212 erez
#include "dma.h"
38
#include "sim-config.h"
39
#include "pic.h"
40 235 erez
#include "abstract.h"
41 212 erez
#include "fields.h"
42 1370 nogj
#include "sched.h"
43 1308 phoenix
#include "debug.h"
44 212 erez
 
45 1370 nogj
/* We keep a copy of all our controllers because we have to export an interface
46
 * to other peripherals eg. ethernet */
47
static struct dma_controller *dmas = NULL;
48 212 erez
 
49 1359 nogj
static uint32_t dma_read32( oraddr_t addr, void *dat );
50
static void dma_write32( oraddr_t addr, uint32_t value, void *dat );
51 235 erez
 
52 212 erez
static unsigned long dma_read_ch_csr( struct dma_channel *channel );
53
static void dma_write_ch_csr( struct dma_channel *channel, unsigned long value );
54 1370 nogj
void dma_controller_clock( struct dma_controller *dma );
55 212 erez
static void dma_load_descriptor( struct dma_channel *channel );
56
static void dma_init_transfer( struct dma_channel *channel );
57
static void dma_channel_terminate_transfer( struct dma_channel *channel, int generate_interrupt );
58
 
59 1370 nogj
void dma_channel_clock( void *dat );
60 212 erez
 
61 1370 nogj
static void masked_increase( oraddr_t *value, unsigned long mask );
62
 
63 212 erez
#define CHANNEL_ND_I(ch) (TEST_FLAG(ch->regs.csr,DMA_CH_CSR,MODE) && TEST_FLAG(ch->regs.csr,DMA_CH_CSR,USE_ED) && ch->dma_nd_i)
64
 
65
 
66
/* Reset. Initializes all registers to default and places devices in memory address space. */
67 1370 nogj
void dma_reset(void *dat)
68 212 erez
{
69 1370 nogj
  struct dma_controller *dma = dat;
70
  unsigned channel_number;
71 212 erez
 
72 1370 nogj
  memset( dma->ch, 0, sizeof(dma->ch) );
73
 
74
  dma->regs.csr = 0;
75
  dma->regs.int_msk_a = 0;
76
  dma->regs.int_msk_b = 0;
77
  dma->regs.int_src_a = 0;
78
  dma->regs.int_src_b = 0;
79 235 erez
 
80 1370 nogj
  for ( channel_number = 0; channel_number < DMA_NUM_CHANNELS; ++ channel_number ) {
81
    dma->ch[channel_number].controller = dma;
82
    dma->ch[channel_number].channel_number = channel_number;
83
    dma->ch[channel_number].channel_mask = 1LU << channel_number;
84
    dma->ch[channel_number].regs.am0 = dma->ch[channel_number].regs.am1 = 0xFFFFFFFC;
85 503 erez
  }
86 212 erez
}
87
 
88
/* Print register values on stdout */
89 1370 nogj
void dma_status( void *dat )
90 212 erez
{
91 1465 nogj
  unsigned j;
92 1370 nogj
  struct dma_controller *dma = dat;
93 212 erez
 
94 1370 nogj
  if ( dma->baseaddr == 0 )
95
    return;
96 212 erez
 
97 1465 nogj
  PRINTF( "\nDMA controller at 0x%"PRIxADDR":\n", dma->baseaddr );
98 1370 nogj
  PRINTF( "CSR       : 0x%08lX\n", dma->regs.csr );
99
  PRINTF( "INT_MSK_A : 0x%08lX\n", dma->regs.int_msk_a );
100
  PRINTF( "INT_MSK_B : 0x%08lX\n", dma->regs.int_msk_b );
101
  PRINTF( "INT_SRC_A : 0x%08lX\n", dma->regs.int_src_a );
102
  PRINTF( "INT_SRC_B : 0x%08lX\n", dma->regs.int_src_b );
103 212 erez
 
104 1370 nogj
  for ( j = 0; j < DMA_NUM_CHANNELS; ++ j ) {
105
    struct dma_channel *channel = &(dma->ch[j]);
106
    if ( !channel->referenced )
107
      continue;
108
    PRINTF( "CH%u_CSR   : 0x%08lX\n", j, channel->regs.csr );
109
    PRINTF( "CH%u_SZ    : 0x%08lX\n", j, channel->regs.sz );
110
    PRINTF( "CH%u_A0    : 0x%08lX\n", j, channel->regs.a0 );
111
    PRINTF( "CH%u_AM0   : 0x%08lX\n", j, channel->regs.am0 );
112
    PRINTF( "CH%u_A1    : 0x%08lX\n", j, channel->regs.a1 );
113
    PRINTF( "CH%u_AM1   : 0x%08lX\n", j, channel->regs.am1 );
114
    PRINTF( "CH%u_DESC  : 0x%08lX\n", j, channel->regs.desc );
115
    PRINTF( "CH%u_SWPTR : 0x%08lX\n", j, channel->regs.swptr );
116 503 erez
  }
117 212 erez
}
118
 
119 1370 nogj
 
120 212 erez
/* Read a register */
121 1359 nogj
uint32_t dma_read32( oraddr_t addr, void *dat )
122 212 erez
{
123 1370 nogj
  struct dma_controller *dma = dat;
124 212 erez
 
125 503 erez
  addr -= dma->baseaddr;
126 212 erez
 
127 503 erez
  if ( addr < DMA_CH_BASE ) {
128
    /* case of global (not per-channel) registers */
129
    switch( addr ) {
130
    case DMA_CSR: return dma->regs.csr;
131
    case DMA_INT_MSK_A: return dma->regs.int_msk_a;
132
    case DMA_INT_MSK_B: return dma->regs.int_msk_b;
133
    case DMA_INT_SRC_A: return dma->regs.int_src_a;
134
    case DMA_INT_SRC_B: return dma->regs.int_src_b;
135
    default:
136 1350 nogj
      fprintf( stderr, "dma_read32( 0x%"PRIxADDR" ): Illegal register\n",
137
               addr + dma->baseaddr );
138 503 erez
      return 0;
139
    }
140
  } else {
141
    /* case of per-channel registers */
142
    unsigned chno = (addr - DMA_CH_BASE) / DMA_CH_SIZE;
143
    addr = (addr - DMA_CH_BASE) % DMA_CH_SIZE;
144
    switch( addr ) {
145
    case DMA_CH_CSR: return dma_read_ch_csr( &(dma->ch[chno]) );
146
    case DMA_CH_SZ: return dma->ch[chno].regs.sz;
147
    case DMA_CH_A0: return dma->ch[chno].regs.a0;
148
    case DMA_CH_AM0: return dma->ch[chno].regs.am0;
149
    case DMA_CH_A1: return dma->ch[chno].regs.a1;
150
    case DMA_CH_AM1: return dma->ch[chno].regs.am1;
151
    case DMA_CH_DESC: return dma->ch[chno].regs.desc;
152
    case DMA_CH_SWPTR: return dma->ch[chno].regs.swptr;
153
    }
154
  }
155 1370 nogj
  return 0;
156 212 erez
}
157
 
158
 
159
/* Handle read from a channel CSR */
160
unsigned long dma_read_ch_csr( struct dma_channel *channel )
161
{
162 503 erez
  unsigned long result = channel->regs.csr;
163 212 erez
 
164 503 erez
  /* before returning, clear all relevant bits */
165
  CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, INT_CHUNK_DONE );
166
  CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, INT_DONE );
167
  CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, INT_ERR );
168
  CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, ERR );
169 212 erez
 
170 503 erez
  return result;
171 212 erez
}
172
 
173
 
174
 
175
/* Write a register */
176 1359 nogj
void dma_write32( oraddr_t addr, uint32_t value, void *dat )
177 212 erez
{
178 1370 nogj
  struct dma_controller *dma = dat;
179 212 erez
 
180 503 erez
  addr -= dma->baseaddr;
181 212 erez
 
182 503 erez
  /* case of global (not per-channel) registers */
183
  if ( addr < DMA_CH_BASE ) {
184
    switch( addr ) {
185
    case DMA_CSR:
186
      if ( TEST_FLAG( value, DMA_CSR, PAUSE ) )
187
        fprintf( stderr, "dma: PAUSE not implemented\n" );
188
      break;
189 212 erez
 
190 503 erez
    case DMA_INT_MSK_A: dma->regs.int_msk_a = value; break;
191
    case DMA_INT_MSK_B: dma->regs.int_msk_b = value; break;
192
    case DMA_INT_SRC_A: dma->regs.int_src_a = value; break;
193
    case DMA_INT_SRC_B: dma->regs.int_src_b = value; break;
194
    default:
195 1350 nogj
      fprintf( stderr, "dma_write32( 0x%"PRIxADDR" ): Illegal register\n",
196
               addr + dma->baseaddr );
197 503 erez
      return;
198
    }
199
  } else {
200
    /* case of per-channel registers */
201
    unsigned chno = (addr - DMA_CH_BASE) / DMA_CH_SIZE;
202
    struct dma_channel *channel = &(dma->ch[chno]);
203
    channel->referenced = 1;
204
    addr = (addr - DMA_CH_BASE) % DMA_CH_SIZE;
205
    switch( addr ) {
206
    case DMA_CSR: dma_write_ch_csr( &(dma->ch[chno]), value ); break;
207
    case DMA_CH_SZ: channel->regs.sz = value; break;
208
    case DMA_CH_A0: channel->regs.a0 = value; break;
209
    case DMA_CH_AM0: channel->regs.am0 = value; break;
210
    case DMA_CH_A1: channel->regs.a1 = value; break;
211
    case DMA_CH_AM1: channel->regs.am1 = value; break;
212
    case DMA_CH_DESC: channel->regs.desc = value; break;
213
    case DMA_CH_SWPTR: channel->regs.swptr = value; break;
214
    }
215
  }
216 212 erez
}
217
 
218
 
219
/* Write a channel CSR
220
 * This ensures only the writable bits are modified.
221
 */
222
void dma_write_ch_csr( struct dma_channel *channel, unsigned long value )
223
{
224 1370 nogj
  /* Check if we should *start* a transfer */
225
  if ( !TEST_FLAG( channel->regs.csr, DMA_CH_CSR, CH_EN ) &&
226
       TEST_FLAG( value, DMA_CH_CSR, CH_EN ))
227 1390 nogj
    SCHED_ADD( dma_channel_clock, channel, 1 );
228 1370 nogj
  else if ( !TEST_FLAG( value, DMA_CH_CSR, CH_EN ) )
229
    /* The CH_EN flag is clear, check if we have a transfer in progress and
230
     * clear it */
231
    SCHED_FIND_REMOVE( dma_channel_clock, channel );
232
 
233 503 erez
  /* Copy the writable bits to the channel CSR */
234
  channel->regs.csr &= ~DMA_CH_CSR_WRITE_MASK;
235
  channel->regs.csr |= value & DMA_CH_CSR_WRITE_MASK;
236 212 erez
}
237
 
238
 
239
 
240 1370 nogj
/* Clock tick for one channel on one DMA controller.
241 212 erez
 * This does the actual "DMA" operation.
242
 * One chunk is transferred per clock.
243
 */
244 1370 nogj
void dma_channel_clock( void *dat )
245 212 erez
{
246 503 erez
  int breakpoint = 0;
247 1370 nogj
  struct dma_channel *channel = dat;
248 235 erez
 
249 1370 nogj
  /* Do we need to abort? */
250
  if ( TEST_FLAG( channel->regs.csr, DMA_CH_CSR, STOP ) ) {
251
    debug( 3,  "DMA: STOP requested\n" );
252
    CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, CH_EN );
253
    CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, BUSY );
254
    SET_FLAG( channel->regs.csr, DMA_CH_CSR, ERR );
255 256 erez
 
256 1370 nogj
    if ( TEST_FLAG( channel->regs.csr, DMA_CH_CSR, INE_ERR ) &&
257
         (channel->controller->regs.int_msk_a & channel->channel_mask) ) {
258
      SET_FLAG( channel->regs.csr, DMA_CH_CSR, INT_ERR );
259
      channel->controller->regs.int_src_a = channel->channel_mask;
260
      report_interrupt( channel->controller->irq );
261 503 erez
    }
262 212 erez
 
263 1370 nogj
    return;
264
  }
265 212 erez
 
266 1370 nogj
  /* In HW Handshake mode, only work when dma_req_i asserted */
267
  if ( TEST_FLAG(channel->regs.csr, DMA_CH_CSR, MODE) && !channel->dma_req_i ) {
268
    /* Reschedule */
269 1390 nogj
    SCHED_ADD( dma_channel_clock, dat, 1 );
270 1370 nogj
    return;
271
  }
272 212 erez
 
273 1370 nogj
  /* If this is the first cycle of the transfer, initialize our state */
274
  if ( !TEST_FLAG( channel->regs.csr, DMA_CH_CSR, BUSY ) ) {
275
    debug( 4,  "DMA: Starting new transfer\n" );
276 212 erez
 
277 1370 nogj
    CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, DONE );
278
    CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, ERR );
279
    SET_FLAG( channel->regs.csr, DMA_CH_CSR, BUSY );
280 212 erez
 
281 1370 nogj
    /* If using linked lists, copy the appropriate fields to our registers */
282
    if ( TEST_FLAG( channel->regs.csr, DMA_CH_CSR, USE_ED ) )
283
      dma_load_descriptor( channel );
284
    else
285
      channel->load_next_descriptor_when_done = 0;
286 212 erez
 
287 1370 nogj
    /* Set our internal status */
288
    dma_init_transfer( channel );
289 212 erez
 
290 1370 nogj
    /* Might need to skip descriptor */
291 503 erez
    if ( CHANNEL_ND_I( channel ) ) {
292 1370 nogj
      debug( 3,  "DMA: dma_nd_i asserted before dma_req_i, skipping descriptor\n" );
293 503 erez
      dma_channel_terminate_transfer( channel, 0 );
294 1370 nogj
      return;
295 503 erez
    }
296 1370 nogj
  }
297 235 erez
 
298 1370 nogj
  /* Transfer one word */
299 1400 nogj
  set_direct32( channel->destination, eval_direct32( channel->source,
300
                                                     &breakpoint, 0, 0 ),
301
                &breakpoint, 0, 0 );
302 1370 nogj
 
303
  /* Advance the source and destionation pointers */
304
  masked_increase( &(channel->source), channel->source_mask );
305
  masked_increase( &(channel->destination), channel->destination_mask );
306
  ++ channel->words_transferred;
307
 
308
  /* Have we finished a whole chunk? */
309
  channel->dma_ack_o = (channel->words_transferred % channel->chunk_size == 0);
310
 
311
  /* When done with a chunk, check for dma_nd_i */
312
  if ( CHANNEL_ND_I( channel ) ) {
313
    debug( 3,  "DMA: dma_nd_i asserted\n" );
314
    dma_channel_terminate_transfer( channel, 0 );
315
    return;
316 503 erez
  }
317 1370 nogj
 
318
  /* Are we done? */
319
  if ( channel->words_transferred >= channel->total_size ) {
320
    dma_channel_terminate_transfer( channel, 1 );
321
    return;
322
  }
323
 
324
  /* Reschedule to transfer the next chunk */
325 1390 nogj
  SCHED_ADD( dma_channel_clock, dat, 1 );
326 212 erez
}
327
 
328
 
329
/* Copy relevant valued from linked list descriptor to channel registers */
330
void dma_load_descriptor( struct dma_channel *channel )
331
{
332 503 erez
  int breakpoint = 0;
333 1400 nogj
  unsigned long desc_csr = eval_direct32( channel->regs.desc + DMA_DESC_CSR, &breakpoint, 0, 0 );
334 212 erez
 
335 503 erez
  channel->load_next_descriptor_when_done = !TEST_FLAG( desc_csr, DMA_DESC_CSR, EOL );
336 212 erez
 
337 503 erez
  ASSIGN_FLAG( channel->regs.csr, DMA_CH_CSR, INC_SRC, TEST_FLAG( desc_csr, DMA_DESC_CSR, INC_SRC ) );
338
  ASSIGN_FLAG( channel->regs.csr, DMA_CH_CSR, INC_DST, TEST_FLAG( desc_csr, DMA_DESC_CSR, INC_DST ) );
339
  ASSIGN_FLAG( channel->regs.csr, DMA_CH_CSR, SRC_SEL, TEST_FLAG( desc_csr, DMA_DESC_CSR, SRC_SEL ) );
340
  ASSIGN_FLAG( channel->regs.csr, DMA_CH_CSR, DST_SEL, TEST_FLAG( desc_csr, DMA_DESC_CSR, DST_SEL ) );
341 212 erez
 
342 503 erez
  SET_FIELD( channel->regs.sz, DMA_CH_SZ, TOT_SZ,        GET_FIELD( desc_csr, DMA_DESC_CSR, TOT_SZ ) );
343 212 erez
 
344 1400 nogj
  channel->regs.a0 = eval_direct32( channel->regs.desc + DMA_DESC_ADR0, &breakpoint, 0, 0 );
345
  channel->regs.a1 = eval_direct32( channel->regs.desc + DMA_DESC_ADR1, &breakpoint, 0, 0 );
346 212 erez
 
347 503 erez
  channel->current_descriptor = channel->regs.desc;
348 1400 nogj
  channel->regs.desc = eval_direct32( channel->regs.desc + DMA_DESC_NEXT, &breakpoint, 0, 0 );
349 212 erez
}
350
 
351
 
352
/* Initialize internal parameters used to implement transfers */
353
void dma_init_transfer( struct dma_channel *channel )
354
{
355 503 erez
  channel->source = channel->regs.a0;
356
  channel->destination = channel->regs.a1;
357
  channel->source_mask = TEST_FLAG( channel->regs.csr, DMA_CH_CSR, INC_SRC ) ? channel->regs.am0 : 0;
358
  channel->destination_mask = TEST_FLAG( channel->regs.csr, DMA_CH_CSR, INC_DST ) ? channel->regs.am1 : 0;
359
  channel->total_size = GET_FIELD( channel->regs.sz, DMA_CH_SZ, TOT_SZ );
360
  channel->chunk_size = GET_FIELD( channel->regs.sz, DMA_CH_SZ, CHK_SZ );
361
  if ( !channel->chunk_size || (channel->chunk_size > channel->total_size) )
362
    channel->chunk_size = channel->total_size;
363
  channel->words_transferred = 0;
364 212 erez
}
365
 
366
 
367
/* Take care of transfer termination */
368
void dma_channel_terminate_transfer( struct dma_channel *channel, int generate_interrupt )
369
{
370 503 erez
  debug( 4,  "DMA: Terminating transfer\n" );
371 256 erez
 
372 503 erez
  /* Might be working in a linked list */
373
  if ( channel->load_next_descriptor_when_done ) {
374
    dma_load_descriptor( channel );
375
    dma_init_transfer( channel );
376 1370 nogj
    /* Reschedule */
377 1390 nogj
    SCHED_ADD( dma_channel_clock, channel, 1 );
378 503 erez
    return;
379
  }
380 212 erez
 
381 503 erez
  /* Might be in auto-restart mode */
382
  if ( TEST_FLAG( channel->regs.csr, DMA_CH_CSR, ARS ) ) {
383
    dma_init_transfer( channel );
384
    return;
385
  }
386 212 erez
 
387 503 erez
  /* If needed, write amount of data transferred back to memory */
388
  if ( TEST_FLAG( channel->regs.csr, DMA_CH_CSR, SZ_WB ) &&
389
       TEST_FLAG( channel->regs.csr, DMA_CH_CSR, USE_ED ) ) {
390 1370 nogj
   /* TODO: What should we write back? Doc says "total number of remaining bytes" !? */
391 503 erez
    unsigned long remaining_words = channel->total_size - channel->words_transferred;
392
    SET_FIELD( channel->regs.sz, DMA_DESC_CSR, TOT_SZ, remaining_words );
393
  }
394 212 erez
 
395 503 erez
  /* Mark end of transfer */
396
  CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, CH_EN );
397
  SET_FLAG( channel->regs.csr, DMA_CH_CSR, DONE );
398
  CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, ERR );
399
  CLEAR_FLAG( channel->regs.csr, DMA_CH_CSR, BUSY );
400 235 erez
 
401 503 erez
  /* If needed, generate interrupt */
402
  if ( generate_interrupt ) {
403
    /* TODO: Which channel should we interrupt? */
404
    if ( TEST_FLAG( channel->regs.csr, DMA_CH_CSR, INE_DONE ) &&
405
         (channel->controller->regs.int_msk_a & channel->channel_mask) ) {
406
      SET_FLAG( channel->regs.csr, DMA_CH_CSR, INT_DONE );
407
      channel->controller->regs.int_src_a = channel->channel_mask;
408
      report_interrupt( channel->controller->irq );
409
    }
410
  }
411 212 erez
}
412
 
413
/* Utility function: Add 4 to a value with a mask */
414 1370 nogj
static void masked_increase( oraddr_t *value, unsigned long mask )
415 212 erez
{
416 503 erez
  *value = (*value & ~mask) | ((*value + 4) & mask);
417 212 erez
}
418 1358 nogj
 
419 1370 nogj
/*-------------------------------------------[ DMA<->Peripheral interface ]---*/
420
/*
421
 * Simulation of control signals
422
 * To be used by simulations for other devices, e.g. ethernet
423
 */
424
 
425
void set_dma_req_i( struct dma_channel *channel )
426 1358 nogj
{
427 1370 nogj
  channel->dma_req_i = 1;
428 1358 nogj
}
429
 
430 1370 nogj
void clear_dma_req_i( struct dma_channel *channel )
431
{
432
  channel->dma_req_i = 0;
433
}
434
 
435
void set_dma_nd_i( struct dma_channel *channel )
436
{
437
  channel->dma_nd_i = 1;
438
}
439
 
440
void clear_dma_nd_i( struct dma_channel *channel )
441
{
442
  channel->dma_nd_i = 0;
443
}
444
 
445
unsigned check_dma_ack_o( struct dma_channel *channel )
446
{
447
  return channel->dma_ack_o;
448
}
449
 
450
struct dma_channel *find_dma_controller_ch( unsigned controller,
451
                                            unsigned channel )
452
{
453
  struct dma_controller *cur = dmas;
454
 
455
  while( cur && controller ) {
456
    cur = cur->next;
457
    controller--;
458
  }
459
 
460
  if( !cur )
461
    return NULL;
462
 
463
  return &(cur->ch[channel]);
464
}
465
 
466
 
467
/*----------------------------------------------------[ DMA configuration ]---*/
468 1358 nogj
void dma_baseaddr(union param_val val, void *dat)
469
{
470 1370 nogj
  struct dma_controller *dma = dat;
471
  dma->baseaddr = val.addr_val;
472 1358 nogj
}
473
 
474
void dma_irq(union param_val val, void *dat)
475
{
476 1370 nogj
  struct dma_controller *dma = dat;
477
  dma->irq = val.int_val;
478 1358 nogj
}
479
 
480
void dma_vapi_id(union param_val val, void *dat)
481
{
482 1370 nogj
  struct dma_controller *dma = dat;
483
  dma->vapi_id = val.int_val;
484 1358 nogj
}
485
 
486 1461 nogj
void dma_enabled(union param_val val, void *dat)
487
{
488
  struct dma_controller *dma = dat;
489
  dma->enabled = val.int_val;
490
}
491
 
492 1370 nogj
void *dma_sec_start(void)
493
{
494
  struct dma_controller *new = malloc(sizeof(struct dma_controller));
495
 
496
  if(!new) {
497
    fprintf(stderr, "Peripheral DMA: Run out of memory\n");
498
    exit(-1);
499
  }
500
 
501
  new->next = NULL;
502 1461 nogj
  new->enabled = 1;
503 1370 nogj
 
504
  return new;
505
}
506
 
507
void dma_sec_end(void *dat)
508
{
509
  struct dma_controller *dma = dat;
510
  struct dma_controller *cur;
511
 
512 1461 nogj
  if(!dma->enabled) {
513
    free(dat);
514
    return;
515
  }
516
 
517 1370 nogj
  register_memoryarea( dma->baseaddr, DMA_ADDR_SPACE, 4, 0, dma_read32, dma_write32, dat );
518
  reg_sim_reset( dma_reset, dat );
519
  reg_sim_stat( dma_status, dat );
520
 
521
  if(dmas) {
522
    for(cur = dmas; cur->next; cur = cur->next);
523
    cur->next = dma;
524
  } else
525
    dmas = dma;
526
}
527
 
528 1358 nogj
void reg_dma_sec(void)
529
{
530 1370 nogj
  struct config_section *sec = reg_config_sec("dma", dma_sec_start, dma_sec_end);
531 1358 nogj
 
532
  reg_config_param(sec, "irq", paramt_int, dma_irq);
533 1461 nogj
  reg_config_param(sec, "enabled", paramt_int, dma_enabled);
534 1358 nogj
  reg_config_param(sec, "baseaddr", paramt_addr, dma_baseaddr);
535
  reg_config_param(sec, "vapi_id", paramt_addr, dma_vapi_id);
536
}

powered by: WebSVN 2.1.0

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