mbox series

[V7,00/13] drivers: Boot Constraint core

Message ID cover.1519380923.git.viresh.kumar@linaro.org
Headers show
Series drivers: Boot Constraint core | expand

Message

Viresh Kumar Feb. 23, 2018, 10:23 a.m. UTC
Hi Greg,

The V7 version incorporates the organizational changes suggested by Olof
earlier. Everything else is same otherwise.

I have tested the Hisilicon patches (again) on hikey 9660 board, IMX stuff was
earlier tested by Sascha (Pengutronix) on i.MX6 and Qualcomm stuff was earlier
tested by Rajendra (Qualcomm) on Dragonboard 410C (This required some more
patches related to display driver which Rajendra should be sending separately
later on).


Problem statement:

Some devices are powered ON by the bootloader before the bootloader
handovers control to Linux. It maybe important for some of 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 disabling or reconfiguring these
resources to ranges satisfying the current users (only device X) and
that can make the LCD screen unstable.

Another case can be a debug serial port enabled from the bootloader.

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 series introduces the concept of "boot-constraint", which are set
by platform specific drivers (for now at least) at early init (like
subsys_initcall) and the kernel will keep satisfying 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 currently.

Pushed here:
git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/linux.git boot-constraint

More documentation on it can be found here:
https://lwn.net/Articles/747250/

V6->V7:
- s/drivers\/boot_constraint/drivers\/bootconstraint/ (Olof)
- Moved platform drivers to drivers/soc/<platform>/boot_constraint.c
- Changed year in file copyrights: s/2017/2018

V5->V6:
- Fix a build error reported by build bot for !CONFIG_OF_ADDRESS. This
  was already sent on 15th December.
- Rebased over latest driver-core-next.

V4->V5:
- SPDX Licence format used.
- arm,primecell stuff removed from boot constraint core and added a
  helper in OF core (which already handles amba and platform devices).
- Removed a bunch of BUG_ON(), pr_fmt(), comments.
- Changed directory and other names from
  boot_constraints/boot_constraint.
- Removed serial.o file and moved the code to hikey and imx files.
- Don't return error from dummy helper.
- Added documentation and corresponding kernel doc comments in the code.
- Updated MAINTAINERS.

V3->V4:
- Added support for imx, hikey and Qcom usecases.
- Enhanced boot constraints core to make drivers code easy and handle
  complex cases.
- Two new patches for OF included to provide APIs to boot constraint
  core.
- Removed the kernel parameter patch for now.
- Don't check return values of debugfs routines.
- Moved the boot constraints core from drivers/base/ to drivers/.

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


*** BLURB HERE ***

