hwspinlock: allow sharing of hwspinlocks
Subsystems (4)
v2 cover hwspinlock: allow sharing of hwspinlocks
The current implementation does not allow two different devices to use a common hwspinlock. This patch set proposes to have, as an option, some hwspinlocks shared between several users.
Below is an example that explain the need for this:
exti: interrupt-controller@5000d000 {
compatible = "st,stm32mp1-exti", "syscon";
interrupt-controller;
#interrupt-cells = <2>;
reg = <0x5000d000 0x400>;
hwlocks = <&hsem 1>;
};The two drivers (stm32mp1-exti and syscon) refer to the same hwlock. With the current hwspinlock implementation, only the first driver succeeds in requesting (hwspin_lock_request_specific) the hwlock. The second request fails.
The proposed approach does not modify the API, but extends the DT 'hwlocks' property with a second optional parameter (the first one identifies an hwlock) that specifies whether an hwlock is requested for exclusive usage (current behavior) or can be shared between several users. Examples:
hwlocks = <&hsem 8>; Ref to hwlock #8 for exclusive usage
hwlocks = <&hsem 8 0>; Ref to hwlock #8 for exclusive (0) usage
hwlocks = <&hsem 8 1>; Ref to hwlock #8 for shared (1) usage
As a constraint, the #hwlock-cells value must be 1 or 2.
In the current implementation, this can have theorically any value but:
- all of the exisiting drivers use the same value : 1.
- the framework supports only one value : 1 (see implementation of of_hwspin_lock_simple_xlate())
Hence, it shall not be a problem to restrict this value to 1 or 2 since it won't break any driver.
Changes since v1:
* Removed useless 'status = "okay"' from stm32mp157c.dtsi
Fabien Dessenne (6):
dt-bindings: hwlock: add support of shared locks
hwspinlock: allow sharing of hwspinlocks
dt-bindings: hwlock: update STM32 #hwlock-cells value
ARM: dts: stm32: Add hwspinlock node for stm32mp157 SoC
ARM: dts: stm32: Add hwlock for irqchip on stm32mp157
ARM: dts: stm32: hwlocks for GPIO for stm32mp157
.../devicetree/bindings/hwlock/hwlock.txt | 27 +++++-- .../bindings/hwlock/st,stm32-hwspinlock.txt | 6 +- Documentation/hwspinlock.txt | 10 ++- arch/arm/boot/dts/stm32mp157-pinctrl.dtsi | 2 + arch/arm/boot/dts/stm32mp157c.dtsi | 9 +++ drivers/hwspinlock/hwspinlock_core.c | 82 +++++++++++++++++----- drivers/hwspinlock/hwspinlock_internal.h | 2 + 7 files changed, 107 insertions(+), 31 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/6 dt-bindings: hwlock: add support of shared locks
Use #hwlock-cells value to define whether the locks can be shared by several users.
--- .../devicetree/bindings/hwlock/hwlock.txt | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/hwlock/hwlock.txt +20 -7
@@ -13,7 +13,7 @@ hwlock providers: Required properties: - #hwlock-cells: Specifies the number of cells needed to represent a - specific lock. + specific lock. Shall be 1 or 2 (see hwlocks below). hwlock users: =============
@@ -27,6 +27,11 @@ Required properties: #hwlock-cells. The list can have just a single hwlock or multiple hwlocks, with each hwlock represented by a phandle and a corresponding args specifier. + If #hwlock-cells is 1, all of the locks are exclusive + (cannot be used by several users). + If #hwlock-cells is 2, the value of the second cell + defines whether the lock is for exclusive usage (0) or + shared (1) i.e. can be used by several users. Optional properties: - hwlock-names: List of hwlock name strings defined in the same order
@@ -46,14 +51,22 @@ of length 1. ... }; -2. Example of a node using multiple specific hwlocks: +2. Example of nodes using multiple and shared specific hwlocks: -The following example has a node requesting two hwlocks, a hwlock within -the hwlock device node 'hwlock1' with #hwlock-cells value of 1, and another -hwlock within the hwlock device node 'hwlock2' with #hwlock-cells value of 2. +The following example has a nodeA requesting two hwlocks: +- an exclusive one (#hwlock-cells = 1) within the hwlock device node 'hwlock1' +- a shared one (#hwlock-cells = 2, second cell = 1) within the hwlock device + node 'hwlock2'. +The shared lock is also be used by nodeB. - node { + nodeA { ... - hwlocks = <&hwlock1 2>, <&hwlock2 0 3>; + hwlocks = <&hwlock1 2>, <&hwlock2 0 1>; ... }; + + nodeB { + ... + hwlocks = <&hwlock2 0 1>; + ... + };
Signature · 1 line
2.7.4
PATCH v2 2/6 hwspinlock: allow sharing of hwspinlocks
In reply to Fabien DessenneThe current implementation does not allow different devices to use a common hwspinlock. Offer the possibility to use the same hwspinlock by several users.
If a device registers to the framework with #hwlock-cells = 2, then the second parameter of the 'hwlocks' DeviceTree property defines whether an hwlock is requested for an exclusive or a shared usage. If a device registers with #hwlock-cells = 1, then all the hwlocks are for an exclusive usage.
--- Documentation/hwspinlock.txt | 10 ++-- drivers/hwspinlock/hwspinlock_core.c | 82 +++++++++++++++++++++++++------- drivers/hwspinlock/hwspinlock_internal.h | 2 + 3 files changed, 73 insertions(+), 21 deletions(-)
Documentation/hwspinlock.txt +7 -3
@@ -54,9 +54,11 @@ Should be called from a process context (might sleep). struct hwspinlock *hwspin_lock_request_specific(unsigned int id); Assign a specific hwspinlock id and return its address, or NULL -if that hwspinlock is already in use. Usually board code will -be calling this function in order to reserve specific hwspinlock -ids for predefined purposes. +if that hwspinlock is already in use and not shared. If that specific +hwspinlock is declared as shared, it can be requested and used by +several users. +Usually board code will be calling this function in order to reserve +specific hwspinlock ids for predefined purposes. Should be called from a process context (might sleep).
@@ -368,11 +370,13 @@ of which represents a single hardware lock:: * struct hwspinlock - this struct represents a single hwspinlock instance * @bank: the hwspinlock_device structure which owns this lock * @lock: initialized and used by hwspinlock core + * @refcount: number of users (when shared) * @priv: private data, owned by the underlying platform-specific hwspinlock drv */ struct hwspinlock { struct hwspinlock_device *bank; spinlock_t lock; + unsigned int refcount; void *priv; };
drivers/hwspinlock/hwspinlock_core.c +64 -18
173 lines not on this page · raw message
drivers/hwspinlock/hwspinlock_internal.h +2 -0
@@ -35,11 +35,13 @@ struct hwspinlock_ops {* struct hwspinlock - this struct represents a single hwspinlock instance * @bank: the hwspinlock_device structure which owns this lock * @lock: initialized and used by hwspinlock core +* @refcount: number of users (when shared) * @priv: private data, owned by the underlying platform-specific hwspinlock drv */ struct hwspinlock {struct hwspinlock_device *bank;spinlock_t lock; +unsigned int refcount;void *priv; };
Signature · 1 line
2.7.4
PATCH v2 3/6 dt-bindings: hwlock: update STM32 #hwlock-cells value
In reply to Fabien DessenneUse a value of 2, so users can share hwlocks.
--- Documentation/devicetree/bindings/hwlock/st,stm32-hwspinlock.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/hwlock/st,stm32-hwspinlock.txt +3 -3
@@ -4,8 +4,8 @@ STM32 Hardware Spinlock Device Binding Required properties : - compatible : should be "st,stm32-hwspinlock". - reg : the register address of hwspinlock. -- #hwlock-cells : hwlock users only use the hwlock id to represent a specific - hwlock, so the number of cells should be <1> here. +- #hwlock-cells : should be <2> so the hwlock users use the hwlock id to + represent a specific hwlock and define its shared / exclusive attribute. - clock-names : Must contain "hsem". - clocks : Must contain a phandle entry for the clock in clock-names, see the common clock bindings.
@@ -16,7 +16,7 @@ Please look at the generic hwlock binding for usage information for consumers, Example of hwlock provider: hwspinlock@4c000000 { compatible = "st,stm32-hwspinlock"; - #hwlock-cells = <1>; + #hwlock-cells = <2>; reg = <0x4c000000 0x400>; clocks = <&rcc HSEM>; clock-names = "hsem";
Signature · 1 line
2.7.4
PATCH v2 4/6 ARM: dts: stm32: Add hwspinlock node for stm32mp157 SoC
In reply to Fabien DessenneDeclare hwspinlock device for stm32mp157 SoC
--- arch/arm/boot/dts/stm32mp157c.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm/boot/dts/stm32mp157c.dtsi +8 -0
@@ -886,6 +886,14 @@ status = "disabled"; }; + hsem: hwspinlock@4c000000 { + compatible = "st,stm32-hwspinlock"; + #hwlock-cells = <2>; + reg = <0x4c000000 0x400>; + clocks = <&rcc HSEM>; + clock-names = "hsem"; + }; + ipcc: mailbox@4c001000 { compatible = "st,stm32mp1-ipcc"; #mbox-cells = <1>;
Signature · 1 line
2.7.4
PATCH v2 5/6 ARM: dts: stm32: Add hwlock for irqchip on stm32mp157
In reply to Fabien DessenneDefine a hwspinlock to be used by the irq controller driver and the syscon driver.
--- arch/arm/boot/dts/stm32mp157c.dtsi | 1 + 1 file changed, 1 insertion(+)
arch/arm/boot/dts/stm32mp157c.dtsi +1 -0
@@ -921,6 +921,7 @@ interrupt-controller; #interrupt-cells = <2>; reg = <0x5000d000 0x400>; + hwlocks = <&hsem 1 1>; }; syscfg: syscon@50020000 {
Signature · 1 line
2.7.4
PATCH v2 6/6 ARM: dts: stm32: hwlocks for GPIO for stm32mp157
In reply to Fabien DessenneDeclare a shared hwlock to be used by all gpio / pin controllers.
--- arch/arm/boot/dts/stm32mp157-pinctrl.dtsi | 2 ++ 1 file changed, 2 insertions(+)
arch/arm/boot/dts/stm32mp157-pinctrl.dtsi +2 -0
@@ -14,6 +14,7 @@ ranges = <0 0x50002000 0xa400>; interrupt-parent = <&exti>; st,syscfg = <&exti 0x60 0xff>; + hwlocks = <&hsem 0 1>; pins-are-numbered; gpioa: gpio@50002000 {
@@ -424,6 +425,7 @@ pins-are-numbered; interrupt-parent = <&exti>; st,syscfg = <&exti 0x60 0xff>; + hwlocks = <&hsem 0 1>; gpioz: gpio@54004000 { gpio-controller;
Signature · 1 line
2.7.4
Hi
I Got Rob's Reviewed-by. Any further comments?
Fabien
Quoted 55 lines · Fabien Dessenne
The current implementation does not allow two different devices to use a common hwspinlock. This patch set proposes to have, as an option, some hwspinlocks shared between several users.
Below is an example that explain the need for this:
exti: interrupt-controller@5000d000 { compatible = "st,stm32mp1-exti", "syscon"; interrupt-controller; #interrupt-cells = <2>; reg = <0x5000d000 0x400>; hwlocks = <&hsem 1>; };The two drivers (stm32mp1-exti and syscon) refer to the same hwlock. With the current hwspinlock implementation, only the first driver succeeds in requesting (
hwspin_lock_request_specific) the hwlock. The second request fails.The proposed approach does not modify the API, but extends the DT 'hwlocks' property with a second optional parameter (the first one identifies an hwlock) that specifies whether an hwlock is requested for exclusive usage (current behavior) or can be shared between several users. Examples:
hwlocks = <&hsem 8>; Ref to hwlock #8 for exclusive usage
hwlocks = <&hsem 8 0>; Ref to hwlock #8 for exclusive (0) usage
hwlocks = <&hsem 8 1>; Ref to hwlock #8 for shared (1) usageAs a constraint, the #hwlock-cells value must be 1 or 2.
In the current implementation, this can have theorically any value but:
- all of the exisiting drivers use the same value : 1.
- the framework supports only one value : 1 (see implementation ofof_hwspin_lock_simple_xlate())
Hence, it shall not be a problem to restrict this value to 1 or 2 since it won't break any driver.Changes since v1:
* Removed useless 'status = "okay"' fromstm32mp157c.dtsiFabien Dessenne (6):
dt-bindings: hwlock: add support of shared locks
hwspinlock: allow sharing of hwspinlocks
dt-bindings: hwlock: update STM32 #hwlock-cells value
ARM: dts: stm32: Add hwspinlock node for stm32mp157 SoC
ARM: dts: stm32: Add hwlock for irqchip on stm32mp157
ARM: dts: stm32: hwlocks for GPIO for stm32mp157.../devicetree/bindings/hwlock/hwlock.txt | 27 +++++-- .../bindings/hwlock/st,stm32-hwspinlock.txt | 6 +- Documentation/hwspinlock.txt | 10 ++- arch/arm/boot/dts/stm32mp157-pinctrl.dtsi | 2 + arch/arm/boot/dts/stm32mp157c.dtsi | 9 +++ drivers/hwspinlock/hwspinlock_core.c | 82 +++++++++++++++++----- drivers/hwspinlock/hwspinlock_internal.h | 2 + 7 files changed, 107 insertions(+), 31 deletions(-)