Using IO functions across ARM, PPC and Microblaze architectures

From: Michal Simek
Date: Fri Dec 07 2012 - 14:27:57 EST


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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/