linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* mtdcr and mfdcr macros
@ 2003-12-03 15:25 Verberk, Bep
  2003-12-03 17:56 ` Verberk, Bep
  2003-12-03 20:02 ` Eugene Surovegin
  0 siblings, 2 replies; 4+ messages in thread
From: Verberk, Bep @ 2003-12-03 15:25 UTC (permalink / raw)
  To: linuxppc-embedded


I'd like a sanity check on a change I am considering to
these macros....

I had some difficulty executing these macros
(found in include/asm/processor.h) in a loop, eg:

#define DMA0_BANKS 	4
#define DCRN_DMA0_BASE	0x100
#define DCRN_DMA0_CR(bank)  (DCRN_DMA0_BASE + (8 * (bank)))

		for(i=0;i<DMA0_BANKS;i++){
			dma0_cr = mfdcr(DCRN_DMA0_CR(i));
			CLEARBITS(dma0_cr, DMA0_CR_PCE);
			mtdcr(DCRN_DMA0_CR(i), dma0_cr);
		};


compiling results in the assembler error
/tmp/cca8HPJ4.s:282: Error: undefined symbol `i' in operation

Compiling with the -E to see what the pre-processor is generating
--
for(i=0;i< 4 ;i++) {
     	dma0_cr = ({unsigned int rval;
	asm volatile("mfdcr %0," "(0x100 + (8 * (i)))"
		  : "=r" (rval)); rval;}) ;
        ( dma0_cr  =  dma0_cr  |   0x00000008  ) ;
        asm volatile("mtdcr " "(0x100 + (8 * (i)))" ",%0"
		: : "r" (  dma0_cr )) ;
};

Looking at the definition of mtdcr and mfdcr in processor.h
--
#define mfdcr(rn)       ({unsigned int rval; \
                        asm volatile("mfdcr %0," __stringify(rn) \
                                     : "=r" (rval)); rval;})
#define mtdcr(rn, v)    asm volatile("mtdcr " __stringify(rn) ",%0" \
				: : "r" (v))

I was suspicious that the use of __stringify was buggering up my
index parameter. I made a slight tweak to these macros to take
(rn) as a numeric input param.

#define mfdcr(rn)       ({unsigned int rval; \
                        asm volatile("mfdcr %0, %1" \
                                     : "=r" (rval) \
				     : "n" (rn));  \
				rval;})

#define mtdcr(rn, v)    asm volatile("mtdcr %1 ,%0" \
				: : "r" (v), "n" (rn));


Testing this morning so far seems to indicate the new version is
working for me, but my usage is fairly limited. Am I missing
anything ??

Cheers,

--
Bep Verberk
verberk@nortelnetworks.com

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: mtdcr and mfdcr macros
  2003-12-03 15:25 mtdcr and mfdcr macros Verberk, Bep
@ 2003-12-03 17:56 ` Verberk, Bep
  2003-12-03 20:02 ` Eugene Surovegin
  1 sibling, 0 replies; 4+ messages in thread
From: Verberk, Bep @ 2003-12-03 17:56 UTC (permalink / raw)
  To: linuxppc-embedded


I realized soon after I sent this that there are
problems with the  changes I made :(

Any advise on how to use these in a loop, or changes
that would allow them to be used in a loop ?

I'll try a few other ideas....

Cheers,
Bep

On Wed, 3 Dec 2003, Verberk, Bep [CAR:7M00:EXCH] wrote:
>
> I'd like a sanity check on a change I am considering to
> these macros....
>
> I had some difficulty executing these macros
> (found in include/asm/processor.h) in a loop, eg:
>
> #define DMA0_BANKS 	4
> #define DCRN_DMA0_BASE	0x100
> #define DCRN_DMA0_CR(bank)  (DCRN_DMA0_BASE + (8 * (bank)))
>
> 		for(i=0;i<DMA0_BANKS;i++){
> 			dma0_cr = mfdcr(DCRN_DMA0_CR(i));
> 			CLEARBITS(dma0_cr, DMA0_CR_PCE);
> 			mtdcr(DCRN_DMA0_CR(i), dma0_cr);
> 		};
>
> compiling results in the assembler error
> /tmp/cca8HPJ4.s:282: Error: undefined symbol `i' in operation
>
> Compiling with the -E to see what the pre-processor is generating
> --
> for(i=0;i< 4 ;i++) {
>      	dma0_cr = ({unsigned int rval;
> 	asm volatile("mfdcr %0," "(0x100 + (8 * (i)))"
> 		  : "=r" (rval)); rval;}) ;
>         ( dma0_cr  =  dma0_cr  |   0x00000008  ) ;
>         asm volatile("mtdcr " "(0x100 + (8 * (i)))" ",%0"
> 		: : "r" (  dma0_cr )) ;
> };
>
> Looking at the definition of mtdcr and mfdcr in processor.h
> --
> #define mfdcr(rn)       ({unsigned int rval; \
>                         asm volatile("mfdcr %0," __stringify(rn) \
>                                      : "=r" (rval)); rval;})
> #define mtdcr(rn, v)    asm volatile("mtdcr " __stringify(rn) ",%0" \
> 				: : "r" (v))
>
> I was suspicious that the use of __stringify was buggering up my
> index parameter. I made a slight tweak to these macros to take
> (rn) as a numeric input param.
>
> #define mfdcr(rn)       ({unsigned int rval; \
>                         asm volatile("mfdcr %0, %1" \
>                                      : "=r" (rval) \
> 				     : "n" (rn));  \
> 				rval;})
>
> #define mtdcr(rn, v)    asm volatile("mtdcr %1 ,%0" \
> 				: : "r" (v), "n" (rn));
>
> Testing this morning so far seems to indicate the new version is
> working for me, but my usage is fairly limited. Am I missing
> anything ??

