1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (c) 2015 Intel Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include <stdlib.h> 25bf215546Sopenharmony_ci#include <math.h> 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "util/macros.h" 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include "intel_l3_config.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_cistruct intel_l3_list { 32bf215546Sopenharmony_ci const struct intel_l3_config *configs; 33bf215546Sopenharmony_ci int length; 34bf215546Sopenharmony_ci}; 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci#define DECLARE_L3_LIST(hw) \ 37bf215546Sopenharmony_ci struct intel_l3_list hw##_l3_list = \ 38bf215546Sopenharmony_ci { .configs = hw##_l3_configs, .length = ARRAY_SIZE(hw##_l3_configs) } 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ci/** 41bf215546Sopenharmony_ci * IVB/HSW validated L3 configurations. The first entry will be used as 42bf215546Sopenharmony_ci * default by gfx7_restore_default_l3_config(), otherwise the ordering is 43bf215546Sopenharmony_ci * unimportant. 44bf215546Sopenharmony_ci */ 45bf215546Sopenharmony_cistatic const struct intel_l3_config ivb_l3_configs[] = { 46bf215546Sopenharmony_ci /* SLM URB ALL DC RO IS C T */ 47bf215546Sopenharmony_ci {{ 0, 32, 0, 0, 32, 0, 0, 0 }}, 48bf215546Sopenharmony_ci {{ 0, 32, 0, 16, 16, 0, 0, 0 }}, 49bf215546Sopenharmony_ci {{ 0, 32, 0, 4, 0, 8, 4, 16 }}, 50bf215546Sopenharmony_ci {{ 0, 28, 0, 8, 0, 8, 4, 16 }}, 51bf215546Sopenharmony_ci {{ 0, 28, 0, 16, 0, 8, 4, 8 }}, 52bf215546Sopenharmony_ci {{ 0, 28, 0, 8, 0, 16, 4, 8 }}, 53bf215546Sopenharmony_ci {{ 0, 28, 0, 0, 0, 16, 4, 16 }}, 54bf215546Sopenharmony_ci {{ 0, 32, 0, 0, 0, 16, 0, 16 }}, 55bf215546Sopenharmony_ci {{ 0, 28, 0, 4, 32, 0, 0, 0 }}, 56bf215546Sopenharmony_ci {{ 16, 16, 0, 16, 16, 0, 0, 0 }}, 57bf215546Sopenharmony_ci {{ 16, 16, 0, 8, 0, 8, 8, 8 }}, 58bf215546Sopenharmony_ci {{ 16, 16, 0, 4, 0, 8, 4, 16 }}, 59bf215546Sopenharmony_ci {{ 16, 16, 0, 4, 0, 16, 4, 8 }}, 60bf215546Sopenharmony_ci {{ 16, 16, 0, 0, 32, 0, 0, 0 }}, 61bf215546Sopenharmony_ci}; 62bf215546Sopenharmony_ciDECLARE_L3_LIST(ivb); 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci/** 65bf215546Sopenharmony_ci * VLV validated L3 configurations. \sa ivb_l3_configs. 66bf215546Sopenharmony_ci */ 67bf215546Sopenharmony_cistatic const struct intel_l3_config vlv_l3_configs[] = { 68bf215546Sopenharmony_ci /* SLM URB ALL DC RO IS C T */ 69bf215546Sopenharmony_ci {{ 0, 64, 0, 0, 32, 0, 0, 0 }}, 70bf215546Sopenharmony_ci {{ 0, 80, 0, 0, 16, 0, 0, 0 }}, 71bf215546Sopenharmony_ci {{ 0, 80, 0, 8, 8, 0, 0, 0 }}, 72bf215546Sopenharmony_ci {{ 0, 64, 0, 16, 16, 0, 0, 0 }}, 73bf215546Sopenharmony_ci {{ 0, 60, 0, 4, 32, 0, 0, 0 }}, 74bf215546Sopenharmony_ci {{ 32, 32, 0, 16, 16, 0, 0, 0 }}, 75bf215546Sopenharmony_ci {{ 32, 40, 0, 8, 16, 0, 0, 0 }}, 76bf215546Sopenharmony_ci {{ 32, 40, 0, 16, 8, 0, 0, 0 }}, 77bf215546Sopenharmony_ci}; 78bf215546Sopenharmony_ciDECLARE_L3_LIST(vlv); 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci/** 81bf215546Sopenharmony_ci * BDW validated L3 configurations. \sa ivb_l3_configs. 82bf215546Sopenharmony_ci */ 83bf215546Sopenharmony_cistatic const struct intel_l3_config bdw_l3_configs[] = { 84bf215546Sopenharmony_ci /* SLM URB ALL DC RO IS C T */ 85bf215546Sopenharmony_ci {{ 0, 48, 48, 0, 0, 0, 0, 0 }}, 86bf215546Sopenharmony_ci {{ 0, 48, 0, 16, 32, 0, 0, 0 }}, 87bf215546Sopenharmony_ci {{ 0, 32, 0, 16, 48, 0, 0, 0 }}, 88bf215546Sopenharmony_ci {{ 0, 32, 0, 0, 64, 0, 0, 0 }}, 89bf215546Sopenharmony_ci {{ 0, 32, 64, 0, 0, 0, 0, 0 }}, 90bf215546Sopenharmony_ci {{ 24, 16, 48, 0, 0, 0, 0, 0 }}, 91bf215546Sopenharmony_ci {{ 24, 16, 0, 16, 32, 0, 0, 0 }}, 92bf215546Sopenharmony_ci {{ 24, 16, 0, 32, 16, 0, 0, 0 }}, 93bf215546Sopenharmony_ci}; 94bf215546Sopenharmony_ciDECLARE_L3_LIST(bdw); 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci/** 97bf215546Sopenharmony_ci * CHV/SKL validated L3 configurations. \sa ivb_l3_configs. 98bf215546Sopenharmony_ci */ 99bf215546Sopenharmony_cistatic const struct intel_l3_config chv_l3_configs[] = { 100bf215546Sopenharmony_ci /* SLM URB ALL DC RO IS C T */ 101bf215546Sopenharmony_ci {{ 0, 48, 48, 0, 0, 0, 0, 0 }}, 102bf215546Sopenharmony_ci {{ 0, 48, 0, 16, 32, 0, 0, 0 }}, 103bf215546Sopenharmony_ci {{ 0, 32, 0, 16, 48, 0, 0, 0 }}, 104bf215546Sopenharmony_ci {{ 0, 32, 0, 0, 64, 0, 0, 0 }}, 105bf215546Sopenharmony_ci {{ 0, 32, 64, 0, 0, 0, 0, 0 }}, 106bf215546Sopenharmony_ci {{ 32, 16, 48, 0, 0, 0, 0, 0 }}, 107bf215546Sopenharmony_ci {{ 32, 16, 0, 16, 32, 0, 0, 0 }}, 108bf215546Sopenharmony_ci {{ 32, 16, 0, 32, 16, 0, 0, 0 }}, 109bf215546Sopenharmony_ci}; 110bf215546Sopenharmony_ciDECLARE_L3_LIST(chv); 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci/** 113bf215546Sopenharmony_ci * BXT 2x6 validated L3 configurations. \sa ivb_l3_configs. 114bf215546Sopenharmony_ci */ 115bf215546Sopenharmony_cistatic const struct intel_l3_config bxt_2x6_l3_configs[] = { 116bf215546Sopenharmony_ci /* SLM URB ALL DC RO IS C T */ 117bf215546Sopenharmony_ci {{ 0, 32, 48, 0, 0, 0, 0, 0 }}, 118bf215546Sopenharmony_ci {{ 0, 32, 0, 8, 40, 0, 0, 0 }}, 119bf215546Sopenharmony_ci {{ 0, 32, 0, 32, 16, 0, 0, 0 }}, 120bf215546Sopenharmony_ci {{ 16, 16, 48, 0, 0, 0, 0, 0 }}, 121bf215546Sopenharmony_ci {{ 16, 16, 0, 40, 8, 0, 0, 0 }}, 122bf215546Sopenharmony_ci {{ 16, 16, 0, 16, 32, 0, 0, 0 }}, 123bf215546Sopenharmony_ci}; 124bf215546Sopenharmony_ciDECLARE_L3_LIST(bxt_2x6); 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_ci/** 127bf215546Sopenharmony_ci * ICL validated L3 configurations. \sa icl_l3_configs. 128bf215546Sopenharmony_ci * Zeroth entry in below table has been commented out intentionally 129bf215546Sopenharmony_ci * due to known issues with this configuration. Many other entries 130bf215546Sopenharmony_ci * suggested by h/w specification aren't added here because they 131bf215546Sopenharmony_ci * do under allocation of L3 cache with below partitioning. 132bf215546Sopenharmony_ci */ 133bf215546Sopenharmony_cistatic const struct intel_l3_config icl_l3_configs[] = { 134bf215546Sopenharmony_ci /* SLM URB ALL DC RO IS C T */ 135bf215546Sopenharmony_ci /*{{ 0, 16, 80, 0, 0, 0, 0, 0 }},*/ 136bf215546Sopenharmony_ci {{ 0, 32, 64, 0, 0, 0, 0, 0 }}, 137bf215546Sopenharmony_ci}; 138bf215546Sopenharmony_ciDECLARE_L3_LIST(icl); 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ci/** 141bf215546Sopenharmony_ci * TGL validated L3 configurations. \sa tgl_l3_configs. 142bf215546Sopenharmony_ci */ 143bf215546Sopenharmony_cistatic const struct intel_l3_config tgl_l3_configs[] = { 144bf215546Sopenharmony_ci /* SLM URB ALL DC RO IS C T */ 145bf215546Sopenharmony_ci {{ 0, 32, 88, 0, 0, 0, 0, 0 }}, 146bf215546Sopenharmony_ci {{ 0, 16, 104, 0, 0, 0, 0, 0 }}, 147bf215546Sopenharmony_ci}; 148bf215546Sopenharmony_ciDECLARE_L3_LIST(tgl); 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ci/** 151bf215546Sopenharmony_ci * Empty L3 configurations. \sa empty_l3_configs. 152bf215546Sopenharmony_ci */ 153bf215546Sopenharmony_cistatic const struct intel_l3_config empty_l3_configs[] = { 154bf215546Sopenharmony_ci /* No configurations. L3FullWayAllocationEnable is always set. */ 155bf215546Sopenharmony_ci}; 156bf215546Sopenharmony_ciDECLARE_L3_LIST(empty); 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci/** 159bf215546Sopenharmony_ci * Return a zero-terminated array of validated L3 configurations for the 160bf215546Sopenharmony_ci * specified device. 161bf215546Sopenharmony_ci */ 162bf215546Sopenharmony_cistatic const struct intel_l3_list * 163bf215546Sopenharmony_ciget_l3_list(const struct intel_device_info *devinfo) 164bf215546Sopenharmony_ci{ 165bf215546Sopenharmony_ci switch (devinfo->ver) { 166bf215546Sopenharmony_ci case 7: 167bf215546Sopenharmony_ci return (devinfo->platform == INTEL_PLATFORM_BYT ? &vlv_l3_list : &ivb_l3_list); 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_ci case 8: 170bf215546Sopenharmony_ci return (devinfo->platform == INTEL_PLATFORM_CHV ? &chv_l3_list : &bdw_l3_list); 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_ci case 9: 173bf215546Sopenharmony_ci if (devinfo->l3_banks == 1) 174bf215546Sopenharmony_ci return &bxt_2x6_l3_list; 175bf215546Sopenharmony_ci return &chv_l3_list; 176bf215546Sopenharmony_ci 177bf215546Sopenharmony_ci case 11: 178bf215546Sopenharmony_ci return &icl_l3_list; 179bf215546Sopenharmony_ci 180bf215546Sopenharmony_ci case 12: 181bf215546Sopenharmony_ci if (devinfo->platform == INTEL_PLATFORM_DG1 || 182bf215546Sopenharmony_ci intel_device_info_is_dg2(devinfo)) 183bf215546Sopenharmony_ci return &empty_l3_list; 184bf215546Sopenharmony_ci else 185bf215546Sopenharmony_ci return &tgl_l3_list; 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ci default: 188bf215546Sopenharmony_ci unreachable("Not implemented"); 189bf215546Sopenharmony_ci } 190bf215546Sopenharmony_ci} 191bf215546Sopenharmony_ci 192bf215546Sopenharmony_ci/** 193bf215546Sopenharmony_ci * L1-normalize a vector of L3 partition weights. 194bf215546Sopenharmony_ci */ 195bf215546Sopenharmony_cistatic struct intel_l3_weights 196bf215546Sopenharmony_cinorm_l3_weights(struct intel_l3_weights w) 197bf215546Sopenharmony_ci{ 198bf215546Sopenharmony_ci float sz = 0; 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_ci for (unsigned i = 0; i < INTEL_NUM_L3P; i++) 201bf215546Sopenharmony_ci sz += w.w[i]; 202bf215546Sopenharmony_ci 203bf215546Sopenharmony_ci for (unsigned i = 0; i < INTEL_NUM_L3P; i++) 204bf215546Sopenharmony_ci w.w[i] /= sz; 205bf215546Sopenharmony_ci 206bf215546Sopenharmony_ci return w; 207bf215546Sopenharmony_ci} 208bf215546Sopenharmony_ci 209bf215546Sopenharmony_ci/** 210bf215546Sopenharmony_ci * Get the relative partition weights of the specified L3 configuration. 211bf215546Sopenharmony_ci */ 212bf215546Sopenharmony_cistruct intel_l3_weights 213bf215546Sopenharmony_ciintel_get_l3_config_weights(const struct intel_l3_config *cfg) 214bf215546Sopenharmony_ci{ 215bf215546Sopenharmony_ci if (cfg) { 216bf215546Sopenharmony_ci struct intel_l3_weights w; 217bf215546Sopenharmony_ci 218bf215546Sopenharmony_ci for (unsigned i = 0; i < INTEL_NUM_L3P; i++) 219bf215546Sopenharmony_ci w.w[i] = cfg->n[i]; 220bf215546Sopenharmony_ci 221bf215546Sopenharmony_ci return norm_l3_weights(w); 222bf215546Sopenharmony_ci } else { 223bf215546Sopenharmony_ci const struct intel_l3_weights w = { { 0 } }; 224bf215546Sopenharmony_ci return w; 225bf215546Sopenharmony_ci } 226bf215546Sopenharmony_ci} 227bf215546Sopenharmony_ci 228bf215546Sopenharmony_ci/** 229bf215546Sopenharmony_ci * Distance between two L3 configurations represented as vectors of weights. 230bf215546Sopenharmony_ci * Usually just the L1 metric except when the two configurations are 231bf215546Sopenharmony_ci * considered incompatible in which case the distance will be infinite. Note 232bf215546Sopenharmony_ci * that the compatibility condition is asymmetric -- They will be considered 233bf215546Sopenharmony_ci * incompatible whenever the reference configuration \p w0 requires SLM, DC, 234bf215546Sopenharmony_ci * or URB but \p w1 doesn't provide it. 235bf215546Sopenharmony_ci */ 236bf215546Sopenharmony_cifloat 237bf215546Sopenharmony_ciintel_diff_l3_weights(struct intel_l3_weights w0, struct intel_l3_weights w1) 238bf215546Sopenharmony_ci{ 239bf215546Sopenharmony_ci if ((w0.w[INTEL_L3P_SLM] && !w1.w[INTEL_L3P_SLM]) || 240bf215546Sopenharmony_ci (w0.w[INTEL_L3P_DC] && !w1.w[INTEL_L3P_DC] && !w1.w[INTEL_L3P_ALL]) || 241bf215546Sopenharmony_ci (w0.w[INTEL_L3P_URB] && !w1.w[INTEL_L3P_URB])) { 242bf215546Sopenharmony_ci return HUGE_VALF; 243bf215546Sopenharmony_ci 244bf215546Sopenharmony_ci } else { 245bf215546Sopenharmony_ci float dw = 0; 246bf215546Sopenharmony_ci 247bf215546Sopenharmony_ci for (unsigned i = 0; i < INTEL_NUM_L3P; i++) 248bf215546Sopenharmony_ci dw += fabsf(w0.w[i] - w1.w[i]); 249bf215546Sopenharmony_ci 250bf215546Sopenharmony_ci return dw; 251bf215546Sopenharmony_ci } 252bf215546Sopenharmony_ci} 253bf215546Sopenharmony_ci 254bf215546Sopenharmony_ci/** 255bf215546Sopenharmony_ci * Return a reasonable default L3 configuration for the specified device based 256bf215546Sopenharmony_ci * on whether SLM and DC are required. In the non-SLM non-DC case the result 257bf215546Sopenharmony_ci * is intended to approximately resemble the hardware defaults. 258bf215546Sopenharmony_ci */ 259bf215546Sopenharmony_cistruct intel_l3_weights 260bf215546Sopenharmony_ciintel_get_default_l3_weights(const struct intel_device_info *devinfo, 261bf215546Sopenharmony_ci bool needs_dc, bool needs_slm) 262bf215546Sopenharmony_ci{ 263bf215546Sopenharmony_ci struct intel_l3_weights w = {{ 0 }}; 264bf215546Sopenharmony_ci 265bf215546Sopenharmony_ci w.w[INTEL_L3P_SLM] = devinfo->ver < 11 && needs_slm; 266bf215546Sopenharmony_ci w.w[INTEL_L3P_URB] = 1.0; 267bf215546Sopenharmony_ci 268bf215546Sopenharmony_ci if (devinfo->ver >= 8) { 269bf215546Sopenharmony_ci w.w[INTEL_L3P_ALL] = 1.0; 270bf215546Sopenharmony_ci } else { 271bf215546Sopenharmony_ci w.w[INTEL_L3P_DC] = needs_dc ? 0.1 : 0; 272bf215546Sopenharmony_ci w.w[INTEL_L3P_RO] = devinfo->platform == INTEL_PLATFORM_BYT ? 0.5 : 1.0; 273bf215546Sopenharmony_ci } 274bf215546Sopenharmony_ci 275bf215546Sopenharmony_ci return norm_l3_weights(w); 276bf215546Sopenharmony_ci} 277bf215546Sopenharmony_ci 278bf215546Sopenharmony_ci/** 279bf215546Sopenharmony_ci * Get the default L3 configuration 280bf215546Sopenharmony_ci */ 281bf215546Sopenharmony_ciconst struct intel_l3_config * 282bf215546Sopenharmony_ciintel_get_default_l3_config(const struct intel_device_info *devinfo) 283bf215546Sopenharmony_ci{ 284bf215546Sopenharmony_ci /* For efficiency assume that the first entry of the array matches the 285bf215546Sopenharmony_ci * default configuration. 286bf215546Sopenharmony_ci */ 287bf215546Sopenharmony_ci const struct intel_l3_list *const list = get_l3_list(devinfo); 288bf215546Sopenharmony_ci assert(list->length > 0 || devinfo->ver >= 12); 289bf215546Sopenharmony_ci if (list->length > 0) { 290bf215546Sopenharmony_ci const struct intel_l3_config *const cfg = &list->configs[0]; 291bf215546Sopenharmony_ci assert(cfg == intel_get_l3_config(devinfo, 292bf215546Sopenharmony_ci intel_get_default_l3_weights(devinfo, false, false))); 293bf215546Sopenharmony_ci return cfg; 294bf215546Sopenharmony_ci } else { 295bf215546Sopenharmony_ci return NULL; 296bf215546Sopenharmony_ci } 297bf215546Sopenharmony_ci} 298bf215546Sopenharmony_ci 299bf215546Sopenharmony_ci/** 300bf215546Sopenharmony_ci * Return the closest validated L3 configuration for the specified device and 301bf215546Sopenharmony_ci * weight vector. 302bf215546Sopenharmony_ci */ 303bf215546Sopenharmony_ciconst struct intel_l3_config * 304bf215546Sopenharmony_ciintel_get_l3_config(const struct intel_device_info *devinfo, 305bf215546Sopenharmony_ci struct intel_l3_weights w0) 306bf215546Sopenharmony_ci{ 307bf215546Sopenharmony_ci const struct intel_l3_list *const list = get_l3_list(devinfo); 308bf215546Sopenharmony_ci const struct intel_l3_config *const cfgs = list->configs; 309bf215546Sopenharmony_ci const struct intel_l3_config *cfg_best = NULL; 310bf215546Sopenharmony_ci float dw_best = HUGE_VALF; 311bf215546Sopenharmony_ci 312bf215546Sopenharmony_ci for (int i = 0; i < list->length; i++) { 313bf215546Sopenharmony_ci const struct intel_l3_config *cfg = &cfgs[i]; 314bf215546Sopenharmony_ci const float dw = intel_diff_l3_weights(w0, intel_get_l3_config_weights(cfg)); 315bf215546Sopenharmony_ci 316bf215546Sopenharmony_ci if (dw < dw_best) { 317bf215546Sopenharmony_ci cfg_best = cfg; 318bf215546Sopenharmony_ci dw_best = dw; 319bf215546Sopenharmony_ci } 320bf215546Sopenharmony_ci } 321bf215546Sopenharmony_ci 322bf215546Sopenharmony_ci assert(cfg_best || devinfo->ver >= 12); 323bf215546Sopenharmony_ci return cfg_best; 324bf215546Sopenharmony_ci} 325bf215546Sopenharmony_ci 326bf215546Sopenharmony_ci/** 327bf215546Sopenharmony_ci * Return the size of an L3 way in KB. 328bf215546Sopenharmony_ci */ 329bf215546Sopenharmony_cistatic unsigned 330bf215546Sopenharmony_ciget_l3_way_size(const struct intel_device_info *devinfo) 331bf215546Sopenharmony_ci{ 332bf215546Sopenharmony_ci const unsigned way_size_per_bank = 333bf215546Sopenharmony_ci (devinfo->ver >= 9 && devinfo->l3_banks == 1) || devinfo->ver >= 11 ? 334bf215546Sopenharmony_ci 4 : 2; 335bf215546Sopenharmony_ci 336bf215546Sopenharmony_ci assert(devinfo->l3_banks); 337bf215546Sopenharmony_ci return way_size_per_bank * devinfo->l3_banks; 338bf215546Sopenharmony_ci} 339bf215546Sopenharmony_ci 340bf215546Sopenharmony_ci/** 341bf215546Sopenharmony_ci * Return the unit brw_context::urb::size is expressed in, in KB. \sa 342bf215546Sopenharmony_ci * intel_device_info::urb::size. 343bf215546Sopenharmony_ci */ 344bf215546Sopenharmony_cistatic unsigned 345bf215546Sopenharmony_ciget_urb_size_scale(const struct intel_device_info *devinfo) 346bf215546Sopenharmony_ci{ 347bf215546Sopenharmony_ci return (devinfo->ver >= 8 ? devinfo->num_slices : 1); 348bf215546Sopenharmony_ci} 349bf215546Sopenharmony_ci 350bf215546Sopenharmony_ciunsigned 351bf215546Sopenharmony_ciintel_get_l3_config_urb_size(const struct intel_device_info *devinfo, 352bf215546Sopenharmony_ci const struct intel_l3_config *cfg) 353bf215546Sopenharmony_ci{ 354bf215546Sopenharmony_ci /* We don't have to program the URB size for some platforms. It's a fixed 355bf215546Sopenharmony_ci * value. 356bf215546Sopenharmony_ci */ 357bf215546Sopenharmony_ci if (cfg == NULL) { 358bf215546Sopenharmony_ci ASSERTED const struct intel_l3_list *const list = get_l3_list(devinfo); 359bf215546Sopenharmony_ci assert(list->length == 0); 360bf215546Sopenharmony_ci return devinfo->urb.size; 361bf215546Sopenharmony_ci } 362bf215546Sopenharmony_ci 363bf215546Sopenharmony_ci /* From the SKL "L3 Allocation and Programming" documentation: 364bf215546Sopenharmony_ci * 365bf215546Sopenharmony_ci * "URB is limited to 1008KB due to programming restrictions. This is not 366bf215546Sopenharmony_ci * a restriction of the L3 implementation, but of the FF and other clients. 367bf215546Sopenharmony_ci * Therefore, in a GT4 implementation it is possible for the programmed 368bf215546Sopenharmony_ci * allocation of the L3 data array to provide 3*384KB=1152KB for URB, but 369bf215546Sopenharmony_ci * only 1008KB of this will be used." 370bf215546Sopenharmony_ci */ 371bf215546Sopenharmony_ci const unsigned max = (devinfo->ver == 9 ? 1008 : ~0); 372bf215546Sopenharmony_ci return MIN2(max, cfg->n[INTEL_L3P_URB] * get_l3_way_size(devinfo)) / 373bf215546Sopenharmony_ci get_urb_size_scale(devinfo); 374bf215546Sopenharmony_ci} 375bf215546Sopenharmony_ci 376bf215546Sopenharmony_ci/** 377bf215546Sopenharmony_ci * Print out the specified L3 configuration. 378bf215546Sopenharmony_ci */ 379bf215546Sopenharmony_civoid 380bf215546Sopenharmony_ciintel_dump_l3_config(const struct intel_l3_config *cfg, FILE *fp) 381bf215546Sopenharmony_ci{ 382bf215546Sopenharmony_ci fprintf(stderr, "SLM=%d URB=%d ALL=%d DC=%d RO=%d IS=%d C=%d T=%d\n", 383bf215546Sopenharmony_ci cfg->n[INTEL_L3P_SLM], cfg->n[INTEL_L3P_URB], cfg->n[INTEL_L3P_ALL], 384bf215546Sopenharmony_ci cfg->n[INTEL_L3P_DC], cfg->n[INTEL_L3P_RO], 385bf215546Sopenharmony_ci cfg->n[INTEL_L3P_IS], cfg->n[INTEL_L3P_C], cfg->n[INTEL_L3P_T]); 386bf215546Sopenharmony_ci} 387