1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2025 Arm Ltd. */
3
4 #ifndef __LINUX_ARM_MPAM_H
5 #define __LINUX_ARM_MPAM_H
6
7 #include <linux/acpi.h>
8 #include <linux/resctrl_types.h>
9 #include <linux/types.h>
10
11 struct mpam_msc;
12
13 enum mpam_msc_iface {
14 MPAM_IFACE_MMIO, /* a real MPAM MSC */
15 MPAM_IFACE_PCC, /* using the MPAM-Fb firmware redirection */
16 };
17
18 enum mpam_class_types {
19 MPAM_CLASS_CACHE, /* Caches, e.g. L2, L3 */
20 MPAM_CLASS_MEMORY, /* Main memory */
21 MPAM_CLASS_UNKNOWN, /* Everything else, e.g. SMMU */
22 };
23
24 #define MPAM_CLASS_ID_DEFAULT 255
25
26 #ifdef CONFIG_ACPI_MPAM
27 int acpi_mpam_parse_resources(struct mpam_msc *msc,
28 struct acpi_mpam_msc_node *tbl_msc);
29
30 int acpi_mpam_count_msc(void);
31 #else
acpi_mpam_parse_resources(struct mpam_msc * msc,struct acpi_mpam_msc_node * tbl_msc)32 static inline int acpi_mpam_parse_resources(struct mpam_msc *msc,
33 struct acpi_mpam_msc_node *tbl_msc)
34 {
35 return -EINVAL;
36 }
37
acpi_mpam_count_msc(void)38 static inline int acpi_mpam_count_msc(void) { return -EINVAL; }
39 #endif
40
41 #ifdef CONFIG_ARM64_MPAM_DRIVER
42 int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
43 enum mpam_class_types type, u8 class_id, int component_id);
44 #else
mpam_ris_create(struct mpam_msc * msc,u8 ris_idx,enum mpam_class_types type,u8 class_id,int component_id)45 static inline int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
46 enum mpam_class_types type, u8 class_id,
47 int component_id)
48 {
49 return -EINVAL;
50 }
51 #endif
52
53 bool resctrl_arch_alloc_capable(void);
54 bool resctrl_arch_mon_capable(void);
55
56 void resctrl_arch_set_cpu_default_closid(int cpu, u32 closid);
57 void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32 rmid);
58 void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmid);
59 void resctrl_arch_sched_in(struct task_struct *tsk);
60 bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid);
61 bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 closid, u32 rmid);
62 u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid);
63 void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid);
64 u32 resctrl_arch_system_num_rmid_idx(void);
65
66 struct rdt_resource;
67 void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r, enum resctrl_event_id evtid);
68 void resctrl_arch_mon_ctx_free(struct rdt_resource *r, enum resctrl_event_id evtid, void *ctx);
69
70 /*
71 * The CPU configuration for MPAM is cheap to write, and is only written if it
72 * has changed. No need for fine grained enables.
73 */
resctrl_arch_enable_mon(void)74 static inline void resctrl_arch_enable_mon(void) { }
resctrl_arch_disable_mon(void)75 static inline void resctrl_arch_disable_mon(void) { }
resctrl_arch_enable_alloc(void)76 static inline void resctrl_arch_enable_alloc(void) { }
resctrl_arch_disable_alloc(void)77 static inline void resctrl_arch_disable_alloc(void) { }
78
resctrl_arch_round_mon_val(unsigned int val)79 static inline unsigned int resctrl_arch_round_mon_val(unsigned int val)
80 {
81 return val;
82 }
83
84 /**
85 * mpam_register_requestor() - Register a requestor with the MPAM driver
86 * @partid_max: The maximum PARTID value the requestor can generate.
87 * @pmg_max: The maximum PMG value the requestor can generate.
88 *
89 * Registers a requestor with the MPAM driver to ensure the chosen system-wide
90 * minimum PARTID and PMG values will allow the requestors features to be used.
91 *
92 * Returns an error if the registration is too late, and a larger PARTID/PMG
93 * value has been advertised to user-space. In this case the requestor should
94 * not use its MPAM features. Returns 0 on success.
95 */
96 int mpam_register_requestor(u16 partid_max, u8 pmg_max);
97
98 #endif /* __LINUX_ARM_MPAM_H */
99