Path: blob/master/arch/x86/kernel/cpu/resctrl/internal.h
49231 views
/* SPDX-License-Identifier: GPL-2.0 */1#ifndef _ASM_X86_RESCTRL_INTERNAL_H2#define _ASM_X86_RESCTRL_INTERNAL_H34#include <linux/resctrl.h>56#define L3_QOS_CDP_ENABLE 0x01ULL78#define L2_QOS_CDP_ENABLE 0x01ULL910#define MBM_CNTR_WIDTH_BASE 241112#define MBA_IS_LINEAR 0x41314#define MBM_CNTR_WIDTH_OFFSET_AMD 201516/* Hygon MBM counter width as an offset from MBM_CNTR_WIDTH_BASE */17#define MBM_CNTR_WIDTH_OFFSET_HYGON 81819#define RMID_VAL_ERROR BIT_ULL(63)2021#define RMID_VAL_UNAVAIL BIT_ULL(62)2223/*24* With the above fields in use 62 bits remain in MSR_IA32_QM_CTR for25* data to be returned. The counter width is discovered from the hardware26* as an offset from MBM_CNTR_WIDTH_BASE.27*/28#define MBM_CNTR_WIDTH_OFFSET_MAX (62 - MBM_CNTR_WIDTH_BASE)2930/**31* struct arch_mbm_state - values used to compute resctrl_arch_rmid_read()s32* return value.33* @chunks: Total data moved (multiply by rdt_group.mon_scale to get bytes)34* @prev_msr: Value of IA32_QM_CTR last time it was read for the RMID used to35* find this struct.36*/37struct arch_mbm_state {38u64 chunks;39u64 prev_msr;40};4142/* Setting bit 0 in L3_QOS_EXT_CFG enables the ABMC feature. */43#define ABMC_ENABLE_BIT 04445/*46* Qos Event Identifiers.47*/48#define ABMC_EXTENDED_EVT_ID BIT(31)49#define ABMC_EVT_ID BIT(0)5051/* Setting bit 1 in MSR_IA32_L3_QOS_EXT_CFG enables the SDCIAE feature. */52#define SDCIAE_ENABLE_BIT 15354/**55* struct rdt_hw_ctrl_domain - Arch private attributes of a set of CPUs that share56* a resource for a control function57* @d_resctrl: Properties exposed to the resctrl file system58* @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID)59*60* Members of this structure are accessed via helpers that provide abstraction.61*/62struct rdt_hw_ctrl_domain {63struct rdt_ctrl_domain d_resctrl;64u32 *ctrl_val;65};6667/**68* struct rdt_hw_mon_domain - Arch private attributes of a set of CPUs that share69* a resource for a monitor function70* @d_resctrl: Properties exposed to the resctrl file system71* @arch_mbm_states: Per-event pointer to the MBM event's saved state.72* An MBM event's state is an array of struct arch_mbm_state73* indexed by RMID on x86.74*75* Members of this structure are accessed via helpers that provide abstraction.76*/77struct rdt_hw_mon_domain {78struct rdt_mon_domain d_resctrl;79struct arch_mbm_state *arch_mbm_states[QOS_NUM_L3_MBM_EVENTS];80};8182static inline struct rdt_hw_ctrl_domain *resctrl_to_arch_ctrl_dom(struct rdt_ctrl_domain *r)83{84return container_of(r, struct rdt_hw_ctrl_domain, d_resctrl);85}8687static inline struct rdt_hw_mon_domain *resctrl_to_arch_mon_dom(struct rdt_mon_domain *r)88{89return container_of(r, struct rdt_hw_mon_domain, d_resctrl);90}9192/**93* struct msr_param - set a range of MSRs from a domain94* @res: The resource to use95* @dom: The domain to update96* @low: Beginning index from base MSR97* @high: End index98*/99struct msr_param {100struct rdt_resource *res;101struct rdt_ctrl_domain *dom;102u32 low;103u32 high;104};105106/**107* struct rdt_hw_resource - arch private attributes of a resctrl resource108* @r_resctrl: Attributes of the resource used directly by resctrl.109* @num_closid: Maximum number of closid this hardware can support,110* regardless of CDP. This is exposed via111* resctrl_arch_get_num_closid() to avoid confusion112* with struct resctrl_schema's property of the same name,113* which has been corrected for features like CDP.114* @msr_base: Base MSR address for CBMs115* @msr_update: Function pointer to update QOS MSRs116* @mon_scale: cqm counter * mon_scale = occupancy in bytes117* @mbm_width: Monitor width, to detect and correct for overflow.118* @cdp_enabled: CDP state of this resource119* @mbm_cntr_assign_enabled: ABMC feature is enabled120* @sdciae_enabled: SDCIAE feature (backing "io_alloc") is enabled.121*122* Members of this structure are either private to the architecture123* e.g. mbm_width, or accessed via helpers that provide abstraction. e.g.124* msr_update and msr_base.125*/126struct rdt_hw_resource {127struct rdt_resource r_resctrl;128u32 num_closid;129unsigned int msr_base;130void (*msr_update)(struct msr_param *m);131unsigned int mon_scale;132unsigned int mbm_width;133bool cdp_enabled;134bool mbm_cntr_assign_enabled;135bool sdciae_enabled;136};137138static inline struct rdt_hw_resource *resctrl_to_arch_res(struct rdt_resource *r)139{140return container_of(r, struct rdt_hw_resource, r_resctrl);141}142143extern struct rdt_hw_resource rdt_resources_all[];144145void arch_mon_domain_online(struct rdt_resource *r, struct rdt_mon_domain *d);146147/* CPUID.(EAX=10H, ECX=ResID=1).EAX */148union cpuid_0x10_1_eax {149struct {150unsigned int cbm_len:5;151} split;152unsigned int full;153};154155/* CPUID.(EAX=10H, ECX=ResID=3).EAX */156union cpuid_0x10_3_eax {157struct {158unsigned int max_delay:12;159} split;160unsigned int full;161};162163/* CPUID.(EAX=10H, ECX=ResID).ECX */164union cpuid_0x10_x_ecx {165struct {166unsigned int reserved:3;167unsigned int noncont:1;168} split;169unsigned int full;170};171172/* CPUID.(EAX=10H, ECX=ResID).EDX */173union cpuid_0x10_x_edx {174struct {175unsigned int cos_max:16;176} split;177unsigned int full;178};179180/*181* ABMC counters are configured by writing to MSR_IA32_L3_QOS_ABMC_CFG.182*183* @bw_type : Event configuration that represents the memory184* transactions being tracked by the @cntr_id.185* @bw_src : Bandwidth source (RMID or CLOSID).186* @reserved1 : Reserved.187* @is_clos : @bw_src field is a CLOSID (not an RMID).188* @cntr_id : Counter identifier.189* @reserved : Reserved.190* @cntr_en : Counting enable bit.191* @cfg_en : Configuration enable bit.192*193* Configuration and counting:194* Counter can be configured across multiple writes to MSR. Configuration195* is applied only when @cfg_en = 1. Counter @cntr_id is reset when the196* configuration is applied.197* @cfg_en = 1, @cntr_en = 0 : Apply @cntr_id configuration but do not198* count events.199* @cfg_en = 1, @cntr_en = 1 : Apply @cntr_id configuration and start200* counting events.201*/202union l3_qos_abmc_cfg {203struct {204unsigned long bw_type :32,205bw_src :12,206reserved1: 3,207is_clos : 1,208cntr_id : 5,209reserved : 9,210cntr_en : 1,211cfg_en : 1;212} split;213unsigned long full;214};215216void rdt_ctrl_update(void *arg);217218int rdt_get_mon_l3_config(struct rdt_resource *r);219220bool rdt_cpu_has(int flag);221222void __init intel_rdt_mbm_apply_quirk(void);223224void rdt_domain_reconfigure_cdp(struct rdt_resource *r);225void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_resource *r);226227#endif /* _ASM_X86_RESCTRL_INTERNAL_H */228229230