cam_sync_synx.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include "cam_sync_synx.h"
  6. /**
  7. * struct cam_synx_obj_row - Synx obj row
  8. */
  9. struct cam_synx_obj_row {
  10. char name[CAM_SYNX_OBJ_NAME_LEN];
  11. uint32_t synx_obj;
  12. enum cam_synx_obj_state state;
  13. cam_sync_callback_for_synx_obj sync_cb;
  14. bool cb_registered_for_sync;
  15. bool sync_signal_synx;
  16. int32_t sync_obj;
  17. };
  18. /**
  19. * struct cam_synx_obj_device - Synx obj device
  20. */
  21. struct cam_synx_obj_device {
  22. struct cam_synx_obj_row rows[CAM_SYNX_MAX_OBJS];
  23. spinlock_t row_spinlocks[CAM_SYNX_MAX_OBJS];
  24. struct synx_session *session_handle;
  25. struct mutex dev_lock;
  26. DECLARE_BITMAP(bitmap, CAM_SYNX_MAX_OBJS);
  27. };
  28. static struct cam_synx_obj_device *g_cam_synx_obj_dev;
  29. static char cam_synx_session_name[64] = "Camera_Generic_Synx_Session";
  30. static int __cam_synx_obj_map_sync_status_util(uint32_t sync_status,
  31. uint32_t *out_synx_status)
  32. {
  33. if (!out_synx_status)
  34. return -EINVAL;
  35. switch (sync_status) {
  36. case CAM_SYNC_STATE_SIGNALED_SUCCESS:
  37. *out_synx_status = SYNX_STATE_SIGNALED_SUCCESS;
  38. break;
  39. case CAM_SYNC_STATE_SIGNALED_CANCEL:
  40. default:
  41. *out_synx_status = SYNX_STATE_SIGNALED_CANCEL;
  42. break;
  43. }
  44. return 0;
  45. }
  46. static int __cam_synx_obj_release(int32_t row_idx)
  47. {
  48. struct cam_synx_obj_row *row = NULL;
  49. spin_lock_bh(&g_cam_synx_obj_dev->row_spinlocks[row_idx]);
  50. row = &g_cam_synx_obj_dev->rows[row_idx];
  51. if (row->state == CAM_SYNX_OBJ_STATE_ACTIVE) {
  52. CAM_WARN(CAM_SYNX,
  53. "Unsignaled synx obj being released name: %s synx_obj:%d",
  54. row->name, row->synx_obj);
  55. synx_signal(g_cam_synx_obj_dev->session_handle, row->synx_obj,
  56. SYNX_STATE_SIGNALED_CANCEL);
  57. }
  58. CAM_DBG(CAM_SYNX,
  59. "Releasing synx_obj: %d[%s] row_idx: %u",
  60. row->synx_obj, row->name, row_idx);
  61. synx_release(g_cam_synx_obj_dev->session_handle, row->synx_obj);
  62. /* deinit row */
  63. memset(row, 0, sizeof(struct cam_synx_obj_row));
  64. clear_bit(row_idx, g_cam_synx_obj_dev->bitmap);
  65. spin_unlock_bh(&g_cam_synx_obj_dev->row_spinlocks[row_idx]);
  66. return 0;
  67. }
  68. static int __cam_synx_obj_find_free_idx(uint32_t *idx)
  69. {
  70. int rc = -ENOMEM;
  71. /* Hold lock to obtain free index */
  72. mutex_lock(&g_cam_synx_obj_dev->dev_lock);
  73. *idx = find_first_zero_bit(g_cam_synx_obj_dev->bitmap, CAM_SYNX_MAX_OBJS);
  74. if (*idx < CAM_SYNX_MAX_OBJS) {
  75. set_bit(*idx, g_cam_synx_obj_dev->bitmap);
  76. rc = 0;
  77. }
  78. mutex_unlock(&g_cam_synx_obj_dev->dev_lock);
  79. if (rc)
  80. CAM_ERR(CAM_SYNX, "No free synx idx");
  81. return rc;
  82. }
  83. static void __cam_synx_obj_init_row(uint32_t idx, const char *name,
  84. uint32_t synx_obj)
  85. {
  86. struct cam_synx_obj_row *row;
  87. spin_lock_bh(&g_cam_synx_obj_dev->row_spinlocks[idx]);
  88. row = &g_cam_synx_obj_dev->rows[idx];
  89. memset(row, 0, sizeof(*row));
  90. row->synx_obj = synx_obj;
  91. row->state = CAM_SYNX_OBJ_STATE_ACTIVE;
  92. strscpy(row->name, name, CAM_SYNX_OBJ_NAME_LEN);
  93. spin_unlock_bh(&g_cam_synx_obj_dev->row_spinlocks[idx]);
  94. }
  95. static int __cam_synx_obj_release_row(int32_t row_idx)
  96. {
  97. if ((row_idx < 0) || (row_idx >= CAM_SYNX_MAX_OBJS)) {
  98. CAM_ERR(CAM_SYNX, "synx row idx: %d is invalid",
  99. row_idx);
  100. return -EINVAL;
  101. }
  102. return __cam_synx_obj_release(row_idx);
  103. }
  104. static void __cam_synx_obj_signal_cb(u32 h_synx, int status, void *data)
  105. {
  106. struct cam_synx_obj_signal_sync_obj signal_sync_obj;
  107. struct cam_synx_obj_row *synx_obj_row = NULL;
  108. if (!data) {
  109. CAM_ERR(CAM_SYNX,
  110. "Invalid data passed to synx obj : %d callback function.",
  111. synx_obj_row->synx_obj);
  112. return;
  113. }
  114. synx_obj_row = (struct cam_synx_obj_row *)data;
  115. /* If this synx obj is signaled by sync obj, skip cb */
  116. if (synx_obj_row->sync_signal_synx)
  117. return;
  118. if (synx_obj_row->synx_obj != h_synx) {
  119. CAM_ERR(CAM_SYNX,
  120. "Synx obj: %d callback does not match synx obj: %d in sync table.",
  121. h_synx, synx_obj_row->synx_obj);
  122. return;
  123. }
  124. if (synx_obj_row->state == CAM_SYNX_OBJ_STATE_INVALID) {
  125. CAM_ERR(CAM_SYNX,
  126. "Synx obj :%d is in invalid state: %d",
  127. synx_obj_row->synx_obj, synx_obj_row->state);
  128. return;
  129. }
  130. CAM_DBG(CAM_SYNX, "Synx obj: %d signaled, signal sync obj: %d",
  131. synx_obj_row->synx_obj, synx_obj_row->sync_obj);
  132. if ((synx_obj_row->cb_registered_for_sync) && (synx_obj_row->sync_cb)) {
  133. signal_sync_obj.synx_obj = synx_obj_row->synx_obj;
  134. switch (status) {
  135. case SYNX_STATE_SIGNALED_SUCCESS:
  136. signal_sync_obj.status = CAM_SYNC_STATE_SIGNALED_SUCCESS;
  137. break;
  138. case SYNX_STATE_SIGNALED_CANCEL:
  139. signal_sync_obj.status = CAM_SYNC_STATE_SIGNALED_CANCEL;
  140. break;
  141. default:
  142. CAM_WARN(CAM_SYNX,
  143. "Synx signal status %d is neither SUCCESS nor CANCEL, custom code?",
  144. status);
  145. signal_sync_obj.status = CAM_SYNC_STATE_SIGNALED_ERROR;
  146. break;
  147. }
  148. synx_obj_row->state = CAM_SYNX_OBJ_STATE_SIGNALED;
  149. synx_obj_row->sync_cb(synx_obj_row->sync_obj, &signal_sync_obj);
  150. }
  151. }
  152. int cam_synx_obj_find_obj_in_table(uint32_t synx_obj, int32_t *idx)
  153. {
  154. int i, rc = -EINVAL;
  155. struct cam_synx_obj_row *row = NULL;
  156. for (i = 0; i < CAM_SYNX_MAX_OBJS; i++) {
  157. spin_lock_bh(&g_cam_synx_obj_dev->row_spinlocks[i]);
  158. row = &g_cam_synx_obj_dev->rows[i];
  159. if ((row->state != CAM_SYNX_OBJ_STATE_INVALID) &&
  160. (row->synx_obj == synx_obj)) {
  161. *idx = i;
  162. spin_unlock_bh(&g_cam_synx_obj_dev->row_spinlocks[i]);
  163. rc = 0;
  164. break;
  165. }
  166. spin_unlock_bh(&g_cam_synx_obj_dev->row_spinlocks[i]);
  167. }
  168. return rc;
  169. }
  170. static int __cam_synx_obj_release_obj(uint32_t synx_obj)
  171. {
  172. int32_t idx;
  173. if (cam_synx_obj_find_obj_in_table(synx_obj, &idx)) {
  174. CAM_ERR(CAM_SYNX, "Failed to find synx obj: %d", synx_obj);
  175. return -EINVAL;
  176. }
  177. return __cam_synx_obj_release(idx);
  178. }
  179. static int __cam_synx_obj_import(const char *name,
  180. struct synx_import_params *params, int32_t *row_idx)
  181. {
  182. int rc = -1;
  183. uint32_t idx;
  184. if (__cam_synx_obj_find_free_idx(&idx))
  185. goto end;
  186. rc = synx_import(g_cam_synx_obj_dev->session_handle, params);
  187. if (rc) {
  188. CAM_ERR(CAM_SYNX, "Synx import failed for fence : %p",
  189. params->indv.fence);
  190. goto free_idx;
  191. }
  192. *row_idx = idx;
  193. __cam_synx_obj_init_row(idx, name, *params->indv.new_h_synx);
  194. CAM_DBG(CAM_SYNX, "Imported synx obj handle: %d[%s] row_idx: %u",
  195. *params->indv.new_h_synx, name, idx);
  196. return rc;
  197. free_idx:
  198. clear_bit(idx, g_cam_synx_obj_dev->bitmap);
  199. end:
  200. return rc;
  201. }
  202. static int __cam_synx_map_generic_flags_to_create(uint32_t generic_flags,
  203. struct synx_create_params *params)
  204. {
  205. if (!params) {
  206. CAM_ERR(CAM_SYNX, "Create parameters missing");
  207. return -EINVAL;
  208. }
  209. /*
  210. * Create Global Always - remove after userspace optimizes and
  211. * determines when global Vs local is needed
  212. */
  213. params->flags |= SYNX_CREATE_GLOBAL_FENCE;
  214. return 0;
  215. }
  216. static int __cam_synx_map_generic_flags_to_import(uint32_t generic_flags,
  217. struct synx_import_indv_params *params)
  218. {
  219. if (!params) {
  220. CAM_ERR(CAM_SYNX, "Import parameters missing");
  221. return -EINVAL;
  222. }
  223. /*
  224. * Create Global Always - remove after userspace optimizes and
  225. * determines when global Vs local is needed
  226. */
  227. params->flags |= SYNX_IMPORT_GLOBAL_FENCE;
  228. return 0;
  229. }
  230. int cam_synx_obj_create(const char *name, uint32_t flags, uint32_t *synx_obj,
  231. int32_t *row_idx)
  232. {
  233. int rc = -1;
  234. uint32_t idx;
  235. struct synx_create_params params;
  236. if (__cam_synx_obj_find_free_idx(&idx))
  237. goto end;
  238. params.fence = NULL;
  239. params.name = name;
  240. params.flags = 0;
  241. params.h_synx = synx_obj;
  242. rc = __cam_synx_map_generic_flags_to_create(flags, &params);
  243. if (rc) {
  244. CAM_ERR(CAM_SYNX, "Failed to generate create flags");
  245. goto free_idx;
  246. }
  247. rc = synx_create(g_cam_synx_obj_dev->session_handle, &params);
  248. if (rc) {
  249. CAM_ERR(CAM_SYNX, "Failed to create synx obj");
  250. goto free_idx;
  251. }
  252. *row_idx = idx;
  253. __cam_synx_obj_init_row(idx, name, *synx_obj);
  254. CAM_DBG(CAM_SYNX, "Created synx obj handle: %d[%s] row_idx: %u",
  255. *synx_obj, name, idx);
  256. return rc;
  257. free_idx:
  258. clear_bit(idx, g_cam_synx_obj_dev->bitmap);
  259. end:
  260. return rc;
  261. }
  262. int cam_synx_obj_import_dma_fence(const char *name, uint32_t flags, void *fence,
  263. uint32_t *synx_obj, int32_t *row_idx)
  264. {
  265. struct synx_import_params params;
  266. if (!fence) {
  267. CAM_ERR(CAM_SYNX,
  268. "Importing DMA fence failed - fence pointer is NULL");
  269. return -EINVAL;
  270. }
  271. params.indv.flags = 0;
  272. params.indv.fence = fence;
  273. params.indv.new_h_synx = synx_obj;
  274. params.type = SYNX_IMPORT_INDV_PARAMS;
  275. params.indv.flags |= SYNX_IMPORT_DMA_FENCE;
  276. if (__cam_synx_map_generic_flags_to_import(flags, &params.indv)) {
  277. CAM_ERR(CAM_SYNX,
  278. "Importing DMA fence failed - invalid synx import flags");
  279. return -EINVAL;
  280. }
  281. return __cam_synx_obj_import(name, &params, row_idx);
  282. }
  283. int cam_synx_obj_internal_signal(int32_t row_idx,
  284. struct cam_synx_obj_signal *signal_synx_obj)
  285. {
  286. int rc = 0;
  287. uint32_t signal_status, synx_obj = 0;
  288. struct cam_synx_obj_row *row = NULL;
  289. if ((row_idx < 0) || (row_idx >= CAM_SYNX_MAX_OBJS)) {
  290. CAM_ERR(CAM_SYNX, "synx obj row idx: %d is invalid",
  291. row_idx);
  292. return -EINVAL;
  293. }
  294. spin_lock_bh(&g_cam_synx_obj_dev->row_spinlocks[row_idx]);
  295. row = &g_cam_synx_obj_dev->rows[row_idx];
  296. /* Ensures sync obj cb is not invoked */
  297. row->sync_signal_synx = true;
  298. synx_obj = row->synx_obj;
  299. if (row->state == CAM_SYNX_OBJ_STATE_SIGNALED) {
  300. spin_unlock_bh(&g_cam_synx_obj_dev->row_spinlocks[row_idx]);
  301. CAM_WARN(CAM_SYNX, "synx obj fd: %d already in signaled state",
  302. signal_synx_obj->synx_obj);
  303. return 0;
  304. }
  305. rc = __cam_synx_obj_map_sync_status_util(signal_synx_obj->status,
  306. &signal_status);
  307. if (rc) {
  308. CAM_WARN(CAM_SYNX,
  309. "Signaling undefined status: %d for synx obj: %d",
  310. signal_synx_obj->status,
  311. signal_synx_obj->synx_obj);
  312. }
  313. row->state = CAM_SYNX_OBJ_STATE_SIGNALED;
  314. spin_unlock_bh(&g_cam_synx_obj_dev->row_spinlocks[row_idx]);
  315. rc = synx_signal(g_cam_synx_obj_dev->session_handle,
  316. signal_synx_obj->synx_obj, signal_status);
  317. if (rc) {
  318. CAM_WARN(CAM_SYNX, "synx obj: %d already signaled rc: %d",
  319. synx_obj, rc);
  320. goto end;
  321. }
  322. CAM_DBG(CAM_SYNX, "synx obj: %d signaled with status: %d rc: %d",
  323. signal_synx_obj->synx_obj, signal_status, rc);
  324. end:
  325. return rc;
  326. }
  327. int cam_synx_obj_release(struct cam_synx_obj_release_params *release_params)
  328. {
  329. if (release_params->use_row_idx)
  330. return __cam_synx_obj_release_row(release_params->u.synx_row_idx);
  331. else
  332. return __cam_synx_obj_release_obj(release_params->u.synx_obj);
  333. }
  334. int cam_synx_obj_signal_obj(struct cam_synx_obj_signal *signal_synx_obj)
  335. {
  336. int rc = 0;
  337. uint32_t idx, signal_status = 0, synx_obj = 0;
  338. struct cam_synx_obj_row *row = NULL;
  339. rc = cam_synx_obj_find_obj_in_table(
  340. signal_synx_obj->synx_obj, &idx);
  341. if (rc) {
  342. CAM_ERR(CAM_SYNX, "Failed to find synx obj: %d",
  343. signal_synx_obj->synx_obj);
  344. return -EINVAL;
  345. }
  346. spin_lock_bh(&g_cam_synx_obj_dev->row_spinlocks[idx]);
  347. row = &g_cam_synx_obj_dev->rows[idx];
  348. synx_obj = row->synx_obj;
  349. if (row->state == CAM_SYNX_OBJ_STATE_SIGNALED) {
  350. spin_unlock_bh(&g_cam_synx_obj_dev->row_spinlocks[idx]);
  351. CAM_WARN(CAM_SYNX, "synx obj: %d already in signaled state",
  352. signal_synx_obj->synx_obj);
  353. return 0;
  354. }
  355. rc = __cam_synx_obj_map_sync_status_util(signal_synx_obj->status,
  356. &signal_status);
  357. if (rc) {
  358. CAM_WARN(CAM_SYNX,
  359. "Signaling undefined sync status: %d for synx obj: %d",
  360. signal_synx_obj->status,
  361. signal_synx_obj->synx_obj);
  362. }
  363. row->state = CAM_SYNX_OBJ_STATE_SIGNALED;
  364. spin_unlock_bh(&g_cam_synx_obj_dev->row_spinlocks[idx]);
  365. rc = synx_signal(g_cam_synx_obj_dev->session_handle,
  366. signal_synx_obj->synx_obj, signal_status);
  367. if (rc) {
  368. CAM_WARN(CAM_SYNX, "synx obj: %d already signaled rc: %d",
  369. synx_obj, rc);
  370. goto end;
  371. }
  372. CAM_DBG(CAM_SYNX, "synx obj: %d signaled with status: %d rc: %d",
  373. signal_synx_obj->synx_obj, signal_status, rc);
  374. end:
  375. return rc;
  376. }
  377. int cam_synx_obj_register_cb(int32_t *sync_obj, int32_t row_idx,
  378. cam_sync_callback_for_synx_obj sync_cb)
  379. {
  380. int rc = 0;
  381. uint32_t synx_obj = 0;
  382. struct cam_synx_obj_row *row = NULL;
  383. struct synx_callback_params cb_params;
  384. if (!sync_obj || !sync_cb) {
  385. CAM_ERR(CAM_SYNX, "Invalid args sync_obj: %p sync_cb: %p",
  386. sync_obj, sync_cb);
  387. return -EINVAL;
  388. }
  389. if ((row_idx < 0) || (row_idx >= CAM_SYNX_MAX_OBJS)) {
  390. CAM_ERR(CAM_SYNX, "synx obj idx: %d is invalid",
  391. row_idx);
  392. return -EINVAL;
  393. }
  394. spin_lock_bh(&g_cam_synx_obj_dev->row_spinlocks[row_idx]);
  395. row = &g_cam_synx_obj_dev->rows[row_idx];
  396. synx_obj = row->synx_obj;
  397. if (row->state != CAM_SYNX_OBJ_STATE_ACTIVE) {
  398. CAM_ERR(CAM_SYNX,
  399. "synx obj at idx: %d handle: %d is not active, current state: %d",
  400. row_idx, row->synx_obj, row->state);
  401. rc = -EINVAL;
  402. spin_unlock_bh(&g_cam_synx_obj_dev->row_spinlocks[row_idx]);
  403. goto end;
  404. }
  405. /**
  406. * If the cb is already registered, return
  407. */
  408. if (row->cb_registered_for_sync) {
  409. CAM_WARN(CAM_SYNX,
  410. "synx obj at idx: %d handle: %d has already registered a cb for sync: %d",
  411. row_idx, row->synx_obj, row->sync_obj);
  412. spin_unlock_bh(&g_cam_synx_obj_dev->row_spinlocks[row_idx]);
  413. goto end;
  414. }
  415. row->sync_cb = sync_cb;
  416. row->sync_obj = *sync_obj;
  417. row->cb_registered_for_sync = true;
  418. cb_params.userdata = row;
  419. cb_params.cancel_cb_func = NULL;
  420. cb_params.h_synx = synx_obj;
  421. cb_params.cb_func = __cam_synx_obj_signal_cb;
  422. spin_unlock_bh(&g_cam_synx_obj_dev->row_spinlocks[row_idx]);
  423. rc = synx_async_wait(g_cam_synx_obj_dev->session_handle, &cb_params);
  424. if (rc) {
  425. CAM_ERR(CAM_SYNX,
  426. "Failed to register cb for synx obj: %d rc: %d",
  427. synx_obj, rc);
  428. goto end;
  429. }
  430. CAM_DBG(CAM_SYNX,
  431. "CB successfully registered for synx obj: %d for sync_obj: %d",
  432. synx_obj, *sync_obj);
  433. end:
  434. return rc;
  435. }
  436. int __cam_synx_init_session(void)
  437. {
  438. struct synx_queue_desc queue_desc;
  439. struct synx_initialization_params params;
  440. params.name = cam_synx_session_name;
  441. params.ptr = &queue_desc;
  442. params.flags = SYNX_INIT_MAX;
  443. params.id = SYNX_CLIENT_NATIVE;
  444. g_cam_synx_obj_dev->session_handle = synx_initialize(&params);
  445. if (!g_cam_synx_obj_dev->session_handle) {
  446. CAM_ERR(CAM_SYNX, "Synx session initialization failed");
  447. return -EINVAL;
  448. }
  449. CAM_DBG(CAM_SYNX, "Synx session initialized: %p",
  450. g_cam_synx_obj_dev->session_handle);
  451. return 0;
  452. }
  453. void cam_synx_obj_close(void)
  454. {
  455. int i, rc = 0;
  456. struct cam_synx_obj_row *row = NULL;
  457. struct synx_callback_params cb_params;
  458. mutex_lock(&g_cam_synx_obj_dev->dev_lock);
  459. for (i = 0; i < CAM_SYNX_MAX_OBJS; i++) {
  460. row = &g_cam_synx_obj_dev->rows[i];
  461. if (row->state == CAM_SYNX_OBJ_STATE_INVALID)
  462. continue;
  463. CAM_DBG(CAM_SYNX, "Releasing synx_obj: %d[%s]",
  464. row->synx_obj, row->name);
  465. /* If registered for cb, remove cb */
  466. if (row->cb_registered_for_sync) {
  467. cb_params.userdata = row;
  468. cb_params.cancel_cb_func = NULL;
  469. cb_params.h_synx = row->synx_obj;
  470. cb_params.cb_func = __cam_synx_obj_signal_cb;
  471. rc = synx_cancel_async_wait(
  472. g_cam_synx_obj_dev->session_handle,
  473. &cb_params);
  474. if (rc) {
  475. CAM_WARN(CAM_SYNX,
  476. "Registered callback could not be canceled for synx obj : %d",
  477. cb_params.h_synx);
  478. }
  479. }
  480. /* Signal and release the synx obj */
  481. if (row->state != CAM_SYNX_OBJ_STATE_SIGNALED)
  482. synx_signal(g_cam_synx_obj_dev->session_handle,
  483. row->synx_obj, SYNX_STATE_SIGNALED_CANCEL);
  484. synx_release(g_cam_synx_obj_dev->session_handle,
  485. row->synx_obj);
  486. memset(row, 0, sizeof(struct cam_synx_obj_row));
  487. clear_bit(i, g_cam_synx_obj_dev->bitmap);
  488. }
  489. mutex_unlock(&g_cam_synx_obj_dev->dev_lock);
  490. CAM_DBG(CAM_SYNX, "Close on Camera SYNX driver");
  491. }
  492. int cam_synx_obj_driver_init(void)
  493. {
  494. int i;
  495. g_cam_synx_obj_dev = kzalloc(sizeof(struct cam_synx_obj_device), GFP_KERNEL);
  496. if (!g_cam_synx_obj_dev)
  497. return -ENOMEM;
  498. if (__cam_synx_init_session())
  499. goto deinit_driver;
  500. mutex_init(&g_cam_synx_obj_dev->dev_lock);
  501. for (i = 0; i < CAM_SYNX_MAX_OBJS; i++)
  502. spin_lock_init(&g_cam_synx_obj_dev->row_spinlocks[i]);
  503. memset(&g_cam_synx_obj_dev->rows, 0, sizeof(g_cam_synx_obj_dev->rows));
  504. memset(&g_cam_synx_obj_dev->bitmap, 0, sizeof(g_cam_synx_obj_dev->bitmap));
  505. bitmap_zero(g_cam_synx_obj_dev->bitmap, CAM_SYNX_MAX_OBJS);
  506. CAM_DBG(CAM_SYNX, "Camera synx obj driver initialized");
  507. return 0;
  508. deinit_driver:
  509. CAM_ERR(CAM_SYNX, "Camera synx obj driver initialization failed");
  510. kfree(g_cam_synx_obj_dev);
  511. g_cam_synx_obj_dev = NULL;
  512. return -EINVAL;
  513. }
  514. void cam_synx_obj_driver_deinit(void)
  515. {
  516. int rc;
  517. if (g_cam_synx_obj_dev->session_handle) {
  518. rc = synx_uninitialize(g_cam_synx_obj_dev->session_handle);
  519. if (rc) {
  520. CAM_ERR(CAM_SYNX,
  521. "Synx failed to uninitialize session: %p, rc: %d",
  522. g_cam_synx_obj_dev->session_handle, rc);
  523. }
  524. }
  525. kfree(g_cam_synx_obj_dev);
  526. g_cam_synx_obj_dev = NULL;
  527. CAM_DBG(CAM_SYNX, "Camera synx obj driver deinitialized");
  528. }