Viresh Kumar (13):
  of: platform: Add of_find_any_device_by_node()
  of: platform: Make of_platform_bus_create() global
  drivers: Add boot constraints core
  boot_constraint: Add support for supply constraints
  boot_constraint: Add support for clk constraints
  boot_constraint: Add support for PM constraints
  boot_constraint: Add debugfs support
  boot_constraint: Manage deferrable constraints
  boot_constraint: Add support for Hisilicon platforms
  boot_constraint: Add support for IMX platform
  boot_constraint: Add Qualcomm display controller constraints
  boot_constraint: Update MAINTAINERS
  boot_constraint: Add documentation

 .../driver-api/boot-constraint/constraints.rst     |  98 +++++++
 Documentation/driver-api/boot-constraint/index.rst |   4 +
 Documentation/driver-api/index.rst                 |   1 +
 MAINTAINERS                                        |   9 +
 drivers/Kconfig                                    |   2 +
 drivers/Makefile                                   |   1 +
 drivers/base/dd.c                                  |  32 ++-
 drivers/bootconstraint/Kconfig                     |   9 +
 drivers/bootconstraint/Makefile                    |   3 +
 drivers/bootconstraint/clk.c                       |  70 +++++
 drivers/bootconstraint/core.c                      | 290 +++++++++++++++++++++
 drivers/bootconstraint/core.h                      |  47 ++++
 drivers/bootconstraint/deferrable_dev.c            | 241 +++++++++++++++++
 drivers/bootconstraint/pm.c                        |  28 ++
 drivers/bootconstraint/supply.c                    | 104 ++++++++
 drivers/clk/imx/clk-imx25.c                        |  12 -
 drivers/clk/imx/clk-imx27.c                        |  13 -
 drivers/clk/imx/clk-imx31.c                        |  12 -
 drivers/clk/imx/clk-imx35.c                        |  10 -
 drivers/clk/imx/clk-imx51-imx53.c                  |  16 --
 drivers/clk/imx/clk-imx6q.c                        |   8 -
 drivers/clk/imx/clk-imx6sl.c                       |   8 -
 drivers/clk/imx/clk-imx6sx.c                       |   8 -
 drivers/clk/imx/clk-imx7d.c                        |  14 -
 drivers/clk/imx/clk.c                              |  38 ---
 drivers/clk/imx/clk.h                              |   1 -
 drivers/of/platform.c                              |  63 ++++-
 drivers/soc/Kconfig                                |   1 +
 drivers/soc/Makefile                               |   1 +
 drivers/soc/hisilicon/Kconfig                      |  15 ++
 drivers/soc/hisilicon/Makefile                     |   3 +
 drivers/soc/hisilicon/boot_constraint.c            | 158 +++++++++++
 drivers/soc/imx/Kconfig                            |   8 +
 drivers/soc/imx/Makefile                           |   1 +
 drivers/soc/imx/boot_constraint.c                  | 126 +++++++++
 drivers/soc/qcom/Kconfig                           |   8 +
 drivers/soc/qcom/Makefile                          |   1 +
 drivers/soc/qcom/boot_constraint.c                 | 122 +++++++++
 include/linux/boot_constraint.h                    | 121 +++++++++
 include/linux/of_platform.h                        |  16 ++
 40 files changed, 1572 insertions(+), 151 deletions(-)
 create mode 100644 Documentation/driver-api/boot-constraint/constraints.rst
 create mode 100644 Documentation/driver-api/boot-constraint/index.rst
 create mode 100644 drivers/bootconstraint/Kconfig
 create mode 100644 drivers/bootconstraint/Makefile
 create mode 100644 drivers/bootconstraint/clk.c
 create mode 100644 drivers/bootconstraint/core.c
 create mode 100644 drivers/bootconstraint/core.h
 create mode 100644 drivers/bootconstraint/deferrable_dev.c
 create mode 100644 drivers/bootconstraint/pm.c
 create mode 100644 drivers/bootconstraint/supply.c
 create mode 100644 drivers/soc/hisilicon/Kconfig
 create mode 100644 drivers/soc/hisilicon/Makefile
 create mode 100644 drivers/soc/hisilicon/boot_constraint.c
 create mode 100644 drivers/soc/imx/boot_constraint.c
 create mode 100644 drivers/soc/qcom/boot_constraint.c
 create mode 100644 include/linux/boot_constraint.h

-- 
2.15.0.194.g9af6a3dea062

Comments

Viresh Kumar March 16, 2018, 5:34 a.m. UTC | #1
On 23-02-18, 15:53, Viresh Kumar wrote:
> Hi Greg,

> 

> The V7 version incorporates the organizational changes suggested by Olof

> earlier. Everything else is same otherwise.

> 

> I have tested the Hisilicon patches (again) on hikey 9660 board, IMX stuff was

> earlier tested by Sascha (Pengutronix) on i.MX6 and Qualcomm stuff was earlier

> tested by Rajendra (Qualcomm) on Dragonboard 410C (This required some more

> patches related to display driver which Rajendra should be sending separately

> later on).


Hi Greg,

Are you going to pick this one for 4.17 ?

Thanks.

