knav_qmss_queue.c 47 KB

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