nf: IDLETIMER: Fix possible use before initialization in idletimer_resume

idletimer_resume() assumes that the PM_SUSPEND_PREPARE notifier is sent
before PM_POST_PREPARE so that timer->last_suspend_time is initialized.
However, it is posible for PM_POST_PREPARE to be sent first if there is an
error returned from another driver's PM_SUSPEND_PREPARE notifier.

Add a flag indicating whether the current value of timer->last_suspend is
valid.

Detected with CONFIG_SLUB_DEBUG & CONFIG_DEBUG_SPINLOCK in arm64. The
timestamp lock is held for more than a minute while
set_normalized_timespec() proceses the poisoned timer->last_suspend_time
argument.

Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Change priority overrides based on master configuration

When BIMC master enables BKE (in limiter mode), priority override
should be disabled since master is getting limited bandwidth.
However when BKE is disabled, make sure priority overrides are enabled
if master is in fixed mode.
Also enable the bke bit as part of switching QOS modes.

Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Changes for QOS computation at BIMC

Modify the computation of dynamic QOS parameters for BIMC. The bandwidth
paramter was incorrectly assumed to be in beats/s, it is infact in bytes/s
so there is no need to take bus width into account.
Also change resolution for statically prgrammed grant period to nano second
from micro second since each tick of the QOS clock is in the nano second
range.

Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Amir Vajid <avajid@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: fix memory leak in msm_bus_fabric_probe

Certain bus driver data structures do not get freed in the error
paths of msm_bus_fabric_probe. Fix the memory leak.

Signed-off-by: Syed Rameez Mustafa <rameezmustafa@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Don't touch ID array in case of invalid IDs

Protect the bus ID array in case config data contains invalid
IDs which can cause out-of-bounds access.

Signed-off-by: Gagan Mac <gmac@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Correct the return value from register-client

On failure, return 0, and not a non-zero value as that can
be interpreted as a valid client ID.

Signed-off-by: Gagan Mac <gmac@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Add checks during bus client unregistration

During unregistration clients should withdraw all pending
requests. This was earlier done in update-request function.
However, that caused acpuclock client requests to be
incorrectly zeroed out.

It seems more appropriate to let the client ensure that
they correctly clean up their requests than to have bus
driver forcefully remove non-zero requests. Hence, a
warning has been added in the unregistration path.

Signed-off-by: Gagan Mac <gmac@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Don't program bw regs in dual config

When in dual configuration mode, don't program the bw registers
since they are already programmed at boot up.

Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Arbitrate IB for dual config masters

Arbitrate the IBs on nodes marked as dual config. This will prevent cases
where the last client's requests is always used to apply dual config rules.

Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Allow QOS address offset to be configurable

Currently the QOS base address for NOC is assumed to be at an
offset of 0x3000 from the base address of the NOC device. But this is not
the case in some chipsets. Make the QOS address offset a configurable
platform parameter.

Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Modify IB aggregation at master

The IB aggregation at master assumed that the sel_clk pointers were set
before trying to access them, but there could be clients that register
but don't do any transaction at all which could lead to data aborts during
the IB aggregation. Change this to directly access the allocated pnode
entry instead of relying on sel_clk pointer.

Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
mach-msm:bus_config:fix possible missing error check

There is a possibility of msm_bus_board_get_iid returning the error.
ERROR check is required before proceeding with the msm_bus_get_fabric_device

Signed-off-by: Swetha Chikkaboraiah <schikk@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Don't divide RPM BW requests

When sending bandwidth requests to slave don't divide the request by
the number of ports as this is done at the RPM driver.

Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Only set clock rate on unset clocks.

Checks to see if the clock is already set before
requesting a rounded(1) rate.

Signed-off-by: Dan Sneddon <dsneddon@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Introduce multi level BKE limiting.

Introduce multi level BKE throttling for BIMC masters. By specifying an
array of thresholds and limiting bandwidth values, multiple levels of
master throttling can be achieved.

Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Akhila Musunuri <makhila@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: export msm_bus_fabric_init_driver

I2c-qup driver is a client of msm_bus_fabric driver while drivers like
onsemi-ncp6335d and fan53555 are clients of i2c-qup driver. In some
targets, onsemi-ncp6335d and fan53555 drivers have to initialize and probe
early before the i2c-qup and msm_bus_fabric driver are ready. Hence export
msm_bus_fabric_init_driver to make sure msm_bus_fabric driver is ready when
its clients need to probe.

Signed-off-by: Ke Liu <keliu@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Correct Error string while reading Clients pdata

Currently if clients miss any DT entry the error messages popping
up as "error getting pdata",which is causing ambiguity while debugging
failure cases.This patch adds correct error string for missing DT entries
and makes the error string more self-explanatory.

Signed-off-by: Sana Venkat Raju <c_vsana@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Prevent BKE swtich from overwriting other fields

Incorrect bit mask could lead to other register fields getting
overwritten when doing a BKE bit switch.

Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Sana Venkat Raju <c_vsana@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: msm_bus: Fix inadvertent stomp on BKE_EN register

While setting the QoS mode of fixed mode masters bad masking
operations is causing accidental stomp on the upper nibble of the
BKE_EN register.

Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
ARM: dts: msm: BIMC for 8974 class devices

Map memory for tools to access BIMC facilities.

Acked-by: rahul ramasubramanian <rahulr@qti.qualcomm.com>
Signed-off-by: Neil Leeder <nleeder@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>