gpio-sim: configfs-based GPIO simulator
Subsystems (4)
v10 cover gpio-sim: configfs-based GPIO simulator
Here's the tenth revision of the simulator.
As there was no reasoning with configfs maintainers for many months, this time the whole concept of committable items has been dropped. Instead, each configfs chip item (or rather a group - more on that later) exposes a new attribute called 'live'. Writing 1 to it brings the chip on-line (registers the platform device) and writing 0 tears it down.
There are some caveats to that approach - for example: we can't block the user-space from deleting chip items when chips are live but is just handled by silently destroying the chip device in the background.
Andy (rightfully) pointed out that parsing of the lists of line names is awkward so in this iteration it's been replaced by a system that is more elegant and will allow to easily extend configuration options for specific GPIO lines. This is achieved by turning the chip's configfs item into a configfs group and allowing the user-space to create additional items inside it. The items must be called line<offset> (e.g. line0, line12 etc.) where the offset part indicates to the module the offset for which given item stores the configuration for. Within each such line item, there are additional attributes that allow specifying configuration for specific lines.
In v10 there are additional significant changes:
Kent and Andy suggested that we should wait for probe() to finish and propagate any errors to user-space. In this version that is implemented. However there's no mechanism for propagating error codes from probe so we always return -ENXIO to the user-space if probe fails. Thanks to this approach, there's no longer need for using udev in user-space to wait for the device to appear. Once we return from the write() to live, the device is good to go.
The lines can now be hogged from the kernel-space. This will allow the user-space to tests various use-cases involving busy lines without having to use the very tested interface to take them in the first place.
I dropped the separate locks for lines because in most cases the chip lock needed to be taken anyway. It simplified the locking in general a lot.
The sysfs interface has been reworked. Instead of creating a single group with a variable number of attributes (for each line) we go for a separate group for each line and a constant number of attributes that can be easily extended in the future.
v1 -> v2:
- add selftests for gpio-sim
- add helper programs for selftests
- update the configfs rename callback to work with the new API introduced in v5.11
- fix a missing quote in the documentation
- use !! whenever using bits operation that are required to return 0 or 1
- use provided bitmap API instead of reimplementing copy or fill operations
- fix a deadlock in gpio_sim_direction_output()
- add new read-only configfs attributes for mapping of configfs items to GPIO device names
- and address other minor issues pointed out in reviews of v1
v2 -> v3:
- use devm_bitmap_alloc() instead of the zalloc variant if we're initializing the bitmap with 1s
- drop the patch exporting device_is_bound()
- don't return -ENODEV from dev_nam and chip_name configfs attributes, return a string indicating that the device is not available yet ('n/a')
- fix indentation where it makes sense
- don't protect IDA functions which use their own locking and where it's not needed
- use kmemdup() instead of kzalloc() + memcpy()
- collected review tags
- minor coding style fixes
v3 -> v4:
- return 'none' instead of 'n/a' from dev_name and chip_name before the device is registered
- use sysfs_emit() instead of s*printf()
- drop GPIO_SIM_MAX_PROP as it's only used in an array's definition where it's fine to hardcode the value
v4 -> v5:
- drop lib patches that are already upstream
- use BIT() instead of (1UL << bit) for flags
- fix refcounting for the configfs_dirent in rename()
- drop d_move() from the rename() callback
- free memory allocated for the live and pending groups in configfs_d_iput() and not in detach_groups()
- make sure that if a group of some name is in the live directory, a new group with the same name cannot be created in the pending directory
v5 -> v6:
- go back to using (1UL << bit) instead of BIT()
- if the live group dentry doesn't exist for whatever reason at the time when mkdir() in the pending group is called (would be a BUG()), return -ENOENT instead of -EEXIST which should only be returned if given subsystem already exists in either live or pending group
v6 -> v7:
- as detailed by Andy in commit 6fda593f3082 ("gpio: mockup: Convert to use software nodes") removing device properties after the platform device is removed but before the GPIO device gets dropped can lead to a use-after-free bug - use software nodes to manually control the freeing of the properties
v7 -> v8:
- fixed some minor coding style issues as pointed out by Andy
v8 -> v9:
- dropped the patches implementing committable-items and reworked the driver to not use them
- reworked the gpio-line-names property and configuring specific lines in general
- many smaller tweaks here and there
v9 -> v10:
- make writing to 'live' wait for the probe to finish and report an error to user-space if it failed
- add the ability to hog lines from the kernel-space
- rework locking (drop separate locks for line context objects)
- rework the sysfs interface (create a separate group for each line with a constant number of attributes instead of going the other way around)
Bartosz Golaszewski (5):
gpiolib: provide gpiod_remove_hogs()
gpio: sim: new testing module
selftests: gpio: provide a helper for reading chip info
selftests: gpio: add a helper for reading GPIO line names
selftests: gpio: add test cases for gpio-sim
Documentation/admin-guide/gpio/gpio-sim.rst | 80 + drivers/gpio/Kconfig | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-sim.c | 1370 +++++++++++++++++ drivers/gpio/gpiolib.c | 11 + include/linux/gpio/machine.h | 2 + tools/testing/selftests/gpio/.gitignore | 2 + tools/testing/selftests/gpio/Makefile | 4 +- tools/testing/selftests/gpio/config | 1 + tools/testing/selftests/gpio/gpio-chip-info.c | 57 + tools/testing/selftests/gpio/gpio-line-name.c | 55 + tools/testing/selftests/gpio/gpio-sim.sh | 306 ++++ 12 files changed, 1895 insertions(+), 2 deletions(-) create mode 100644 Documentation/admin-guide/gpio/gpio-sim.rst create mode 100644 drivers/gpio/gpio-sim.c create mode 100644 tools/testing/selftests/gpio/gpio-chip-info.c create mode 100644 tools/testing/selftests/gpio/gpio-line-name.c create mode 100755 tools/testing/selftests/gpio/gpio-sim.sh
Signature · 1 line
2.25.1
PATCH v10 1/5 gpiolib: provide gpiod_remove_hogs()
Currently all users of gpiod_add_hogs() call it only once at system init so there never was any need for a mechanism allowing to remove them. Now the upcoming gpio-sim will need to tear down chips with hogged lines so provide a function that allows to remove hogs.
--- drivers/gpio/gpiolib.c | 11 +++++++++++ include/linux/gpio/machine.h | 2 ++ 2 files changed, 13 insertions(+)
drivers/gpio/gpiolib.c +11 -0
@@ -3540,6 +3540,17 @@ void gpiod_add_hogs(struct gpiod_hog *hogs) }EXPORT_SYMBOL_GPL (gpiod_add_hogs); +void gpiod_remove_hogs (struct gpiod_hog *hogs) +{ +struct gpiod_hog *hog; + +mutex_lock (&gpio_machine_hogs_mutex); +for (hog = &hogs[0 ]; hog->chip_label; hog++) +list_del (&hog->list); +mutex_unlock (&gpio_machine_hogs_mutex); +} +EXPORT_SYMBOL_GPL (gpiod_remove_hogs); +static struct gpiod_lookup_table *gpiod_find_lookup_table (struct device *dev) {const char *dev_id = dev ?dev_name (dev) :NULL ;
include/linux/gpio/machine.h +2 -0
@@ -100,6 +100,7 @@ void gpiod_add_lookup_table(struct gpiod_lookup_table *table);void gpiod_add_lookup_tables (struct gpiod_lookup_table **tables,size_t n);void gpiod_remove_lookup_table (struct gpiod_lookup_table *table);void gpiod_add_hogs (struct gpiod_hog *hogs); +void gpiod_remove_hogs (struct gpiod_hog *hogs);#else /* ! CONFIG_GPIOLIB */ static inline void gpiod_add_lookup_table (struct gpiod_lookup_table *table) {}
@@ -108,6 +109,7 @@ void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}static inline void gpiod_remove_lookup_table (struct gpiod_lookup_table *table) {}static inline void gpiod_add_hogs (struct gpiod_hog *hogs) {} +static inline void gpiod_remove_hogs (struct gpiod_hog *hogs) {}#endif /* CONFIG_GPIOLIB */ #endif /* __LINUX_GPIO_MACHINE_H */
Signature · 1 line
2.25.1
PATCH v10 2/5 gpio: sim: new testing module
In reply to Bartosz GolaszewskiImplement a new, modern GPIO testing module controlled by configfs attributes instead of module parameters. The goal of this driver is to provide a replacement for gpio-mockup that will be easily extensible with new features and doesn't require reloading the module to change the setup.
--- Documentation/admin-guide/gpio/gpio-sim.rst | 80 ++ drivers/gpio/Kconfig | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-sim.c | 1370 +++++++++++++++++++ 4 files changed, 1459 insertions(+) create mode 100644 Documentation/admin-guide/gpio/gpio-sim.rst create mode 100644 drivers/gpio/gpio-sim.c
Documentation/admin-guide/gpio/gpio-sim.rst new file +80 -0
@@ -0,0 +1,80 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Configfs GPIO Simulator +======================= + +The configfs GPIO Simulator (gpio-sim) provides a way to create simulated GPIO +chips for testing purposes. The lines exposed by these chips can be accessed +using the standard GPIO character device interface as well as manipulated +using sysfs attributes. + +Creating simulated chips +------------------------ + +The gpio-sim module registers a configfs subsystem called 'gpio-sim'. + +In order to instantiate a new simulated chip, the user needs to mkdir() a new +directory gpio-sim/. Inside each new directory, there's a set of attributes +that can be used to configure the new chip. Additionally the user can mkdir() +subdirectories inside the chip's directory that allow to pass additional +configuration for specific lines. The name of those subdirectories must take +the form of: 'line<offset>' (e.g. 'line0', 'line20', etc.) as the name will be +used by the module to assign the config to the specific line at given offset. + +Once the confiuration is complete, the 'live' attribute must be set to 1 in +order to instantiate the chip. It can be set back to 0 to destroy the simulated +chip. The module will synchronously wait for the new simulated device to be +successfully probed and if this doesn't happen, writing to 'live' will result +in an error. + +Currently supported chip configuration attributes are: + + num_lines - an unsigned integer value defining the number of GPIO lines to + export + + label - a string defining the label for the GPIO chip + +Additionally two read-only attributes named 'chip_name' and 'dev_name' are +exposed in order to provide users with a mapping from configfs directories to +the actual devices created in the kernel. The former returns the name of the +GPIO device as assigned by gpiolib (i.e. "gpiochip0", "gpiochip1", etc.). The +latter returns the parent device name as defined by the gpio-sim driver (i.e. +"gpio-sim.0", "gpio-sim.1", etc.). This allows user-space to map the configfs +items both to the correct character device file as well as the associated entry +in sysfs. + +Supported line configuration attributes are: + + name - a string defining the name of this line as used by the + "gpio-line-names" device property + +Lines can be hogged by creating a new directory under the line's directory. The +directory must be called 'hog' and there can only be a single instance of it. +The hog directory also exposes additional attributes: + + name - name of the kernel consumer of this hogged line + + direction - hog direction, must be one of: 'input', 'output-high' and + 'output-low' + +Simulated GPIO chips can also be defined in device-tree. The compatible string +must be: "gpio-simulator". Supported properties are: + + "gpio-sim,label" - chip label + +Other standard GPIO properties (like "gpio-line-names", "ngpios" or gpio-hog) +are also supported. + +Manipulating simulated lines +---------------------------- + +Each simulated GPIO chip creates a separate sysfs group under its device +directory for each exposed line. The name of each group is of the form: +'sim_gpioX' where X is the offset of the line. Inside each group there are +two attibutes: + + pull - allows to read and set the current simulated pull setting for every + line, when writing the value must be one of: 'pull-up', 'pull-down' + + value - allows to read the current value of the line which may be different + from the pull if the line is being driven from user-space
drivers/gpio/Kconfig +8 -0
@@ -1694,6 +1694,14 @@ config GPIO_VIRTIO These virtual GPIOs can be routed to real GPIOs or attached to simulators on the host (like QEMU). +config GPIO_SIM + tristate "GPIO Simulator Module" + select IRQ_SIM + select CONFIGFS_FS + help + This enables the GPIO simulator - a configfs-based GPIO testing + driver. + endmenu endif
drivers/gpio/Makefile +1 -0
@@ -133,6 +133,7 @@ obj-$(CONFIG_GPIO_SAMA5D2_PIOBU) += gpio-sama5d2-piobu.o obj-$(CONFIG_GPIO_SCH311X) += gpio-sch311x.o obj-$(CONFIG_GPIO_SCH) += gpio-sch.o obj-$(CONFIG_GPIO_SIFIVE) += gpio-sifive.o +obj-$(CONFIG_GPIO_SIM) += gpio-sim.o obj-$(CONFIG_GPIO_SIOX) += gpio-siox.o obj-$(CONFIG_GPIO_SL28CPLD) += gpio-sl28cpld.o obj-$(CONFIG_GPIO_SODAVILLE) += gpio-sodaville.o
drivers/gpio/gpio-sim.c new file +1370 -0
1,370 lines not on this page · raw message
Signature · 1 line
2.25.1
kernel test robot
build botRe: [PATCH v10 2/5] gpio: sim: new testing module
I love your patch! Perhaps something to improve:
Hi Bartosz,
I love your patch! Perhaps something to improve:
[auto build test WARNING on v5.16-rc2]
[cannot apply to shuah-kselftest/next linusw-gpio/for-next next-20211124] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Bartosz-Golaszewski/gpio-sim-configfs-based-GPIO-simulator/20211124-194521 base: 136057256686de39cc3a07c2e39ef6bc43003ff6 config: i386-buildonly-randconfig-r001-20211124 (https://download.01.org/0day-ci/archive/20211125/202111250402.c73il0rL-lkp(a)intel.com/config) compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 67a1c45def8a75061203461ab0060c75c864df1c)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/6e279d2416d71b602a9d97147e762c9ed38d484a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Bartosz-Golaszewski/gpio-sim-configfs-based-GPIO-simulator/20211124-194521 git checkout 6e279d2416d71b602a9d97147e762c9ed38d484a
# save the config file to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/gpio/gpio-sim.c:1085:2: warning: variable 'repr' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
default:
^~~~~~~
drivers/gpio/gpio-sim.c:1090:31: note: uninitialized use occurs here
return sprintf(page, "%s\n", repr);
^~~~
drivers/gpio/gpio-sim.c:1068:12: note: initialize the variable 'repr' to silence this warning
char *repr;
^
= NULL1 warning generated.
vim +/repr +1085 drivers/gpio/gpio-sim.c
1063
1064 static ssize_t gpio_sim_config_hog_direction_show(struct config_item *item,
1065 char *page)
1066 {
1067 struct gpio_sim_line_ctx *ctx = gpio_sim_hog_item_to_line_ctx(item);
1068 char *repr;
1069 int dir;
1070
1071 mutex_lock(&ctx->parent->lock);
1072 dir = ctx->hog_dir;
1073 mutex_unlock(&ctx->parent->lock);
1074
1075 switch (dir) {
1076 case GPIOD_IN:
1077 repr = "input";
1078 break;
1079 case GPIOD_OUT_HIGH:
1080 repr = "output-high";
1081 break;
1082 case GPIOD_OUT_LOW:
1083 repr = "output-low";
1084 break;
> 1085 default:
1086 WARN(1, "Unexpected hog direction value: %d", dir);
1087 break;
1088 }
1089
1090 return sprintf(page, "%s\n", repr);
1091 }
1092
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v10 2/5] gpio: sim: new testing module
In reply to Bartosz GolaszewskiQuoted 8 lines · Bartosz Golaszewski
Implement a new, modern GPIO testing module controlled by configfs attributes instead of module parameters. The goal of this driver is to provide a replacement for gpio-mockup that will be easily extensible with new features and doesn't require reloading the module to change the setup.
Signed-off-by Bartosz Golaszewski <[email protected]>
Quoted 9 lines
--- Documentation/admin-guide/gpio/gpio-sim.rst | 80 ++ drivers/gpio/Kconfig | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-sim.c | 1370 +++++++++++++++++++ 4 files changed, 1459 insertions(+) create mode 100644 Documentation/admin-guide/gpio/gpio-sim.rst create mode 100644 drivers/gpio/gpio-sim.c
Hi guys!
I'd like to get your opinion on some parts of the interface.
Should we allow creating multiple gpiochips per platform device like some drivers do? And if so - should the sysfs groups be created for each gpiochip device kobject and not the parent?
Currently we do this:
# Create the chip (platform device + single gpiochip):
mkdir /sys/kernel/config/gpio-sim/my-chip
# Configure it
echo 8 > /sys/kernel/config/gpio-sim/my-chip/num_lines # Enable it
echo 1 > /sys/kernel/config/gpio-sim/my-chip/live
What I mean above would make it look like this:
# Create the platform device
mkdir /sys/kernel/config/gpio-sim/my-gpio-device
# what's inside?
ls /sys/kernel/config/gpio-sim/my-gpio-device
live
# Create GPIO chips
mkdir /sys/kernel/config/gpio-sim/my-gpio-device/chip0 mkdir /sys/kernel/config/gpio-sim/my-gpio-device/chip1
# Configure chips
echo 8 > /sys/kernel/config/gpio-sim/my-gpio-device/chip0/num_lines echo 4 > /sys/kernel/config/gpio-sim/my-gpio-device/chip1/num_lines echo foobar > /sys/kernel/config/gpio-sim/my-gpio-device/chip1/label
# Enable both chips
echo 1 > /sys/kernel/config/gpio-sim/my-gpio-device/live
And in sysfs instead of current:
echo pull-up > /sys/devices/platform/gpio-sim.0/sim_line0/pull
We'd have to do:
echo pull-up > /sys/devices/platform/gpio-sim.0/gpiochip1/sim_line0/pull
While I don't see any usefulness of that at this time, if we don't do it now, then it'll be hard to extend this module later. What are your thoughts?
Bart
Re: [PATCH v10 2/5] gpio: sim: new testing module
Quoted 61 lines · Bartosz Golaszewski
Quoted 8 lines · Bartosz Golaszewski
Implement a new, modern GPIO testing module controlled by configfs attributes instead of module parameters. The goal of this driver is to provide a replacement for gpio-mockup that will be easily extensible with new features and doesn't require reloading the module to change the setup.
Signed-off-by Bartosz Golaszewski <[email protected]>Quoted 9 lines
--- Documentation/admin-guide/gpio/gpio-sim.rst | 80 ++ drivers/gpio/Kconfig | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-sim.c | 1370 +++++++++++++++++++ 4 files changed, 1459 insertions(+) create mode 100644 Documentation/admin-guide/gpio/gpio-sim.rst create mode 100644 drivers/gpio/gpio-sim.cHi guys!
I'd like to get your opinion on some parts of the interface.
Should we allow creating multiple gpiochips per platform device like some drivers do? And if so - should the sysfs groups be created for each gpiochip device kobject and not the parent?
Currently we do this:
# Create the chip (platform device + single gpiochip):
mkdir/sys/kernel/config/gpio-sim/my-chip
# Configure it
echo 8 >/sys/kernel/config/gpio-sim/my-chip/num_lines# Enable it
echo 1 >/sys/kernel/config/gpio-sim/my-chip/liveWhat I mean above would make it look like this:
# Create the platform device
mkdir/sys/kernel/config/gpio-sim/my-gpio-device# what's inside?
ls/sys/kernel/config/gpio-sim/my-gpio-device
live# Create GPIO chips
mkdir/sys/kernel/config/gpio-sim/my-gpio-device/chip0mkdir/sys/kernel/config/gpio-sim/my-gpio-device/chip1# Configure chips
echo 8 >/sys/kernel/config/gpio-sim/my-gpio-device/chip0/num_linesecho 4 >/sys/kernel/config/gpio-sim/my-gpio-device/chip1/num_linesecho foobar >/sys/kernel/config/gpio-sim/my-gpio-device/chip1/label# Enable both chips
echo 1 >/sys/kernel/config/gpio-sim/my-gpio-device/liveAnd in sysfs instead of current:
echo pull-up >
/sys/devices/platform/gpio-sim.0/sim_line0/pull
Quoted 8 lines
We'd have to do:
echo pull-up >
/sys/devices/platform/gpio-sim.0/gpiochip1/sim_line0/pullWhile I don't see any usefulness of that at this time, if we don't do it now, then it'll be hard to extend this module later. What are your thoughts?
I might be missing something, but I don't see the platform abstraction adding anything that can't be easily emulated in userspace using multiple chips, and it complicates the minimal case as you now have to create a platform as well as the chip.
So I'd keep it simple and stick with the chip level abstraction.
Cheers,
Kent.
Re: [PATCH v10 2/5] gpio: sim: new testing module
Quoted 72 lines · Kent Gibson
Quoted 61 lines · Bartosz Golaszewski
Quoted 8 lines · Bartosz Golaszewski
Implement a new, modern GPIO testing module controlled by configfs attributes instead of module parameters. The goal of this driver is to provide a replacement for gpio-mockup that will be easily extensible with new features and doesn't require reloading the module to change the setup.
Signed-off-by Bartosz Golaszewski <[email protected]>Quoted 9 lines
--- Documentation/admin-guide/gpio/gpio-sim.rst | 80 ++ drivers/gpio/Kconfig | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-sim.c | 1370 +++++++++++++++++++ 4 files changed, 1459 insertions(+) create mode 100644 Documentation/admin-guide/gpio/gpio-sim.rst create mode 100644 drivers/gpio/gpio-sim.cHi guys!
I'd like to get your opinion on some parts of the interface.
Should we allow creating multiple gpiochips per platform device like some drivers do? And if so - should the sysfs groups be created for each gpiochip device kobject and not the parent?
Currently we do this:
# Create the chip (platform device + single gpiochip):
mkdir/sys/kernel/config/gpio-sim/my-chip
# Configure it
echo 8 >/sys/kernel/config/gpio-sim/my-chip/num_lines# Enable it
echo 1 >/sys/kernel/config/gpio-sim/my-chip/liveWhat I mean above would make it look like this:
# Create the platform device
mkdir/sys/kernel/config/gpio-sim/my-gpio-device# what's inside?
ls/sys/kernel/config/gpio-sim/my-gpio-device
live# Create GPIO chips
mkdir/sys/kernel/config/gpio-sim/my-gpio-device/chip0mkdir/sys/kernel/config/gpio-sim/my-gpio-device/chip1# Configure chips
echo 8 >/sys/kernel/config/gpio-sim/my-gpio-device/chip0/num_linesecho 4 >/sys/kernel/config/gpio-sim/my-gpio-device/chip1/num_linesecho foobar >/sys/kernel/config/gpio-sim/my-gpio-device/chip1/label# Enable both chips
echo 1 >/sys/kernel/config/gpio-sim/my-gpio-device/liveAnd in sysfs instead of current:
echo pull-up >
/sys/devices/platform/gpio-sim.0/sim_line0/pullQuoted 8 lines
We'd have to do:
echo pull-up >
/sys/devices/platform/gpio-sim.0/gpiochip1/sim_line0/pullWhile I don't see any usefulness of that at this time, if we don't do it now, then it'll be hard to extend this module later. What are your thoughts?
Quoted 4 lines
I might be missing something, but I don't see the platform abstraction adding anything that can't be easily emulated in userspace using multiple chips, and it complicates the minimal case as you now have to create a platform as well as the chip.
I wouldn't stress about the level of complication of the user-space interface. Normally users will wrap it in some kind of library anyway.
Quoted 5 lines
So I'd keep it simple and stick with the chip level abstraction.
Cheers,
Kent.
Yes, in user-space nothing would change as it only sees separate gpiochips whether they're just banks of the same device or actual devices of their own (except if you start digging into uevents' contents, then you'll see it).
But this module is also aimed at doing some kernel subsystem testing (even if triggered from user-space) and providing multiple banks of GPIOs is a regularly used feature. Adding it allows us to test this other level of hierarchy + multi-level device properties etc.
Another issue is logical correctness. In this version the line attributes in sysfs are at the platform device level (/sys/platform/devices/gpio-sim.X). Logically they really should be at the gpio device level (/sys/platform/devices/gpio-sim.X/gpiochipY).
So I'm willing to give it a shot.
kernel test robot
build bot[RFC PATCH] gpio: sim: gpio_sim_config_hog_item_ops can be static
In reply to Bartosz Golaszewskidrivers/gpio/gpio-sim.c:1155:33: warning: symbol 'gpio_sim_config_hog_item_ops' was not declared. Should it be static?
drivers/gpio/gpio-sim.c:1155:33: warning: symbol 'gpio_sim_config_hog_item_ops' was not declared. Should it be static?
--- gpio-sim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-sim.c +1 -1
@@ -1152,7 +1152,7 @@ static void gpio_sim_config_hog_item_release(struct config_item *item)mutex_unlock (&ctx->parent->lock); } -struct configfs_item_operations gpio_sim_config_hog_item_ops = { +static struct configfs_item_operations gpio_sim_config_hog_item_ops = { .release = gpio_sim_config_hog_item_release, };
kernel test robot
build botRe: [PATCH v10 2/5] gpio: sim: new testing module
In reply to Bartosz GolaszewskiI love your patch! Perhaps something to improve:
Hi Bartosz,
I love your patch! Perhaps something to improve:
[auto build test WARNING on v5.16-rc2]
[cannot apply to shuah-kselftest/next linusw-gpio/for-next next-20211126] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Bartosz-Golaszewski/gpio-sim-configfs-based-GPIO-simulator/20211124-194521 base: 136057256686de39cc3a07c2e39ef6bc43003ff6 config: openrisc-randconfig-s031-20211126 (https://download.01.org/0day-ci/archive/20211127/202111270258.J1S6rXiv-lkp(a)intel.com/config) compiler: or1k-linux-gcc (GCC) 11.2.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.4-dirty
# https://github.com/0day-ci/linux/commit/6e279d2416d71b602a9d97147e762c9ed38d484a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Bartosz-Golaszewski/gpio-sim-configfs-based-GPIO-simulator/20211124-194521
git checkout 6e279d2416d71b602a9d97147e762c9ed38d484a
# save the config file to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=openrisc SHELL=/bin/bash drivers/gpio/
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
>> drivers/gpio/gpio-sim.c:1155:33: sparse: sparse: symbol 'gpio_sim_config_hog_item_ops' was not declared. Should it be static?
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH v10 3/5 selftests: gpio: provide a helper for reading chip info
In reply to Bartosz GolaszewskiAdd a simple program that allows to retrieve chip properties from the GPIO character device. This will be used in gpio-sim selftests.
--- tools/testing/selftests/gpio/.gitignore | 1 + tools/testing/selftests/gpio/Makefile | 2 +- tools/testing/selftests/gpio/gpio-chip-info.c | 57 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/gpio/gpio-chip-info.c
tools/testing/selftests/gpio/.gitignore +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only gpio-mockup-cdev +gpio-chip-info
tools/testing/selftests/gpio/Makefile +1 -1
@@ -2,7 +2,7 @@ TEST_PROGS := gpio-mockup.sh TEST_FILES := gpio-mockup-sysfs.sh -TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev +TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info CFLAGS += -O2 -g -Wall -I../../../../usr/include/ include ../lib.mk
tools/testing/selftests/gpio/gpio-chip-info.c new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v10 4/5 selftests: gpio: add a helper for reading GPIO line names
In reply to Bartosz GolaszewskiAdd a simple program that allows to read GPIO line names from the character device. This will be used in gpio-sim selftests.
--- tools/testing/selftests/gpio/.gitignore | 1 + tools/testing/selftests/gpio/Makefile | 2 +- tools/testing/selftests/gpio/gpio-line-name.c | 55 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/gpio/gpio-line-name.c
tools/testing/selftests/gpio/.gitignore +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only gpio-mockup-cdev gpio-chip-info +gpio-line-name
tools/testing/selftests/gpio/Makefile +1 -1
@@ -2,7 +2,7 @@ TEST_PROGS := gpio-mockup.sh TEST_FILES := gpio-mockup-sysfs.sh -TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info +TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name CFLAGS += -O2 -g -Wall -I../../../../usr/include/ include ../lib.mk
tools/testing/selftests/gpio/gpio-line-name.c new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v10 5/5 selftests: gpio: add test cases for gpio-sim
In reply to Bartosz GolaszewskiAdd a set of tests for the new gpio-sim module. This is a pure shell test-suite and uses the helper programs available in the gpio selftests directory. These test-cases only test the functionalities exposed by the gpio-sim driver, not those handled by core gpiolib code.
--- tools/testing/selftests/gpio/Makefile | 2 +- tools/testing/selftests/gpio/config | 1 + tools/testing/selftests/gpio/gpio-sim.sh | 306 +++++++++++++++++++++++ 3 files changed, 308 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/gpio/gpio-sim.sh
tools/testing/selftests/gpio/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -TEST_PROGS := gpio-mockup.sh +TEST_PROGS := gpio-mockup.sh gpio-sim.sh TEST_FILES := gpio-mockup-sysfs.sh TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name CFLAGS += -O2 -g -Wall -I../../../../usr/include/
tools/testing/selftests/gpio/config +1 -0
@@ -1,3 +1,4 @@ CONFIG_GPIOLIB=y CONFIG_GPIO_CDEV=y CONFIG_GPIO_MOCKUP=m +CONFIG_GPIO_SIM=m
tools/testing/selftests/gpio/gpio-sim.sh new file +306 -0
306 lines not on this page · raw message
Signature · 1 line
2.25.1