@@ -23,6 +23,12 @@ static bool mcc_initialized = false;
2323#define T6000_DCS_STRIDE 0x100000
2424#define T6000_DCS_COUNT 4
2525
26+ #define T6031_PLANE_OFFSET 0
27+ #define T6031_PLANE_STRIDE 0x40000
28+ #define T6031_GLOBAL_OFFSET 0x100000
29+ #define T6031_DCS_OFFSET 0x400000
30+ #define T6031_DCS_STRIDE 0x200000
31+
2632#define PLANE_TZ_MAX_REGS 4
2733
2834struct tz_regs {
@@ -49,6 +55,14 @@ struct tz_regs t602x_tz_regs = {
4955 .enable = 0x6c8 ,
5056};
5157
58+ struct tz_regs t603x_tz_regs = {
59+ .count = 4 ,
60+ .stride = 0x14 ,
61+ .start = 0x6d8 ,
62+ .end = 0x6dc ,
63+ .enable = 0x6e4 ,
64+ };
65+
5266#define PLANE_CACHE_ENABLE 0x1c00
5367#define PLANE_CACHE_STATUS 0x1c04
5468
@@ -64,6 +78,12 @@ struct tz_regs t602x_tz_regs = {
6478 (FIELD_PREP(T6000_CACHE_STATUS_DATA_COUNT, T6000_CACHE_WAYS) | \
6579 FIELD_PREP(T6000_CACHE_STATUS_TAG_COUNT, T6000_CACHE_WAYS))
6680
81+ #define T6031_CACHE_WAYS 12
82+ #define T6031_CACHE_STATUS_MASK (T6000_CACHE_STATUS_DATA_COUNT | T6000_CACHE_STATUS_TAG_COUNT)
83+ #define T6031_CACHE_STATUS_VAL \
84+ (FIELD_PREP(T6000_CACHE_STATUS_DATA_COUNT, T6031_CACHE_WAYS) | \
85+ FIELD_PREP(T6000_CACHE_STATUS_TAG_COUNT, T6031_CACHE_WAYS))
86+
6787#define T8103_CACHE_WAYS 16
6888#define T8103_CACHE_STATUS_MASK (T8103_CACHE_STATUS_DATA_COUNT | T8103_CACHE_STATUS_TAG_COUNT)
6989#define T8103_CACHE_STATUS_VAL \
@@ -134,6 +154,8 @@ int mcc_enable_cache(void)
134154 if (!mcc_initialized )
135155 return -1 ;
136156
157+ /* The 6030 memory controller supports setting a waymask, but the desktop chips do not appear to
158+ use it */
137159 for (int mcc = 0 ; mcc < mcc_count ; mcc ++ ) {
138160 for (int plane = 0 ; plane < mcc_regs [mcc ].plane_count ; plane ++ ) {
139161 plane_write32 (mcc , plane , PLANE_CACHE_ENABLE , mcc_regs [mcc ].cache_enable_val );
@@ -161,7 +183,12 @@ int mcc_unmap_carveouts(void)
161183
162184 mcc_carveout_count = 0 ;
163185 memset (mcc_carveouts , 0 , sizeof mcc_carveouts );
186+
164187 // All MCCs and planes should have identical configs
188+ // Note: For unhandled machines, the TZ regions can be found (on m1, m2, m3) by looking at
189+ // region-id-2 and region-id-4 on a booted macos, in the /chosen/carveout-memory-map DT node.
190+ // This can be used along with dumping the mcc reg space to find the correct start/end/enable
191+ // above.
165192 for (u32 i = 0 ; i < mcc_regs [0 ].tz -> count ; i ++ ) {
166193 uint64_t off = mcc_regs [0 ].tz -> stride * i ;
167194 uint64_t start = plane_read32 (0 , 0 , mcc_regs [0 ].tz -> start + off );
@@ -291,6 +318,72 @@ int mcc_init_t6000(int node, int *path, bool t602x)
291318 return 0 ;
292319}
293320
321+ int mcc_init_t6031 (int node , int * path )
322+ {
323+ u32 reg_len ;
324+ u32 reg_offset = 3 ;
325+
326+ if (!adt_getprop (adt , node , "reg" , & reg_len )) {
327+ printf ("MCC: Failed to get reg property!\n" );
328+ return -1 ;
329+ }
330+
331+ mcc_count = reg_len / 16 - reg_offset ;
332+
333+ printf ("MCC: Initializing T6031 MCCs (%d instances)...\n" , mcc_count );
334+
335+ if (mcc_count > MAX_MCC_INSTANCES ) {
336+ printf ("MCC: Too many instances, increase MAX_MCC_INSTANCES!\n" );
337+ mcc_count = MAX_MCC_INSTANCES ;
338+ }
339+
340+ u32 plane_count = 0 ;
341+ u32 dcs_count = 0 ;
342+
343+ if (!ADT_GETPROP (adt , node , "dcs-count-per-amcc" , & dcs_count )) {
344+ printf ("MCC: Failed to get dcs count!\n" );
345+ return -1 ;
346+ }
347+
348+ if (!ADT_GETPROP (adt , node , "plane-count-per-amcc" , & plane_count )) {
349+ printf ("MCC: Failed to get plane count!\n" );
350+ return -1 ;
351+ }
352+
353+ for (int i = 0 ; i < mcc_count ; i ++ ) {
354+ u64 base ;
355+ if (adt_get_reg (adt , path , "reg" , i + reg_offset , & base , NULL )) {
356+ printf ("MCC: Failed to get reg index %d!\n" , i + reg_offset );
357+ return -1 ;
358+ }
359+
360+ mcc_regs [i ].plane_base = base + T6031_PLANE_OFFSET ;
361+ mcc_regs [i ].plane_stride = T6031_PLANE_STRIDE ;
362+ mcc_regs [i ].plane_count = plane_count ;
363+
364+ mcc_regs [i ].global_base = base + T6031_GLOBAL_OFFSET ;
365+
366+ mcc_regs [i ].dcs_base = base + T6031_DCS_OFFSET ;
367+ mcc_regs [i ].dcs_stride = T6031_DCS_STRIDE ;
368+ mcc_regs [i ].dcs_count = dcs_count ;
369+
370+ mcc_regs [i ].cache_enable_val = 1 ;
371+ mcc_regs [i ].cache_ways = T6031_CACHE_WAYS ;
372+ mcc_regs [i ].cache_status_mask = T6031_CACHE_STATUS_MASK ;
373+ mcc_regs [i ].cache_status_val = T6031_CACHE_STATUS_VAL ;
374+ mcc_regs [i ].cache_disable = 0 ;
375+
376+ mcc_regs [i ].tz = & t603x_tz_regs ;
377+ }
378+
379+ printf ("MCC: Initialized T6031 MCCs (%d instances, %d planes, %d channels)\n" , mcc_count ,
380+ mcc_regs [0 ].plane_count , mcc_regs [0 ].dcs_count );
381+
382+ mcc_initialized = true;
383+
384+ return 0 ;
385+ }
386+
294387int mcc_init (void )
295388{
296389 int path [8 ];
@@ -309,8 +402,10 @@ int mcc_init(void)
309402 return mcc_init_t6000 (node , path , false);
310403 } else if (adt_is_compatible (adt , node , "mcc,t6020" )) {
311404 return mcc_init_t6000 (node , path , true);
405+ } else if (adt_is_compatible (adt , node , "mcc,t6031" )) {
406+ return mcc_init_t6031 (node , path );
312407 } else {
313- printf ("MCC: Unsupported version\n" );
408+ printf ("MCC: Unsupported version:%s \n" , adt_get_property ( adt , node , "compatible" ) -> value );
314409 return -1 ;
315410 }
316411}
0 commit comments