Skip to contentSkip to conversation

hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

PATCH Superseded Kumar Gala 3 participants 12 messages Jul 29, 2013 – Aug 13, 2013

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kumar Gala

author
#0 lore raw

PATCH 1/1 hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

Add driver for Qualcomm MSM Hardware Mutex block that exists on newer MSM SoC (MSM8974, etc).

CC Jeffrey Hugo <[email protected]>
CC Eric Holmberg <[email protected]>
---
 .../devicetree/bindings/arm/msm/tcsr-mutex.txt     |  20 +++
 drivers/hwspinlock/Kconfig                         |  11 ++
 drivers/hwspinlock/Makefile                        |   1 +
 drivers/hwspinlock/msm_hwspinlock.c                | 150 +++++++++++++++++++++
 4 files changed, 182 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt
 create mode 100644 drivers/hwspinlock/msm_hwspinlock.c
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +20 -0
new file mode 100644
index 0000000..ddd6889
@@ -0,0 +1,20 @@
+Qualcomm MSM Hardware Mutex Block:
+
+The hardware block provides mutexes utilized between different processors
+on the SoC as part of the communication protocol used by these processors.
+
+Required properties:
+- compatible: should be "qcom,tcsr-mutex"
+- reg: Should contain registers location and length of mutex registers
+- reg-names:
+	"mutex-base"  - string to identify mutex registers
+- qcom,num-locks: the number of locks/mutexes supported
+
+Example:
+
+	qcom,tcsr-mutex@fd484000 {
+		compatible = "qcom,tcsr-mutex";
+		reg = <0xfd484000 0x1000>;
+		reg-names = "mutex-base";
+		qcom,num-locks = <32>;
+	};
drivers/hwspinlock/Kconfig +11 -0
index 70637d2..192e939 100644
@@ -8,6 +8,17 @@ config HWSPINLOCK
 
 menu "Hardware Spinlock drivers"
 
+config HWSPINLOCK_MSM
+	tristate "MSM Hardware Spinlock device"
+	depends on ARCH_MSM
+	select HWSPINLOCK
+	help
+	  Say y here to support the MSM Hardware Mutex functionality, which
+	  provides a synchronisation mechanism for the various processors on
+	  the SoC.
+
+	  If unsure, say N.
+
 config HWSPINLOCK_OMAP
 	tristate "OMAP Hardware Spinlock device"
 	depends on ARCH_OMAP4 || SOC_OMAP5
drivers/hwspinlock/Makefile +1 -0
index 93eb64b..4074c56 100644
@@ -3,5 +3,6 @@
 #
 
 obj-$(CONFIG_HWSPINLOCK)		+= hwspinlock_core.o
+obj-$(CONFIG_HWSPINLOCK_MSM)		+= msm_hwspinlock.o
 obj-$(CONFIG_HWSPINLOCK_OMAP)		+= omap_hwspinlock.o
 obj-$(CONFIG_HSEM_U8500)		+= u8500_hsem.o
drivers/hwspinlock/msm_hwspinlock.c new file +150 -0

150 lines not on this page · raw message

Signature · 1 line
1.8.2.1
author
#1 lore raw
Quoted 7 lines · Kumar Gala

Add driver for Qualcomm MSM Hardware Mutex block that exists on newer MSM SoC (MSM8974, etc).

CC Jeffrey Hugo <[email protected]>
CC Eric Holmberg <[email protected]>

---

[ had old device tree mailing list ]

Quoted 230 lines
.../devicetree/bindings/arm/msm/tcsr-mutex.txt     |  20 +++
drivers/hwspinlock/Kconfig                         |  11 ++
drivers/hwspinlock/Makefile                        |   1 +
drivers/hwspinlock/msm_hwspinlock.c                | 150 +++++++++++++++++++++
4 files changed, 182 insertions(+)

