r600_dpm.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  1. /*
  2. * Copyright 2011 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Alex Deucher
  23. */
  24. #include "drmP.h"
  25. #include "radeon.h"
  26. #include "radeon_asic.h"
  27. #include "r600d.h"
  28. #include "r600_dpm.h"
  29. #include "atom.h"
  30. const u32 r600_utc[R600_PM_NUMBER_OF_TC] =
  31. {
  32. R600_UTC_DFLT_00,
  33. R600_UTC_DFLT_01,
  34. R600_UTC_DFLT_02,
  35. R600_UTC_DFLT_03,
  36. R600_UTC_DFLT_04,
  37. R600_UTC_DFLT_05,
  38. R600_UTC_DFLT_06,
  39. R600_UTC_DFLT_07,
  40. R600_UTC_DFLT_08,
  41. R600_UTC_DFLT_09,
  42. R600_UTC_DFLT_10,
  43. R600_UTC_DFLT_11,
  44. R600_UTC_DFLT_12,
  45. R600_UTC_DFLT_13,
  46. R600_UTC_DFLT_14,
  47. };
  48. const u32 r600_dtc[R600_PM_NUMBER_OF_TC] =
  49. {
  50. R600_DTC_DFLT_00,
  51. R600_DTC_DFLT_01,
  52. R600_DTC_DFLT_02,
  53. R600_DTC_DFLT_03,
  54. R600_DTC_DFLT_04,
  55. R600_DTC_DFLT_05,
  56. R600_DTC_DFLT_06,
  57. R600_DTC_DFLT_07,
  58. R600_DTC_DFLT_08,
  59. R600_DTC_DFLT_09,
  60. R600_DTC_DFLT_10,
  61. R600_DTC_DFLT_11,
  62. R600_DTC_DFLT_12,
  63. R600_DTC_DFLT_13,
  64. R600_DTC_DFLT_14,
  65. };
  66. void r600_dpm_print_class_info(u32 class, u32 class2)
  67. {
  68. printk("\tui class: ");
  69. switch (class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
  70. case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
  71. default:
  72. printk("none\n");
  73. break;
  74. case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
  75. printk("battery\n");
  76. break;
  77. case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
  78. printk("balanced\n");
  79. break;
  80. case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
  81. printk("performance\n");
  82. break;
  83. }
  84. printk("\tinternal class: ");
  85. if (((class & ~ATOM_PPLIB_CLASSIFICATION_UI_MASK) == 0) &&
  86. (class2 == 0))
  87. printk("none");
  88. else {
  89. if (class & ATOM_PPLIB_CLASSIFICATION_BOOT)
  90. printk("boot ");
  91. if (class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
  92. printk("thermal ");
  93. if (class & ATOM_PPLIB_CLASSIFICATION_LIMITEDPOWERSOURCE)
  94. printk("limited_pwr ");
  95. if (class & ATOM_PPLIB_CLASSIFICATION_REST)
  96. printk("rest ");
  97. if (class & ATOM_PPLIB_CLASSIFICATION_FORCED)
  98. printk("forced ");
  99. if (class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  100. printk("3d_perf ");
  101. if (class & ATOM_PPLIB_CLASSIFICATION_OVERDRIVETEMPLATE)
  102. printk("ovrdrv ");
  103. if (class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
  104. printk("uvd ");
  105. if (class & ATOM_PPLIB_CLASSIFICATION_3DLOW)
  106. printk("3d_low ");
  107. if (class & ATOM_PPLIB_CLASSIFICATION_ACPI)
  108. printk("acpi ");
  109. if (class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
  110. printk("uvd_hd2 ");
  111. if (class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
  112. printk("uvd_hd ");
  113. if (class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
  114. printk("uvd_sd ");
  115. if (class2 & ATOM_PPLIB_CLASSIFICATION2_LIMITEDPOWERSOURCE_2)
  116. printk("limited_pwr2 ");
  117. if (class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
  118. printk("ulv ");
  119. if (class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
  120. printk("uvd_mvc ");
  121. }
  122. printk("\n");
  123. }
  124. void r600_dpm_print_cap_info(u32 caps)
  125. {
  126. printk("\tcaps: ");
  127. if (caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
  128. printk("single_disp ");
  129. if (caps & ATOM_PPLIB_SUPPORTS_VIDEO_PLAYBACK)
  130. printk("video ");
  131. if (caps & ATOM_PPLIB_DISALLOW_ON_DC)
  132. printk("no_dc ");
  133. printk("\n");
  134. }
  135. void r600_dpm_print_ps_status(struct radeon_device *rdev,
  136. struct radeon_ps *rps)
  137. {
  138. printk("\tstatus: ");
  139. if (rps == rdev->pm.dpm.current_ps)
  140. printk("c ");
  141. if (rps == rdev->pm.dpm.requested_ps)
  142. printk("r ");
  143. if (rps == rdev->pm.dpm.boot_ps)
  144. printk("b ");
  145. printk("\n");
  146. }
  147. u32 r600_dpm_get_vblank_time(struct radeon_device *rdev)
  148. {
  149. struct drm_device *dev = rdev->ddev;
  150. struct drm_crtc *crtc;
  151. struct radeon_crtc *radeon_crtc;
  152. u32 vblank_in_pixels;
  153. u32 vblank_time_us = 0xffffffff; /* if the displays are off, vblank time is max */
  154. if (rdev->num_crtc && rdev->mode_info.mode_config_initialized) {
  155. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  156. radeon_crtc = to_radeon_crtc(crtc);
  157. if (crtc->enabled && radeon_crtc->enabled && radeon_crtc->hw_mode.clock) {
  158. vblank_in_pixels =
  159. radeon_crtc->hw_mode.crtc_htotal *
  160. (radeon_crtc->hw_mode.crtc_vblank_end -
  161. radeon_crtc->hw_mode.crtc_vdisplay +
  162. (radeon_crtc->v_border * 2));
  163. vblank_time_us = vblank_in_pixels * 1000 / radeon_crtc->hw_mode.clock;
  164. break;
  165. }
  166. }
  167. }
  168. return vblank_time_us;
  169. }
  170. u32 r600_dpm_get_vrefresh(struct radeon_device *rdev)
  171. {
  172. struct drm_device *dev = rdev->ddev;
  173. struct drm_crtc *crtc;
  174. struct radeon_crtc *radeon_crtc;
  175. u32 vrefresh = 0;
  176. if (rdev->num_crtc && rdev->mode_info.mode_config_initialized) {
  177. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  178. radeon_crtc = to_radeon_crtc(crtc);
  179. if (crtc->enabled && radeon_crtc->enabled && radeon_crtc->hw_mode.clock) {
  180. vrefresh = drm_mode_vrefresh(&radeon_crtc->hw_mode);
  181. break;
  182. }
  183. }
  184. }
  185. return vrefresh;
  186. }
  187. void r600_calculate_u_and_p(u32 i, u32 r_c, u32 p_b,
  188. u32 *p, u32 *u)
  189. {
  190. u32 b_c = 0;
  191. u32 i_c;
  192. u32 tmp;
  193. i_c = (i * r_c) / 100;
  194. tmp = i_c >> p_b;
  195. while (tmp) {
  196. b_c++;
  197. tmp >>= 1;
  198. }
  199. *u = (b_c + 1) / 2;
  200. *p = i_c / (1 << (2 * (*u)));
  201. }
  202. int r600_calculate_at(u32 t, u32 h, u32 fh, u32 fl, u32 *tl, u32 *th)
  203. {
  204. u32 k, a, ah, al;
  205. u32 t1;
  206. if ((fl == 0) || (fh == 0) || (fl > fh))
  207. return -EINVAL;
  208. k = (100 * fh) / fl;
  209. t1 = (t * (k - 100));
  210. a = (1000 * (100 * h + t1)) / (10000 + (t1 / 100));
  211. a = (a + 5) / 10;
  212. ah = ((a * t) + 5000) / 10000;
  213. al = a - ah;
  214. *th = t - ah;
  215. *tl = t + al;
  216. return 0;
  217. }
  218. void r600_gfx_clockgating_enable(struct radeon_device *rdev, bool enable)
  219. {
  220. int i;
  221. if (enable) {
  222. WREG32_P(SCLK_PWRMGT_CNTL, DYN_GFX_CLK_OFF_EN, ~DYN_GFX_CLK_OFF_EN);
  223. } else {
  224. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~DYN_GFX_CLK_OFF_EN);
  225. WREG32(CG_RLC_REQ_AND_RSP, 0x2);
  226. for (i = 0; i < rdev->usec_timeout; i++) {
  227. if (((RREG32(CG_RLC_REQ_AND_RSP) & CG_RLC_RSP_TYPE_MASK) >> CG_RLC_RSP_TYPE_SHIFT) == 1)
  228. break;
  229. udelay(1);
  230. }
  231. WREG32(CG_RLC_REQ_AND_RSP, 0x0);
  232. WREG32(GRBM_PWR_CNTL, 0x1);
  233. RREG32(GRBM_PWR_CNTL);
  234. }
  235. }
  236. void r600_dynamicpm_enable(struct radeon_device *rdev, bool enable)
  237. {
  238. if (enable)
  239. WREG32_P(GENERAL_PWRMGT, GLOBAL_PWRMGT_EN, ~GLOBAL_PWRMGT_EN);
  240. else
  241. WREG32_P(GENERAL_PWRMGT, 0, ~GLOBAL_PWRMGT_EN);
  242. }
  243. void r600_enable_thermal_protection(struct radeon_device *rdev, bool enable)
  244. {
  245. if (enable)
  246. WREG32_P(GENERAL_PWRMGT, 0, ~THERMAL_PROTECTION_DIS);
  247. else
  248. WREG32_P(GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, ~THERMAL_PROTECTION_DIS);
  249. }
  250. void r600_enable_acpi_pm(struct radeon_device *rdev)
  251. {
  252. WREG32_P(GENERAL_PWRMGT, STATIC_PM_EN, ~STATIC_PM_EN);
  253. }
  254. void r600_enable_dynamic_pcie_gen2(struct radeon_device *rdev, bool enable)
  255. {
  256. if (enable)
  257. WREG32_P(GENERAL_PWRMGT, ENABLE_GEN2PCIE, ~ENABLE_GEN2PCIE);
  258. else
  259. WREG32_P(GENERAL_PWRMGT, 0, ~ENABLE_GEN2PCIE);
  260. }
  261. bool r600_dynamicpm_enabled(struct radeon_device *rdev)
  262. {
  263. if (RREG32(GENERAL_PWRMGT) & GLOBAL_PWRMGT_EN)
  264. return true;
  265. else
  266. return false;
  267. }
  268. void r600_enable_sclk_control(struct radeon_device *rdev, bool enable)
  269. {
  270. if (enable)
  271. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~SCLK_PWRMGT_OFF);
  272. else
  273. WREG32_P(SCLK_PWRMGT_CNTL, SCLK_PWRMGT_OFF, ~SCLK_PWRMGT_OFF);
  274. }
  275. void r600_enable_mclk_control(struct radeon_device *rdev, bool enable)
  276. {
  277. if (enable)
  278. WREG32_P(MCLK_PWRMGT_CNTL, 0, ~MPLL_PWRMGT_OFF);
  279. else
  280. WREG32_P(MCLK_PWRMGT_CNTL, MPLL_PWRMGT_OFF, ~MPLL_PWRMGT_OFF);
  281. }
  282. void r600_enable_spll_bypass(struct radeon_device *rdev, bool enable)
  283. {
  284. if (enable)
  285. WREG32_P(CG_SPLL_FUNC_CNTL, SPLL_BYPASS_EN, ~SPLL_BYPASS_EN);
  286. else
  287. WREG32_P(CG_SPLL_FUNC_CNTL, 0, ~SPLL_BYPASS_EN);
  288. }
  289. void r600_wait_for_spll_change(struct radeon_device *rdev)
  290. {
  291. int i;
  292. for (i = 0; i < rdev->usec_timeout; i++) {
  293. if (RREG32(CG_SPLL_FUNC_CNTL) & SPLL_CHG_STATUS)
  294. break;
  295. udelay(1);
  296. }
  297. }
  298. void r600_set_bsp(struct radeon_device *rdev, u32 u, u32 p)
  299. {
  300. WREG32(CG_BSP, BSP(p) | BSU(u));
  301. }
  302. void r600_set_at(struct radeon_device *rdev,
  303. u32 l_to_m, u32 m_to_h,
  304. u32 h_to_m, u32 m_to_l)
  305. {
  306. WREG32(CG_RT, FLS(l_to_m) | FMS(m_to_h));
  307. WREG32(CG_LT, FHS(h_to_m) | FMS(m_to_l));
  308. }
  309. void r600_set_tc(struct radeon_device *rdev,
  310. u32 index, u32 u_t, u32 d_t)
  311. {
  312. WREG32(CG_FFCT_0 + (index * 4), UTC_0(u_t) | DTC_0(d_t));
  313. }
  314. void r600_select_td(struct radeon_device *rdev,
  315. enum r600_td td)
  316. {
  317. if (td == R600_TD_AUTO)
  318. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~FIR_FORCE_TREND_SEL);
  319. else
  320. WREG32_P(SCLK_PWRMGT_CNTL, FIR_FORCE_TREND_SEL, ~FIR_FORCE_TREND_SEL);
  321. if (td == R600_TD_UP)
  322. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~FIR_TREND_MODE);
  323. if (td == R600_TD_DOWN)
  324. WREG32_P(SCLK_PWRMGT_CNTL, FIR_TREND_MODE, ~FIR_TREND_MODE);
  325. }
  326. void r600_set_vrc(struct radeon_device *rdev, u32 vrv)
  327. {
  328. WREG32(CG_FTV, vrv);
  329. }
  330. void r600_set_tpu(struct radeon_device *rdev, u32 u)
  331. {
  332. WREG32_P(CG_TPC, TPU(u), ~TPU_MASK);
  333. }
  334. void r600_set_tpc(struct radeon_device *rdev, u32 c)
  335. {
  336. WREG32_P(CG_TPC, TPCC(c), ~TPCC_MASK);
  337. }
  338. void r600_set_sstu(struct radeon_device *rdev, u32 u)
  339. {
  340. WREG32_P(CG_SSP, CG_SSTU(u), ~CG_SSTU_MASK);
  341. }
  342. void r600_set_sst(struct radeon_device *rdev, u32 t)
  343. {
  344. WREG32_P(CG_SSP, CG_SST(t), ~CG_SST_MASK);
  345. }
  346. void r600_set_git(struct radeon_device *rdev, u32 t)
  347. {
  348. WREG32_P(CG_GIT, CG_GICST(t), ~CG_GICST_MASK);
  349. }
  350. void r600_set_fctu(struct radeon_device *rdev, u32 u)
  351. {
  352. WREG32_P(CG_FC_T, FC_TU(u), ~FC_TU_MASK);
  353. }
  354. void r600_set_fct(struct radeon_device *rdev, u32 t)
  355. {
  356. WREG32_P(CG_FC_T, FC_T(t), ~FC_T_MASK);
  357. }
  358. void r600_set_ctxcgtt3d_rphc(struct radeon_device *rdev, u32 p)
  359. {
  360. WREG32_P(CG_CTX_CGTT3D_R, PHC(p), ~PHC_MASK);
  361. }
  362. void r600_set_ctxcgtt3d_rsdc(struct radeon_device *rdev, u32 s)
  363. {
  364. WREG32_P(CG_CTX_CGTT3D_R, SDC(s), ~SDC_MASK);
  365. }
  366. void r600_set_vddc3d_oorsu(struct radeon_device *rdev, u32 u)
  367. {
  368. WREG32_P(CG_VDDC3D_OOR, SU(u), ~SU_MASK);
  369. }
  370. void r600_set_vddc3d_oorphc(struct radeon_device *rdev, u32 p)
  371. {
  372. WREG32_P(CG_VDDC3D_OOR, PHC(p), ~PHC_MASK);
  373. }
  374. void r600_set_vddc3d_oorsdc(struct radeon_device *rdev, u32 s)
  375. {
  376. WREG32_P(CG_VDDC3D_OOR, SDC(s), ~SDC_MASK);
  377. }
  378. void r600_set_mpll_lock_time(struct radeon_device *rdev, u32 lock_time)
  379. {
  380. WREG32_P(MPLL_TIME, MPLL_LOCK_TIME(lock_time), ~MPLL_LOCK_TIME_MASK);
  381. }
  382. void r600_set_mpll_reset_time(struct radeon_device *rdev, u32 reset_time)
  383. {
  384. WREG32_P(MPLL_TIME, MPLL_RESET_TIME(reset_time), ~MPLL_RESET_TIME_MASK);
  385. }
  386. void r600_engine_clock_entry_enable(struct radeon_device *rdev,
  387. u32 index, bool enable)
  388. {
  389. if (enable)
  390. WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART2 + (index * 4 * 2),
  391. STEP_0_SPLL_ENTRY_VALID, ~STEP_0_SPLL_ENTRY_VALID);
  392. else
  393. WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART2 + (index * 4 * 2),
  394. 0, ~STEP_0_SPLL_ENTRY_VALID);
  395. }
  396. void r600_engine_clock_entry_enable_pulse_skipping(struct radeon_device *rdev,
  397. u32 index, bool enable)
  398. {
  399. if (enable)
  400. WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART2 + (index * 4 * 2),
  401. STEP_0_SPLL_STEP_ENABLE, ~STEP_0_SPLL_STEP_ENABLE);
  402. else
  403. WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART2 + (index * 4 * 2),
  404. 0, ~STEP_0_SPLL_STEP_ENABLE);
  405. }
  406. void r600_engine_clock_entry_enable_post_divider(struct radeon_device *rdev,
  407. u32 index, bool enable)
  408. {
  409. if (enable)
  410. WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART2 + (index * 4 * 2),
  411. STEP_0_POST_DIV_EN, ~STEP_0_POST_DIV_EN);
  412. else
  413. WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART2 + (index * 4 * 2),
  414. 0, ~STEP_0_POST_DIV_EN);
  415. }
  416. void r600_engine_clock_entry_set_post_divider(struct radeon_device *rdev,
  417. u32 index, u32 divider)
  418. {
  419. WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART1 + (index * 4 * 2),
  420. STEP_0_SPLL_POST_DIV(divider), ~STEP_0_SPLL_POST_DIV_MASK);
  421. }
  422. void r600_engine_clock_entry_set_reference_divider(struct radeon_device *rdev,
  423. u32 index, u32 divider)
  424. {
  425. WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART1 + (index * 4 * 2),
  426. STEP_0_SPLL_REF_DIV(divider), ~STEP_0_SPLL_REF_DIV_MASK);
  427. }
  428. void r600_engine_clock_entry_set_feedback_divider(struct radeon_device *rdev,
  429. u32 index, u32 divider)
  430. {
  431. WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART1 + (index * 4 * 2),
  432. STEP_0_SPLL_FB_DIV(divider), ~STEP_0_SPLL_FB_DIV_MASK);
  433. }
  434. void r600_engine_clock_entry_set_step_time(struct radeon_device *rdev,
  435. u32 index, u32 step_time)
  436. {
  437. WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART1 + (index * 4 * 2),
  438. STEP_0_SPLL_STEP_TIME(step_time), ~STEP_0_SPLL_STEP_TIME_MASK);
  439. }
  440. void r600_vid_rt_set_ssu(struct radeon_device *rdev, u32 u)
  441. {
  442. WREG32_P(VID_RT, SSTU(u), ~SSTU_MASK);
  443. }
  444. void r600_vid_rt_set_vru(struct radeon_device *rdev, u32 u)
  445. {
  446. WREG32_P(VID_RT, VID_CRTU(u), ~VID_CRTU_MASK);
  447. }
  448. void r600_vid_rt_set_vrt(struct radeon_device *rdev, u32 rt)
  449. {
  450. WREG32_P(VID_RT, VID_CRT(rt), ~VID_CRT_MASK);
  451. }
  452. void r600_voltage_control_enable_pins(struct radeon_device *rdev,
  453. u64 mask)
  454. {
  455. WREG32(LOWER_GPIO_ENABLE, mask & 0xffffffff);
  456. WREG32(UPPER_GPIO_ENABLE, upper_32_bits(mask));
  457. }
  458. void r600_voltage_control_program_voltages(struct radeon_device *rdev,
  459. enum r600_power_level index, u64 pins)
  460. {
  461. u32 tmp, mask;
  462. u32 ix = 3 - (3 & index);
  463. WREG32(CTXSW_VID_LOWER_GPIO_CNTL + (ix * 4), pins & 0xffffffff);
  464. mask = 7 << (3 * ix);
  465. tmp = RREG32(VID_UPPER_GPIO_CNTL);
  466. tmp = (tmp & ~mask) | ((pins >> (32 - (3 * ix))) & mask);
  467. WREG32(VID_UPPER_GPIO_CNTL, tmp);
  468. }
  469. void r600_voltage_control_deactivate_static_control(struct radeon_device *rdev,
  470. u64 mask)
  471. {
  472. u32 gpio;
  473. gpio = RREG32(GPIOPAD_MASK);
  474. gpio &= ~mask;
  475. WREG32(GPIOPAD_MASK, gpio);
  476. gpio = RREG32(GPIOPAD_EN);
  477. gpio &= ~mask;
  478. WREG32(GPIOPAD_EN, gpio);
  479. gpio = RREG32(GPIOPAD_A);
  480. gpio &= ~mask;
  481. WREG32(GPIOPAD_A, gpio);
  482. }
  483. void r600_power_level_enable(struct radeon_device *rdev,
  484. enum r600_power_level index, bool enable)
  485. {
  486. u32 ix = 3 - (3 & index);
  487. if (enable)
  488. WREG32_P(CTXSW_PROFILE_INDEX + (ix * 4), CTXSW_FREQ_STATE_ENABLE,
  489. ~CTXSW_FREQ_STATE_ENABLE);
  490. else
  491. WREG32_P(CTXSW_PROFILE_INDEX + (ix * 4), 0,
  492. ~CTXSW_FREQ_STATE_ENABLE);
  493. }
  494. void r600_power_level_set_voltage_index(struct radeon_device *rdev,
  495. enum r600_power_level index, u32 voltage_index)
  496. {
  497. u32 ix = 3 - (3 & index);
  498. WREG32_P(CTXSW_PROFILE_INDEX + (ix * 4),
  499. CTXSW_FREQ_VIDS_CFG_INDEX(voltage_index), ~CTXSW_FREQ_VIDS_CFG_INDEX_MASK);
  500. }
  501. void r600_power_level_set_mem_clock_index(struct radeon_device *rdev,
  502. enum r600_power_level index, u32 mem_clock_index)
  503. {
  504. u32 ix = 3 - (3 & index);
  505. WREG32_P(CTXSW_PROFILE_INDEX + (ix * 4),
  506. CTXSW_FREQ_MCLK_CFG_INDEX(mem_clock_index), ~CTXSW_FREQ_MCLK_CFG_INDEX_MASK);
  507. }
  508. void r600_power_level_set_eng_clock_index(struct radeon_device *rdev,
  509. enum r600_power_level index, u32 eng_clock_index)
  510. {
  511. u32 ix = 3 - (3 & index);
  512. WREG32_P(CTXSW_PROFILE_INDEX + (ix * 4),
  513. CTXSW_FREQ_SCLK_CFG_INDEX(eng_clock_index), ~CTXSW_FREQ_SCLK_CFG_INDEX_MASK);
  514. }
  515. void r600_power_level_set_watermark_id(struct radeon_device *rdev,
  516. enum r600_power_level index,
  517. enum r600_display_watermark watermark_id)
  518. {
  519. u32 ix = 3 - (3 & index);
  520. u32 tmp = 0;
  521. if (watermark_id == R600_DISPLAY_WATERMARK_HIGH)
  522. tmp = CTXSW_FREQ_DISPLAY_WATERMARK;
  523. WREG32_P(CTXSW_PROFILE_INDEX + (ix * 4), tmp, ~CTXSW_FREQ_DISPLAY_WATERMARK);
  524. }
  525. void r600_power_level_set_pcie_gen2(struct radeon_device *rdev,
  526. enum r600_power_level index, bool compatible)
  527. {
  528. u32 ix = 3 - (3 & index);
  529. u32 tmp = 0;
  530. if (compatible)
  531. tmp = CTXSW_FREQ_GEN2PCIE_VOLT;
  532. WREG32_P(CTXSW_PROFILE_INDEX + (ix * 4), tmp, ~CTXSW_FREQ_GEN2PCIE_VOLT);
  533. }
  534. enum r600_power_level r600_power_level_get_current_index(struct radeon_device *rdev)
  535. {
  536. u32 tmp;
  537. tmp = RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK;
  538. tmp >>= CURRENT_PROFILE_INDEX_SHIFT;
  539. return tmp;
  540. }
  541. enum r600_power_level r600_power_level_get_target_index(struct radeon_device *rdev)
  542. {
  543. u32 tmp;
  544. tmp = RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & TARGET_PROFILE_INDEX_MASK;
  545. tmp >>= TARGET_PROFILE_INDEX_SHIFT;
  546. return tmp;
  547. }
  548. void r600_power_level_set_enter_index(struct radeon_device *rdev,
  549. enum r600_power_level index)
  550. {
  551. WREG32_P(TARGET_AND_CURRENT_PROFILE_INDEX, DYN_PWR_ENTER_INDEX(index),
  552. ~DYN_PWR_ENTER_INDEX_MASK);
  553. }
  554. void r600_wait_for_power_level_unequal(struct radeon_device *rdev,
  555. enum r600_power_level index)
  556. {
  557. int i;
  558. for (i = 0; i < rdev->usec_timeout; i++) {
  559. if (r600_power_level_get_target_index(rdev) != index)
  560. break;
  561. udelay(1);
  562. }
  563. for (i = 0; i < rdev->usec_timeout; i++) {
  564. if (r600_power_level_get_current_index(rdev) != index)
  565. break;
  566. udelay(1);
  567. }
  568. }
  569. void r600_wait_for_power_level(struct radeon_device *rdev,
  570. enum r600_power_level index)
  571. {
  572. int i;
  573. for (i = 0; i < rdev->usec_timeout; i++) {
  574. if (r600_power_level_get_target_index(rdev) == index)
  575. break;
  576. udelay(1);
  577. }
  578. for (i = 0; i < rdev->usec_timeout; i++) {
  579. if (r600_power_level_get_current_index(rdev) == index)
  580. break;
  581. udelay(1);
  582. }
  583. }
  584. void r600_start_dpm(struct radeon_device *rdev)
  585. {
  586. r600_enable_sclk_control(rdev, false);
  587. r600_enable_mclk_control(rdev, false);
  588. r600_dynamicpm_enable(rdev, true);
  589. radeon_wait_for_vblank(rdev, 0);
  590. radeon_wait_for_vblank(rdev, 1);
  591. r600_enable_spll_bypass(rdev, true);
  592. r600_wait_for_spll_change(rdev);
  593. r600_enable_spll_bypass(rdev, false);
  594. r600_wait_for_spll_change(rdev);
  595. r600_enable_spll_bypass(rdev, true);
  596. r600_wait_for_spll_change(rdev);
  597. r600_enable_spll_bypass(rdev, false);
  598. r600_wait_for_spll_change(rdev);
  599. r600_enable_sclk_control(rdev, true);
  600. r600_enable_mclk_control(rdev, true);
  601. }
  602. void r600_stop_dpm(struct radeon_device *rdev)
  603. {
  604. r600_dynamicpm_enable(rdev, false);
  605. }
  606. int r600_dpm_pre_set_power_state(struct radeon_device *rdev)
  607. {
  608. return 0;
  609. }
  610. void r600_dpm_post_set_power_state(struct radeon_device *rdev)
  611. {
  612. }
  613. bool r600_is_uvd_state(u32 class, u32 class2)
  614. {
  615. if (class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
  616. return true;
  617. if (class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
  618. return true;
  619. if (class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
  620. return true;
  621. if (class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
  622. return true;
  623. if (class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
  624. return true;
  625. return false;
  626. }
  627. static int r600_set_thermal_temperature_range(struct radeon_device *rdev,
  628. int min_temp, int max_temp)
  629. {
  630. int low_temp = 0 * 1000;
  631. int high_temp = 255 * 1000;
  632. if (low_temp < min_temp)
  633. low_temp = min_temp;
  634. if (high_temp > max_temp)
  635. high_temp = max_temp;
  636. if (high_temp < low_temp) {
  637. DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp);
  638. return -EINVAL;
  639. }
  640. WREG32_P(CG_THERMAL_INT, DIG_THERM_INTH(high_temp / 1000), ~DIG_THERM_INTH_MASK);
  641. WREG32_P(CG_THERMAL_INT, DIG_THERM_INTL(low_temp / 1000), ~DIG_THERM_INTL_MASK);
  642. WREG32_P(CG_THERMAL_CTRL, DIG_THERM_DPM(high_temp / 1000), ~DIG_THERM_DPM_MASK);
  643. rdev->pm.dpm.thermal.min_temp = low_temp;
  644. rdev->pm.dpm.thermal.max_temp = high_temp;
  645. return 0;
  646. }
  647. bool r600_is_internal_thermal_sensor(enum radeon_int_thermal_type sensor)
  648. {
  649. switch (sensor) {
  650. case THERMAL_TYPE_RV6XX:
  651. case THERMAL_TYPE_RV770:
  652. case THERMAL_TYPE_EVERGREEN:
  653. case THERMAL_TYPE_SUMO:
  654. case THERMAL_TYPE_NI:
  655. case THERMAL_TYPE_SI:
  656. case THERMAL_TYPE_CI:
  657. case THERMAL_TYPE_KV:
  658. return true;
  659. case THERMAL_TYPE_ADT7473_WITH_INTERNAL:
  660. case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
  661. return false; /* need special handling */
  662. case THERMAL_TYPE_NONE:
  663. case THERMAL_TYPE_EXTERNAL:
  664. case THERMAL_TYPE_EXTERNAL_GPIO:
  665. default:
  666. return false;
  667. }
  668. }
  669. int r600_dpm_late_enable(struct radeon_device *rdev)
  670. {
  671. int ret;
  672. if (rdev->irq.installed &&
  673. r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
  674. ret = r600_set_thermal_temperature_range(rdev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX);
  675. if (ret)
  676. return ret;
  677. rdev->irq.dpm_thermal = true;
  678. radeon_irq_set(rdev);
  679. }
  680. return 0;
  681. }
  682. union power_info {
  683. struct _ATOM_POWERPLAY_INFO info;
  684. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  685. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  686. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  687. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  688. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  689. struct _ATOM_PPLIB_POWERPLAYTABLE4 pplib4;
  690. struct _ATOM_PPLIB_POWERPLAYTABLE5 pplib5;
  691. };
  692. union fan_info {
  693. struct _ATOM_PPLIB_FANTABLE fan;
  694. struct _ATOM_PPLIB_FANTABLE2 fan2;
  695. struct _ATOM_PPLIB_FANTABLE3 fan3;
  696. };
  697. static int r600_parse_clk_voltage_dep_table(struct radeon_clock_voltage_dependency_table *radeon_table,
  698. ATOM_PPLIB_Clock_Voltage_Dependency_Table *atom_table)
  699. {
  700. u32 size = atom_table->ucNumEntries *
  701. sizeof(struct radeon_clock_voltage_dependency_entry);
  702. int i;
  703. ATOM_PPLIB_Clock_Voltage_Dependency_Record *entry;
  704. radeon_table->entries = kzalloc(size, GFP_KERNEL);
  705. if (!radeon_table->entries)
  706. return -ENOMEM;
  707. entry = &atom_table->entries[0];
  708. for (i = 0; i < atom_table->ucNumEntries; i++) {
  709. radeon_table->entries[i].clk = le16_to_cpu(entry->usClockLow) |
  710. (entry->ucClockHigh << 16);
  711. radeon_table->entries[i].v = le16_to_cpu(entry->usVoltage);
  712. entry = (ATOM_PPLIB_Clock_Voltage_Dependency_Record *)
  713. ((u8 *)entry + sizeof(ATOM_PPLIB_Clock_Voltage_Dependency_Record));
  714. }
  715. radeon_table->count = atom_table->ucNumEntries;
  716. return 0;
  717. }
  718. int r600_get_platform_caps(struct radeon_device *rdev)
  719. {
  720. struct radeon_mode_info *mode_info = &rdev->mode_info;
  721. union power_info *power_info;
  722. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  723. u16 data_offset;
  724. u8 frev, crev;
  725. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  726. &frev, &crev, &data_offset))
  727. return -EINVAL;
  728. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  729. rdev->pm.dpm.platform_caps = le32_to_cpu(power_info->pplib.ulPlatformCaps);
  730. rdev->pm.dpm.backbias_response_time = le16_to_cpu(power_info->pplib.usBackbiasTime);
  731. rdev->pm.dpm.voltage_response_time = le16_to_cpu(power_info->pplib.usVoltageTime);
  732. return 0;
  733. }
  734. /* sizeof(ATOM_PPLIB_EXTENDEDHEADER) */
  735. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2 12
  736. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3 14
  737. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4 16
  738. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5 18
  739. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6 20
  740. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7 22
  741. int r600_parse_extended_power_table(struct radeon_device *rdev)
  742. {
  743. struct radeon_mode_info *mode_info = &rdev->mode_info;
  744. union power_info *power_info;
  745. union fan_info *fan_info;
  746. ATOM_PPLIB_Clock_Voltage_Dependency_Table *dep_table;
  747. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  748. u16 data_offset;
  749. u8 frev, crev;
  750. int ret, i;
  751. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  752. &frev, &crev, &data_offset))
  753. return -EINVAL;
  754. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  755. /* fan table */
  756. if (le16_to_cpu(power_info->pplib.usTableSize) >=
  757. sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE3)) {
  758. if (power_info->pplib3.usFanTableOffset) {
  759. fan_info = (union fan_info *)(mode_info->atom_context->bios + data_offset +
  760. le16_to_cpu(power_info->pplib3.usFanTableOffset));
  761. rdev->pm.dpm.fan.t_hyst = fan_info->fan.ucTHyst;
  762. rdev->pm.dpm.fan.t_min = le16_to_cpu(fan_info->fan.usTMin);
  763. rdev->pm.dpm.fan.t_med = le16_to_cpu(fan_info->fan.usTMed);
  764. rdev->pm.dpm.fan.t_high = le16_to_cpu(fan_info->fan.usTHigh);
  765. rdev->pm.dpm.fan.pwm_min = le16_to_cpu(fan_info->fan.usPWMMin);
  766. rdev->pm.dpm.fan.pwm_med = le16_to_cpu(fan_info->fan.usPWMMed);
  767. rdev->pm.dpm.fan.pwm_high = le16_to_cpu(fan_info->fan.usPWMHigh);
  768. if (fan_info->fan.ucFanTableFormat >= 2)
  769. rdev->pm.dpm.fan.t_max = le16_to_cpu(fan_info->fan2.usTMax);
  770. else
  771. rdev->pm.dpm.fan.t_max = 10900;
  772. rdev->pm.dpm.fan.cycle_delay = 100000;
  773. if (fan_info->fan.ucFanTableFormat >= 3) {
  774. rdev->pm.dpm.fan.control_mode = fan_info->fan3.ucFanControlMode;
  775. rdev->pm.dpm.fan.default_max_fan_pwm =
  776. le16_to_cpu(fan_info->fan3.usFanPWMMax);
  777. rdev->pm.dpm.fan.default_fan_output_sensitivity = 4836;
  778. rdev->pm.dpm.fan.fan_output_sensitivity =
  779. le16_to_cpu(fan_info->fan3.usFanOutputSensitivity);
  780. }
  781. rdev->pm.dpm.fan.ucode_fan_control = true;
  782. }
  783. }
  784. /* clock dependancy tables, shedding tables */
  785. if (le16_to_cpu(power_info->pplib.usTableSize) >=
  786. sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE4)) {
  787. if (power_info->pplib4.usVddcDependencyOnSCLKOffset) {
  788. dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
  789. (mode_info->atom_context->bios + data_offset +
  790. le16_to_cpu(power_info->pplib4.usVddcDependencyOnSCLKOffset));
  791. ret = r600_parse_clk_voltage_dep_table(&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk,
  792. dep_table);
  793. if (ret)
  794. return ret;
  795. }
  796. if (power_info->pplib4.usVddciDependencyOnMCLKOffset) {
  797. dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
  798. (mode_info->atom_context->bios + data_offset +
  799. le16_to_cpu(power_info->pplib4.usVddciDependencyOnMCLKOffset));
  800. ret = r600_parse_clk_voltage_dep_table(&rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk,
  801. dep_table);
  802. if (ret) {
  803. kfree(rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries);
  804. return ret;
  805. }
  806. }
  807. if (power_info->pplib4.usVddcDependencyOnMCLKOffset) {
  808. dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
  809. (mode_info->atom_context->bios + data_offset +
  810. le16_to_cpu(power_info->pplib4.usVddcDependencyOnMCLKOffset));
  811. ret = r600_parse_clk_voltage_dep_table(&rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk,
  812. dep_table);
  813. if (ret) {
  814. kfree(rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries);
  815. kfree(rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk.entries);
  816. return ret;
  817. }
  818. }
  819. if (power_info->pplib4.usMvddDependencyOnMCLKOffset) {
  820. dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
  821. (mode_info->atom_context->bios + data_offset +
  822. le16_to_cpu(power_info->pplib4.usMvddDependencyOnMCLKOffset));
  823. ret = r600_parse_clk_voltage_dep_table(&rdev->pm.dpm.dyn_state.mvdd_dependency_on_mclk,
  824. dep_table);
  825. if (ret) {
  826. kfree(rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries);
  827. kfree(rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk.entries);
  828. kfree(rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk.entries);
  829. return ret;
  830. }
  831. }
  832. if (power_info->pplib4.usMaxClockVoltageOnDCOffset) {
  833. ATOM_PPLIB_Clock_Voltage_Limit_Table *clk_v =
  834. (ATOM_PPLIB_Clock_Voltage_Limit_Table *)
  835. (mode_info->atom_context->bios + data_offset +
  836. le16_to_cpu(power_info->pplib4.usMaxClockVoltageOnDCOffset));
  837. if (clk_v->ucNumEntries) {
  838. rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc.sclk =
  839. le16_to_cpu(clk_v->entries[0].usSclkLow) |
  840. (clk_v->entries[0].ucSclkHigh << 16);
  841. rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc.mclk =
  842. le16_to_cpu(clk_v->entries[0].usMclkLow) |
  843. (clk_v->entries[0].ucMclkHigh << 16);
  844. rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc.vddc =
  845. le16_to_cpu(clk_v->entries[0].usVddc);
  846. rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc.vddci =
  847. le16_to_cpu(clk_v->entries[0].usVddci);
  848. }
  849. }
  850. if (power_info->pplib4.usVddcPhaseShedLimitsTableOffset) {
  851. ATOM_PPLIB_PhaseSheddingLimits_Table *psl =
  852. (ATOM_PPLIB_PhaseSheddingLimits_Table *)
  853. (mode_info->atom_context->bios + data_offset +
  854. le16_to_cpu(power_info->pplib4.usVddcPhaseShedLimitsTableOffset));
  855. ATOM_PPLIB_PhaseSheddingLimits_Record *entry;
  856. rdev->pm.dpm.dyn_state.phase_shedding_limits_table.entries =
  857. kzalloc(psl->ucNumEntries *
  858. sizeof(struct radeon_phase_shedding_limits_entry),
  859. GFP_KERNEL);
  860. if (!rdev->pm.dpm.dyn_state.phase_shedding_limits_table.entries) {
  861. r600_free_extended_power_table(rdev);
  862. return -ENOMEM;
  863. }
  864. entry = &psl->entries[0];
  865. for (i = 0; i < psl->ucNumEntries; i++) {
  866. rdev->pm.dpm.dyn_state.phase_shedding_limits_table.entries[i].sclk =
  867. le16_to_cpu(entry->usSclkLow) | (entry->ucSclkHigh << 16);
  868. rdev->pm.dpm.dyn_state.phase_shedding_limits_table.entries[i].mclk =
  869. le16_to_cpu(entry->usMclkLow) | (entry->ucMclkHigh << 16);
  870. rdev->pm.dpm.dyn_state.phase_shedding_limits_table.entries[i].voltage =
  871. le16_to_cpu(entry->usVoltage);
  872. entry = (ATOM_PPLIB_PhaseSheddingLimits_Record *)
  873. ((u8 *)entry + sizeof(ATOM_PPLIB_PhaseSheddingLimits_Record));
  874. }
  875. rdev->pm.dpm.dyn_state.phase_shedding_limits_table.count =
  876. psl->ucNumEntries;
  877. }
  878. }
  879. /* cac data */
  880. if (le16_to_cpu(power_info->pplib.usTableSize) >=
  881. sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE5)) {
  882. rdev->pm.dpm.tdp_limit = le32_to_cpu(power_info->pplib5.ulTDPLimit);
  883. rdev->pm.dpm.near_tdp_limit = le32_to_cpu(power_info->pplib5.ulNearTDPLimit);
  884. rdev->pm.dpm.near_tdp_limit_adjusted = rdev->pm.dpm.near_tdp_limit;
  885. rdev->pm.dpm.tdp_od_limit = le16_to_cpu(power_info->pplib5.usTDPODLimit);
  886. if (rdev->pm.dpm.tdp_od_limit)
  887. rdev->pm.dpm.power_control = true;
  888. else
  889. rdev->pm.dpm.power_control = false;
  890. rdev->pm.dpm.tdp_adjustment = 0;
  891. rdev->pm.dpm.sq_ramping_threshold = le32_to_cpu(power_info->pplib5.ulSQRampingThreshold);
  892. rdev->pm.dpm.cac_leakage = le32_to_cpu(power_info->pplib5.ulCACLeakage);
  893. rdev->pm.dpm.load_line_slope = le16_to_cpu(power_info->pplib5.usLoadLineSlope);
  894. if (power_info->pplib5.usCACLeakageTableOffset) {
  895. ATOM_PPLIB_CAC_Leakage_Table *cac_table =
  896. (ATOM_PPLIB_CAC_Leakage_Table *)
  897. (mode_info->atom_context->bios + data_offset +
  898. le16_to_cpu(power_info->pplib5.usCACLeakageTableOffset));
  899. ATOM_PPLIB_CAC_Leakage_Record *entry;
  900. u32 size = cac_table->ucNumEntries * sizeof(struct radeon_cac_leakage_table);
  901. rdev->pm.dpm.dyn_state.cac_leakage_table.entries = kzalloc(size, GFP_KERNEL);
  902. if (!rdev->pm.dpm.dyn_state.cac_leakage_table.entries) {
  903. r600_free_extended_power_table(rdev);
  904. return -ENOMEM;
  905. }
  906. entry = &cac_table->entries[0];
  907. for (i = 0; i < cac_table->ucNumEntries; i++) {
  908. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_EVV) {
  909. rdev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc1 =
  910. le16_to_cpu(entry->usVddc1);
  911. rdev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc2 =
  912. le16_to_cpu(entry->usVddc2);
  913. rdev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc3 =
  914. le16_to_cpu(entry->usVddc3);
  915. } else {
  916. rdev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc =
  917. le16_to_cpu(entry->usVddc);
  918. rdev->pm.dpm.dyn_state.cac_leakage_table.entries[i].leakage =
  919. le32_to_cpu(entry->ulLeakageValue);
  920. }
  921. entry = (ATOM_PPLIB_CAC_Leakage_Record *)
  922. ((u8 *)entry + sizeof(ATOM_PPLIB_CAC_Leakage_Record));
  923. }
  924. rdev->pm.dpm.dyn_state.cac_leakage_table.count = cac_table->ucNumEntries;
  925. }
  926. }
  927. /* ext tables */
  928. if (le16_to_cpu(power_info->pplib.usTableSize) >=
  929. sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE3)) {
  930. ATOM_PPLIB_EXTENDEDHEADER *ext_hdr = (ATOM_PPLIB_EXTENDEDHEADER *)
  931. (mode_info->atom_context->bios + data_offset +
  932. le16_to_cpu(power_info->pplib3.usExtendendedHeaderOffset));
  933. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2) &&
  934. ext_hdr->usVCETableOffset) {
  935. VCEClockInfoArray *array = (VCEClockInfoArray *)
  936. (mode_info->atom_context->bios + data_offset +
  937. le16_to_cpu(ext_hdr->usVCETableOffset) + 1);
  938. ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *limits =
  939. (ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *)
  940. (mode_info->atom_context->bios + data_offset +
  941. le16_to_cpu(ext_hdr->usVCETableOffset) + 1 +
  942. 1 + array->ucNumEntries * sizeof(VCEClockInfo));
  943. ATOM_PPLIB_VCE_State_Table *states =
  944. (ATOM_PPLIB_VCE_State_Table *)
  945. (mode_info->atom_context->bios + data_offset +
  946. le16_to_cpu(ext_hdr->usVCETableOffset) + 1 +
  947. 1 + (array->ucNumEntries * sizeof (VCEClockInfo)) +
  948. 1 + (limits->numEntries * sizeof(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record)));
  949. ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record *entry;
  950. ATOM_PPLIB_VCE_State_Record *state_entry;
  951. VCEClockInfo *vce_clk;
  952. u32 size = limits->numEntries *
  953. sizeof(struct radeon_vce_clock_voltage_dependency_entry);
  954. rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries =
  955. kzalloc(size, GFP_KERNEL);
  956. if (!rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries) {
  957. r600_free_extended_power_table(rdev);
  958. return -ENOMEM;
  959. }
  960. rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.count =
  961. limits->numEntries;
  962. entry = &limits->entries[0];
  963. state_entry = &states->entries[0];
  964. for (i = 0; i < limits->numEntries; i++) {
  965. vce_clk = (VCEClockInfo *)
  966. ((u8 *)&array->entries[0] +
  967. (entry->ucVCEClockInfoIndex * sizeof(VCEClockInfo)));
  968. rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].evclk =
  969. le16_to_cpu(vce_clk->usEVClkLow) | (vce_clk->ucEVClkHigh << 16);
  970. rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].ecclk =
  971. le16_to_cpu(vce_clk->usECClkLow) | (vce_clk->ucECClkHigh << 16);
  972. rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].v =
  973. le16_to_cpu(entry->usVoltage);
  974. entry = (ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record *)
  975. ((u8 *)entry + sizeof(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record));
  976. }
  977. for (i = 0; i < states->numEntries; i++) {
  978. if (i >= RADEON_MAX_VCE_LEVELS)
  979. break;
  980. vce_clk = (VCEClockInfo *)
  981. ((u8 *)&array->entries[0] +
  982. (state_entry->ucVCEClockInfoIndex * sizeof(VCEClockInfo)));
  983. rdev->pm.dpm.vce_states[i].evclk =
  984. le16_to_cpu(vce_clk->usEVClkLow) | (vce_clk->ucEVClkHigh << 16);
  985. rdev->pm.dpm.vce_states[i].ecclk =
  986. le16_to_cpu(vce_clk->usECClkLow) | (vce_clk->ucECClkHigh << 16);
  987. rdev->pm.dpm.vce_states[i].clk_idx =
  988. state_entry->ucClockInfoIndex & 0x3f;
  989. rdev->pm.dpm.vce_states[i].pstate =
  990. (state_entry->ucClockInfoIndex & 0xc0) >> 6;
  991. state_entry = (ATOM_PPLIB_VCE_State_Record *)
  992. ((u8 *)state_entry + sizeof(ATOM_PPLIB_VCE_State_Record));
  993. }
  994. }
  995. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3) &&
  996. ext_hdr->usUVDTableOffset) {
  997. UVDClockInfoArray *array = (UVDClockInfoArray *)
  998. (mode_info->atom_context->bios + data_offset +
  999. le16_to_cpu(ext_hdr->usUVDTableOffset) + 1);
  1000. ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table *limits =
  1001. (ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table *)
  1002. (mode_info->atom_context->bios + data_offset +
  1003. le16_to_cpu(ext_hdr->usUVDTableOffset) + 1 +
  1004. 1 + (array->ucNumEntries * sizeof (UVDClockInfo)));
  1005. ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record *entry;
  1006. u32 size = limits->numEntries *
  1007. sizeof(struct radeon_uvd_clock_voltage_dependency_entry);
  1008. rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries =
  1009. kzalloc(size, GFP_KERNEL);
  1010. if (!rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries) {
  1011. r600_free_extended_power_table(rdev);
  1012. return -ENOMEM;
  1013. }
  1014. rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count =
  1015. limits->numEntries;
  1016. entry = &limits->entries[0];
  1017. for (i = 0; i < limits->numEntries; i++) {
  1018. UVDClockInfo *uvd_clk = (UVDClockInfo *)
  1019. ((u8 *)&array->entries[0] +
  1020. (entry->ucUVDClockInfoIndex * sizeof(UVDClockInfo)));
  1021. rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].vclk =
  1022. le16_to_cpu(uvd_clk->usVClkLow) | (uvd_clk->ucVClkHigh << 16);
  1023. rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].dclk =
  1024. le16_to_cpu(uvd_clk->usDClkLow) | (uvd_clk->ucDClkHigh << 16);
  1025. rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].v =
  1026. le16_to_cpu(entry->usVoltage);
  1027. entry = (ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record *)
  1028. ((u8 *)entry + sizeof(ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record));
  1029. }
  1030. }
  1031. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4) &&
  1032. ext_hdr->usSAMUTableOffset) {
  1033. ATOM_PPLIB_SAMClk_Voltage_Limit_Table *limits =
  1034. (ATOM_PPLIB_SAMClk_Voltage_Limit_Table *)
  1035. (mode_info->atom_context->bios + data_offset +
  1036. le16_to_cpu(ext_hdr->usSAMUTableOffset) + 1);
  1037. ATOM_PPLIB_SAMClk_Voltage_Limit_Record *entry;
  1038. u32 size = limits->numEntries *
  1039. sizeof(struct radeon_clock_voltage_dependency_entry);
  1040. rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries =
  1041. kzalloc(size, GFP_KERNEL);
  1042. if (!rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries) {
  1043. r600_free_extended_power_table(rdev);
  1044. return -ENOMEM;
  1045. }
  1046. rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.count =
  1047. limits->numEntries;
  1048. entry = &limits->entries[0];
  1049. for (i = 0; i < limits->numEntries; i++) {
  1050. rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[i].clk =
  1051. le16_to_cpu(entry->usSAMClockLow) | (entry->ucSAMClockHigh << 16);
  1052. rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[i].v =
  1053. le16_to_cpu(entry->usVoltage);
  1054. entry = (ATOM_PPLIB_SAMClk_Voltage_Limit_Record *)
  1055. ((u8 *)entry + sizeof(ATOM_PPLIB_SAMClk_Voltage_Limit_Record));
  1056. }
  1057. }
  1058. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5) &&
  1059. ext_hdr->usPPMTableOffset) {
  1060. ATOM_PPLIB_PPM_Table *ppm = (ATOM_PPLIB_PPM_Table *)
  1061. (mode_info->atom_context->bios + data_offset +
  1062. le16_to_cpu(ext_hdr->usPPMTableOffset));
  1063. rdev->pm.dpm.dyn_state.ppm_table =
  1064. kzalloc(sizeof(struct radeon_ppm_table), GFP_KERNEL);
  1065. if (!rdev->pm.dpm.dyn_state.ppm_table) {
  1066. r600_free_extended_power_table(rdev);
  1067. return -ENOMEM;
  1068. }
  1069. rdev->pm.dpm.dyn_state.ppm_table->ppm_design = ppm->ucPpmDesign;
  1070. rdev->pm.dpm.dyn_state.ppm_table->cpu_core_number =
  1071. le16_to_cpu(ppm->usCpuCoreNumber);
  1072. rdev->pm.dpm.dyn_state.ppm_table->platform_tdp =
  1073. le32_to_cpu(ppm->ulPlatformTDP);
  1074. rdev->pm.dpm.dyn_state.ppm_table->small_ac_platform_tdp =
  1075. le32_to_cpu(ppm->ulSmallACPlatformTDP);
  1076. rdev->pm.dpm.dyn_state.ppm_table->platform_tdc =
  1077. le32_to_cpu(ppm->ulPlatformTDC);
  1078. rdev->pm.dpm.dyn_state.ppm_table->small_ac_platform_tdc =
  1079. le32_to_cpu(ppm->ulSmallACPlatformTDC);
  1080. rdev->pm.dpm.dyn_state.ppm_table->apu_tdp =
  1081. le32_to_cpu(ppm->ulApuTDP);
  1082. rdev->pm.dpm.dyn_state.ppm_table->dgpu_tdp =
  1083. le32_to_cpu(ppm->ulDGpuTDP);
  1084. rdev->pm.dpm.dyn_state.ppm_table->dgpu_ulv_power =
  1085. le32_to_cpu(ppm->ulDGpuUlvPower);
  1086. rdev->pm.dpm.dyn_state.ppm_table->tj_max =
  1087. le32_to_cpu(ppm->ulTjmax);
  1088. }
  1089. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6) &&
  1090. ext_hdr->usACPTableOffset) {
  1091. ATOM_PPLIB_ACPClk_Voltage_Limit_Table *limits =
  1092. (ATOM_PPLIB_ACPClk_Voltage_Limit_Table *)
  1093. (mode_info->atom_context->bios + data_offset +
  1094. le16_to_cpu(ext_hdr->usACPTableOffset) + 1);
  1095. ATOM_PPLIB_ACPClk_Voltage_Limit_Record *entry;
  1096. u32 size = limits->numEntries *
  1097. sizeof(struct radeon_clock_voltage_dependency_entry);
  1098. rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries =
  1099. kzalloc(size, GFP_KERNEL);
  1100. if (!rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries) {
  1101. r600_free_extended_power_table(rdev);
  1102. return -ENOMEM;
  1103. }
  1104. rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.count =
  1105. limits->numEntries;
  1106. entry = &limits->entries[0];
  1107. for (i = 0; i < limits->numEntries; i++) {
  1108. rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[i].clk =
  1109. le16_to_cpu(entry->usACPClockLow) | (entry->ucACPClockHigh << 16);
  1110. rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[i].v =
  1111. le16_to_cpu(entry->usVoltage);
  1112. entry = (ATOM_PPLIB_ACPClk_Voltage_Limit_Record *)
  1113. ((u8 *)entry + sizeof(ATOM_PPLIB_ACPClk_Voltage_Limit_Record));
  1114. }
  1115. }
  1116. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7) &&
  1117. ext_hdr->usPowerTuneTableOffset) {
  1118. u8 rev = *(u8 *)(mode_info->atom_context->bios + data_offset +
  1119. le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
  1120. ATOM_PowerTune_Table *pt;
  1121. rdev->pm.dpm.dyn_state.cac_tdp_table =
  1122. kzalloc(sizeof(struct radeon_cac_tdp_table), GFP_KERNEL);
  1123. if (!rdev->pm.dpm.dyn_state.cac_tdp_table) {
  1124. r600_free_extended_power_table(rdev);
  1125. return -ENOMEM;
  1126. }
  1127. if (rev > 0) {
  1128. ATOM_PPLIB_POWERTUNE_Table_V1 *ppt = (ATOM_PPLIB_POWERTUNE_Table_V1 *)
  1129. (mode_info->atom_context->bios + data_offset +
  1130. le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
  1131. rdev->pm.dpm.dyn_state.cac_tdp_table->maximum_power_delivery_limit =
  1132. le16_to_cpu(ppt->usMaximumPowerDeliveryLimit);
  1133. pt = &ppt->power_tune_table;
  1134. } else {
  1135. ATOM_PPLIB_POWERTUNE_Table *ppt = (ATOM_PPLIB_POWERTUNE_Table *)
  1136. (mode_info->atom_context->bios + data_offset +
  1137. le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
  1138. rdev->pm.dpm.dyn_state.cac_tdp_table->maximum_power_delivery_limit = 255;
  1139. pt = &ppt->power_tune_table;
  1140. }
  1141. rdev->pm.dpm.dyn_state.cac_tdp_table->tdp = le16_to_cpu(pt->usTDP);
  1142. rdev->pm.dpm.dyn_state.cac_tdp_table->configurable_tdp =
  1143. le16_to_cpu(pt->usConfigurableTDP);
  1144. rdev->pm.dpm.dyn_state.cac_tdp_table->tdc = le16_to_cpu(pt->usTDC);
  1145. rdev->pm.dpm.dyn_state.cac_tdp_table->battery_power_limit =
  1146. le16_to_cpu(pt->usBatteryPowerLimit);
  1147. rdev->pm.dpm.dyn_state.cac_tdp_table->small_power_limit =
  1148. le16_to_cpu(pt->usSmallPowerLimit);
  1149. rdev->pm.dpm.dyn_state.cac_tdp_table->low_cac_leakage =
  1150. le16_to_cpu(pt->usLowCACLeakage);
  1151. rdev->pm.dpm.dyn_state.cac_tdp_table->high_cac_leakage =
  1152. le16_to_cpu(pt->usHighCACLeakage);
  1153. }
  1154. }
  1155. return 0;
  1156. }
  1157. void r600_free_extended_power_table(struct radeon_device *rdev)
  1158. {
  1159. struct radeon_dpm_dynamic_state *dyn_state = &rdev->pm.dpm.dyn_state;
  1160. kfree(dyn_state->vddc_dependency_on_sclk.entries);
  1161. kfree(dyn_state->vddci_dependency_on_mclk.entries);
  1162. kfree(dyn_state->vddc_dependency_on_mclk.entries);
  1163. kfree(dyn_state->mvdd_dependency_on_mclk.entries);
  1164. kfree(dyn_state->cac_leakage_table.entries);
  1165. kfree(dyn_state->phase_shedding_limits_table.entries);
  1166. kfree(dyn_state->ppm_table);
  1167. kfree(dyn_state->cac_tdp_table);
  1168. kfree(dyn_state->vce_clock_voltage_dependency_table.entries);
  1169. kfree(dyn_state->uvd_clock_voltage_dependency_table.entries);
  1170. kfree(dyn_state->samu_clock_voltage_dependency_table.entries);
  1171. kfree(dyn_state->acp_clock_voltage_dependency_table.entries);
  1172. }
  1173. enum radeon_pcie_gen r600_get_pcie_gen_support(struct radeon_device *rdev,
  1174. u32 sys_mask,
  1175. enum radeon_pcie_gen asic_gen,
  1176. enum radeon_pcie_gen default_gen)
  1177. {
  1178. switch (asic_gen) {
  1179. case RADEON_PCIE_GEN1:
  1180. return RADEON_PCIE_GEN1;
  1181. case RADEON_PCIE_GEN2:
  1182. return RADEON_PCIE_GEN2;
  1183. case RADEON_PCIE_GEN3:
  1184. return RADEON_PCIE_GEN3;
  1185. default:
  1186. if ((sys_mask & DRM_PCIE_SPEED_80) && (default_gen == RADEON_PCIE_GEN3))
  1187. return RADEON_PCIE_GEN3;
  1188. else if ((sys_mask & DRM_PCIE_SPEED_50) && (default_gen == RADEON_PCIE_GEN2))
  1189. return RADEON_PCIE_GEN2;
  1190. else
  1191. return RADEON_PCIE_GEN1;
  1192. }
  1193. return RADEON_PCIE_GEN1;
  1194. }
  1195. u16 r600_get_pcie_lane_support(struct radeon_device *rdev,
  1196. u16 asic_lanes,
  1197. u16 default_lanes)
  1198. {
  1199. switch (asic_lanes) {
  1200. case 0:
  1201. default:
  1202. return default_lanes;
  1203. case 1:
  1204. return 1;
  1205. case 2:
  1206. return 2;
  1207. case 4:
  1208. return 4;
  1209. case 8:
  1210. return 8;
  1211. case 12:
  1212. return 12;
  1213. case 16:
  1214. return 16;
  1215. }
  1216. }
  1217. u8 r600_encode_pci_lane_width(u32 lanes)
  1218. {
  1219. u8 encoded_lanes[] = { 0, 1, 2, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 6 };
  1220. if (lanes > 16)
  1221. return 0;
  1222. return encoded_lanes[lanes];
  1223. }