How to access DCR registers in powerpc440gx? Got err when use macro def in Linux kernel

David Gibson david at gibson.dropbear.id.au
Fri Sep 11 15:31:06 EST 2009


On Fri, Sep 11, 2009 at 12:14:55PM +0800, g r1x wrote:
> Now, I'm writing a DMA driver on powerpc
> 440gx platform(2.6.26.5), as the only way to set up DMA Controller is
> to access it's dcr registers with 'mfdcr' and 'mtdcr'.
> 
> I've found some dma code in Linux kernel 2.6.26.5, so I copy the code
> u wrote to my driver module directory, and include them, but when I
> compile my driver, gcc complains following err messages:

[snip]
> #define mfdcr(rn) \
>      ({      \
>              unsigned long rval; \
>              asm volatile("mfdcr %0,%1" : "=r"(rval) : "i"(rn)); \
>              rval; \
>      })

This form of mfdcr macro will only work when passed a constant DCR
number.  That's a limitation in the actual CPU implementation of the
mfdcr instruction (the DCR number is part of the instruction opcode).

Some newer cores have an indirect for of mfdcr which allows the DCR
number to be specified in a register, but I don't know if 440gx is one
of them.

In current kernels we have some DCR macros that use a big table of
pre-generated instructions in order to allow accesses to runtime
computed DCR numbers.  But either they didn't exist in 2.6.26, or they
have a different name, I don't remember.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson


More information about the Linuxppc-dev mailing list