msm_cvp_res_parse.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  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_fw_name(struct msm_cvp_platform_resources *res)
  281. {
  282. struct platform_device *pdev = res->pdev;
  283. return of_property_read_string_index(pdev->dev.of_node,
  284. "cvp,firmware-name", 0, &res->fw_name);
  285. }
  286. static int msm_cvp_load_subcache_info(struct msm_cvp_platform_resources *res)
  287. {
  288. int rc = 0, num_subcaches = 0, c;
  289. struct platform_device *pdev = res->pdev;
  290. struct subcache_set *subcaches = &res->subcache_set;
  291. num_subcaches = of_property_count_strings(pdev->dev.of_node,
  292. "cache-slice-names");
  293. if (num_subcaches <= 0) {
  294. dprintk(CVP_CORE, "No subcaches found\n");
  295. goto err_load_subcache_table_fail;
  296. }
  297. subcaches->subcache_tbl = devm_kzalloc(&pdev->dev,
  298. sizeof(*subcaches->subcache_tbl) * num_subcaches, GFP_KERNEL);
  299. if (!subcaches->subcache_tbl) {
  300. dprintk(CVP_ERR,
  301. "Failed to allocate memory for subcache tbl\n");
  302. rc = -ENOMEM;
  303. goto err_load_subcache_table_fail;
  304. }
  305. subcaches->count = num_subcaches;
  306. dprintk(CVP_CORE, "Found %d subcaches\n", num_subcaches);
  307. for (c = 0; c < num_subcaches; ++c) {
  308. struct subcache_info *vsc = &res->subcache_set.subcache_tbl[c];
  309. of_property_read_string_index(pdev->dev.of_node,
  310. "cache-slice-names", c, &vsc->name);
  311. }
  312. res->sys_cache_present = true;
  313. return 0;
  314. err_load_subcache_table_fail:
  315. res->sys_cache_present = false;
  316. subcaches->count = 0;
  317. subcaches->subcache_tbl = NULL;
  318. return rc;
  319. }
  320. /**
  321. * msm_cvp_load_u32_table() - load dtsi table entries
  322. * @pdev: A pointer to the platform device.
  323. * @of_node: A pointer to the device node.
  324. * @table_name: A pointer to the dtsi table entry name.
  325. * @struct_size: The size of the structure which is nothing but
  326. * a single entry in the dtsi table.
  327. * @table: A pointer to the table pointer which needs to be
  328. * filled by the dtsi table entries.
  329. * @num_elements: Number of elements pointer which needs to be filled
  330. * with the number of elements in the table.
  331. *
  332. * This is a generic implementation to load single or multiple array
  333. * table from dtsi. The array elements should be of size equal to u32.
  334. *
  335. * Return: Return '0' for success else appropriate error value.
  336. */
  337. int msm_cvp_load_u32_table(struct platform_device *pdev,
  338. struct device_node *of_node, char *table_name, int struct_size,
  339. u32 **table, u32 *num_elements)
  340. {
  341. int rc = 0, num_elemts = 0;
  342. u32 *ptbl = NULL;
  343. if (!of_find_property(of_node, table_name, NULL)) {
  344. dprintk(CVP_CORE, "%s not found\n", table_name);
  345. return 0;
  346. }
  347. num_elemts = get_u32_array_num_elements(of_node, table_name);
  348. if (!num_elemts) {
  349. dprintk(CVP_ERR, "no elements in %s\n", table_name);
  350. return 0;
  351. }
  352. num_elemts /= struct_size / sizeof(u32);
  353. ptbl = devm_kzalloc(&pdev->dev, num_elemts * struct_size, GFP_KERNEL);
  354. if (!ptbl) {
  355. dprintk(CVP_ERR, "Failed to alloc table %s\n", table_name);
  356. return -ENOMEM;
  357. }
  358. if (of_property_read_u32_array(of_node, table_name, ptbl,
  359. num_elemts * struct_size / sizeof(u32))) {
  360. dprintk(CVP_ERR, "Failed to read %s\n", table_name);
  361. return -EINVAL;
  362. }
  363. *table = ptbl;
  364. if (num_elements)
  365. *num_elements = num_elemts;
  366. return rc;
  367. }
  368. EXPORT_SYMBOL(msm_cvp_load_u32_table);
  369. /* A comparator to compare loads (needed later on) */
  370. static int cmp(const void *a, const void *b)
  371. {
  372. return ((struct allowed_clock_rates_table *)a)->clock_rate -
  373. ((struct allowed_clock_rates_table *)b)->clock_rate;
  374. }
  375. static int msm_cvp_load_allowed_clocks_table(
  376. struct msm_cvp_platform_resources *res)
  377. {
  378. int rc = 0;
  379. struct platform_device *pdev = res->pdev;
  380. if (!of_find_property(pdev->dev.of_node,
  381. "qcom,allowed-clock-rates", NULL)) {
  382. dprintk(CVP_CORE, "qcom,allowed-clock-rates not found\n");
  383. return 0;
  384. }
  385. rc = msm_cvp_load_u32_table(pdev, pdev->dev.of_node,
  386. "qcom,allowed-clock-rates",
  387. sizeof(*res->allowed_clks_tbl),
  388. (u32 **)&res->allowed_clks_tbl,
  389. &res->allowed_clks_tbl_size);
  390. if (rc) {
  391. dprintk(CVP_ERR,
  392. "%s: failed to read allowed clocks table\n", __func__);
  393. return rc;
  394. }
  395. sort(res->allowed_clks_tbl, res->allowed_clks_tbl_size,
  396. sizeof(*res->allowed_clks_tbl), cmp, NULL);
  397. return 0;
  398. }
  399. static int msm_cvp_populate_mem_cdsp(struct device *dev,
  400. struct msm_cvp_platform_resources *res)
  401. {
  402. struct device_node *mem_node;
  403. int ret;
  404. mem_node = of_parse_phandle(dev->of_node, "memory-region", 0);
  405. if (mem_node) {
  406. ret = of_reserved_mem_device_init_by_idx(dev,
  407. dev->of_node, 0);
  408. of_node_put(dev->of_node);
  409. if (ret) {
  410. dprintk(CVP_ERR,
  411. "Failed to initialize reserved mem, ret %d\n",
  412. ret);
  413. return ret;
  414. }
  415. }
  416. res->mem_cdsp.dev = dev;
  417. return 0;
  418. }
  419. static int msm_cvp_populate_bus(struct device *dev,
  420. struct msm_cvp_platform_resources *res)
  421. {
  422. struct bus_set *buses = &res->bus_set;
  423. const char *temp_name = NULL;
  424. struct bus_info *bus = NULL, *temp_table;
  425. u32 range[2];
  426. int rc = 0;
  427. temp_table = krealloc(buses->bus_tbl, sizeof(*temp_table) *
  428. (buses->count + 1), GFP_KERNEL);
  429. if (!temp_table) {
  430. dprintk(CVP_ERR, "%s: Failed to allocate memory", __func__);
  431. rc = -ENOMEM;
  432. goto err_bus;
  433. }
  434. buses->bus_tbl = temp_table;
  435. bus = &buses->bus_tbl[buses->count];
  436. memset(bus, 0x0, sizeof(struct bus_info));
  437. rc = of_property_read_string(dev->of_node, "label", &temp_name);
  438. if (rc) {
  439. dprintk(CVP_ERR, "'label' not found in node\n");
  440. goto err_bus;
  441. }
  442. /* need a non-const version of name, hence copying it over */
  443. bus->name = devm_kstrdup(dev, temp_name, GFP_KERNEL);
  444. if (!bus->name) {
  445. rc = -ENOMEM;
  446. goto err_bus;
  447. }
  448. rc = of_property_read_u32(dev->of_node, "qcom,bus-master",
  449. &bus->master);
  450. if (rc) {
  451. dprintk(CVP_ERR, "'qcom,bus-master' not found in node\n");
  452. goto err_bus;
  453. }
  454. rc = of_property_read_u32(dev->of_node, "qcom,bus-slave", &bus->slave);
  455. if (rc) {
  456. dprintk(CVP_ERR, "'qcom,bus-slave' not found in node\n");
  457. goto err_bus;
  458. }
  459. rc = of_property_read_string(dev->of_node, "qcom,bus-governor",
  460. &bus->governor);
  461. if (rc) {
  462. rc = 0;
  463. dprintk(CVP_CORE,
  464. "'qcom,bus-governor' not found, default to performance governor\n");
  465. bus->governor = PERF_GOV;
  466. }
  467. if (!strcmp(bus->governor, PERF_GOV))
  468. bus->is_prfm_gov_used = true;
  469. rc = of_property_read_u32_array(dev->of_node, "qcom,bus-range-kbps",
  470. range, ARRAY_SIZE(range));
  471. if (rc) {
  472. rc = 0;
  473. dprintk(CVP_CORE,
  474. "'qcom,range' not found defaulting to <0 INT_MAX>\n");
  475. range[0] = 0;
  476. range[1] = INT_MAX;
  477. }
  478. bus->range[0] = range[0]; /* min */
  479. bus->range[1] = range[1]; /* max */
  480. buses->count++;
  481. bus->dev = dev;
  482. dprintk(CVP_CORE, "Found bus %s [%d->%d] with governor %s\n",
  483. bus->name, bus->master, bus->slave, bus->governor);
  484. err_bus:
  485. return rc;
  486. }
  487. static int msm_cvp_load_regulator_table(
  488. struct msm_cvp_platform_resources *res)
  489. {
  490. int rc = 0;
  491. struct platform_device *pdev = res->pdev;
  492. struct regulator_set *regulators = &res->regulator_set;
  493. struct device_node *domains_parent_node = NULL;
  494. struct property *domains_property = NULL;
  495. int reg_count = 0;
  496. regulators->count = 0;
  497. regulators->regulator_tbl = NULL;
  498. domains_parent_node = pdev->dev.of_node;
  499. for_each_property_of_node(domains_parent_node, domains_property) {
  500. const char *search_string = "-supply";
  501. char *supply;
  502. bool matched = false;
  503. /* check if current property is possibly a regulator */
  504. supply = strnstr(domains_property->name, search_string,
  505. strlen(domains_property->name) + 1);
  506. matched = supply && (*(supply + strlen(search_string)) == '\0');
  507. if (!matched)
  508. continue;
  509. reg_count++;
  510. }
  511. regulators->regulator_tbl = devm_kzalloc(&pdev->dev,
  512. sizeof(*regulators->regulator_tbl) *
  513. reg_count, GFP_KERNEL);
  514. if (!regulators->regulator_tbl) {
  515. rc = -ENOMEM;
  516. dprintk(CVP_ERR,
  517. "Failed to alloc memory for regulator table\n");
  518. goto err_reg_tbl_alloc;
  519. }
  520. for_each_property_of_node(domains_parent_node, domains_property) {
  521. const char *search_string = "-supply";
  522. char *supply;
  523. bool matched = false;
  524. struct device_node *regulator_node = NULL;
  525. struct regulator_info *rinfo = NULL;
  526. /* check if current property is possibly a regulator */
  527. supply = strnstr(domains_property->name, search_string,
  528. strlen(domains_property->name) + 1);
  529. matched = supply && (supply[strlen(search_string)] == '\0');
  530. if (!matched)
  531. continue;
  532. /* make sure prop isn't being misused */
  533. regulator_node = of_parse_phandle(domains_parent_node,
  534. domains_property->name, 0);
  535. if (IS_ERR(regulator_node)) {
  536. dprintk(CVP_WARN, "%s is not a phandle\n",
  537. domains_property->name);
  538. continue;
  539. }
  540. regulators->count++;
  541. /* populate regulator info */
  542. rinfo = &regulators->regulator_tbl[regulators->count - 1];
  543. rinfo->name = devm_kzalloc(&pdev->dev,
  544. (supply - domains_property->name) + 1, GFP_KERNEL);
  545. if (!rinfo->name) {
  546. rc = -ENOMEM;
  547. dprintk(CVP_ERR,
  548. "Failed to alloc memory for regulator name\n");
  549. goto err_reg_name_alloc;
  550. }
  551. strlcpy(rinfo->name, domains_property->name,
  552. (supply - domains_property->name) + 1);
  553. rinfo->has_hw_power_collapse = of_property_read_bool(
  554. regulator_node, "qcom,support-hw-trigger");
  555. dprintk(CVP_CORE, "Found regulator %s: h/w collapse = %s\n",
  556. rinfo->name,
  557. rinfo->has_hw_power_collapse ? "yes" : "no");
  558. }
  559. if (!regulators->count)
  560. dprintk(CVP_CORE, "No regulators found");
  561. return 0;
  562. err_reg_name_alloc:
  563. err_reg_tbl_alloc:
  564. msm_cvp_free_regulator_table(res);
  565. return rc;
  566. }
  567. static int msm_cvp_load_clock_table(
  568. struct msm_cvp_platform_resources *res)
  569. {
  570. int rc = 0, num_clocks = 0, c = 0;
  571. struct platform_device *pdev = res->pdev;
  572. int *clock_ids = NULL;
  573. int *clock_props = NULL;
  574. struct clock_set *clocks = &res->clock_set;
  575. num_clocks = of_property_count_strings(pdev->dev.of_node,
  576. "clock-names");
  577. if (num_clocks <= 0) {
  578. dprintk(CVP_CORE, "No clocks found\n");
  579. clocks->count = 0;
  580. rc = 0;
  581. goto err_load_clk_table_fail;
  582. }
  583. clock_ids = devm_kzalloc(&pdev->dev, num_clocks *
  584. sizeof(*clock_ids), GFP_KERNEL);
  585. if (!clock_ids) {
  586. dprintk(CVP_ERR, "No memory to read clock ids\n");
  587. rc = -ENOMEM;
  588. goto err_load_clk_table_fail;
  589. }
  590. rc = of_property_read_u32_array(pdev->dev.of_node,
  591. "clock-ids", clock_ids,
  592. num_clocks);
  593. if (rc) {
  594. dprintk(CVP_CORE, "Failed to read clock ids: %d\n", rc);
  595. msm_cvp_mmrm_enabled = false;
  596. dprintk(CVP_CORE, "flag msm_cvp_mmrm_enabled disabled\n");
  597. }
  598. clock_props = devm_kzalloc(&pdev->dev, num_clocks *
  599. sizeof(*clock_props), GFP_KERNEL);
  600. if (!clock_props) {
  601. dprintk(CVP_ERR, "No memory to read clock properties\n");
  602. rc = -ENOMEM;
  603. goto err_load_clk_table_fail;
  604. }
  605. rc = of_property_read_u32_array(pdev->dev.of_node,
  606. "qcom,clock-configs", clock_props,
  607. num_clocks);
  608. if (rc) {
  609. dprintk(CVP_ERR, "Failed to read clock properties: %d\n", rc);
  610. goto err_load_clk_prop_fail;
  611. }
  612. clocks->clock_tbl = devm_kzalloc(&pdev->dev, sizeof(*clocks->clock_tbl)
  613. * num_clocks, GFP_KERNEL);
  614. if (!clocks->clock_tbl) {
  615. dprintk(CVP_ERR, "Failed to allocate memory for clock tbl\n");
  616. rc = -ENOMEM;
  617. goto err_load_clk_prop_fail;
  618. }
  619. clocks->count = num_clocks;
  620. dprintk(CVP_CORE, "Found %d clocks\n", num_clocks);
  621. for (c = 0; c < num_clocks; ++c) {
  622. struct clock_info *vc = &res->clock_set.clock_tbl[c];
  623. of_property_read_string_index(pdev->dev.of_node,
  624. "clock-names", c, &vc->name);
  625. if (msm_cvp_mmrm_enabled == true)
  626. vc->clk_id = clock_ids[c];
  627. if (clock_props[c] & CLOCK_PROP_HAS_SCALING) {
  628. vc->has_scaling = true;
  629. } else {
  630. vc->count = 0;
  631. vc->has_scaling = false;
  632. }
  633. if (clock_props[c] & CLOCK_PROP_HAS_MEM_RETENTION)
  634. vc->has_mem_retention = true;
  635. else
  636. vc->has_mem_retention = false;
  637. dprintk(CVP_CORE, "Found clock %s id %d: scale-able = %s\n",
  638. vc->name, vc->clk_id, vc->count ? "yes" : "no");
  639. }
  640. return 0;
  641. err_load_clk_prop_fail:
  642. err_load_clk_table_fail:
  643. return rc;
  644. }
  645. #define MAX_CLK_RESETS 5
  646. static int msm_cvp_load_reset_table(
  647. struct msm_cvp_platform_resources *res)
  648. {
  649. struct platform_device *pdev = res->pdev;
  650. struct reset_set *rst = &res->reset_set;
  651. int num_clocks = 0, c = 0, ret = 0;
  652. int pwr_stats[MAX_CLK_RESETS];
  653. num_clocks = of_property_count_strings(pdev->dev.of_node,
  654. "reset-names");
  655. if (num_clocks <= 0 || num_clocks > MAX_CLK_RESETS) {
  656. dprintk(CVP_ERR, "Num reset clocks out of range\n");
  657. rst->count = 0;
  658. return 0;
  659. }
  660. rst->reset_tbl = devm_kcalloc(&pdev->dev, num_clocks,
  661. sizeof(*rst->reset_tbl), GFP_KERNEL);
  662. if (!rst->reset_tbl)
  663. return -ENOMEM;
  664. rst->count = num_clocks;
  665. dprintk(CVP_CORE, "Found %d reset clocks\n", num_clocks);
  666. ret = of_property_read_u32_array(pdev->dev.of_node,
  667. "reset-power-status", pwr_stats,
  668. num_clocks);
  669. if (ret) {
  670. dprintk(CVP_ERR, "Failed to read reset pwr state: %d\n", ret);
  671. devm_kfree(&pdev->dev, rst->reset_tbl);
  672. return ret;
  673. }
  674. for (c = 0; c < num_clocks; ++c) {
  675. struct reset_info *rc = &res->reset_set.reset_tbl[c];
  676. of_property_read_string_index(pdev->dev.of_node,
  677. "reset-names", c, &rc->name);
  678. rc->required_stage = pwr_stats[c];
  679. }
  680. return 0;
  681. }
  682. static int find_key_value(struct msm_cvp_platform_data *platform_data,
  683. const char *key)
  684. {
  685. int i = 0;
  686. struct msm_cvp_common_data *common_data = platform_data->common_data;
  687. int size = platform_data->common_data_length;
  688. for (i = 0; i < size; i++) {
  689. if (!strcmp(common_data[i].key, key))
  690. return common_data[i].value;
  691. }
  692. return 0;
  693. }
  694. int cvp_read_platform_resources_from_drv_data(
  695. struct msm_cvp_core *core)
  696. {
  697. struct msm_cvp_platform_data *platform_data;
  698. struct msm_cvp_platform_resources *res;
  699. int rc = 0, i;
  700. if (!core || !core->platform_data) {
  701. dprintk(CVP_ERR, "%s Invalid data\n", __func__);
  702. return -ENOENT;
  703. }
  704. platform_data = core->platform_data;
  705. res = &core->resources;
  706. res->sku_version = platform_data->sku_version;
  707. res->dsp_enabled = find_key_value(platform_data,
  708. "qcom,dsp-enabled");
  709. res->max_ssr_allowed = find_key_value(platform_data,
  710. "qcom,max-ssr-allowed");
  711. res->sw_power_collapsible = find_key_value(platform_data,
  712. "qcom,sw-power-collapse");
  713. res->debug_timeout = find_key_value(platform_data,
  714. "qcom,debug-timeout");
  715. res->pm_qos.latency_us = find_key_value(platform_data,
  716. "qcom,pm-qos-latency-us");
  717. res->pm_qos.silver_count = 0;
  718. for(i = 0; i < MAX_SILVER_CORE_NUM; i++) {
  719. if(topology_cluster_id(i) == 0)
  720. res->pm_qos.silver_count++;
  721. else
  722. break;
  723. }
  724. for (i = 0; i < res->pm_qos.silver_count; i++)
  725. res->pm_qos.silver_cores[i] = i;
  726. res->pm_qos.off_vote_cnt = 0;
  727. spin_lock_init(&res->pm_qos.lock);
  728. res->max_secure_inst_count = find_key_value(platform_data,
  729. "qcom,max-secure-instances");
  730. res->thermal_mitigable = find_key_value(platform_data,
  731. "qcom,enable-thermal-mitigation");
  732. res->msm_cvp_pwr_collapse_delay = find_key_value(platform_data,
  733. "qcom,power-collapse-delay");
  734. res->msm_cvp_hw_rsp_timeout = find_key_value(platform_data,
  735. "qcom,hw-resp-timeout");
  736. res->msm_cvp_dsp_rsp_timeout = find_key_value(platform_data,
  737. "qcom,dsp-resp-timeout");
  738. res->non_fatal_pagefaults = find_key_value(platform_data,
  739. "qcom,domain-attr-non-fatal-faults");
  740. //Address offsets for QOS setting.
  741. //There are diff between lanai and palawan for QOS register addresses
  742. res->qos_noc_rge_niu_offset = find_key_value(platform_data,
  743. "qcom,qos_noc_rge_niu_offset");
  744. res->qos_noc_gce_vadl_tof_niu_offset = find_key_value(platform_data,
  745. "qcom,qos_noc_gce_vadl_tof_niu_offset");
  746. res->qos_noc_cdm_niu_offset = find_key_value(platform_data,
  747. "qcom,qos_noc_cdm_niu_offset");
  748. res->noc_core_err_offset = find_key_value(platform_data,
  749. "qcom,noc_core_err_offset");
  750. res->noc_main_sidebandmanager_offset = find_key_value(platform_data,
  751. "qcom,noc_main_sidebandmanager_offset");
  752. res->vpu_ver = platform_data->vpu_ver;
  753. res->ubwc_config = platform_data->ubwc_config;
  754. res->fatal_ssr = false;
  755. return rc;
  756. }
  757. int cvp_read_platform_resources_from_dt(
  758. struct msm_cvp_platform_resources *res)
  759. {
  760. struct platform_device *pdev = res->pdev;
  761. struct resource *kres = NULL;
  762. int rc = 0;
  763. uint32_t firmware_base = 0;
  764. if (!pdev->dev.of_node) {
  765. dprintk(CVP_ERR, "DT node not found\n");
  766. return -ENOENT;
  767. }
  768. INIT_LIST_HEAD(&res->context_banks);
  769. res->firmware_base = (phys_addr_t)firmware_base;
  770. kres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  771. res->register_base = kres ? kres->start : -1;
  772. res->register_size = kres ? (kres->end + 1 - kres->start) : -1;
  773. res->irq = platform_get_irq(pdev, 0);
  774. dprintk(CVP_CORE, "%s: res->irq:%d \n",
  775. __func__, res->irq);
  776. //Parsing for WD interrupt
  777. res->irq_wd = platform_get_irq(pdev, 1);
  778. dprintk(CVP_CORE, "%s: res->irq_wd:%d \n",
  779. __func__, res->irq_wd);
  780. rc = msm_cvp_load_fw_name(res);
  781. dprintk(CVP_CORE, "Firmware filename: %s\n", res->fw_name);
  782. if (rc)
  783. dprintk(CVP_WARN, "Failed to load fw name info: %d\n", rc);
  784. rc = msm_cvp_load_subcache_info(res);
  785. if (rc)
  786. dprintk(CVP_WARN, "Failed to load subcache info: %d\n", rc);
  787. rc = msm_cvp_load_qdss_table(res);
  788. if (rc)
  789. dprintk(CVP_WARN, "Failed to load qdss reg table: %d\n", rc);
  790. rc = msm_cvp_load_reg_table(res);
  791. if (rc) {
  792. dprintk(CVP_ERR, "Failed to load reg table: %d\n", rc);
  793. goto err_load_reg_table;
  794. }
  795. rc = msm_cvp_load_ipcc_regs(res);
  796. if (rc)
  797. dprintk(CVP_ERR, "Failed to load IPCC regs: %d\n", rc);
  798. rc = msm_cvp_load_regspace_mapping(res);
  799. if (rc)
  800. dprintk(CVP_ERR, "Failed to load reg space mapping: %d\n", rc);
  801. rc = msm_cvp_load_gcc_regs(res);
  802. rc = msm_cvp_load_regulator_table(res);
  803. if (rc) {
  804. dprintk(CVP_ERR, "Failed to load list of regulators %d\n", rc);
  805. goto err_load_regulator_table;
  806. }
  807. rc = msm_cvp_load_clock_table(res);
  808. if (rc) {
  809. dprintk(CVP_ERR,
  810. "Failed to load clock table: %d\n", rc);
  811. goto err_load_clock_table;
  812. }
  813. rc = msm_cvp_load_allowed_clocks_table(res);
  814. if (rc) {
  815. dprintk(CVP_ERR,
  816. "Failed to load allowed clocks table: %d\n", rc);
  817. goto err_load_allowed_clocks_table;
  818. }
  819. rc = msm_cvp_load_reset_table(res);
  820. if (rc) {
  821. dprintk(CVP_ERR,
  822. "Failed to load reset table: %d\n", rc);
  823. goto err_load_reset_table;
  824. }
  825. res->use_non_secure_pil = of_property_read_bool(pdev->dev.of_node,
  826. "qcom,use-non-secure-pil");
  827. if (res->use_non_secure_pil || !is_iommu_present(res)) {
  828. of_property_read_u32(pdev->dev.of_node, "qcom,fw-bias",
  829. &firmware_base);
  830. res->firmware_base = (phys_addr_t)firmware_base;
  831. dprintk(CVP_CORE,
  832. "Using fw-bias : %pa", &res->firmware_base);
  833. }
  834. return rc;
  835. err_load_reset_table:
  836. msm_cvp_free_allowed_clocks_table(res);
  837. err_load_allowed_clocks_table:
  838. msm_cvp_free_clock_table(res);
  839. err_load_clock_table:
  840. msm_cvp_free_regulator_table(res);
  841. err_load_regulator_table:
  842. msm_cvp_free_reg_table(res);
  843. err_load_reg_table:
  844. return rc;
  845. }
  846. static int msm_cvp_setup_context_bank(struct msm_cvp_platform_resources *res,
  847. struct context_bank_info *cb, struct device *dev)
  848. {
  849. int rc = 0;
  850. struct bus_type *bus;
  851. if (!dev || !cb || !res) {
  852. dprintk(CVP_ERR,
  853. "%s: Invalid Input params\n", __func__);
  854. return -EINVAL;
  855. }
  856. cb->dev = dev;
  857. bus = cb->dev->bus;
  858. if (IS_ERR_OR_NULL(bus)) {
  859. dprintk(CVP_ERR, "%s - failed to get bus type\n", __func__);
  860. rc = PTR_ERR(bus) ?: -ENODEV;
  861. goto remove_cb;
  862. }
  863. /*
  864. * configure device segment size and segment boundary to ensure
  865. * iommu mapping returns one mapping (which is required for partial
  866. * cache operations)
  867. */
  868. if (!dev->dma_parms)
  869. dev->dma_parms =
  870. devm_kzalloc(dev, sizeof(*dev->dma_parms), GFP_KERNEL);
  871. dma_set_max_seg_size(dev, DMA_BIT_MASK(32));
  872. dma_set_seg_boundary(dev, DMA_BIT_MASK(64));
  873. dprintk(CVP_CORE, "Attached %s and created mapping\n", dev_name(dev));
  874. dprintk(CVP_CORE,
  875. "Context bank name:%s, buffer_type: %#x, is_secure: %d, address range start: %#x, size: %#x, dev: %pK",
  876. cb->name, cb->buffer_type, cb->is_secure, cb->addr_range.start,
  877. cb->addr_range.size, cb->dev);
  878. return rc;
  879. remove_cb:
  880. return rc;
  881. }
  882. int msm_cvp_smmu_fault_handler(struct iommu_domain *domain,
  883. struct device *dev, unsigned long iova, int flags, void *token)
  884. {
  885. struct msm_cvp_core *core = token;
  886. struct iris_hfi_device *hdev;
  887. struct msm_cvp_inst *inst;
  888. bool log = false;
  889. if (!domain || !core) {
  890. dprintk(CVP_ERR, "%s - invalid param %pK %pK\n",
  891. __func__, domain, core);
  892. return -EINVAL;
  893. }
  894. dprintk(CVP_ERR, "%s - faulting address: %lx fault cnt %d\n",
  895. __func__, iova, core->smmu_fault_count);
  896. if (core->smmu_fault_count > 0) {
  897. core->smmu_fault_count++;
  898. return -ENOSYS;
  899. }
  900. mutex_lock(&core->lock);
  901. core->smmu_fault_count++;
  902. if (!core->last_fault_addr)
  903. core->last_fault_addr = iova;
  904. log = (core->log.snapshot_index > 0)? false : true;
  905. list_for_each_entry(inst, &core->instances, list) {
  906. cvp_print_inst(CVP_ERR, inst);
  907. msm_cvp_print_inst_bufs(inst, log);
  908. }
  909. hdev = core->dev_ops->hfi_device_data;
  910. if (hdev) {
  911. hdev->error = CVP_ERR_NOC_ERROR;
  912. call_hfi_op(core->dev_ops, debug_hook, hdev);
  913. }
  914. mutex_unlock(&core->lock);
  915. /*
  916. * Return -EINVAL to elicit the default behaviour of smmu driver.
  917. * If we return -ENOSYS, then smmu driver assumes page fault handler
  918. * is not installed and prints a list of useful debug information like
  919. * FAR, SID etc. This information is not printed if we return 0.
  920. */
  921. return -ENOSYS;
  922. }
  923. static int msm_cvp_populate_context_bank(struct device *dev,
  924. struct msm_cvp_core *core)
  925. {
  926. int rc = 0;
  927. struct context_bank_info *cb = NULL;
  928. struct device_node *np = NULL;
  929. if (!dev || !core) {
  930. dprintk(CVP_ERR, "%s - invalid inputs\n", __func__);
  931. return -EINVAL;
  932. }
  933. np = dev->of_node;
  934. cb = devm_kzalloc(dev, sizeof(*cb), GFP_KERNEL);
  935. if (!cb) {
  936. dprintk(CVP_ERR, "%s - Failed to allocate cb\n", __func__);
  937. return -ENOMEM;
  938. }
  939. rc = of_property_read_string(np, "label", &cb->name);
  940. if (rc) {
  941. dprintk(CVP_CORE,
  942. "Failed to read cb label from device tree\n");
  943. rc = 0;
  944. }
  945. INIT_LIST_HEAD(&cb->list);
  946. list_add_tail(&cb->list, &core->resources.context_banks);
  947. dprintk(CVP_CORE, "%s: context bank has name %s\n", __func__, cb->name);
  948. if (!strcmp(cb->name, "cvp_camera")) {
  949. cb->is_secure = true;
  950. rc = msm_cvp_setup_context_bank(&core->resources, cb, dev);
  951. if (rc) {
  952. dprintk(CVP_ERR, "Cannot setup context bank %s %d\n",
  953. cb->name, rc);
  954. goto err_setup_cb;
  955. }
  956. return 0;
  957. }
  958. rc = of_property_read_u32_array(np, "qcom,iommu-dma-addr-pool",
  959. (u32 *)&cb->addr_range, 2);
  960. if (rc) {
  961. dprintk(CVP_CORE,
  962. "Could not read addr pool for context bank : %s %d\n",
  963. cb->name, rc);
  964. }
  965. cb->is_secure = of_property_read_bool(np, "qcom,iommu-vmid");
  966. dprintk(CVP_CORE, "context bank %s : secure = %d\n",
  967. cb->name, cb->is_secure);
  968. /* setup buffer type for each sub device*/
  969. rc = of_property_read_u32(np, "buffer-types", &cb->buffer_type);
  970. if (rc) {
  971. dprintk(CVP_ERR, "failed to load buffer_type info %d\n", rc);
  972. rc = -ENOENT;
  973. goto err_setup_cb;
  974. }
  975. dprintk(CVP_CORE,
  976. "context bank %s address start = %x address size = %x buffer_type = %x\n",
  977. cb->name, cb->addr_range.start,
  978. cb->addr_range.size, cb->buffer_type);
  979. cb->domain = iommu_get_domain_for_dev(dev);
  980. if (IS_ERR_OR_NULL(cb->domain)) {
  981. dprintk(CVP_ERR, "Create domain failed\n");
  982. rc = -ENODEV;
  983. goto err_setup_cb;
  984. }
  985. rc = msm_cvp_setup_context_bank(&core->resources, cb, dev);
  986. if (rc) {
  987. dprintk(CVP_ERR, "Cannot setup context bank %d\n", rc);
  988. goto err_setup_cb;
  989. }
  990. iommu_set_fault_handler(cb->domain,
  991. msm_cvp_smmu_fault_handler, (void *)core);
  992. return 0;
  993. err_setup_cb:
  994. list_del(&cb->list);
  995. return rc;
  996. }
  997. int cvp_read_context_bank_resources_from_dt(struct platform_device *pdev)
  998. {
  999. struct msm_cvp_core *core;
  1000. int rc = 0;
  1001. if (!pdev) {
  1002. dprintk(CVP_ERR, "Invalid platform device\n");
  1003. return -EINVAL;
  1004. } else if (!pdev->dev.parent) {
  1005. dprintk(CVP_ERR, "Failed to find a parent for %s\n",
  1006. dev_name(&pdev->dev));
  1007. return -ENODEV;
  1008. }
  1009. core = dev_get_drvdata(pdev->dev.parent);
  1010. if (!core) {
  1011. dprintk(CVP_ERR, "Failed to find cookie in parent device %s",
  1012. dev_name(pdev->dev.parent));
  1013. return -EINVAL;
  1014. }
  1015. rc = msm_cvp_populate_context_bank(&pdev->dev, core);
  1016. if (rc)
  1017. dprintk(CVP_ERR, "Failed to probe context bank\n");
  1018. else
  1019. dprintk(CVP_CORE, "Successfully probed context bank\n");
  1020. return rc;
  1021. }
  1022. int cvp_read_bus_resources_from_dt(struct platform_device *pdev)
  1023. {
  1024. struct msm_cvp_core *core;
  1025. if (!pdev) {
  1026. dprintk(CVP_ERR, "Invalid platform device\n");
  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_bus(&pdev->dev, &core->resources);
  1040. }
  1041. int cvp_read_mem_cdsp_resources_from_dt(struct platform_device *pdev)
  1042. {
  1043. struct msm_cvp_core *core;
  1044. if (!pdev) {
  1045. dprintk(CVP_ERR, "%s: invalid platform device\n", __func__);
  1046. return -EINVAL;
  1047. } else if (!pdev->dev.parent) {
  1048. dprintk(CVP_ERR, "Failed to find a parent for %s\n",
  1049. dev_name(&pdev->dev));
  1050. return -ENODEV;
  1051. }
  1052. core = dev_get_drvdata(pdev->dev.parent);
  1053. if (!core) {
  1054. dprintk(CVP_ERR, "Failed to find cookie in parent device %s",
  1055. dev_name(pdev->dev.parent));
  1056. return -EINVAL;
  1057. }
  1058. return msm_cvp_populate_mem_cdsp(&pdev->dev, &core->resources);
  1059. }