diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2011-03-23 19:41:58 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-03-23 22:46:13 -0400 |
commit | 3f5527fe7e0fb50556b97b8addbe3832985f793e (patch) | |
tree | c4716151c4db4f436f19e0e6d9de4db3ef2c0308 /arch/m68k | |
parent | f6b57e322f85f9d69db15ca112ee33cab33041b8 (diff) |
m68k: introduce little-endian bitops
Introduce little-endian bit operations by renaming native ext2 bit
operations and changing find_*_bit_le() to take a "void *". The ext2 bit
operations are kept as wrapper macros using little-endian bit operations
to maintain bisectability until the conversions are finished.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Roman Zippel <zippel@linux-m68k.org>
Cc: Andreas Schwab <schwab@linux-m68k.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/m68k')
-rw-r--r-- | arch/m68k/include/asm/bitops_mm.h | 93 |
1 files changed, 67 insertions, 26 deletions
diff --git a/arch/m68k/include/asm/bitops_mm.h b/arch/m68k/include/asm/bitops_mm.h index 31a16d47d205..d4658487defd 100644 --- a/arch/m68k/include/asm/bitops_mm.h +++ b/arch/m68k/include/asm/bitops_mm.h | |||
@@ -359,24 +359,45 @@ static inline int minix_test_bit(int nr, const void *vaddr) | |||
359 | return (p[nr >> 4] & (1U << (nr & 15))) != 0; | 359 | return (p[nr >> 4] & (1U << (nr & 15))) != 0; |
360 | } | 360 | } |
361 | 361 | ||
362 | /* Bitmap functions for the ext2 filesystem. */ | 362 | /* Bitmap functions for the little endian bitmap. */ |
363 | |||
364 | static inline void __set_bit_le(int nr, void *addr) | ||
365 | { | ||
366 | __set_bit(nr ^ 24, addr); | ||
367 | } | ||
363 | 368 | ||
364 | #define ext2_set_bit(nr, addr) __test_and_set_bit((nr) ^ 24, (unsigned long *)(addr)) | 369 | static inline void __clear_bit_le(int nr, void *addr) |
365 | #define ext2_set_bit_atomic(lock, nr, addr) test_and_set_bit((nr) ^ 24, (unsigned long *)(addr)) | 370 | { |
366 | #define ext2_clear_bit(nr, addr) __test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr)) | 371 | __clear_bit(nr ^ 24, addr); |
367 | #define ext2_clear_bit_atomic(lock, nr, addr) test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr)) | 372 | } |
368 | #define ext2_find_next_zero_bit(addr, size, offset) \ | 373 | |
369 | find_next_zero_bit_le((unsigned long *)addr, size, offset) | 374 | static inline int __test_and_set_bit_le(int nr, void *addr) |
370 | #define ext2_find_next_bit(addr, size, offset) \ | 375 | { |
371 | find_next_bit_le((unsigned long *)addr, size, offset) | 376 | return __test_and_set_bit(nr ^ 24, addr); |
377 | } | ||
378 | |||
379 | static inline int test_and_set_bit_le(int nr, void *addr) | ||
380 | { | ||
381 | return test_and_set_bit(nr ^ 24, addr); | ||
382 | } | ||
383 | |||
384 | static inline int __test_and_clear_bit_le(int nr, void *addr) | ||
385 | { | ||
386 | return __test_and_clear_bit(nr ^ 24, addr); | ||
387 | } | ||
372 | 388 | ||
373 | static inline int ext2_test_bit(int nr, const void *vaddr) | 389 | static inline int test_and_clear_bit_le(int nr, void *addr) |
390 | { | ||
391 | return test_and_clear_bit(nr ^ 24, addr); | ||
392 | } | ||
393 | |||
394 | static inline int test_bit_le(int nr, const void *vaddr) | ||
374 | { | 395 | { |
375 | const unsigned char *p = vaddr; | 396 | const unsigned char *p = vaddr; |
376 | return (p[nr >> 3] & (1U << (nr & 7))) != 0; | 397 | return (p[nr >> 3] & (1U << (nr & 7))) != 0; |
377 | } | 398 | } |
378 | 399 | ||
379 | static inline int ext2_find_first_zero_bit(const void *vaddr, unsigned size) | 400 | static inline int find_first_zero_bit_le(const void *vaddr, unsigned size) |
380 | { | 401 | { |
381 | const unsigned long *p = vaddr, *addr = vaddr; | 402 | const unsigned long *p = vaddr, *addr = vaddr; |
382 | int res; | 403 | int res; |
@@ -393,33 +414,36 @@ static inline int ext2_find_first_zero_bit(const void *vaddr, unsigned size) | |||
393 | 414 | ||
394 | --p; | 415 | --p; |
395 | for (res = 0; res < 32; res++) | 416 | for (res = 0; res < 32; res++) |
396 | if (!ext2_test_bit (res, p)) | 417 | if (!test_bit_le(res, p)) |
397 | break; | 418 | break; |
398 | return (p - addr) * 32 + res; | 419 | return (p - addr) * 32 + res; |
399 | } | 420 | } |
400 | 421 | ||
401 | static inline unsigned long find_next_zero_bit_le(const unsigned long *addr, | 422 | static inline unsigned long find_next_zero_bit_le(const void *addr, |
402 | unsigned long size, unsigned long offset) | 423 | unsigned long size, unsigned long offset) |
403 | { | 424 | { |
404 | const unsigned long *p = addr + (offset >> 5); | 425 | const unsigned long *p = addr; |
405 | int bit = offset & 31UL, res; | 426 | int bit = offset & 31UL, res; |
406 | 427 | ||
407 | if (offset >= size) | 428 | if (offset >= size) |
408 | return size; | 429 | return size; |
409 | 430 | ||
431 | p += offset >> 5; | ||
432 | |||
410 | if (bit) { | 433 | if (bit) { |
434 | offset -= bit; | ||
411 | /* Look for zero in first longword */ | 435 | /* Look for zero in first longword */ |
412 | for (res = bit; res < 32; res++) | 436 | for (res = bit; res < 32; res++) |
413 | if (!ext2_test_bit (res, p)) | 437 | if (!test_bit_le(res, p)) |
414 | return (p - addr) * 32 + res; | 438 | return offset + res; |
415 | p++; | 439 | p++; |
440 | offset += 32; | ||
416 | } | 441 | } |
417 | /* No zero yet, search remaining full bytes for a zero */ | 442 | /* No zero yet, search remaining full bytes for a zero */ |
418 | res = ext2_find_first_zero_bit (p, size - 32 * (p - addr)); | 443 | return offset + find_first_zero_bit_le(p, size - offset); |
419 | return (p - addr) * 32 + res; | ||
420 | } | 444 | } |
421 | 445 | ||
422 | static inline int ext2_find_first_bit(const void *vaddr, unsigned size) | 446 | static inline int find_first_bit_le(const void *vaddr, unsigned size) |
423 | { | 447 | { |
424 | const unsigned long *p = vaddr, *addr = vaddr; | 448 | const unsigned long *p = vaddr, *addr = vaddr; |
425 | int res; | 449 | int res; |
@@ -435,32 +459,49 @@ static inline int ext2_find_first_bit(const void *vaddr, unsigned size) | |||
435 | 459 | ||
436 | --p; | 460 | --p; |
437 | for (res = 0; res < 32; res++) | 461 | for (res = 0; res < 32; res++) |
438 | if (ext2_test_bit(res, p)) | 462 | if (test_bit_le(res, p)) |
439 | break; | 463 | break; |
440 | return (p - addr) * 32 + res; | 464 | return (p - addr) * 32 + res; |
441 | } | 465 | } |
442 | 466 | ||
443 | static inline unsigned long find_next_bit_le(const unsigned long *addr, | 467 | static inline unsigned long find_next_bit_le(const void *addr, |
444 | unsigned long size, unsigned long offset) | 468 | unsigned long size, unsigned long offset) |
445 | { | 469 | { |
446 | const unsigned long *p = addr + (offset >> 5); | 470 | const unsigned long *p = addr; |
447 | int bit = offset & 31UL, res; | 471 | int bit = offset & 31UL, res; |
448 | 472 | ||
449 | if (offset >= size) | 473 | if (offset >= size) |
450 | return size; | 474 | return size; |
451 | 475 | ||
476 | p += offset >> 5; | ||
477 | |||
452 | if (bit) { | 478 | if (bit) { |
479 | offset -= bit; | ||
453 | /* Look for one in first longword */ | 480 | /* Look for one in first longword */ |
454 | for (res = bit; res < 32; res++) | 481 | for (res = bit; res < 32; res++) |
455 | if (ext2_test_bit(res, p)) | 482 | if (test_bit_le(res, p)) |
456 | return (p - addr) * 32 + res; | 483 | return offset + res; |
457 | p++; | 484 | p++; |
485 | offset += 32; | ||
458 | } | 486 | } |
459 | /* No set bit yet, search remaining full bytes for a set bit */ | 487 | /* No set bit yet, search remaining full bytes for a set bit */ |
460 | res = ext2_find_first_bit(p, size - 32 * (p - addr)); | 488 | return offset + find_first_bit_le(p, size - offset); |
461 | return (p - addr) * 32 + res; | ||
462 | } | 489 | } |
463 | 490 | ||
491 | /* Bitmap functions for the ext2 filesystem. */ | ||
492 | |||
493 | #define ext2_set_bit __test_and_set_bit_le | ||
494 | #define ext2_set_bit_atomic(lock, nr, addr) \ | ||
495 | test_and_set_bit_le(nr, addr) | ||
496 | #define ext2_clear_bit __test_and_clear_bit_le | ||
497 | #define ext2_clear_bit_atomic(lock, nr, addr) \ | ||
498 | test_and_clear_bit_le(nr, addr) | ||
499 | #define ext2_find_next_zero_bit find_next_zero_bit_le | ||
500 | #define ext2_find_next_bit find_next_bit_le | ||
501 | #define ext2_test_bit test_bit_le | ||
502 | #define ext2_find_first_zero_bit find_first_zero_bit_le | ||
503 | #define ext2_find_first_bit find_first_bit_le | ||
504 | |||
464 | #endif /* __KERNEL__ */ | 505 | #endif /* __KERNEL__ */ |
465 | 506 | ||
466 | #endif /* _M68K_BITOPS_H */ | 507 | #endif /* _M68K_BITOPS_H */ |