--
Bep Verberk
verberk@nortelnetworks.com

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: mtdcr and mfdcr macros
  2003-12-03 15:25 mtdcr and mfdcr macros Verberk, Bep
  2003-12-03 17:56 ` Verberk, Bep
@ 2003-12-03 20:02 ` Eugene Surovegin
  2003-12-04 14:03   ` Verberk, Bep
  1 sibling, 1 reply; 4+ messages in thread
From: Eugene Surovegin @ 2003-12-03 20:02 UTC (permalink / raw)
  To: Verberk, Bep; +Cc: linuxppc-embedded


On Wed, Dec 03, 2003 at 10:25:18AM -0500, Verberk, Bep wrote:
>
> I'd like a sanity check on a change I am considering to
> these macros....
>
> I had some difficulty executing these macros
> (found in include/asm/processor.h) in a loop, eg:
>
> #define DMA0_BANKS 	4
> #define DCRN_DMA0_BASE	0x100
> #define DCRN_DMA0_CR(bank)  (DCRN_DMA0_BASE + (8 * (bank)))
>
> 		for(i=0;i<DMA0_BANKS;i++){
> 			dma0_cr = mfdcr(DCRN_DMA0_CR(i));
> 			CLEARBITS(dma0_cr, DMA0_CR_PCE);
> 			mtdcr(DCRN_DMA0_CR(i), dma0_cr);
> 		};

You cannot use mtdcr/mfdcr with DCR number changed on run-time. These
instructions encode DCR number in their body (look at the instruction
format in any 4xx manual).

And, yes this is major PITA.

The only way (I know) to use dynamic DCR numbers is to have a table
with mfdcr/mtdcr instructions for every possible DCR number and jump
on the correct one depending on supplied DCR number.

Eugene.

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: mtdcr and mfdcr macros
  2003-12-03 20:02 ` Eugene Surovegin
@ 2003-12-04 14:03   ` Verberk, Bep
  0 siblings, 0 replies; 4+ messages in thread
From: Verberk, Bep @ 2003-12-04 14:03 UTC (permalink / raw)
  To: Eugene Surovegin; +Cc: linuxppc-embedded


Ah yes, I see what you're saying. That is a bummer.

Thanks.
Bep

On Wed, 3 Dec 2003, Eugene Surovegin wrote:
>
> On Wed, Dec 03, 2003 at 10:25:18AM -0500, Verberk, Bep wrote:
> >
> > I'd like a sanity check on a change I am considering to these
> > macros....
> >
> > I had some difficulty executing these macros (found in
> > include/asm/processor.h) in a loop, eg:
> >
> > #define DMA0_BANKS 	4
> > #define DCRN_DMA0_BASE	0x100
> > #define DCRN_DMA0_CR(bank)  (DCRN_DMA0_BASE + (8 * (bank)))
> >
> > 		for(i=0;i<DMA0_BANKS;i++){
> > 			dma0_cr = mfdcr(DCRN_DMA0_CR(i));
> > 			CLEARBITS(dma0_cr, DMA0_CR_PCE);
> > 			mtdcr(DCRN_DMA0_CR(i), dma0_cr);
> > 		};
>
> You cannot use mtdcr/mfdcr with DCR number changed on run-time. These
> instructions encode DCR number in their body (look at the instruction
> format in any 4xx manual).
>
> And, yes this is major PITA.
>
> The only way (I know) to use dynamic DCR numbers is to have a table
> with mfdcr/mtdcr instructions for every possible DCR number and jump
> on the correct one depending on supplied DCR number.

--
Bep Verberk
verberk@nortelnetworks.com

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-12-04 14:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-03 15:25 mtdcr and mfdcr macros Verberk, Bep
2003-12-03 17:56 ` Verberk, Bep
2003-12-03 20:02 ` Eugene Surovegin
2003-12-04 14:03   ` Verberk, Bep

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).