In addition to migrating the files to use SPDX license headers this
 introduces the ability for clients to operate a hwlock without the
 framework taking any additional locks.
 -----BEGIN PGP SIGNATURE-----
 
 iQJPBAABCAA5FiEEBd4DzF816k8JZtUlCx85Pw2ZrcUFAlsevMIbHGJqb3JuLmFu
 ZGVyc3NvbkBsaW5hcm8ub3JnAAoJEAsfOT8Nma3FqjgQAKWiDEoEw75RZnfmRAVB
 Ot8TgeUoj6CodjV0pe3fLYBYLKzJbEBiC8VfjFKeq9JwndPsGaCXqcnrKegl11pd
 /supYYzsAWT4YUZFsq0Y00mnNWKHLVL2VkKh4yPD+GaRuBDITKaurBnv3tB19ccG
 aeG5eS2bIhMhcaRaPVSRYlb34Zz8PssvlYefToUiNCuBI33D45fRSvvn5z3o5xAh
 ZL0qEBVG8BviPIPMwlp5w1PIC8Rz+eyZRmaH+fV5lewUqh32hzf4ynAIr0aDYug7
 tzFeSPqjxpvzRgZtocsJ2NqTm3jMEyzHL9X+Rt31ryN4flTROkCiWg4xDONvac7E
 fAq924WhvYqe2flNJjUR6azxjO0RsTx78LiAxZir43tvSjqdm3RTPgWOlCTdzP4u
 O5lDAm7c1QZISlKAXJewRccuUxg2XVdYa2tTBQalBqq9Ys1ZiMeWQ4UUNzvEIBji
 vlj2KguG5CgPrThhk/S11JCvG7Ti5frljebVasyF5nLX78bXPfTaBpPNre+kL6Ee
 4AylueOFeT5+Ft8a7quokzvBGUmlwYPq6jPAAL4TrU39SLIWxXRv3qDczBRe0j9G
 Xh6L8GVrUIEWxJz04OxtsgG/N3zNujjUTy/G3A3AZgM7Ijneu0xNKAjXNHfD2XNu
 pH2+HeF8vKQNB89gZJkF90XW
 =KYHF
 -----END PGP SIGNATURE-----

Merge tag 'hwlock-v4.18' of git://github.com/andersson/remoteproc

Pull hwspinlock updates from Bjorn Andersson:
 "In addition to migrating the files to use SPDX license headers this
  introduces the ability for clients to operate a hwlock without the
  framework taking any additional locks"

* tag 'hwlock-v4.18' of git://github.com/andersson/remoteproc:
  hwspinlock/u8500: Switch to SPDX license identifier
  hwspinlock: sprd: Switch to SPDX license identifier
  hwspinlock/sirf: Switch to SPDX license identifier
  hwspinlock: qcom: Switch to SPDX license identifier
  hwspinlock/omap: Switch to SPDX license identifier
  hwspinlock/core: Switch to SPDX license identifier
  hwspinlock: Introduce one new mode for hwspinlock
  hwspinlock: Convert to use 'switch' statement
This commit is contained in:
Linus Torvalds 2018-06-11 12:09:19 -07:00
Родитель d2b2250c3e e759176c7f
Коммит 6f75edeadd
9 изменённых файлов: 118 добавлений и 81 удалений

Просмотреть файл

@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
# #
# Generic HWSPINLOCK framework # Generic HWSPINLOCK framework
# #

Просмотреть файл

