linux/include/acpi/processor.h

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __ACPI_PROCESSOR_H
#define __ACPI_PROCESSOR_H

#include <linux/cpu.h>
#include <linux/cpufreq.h>
#include <linux/pm_qos.h>
#include <linux/printk.h>
#include <linux/sched.h>
#include <linux/smp.h>
#include <linux/thermal.h>
#include <linux/types.h>
#include <linux/workqueue.h>

#include <asm/acpi.h>

#define ACPI_PROCESSOR_CLASS
#define ACPI_PROCESSOR_DEVICE_NAME
#define ACPI_PROCESSOR_DEVICE_HID
#define ACPI_PROCESSOR_CONTAINER_HID

#define ACPI_PROCESSOR_BUSY_METRIC

#define ACPI_PROCESSOR_MAX_POWER
#define ACPI_PROCESSOR_MAX_C2_LATENCY
#define ACPI_PROCESSOR_MAX_C3_LATENCY

#define ACPI_PROCESSOR_MAX_THROTTLING
#define ACPI_PROCESSOR_MAX_THROTTLE
#define ACPI_PROCESSOR_MAX_DUTY_WIDTH

#define ACPI_PDC_REVISION_ID

#define ACPI_PSD_REV0_REVISION
#define ACPI_PSD_REV0_ENTRIES

#define ACPI_TSD_REV0_REVISION
#define ACPI_TSD_REV0_ENTRIES
/*
 * Types of coordination defined in ACPI 3.0. Same macros can be used across
 * P, C and T states
 */
#define DOMAIN_COORD_TYPE_SW_ALL
#define DOMAIN_COORD_TYPE_SW_ANY
#define DOMAIN_COORD_TYPE_HW_ALL

#define ACPI_CSTATE_SYSTEMIO
#define ACPI_CSTATE_FFH
#define ACPI_CSTATE_HALT
#define ACPI_CSTATE_INTEGER

#define ACPI_CX_DESC_LEN

/* Power Management */

struct acpi_processor_cx;

struct acpi_power_register {} __packed;

struct acpi_processor_cx {};

struct acpi_lpi_state {};

struct acpi_processor_power {};

/* Performance Management */

struct acpi_psd_package {} __packed;

struct acpi_pct_register {} __packed;

struct acpi_processor_px {};

struct acpi_processor_performance {};

/* Throttling Control */

struct acpi_tsd_package {} __packed;

struct acpi_ptc_register {} __packed;

struct acpi_processor_tx_tss {};
struct acpi_processor_tx {};

struct acpi_processor;
struct acpi_processor_throttling {};

/* Limit Interface */

struct acpi_processor_lx {};

struct acpi_processor_limit {};

struct acpi_processor_flags {};

struct acpi_processor {};

struct acpi_processor_errata {};

extern int acpi_processor_preregister_performance(struct
						  acpi_processor_performance
						  __percpu *performance);

extern int acpi_processor_register_performance(struct acpi_processor_performance
					       *performance, unsigned int cpu);
extern void acpi_processor_unregister_performance(unsigned int cpu);

int acpi_processor_pstate_control(void);
/* note: this locks both the calling module and the processor module
         if a _PPC object exists, rmmod is disallowed then */
int acpi_processor_notify_smm(struct module *calling_module);
int acpi_processor_get_psd(acpi_handle handle,
			   struct acpi_psd_package *pdomain);

/* parsing the _P* objects. */
extern int acpi_processor_get_performance_info(struct acpi_processor *pr);

/* for communication between multiple parts of the processor kernel module */
DECLARE_PER_CPU(struct acpi_processor *, processors);
extern struct acpi_processor_errata errata;

#if defined(ARCH_HAS_POWER_INIT) && defined(CONFIG_ACPI_PROCESSOR_CSTATE)
void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
					unsigned int cpu);
int acpi_processor_ffh_cstate_probe(unsigned int cpu,
				    struct acpi_processor_cx *cx,
				    struct acpi_power_register *reg);
void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cstate);
#else
static inline void acpi_processor_power_init_bm_check(struct
						      acpi_processor_flags
						      *flags, unsigned int cpu)
{
	flags->bm_check = 1;
	return;
}
static inline int acpi_processor_ffh_cstate_probe(unsigned int cpu,
						  struct acpi_processor_cx *cx,
						  struct acpi_power_register
						  *reg)
{
	return -1;
}
static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx
						   *cstate)
{
	return;
}
#endif

static inline int call_on_cpu(int cpu, long (*fn)(void *), void *arg,
			      bool direct)
{}

/* in processor_perflib.c */

