xref: /illumos-gate/usr/src/uts/intel/io/amdzen/amdzen.h (revision a4955f4fa65e38d70c07d38e657a9aff43fa155f)
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 2022 Oxide Computer Company
14  */
15 
16 #ifndef _AMDZEN_H
17 #define	_AMDZEN_H
18 
19 #include <sys/ddi.h>
20 #include <sys/sunddi.h>
21 #include <sys/list.h>
22 #include <sys/pci.h>
23 #include <sys/taskq.h>
24 #include <sys/bitmap.h>
25 #include <sys/amdzen/df.h>
26 
27 #include "amdzen_client.h"
28 
29 /*
30  * This header describes properties of the data fabric and our internal state
31  * for the Zen Nexus driver.
32  */
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * The data fabric devices are always defined to be on PCI bus zero starting at
40  * device 0x18.
41  */
42 #define	AMDZEN_DF_BUSNO		0x00
43 #define	AMDZEN_DF_FIRST_DEVICE	0x18
44 
45 /*
46  * The maximum amount of Data Fabric node's we can see. In Zen 1 there were up
47  * to four per package.
48  */
49 #define	AMDZEN_MAX_DFS		0x8
50 
51 /*
52  * The maximum number of PCI functions we expect to encounter on the data
53  * fabric.
54  */
55 #define	AMDZEN_MAX_DF_FUNCS	0x8
56 
57 /*
58  * Northbridge registers that are relevant for the nexus, mostly for SMN.
59  */
60 #define	AMDZEN_NB_SMN_ADDR	0x60
61 #define	AMDZEN_NB_SMN_DATA	0x64
62 
63 /*
64  * AMD PCI ID for reference
65  */
66 #define	AMDZEN_PCI_VID_AMD	0x1022
67 
68 /*
69  * Hygon PCI ID for reference
70  */
71 #define	AMDZEN_PCI_VID_HYGON	0x1d94
72 
73 typedef enum {
74 	AMDZEN_STUB_TYPE_DF,
75 	AMDZEN_STUB_TYPE_NB
76 } amdzen_stub_type_t;
77 
78 typedef struct {
79 	list_node_t		azns_link;
80 	dev_info_t		*azns_dip;
81 	uint16_t		azns_vid;
82 	uint16_t		azns_did;
83 	uint16_t		azns_bus;
84 	uint16_t		azns_dev;
85 	uint16_t		azns_func;
86 	ddi_acc_handle_t	azns_cfgspace;
87 } amdzen_stub_t;
88 
89 typedef enum  {
90 	AMDZEN_DFE_F_MCA	= 1 << 0,
91 	AMDZEN_DFE_F_ENABLED	= 1 << 1
92 } amdzen_df_ent_flags_t;
93 
94 typedef struct {
95 	uint8_t adfe_drvid;
96 	amdzen_df_ent_flags_t adfe_flags;
97 	df_type_t adfe_type;
98 	uint8_t adfe_subtype;
99 	uint8_t adfe_fabric_id;
100 	uint8_t adfe_inst_id;
101 	uint32_t adfe_info0;
102 	uint32_t adfe_info1;
103 	uint32_t adfe_info2;
104 	uint32_t adfe_info3;
105 } amdzen_df_ent_t;
106 
107 typedef enum {
108 	AMDZEN_DF_F_VALID		= 1 << 0,
109 	AMDZEN_DF_F_FOUND_NB		= 1 << 1,
110 } amdzen_df_flags_t;
111 
112 typedef struct {
113 	amdzen_df_flags_t	adf_flags;
114 	uint_t		adf_nb_busno;
115 	amdzen_stub_t	*adf_funcs[AMDZEN_MAX_DF_FUNCS];
116 	amdzen_stub_t	*adf_nb;
117 	uint8_t		adf_major;
118 	uint8_t		adf_minor;
119 	uint_t		adf_nents;
120 	df_rev_t	adf_rev;
121 	amdzen_df_ent_t	*adf_ents;
122 	uint32_t	adf_nodeid;
123 	uint32_t	adf_syscfg;
124 	uint32_t	adf_mask0;
125 	uint32_t	adf_mask1;
126 	uint32_t	adf_mask2;
127 	df_fabric_decomp_t	adf_decomp;
128 } amdzen_df_t;
129 
130 typedef enum {
131 	AMDZEN_F_UNSUPPORTED		= 1 << 0,
132 	AMDZEN_F_DEVICE_ERROR		= 1 << 1,
133 	AMDZEN_F_MAP_ERROR		= 1 << 2,
134 	AMDZEN_F_SCAN_DISPATCHED	= 1 << 3,
135 	AMDZEN_F_SCAN_COMPLETE		= 1 << 4,
136 	AMDZEN_F_ATTACH_DISPATCHED	= 1 << 5,
137 	AMDZEN_F_ATTACH_COMPLETE	= 1 << 6
138 } amdzen_flags_t;
139 
140 #define	AMDZEN_F_TASKQ_MASK	(AMDZEN_F_SCAN_DISPATCHED | \
141     AMDZEN_F_SCAN_COMPLETE | AMDZEN_F_ATTACH_DISPATCHED | \
142     AMDZEN_F_ATTACH_COMPLETE)
143 
144 typedef struct amdzen {
145 	kmutex_t	azn_mutex;
146 	kcondvar_t	azn_cv;
147 	amdzen_flags_t	azn_flags;
148 	dev_info_t	*azn_dip;
149 	taskqid_t	azn_taskqid;
150 	uint_t		azn_nscanned;
151 	uint_t		azn_npresent;
152 	list_t		azn_df_stubs;
153 	list_t		azn_nb_stubs;
154 	uint_t		azn_ndfs;
155 	amdzen_df_t	azn_dfs[AMDZEN_MAX_DFS];
156 } amdzen_t;
157 
158 typedef enum {
159 	AMDZEN_C_SMNTEMP = 1,
160 	AMDZEN_C_USMN,
161 	AMDZEN_C_ZEN_UDF,
162 	AMDZEN_C_ZEN_UMC
163 } amdzen_child_t;
164 
165 /*
166  * Functions for stubs.
167  */
168 extern int amdzen_attach_stub(dev_info_t *, ddi_attach_cmd_t);
169 extern int amdzen_detach_stub(dev_info_t *, ddi_detach_cmd_t);
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 #endif /* _AMDZEN_H */
176