linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Using IO functions across ARM, PPC and Microblaze architectures
@ 2012-12-07 19:28 Michal Simek
  2012-12-07 21:16 ` Alan Cox
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Simek @ 2012-12-07 19:28 UTC (permalink / raw)
  To: linux-arch, LKML

Hi,

I would like to get some advices what correct coding style is.

I have one problem with some drivers (uartlite for example)
which are shared across three architectures arm, powerpc and microblaze.

Because I need to use IO functions which will behave
on arm as little endian and on powerpc as big endian
and on microblaze depends on endian setting.
I haven't found any IO function which I could use by 3 architectures
without using preprocessor macros or runtime detection

Please correct me if there is any standard IO function which I could use
for this case.

I was looking at.
readl - make no sense on PowerPC because I need big endian and it is
little there
ioread - is little endian on PPC(ioreadXXbe is big endain)
ioreadXXbe - is always big endian
in_be/in_le - is the same option as ioread/writebe

Using __raw_readl function should be also problematic on ARM
because doesn't prevent reordering or partial accesses.


It means that I should use helper function.

1. Using helper function + preprocessor macros
(using static inline function also possible)

#ifdef __LITTLE_ENDIAN
# define driver_read ioread32
#else
# define driver_read ioread32be
#endif

fce() {
      u32 val = driver_read(..);
}

2. Using function pointers
a) initialization based on preprocesor macros

fce() {
      u32 val;

#ifdef __LITTLE_ENDIAN
      dev_data->read_fn = ioread32
#else
      dev_data->read_fn = ioread32be
#endif

      val = dev_data->read_fn(..);
}

b) Runtime initialization - here is the question if there is
any standard function which I could use.

fce() {
	int num = 1;
	/* run time endian detection */	
	if (*(char *)&num == 1) {
		dev_data->read_fn = ioread32
	else
		dev_data->read_fn = ioread32be

	val = dev_data->read_fn(..);
}

Can you recommend me the best way I should use?

Thanks,
Michal

-- 
Michal Simek, Ing. (M.Eng)
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel 2.6 Microblaze Linux - http://www.monstr.eu/fdt/
Microblaze U-BOOT custodian

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

end of thread, other threads:[~2013-01-30 12:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-07 19:28 Using IO functions across ARM, PPC and Microblaze architectures Michal Simek
2012-12-07 21:16 ` Alan Cox
2012-12-08 10:57   ` Geert Uytterhoeven
2013-01-30 12:33     ` Michal Simek

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