msm_cvp_res_parse.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  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. rc = of_property_read_string(np, "label", &cb->name);
  920. if (rc) {
  921. dprintk(CVP_CORE,
  922. "Failed to read cb label from device tree\n");
  923. rc = 0;
  924. }
  925. INIT_LIST_HEAD(&cb->list);
  926. list_add_tail(&cb->list, &core->resources.context_banks);
  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_CORE,
  942. "Could not read addr pool for context bank : %s %d\n",
  943. cb->name, rc);
  944. }
  945. cb->is_secure = of_property_read_bool(np, "qcom,iommu-vmid");
  946. dprintk(CVP_CORE, "context bank %s : secure = %d\n",
  947. cb->name, cb->is_secure);
  948. /* setup buffer type for each sub device*/
  949. rc = of_property_read_u32(np, "buffer-types", &cb->buffer_type);
  950. if (rc) {
  951. dprintk(CVP_ERR, "failed to load buffer_type info %d\n", rc);
  952. rc = -ENOENT;
  953. goto err_setup_cb;
  954. }
  955. dprintk(CVP_CORE,
  956. "context bank %s address start = %x address size = %x buffer_type = %x\n",
  957. cb->name, cb->addr_range.start,
  958. cb->addr_range.size, cb->buffer_type);
  959. cb->domain = iommu_get_domain_for_dev(dev);
  960. if (IS_ERR_OR_NULL(cb->domain)) {
  961. dprintk(CVP_ERR, "Create domain failed\n");
  962. rc = -ENODEV;
  963. goto err_setup_cb;
  964. }
  965. rc = msm_cvp_setup_context_bank(&core->resources, cb, dev);
  966. if (rc) {
  967. dprintk(CVP_ERR, "Cannot setup context bank %d\n", rc);
  968. goto err_setup_cb;
  969. }
  970. iommu_set_fault_handler(cb->domain,
  971. msm_cvp_smmu_fault_handler, (void *)core);
  972. return 0;
  973. err_setup_cb:
  974. list_del(&cb->list);
  975. return rc;
  976. }
  977. int cvp_read_context_bank_resources_from_dt(struct platform_device *pdev)
  978. {
  979. struct msm_cvp_core *core;
  980. int rc = 0;
  981. if (!pdev) {
  982. dprintk(CVP_ERR, "Invalid platform device\n");
  983. return -EINVAL;
  984. } else if (!pdev->dev.parent) {
  985. dprintk(CVP_ERR, "Failed to find a parent for %s\n",
  986. dev_name(&pdev->dev));
  987. return -ENODEV;
  988. }
  989. core = dev_get_drvdata(pdev->dev.parent);
  990. if (!core) {
  991. dprintk(CVP_ERR, "Failed to find cookie in parent device %s",
  992. dev_name(pdev->dev.parent));
  993. return -EINVAL;
  994. }
  995. rc = msm_cvp_populate_context_bank(&pdev->dev, core);
  996. if (rc)
  997. dprintk(CVP_ERR, "Failed to probe context bank\n");
  998. else
  999. dprintk(CVP_CORE, "Successfully probed context bank\n");
  1000. return rc;
  1001. }
  1002. int cvp_read_bus_resources_from_dt(struct platform_device *pdev)
  1003. {
  1004. struct msm_cvp_core *core;
  1005. if (!pdev) {
  1006. dprintk(CVP_ERR, "Invalid platform device\n");
  1007. return -EINVAL;
  1008. } else if (!pdev->dev.parent) {
  1009. dprintk(CVP_ERR, "Failed to find a parent for %s\n",
  1010. dev_name(&pdev->dev));
  1011. return -ENODEV;
  1012. }
  1013. core = dev_get_drvdata(pdev->dev.parent);
  1014. if (!core) {
  1015. dprintk(CVP_ERR, "Failed to find cookie in parent device %s",
  1016. dev_name(pdev->dev.parent));
  1017. return -EINVAL;
  1018. }
  1019. return msm_cvp_populate_bus(&pdev->dev, &core->resources);
  1020. }
  1021. int cvp_read_mem_cdsp_resources_from_dt(struct platform_device *pdev)
  1022. {
  1023. struct msm_cvp_core *core;
  1024. if (!pdev) {
  1025. dprintk(CVP_ERR, "%s: invalid platform device\n", __func__);
  1026. return -EINVAL;
  1027. } else if (!pdev->dev.parent) {
  1028. dprintk(CVP_ERR, "Failed to find a parent for %s\n",
  1029. dev_name(&pdev->dev));
  1030. return -ENODEV;
  1031. }
  1032. core = dev_get_drvdata(pdev->dev.parent);
  1033. if (!core) {
  1034. dprintk(CVP_ERR, "Failed to find cookie in parent device %s",
  1035. dev_name(pdev->dev.parent));
  1036. return -EINVAL;
  1037. }
  1038. return msm_cvp_populate_mem_cdsp(&pdev->dev, &core->resources);
  1039. }