linux/drivers/platform/x86/amd/pmf/pmf.h

/* SPDX-License-Identifier: GPL-2.0 */
/*
 * AMD Platform Management Framework Driver
 *
 * Copyright (c) 2022, Advanced Micro Devices, Inc.
 * All Rights Reserved.
 *
 * Author: Shyam Sundar S K <[email protected]>
 */

#ifndef PMF_H
#define PMF_H

#include <linux/acpi.h>
#include <linux/input.h>
#include <linux/platform_profile.h>

#define POLICY_BUF_MAX_SZ
#define POLICY_SIGN_COOKIE
#define POLICY_COOKIE_OFFSET

struct cookie_header {} __packed;

/* APMF Functions */
#define APMF_FUNC_VERIFY_INTERFACE
#define APMF_FUNC_GET_SYS_PARAMS
#define APMF_FUNC_SBIOS_REQUESTS
#define APMF_FUNC_SBIOS_HEARTBEAT
#define APMF_FUNC_AUTO_MODE
#define APMF_FUNC_SET_FAN_IDX
#define APMF_FUNC_OS_POWER_SLIDER_UPDATE
#define APMF_FUNC_STATIC_SLIDER_GRANULAR
#define APMF_FUNC_DYN_SLIDER_AC
#define APMF_FUNC_DYN_SLIDER_DC
#define APMF_FUNC_SBIOS_HEARTBEAT_V2

/* Message Definitions */
#define SET_SPL
#define SET_SPPT
#define SET_FPPT
#define GET_SPL
#define GET_SPPT
#define GET_FPPT
#define SET_DRAM_ADDR_HIGH
#define SET_DRAM_ADDR_LOW
#define SET_TRANSFER_TABLE
#define SET_STT_MIN_LIMIT
#define SET_STT_LIMIT_APU
#define SET_STT_LIMIT_HS2
#define SET_SPPT_APU_ONLY
#define GET_SPPT_APU_ONLY
#define GET_STT_MIN_LIMIT
#define GET_STT_LIMIT_APU
#define GET_STT_LIMIT_HS2
#define SET_P3T
#define SET_PMF_PPT
#define SET_PMF_PPT_APU_ONLY

/* OS slider update notification */
#define DC_BEST_PERF
#define DC_BETTER_PERF
#define DC_BATTERY_SAVER
#define AC_BEST_PERF
#define AC_BETTER_PERF
#define AC_BETTER_BATTERY

/* Fan Index for Auto Mode */
#define FAN_INDEX_AUTO

#define ARG_NONE
#define AVG_SAMPLE_SIZE

/* Policy Actions */
#define PMF_POLICY_SPL
#define PMF_POLICY_SPPT
#define PMF_POLICY_FPPT
#define PMF_POLICY_SPPT_APU_ONLY
#define PMF_POLICY_STT_MIN
#define PMF_POLICY_STT_SKINTEMP_APU
#define PMF_POLICY_STT_SKINTEMP_HS2
#define PMF_POLICY_SYSTEM_STATE
#define PMF_POLICY_P3T

/* TA macros */
#define PMF_TA_IF_VERSION_MAJOR
#define TA_PMF_ACTION_MAX
#define TA_PMF_UNDO_MAX
#define TA_OUTPUT_RESERVED_MEM
#define MAX_OPERATION_PARAMS

#define PMF_IF_V1
#define PMF_IF_V2

#define APTS_MAX_STATES

/* APTS PMF BIOS Interface */
struct amd_pmf_apts_output {} __packed;

struct amd_pmf_apts_granular_output {} __packed;

struct amd_pmf_apts_granular {};

struct sbios_hb_event_v2 {} __packed;

enum sbios_hb_v2 {};

/* AMD PMF BIOS interfaces */
struct apmf_verify_interface {} __packed;

struct apmf_system_params {} __packed;

struct apmf_sbios_req {} __packed;

struct apmf_sbios_req_v2 {} __packed;

struct apmf_fan_idx {} __packed;

struct smu_pmf_metrics {} __packed;

enum amd_stt_skin_temp {};

enum amd_slider_op {};

enum power_source {};

enum power_modes {};

enum power_modes_v2 {};

struct amd_pmf_dev {};

struct apmf_sps_prop_granular_v2 {} __packed;

struct apmf_sps_prop_granular {} __packed;

/* Static Slider */
struct apmf_static_slider_granular_output {} __packed;

struct amd_pmf_static_slider_granular {};

struct apmf_static_slider_granular_output_v2 {} __packed;

struct amd_pmf_static_slider_granular_v2 {};

struct os_power_slider {} __packed;

struct fan_table_control {};

struct power_table_control {};

/* Auto Mode Layer */
enum auto_mode_transition_priority {};

enum auto_mode_mode {};

struct auto_mode_trans_params {};

struct auto_mode_mode_settings {};

struct auto_mode_mode_config {};

struct apmf_auto_mode {} __packed;

/* CnQF Layer */
enum cnqf_trans_priority {};

enum cnqf_mode {};

enum apmf_cnqf_pos {};

struct cnqf_mode_settings {};

struct cnqf_tran_params {};

struct cnqf_config {};

struct apmf_cnqf_power_set {} __packed;

struct apmf_dyn_slider_output {} __packed;

/* Smart PC - TA internals */
enum system_state {};

enum ta_slider {};

/* Command ids for TA communication */
enum ta_pmf_command {};

enum ta_pmf_error_type {};

struct pmf_action_table {};

/* Input conditions */
struct ta_pmf_condition_info {};

struct ta_pmf_load_policy_table {};

/* TA initialization params */
struct ta_pmf_init_table {};

/* Everything the TA needs to Enact Policies */
struct ta_pmf_enact_table {};

struct ta_pmf_action {};

/* Output actions from TA */
struct ta_pmf_enact_result {};

ta_pmf_input;

ta_pmf_output;

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);

/* SPS Layer */
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);
void amd_pmf_deinit_sps(struct amd_pmf_dev *dev);
int apmf_get_static_slider_granular(struct amd_pmf_dev *pdev,
				    struct apmf_static_slider_granular_output *output);
bool is_pprof_balanced(struct amd_pmf_dev *pmf);
int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev);
const char *amd_pmf_source_as_str(unsigned int state);

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);

/* 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_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);

/* 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;

/* 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);
int apmf_check_smart_pc(struct amd_pmf_dev *pmf_dev);

/* Smart PC - TA interfaces */
void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in);
void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in);

/* Quirk infrastructure */
void amd_pmf_quirks_init(struct amd_pmf_dev *dev);

#endif /* PMF_H */