@ -1,18 +1,10 @@
// SPDX-License-Identifier: GPL-2.0
/* /*
* Hardware spinlock framework * Hardware spinlock framework
* *
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
* *
* Contact: Ohad Ben-Cohen <ohad@wizery.com> * Contact: Ohad Ben-Cohen <ohad@wizery.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/ */
#define pr_fmt(fmt) "%s: " fmt, __func__ #define pr_fmt(fmt) "%s: " fmt, __func__
@ -71,10 +63,16 @@ static DEFINE_MUTEX(hwspinlock_tree_lock);
* This function attempts to lock an hwspinlock, and will immediately * This function attempts to lock an hwspinlock, and will immediately
* fail if the hwspinlock is already taken. * fail if the hwspinlock is already taken.
* *
* Upon a successful return from this function, preemption (and possibly * Caution: If the mode is HWLOCK_RAW, that means user must protect the routine
* interrupts) is disabled, so the caller must not sleep, and is advised to * of getting hardware lock with mutex or spinlock. Since in some scenarios,
* release the hwspinlock as soon as possible. This is required in order to * user need some time-consuming or sleepable operations under the hardware
* minimize remote cores polling on the hardware interconnect. * lock, they need one sleepable lock (like mutex) to protect the operations.
*
* If the mode is not HWLOCK_RAW, upon a successful return from this function,
* preemption (and possibly interrupts) is disabled, so the caller must not
* sleep, and is advised to release the hwspinlock as soon as possible. This is
* required in order to minimize remote cores polling on the hardware
* interconnect.
* *
* The user decides whether local interrupts are disabled or not, and if yes, * The user decides whether local interrupts are disabled or not, and if yes,
* whether he wants their previous state to be saved. It is up to the user * whether he wants their previous state to be saved. It is up to the user
@ -106,12 +104,20 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags)
* problems with hwspinlock usage (e.g. scheduler checks like * problems with hwspinlock usage (e.g. scheduler checks like
* 'scheduling while atomic' etc.) * 'scheduling while atomic' etc.)
*/ */
if (mode == HWLOCK_IRQSTATE) switch (mode) {
case HWLOCK_IRQSTATE:
ret = spin_trylock_irqsave(&hwlock->lock, *flags); ret = spin_trylock_irqsave(&hwlock->lock, *flags);
else if (mode == HWLOCK_IRQ) break;
case HWLOCK_IRQ:
ret = spin_trylock_irq(&hwlock->lock); ret = spin_trylock_irq(&hwlock->lock);
else break;
case HWLOCK_RAW:
ret = 1;
break;
default:
ret = spin_trylock(&hwlock->lock); ret = spin_trylock(&hwlock->lock);
break;
}
/* is lock already taken by another context on the local cpu ? */ /* is lock already taken by another context on the local cpu ? */
if (!ret) if (!ret)
@ -122,12 +128,20 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags)
/* if hwlock is already taken, undo spin_trylock_* and exit */ /* if hwlock is already taken, undo spin_trylock_* and exit */
if (!ret) { if (!ret) {
if (mode == HWLOCK_IRQSTATE) switch (mode) {
case HWLOCK_IRQSTATE:
spin_unlock_irqrestore(&hwlock->lock, *flags); spin_unlock_irqrestore(&hwlock->lock, *flags);
else if (mode == HWLOCK_IRQ) break;
case HWLOCK_IRQ:
spin_unlock_irq(&hwlock->lock); spin_unlock_irq(&hwlock->lock);
else break;
case HWLOCK_RAW:
/* Nothing to do */
break;
default:
spin_unlock(&hwlock->lock); spin_unlock(&hwlock->lock);
break;
}
return -EBUSY; return -EBUSY;
} }
@ -160,9 +174,14 @@ EXPORT_SYMBOL_GPL(__hwspin_trylock);
* is already taken, the function will busy loop waiting for it to * is already taken, the function will busy loop waiting for it to
* be released, but give up after @timeout msecs have elapsed. * be released, but give up after @timeout msecs have elapsed.
* *
* Upon a successful return from this function, preemption is disabled * Caution: If the mode is HWLOCK_RAW, that means user must protect the routine
* (and possibly local interrupts, too), so the caller must not sleep, * of getting hardware lock with mutex or spinlock. Since in some scenarios,
* and is advised to release the hwspinlock as soon as possible. * user need some time-consuming or sleepable operations under the hardware
* lock, they need one sleepable lock (like mutex) to protect the operations.
*
* If the mode is not HWLOCK_RAW, upon a successful return from this function,
* preemption is disabled (and possibly local interrupts, too), so the caller
* must not sleep, and is advised to release the hwspinlock as soon as possible.
* This is required in order to minimize remote cores polling on the * This is required in order to minimize remote cores polling on the
* hardware interconnect. * hardware interconnect.
* *
@ -249,12 +268,20 @@ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags)
hwlock->bank->ops->unlock(hwlock); hwlock->bank->ops->unlock(hwlock);
/* Undo the spin_trylock{_irq, _irqsave} called while locking */ /* Undo the spin_trylock{_irq, _irqsave} called while locking */
if (mode == HWLOCK_IRQSTATE) switch (mode) {
case HWLOCK_IRQSTATE:
spin_unlock_irqrestore(&hwlock->lock, *flags); spin_unlock_irqrestore(&hwlock->lock, *flags);
else if (mode == HWLOCK_IRQ) break;
case HWLOCK_IRQ:
spin_unlock_irq(&hwlock->lock); spin_unlock_irq(&hwlock->lock);
else break;
case HWLOCK_RAW:
/* Nothing to do */
break;
default:
spin_unlock(&hwlock->lock); spin_unlock(&hwlock->lock);
break;
}
} }
EXPORT_SYMBOL_GPL(__hwspin_unlock); EXPORT_SYMBOL_GPL(__hwspin_unlock);