#ifdef CONFIG_CPU_FREQ
extern bool acpi_processor_cpufreq_init;
void acpi_processor_ignore_ppc_init(void);
void acpi_processor_ppc_init(struct cpufreq_policy *policy);
void acpi_processor_ppc_exit(struct cpufreq_policy *policy);
void acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag);
extern int acpi_processor_get_bios_limit(int cpu, unsigned int *limit);
#else
static inline void acpi_processor_ignore_ppc_init(void)
{
	return;
}
static inline void acpi_processor_ppc_init(struct cpufreq_policy *policy)
{
	return;
}
static inline void acpi_processor_ppc_exit(struct cpufreq_policy *policy)
{
	return;
}
static inline void acpi_processor_ppc_has_changed(struct acpi_processor *pr,
								int event_flag)
{
	static unsigned int printout = 1;
	if (printout) {
		printk(KERN_WARNING
		       "Warning: Processor Platform Limit event detected, but not handled.\n");
		printk(KERN_WARNING
		       "Consider compiling CPUfreq support into your kernel.\n");
		printout = 0;
	}
}
static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
{
	return -ENODEV;
}

#endif				/* CONFIG_CPU_FREQ */

/* in processor_core.c */
phys_cpuid_t acpi_get_phys_id(acpi_handle, int type, u32 acpi_id);
phys_cpuid_t acpi_map_madt_entry(u32 acpi_id);
int acpi_map_cpuid(phys_cpuid_t phys_id, u32 acpi_id);
int acpi_get_cpuid(acpi_handle, int type, u32 acpi_id);

#ifdef CONFIG_ACPI_CPPC_LIB
extern int acpi_cppc_processor_probe(struct acpi_processor *pr);
extern void acpi_cppc_processor_exit(struct acpi_processor *pr);
#else
static inline int acpi_cppc_processor_probe(struct acpi_processor *pr)
{
	return 0;
}
static inline void acpi_cppc_processor_exit(struct acpi_processor *pr)
{
	return;
}
#endif	/* CONFIG_ACPI_CPPC_LIB */

/* in processor_pdc.c */
void acpi_processor_set_pdc(acpi_handle handle);

/* in processor_throttling.c */
#ifdef CONFIG_ACPI_CPU_FREQ_PSS
int acpi_processor_tstate_has_changed(struct acpi_processor *pr);
int acpi_processor_get_throttling_info(struct acpi_processor *pr);
extern int acpi_processor_set_throttling(struct acpi_processor *pr,
					 int state, bool force);
/*
 * Reevaluate whether the T-state is invalid after one cpu is
 * onlined/offlined. In such case the flags.throttling will be updated.
 */
extern void acpi_processor_reevaluate_tstate(struct acpi_processor *pr,
			bool is_dead);
extern const struct file_operations acpi_processor_throttling_fops;
extern void acpi_processor_throttling_init(void);
#else
static inline int acpi_processor_tstate_has_changed(struct acpi_processor *pr)
{
	return 0;
}

static inline int acpi_processor_get_throttling_info(struct acpi_processor *pr)
{
	return -ENODEV;
}

static inline int acpi_processor_set_throttling(struct acpi_processor *pr,
					 int state, bool force)
{
	return -ENODEV;
}

static inline void acpi_processor_reevaluate_tstate(struct acpi_processor *pr,
			bool is_dead) {}

static inline void acpi_processor_throttling_init(void) {}
#endif	/* CONFIG_ACPI_CPU_FREQ_PSS */

/* in processor_idle.c */
extern struct cpuidle_driver acpi_idle_driver;
#ifdef CONFIG_ACPI_PROCESSOR_IDLE
int acpi_processor_power_init(struct acpi_processor *pr);
int acpi_processor_power_exit(struct acpi_processor *pr);
int acpi_processor_power_state_has_changed(struct acpi_processor *pr);
int acpi_processor_hotplug(struct acpi_processor *pr);
#else
static inline int acpi_processor_power_init(struct acpi_processor *pr)
{
	return -ENODEV;
}

static inline int acpi_processor_power_exit(struct acpi_processor *pr)
{
	return -ENODEV;
}

static inline int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
{
	return -ENODEV;
}

static inline int acpi_processor_hotplug(struct acpi_processor *pr)
{
	return -ENODEV;
}
#endif /* CONFIG_ACPI_PROCESSOR_IDLE */

/* in processor_thermal.c */
int acpi_processor_thermal_init(struct acpi_processor *pr,
				struct acpi_device *device);
void acpi_processor_thermal_exit(struct acpi_processor *pr,
				 struct acpi_device *device);
extern const struct thermal_cooling_device_ops processor_cooling_ops;
#ifdef CONFIG_CPU_FREQ
void acpi_thermal_cpufreq_init(struct cpufreq_policy *policy);
void acpi_thermal_cpufreq_exit(struct cpufreq_policy *policy);
#else
static inline void acpi_thermal_cpufreq_init(struct cpufreq_policy *policy)
{
	return;
}
static inline void acpi_thermal_cpufreq_exit(struct cpufreq_policy *policy)
{
	return;
}
#endif	/* CONFIG_CPU_FREQ */

#ifdef CONFIG_ACPI_PROCESSOR_IDLE
extern int acpi_processor_ffh_lpi_probe(unsigned int cpu);
extern int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi);
#endif

#endif