regmap: add regmap_might_sleep()
Subsystems (4)
PATCH 1/2 regmap: add regmap_might_sleep()
Sometimes a driver needs to know if the underlying regmap could sleep. For example, consider the gpio-regmap driver which needs to fill the gpiochip->can_sleep property.
It might be possible to pass this information via the gpio_regmap_config, but this has the following drawbacks. First, that property is redundant and both places might contratict each other. And secondly, the driver might not even know the type of the regmap because it just gets an opaque pointer by querying the device tree.
--- drivers/base/regmap/regmap.c | 11 +++++++++++ include/linux/regmap.h | 7 +++++++ 2 files changed, 18 insertions(+)
drivers/base/regmap/regmap.c +11 -0
@@ -1847,6 +1847,17 @@ size_t regmap_get_raw_write_max(struct regmap *map) }EXPORT_SYMBOL_GPL (regmap_get_raw_write_max); +/** +* regmap_might_sleep - Returns whether a regmap access might sleep. +* +* @map: Map to check. +*/ +bool regmap_might_sleep (struct regmap *map) +{ +return map->can_sleep; +} +EXPORT_SYMBOL_GPL (regmap_might_sleep); +static int _regmap_bus_formatted_write (void *context,unsigned int reg,unsigned int val) {
include/linux/regmap.h +7 -0
@@ -1079,6 +1079,7 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config);struct regmap *dev_get_regmap (struct device *dev,const char *name);struct device *regmap_get_device (struct regmap *map); +bool regmap_might_sleep (struct regmap *map);int regmap_write (struct regmap *map,unsigned int reg,unsigned int val);int regmap_write_async (struct regmap *map,unsigned int reg,unsigned int val); int regmap_raw_write(struct regmap *map, unsigned int reg,
@@ -1816,6 +1817,12 @@ static inline struct device *regmap_get_device(struct regmap *map)return NULL ; } +static inline bool regmap_might_sleep (struct regmap *map) +{ +WARN_ONCE (1 ,"regmap API is disabled" ); +return true; +} +#endif #endif
Signature · 1 line
2.20.1
PATCH 2/2 gpio: regmap: use new regmap_might_sleep()
Now that the regmap can be queried whether it might sleep, we can get rid of the conservative setting "can_sleep = true". New drivers which want to use gpio-regmap and can access the registers memory-mapped won't have the restriction that their consumers have to use the gpiod_*cansleep() variants anymore.
--- drivers/gpio/gpio-regmap.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/gpio/gpio-regmap.c +1 -8
@@ -259,14 +259,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config chip->of_node =to_of_node (config->fwnode);#endif /* CONFIG_OF_GPIO */ -/* -* If our regmap is fast_io we should probably set can_sleep to false. -* Right now, the regmap doesn't save this property, nor is there any -* access function for it. -* The only regmap type which uses fast_io is regmap-mmio. For now, -* assume a safe default of true here. -*/ - chip->can_sleep = true; + chip->can_sleep =regmap_might_sleep (gpio->regmap); chip->get = gpio_regmap_get;if (gpio->reg_set_base && gpio->reg_clr_base)
Signature · 1 line
2.20.1
Mark Brown
maintainerQuoted 3 lines · Michael Walle
Sometimes a driver needs to know if the underlying regmap could sleep. For example, consider the gpio-regmap driver which needs to fill the
gpiochip->can_sleepproperty.
Whatever is creating the regmap really ought to know what device it's dealing with...
Quoted 5 lines
It might be possible to pass this information via the
gpio_regmap_config, but this has the following drawbacks. First, that property is redundant and both places might contratict each other. And secondly, the driver might not even know the type of the regmap because it just gets an opaque pointer by querying the device tree.
If it's a generic GPIO driver from a code correctness point of view it's always got a risk of sleeping...
Am 2021-04-30 17:19, schrieb Mark Brown:
Quoted 8 lines · Michael Walle
Quoted 4 lines
Sometimes a driver needs to know if the underlying regmap could sleep. For example, consider the gpio-regmap driver which needs to fill the
gpiochip->can_sleepproperty.Whatever is creating the regmap really ought to know what device it's dealing with...
But creating and using the regmap are two seperate things, no? Consider the gpio-sl28cpld. It will just use whatever regmap the parent has created. How would it know what type of regmap it is?
Quoted 8 lines
Quoted 5 lines
It might be possible to pass this information via the
gpio_regmap_config, but this has the following drawbacks. First, that property is redundant and both places might contratict each other. And secondly, the driver might not even know the type of the regmap because it just gets an opaque pointer by querying the device tree.If it's a generic GPIO driver from a code correctness point of view it's always got a risk of sleeping...
I can't follow you here.
-michael
Mark Brown
maintainerQuoted 8 lines · Michael Walle
Am 2021-04-30 17:19, schrieb Mark Brown:
Quoted 2 lines
Whatever is creating the regmap really ought to know what device it's dealing with...
But creating and using the regmap are two seperate things, no? Consider the gpio-sl28cpld. It will just use whatever regmap the parent has created. How would it know what type of regmap it is?
But that's a driver for a specific device AFAICT which looks like it's only got an I2C binding on the MFD so the driver knows that it's for a device that's on a bus that's going to sleep and doesn't need to infer anything? This looks like the common case I'd expect where there's no variation.
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
It might be possible to pass this information via the
gpio_regmap_config, but this has the following drawbacks. First, that property is redundant and both places might contratict each other. And secondly, the driver might not even know the type of the regmap because
it just gets an opaque pointer by querying the device tree.If it's a generic GPIO driver from a code correctness point of view it's always got a risk of sleeping...
I can't follow you here.
If users happen to end up with a map flagged as fast they can work on the whatever driver uses this stuff and not realise they're breaking other users of the same driver that end up with slow I/O. The whole point of the flag in GPIO is AIUI warnings to help with that case.
Am 2021-04-30 19:26, schrieb Mark Brown:
Quoted 10 lines · Michael Walle
Quoted 8 lines
Am 2021-04-30 17:19, schrieb Mark Brown:
Quoted 2 lines
Whatever is creating the regmap really ought to know what device it's dealing with...
But creating and using the regmap are two seperate things, no? Consider the gpio-sl28cpld. It will just use whatever regmap the parent has created. How would it know what type of regmap it is?
Quoted 5 lines
But that's a driver for a specific device AFAICT which looks like it's only got an I2C binding on the MFD so the driver knows that it's for a device that's on a bus that's going to sleep and doesn't need to infer anything? This looks like the common case I'd expect where there's no variation.
You are right, at the moment this driver only has an I2C binding. But the idea was that this IP block and driver can be reused behind any kind of bridge; I2C, SPI or MMIO. Actually, I had the impression that all you need to do to convert it to MMIO is to replace the "kontron,sl28cpld" compatible with a "syscon" compatible. But it isn't that easy. Anyway, the idea is that you don't need to change anything in the gpio-sl28cpld driver, just change the parent. But if we can't ask the regmap what type it is, then we'll have to modify the gpio-sl28cpld driver and we will have to figure it out by some other means.
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
It might be possible to pass this information via the
gpio_regmap_config, but this has the following drawbacks. First, that property is redundant and both places might contratict each other. And secondly, the driver might not even know the type of the regmap because
it just gets an opaque pointer by querying the device tree.If it's a generic GPIO driver from a code correctness point of view it's always got a risk of sleeping...
Quoted 6 lines
Quoted 1 line
I can't follow you here.
If users happen to end up with a map flagged as fast they can work on the whatever driver uses this stuff and not realise they're breaking other users of the same driver that end up with slow I/O. The whole point of the flag in GPIO is AIUI warnings to help with that case.
Hm, but as of now, the only thing which makes the gpio-regmap driver slow i/o is the regmap itself.
-michael
Mark Brown
maintainerQuoted 11 lines · Michael Walle
Am 2021-04-30 19:26, schrieb Mark Brown:
Quoted 5 lines
But that's a driver for a specific device AFAICT which looks like it's only got an I2C binding on the MFD so the driver knows that it's for a device that's on a bus that's going to sleep and doesn't need to infer anything? This looks like the common case I'd expect where there's no variation.
You are right, at the moment this driver only has an I2C binding. But the idea was that this IP block and driver can be reused behind any kind of bridge; I2C, SPI or MMIO. Actually, I had the impression
Is this actually a way people are building hardware though?
Quoted 7 lines
that all you need to do to convert it to MMIO is to replace the "kontron,sl28cpld" compatible with a "syscon" compatible. But it isn't that easy. Anyway, the idea is that you don't need to change anything in the gpio-sl28cpld driver, just change the parent. But if we can't ask the regmap what type it is, then we'll have to modify the gpio-sl28cpld driver and we will have to figure it out by some other means.
Well, you don't need to change anything at all - the driver will work perfectly fine if it's flagging up the GPIOs as potentially sleeping even if they end up not actually sleeping.
Quoted 7 lines
Quoted 4 lines
If users happen to end up with a map flagged as fast they can work on the whatever driver uses this stuff and not realise they're breaking other users of the same driver that end up with slow I/O. The whole point of the flag in GPIO is AIUI warnings to help with that case.
Hm, but as of now, the only thing which makes the gpio-regmap driver slow i/o is the regmap itself.
Surely it's just a case of the device that's creating the gpio regmap setting a flag when it instantiates it? It's just one more thing that the parent knows about the device. This doesn't seem insurmountable.
Am 2021-05-06 14:43, schrieb Mark Brown:
Quoted 9 lines · Michael Walle
Quoted 7 lines
Am 2021-04-30 19:26, schrieb Mark Brown:
Quoted 5 lines
But that's a driver for a specific device AFAICT which looks like it's only got an I2C binding on the MFD so the driver knows that it's for a device that's on a bus that's going to sleep and doesn't need to infer anything? This looks like the common case I'd expect where there's no variation.
Quoted 5 lines
Quoted 3 lines
You are right, at the moment this driver only has an I2C binding. But the idea was that this IP block and driver can be reused behind any kind of bridge; I2C, SPI or MMIO. Actually, I had the impression
Is this actually a way people are building hardware though?
Granted, this might be a special case because the driver is for an IP inside CPLD/FPGA, thus you could easily switch the bridge.
Quoted 11 lines
Quoted 7 lines
that all you need to do to convert it to MMIO is to replace the "kontron,sl28cpld" compatible with a "syscon" compatible. But it isn't that easy. Anyway, the idea is that you don't need to change anything in the gpio-sl28cpld driver, just change the parent. But if we can't ask the regmap what type it is, then we'll have to modify the gpio-sl28cpld driver and we will have to figure it out by some other means.
Well, you don't need to change anything at all - the driver will work perfectly fine if it's flagging up the GPIOs as potentially sleeping even if they end up not actually sleeping.
Unless you need the non-sleeping version for a gpio.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
If users happen to end up with a map flagged as fast they can work on the whatever driver uses this stuff and not realise they're breaking other users of the same driver that end up with slow I/O. The whole point of the flag in GPIO is AIUI warnings to help with that case.
Hm, but as of now, the only thing which makes the gpio-regmap driver slow i/o is the regmap itself.
Surely it's just a case of the device that's creating the gpio regmap setting a flag when it instantiates it? It's just one more thing that the parent knows about the device. This doesn't seem insurmountable.
No its not. It just seemed like it is way easier to just ask the regmap.
-michael
Mark Brown
maintainerQuoted 7 lines · Michael Walle
Am 2021-05-06 14:43, schrieb Mark Brown:
Quoted 3 lines
Surely it's just a case of the device that's creating the gpio regmap setting a flag when it instantiates it? It's just one more thing that the parent knows about the device. This doesn't seem insurmountable.
No its not. It just seemed like it is way easier to just ask the regmap.
I'd rather cause a small amount of hoop jumping for one or two users than open up an API that feels like it's going to encourage dodgy usage, there's already enough problems with things like regulator_get_optional() and this feels like it's going down similar roads.