[lkml]   [2020]   [Sep]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH RFC 06/11] media: vidtv: get rid of some endiannes nonsense
Hi Daniel,

Em Mon, 14 Sep 2020 12:14:38 -0300
"Daniel W. S. Almeida" <> escreveu:

> Hi Mauro,
> > Genmask is always highest order to low order. It doesn't make
> > any sense to make it depends on endiannes.
> >
> I added these #ifdefs due to this:
> i.e.
> Fields to access are specified as GENMASK() values - an N-bit field
> starting at bit #M is encoded as GENMASK(M + N - 1, N). Note that
> bit numbers refer to endianness of the object we are working with -
> e.g. GENMASK(11, 0) in __be16 refers to the second byte and the lower
> 4 bits of the first byte. In __le16 it would refer to the first byte
> and the lower 4 bits of the second byte, etc.
> I am not 100% sure, but maybe we actually need them?

By looking at the changes you did with regards to bitfields,
it sounds that you didn't quite get how BE/LE works.

Basically, if the CPU needs to store a value (like 0x8001) on some
place, it will store two values: 0x80 and 0x01. Depending on the
endiannes, either 0x80 or 0x01 will be stored first. See:

In any case, when you do something like:

mask = GENMASK(11, 0);
ret = be16_to_cpu(s->bitfield) & mask;

The be16_to_cpu() will ensure that the bits will be at the
position expected by the CPU endiannes. So, no need to check
for __BIG_ENDIAN or __LITTLE_ENDIAN when be*_to_cpu() macros
are used.

Please also notice that, when there's just one byte to be
stored (e. g. 8 bits), the endiannes won't matter, as the bits
will still be stored at the same way. that's why there's no
be8_to_cpu() or cpu_to_be8() macros.


 \ /
  Last update: 2020-09-15 14:31    [W:0.058 / U:3.880 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site