create mode 100644 Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt create mode 100644 drivers/hwspinlock/msm_hwspinlock.c

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +20 -0
new file mode 100644
index 0000000..ddd6889
@@ -0,0 +1,20 @@
+Qualcomm MSM Hardware Mutex Block:
+
+The hardware block provides mutexes utilized between different processors
+on the SoC as part of the communication protocol used by these processors.
+
+Required properties:
+- compatible: should be "qcom,tcsr-mutex"
+- reg: Should contain registers location and length of mutex registers
+- reg-names:
+	"mutex-base"  - string to identify mutex registers
+- qcom,num-locks: the number of locks/mutexes supported
+
+Example:
+
+	qcom,tcsr-mutex@fd484000 {
+		compatible = "qcom,tcsr-mutex";
+		reg = <0xfd484000 0x1000>;
+		reg-names = "mutex-base";
+		qcom,num-locks = <32>;
+	};
drivers/hwspinlock/Kconfig +0 -0
index 70637d2..192e939 100644
@@ -8,6 +8,17 @@ config HWSPINLOCK
 

menu "Hardware Spinlock drivers"

drivers/hwspinlock/Kconfig +11 -0
+config HWSPINLOCK_MSM
+	tristate "MSM Hardware Spinlock device"
+	depends on ARCH_MSM
+	select HWSPINLOCK
+	help
+	  Say y here to support the MSM Hardware Mutex functionality, which
+	  provides a synchronisation mechanism for the various processors on
+	  the SoC.
+
+	  If unsure, say N.
+

config HWSPINLOCK_OMAP

	tristate "OMAP Hardware Spinlock device"
	depends on ARCH_OMAP4 || SOC_OMAP5
drivers/hwspinlock/Makefile +0 -0
index 93eb64b..4074c56 100644
@@ -3,5 +3,6 @@
 #
 

obj-$(CONFIG_HWSPINLOCK) += hwspinlock_core.o
+obj-$(CONFIG_HWSPINLOCK_MSM) += msm_hwspinlock.o
obj-$(CONFIG_HWSPINLOCK_OMAP) += omap_hwspinlock.o
obj-$(CONFIG_HSEM_U8500) += u8500_hsem.o

