qcom_pd_mapper.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Qualcomm Protection Domain mapper
  4. *
  5. * Copyright (c) 2023 Linaro Ltd.
  6. */
  7. #include <linux/auxiliary_bus.h>
  8. #include <linux/kernel.h>
  9. #include <linux/mod_devicetable.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/refcount.h>
  13. #include <linux/slab.h>
  14. #include <linux/soc/qcom/qmi.h>
  15. #include "pdr_internal.h"
  16. #define SERVREG_QMI_VERSION 0x101
  17. #define SERVREG_QMI_INSTANCE 0
  18. #define TMS_SERVREG_SERVICE "tms/servreg"
  19. struct qcom_pdm_domain_data {
  20. const char *domain;
  21. u32 instance_id;
  22. /* NULL-terminated array */
  23. const char * services[];
  24. };
  25. struct qcom_pdm_domain {
  26. struct list_head list;
  27. const char *name;
  28. u32 instance_id;
  29. };
  30. struct qcom_pdm_service {
  31. struct list_head list;
  32. struct list_head domains;
  33. const char *name;
  34. };
  35. struct qcom_pdm_data {
  36. refcount_t refcnt;
  37. struct qmi_handle handle;
  38. struct list_head services;
  39. };
  40. static DEFINE_MUTEX(qcom_pdm_mutex); /* protects __qcom_pdm_data */
  41. static struct qcom_pdm_data *__qcom_pdm_data;
  42. static struct qcom_pdm_service *qcom_pdm_find(struct qcom_pdm_data *data,
  43. const char *name)
  44. {
  45. struct qcom_pdm_service *service;
  46. list_for_each_entry(service, &data->services, list) {
  47. if (!strcmp(service->name, name))
  48. return service;
  49. }
  50. return NULL;
  51. }
  52. static int qcom_pdm_add_service_domain(struct qcom_pdm_data *data,
  53. const char *service_name,
  54. const char *domain_name,
  55. u32 instance_id)
  56. {
  57. struct qcom_pdm_service *service;
  58. struct qcom_pdm_domain *domain;
  59. service = qcom_pdm_find(data, service_name);
  60. if (service) {
  61. list_for_each_entry(domain, &service->domains, list) {
  62. if (!strcmp(domain->name, domain_name))
  63. return -EBUSY;
  64. }
  65. } else {
  66. service = kzalloc_obj(*service);
  67. if (!service)
  68. return -ENOMEM;
  69. INIT_LIST_HEAD(&service->domains);
  70. service->name = service_name;
  71. list_add_tail(&service->list, &data->services);
  72. }
  73. domain = kzalloc_obj(*domain);
  74. if (!domain) {
  75. if (list_empty(&service->domains)) {
  76. list_del(&service->list);
  77. kfree(service);
  78. }
  79. return -ENOMEM;
  80. }
  81. domain->name = domain_name;
  82. domain->instance_id = instance_id;
  83. list_add_tail(&domain->list, &service->domains);
  84. return 0;
  85. }
  86. static int qcom_pdm_add_domain(struct qcom_pdm_data *data,
  87. const struct qcom_pdm_domain_data *domain)
  88. {
  89. int ret;
  90. int i;
  91. ret = qcom_pdm_add_service_domain(data,
  92. TMS_SERVREG_SERVICE,
  93. domain->domain,
  94. domain->instance_id);
  95. if (ret)
  96. return ret;
  97. for (i = 0; domain->services[i]; i++) {
  98. ret = qcom_pdm_add_service_domain(data,
  99. domain->services[i],
  100. domain->domain,
  101. domain->instance_id);
  102. if (ret)
  103. return ret;
  104. }
  105. return 0;
  106. }
  107. static void qcom_pdm_free_domains(struct qcom_pdm_data *data)
  108. {
  109. struct qcom_pdm_service *service, *tservice;
  110. struct qcom_pdm_domain *domain, *tdomain;
  111. list_for_each_entry_safe(service, tservice, &data->services, list) {
  112. list_for_each_entry_safe(domain, tdomain, &service->domains, list) {
  113. list_del(&domain->list);
  114. kfree(domain);
  115. }
  116. list_del(&service->list);
  117. kfree(service);
  118. }
  119. }
  120. static void qcom_pdm_get_domain_list(struct qmi_handle *qmi,
  121. struct sockaddr_qrtr *sq,
  122. struct qmi_txn *txn,
  123. const void *decoded)
  124. {
  125. struct qcom_pdm_data *data = container_of(qmi, struct qcom_pdm_data, handle);
  126. const struct servreg_get_domain_list_req *req = decoded;
  127. struct servreg_get_domain_list_resp *rsp;
  128. struct qcom_pdm_service *service;
  129. u32 offset;
  130. int ret;
  131. rsp = kzalloc_obj(*rsp);
  132. if (!rsp)
  133. return;
  134. offset = req->domain_offset_valid ? req->domain_offset : 0;
  135. rsp->resp.result = QMI_RESULT_SUCCESS_V01;
  136. rsp->resp.error = QMI_ERR_NONE_V01;
  137. rsp->db_rev_count_valid = true;
  138. rsp->db_rev_count = 1;
  139. rsp->total_domains_valid = true;
  140. rsp->total_domains = 0;
  141. mutex_lock(&qcom_pdm_mutex);
  142. service = qcom_pdm_find(data, req->service_name);
  143. if (service) {
  144. struct qcom_pdm_domain *domain;
  145. rsp->domain_list_valid = true;
  146. rsp->domain_list_len = 0;
  147. list_for_each_entry(domain, &service->domains, list) {
  148. u32 i = rsp->total_domains++;
  149. if (i >= offset && i < SERVREG_DOMAIN_LIST_LENGTH) {
  150. u32 j = rsp->domain_list_len++;
  151. strscpy(rsp->domain_list[j].name, domain->name,
  152. sizeof(rsp->domain_list[i].name));
  153. rsp->domain_list[j].instance = domain->instance_id;
  154. pr_debug("PDM: found %s / %d\n", domain->name,
  155. domain->instance_id);
  156. }
  157. }
  158. }
  159. pr_debug("PDM: service '%s' offset %d returning %d domains (of %d)\n", req->service_name,
  160. req->domain_offset_valid ? req->domain_offset : -1, rsp->domain_list_len, rsp->total_domains);
  161. ret = qmi_send_response(qmi, sq, txn, SERVREG_GET_DOMAIN_LIST_REQ,
  162. SERVREG_GET_DOMAIN_LIST_RESP_MAX_LEN,
  163. servreg_get_domain_list_resp_ei, rsp);
  164. if (ret)
  165. pr_err("Error sending servreg response: %d\n", ret);
  166. mutex_unlock(&qcom_pdm_mutex);
  167. kfree(rsp);
  168. }
  169. static void qcom_pdm_pfr(struct qmi_handle *qmi,
  170. struct sockaddr_qrtr *sq,
  171. struct qmi_txn *txn,
  172. const void *decoded)
  173. {
  174. const struct servreg_loc_pfr_req *req = decoded;
  175. struct servreg_loc_pfr_resp rsp = {};
  176. int ret;
  177. pr_warn_ratelimited("PDM: service '%s' crash: '%s'\n", req->service, req->reason);
  178. rsp.rsp.result = QMI_RESULT_SUCCESS_V01;
  179. rsp.rsp.error = QMI_ERR_NONE_V01;
  180. ret = qmi_send_response(qmi, sq, txn, SERVREG_LOC_PFR_REQ,
  181. SERVREG_LOC_PFR_RESP_MAX_LEN,
  182. servreg_loc_pfr_resp_ei, &rsp);
  183. if (ret)
  184. pr_err("Error sending servreg response: %d\n", ret);
  185. }
  186. static const struct qmi_msg_handler qcom_pdm_msg_handlers[] = {
  187. {
  188. .type = QMI_REQUEST,
  189. .msg_id = SERVREG_GET_DOMAIN_LIST_REQ,
  190. .ei = servreg_get_domain_list_req_ei,
  191. .decoded_size = sizeof(struct servreg_get_domain_list_req),
  192. .fn = qcom_pdm_get_domain_list,
  193. },
  194. {
  195. .type = QMI_REQUEST,
  196. .msg_id = SERVREG_LOC_PFR_REQ,
  197. .ei = servreg_loc_pfr_req_ei,
  198. .decoded_size = sizeof(struct servreg_loc_pfr_req),
  199. .fn = qcom_pdm_pfr,
  200. },
  201. { },
  202. };
  203. static const struct qcom_pdm_domain_data adsp_audio_pd = {
  204. .domain = "msm/adsp/audio_pd",
  205. .instance_id = 74,
  206. .services = {
  207. "avs/audio",
  208. NULL,
  209. },
  210. };
  211. static const struct qcom_pdm_domain_data adsp_charger_pd = {
  212. .domain = "msm/adsp/charger_pd",
  213. .instance_id = 74,
  214. .services = { NULL },
  215. };
  216. static const struct qcom_pdm_domain_data adsp_root_pd = {
  217. .domain = "msm/adsp/root_pd",
  218. .instance_id = 74,
  219. .services = { NULL },
  220. };
  221. static const struct qcom_pdm_domain_data adsp_root_pd_pdr = {
  222. .domain = "msm/adsp/root_pd",
  223. .instance_id = 74,
  224. .services = {
  225. "tms/pdr_enabled",
  226. NULL,
  227. },
  228. };
  229. static const struct qcom_pdm_domain_data adsp_sensor_pd = {
  230. .domain = "msm/adsp/sensor_pd",
  231. .instance_id = 74,
  232. .services = { NULL },
  233. };
  234. static const struct qcom_pdm_domain_data msm8996_adsp_audio_pd = {
  235. .domain = "msm/adsp/audio_pd",
  236. .instance_id = 4,
  237. .services = { NULL },
  238. };
  239. static const struct qcom_pdm_domain_data msm8996_adsp_root_pd = {
  240. .domain = "msm/adsp/root_pd",
  241. .instance_id = 4,
  242. .services = { NULL },
  243. };
  244. static const struct qcom_pdm_domain_data cdsp_root_pd = {
  245. .domain = "msm/cdsp/root_pd",
  246. .instance_id = 76,
  247. .services = { NULL },
  248. };
  249. static const struct qcom_pdm_domain_data slpi_root_pd = {
  250. .domain = "msm/slpi/root_pd",
  251. .instance_id = 90,
  252. .services = { NULL },
  253. };
  254. static const struct qcom_pdm_domain_data slpi_sensor_pd = {
  255. .domain = "msm/slpi/sensor_pd",
  256. .instance_id = 90,
  257. .services = { NULL },
  258. };
  259. static const struct qcom_pdm_domain_data mpss_root_pd = {
  260. .domain = "msm/modem/root_pd",
  261. .instance_id = 180,
  262. .services = {
  263. NULL,
  264. },
  265. };
  266. static const struct qcom_pdm_domain_data mpss_root_pd_gps = {
  267. .domain = "msm/modem/root_pd",
  268. .instance_id = 180,
  269. .services = {
  270. "gps/gps_service",
  271. NULL,
  272. },
  273. };
  274. static const struct qcom_pdm_domain_data mpss_root_pd_gps_pdr = {
  275. .domain = "msm/modem/root_pd",
  276. .instance_id = 180,
  277. .services = {
  278. "gps/gps_service",
  279. "tms/pdr_enabled",
  280. NULL,
  281. },
  282. };
  283. static const struct qcom_pdm_domain_data msm8996_mpss_root_pd = {
  284. .domain = "msm/modem/root_pd",
  285. .instance_id = 100,
  286. .services = { NULL },
  287. };
  288. static const struct qcom_pdm_domain_data mpss_wlan_pd = {
  289. .domain = "msm/modem/wlan_pd",
  290. .instance_id = 180,
  291. .services = {
  292. "kernel/elf_loader",
  293. "wlan/fw",
  294. NULL,
  295. },
  296. };
  297. static const struct qcom_pdm_domain_data *kaanapali_domains[] = {
  298. &adsp_audio_pd,
  299. &adsp_root_pd,
  300. &adsp_sensor_pd,
  301. &cdsp_root_pd,
  302. &mpss_root_pd_gps,
  303. NULL,
  304. };
  305. static const struct qcom_pdm_domain_data *msm8996_domains[] = {
  306. &msm8996_adsp_audio_pd,
  307. &msm8996_adsp_root_pd,
  308. &msm8996_mpss_root_pd,
  309. NULL,
  310. };
  311. static const struct qcom_pdm_domain_data *msm8998_domains[] = {
  312. &mpss_root_pd,
  313. &mpss_wlan_pd,
  314. NULL,
  315. };
  316. static const struct qcom_pdm_domain_data *qcm2290_domains[] = {
  317. &adsp_audio_pd,
  318. &adsp_root_pd,
  319. &adsp_sensor_pd,
  320. &mpss_root_pd_gps,
  321. &mpss_wlan_pd,
  322. NULL,
  323. };
  324. static const struct qcom_pdm_domain_data *qcs404_domains[] = {
  325. &adsp_audio_pd,
  326. &adsp_root_pd,
  327. &adsp_sensor_pd,
  328. &cdsp_root_pd,
  329. &mpss_root_pd,
  330. &mpss_wlan_pd,
  331. NULL,
  332. };
  333. static const struct qcom_pdm_domain_data *sc7180_domains[] = {
  334. &adsp_audio_pd,
  335. &adsp_root_pd_pdr,
  336. &adsp_sensor_pd,
  337. &mpss_root_pd_gps_pdr,
  338. &mpss_wlan_pd,
  339. NULL,
  340. };
  341. static const struct qcom_pdm_domain_data *sc7280_domains[] = {
  342. &adsp_audio_pd,
  343. &adsp_root_pd_pdr,
  344. &adsp_charger_pd,
  345. &adsp_sensor_pd,
  346. &cdsp_root_pd,
  347. &mpss_root_pd_gps_pdr,
  348. NULL,
  349. };
  350. static const struct qcom_pdm_domain_data *sc8180x_domains[] = {
  351. &adsp_audio_pd,
  352. &adsp_root_pd,
  353. &adsp_charger_pd,
  354. &cdsp_root_pd,
  355. &mpss_root_pd_gps,
  356. &mpss_wlan_pd,
  357. NULL,
  358. };
  359. static const struct qcom_pdm_domain_data *sc8280xp_domains[] = {
  360. &adsp_audio_pd,
  361. &adsp_root_pd_pdr,
  362. &adsp_charger_pd,
  363. &cdsp_root_pd,
  364. NULL,
  365. };
  366. /* Unlike SDM660, SDM630/636 lack CDSP */
  367. static const struct qcom_pdm_domain_data *sdm630_domains[] = {
  368. &adsp_audio_pd,
  369. &adsp_root_pd,
  370. &adsp_sensor_pd,
  371. &mpss_root_pd,
  372. &mpss_wlan_pd,
  373. NULL,
  374. };
  375. static const struct qcom_pdm_domain_data *sdm660_domains[] = {
  376. &adsp_audio_pd,
  377. &adsp_root_pd,
  378. &adsp_sensor_pd,
  379. &cdsp_root_pd,
  380. &mpss_root_pd,
  381. &mpss_wlan_pd,
  382. NULL,
  383. };
  384. static const struct qcom_pdm_domain_data *sdm670_domains[] = {
  385. &adsp_audio_pd,
  386. &adsp_root_pd,
  387. &cdsp_root_pd,
  388. &mpss_root_pd,
  389. &mpss_wlan_pd,
  390. NULL,
  391. };
  392. static const struct qcom_pdm_domain_data *sdm845_domains[] = {
  393. &adsp_audio_pd,
  394. &adsp_root_pd,
  395. &cdsp_root_pd,
  396. &mpss_root_pd,
  397. &mpss_wlan_pd,
  398. &slpi_root_pd,
  399. &slpi_sensor_pd,
  400. NULL,
  401. };
  402. static const struct qcom_pdm_domain_data *sm6115_domains[] = {
  403. &adsp_audio_pd,
  404. &adsp_root_pd,
  405. &adsp_sensor_pd,
  406. &cdsp_root_pd,
  407. &mpss_root_pd_gps,
  408. &mpss_wlan_pd,
  409. NULL,
  410. };
  411. static const struct qcom_pdm_domain_data *sm6350_domains[] = {
  412. &adsp_audio_pd,
  413. &adsp_root_pd,
  414. &adsp_sensor_pd,
  415. &cdsp_root_pd,
  416. &mpss_wlan_pd,
  417. NULL,
  418. };
  419. static const struct qcom_pdm_domain_data *sm7150_domains[] = {
  420. &adsp_audio_pd,
  421. &adsp_root_pd,
  422. &adsp_sensor_pd,
  423. &cdsp_root_pd,
  424. &mpss_root_pd_gps,
  425. &mpss_wlan_pd,
  426. NULL,
  427. };
  428. static const struct qcom_pdm_domain_data *sm8150_domains[] = {
  429. &adsp_audio_pd,
  430. &adsp_root_pd,
  431. &cdsp_root_pd,
  432. &mpss_root_pd_gps,
  433. &mpss_wlan_pd,
  434. NULL,
  435. };
  436. static const struct qcom_pdm_domain_data *sm8250_domains[] = {
  437. &adsp_audio_pd,
  438. &adsp_root_pd,
  439. &cdsp_root_pd,
  440. &slpi_root_pd,
  441. &slpi_sensor_pd,
  442. NULL,
  443. };
  444. static const struct qcom_pdm_domain_data *sm8350_domains[] = {
  445. &adsp_audio_pd,
  446. &adsp_root_pd_pdr,
  447. &adsp_charger_pd,
  448. &cdsp_root_pd,
  449. &mpss_root_pd_gps,
  450. &slpi_root_pd,
  451. &slpi_sensor_pd,
  452. NULL,
  453. };
  454. static const struct qcom_pdm_domain_data *sm8550_domains[] = {
  455. &adsp_audio_pd,
  456. &adsp_root_pd,
  457. &adsp_charger_pd,
  458. &adsp_sensor_pd,
  459. &cdsp_root_pd,
  460. &mpss_root_pd_gps,
  461. NULL,
  462. };
  463. static const struct qcom_pdm_domain_data *x1e80100_domains[] = {
  464. &adsp_audio_pd,
  465. &adsp_root_pd,
  466. &adsp_charger_pd,
  467. &adsp_sensor_pd,
  468. &cdsp_root_pd,
  469. NULL,
  470. };
  471. static const struct of_device_id qcom_pdm_domains[] __maybe_unused = {
  472. { .compatible = "qcom,apq8016", .data = NULL, },
  473. { .compatible = "qcom,apq8064", .data = NULL, },
  474. { .compatible = "qcom,apq8074", .data = NULL, },
  475. { .compatible = "qcom,apq8084", .data = NULL, },
  476. { .compatible = "qcom,apq8096", .data = msm8996_domains, },
  477. { .compatible = "qcom,kaanapali", .data = kaanapali_domains, },
  478. { .compatible = "qcom,msm8226", .data = NULL, },
  479. { .compatible = "qcom,msm8909", .data = NULL, },
  480. { .compatible = "qcom,msm8916", .data = NULL, },
  481. { .compatible = "qcom,msm8939", .data = NULL, },
  482. { .compatible = "qcom,msm8974", .data = NULL, },
  483. { .compatible = "qcom,msm8996", .data = msm8996_domains, },
  484. { .compatible = "qcom,msm8998", .data = msm8998_domains, },
  485. { .compatible = "qcom,qcm2290", .data = qcm2290_domains, },
  486. { .compatible = "qcom,qcm6490", .data = sc7280_domains, },
  487. { .compatible = "qcom,qcs404", .data = qcs404_domains, },
  488. { .compatible = "qcom,sc7180", .data = sc7180_domains, },
  489. { .compatible = "qcom,sc7280", .data = sc7280_domains, },
  490. { .compatible = "qcom,sc8180x", .data = sc8180x_domains, },
  491. { .compatible = "qcom,sc8280xp", .data = sc8280xp_domains, },
  492. { .compatible = "qcom,sdm630", .data = sdm630_domains, },
  493. { .compatible = "qcom,sdm636", .data = sdm630_domains, },
  494. { .compatible = "qcom,sda660", .data = sdm660_domains, },
  495. { .compatible = "qcom,sdm660", .data = sdm660_domains, },
  496. { .compatible = "qcom,sdm670", .data = sdm670_domains, },
  497. { .compatible = "qcom,sdm845", .data = sdm845_domains, },
  498. { .compatible = "qcom,sm4250", .data = sm6115_domains, },
  499. { .compatible = "qcom,sm6115", .data = sm6115_domains, },
  500. { .compatible = "qcom,sm6350", .data = sm6350_domains, },
  501. { .compatible = "qcom,sm7150", .data = sm7150_domains, },
  502. { .compatible = "qcom,sm7225", .data = sm6350_domains, },
  503. { .compatible = "qcom,sm7325", .data = sc7280_domains, },
  504. { .compatible = "qcom,sm8150", .data = sm8150_domains, },
  505. { .compatible = "qcom,sm8250", .data = sm8250_domains, },
  506. { .compatible = "qcom,sm8350", .data = sm8350_domains, },
  507. { .compatible = "qcom,sm8450", .data = sm8350_domains, },
  508. { .compatible = "qcom,sm8550", .data = sm8550_domains, },
  509. { .compatible = "qcom,sm8650", .data = sm8550_domains, },
  510. { .compatible = "qcom,sm8750", .data = sm8550_domains, },
  511. { .compatible = "qcom,x1e80100", .data = x1e80100_domains, },
  512. { .compatible = "qcom,x1p42100", .data = x1e80100_domains, },
  513. {},
  514. };
  515. static void qcom_pdm_stop(struct qcom_pdm_data *data)
  516. {
  517. qcom_pdm_free_domains(data);
  518. /* The server is removed automatically */
  519. qmi_handle_release(&data->handle);
  520. kfree(data);
  521. }
  522. static struct qcom_pdm_data *qcom_pdm_start(void)
  523. {
  524. const struct qcom_pdm_domain_data * const *domains;
  525. const struct of_device_id *match;
  526. struct qcom_pdm_data *data;
  527. struct device_node *root;
  528. int ret, i;
  529. root = of_find_node_by_path("/");
  530. if (!root)
  531. return ERR_PTR(-ENODEV);
  532. match = of_match_node(qcom_pdm_domains, root);
  533. of_node_put(root);
  534. if (!match) {
  535. pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
  536. return ERR_PTR(-ENODEV);
  537. }
  538. domains = match->data;
  539. if (!domains) {
  540. pr_debug("PDM: no domains\n");
  541. return ERR_PTR(-ENODEV);
  542. }
  543. data = kzalloc_obj(*data);
  544. if (!data)
  545. return ERR_PTR(-ENOMEM);
  546. INIT_LIST_HEAD(&data->services);
  547. ret = qmi_handle_init(&data->handle, SERVREG_GET_DOMAIN_LIST_REQ_MAX_LEN,
  548. NULL, qcom_pdm_msg_handlers);
  549. if (ret) {
  550. kfree(data);
  551. return ERR_PTR(ret);
  552. }
  553. refcount_set(&data->refcnt, 1);
  554. for (i = 0; domains[i]; i++) {
  555. ret = qcom_pdm_add_domain(data, domains[i]);
  556. if (ret)
  557. goto err_stop;
  558. }
  559. ret = qmi_add_server(&data->handle, SERVREG_LOCATOR_SERVICE,
  560. SERVREG_QMI_VERSION, SERVREG_QMI_INSTANCE);
  561. if (ret) {
  562. pr_err("PDM: error adding server %d\n", ret);
  563. goto err_stop;
  564. }
  565. return data;
  566. err_stop:
  567. qcom_pdm_stop(data);
  568. return ERR_PTR(ret);
  569. }
  570. static int qcom_pdm_probe(struct auxiliary_device *auxdev,
  571. const struct auxiliary_device_id *id)
  572. {
  573. struct qcom_pdm_data *data;
  574. int ret = 0;
  575. mutex_lock(&qcom_pdm_mutex);
  576. if (!__qcom_pdm_data) {
  577. data = qcom_pdm_start();
  578. if (IS_ERR(data))
  579. ret = PTR_ERR(data);
  580. else
  581. __qcom_pdm_data = data;
  582. } else {
  583. refcount_inc(&__qcom_pdm_data->refcnt);
  584. }
  585. auxiliary_set_drvdata(auxdev, __qcom_pdm_data);
  586. mutex_unlock(&qcom_pdm_mutex);
  587. return ret;
  588. }
  589. static void qcom_pdm_remove(struct auxiliary_device *auxdev)
  590. {
  591. struct qcom_pdm_data *data;
  592. data = auxiliary_get_drvdata(auxdev);
  593. if (!data)
  594. return;
  595. if (refcount_dec_and_mutex_lock(&data->refcnt, &qcom_pdm_mutex)) {
  596. __qcom_pdm_data = NULL;
  597. qcom_pdm_stop(data);
  598. mutex_unlock(&qcom_pdm_mutex);
  599. }
  600. }
  601. static const struct auxiliary_device_id qcom_pdm_table[] = {
  602. { .name = "qcom_common.pd-mapper" },
  603. {},
  604. };
  605. MODULE_DEVICE_TABLE(auxiliary, qcom_pdm_table);
  606. static struct auxiliary_driver qcom_pdm_drv = {
  607. .name = "qcom-pdm-mapper",
  608. .id_table = qcom_pdm_table,
  609. .probe = qcom_pdm_probe,
  610. .remove = qcom_pdm_remove,
  611. };
  612. module_auxiliary_driver(qcom_pdm_drv);
  613. MODULE_DESCRIPTION("Qualcomm Protection Domain Mapper");
  614. MODULE_LICENSE("GPL");