/* MN10300 Non-trivial bit operations1*2* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.3* Written by David Howells ([email protected])4*5* This program is free software; you can redistribute it and/or6* modify it under the terms of the GNU General Public Licence7* as published by the Free Software Foundation; either version8* 2 of the Licence, or (at your option) any later version.9*/10#include <linux/module.h>11#include <asm/bitops.h>12#include <asm/system.h>1314/*15* try flipping a bit using BSET and BCLR16*/17void change_bit(unsigned long nr, volatile void *addr)18{19if (test_bit(nr, addr))20goto try_clear_bit;2122try_set_bit:23if (!test_and_set_bit(nr, addr))24return;2526try_clear_bit:27if (test_and_clear_bit(nr, addr))28return;2930goto try_set_bit;31}3233/*34* try flipping a bit using BSET and BCLR and returning the old value35*/36int test_and_change_bit(unsigned long nr, volatile void *addr)37{38if (test_bit(nr, addr))39goto try_clear_bit;4041try_set_bit:42if (!test_and_set_bit(nr, addr))43return 0;4445try_clear_bit:46if (test_and_clear_bit(nr, addr))47return 1;4849goto try_set_bit;50}515253