* [PATCH 2/5] platform/x86/amd/pmf: Inline simple helper functions of Core Layer
2026-09-01 15:02 [PATCH 0/5] platform/x86/amd/pmf: Clean up undesirable function outlining Rong Zhang
2026-09-01 15:02 ` [PATCH 1/5] platform/x86/amd/pmf: Inline !AMD_PMF_DEBUG stub Rong Zhang
@ 2026-09-01 15:02 ` Rong Zhang
2026-09-01 15:02 ` [PATCH 3/5] platform/x86/amd/pmf: Inline simple helper function of SPS Layer Rong Zhang
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Rong Zhang @ 2026-09-01 15:02 UTC (permalink / raw)
To: Shyam Sundar S K, Hans de Goede, Ilpo Järvinen,
Sanket Goswami, Mario Limonciello (AMD)
Cc: platform-driver-x86, linux-kernel, Rong Zhang
The Core Layer has simple and dumb helper functions defined as global
symbols, which are heavily used by other layers and become symbols
against linkage. This bloats the size of the module.
Convert them into static inline functions to get rid of the overhead of
function outlining and linkage, and shrink the module
(!CONFIG_AMD_PMF_DEBUG && CONFIG_AMD_PMF_UTIL_SUPPORT) size by 432 Bytes
(GCC 16 -O2):
text data bss total filename (before)
26781 31636 2768 61185 amd-pmf.ko
text data bss total filename (after)
26533 31452 2768 60753 amd-pmf.ko
Signed-off-by: Rong Zhang <i@rong.moe>
---
drivers/platform/x86/amd/pmf/acpi.c | 11 -----------
drivers/platform/x86/amd/pmf/core.c | 22 ---------------------
drivers/platform/x86/amd/pmf/pmf.h | 39 +++++++++++++++++++++++++++++++++----
3 files changed, 35 insertions(+), 37 deletions(-)
diff --git a/drivers/platform/x86/amd/pmf/acpi.c b/drivers/platform/x86/amd/pmf/acpi.c
index 3d94b03cf794..6a2c11e75eea 100644
--- a/drivers/platform/x86/amd/pmf/acpi.c
+++ b/drivers/platform/x86/amd/pmf/acpi.c
@@ -158,17 +158,6 @@ static int apts_if_call_store_buffer(struct amd_pmf_dev *pdev,
return err;
}
-int is_apmf_func_supported(struct amd_pmf_dev *pdev, unsigned long index)
-{
- /* If bit-n is set, that indicates function n+1 is supported */
- return !!(pdev->supported_func & BIT(index - 1));
-}
-
-int is_apmf_bios_input_notifications_supported(struct amd_pmf_dev *pdev)
-{
- return !!(pdev->notifications & CUSTOM_BIOS_INPUT_BITS);
-}
-
int apts_get_static_slider_granular_v2(struct amd_pmf_dev *pdev,
struct amd_pmf_apts_granular_output *data, u32 apts_idx)
{
diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c
index b4eae65e675b..ec2ce7fa3dee 100644
--- a/drivers/platform/x86/amd/pmf/core.c
+++ b/drivers/platform/x86/amd/pmf/core.c
@@ -138,14 +138,6 @@ static void amd_pmf_dbgfs_register(struct amd_pmf_dev *dev)
¤t_power_limits_fops);
}
-int amd_pmf_get_power_source(void)
-{
- if (power_supply_is_system_supplied() > 0)
- return POWER_SOURCE_AC;
- else
- return POWER_SOURCE_DC;
-}
-
static inline u32 amd_pmf_reg_read(struct amd_pmf_dev *dev, int reg_offset)
{
return ioread32(dev->regbase + reg_offset);
@@ -176,20 +168,6 @@ static void __maybe_unused amd_pmf_dump_registers(struct amd_pmf_dev *dev)
dev_dbg(dev->dev, "AMD_PMF_REGISTER_MESSAGE:%x\n", value);
}
-/**
- * fixp_q88_fromint: Convert integer to Q8.8
- * @val: input value
- *
- * Converts an integer into binary fixed point format where 8 bits
- * are used for integer and 8 bits are used for the decimal.
- *
- * Return: unsigned integer converted to Q8.8 format
- */
-u32 fixp_q88_fromint(u32 val)
-{
- return val << 8;
-}
-
int amd_pmf_send_cmd(struct amd_pmf_dev *dev, u8 message, bool get, u32 arg, u32 *data)
{
int rc;
diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h
index 4da2ef1abb50..024f20306e11 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -13,11 +13,13 @@
#include <linux/acpi.h>
#include <linux/amd-pmf-io.h>
+#include <linux/bits.h>
#include <linux/circ_buf.h>
#include <linux/compiler_attributes.h>
#include <linux/compiler_types.h>
#include <linux/input.h>
#include <linux/mutex_types.h>
+#include <linux/power_supply.h>
#include <linux/platform_device.h>
#include <linux/platform_profile.h>
#include <linux/types.h>
@@ -1073,18 +1075,47 @@ struct ta_pmf_shared_memory {
/* Core Layer */
int apmf_acpi_init(struct amd_pmf_dev *pmf_dev);
void apmf_acpi_deinit(struct amd_pmf_dev *pmf_dev);
-int is_apmf_func_supported(struct amd_pmf_dev *pdev, unsigned long index);
int amd_pmf_send_cmd(struct amd_pmf_dev *dev, u8 message, bool get, u32 arg, u32 *data);
int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev);
-int amd_pmf_get_power_source(void);
int apmf_install_handler(struct amd_pmf_dev *pmf_dev);
int apmf_os_power_slider_update(struct amd_pmf_dev *dev, u8 flag);
int amd_pmf_set_dram_addr(struct amd_pmf_dev *dev, bool alloc_buffer);
int amd_pmf_notify_sbios_heartbeat_event_v2(struct amd_pmf_dev *dev, u8 flag);
-u32 fixp_q88_fromint(u32 val);
-int is_apmf_bios_input_notifications_supported(struct amd_pmf_dev *pdev);
void amd_pmf_set_device(struct device *p_device);
+static inline int is_apmf_func_supported(struct amd_pmf_dev *pdev, unsigned long index)
+{
+ /* If bit-n is set, that indicates function n+1 is supported */
+ return !!(pdev->supported_func & BIT(index - 1));
+}
+
+static inline int is_apmf_bios_input_notifications_supported(struct amd_pmf_dev *pdev)
+{
+ return !!(pdev->notifications & CUSTOM_BIOS_INPUT_BITS);
+}
+
+static inline int amd_pmf_get_power_source(void)
+{
+ if (power_supply_is_system_supplied() > 0)
+ return POWER_SOURCE_AC;
+ else
+ return POWER_SOURCE_DC;
+}
+
+/**
+ * fixp_q88_fromint: Convert integer to Q8.8
+ * @val: input value
+ *
+ * Converts an integer into binary fixed point format where 8 bits
+ * are used for integer and 8 bits are used for the decimal.
+ *
+ * Return: unsigned integer converted to Q8.8 format
+ */
+static inline u32 fixp_q88_fromint(u32 val)
+{
+ return val << 8;
+}
+
/* Metrics layer */
int amd_pmf_get_tbl_dram_addr(struct amd_pmf_dev *dev);
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 5/5] platform/x86/amd/pmf: Inline wrappers of ap{mf,ts}_if_call_store_buffer()
2026-09-01 15:02 [PATCH 0/5] platform/x86/amd/pmf: Clean up undesirable function outlining Rong Zhang
` (3 preceding siblings ...)
2026-09-01 15:02 ` [PATCH 4/5] platform/x86/amd/pmf: Inline simple helper function of Smart PC TA interfaces Rong Zhang
@ 2026-09-01 15:02 ` Rong Zhang
2026-09-01 15:09 ` [PATCH 0/5] platform/x86/amd/pmf: Clean up undesirable function outlining Mario Limonciello
5 siblings, 0 replies; 7+ messages in thread
From: Rong Zhang @ 2026-09-01 15:02 UTC (permalink / raw)
To: Shyam Sundar S K, Hans de Goede, Ilpo Järvinen,
Sanket Goswami, Mario Limonciello (AMD)
Cc: platform-driver-x86, linux-kernel, Rong Zhang
There are several simple and dumb wrappers of
ap{mf,ts}_if_call_store_buffer() defined as global symbols, which are
heavily used by multiple layers and become symbols against linkage. This
bloats the size of the module.
Since is_apmf_func_supported() has been converted, convert the mentioned
wrappers into static inline functions to get rid of the overhead of
function outlining and linkage, and shrink the module
(!CONFIG_AMD_PMF_DEBUG && CONFIG_AMD_PMF_UTIL_SUPPORT) size by 515 Bytes
(GCC 16 -O2):
text data bss total filename (before)
26261 31264 2768 60293 amd-pmf.ko
text data bss total filename (after)
26046 30964 2768 59778 amd-pmf.ko
Signed-off-by: Rong Zhang <i@rong.moe>
---
drivers/platform/x86/amd/pmf/acpi.c | 65 +----------------------------
drivers/platform/x86/amd/pmf/pmf.h | 83 +++++++++++++++++++++++++++++++------
2 files changed, 73 insertions(+), 75 deletions(-)
diff --git a/drivers/platform/x86/amd/pmf/acpi.c b/drivers/platform/x86/amd/pmf/acpi.c
index 6a2c11e75eea..4392bf0bc0bf 100644
--- a/drivers/platform/x86/amd/pmf/acpi.c
+++ b/drivers/platform/x86/amd/pmf/acpi.c
@@ -50,7 +50,7 @@ static union acpi_object *apmf_if_call(struct amd_pmf_dev *pdev, int fn, struct
return buffer.pointer;
}
-static int apmf_if_call_store_buffer(struct amd_pmf_dev *pdev, int fn, void *dest, size_t out_sz)
+int apmf_if_call_store_buffer(struct amd_pmf_dev *pdev, int fn, void *dest, size_t out_sz)
{
union acpi_object *info;
size_t size;
@@ -121,8 +121,7 @@ static union acpi_object *apts_if_call(struct amd_pmf_dev *pdev, u32 state_index
return buffer.pointer;
}
-static int apts_if_call_store_buffer(struct amd_pmf_dev *pdev,
- u32 index, void *data, size_t out_sz)
+int apts_if_call_store_buffer(struct amd_pmf_dev *pdev, u32 index, void *data, size_t out_sz)
{
union acpi_object *info;
size_t size;
@@ -158,35 +157,6 @@ static int apts_if_call_store_buffer(struct amd_pmf_dev *pdev,
return err;
}
-int apts_get_static_slider_granular_v2(struct amd_pmf_dev *pdev,
- struct amd_pmf_apts_granular_output *data, u32 apts_idx)
-{
- if (!is_apmf_func_supported(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR))
- return -EINVAL;
-
- return apts_if_call_store_buffer(pdev, apts_idx, data, sizeof(*data));
-}
-
-int apmf_get_static_slider_granular_v2(struct amd_pmf_dev *pdev,
- struct apmf_static_slider_granular_output_v2 *data)
-{
- if (!is_apmf_func_supported(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR))
- return -EINVAL;
-
- return apmf_if_call_store_buffer(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR,
- data, sizeof(*data));
-}
-
-int apmf_get_static_slider_granular(struct amd_pmf_dev *pdev,
- struct apmf_static_slider_granular_output *data)
-{
- if (!is_apmf_func_supported(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR))
- return -EINVAL;
-
- return apmf_if_call_store_buffer(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR,
- data, sizeof(*data));
-}
-
int apmf_os_power_slider_update(struct amd_pmf_dev *pdev, u8 event)
{
struct os_power_slider args;
@@ -302,27 +272,6 @@ static int apmf_notify_smart_pc_update(struct amd_pmf_dev *pdev, u32 val, u32 pr
return 0;
}
-int apmf_get_auto_mode_def(struct amd_pmf_dev *pdev, struct apmf_auto_mode *data)
-{
- return apmf_if_call_store_buffer(pdev, APMF_FUNC_AUTO_MODE, data, sizeof(*data));
-}
-
-int apmf_get_sbios_requests_v2(struct amd_pmf_dev *pdev, struct apmf_sbios_req_v2 *req)
-{
- return apmf_if_call_store_buffer(pdev, APMF_FUNC_SBIOS_REQUESTS, req, sizeof(*req));
-}
-
-int apmf_get_sbios_requests_v1(struct amd_pmf_dev *pdev, struct apmf_sbios_req_v1 *req)
-{
- return apmf_if_call_store_buffer(pdev, APMF_FUNC_SBIOS_REQUESTS, req, sizeof(*req));
-}
-
-int apmf_get_sbios_requests(struct amd_pmf_dev *pdev, struct apmf_sbios_req *req)
-{
- return apmf_if_call_store_buffer(pdev, APMF_FUNC_SBIOS_REQUESTS,
- req, sizeof(*req));
-}
-
/* Store custom BIOS inputs data in ring buffer */
static void amd_pmf_custom_bios_inputs_rb(struct amd_pmf_dev *pmf_dev)
{
@@ -484,16 +433,6 @@ static int apmf_get_system_params(struct amd_pmf_dev *dev)
return 0;
}
-int apmf_get_dyn_slider_def_ac(struct amd_pmf_dev *pdev, struct apmf_dyn_slider_output *data)
-{
- return apmf_if_call_store_buffer(pdev, APMF_FUNC_DYN_SLIDER_AC, data, sizeof(*data));
-}
-
-int apmf_get_dyn_slider_def_dc(struct amd_pmf_dev *pdev, struct apmf_dyn_slider_output *data)
-{
- return apmf_if_call_store_buffer(pdev, APMF_FUNC_DYN_SLIDER_DC, data, sizeof(*data));
-}
-
static apmf_event_handler_t apmf_event_handlers[] = {
[PMF_IF_V1] = apmf_event_handler_v1,
[PMF_IF_V2] = apmf_event_handler_v2,
diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h
index 6d9963677a46..9f64ab833c08 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -17,6 +17,7 @@
#include <linux/circ_buf.h>
#include <linux/compiler_attributes.h>
#include <linux/compiler_types.h>
+#include <linux/errno.h>
#include <linux/input.h>
#include <linux/mutex_types.h>
#include <linux/power_supply.h>
@@ -1075,6 +1076,8 @@ struct ta_pmf_shared_memory {
/* Core Layer */
int apmf_acpi_init(struct amd_pmf_dev *pmf_dev);
void apmf_acpi_deinit(struct amd_pmf_dev *pmf_dev);
+int apmf_if_call_store_buffer(struct amd_pmf_dev *pdev, int fn, void *dest, size_t out_sz);
+int apts_if_call_store_buffer(struct amd_pmf_dev *pdev, u32 index, void *data, size_t out_sz);
int amd_pmf_send_cmd(struct amd_pmf_dev *dev, u8 message, bool get, u32 arg, u32 *data);
int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev);
int apmf_install_handler(struct amd_pmf_dev *pmf_dev);
@@ -1124,17 +1127,43 @@ int amd_pmf_get_pprof_modes(struct amd_pmf_dev *pmf);
void amd_pmf_update_slider(struct amd_pmf_dev *dev, bool op, int idx,
struct amd_pmf_static_slider_granular *table);
int amd_pmf_init_sps(struct amd_pmf_dev *dev);
-int apmf_get_static_slider_granular(struct amd_pmf_dev *pdev,
- struct apmf_static_slider_granular_output *output);
int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev);
const char *amd_pmf_source_as_str(unsigned int state);
int apmf_update_fan_idx(struct amd_pmf_dev *pdev, bool manual, u32 idx);
int amd_pmf_set_sps_power_limits(struct amd_pmf_dev *pmf);
-int apmf_get_static_slider_granular_v2(struct amd_pmf_dev *dev,
- struct apmf_static_slider_granular_output_v2 *data);
-int apts_get_static_slider_granular_v2(struct amd_pmf_dev *pdev,
- struct amd_pmf_apts_granular_output *data, u32 apts_idx);
+
+static inline int
+apts_get_static_slider_granular_v2(struct amd_pmf_dev *pdev,
+ struct amd_pmf_apts_granular_output *data, u32 apts_idx)
+{
+ if (!is_apmf_func_supported(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR))
+ return -EINVAL;
+
+ return apts_if_call_store_buffer(pdev, apts_idx, data, sizeof(*data));
+}
+
+static inline int
+apmf_get_static_slider_granular_v2(struct amd_pmf_dev *pdev,
+ struct apmf_static_slider_granular_output_v2 *data)
+{
+ if (!is_apmf_func_supported(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR))
+ return -EINVAL;
+
+ return apmf_if_call_store_buffer(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR,
+ data, sizeof(*data));
+}
+
+static inline int
+apmf_get_static_slider_granular(struct amd_pmf_dev *pdev,
+ struct apmf_static_slider_granular_output *data)
+{
+ if (!is_apmf_func_supported(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR))
+ return -EINVAL;
+
+ return apmf_if_call_store_buffer(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR,
+ data, sizeof(*data));
+}
static inline bool is_pprof_balanced(struct amd_pmf_dev *pmf)
{
@@ -1142,26 +1171,56 @@ static inline bool is_pprof_balanced(struct amd_pmf_dev *pmf)
}
/* Auto Mode Layer */
-int apmf_get_auto_mode_def(struct amd_pmf_dev *pdev, struct apmf_auto_mode *data);
void amd_pmf_init_auto_mode(struct amd_pmf_dev *dev);
void amd_pmf_deinit_auto_mode(struct amd_pmf_dev *dev);
void amd_pmf_trans_automode(struct amd_pmf_dev *dev, int socket_power, ktime_t time_elapsed_ms);
-int apmf_get_sbios_requests(struct amd_pmf_dev *pdev, struct apmf_sbios_req *req);
-int apmf_get_sbios_requests_v1(struct amd_pmf_dev *pdev, struct apmf_sbios_req_v1 *req);
-int apmf_get_sbios_requests_v2(struct amd_pmf_dev *pdev, struct apmf_sbios_req_v2 *req);
void amd_pmf_update_2_cql(struct amd_pmf_dev *dev, bool is_cql_event);
int amd_pmf_reset_amt(struct amd_pmf_dev *dev);
void amd_pmf_handle_amt(struct amd_pmf_dev *dev);
+static inline int apmf_get_auto_mode_def(struct amd_pmf_dev *pdev, struct apmf_auto_mode *data)
+{
+ return apmf_if_call_store_buffer(pdev, APMF_FUNC_AUTO_MODE, data, sizeof(*data));
+}
+
+static inline int apmf_get_sbios_requests_v2(struct amd_pmf_dev *pdev,
+ struct apmf_sbios_req_v2 *req)
+{
+ return apmf_if_call_store_buffer(pdev, APMF_FUNC_SBIOS_REQUESTS, req, sizeof(*req));
+}
+
+static inline int apmf_get_sbios_requests_v1(struct amd_pmf_dev *pdev,
+ struct apmf_sbios_req_v1 *req)
+{
+ return apmf_if_call_store_buffer(pdev, APMF_FUNC_SBIOS_REQUESTS, req, sizeof(*req));
+}
+
+static inline int apmf_get_sbios_requests(struct amd_pmf_dev *pdev,
+ struct apmf_sbios_req *req)
+{
+ return apmf_if_call_store_buffer(pdev, APMF_FUNC_SBIOS_REQUESTS,
+ req, sizeof(*req));
+}
+
/* CnQF Layer */
-int apmf_get_dyn_slider_def_ac(struct amd_pmf_dev *pdev, struct apmf_dyn_slider_output *data);
-int apmf_get_dyn_slider_def_dc(struct amd_pmf_dev *pdev, struct apmf_dyn_slider_output *data);
int amd_pmf_init_cnqf(struct amd_pmf_dev *dev);
void amd_pmf_deinit_cnqf(struct amd_pmf_dev *dev);
int amd_pmf_trans_cnqf(struct amd_pmf_dev *dev, int socket_power, ktime_t time_lapsed_ms);
extern const struct attribute_group cnqf_feature_attribute_group;
+static inline int apmf_get_dyn_slider_def_ac(struct amd_pmf_dev *pdev,
+ struct apmf_dyn_slider_output *data)
+{
+ return apmf_if_call_store_buffer(pdev, APMF_FUNC_DYN_SLIDER_AC, data, sizeof(*data));
+}
+
+static inline int apmf_get_dyn_slider_def_dc(struct amd_pmf_dev *pdev,
+ struct apmf_dyn_slider_output *data)
+{
+ return apmf_if_call_store_buffer(pdev, APMF_FUNC_DYN_SLIDER_DC, data, sizeof(*data));
+}
+
/* Smart PC builder Layer */
int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev);
void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev);
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread