Skip to contentSkip to conversation

drivers: Boot Constraints core

PATCH Superseded Viresh Kumar 4 participants 23 messages Aug 1, 2017 – Sep 19, 2017

Subsystems (3)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover drivers: Boot Constraints core

Hi Greg,

Here is V3 of the boot constraints core based on the feedbacks I have received during V2. This tested on real hardware (Qcom dragonboard 410c) with a display controller configured from bootloader to display a flash screen. Obviously it doesn't work seamlessly without this series and works just fine with it. Rajendra Nayak helped getting this tested on Qcom hardware.

Problem statement:

Some devices are powered ON by the bootloader before the bootloader handovers control to Linux. It maybe important for those devices to keep working until the time a Linux device driver probes the device and reconfigure its resources.

A typical example of that can be the LCD controller, which is used by the bootloaders to show image(s) while the platform is booting into Linux. The LCD controller can be using some resources, like clk, regulators, etc, that are shared between several devices. These shared resources should be configured to satisfy need of all the users. If another device's (X) driver gets probed before the LCD controller driver in this case, then it may end up reconfiguring these resources to ranges satisfying the current users (only device X) and that can make the LCD screen unstable.

Of course we can have more complex cases where the same resource is getting used by two devices while the kernel boots and the order in which devices get probed wouldn't matter as the other device will surely break then.

There are also cases where the resources may not be shared, but the kernel will disable them forcefully as no users may have appeared until a certain point in kernel boot. This makes sure that the resources stay enabled. A wide variety of constraints can be satisfied using the new framework.

Proposed solution:

This patchset introduces the concept of boot-constraints, which are set by platform specific drivers (for now at least) at early init (like subsys_initcall) and the kernel will satisfy them until the time driver for such a device is probed (successfully or unsuccessfully). Once the driver is probed, the driver core removes the constraints set for the device. This series implements clk, regulator and PM domain constraints for now.

The last patch isn't up for merge yet, and is used to test the boot constraint framework on Qcom 410c along with some of the display controller patches from Rob's series [1] to make sure the controller's registers are configured properly.

Rebased over: drivers/driver-core-next (some debugfs dependencies)
Pushed here: git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/linux.git device/boot-constraints

V2->V3:
- Removed DT support as we aren't sure about how to define the bindings yet.
- Added CLK and PM domain constraint types.
- A new directory is added for boot constraints, which will also contain platform specific drivers in future.
- Deferred devices are still supported, just that it wouldn't be called from generic code anymore but platform specific code.
- Tested on Qcom 410c dragonboard with display flash screen (Rajendra).
- Usual renaming/commit-log-updates/etc changes done.

V1->V2:
- Add support for setting constraints for devices created from DT.
- Allow handling deferred devices earlier then late_init.
- Remove 'default y' line from kconfig.
- Drop '=" after boot_constraints_disable kernel param.
- Dropped the dummy testing patch now.

--
viresh

[1] https://marc.info/?l=dri-devel&m=149979722606563&w=2

Rajendra Nayak (1):
drivers: boot_constraint: Add Qualcomm display controller constraints

Viresh Kumar (7):
drivers: Add boot constraints core
drivers: boot_constraint: Add boot_constraints_disable kernel
parameter
drivers: boot_constraint: Add support for supply constraints
drivers: boot_constraint: Add support for clk constraints
drivers: boot_constraint: Add support for PM constraints
drivers: boot_constraint: Add debugfs support
drivers: boot_constraint: Manage deferrable constraints

 Documentation/admin-guide/kernel-parameters.txt |   3 +
 drivers/base/Kconfig                            |  10 +
 drivers/base/Makefile                           |   1 +
 drivers/base/base.h                             |   1 +
 drivers/base/boot_constraints/Makefile          |   3 +
 drivers/base/boot_constraints/clk.c             |  74 ++++++
 drivers/base/boot_constraints/core.c            | 300 ++++++++++++++++++++++++
 drivers/base/boot_constraints/core.h            |  50 ++++
 drivers/base/boot_constraints/deferrable_dev.c  | 192 +++++++++++++++
 drivers/base/boot_constraints/pm.c              |  32 +++
 drivers/base/boot_constraints/qcom-display.c    | 107 +++++++++
 drivers/base/boot_constraints/supply.c          | 108 +++++++++
 drivers/base/dd.c                               |  32 ++-
 include/linux/boot_constraint.h                 |  68 ++++++
 14 files changed, 974 insertions(+), 7 deletions(-)
 create mode 100644 drivers/base/boot_constraints/Makefile
 create mode 100644 drivers/base/boot_constraints/clk.c
 create mode 100644 drivers/base/boot_constraints/core.c
 create mode 100644 drivers/base/boot_constraints/core.h
 create mode 100644 drivers/base/boot_constraints/deferrable_dev.c
 create mode 100644 drivers/base/boot_constraints/pm.c
 create mode 100644 drivers/base/boot_constraints/qcom-display.c
 create mode 100644 drivers/base/boot_constraints/supply.c
 create mode 100644 include/linux/boot_constraint.h
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
#1 lore raw

PATCH v3 1/8 drivers: Add boot constraints core

Some devices are powered ON by the bootloader before the bootloader handovers control to Linux. It maybe important for those devices to keep working until the time a Linux device driver probes the device and reconfigure its resources.

A typical example of that can be the LCD controller, which is used by the bootloaders to show image(s) while the platform is booting into Linux. The LCD controller can be using some resources, like clk, regulators, PM domain, etc, that are shared between several devices. These shared resources should be configured to satisfy need of all the users. If another device's (X) driver gets probed before the LCD controller driver in this case, then it may end up reconfiguring these resources to ranges satisfying the current users (only device X) and that can make the LCD screen unstable.

This patch introduces the concept of boot-constraints, which will be set by the bootloaders and the kernel will satisfy them until the time driver for such a device is probed (successfully or unsuccessfully).

The list of boot constraint types is empty for now, and will be incrementally updated by later patches.

Only two routines are exposed by the boot constraints core for now:

- dev_boot_constraint_add(): This shall be called by parts of the kernel (before the device is probed) to set the constraints.

- dev_boot_constraints_remove(): This is called only by the driver core after a device is probed successfully or unsuccessfully. Special handling is done here for deffered probing.

---
 drivers/base/Kconfig                   |  10 ++
 drivers/base/Makefile                  |   1 +
 drivers/base/boot_constraints/Makefile |   3 +
 drivers/base/boot_constraints/core.c   | 199 +++++++++++++++++++++++++++++++++
 drivers/base/boot_constraints/core.h   |  33 ++++++
 drivers/base/dd.c                      |  20 ++--
 include/linux/boot_constraint.h        |  46 ++++++++
 7 files changed, 305 insertions(+), 7 deletions(-)
 create mode 100644 drivers/base/boot_constraints/Makefile
 create mode 100644 drivers/base/boot_constraints/core.c
 create mode 100644 drivers/base/boot_constraints/core.h
 create mode 100644 include/linux/boot_constraint.h
drivers/base/Kconfig +10 -0
index f046d21de57d..2333db2a33b7 100644
@@ -347,4 +347,14 @@ config GENERIC_ARCH_TOPOLOGY
 	  appropriate scaling, sysfs interface for changing capacity values at
 	  runtime.
 
+config DEV_BOOT_CONSTRAINTS
+	bool "Boot constraints for devices"
+	help
+	  This enables boot constraints detection for devices. These constraints
+	  are (normally) set by the Bootloader and must be satisfied by the
+	  kernel until the relevant device driver is probed. Once the driver is
+	  probed, the constraint is dropped.
+
+	  If unsure, say N.
+
 endmenu
