1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Intel Uncore Frequency Control: Common defines and prototypes 4 * Copyright (c) 2022, Intel Corporation. 5 * All rights reserved. 6 * 7 */ 8 9 #ifndef __INTEL_UNCORE_FREQ_COMMON_H 10 #define __INTEL_UNCORE_FREQ_COMMON_H 11 12 #include <linux/device.h> 13 14 /* 15 * Define uncore agents, which are under uncore frequency control. 16 * Defined in the same order as specified in the TPMI UFS Specifications. 17 * It is possible that there are common uncore frequency control to more than 18 * one hardware agents. So, these defines are used as a bit mask. 19 */ 20 21 #define AGENT_TYPE_CORE 0x01 22 #define AGENT_TYPE_CACHE 0x02 23 #define AGENT_TYPE_MEMORY 0x04 24 #define AGENT_TYPE_IO 0x08 25 26 /** 27 * struct uncore_data - Encapsulate all uncore data 28 * @stored_uncore_data: Last user changed MSR 620 value, which will be restored 29 * on system resume. 30 * @initial_min_freq_khz: Sampled minimum uncore frequency at driver init 31 * @initial_max_freq_khz: Sampled maximum uncore frequency at driver init 32 * @control_cpu: Designated CPU for a die to read/write 33 * @valid: Mark the data valid/invalid 34 * @package_id: Package id for this instance 35 * @die_id: Die id for this instance 36 * @domain_id: Power domain id for this instance 37 * @cluster_id: cluster id in a domain 38 * @instance_id: Unique instance id to append to directory name 39 * @name: Sysfs entry name for this instance 40 * @agent_type_mask: Bit mask of all hardware agents for this domain 41 * @uncore_attr_group: Attribute group storage 42 * @max_freq_khz_kobj_attr: Storage for kobject attribute max_freq_khz 43 * @mix_freq_khz_kobj_attr: Storage for kobject attribute min_freq_khz 44 * @initial_max_freq_khz_kobj_attr: Storage for kobject attribute initial_max_freq_khz 45 * @initial_min_freq_khz_kobj_attr: Storage for kobject attribute initial_min_freq_khz 46 * @current_freq_khz_kobj_attr: Storage for kobject attribute current_freq_khz 47 * @domain_id_kobj_attr: Storage for kobject attribute domain_id 48 * @fabric_cluster_id_kobj_attr: Storage for kobject attribute fabric_cluster_id 49 * @package_id_kobj_attr: Storage for kobject attribute package_id 50 * @elc_low_threshold_percent_kobj_attr: 51 Storage for kobject attribute elc_low_threshold_percent 52 * @elc_high_threshold_percent_kobj_attr: 53 Storage for kobject attribute elc_high_threshold_percent 54 * @elc_high_threshold_enable_kobj_attr: 55 Storage for kobject attribute elc_high_threshold_enable 56 * @elc_floor_freq_khz_kobj_attr: Storage for kobject attribute elc_floor_freq_khz 57 * @agent_types_kobj_attr: Storage for kobject attribute agent_type 58 * @uncore_attrs: Attribute storage for group creation 59 * 60 * This structure is used to encapsulate all data related to uncore sysfs 61 * settings for a die/package. 62 */ 63 struct uncore_data { 64 u64 stored_uncore_data; 65 u32 initial_min_freq_khz; 66 u32 initial_max_freq_khz; 67 int control_cpu; 68 bool valid; 69 int package_id; 70 int die_id; 71 int domain_id; 72 int cluster_id; 73 int instance_id; 74 char name[32]; 75 u16 agent_type_mask; 76 77 struct attribute_group uncore_attr_group; 78 struct kobj_attribute max_freq_khz_kobj_attr; 79 struct kobj_attribute min_freq_khz_kobj_attr; 80 struct kobj_attribute initial_max_freq_khz_kobj_attr; 81 struct kobj_attribute initial_min_freq_khz_kobj_attr; 82 struct kobj_attribute current_freq_khz_kobj_attr; 83 struct kobj_attribute domain_id_kobj_attr; 84 struct kobj_attribute fabric_cluster_id_kobj_attr; 85 struct kobj_attribute package_id_kobj_attr; 86 struct kobj_attribute elc_low_threshold_percent_kobj_attr; 87 struct kobj_attribute elc_high_threshold_percent_kobj_attr; 88 struct kobj_attribute elc_high_threshold_enable_kobj_attr; 89 struct kobj_attribute elc_floor_freq_khz_kobj_attr; 90 struct kobj_attribute agent_types_kobj_attr; 91 struct kobj_attribute die_id_kobj_attr; 92 struct attribute *uncore_attrs[15]; 93 }; 94 95 #define UNCORE_DOMAIN_ID_INVALID -1 96 97 enum uncore_index { 98 UNCORE_INDEX_MIN_FREQ, 99 UNCORE_INDEX_MAX_FREQ, 100 UNCORE_INDEX_CURRENT_FREQ, 101 UNCORE_INDEX_EFF_LAT_CTRL_LOW_THRESHOLD, 102 UNCORE_INDEX_EFF_LAT_CTRL_HIGH_THRESHOLD, 103 UNCORE_INDEX_EFF_LAT_CTRL_HIGH_THRESHOLD_ENABLE, 104 UNCORE_INDEX_EFF_LAT_CTRL_FREQ, 105 UNCORE_INDEX_DIE_ID, 106 }; 107 108 int uncore_freq_common_init(int (*read)(struct uncore_data *data, unsigned int *value, 109 enum uncore_index index), 110 int (*write)(struct uncore_data *data, unsigned int input, 111 enum uncore_index index)); 112 void uncore_freq_common_exit(void); 113 int uncore_freq_add_entry(struct uncore_data *data, int cpu); 114 void uncore_freq_remove_die_entry(struct uncore_data *data); 115 116 #endif 117