xref: /illumos-gate/usr/src/uts/intel/io/amdzen/amdzen_client.h (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2023 Oxide Computer Company
14  */
15 
16 #ifndef _AMDZEN_CLIENT_H
17 #define	_AMDZEN_CLIENT_H
18 
19 /*
20  * This header provides client routines to clients of the amdzen nexus driver.
21  */
22 
23 #include <sys/types.h>
24 #include <sys/amdzen/df.h>
25 #include <sys/amdzen/smn.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /*
32  * This struct encodes enough information to later be used to compose and
33  * decompose a fabric ID and component ID. A fabric ID is broken into its node
34  * and component IDs and then a node ID is further decomposed into a socket and
35  * die ID.
36  */
37 typedef struct {
38 	uint32_t	dfd_sock_mask;
39 	uint32_t	dfd_die_mask;
40 	uint32_t	dfd_node_mask;
41 	uint32_t	dfd_comp_mask;
42 	uint8_t		dfd_sock_shift;
43 	uint8_t		dfd_die_shift;
44 	uint8_t		dfd_node_shift;
45 	uint8_t		dfd_comp_shift;
46 } df_fabric_decomp_t;
47 
48 /*
49  * This struct is similar to the above, but describes how an APIC ID is broken
50  * down into its logical pieces. These are not the same as those above and
51  * cannot be assumed to be. The mask is present when decomposing the ID and
52  * should be applied before the shift.
53  */
54 typedef struct {
55 	uint32_t	aad_sock_mask;
56 	uint32_t	aad_die_mask;
57 	uint32_t	aad_ccd_mask;
58 	uint32_t	aad_ccx_mask;
59 	uint32_t	aad_core_mask;
60 	uint32_t	aad_thread_mask;
61 	uint8_t		aad_sock_shift;
62 	uint8_t		aad_die_shift;
63 	uint8_t		aad_ccd_shift;
64 	uint8_t		aad_ccx_shift;
65 	uint8_t		aad_core_shift;
66 	uint8_t		aad_thread_shift;
67 } amdzen_apic_decomp_t;
68 
69 /*
70  * The following routines are used for Fabric and APIC ID decomposition and are
71  * suitable either for kernel or userland use. They are found in
72  * usr/src/common/zen/zen_fabric_utils.c.
73  */
74 extern boolean_t zen_fabric_id_valid_fabid(const df_fabric_decomp_t *,
75     const uint32_t);
76 extern boolean_t zen_fabric_id_valid_parts(const df_fabric_decomp_t *,
77     const uint32_t, const uint32_t, const uint32_t);
78 extern void zen_fabric_id_decompose(const df_fabric_decomp_t *, const uint32_t,
79     uint32_t *, uint32_t *, uint32_t *);
80 extern void zen_fabric_id_compose(const df_fabric_decomp_t *, const uint32_t,
81     const uint32_t, const uint32_t, uint32_t *);
82 
83 extern void zen_apic_id_compose(const amdzen_apic_decomp_t *, const uint32_t,
84     const uint32_t, const uint32_t, const uint32_t, const uint32_t,
85     const uint32_t, uint32_t *);
86 
87 #ifdef	_KERNEL
88 
89 extern uint_t amdzen_c_df_count(void);
90 extern df_rev_t amdzen_c_df_rev(void);
91 extern int amdzen_c_df_fabric_decomp(df_fabric_decomp_t *);
92 
93 /*
94  * SMN and DF access routines.
95  */
96 extern int amdzen_c_smn_read(uint_t, const smn_reg_t, uint32_t *);
97 extern int amdzen_c_smn_write(uint_t, const smn_reg_t, const uint32_t);
98 extern int amdzen_c_df_read32(uint_t, uint8_t, const df_reg_def_t, uint32_t *);
99 extern int amdzen_c_df_read64(uint_t, uint8_t, const df_reg_def_t, uint64_t *);
100 
101 /*
102  * The following are logical types that we can iterate over. Note, that these
103  * are a combination of a DF type and subtype. This is used to smooth over the
104  * differences between different DF revisions and how they indicate these types.
105  */
106 typedef enum {
107 	/*
108 	 * Iterate over only DDR memory controllers.
109 	 */
110 	ZEN_DF_TYPE_CS_UMC,
111 	/*
112 	 * Iterate only over CPU based CCMs.
113 	 */
114 	ZEN_DF_TYPE_CCM_CPU
115 } zen_df_type_t;
116 
117 typedef int (*amdzen_c_iter_f)(uint_t, uint32_t, uint32_t, void *);
118 extern int amdzen_c_df_iter(uint_t, zen_df_type_t, amdzen_c_iter_f, void *);
119 
120 #endif	/* _KERNEL */
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 
126 #endif /* _AMDZEN_CLIENT_H */
127