]>
git.ipfire.org Git - people/ms/u-boot.git/blob - examples/mem_to_mem_idma2intr.c
1 /* The dpalloc function used and implemented in this file was derieved
2 * from PPCBoot/U-Boot file "cpu/mpc8260/commproc.c".
5 /* Author: Arun Dharankar <ADharankar@ATTBI.Com>
6 * This example is meant to only demonstrate how the IDMA could be used.
10 * This file is based on "arch/ppc/8260_io/commproc.c" - here is it's
13 * General Purpose functions for the global management of the
14 * 8260 Communication Processor Module.
15 * Copyright (c) 1999 Dan Malek (dmalek@jlc.net)
16 * Copyright (c) 2000 MontaVista Software, Inc (source@mvista.com)
19 * In addition to the individual control of the communication
20 * channels, there are a few functions that globally affect the
21 * communication processor.
23 * Buffer descriptors must be allocated from the dual ported memory
24 * space. The allocator for that is here. When the communication
25 * process is reset, we reclaim the memory available. There is
26 * currently no deallocator for this memory.
35 #ifndef STANDALONE /* Linked into/Part of PPCBoot */
38 #else /* Standalone app of PPCBoot */
40 #define printf mon_printf
44 #define udelay mon_udelay
45 #define malloc mon_malloc
46 #define WATCHDOG_RESET() { \
47 *(ushort *)(CFG_IMMR + 0x1000E) = 0x556c; \
48 *(ushort *)(CFG_IMMR + 0x1000E) = 0xaa39; \
50 #endif /* STANDALONE */
54 #define DEBUG(fmt, args...) { \
56 printf("[%s %d %s]: ",__FILE__,__LINE__,__FUNCTION__); \
57 printf(fmt, ##args); \
61 #define CPM_CR_IDMA1_SBLOCK (0x14)
62 #define CPM_CR_IDMA2_SBLOCK (0x15)
63 #define CPM_CR_IDMA3_SBLOCK (0x16)
64 #define CPM_CR_IDMA4_SBLOCK (0x17)
65 #define CPM_CR_IDMA1_PAGE (0x07)
66 #define CPM_CR_IDMA2_PAGE (0x08)
67 #define CPM_CR_IDMA3_PAGE (0x09)
68 #define CPM_CR_IDMA4_PAGE (0x0a)
69 #define PROFF_IDMA1_BASE ((uint)0x87fe)
70 #define PROFF_IDMA2_BASE ((uint)0x88fe)
71 #define PROFF_IDMA3_BASE ((uint)0x89fe)
72 #define PROFF_IDMA4_BASE ((uint)0x8afe)
74 #define CPM_CR_INIT_TRX ((ushort)0x0000)
75 #define CPM_CR_FLG ((ushort)0x0001)
77 #define mk_cr_cmd(PG, SBC, MCN, OP) \
78 ((PG << 26) | (SBC << 21) | (MCN << 6) | OP)
82 typedef struct ibdbits
{
86 unsigned b_interrupt
:1;
106 typedef union ibdbitsu
{
112 typedef struct idma_buf_desc
{
113 ibdbitsu_t ibd_bits
; /* Status and Control */
114 uint ibd_datlen
; /* Data length in buffer */
115 uint ibd_sbuf
; /* Source buffer addr in host mem */
116 uint ibd_dbuf
; /* Destination buffer addr in host mem */
121 typedef struct dcmbits
{
136 typedef union dcmbitsu
{
142 typedef struct pram_idma
{
144 dcmbitsu_t pi_dcmbits
;
147 ushort pi_bufinv
; /* internal to CPM */
149 ushort pi_dprinptr
; /* internal to CPM */
151 ushort pi_dproutptr
; /* internal to CPM */
156 ushort pi_resv1
; /* internal to CPM */
164 volatile immap_t
*immap
= (immap_t
*) CFG_IMMR
;
166 volatile pram_idma_t
*piptr
;
168 volatile int dmadone
;
169 volatile int *dmadonep
= &dmadone
;
170 void dmadone_handler (void *);
172 int idma_init (void);
173 void idma_start (int, int, int, uint
, uint
, int);
174 uint
dpalloc (uint
, uint
);
177 uint dpinit_done
= 0;
184 switch (mon_getc ()) {
185 case 0x03: /* ^C - Control C */
193 void * memset(void * s
,int c
,size_t count
)
195 char *xs
= (char *) s
;
200 int memcmp(const void * cs
,const void * ct
,size_t count
)
202 const unsigned char *su1
, *su2
;
204 for( su1
= cs
, su2
= ct
; 0 < count
; ++su1
, ++su2
, count
--)
205 if ((res
= *su1
- *su2
) != 0)
209 #endif /* STANDALONE */
212 int mem_to_mem_idma2intr (bd_t
* bd
, int argc
, char *argv
[])
214 int do_idma (bd_t
* bd
, int argc
, char *argv
[])
215 #endif /* STANDALONE */
223 DEBUG ("Installing dma handler\n");
224 mon_install_hdlr (7, dmadone_handler
, (void *) bdf
);
226 memset ((void *) 0x100000, 'a', 512);
227 memset ((void *) 0x200000, 'b', 512);
229 for (i
= 0; i
< 32; i
++) {
230 printf ("Startin IDMA, iteration=%d\n", i
);
231 idma_start (1, 1, 512, 0x100000, 0x200000, 3);
234 DEBUG ("Uninstalling dma handler\n");
241 idma_start (int sinc
, int dinc
, int sz
, uint sbuf
, uint dbuf
, int ttype
)
243 /* ttype is for M-M, M-P, P-M or P-P: not used for now */
245 piptr
->pi_istate
= 0; /* manual says: clear it before every START_IDMA */
246 piptr
->pi_dcmbits
.b
.b_resv1
= 0;
249 piptr
->pi_dcmbits
.b
.b_sinc
= 1;
251 piptr
->pi_dcmbits
.b
.b_sinc
= 0;
254 piptr
->pi_dcmbits
.b
.b_dinc
= 1;
256 piptr
->pi_dcmbits
.b
.b_dinc
= 0;
258 piptr
->pi_dcmbits
.b
.b_erm
= 0;
259 piptr
->pi_dcmbits
.b
.b_sd
= 0x00; /* M-M */
261 bdf
->ibd_sbuf
= sbuf
;
262 bdf
->ibd_dbuf
= dbuf
;
263 bdf
->ibd_bits
.b
.b_cm
= 0;
264 bdf
->ibd_bits
.b
.b_interrupt
= 1;
265 bdf
->ibd_bits
.b
.b_wrap
= 1;
266 bdf
->ibd_bits
.b
.b_last
= 1;
267 bdf
->ibd_bits
.b
.b_sdn
= 0;
268 bdf
->ibd_bits
.b
.b_ddn
= 0;
269 bdf
->ibd_bits
.b
.b_dgbl
= 0;
270 bdf
->ibd_bits
.b
.b_ddtb
= 0;
271 bdf
->ibd_bits
.b
.b_sgbl
= 0;
272 bdf
->ibd_bits
.b
.b_sdtb
= 0;
273 bdf
->ibd_bits
.b
.b_dbo
= 1;
274 bdf
->ibd_bits
.b
.b_sbo
= 1;
275 bdf
->ibd_bits
.b
.b_valid
= 1;
276 bdf
->ibd_datlen
= 512;
280 immap
->im_sdma
.sdma_idmr2
= (uchar
) 0xf;
282 immap
->im_cpm
.cp_cpcr
= mk_cr_cmd (CPM_CR_IDMA2_PAGE
,
283 CPM_CR_IDMA2_SBLOCK
, 0x0,
286 while (*dmadonep
!= 1) {
288 DEBUG ("\nInterrupted waiting for DMA interrupt.\n");
291 printf ("Waiting for DMA interrupt (dmadone=%d b_valid = %d)...\n",
292 dmadone
, bdf
->ibd_bits
.b
.b_valid
);
295 printf ("DMA complete notification received!\n");
298 DEBUG ("memcmp(0x%08x, 0x%08x, 512) = %d\n",
299 sbuf
, dbuf
, memcmp ((void *) sbuf
, (void *) dbuf
, 512));
304 #define MAX_INT_BUFSZ 64
305 #define DCM_WRAP 0 /* MUST be consistant with MAX_INT_BUFSZ */
311 immap
->im_cpm
.cp_rccr
&= ~0x00F3FFFF;
312 immap
->im_cpm
.cp_rccr
|= 0x00A00A00;
314 memaddr
= dpalloc (sizeof (pram_idma_t
), 64);
316 *(volatile ushort
*) &immap
->im_dprambase
[PROFF_IDMA2_BASE
] = memaddr
;
317 piptr
= (volatile pram_idma_t
*) ((uint
) (immap
) + memaddr
);
319 piptr
->pi_resv1
= 0; /* manual says: clear it */
320 piptr
->pi_dcmbits
.b
.b_fb
= 0;
321 piptr
->pi_dcmbits
.b
.b_lp
= 1;
322 piptr
->pi_dcmbits
.b
.b_erm
= 0;
323 piptr
->pi_dcmbits
.b
.b_dt
= 0;
325 memaddr
= (uint
) dpalloc (sizeof (ibd_t
), 64);
326 piptr
->pi_ibase
= piptr
->pi_ibdptr
= (volatile short) memaddr
;
327 bdf
= (volatile ibd_t
*) ((uint
) (immap
) + memaddr
);
328 bdf
->ibd_bits
.b
.b_valid
= 0;
330 memaddr
= (uint
) dpalloc (64, 64);
331 piptr
->pi_dprbuf
= (volatile ushort
) memaddr
;
332 piptr
->pi_dcmbits
.b
.b_wrap
= 4;
333 piptr
->pi_ssmax
= 32;
335 piptr
->pi_sts
= piptr
->pi_ssmax
;
336 piptr
->pi_dts
= piptr
->pi_ssmax
;
341 void dmadone_handler (void *arg
)
343 immap
->im_sdma
.sdma_idmr2
= (uchar
) 0x0;
351 static uint dpbase
= 0;
353 uint
dpalloc (uint size
, uint align
)
355 DECLARE_GLOBAL_DATA_PTR
;
357 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
359 uint align_mask
, off
;
362 /* Pointer to initial global data area */
364 if (dpinit_done
== 0) {
365 dpbase
= gd
->dp_alloc_base
;
369 align_mask
= align
- 1;
372 if ((off
= (dpbase
& align_mask
)) != 0)
373 dpbase
+= (align
- off
);
375 if ((off
= size
& align_mask
) != 0)
378 if ((dpbase
+ size
) >= gd
->dp_alloc_top
) {
380 printf ("dpalloc: ran out of dual port ram!");
387 memset ((void *) &immr
->im_dprambase
[retloc
], 0, size
);