Difference between revisions of "Hardware spinlock overview"

[quality revision] [quality revision]
m (Component description)
 
m
 

Template:ArticleMainWriter Template:ReviewersList Template:ArticleApprovedVersion Summary
This article gives information about the Linux® hardware spinlock framework.

It explains how to activate the hardware spinlock framework and, based on examples, how to use it.

1 Framework purpose[edit]

Hardware spinlock modules provide hardware assistance for synchronization and mutual exclusion between heterogeneous processors and those not operating under a single, shared operating system.

A generic hardware spinlock framework allows platform-independent drivers to use the hardware spinlock device in order to access data structures that are shared between processors, that otherwise have no alternative mechanism to accomplish synchronization and mutual exclusion operations.

2 System overview[edit]

Alternate text

2.1 Component description[edit]

  • Hardware spinlock:. The role of this framework is to:
    • provide an API to other drivers
    • call specific vendor callbacks to perform lock and unlock operations
  • stm32-hwspinlock microprocessor specific hardware spinlock driver. The role of this driver is to:
    • register vendor-specific functions (callback) to the hardware spinlock framework
    • access HSEM peripheral registers to perform lock and unlock operations
  • Client driver
    • Client driver could be any driver that needs to use hardware spinlock to protect a critical section of code

2.2 API description[edit]

2.2.1 Kernel space interface[edit]

Kernel drivers can be clients of the hardware spinlock framework and can request, lock, unlock and free a hardware spinlock.

Client functions are described in kernel documentation file user API section: Documentation/hwspinlock.txt[1].

2.2.2 Driver interface[edit]

Hardware spinlock driver interfaces (registration, operations) are described in the kernel documentation file API for implementors section: Documentation/hwspinlock.txt[1].

3 Configuration[edit]

3.1 Kernel configuration[edit]

Hardware spinlock is activated by default in ST deliveries. Nevertheless, if a specific configuration is needed, this section indicates how hardware spinlock can be activated/deactivated in the kernel.

Activate hardware spinlock in the kernel configuration using the Linux Menuconfig tool: Menuconfig or how to configure kernel

Device Drivers  --->
  <*> Hardware Spinlock drivers--->
    <*> STM32 Hardware Spinlock device

3.2 Device tree configuration[edit]

Hardware spinlock bindings[2] documentation deals with all required or optional hardware spinlock generic DT properties.

Detailed DT configuration for STM32 internal peripherals:

hsem: hwspinlock@4c000000 {
       compatible = "st,stm32-hwspinlock";
       #hwlock-cells = <1>;
};

foo-client {
      hwlocks = <&hsem 0>; /*Client use lock 0*/
};

4 How to use the framework[edit]

Typical usage of hardware spinlock by drivers is taken from the kernel documentation file API for a typical usage section: Documentation/hwspinlock.txt[1].:

#include <linux/hwspinlock.h>
#include <linux/err.h>
 
int hwspinlock_example1(void)
{
	struct hwspinlock *hwlock;
	int ret;

	/* dynamically assign a hwspinlock without device tree usage*/
	hwlock = hwspin_lock_request();
	if (!hwlock)
		...

	id = hwspin_lock_get_id(hwlock);
	/* probably need to communicate id to a remote processor now */

	/* take the lock, spin for 1 sec if it's already taken */
	ret = hwspin_lock_timeout(hwlock, 1000);
	if (ret)
		...

	/*
	* we took the lock, do our thing now, but do NOT sleep
	*/

	/* release the lock */
	hwspin_unlock(hwlock);

	/* free the lock */
	ret = hwspin_lock_free(hwlock);
	if (ret)
		...

	return ret;
}

5 Source code location[edit]

Source files are located inside kernel Linux.

  • Hardware spinlock core part: generic core[3]
  • STM32 hardware spinlock vendor part: driver code [4]

6 References[edit]

  1. 1.01.11.2 Documentation/hwspinlock.txt , Hardware spinlock 'inkern' API
  2. Documentation/devicetree/bindings/hwlock/hwlock.txt , Linux Foundation, hardware spinlock generic DT bindings
  3. Hardware spinlock framework source - hwspinlock_core.c Sources of generic hardware spinlock framework
  4. STM32 hardware spinlock driver Provides all vendor specifics functions


<noinclude>