drivers/hwspinlock/msm_hwspinlock.c new file +150 -0
new file mode 100644
index 0000000..c7d80c5
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * 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/err.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/hwspinlock.h>
+
+#include <asm/io.h>
+
+#include "hwspinlock_internal.h"
+
+#define SPINLOCK_ID_APPS_PROC	1
+#define BASE_ID			0
+
+static int msm_hwspinlock_trylock(struct hwspinlock *lock)
+{
+	void __iomem *lock_addr = lock->priv;
+
+	writel_relaxed(SPINLOCK_ID_APPS_PROC, lock_addr);
+	smp_mb();
+	return readl_relaxed(lock_addr) == SPINLOCK_ID_APPS_PROC;
+}
+
+static void msm_hwspinlock_unlock(struct hwspinlock *lock)
+{
+	int lock_owner;
+	void __iomem *lock_addr = lock->priv;
+
+	lock_owner = readl_relaxed(lock_addr);
+	if (lock_owner != SPINLOCK_ID_APPS_PROC) {
+		pr_err("%s: spinlock not owned by Apps (actual owner is %d)\n",
+				__func__, lock_owner);
+	}
+
+	writel_relaxed(0, lock_addr);
+	smp_mb();
+}
+
+static const struct hwspinlock_ops msm_hwspinlock_ops = {
+	.trylock	= msm_hwspinlock_trylock,
+	.unlock		= msm_hwspinlock_unlock,
+};
+
+static struct of_device_id msm_hwspinlock_of_match[];
+static int msm_hwspinlock_probe(struct platform_device *pdev)
+{
+	int ret, i, stride;
+	u32 num_locks;
+	struct hwspinlock_device *bank;
+	struct hwspinlock *hwlock;
+	struct resource *res;
+	void __iomem *iobase;
+	struct device_node *node = pdev->dev.of_node;
+	const struct of_device_id *match;
+
+	match = of_match_device(msm_hwspinlock_of_match, &pdev->dev);
+	if (!match)
+		return -EINVAL;
+
+	ret = of_property_read_u32(node, "qcom,num-locks", &num_locks);
+	if (ret || (num_locks == 0))
+		return -ENODEV;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mutex-base");
+	iobase = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(iobase))
+		return PTR_ERR(iobase);
+
+	bank = devm_kzalloc(&pdev->dev,
+		 sizeof(*bank) + num_locks * sizeof(*hwlock), GFP_KERNEL);
+	if (!bank)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, bank);
+
+	for (i = 0, hwlock = &bank->lock[0]; i < num_locks; i++, hwlock++)
+		hwlock->priv = iobase + i * stride;
+
+	ret = hwspin_lock_register(bank, &pdev->dev, &msm_hwspinlock_ops,
+						BASE_ID, num_locks);
+	return ret;
+}
+
+static int msm_hwspinlock_remove(struct platform_device *pdev)
+{
+	struct hwspinlock_device *bank = platform_get_drvdata(pdev);
+	int ret;
+
+	ret = hwspin_lock_unregister(bank);
+	if (ret) {
+		dev_err(&pdev->dev, "%s failed: %d\n", __func__, ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static struct of_device_id msm_hwspinlock_of_match[] = {
+	{
+		.compatible = "qcom,tcsr-mutex",
+		.data = (void *)0x80, /* register stride */
+	},
+	{ },
+};
+
+static struct platform_driver msm_hwspinlock_driver = {
+	.probe		= msm_hwspinlock_probe,
+	.remove		= msm_hwspinlock_remove,
+	.driver		= {
+		.name	= "msm_hwspinlock",
+		.owner	= THIS_MODULE,
+		.of_match_table = msm_hwspinlock_of_match,
+	},
+};
+
+static int __init msm_hwspinlock_init(void)
+{
+	return platform_driver_register(&msm_hwspinlock_driver);
+}
+/* board init code might need to reserve hwspinlocks for predefined purposes */
+postcore_initcall(msm_hwspinlock_init);
+
+static void __exit msm_hwspinlock_exit(void)
+{
+	platform_driver_unregister(&msm_hwspinlock_driver);
+}
+module_exit(msm_hwspinlock_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Hardware spinlock driver for MSM");
+MODULE_AUTHOR("Kumar Gala <[email protected]>");
+MODULE_AUTHOR("Jeffrey Hugo <[email protected]>");
+MODULE_AUTHOR("Eric Holmberg <[email protected]>");
Signature · 6 lines
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

#2 lore raw
Quoted 5 lines · Kumar Gala

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +0 -0
new file mode 100644
index 0000000..ddd6889

Maybe this should go under a new hwspinlock directory?

Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +7 -0
@@ -0,0 +1,20 @@
+Qualcomm MSM Hardware Mutex Block:
+
+The hardware block provides mutexes utilized between different processors
+on the SoC as part of the communication protocol used by these processors.
+
+Required properties:
+- compatible: should be "qcom,tcsr-mutex"
Quoted 8 lines

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt line 15

Quoted 8 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +8 -0
+- reg: Should contain registers location and length of mutex registers
+- reg-names:
+	"mutex-base"  - string to identify mutex registers
+- qcom,num-locks: the number of locks/mutexes supported
+
+Example:
+
+	qcom,tcsr-mutex@fd484000 {

Maybe it should be hw-mutex@fd484000?

Quoted 28 lines
Quoted 28 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +5 -0
+		compatible = "qcom,tcsr-mutex";
+		reg = <0xfd484000 0x1000>;
+		reg-names = "mutex-base";
+		qcom,num-locks = <32>;
+	};
drivers/hwspinlock/msm_hwspinlock.c new file +17 -0
new file mode 100644
index 0000000..c7d80c5
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * 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/err.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/device.h>
Quoted 8 lines

drivers/hwspinlock/msm_hwspinlock.c line 25

Quoted 8 lines
drivers/hwspinlock/msm_hwspinlock.c new file +8 -0
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/hwspinlock.h>
+
+#include <asm/io.h>

<linux/io.h> please.

Quoted 4 lines
Quoted 4 lines
drivers/hwspinlock/msm_hwspinlock.c new file +4 -0
+
+#include "hwspinlock_internal.h"
+
+#define SPINLOCK_ID_APPS_PROC	1
Quoted 8 lines

drivers/hwspinlock/msm_hwspinlock.c line 37

Quoted 8 lines
drivers/hwspinlock/msm_hwspinlock.c new file +8 -0
+#define BASE_ID			0
+
+static int msm_hwspinlock_trylock(struct hwspinlock *lock)
+{
+	void __iomem *lock_addr = lock->priv;
+
+	writel_relaxed(SPINLOCK_ID_APPS_PROC, lock_addr);
+	smp_mb();

Are you sure you don't want mb() instead? What is this barrier for? Comment please.

Quoted 8 lines
Quoted 8 lines
drivers/hwspinlock/msm_hwspinlock.c new file +8 -0
+	return readl_relaxed(lock_addr) == SPINLOCK_ID_APPS_PROC;
+}
+
+static void msm_hwspinlock_unlock(struct hwspinlock *lock)
+{
+	int lock_owner;
+	void __iomem *lock_addr = lock->priv;
+
Quoted 8 lines

drivers/hwspinlock/msm_hwspinlock.c line 53

Quoted 8 lines
drivers/hwspinlock/msm_hwspinlock.c new file +8 -0
+	lock_owner = readl_relaxed(lock_addr);
+	if (lock_owner != SPINLOCK_ID_APPS_PROC) {
+		pr_err("%s: spinlock not owned by Apps (actual owner is %d)\n",
+				__func__, lock_owner);
+	}
+
+	writel_relaxed(0, lock_addr);
+	smp_mb();

Same here. What is smp_mb() for?

Quoted 8 lines

drivers/hwspinlock/msm_hwspinlock.c line 61

Quoted 8 lines
drivers/hwspinlock/msm_hwspinlock.c new file +8 -0
+}
+
+static const struct hwspinlock_ops msm_hwspinlock_ops = {
+	.trylock	= msm_hwspinlock_trylock,
+	.unlock		= msm_hwspinlock_unlock,
+};
+
+static struct of_device_id msm_hwspinlock_of_match[];

Why not just put the match table here then? Also, can it be const?

Quoted 9 lines
Quoted 9 lines
drivers/hwspinlock/msm_hwspinlock.c new file +9 -0
+static int msm_hwspinlock_probe(struct platform_device *pdev)
+{
+	int ret, i, stride;
+	u32 num_locks;
+	struct hwspinlock_device *bank;
+	struct hwspinlock *hwlock;
+	struct resource *res;
+	void __iomem *iobase;
+	struct device_node *node = pdev->dev.of_node;
Quoted 8 lines

drivers/hwspinlock/msm_hwspinlock.c line 78

Quoted 8 lines
drivers/hwspinlock/msm_hwspinlock.c new file +8 -0
+	const struct of_device_id *match;
+
+	match = of_match_device(msm_hwspinlock_of_match, &pdev->dev);
+	if (!match)
+		return -EINVAL;
+
+	ret = of_property_read_u32(node, "qcom,num-locks", &num_locks);
+	if (ret || (num_locks == 0))

Drop useless ().

Quoted 4 lines
Quoted 4 lines
drivers/hwspinlock/msm_hwspinlock.c new file +4 -0
+		return -ENODEV;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mutex-base");
+	iobase = devm_ioremap_resource(&pdev->dev, res);
Quoted 8 lines

drivers/hwspinlock/msm_hwspinlock.c line 90

Quoted 8 lines
drivers/hwspinlock/msm_hwspinlock.c new file +8 -0
+	if (IS_ERR(iobase))
+		return PTR_ERR(iobase);
+
+	bank = devm_kzalloc(&pdev->dev,
+		 sizeof(*bank) + num_locks * sizeof(*hwlock), GFP_KERNEL);
+	if (!bank)
+		return -ENOMEM;
+

Style Nit: Maybe we could grow a local variable to get this to be one line.

	size_t array_size;

	array_size = num_lock * sizeof(*hwlock);
	bank = devm_kzalloc(&pdev->dev, sizeof(*bank) + array_size, GFP_KERNEL);
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
author
#3 lore raw
Quoted 8 lines · Stephen Boyd
Quoted 5 lines · Kumar Gala

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +0 -0
new file mode 100644
index 0000000..ddd6889

Maybe this should go under a new hwspinlock directory?

Will look for Ohad to comment on this.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +9 -0
@@ -0,0 +1,20 @@
+Qualcomm MSM Hardware Mutex Block:
+
+The hardware block provides mutexes utilized between different processors
+on the SoC as part of the communication protocol used by these processors.
+
+Required properties:
+- compatible: should be "qcom,tcsr-mutex"
+- reg: Should contain registers location and length of mutex registers
+- reg-names:
Quoted 8 lines
Quoted 6 lines

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt line 15

Quoted 6 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +6 -0
+	"mutex-base"  - string to identify mutex registers
+- qcom,num-locks: the number of locks/mutexes supported
+
+Example:
+
+	qcom,tcsr-mutex@fd484000 {

Maybe it should be hw-mutex@fd484000?

again, will look for Ohad to make some comment on this.

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +5 -0
+		compatible = "qcom,tcsr-mutex";
+		reg = <0xfd484000 0x1000>;
+		reg-names = "mutex-base";
+		qcom,num-locks = <32>;
+	};
drivers/hwspinlock/msm_hwspinlock.c new file +19 -0
new file mode 100644
index 0000000..c7d80c5
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * 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/err.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
Quoted 8 lines
Quoted 6 lines

drivers/hwspinlock/msm_hwspinlock.c line 25

Quoted 6 lines
drivers/hwspinlock/msm_hwspinlock.c new file +6 -0
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/hwspinlock.h>
+
+#include <asm/io.h>

<linux/io.h> please.

will change, I choice <asm/io.h> since *_relaxed are arm specific.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/hwspinlock/msm_hwspinlock.c new file +7 -0
+
+#include "hwspinlock_internal.h"
+
+#define SPINLOCK_ID_APPS_PROC	1
+#define BASE_ID			0
+
+static int msm_hwspinlock_trylock(struct hwspinlock *lock)
Quoted 8 lines
Quoted 5 lines

drivers/hwspinlock/msm_hwspinlock.c line 37

Quoted 5 lines
drivers/hwspinlock/msm_hwspinlock.c new file +5 -0
+{
+	void __iomem *lock_addr = lock->priv;
+
+	writel_relaxed(SPINLOCK_ID_APPS_PROC, lock_addr);
+	smp_mb();

Are you sure you don't want mb() instead? What is this barrier for? Comment please.

Hopefully, Eric or Jeff can comment.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/hwspinlock/msm_hwspinlock.c new file +10 -0
+	return readl_relaxed(lock_addr) == SPINLOCK_ID_APPS_PROC;
+}
+
+static void msm_hwspinlock_unlock(struct hwspinlock *lock)
+{
+	int lock_owner;
+	void __iomem *lock_addr = lock->priv;
+
+	lock_owner = readl_relaxed(lock_addr);
+	if (lock_owner != SPINLOCK_ID_APPS_PROC) {
Quoted 8 lines
Quoted 6 lines

drivers/hwspinlock/msm_hwspinlock.c line 53

Quoted 6 lines
drivers/hwspinlock/msm_hwspinlock.c new file +6 -0
+		pr_err("%s: spinlock not owned by Apps (actual owner is %d)\n",
+				__func__, lock_owner);
+	}
+
+	writel_relaxed(0, lock_addr);
+	smp_mb();

Same here. What is smp_mb() for?

Hopefully, Eric or Jeff can comment.

Quoted 12 lines
Quoted 9 lines

drivers/hwspinlock/msm_hwspinlock.c line 61

Quoted 9 lines
drivers/hwspinlock/msm_hwspinlock.c new file +8 -0
+}
+
+static const struct hwspinlock_ops msm_hwspinlock_ops = {
+	.trylock	= msm_hwspinlock_trylock,
+	.unlock		= msm_hwspinlock_unlock,
+};
+
+static struct of_device_id msm_hwspinlock_of_match[];

Why not just put the match table here then? Also, can it be const?

Will change and make const

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/hwspinlock/msm_hwspinlock.c new file +11 -0
+static int msm_hwspinlock_probe(struct platform_device *pdev)
+{
+	int ret, i, stride;
+	u32 num_locks;
+	struct hwspinlock_device *bank;
+	struct hwspinlock *hwlock;
+	struct resource *res;
+	void __iomem *iobase;
+	struct device_node *node = pdev->dev.of_node;
+	const struct of_device_id *match;
+
Quoted 8 lines
Quoted 6 lines

drivers/hwspinlock/msm_hwspinlock.c line 78

Quoted 6 lines
drivers/hwspinlock/msm_hwspinlock.c new file +6 -0
+	match = of_match_device(msm_hwspinlock_of_match, &pdev->dev);
+	if (!match)
+		return -EINVAL;
+
+	ret = of_property_read_u32(node, "qcom,num-locks", &num_locks);
+	if (ret || (num_locks == 0))

Drop useless ().

done

Quoted 17 lines
Quoted 13 lines

drivers/hwspinlock/msm_hwspinlock.c line 90

Quoted 13 lines
drivers/hwspinlock/msm_hwspinlock.c new file +12 -0
+		return -ENODEV;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mutex-base");
+	iobase = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(iobase))
+		return PTR_ERR(iobase);
+
+	bank = devm_kzalloc(&pdev->dev,
+		 sizeof(*bank) + num_locks * sizeof(*hwlock), GFP_KERNEL);
+	if (!bank)
+		return -ENOMEM;
+

Style Nit: Maybe we could grow a local variable to get this to be one line.

Quoted 4 lines
	size_t array_size;

	array_size = num_lock * sizeof(*hwlock);
	bank = devm_kzalloc(&pdev->dev, sizeof(*bank) + array_size, GFP_KERNEL);

done

- k

Quoted 8 lines
Signature · 7 lines
-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

#4 lore raw
Quoted 4 lines · Kumar Gala
Quoted 1 line · Stephen Boyd

On 07/29, Kumar Gala wrote:

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

drivers/hwspinlock/msm_hwspinlock.c line 25

Quoted 4 lines
drivers/hwspinlock/msm_hwspinlock.c new file +4 -0
+#include <linux/of_device.h>
+#include <linux/hwspinlock.h>
+
+#include <asm/io.h>

<linux/io.h> please.

will change, I choice <asm/io.h> since *_relaxed are arm specific.

I thought readl_relaxed() was universal for HAS_IOMEM arches. Unfortunately writel_relaxed() isn't defined on all arches. Luckily this driver depends on ARCH_MSM so it isn't a problem.

Perhaps it should just depend on HAS_IOMEM so we can use it on arm64 and/or hexagon in the future without having to change the Kconfig. That would require introducing writel_relaxed() into the other arches that don't have it right now.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
author
#5 lore raw
In reply to Kumar Gala
Quoted 34 lines · Kumar Gala
Quoted 8 lines · Stephen Boyd
Quoted 5 lines · Kumar Gala

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +0 -0
new file mode 100644
index 0000000..ddd6889

Maybe this should go under a new hwspinlock directory?

Will look for Ohad to comment on this.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +9 -0
@@ -0,0 +1,20 @@
+Qualcomm MSM Hardware Mutex Block:
+
+The hardware block provides mutexes utilized between different processors
+on the SoC as part of the communication protocol used by these processors.
+
+Required properties:
+- compatible: should be "qcom,tcsr-mutex"
+- reg: Should contain registers location and length of mutex registers
+- reg-names:
Quoted 8 lines
Quoted 6 lines

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt line 15

Quoted 6 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +6 -0
+	"mutex-base"  - string to identify mutex registers
+- qcom,num-locks: the number of locks/mutexes supported
+
+Example:
+
+	qcom,tcsr-mutex@fd484000 {

Maybe it should be hw-mutex@fd484000?

Quoted 7 lines

again, will look for Ohad to make some comment on this.

Quoted 5 lines
Quoted 5 lines

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt line 20

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +5 -0
+		compatible = "qcom,tcsr-mutex";
+		reg = <0xfd484000 0x1000>;
+		reg-names = "mutex-base";
+		qcom,num-locks = <32>;
+	};

Ohad, ping.

- k

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

#6 lore raw

+ Grant

Quoted 34 lines · Kumar Gala
Quoted 34 lines · Stephen Boyd
Quoted 8 lines · Kumar Gala
Quoted 5 lines

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +0 -0
new file mode 100644
index 0000000..ddd6889

Maybe this should go under a new hwspinlock directory?

Will look for Ohad to comment on this.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +9 -0
@@ -0,0 +1,20 @@
+Qualcomm MSM Hardware Mutex Block:
+
+The hardware block provides mutexes utilized between different processors
+on the SoC as part of the communication protocol used by these processors.
+
+Required properties:
+- compatible: should be "qcom,tcsr-mutex"
+- reg: Should contain registers location and length of mutex registers
+- reg-names:
Quoted 8 lines
Quoted 6 lines

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt line 15

Quoted 6 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +6 -0
+  "mutex-base"  - string to identify mutex registers
+- qcom,num-locks: the number of locks/mutexes supported
+
+Example:
+
+  qcom,tcsr-mutex@fd484000 {

Maybe it should be hw-mutex@fd484000?

again, will look for Ohad to make some comment on this.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt line 20

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +5 -0
+          compatible = "qcom,tcsr-mutex";
+          reg = <0xfd484000 0x1000>;
+          reg-names = "mutex-base";
+          qcom,num-locks = <32>;
+  };

Ohad, ping.

I'd prefer a DT maintainer to take a look at your two open questions above, especially if I'm to merge a new file into the devicetree Documentation folder.

Grant, any chance you have a moment to take a look?

Otherwise, Stephen - do we have your Ack here? I was happy to see your review but not sure what's the latest status.

Thanks,
Ohad.

#7 lore raw
Quoted 2 lines · Ohad Ben-Cohen

Otherwise, Stephen - do we have your Ack here? I was happy to see your review but not sure what's the latest status.

The smp_mb() should be removed. Otherwise I'm willing to accept that we only build this driver on ARCH_MSM for now. We can fix that in the future to be available to hexagon if they ever want it. After that it just needs a DT review/ack so I'll be happy to add a reviewed-by on v3.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
author
#8 lore raw
Quoted 8 lines · Stephen Boyd
Quoted 2 lines · Ohad Ben-Cohen

Otherwise, Stephen - do we have your Ack here? I was happy to see your review but not sure what's the latest status.

The smp_mb() should be removed. Otherwise I'm willing to accept that we only build this driver on ARCH_MSM for now. We can fix that in the future to be available to hexagon if they ever want it. After that it just needs a DT review/ack so I'll be happy to add a reviewed-by on v3.

Yeah, waiting on our DT resolution before posting v3 w/various changes like removing the smp_mb() and a few other things.

- k

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

author
#9 lore raw
In reply to Ohad Ben-Cohen
Quoted 49 lines · Ohad Ben-Cohen

+ Grant

Quoted 34 lines · Kumar Gala
Quoted 34 lines · Stephen Boyd
Quoted 8 lines · Kumar Gala
Quoted 5 lines

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +0 -0
new file mode 100644
index 0000000..ddd6889

Maybe this should go under a new hwspinlock directory?

Will look for Ohad to comment on this.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +9 -0
@@ -0,0 +1,20 @@
+Qualcomm MSM Hardware Mutex Block:
+
+The hardware block provides mutexes utilized between different processors
+on the SoC as part of the communication protocol used by these processors.
+
+Required properties:
+- compatible: should be "qcom,tcsr-mutex"
+- reg: Should contain registers location and length of mutex registers
+- reg-names:
Quoted 8 lines
Quoted 6 lines

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt line 15

Quoted 6 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +6 -0
+  "mutex-base"  - string to identify mutex registers
+- qcom,num-locks: the number of locks/mutexes supported
+
+Example:
+
+  qcom,tcsr-mutex@fd484000 {

Maybe it should be hw-mutex@fd484000?

again, will look for Ohad to make some comment on this.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt line 20

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt new file +5 -0
+          compatible = "qcom,tcsr-mutex";
+          reg = <0xfd484000 0x1000>;
+          reg-names = "mutex-base";
+          qcom,num-locks = <32>;
+  };

Ohad, ping.

I'd prefer a DT maintainer to take a look at your two open questions above, especially if I'm to merge a new file into the devicetree Documentation folder.

Quoted 8 lines

Grant, any chance you have a moment to take a look?

Otherwise, Stephen - do we have your Ack here? I was happy to see your review but not sure what's the latest status.

Thanks,
Ohad.
--

So I think I'd ask you to recommend a name, should we just us 'hwspinlock'. The general view from ePAPR and dts is the node name should be a bit more generic (like ethernet or pci). So what would you suggest?

- k

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

#10 lore raw
Quoted 1 line · Kumar Gala

So I think I'd ask you to recommend a name, should we just us 'hwspinlock'. The general view from ePAPR and dts is the node name should be a bit more generic (like ethernet or pci). So what would you suggest?

How about 'hwlock' ?

This should be generic enough to cover all instances of hardware locks (we already know hwspinlock isn't generic enough, as there are some mutex-like hardware locks which doesn't require busy looping).

author
#11 lore raw
Quoted 8 lines · Ohad Ben-Cohen
Quoted 1 line · Kumar Gala

So I think I'd ask you to recommend a name, should we just us 'hwspinlock'. The general view from ePAPR and dts is the node name should be a bit more generic (like ethernet or pci). So what would you suggest?

How about 'hwlock' ?

This should be generic enough to cover all instances of hardware locks (we already know hwspinlock isn't generic enough, as there are some mutex-like hardware locks which doesn't require busy looping).

hwlock sounds good to me, I'll go with it.

- k

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation