Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arch/arm64/boot/dts/qcom/hamoa.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@
reg = <0x13>;
#power-domain-cells = <1>;
};

scmi_vendor: protocol@80 {
reg = <0x80>;
};
};
};

Expand Down
4 changes: 4 additions & 0 deletions arch/arm64/configs/qcom.config
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ CONFIG_PROC_EVENTS=y
CONFIG_PTP_QCOM_CLOCK_TSC=m
CONFIG_QCA808X_PHY=m
CONFIG_QCOM_QMI_COOLING=y
CONFIG_QCOM_SCMI_GENERIC_EXT=y
CONFIG_REMOTEPROC_THERMAL=y
CONFIG_SCHED_CLASS_EXT=y
CONFIG_SCHED_DEBUG=y
Expand Down Expand Up @@ -122,6 +123,9 @@ CONFIG_SCSI_SMARTPQI=m
# Support performance profiling
CONFIG_FTRACE=y
CONFIG_FUNCTION_TRACER=y
# QCOM SCMI memlat bus scaling
CONFIG_DEVFREQ_GOV_REMOTE=y
CONFIG_SCMI_QCOM_MEMLAT_DEVFREQ=m
# Kubernetes support
CONFIG_CFS_BANDWIDTH=y
CONFIG_CGROUP_FAVOR_DYNMODS=y
Expand Down
21 changes: 21 additions & 0 deletions drivers/devfreq/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ config DEVFREQ_GOV_POWERSAVE
the DEVFREQ framework returns the lowest frequency available
at any time.

config DEVFREQ_GOV_REMOTE
tristate "Remote"
help
A simple governor to track the frequency of devices whose
dvfs control lies outside the kernel. This governor acts
as an observer and provides for ways to track frequency and
set/get information related to the remote dvfs device.

config DEVFREQ_GOV_USERSPACE
tristate "Userspace"
help
Expand Down Expand Up @@ -161,6 +169,19 @@ config ARM_SUN8I_A33_MBUS_DEVFREQ
This adds the DEVFREQ driver for the MBUS controller in some
Allwinner sun8i (A33 through H3) and sun50i (A64 and H5) SoCs.

config SCMI_QCOM_MEMLAT_DEVFREQ
tristate "Qualcomm Technologies Inc. SCMI client driver"
depends on QCOM_SCMI_GENERIC_EXT || COMPILE_TEST
select DEVFREQ_GOV_REMOTE
help
This driver uses the MEMLAT (memory latency) algorithm string
hosted on QCOM SCMI Vendor Protocol to detect memory latency
workloads and control frequency/level of the various memory
buses (DDR/LLCC/DDR_QOS).

This driver defines/documents the parameter IDs used while configuring
the memory buses.

source "drivers/devfreq/event/Kconfig"

endif # PM_DEVFREQ
2 changes: 2 additions & 0 deletions drivers/devfreq/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ obj-$(CONFIG_PM_DEVFREQ_EVENT) += devfreq-event.o
obj-$(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND) += governor_simpleondemand.o
obj-$(CONFIG_DEVFREQ_GOV_PERFORMANCE) += governor_performance.o
obj-$(CONFIG_DEVFREQ_GOV_POWERSAVE) += governor_powersave.o
obj-$(CONFIG_DEVFREQ_GOV_REMOTE) += governor_remote.o
obj-$(CONFIG_DEVFREQ_GOV_USERSPACE) += governor_userspace.o
obj-$(CONFIG_DEVFREQ_GOV_PASSIVE) += governor_passive.o

Expand All @@ -16,6 +17,7 @@ obj-$(CONFIG_ARM_MEDIATEK_CCI_DEVFREQ) += mtk-cci-devfreq.o
obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o
obj-$(CONFIG_ARM_SUN8I_A33_MBUS_DEVFREQ) += sun8i-a33-mbus.o
obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra30-devfreq.o
obj-$(CONFIG_SCMI_QCOM_MEMLAT_DEVFREQ) += scmi-qcom-memlat-devfreq.o

# DEVFREQ Event Drivers
obj-$(CONFIG_PM_DEVFREQ_EVENT) += event/
11 changes: 10 additions & 1 deletion drivers/devfreq/devfreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <linux/stat.h>
#include <linux/pm_opp.h>
#include <linux/devfreq.h>
#include <linux/devfreq-governor.h>
#include <linux/workqueue.h>
#include <linux/platform_device.h>
#include <linux/list.h>
Expand All @@ -28,7 +29,6 @@
#include <linux/of.h>
#include <linux/pm_qos.h>
#include <linux/units.h>
#include "governor.h"

#define CREATE_TRACE_POINTS
#include <trace/events/devfreq.h>
Expand Down Expand Up @@ -348,6 +348,10 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
unsigned long cur_freq;
int err = 0;

/* Frequency already updated, update trans-stat info */
if (IS_SUPPORTED_FLAG(devfreq->governor->flags, TRACK_REMOTE))
goto update_status;

if (devfreq->profile->get_cur_freq)
devfreq->profile->get_cur_freq(devfreq->dev.parent, &cur_freq);
else
Expand Down Expand Up @@ -375,6 +379,7 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
freqs.new = new_freq;
devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);

update_status:
if (devfreq_update_status(devfreq, new_freq))
dev_warn(&devfreq->dev,
"Couldn't update frequency transition information.\n");
Expand Down Expand Up @@ -1568,6 +1573,10 @@ static ssize_t target_freq_show(struct device *dev,
{
struct devfreq *df = to_devfreq(dev);

if (!df->profile || !df->governor ||
!IS_SUPPORTED_ATTR(df->governor->attrs, TARGET_FREQ))
return -EINVAL;

return sprintf(buf, "%lu\n", df->previous_freq);
}
static DEVICE_ATTR_RO(target_freq);
Expand Down
128 changes: 4 additions & 124 deletions drivers/devfreq/governor.h
Original file line number Diff line number Diff line change
@@ -1,127 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* governor.h - internal header for devfreq governors.
*
* Copyright (C) 2011 Samsung Electronics
* MyungJoo Ham <myungjoo.ham@samsung.com>
*
* This header is for devfreq governors in drivers/devfreq/
* Compatibility shim: governor.h was moved to include/linux/devfreq-governor.h
* in kernel 6.19 (commit 447c4e8338db). This file exists to support out-of-tree
* modules (e.g. kgsl) that still reference the old location on 6.18.y kernels.
*/

#ifndef _GOVERNOR_H
#define _GOVERNOR_H

#include <linux/devfreq.h>

#define DEVFREQ_NAME_LEN 16

#define to_devfreq(DEV) container_of((DEV), struct devfreq, dev)

/* Devfreq events */
#define DEVFREQ_GOV_START 0x1
#define DEVFREQ_GOV_STOP 0x2
#define DEVFREQ_GOV_UPDATE_INTERVAL 0x3
#define DEVFREQ_GOV_SUSPEND 0x4
#define DEVFREQ_GOV_RESUME 0x5

#define DEVFREQ_MIN_FREQ 0
#define DEVFREQ_MAX_FREQ ULONG_MAX

/*
* Definition of the governor feature flags
* - DEVFREQ_GOV_FLAG_IMMUTABLE
* : This governor is never changeable to other governors.
* - DEVFREQ_GOV_FLAG_IRQ_DRIVEN
* : The devfreq won't schedule the work for this governor.
*/
#define DEVFREQ_GOV_FLAG_IMMUTABLE BIT(0)
#define DEVFREQ_GOV_FLAG_IRQ_DRIVEN BIT(1)

/*
* Definition of governor attribute flags except for common sysfs attributes
* - DEVFREQ_GOV_ATTR_POLLING_INTERVAL
* : Indicate polling_interval sysfs attribute
* - DEVFREQ_GOV_ATTR_TIMER
* : Indicate timer sysfs attribute
*/
#define DEVFREQ_GOV_ATTR_POLLING_INTERVAL BIT(0)
#define DEVFREQ_GOV_ATTR_TIMER BIT(1)

/**
* struct devfreq_cpu_data - Hold the per-cpu data
* @node: list node
* @dev: reference to cpu device.
* @first_cpu: the cpumask of the first cpu of a policy.
* @opp_table: reference to cpu opp table.
* @cur_freq: the current frequency of the cpu.
* @min_freq: the min frequency of the cpu.
* @max_freq: the max frequency of the cpu.
*
* This structure stores the required cpu_data of a cpu.
* This is auto-populated by the governor.
*/
struct devfreq_cpu_data {
struct list_head node;

struct device *dev;
unsigned int first_cpu;

struct opp_table *opp_table;
unsigned int cur_freq;
unsigned int min_freq;
unsigned int max_freq;
};

/**
* struct devfreq_governor - Devfreq policy governor
* @node: list node - contains registered devfreq governors
* @name: Governor's name
* @attrs: Governor's sysfs attribute flags
* @flags: Governor's feature flags
* @get_target_freq: Returns desired operating frequency for the device.
* Basically, get_target_freq will run
* devfreq_dev_profile.get_dev_status() to get the
* status of the device (load = busy_time / total_time).
* @event_handler: Callback for devfreq core framework to notify events
* to governors. Events include per device governor
* init and exit, opp changes out of devfreq, suspend
* and resume of per device devfreq during device idle.
*
* Note that the callbacks are called with devfreq->lock locked by devfreq.
*/
struct devfreq_governor {
struct list_head node;

const char name[DEVFREQ_NAME_LEN];
const u64 attrs;
const u64 flags;
int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
int (*event_handler)(struct devfreq *devfreq,
unsigned int event, void *data);
};

void devfreq_monitor_start(struct devfreq *devfreq);
void devfreq_monitor_stop(struct devfreq *devfreq);
void devfreq_monitor_suspend(struct devfreq *devfreq);
void devfreq_monitor_resume(struct devfreq *devfreq);
void devfreq_update_interval(struct devfreq *devfreq, unsigned int *delay);

int devfreq_add_governor(struct devfreq_governor *governor);
int devfreq_remove_governor(struct devfreq_governor *governor);

int devm_devfreq_add_governor(struct device *dev,
struct devfreq_governor *governor);

int devfreq_update_status(struct devfreq *devfreq, unsigned long freq);
int devfreq_update_target(struct devfreq *devfreq, unsigned long freq);
void devfreq_get_freq_range(struct devfreq *devfreq, unsigned long *min_freq,
unsigned long *max_freq);

static inline int devfreq_update_stats(struct devfreq *df)
{
if (!df->profile->get_dev_status)
return -EINVAL;

return df->profile->get_dev_status(df->dev.parent, &df->last_status);
}
#endif /* _GOVERNOR_H */
#include <linux/devfreq-governor.h>
28 changes: 27 additions & 1 deletion drivers/devfreq/governor_passive.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,33 @@
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/devfreq.h>
#include <linux/devfreq-governor.h>
#include <linux/units.h>
#include "governor.h"

/**
* struct devfreq_cpu_data - Hold the per-cpu data
* @node: list node
* @dev: reference to cpu device.
* @first_cpu: the cpumask of the first cpu of a policy.
* @opp_table: reference to cpu opp table.
* @cur_freq: the current frequency of the cpu.
* @min_freq: the min frequency of the cpu.
* @max_freq: the max frequency of the cpu.
*
* This structure stores the required cpu_data of a cpu.
* This is auto-populated by the governor.
*/
struct devfreq_cpu_data {
struct list_head node;

struct device *dev;
unsigned int first_cpu;

struct opp_table *opp_table;
unsigned int cur_freq;
unsigned int min_freq;
unsigned int max_freq;
};

static struct devfreq_cpu_data *
get_parent_cpu_data(struct devfreq_passive_data *p_data,
Expand Down Expand Up @@ -424,6 +449,7 @@ static int devfreq_passive_event_handler(struct devfreq *devfreq,

static struct devfreq_governor devfreq_passive = {
.name = DEVFREQ_GOV_PASSIVE,
.attrs = DEVFREQ_GOV_ATTR_TARGET_FREQ,
.flags = DEVFREQ_GOV_FLAG_IMMUTABLE,
.get_target_freq = devfreq_passive_get_target_freq,
.event_handler = devfreq_passive_event_handler,
Expand Down
3 changes: 2 additions & 1 deletion drivers/devfreq/governor_performance.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

#include <linux/devfreq.h>
#include <linux/devfreq-governor.h>
#include <linux/module.h>
#include "governor.h"

static int devfreq_performance_func(struct devfreq *df,
unsigned long *freq)
Expand Down Expand Up @@ -37,6 +37,7 @@ static int devfreq_performance_handler(struct devfreq *devfreq,

static struct devfreq_governor devfreq_performance = {
.name = DEVFREQ_GOV_PERFORMANCE,
.attrs = DEVFREQ_GOV_ATTR_TARGET_FREQ,
.get_target_freq = devfreq_performance_func,
.event_handler = devfreq_performance_handler,
};
Expand Down
3 changes: 2 additions & 1 deletion drivers/devfreq/governor_powersave.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

#include <linux/devfreq.h>
#include <linux/devfreq-governor.h>
#include <linux/module.h>
#include "governor.h"

static int devfreq_powersave_func(struct devfreq *df,
unsigned long *freq)
Expand Down Expand Up @@ -37,6 +37,7 @@ static int devfreq_powersave_handler(struct devfreq *devfreq,

static struct devfreq_governor devfreq_powersave = {
.name = DEVFREQ_GOV_POWERSAVE,
.attrs = DEVFREQ_GOV_ATTR_TARGET_FREQ,
.get_target_freq = devfreq_powersave_func,
.event_handler = devfreq_powersave_handler,
};
Expand Down
Loading
Loading