{{ArticleBasedOnModel | [[Framework overview article model]]}}
{{ArticleMainWriter | BenjaminG}}
{{ReviewersList | ArnaudP, FabienD}}
{{ArticleApprovedVersion| BenjaminG | Jean-ChristopheT(Passed, 03Jan'19), GeraldB(Not Done), ArnaudP(Passed 03Dec'18), FabienD(Passed 30Nov'18) | No previous approved version | PhilipS - 11Jan'19 - 10250 | 15Jan'19}} 
[[Category:Hardware spinlock|0]]</noinclude>


'''Summary'''<br>
This article gives information about the Linux<sup>&reg;</sup> hardware spinlock framework.

It explains how to activate the hardware spinlock framework and, based on examples, how to use it.

==Framework purpose==

Hardware spinlock modules provide hardware assistance for synchronization
and mutual exclusion between heterogeneous processors and those not operating
under a single, shared operating system.

A generic hardware spinlock framework allows platform-independent drivers to use
the hardware spinlock device in order to access data structures that are shared
between processors, that otherwise have no alternative mechanism
to accomplish synchronization and mutual exclusion operations.

==System overview==
[[File:HWSpinlock-overview.png|thumb|center|upright=4|alt=Alternate text|Hardware spinlock framework overview| |link=]]

===Component description===
* '''Hardware spinlock:'''. The role of this framework is to:
**provide an API to other drivers
**call specific vendor callbacks to perform lock and unlock operations

* '''stm32-hwspinlock''' microprocessor '''specific''' hardware spinlock driver. The role of this driver is to:
**register vendor-specific functions (callback) to the hardware spinlock framework
**access [[HSEM_internal_peripheral| HSEM peripheral]] registers to perform lock and unlock operations

* '''Client driver'''
**Client driver could be any driver that needs to use hardware spinlock to protect a critical section of code

===API description===
====Kernel space interface====
Kernel drivers can be clients of the hardware spinlock framework and can request, lock, unlock and free a hardware spinlock.

Client functions are described in kernel documentation file user API section: Documentation/hwspinlock.txt<ref name="inkern">{{CodeSource | Linux kernel | Documentation/hwspinlock.txt}}, Hardware spinlock 'inkern' API</ref>.

====Driver interface====
Hardware spinlock driver interfaces (registration, operations) are described in the kernel documentation file API for implementors section: Documentation/hwspinlock.txt<ref name="inkern">{{CodeSource | Linux kernel | Documentation/hwspinlock.txt}}, Hardware spinlock 'inkern' API</ref>.

==Configuration==

===Kernel configuration===
Hardware spinlock is activated by default in ST deliveries. Nevertheless, if a specific configuration is needed, this section indicates how hardware spinlock can be activated/deactivated in the kernel.

Activate hardware spinlock in the kernel configuration using the Linux Menuconfig tool: [[Menuconfig or how to configure kernel]]

 Device Drivers  --->
   '''<*> Hardware Spinlock drivers--->'''
     '''<*> STM32 Hardware Spinlock device'''

===Device tree configuration===
''Hardware spinlock bindings''<ref name="Hardware Spinlock bindings">{{CodeSource | Linux kernel | Documentation/devicetree/bindings/hwlock/hwlock.txt}}, Linux Foundation, hardware spinlock generic DT bindings</ref> documentation deals with all required or optional hardware spinlock generic DT properties.

Detailed DT configuration for STM32 internal peripherals:
 {{highlight|hsem}}: hwspinlock@4c000000 {
        compatible = "st,stm32-hwspinlock";
        #hwlock-cells = <1>;
 };

 foo-client {
       hwlocks = <{{highlight|&hsem}} 0>; {{highlight|/*Client use lock 0*/}}
 };

==How to use the framework==
Typical usage of hardware spinlock by drivers is taken from the kernel documentation file API for a typical usage section: Documentation/hwspinlock.txt<ref name="inkern">{{CodeSource | Linux kernel | Documentation/hwspinlock.txt}}, Hardware spinlock 'inkern' API</ref>.:<pre>

#include <linux/hwspinlock.h>

#include <linux/err.h>


int hwspinlock_example1(void)
{
	struct hwspinlock *hwlock;
	int ret;

	/* dynamically assign a hwspinlock without device tree usage*/
	hwlock = hwspin_lock_request();
	if (!hwlock)
		...

	id = hwspin_lock_get_id(hwlock);
	/* probably need to communicate id to a remote processor now */

	/* take the lock, spin for 1 sec if it's already taken */
	ret = hwspin_lock_timeout(hwlock, 1000);
	if (ret)
		...

	/*
	* we took the lock, do our thing now, but do NOT sleep
	*/

	/* release the lock */
	hwspin_unlock(hwlock);

	/* free the lock */
	ret = hwspin_lock_free(hwlock);
	if (ret)
		...

	return ret;
}</pre>


==Source code location==
Source files are located inside kernel Linux.

*'''Hardware spinlock core part''': generic core<ref>{{CodeSource | Linux kernel | drivers/hwspinlock/hwspinlock_core.c | Hardware spinlock framework source - hwspinlock_core.c}} Sources of generic hardware spinlock framework</ref>


*'''STM32 hardware spinlock vendor part''': driver code <ref>{{CodeSource | Linux kernel | drivers/hwspinlock/stm32_hwspinlock.c | STM32 hardware spinlock driver}} Provides all vendor specifics functions</ref>


==References==<references />

<noinclude>

[[Category:Hardware spinlock|0]]
{{PublicationRequestId | 10250 | 2019-01-11 | PhilipS}}
{{ArticleBasedOnModel | Framework overview article model}}</noinclude>
Line 1: Line 1:
<noinclude>
 
{{ArticleBasedOnModel | [[Framework overview article model]]}}
 
{{ArticleMainWriter | BenjaminG}}
 
{{ReviewersList | ArnaudP, FabienD}}
 
{{ArticleApprovedVersion| BenjaminG | Jean-ChristopheT(Passed, 03Jan'19), GeraldB(Not Done), ArnaudP(Passed 03Dec'18), FabienD(Passed 30Nov'18) | No previous approved version | PhilipS - 11Jan'19 - 10250 | 15Jan'19}}
 
[[Category:Hardware spinlock|0]]
 
</noinclude>
 
 
'''Summary'''<br>
 
 
This article gives information about the Linux<sup>&reg;</sup> hardware spinlock framework.
 
This article gives information about the Linux<sup>&reg;</sup> hardware spinlock framework.
   
Line 120: Line 111:
 
==References==
 
==References==
 
<references />
 
<references />
  +
  +
<noinclude>
  +
[[Category:Hardware spinlock|0]]
  +
{{PublicationRequestId | 10250 | 2019-01-11 | PhilipS}}
  +
{{ArticleBasedOnModel | Framework overview article model}}
  +
</noinclude>

Attachments

Discussions