linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* PowerPC iotable_init equivalent?
@ 2009-04-17 21:21 Eddie Dawydiuk
  2009-04-17 21:31 ` Roderick Colenbrander
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eddie Dawydiuk @ 2009-04-17 21:21 UTC (permalink / raw)
  To: linuxppc-dev, Grant Likely

Hello,

In the past I've worked with ARM architectures where I could setup virtual / 
physical address mappings so I don't have to ioremap then pass around pointers. 
Does PowerPC have an equivalent abstraction? If not whats the recommended approach?

That is, is there a better approach to the following...

volatile static unsigned char *my_reg = NULL;

static inline void read_func() {

	if (!my_reg)
         	my_reg = (unsigned char *)
			ioremap(REG_PHYS_BASE, REG_SIZE);
//do something with the reg
}


static inline void write_func() {

	if (!my_reg)
         	my_reg = (unsigned char *)
			ioremap(REG_PHYS_BASE, REG_SIZE);
//do something with the reg
}

-- 
Best Regards,
________________________________________________________________
  Eddie Dawydiuk, Technologic Systems | voice:  (480) 837-5200
  16525 East Laser Drive 	     | fax:    (480) 837-5300
  Fountain Hills, AZ 85268            | web: www.embeddedARM.com

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

* Re: PowerPC iotable_init equivalent?
  2009-04-17 21:21 PowerPC iotable_init equivalent? Eddie Dawydiuk
@ 2009-04-17 21:31 ` Roderick Colenbrander
  2009-04-17 21:32 ` Kumar Gala
  2009-04-18  5:42 ` Grant Likely
  2 siblings, 0 replies; 4+ messages in thread
From: Roderick Colenbrander @ 2009-04-17 21:31 UTC (permalink / raw)
  To: Eddie Dawydiuk; +Cc: linuxppc-dev

On Fri, Apr 17, 2009 at 11:21 PM, Eddie Dawydiuk <eddie@embeddedarm.com> wr=
ote:
> Hello,
>
> In the past I've worked with ARM architectures where I could setup virtua=
l /
> physical address mappings so I don't have to ioremap then pass around
> pointers. Does PowerPC have an equivalent abstraction? If not whats the
> recommended approach?
>
> That is, is there a better approach to the following...
>
> volatile static unsigned char *my_reg =3D NULL;
>
> static inline void read_func() {
>
> =A0 =A0 =A0 =A0if (!my_reg)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0my_reg =3D (unsigned char *)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ioremap(REG_PHYS_BASE, REG=
_SIZE);
> //do something with the reg
> }
>
>
> static inline void write_func() {
>
> =A0 =A0 =A0 =A0if (!my_reg)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0my_reg =3D (unsigned char *)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ioremap(REG_PHYS_BASE, REG=
_SIZE);
> //do something with the reg
> }
>
> --
> Best Regards,
> ________________________________________________________________
> =A0Eddie Dawydiuk, Technologic Systems | voice: =A0(480) 837-5200
> =A016525 East Laser Drive =A0 =A0 =A0 =A0 =A0 =A0 =A0| fax: =A0 =A0(480) =
837-5300
> =A0Fountain Hills, AZ 85268 =A0 =A0 =A0 =A0 =A0 =A0| web: www.embeddedARM=
.com
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev
>

In general you set devices up a dts file. You can reach its contents
using openfirmware functions (of_*). In general you use an of_*
function to look up your periperhal in the device tree. Once you have
its node you would able to do e.g. of_iomap (which uses ioremap with
the right offsets behind its back) to map the device. So you don't
hard code physical addresses anymore in the code.

Regards,
Roderick Colenbrander

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

* Re: PowerPC iotable_init equivalent?
  2009-04-17 21:21 PowerPC iotable_init equivalent? Eddie Dawydiuk
  2009-04-17 21:31 ` Roderick Colenbrander
@ 2009-04-17 21:32 ` Kumar Gala
  2009-04-18  5:42 ` Grant Likely
  2 siblings, 0 replies; 4+ messages in thread
From: Kumar Gala @ 2009-04-17 21:32 UTC (permalink / raw)
  To: Eddie Dawydiuk; +Cc: linuxppc-dev


On Apr 17, 2009, at 4:21 PM, Eddie Dawydiuk wrote:

> Hello,
>
> In the past I've worked with ARM architectures where I could setup  
> virtual / physical address mappings so I don't have to ioremap then  
> pass around pointers. Does PowerPC have an equivalent abstraction?  
> If not whats the recommended approach?
>
> That is, is there a better approach to the following...
>
> volatile static unsigned char *my_reg = NULL;
>
> static inline void read_func() {
>
> 	if (!my_reg)
>        	my_reg = (unsigned char *)
> 			ioremap(REG_PHYS_BASE, REG_SIZE);
> //do something with the reg
> }
>
>
> static inline void write_func() {
>
> 	if (!my_reg)
>        	my_reg = (unsigned char *)
> 			ioremap(REG_PHYS_BASE, REG_SIZE);
> //do something with the reg
> }

Yes have a struct that keeps track of the virt addr and do the mapping  
once at init time.  This is what most drivers do.

- k

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

* Re: PowerPC iotable_init equivalent?
  2009-04-17 21:21 PowerPC iotable_init equivalent? Eddie Dawydiuk
  2009-04-17 21:31 ` Roderick Colenbrander
  2009-04-17 21:32 ` Kumar Gala
@ 2009-04-18  5:42 ` Grant Likely
  2 siblings, 0 replies; 4+ messages in thread
From: Grant Likely @ 2009-04-18  5:42 UTC (permalink / raw)
  To: Eddie Dawydiuk; +Cc: linuxppc-dev

On Fri, Apr 17, 2009 at 3:21 PM, Eddie Dawydiuk <eddie@embeddedarm.com> wrote:
> Hello,
>
> In the past I've worked with ARM architectures where I could setup virtual /
> physical address mappings so I don't have to ioremap then pass around
> pointers. Does PowerPC have an equivalent abstraction? If not whats the
> recommended approach?

No.  Predefining virt->phys mappings is fragile since it makes
assumptions about how the kernel is going to carve up the virtual
address space.  Better to let the kernel allocate virtual ranges as it
needs them.

As Kumar says, do your ioremap() (or, even better: of_iomap()) in your
driver's probe function and store it in the driver's private data
structure.

g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

end of thread, other threads:[~2009-04-18  5:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-17 21:21 PowerPC iotable_init equivalent? Eddie Dawydiuk
2009-04-17 21:31 ` Roderick Colenbrander
2009-04-17 21:32 ` Kumar Gala
2009-04-18  5:42 ` Grant Likely

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).