* Re: [PATCH v10 4/4] gpio: xilinx: Utilize generic bitmap_get_value and _set_value
@ 2020-10-03 3:13 kernel test robot
0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2020-10-03 3:13 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 8977 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <e1753313c18ebb233bce1b1b48749858e5402235.1601679792.git.syednwaris@gmail.com>
References: <e1753313c18ebb233bce1b1b48749858e5402235.1601679792.git.syednwaris@gmail.com>
TO: Syed Nayyar Waris <syednwaris@gmail.com>
Hi Syed,
I love your patch! Perhaps something to improve:
[auto build test WARNING on 9123e3a74ec7b934a4a099e98af6a61c2f80bbf5]
url: https://github.com/0day-ci/linux/commits/Syed-Nayyar-Waris/Introduce-the-for_each_set_clump-macro/20201003-075413
base: 9123e3a74ec7b934a4a099e98af6a61c2f80bbf5
:::::: branch date: 3 hours ago
:::::: commit date: 3 hours ago
config: arm64-randconfig-s031-20201002 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.2-201-g24bdaac6-dirty
# https://github.com/0day-ci/linux/commit/d8b00c69c075459dadbdbcd8966b5b885a08a1bd
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Syed-Nayyar-Waris/Introduce-the-for_each_set_clump-macro/20201003-075413
git checkout d8b00c69c075459dadbdbcd8966b5b885a08a1bd
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
echo
echo "sparse warnings: (new ones prefixed by >>)"
echo
drivers/gpio/gpio-xilinx.c: note: in included file (through include/linux/cpumask.h, include/linux/smp.h, arch/arm64/include/asm/arch_timer.h, ...):
>> include/linux/bitmap.h:593:30: sparse: sparse: invalid access past the end of 'new' (8 8)
>> include/linux/bitmap.h:638:17: sparse: sparse: invalid access past the end of 'old' (8 8)
>> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long
include/linux/bitmap.h:594:63: sparse: sparse: shift too big (64) for type unsigned long
vim +/new +593 include/linux/bitmap.h
169c474fb22d8a5 William Breathitt Gray 2019-12-04 569
66845ead81685a8 Syed Nayyar Waris 2020-10-03 570 /**
66845ead81685a8 Syed Nayyar Waris 2020-10-03 571 * bitmap_get_value - get a value of n-bits from the memory region
66845ead81685a8 Syed Nayyar Waris 2020-10-03 572 * @map: address to the bitmap memory region
66845ead81685a8 Syed Nayyar Waris 2020-10-03 573 * @start: bit offset of the n-bit value
66845ead81685a8 Syed Nayyar Waris 2020-10-03 574 * @nbits: size of value in bits
66845ead81685a8 Syed Nayyar Waris 2020-10-03 575 *
66845ead81685a8 Syed Nayyar Waris 2020-10-03 576 * Returns value of nbits located at the @start bit offset within the @map
66845ead81685a8 Syed Nayyar Waris 2020-10-03 577 * memory region.
66845ead81685a8 Syed Nayyar Waris 2020-10-03 578 */
66845ead81685a8 Syed Nayyar Waris 2020-10-03 579 static inline unsigned long bitmap_get_value(const unsigned long *map,
66845ead81685a8 Syed Nayyar Waris 2020-10-03 580 unsigned long start,
66845ead81685a8 Syed Nayyar Waris 2020-10-03 581 unsigned long nbits)
66845ead81685a8 Syed Nayyar Waris 2020-10-03 582 {
66845ead81685a8 Syed Nayyar Waris 2020-10-03 583 const size_t index = BIT_WORD(start);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 584 const unsigned long offset = start % BITS_PER_LONG;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 585 const unsigned long ceiling = roundup(start + 1, BITS_PER_LONG);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 586 const unsigned long space = ceiling - start;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 587 unsigned long value_low, value_high;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 588
66845ead81685a8 Syed Nayyar Waris 2020-10-03 589 if (space >= nbits)
66845ead81685a8 Syed Nayyar Waris 2020-10-03 590 return (map[index] >> offset) & GENMASK(nbits - 1, 0);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 591 else {
66845ead81685a8 Syed Nayyar Waris 2020-10-03 592 value_low = map[index] & BITMAP_FIRST_WORD_MASK(start);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 @593 value_high = map[index + 1] & BITMAP_LAST_WORD_MASK(start + nbits);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 594 return (value_low >> offset) | (value_high << space);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 595 }
66845ead81685a8 Syed Nayyar Waris 2020-10-03 596 }
66845ead81685a8 Syed Nayyar Waris 2020-10-03 597
169c474fb22d8a5 William Breathitt Gray 2019-12-04 598 /**
169c474fb22d8a5 William Breathitt Gray 2019-12-04 599 * bitmap_set_value8 - set an 8-bit value within a memory region
169c474fb22d8a5 William Breathitt Gray 2019-12-04 600 * @map: address to the bitmap memory region
169c474fb22d8a5 William Breathitt Gray 2019-12-04 601 * @value: the 8-bit value; values wider than 8 bits may clobber bitmap
169c474fb22d8a5 William Breathitt Gray 2019-12-04 602 * @start: bit offset of the 8-bit value; must be a multiple of 8
169c474fb22d8a5 William Breathitt Gray 2019-12-04 603 */
169c474fb22d8a5 William Breathitt Gray 2019-12-04 604 static inline void bitmap_set_value8(unsigned long *map, unsigned long value,
169c474fb22d8a5 William Breathitt Gray 2019-12-04 605 unsigned long start)
169c474fb22d8a5 William Breathitt Gray 2019-12-04 606 {
169c474fb22d8a5 William Breathitt Gray 2019-12-04 607 const size_t index = BIT_WORD(start);
169c474fb22d8a5 William Breathitt Gray 2019-12-04 608 const unsigned long offset = start % BITS_PER_LONG;
169c474fb22d8a5 William Breathitt Gray 2019-12-04 609
169c474fb22d8a5 William Breathitt Gray 2019-12-04 610 map[index] &= ~(0xFFUL << offset);
169c474fb22d8a5 William Breathitt Gray 2019-12-04 611 map[index] |= value << offset;
169c474fb22d8a5 William Breathitt Gray 2019-12-04 612 }
169c474fb22d8a5 William Breathitt Gray 2019-12-04 613
66845ead81685a8 Syed Nayyar Waris 2020-10-03 614 /**
66845ead81685a8 Syed Nayyar Waris 2020-10-03 615 * bitmap_set_value - set n-bit value within a memory region
66845ead81685a8 Syed Nayyar Waris 2020-10-03 616 * @map: address to the bitmap memory region
66845ead81685a8 Syed Nayyar Waris 2020-10-03 617 * @value: value of nbits
66845ead81685a8 Syed Nayyar Waris 2020-10-03 618 * @start: bit offset of the n-bit value
66845ead81685a8 Syed Nayyar Waris 2020-10-03 619 * @nbits: size of value in bits
66845ead81685a8 Syed Nayyar Waris 2020-10-03 620 */
66845ead81685a8 Syed Nayyar Waris 2020-10-03 621 static inline void bitmap_set_value(unsigned long *map,
66845ead81685a8 Syed Nayyar Waris 2020-10-03 622 unsigned long value,
66845ead81685a8 Syed Nayyar Waris 2020-10-03 623 unsigned long start, unsigned long nbits)
66845ead81685a8 Syed Nayyar Waris 2020-10-03 624 {
66845ead81685a8 Syed Nayyar Waris 2020-10-03 625 const size_t index = BIT_WORD(start);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 626 const unsigned long offset = start % BITS_PER_LONG;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 627 const unsigned long ceiling = roundup(start + 1, BITS_PER_LONG);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 628 const unsigned long space = ceiling - start;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 629
66845ead81685a8 Syed Nayyar Waris 2020-10-03 630 value &= GENMASK(nbits - 1, 0);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 631
66845ead81685a8 Syed Nayyar Waris 2020-10-03 632 if (space >= nbits) {
66845ead81685a8 Syed Nayyar Waris 2020-10-03 633 map[index] &= ~(GENMASK(nbits + offset - 1, offset));
66845ead81685a8 Syed Nayyar Waris 2020-10-03 634 map[index] |= value << offset;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 635 } else {
66845ead81685a8 Syed Nayyar Waris 2020-10-03 636 map[index] &= ~BITMAP_FIRST_WORD_MASK(start);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 637 map[index] |= value << offset;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 @638 map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 @639 map[index + 1] |= (value >> space);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 640 }
66845ead81685a8 Syed Nayyar Waris 2020-10-03 641 }
66845ead81685a8 Syed Nayyar Waris 2020-10-03 642
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 36623 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v10 4/4] gpio: xilinx: Utilize generic bitmap_get_value and _set_value
2020-10-02 23:52 ` Syed Nayyar Waris
(?)
@ 2020-10-09 13:36 ` kernel test robot
-1 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2020-10-09 13:36 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 8713 bytes --]
Hi Syed,
I love your patch! Perhaps something to improve:
[auto build test WARNING on 9123e3a74ec7b934a4a099e98af6a61c2f80bbf5]
url: https://github.com/0day-ci/linux/commits/Syed-Nayyar-Waris/Introduce-the-for_each_set_clump-macro/20201003-075413
base: 9123e3a74ec7b934a4a099e98af6a61c2f80bbf5
:::::: branch date: 3 hours ago
:::::: commit date: 3 hours ago
config: arm64-randconfig-s031-20201002 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.2-201-g24bdaac6-dirty
# https://github.com/0day-ci/linux/commit/d8b00c69c075459dadbdbcd8966b5b885a08a1bd
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Syed-Nayyar-Waris/Introduce-the-for_each_set_clump-macro/20201003-075413
git checkout d8b00c69c075459dadbdbcd8966b5b885a08a1bd
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
echo
echo "sparse warnings: (new ones prefixed by >>)"
echo
drivers/gpio/gpio-xilinx.c: note: in included file (through include/linux/cpumask.h, include/linux/smp.h, arch/arm64/include/asm/arch_timer.h, ...):
>> include/linux/bitmap.h:593:30: sparse: sparse: invalid access past the end of 'new' (8 8)
>> include/linux/bitmap.h:638:17: sparse: sparse: invalid access past the end of 'old' (8 8)
>> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long
include/linux/bitmap.h:594:63: sparse: sparse: shift too big (64) for type unsigned long
vim +/new +593 include/linux/bitmap.h
169c474fb22d8a5 William Breathitt Gray 2019-12-04 569
66845ead81685a8 Syed Nayyar Waris 2020-10-03 570 /**
66845ead81685a8 Syed Nayyar Waris 2020-10-03 571 * bitmap_get_value - get a value of n-bits from the memory region
66845ead81685a8 Syed Nayyar Waris 2020-10-03 572 * @map: address to the bitmap memory region
66845ead81685a8 Syed Nayyar Waris 2020-10-03 573 * @start: bit offset of the n-bit value
66845ead81685a8 Syed Nayyar Waris 2020-10-03 574 * @nbits: size of value in bits
66845ead81685a8 Syed Nayyar Waris 2020-10-03 575 *
66845ead81685a8 Syed Nayyar Waris 2020-10-03 576 * Returns value of nbits located at the @start bit offset within the @map
66845ead81685a8 Syed Nayyar Waris 2020-10-03 577 * memory region.
66845ead81685a8 Syed Nayyar Waris 2020-10-03 578 */
66845ead81685a8 Syed Nayyar Waris 2020-10-03 579 static inline unsigned long bitmap_get_value(const unsigned long *map,
66845ead81685a8 Syed Nayyar Waris 2020-10-03 580 unsigned long start,
66845ead81685a8 Syed Nayyar Waris 2020-10-03 581 unsigned long nbits)
66845ead81685a8 Syed Nayyar Waris 2020-10-03 582 {
66845ead81685a8 Syed Nayyar Waris 2020-10-03 583 const size_t index = BIT_WORD(start);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 584 const unsigned long offset = start % BITS_PER_LONG;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 585 const unsigned long ceiling = roundup(start + 1, BITS_PER_LONG);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 586 const unsigned long space = ceiling - start;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 587 unsigned long value_low, value_high;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 588
66845ead81685a8 Syed Nayyar Waris 2020-10-03 589 if (space >= nbits)
66845ead81685a8 Syed Nayyar Waris 2020-10-03 590 return (map[index] >> offset) & GENMASK(nbits - 1, 0);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 591 else {
66845ead81685a8 Syed Nayyar Waris 2020-10-03 592 value_low = map[index] & BITMAP_FIRST_WORD_MASK(start);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 @593 value_high = map[index + 1] & BITMAP_LAST_WORD_MASK(start + nbits);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 594 return (value_low >> offset) | (value_high << space);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 595 }
66845ead81685a8 Syed Nayyar Waris 2020-10-03 596 }
66845ead81685a8 Syed Nayyar Waris 2020-10-03 597
169c474fb22d8a5 William Breathitt Gray 2019-12-04 598 /**
169c474fb22d8a5 William Breathitt Gray 2019-12-04 599 * bitmap_set_value8 - set an 8-bit value within a memory region
169c474fb22d8a5 William Breathitt Gray 2019-12-04 600 * @map: address to the bitmap memory region
169c474fb22d8a5 William Breathitt Gray 2019-12-04 601 * @value: the 8-bit value; values wider than 8 bits may clobber bitmap
169c474fb22d8a5 William Breathitt Gray 2019-12-04 602 * @start: bit offset of the 8-bit value; must be a multiple of 8
169c474fb22d8a5 William Breathitt Gray 2019-12-04 603 */
169c474fb22d8a5 William Breathitt Gray 2019-12-04 604 static inline void bitmap_set_value8(unsigned long *map, unsigned long value,
169c474fb22d8a5 William Breathitt Gray 2019-12-04 605 unsigned long start)
169c474fb22d8a5 William Breathitt Gray 2019-12-04 606 {
169c474fb22d8a5 William Breathitt Gray 2019-12-04 607 const size_t index = BIT_WORD(start);
169c474fb22d8a5 William Breathitt Gray 2019-12-04 608 const unsigned long offset = start % BITS_PER_LONG;
169c474fb22d8a5 William Breathitt Gray 2019-12-04 609
169c474fb22d8a5 William Breathitt Gray 2019-12-04 610 map[index] &= ~(0xFFUL << offset);
169c474fb22d8a5 William Breathitt Gray 2019-12-04 611 map[index] |= value << offset;
169c474fb22d8a5 William Breathitt Gray 2019-12-04 612 }
169c474fb22d8a5 William Breathitt Gray 2019-12-04 613
66845ead81685a8 Syed Nayyar Waris 2020-10-03 614 /**
66845ead81685a8 Syed Nayyar Waris 2020-10-03 615 * bitmap_set_value - set n-bit value within a memory region
66845ead81685a8 Syed Nayyar Waris 2020-10-03 616 * @map: address to the bitmap memory region
66845ead81685a8 Syed Nayyar Waris 2020-10-03 617 * @value: value of nbits
66845ead81685a8 Syed Nayyar Waris 2020-10-03 618 * @start: bit offset of the n-bit value
66845ead81685a8 Syed Nayyar Waris 2020-10-03 619 * @nbits: size of value in bits
66845ead81685a8 Syed Nayyar Waris 2020-10-03 620 */
66845ead81685a8 Syed Nayyar Waris 2020-10-03 621 static inline void bitmap_set_value(unsigned long *map,
66845ead81685a8 Syed Nayyar Waris 2020-10-03 622 unsigned long value,
66845ead81685a8 Syed Nayyar Waris 2020-10-03 623 unsigned long start, unsigned long nbits)
66845ead81685a8 Syed Nayyar Waris 2020-10-03 624 {
66845ead81685a8 Syed Nayyar Waris 2020-10-03 625 const size_t index = BIT_WORD(start);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 626 const unsigned long offset = start % BITS_PER_LONG;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 627 const unsigned long ceiling = roundup(start + 1, BITS_PER_LONG);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 628 const unsigned long space = ceiling - start;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 629
66845ead81685a8 Syed Nayyar Waris 2020-10-03 630 value &= GENMASK(nbits - 1, 0);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 631
66845ead81685a8 Syed Nayyar Waris 2020-10-03 632 if (space >= nbits) {
66845ead81685a8 Syed Nayyar Waris 2020-10-03 633 map[index] &= ~(GENMASK(nbits + offset - 1, offset));
66845ead81685a8 Syed Nayyar Waris 2020-10-03 634 map[index] |= value << offset;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 635 } else {
66845ead81685a8 Syed Nayyar Waris 2020-10-03 636 map[index] &= ~BITMAP_FIRST_WORD_MASK(start);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 637 map[index] |= value << offset;
66845ead81685a8 Syed Nayyar Waris 2020-10-03 @638 map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 @639 map[index + 1] |= (value >> space);
66845ead81685a8 Syed Nayyar Waris 2020-10-03 640 }
66845ead81685a8 Syed Nayyar Waris 2020-10-03 641 }
66845ead81685a8 Syed Nayyar Waris 2020-10-03 642
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 36623 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v10 4/4] gpio: xilinx: Utilize generic bitmap_get_value and _set_value
2020-10-02 23:47 [PATCH v10 0/4] Introduce the for_each_set_clump macro Syed Nayyar Waris
@ 2020-10-02 23:52 ` Syed Nayyar Waris
0 siblings, 0 replies; 4+ messages in thread
From: Syed Nayyar Waris @ 2020-10-02 23:52 UTC (permalink / raw)
To: linus.walleij, akpm
Cc: andriy.shevchenko, vilhelm.gray, bgolaszewski, michal.simek,
linux-gpio, linux-arm-kernel, linux-kernel
This patch reimplements the xgpio_set_multiple function in
drivers/gpio/gpio-xilinx.c to use the new generic functions:
bitmap_get_value and bitmap_set_value. The code is now simpler
to read and understand. Moreover, instead of looping for each bit
in xgpio_set_multiple function, now we can check each channel at
a time and save cycles.
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Syed Nayyar Waris <syednwaris@gmail.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
---
Changes in v10:
- No change.
Changes in v9:
- Remove looping of 'for_each_set_clump' and instead process two
halves of a 64-bit bitmap separately or individually. Use normal spin_lock
call for second inner lock. And take the spin_lock_init call outside the 'if'
condition in the 'probe' function of driver.
Changes in v8:
- No change.
Changes in v7:
- No change.
Changes in v6:
- No change.
Changes in v5:
- Minor change: Inline values '32' and '64' in code for better
code readability.
Changes in v4:
- Minor change: Inline values '32' and '64' in code for better
code readability.
Changes in v3:
- No change.
Changes in v2:
- No change
drivers/gpio/gpio-xilinx.c | 66 +++++++++++++++++++-------------------
1 file changed, 33 insertions(+), 33 deletions(-)
diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index 67f9f82e0db0..48393d06fb55 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -136,39 +136,39 @@ static void xgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
unsigned long *bits)
{
- unsigned long flags;
+ unsigned long flag;
struct xgpio_instance *chip = gpiochip_get_data(gc);
- int index = xgpio_index(chip, 0);
- int offset, i;
-
- spin_lock_irqsave(&chip->gpio_lock[index], flags);
-
- /* Write to GPIO signals */
- for (i = 0; i < gc->ngpio; i++) {
- if (*mask == 0)
- break;
- /* Once finished with an index write it out to the register */
- if (index != xgpio_index(chip, i)) {
- xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
- index * XGPIO_CHANNEL_OFFSET,
- chip->gpio_state[index]);
- spin_unlock_irqrestore(&chip->gpio_lock[index], flags);
- index = xgpio_index(chip, i);
- spin_lock_irqsave(&chip->gpio_lock[index], flags);
- }
- if (__test_and_clear_bit(i, mask)) {
- offset = xgpio_offset(chip, i);
- if (test_bit(i, bits))
- chip->gpio_state[index] |= BIT(offset);
- else
- chip->gpio_state[index] &= ~BIT(offset);
- }
- }
-
- xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
- index * XGPIO_CHANNEL_OFFSET, chip->gpio_state[index]);
-
- spin_unlock_irqrestore(&chip->gpio_lock[index], flags);
+ u32 *const state = chip->gpio_state;
+ unsigned int *const width = chip->gpio_width;
+
+ DECLARE_BITMAP(old, 64);
+ DECLARE_BITMAP(new, 64);
+ DECLARE_BITMAP(changed, 64);
+
+ spin_lock_irqsave(&chip->gpio_lock[0], flag);
+ spin_lock(&chip->gpio_lock[1]);
+
+ bitmap_set_value(old, state[0], 0, width[0]);
+ bitmap_set_value(old, state[1], width[0], width[1]);
+ bitmap_replace(new, old, bits, mask, gc->ngpio);
+
+ bitmap_set_value(old, state[0], 0, 32);
+ bitmap_set_value(old, state[1], 32, 32);
+ state[0] = bitmap_get_value(new, 0, width[0]);
+ state[1] = bitmap_get_value(new, width[0], width[1]);
+ bitmap_set_value(new, state[0], 0, 32);
+ bitmap_set_value(new, state[1], 32, 32);
+ bitmap_xor(changed, old, new, 64);
+
+ if (((u32 *)changed)[0])
+ xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET,
+ state[0]);
+ if (((u32 *)changed)[1])
+ xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
+ XGPIO_CHANNEL_OFFSET, state[1]);
+
+ spin_unlock(&chip->gpio_lock[1]);
+ spin_unlock_irqrestore(&chip->gpio_lock[0], flag);
}
/**
@@ -292,6 +292,7 @@ static int xgpio_probe(struct platform_device *pdev)
chip->gpio_width[0] = 32;
spin_lock_init(&chip->gpio_lock[0]);
+ spin_lock_init(&chip->gpio_lock[1]);
if (of_property_read_u32(np, "xlnx,is-dual", &is_dual))
is_dual = 0;
@@ -314,7 +315,6 @@ static int xgpio_probe(struct platform_device *pdev)
&chip->gpio_width[1]))
chip->gpio_width[1] = 32;
- spin_lock_init(&chip->gpio_lock[1]);
}
chip->gc.base = -1;
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v10 4/4] gpio: xilinx: Utilize generic bitmap_get_value and _set_value
@ 2020-10-02 23:52 ` Syed Nayyar Waris
0 siblings, 0 replies; 4+ messages in thread
From: Syed Nayyar Waris @ 2020-10-02 23:52 UTC (permalink / raw)
To: linus.walleij, akpm
Cc: linux-gpio, linux-kernel, vilhelm.gray, michal.simek,
bgolaszewski, andriy.shevchenko, linux-arm-kernel
This patch reimplements the xgpio_set_multiple function in
drivers/gpio/gpio-xilinx.c to use the new generic functions:
bitmap_get_value and bitmap_set_value. The code is now simpler
to read and understand. Moreover, instead of looping for each bit
in xgpio_set_multiple function, now we can check each channel at
a time and save cycles.
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Syed Nayyar Waris <syednwaris@gmail.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
---
Changes in v10:
- No change.
Changes in v9:
- Remove looping of 'for_each_set_clump' and instead process two
halves of a 64-bit bitmap separately or individually. Use normal spin_lock
call for second inner lock. And take the spin_lock_init call outside the 'if'
condition in the 'probe' function of driver.
Changes in v8:
- No change.
Changes in v7:
- No change.
Changes in v6:
- No change.
Changes in v5:
- Minor change: Inline values '32' and '64' in code for better
code readability.
Changes in v4:
- Minor change: Inline values '32' and '64' in code for better
code readability.
Changes in v3:
- No change.
Changes in v2:
- No change
drivers/gpio/gpio-xilinx.c | 66 +++++++++++++++++++-------------------
1 file changed, 33 insertions(+), 33 deletions(-)
diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index 67f9f82e0db0..48393d06fb55 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -136,39 +136,39 @@ static void xgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
unsigned long *bits)
{
- unsigned long flags;
+ unsigned long flag;
struct xgpio_instance *chip = gpiochip_get_data(gc);
- int index = xgpio_index(chip, 0);
- int offset, i;
-
- spin_lock_irqsave(&chip->gpio_lock[index], flags);
-
- /* Write to GPIO signals */
- for (i = 0; i < gc->ngpio; i++) {
- if (*mask == 0)
- break;
- /* Once finished with an index write it out to the register */
- if (index != xgpio_index(chip, i)) {
- xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
- index * XGPIO_CHANNEL_OFFSET,
- chip->gpio_state[index]);
- spin_unlock_irqrestore(&chip->gpio_lock[index], flags);
- index = xgpio_index(chip, i);
- spin_lock_irqsave(&chip->gpio_lock[index], flags);
- }
- if (__test_and_clear_bit(i, mask)) {
- offset = xgpio_offset(chip, i);
- if (test_bit(i, bits))
- chip->gpio_state[index] |= BIT(offset);
- else
- chip->gpio_state[index] &= ~BIT(offset);
- }
- }
-
- xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
- index * XGPIO_CHANNEL_OFFSET, chip->gpio_state[index]);
-
- spin_unlock_irqrestore(&chip->gpio_lock[index], flags);
+ u32 *const state = chip->gpio_state;
+ unsigned int *const width = chip->gpio_width;
+
+ DECLARE_BITMAP(old, 64);
+ DECLARE_BITMAP(new, 64);
+ DECLARE_BITMAP(changed, 64);
+
+ spin_lock_irqsave(&chip->gpio_lock[0], flag);
+ spin_lock(&chip->gpio_lock[1]);
+
+ bitmap_set_value(old, state[0], 0, width[0]);
+ bitmap_set_value(old, state[1], width[0], width[1]);
+ bitmap_replace(new, old, bits, mask, gc->ngpio);
+
+ bitmap_set_value(old, state[0], 0, 32);
+ bitmap_set_value(old, state[1], 32, 32);
+ state[0] = bitmap_get_value(new, 0, width[0]);
+ state[1] = bitmap_get_value(new, width[0], width[1]);
+ bitmap_set_value(new, state[0], 0, 32);
+ bitmap_set_value(new, state[1], 32, 32);
+ bitmap_xor(changed, old, new, 64);
+
+ if (((u32 *)changed)[0])
+ xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET,
+ state[0]);
+ if (((u32 *)changed)[1])
+ xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
+ XGPIO_CHANNEL_OFFSET, state[1]);
+
+ spin_unlock(&chip->gpio_lock[1]);
+ spin_unlock_irqrestore(&chip->gpio_lock[0], flag);
}
/**
@@ -292,6 +292,7 @@ static int xgpio_probe(struct platform_device *pdev)
chip->gpio_width[0] = 32;
spin_lock_init(&chip->gpio_lock[0]);
+ spin_lock_init(&chip->gpio_lock[1]);
if (of_property_read_u32(np, "xlnx,is-dual", &is_dual))
is_dual = 0;
@@ -314,7 +315,6 @@ static int xgpio_probe(struct platform_device *pdev)
&chip->gpio_width[1]))
chip->gpio_width[1] = 32;
- spin_lock_init(&chip->gpio_lock[1]);
}
chip->gc.base = -1;
--
2.26.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-10-09 13:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-03 3:13 [PATCH v10 4/4] gpio: xilinx: Utilize generic bitmap_get_value and _set_value kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2020-10-02 23:47 [PATCH v10 0/4] Introduce the for_each_set_clump macro Syed Nayyar Waris
2020-10-02 23:52 ` [PATCH v10 4/4] gpio: xilinx: Utilize generic bitmap_get_value and _set_value Syed Nayyar Waris
2020-10-02 23:52 ` Syed Nayyar Waris
2020-10-09 13:36 ` kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.