msm_cvp_res_parse.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/iommu.h>
  7. #include <linux/of.h>
  8. #include <linux/slab.h>
  9. #include <linux/sort.h>
  10. #include <linux/of_reserved_mem.h>
  11. #include "msm_cvp_debug.h"
  12. #include "msm_cvp_resources.h"
  13. #include "msm_cvp_res_parse.h"
  14. #include "cvp_core_hfi.h"
  15. #include "soc/qcom/secure_buffer.h"
  16. enum clock_properties {
  17. CLOCK_PROP_HAS_SCALING = 1 << 0,
  18. CLOCK_PROP_HAS_MEM_RETENTION = 1 << 1,
  19. };
  20. #define PERF_GOV "performance"
  21. static inline struct device *msm_iommu_get_ctx(const char *ctx_name)
  22. {
  23. return NULL;
  24. }
  25. static size_t get_u32_array_num_elements(struct device_node *np,
  26. char *name)
  27. {
  28. int len;
  29. size_t num_elements = 0;
  30. if (!of_get_property(np, name, &len)) {
  31. dprintk(CVP_ERR, "Failed to read %s from device tree\n",
  32. name);
  33. goto fail_read;
  34. }
  35. num_elements = len / sizeof(u32);
  36. if (num_elements <= 0) {
  37. dprintk(CVP_ERR, "%s not specified in device tree\n",
  38. name);
  39. goto fail_read;
  40. }
  41. return num_elements;
  42. fail_read:
  43. return 0;
  44. }
  45. static inline void msm_cvp_free_allowed_clocks_table(
  46. struct msm_cvp_platform_resources *res)
  47. {
  48. res->allowed_clks_tbl = NULL;
  49. }
  50. static inline void msm_cvp_free_cycles_per_mb_table(
  51. struct msm_cvp_platform_resources *res)
  52. {
  53. res->clock_freq_tbl.clk_prof_entries = NULL;
  54. }
  55. static inline void msm_cvp_free_reg_table(
  56. struct msm_cvp_platform_resources *res)
  57. {
  58. res->reg_set.reg_tbl = NULL;
  59. }
  60. static inline void msm_cvp_free_qdss_addr_table(
  61. struct msm_cvp_platform_resources *res)
  62. {
  63. res->qdss_addr_set.addr_tbl = NULL;
  64. }
  65. static inline void msm_cvp_free_bus_vectors(
  66. struct msm_cvp_platform_resources *res)
  67. {
  68. kfree(res->bus_set.bus_tbl);
  69. res->bus_set.bus_tbl = NULL;
  70. res->bus_set.count = 0;
  71. }
  72. static inline void msm_cvp_free_regulator_table(
  73. struct msm_cvp_platform_resources *res)
  74. {
  75. int c = 0;
  76. for (c = 0; c < res->regulator_set.count; ++c) {
  77. struct regulator_info *rinfo =
  78. &res->regulator_set.regulator_tbl[c];
  79. rinfo->name = NULL;
  80. }
  81. res->regulator_set.regulator_tbl = NULL;
  82. res->regulator_set.count = 0;
  83. }
  84. static inline void msm_cvp_free_clock_table(
  85. struct msm_cvp_platform_resources *res)
  86. {
  87. res->clock_set.clock_tbl = NULL;
  88. res->clock_set.count = 0;
  89. }
  90. void msm_cvp_free_platform_resources(
  91. struct msm_cvp_platform_resources *res)
  92. {
  93. msm_cvp_free_clock_table(res);
  94. msm_cvp_free_regulator_table(res);
  95. msm_cvp_free_allowed_clocks_table(res);
  96. msm_cvp_free_reg_table(res);
  97. msm_cvp_free_qdss_addr_table(res);
  98. msm_cvp_free_bus_vectors(res);
  99. }
  100. static int msm_cvp_load_ipcc_regs(struct msm_cvp_platform_resources *res)
  101. {
  102. int ret = 0;
  103. unsigned int reg_config[2];
  104. struct platform_device *pdev = res->pdev;
  105. ret = of_property_read_u32_array(pdev->dev.of_node, "qcom,ipcc-reg",
  106. reg_config, 2);
  107. if (ret) {
  108. dprintk(CVP_ERR, "Failed to read ipcc reg: %d\n", ret);
  109. return ret;
  110. }
  111. res->ipcc_reg_base = reg_config[0];
  112. res->ipcc_reg_size = reg_config[1];
  113. dprintk(CVP_CORE,
  114. "ipcc reg_base = %x, reg_size = %x\n",
  115. res->ipcc_reg_base,
  116. res->ipcc_reg_size
  117. );
  118. return ret;
  119. }
  120. static int msm_cvp_load_regspace_mapping(struct msm_cvp_platform_resources *res)
  121. {
  122. int ret = 0;
  123. unsigned int ipclite_mapping_config[3] = {0};
  124. unsigned int hwmutex_mapping_config[3] = {0};
  125. unsigned int aon_mapping_config[3] = {0};
  126. unsigned int timer_config[3] = {0};
  127. struct platform_device *pdev = res->pdev;
  128. ret = of_property_read_u32_array(pdev->dev.of_node, "ipclite_mappings",
  129. ipclite_mapping_config, 3);
  130. if (ret) {
  131. dprintk(CVP_ERR, "Failed to read ipclite reg: %d\n", ret);
  132. return ret;
  133. }
  134. res->reg_mappings.ipclite_iova = ipclite_mapping_config[0];
  135. res->reg_mappings.ipclite_size = ipclite_mapping_config[1];
  136. res->reg_mappings.ipclite_phyaddr = ipclite_mapping_config[2];
  137. ret = of_property_read_u32_array(pdev->dev.of_node, "hwmutex_mappings",
  138. hwmutex_mapping_config, 3);
  139. if (ret) {
  140. dprintk(CVP_ERR, "Failed to read hwmutex reg: %d\n", ret);
  141. return ret;
  142. }
  143. res->reg_mappings.hwmutex_iova = hwmutex_mapping_config[0];
  144. res->reg_mappings.hwmutex_size = hwmutex_mapping_config[1];
  145. res->reg_mappings.hwmutex_phyaddr = hwmutex_mapping_config[2];
  146. ret = of_property_read_u32_array(pdev->dev.of_node, "aon_mappings",
  147. aon_mapping_config, 3);
  148. if (ret) {
  149. dprintk(CVP_ERR, "Failed to read aon reg: %d\n", ret);
  150. return ret;
  151. }
  152. res->reg_mappings.aon_iova = aon_mapping_config[0];
  153. res->reg_mappings.aon_size = aon_mapping_config[1];
  154. res->reg_mappings.aon_phyaddr = aon_mapping_config[2];
  155. ret = of_property_read_u32_array(pdev->dev.of_node,
  156. "aon_timer_mappings", timer_config, 3);
  157. if (ret) {
  158. dprintk(CVP_ERR, "Failed to read timer reg: %d\n", ret);
  159. return ret;
  160. }
  161. res->reg_mappings.timer_iova = timer_config[0];
  162. res->reg_mappings.timer_size = timer_config[1];
  163. res->reg_mappings.timer_phyaddr = timer_config[2];
  164. dprintk(CVP_CORE,
  165. "reg mappings %#x %#x %#x %#x %#x %#X %#x %#x %#x %#x %#x %#x\n",
  166. res->reg_mappings.ipclite_iova, res->reg_mappings.ipclite_size,
  167. res->reg_mappings.ipclite_phyaddr, res->reg_mappings.hwmutex_iova,
  168. res->reg_mappings.hwmutex_size, res->reg_mappings.hwmutex_phyaddr,
  169. res->reg_mappings.aon_iova, res->reg_mappings.aon_size,
  170. res->reg_mappings.aon_phyaddr, res->reg_mappings.timer_iova,
  171. res->reg_mappings.timer_size, res->reg_mappings.timer_phyaddr);
  172. return ret;
  173. }
  174. static int msm_cvp_load_gcc_regs(struct msm_cvp_platform_resources *res)
  175. {
  176. int ret = 0;
  177. unsigned int reg_config[2];
  178. struct platform_device *pdev = res->pdev;
  179. ret = of_property_read_u32_array(pdev->dev.of_node, "qcom,gcc-reg",
  180. reg_config, 2);
  181. if (ret) {
  182. dprintk(CVP_WARN, "No gcc reg configured: %d\n", ret);
  183. return ret;
  184. }
  185. res->gcc_reg_base = reg_config[0];
  186. res->gcc_reg_size = reg_config[1];
  187. return ret;
  188. }
  189. static int msm_cvp_load_reg_table(struct msm_cvp_platform_resources *res)
  190. {
  191. struct reg_set *reg_set;
  192. struct platform_device *pdev = res->pdev;
  193. int i;
  194. int rc = 0;
  195. if (!of_find_property(pdev->dev.of_node, "qcom,reg-presets", NULL)) {
  196. /*
  197. * qcom,reg-presets is an optional property. It likely won't be
  198. * present if we don't have any register settings to program
  199. */
  200. dprintk(CVP_CORE, "qcom,reg-presets not found\n");
  201. return 0;
  202. }
  203. reg_set = &res->reg_set;
  204. reg_set->count = get_u32_array_num_elements(pdev->dev.of_node,
  205. "qcom,reg-presets");
  206. reg_set->count /= sizeof(*reg_set->reg_tbl) / sizeof(u32);
  207. if (!reg_set->count) {
  208. dprintk(CVP_CORE, "no elements in reg set\n");
  209. return rc;
  210. }
  211. reg_set->reg_tbl = devm_kzalloc(&pdev->dev, reg_set->count *
  212. sizeof(*(reg_set->reg_tbl)), GFP_KERNEL);
  213. if (!reg_set->reg_tbl) {
  214. dprintk(CVP_ERR, "%s Failed to alloc register table\n",
  215. __func__);
  216. return -ENOMEM;
  217. }
  218. if (of_property_read_u32_array(pdev->dev.of_node, "qcom,reg-presets",
  219. (u32 *)reg_set->reg_tbl, reg_set->count * 2)) {
  220. dprintk(CVP_ERR, "Failed to read register table\n");
  221. msm_cvp_free_reg_table(res);
  222. return -EINVAL;
  223. }
  224. for (i = 0; i < reg_set->count; i++) {
  225. dprintk(CVP_CORE,
  226. "reg = %x, value = %x\n",
  227. reg_set->reg_tbl[i].reg,
  228. reg_set->reg_tbl[i].value
  229. );
  230. }
  231. return rc;
  232. }
  233. static int msm_cvp_load_qdss_table(struct msm_cvp_platform_resources *res)
  234. {
  235. struct addr_set *qdss_addr_set;
  236. struct platform_device *pdev = res->pdev;
  237. int i;
  238. int rc = 0;
  239. if (!of_find_property(pdev->dev.of_node, "qcom,qdss-presets", NULL)) {
  240. /*
  241. * qcom,qdss-presets is an optional property. It likely won't be
  242. * present if we don't have any register settings to program
  243. */
  244. dprintk(CVP_CORE, "qcom,qdss-presets not found\n");
  245. return rc;
  246. }
  247. qdss_addr_set = &res->qdss_addr_set;
  248. qdss_addr_set->count = get_u32_array_num_elements(pdev->dev.of_node,
  249. "qcom,qdss-presets");
  250. qdss_addr_set->count /= sizeof(*qdss_addr_set->addr_tbl) / sizeof(u32);
  251. if (!qdss_addr_set->count) {
  252. dprintk(CVP_CORE, "no elements in qdss reg set\n");
  253. return rc;
  254. }
  255. qdss_addr_set->addr_tbl = devm_kzalloc(&pdev->dev,
  256. qdss_addr_set->count * sizeof(*qdss_addr_set->addr_tbl),
  257. GFP_KERNEL);
  258. if (!qdss_addr_set->addr_tbl) {
  259. dprintk(CVP_ERR, "%s Failed to alloc register table\n",
  260. __func__);
  261. rc = -ENOMEM;
  262. goto err_qdss_addr_tbl;
  263. }
  264. rc = of_property_read_u32_array(pdev->dev.of_node, "qcom,qdss-presets",
  265. (u32 *)qdss_addr_set->addr_tbl, qdss_addr_set->count * 2);
  266. if (rc) {
  267. dprintk(CVP_ERR, "Failed to read qdss address table\n");
  268. msm_cvp_free_qdss_addr_table(res);
  269. rc = -EINVAL;
  270. goto err_qdss_addr_tbl;
  271. }
  272. for (i = 0; i < qdss_addr_set->count; i++) {
  273. dprintk(CVP_CORE, "qdss addr = %x, value = %x\n",
  274. qdss_addr_set->addr_tbl[i].start,
  275. qdss_addr_set->addr_tbl[i].size);
  276. }
  277. err_qdss_addr_tbl:
  278. return rc;
  279. }
  280. static int msm_cvp_load_subcache_info(struct msm_cvp_platform_resources *res)
  281. {
  282. int rc = 0, num_subcaches = 0, c;
  283. struct platform_device *pdev = res->pdev;
  284. struct subcache_set *subcaches = &res->subcache_set;
  285. num_subcaches = of_property_count_strings(pdev->dev.of_node,
  286. "cache-slice-names");
  287. if (num_subcaches <= 0) {
  288. dprintk(CVP_CORE, "No subcaches found\n");
  289. goto err_load_subcache_table_fail;
  290. }
  291. subcaches->subcache_tbl = devm_kzalloc(&pdev->dev,
  292. sizeof(*subcaches->subcache_tbl) * num_subcaches, GFP_KERNEL);
  293. if (!subcaches->subcache_tbl) {
  294. dprintk(CVP_ERR,
  295. "Failed to allocate memory for subcache tbl\n");
  296. rc = -ENOMEM;
  297. goto err_load_subcache_table_fail;
  298. }
  299. subcaches->count = num_subcaches;
  300. dprintk(CVP_CORE, "Found %d subcaches\n", num_subcaches);
  301. for (c = 0; c < num_subcaches; ++c) {
  302. struct subcache_info *vsc = &res->subcache_set.subcache_tbl[c];
  303. of_property_read_string_index(pdev->dev.of_node,
  304. "cache-slice-names", c, &vsc->name);
  305. }
  306. res->sys_cache_present = true;
  307. return 0;
  308. err_load_subcache_table_fail:
  309. res->sys_cache_present = false;
  310. subcaches->count = 0;
  311. subcaches->subcache_tbl = NULL;
  312. return rc;
  313. }
  314. /**
  315. * msm_cvp_load_u32_table() - load dtsi table entries
  316. * @pdev: A pointer to the platform device.
  317. * @of_node: A pointer to the device node.
  318. * @table_name: A pointer to the dtsi table entry name.
  319. * @struct_size: The size of the structure which is nothing but
  320. * a single entry in the dtsi table.
  321. * @table: A pointer to the table pointer which needs to be
  322. * filled by the dtsi table entries.
  323. * @num_elements: Number of elements pointer which needs to be filled
  324. * with the number of elements in the table.
  325. *
  326. * This is a generic implementation to load single or multiple array
  327. * table from dtsi. The array elements should be of size equal to u32.
  328. *
  329. * Return: Return '0' for success else appropriate error value.
  330. */
  331. int msm_cvp_load_u32_table(struct platform_device *pdev,
  332. struct device_node *of_node, char *table_name, int struct_size,
  333. u32 **table, u32 *num_elements)
  334. {
  335. int rc = 0, num_elemts = 0;
  336. u32 *ptbl = NULL;
  337. if (!of_find_property(of_node, table_name, NULL)) {
  338. dprintk(CVP_CORE, "%s not found\n", table_name);
  339. return 0;
  340. }
  341. num_elemts = get_u32_array_num_elements(of_node, table_name);
  342. if (!num_elemts) {
  343. dprintk(CVP_ERR, "no elements in %s\n", table_name);
  344. return 0;
  345. }
  346. num_elemts /= struct_size / sizeof(u32);
  347. ptbl = devm_kzalloc(&pdev->dev, num_elemts * struct_size, GFP_KERNEL);
  348. if (!ptbl) {
  349. dprintk(CVP_ERR, "Failed to alloc table %s\n", table_name);
  350. return -ENOMEM;
  351. }
  352. if (of_property_read_u32_array(of_node, table_name, ptbl,
  353. num_elemts * struct_size / sizeof(u32))) {
  354. dprintk(CVP_ERR, "Failed to read %s\n", table_name);
  355. return -EINVAL;
  356. }
  357. *table = ptbl;
  358. if (num_elements)
  359. *num_elements = num_elemts;
  360. return rc;
  361. }
  362. EXPORT_SYMBOL(msm_cvp_load_u32_table);
  363. /* A comparator to compare loads (needed later on) */
  364. static int cmp(const void *a, const void *b)
  365. {
  366. return ((struct allowed_clock_rates_table *)a)->clock_rate -
  367. ((struct allowed_clock_rates_table *)b)->clock_rate;
  368. }
  369. static int msm_cvp_load_allowed_clocks_table(
  370. struct msm_cvp_platform_resources *res)
  371. {
  372. int rc = 0;
  373. struct platform_device *pdev = res->pdev;
  374. if (!of_find_property(pdev->dev.of_node,
  375. "qcom,allowed-clock-rates", NULL)) {
  376. dprintk(CVP_CORE, "qcom,allowed-clock-rates not found\n");
  377. return 0;
  378. }
  379. rc = msm_cvp_load_u32_table(pdev, pdev->dev.of_node,
  380. "qcom,allowed-clock-rates",
  381. sizeof(*res->allowed_clks_tbl),
  382. (u32 **)&res->allowed_clks_tbl,
  383. &res->allowed_clks_tbl_size);
  384. if (rc) {
  385. dprintk(CVP_ERR,
  386. "%s: failed to read allowed clocks table\n", __func__);
  387. return rc;
  388. }
  389. sort(res->allowed_clks_tbl, res->allowed_clks_tbl_size,
  390. sizeof(*res->allowed_clks_tbl), cmp, NULL);
  391. return 0;
  392. }
  393. static int msm_cvp_populate_mem_cdsp(struct device *dev,
  394. struct msm_cvp_platform_resources *res)
  395. {
  396. struct device_node *mem_node;
  397. int ret;
  398. mem_node = of_parse_phandle(dev->of_node, "memory-region", 0);
  399. if (mem_node) {
  400. ret = of_reserved_mem_device_init_by_idx(dev,
  401. dev->of_node, 0);
  402. of_node_put(dev->of_node);
  403. if (ret) {
  404. dprintk(CVP_ERR,
  405. "Failed to initialize reserved mem, ret %d\n",
  406. ret);
  407. return ret;
  408. }
  409. }
  410. res->mem_cdsp.dev = dev;
  411. return 0;
  412. }
  413. static int msm_cvp_populate_bus(struct device *dev,
  414. struct msm_cvp_platform_resources *res)
  415. {
  416. struct bus_set *buses = &res->bus_set;
  417. const char *temp_name = NULL;
  418. struct bus_info *bus = NULL, *temp_table;
  419. u32 range[2];
  420. int rc = 0;
  421. temp_table = krealloc(buses->bus_tbl, sizeof(*temp_table) *
  422. (buses->count + 1), GFP_KERNEL);
  423. if (!temp_table) {
  424. dprintk(CVP_ERR, "%s: Failed to allocate memory", __func__);
  425. rc = -ENOMEM;
  426. goto err_bus;
  427. }
  428. buses->bus_tbl = temp_table;
  429. bus = &buses->bus_tbl[buses->count];
  430. memset(bus, 0x0, sizeof(struct bus_info));
  431. rc = of_property_read_string(dev->of_node, "label", &temp_name);
  432. if (rc) {
  433. dprintk(CVP_ERR, "'label' not found in node\n");
  434. goto err_bus;
  435. }
  436. /* need a non-const version of name, hence copying it over */
  437. bus->name = devm_kstrdup(dev, temp_name, GFP_KERNEL);
  438. if (!bus->name) {
  439. rc = -ENOMEM;
  440. goto err_bus;
  441. }
  442. rc = of_property_read_u32(dev->of_node, "qcom,bus-master",
  443. &bus->master);
  444. if (rc) {
  445. dprintk(CVP_ERR, "'qcom,bus-master' not found in node\n");
  446. goto err_bus;
  447. }
  448. rc = of_property_read_u32(dev->of_node, "qcom,bus-slave", &bus->slave);
  449. if (rc) {
  450. dprintk(CVP_ERR, "'qcom,bus-slave' not found in node\n");
  451. goto err_bus;
  452. }
  453. rc = of_property_read_string(dev->of_node, "qcom,bus-governor",
  454. &bus->governor);
  455. if (rc) {
  456. rc = 0;
  457. dprintk(CVP_CORE,
  458. "'qcom,bus-governor' not found, default to performance governor\n");
  459. bus->governor = PERF_GOV;
  460. }
  461. if (!strcmp(bus->governor, PERF_GOV))
  462. bus->is_prfm_gov_used = true;
  463. rc = of_property_read_u32_array(dev->of_node, "qcom,bus-range-kbps",
  464. range, ARRAY_SIZE(range));
  465. if (rc) {
  466. rc = 0;
  467. dprintk(CVP_CORE,
  468. "'qcom,range' not found defaulting to <0 INT_MAX>\n");
  469. range[0] = 0;
  470. range[1] = INT_MAX;
  471. }
  472. bus->range[0] = range[0]; /* min */
  473. bus->range[1] = range[1]; /* max */
  474. buses->count++;
  475. bus->dev = dev;
  476. dprintk(CVP_CORE, "Found bus %s [%d->%d] with governor %s\n",
  477. bus->name, bus->master, bus->slave, bus->governor);
  478. err_bus:
  479. return rc;
  480. }
  481. static int msm_cvp_load_regulator_table(
  482. struct msm_cvp_platform_resources *res)
  483. {
  484. int rc = 0;
  485. struct platform_device *pdev = res->pdev;
  486. struct regulator_set *regulators = &res->regulator_set;
  487. struct device_node *domains_parent_node = NULL;
  488. struct property *domains_property = NULL;
  489. int reg_count = 0;
  490. regulators->count = 0;
  491. regulators->regulator_tbl = NULL;
  492. domains_parent_node = pdev->dev.of_node;
  493. for_each_property_of_node(domains_parent_node, domains_property) {
  494. const char *search_string = "-supply";
  495. char *supply;
  496. bool matched = false;
  497. /* check if current property is possibly a regulator */
  498. supply = strnstr(domains_property->name, search_string,
  499. strlen(domains_property->name) + 1);
  500. matched = supply && (*(supply + strlen(search_string)) == '\0');
  501. if (!matched)
  502. continue;
  503. reg_count++;
  504. }
  505. regulators->regulator_tbl = devm_kzalloc(&pdev->dev,
  506. sizeof(*regulators->regulator_tbl) *
  507. reg_count, GFP_KERNEL);
  508. if (!regulators->regulator_tbl) {
  509. rc = -ENOMEM;
  510. dprintk(CVP_ERR,
  511. "Failed to alloc memory for regulator table\n");
  512. goto err_reg_tbl_alloc;
  513. }
  514. for_each_property_of_node(domains_parent_node, domains_property) {
  515. const char *search_string = "-supply";
  516. char *supply;
  517. bool matched = false;
  518. struct device_node *regulator_node = NULL;
  519. struct regulator_info *rinfo = NULL;
  520. /* check if current property is possibly a regulator */
  521. supply = strnstr(domains_property->name, search_string,
  522. strlen(domains_property->name) + 1);
  523. matched = supply && (supply[strlen(search_string)] == '\0');
  524. if (!matched)
  525. continue;
  526. /* make sure prop isn't being misused */
  527. regulator_node = of_parse_phandle(domains_parent_node,
  528. domains_property->name, 0);
  529. if (IS_ERR(regulator_node)) {
  530. dprintk(CVP_WARN, "%s is not a phandle\n",
  531. domains_property->name);
  532. continue;
  533. }
  534. regulators->count++;
  535. /* populate regulator info */
  536. rinfo = &regulators->regulator_tbl[regulators->count - 1];
  537. rinfo->name = devm_kzalloc(&pdev->dev,
  538. (supply - domains_property->name) + 1, GFP_KERNEL);
  539. if (!rinfo->name) {
  540. rc = -ENOMEM;
  541. dprintk(CVP_ERR,
  542. "Failed to alloc memory for regulator name\n");
  543. goto err_reg_name_alloc;
  544. }
  545. strlcpy(rinfo->name, domains_property->name,
  546. (supply - domains_property->name) + 1);
  547. rinfo->has_hw_power_collapse = of_property_read_bool(
  548. regulator_node, "qcom,support-hw-trigger");
  549. dprintk(CVP_CORE, "Found regulator %s: h/w collapse = %s\n",
  550. rinfo->name,
  551. rinfo->has_hw_power_collapse ? "yes" : "no");
  552. }
  553. if (!regulators->count)
  554. dprintk(CVP_CORE, "No regulators found");
  555. return 0;
  556. err_reg_name_alloc:
  557. err_reg_tbl_alloc:
  558. msm_cvp_free_regulator_table(res);
  559. return rc;
  560. }
  561. static int msm_cvp_load_clock_table(
  562. struct msm_cvp_platform_resources *res)
  563. {
  564. int rc = 0, num_clocks = 0, c = 0;
  565. struct platform_device *pdev = res->pdev;
  566. int *clock_ids = NULL;
  567. int *clock_props = NULL;
  568. struct clock_set *clocks = &res->clock_set;
  569. num_clocks = of_property_count_strings(pdev->dev.of_node,
  570. "clock-names");
  571. if (num_clocks <= 0) {
  572. dprintk(CVP_CORE, "No clocks found\n");
  573. clocks->count = 0;
  574. rc = 0;
  575. goto err_load_clk_table_fail;
  576. }
  577. clock_ids = devm_kzalloc(&pdev->dev, num_clocks *
  578. sizeof(*clock_ids), GFP_KERNEL);
  579. if (!clock_ids) {
  580. dprintk(CVP_ERR, "No memory to read clock ids\n");
  581. rc = -ENOMEM;
  582. goto err_load_clk_table_fail;
  583. }
  584. rc = of_property_read_u32_array(pdev->dev.of_node,
  585. "clock-ids", clock_ids,
  586. num_clocks);
  587. if (rc) {
  588. dprintk(CVP_CORE, "Failed to read clock ids: %d\n", rc);
  589. msm_cvp_mmrm_enabled = false;
  590. dprintk(CVP_CORE, "flag msm_cvp_mmrm_enabled disabled\n");
  591. }
  592. clock_props = devm_kzalloc(&pdev->dev, num_clocks *
  593. sizeof(*clock_props), GFP_KERNEL);
  594. if (!clock_props) {
  595. dprintk(CVP_ERR, "No memory to read clock properties\n");
  596. rc = -ENOMEM;
  597. goto err_load_clk_table_fail;
  598. }
  599. rc = of_property_read_u32_array(pdev->dev.of_node,
  600. "qcom,clock-configs", clock_props,
  601. num_clocks);
  602. if (rc) {
  603. dprintk(CVP_ERR, "Failed to read clock properties: %d\n", rc);
  604. goto err_load_clk_prop_fail;
  605. }
  606. clocks->clock_tbl = devm_kzalloc(&pdev->dev, sizeof(*clocks->clock_tbl)
  607. * num_clocks, GFP_KERNEL);
  608. if (!clocks->clock_tbl) {
  609. dprintk(CVP_ERR, "Failed to allocate memory for clock tbl\n");
  610. rc = -ENOMEM;
  611. goto err_load_clk_prop_fail;
  612. }
  613. clocks->count = num_clocks;
  614. dprintk(CVP_CORE, "Found %d clocks\n", num_clocks);
  615. for (c = 0; c < num_clocks; ++c) {
  616. struct clock_info *vc = &res->clock_set.clock_tbl[c];
  617. of_property_read_string_index(pdev->dev.of_node,
  618. "clock-names", c, &vc->name);
  619. if (msm_cvp_mmrm_enabled == true)
  620. vc->clk_id = clock_ids[c];
  621. if (clock_props[c] & CLOCK_PROP_HAS_SCALING) {
  622. vc->has_scaling = true;
  623. } else {
  624. vc->count = 0;
  625. vc->has_scaling = false;
  626. }
  627. if (clock_props[c] & CLOCK_PROP_HAS_MEM_RETENTION)
  628. vc->has_mem_retention = true;
  629. else
  630. vc->has_mem_retention = false;
  631. dprintk(CVP_CORE, "Found clock %s id %d: scale-able = %s\n",
  632. vc->name, vc->clk_id, vc->count ? "yes" : "no");
  633. }
  634. return 0;
  635. err_load_clk_prop_fail:
  636. err_load_clk_table_fail:
  637. return rc;
  638. }
  639. #define MAX_CLK_RESETS 5
  640. static int msm_cvp_load_reset_table(
  641. struct msm_cvp_platform_resources *res)
  642. {
  643. struct platform_device *pdev = res->pdev;
  644. struct reset_set *rst = &res->reset_set;
  645. int num_clocks = 0, c = 0, ret = 0;
  646. int pwr_stats[MAX_CLK_RESETS];
  647. num_clocks = of_property_count_strings(pdev->dev.of_node,
  648. "reset-names");
  649. if (num_clocks <= 0 || num_clocks > MAX_CLK_RESETS) {
  650. dprintk(CVP_ERR, "Num reset clocks out of range\n");
  651. rst->count = 0;
  652. return 0;
  653. }
  654. rst->reset_tbl = devm_kcalloc(&pdev->dev, num_clocks,
  655. sizeof(*rst->reset_tbl), GFP_KERNEL);
  656. if (!rst->reset_tbl)
  657. return -ENOMEM;
  658. rst->count = num_clocks;
  659. dprintk(CVP_CORE, "Found %d reset clocks\n", num_clocks);
  660. ret = of_property_read_u32_array(pdev->dev.of_node,
  661. "reset-power-status", pwr_stats,
  662. num_clocks);
  663. if (ret) {
  664. dprintk(CVP_ERR, "Failed to read reset pwr state: %d\n", ret);
  665. devm_kfree(&pdev->dev, rst->reset_tbl);
  666. return ret;
  667. }
  668. for (c = 0; c < num_clocks; ++c) {
  669. struct reset_info *rc = &res->reset_set.reset_tbl[c];
  670. of_property_read_string_index(pdev->dev.of_node,
  671. "reset-names", c, &rc->name);
  672. rc->required_stage = pwr_stats[c];
  673. }
  674. return 0;
  675. }
  676. static int find_key_value(struct msm_cvp_platform_data *platform_data,
  677. const char *key)
  678. {
  679. int i = 0;
  680. struct msm_cvp_common_data *common_data = platform_data->common_data;
  681. int size = platform_data->common_data_length;
  682. for (i = 0; i < size; i++) {
  683. if (!strcmp(common_data[i].key, key))
  684. return common_data[i].value;
  685. }
  686. return 0;
  687. }
  688. int cvp_read_platform_resources_from_drv_data(
  689. struct msm_cvp_core *core)
  690. {
  691. struct msm_cvp_platform_data *platform_data;
  692. struct msm_cvp_platform_resources *res;
  693. int rc = 0, i;
  694. if (!core || !core->platform_data) {
  695. dprintk(CVP_ERR, "%s Invalid data\n", __func__);
  696. return -ENOENT;
  697. }
  698. platform_data = core->platform_data;
  699. res = &core->resources;
  700. res->sku_version = platform_data->sku_version;
  701. res->fw_name = "evass";
  702. dprintk(CVP_CORE, "Firmware filename: %s\n", res->fw_name);
  703. res->dsp_enabled = find_key_value(platform_data,
  704. "qcom,dsp-enabled");
  705. res->max_ssr_allowed = find_key_value(platform_data,
  706. "qcom,max-ssr-allowed");
  707. res->sw_power_collapsible = find_key_value(platform_data,
  708. "qcom,sw-power-collapse");
  709. res->debug_timeout = find_key_value(platform_data,
  710. "qcom,debug-timeout");
  711. res->pm_qos.latency_us = find_key_value(platform_data,
  712. "qcom,pm-qos-latency-us");
  713. res->pm_qos.silver_count = 0;
  714. for(i = 0; i < MAX_SILVER_CORE_NUM; i++) {
  715. if(topology_cluster_id(i) == 0)
  716. res->pm_qos.silver_count++;
  717. else
  718. break;
  719. }
  720. for (i = 0; i < res->pm_qos.silver_count; i++)
  721. res->pm_qos.silver_cores[i] = i;
  722. res->pm_qos.off_vote_cnt = 0;
  723. spin_lock_init(&res->pm_qos.lock);
  724. res->max_secure_inst_count = find_key_value(platform_data,
  725. "qcom,max-secure-instances");
  726. res->thermal_mitigable = find_key_value(platform_data,
  727. "qcom,enable-thermal-mitigation");
  728. res->msm_cvp_pwr_collapse_delay = find_key_value(platform_data,
  729. "qcom,power-collapse-delay");
  730. res->msm_cvp_hw_rsp_timeout = find_key_value(platform_data,
  731. "qcom,hw-resp-timeout");
  732. res->msm_cvp_dsp_rsp_timeout = find_key_value(platform_data,
  733. "qcom,dsp-resp-timeout");
  734. res->non_fatal_pagefaults = find_key_value(platform_data,
  735. "qcom,domain-attr-non-fatal-faults");
  736. res->vpu_ver = platform_data->vpu_ver;
  737. res->ubwc_config = platform_data->ubwc_config;
  738. res->fatal_ssr = false;
  739. return rc;
  740. }
  741. int cvp_read_platform_resources_from_dt(
  742. struct msm_cvp_platform_resources *res)
  743. {
  744. struct platform_device *pdev = res->pdev;
  745. struct resource *kres = NULL;
  746. int rc = 0;
  747. uint32_t firmware_base = 0;
  748. if (!pdev->dev.of_node) {
  749. dprintk(CVP_ERR, "DT node not found\n");
  750. return -ENOENT;
  751. }
  752. INIT_LIST_HEAD(&res->context_banks);
  753. res->firmware_base = (phys_addr_t)firmware_base;
  754. kres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  755. res->register_base = kres ? kres->start : -1;
  756. res->register_size = kres ? (kres->end + 1 - kres->start) : -1;
  757. res->irq = platform_get_irq(pdev, 0);
  758. dprintk(CVP_CORE, "%s: res->irq:%d \n",
  759. __func__, res->irq);
  760. //Parsing for WD interrupt
  761. res->irq_wd = platform_get_irq(pdev, 1);
  762. dprintk(CVP_CORE, "%s: res->irq_wd:%d \n",
  763. __func__, res->irq_wd);
  764. rc = msm_cvp_load_subcache_info(res);
  765. if (rc)
  766. dprintk(CVP_WARN, "Failed to load subcache info: %d\n", rc);
  767. rc = msm_cvp_load_qdss_table(res);
  768. if (rc)
  769. dprintk(CVP_WARN, "Failed to load qdss reg table: %d\n", rc);
  770. rc = msm_cvp_load_reg_table(res);
  771. if (rc) {
  772. dprintk(CVP_ERR, "Failed to load reg table: %d\n", rc);
  773. goto err_load_reg_table;
  774. }
  775. rc = msm_cvp_load_ipcc_regs(res);
  776. if (rc)
  777. dprintk(CVP_ERR, "Failed to load IPCC regs: %d\n", rc);
  778. rc = msm_cvp_load_regspace_mapping(res);
  779. if (rc)
  780. dprintk(CVP_ERR, "Failed to load reg space mapping: %d\n", rc);
  781. rc = msm_cvp_load_gcc_regs(res);
  782. rc = msm_cvp_load_regulator_table(res);
  783. if (rc) {
  784. dprintk(CVP_ERR, "Failed to load list of regulators %d\n", rc);
  785. goto err_load_regulator_table;
  786. }
  787. rc = msm_cvp_load_clock_table(res);
  788. if (rc) {
  789. dprintk(CVP_ERR,
  790. "Failed to load clock table: %d\n", rc);
  791. goto err_load_clock_table;
  792. }
  793. rc = msm_cvp_load_allowed_clocks_table(res);
  794. if (rc) {
  795. dprintk(CVP_ERR,
  796. "Failed to load allowed clocks table: %d\n", rc);
  797. goto err_load_allowed_clocks_table;
  798. }
  799. rc = msm_cvp_load_reset_table(res);
  800. if (rc) {
  801. dprintk(CVP_ERR,
  802. "Failed to load reset table: %d\n", rc);
  803. goto err_load_reset_table;
  804. }
  805. res->use_non_secure_pil = of_property_read_bool(pdev->dev.of_node,
  806. "qcom,use-non-secure-pil");
  807. if (res->use_non_secure_pil || !is_iommu_present(res)) {
  808. of_property_read_u32(pdev->dev.of_node, "qcom,fw-bias",
  809. &firmware_base);
  810. res->firmware_base = (phys_addr_t)firmware_base;
  811. dprintk(CVP_CORE,
  812. "Using fw-bias : %pa", &res->firmware_base);
  813. }
  814. return rc;
  815. err_load_reset_table:
  816. msm_cvp_free_allowed_clocks_table(res);
  817. err_load_allowed_clocks_table:
  818. msm_cvp_free_clock_table(res);
  819. err_load_clock_table:
  820. msm_cvp_free_regulator_table(res);
  821. err_load_regulator_table:
  822. msm_cvp_free_reg_table(res);
  823. err_load_reg_table:
  824. return rc;
  825. }
  826. static int msm_cvp_setup_context_bank(struct msm_cvp_platform_resources *res,
  827. struct context_bank_info *cb, struct device *dev)
  828. {
  829. int rc = 0;
  830. struct bus_type *bus;
  831. if (!dev || !cb || !res) {
  832. dprintk(CVP_ERR,
  833. "%s: Invalid Input params\n", __func__);
  834. return -EINVAL;
  835. }
  836. cb->dev = dev;
  837. bus = cb->dev->bus;
  838. if (IS_ERR_OR_NULL(bus)) {
  839. dprintk(CVP_ERR, "%s - failed to get bus type\n", __func__);
  840. rc = PTR_ERR(bus) ?: -ENODEV;
  841. goto remove_cb;
  842. }
  843. /*
  844. * configure device segment size and segment boundary to ensure
  845. * iommu mapping returns one mapping (which is required for partial
  846. * cache operations)
  847. */
  848. if (!dev->dma_parms)
  849. dev->dma_parms =
  850. devm_kzalloc(dev, sizeof(*dev->dma_parms), GFP_KERNEL);
  851. dma_set_max_seg_size(dev, DMA_BIT_MASK(32));
  852. dma_set_seg_boundary(dev, DMA_BIT_MASK(64));
  853. dprintk(CVP_CORE, "Attached %s and created mapping\n", dev_name(dev));
  854. dprintk(CVP_CORE,
  855. "Context bank name:%s, buffer_type: %#x, is_secure: %d, address range start: %#x, size: %#x, dev: %pK",
  856. cb->name, cb->buffer_type, cb->is_secure, cb->addr_range.start,
  857. cb->addr_range.size, cb->dev);
  858. return rc;
  859. remove_cb:
  860. return rc;
  861. }
  862. int msm_cvp_smmu_fault_handler(struct iommu_domain *domain,
  863. struct device *dev, unsigned long iova, int flags, void *token)
  864. {
  865. struct msm_cvp_core *core = token;
  866. struct iris_hfi_device *hdev;
  867. struct msm_cvp_inst *inst;
  868. bool log = false;
  869. if (!domain || !core) {
  870. dprintk(CVP_ERR, "%s - invalid param %pK %pK\n",
  871. __func__, domain, core);
  872. return -EINVAL;
  873. }
  874. dprintk(CVP_ERR, "%s - faulting address: %lx fault cnt %d\n",
  875. __func__, iova, core->smmu_fault_count);
  876. if (core->smmu_fault_count > 0) {
  877. core->smmu_fault_count++;
  878. return -ENOSYS;
  879. }
  880. mutex_lock(&core->lock);
  881. core->smmu_fault_count++;
  882. if (!core->last_fault_addr)
  883. core->last_fault_addr = iova;
  884. log = (core->log.snapshot_index > 0)? false : true;
  885. list_for_each_entry(inst, &core->instances, list) {
  886. cvp_print_inst(CVP_ERR, inst);
  887. msm_cvp_print_inst_bufs(inst, log);
  888. }
  889. hdev = core->dev_ops->hfi_device_data;
  890. if (hdev) {
  891. hdev->error = CVP_ERR_NOC_ERROR;
  892. call_hfi_op(core->dev_ops, debug_hook, hdev);
  893. }
  894. mutex_unlock(&core->lock);
  895. /*
  896. * Return -EINVAL to elicit the default behaviour of smmu driver.
  897. * If we return -ENOSYS, then smmu driver assumes page fault handler
  898. * is not installed and prints a list of useful debug information like
  899. * FAR, SID etc. This information is not printed if we return 0.
  900. */
  901. return -ENOSYS;
  902. }
  903. static int msm_cvp_populate_context_bank(struct device *dev,
  904. struct msm_cvp_core *core)
  905. {
  906. int rc = 0;
  907. struct context_bank_info *cb = NULL;
  908. struct device_node *np = NULL;
  909. if (!dev || !core) {
  910. dprintk(CVP_ERR, "%s - invalid inputs\n", __func__);
  911. return -EINVAL;
  912. }
  913. np = dev->of_node;
  914. cb = devm_kzalloc(dev, sizeof(*cb), GFP_KERNEL);
  915. if (!cb) {
  916. dprintk(CVP_ERR, "%s - Failed to allocate cb\n", __func__);
  917. return -ENOMEM;
  918. }
  919. INIT_LIST_HEAD(&cb->list);
  920. list_add_tail(&cb->list, &core->resources.context_banks);
  921. rc = of_property_read_string(np, "label", &cb->name);
  922. if (rc) {
  923. dprintk(CVP_CORE,
  924. "Failed to read cb label from device tree\n");
  925. rc = 0;
  926. }
  927. dprintk(CVP_CORE, "%s: context bank has name %s\n", __func__, cb->name);
  928. if (!strcmp(cb->name, "cvp_camera")) {
  929. cb->is_secure = true;
  930. rc = msm_cvp_setup_context_bank(&core->resources, cb, dev);
  931. if (rc) {
  932. dprintk(CVP_ERR, "Cannot setup context bank %s %d\n",
  933. cb->name, rc);
  934. goto err_setup_cb;
  935. }
  936. return 0;
  937. }
  938. rc = of_property_read_u32_array(np, "qcom,iommu-dma-addr-pool",
  939. (u32 *)&cb->addr_range, 2);
  940. if (rc) {
  941. dprintk(CVP_ERR,
  942. "Could not read addr pool for context bank : %s %d\n",
  943. cb->name, rc);
  944. goto err_setup_cb;
  945. }
  946. cb->is_secure = of_property_read_bool(np, "qcom,iommu-vmid");
  947. dprintk(CVP_CORE, "context bank %s : secure = %d\n",
  948. cb->name, cb->is_secure);
  949. /* setup buffer type for each sub device*/
  950. rc = of_property_read_u32(np, "buffer-types", &cb->buffer_type);
  951. if (rc) {
  952. dprintk(CVP_ERR, "failed to load buffer_type info %d\n", rc);
  953. rc = -ENOENT;
  954. goto err_setup_cb;
  955. }
  956. dprintk(CVP_CORE,
  957. "context bank %s address start = %x address size = %x buffer_type = %x\n",
  958. cb->name, cb->addr_range.start,
  959. cb->addr_range.size, cb->buffer_type);
  960. cb->domain = iommu_get_domain_for_dev(dev);
  961. if (IS_ERR_OR_NULL(cb->domain)) {
  962. dprintk(CVP_ERR, "Create domain failed\n");
  963. rc = -ENODEV;
  964. goto err_setup_cb;
  965. }
  966. rc = msm_cvp_setup_context_bank(&core->resources, cb, dev);
  967. if (rc) {
  968. dprintk(CVP_ERR, "Cannot setup context bank %d\n", rc);
  969. goto err_setup_cb;
  970. }
  971. iommu_set_fault_handler(cb->domain,
  972. msm_cvp_smmu_fault_handler, (void *)core);
  973. return 0;
  974. err_setup_cb:
  975. list_del(&cb->list);
  976. return rc;
  977. }
  978. int cvp_read_context_bank_resources_from_dt(struct platform_device *pdev)
  979. {
  980. struct msm_cvp_core *core;
  981. int rc = 0;
  982. if (!pdev) {
  983. dprintk(CVP_ERR, "Invalid platform device\n");
  984. return -EINVAL;
  985. } else if (!pdev->dev.parent) {
  986. dprintk(CVP_ERR, "Failed to find a parent for %s\n",
  987. dev_name(&pdev->dev));
  988. return -ENODEV;
  989. }
  990. core = dev_get_drvdata(pdev->dev.parent);
  991. if (!core) {
  992. dprintk(CVP_ERR, "Failed to find cookie in parent device %s",
  993. dev_name(pdev->dev.parent));
  994. return -EINVAL;
  995. }
  996. rc = msm_cvp_populate_context_bank(&pdev->dev, core);
  997. if (rc)
  998. dprintk(CVP_ERR, "Failed to probe context bank\n");
  999. else
  1000. dprintk(CVP_CORE, "Successfully probed context bank\n");
  1001. return rc;
  1002. }
  1003. int cvp_read_bus_resources_from_dt(struct platform_device *pdev)
  1004. {
  1005. struct msm_cvp_core *core;
  1006. if (!pdev) {
  1007. dprintk(CVP_ERR, "Invalid platform device\n");
  1008. return -EINVAL;
  1009. } else if (!pdev->dev.parent) {
  1010. dprintk(CVP_ERR, "Failed to find a parent for %s\n",
  1011. dev_name(&pdev->dev));
  1012. return -ENODEV;
  1013. }
  1014. core = dev_get_drvdata(pdev->dev.parent);
  1015. if (!core) {
  1016. dprintk(CVP_ERR, "Failed to find cookie in parent device %s",
  1017. dev_name(pdev->dev.parent));
  1018. return -EINVAL;
  1019. }
  1020. return msm_cvp_populate_bus(&pdev->dev, &core->resources);
  1021. }
  1022. int cvp_read_mem_cdsp_resources_from_dt(struct platform_device *pdev)
  1023. {
  1024. struct msm_cvp_core *core;
  1025. if (!pdev) {
  1026. dprintk(CVP_ERR, "%s: invalid platform device\n", __func__);
  1027. return -EINVAL;
  1028. } else if (!pdev->dev.parent) {
  1029. dprintk(CVP_ERR, "Failed to find a parent for %s\n",
  1030. dev_name(&pdev->dev));
  1031. return -ENODEV;
  1032. }
  1033. core = dev_get_drvdata(pdev->dev.parent);
  1034. if (!core) {
  1035. dprintk(CVP_ERR, "Failed to find cookie in parent device %s",
  1036. dev_name(pdev->dev.parent));
  1037. return -EINVAL;
  1038. }
  1039. return msm_cvp_populate_mem_cdsp(&pdev->dev, &core->resources);
  1040. }