knav_qmss_queue.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  1. /*
  2. * Keystone Queue Manager subsystem driver
  3. *
  4. * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
  5. * Authors: Sandeep Nair <sandeep_n@ti.com>
  6. * Cyril Chemparathy <cyril@ti.com>
  7. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. */
  18. #include <linux/debugfs.h>
  19. #include <linux/dma-mapping.h>
  20. #include <linux/firmware.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/io.h>
  23. #include <linux/module.h>
  24. #include <linux/of_address.h>
  25. #include <linux/of_device.h>
  26. #include <linux/of_irq.h>
  27. #include <linux/pm_runtime.h>
  28. #include <linux/slab.h>
  29. #include <linux/soc/ti/knav_qmss.h>
  30. #include "knav_qmss.h"
  31. static struct knav_device *kdev;
  32. static DEFINE_MUTEX(knav_dev_lock);
  33. /* Queue manager register indices in DTS */
  34. #define KNAV_QUEUE_PEEK_REG_INDEX 0
  35. #define KNAV_QUEUE_STATUS_REG_INDEX 1
  36. #define KNAV_QUEUE_CONFIG_REG_INDEX 2
  37. #define KNAV_QUEUE_REGION_REG_INDEX 3
  38. #define KNAV_QUEUE_PUSH_REG_INDEX 4
  39. #define KNAV_QUEUE_POP_REG_INDEX 5
  40. /* Queue manager register indices in DTS for QMSS in K2G NAVSS.
  41. * There are no status and vbusm push registers on this version
  42. * of QMSS. Push registers are same as pop, So all indices above 1
  43. * are to be re-defined
  44. */
  45. #define KNAV_L_QUEUE_CONFIG_REG_INDEX 1
  46. #define KNAV_L_QUEUE_REGION_REG_INDEX 2
  47. #define KNAV_L_QUEUE_PUSH_REG_INDEX 3
  48. /* PDSP register indices in DTS */
  49. #define KNAV_QUEUE_PDSP_IRAM_REG_INDEX 0
  50. #define KNAV_QUEUE_PDSP_REGS_REG_INDEX 1
  51. #define KNAV_QUEUE_PDSP_INTD_REG_INDEX 2
  52. #define KNAV_QUEUE_PDSP_CMD_REG_INDEX 3
  53. #define knav_queue_idx_to_inst(kdev, idx) \
  54. (kdev->instances + (idx << kdev->inst_shift))
  55. #define for_each_handle_rcu(qh, inst) \
  56. list_for_each_entry_rcu(qh, &inst->handles, list)
  57. #define for_each_instance(idx, inst, kdev) \
  58. for (idx = 0, inst = kdev->instances; \
  59. idx < (kdev)->num_queues_in_use; \
  60. idx++, inst = knav_queue_idx_to_inst(kdev, idx))
  61. /* All firmware file names end up here. List the firmware file names below.
  62. * Newest followed by older ones. Search is done from start of the array
  63. * until a firmware file is found.
  64. */
  65. const char *knav_acc_firmwares[] = {"ks2_qmss_pdsp_acc48.bin"};
  66. static bool device_ready;
  67. bool knav_qmss_device_ready(void)
  68. {
  69. return device_ready;
  70. }
  71. EXPORT_SYMBOL_GPL(knav_qmss_device_ready);
  72. /**
  73. * knav_queue_notify: qmss queue notfier call
  74. *
  75. * @inst: qmss queue instance like accumulator
  76. */
  77. void knav_queue_notify(struct knav_queue_inst *inst)
  78. {
  79. struct knav_queue *qh;
  80. if (!inst)
  81. return;
  82. rcu_read_lock();
  83. for_each_handle_rcu(qh, inst) {
  84. if (atomic_read(&qh->notifier_enabled) <= 0)
  85. continue;
  86. if (WARN_ON(!qh->notifier_fn))
  87. continue;
  88. this_cpu_inc(qh->stats->notifies);
  89. qh->notifier_fn(qh->notifier_fn_arg);
  90. }
  91. rcu_read_unlock();
  92. }
  93. EXPORT_SYMBOL_GPL(knav_queue_notify);
  94. static irqreturn_t knav_queue_int_handler(int irq, void *_instdata)
  95. {
  96. struct knav_queue_inst *inst = _instdata;
  97. knav_queue_notify(inst);
  98. return IRQ_HANDLED;
  99. }
  100. static int knav_queue_setup_irq(struct knav_range_info *range,
  101. struct knav_queue_inst *inst)
  102. {
  103. unsigned queue = inst->id - range->queue_base;
  104. int ret = 0, irq;
  105. if (range->flags & RANGE_HAS_IRQ) {
  106. irq = range->irqs[queue].irq;
  107. ret = request_irq(irq, knav_queue_int_handler, 0,
  108. inst->irq_name, inst);
  109. if (ret)
  110. return ret;
  111. disable_irq(irq);
  112. if (range->irqs[queue].cpu_mask) {
  113. ret = irq_set_affinity_hint(irq, range->irqs[queue].cpu_mask);
  114. if (ret) {
  115. dev_warn(range->kdev->dev,
  116. "Failed to set IRQ affinity\n");
  117. return ret;
  118. }
  119. }
  120. }
  121. return ret;
  122. }
  123. static void knav_queue_free_irq(struct knav_queue_inst *inst)
  124. {
  125. struct knav_range_info *range = inst->range;
  126. unsigned queue = inst->id - inst->range->queue_base;
  127. int irq;
  128. if (range->flags & RANGE_HAS_IRQ) {
  129. irq = range->irqs[queue].irq;
  130. irq_set_affinity_hint(irq, NULL);
  131. free_irq(irq, inst);
  132. }
  133. }
  134. static inline bool knav_queue_is_busy(struct knav_queue_inst *inst)
  135. {
  136. return !list_empty(&inst->handles);
  137. }
  138. static inline bool knav_queue_is_reserved(struct knav_queue_inst *inst)
  139. {
  140. return inst->range->flags & RANGE_RESERVED;
  141. }
  142. static inline bool knav_queue_is_shared(struct knav_queue_inst *inst)
  143. {
  144. struct knav_queue *tmp;
  145. rcu_read_lock();
  146. for_each_handle_rcu(tmp, inst) {
  147. if (tmp->flags & KNAV_QUEUE_SHARED) {
  148. rcu_read_unlock();
  149. return true;
  150. }
  151. }
  152. rcu_read_unlock();
  153. return false;
  154. }
  155. static inline bool knav_queue_match_type(struct knav_queue_inst *inst,
  156. unsigned type)
  157. {
  158. if ((type == KNAV_QUEUE_QPEND) &&
  159. (inst->range->flags & RANGE_HAS_IRQ)) {
  160. return true;
  161. } else if ((type == KNAV_QUEUE_ACC) &&
  162. (inst->range->flags & RANGE_HAS_ACCUMULATOR)) {
  163. return true;
  164. } else if ((type == KNAV_QUEUE_GP) &&
  165. !(inst->range->flags &
  166. (RANGE_HAS_ACCUMULATOR | RANGE_HAS_IRQ))) {
  167. return true;
  168. }
  169. return false;
  170. }
  171. static inline struct knav_queue_inst *
  172. knav_queue_match_id_to_inst(struct knav_device *kdev, unsigned id)
  173. {
  174. struct knav_queue_inst *inst;
  175. int idx;
  176. for_each_instance(idx, inst, kdev) {
  177. if (inst->id == id)
  178. return inst;
  179. }
  180. return NULL;
  181. }
  182. static inline struct knav_queue_inst *knav_queue_find_by_id(int id)
  183. {
  184. if (kdev->base_id <= id &&
  185. kdev->base_id + kdev->num_queues > id) {
  186. id -= kdev->base_id;
  187. return knav_queue_match_id_to_inst(kdev, id);
  188. }
  189. return NULL;
  190. }
  191. static struct knav_queue *__knav_queue_open(struct knav_queue_inst *inst,
  192. const char *name, unsigned flags)
  193. {
  194. struct knav_queue *qh;
  195. unsigned id;
  196. int ret = 0;
  197. qh = devm_kzalloc(inst->kdev->dev, sizeof(*qh), GFP_KERNEL);
  198. if (!qh)
  199. return ERR_PTR(-ENOMEM);
  200. qh->stats = alloc_percpu(struct knav_queue_stats);
  201. if (!qh->stats) {
  202. ret = -ENOMEM;
  203. goto err;
  204. }
  205. qh->flags = flags;
  206. qh->inst = inst;
  207. id = inst->id - inst->qmgr->start_queue;
  208. qh->reg_push = &inst->qmgr->reg_push[id];
  209. qh->reg_pop = &inst->qmgr->reg_pop[id];
  210. qh->reg_peek = &inst->qmgr->reg_peek[id];
  211. /* first opener? */
  212. if (!knav_queue_is_busy(inst)) {
  213. struct knav_range_info *range = inst->range;
  214. inst->name = kstrndup(name, KNAV_NAME_SIZE - 1, GFP_KERNEL);
  215. if (range->ops && range->ops->open_queue)
  216. ret = range->ops->open_queue(range, inst, flags);
  217. if (ret)
  218. goto err;
  219. }
  220. list_add_tail_rcu(&qh->list, &inst->handles);
  221. return qh;
  222. err:
  223. if (qh->stats)
  224. free_percpu(qh->stats);
  225. devm_kfree(inst->kdev->dev, qh);
  226. return ERR_PTR(ret);
  227. }
  228. static struct knav_queue *
  229. knav_queue_open_by_id(const char *name, unsigned id, unsigned flags)
  230. {
  231. struct knav_queue_inst *inst;
  232. struct knav_queue *qh;
  233. mutex_lock(&knav_dev_lock);
  234. qh = ERR_PTR(-ENODEV);
  235. inst = knav_queue_find_by_id(id);
  236. if (!inst)
  237. goto unlock_ret;
  238. qh = ERR_PTR(-EEXIST);
  239. if (!(flags & KNAV_QUEUE_SHARED) && knav_queue_is_busy(inst))
  240. goto unlock_ret;
  241. qh = ERR_PTR(-EBUSY);
  242. if ((flags & KNAV_QUEUE_SHARED) &&
  243. (knav_queue_is_busy(inst) && !knav_queue_is_shared(inst)))
  244. goto unlock_ret;
  245. qh = __knav_queue_open(inst, name, flags);
  246. unlock_ret:
  247. mutex_unlock(&knav_dev_lock);
  248. return qh;
  249. }
  250. static struct knav_queue *knav_queue_open_by_type(const char *name,
  251. unsigned type, unsigned flags)
  252. {
  253. struct knav_queue_inst *inst;
  254. struct knav_queue *qh = ERR_PTR(-EINVAL);
  255. int idx;
  256. mutex_lock(&knav_dev_lock);
  257. for_each_instance(idx, inst, kdev) {
  258. if (knav_queue_is_reserved(inst))
  259. continue;
  260. if (!knav_queue_match_type(inst, type))
  261. continue;
  262. if (knav_queue_is_busy(inst))
  263. continue;
  264. qh = __knav_queue_open(inst, name, flags);
  265. goto unlock_ret;
  266. }
  267. unlock_ret:
  268. mutex_unlock(&knav_dev_lock);
  269. return qh;
  270. }
  271. static void knav_queue_set_notify(struct knav_queue_inst *inst, bool enabled)
  272. {
  273. struct knav_range_info *range = inst->range;
  274. if (range->ops && range->ops->set_notify)
  275. range->ops->set_notify(range, inst, enabled);
  276. }
  277. static int knav_queue_enable_notifier(struct knav_queue *qh)
  278. {
  279. struct knav_queue_inst *inst = qh->inst;
  280. bool first;
  281. if (WARN_ON(!qh->notifier_fn))
  282. return -EINVAL;
  283. /* Adjust the per handle notifier count */
  284. first = (atomic_inc_return(&qh->notifier_enabled) == 1);
  285. if (!first)
  286. return 0; /* nothing to do */
  287. /* Now adjust the per instance notifier count */
  288. first = (atomic_inc_return(&inst->num_notifiers) == 1);
  289. if (first)
  290. knav_queue_set_notify(inst, true);
  291. return 0;
  292. }
  293. static int knav_queue_disable_notifier(struct knav_queue *qh)
  294. {
  295. struct knav_queue_inst *inst = qh->inst;
  296. bool last;
  297. last = (atomic_dec_return(&qh->notifier_enabled) == 0);
  298. if (!last)
  299. return 0; /* nothing to do */
  300. last = (atomic_dec_return(&inst->num_notifiers) == 0);
  301. if (last)
  302. knav_queue_set_notify(inst, false);
  303. return 0;
  304. }
  305. static int knav_queue_set_notifier(struct knav_queue *qh,
  306. struct knav_queue_notify_config *cfg)
  307. {
  308. knav_queue_notify_fn old_fn = qh->notifier_fn;
  309. if (!cfg)
  310. return -EINVAL;
  311. if (!(qh->inst->range->flags & (RANGE_HAS_ACCUMULATOR | RANGE_HAS_IRQ)))
  312. return -ENOTSUPP;
  313. if (!cfg->fn && old_fn)
  314. knav_queue_disable_notifier(qh);
  315. qh->notifier_fn = cfg->fn;
  316. qh->notifier_fn_arg = cfg->fn_arg;
  317. if (cfg->fn && !old_fn)
  318. knav_queue_enable_notifier(qh);
  319. return 0;
  320. }
  321. static int knav_gp_set_notify(struct knav_range_info *range,
  322. struct knav_queue_inst *inst,
  323. bool enabled)
  324. {
  325. unsigned queue;
  326. if (range->flags & RANGE_HAS_IRQ) {
  327. queue = inst->id - range->queue_base;
  328. if (enabled)
  329. enable_irq(range->irqs[queue].irq);
  330. else
  331. disable_irq_nosync(range->irqs[queue].irq);
  332. }
  333. return 0;
  334. }
  335. static int knav_gp_open_queue(struct knav_range_info *range,
  336. struct knav_queue_inst *inst, unsigned flags)
  337. {
  338. return knav_queue_setup_irq(range, inst);
  339. }
  340. static int knav_gp_close_queue(struct knav_range_info *range,
  341. struct knav_queue_inst *inst)
  342. {
  343. knav_queue_free_irq(inst);
  344. return 0;
  345. }
  346. struct knav_range_ops knav_gp_range_ops = {
  347. .set_notify = knav_gp_set_notify,
  348. .open_queue = knav_gp_open_queue,
  349. .close_queue = knav_gp_close_queue,
  350. };
  351. static int knav_queue_get_count(void *qhandle)
  352. {
  353. struct knav_queue *qh = qhandle;
  354. struct knav_queue_inst *inst = qh->inst;
  355. return readl_relaxed(&qh->reg_peek[0].entry_count) +
  356. atomic_read(&inst->desc_count);
  357. }
  358. static void knav_queue_debug_show_instance(struct seq_file *s,
  359. struct knav_queue_inst *inst)
  360. {
  361. struct knav_device *kdev = inst->kdev;
  362. struct knav_queue *qh;
  363. int cpu = 0;
  364. int pushes = 0;
  365. int pops = 0;
  366. int push_errors = 0;
  367. int pop_errors = 0;
  368. int notifies = 0;
  369. if (!knav_queue_is_busy(inst))
  370. return;
  371. seq_printf(s, "\tqueue id %d (%s)\n",
  372. kdev->base_id + inst->id, inst->name);
  373. for_each_handle_rcu(qh, inst) {
  374. for_each_possible_cpu(cpu) {
  375. pushes += per_cpu_ptr(qh->stats, cpu)->pushes;
  376. pops += per_cpu_ptr(qh->stats, cpu)->pops;
  377. push_errors += per_cpu_ptr(qh->stats, cpu)->push_errors;
  378. pop_errors += per_cpu_ptr(qh->stats, cpu)->pop_errors;
  379. notifies += per_cpu_ptr(qh->stats, cpu)->notifies;
  380. }
  381. seq_printf(s, "\t\thandle %p: pushes %8d, pops %8d, count %8d, notifies %8d, push errors %8d, pop errors %8d\n",
  382. qh,
  383. pushes,
  384. pops,
  385. knav_queue_get_count(qh),
  386. notifies,
  387. push_errors,
  388. pop_errors);
  389. }
  390. }
  391. static int knav_queue_debug_show(struct seq_file *s, void *v)
  392. {
  393. struct knav_queue_inst *inst;
  394. int idx;
  395. mutex_lock(&knav_dev_lock);
  396. seq_printf(s, "%s: %u-%u\n",
  397. dev_name(kdev->dev), kdev->base_id,
  398. kdev->base_id + kdev->num_queues - 1);
  399. for_each_instance(idx, inst, kdev)
  400. knav_queue_debug_show_instance(s, inst);
  401. mutex_unlock(&knav_dev_lock);
  402. return 0;
  403. }
  404. static int knav_queue_debug_open(struct inode *inode, struct file *file)
  405. {
  406. return single_open(file, knav_queue_debug_show, NULL);
  407. }
  408. static const struct file_operations knav_queue_debug_ops = {
  409. .open = knav_queue_debug_open,
  410. .read = seq_read,
  411. .llseek = seq_lseek,
  412. .release = single_release,
  413. };
  414. static inline int knav_queue_pdsp_wait(u32 * __iomem addr, unsigned timeout,
  415. u32 flags)
  416. {
  417. unsigned long end;
  418. u32 val = 0;
  419. end = jiffies + msecs_to_jiffies(timeout);
  420. while (time_after(end, jiffies)) {
  421. val = readl_relaxed(addr);
  422. if (flags)
  423. val &= flags;
  424. if (!val)
  425. break;
  426. cpu_relax();
  427. }
  428. return val ? -ETIMEDOUT : 0;
  429. }
  430. static int knav_queue_flush(struct knav_queue *qh)
  431. {
  432. struct knav_queue_inst *inst = qh->inst;
  433. unsigned id = inst->id - inst->qmgr->start_queue;
  434. atomic_set(&inst->desc_count, 0);
  435. writel_relaxed(0, &inst->qmgr->reg_push[id].ptr_size_thresh);
  436. return 0;
  437. }
  438. /**
  439. * knav_queue_open() - open a hardware queue
  440. * @name - name to give the queue handle
  441. * @id - desired queue number if any or specifes the type
  442. * of queue
  443. * @flags - the following flags are applicable to queues:
  444. * KNAV_QUEUE_SHARED - allow the queue to be shared. Queues are
  445. * exclusive by default.
  446. * Subsequent attempts to open a shared queue should
  447. * also have this flag.
  448. *
  449. * Returns a handle to the open hardware queue if successful. Use IS_ERR()
  450. * to check the returned value for error codes.
  451. */
  452. void *knav_queue_open(const char *name, unsigned id,
  453. unsigned flags)
  454. {
  455. struct knav_queue *qh = ERR_PTR(-EINVAL);
  456. switch (id) {
  457. case KNAV_QUEUE_QPEND:
  458. case KNAV_QUEUE_ACC:
  459. case KNAV_QUEUE_GP:
  460. qh = knav_queue_open_by_type(name, id, flags);
  461. break;
  462. default:
  463. qh = knav_queue_open_by_id(name, id, flags);
  464. break;
  465. }
  466. return qh;
  467. }
  468. EXPORT_SYMBOL_GPL(knav_queue_open);
  469. /**
  470. * knav_queue_close() - close a hardware queue handle
  471. * @qh - handle to close
  472. */
  473. void knav_queue_close(void *qhandle)
  474. {
  475. struct knav_queue *qh = qhandle;
  476. struct knav_queue_inst *inst = qh->inst;
  477. while (atomic_read(&qh->notifier_enabled) > 0)
  478. knav_queue_disable_notifier(qh);
  479. mutex_lock(&knav_dev_lock);
  480. list_del_rcu(&qh->list);
  481. mutex_unlock(&knav_dev_lock);
  482. synchronize_rcu();
  483. if (!knav_queue_is_busy(inst)) {
  484. struct knav_range_info *range = inst->range;
  485. if (range->ops && range->ops->close_queue)
  486. range->ops->close_queue(range, inst);
  487. }
  488. free_percpu(qh->stats);
  489. devm_kfree(inst->kdev->dev, qh);
  490. }
  491. EXPORT_SYMBOL_GPL(knav_queue_close);
  492. /**
  493. * knav_queue_device_control() - Perform control operations on a queue
  494. * @qh - queue handle
  495. * @cmd - control commands
  496. * @arg - command argument
  497. *
  498. * Returns 0 on success, errno otherwise.
  499. */
  500. int knav_queue_device_control(void *qhandle, enum knav_queue_ctrl_cmd cmd,
  501. unsigned long arg)
  502. {
  503. struct knav_queue *qh = qhandle;
  504. struct knav_queue_notify_config *cfg;
  505. int ret;
  506. switch ((int)cmd) {
  507. case KNAV_QUEUE_GET_ID:
  508. ret = qh->inst->kdev->base_id + qh->inst->id;
  509. break;
  510. case KNAV_QUEUE_FLUSH:
  511. ret = knav_queue_flush(qh);
  512. break;
  513. case KNAV_QUEUE_SET_NOTIFIER:
  514. cfg = (void *)arg;
  515. ret = knav_queue_set_notifier(qh, cfg);
  516. break;
  517. case KNAV_QUEUE_ENABLE_NOTIFY:
  518. ret = knav_queue_enable_notifier(qh);
  519. break;
  520. case KNAV_QUEUE_DISABLE_NOTIFY:
  521. ret = knav_queue_disable_notifier(qh);
  522. break;
  523. case KNAV_QUEUE_GET_COUNT:
  524. ret = knav_queue_get_count(qh);
  525. break;
  526. default:
  527. ret = -ENOTSUPP;
  528. break;
  529. }
  530. return ret;
  531. }
  532. EXPORT_SYMBOL_GPL(knav_queue_device_control);
  533. /**
  534. * knav_queue_push() - push data (or descriptor) to the tail of a queue
  535. * @qh - hardware queue handle
  536. * @data - data to push
  537. * @size - size of data to push
  538. * @flags - can be used to pass additional information
  539. *
  540. * Returns 0 on success, errno otherwise.
  541. */
  542. int knav_queue_push(void *qhandle, dma_addr_t dma,
  543. unsigned size, unsigned flags)
  544. {
  545. struct knav_queue *qh = qhandle;
  546. u32 val;
  547. val = (u32)dma | ((size / 16) - 1);
  548. writel_relaxed(val, &qh->reg_push[0].ptr_size_thresh);
  549. this_cpu_inc(qh->stats->pushes);
  550. return 0;
  551. }
  552. EXPORT_SYMBOL_GPL(knav_queue_push);
  553. /**
  554. * knav_queue_pop() - pop data (or descriptor) from the head of a queue
  555. * @qh - hardware queue handle
  556. * @size - (optional) size of the data pop'ed.
  557. *
  558. * Returns a DMA address on success, 0 on failure.
  559. */
  560. dma_addr_t knav_queue_pop(void *qhandle, unsigned *size)
  561. {
  562. struct knav_queue *qh = qhandle;
  563. struct knav_queue_inst *inst = qh->inst;
  564. dma_addr_t dma;
  565. u32 val, idx;
  566. /* are we accumulated? */
  567. if (inst->descs) {
  568. if (unlikely(atomic_dec_return(&inst->desc_count) < 0)) {
  569. atomic_inc(&inst->desc_count);
  570. return 0;
  571. }
  572. idx = atomic_inc_return(&inst->desc_head);
  573. idx &= ACC_DESCS_MASK;
  574. val = inst->descs[idx];
  575. } else {
  576. val = readl_relaxed(&qh->reg_pop[0].ptr_size_thresh);
  577. if (unlikely(!val))
  578. return 0;
  579. }
  580. dma = val & DESC_PTR_MASK;
  581. if (size)
  582. *size = ((val & DESC_SIZE_MASK) + 1) * 16;
  583. this_cpu_inc(qh->stats->pops);
  584. return dma;
  585. }
  586. EXPORT_SYMBOL_GPL(knav_queue_pop);
  587. /* carve out descriptors and push into queue */
  588. static void kdesc_fill_pool(struct knav_pool *pool)
  589. {
  590. struct knav_region *region;
  591. int i;
  592. region = pool->region;
  593. pool->desc_size = region->desc_size;
  594. for (i = 0; i < pool->num_desc; i++) {
  595. int index = pool->region_offset + i;
  596. dma_addr_t dma_addr;
  597. unsigned dma_size;
  598. dma_addr = region->dma_start + (region->desc_size * index);
  599. dma_size = ALIGN(pool->desc_size, SMP_CACHE_BYTES);
  600. dma_sync_single_for_device(pool->dev, dma_addr, dma_size,
  601. DMA_TO_DEVICE);
  602. knav_queue_push(pool->queue, dma_addr, dma_size, 0);
  603. }
  604. }
  605. /* pop out descriptors and close the queue */
  606. static void kdesc_empty_pool(struct knav_pool *pool)
  607. {
  608. dma_addr_t dma;
  609. unsigned size;
  610. void *desc;
  611. int i;
  612. if (!pool->queue)
  613. return;
  614. for (i = 0;; i++) {
  615. dma = knav_queue_pop(pool->queue, &size);
  616. if (!dma)
  617. break;
  618. desc = knav_pool_desc_dma_to_virt(pool, dma);
  619. if (!desc) {
  620. dev_dbg(pool->kdev->dev,
  621. "couldn't unmap desc, continuing\n");
  622. continue;
  623. }
  624. }
  625. WARN_ON(i != pool->num_desc);
  626. knav_queue_close(pool->queue);
  627. }
  628. /* Get the DMA address of a descriptor */
  629. dma_addr_t knav_pool_desc_virt_to_dma(void *ph, void *virt)
  630. {
  631. struct knav_pool *pool = ph;
  632. return pool->region->dma_start + (virt - pool->region->virt_start);
  633. }
  634. EXPORT_SYMBOL_GPL(knav_pool_desc_virt_to_dma);
  635. void *knav_pool_desc_dma_to_virt(void *ph, dma_addr_t dma)
  636. {
  637. struct knav_pool *pool = ph;
  638. return pool->region->virt_start + (dma - pool->region->dma_start);
  639. }
  640. EXPORT_SYMBOL_GPL(knav_pool_desc_dma_to_virt);
  641. /**
  642. * knav_pool_create() - Create a pool of descriptors
  643. * @name - name to give the pool handle
  644. * @num_desc - numbers of descriptors in the pool
  645. * @region_id - QMSS region id from which the descriptors are to be
  646. * allocated.
  647. *
  648. * Returns a pool handle on success.
  649. * Use IS_ERR_OR_NULL() to identify error values on return.
  650. */
  651. void *knav_pool_create(const char *name,
  652. int num_desc, int region_id)
  653. {
  654. struct knav_region *reg_itr, *region = NULL;
  655. struct knav_pool *pool, *pi;
  656. struct list_head *node;
  657. unsigned last_offset;
  658. bool slot_found;
  659. int ret;
  660. if (!kdev)
  661. return ERR_PTR(-EPROBE_DEFER);
  662. if (!kdev->dev)
  663. return ERR_PTR(-ENODEV);
  664. pool = devm_kzalloc(kdev->dev, sizeof(*pool), GFP_KERNEL);
  665. if (!pool) {
  666. dev_err(kdev->dev, "out of memory allocating pool\n");
  667. return ERR_PTR(-ENOMEM);
  668. }
  669. for_each_region(kdev, reg_itr) {
  670. if (reg_itr->id != region_id)
  671. continue;
  672. region = reg_itr;
  673. break;
  674. }
  675. if (!region) {
  676. dev_err(kdev->dev, "region-id(%d) not found\n", region_id);
  677. ret = -EINVAL;
  678. goto err;
  679. }
  680. pool->queue = knav_queue_open(name, KNAV_QUEUE_GP, 0);
  681. if (IS_ERR_OR_NULL(pool->queue)) {
  682. dev_err(kdev->dev,
  683. "failed to open queue for pool(%s), error %ld\n",
  684. name, PTR_ERR(pool->queue));
  685. ret = PTR_ERR(pool->queue);
  686. goto err;
  687. }
  688. pool->name = kstrndup(name, KNAV_NAME_SIZE - 1, GFP_KERNEL);
  689. pool->kdev = kdev;
  690. pool->dev = kdev->dev;
  691. mutex_lock(&knav_dev_lock);
  692. if (num_desc > (region->num_desc - region->used_desc)) {
  693. dev_err(kdev->dev, "out of descs in region(%d) for pool(%s)\n",
  694. region_id, name);
  695. ret = -ENOMEM;
  696. goto err_unlock;
  697. }
  698. /* Region maintains a sorted (by region offset) list of pools
  699. * use the first free slot which is large enough to accomodate
  700. * the request
  701. */
  702. last_offset = 0;
  703. slot_found = false;
  704. node = &region->pools;
  705. list_for_each_entry(pi, &region->pools, region_inst) {
  706. if ((pi->region_offset - last_offset) >= num_desc) {
  707. slot_found = true;
  708. break;
  709. }
  710. last_offset = pi->region_offset + pi->num_desc;
  711. }
  712. node = &pi->region_inst;
  713. if (slot_found) {
  714. pool->region = region;
  715. pool->num_desc = num_desc;
  716. pool->region_offset = last_offset;
  717. region->used_desc += num_desc;
  718. list_add_tail(&pool->list, &kdev->pools);
  719. list_add_tail(&pool->region_inst, node);
  720. } else {
  721. dev_err(kdev->dev, "pool(%s) create failed: fragmented desc pool in region(%d)\n",
  722. name, region_id);
  723. ret = -ENOMEM;
  724. goto err_unlock;
  725. }
  726. mutex_unlock(&knav_dev_lock);
  727. kdesc_fill_pool(pool);
  728. return pool;
  729. err_unlock:
  730. mutex_unlock(&knav_dev_lock);
  731. err:
  732. kfree(pool->name);
  733. devm_kfree(kdev->dev, pool);
  734. return ERR_PTR(ret);
  735. }
  736. EXPORT_SYMBOL_GPL(knav_pool_create);
  737. /**
  738. * knav_pool_destroy() - Free a pool of descriptors
  739. * @pool - pool handle
  740. */
  741. void knav_pool_destroy(void *ph)
  742. {
  743. struct knav_pool *pool = ph;
  744. if (!pool)
  745. return;
  746. if (!pool->region)
  747. return;
  748. kdesc_empty_pool(pool);
  749. mutex_lock(&knav_dev_lock);
  750. pool->region->used_desc -= pool->num_desc;
  751. list_del(&pool->region_inst);
  752. list_del(&pool->list);
  753. mutex_unlock(&knav_dev_lock);
  754. kfree(pool->name);
  755. devm_kfree(kdev->dev, pool);
  756. }
  757. EXPORT_SYMBOL_GPL(knav_pool_destroy);
  758. /**
  759. * knav_pool_desc_get() - Get a descriptor from the pool
  760. * @pool - pool handle
  761. *
  762. * Returns descriptor from the pool.
  763. */
  764. void *knav_pool_desc_get(void *ph)
  765. {
  766. struct knav_pool *pool = ph;
  767. dma_addr_t dma;
  768. unsigned size;
  769. void *data;
  770. dma = knav_queue_pop(pool->queue, &size);
  771. if (unlikely(!dma))
  772. return ERR_PTR(-ENOMEM);
  773. data = knav_pool_desc_dma_to_virt(pool, dma);
  774. return data;
  775. }
  776. EXPORT_SYMBOL_GPL(knav_pool_desc_get);
  777. /**
  778. * knav_pool_desc_put() - return a descriptor to the pool
  779. * @pool - pool handle
  780. */
  781. void knav_pool_desc_put(void *ph, void *desc)
  782. {
  783. struct knav_pool *pool = ph;
  784. dma_addr_t dma;
  785. dma = knav_pool_desc_virt_to_dma(pool, desc);
  786. knav_queue_push(pool->queue, dma, pool->region->desc_size, 0);
  787. }
  788. EXPORT_SYMBOL_GPL(knav_pool_desc_put);
  789. /**
  790. * knav_pool_desc_map() - Map descriptor for DMA transfer
  791. * @pool - pool handle
  792. * @desc - address of descriptor to map
  793. * @size - size of descriptor to map
  794. * @dma - DMA address return pointer
  795. * @dma_sz - adjusted return pointer
  796. *
  797. * Returns 0 on success, errno otherwise.
  798. */
  799. int knav_pool_desc_map(void *ph, void *desc, unsigned size,
  800. dma_addr_t *dma, unsigned *dma_sz)
  801. {
  802. struct knav_pool *pool = ph;
  803. *dma = knav_pool_desc_virt_to_dma(pool, desc);
  804. size = min(size, pool->region->desc_size);
  805. size = ALIGN(size, SMP_CACHE_BYTES);
  806. *dma_sz = size;
  807. dma_sync_single_for_device(pool->dev, *dma, size, DMA_TO_DEVICE);
  808. /* Ensure the descriptor reaches to the memory */
  809. __iowmb();
  810. return 0;
  811. }
  812. EXPORT_SYMBOL_GPL(knav_pool_desc_map);
  813. /**
  814. * knav_pool_desc_unmap() - Unmap descriptor after DMA transfer
  815. * @pool - pool handle
  816. * @dma - DMA address of descriptor to unmap
  817. * @dma_sz - size of descriptor to unmap
  818. *
  819. * Returns descriptor address on success, Use IS_ERR_OR_NULL() to identify
  820. * error values on return.
  821. */
  822. void *knav_pool_desc_unmap(void *ph, dma_addr_t dma, unsigned dma_sz)
  823. {
  824. struct knav_pool *pool = ph;
  825. unsigned desc_sz;
  826. void *desc;
  827. desc_sz = min(dma_sz, pool->region->desc_size);
  828. desc = knav_pool_desc_dma_to_virt(pool, dma);
  829. dma_sync_single_for_cpu(pool->dev, dma, desc_sz, DMA_FROM_DEVICE);
  830. prefetch(desc);
  831. return desc;
  832. }
  833. EXPORT_SYMBOL_GPL(knav_pool_desc_unmap);
  834. /**
  835. * knav_pool_count() - Get the number of descriptors in pool.
  836. * @pool - pool handle
  837. * Returns number of elements in the pool.
  838. */
  839. int knav_pool_count(void *ph)
  840. {
  841. struct knav_pool *pool = ph;
  842. return knav_queue_get_count(pool->queue);
  843. }
  844. EXPORT_SYMBOL_GPL(knav_pool_count);
  845. static void knav_queue_setup_region(struct knav_device *kdev,
  846. struct knav_region *region)
  847. {
  848. unsigned hw_num_desc, hw_desc_size, size;
  849. struct knav_reg_region __iomem *regs;
  850. struct knav_qmgr_info *qmgr;
  851. struct knav_pool *pool;
  852. int id = region->id;
  853. struct page *page;
  854. /* unused region? */
  855. if (!region->num_desc) {
  856. dev_warn(kdev->dev, "unused region %s\n", region->name);
  857. return;
  858. }
  859. /* get hardware descriptor value */
  860. hw_num_desc = ilog2(region->num_desc - 1) + 1;
  861. /* did we force fit ourselves into nothingness? */
  862. if (region->num_desc < 32) {
  863. region->num_desc = 0;
  864. dev_warn(kdev->dev, "too few descriptors in region %s\n",
  865. region->name);
  866. return;
  867. }
  868. size = region->num_desc * region->desc_size;
  869. region->virt_start = alloc_pages_exact(size, GFP_KERNEL | GFP_DMA |
  870. GFP_DMA32);
  871. if (!region->virt_start) {
  872. region->num_desc = 0;
  873. dev_err(kdev->dev, "memory alloc failed for region %s\n",
  874. region->name);
  875. return;
  876. }
  877. region->virt_end = region->virt_start + size;
  878. page = virt_to_page(region->virt_start);
  879. region->dma_start = dma_map_page(kdev->dev, page, 0, size,
  880. DMA_BIDIRECTIONAL);
  881. if (dma_mapping_error(kdev->dev, region->dma_start)) {
  882. dev_err(kdev->dev, "dma map failed for region %s\n",
  883. region->name);
  884. goto fail;
  885. }
  886. region->dma_end = region->dma_start + size;
  887. pool = devm_kzalloc(kdev->dev, sizeof(*pool), GFP_KERNEL);
  888. if (!pool) {
  889. dev_err(kdev->dev, "out of memory allocating dummy pool\n");
  890. goto fail;
  891. }
  892. pool->num_desc = 0;
  893. pool->region_offset = region->num_desc;
  894. list_add(&pool->region_inst, &region->pools);
  895. dev_dbg(kdev->dev,
  896. "region %s (%d): size:%d, link:%d@%d, dma:%pad-%pad, virt:%p-%p\n",
  897. region->name, id, region->desc_size, region->num_desc,
  898. region->link_index, &region->dma_start, &region->dma_end,
  899. region->virt_start, region->virt_end);
  900. hw_desc_size = (region->desc_size / 16) - 1;
  901. hw_num_desc -= 5;
  902. for_each_qmgr(kdev, qmgr) {
  903. regs = qmgr->reg_region + id;
  904. writel_relaxed((u32)region->dma_start, &regs->base);
  905. writel_relaxed(region->link_index, &regs->start_index);
  906. writel_relaxed(hw_desc_size << 16 | hw_num_desc,
  907. &regs->size_count);
  908. }
  909. return;
  910. fail:
  911. if (region->dma_start)
  912. dma_unmap_page(kdev->dev, region->dma_start, size,
  913. DMA_BIDIRECTIONAL);
  914. if (region->virt_start)
  915. free_pages_exact(region->virt_start, size);
  916. region->num_desc = 0;
  917. return;
  918. }
  919. static const char *knav_queue_find_name(struct device_node *node)
  920. {
  921. const char *name;
  922. if (of_property_read_string(node, "label", &name) < 0)
  923. name = node->name;
  924. if (!name)
  925. name = "unknown";
  926. return name;
  927. }
  928. static int knav_queue_setup_regions(struct knav_device *kdev,
  929. struct device_node *regions)
  930. {
  931. struct device *dev = kdev->dev;
  932. struct knav_region *region;
  933. struct device_node *child;
  934. u32 temp[2];
  935. int ret;
  936. for_each_child_of_node(regions, child) {
  937. region = devm_kzalloc(dev, sizeof(*region), GFP_KERNEL);
  938. if (!region) {
  939. dev_err(dev, "out of memory allocating region\n");
  940. return -ENOMEM;
  941. }
  942. region->name = knav_queue_find_name(child);
  943. of_property_read_u32(child, "id", &region->id);
  944. ret = of_property_read_u32_array(child, "region-spec", temp, 2);
  945. if (!ret) {
  946. region->num_desc = temp[0];
  947. region->desc_size = temp[1];
  948. } else {
  949. dev_err(dev, "invalid region info %s\n", region->name);
  950. devm_kfree(dev, region);
  951. continue;
  952. }
  953. if (!of_get_property(child, "link-index", NULL)) {
  954. dev_err(dev, "No link info for %s\n", region->name);
  955. devm_kfree(dev, region);
  956. continue;
  957. }
  958. ret = of_property_read_u32(child, "link-index",
  959. &region->link_index);
  960. if (ret) {
  961. dev_err(dev, "link index not found for %s\n",
  962. region->name);
  963. devm_kfree(dev, region);
  964. continue;
  965. }
  966. INIT_LIST_HEAD(&region->pools);
  967. list_add_tail(&region->list, &kdev->regions);
  968. }
  969. if (list_empty(&kdev->regions)) {
  970. dev_err(dev, "no valid region information found\n");
  971. return -ENODEV;
  972. }
  973. /* Next, we run through the regions and set things up */
  974. for_each_region(kdev, region)
  975. knav_queue_setup_region(kdev, region);
  976. return 0;
  977. }
  978. static int knav_get_link_ram(struct knav_device *kdev,
  979. const char *name,
  980. struct knav_link_ram_block *block)
  981. {
  982. struct platform_device *pdev = to_platform_device(kdev->dev);
  983. struct device_node *node = pdev->dev.of_node;
  984. u32 temp[2];
  985. /*
  986. * Note: link ram resources are specified in "entry" sized units. In
  987. * reality, although entries are ~40bits in hardware, we treat them as
  988. * 64-bit entities here.
  989. *
  990. * For example, to specify the internal link ram for Keystone-I class
  991. * devices, we would set the linkram0 resource to 0x80000-0x83fff.
  992. *
  993. * This gets a bit weird when other link rams are used. For example,
  994. * if the range specified is 0x0c000000-0x0c003fff (i.e., 16K entries
  995. * in MSMC SRAM), the actual memory used is 0x0c000000-0x0c020000,
  996. * which accounts for 64-bits per entry, for 16K entries.
  997. */
  998. if (!of_property_read_u32_array(node, name , temp, 2)) {
  999. if (temp[0]) {
  1000. /*
  1001. * queue_base specified => using internal or onchip
  1002. * link ram WARNING - we do not "reserve" this block
  1003. */
  1004. block->dma = (dma_addr_t)temp[0];
  1005. block->virt = NULL;
  1006. block->size = temp[1];
  1007. } else {
  1008. block->size = temp[1];
  1009. /* queue_base not specific => allocate requested size */
  1010. block->virt = dmam_alloc_coherent(kdev->dev,
  1011. 8 * block->size, &block->dma,
  1012. GFP_KERNEL);
  1013. if (!block->virt) {
  1014. dev_err(kdev->dev, "failed to alloc linkram\n");
  1015. return -ENOMEM;
  1016. }
  1017. }
  1018. } else {
  1019. return -ENODEV;
  1020. }
  1021. return 0;
  1022. }
  1023. static int knav_queue_setup_link_ram(struct knav_device *kdev)
  1024. {
  1025. struct knav_link_ram_block *block;
  1026. struct knav_qmgr_info *qmgr;
  1027. for_each_qmgr(kdev, qmgr) {
  1028. block = &kdev->link_rams[0];
  1029. dev_dbg(kdev->dev, "linkram0: dma:%pad, virt:%p, size:%x\n",
  1030. &block->dma, block->virt, block->size);
  1031. writel_relaxed((u32)block->dma, &qmgr->reg_config->link_ram_base0);
  1032. if (kdev->version == QMSS_66AK2G)
  1033. writel_relaxed(block->size,
  1034. &qmgr->reg_config->link_ram_size0);
  1035. else
  1036. writel_relaxed(block->size - 1,
  1037. &qmgr->reg_config->link_ram_size0);
  1038. block++;
  1039. if (!block->size)
  1040. continue;
  1041. dev_dbg(kdev->dev, "linkram1: dma:%pad, virt:%p, size:%x\n",
  1042. &block->dma, block->virt, block->size);
  1043. writel_relaxed(block->dma, &qmgr->reg_config->link_ram_base1);
  1044. }
  1045. return 0;
  1046. }
  1047. static int knav_setup_queue_range(struct knav_device *kdev,
  1048. struct device_node *node)
  1049. {
  1050. struct device *dev = kdev->dev;
  1051. struct knav_range_info *range;
  1052. struct knav_qmgr_info *qmgr;
  1053. u32 temp[2], start, end, id, index;
  1054. int ret, i;
  1055. range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL);
  1056. if (!range) {
  1057. dev_err(dev, "out of memory allocating range\n");
  1058. return -ENOMEM;
  1059. }
  1060. range->kdev = kdev;
  1061. range->name = knav_queue_find_name(node);
  1062. ret = of_property_read_u32_array(node, "qrange", temp, 2);
  1063. if (!ret) {
  1064. range->queue_base = temp[0] - kdev->base_id;
  1065. range->num_queues = temp[1];
  1066. } else {
  1067. dev_err(dev, "invalid queue range %s\n", range->name);
  1068. devm_kfree(dev, range);
  1069. return -EINVAL;
  1070. }
  1071. for (i = 0; i < RANGE_MAX_IRQS; i++) {
  1072. struct of_phandle_args oirq;
  1073. if (of_irq_parse_one(node, i, &oirq))
  1074. break;
  1075. range->irqs[i].irq = irq_create_of_mapping(&oirq);
  1076. if (range->irqs[i].irq == IRQ_NONE)
  1077. break;
  1078. range->num_irqs++;
  1079. if (IS_ENABLED(CONFIG_SMP) && oirq.args_count == 3) {
  1080. unsigned long mask;
  1081. int bit;
  1082. range->irqs[i].cpu_mask = devm_kzalloc(dev,
  1083. cpumask_size(), GFP_KERNEL);
  1084. if (!range->irqs[i].cpu_mask)
  1085. return -ENOMEM;
  1086. mask = (oirq.args[2] & 0x0000ff00) >> 8;
  1087. for_each_set_bit(bit, &mask, BITS_PER_LONG)
  1088. cpumask_set_cpu(bit, range->irqs[i].cpu_mask);
  1089. }
  1090. }
  1091. range->num_irqs = min(range->num_irqs, range->num_queues);
  1092. if (range->num_irqs)
  1093. range->flags |= RANGE_HAS_IRQ;
  1094. if (of_get_property(node, "qalloc-by-id", NULL))
  1095. range->flags |= RANGE_RESERVED;
  1096. if (of_get_property(node, "accumulator", NULL)) {
  1097. ret = knav_init_acc_range(kdev, node, range);
  1098. if (ret < 0) {
  1099. devm_kfree(dev, range);
  1100. return ret;
  1101. }
  1102. } else {
  1103. range->ops = &knav_gp_range_ops;
  1104. }
  1105. /* set threshold to 1, and flush out the queues */
  1106. for_each_qmgr(kdev, qmgr) {
  1107. start = max(qmgr->start_queue, range->queue_base);
  1108. end = min(qmgr->start_queue + qmgr->num_queues,
  1109. range->queue_base + range->num_queues);
  1110. for (id = start; id < end; id++) {
  1111. index = id - qmgr->start_queue;
  1112. writel_relaxed(THRESH_GTE | 1,
  1113. &qmgr->reg_peek[index].ptr_size_thresh);
  1114. writel_relaxed(0,
  1115. &qmgr->reg_push[index].ptr_size_thresh);
  1116. }
  1117. }
  1118. list_add_tail(&range->list, &kdev->queue_ranges);
  1119. dev_dbg(dev, "added range %s: %d-%d, %d irqs%s%s%s\n",
  1120. range->name, range->queue_base,
  1121. range->queue_base + range->num_queues - 1,
  1122. range->num_irqs,
  1123. (range->flags & RANGE_HAS_IRQ) ? ", has irq" : "",
  1124. (range->flags & RANGE_RESERVED) ? ", reserved" : "",
  1125. (range->flags & RANGE_HAS_ACCUMULATOR) ? ", acc" : "");
  1126. kdev->num_queues_in_use += range->num_queues;
  1127. return 0;
  1128. }
  1129. static int knav_setup_queue_pools(struct knav_device *kdev,
  1130. struct device_node *queue_pools)
  1131. {
  1132. struct device_node *type, *range;
  1133. int ret;
  1134. for_each_child_of_node(queue_pools, type) {
  1135. for_each_child_of_node(type, range) {
  1136. ret = knav_setup_queue_range(kdev, range);
  1137. /* return value ignored, we init the rest... */
  1138. }
  1139. }
  1140. /* ... and barf if they all failed! */
  1141. if (list_empty(&kdev->queue_ranges)) {
  1142. dev_err(kdev->dev, "no valid queue range found\n");
  1143. return -ENODEV;
  1144. }
  1145. return 0;
  1146. }
  1147. static void knav_free_queue_range(struct knav_device *kdev,
  1148. struct knav_range_info *range)
  1149. {
  1150. if (range->ops && range->ops->free_range)
  1151. range->ops->free_range(range);
  1152. list_del(&range->list);
  1153. devm_kfree(kdev->dev, range);
  1154. }
  1155. static void knav_free_queue_ranges(struct knav_device *kdev)
  1156. {
  1157. struct knav_range_info *range;
  1158. for (;;) {
  1159. range = first_queue_range(kdev);
  1160. if (!range)
  1161. break;
  1162. knav_free_queue_range(kdev, range);
  1163. }
  1164. }
  1165. static void knav_queue_free_regions(struct knav_device *kdev)
  1166. {
  1167. struct knav_region *region;
  1168. struct knav_pool *pool, *tmp;
  1169. unsigned size;
  1170. for (;;) {
  1171. region = first_region(kdev);
  1172. if (!region)
  1173. break;
  1174. list_for_each_entry_safe(pool, tmp, &region->pools, region_inst)
  1175. knav_pool_destroy(pool);
  1176. size = region->virt_end - region->virt_start;
  1177. if (size)
  1178. free_pages_exact(region->virt_start, size);
  1179. list_del(&region->list);
  1180. devm_kfree(kdev->dev, region);
  1181. }
  1182. }
  1183. static void __iomem *knav_queue_map_reg(struct knav_device *kdev,
  1184. struct device_node *node, int index)
  1185. {
  1186. struct resource res;
  1187. void __iomem *regs;
  1188. int ret;
  1189. ret = of_address_to_resource(node, index, &res);
  1190. if (ret) {
  1191. dev_err(kdev->dev, "Can't translate of node(%s) address for index(%d)\n",
  1192. node->name, index);
  1193. return ERR_PTR(ret);
  1194. }
  1195. regs = devm_ioremap_resource(kdev->dev, &res);
  1196. if (IS_ERR(regs))
  1197. dev_err(kdev->dev, "Failed to map register base for index(%d) node(%s)\n",
  1198. index, node->name);
  1199. return regs;
  1200. }
  1201. static int knav_queue_init_qmgrs(struct knav_device *kdev,
  1202. struct device_node *qmgrs)
  1203. {
  1204. struct device *dev = kdev->dev;
  1205. struct knav_qmgr_info *qmgr;
  1206. struct device_node *child;
  1207. u32 temp[2];
  1208. int ret;
  1209. for_each_child_of_node(qmgrs, child) {
  1210. qmgr = devm_kzalloc(dev, sizeof(*qmgr), GFP_KERNEL);
  1211. if (!qmgr) {
  1212. dev_err(dev, "out of memory allocating qmgr\n");
  1213. return -ENOMEM;
  1214. }
  1215. ret = of_property_read_u32_array(child, "managed-queues",
  1216. temp, 2);
  1217. if (!ret) {
  1218. qmgr->start_queue = temp[0];
  1219. qmgr->num_queues = temp[1];
  1220. } else {
  1221. dev_err(dev, "invalid qmgr queue range\n");
  1222. devm_kfree(dev, qmgr);
  1223. continue;
  1224. }
  1225. dev_info(dev, "qmgr start queue %d, number of queues %d\n",
  1226. qmgr->start_queue, qmgr->num_queues);
  1227. qmgr->reg_peek =
  1228. knav_queue_map_reg(kdev, child,
  1229. KNAV_QUEUE_PEEK_REG_INDEX);
  1230. if (kdev->version == QMSS) {
  1231. qmgr->reg_status =
  1232. knav_queue_map_reg(kdev, child,
  1233. KNAV_QUEUE_STATUS_REG_INDEX);
  1234. }
  1235. qmgr->reg_config =
  1236. knav_queue_map_reg(kdev, child,
  1237. (kdev->version == QMSS_66AK2G) ?
  1238. KNAV_L_QUEUE_CONFIG_REG_INDEX :
  1239. KNAV_QUEUE_CONFIG_REG_INDEX);
  1240. qmgr->reg_region =
  1241. knav_queue_map_reg(kdev, child,
  1242. (kdev->version == QMSS_66AK2G) ?
  1243. KNAV_L_QUEUE_REGION_REG_INDEX :
  1244. KNAV_QUEUE_REGION_REG_INDEX);
  1245. qmgr->reg_push =
  1246. knav_queue_map_reg(kdev, child,
  1247. (kdev->version == QMSS_66AK2G) ?
  1248. KNAV_L_QUEUE_PUSH_REG_INDEX :
  1249. KNAV_QUEUE_PUSH_REG_INDEX);
  1250. if (kdev->version == QMSS) {
  1251. qmgr->reg_pop =
  1252. knav_queue_map_reg(kdev, child,
  1253. KNAV_QUEUE_POP_REG_INDEX);
  1254. }
  1255. if (IS_ERR(qmgr->reg_peek) ||
  1256. ((kdev->version == QMSS) &&
  1257. (IS_ERR(qmgr->reg_status) || IS_ERR(qmgr->reg_pop))) ||
  1258. IS_ERR(qmgr->reg_config) || IS_ERR(qmgr->reg_region) ||
  1259. IS_ERR(qmgr->reg_push)) {
  1260. dev_err(dev, "failed to map qmgr regs\n");
  1261. if (kdev->version == QMSS) {
  1262. if (!IS_ERR(qmgr->reg_status))
  1263. devm_iounmap(dev, qmgr->reg_status);
  1264. if (!IS_ERR(qmgr->reg_pop))
  1265. devm_iounmap(dev, qmgr->reg_pop);
  1266. }
  1267. if (!IS_ERR(qmgr->reg_peek))
  1268. devm_iounmap(dev, qmgr->reg_peek);
  1269. if (!IS_ERR(qmgr->reg_config))
  1270. devm_iounmap(dev, qmgr->reg_config);
  1271. if (!IS_ERR(qmgr->reg_region))
  1272. devm_iounmap(dev, qmgr->reg_region);
  1273. if (!IS_ERR(qmgr->reg_push))
  1274. devm_iounmap(dev, qmgr->reg_push);
  1275. devm_kfree(dev, qmgr);
  1276. continue;
  1277. }
  1278. /* Use same push register for pop as well */
  1279. if (kdev->version == QMSS_66AK2G)
  1280. qmgr->reg_pop = qmgr->reg_push;
  1281. list_add_tail(&qmgr->list, &kdev->qmgrs);
  1282. dev_info(dev, "added qmgr start queue %d, num of queues %d, reg_peek %p, reg_status %p, reg_config %p, reg_region %p, reg_push %p, reg_pop %p\n",
  1283. qmgr->start_queue, qmgr->num_queues,
  1284. qmgr->reg_peek, qmgr->reg_status,
  1285. qmgr->reg_config, qmgr->reg_region,
  1286. qmgr->reg_push, qmgr->reg_pop);
  1287. }
  1288. return 0;
  1289. }
  1290. static int knav_queue_init_pdsps(struct knav_device *kdev,
  1291. struct device_node *pdsps)
  1292. {
  1293. struct device *dev = kdev->dev;
  1294. struct knav_pdsp_info *pdsp;
  1295. struct device_node *child;
  1296. for_each_child_of_node(pdsps, child) {
  1297. pdsp = devm_kzalloc(dev, sizeof(*pdsp), GFP_KERNEL);
  1298. if (!pdsp) {
  1299. dev_err(dev, "out of memory allocating pdsp\n");
  1300. return -ENOMEM;
  1301. }
  1302. pdsp->name = knav_queue_find_name(child);
  1303. pdsp->iram =
  1304. knav_queue_map_reg(kdev, child,
  1305. KNAV_QUEUE_PDSP_IRAM_REG_INDEX);
  1306. pdsp->regs =
  1307. knav_queue_map_reg(kdev, child,
  1308. KNAV_QUEUE_PDSP_REGS_REG_INDEX);
  1309. pdsp->intd =
  1310. knav_queue_map_reg(kdev, child,
  1311. KNAV_QUEUE_PDSP_INTD_REG_INDEX);
  1312. pdsp->command =
  1313. knav_queue_map_reg(kdev, child,
  1314. KNAV_QUEUE_PDSP_CMD_REG_INDEX);
  1315. if (IS_ERR(pdsp->command) || IS_ERR(pdsp->iram) ||
  1316. IS_ERR(pdsp->regs) || IS_ERR(pdsp->intd)) {
  1317. dev_err(dev, "failed to map pdsp %s regs\n",
  1318. pdsp->name);
  1319. if (!IS_ERR(pdsp->command))
  1320. devm_iounmap(dev, pdsp->command);
  1321. if (!IS_ERR(pdsp->iram))
  1322. devm_iounmap(dev, pdsp->iram);
  1323. if (!IS_ERR(pdsp->regs))
  1324. devm_iounmap(dev, pdsp->regs);
  1325. if (!IS_ERR(pdsp->intd))
  1326. devm_iounmap(dev, pdsp->intd);
  1327. devm_kfree(dev, pdsp);
  1328. continue;
  1329. }
  1330. of_property_read_u32(child, "id", &pdsp->id);
  1331. list_add_tail(&pdsp->list, &kdev->pdsps);
  1332. dev_dbg(dev, "added pdsp %s: command %p, iram %p, regs %p, intd %p\n",
  1333. pdsp->name, pdsp->command, pdsp->iram, pdsp->regs,
  1334. pdsp->intd);
  1335. }
  1336. return 0;
  1337. }
  1338. static int knav_queue_stop_pdsp(struct knav_device *kdev,
  1339. struct knav_pdsp_info *pdsp)
  1340. {
  1341. u32 val, timeout = 1000;
  1342. int ret;
  1343. val = readl_relaxed(&pdsp->regs->control) & ~PDSP_CTRL_ENABLE;
  1344. writel_relaxed(val, &pdsp->regs->control);
  1345. ret = knav_queue_pdsp_wait(&pdsp->regs->control, timeout,
  1346. PDSP_CTRL_RUNNING);
  1347. if (ret < 0) {
  1348. dev_err(kdev->dev, "timed out on pdsp %s stop\n", pdsp->name);
  1349. return ret;
  1350. }
  1351. pdsp->loaded = false;
  1352. pdsp->started = false;
  1353. return 0;
  1354. }
  1355. static int knav_queue_load_pdsp(struct knav_device *kdev,
  1356. struct knav_pdsp_info *pdsp)
  1357. {
  1358. int i, ret, fwlen;
  1359. const struct firmware *fw;
  1360. bool found = false;
  1361. u32 *fwdata;
  1362. for (i = 0; i < ARRAY_SIZE(knav_acc_firmwares); i++) {
  1363. if (knav_acc_firmwares[i]) {
  1364. ret = request_firmware_direct(&fw,
  1365. knav_acc_firmwares[i],
  1366. kdev->dev);
  1367. if (!ret) {
  1368. found = true;
  1369. break;
  1370. }
  1371. }
  1372. }
  1373. if (!found) {
  1374. dev_err(kdev->dev, "failed to get firmware for pdsp\n");
  1375. return -ENODEV;
  1376. }
  1377. dev_info(kdev->dev, "firmware file %s downloaded for PDSP\n",
  1378. knav_acc_firmwares[i]);
  1379. writel_relaxed(pdsp->id + 1, pdsp->command + 0x18);
  1380. /* download the firmware */
  1381. fwdata = (u32 *)fw->data;
  1382. fwlen = (fw->size + sizeof(u32) - 1) / sizeof(u32);
  1383. for (i = 0; i < fwlen; i++)
  1384. writel_relaxed(be32_to_cpu(fwdata[i]), pdsp->iram + i);
  1385. release_firmware(fw);
  1386. return 0;
  1387. }
  1388. static int knav_queue_start_pdsp(struct knav_device *kdev,
  1389. struct knav_pdsp_info *pdsp)
  1390. {
  1391. u32 val, timeout = 1000;
  1392. int ret;
  1393. /* write a command for sync */
  1394. writel_relaxed(0xffffffff, pdsp->command);
  1395. while (readl_relaxed(pdsp->command) != 0xffffffff)
  1396. cpu_relax();
  1397. /* soft reset the PDSP */
  1398. val = readl_relaxed(&pdsp->regs->control);
  1399. val &= ~(PDSP_CTRL_PC_MASK | PDSP_CTRL_SOFT_RESET);
  1400. writel_relaxed(val, &pdsp->regs->control);
  1401. /* enable pdsp */
  1402. val = readl_relaxed(&pdsp->regs->control) | PDSP_CTRL_ENABLE;
  1403. writel_relaxed(val, &pdsp->regs->control);
  1404. /* wait for command register to clear */
  1405. ret = knav_queue_pdsp_wait(pdsp->command, timeout, 0);
  1406. if (ret < 0) {
  1407. dev_err(kdev->dev,
  1408. "timed out on pdsp %s command register wait\n",
  1409. pdsp->name);
  1410. return ret;
  1411. }
  1412. return 0;
  1413. }
  1414. static void knav_queue_stop_pdsps(struct knav_device *kdev)
  1415. {
  1416. struct knav_pdsp_info *pdsp;
  1417. /* disable all pdsps */
  1418. for_each_pdsp(kdev, pdsp)
  1419. knav_queue_stop_pdsp(kdev, pdsp);
  1420. }
  1421. static int knav_queue_start_pdsps(struct knav_device *kdev)
  1422. {
  1423. struct knav_pdsp_info *pdsp;
  1424. int ret;
  1425. knav_queue_stop_pdsps(kdev);
  1426. /* now load them all. We return success even if pdsp
  1427. * is not loaded as acc channels are optional on having
  1428. * firmware availability in the system. We set the loaded
  1429. * and stated flag and when initialize the acc range, check
  1430. * it and init the range only if pdsp is started.
  1431. */
  1432. for_each_pdsp(kdev, pdsp) {
  1433. ret = knav_queue_load_pdsp(kdev, pdsp);
  1434. if (!ret)
  1435. pdsp->loaded = true;
  1436. }
  1437. for_each_pdsp(kdev, pdsp) {
  1438. if (pdsp->loaded) {
  1439. ret = knav_queue_start_pdsp(kdev, pdsp);
  1440. if (!ret)
  1441. pdsp->started = true;
  1442. }
  1443. }
  1444. return 0;
  1445. }
  1446. static inline struct knav_qmgr_info *knav_find_qmgr(unsigned id)
  1447. {
  1448. struct knav_qmgr_info *qmgr;
  1449. for_each_qmgr(kdev, qmgr) {
  1450. if ((id >= qmgr->start_queue) &&
  1451. (id < qmgr->start_queue + qmgr->num_queues))
  1452. return qmgr;
  1453. }
  1454. return NULL;
  1455. }
  1456. static int knav_queue_init_queue(struct knav_device *kdev,
  1457. struct knav_range_info *range,
  1458. struct knav_queue_inst *inst,
  1459. unsigned id)
  1460. {
  1461. char irq_name[KNAV_NAME_SIZE];
  1462. inst->qmgr = knav_find_qmgr(id);
  1463. if (!inst->qmgr)
  1464. return -1;
  1465. INIT_LIST_HEAD(&inst->handles);
  1466. inst->kdev = kdev;
  1467. inst->range = range;
  1468. inst->irq_num = -1;
  1469. inst->id = id;
  1470. scnprintf(irq_name, sizeof(irq_name), "hwqueue-%d", id);
  1471. inst->irq_name = kstrndup(irq_name, sizeof(irq_name), GFP_KERNEL);
  1472. if (range->ops && range->ops->init_queue)
  1473. return range->ops->init_queue(range, inst);
  1474. else
  1475. return 0;
  1476. }
  1477. static int knav_queue_init_queues(struct knav_device *kdev)
  1478. {
  1479. struct knav_range_info *range;
  1480. int size, id, base_idx;
  1481. int idx = 0, ret = 0;
  1482. /* how much do we need for instance data? */
  1483. size = sizeof(struct knav_queue_inst);
  1484. /* round this up to a power of 2, keep the index to instance
  1485. * arithmetic fast.
  1486. * */
  1487. kdev->inst_shift = order_base_2(size);
  1488. size = (1 << kdev->inst_shift) * kdev->num_queues_in_use;
  1489. kdev->instances = devm_kzalloc(kdev->dev, size, GFP_KERNEL);
  1490. if (!kdev->instances)
  1491. return -ENOMEM;
  1492. for_each_queue_range(kdev, range) {
  1493. if (range->ops && range->ops->init_range)
  1494. range->ops->init_range(range);
  1495. base_idx = idx;
  1496. for (id = range->queue_base;
  1497. id < range->queue_base + range->num_queues; id++, idx++) {
  1498. ret = knav_queue_init_queue(kdev, range,
  1499. knav_queue_idx_to_inst(kdev, idx), id);
  1500. if (ret < 0)
  1501. return ret;
  1502. }
  1503. range->queue_base_inst =
  1504. knav_queue_idx_to_inst(kdev, base_idx);
  1505. }
  1506. return 0;
  1507. }
  1508. /* Match table for of_platform binding */
  1509. static const struct of_device_id keystone_qmss_of_match[] = {
  1510. {
  1511. .compatible = "ti,keystone-navigator-qmss",
  1512. },
  1513. {
  1514. .compatible = "ti,66ak2g-navss-qm",
  1515. .data = (void *)QMSS_66AK2G,
  1516. },
  1517. {},
  1518. };
  1519. MODULE_DEVICE_TABLE(of, keystone_qmss_of_match);
  1520. static int knav_queue_probe(struct platform_device *pdev)
  1521. {
  1522. struct device_node *node = pdev->dev.of_node;
  1523. struct device_node *qmgrs, *queue_pools, *regions, *pdsps;
  1524. const struct of_device_id *match;
  1525. struct device *dev = &pdev->dev;
  1526. u32 temp[2];
  1527. int ret;
  1528. if (!node) {
  1529. dev_err(dev, "device tree info unavailable\n");
  1530. return -ENODEV;
  1531. }
  1532. kdev = devm_kzalloc(dev, sizeof(struct knav_device), GFP_KERNEL);
  1533. if (!kdev) {
  1534. dev_err(dev, "memory allocation failed\n");
  1535. return -ENOMEM;
  1536. }
  1537. match = of_match_device(of_match_ptr(keystone_qmss_of_match), dev);
  1538. if (match && match->data)
  1539. kdev->version = QMSS_66AK2G;
  1540. platform_set_drvdata(pdev, kdev);
  1541. kdev->dev = dev;
  1542. INIT_LIST_HEAD(&kdev->queue_ranges);
  1543. INIT_LIST_HEAD(&kdev->qmgrs);
  1544. INIT_LIST_HEAD(&kdev->pools);
  1545. INIT_LIST_HEAD(&kdev->regions);
  1546. INIT_LIST_HEAD(&kdev->pdsps);
  1547. pm_runtime_enable(&pdev->dev);
  1548. ret = pm_runtime_get_sync(&pdev->dev);
  1549. if (ret < 0) {
  1550. dev_err(dev, "Failed to enable QMSS\n");
  1551. return ret;
  1552. }
  1553. if (of_property_read_u32_array(node, "queue-range", temp, 2)) {
  1554. dev_err(dev, "queue-range not specified\n");
  1555. ret = -ENODEV;
  1556. goto err;
  1557. }
  1558. kdev->base_id = temp[0];
  1559. kdev->num_queues = temp[1];
  1560. /* Initialize queue managers using device tree configuration */
  1561. qmgrs = of_get_child_by_name(node, "qmgrs");
  1562. if (!qmgrs) {
  1563. dev_err(dev, "queue manager info not specified\n");
  1564. ret = -ENODEV;
  1565. goto err;
  1566. }
  1567. ret = knav_queue_init_qmgrs(kdev, qmgrs);
  1568. of_node_put(qmgrs);
  1569. if (ret)
  1570. goto err;
  1571. /* get pdsp configuration values from device tree */
  1572. pdsps = of_get_child_by_name(node, "pdsps");
  1573. if (pdsps) {
  1574. ret = knav_queue_init_pdsps(kdev, pdsps);
  1575. if (ret)
  1576. goto err;
  1577. ret = knav_queue_start_pdsps(kdev);
  1578. if (ret)
  1579. goto err;
  1580. }
  1581. of_node_put(pdsps);
  1582. /* get usable queue range values from device tree */
  1583. queue_pools = of_get_child_by_name(node, "queue-pools");
  1584. if (!queue_pools) {
  1585. dev_err(dev, "queue-pools not specified\n");
  1586. ret = -ENODEV;
  1587. goto err;
  1588. }
  1589. ret = knav_setup_queue_pools(kdev, queue_pools);
  1590. of_node_put(queue_pools);
  1591. if (ret)
  1592. goto err;
  1593. ret = knav_get_link_ram(kdev, "linkram0", &kdev->link_rams[0]);
  1594. if (ret) {
  1595. dev_err(kdev->dev, "could not setup linking ram\n");
  1596. goto err;
  1597. }
  1598. ret = knav_get_link_ram(kdev, "linkram1", &kdev->link_rams[1]);
  1599. if (ret) {
  1600. /*
  1601. * nothing really, we have one linking ram already, so we just
  1602. * live within our means
  1603. */
  1604. }
  1605. ret = knav_queue_setup_link_ram(kdev);
  1606. if (ret)
  1607. goto err;
  1608. regions = of_get_child_by_name(node, "descriptor-regions");
  1609. if (!regions) {
  1610. dev_err(dev, "descriptor-regions not specified\n");
  1611. goto err;
  1612. }
  1613. ret = knav_queue_setup_regions(kdev, regions);
  1614. of_node_put(regions);
  1615. if (ret)
  1616. goto err;
  1617. ret = knav_queue_init_queues(kdev);
  1618. if (ret < 0) {
  1619. dev_err(dev, "hwqueue initialization failed\n");
  1620. goto err;
  1621. }
  1622. debugfs_create_file("qmss", S_IFREG | S_IRUGO, NULL, NULL,
  1623. &knav_queue_debug_ops);
  1624. device_ready = true;
  1625. return 0;
  1626. err:
  1627. knav_queue_stop_pdsps(kdev);
  1628. knav_queue_free_regions(kdev);
  1629. knav_free_queue_ranges(kdev);
  1630. pm_runtime_put_sync(&pdev->dev);
  1631. pm_runtime_disable(&pdev->dev);
  1632. return ret;
  1633. }
  1634. static int knav_queue_remove(struct platform_device *pdev)
  1635. {
  1636. /* TODO: Free resources */
  1637. pm_runtime_put_sync(&pdev->dev);
  1638. pm_runtime_disable(&pdev->dev);
  1639. return 0;
  1640. }
  1641. static struct platform_driver keystone_qmss_driver = {
  1642. .probe = knav_queue_probe,
  1643. .remove = knav_queue_remove,
  1644. .driver = {
  1645. .name = "keystone-navigator-qmss",
  1646. .of_match_table = keystone_qmss_of_match,
  1647. },
  1648. };
  1649. module_platform_driver(keystone_qmss_driver);
  1650. MODULE_LICENSE("GPL v2");
  1651. MODULE_DESCRIPTION("TI QMSS driver for Keystone SOCs");
  1652. MODULE_AUTHOR("Sandeep Nair <sandeep_n@ti.com>");
  1653. MODULE_AUTHOR("Santosh Shilimkar <santosh.shilimkar@ti.com>");