Просмотреть файл

@ -1,18 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0 */
/* /*
* Hardware spinlocks internal header * Hardware spinlocks internal header
* *
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
* *
* Contact: Ohad Ben-Cohen <ohad@wizery.com> * Contact: Ohad Ben-Cohen <ohad@wizery.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/ */
#ifndef __HWSPINLOCK_HWSPINLOCK_H #ifndef __HWSPINLOCK_HWSPINLOCK_H

Просмотреть файл

@ -1,3 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
/* /*
* OMAP hardware spinlock driver * OMAP hardware spinlock driver
* *
@ -6,15 +7,6 @@
* Contact: Simon Que <sque@ti.com> * Contact: Simon Que <sque@ti.com>
* Hari Kanigeri <h-kanigeri2@ti.com> * Hari Kanigeri <h-kanigeri2@ti.com>
* Ohad Ben-Cohen <ohad@wizery.com> * Ohad Ben-Cohen <ohad@wizery.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>

Просмотреть файл

@ -1,15 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (c) 2013, The Linux Foundation. All rights reserved. * Copyright (c) 2013, The Linux Foundation. All rights reserved.
* Copyright (c) 2015, Sony Mobile Communications AB * Copyright (c) 2015, Sony Mobile Communications AB
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/ */
#include <linux/hwspinlock.h> #include <linux/hwspinlock.h>

Просмотреть файл

@ -1,9 +1,8 @@
// SPDX-License-Identifier: GPL-2.0
/* /*
* SIRF hardware spinlock driver * SIRF hardware spinlock driver
* *
* Copyright (c) 2015 Cambridge Silicon Radio Limited, a CSR plc group company. * Copyright (c) 2015 Cambridge Silicon Radio Limited, a CSR plc group company.
*
* Licensed under GPLv2.
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>

Просмотреть файл

@ -1,15 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/* /*
* Spreadtrum hardware spinlock driver * Spreadtrum hardware spinlock driver
* Copyright (C) 2017 Spreadtrum - http://www.spreadtrum.com * Copyright (C) 2017 Spreadtrum - http://www.spreadtrum.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/ */
#include <linux/bitops.h> #include <linux/bitops.h>

Просмотреть файл

@ -1,3 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
/* /*
* u8500 HWSEM driver * u8500 HWSEM driver
* *
@ -10,15 +11,6 @@
* Simon Que <sque@ti.com> * Simon Que <sque@ti.com>
* Hari Kanigeri <h-kanigeri2@ti.com> * Hari Kanigeri <h-kanigeri2@ti.com>
* Ohad Ben-Cohen <ohad@wizery.com> * Ohad Ben-Cohen <ohad@wizery.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/ */
#include <linux/module.h> #include <linux/module.h>

Просмотреть файл