drivers/base/Makefile +1 -0
index 397e5c344e6a..8c37ca07114b 100644
@@ -5,6 +5,7 @@ obj-y			:= component.o core.o bus.o dd.o syscore.o \
 			   cpu.o firmware.o init.o map.o devres.o \
 			   attribute_container.o transport_class.o \
 			   topology.o container.o property.o cacheinfo.o
+obj-$(CONFIG_DEV_BOOT_CONSTRAINTS) += boot_constraints/
 obj-$(CONFIG_DEVTMPFS)	+= devtmpfs.o
 obj-$(CONFIG_DMA_CMA) += dma-contiguous.o
 obj-y			+= power/
drivers/base/boot_constraints/Makefile new file +3 -0
new file mode 100644
index 000000000000..0f2680177974
@@ -0,0 +1,3 @@
+# Makefile for device boot constraints
+
+obj-y := core.o
drivers/base/boot_constraints/core.c new file +199 -0

199 lines not on this page · raw message

drivers/base/boot_constraints/core.h new file +33 -0
new file mode 100644
index 000000000000..7ba4ac172c09
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <[email protected]>
+ *
+ * This file is released under the GPLv2.
+ */
+#ifndef _CORE_H
+#define _CORE_H
+
+#include <linux/boot_constraint.h>
+#include <linux/device.h>
+#include <linux/list.h>
+
+struct constraint_dev {
+	struct device *dev;
+	struct list_head node;
+	struct list_head constraints;
+};
+
+struct constraint {
+	struct constraint_dev *cdev;
+	struct list_head node;
+	enum dev_boot_constraint_type type;
+	void (*free_resources)(void *data);
+	void *free_resources_data;
+
+	int (*add)(struct constraint *constraint, void *data);
+	void (*remove)(struct constraint *constraint);
+	void *private;
+};
+
+/* Forward declarations of constraint specific callbacks */
+#endif /* _CORE_H */
drivers/base/dd.c +13 -7
index c17fefc77345..2262a4a4c0e4 100644
@@ -17,6 +17,7 @@
  * This file is released under the GPLv2
  */
 
+#include <linux/boot_constraint.h>
 #include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
@@ -383,15 +384,20 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 	 */
 	devices_kset_move_last(dev);
 
