LXR | KVM | PM | Time | Interrupt | Systems Performance | Bootup Optimization

Linux hwspinlock子系统(STM32MP157 HSEM)

hwspinlock(硬件自旋锁)是 Linux 内核中的一个同步机制,它提供了一种在多核处理器系统中保护共享资源的方法。

hwspinlock分为三部分:

  • hwspinlock core提供注册注销以及对hwspinlock获取和释放接口。
  • hwspinlock Controller驱动。
  • hwspinlock Client驱动,使用hwspinlock提供的同步机制,维护和其他核共享资源。

1 hwspinlock配置和文件

hwspinlock配置:

Device Drivers
  Hardware Spinlock drivers
    STM32 Hardware Spinlock device

 相关文件如下:

drivers/hwspinlock/
├── hwspinlock_core.c--hwspinlock的注册注销接口,以及使用lock/unlock API。 ├── stm32_hwspinlock.c--STM32 hwspinlock驱动。

2 hwspinlock硬件:HSEM

3 hwspinlock API

hwspinlock注册和注销接口:

int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev,
        const struct hwspinlock_ops *ops, int base_id, int num_locks);
int hwspin_lock_unregister(struct hwspinlock_device *bank);
int devm_hwspin_lock_unregister(struct device *dev,
                struct hwspinlock_device *bank);
int devm_hwspin_lock_register(struct device *dev,
                  struct hwspinlock_device *bank,
                  const struct hwspinlock_ops *ops,
                  int base_id, int num_locks);

 从hwspinlock core获取一个hwspinlock client:

struct hwspinlock *hwspin_lock_request(void);
struct hwspinlock *hwspin_lock_request_specific(unsigned int id);
struct hwspinlock *devm_hwspin_lock_request(struct device *dev);
struct hwspinlock *devm_hwspin_lock_request_specific(struct device *dev,
                             unsigned int id);

获取或者释放hwspinlock:

int __hwspin_lock_timeout(struct hwspinlock *, unsigned int, int,
                            unsigned long *);
int __hwspin_trylock(struct hwspinlock *, int, unsigned long *);
void __hwspin_unlock(struct hwspinlock *, int, unsigned long *);

4 STM32MP157 HSEM驱动

4.1 hwspinlock Controller驱动

hwspinlock dts:

        hsem: hwspinlock@4c000000 {
            compatible = "st,stm32-hwspinlock";
            #hwlock-cells = <2>;
            reg = <0x4c000000 0x400>;
            clocks = <&rcc HSEM>;
            clock-names = "hsem";
        };

 hwspinlock驱动程序:

stm32_hwspinlock_init
  stm32_hwspinlock_driver
    stm32_hwspinlock_probe
      hwspin_lock_register
        hwspin_lock_register_single

4.2 hwspinlock Client驱动

devm_hwspin_lock_request_specific:从hwspinlock core中获取一个特定hwspinlock实例。

hwspin_lock_timeout_irqsave:尝试获取hwspinlock锁。

hwspin_unlock_irqrestore:释放hwspinlock锁。

posted on 2024-07-15 23:59  ArnoldLu  阅读(139)  评论(0编辑  收藏  举报

导航