@ -1,18 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0 */
/* /*
* Hardware spinlock public header * Hardware spinlock public header
* *
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
* *
* Contact: Ohad Ben-Cohen <ohad@wizery.com> * Contact: Ohad Ben-Cohen <ohad@wizery.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/ */
#ifndef __LINUX_HWSPINLOCK_H #ifndef __LINUX_HWSPINLOCK_H
@ -24,6 +16,7 @@
/* hwspinlock mode argument */ /* hwspinlock mode argument */
#define HWLOCK_IRQSTATE 0x01 /* Disable interrupts, save state */ #define HWLOCK_IRQSTATE 0x01 /* Disable interrupts, save state */
#define HWLOCK_IRQ 0x02 /* Disable interrupts, don't save state */ #define HWLOCK_IRQ 0x02 /* Disable interrupts, don't save state */
#define HWLOCK_RAW 0x03
struct device; struct device;
struct device_node; struct device_node;
@ -175,6 +168,25 @@ static inline int hwspin_trylock_irq(struct hwspinlock *hwlock)
return __hwspin_trylock(hwlock, HWLOCK_IRQ, NULL); return __hwspin_trylock(hwlock, HWLOCK_IRQ, NULL);
} }
/**
* hwspin_trylock_raw() - attempt to lock a specific hwspinlock
* @hwlock: an hwspinlock which we want to trylock
*
* This function attempts to lock an hwspinlock, and will immediately fail
* if the hwspinlock is already taken.
*
* Caution: User must protect the routine of getting hardware lock with mutex
* or spinlock to avoid dead-lock, that will let user can do some time-consuming
* or sleepable operations under the hardware lock.
*
* Returns 0 if we successfully locked the hwspinlock, -EBUSY if
* the hwspinlock was already taken, and -EINVAL if @hwlock is invalid.
*/
static inline int hwspin_trylock_raw(struct hwspinlock *hwlock)
{
return __hwspin_trylock(hwlock, HWLOCK_RAW, NULL);
}
/** /**
* hwspin_trylock() - attempt to lock a specific hwspinlock * hwspin_trylock() - attempt to lock a specific hwspinlock
* @hwlock: an hwspinlock which we want to trylock * @hwlock: an hwspinlock which we want to trylock
@ -242,6 +254,29 @@ int hwspin_lock_timeout_irq(struct hwspinlock *hwlock, unsigned int to)
return __hwspin_lock_timeout(hwlock, to, HWLOCK_IRQ, NULL); return __hwspin_lock_timeout(hwlock, to, HWLOCK_IRQ, NULL);
} }
/**
* hwspin_lock_timeout_raw() - lock an hwspinlock with timeout limit
* @hwlock: the hwspinlock to be locked
* @to: timeout value in msecs
*
* This function locks the underlying @hwlock. If the @hwlock
* is already taken, the function will busy loop waiting for it to
* be released, but give up when @timeout msecs have elapsed.
*
* Caution: User must protect the routine of getting hardware lock with mutex
* or spinlock to avoid dead-lock, that will let user can do some time-consuming
* or sleepable operations under the hardware lock.
*
* Returns 0 when the @hwlock was successfully taken, and an appropriate
* error code otherwise (most notably an -ETIMEDOUT if the @hwlock is still
* busy after @timeout msecs). The function will never sleep.
*/
static inline
int hwspin_lock_timeout_raw(struct hwspinlock *hwlock, unsigned int to)
{
return __hwspin_lock_timeout(hwlock, to, HWLOCK_RAW, NULL);
}
/** /**
* hwspin_lock_timeout() - lock an hwspinlock with timeout limit * hwspin_lock_timeout() - lock an hwspinlock with timeout limit
* @hwlock: the hwspinlock to be locked * @hwlock: the hwspinlock to be locked
@ -301,6 +336,21 @@ static inline void hwspin_unlock_irq(struct hwspinlock *hwlock)
__hwspin_unlock(hwlock, HWLOCK_IRQ, NULL); __hwspin_unlock(hwlock, HWLOCK_IRQ, NULL);
} }
/**
* hwspin_unlock_raw() - unlock hwspinlock
* @hwlock: a previously-acquired hwspinlock which we want to unlock
*
* This function will unlock a specific hwspinlock.
*
* @hwlock must be already locked (e.g. by hwspin_trylock()) before calling
* this function: it is a bug to call unlock on a @hwlock that is already
* unlocked.
*/
static inline void hwspin_unlock_raw(struct hwspinlock *hwlock)
{
__hwspin_unlock(hwlock, HWLOCK_RAW, NULL);
}
/** /**
* hwspin_unlock() - unlock hwspinlock * hwspin_unlock() - unlock hwspinlock
* @hwlock: a previously-acquired hwspinlock which we want to unlock * @hwlock: a previously-acquired hwspinlock which we want to unlock