-- 
viresh
Viresh Kumar March 22, 2018, 1:26 a.m. UTC | #2
On 23-02-18, 15:53, Viresh Kumar wrote:
> Problem statement:

> 

> Some devices are powered ON by the bootloader before the bootloader

> handovers control to Linux. It maybe important for some of 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 disabling or reconfiguring these

> resources to ranges satisfying the current users (only device X) and

> that can make the LCD screen unstable.

> 

> Another case can be a debug serial port enabled from the bootloader.

> 

> 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.


And we have a _real_ use case for this complex scenario as well.

Georgi (cc'd) is currently working[1] on implementing generic support for the
interconnect bus, which tries to play with the bandwidth of the bus based on how
much are the requirements from different parts of the SoC. The 4th version was
posted recently by him, and things are looking good/positive.

The bootloader configures the interconnect to provide sufficient bandwidth for
all the devices which are used during boot, few of them are the CPUs, serial and
the LCD controller. As the kernel starts taking control of things, the drivers
being probed start putting their requirements on the interconnect bus.  Because
the interconnect doesn't have any representation from the devices which are not
yet initialized by the kernel, the interconnect core incorrectly reduces the
bandwidth of the bus to a level unacceptable to the devices running currently,
like the CPUs and this makes kernel boot awfully slow. This is not an ordering
problem as no matter which device we probe first, we are going to break
something else.

Georgi already tried using the boot constraint patches to solve this complex
problem, and its a perfect fit.

-- 
viresh

[1] http://lkml.kernel.org/r/20180309210958.16672-1-georgi.djakov@linaro.org
Greg Kroah-Hartman March 23, 2018, 3:04 p.m. UTC | #3
On Thu, Mar 22, 2018 at 09:26:06AM +0800, Viresh Kumar wrote:
> On 23-02-18, 15:53, Viresh Kumar wrote:

> > Problem statement:

> > 

> > Some devices are powered ON by the bootloader before the bootloader

> > handovers control to Linux. It maybe important for some of 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 disabling or reconfiguring these

> > resources to ranges satisfying the current users (only device X) and

> > that can make the LCD screen unstable.

> > 

> > Another case can be a debug serial port enabled from the bootloader.

> > 

> > 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.

> 

> And we have a _real_ use case for this complex scenario as well.

> 

> Georgi (cc'd) is currently working[1] on implementing generic support for the

> interconnect bus, which tries to play with the bandwidth of the bus based on how

> much are the requirements from different parts of the SoC. The 4th version was

> posted recently by him, and things are looking good/positive.

> 

> The bootloader configures the interconnect to provide sufficient bandwidth for

> all the devices which are used during boot, few of them are the CPUs, serial and

> the LCD controller. As the kernel starts taking control of things, the drivers

> being probed start putting their requirements on the interconnect bus.  Because

> the interconnect doesn't have any representation from the devices which are not

> yet initialized by the kernel, the interconnect core incorrectly reduces the

> bandwidth of the bus to a level unacceptable to the devices running currently,

> like the CPUs and this makes kernel boot awfully slow. This is not an ordering

> problem as no matter which device we probe first, we are going to break

> something else.

> 

> Georgi already tried using the boot constraint patches to solve this complex

> problem, and its a perfect fit.


I'm delaying this as I still don't see that "perfect fit" yet.  If there
are add-on patches that take better advantage of this, great, let's see
those, but right now, it feels like you are the only one wanting this.
And the increased complexity overall seems not really worth it yet :(

greg k-h
Georgi Djakov March 30, 2018, 3:24 p.m. UTC | #4
Hi Greg and Viresh,

On 03/23/2018 05:04 PM, Greg Kroah-Hartman wrote:
> On Thu, Mar 22, 2018 at 09:26:06AM +0800, Viresh Kumar wrote:

>> On 23-02-18, 15:53, Viresh Kumar wrote:

>>> Problem statement:

>>>

>>> Some devices are powered ON by the bootloader before the bootloader

>>> handovers control to Linux. It maybe important for some of 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 disabling or reconfiguring these

>>> resources to ranges satisfying the current users (only device X) and

>>> that can make the LCD screen unstable.

>>>

>>> Another case can be a debug serial port enabled from the bootloader.

>>>

>>> 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.

>>

>> And we have a _real_ use case for this complex scenario as well.

>>

>> Georgi (cc'd) is currently working[1] on implementing generic support for the

>> interconnect bus, which tries to play with the bandwidth of the bus based on how

>> much are the requirements from different parts of the SoC. The 4th version was

>> posted recently by him, and things are looking good/positive.

>>

>> The bootloader configures the interconnect to provide sufficient bandwidth for

>> all the devices which are used during boot, few of them are the CPUs, serial and

>> the LCD controller. As the kernel starts taking control of things, the drivers

>> being probed start putting their requirements on the interconnect bus.  Because

>> the interconnect doesn't have any representation from the devices which are not

>> yet initialized by the kernel, the interconnect core incorrectly reduces the

>> bandwidth of the bus to a level unacceptable to the devices running currently,

>> like the CPUs and this makes kernel boot awfully slow. This is not an ordering

>> problem as no matter which device we probe first, we are going to break

>> something else.


The interconnect core takes requests from consumer drivers for their
bandwidth needs and configures the hardware to keep the lowest possible
power profile. I think that the boot constraint patches would be useful
to make a board run at maximum performance during boot, until all
consumer drivers are probed and all bandwidth requests are taken into
account.

>> Georgi already tried using the boot constraint patches to solve this complex

>> problem, and its a perfect fit.


These patches solve a common problem for different subsystems, so it
makes sense to handle it into the driver core, instead of leaving each
subsystem to do their own hacks.

> I'm delaying this as I still don't see that "perfect fit" yet.  If there

> are add-on patches that take better advantage of this, great, let's see

> those, but right now, it feels like you are the only one wanting this.

> And the increased complexity overall seems not really worth it yet :(


The interconnect code is still under review, but on the next submission
i will include a patch to make use of the boot constraints, so that we
hopefully move this forward.

Thanks,
Georgi
Lucas Stach April 10, 2018, 1:40 p.m. UTC | #5
Hi Georgi,

Am Freitag, den 30.03.2018, 18:24 +0300 schrieb Georgi Djakov:
[...]
> The interconnect core takes requests from consumer drivers for their

> bandwidth needs and configures the hardware to keep the lowest possible

> power profile. I think that the boot constraint patches would be useful

> to make a board run at maximum performance during boot, until all

> consumer drivers are probed and all bandwidth requests are taken into

> account.


Can you please describe how this bootconstraints core integration is
simpler than a "run things at max performance until late kernel init",
which could be triggered by a simple initcall similar to what is done
for clocks and regulators?

To me the bootcontraints stuff looks like a fairly complex solution and
your use-case doesn't even sound like you strictly want to keep a
bootloader configuration, but rather run things at max performance
until you are reasonably sure that you got all the necessary bandwidth
requests.

Regards,
Lucas
Viresh Kumar April 11, 2018, 4:39 a.m. UTC | #6
On 10-04-18, 15:40, Lucas Stach wrote:
> Can you please describe how this bootconstraints core integration is

> simpler than a "run things at max performance until late kernel init",

> which could be triggered by a simple initcall similar to what is done

> for clocks and regulators?

> 

> To me the bootcontraints stuff looks like a fairly complex solution and

> your use-case doesn't even sound like you strictly want to keep a

> bootloader configuration, but rather run things at max performance

> until you are reasonably sure that you got all the necessary bandwidth

> requests.


What about this case where drivers of some of the devices used during
boot are built as modules, like display, HDMI, etc., and would be
available only after userspace is up. We need to take care of their
bandwidth requirements as well, until the time their driver comes up.

-- 
viresh