ipa_rm.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2013-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/slab.h>
  6. #include <linux/workqueue.h>
  7. #include <linux/ipa.h>
  8. #include "ipa_rm_dependency_graph.h"
  9. #include "ipa_rm_i.h"
  10. #include "ipa_common_i.h"
  11. static const char *resource_name_to_str[IPA_RM_RESOURCE_MAX] = {
  12. __stringify(IPA_RM_RESOURCE_Q6_PROD),
  13. __stringify(IPA_RM_RESOURCE_Q6_CONS),
  14. __stringify(IPA_RM_RESOURCE_USB_PROD),
  15. __stringify(IPA_RM_RESOURCE_USB_CONS),
  16. __stringify(IPA_RM_RESOURCE_USB_DPL_DUMMY_PROD),
  17. __stringify(IPA_RM_RESOURCE_USB_DPL_CONS),
  18. __stringify(IPA_RM_RESOURCE_HSIC_PROD),
  19. __stringify(IPA_RM_RESOURCE_HSIC_CONS),
  20. __stringify(IPA_RM_RESOURCE_STD_ECM_PROD),
  21. __stringify(IPA_RM_RESOURCE_APPS_CONS),
  22. __stringify(IPA_RM_RESOURCE_RNDIS_PROD),
  23. __stringify(RESERVED_CONS_11),
  24. __stringify(IPA_RM_RESOURCE_WWAN_0_PROD),
  25. __stringify(RESERVED_CONS_13),
  26. __stringify(IPA_RM_RESOURCE_WLAN_PROD),
  27. __stringify(IPA_RM_RESOURCE_WLAN_CONS),
  28. __stringify(IPA_RM_RESOURCE_ODU_ADAPT_PROD),
  29. __stringify(IPA_RM_RESOURCE_ODU_ADAPT_CONS),
  30. __stringify(IPA_RM_RESOURCE_MHI_PROD),
  31. __stringify(IPA_RM_RESOURCE_MHI_CONS),
  32. __stringify(IPA_RM_RESOURCE_ETHERNET_PROD),
  33. __stringify(IPA_RM_RESOURCE_ETHERNET_CONS),
  34. };
  35. struct ipa_rm_profile_vote_type {
  36. enum ipa_voltage_level volt[IPA_RM_RESOURCE_MAX];
  37. enum ipa_voltage_level curr_volt;
  38. u32 bw_resources[IPA_RM_RESOURCE_MAX];
  39. u32 curr_bw;
  40. };
  41. struct ipa_rm_context_type {
  42. struct ipa_rm_dep_graph *dep_graph;
  43. struct workqueue_struct *ipa_rm_wq;
  44. spinlock_t ipa_rm_lock;
  45. struct ipa_rm_profile_vote_type prof_vote;
  46. };
  47. static struct ipa_rm_context_type *ipa_rm_ctx;
  48. struct ipa_rm_notify_ipa_work_type {
  49. struct work_struct work;
  50. enum ipa_voltage_level volt;
  51. u32 bandwidth_mbps;
  52. };
  53. /**
  54. * ipa_rm_create_resource() - create resource
  55. * @create_params: [in] parameters needed
  56. * for resource initialization
  57. *
  58. * Returns: 0 on success, negative on failure
  59. *
  60. * This function is called by IPA RM client to initialize client's resources.
  61. * This API should be called before any other IPA RM API on a given resource
  62. * name.
  63. *
  64. */
  65. int ipa_rm_create_resource(struct ipa_rm_create_params *create_params)
  66. {
  67. struct ipa_rm_resource *resource;
  68. unsigned long flags;
  69. int result;
  70. if (unlikely(!ipa_rm_ctx)) {
  71. IPA_RM_ERR("IPA RM was not initialized\n");
  72. return -EINVAL;
  73. }
  74. if (!create_params) {
  75. IPA_RM_ERR("invalid args\n");
  76. return -EINVAL;
  77. }
  78. IPA_RM_DBG("%s\n", ipa_rm_resource_str(create_params->name));
  79. if (create_params->floor_voltage < 0 ||
  80. create_params->floor_voltage >= IPA_VOLTAGE_MAX) {
  81. IPA_RM_ERR("invalid voltage %d\n",
  82. create_params->floor_voltage);
  83. return -EINVAL;
  84. }
  85. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  86. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  87. create_params->name,
  88. &resource) == 0) {
  89. IPA_RM_ERR("resource already exists\n");
  90. result = -EEXIST;
  91. goto bail;
  92. }
  93. result = ipa_rm_resource_create(create_params,
  94. &resource);
  95. if (result) {
  96. IPA_RM_ERR("ipa_rm_resource_create() failed\n");
  97. goto bail;
  98. }
  99. result = ipa_rm_dep_graph_add(ipa_rm_ctx->dep_graph, resource);
  100. if (result) {
  101. IPA_RM_ERR("ipa_rm_dep_graph_add() failed\n");
  102. ipa_rm_resource_delete(resource);
  103. goto bail;
  104. }
  105. bail:
  106. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  107. IPA_RM_DBG("EXIT with %d\n", result);
  108. return result;
  109. }
  110. EXPORT_SYMBOL(ipa_rm_create_resource);
  111. /**
  112. * ipa_rm_delete_resource() - delete resource
  113. * @resource_name: name of resource to be deleted
  114. *
  115. * Returns: 0 on success, negative on failure
  116. *
  117. * This function is called by IPA RM client to delete client's resources.
  118. *
  119. */
  120. int ipa_rm_delete_resource(enum ipa_rm_resource_name resource_name)
  121. {
  122. struct ipa_rm_resource *resource;
  123. unsigned long flags;
  124. int result;
  125. if (unlikely(!ipa_rm_ctx)) {
  126. IPA_RM_ERR("IPA RM was not initialized\n");
  127. return -EINVAL;
  128. }
  129. IPA_RM_DBG("%s\n", ipa_rm_resource_str(resource_name));
  130. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  131. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  132. resource_name,
  133. &resource) != 0) {
  134. IPA_RM_ERR("resource does not exist\n");
  135. result = -EINVAL;
  136. goto bail;
  137. }
  138. result = ipa_rm_resource_delete(resource);
  139. if (result) {
  140. IPA_RM_ERR("ipa_rm_resource_delete() failed\n");
  141. goto bail;
  142. }
  143. result = ipa_rm_dep_graph_remove(ipa_rm_ctx->dep_graph,
  144. resource_name);
  145. if (result) {
  146. IPA_RM_ERR("ipa_rm_dep_graph_remove() failed\n");
  147. goto bail;
  148. }
  149. bail:
  150. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  151. IPA_RM_DBG("EXIT with %d\n", result);
  152. return result;
  153. }
  154. EXPORT_SYMBOL(ipa_rm_delete_resource);
  155. static int _ipa_rm_add_dependency(enum ipa_rm_resource_name resource_name,
  156. enum ipa_rm_resource_name depends_on_name,
  157. bool userspace_dep)
  158. {
  159. unsigned long flags;
  160. int result;
  161. if (unlikely(!ipa_rm_ctx)) {
  162. IPA_RM_ERR("IPA RM was not initialized\n");
  163. return -EINVAL;
  164. }
  165. IPA_RM_DBG("%s -> %s\n", ipa_rm_resource_str(resource_name),
  166. ipa_rm_resource_str(depends_on_name));
  167. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  168. result = ipa_rm_dep_graph_add_dependency(
  169. ipa_rm_ctx->dep_graph,
  170. resource_name,
  171. depends_on_name,
  172. userspace_dep);
  173. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  174. IPA_RM_DBG("EXIT with %d\n", result);
  175. return result;
  176. }
  177. /**
  178. * ipa_rm_add_dependency() - create dependency between 2 resources
  179. * @resource_name: name of dependent resource
  180. * @depends_on_name: name of its dependency
  181. *
  182. * Returns: 0 on success, negative on failure
  183. *
  184. * Side effects: IPA_RM_RESORCE_GRANTED could be generated
  185. * in case client registered with IPA RM
  186. */
  187. int ipa_rm_add_dependency(enum ipa_rm_resource_name resource_name,
  188. enum ipa_rm_resource_name depends_on_name)
  189. {
  190. return _ipa_rm_add_dependency(resource_name, depends_on_name, false);
  191. }
  192. EXPORT_SYMBOL(ipa_rm_add_dependency);
  193. /**
  194. * ipa_rm_add_dependency_from_ioctl() - create dependency between 2 resources
  195. * @resource_name: name of dependent resource
  196. * @depends_on_name: name of its dependency
  197. *
  198. * This function is expected to be called from IOCTL and the dependency will be
  199. * marked as is was added by the userspace.
  200. *
  201. * Returns: 0 on success, negative on failure
  202. *
  203. * Side effects: IPA_RM_RESORCE_GRANTED could be generated
  204. * in case client registered with IPA RM
  205. */
  206. int ipa_rm_add_dependency_from_ioctl(enum ipa_rm_resource_name resource_name,
  207. enum ipa_rm_resource_name depends_on_name)
  208. {
  209. return _ipa_rm_add_dependency(resource_name, depends_on_name, true);
  210. }
  211. static int _ipa_rm_add_dependency_sync(enum ipa_rm_resource_name resource_name,
  212. enum ipa_rm_resource_name depends_on_name,
  213. bool userspsace_dep)
  214. {
  215. int result;
  216. struct ipa_rm_resource *consumer;
  217. unsigned long time;
  218. unsigned long flags;
  219. if (unlikely(!ipa_rm_ctx)) {
  220. IPA_RM_ERR("IPA RM was not initialized\n");
  221. return -EINVAL;
  222. }
  223. IPA_RM_DBG("%s -> %s\n", ipa_rm_resource_str(resource_name),
  224. ipa_rm_resource_str(depends_on_name));
  225. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  226. result = ipa_rm_dep_graph_add_dependency(
  227. ipa_rm_ctx->dep_graph,
  228. resource_name,
  229. depends_on_name,
  230. userspsace_dep);
  231. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  232. if (result == -EINPROGRESS) {
  233. ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  234. depends_on_name,
  235. &consumer);
  236. IPA_RM_DBG("%s waits for GRANT of %s.\n",
  237. ipa_rm_resource_str(resource_name),
  238. ipa_rm_resource_str(depends_on_name));
  239. time = wait_for_completion_timeout(
  240. &((struct ipa_rm_resource_cons *)consumer)->
  241. request_consumer_in_progress,
  242. HZ * 5);
  243. result = 0;
  244. if (!time) {
  245. IPA_RM_ERR("TIMEOUT waiting for %s GRANT event.",
  246. ipa_rm_resource_str(depends_on_name));
  247. result = -ETIME;
  248. } else {
  249. IPA_RM_DBG("%s waited for %s GRANT %lu time.\n",
  250. ipa_rm_resource_str(resource_name),
  251. ipa_rm_resource_str(depends_on_name),
  252. time);
  253. }
  254. }
  255. IPA_RM_DBG("EXIT with %d\n", result);
  256. return result;
  257. }
  258. /**
  259. * ipa_rm_add_dependency_sync() - Create a dependency between 2 resources
  260. * in a synchronized fashion. In case a producer resource is in GRANTED state
  261. * and the newly added consumer resource is in RELEASED state, the consumer
  262. * entity will be requested and the function will block until the consumer
  263. * is granted.
  264. * @resource_name: name of dependent resource
  265. * @depends_on_name: name of its dependency
  266. *
  267. * This function is expected to be called from IOCTL and the dependency will be
  268. * marked as is was added by the userspace.
  269. *
  270. * Returns: 0 on success, negative on failure
  271. *
  272. * Side effects: May block. See documentation above.
  273. */
  274. int ipa_rm_add_dependency_sync(enum ipa_rm_resource_name resource_name,
  275. enum ipa_rm_resource_name depends_on_name)
  276. {
  277. return _ipa_rm_add_dependency_sync(resource_name, depends_on_name,
  278. false);
  279. }
  280. EXPORT_SYMBOL(ipa_rm_add_dependency_sync);
  281. /**
  282. * ipa_rm_add_dependency_sync_from_ioctl() - Create a dependency between 2
  283. * resources in a synchronized fashion. In case a producer resource is in
  284. * GRANTED state and the newly added consumer resource is in RELEASED state,
  285. * the consumer entity will be requested and the function will block until
  286. * the consumer is granted.
  287. * @resource_name: name of dependent resource
  288. * @depends_on_name: name of its dependency
  289. *
  290. * Returns: 0 on success, negative on failure
  291. *
  292. * Side effects: May block. See documentation above.
  293. */
  294. int ipa_rm_add_dependency_sync_from_ioctl(
  295. enum ipa_rm_resource_name resource_name,
  296. enum ipa_rm_resource_name depends_on_name)
  297. {
  298. return _ipa_rm_add_dependency_sync(resource_name, depends_on_name,
  299. true);
  300. }
  301. static int _ipa_rm_delete_dependency(enum ipa_rm_resource_name resource_name,
  302. enum ipa_rm_resource_name depends_on_name,
  303. bool userspace_dep)
  304. {
  305. unsigned long flags;
  306. int result;
  307. if (unlikely(!ipa_rm_ctx)) {
  308. IPA_RM_ERR("IPA RM was not initialized\n");
  309. return -EINVAL;
  310. }
  311. IPA_RM_DBG("%s -> %s\n", ipa_rm_resource_str(resource_name),
  312. ipa_rm_resource_str(depends_on_name));
  313. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  314. result = ipa_rm_dep_graph_delete_dependency(
  315. ipa_rm_ctx->dep_graph,
  316. resource_name,
  317. depends_on_name,
  318. userspace_dep);
  319. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  320. IPA_RM_DBG("EXIT with %d\n", result);
  321. return result;
  322. }
  323. /**
  324. * ipa_rm_delete_dependency() - delete dependency between 2 resources
  325. * @resource_name: name of dependent resource
  326. * @depends_on_name: name of its dependency
  327. *
  328. * Returns: 0 on success, negative on failure
  329. *
  330. * Side effects: IPA_RM_RESORCE_GRANTED could be generated
  331. * in case client registered with IPA RM
  332. */
  333. int ipa_rm_delete_dependency(enum ipa_rm_resource_name resource_name,
  334. enum ipa_rm_resource_name depends_on_name)
  335. {
  336. return _ipa_rm_delete_dependency(resource_name, depends_on_name, false);
  337. }
  338. EXPORT_SYMBOL(ipa_rm_delete_dependency);
  339. /**
  340. * ipa_rm_delete_dependency_fron_ioctl() - delete dependency between 2 resources
  341. * @resource_name: name of dependent resource
  342. * @depends_on_name: name of its dependency
  343. *
  344. * This function is expected to be called from IOCTL and the dependency will be
  345. * marked as is was added by the userspace.
  346. *
  347. * Returns: 0 on success, negative on failure
  348. *
  349. * Side effects: IPA_RM_RESORCE_GRANTED could be generated
  350. * in case client registered with IPA RM
  351. */
  352. int ipa_rm_delete_dependency_from_ioctl(enum ipa_rm_resource_name resource_name,
  353. enum ipa_rm_resource_name depends_on_name)
  354. {
  355. return _ipa_rm_delete_dependency(resource_name, depends_on_name, true);
  356. }
  357. /**
  358. * ipa_rm_request_resource() - request resource
  359. * @resource_name: [in] name of the requested resource
  360. *
  361. * Returns: 0 on success, negative on failure
  362. *
  363. * All registered callbacks are called with IPA_RM_RESOURCE_GRANTED
  364. * on successful completion of this operation.
  365. */
  366. int ipa_rm_request_resource(enum ipa_rm_resource_name resource_name)
  367. {
  368. struct ipa_rm_resource *resource;
  369. unsigned long flags;
  370. int result;
  371. if (unlikely(!ipa_rm_ctx)) {
  372. IPA_RM_ERR("IPA RM was not initialized\n");
  373. return -EINVAL;
  374. }
  375. if (!IPA_RM_RESORCE_IS_PROD(resource_name)) {
  376. IPA_RM_ERR("can be called on PROD only\n");
  377. return -EINVAL;
  378. }
  379. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  380. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  381. resource_name,
  382. &resource) != 0) {
  383. IPA_RM_ERR("resource does not exist\n");
  384. result = -EPERM;
  385. goto bail;
  386. }
  387. result = ipa_rm_resource_producer_request(
  388. (struct ipa_rm_resource_prod *)resource);
  389. bail:
  390. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  391. return result;
  392. }
  393. EXPORT_SYMBOL(ipa_rm_request_resource);
  394. void delayed_release_work_func(struct work_struct *work)
  395. {
  396. unsigned long flags;
  397. struct ipa_rm_resource *resource;
  398. struct ipa_rm_delayed_release_work_type *rwork = container_of(
  399. to_delayed_work(work),
  400. struct ipa_rm_delayed_release_work_type,
  401. work);
  402. if (!IPA_RM_RESORCE_IS_CONS(rwork->resource_name)) {
  403. IPA_RM_ERR("can be called on CONS only\n");
  404. kfree(rwork);
  405. return;
  406. }
  407. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  408. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  409. rwork->resource_name,
  410. &resource) != 0) {
  411. IPA_RM_ERR("resource does not exists\n");
  412. goto bail;
  413. }
  414. ipa_rm_resource_consumer_release(
  415. (struct ipa_rm_resource_cons *)resource, rwork->needed_bw,
  416. rwork->dec_usage_count);
  417. bail:
  418. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  419. kfree(rwork);
  420. }
  421. /**
  422. * ipa_rm_request_resource_with_timer() - requests the specified consumer
  423. * resource and releases it after 1 second
  424. * @resource_name: name of the requested resource
  425. *
  426. * Returns: 0 on success, negative on failure
  427. */
  428. int ipa_rm_request_resource_with_timer(enum ipa_rm_resource_name resource_name)
  429. {
  430. unsigned long flags;
  431. struct ipa_rm_resource *resource;
  432. struct ipa_rm_delayed_release_work_type *release_work;
  433. int result;
  434. if (!IPA_RM_RESORCE_IS_CONS(resource_name)) {
  435. IPA_RM_ERR("can be called on CONS only\n");
  436. return -EINVAL;
  437. }
  438. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  439. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  440. resource_name,
  441. &resource) != 0) {
  442. IPA_RM_ERR("resource does not exists\n");
  443. result = -EPERM;
  444. goto bail;
  445. }
  446. result = ipa_rm_resource_consumer_request(
  447. (struct ipa_rm_resource_cons *)resource, 0, false, true);
  448. if (result != 0 && result != -EINPROGRESS) {
  449. IPA_RM_ERR("consumer request returned error %d\n", result);
  450. result = -EPERM;
  451. goto bail;
  452. }
  453. release_work = kzalloc(sizeof(*release_work), GFP_ATOMIC);
  454. if (!release_work) {
  455. result = -ENOMEM;
  456. goto bail;
  457. }
  458. release_work->resource_name = resource->name;
  459. release_work->needed_bw = 0;
  460. release_work->dec_usage_count = false;
  461. INIT_DELAYED_WORK(&release_work->work, delayed_release_work_func);
  462. schedule_delayed_work(&release_work->work,
  463. msecs_to_jiffies(IPA_RM_RELEASE_DELAY_IN_MSEC));
  464. result = 0;
  465. bail:
  466. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  467. return result;
  468. }
  469. /**
  470. * ipa_rm_release_resource() - release resource
  471. * @resource_name: [in] name of the requested resource
  472. *
  473. * Returns: 0 on success, negative on failure
  474. *
  475. * All registered callbacks are called with IPA_RM_RESOURCE_RELEASED
  476. * on successful completion of this operation.
  477. */
  478. int ipa_rm_release_resource(enum ipa_rm_resource_name resource_name)
  479. {
  480. unsigned long flags;
  481. struct ipa_rm_resource *resource;
  482. int result;
  483. if (unlikely(!ipa_rm_ctx)) {
  484. IPA_RM_ERR("IPA RM was not initialized\n");
  485. return -EINVAL;
  486. }
  487. if (!IPA_RM_RESORCE_IS_PROD(resource_name)) {
  488. IPA_RM_ERR("can be called on PROD only\n");
  489. return -EINVAL;
  490. }
  491. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  492. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  493. resource_name,
  494. &resource) != 0) {
  495. IPA_RM_ERR("resource does not exists\n");
  496. result = -EPERM;
  497. goto bail;
  498. }
  499. result = ipa_rm_resource_producer_release(
  500. (struct ipa_rm_resource_prod *)resource);
  501. bail:
  502. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  503. return result;
  504. }
  505. EXPORT_SYMBOL(ipa_rm_release_resource);
  506. /**
  507. * ipa_rm_register() - register for event
  508. * @resource_name: resource name
  509. * @reg_params: [in] registration parameters
  510. *
  511. * Returns: 0 on success, negative on failure
  512. *
  513. * Registration parameters provided here should be the same
  514. * as provided later in ipa_rm_deregister() call.
  515. */
  516. int ipa_rm_register(enum ipa_rm_resource_name resource_name,
  517. struct ipa_rm_register_params *reg_params)
  518. {
  519. int result;
  520. unsigned long flags;
  521. struct ipa_rm_resource *resource;
  522. IPA_RM_DBG("%s\n", ipa_rm_resource_str(resource_name));
  523. if (!IPA_RM_RESORCE_IS_PROD(resource_name)) {
  524. IPA_RM_ERR("can be called on PROD only\n");
  525. return -EINVAL;
  526. }
  527. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  528. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  529. resource_name,
  530. &resource) != 0) {
  531. IPA_RM_ERR("resource does not exists\n");
  532. result = -EPERM;
  533. goto bail;
  534. }
  535. result = ipa_rm_resource_producer_register(
  536. (struct ipa_rm_resource_prod *)resource,
  537. reg_params,
  538. true);
  539. bail:
  540. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  541. IPA_RM_DBG("EXIT with %d\n", result);
  542. return result;
  543. }
  544. EXPORT_SYMBOL(ipa_rm_register);
  545. /**
  546. * ipa_rm_deregister() - cancel the registration
  547. * @resource_name: resource name
  548. * @reg_params: [in] registration parameters
  549. *
  550. * Returns: 0 on success, negative on failure
  551. *
  552. * Registration parameters provided here should be the same
  553. * as provided in ipa_rm_register() call.
  554. */
  555. int ipa_rm_deregister(enum ipa_rm_resource_name resource_name,
  556. struct ipa_rm_register_params *reg_params)
  557. {
  558. int result;
  559. unsigned long flags;
  560. struct ipa_rm_resource *resource;
  561. IPA_RM_DBG("%s\n", ipa_rm_resource_str(resource_name));
  562. if (!IPA_RM_RESORCE_IS_PROD(resource_name)) {
  563. IPA_RM_ERR("can be called on PROD only\n");
  564. return -EINVAL;
  565. }
  566. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  567. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  568. resource_name,
  569. &resource) != 0) {
  570. IPA_RM_ERR("resource does not exists\n");
  571. result = -EPERM;
  572. goto bail;
  573. }
  574. result = ipa_rm_resource_producer_deregister(
  575. (struct ipa_rm_resource_prod *)resource,
  576. reg_params);
  577. bail:
  578. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  579. IPA_RM_DBG("EXIT with %d\n", result);
  580. return result;
  581. }
  582. EXPORT_SYMBOL(ipa_rm_deregister);
  583. /**
  584. * ipa_rm_set_perf_profile() - set performance profile
  585. * @resource_name: resource name
  586. * @profile: [in] profile information.
  587. *
  588. * Returns: 0 on success, negative on failure
  589. *
  590. * Set resource performance profile.
  591. * Updates IPA driver if performance level changed.
  592. */
  593. int ipa_rm_set_perf_profile(enum ipa_rm_resource_name resource_name,
  594. struct ipa_rm_perf_profile *profile)
  595. {
  596. int result;
  597. unsigned long flags;
  598. struct ipa_rm_resource *resource;
  599. if (unlikely(!ipa_rm_ctx)) {
  600. IPA_RM_ERR("IPA RM was not initialized\n");
  601. return -EINVAL;
  602. }
  603. IPA_RM_DBG("%s\n", ipa_rm_resource_str(resource_name));
  604. if (profile)
  605. IPA_RM_DBG("BW: %d\n", profile->max_supported_bandwidth_mbps);
  606. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  607. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  608. resource_name,
  609. &resource) != 0) {
  610. IPA_RM_ERR("resource does not exists\n");
  611. result = -EPERM;
  612. goto bail;
  613. }
  614. result = ipa_rm_resource_set_perf_profile(resource, profile);
  615. if (result) {
  616. IPA_RM_ERR("ipa_rm_resource_set_perf_profile failed %d\n",
  617. result);
  618. goto bail;
  619. }
  620. result = 0;
  621. bail:
  622. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  623. IPA_RM_DBG("EXIT with %d\n", result);
  624. return result;
  625. }
  626. EXPORT_SYMBOL(ipa_rm_set_perf_profile);
  627. /**
  628. * ipa_rm_notify_completion() -
  629. * consumer driver notification for
  630. * request_resource / release_resource operations
  631. * completion
  632. * @event: notified event
  633. * @resource_name: resource name
  634. *
  635. * Returns: 0 on success, negative on failure
  636. */
  637. int ipa_rm_notify_completion(enum ipa_rm_event event,
  638. enum ipa_rm_resource_name resource_name)
  639. {
  640. int result;
  641. if (unlikely(!ipa_rm_ctx)) {
  642. IPA_RM_ERR("IPA RM was not initialized\n");
  643. return -EINVAL;
  644. }
  645. IPA_RM_DBG("event %d on %s\n", event,
  646. ipa_rm_resource_str(resource_name));
  647. if (!IPA_RM_RESORCE_IS_CONS(resource_name)) {
  648. IPA_RM_ERR("can be called on CONS only\n");
  649. result = -EINVAL;
  650. goto bail;
  651. }
  652. ipa_rm_wq_send_cmd(IPA_RM_WQ_RESOURCE_CB,
  653. resource_name,
  654. event,
  655. false);
  656. result = 0;
  657. bail:
  658. IPA_RM_DBG("EXIT with %d\n", result);
  659. return result;
  660. }
  661. EXPORT_SYMBOL(ipa_rm_notify_completion);
  662. static void ipa_rm_wq_handler(struct work_struct *work)
  663. {
  664. unsigned long flags;
  665. struct ipa_rm_resource *resource;
  666. struct ipa_rm_wq_work_type *ipa_rm_work =
  667. container_of(work,
  668. struct ipa_rm_wq_work_type,
  669. work);
  670. IPA_RM_DBG_LOW("%s cmd=%d event=%d notify_registered_only=%d\n",
  671. ipa_rm_resource_str(ipa_rm_work->resource_name),
  672. ipa_rm_work->wq_cmd,
  673. ipa_rm_work->event,
  674. ipa_rm_work->notify_registered_only);
  675. switch (ipa_rm_work->wq_cmd) {
  676. case IPA_RM_WQ_NOTIFY_PROD:
  677. if (!IPA_RM_RESORCE_IS_PROD(ipa_rm_work->resource_name)) {
  678. IPA_RM_ERR("resource is not PROD\n");
  679. goto free_work;
  680. }
  681. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  682. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  683. ipa_rm_work->resource_name,
  684. &resource) != 0){
  685. IPA_RM_ERR("resource does not exists\n");
  686. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  687. goto free_work;
  688. }
  689. ipa_rm_resource_producer_notify_clients(
  690. (struct ipa_rm_resource_prod *)resource,
  691. ipa_rm_work->event,
  692. ipa_rm_work->notify_registered_only);
  693. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  694. break;
  695. case IPA_RM_WQ_NOTIFY_CONS:
  696. break;
  697. case IPA_RM_WQ_RESOURCE_CB:
  698. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  699. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  700. ipa_rm_work->resource_name,
  701. &resource) != 0){
  702. IPA_RM_ERR("resource does not exists\n");
  703. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  704. goto free_work;
  705. }
  706. ipa_rm_resource_consumer_handle_cb(
  707. (struct ipa_rm_resource_cons *)resource,
  708. ipa_rm_work->event);
  709. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  710. break;
  711. default:
  712. break;
  713. }
  714. free_work:
  715. kfree((void *) work);
  716. }
  717. static void ipa_rm_wq_resume_handler(struct work_struct *work)
  718. {
  719. unsigned long flags;
  720. struct ipa_rm_resource *resource;
  721. struct ipa_rm_wq_suspend_resume_work_type *ipa_rm_work =
  722. container_of(work,
  723. struct ipa_rm_wq_suspend_resume_work_type,
  724. work);
  725. IPA_RM_DBG_LOW("resume work handler: %s",
  726. ipa_rm_resource_str(ipa_rm_work->resource_name));
  727. if (!IPA_RM_RESORCE_IS_CONS(ipa_rm_work->resource_name)) {
  728. IPA_RM_ERR("resource is not CONS\n");
  729. return;
  730. }
  731. IPA_ACTIVE_CLIENTS_INC_RESOURCE(ipa_rm_resource_str(
  732. ipa_rm_work->resource_name));
  733. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  734. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  735. ipa_rm_work->resource_name,
  736. &resource) != 0){
  737. IPA_RM_ERR("resource does not exists\n");
  738. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  739. IPA_ACTIVE_CLIENTS_DEC_RESOURCE(ipa_rm_resource_str(
  740. ipa_rm_work->resource_name));
  741. goto bail;
  742. }
  743. ipa_rm_resource_consumer_request_work(
  744. (struct ipa_rm_resource_cons *)resource,
  745. ipa_rm_work->prev_state, ipa_rm_work->needed_bw, true,
  746. ipa_rm_work->inc_usage_count);
  747. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  748. bail:
  749. kfree(ipa_rm_work);
  750. }
  751. static void ipa_rm_wq_suspend_handler(struct work_struct *work)
  752. {
  753. unsigned long flags;
  754. struct ipa_rm_resource *resource;
  755. struct ipa_rm_wq_suspend_resume_work_type *ipa_rm_work =
  756. container_of(work,
  757. struct ipa_rm_wq_suspend_resume_work_type,
  758. work);
  759. IPA_RM_DBG_LOW("suspend work handler: %s",
  760. ipa_rm_resource_str(ipa_rm_work->resource_name));
  761. if (!IPA_RM_RESORCE_IS_CONS(ipa_rm_work->resource_name)) {
  762. IPA_RM_ERR("resource is not CONS\n");
  763. return;
  764. }
  765. ipa_suspend_resource_sync(ipa_rm_work->resource_name);
  766. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  767. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  768. ipa_rm_work->resource_name,
  769. &resource) != 0){
  770. IPA_RM_ERR("resource does not exists\n");
  771. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  772. return;
  773. }
  774. ipa_rm_resource_consumer_release_work(
  775. (struct ipa_rm_resource_cons *)resource,
  776. ipa_rm_work->prev_state,
  777. true);
  778. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  779. kfree(ipa_rm_work);
  780. }
  781. /**
  782. * ipa_rm_wq_send_cmd() - send a command for deferred work
  783. * @wq_cmd: command that should be executed
  784. * @resource_name: resource on which command should be executed
  785. * @notify_registered_only: notify only clients registered by
  786. * ipa_rm_register()
  787. *
  788. * Returns: 0 on success, negative otherwise
  789. */
  790. int ipa_rm_wq_send_cmd(enum ipa_rm_wq_cmd wq_cmd,
  791. enum ipa_rm_resource_name resource_name,
  792. enum ipa_rm_event event,
  793. bool notify_registered_only)
  794. {
  795. int result = -ENOMEM;
  796. struct ipa_rm_wq_work_type *work = kzalloc(sizeof(*work), GFP_ATOMIC);
  797. if (work) {
  798. INIT_WORK((struct work_struct *)work, ipa_rm_wq_handler);
  799. work->wq_cmd = wq_cmd;
  800. work->resource_name = resource_name;
  801. work->event = event;
  802. work->notify_registered_only = notify_registered_only;
  803. result = queue_work(ipa_rm_ctx->ipa_rm_wq,
  804. (struct work_struct *)work);
  805. }
  806. return result;
  807. }
  808. int ipa_rm_wq_send_suspend_cmd(enum ipa_rm_resource_name resource_name,
  809. enum ipa_rm_resource_state prev_state,
  810. u32 needed_bw)
  811. {
  812. int result = -ENOMEM;
  813. struct ipa_rm_wq_suspend_resume_work_type *work = kzalloc(sizeof(*work),
  814. GFP_ATOMIC);
  815. if (work) {
  816. INIT_WORK((struct work_struct *)work,
  817. ipa_rm_wq_suspend_handler);
  818. work->resource_name = resource_name;
  819. work->prev_state = prev_state;
  820. work->needed_bw = needed_bw;
  821. result = queue_work(ipa_rm_ctx->ipa_rm_wq,
  822. (struct work_struct *)work);
  823. }
  824. return result;
  825. }
  826. int ipa_rm_wq_send_resume_cmd(enum ipa_rm_resource_name resource_name,
  827. enum ipa_rm_resource_state prev_state,
  828. u32 needed_bw,
  829. bool inc_usage_count)
  830. {
  831. int result = -ENOMEM;
  832. struct ipa_rm_wq_suspend_resume_work_type *work = kzalloc(sizeof(*work),
  833. GFP_ATOMIC);
  834. if (work) {
  835. INIT_WORK((struct work_struct *)work, ipa_rm_wq_resume_handler);
  836. work->resource_name = resource_name;
  837. work->prev_state = prev_state;
  838. work->needed_bw = needed_bw;
  839. work->inc_usage_count = inc_usage_count;
  840. result = queue_work(ipa_rm_ctx->ipa_rm_wq,
  841. (struct work_struct *)work);
  842. } else {
  843. IPA_RM_ERR("no mem\n");
  844. }
  845. return result;
  846. }
  847. /**
  848. * ipa_rm_initialize() - initialize IPA RM component
  849. *
  850. * Returns: 0 on success, negative otherwise
  851. */
  852. int ipa_rm_initialize(void)
  853. {
  854. int result;
  855. ipa_rm_ctx = kzalloc(sizeof(*ipa_rm_ctx), GFP_KERNEL);
  856. if (!ipa_rm_ctx) {
  857. IPA_RM_ERR("no mem\n");
  858. result = -ENOMEM;
  859. goto bail;
  860. }
  861. ipa_rm_ctx->ipa_rm_wq = create_singlethread_workqueue("ipa_rm_wq");
  862. if (!ipa_rm_ctx->ipa_rm_wq) {
  863. IPA_RM_ERR("create workqueue failed\n");
  864. result = -ENOMEM;
  865. goto create_wq_fail;
  866. }
  867. result = ipa_rm_dep_graph_create(&(ipa_rm_ctx->dep_graph));
  868. if (result) {
  869. IPA_RM_ERR("create dependency graph failed\n");
  870. goto graph_alloc_fail;
  871. }
  872. spin_lock_init(&ipa_rm_ctx->ipa_rm_lock);
  873. IPA_RM_DBG("SUCCESS\n");
  874. return 0;
  875. graph_alloc_fail:
  876. destroy_workqueue(ipa_rm_ctx->ipa_rm_wq);
  877. create_wq_fail:
  878. kfree(ipa_rm_ctx);
  879. bail:
  880. return result;
  881. }
  882. /**
  883. * ipa_rm_stat() - print RM stat
  884. * @buf: [in] The user buff used to print
  885. * @size: [in] The size of buf
  886. * Returns: number of bytes used on success, negative on failure
  887. *
  888. * This function is called by ipa_debugfs in order to receive
  889. * a full picture of the current state of the RM
  890. */
  891. int ipa_rm_stat(char *buf, int size)
  892. {
  893. unsigned long flags;
  894. int i, cnt = 0, result = EINVAL;
  895. struct ipa_rm_resource *resource = NULL;
  896. u32 sum_bw_prod = 0;
  897. u32 sum_bw_cons = 0;
  898. if (!buf || size < 0)
  899. return result;
  900. spin_lock_irqsave(&ipa_rm_ctx->ipa_rm_lock, flags);
  901. for (i = 0; i < IPA_RM_RESOURCE_MAX; ++i) {
  902. if (!IPA_RM_RESORCE_IS_PROD(i))
  903. continue;
  904. result = ipa_rm_dep_graph_get_resource(
  905. ipa_rm_ctx->dep_graph,
  906. i,
  907. &resource);
  908. if (!result) {
  909. result = ipa_rm_resource_producer_print_stat(
  910. resource, buf + cnt,
  911. size-cnt);
  912. if (result < 0)
  913. goto bail;
  914. cnt += result;
  915. }
  916. }
  917. for (i = 0; i < IPA_RM_RESOURCE_MAX; i++) {
  918. if (IPA_RM_RESORCE_IS_PROD(i))
  919. sum_bw_prod += ipa_rm_ctx->prof_vote.bw_resources[i];
  920. else
  921. sum_bw_cons += ipa_rm_ctx->prof_vote.bw_resources[i];
  922. }
  923. result = scnprintf(buf + cnt, size - cnt,
  924. "All prod bandwidth: %d, All cons bandwidth: %d\n",
  925. sum_bw_prod, sum_bw_cons);
  926. cnt += result;
  927. result = scnprintf(buf + cnt, size - cnt,
  928. "Voting: voltage %d, bandwidth %d\n",
  929. ipa_rm_ctx->prof_vote.curr_volt,
  930. ipa_rm_ctx->prof_vote.curr_bw);
  931. cnt += result;
  932. result = cnt;
  933. bail:
  934. spin_unlock_irqrestore(&ipa_rm_ctx->ipa_rm_lock, flags);
  935. return result;
  936. }
  937. /**
  938. * ipa_rm_resource_str() - returns string that represent the resource
  939. * @resource_name: [in] resource name
  940. */
  941. const char *ipa_rm_resource_str(enum ipa_rm_resource_name resource_name)
  942. {
  943. if (resource_name < 0 || resource_name >= IPA_RM_RESOURCE_MAX)
  944. return "INVALID RESOURCE";
  945. return resource_name_to_str[resource_name];
  946. };
  947. static void ipa_rm_perf_profile_notify_to_ipa_work(struct work_struct *work)
  948. {
  949. struct ipa_rm_notify_ipa_work_type *notify_work = container_of(work,
  950. struct ipa_rm_notify_ipa_work_type,
  951. work);
  952. int res;
  953. IPA_RM_DBG_LOW("calling to IPA driver. voltage %d bandwidth %d\n",
  954. notify_work->volt, notify_work->bandwidth_mbps);
  955. res = ipa_set_required_perf_profile(notify_work->volt,
  956. notify_work->bandwidth_mbps);
  957. if (res) {
  958. IPA_RM_ERR("ipa_set_required_perf_profile failed %d\n", res);
  959. goto bail;
  960. }
  961. IPA_RM_DBG_LOW("IPA driver notified\n");
  962. bail:
  963. kfree(notify_work);
  964. }
  965. static void ipa_rm_perf_profile_notify_to_ipa(enum ipa_voltage_level volt,
  966. u32 bandwidth)
  967. {
  968. struct ipa_rm_notify_ipa_work_type *work;
  969. work = kzalloc(sizeof(*work), GFP_ATOMIC);
  970. if (!work)
  971. return;
  972. INIT_WORK(&work->work, ipa_rm_perf_profile_notify_to_ipa_work);
  973. work->volt = volt;
  974. work->bandwidth_mbps = bandwidth;
  975. queue_work(ipa_rm_ctx->ipa_rm_wq, &work->work);
  976. }
  977. /**
  978. * ipa_rm_perf_profile_change() - change performance profile vote for resource
  979. * @resource_name: [in] resource name
  980. *
  981. * change bandwidth and voltage vote based on resource state.
  982. */
  983. void ipa_rm_perf_profile_change(enum ipa_rm_resource_name resource_name)
  984. {
  985. enum ipa_voltage_level old_volt;
  986. u32 *bw_ptr;
  987. u32 old_bw;
  988. struct ipa_rm_resource *resource;
  989. int i;
  990. u32 sum_bw_prod = 0;
  991. u32 sum_bw_cons = 0;
  992. IPA_RM_DBG_LOW("%s\n", ipa_rm_resource_str(resource_name));
  993. if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph,
  994. resource_name,
  995. &resource) != 0) {
  996. IPA_RM_ERR("resource does not exists\n");
  997. WARN_ON(1);
  998. return;
  999. }
  1000. old_volt = ipa_rm_ctx->prof_vote.curr_volt;
  1001. old_bw = ipa_rm_ctx->prof_vote.curr_bw;
  1002. bw_ptr = &ipa_rm_ctx->prof_vote.bw_resources[resource_name];
  1003. switch (resource->state) {
  1004. case IPA_RM_GRANTED:
  1005. case IPA_RM_REQUEST_IN_PROGRESS:
  1006. IPA_RM_DBG_LOW("max_bw = %d, needed_bw = %d\n",
  1007. resource->max_bw, resource->needed_bw);
  1008. *bw_ptr = min(resource->max_bw, resource->needed_bw);
  1009. ipa_rm_ctx->prof_vote.volt[resource_name] =
  1010. resource->floor_voltage;
  1011. break;
  1012. case IPA_RM_RELEASE_IN_PROGRESS:
  1013. case IPA_RM_RELEASED:
  1014. *bw_ptr = 0;
  1015. ipa_rm_ctx->prof_vote.volt[resource_name] = 0;
  1016. break;
  1017. default:
  1018. IPA_RM_ERR("unknown state %d\n", resource->state);
  1019. WARN_ON(1);
  1020. return;
  1021. }
  1022. IPA_RM_DBG_LOW("resource bandwidth: %d voltage: %d\n", *bw_ptr,
  1023. resource->floor_voltage);
  1024. ipa_rm_ctx->prof_vote.curr_volt = IPA_VOLTAGE_UNSPECIFIED;
  1025. for (i = 0; i < IPA_RM_RESOURCE_MAX; i++) {
  1026. if (ipa_rm_ctx->prof_vote.volt[i] >
  1027. ipa_rm_ctx->prof_vote.curr_volt) {
  1028. ipa_rm_ctx->prof_vote.curr_volt =
  1029. ipa_rm_ctx->prof_vote.volt[i];
  1030. }
  1031. }
  1032. for (i = 0; i < IPA_RM_RESOURCE_MAX; i++) {
  1033. if (IPA_RM_RESORCE_IS_PROD(i))
  1034. sum_bw_prod += ipa_rm_ctx->prof_vote.bw_resources[i];
  1035. else
  1036. sum_bw_cons += ipa_rm_ctx->prof_vote.bw_resources[i];
  1037. }
  1038. IPA_RM_DBG_LOW("all prod bandwidth: %d all cons bandwidth: %d\n",
  1039. sum_bw_prod, sum_bw_cons);
  1040. ipa_rm_ctx->prof_vote.curr_bw = min(sum_bw_prod, sum_bw_cons);
  1041. if (ipa_rm_ctx->prof_vote.curr_volt == old_volt &&
  1042. ipa_rm_ctx->prof_vote.curr_bw == old_bw) {
  1043. IPA_RM_DBG_LOW("same voting\n");
  1044. return;
  1045. }
  1046. IPA_RM_DBG_LOW("new voting: voltage %d bandwidth %d\n",
  1047. ipa_rm_ctx->prof_vote.curr_volt,
  1048. ipa_rm_ctx->prof_vote.curr_bw);
  1049. ipa_rm_perf_profile_notify_to_ipa(ipa_rm_ctx->prof_vote.curr_volt,
  1050. ipa_rm_ctx->prof_vote.curr_bw);
  1051. return;
  1052. };
  1053. /**
  1054. * ipa_rm_exit() - free all IPA RM resources
  1055. */
  1056. void ipa_rm_exit(void)
  1057. {
  1058. IPA_RM_DBG("ENTER\n");
  1059. ipa_rm_dep_graph_delete(ipa_rm_ctx->dep_graph);
  1060. destroy_workqueue(ipa_rm_ctx->ipa_rm_wq);
  1061. kfree(ipa_rm_ctx);
  1062. ipa_rm_ctx = NULL;
  1063. IPA_RM_DBG("EXIT\n");
  1064. }