-	if (dev->bus->probe) {
+	if (dev->bus->probe)
 		ret = dev->bus->probe(dev);
-		if (ret)
-			goto probe_failed;
-	} else if (drv->probe) {
+	else if (drv->probe)
 		ret = drv->probe(dev);
-		if (ret)
-			goto probe_failed;
-	}
+
+	/*
+	 * Remove boot constraints for both successful and unsuccessful probe(),
+	 * except for the case where EPROBE_DEFER is returned by probe().
+	 */
+	if (ret != -EPROBE_DEFER)
+		dev_boot_constraints_remove(dev);
+
+	if (ret)
+		goto probe_failed;
 
 	if (test_remove) {
 		test_remove = false;
include/linux/boot_constraint.h new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.13.0.71.gd7076ec9c9cb
#8 lore raw

PATCH v3 2/8 drivers: boot_constraint: Add boot_constraints_disable kernel parameter

In reply to Viresh Kumar

Users must be given an option to discard any constraints set by bootloaders. For example, consider that a constraint is set for the LCD controller's supply and the LCD driver isn't loaded by the kernel. If the user doesn't need to use the LCD device, then he shouldn't be forced to honour the constraint.

We can also think about finer control of such constraints with help of some sysfs files, but a kernel parameter is fine to begin with.

---
 Documentation/admin-guide/kernel-parameters.txt |  3 +++
 drivers/base/boot_constraints/core.c            | 17 +++++++++++++++++
 2 files changed, 20 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +3 -0
index d9c171ce4190..0706d1b6004d 100644
@@ -426,6 +426,9 @@
 			embedded devices based on command line input.
 			See Documentation/block/cmdline-partition.txt
 
+	boot_constraints_disable
+			Do not set any boot constraints for devices.
+
 	boot_delay=	Milliseconds to delay each printk during boot.
 			Values larger than 10 seconds (10000) are changed to
 			no delay (0).
drivers/base/boot_constraints/core.c +17 -0
index 366a05d6d9ba..e0c33b2b216f 100644
@@ -24,6 +24,17 @@
 static LIST_HEAD(constraint_devices);
 static DEFINE_MUTEX(constraint_devices_mutex);
 
+static bool boot_constraints_disabled;
+
+static int __init constraints_disable(char *str)
+{
+	boot_constraints_disabled = true;
+	pr_debug("disabled\n");
+
+	return 0;
+}
+early_param("boot_constraints_disable", constraints_disable);
+
 /* Boot constraints core */
 
 static struct constraint_dev *constraint_device_find(struct device *dev)
@@ -126,6 +137,9 @@ int dev_boot_constraint_add(struct device *dev,
 	struct constraint *constraint;
 	int ret;
 
+	if (boot_constraints_disabled)
+		return -ENODEV;
+
 	mutex_lock(&constraint_devices_mutex);
 
 	/* Find or add the cdev type first */
@@ -184,6 +198,9 @@ void dev_boot_constraints_remove(struct device *dev)
 	struct constraint_dev *cdev;
 	struct constraint *constraint, *temp;
 
+	if (boot_constraints_disabled)
+		return;
+
 	mutex_lock(&constraint_devices_mutex);
 
 	cdev = constraint_device_find(dev);
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
#13 lore raw

PATCH v3 3/8 drivers: boot_constraint: Add support for supply constraints

In reply to Viresh Kumar

This patch adds the first constraint type: power-supply.

The constraint is set by enabling the regulator and setting a voltage range (if required) for the respective regulator device, which will be honored by the regulator core even if more users turn up. Once the device is probed, the regulator is released and the constraint is removed.

---
 drivers/base/boot_constraints/Makefile |  2 +-
 drivers/base/boot_constraints/core.c   |  4 ++
 drivers/base/boot_constraints/core.h   |  3 ++
 drivers/base/boot_constraints/supply.c | 98 ++++++++++++++++++++++++++++++++++
 include/linux/boot_constraint.h        |  8 ++-
 5 files changed, 113 insertions(+), 2 deletions(-)
 create mode 100644 drivers/base/boot_constraints/supply.c
drivers/base/boot_constraints/Makefile +1 -1
index 0f2680177974..a45616f0c3b0 100644
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := core.o
+obj-y := core.o supply.o
drivers/base/boot_constraints/core.c +4 -0
index e0c33b2b216f..06b618a85c0a 100644
@@ -105,6 +105,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev,
 	void (*remove)(struct constraint *constraint);
 
 	switch (type) {
+	case DEV_BOOT_CONSTRAINT_SUPPLY:
+		add = constraint_supply_add;
+		remove = constraint_supply_remove;
+		break;
 	default:
 		return ERR_PTR(-EINVAL);
 	}
drivers/base/boot_constraints/core.h +3 -0
index 7ba4ac172c09..73b9d2d22a12 100644
@@ -30,4 +30,7 @@ struct constraint {
 };
 
 /* Forward declarations of constraint specific callbacks */
+int constraint_supply_add(struct constraint *constraint, void *data);
+void constraint_supply_remove(struct constraint *constraint);
+
 #endif /* _CORE_H */
drivers/base/boot_constraints/supply.c new file +98 -0

98 lines not on this page · raw message

include/linux/boot_constraint.h +7 -1
index ae34fee547c5..d19b8ec2f10d 100644
@@ -15,7 +15,13 @@
 struct device;
 
 enum dev_boot_constraint_type {
-	DEV_BOOT_CONSTRAINT_NONE,
+	DEV_BOOT_CONSTRAINT_SUPPLY,
+};
+
+struct dev_boot_constraint_supply_info {
+	const char *name;
+	unsigned int u_volt_min;
+	unsigned int u_volt_max;
 };
 
 struct dev_boot_constraint {
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
#14 lore raw

PATCH v3 4/8 drivers: boot_constraint: Add support for clk constraints

In reply to Viresh Kumar

This patch adds the clk constraint type.

The constraint is set by enabling the clk for the device. Once the device is probed, the clk is disabled and the constraint is removed.

We may want to do clk_set_rate() from here, but lets wait for some real users that really want it.

---
 drivers/base/boot_constraints/Makefile |  2 +-
 drivers/base/boot_constraints/clk.c    | 70 ++++++++++++++++++++++++++++++++++
 drivers/base/boot_constraints/core.c   |  4 ++
 drivers/base/boot_constraints/core.h   |  3 ++
 include/linux/boot_constraint.h        |  5 +++
 5 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/boot_constraints/clk.c
drivers/base/boot_constraints/Makefile +1 -1
index a45616f0c3b0..3424379fd1e4 100644
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := core.o supply.o
+obj-y := clk.o core.o supply.o
drivers/base/boot_constraints/clk.c new file +70 -0

70 lines not on this page · raw message

drivers/base/boot_constraints/core.c +4 -0
index 06b618a85c0a..88568ed1bfad 100644
@@ -105,6 +105,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev,
 	void (*remove)(struct constraint *constraint);
 
 	switch (type) {
+	case DEV_BOOT_CONSTRAINT_CLK:
+		add = constraint_clk_add;
+		remove = constraint_clk_remove;
+		break;
 	case DEV_BOOT_CONSTRAINT_SUPPLY:
 		add = constraint_supply_add;
 		remove = constraint_supply_remove;
drivers/base/boot_constraints/core.h +3 -0
index 73b9d2d22a12..4f28ac2ef691 100644
@@ -30,6 +30,9 @@ struct constraint {
 };
 
 /* Forward declarations of constraint specific callbacks */
+int constraint_clk_add(struct constraint *constraint, void *data);
+void constraint_clk_remove(struct constraint *constraint);
+
 int constraint_supply_add(struct constraint *constraint, void *data);
 void constraint_supply_remove(struct constraint *constraint);
 
include/linux/boot_constraint.h +5 -0
index d19b8ec2f10d..a2696002e6e1 100644
@@ -15,9 +15,14 @@
 struct device;
 
 enum dev_boot_constraint_type {
+	DEV_BOOT_CONSTRAINT_CLK,
 	DEV_BOOT_CONSTRAINT_SUPPLY,
 };
 
+struct dev_boot_constraint_clk_info {
+	const char *name;
+};
+
 struct dev_boot_constraint_supply_info {
 	const char *name;
 	unsigned int u_volt_min;
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
#15 lore raw

PATCH v3 5/8 drivers: boot_constraint: Add support for PM constraints

In reply to Viresh Kumar

This patch adds the PM constraint type.

The constraint is set by attaching the power domain for the device, which will also enable the power domain. This guarantees that the power domain doesn't get shut down while being used.

We don't need to detach the power domain to remove the constraint as the domain is attached only once, from here or before driver probe.

---
 drivers/base/boot_constraints/Makefile |  2 +-
 drivers/base/boot_constraints/core.c   |  4 ++++
 drivers/base/boot_constraints/core.h   |  3 +++
 drivers/base/boot_constraints/pm.c     | 24 ++++++++++++++++++++++++
 include/linux/boot_constraint.h        |  1 +
 5 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/boot_constraints/pm.c
drivers/base/boot_constraints/Makefile +1 -1
index 3424379fd1e4..b7ade1a7afb5 100644
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := clk.o core.o supply.o
+obj-y := clk.o core.o pm.o supply.o
drivers/base/boot_constraints/core.c +4 -0
index 88568ed1bfad..06267f0c88d4 100644
@@ -109,6 +109,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev,
 		add = constraint_clk_add;
 		remove = constraint_clk_remove;
 		break;
+	case DEV_BOOT_CONSTRAINT_PM:
+		add = constraint_pm_add;
+		remove = constraint_pm_remove;
+		break;
 	case DEV_BOOT_CONSTRAINT_SUPPLY:
 		add = constraint_supply_add;
 		remove = constraint_supply_remove;
drivers/base/boot_constraints/core.h +3 -0
index 4f28ac2ef691..a051c3d7c8ab 100644
@@ -33,6 +33,9 @@ struct constraint {
 int constraint_clk_add(struct constraint *constraint, void *data);
 void constraint_clk_remove(struct constraint *constraint);
 
+int constraint_pm_add(struct constraint *constraint, void *data);
+void constraint_pm_remove(struct constraint *constraint);
+
 int constraint_supply_add(struct constraint *constraint, void *data);
 void constraint_supply_remove(struct constraint *constraint);
 
drivers/base/boot_constraints/pm.c new file +24 -0
new file mode 100644
index 000000000000..edba5eca5093
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2017 Linaro.
+ * Viresh Kumar <[email protected]>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#define pr_fmt(fmt) "PM Boot Constraints: " fmt
+
+#include <linux/pm_domain.h>
+
+#include "core.h"
+
+int constraint_pm_add(struct constraint *constraint, void *data)
+{
+	struct device *dev = constraint->cdev->dev;
+
+	return dev_pm_domain_attach(dev, true);
+}
+
+void constraint_pm_remove(struct constraint *constraint)
+{
+	/* Nothing to do for now */
+}
include/linux/boot_constraint.h +1 -0
index a2696002e6e1..edc9abe7913a 100644
@@ -16,6 +16,7 @@ struct device;
 
 enum dev_boot_constraint_type {
 	DEV_BOOT_CONSTRAINT_CLK,
+	DEV_BOOT_CONSTRAINT_PM,
 	DEV_BOOT_CONSTRAINT_SUPPLY,
 };
 
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
#16 lore raw

PATCH v3 6/8 drivers: boot_constraint: Add debugfs support

In reply to Viresh Kumar

This patch adds debugfs support for boot constraints. This is how it looks for a "vmmc-supply" constraint for the MMC device.

$ ls -R /sys/kernel/debug/boot_constraints/
/sys/kernel/debug/boot_constraints/:
f723d000.dwmmc0

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0:
clk-ciu pm-domain supply-vmmc supply-vmmcaux

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/clk-ciu:

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/pm-domain:

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmc:
u_volt_max u_volt_min

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmcaux:
u_volt_max u_volt_min

---
 drivers/base/boot_constraints/clk.c    |  4 ++
 drivers/base/boot_constraints/core.c   | 72 ++++++++++++++++++++++++++++++++++
 drivers/base/boot_constraints/core.h   |  6 +++
 drivers/base/boot_constraints/pm.c     | 12 +++++-
 drivers/base/boot_constraints/supply.c | 10 +++++
 5 files changed, 102 insertions(+), 2 deletions(-)
drivers/base/boot_constraints/clk.c +4 -0
index b5b1d63c3e76..bdbfcbc2944d 100644
@@ -49,6 +49,9 @@ int constraint_clk_add(struct constraint *constraint, void *data)
 	cclk->clk_info.name = kstrdup_const(clk_info->name, GFP_KERNEL);
 	constraint->private = cclk;
 
+	/* Debugfs */
+	constraint_add_debugfs(constraint, clk_info->name);
+
 	return 0;
 
 put_clk:
@@ -63,6 +66,7 @@ void constraint_clk_remove(struct constraint *constraint)
 {
 	struct constraint_clk *cclk = constraint->private;
 
+	constraint_remove_debugfs(constraint);
 	kfree_const(cclk->clk_info.name);
 	clk_disable_unprepare(cclk->clk);
 	clk_put(cclk->clk);
drivers/base/boot_constraints/core.c +72 -0

90 lines not on this page · raw message

drivers/base/boot_constraints/core.h +6 -0
index a051c3d7c8ab..ee84e237c66a 100644
@@ -8,6 +8,7 @@
 #define _CORE_H
 
 #include <linux/boot_constraint.h>
+#include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/list.h>
 
@@ -15,6 +16,7 @@ struct constraint_dev {
 	struct device *dev;
 	struct list_head node;
 	struct list_head constraints;
+	struct dentry *dentry;
 };
 
 struct constraint {
@@ -23,12 +25,16 @@ struct constraint {
 	enum dev_boot_constraint_type type;
 	void (*free_resources)(void *data);
 	void *free_resources_data;
+	struct dentry *dentry;
 
 	int (*add)(struct constraint *constraint, void *data);
 	void (*remove)(struct constraint *constraint);
 	void *private;
 };
 
+void constraint_add_debugfs(struct constraint *constraint, const char *suffix);
+void constraint_remove_debugfs(struct constraint *constraint);
+
 /* Forward declarations of constraint specific callbacks */
 int constraint_clk_add(struct constraint *constraint, void *data);
 void constraint_clk_remove(struct constraint *constraint);
drivers/base/boot_constraints/pm.c +10 -2
index edba5eca5093..95910d0dc457 100644
@@ -14,11 +14,19 @@
 int constraint_pm_add(struct constraint *constraint, void *data)
 {
 	struct device *dev = constraint->cdev->dev;
+	int ret;
 
-	return dev_pm_domain_attach(dev, true);
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret)
+		return ret;
+
+	/* Debugfs */
+	constraint_add_debugfs(constraint, "domain");
+
+	return 0;
 }
 
 void constraint_pm_remove(struct constraint *constraint)
 {
-	/* Nothing to do for now */
+	constraint_remove_debugfs(constraint);
 }
drivers/base/boot_constraints/supply.c +10 -0
index 30f816dbf12c..b206f500b2bc 100644
@@ -60,6 +60,15 @@ int constraint_supply_add(struct constraint *constraint, void *data)
 	csupply->supply.name = kstrdup_const(supply->name, GFP_KERNEL);
 	constraint->private = csupply;
 
+	/* Debugfs */
+	constraint_add_debugfs(constraint, supply->name);
+
+	debugfs_create_u32("u_volt_min", 0444, constraint->dentry,
+			   &csupply->supply.u_volt_min);
+
+	debugfs_create_u32("u_volt_max", 0444, constraint->dentry,
+			   &csupply->supply.u_volt_max);
+
 	return 0;
 
 remove_voltage:
@@ -80,6 +89,7 @@ void constraint_supply_remove(struct constraint *constraint)
 	struct device *dev = constraint->cdev->dev;
 	int ret;
 
+	constraint_remove_debugfs(constraint);
 	kfree_const(supply->name);
 
 	ret = regulator_disable(csupply->reg);
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
#19 lore raw

PATCH v3 7/8 drivers: boot_constraint: Manage deferrable constraints

In reply to Viresh Kumar

It is possible that some of the resources aren't available at the time constraints are getting set and the boot constraints core will return -EPROBE_DEFER for them. In order to retry adding the constraints at a later point of time (after the resource is added and before any of its users come up), this patch proposes two things:

- Each constraint is represented by a virtual platform device, so that it is re-probed again until the time all the dependencies aren't met. The platform device is removed along with the constraint, with help of the free_resources() callback.

- Enable early defer probing support by calling driver_enable_deferred_probe(), so that the core retries probing deferred devices every time any device is bound to a driver. This makes sure that the constraint is set before any of the users of the resources come up.

This is tested on ARM64 Hikey board where probe was deferred for a device.

---
 drivers/base/base.h                            |   1 +
 drivers/base/boot_constraints/Makefile         |   2 +-
 drivers/base/boot_constraints/core.c           |   2 +-
 drivers/base/boot_constraints/core.h           |   2 +
 drivers/base/boot_constraints/deferrable_dev.c | 192 +++++++++++++++++++++++++
 drivers/base/dd.c                              |  12 ++
 include/linux/boot_constraint.h                |  10 ++
 7 files changed, 219 insertions(+), 2 deletions(-)
 create mode 100644 drivers/base/boot_constraints/deferrable_dev.c
drivers/base/base.h +1 -0
index 539432a14b5c..9c117f0dc44c 100644
@@ -131,6 +131,7 @@ extern char *make_class_name(const char *name, struct kobject *kobj);
 extern int devres_release_all(struct device *dev);
 extern void device_block_probing(void);
 extern void device_unblock_probing(void);
+extern void driver_enable_deferred_probe(void);
 
 /* /sys/devices directory */
 extern struct kset *devices_kset;
drivers/base/boot_constraints/Makefile +1 -1
index b7ade1a7afb5..a765094623a3 100644
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := clk.o core.o pm.o supply.o
+obj-y := clk.o deferrable_dev.o core.o pm.o supply.o
drivers/base/boot_constraints/core.c +1 -1
index c0e3a85ff85a..8e2f9b8fe80f 100644
@@ -24,7 +24,7 @@
 static LIST_HEAD(constraint_devices);
 static DEFINE_MUTEX(constraint_devices_mutex);
 
-static bool boot_constraints_disabled;
+bool boot_constraints_disabled;
 
 static int __init constraints_disable(char *str)
 {
drivers/base/boot_constraints/core.h +2 -0
index ee84e237c66a..41354f7206bf 100644
@@ -32,6 +32,8 @@ struct constraint {
 	void *private;
 };
 
+extern bool boot_constraints_disabled;
+
 void constraint_add_debugfs(struct constraint *constraint, const char *suffix);
 void constraint_remove_debugfs(struct constraint *constraint);
 
drivers/base/boot_constraints/deferrable_dev.c new file +192 -0

192 lines not on this page · raw message

drivers/base/dd.c +12 -0
index 2262a4a4c0e4..62a8a22f8b04 100644
@@ -204,6 +204,18 @@ void device_unblock_probing(void)
 }
 
 /**
+ * driver_enable_deferred_probe() - Enable probing of deferred devices
+ *
+ * We don't want to get in the way when the bulk of drivers are getting probed
+ * and so deferred probe is disabled in the beginning. Enable it now because we
+ * need it.
+ */
+void driver_enable_deferred_probe(void)
+{
+	driver_deferred_probe_enable = true;
+}
+
+/**
  * deferred_probe_initcall() - Enable probing of deferred devices
  *
  * We don't want to get in the way when the bulk of drivers are getting probed.
include/linux/boot_constraint.h +10 -0
index edc9abe7913a..f66c2f6d14dc 100644
@@ -47,12 +47,22 @@ struct dev_boot_constraint_info {
 int dev_boot_constraint_add(struct device *dev,
 			    struct dev_boot_constraint_info *info);
 void dev_boot_constraints_remove(struct device *dev);
+int dev_boot_constraint_add_deferrable(struct device *dev,
+			struct dev_boot_constraint *constraints, int count);
+int dev_boot_constraint_add_of_deferrable(const char *compatible,
+			struct dev_boot_constraint *constraints, int count);
 #else
 static inline
 int dev_boot_constraint_add(struct device *dev,
 			    struct dev_boot_constraint_info *info);
 { return -EINVAL; }
 static inline void dev_boot_constraints_remove(struct device *dev) {}
+static inline int dev_boot_constraint_add_deferrable(struct device *dev,
+			struct dev_boot_constraint *constraints, int count)
+{ return -EINVAL; }
+static inline int dev_boot_constraint_add_of_deferrable(const char *compatible,
+			struct dev_boot_constraint *constraints, int count)
+{ return -EINVAL; }
 #endif /* CONFIG_DEV_BOOT_CONSTRAINTS */
 
 #endif /* _LINUX_BOOT_CONSTRAINT_H */
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
#20 lore raw

PATCH v3 8/8 drivers: boot_constraint: Add Qualcomm display controller constraints

In reply to Viresh Kumar

From: Rajendra Nayak <[email protected]>

NOT TO BE MERGED

This sets boot constraints for the display controller used on Qualcomm dragonboard 410c.

---
 drivers/base/boot_constraints/Makefile       |   2 +-
 drivers/base/boot_constraints/qcom-display.c | 107 +++++++++++++++++++++++++++
 2 files changed, 108 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/boot_constraints/qcom-display.c
drivers/base/boot_constraints/Makefile +1 -1
index a765094623a3..b0bdf67ebbbf 100644
@@ -1,3 +1,3 @@
 # Makefile for device boot constraints
 
-obj-y := clk.o deferrable_dev.o core.o pm.o supply.o
+obj-y := clk.o deferrable_dev.o core.o pm.o supply.o qcom-display.o
drivers/base/boot_constraints/qcom-display.c new file +107 -0

107 lines not on this page · raw message

Signature · 1 line
2.13.0.71.gd7076ec9c9cb
#17 lore raw

Re: [PATCH V3 6/8] drivers: boot_constraint: Add debugfs support

In reply to Viresh Kumar
Quoted 14 lines · Viresh Kumar

This patch adds debugfs support for boot constraints. This is how it looks for a "vmmc-supply" constraint for the MMC device.

$ ls -R /sys/kernel/debug/boot_constraints/
/sys/kernel/debug/boot_constraints/:
f723d000.dwmmc0

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0:
clk-ciu pm-domain supply-vmmc supply-vmmcaux

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/clk-ciu:

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/pm-domain:

Quoted 8 lines

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmc:
u_volt_max u_volt_min

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmcaux:
u_volt_max u_volt_min

Minor debugfs api interaction nits below:

Quoted 13 lines
---
 drivers/base/boot_constraints/clk.c    |  4 ++
 drivers/base/boot_constraints/core.c   | 72 ++++++++++++++++++++++++++++++++++
 drivers/base/boot_constraints/core.h   |  6 +++
 drivers/base/boot_constraints/pm.c     | 12 +++++-
 drivers/base/boot_constraints/supply.c | 10 +++++
 5 files changed, 102 insertions(+), 2 deletions(-)
drivers/base/boot_constraints/clk.c +0 -0
index b5b1d63c3e76..bdbfcbc2944d 100644

drivers/base/boot_constraints/clk.c int constraint_clk_add(struct constraint *constraint, void *data) · line 52

Quoted 4 lines
drivers/base/boot_constraints/clk.c +1 -0
@@ -49,6 +49,9 @@ int constraint_clk_add(struct constraint *constraint, void *data)
 	cclk->clk_info.name = kstrdup_const(clk_info->name, GFP_KERNEL);
 	constraint->private = cclk;
 
+	/* Debugfs */

That's obvious no need for the comment...

Quoted 22 lines
drivers/base/boot_constraints/clk.c +3 -0
+	constraint_add_debugfs(constraint, clk_info->name);
+
 	return 0;
 
 put_clk:
@@ -63,6 +66,7 @@ void constraint_clk_remove(struct constraint *constraint)
 {
 	struct constraint_clk *cclk = constraint->private;
 
+	constraint_remove_debugfs(constraint);
 	kfree_const(cclk->clk_info.name);
 	clk_disable_unprepare(cclk->clk);
 	clk_put(cclk->clk);
drivers/base/boot_constraints/core.c +1 -0
index 06267f0c88d4..c0e3a85ff85a 100644
@@ -35,6 +35,76 @@ static int __init constraints_disable(char *str)
 }
 early_param("boot_constraints_disable", constraints_disable);
 
+/* Debugfs */

drivers/base/boot_constraints/core.c static int __init constraints_disable(char *str) · line 48

Quoted 10 lines
drivers/base/boot_constraints/core.c +10 -0
+
+static struct dentry *rootdir;
+
+static void constraint_device_add_debugfs(struct constraint_dev *cdev)
+{
+	struct device *dev = cdev->dev;
+
+	cdev->dentry = debugfs_create_dir(dev_name(dev), rootdir);
+	if (!cdev->dentry)
+		dev_err(dev, "Failed to create constraint dev debugfs dir\n");

No, you never need to check the return value of a debugfs call. You shouldn't care what happens here, it's just debugfs, a user can't do anything with this info, and neither should you change your actions (which you aren't here, which is good, but not true later on...)

So just call the function, save the value, and move on, it's always going to return a value that you can use in any future debugfs calls, no need to care.

Quoted 25 lines
drivers/base/boot_constraints/core.c +25 -0
+}
+
+static void constraint_device_remove_debugfs(struct constraint_dev *cdev)
+{
+	debugfs_remove_recursive(cdev->dentry);
+}
+
+void constraint_add_debugfs(struct constraint *constraint, const char *suffix)
+{
+	struct device *dev = constraint->cdev->dev;
+	const char *prefix;
+	char name[NAME_MAX];
+
+	switch (constraint->type) {
+	case DEV_BOOT_CONSTRAINT_CLK:
+		prefix = "clk";
+		break;
+	case DEV_BOOT_CONSTRAINT_PM:
+		prefix = "pm";
+		break;
+	case DEV_BOOT_CONSTRAINT_SUPPLY:
+		prefix = "supply";
+		break;
+	default:
+		dev_err(dev, "%s: Constraint type (%d) not supported\n",

drivers/base/boot_constraints/core.c static int __init constraints_disable(char *str) · line 83

Quoted 10 lines
drivers/base/boot_constraints/core.c +10 -0
+			__func__, constraint->type);
+		return;
+	}
+
+	snprintf(name, NAME_MAX, "%s-%s", prefix, suffix);
+
+	constraint->dentry = debugfs_create_dir(name, constraint->cdev->dentry);
+	if (!constraint->dentry)
+		dev_err(dev, "Failed to create constraint (%s) debugfs dir\n",
+			name);

Again, you don't care, just call it and move on.

Quoted 7 lines
drivers/base/boot_constraints/core.c +7 -0
+}
+
+void constraint_remove_debugfs(struct constraint *constraint)
+{
+	debugfs_remove_recursive(constraint->dentry);
+}
+

drivers/base/boot_constraints/core.c static int __init constraints_disable(char *str) · line 100

Quoted 10 lines
drivers/base/boot_constraints/core.c +10 -0
+static int __init constraint_debugfs_init(void)
+{
+	if (boot_constraints_disabled)
+		return -ENODEV;
+
+	/* Create /sys/kernel/debug/opp directory */
+	rootdir = debugfs_create_dir("boot_constraints", NULL);
+	if (!rootdir) {
+		pr_err("Failed to create root directory\n");
+		return -ENOMEM;

And again, you don't care, call it and move on, don't return an incorrect value like this :)

Quoted 68 lines
drivers/base/boot_constraints/core.c +9 -0
+	}
+
+	return 0;
+}
+core_initcall(constraint_debugfs_init);
+
+
 /* Boot constraints core */
 
 static struct constraint_dev *constraint_device_find(struct device *dev)
@@ -62,12 +132,14 @@ static struct constraint_dev *constraint_device_allocate(struct device *dev)
 	INIT_LIST_HEAD(&cdev->constraints);
 
 	list_add(&cdev->node, &constraint_devices);
+	constraint_device_add_debugfs(cdev);
 
 	return cdev;
 }
 
 static void constraint_device_free(struct constraint_dev *cdev)
 {
+	constraint_device_remove_debugfs(cdev);
 	list_del(&cdev->node);
 	kfree(cdev);
 }
drivers/base/boot_constraints/core.h +6 -0
index a051c3d7c8ab..ee84e237c66a 100644
@@ -8,6 +8,7 @@
 #define _CORE_H
 
 #include <linux/boot_constraint.h>
+#include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/list.h>
 
@@ -15,6 +16,7 @@ struct constraint_dev {
 	struct device *dev;
 	struct list_head node;
 	struct list_head constraints;
+	struct dentry *dentry;
 };
 
 struct constraint {
@@ -23,12 +25,16 @@ struct constraint {
 	enum dev_boot_constraint_type type;
 	void (*free_resources)(void *data);
 	void *free_resources_data;
+	struct dentry *dentry;
 
 	int (*add)(struct constraint *constraint, void *data);
 	void (*remove)(struct constraint *constraint);
 	void *private;
 };
 
+void constraint_add_debugfs(struct constraint *constraint, const char *suffix);
+void constraint_remove_debugfs(struct constraint *constraint);
+
 /* Forward declarations of constraint specific callbacks */
 int constraint_clk_add(struct constraint *constraint, void *data);
 void constraint_clk_remove(struct constraint *constraint);
drivers/base/boot_constraints/pm.c +0 -0
index edba5eca5093..95910d0dc457 100644
@@ -14,11 +14,19 @@
 int constraint_pm_add(struct constraint *constraint, void *data)

drivers/base/boot_constraints/pm.c line 23

Quoted 10 lines
drivers/base/boot_constraints/pm.c +6 -1
 {
 	struct device *dev = constraint->cdev->dev;
+	int ret;
 
-	return dev_pm_domain_attach(dev, true);
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret)
+		return ret;
+
+	/* Debugfs */

Again, obvious comment, no need to have it.

Quoted 16 lines
drivers/base/boot_constraints/pm.c +4 -1
+	constraint_add_debugfs(constraint, "domain");
+
+	return 0;
 }
 
 void constraint_pm_remove(struct constraint *constraint)
 {
-	/* Nothing to do for now */
+	constraint_remove_debugfs(constraint);
 }
drivers/base/boot_constraints/supply.c +0 -0
index 30f816dbf12c..b206f500b2bc 100644
@@ -60,6 +60,15 @@ int constraint_supply_add(struct constraint *constraint, void *data)
 	csupply->supply.name = kstrdup_const(supply->name, GFP_KERNEL);

drivers/base/boot_constraints/supply.c int constraint_supply_add(struct constraint *constraint, void *data) · line 70

Quoted 10 lines
drivers/base/boot_constraints/supply.c +8 -0
 	constraint->private = csupply;
 
+	/* Debugfs */
+	constraint_add_debugfs(constraint, supply->name);
+
+	debugfs_create_u32("u_volt_min", 0444, constraint->dentry,
+			   &csupply->supply.u_volt_min);
+
+	debugfs_create_u32("u_volt_max", 0444, constraint->dentry,
+			   &csupply->supply.u_volt_max);

See, that's how you do it!

thanks,

greg k-h

#9 lore raw

Re: [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter

In reply to Viresh Kumar
Quoted 21 lines · Viresh Kumar

Users must be given an option to discard any constraints set by bootloaders. For example, consider that a constraint is set for the LCD controller's supply and the LCD driver isn't loaded by the kernel. If the user doesn't need to use the LCD device, then he shouldn't be forced to honour the constraint.

We can also think about finer control of such constraints with help of some sysfs files, but a kernel parameter is fine to begin with.

---
 Documentation/admin-guide/kernel-parameters.txt |  3 +++
 drivers/base/boot_constraints/core.c            | 17 +++++++++++++++++
 2 files changed, 20 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +0 -0
index d9c171ce4190..0706d1b6004d 100644

Documentation/admin-guide/kernel-parameters.txt line 430

Quoted 5 lines
Documentation/admin-guide/kernel-parameters.txt +2 -0
@@ -426,6 +426,9 @@
 			embedded devices based on command line input.
 			See Documentation/block/cmdline-partition.txt
 
+	boot_constraints_disable
+			Do not set any boot constraints for devices.

Shouldn't that be the default? As really, that is what the situation is today, why force everyone to always enable the disable value? And enabling a value to disable something is usually a sign of bad naming...

drivers/base/boot_constraints/core.c line 27

Quoted 13 lines
Documentation/admin-guide/kernel-parameters.txt +1 -0
+
 	boot_delay=	Milliseconds to delay each printk during boot.
 			Values larger than 10 seconds (10000) are changed to
 			no delay (0).
drivers/base/boot_constraints/core.c +1 -0
index 366a05d6d9ba..e0c33b2b216f 100644
@@ -24,6 +24,17 @@
 static LIST_HEAD(constraint_devices);
 static DEFINE_MUTEX(constraint_devices_mutex);
 
+static bool boot_constraints_disabled;

Again, this should only be an "enable" type of option, that kicks in if you are using this type of bootloader/kernel interaction. Don't force someone to disable it.

thanks,

greg k-h

#2 lore raw

Re: [PATCH V3 1/8] drivers: Add boot constraints core

In reply to Viresh Kumar
Quoted 22 lines · Viresh Kumar

Some devices are powered ON by the bootloader before the bootloader handovers control to Linux. It maybe important for those devices to keep working until the time a Linux device driver probes the device and reconfigure its resources.

A typical example of that can be the LCD controller, which is used by the bootloaders to show image(s) while the platform is booting into Linux. The LCD controller can be using some resources, like clk, regulators, PM domain, etc, that are shared between several devices. These shared resources should be configured to satisfy need of all the users. If another device's (X) driver gets probed before the LCD controller driver in this case, then it may end up reconfiguring these resources to ranges satisfying the current users (only device X) and that can make the LCD screen unstable.

This patch introduces the concept of boot-constraints, which will be set by the bootloaders and the kernel will satisfy them until the time driver for such a device is probed (successfully or unsuccessfully).

The list of boot constraint types is empty for now, and will be incrementally updated by later patches.

Quoted 8 lines

Only two routines are exposed by the boot constraints core for now:

- dev_boot_constraint_add(): This shall be called by parts of the kernel (before the device is probed) to set the constraints.

- dev_boot_constraints_remove(): This is called only by the driver core after a device is probed successfully or unsuccessfully. Special handling is done here for deffered probing.

How is this information getting to the kernel from the bootloader? I didn't see where that happened, just a single example driver that somehow "knew" what had to happen, which seems odd...

This is a lot of new code for no users, I would like to see at least 3 real drivers that are using it before we merge it, as then you have a chance of getting the user/kernel api correct.

thanks,

greg k-h

#10 lore raw

Re: [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter

In reply to Greg Kroah-Hartman
Quoted 44 lines · Greg Kroah-Hartman
Quoted 21 lines · Viresh Kumar

Users must be given an option to discard any constraints set by bootloaders. For example, consider that a constraint is set for the LCD controller's supply and the LCD driver isn't loaded by the kernel. If the user doesn't need to use the LCD device, then he shouldn't be forced to honour the constraint.

We can also think about finer control of such constraints with help of some sysfs files, but a kernel parameter is fine to begin with.

---
 Documentation/admin-guide/kernel-parameters.txt |  3 +++
 drivers/base/boot_constraints/core.c            | 17 +++++++++++++++++
 2 files changed, 20 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +0 -0
index d9c171ce4190..0706d1b6004d 100644

Documentation/admin-guide/kernel-parameters.txt line 430

Quoted 5 lines
Documentation/admin-guide/kernel-parameters.txt +2 -0
@@ -426,6 +426,9 @@
 			embedded devices based on command line input.
 			See Documentation/block/cmdline-partition.txt
 
+	boot_constraints_disable
+			Do not set any boot constraints for devices.

Shouldn't that be the default? As really, that is what the situation is today, why force everyone to always enable the disable value? And enabling a value to disable something is usually a sign of bad naming...

Quoted 12 lines
Documentation/admin-guide/kernel-parameters.txt +1 -0
+
 	boot_delay=	Milliseconds to delay each printk during boot.
 			Values larger than 10 seconds (10000) are changed to
 			no delay (0).
drivers/base/boot_constraints/core.c +0 -0
index 366a05d6d9ba..e0c33b2b216f 100644
@@ -24,6 +24,17 @@
 static LIST_HEAD(constraint_devices);
 static DEFINE_MUTEX(constraint_devices_mutex);
 
Quoted 5 lines

drivers/base/boot_constraints/core.c line 27

Quoted 1 line
drivers/base/boot_constraints/core.c +1 -0
+static bool boot_constraints_disabled;

Again, this should only be an "enable" type of option, that kicks in if you are using this type of bootloader/kernel interaction. Don't force someone to disable it.

I might add that "disable" type options lead to annoying double negatives. Regardless of the default, I'd generally prefer "enable" type options that you enable/disable as needed.

BR,
Jani.

Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
#3 lore raw

Re: [PATCH V3 1/8] drivers: Add boot constraints core

In reply to Greg Kroah-Hartman
Quoted 3 lines · Greg Kroah-Hartman

How is this information getting to the kernel from the bootloader? I didn't see where that happened, just a single example driver that somehow "knew" what had to happen, which seems odd...

I tried to do it with DT earlier, but we couldn't reach to an agreement on what bindings to add and so this series started doing things the old way. The kernel would have platform specific drivers, which would exactly know what constraints to set and we wouldn't need the bootloaders to pass anything for now.

Quoted 1 line

This is a lot of new code for no users,

I agree and so added the patch 8/8 to show a real user. I will convert that to a patch going forward, which can be merged along with this series.

Quoted 3 lines

I would like to see at least 3
real drivers that are using it before we merge it, as then you have a chance of getting the user/kernel api correct.

Hmm, so I am quite sure that this is a fairly generic problem to solve, specifically for all the handheld devices. I can get code for few of the Qcom SoCs but they may end up using the same platform driver. Not sure if I can get code for multiple SoC families in the beginning.

Signature · 1 line
viresh
#11 lore raw

Re: [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter

In reply to Greg Kroah-Hartman
Quoted 7 lines · Greg Kroah-Hartman

Documentation/admin-guide/kernel-parameters.txt line 430

Quoted 2 lines · Viresh Kumar
Documentation/admin-guide/kernel-parameters.txt +2 -0
+	boot_constraints_disable
+			Do not set any boot constraints for devices.

Shouldn't that be the default? As really, that is what the situation is today, why force everyone to always enable the disable value? And enabling a value to disable something is usually a sign of bad naming...

I will explain once again how it is getting used and then will do whatever you suggest.

- Platforms that don't need boot constraints should not enable the CONFIG in the first place. Though we use the same kernel image on multiple hardware types many times.
- If a platform doesn't have a platform-specific driver that adds constraints at boot, then the boot constraint core wouldn't get into picture at all and it is as good as being disabled.
- And the above boot-argument (boot_constraints_disable) is used ONLY in the case where the platform driver is adding boot constraints at runtime.

So, the boot-constraints are disabled by default for everyone even if the configuration is enabled. And that's why I named it the way it is right now.

Do you still feel that it needs to be renamed?

Signature · 1 line
viresh
#18 lore raw

Re: [PATCH V3 6/8] drivers: boot_constraint: Add debugfs support

In reply to Greg Kroah-Hartman
Quoted 18 lines · Greg Kroah-Hartman
Quoted 17 lines · Viresh Kumar

This patch adds debugfs support for boot constraints. This is how it looks for a "vmmc-supply" constraint for the MMC device.

$ ls -R /sys/kernel/debug/boot_constraints/
/sys/kernel/debug/boot_constraints/:
f723d000.dwmmc0

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0:
clk-ciu pm-domain supply-vmmc supply-vmmcaux

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/clk-ciu:

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/pm-domain:

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmc:
u_volt_max u_volt_min

Quoted 7 lines
Quoted 5 lines

/sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmcaux:
u_volt_max u_volt_min

Minor debugfs api interaction nits below:

All accepted :)

Signature · 1 line
viresh
#12 lore raw

Re: [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter

In reply to Viresh Kumar
Quoted 9 lines · Viresh Kumar
Quoted 7 lines · Greg Kroah-Hartman

Documentation/admin-guide/kernel-parameters.txt line 430

Quoted 2 lines · Viresh Kumar
Documentation/admin-guide/kernel-parameters.txt +2 -0
+	boot_constraints_disable
+			Do not set any boot constraints for devices.

Shouldn't that be the default? As really, that is what the situation is today, why force everyone to always enable the disable value? And enabling a value to disable something is usually a sign of bad naming...

Quoted 6 lines

I will explain once again how it is getting used and then will do whatever you suggest.

- Platforms that don't need boot constraints should not enable the CONFIG in the first place. Though we use the same kernel image on multiple hardware types many times.

Right, which means this is useless as an option, don't ever rely on it :)

Quoted 3 lines

- If a platform doesn't have a platform-specific driver that adds constraints at boot, then the boot constraint core wouldn't get into picture at all and it is as good as being disabled.

Possibly, but see above for the goal of one kernel image, many different devices.

Quoted 7 lines

- And the above boot-argument (boot_constraints_disable) is used ONLY in the case where the platform driver is adding boot constraints at runtime.

So, the boot-constraints are disabled by default for everyone even if the configuration is enabled. And that's why I named it the way it is right now.

Do you still feel that it needs to be renamed?

Well, negative options are ackward (although usb_disable is an option...) It still feels wrong, and I worry about the above single-image goal...

#4 lore raw

Re: [PATCH V3 1/8] drivers: Add boot constraints core

In reply to Viresh Kumar
Quoted 9 lines · Viresh Kumar
Quoted 3 lines · Greg Kroah-Hartman

How is this information getting to the kernel from the bootloader? I didn't see where that happened, just a single example driver that somehow "knew" what had to happen, which seems odd...

I tried to do it with DT earlier, but we couldn't reach to an agreement on what bindings to add and so this series started doing things the old way. The kernel would have platform specific drivers, which would exactly know what constraints to set and we wouldn't need the bootloaders to pass anything for now.

Who couldn't reach an agreement? So you gave up and decided to make a whole bunch of kernel code instead of just using new DT entries? That's crazy...

Quoted 5 lines
Quoted 1 line

This is a lot of new code for no users,

I agree and so added the patch 8/8 to show a real user. I will convert that to a patch going forward, which can be merged along with this series.

Quoted 8 lines
Quoted 3 lines

I would like to see at least 3
real drivers that are using it before we merge it, as then you have a chance of getting the user/kernel api correct.

Hmm, so I am quite sure that this is a fairly generic problem to solve, specifically for all the handheld devices. I can get code for few of the Qcom SoCs but they may end up using the same platform driver. Not sure if I can get code for multiple SoC families in the beginning.

Let's see a working system or two first here please.

But you are implying that existing handheld devices need this problem solved, how do they do it today without this code as obviously they are shipping working solutions.

thanks,

greg k-h

#5 lore raw

Re: [PATCH V3 1/8] drivers: Add boot constraints core

Quoted 1 line · Greg Kroah-Hartman

Who couldn't reach an agreement?

Rob Herring (DT Maintainer) didn't like the first set of bindings and wasn't convinced that we need any new bindings for this purpose to begin with.

Quoted 3 lines

So you gave up and decided to make a
whole bunch of kernel code instead of just using new DT entries? That's crazy...

Its not a lot really. Most of the code is anyways required, the only extra part is the platform specific drivers, which are replacing what the DT would have done. So, it shouldn't be that big of a deal I suppose.

Quoted 1 line

Let's see a working system or two first here please.

Sure, I will get as many converted as possible.

Quoted 3 lines

But you are implying that existing handheld devices need this problem solved, how do they do it today without this code as obviously they are shipping working solutions.

So yeah, LCD is a common usecase but the configurations aren't always shared. It may not be an issue with private clock/regulator resources, but with shared ones.

Though even with the private resources, we may want the clock/domains/regulators to stay powered on and I assume that the platforms would be doing hacky stuff to get that all working right now.

Signature · 1 line
viresh
#6 lore raw

Re: [PATCH V3 1/8] drivers: Add boot constraints core

Quoted 5 lines · Viresh Kumar
Quoted 1 line · Greg Kroah-Hartman

Who couldn't reach an agreement?

Rob Herring (DT Maintainer) didn't like the first set of bindings and wasn't convinced that we need any new bindings for this purpose to begin with.

So Rob wanted more kernel code and less bindings? Ok, I'll ask for Rob to sign off on these patches then :)

Quoted 11 lines
Quoted 3 lines

But you are implying that existing handheld devices need this problem solved, how do they do it today without this code as obviously they are shipping working solutions.

So yeah, LCD is a common usecase but the configurations aren't always shared. It may not be an issue with private clock/regulator resources, but with shared ones.

Though even with the private resources, we may want the clock/domains/regulators to stay powered on and I assume that the platforms would be doing hacky stuff to get that all working right now.

As you have the source for a number of such systems, you might want to verify this please. Also, what is going to cause any new systems to use this new api?

thanks,

greg k-h

#21 lore raw

Re: [PATCH V3 8/8] drivers: boot_constraint: Add Qualcomm display controller constraints

In reply to Viresh Kumar

Hi!

Quoted 62 lines

From: Rajendra Nayak <[email protected]>

NOT TO BE MERGED

This sets boot constraints for the display controller used on Qualcomm dragonboard 410c.

drivers/base/boot_constraints/qcom-display.c new file +52 -0
+#include <linux/boot_constraint.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+
+struct dev_boot_constraint_clk_info iface_clk_info = {
+	.name = "iface_clk",
+};
+
+struct dev_boot_constraint_clk_info bus_clk_info = {
+	.name = "bus_clk",
+};
+
+struct dev_boot_constraint_clk_info core_clk_info = {
+	.name = "core_clk",
+};
+
+struct dev_boot_constraint_clk_info vsync_clk_info = {
+	.name = "vsync_clk",
+};
+
+struct dev_boot_constraint_clk_info esc0_clk_info = {
+	.name = "core_clk",
+};
+
+struct dev_boot_constraint_clk_info byte_clk_info = {
+	.name = "byte_clk",
+};
+
+struct dev_boot_constraint_clk_info pixel_clk_info = {
+	.name = "pixel_clk",
+};
+
+struct dev_boot_constraint_supply_info vdda_info = {
+	.name = "vdda"
+};
+
+struct dev_boot_constraint_supply_info vddio_info = {
+	.name = "vddio"
+};
+
+struct dev_boot_constraint constraints_mdss[] = {
+	{
+		.type = DEV_BOOT_CONSTRAINT_PM,
+		.data = NULL,
+	},
+};
+
+struct dev_boot_constraint constraints_mdp[] = {
+	{
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &iface_clk_info,
+	}, {

drivers/base/boot_constraints/qcom-display.c line 67

Quoted 10 lines
drivers/base/boot_constraints/qcom-display.c new file +10 -0
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &bus_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &core_clk_info,
+	}, {
+		.type = DEV_BOOT_CONSTRAINT_CLK,
+		.data = &vsync_clk_info,
+	},
+};

Hmm. I know this is not for merge, but should this go to device tree somewhere?

Signature · 9 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170904/61d21e65/attachment.sig>
#22 lore raw

Re: [PATCH V3 8/8] drivers: boot_constraint: Add Qualcomm display controller constraints

Quoted 1 line · Pavel Machek

Hmm. I know this is not for merge, but should this go to device tree somewhere?

Eventually yes. It should come from the boot loader in some way, which includes DT, ACPI, etc.

This is just trying to get the core in first and once we have it merged, we can propose DT bindings to start with.

Signature · 1 line
viresh
#7 lore raw

Re: [PATCH V3 1/8] drivers: Add boot constraints core

In reply to Greg Kroah-Hartman
Quoted 8 lines · Greg Kroah-Hartman
Quoted 5 lines · Viresh Kumar
Quoted 1 line · Greg Kroah-Hartman

Who couldn't reach an agreement?

Rob Herring (DT Maintainer) didn't like the first set of bindings and wasn't convinced that we need any new bindings for this purpose to begin with.

So Rob wanted more kernel code and less bindings?

We had a similar thread sometime back (Performance states for power domains), where we couldn't get to the bindings in the first go. Rob suggested that we can actually get the code in first and then we can look at how to get stuff from DT once we understand it more.

He wasn't happy with the bindings I proposed and so I took the same approach here. Its not a lot of code we are going to have to remove once we move to DT, so it ain't that bad.

Quoted 1 line

Ok, I'll ask for Rob to sign off on these patches then :)

I can't give any guarantee of that ;)

Quoted 2 lines

As you have the source for a number of such systems, you might want to verify this please.

I will try to talk to few guys during Linaro connect next week and also look into source for such stuff.

Quoted 2 lines

Also, what is going to cause any new systems to use this new api?

As far as my part go, I can do my best to advertise it with articles and presentations. But eventually people have to get motivated to use it themselves :)

What else can I do as an author here? I will do whatever it takes to get people to use it.

Signature · 1 line
viresh