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 * @seqnum_id: Unique sequential id to append to directory name 39 * @instance_id: Die indices or feature instances for a single TPMI device 40 * @name: Sysfs entry name for this instance 41 * @agent_type_mask: Bit mask of all hardware agents for this domain 42 * @uncore_attr_group: Attribute group storage 43 * @max_freq_khz_kobj_attr: Storage for kobject attribute max_freq_khz 44 * @min_freq_khz_kobj_attr: Storage for kobject attribute min_freq_khz 45 * @initial_max_freq_khz_kobj_attr: Storage for kobject attribute initial_max_freq_khz 46 * @initial_min_freq_khz_kobj_attr: Storage for kobject attribute initial_min_freq_khz 47 * @current_freq_khz_kobj_attr: Storage for kobject attribute current_freq_khz 48 * @domain_id_kobj_attr: Storage for kobject attribute domain_id 49 * @fabric_cluster_id_kobj_attr: Storage for kobject attribute fabric_cluster_id 50 * @package_id_kobj_attr: Storage for kobject attribute package_id 51 * @elc_low_threshold_percent_kobj_attr: 52 * Storage for kobject attribute elc_low_threshold_percent 53 * @elc_high_threshold_percent_kobj_attr: 54 * Storage for kobject attribute elc_high_threshold_percent 55 * @elc_high_threshold_enable_kobj_attr: 56 * Storage for kobject attribute elc_high_threshold_enable 57 * @elc_floor_freq_khz_kobj_attr: Storage for kobject attribute elc_floor_freq_khz 58 * @agent_types_kobj_attr: Storage for kobject attribute agent_type 59 * @die_id_kobj_attr: Attribute storage for die_id information 60 * @instance_id_kobj_attr: Attribute storage for instance_id value 61 * @uncore_attrs: Attribute storage for group creation 62 * 63 * This structure is used to encapsulate all data related to uncore sysfs 64 * settings for a die/package. 65 */ 66 struct uncore_data { 67 u64 stored_uncore_data; 68 u32 initial_min_freq_khz; 69 u32 initial_max_freq_khz; 70 int control_cpu; 71 bool valid; 72 int package_id; 73 int die_id; 74 int domain_id; 75 int cluster_id; 76 int seqnum_id; 77 int instance_id; 78 char name[32]; 79 u16 agent_type_mask; 80 81 struct attribute_group uncore_attr_group; 82 struct kobj_attribute max_freq_khz_kobj_attr; 83 struct kobj_attribute min_freq_khz_kobj_attr; 84 struct kobj_attribute initial_max_freq_khz_kobj_attr; 85 struct kobj_attribute initial_min_freq_khz_kobj_attr; 86 struct kobj_attribute current_freq_khz_kobj_attr; 87 struct kobj_attribute domain_id_kobj_attr; 88 struct kobj_attribute fabric_cluster_id_kobj_attr; 89 struct kobj_attribute package_id_kobj_attr; 90 struct kobj_attribute elc_low_threshold_percent_kobj_attr; 91 struct kobj_attribute elc_high_threshold_percent_kobj_attr; 92 struct kobj_attribute elc_high_threshold_enable_kobj_attr; 93 struct kobj_attribute elc_floor_freq_khz_kobj_attr; 94 struct kobj_attribute agent_types_kobj_attr; 95 struct kobj_attribute die_id_kobj_attr; 96 struct kobj_attribute instance_id_kobj_attr; 97 struct attribute *uncore_attrs[16]; 98 }; 99 100 #define UNCORE_DOMAIN_ID_INVALID -1 101 102 enum uncore_index { 103 UNCORE_INDEX_MIN_FREQ, 104 UNCORE_INDEX_MAX_FREQ, 105 UNCORE_INDEX_CURRENT_FREQ, 106 UNCORE_INDEX_EFF_LAT_CTRL_LOW_THRESHOLD, 107 UNCORE_INDEX_EFF_LAT_CTRL_HIGH_THRESHOLD, 108 UNCORE_INDEX_EFF_LAT_CTRL_HIGH_THRESHOLD_ENABLE, 109 UNCORE_INDEX_EFF_LAT_CTRL_FREQ, 110 UNCORE_INDEX_DIE_ID, 111 }; 112 113 int uncore_freq_common_init(int (*read)(struct uncore_data *data, unsigned int *value, 114 enum uncore_index index), 115 int (*write)(struct uncore_data *data, unsigned int input, 116 enum uncore_index index)); 117 void uncore_freq_common_exit(void); 118 int uncore_freq_add_entry(struct uncore_data *data, int cpu); 119 void uncore_freq_remove_die_entry(struct uncore_data *data); 120 121 #endif 122