remoteproc_core.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  1. /*
  2. * Remote Processor Framework
  3. *
  4. * Copyright (C) 2011 Texas Instruments, Inc.
  5. * Copyright (C) 2011 Google, Inc.
  6. *
  7. * Ohad Ben-Cohen <ohad@wizery.com>
  8. * Brian Swetland <swetland@google.com>
  9. * Mark Grosen <mgrosen@ti.com>
  10. * Fernando Guzman Lugo <fernando.lugo@ti.com>
  11. * Suman Anna <s-anna@ti.com>
  12. * Robert Tivy <rtivy@ti.com>
  13. * Armando Uribe De Leon <x0095078@ti.com>
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * version 2 as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. */
  24. #define pr_fmt(fmt) "%s: " fmt, __func__
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/device.h>
  28. #include <linux/slab.h>
  29. #include <linux/mutex.h>
  30. #include <linux/dma-mapping.h>
  31. #include <linux/firmware.h>
  32. #include <linux/string.h>
  33. #include <linux/debugfs.h>
  34. #include <linux/remoteproc.h>
  35. #include <linux/iommu.h>
  36. #include <linux/idr.h>
  37. #include <linux/elf.h>
  38. #include <linux/virtio_ids.h>
  39. #include <linux/virtio_ring.h>
  40. #include <asm/byteorder.h>
  41. #include "remoteproc_internal.h"
  42. typedef int (*rproc_handle_resources_t)(struct rproc *rproc,
  43. struct resource_table *table, int len);
  44. typedef int (*rproc_handle_resource_t)(struct rproc *rproc, void *, int avail);
  45. /* Unique indices for remoteproc devices */
  46. static DEFINE_IDA(rproc_dev_index);
  47. static const char * const rproc_crash_names[] = {
  48. [RPROC_MMUFAULT] = "mmufault",
  49. };
  50. /* translate rproc_crash_type to string */
  51. static const char *rproc_crash_to_string(enum rproc_crash_type type)
  52. {
  53. if (type < ARRAY_SIZE(rproc_crash_names))
  54. return rproc_crash_names[type];
  55. return "unkown";
  56. }
  57. /*
  58. * This is the IOMMU fault handler we register with the IOMMU API
  59. * (when relevant; not all remote processors access memory through
  60. * an IOMMU).
  61. *
  62. * IOMMU core will invoke this handler whenever the remote processor
  63. * will try to access an unmapped device address.
  64. */
  65. static int rproc_iommu_fault(struct iommu_domain *domain, struct device *dev,
  66. unsigned long iova, int flags, void *token)
  67. {
  68. struct rproc *rproc = token;
  69. dev_err(dev, "iommu fault: da 0x%lx flags 0x%x\n", iova, flags);
  70. rproc_report_crash(rproc, RPROC_MMUFAULT);
  71. /*
  72. * Let the iommu core know we're not really handling this fault;
  73. * we just used it as a recovery trigger.
  74. */
  75. return -ENOSYS;
  76. }
  77. static int rproc_enable_iommu(struct rproc *rproc)
  78. {
  79. struct iommu_domain *domain;
  80. struct device *dev = rproc->dev.parent;
  81. int ret;
  82. /*
  83. * We currently use iommu_present() to decide if an IOMMU
  84. * setup is needed.
  85. *
  86. * This works for simple cases, but will easily fail with
  87. * platforms that do have an IOMMU, but not for this specific
  88. * rproc.
  89. *
  90. * This will be easily solved by introducing hw capabilities
  91. * that will be set by the remoteproc driver.
  92. */
  93. if (!iommu_present(dev->bus)) {
  94. dev_dbg(dev, "iommu not found\n");
  95. return 0;
  96. }
  97. domain = iommu_domain_alloc(dev->bus);
  98. if (!domain) {
  99. dev_err(dev, "can't alloc iommu domain\n");
  100. return -ENOMEM;
  101. }
  102. iommu_set_fault_handler(domain, rproc_iommu_fault, rproc);
  103. ret = iommu_attach_device(domain, dev);
  104. if (ret) {
  105. dev_err(dev, "can't attach iommu device: %d\n", ret);
  106. goto free_domain;
  107. }
  108. rproc->domain = domain;
  109. return 0;
  110. free_domain:
  111. iommu_domain_free(domain);
  112. return ret;
  113. }
  114. static void rproc_disable_iommu(struct rproc *rproc)
  115. {
  116. struct iommu_domain *domain = rproc->domain;
  117. struct device *dev = rproc->dev.parent;
  118. if (!domain)
  119. return;
  120. iommu_detach_device(domain, dev);
  121. iommu_domain_free(domain);
  122. return;
  123. }
  124. /*
  125. * Some remote processors will ask us to allocate them physically contiguous
  126. * memory regions (which we call "carveouts"), and map them to specific
  127. * device addresses (which are hardcoded in the firmware).
  128. *
  129. * They may then ask us to copy objects into specific device addresses (e.g.
  130. * code/data sections) or expose us certain symbols in other device address
  131. * (e.g. their trace buffer).
  132. *
  133. * This function is an internal helper with which we can go over the allocated
  134. * carveouts and translate specific device address to kernel virtual addresses
  135. * so we can access the referenced memory.
  136. *
  137. * Note: phys_to_virt(iommu_iova_to_phys(rproc->domain, da)) will work too,
  138. * but only on kernel direct mapped RAM memory. Instead, we're just using
  139. * here the output of the DMA API, which should be more correct.
  140. */
  141. void *rproc_da_to_va(struct rproc *rproc, u64 da, int len)
  142. {
  143. struct rproc_mem_entry *carveout;
  144. void *ptr = NULL;
  145. list_for_each_entry(carveout, &rproc->carveouts, node) {
  146. int offset = da - carveout->da;
  147. /* try next carveout if da is too small */
  148. if (offset < 0)
  149. continue;
  150. /* try next carveout if da is too large */
  151. if (offset + len > carveout->len)
  152. continue;
  153. ptr = carveout->va + offset;
  154. break;
  155. }
  156. return ptr;
  157. }
  158. EXPORT_SYMBOL(rproc_da_to_va);
  159. int rproc_alloc_vring(struct rproc_vdev *rvdev, int i)
  160. {
  161. struct rproc *rproc = rvdev->rproc;
  162. struct device *dev = &rproc->dev;
  163. struct rproc_vring *rvring = &rvdev->vring[i];
  164. dma_addr_t dma;
  165. void *va;
  166. int ret, size, notifyid;
  167. /* actual size of vring (in bytes) */
  168. size = PAGE_ALIGN(vring_size(rvring->len, rvring->align));
  169. /*
  170. * Allocate non-cacheable memory for the vring. In the future
  171. * this call will also configure the IOMMU for us
  172. * TODO: let the rproc know the da of this vring
  173. */
  174. va = dma_alloc_coherent(dev->parent, size, &dma, GFP_KERNEL);
  175. if (!va) {
  176. dev_err(dev->parent, "dma_alloc_coherent failed\n");
  177. return -EINVAL;
  178. }
  179. /*
  180. * Assign an rproc-wide unique index for this vring
  181. * TODO: assign a notifyid for rvdev updates as well
  182. * TODO: let the rproc know the notifyid of this vring
  183. * TODO: support predefined notifyids (via resource table)
  184. */
  185. ret = idr_alloc(&rproc->notifyids, rvring, 0, 0, GFP_KERNEL);
  186. if (ret) {
  187. dev_err(dev, "idr_alloc failed: %d\n", ret);
  188. dma_free_coherent(dev->parent, size, va, dma);
  189. return ret;
  190. }
  191. notifyid = ret;
  192. dev_dbg(dev, "vring%d: va %p dma %llx size %x idr %d\n", i, va,
  193. (unsigned long long)dma, size, notifyid);
  194. rvring->va = va;
  195. rvring->dma = dma;
  196. rvring->notifyid = notifyid;
  197. return 0;
  198. }
  199. static int
  200. rproc_parse_vring(struct rproc_vdev *rvdev, struct fw_rsc_vdev *rsc, int i)
  201. {
  202. struct rproc *rproc = rvdev->rproc;
  203. struct device *dev = &rproc->dev;
  204. struct fw_rsc_vdev_vring *vring = &rsc->vring[i];
  205. struct rproc_vring *rvring = &rvdev->vring[i];
  206. dev_dbg(dev, "vdev rsc: vring%d: da %x, qsz %d, align %d\n",
  207. i, vring->da, vring->num, vring->align);
  208. /* make sure reserved bytes are zeroes */
  209. if (vring->reserved) {
  210. dev_err(dev, "vring rsc has non zero reserved bytes\n");
  211. return -EINVAL;
  212. }
  213. /* verify queue size and vring alignment are sane */
  214. if (!vring->num || !vring->align) {
  215. dev_err(dev, "invalid qsz (%d) or alignment (%d)\n",
  216. vring->num, vring->align);
  217. return -EINVAL;
  218. }
  219. rvring->len = vring->num;
  220. rvring->align = vring->align;
  221. rvring->rvdev = rvdev;
  222. return 0;
  223. }
  224. void rproc_free_vring(struct rproc_vring *rvring)
  225. {
  226. int size = PAGE_ALIGN(vring_size(rvring->len, rvring->align));
  227. struct rproc *rproc = rvring->rvdev->rproc;
  228. dma_free_coherent(rproc->dev.parent, size, rvring->va, rvring->dma);
  229. idr_remove(&rproc->notifyids, rvring->notifyid);
  230. }
  231. /**
  232. * rproc_handle_vdev() - handle a vdev fw resource
  233. * @rproc: the remote processor
  234. * @rsc: the vring resource descriptor
  235. * @avail: size of available data (for sanity checking the image)
  236. *
  237. * This resource entry requests the host to statically register a virtio
  238. * device (vdev), and setup everything needed to support it. It contains
  239. * everything needed to make it possible: the virtio device id, virtio
  240. * device features, vrings information, virtio config space, etc...
  241. *
  242. * Before registering the vdev, the vrings are allocated from non-cacheable
  243. * physically contiguous memory. Currently we only support two vrings per
  244. * remote processor (temporary limitation). We might also want to consider
  245. * doing the vring allocation only later when ->find_vqs() is invoked, and
  246. * then release them upon ->del_vqs().
  247. *
  248. * Note: @da is currently not really handled correctly: we dynamically
  249. * allocate it using the DMA API, ignoring requested hard coded addresses,
  250. * and we don't take care of any required IOMMU programming. This is all
  251. * going to be taken care of when the generic iommu-based DMA API will be
  252. * merged. Meanwhile, statically-addressed iommu-based firmware images should
  253. * use RSC_DEVMEM resource entries to map their required @da to the physical
  254. * address of their base CMA region (ouch, hacky!).
  255. *
  256. * Returns 0 on success, or an appropriate error code otherwise
  257. */
  258. static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc,
  259. int avail)
  260. {
  261. struct device *dev = &rproc->dev;
  262. struct rproc_vdev *rvdev;
  263. int i, ret;
  264. /* make sure resource isn't truncated */
  265. if (sizeof(*rsc) + rsc->num_of_vrings * sizeof(struct fw_rsc_vdev_vring)
  266. + rsc->config_len > avail) {
  267. dev_err(dev, "vdev rsc is truncated\n");
  268. return -EINVAL;
  269. }
  270. /* make sure reserved bytes are zeroes */
  271. if (rsc->reserved[0] || rsc->reserved[1]) {
  272. dev_err(dev, "vdev rsc has non zero reserved bytes\n");
  273. return -EINVAL;
  274. }
  275. dev_dbg(dev, "vdev rsc: id %d, dfeatures %x, cfg len %d, %d vrings\n",
  276. rsc->id, rsc->dfeatures, rsc->config_len, rsc->num_of_vrings);
  277. /* we currently support only two vrings per rvdev */
  278. if (rsc->num_of_vrings > ARRAY_SIZE(rvdev->vring)) {
  279. dev_err(dev, "too many vrings: %d\n", rsc->num_of_vrings);
  280. return -EINVAL;
  281. }
  282. rvdev = kzalloc(sizeof(struct rproc_vdev), GFP_KERNEL);
  283. if (!rvdev)
  284. return -ENOMEM;
  285. rvdev->rproc = rproc;
  286. /* parse the vrings */
  287. for (i = 0; i < rsc->num_of_vrings; i++) {
  288. ret = rproc_parse_vring(rvdev, rsc, i);
  289. if (ret)
  290. goto free_rvdev;
  291. }
  292. /* remember the device features */
  293. rvdev->dfeatures = rsc->dfeatures;
  294. list_add_tail(&rvdev->node, &rproc->rvdevs);
  295. /* it is now safe to add the virtio device */
  296. ret = rproc_add_virtio_dev(rvdev, rsc->id);
  297. if (ret)
  298. goto free_rvdev;
  299. return 0;
  300. free_rvdev:
  301. kfree(rvdev);
  302. return ret;
  303. }
  304. /**
  305. * rproc_handle_trace() - handle a shared trace buffer resource
  306. * @rproc: the remote processor
  307. * @rsc: the trace resource descriptor
  308. * @avail: size of available data (for sanity checking the image)
  309. *
  310. * In case the remote processor dumps trace logs into memory,
  311. * export it via debugfs.
  312. *
  313. * Currently, the 'da' member of @rsc should contain the device address
  314. * where the remote processor is dumping the traces. Later we could also
  315. * support dynamically allocating this address using the generic
  316. * DMA API (but currently there isn't a use case for that).
  317. *
  318. * Returns 0 on success, or an appropriate error code otherwise
  319. */
  320. static int rproc_handle_trace(struct rproc *rproc, struct fw_rsc_trace *rsc,
  321. int avail)
  322. {
  323. struct rproc_mem_entry *trace;
  324. struct device *dev = &rproc->dev;
  325. void *ptr;
  326. char name[15];
  327. if (sizeof(*rsc) > avail) {
  328. dev_err(dev, "trace rsc is truncated\n");
  329. return -EINVAL;
  330. }
  331. /* make sure reserved bytes are zeroes */
  332. if (rsc->reserved) {
  333. dev_err(dev, "trace rsc has non zero reserved bytes\n");
  334. return -EINVAL;
  335. }
  336. /* what's the kernel address of this resource ? */
  337. ptr = rproc_da_to_va(rproc, rsc->da, rsc->len);
  338. if (!ptr) {
  339. dev_err(dev, "erroneous trace resource entry\n");
  340. return -EINVAL;
  341. }
  342. trace = kzalloc(sizeof(*trace), GFP_KERNEL);
  343. if (!trace) {
  344. dev_err(dev, "kzalloc trace failed\n");
  345. return -ENOMEM;
  346. }
  347. /* set the trace buffer dma properties */
  348. trace->len = rsc->len;
  349. trace->va = ptr;
  350. /* make sure snprintf always null terminates, even if truncating */
  351. snprintf(name, sizeof(name), "trace%d", rproc->num_traces);
  352. /* create the debugfs entry */
  353. trace->priv = rproc_create_trace_file(name, rproc, trace);
  354. if (!trace->priv) {
  355. trace->va = NULL;
  356. kfree(trace);
  357. return -EINVAL;
  358. }
  359. list_add_tail(&trace->node, &rproc->traces);
  360. rproc->num_traces++;
  361. dev_dbg(dev, "%s added: va %p, da 0x%x, len 0x%x\n", name, ptr,
  362. rsc->da, rsc->len);
  363. return 0;
  364. }
  365. /**
  366. * rproc_handle_devmem() - handle devmem resource entry
  367. * @rproc: remote processor handle
  368. * @rsc: the devmem resource entry
  369. * @avail: size of available data (for sanity checking the image)
  370. *
  371. * Remote processors commonly need to access certain on-chip peripherals.
  372. *
  373. * Some of these remote processors access memory via an iommu device,
  374. * and might require us to configure their iommu before they can access
  375. * the on-chip peripherals they need.
  376. *
  377. * This resource entry is a request to map such a peripheral device.
  378. *
  379. * These devmem entries will contain the physical address of the device in
  380. * the 'pa' member. If a specific device address is expected, then 'da' will
  381. * contain it (currently this is the only use case supported). 'len' will
  382. * contain the size of the physical region we need to map.
  383. *
  384. * Currently we just "trust" those devmem entries to contain valid physical
  385. * addresses, but this is going to change: we want the implementations to
  386. * tell us ranges of physical addresses the firmware is allowed to request,
  387. * and not allow firmwares to request access to physical addresses that
  388. * are outside those ranges.
  389. */
  390. static int rproc_handle_devmem(struct rproc *rproc, struct fw_rsc_devmem *rsc,
  391. int avail)
  392. {
  393. struct rproc_mem_entry *mapping;
  394. struct device *dev = &rproc->dev;
  395. int ret;
  396. /* no point in handling this resource without a valid iommu domain */
  397. if (!rproc->domain)
  398. return -EINVAL;
  399. if (sizeof(*rsc) > avail) {
  400. dev_err(dev, "devmem rsc is truncated\n");
  401. return -EINVAL;
  402. }
  403. /* make sure reserved bytes are zeroes */
  404. if (rsc->reserved) {
  405. dev_err(dev, "devmem rsc has non zero reserved bytes\n");
  406. return -EINVAL;
  407. }
  408. mapping = kzalloc(sizeof(*mapping), GFP_KERNEL);
  409. if (!mapping) {
  410. dev_err(dev, "kzalloc mapping failed\n");
  411. return -ENOMEM;
  412. }
  413. ret = iommu_map(rproc->domain, rsc->da, rsc->pa, rsc->len, rsc->flags);
  414. if (ret) {
  415. dev_err(dev, "failed to map devmem: %d\n", ret);
  416. goto out;
  417. }
  418. /*
  419. * We'll need this info later when we'll want to unmap everything
  420. * (e.g. on shutdown).
  421. *
  422. * We can't trust the remote processor not to change the resource
  423. * table, so we must maintain this info independently.
  424. */
  425. mapping->da = rsc->da;
  426. mapping->len = rsc->len;
  427. list_add_tail(&mapping->node, &rproc->mappings);
  428. dev_dbg(dev, "mapped devmem pa 0x%x, da 0x%x, len 0x%x\n",
  429. rsc->pa, rsc->da, rsc->len);
  430. return 0;
  431. out:
  432. kfree(mapping);
  433. return ret;
  434. }
  435. /**
  436. * rproc_handle_carveout() - handle phys contig memory allocation requests
  437. * @rproc: rproc handle
  438. * @rsc: the resource entry
  439. * @avail: size of available data (for image validation)
  440. *
  441. * This function will handle firmware requests for allocation of physically
  442. * contiguous memory regions.
  443. *
  444. * These request entries should come first in the firmware's resource table,
  445. * as other firmware entries might request placing other data objects inside
  446. * these memory regions (e.g. data/code segments, trace resource entries, ...).
  447. *
  448. * Allocating memory this way helps utilizing the reserved physical memory
  449. * (e.g. CMA) more efficiently, and also minimizes the number of TLB entries
  450. * needed to map it (in case @rproc is using an IOMMU). Reducing the TLB
  451. * pressure is important; it may have a substantial impact on performance.
  452. */
  453. static int rproc_handle_carveout(struct rproc *rproc,
  454. struct fw_rsc_carveout *rsc, int avail)
  455. {
  456. struct rproc_mem_entry *carveout, *mapping;
  457. struct device *dev = &rproc->dev;
  458. dma_addr_t dma;
  459. void *va;
  460. int ret;
  461. if (sizeof(*rsc) > avail) {
  462. dev_err(dev, "carveout rsc is truncated\n");
  463. return -EINVAL;
  464. }
  465. /* make sure reserved bytes are zeroes */
  466. if (rsc->reserved) {
  467. dev_err(dev, "carveout rsc has non zero reserved bytes\n");
  468. return -EINVAL;
  469. }
  470. dev_dbg(dev, "carveout rsc: da %x, pa %x, len %x, flags %x\n",
  471. rsc->da, rsc->pa, rsc->len, rsc->flags);
  472. carveout = kzalloc(sizeof(*carveout), GFP_KERNEL);
  473. if (!carveout) {
  474. dev_err(dev, "kzalloc carveout failed\n");
  475. return -ENOMEM;
  476. }
  477. va = dma_alloc_coherent(dev->parent, rsc->len, &dma, GFP_KERNEL);
  478. if (!va) {
  479. dev_err(dev->parent, "dma_alloc_coherent err: %d\n", rsc->len);
  480. ret = -ENOMEM;
  481. goto free_carv;
  482. }
  483. dev_dbg(dev, "carveout va %p, dma %llx, len 0x%x\n", va,
  484. (unsigned long long)dma, rsc->len);
  485. /*
  486. * Ok, this is non-standard.
  487. *
  488. * Sometimes we can't rely on the generic iommu-based DMA API
  489. * to dynamically allocate the device address and then set the IOMMU
  490. * tables accordingly, because some remote processors might
  491. * _require_ us to use hard coded device addresses that their
  492. * firmware was compiled with.
  493. *
  494. * In this case, we must use the IOMMU API directly and map
  495. * the memory to the device address as expected by the remote
  496. * processor.
  497. *
  498. * Obviously such remote processor devices should not be configured
  499. * to use the iommu-based DMA API: we expect 'dma' to contain the
  500. * physical address in this case.
  501. */
  502. if (rproc->domain) {
  503. mapping = kzalloc(sizeof(*mapping), GFP_KERNEL);
  504. if (!mapping) {
  505. dev_err(dev, "kzalloc mapping failed\n");
  506. ret = -ENOMEM;
  507. goto dma_free;
  508. }
  509. ret = iommu_map(rproc->domain, rsc->da, dma, rsc->len,
  510. rsc->flags);
  511. if (ret) {
  512. dev_err(dev, "iommu_map failed: %d\n", ret);
  513. goto free_mapping;
  514. }
  515. /*
  516. * We'll need this info later when we'll want to unmap
  517. * everything (e.g. on shutdown).
  518. *
  519. * We can't trust the remote processor not to change the
  520. * resource table, so we must maintain this info independently.
  521. */
  522. mapping->da = rsc->da;
  523. mapping->len = rsc->len;
  524. list_add_tail(&mapping->node, &rproc->mappings);
  525. dev_dbg(dev, "carveout mapped 0x%x to 0x%llx\n",
  526. rsc->da, (unsigned long long)dma);
  527. }
  528. /*
  529. * Some remote processors might need to know the pa
  530. * even though they are behind an IOMMU. E.g., OMAP4's
  531. * remote M3 processor needs this so it can control
  532. * on-chip hardware accelerators that are not behind
  533. * the IOMMU, and therefor must know the pa.
  534. *
  535. * Generally we don't want to expose physical addresses
  536. * if we don't have to (remote processors are generally
  537. * _not_ trusted), so we might want to do this only for
  538. * remote processor that _must_ have this (e.g. OMAP4's
  539. * dual M3 subsystem).
  540. *
  541. * Non-IOMMU processors might also want to have this info.
  542. * In this case, the device address and the physical address
  543. * are the same.
  544. */
  545. rsc->pa = dma;
  546. carveout->va = va;
  547. carveout->len = rsc->len;
  548. carveout->dma = dma;
  549. carveout->da = rsc->da;
  550. list_add_tail(&carveout->node, &rproc->carveouts);
  551. return 0;
  552. free_mapping:
  553. kfree(mapping);
  554. dma_free:
  555. dma_free_coherent(dev->parent, rsc->len, va, dma);
  556. free_carv:
  557. kfree(carveout);
  558. return ret;
  559. }
  560. static int rproc_count_vrings(struct rproc *rproc, struct fw_rsc_vdev *rsc,
  561. int avail)
  562. {
  563. /* Summarize the number of notification IDs */
  564. rproc->max_notifyid += rsc->num_of_vrings;
  565. return 0;
  566. }
  567. /*
  568. * A lookup table for resource handlers. The indices are defined in
  569. * enum fw_resource_type.
  570. */
  571. static rproc_handle_resource_t rproc_loading_handlers[RSC_LAST] = {
  572. [RSC_CARVEOUT] = (rproc_handle_resource_t)rproc_handle_carveout,
  573. [RSC_DEVMEM] = (rproc_handle_resource_t)rproc_handle_devmem,
  574. [RSC_TRACE] = (rproc_handle_resource_t)rproc_handle_trace,
  575. [RSC_VDEV] = NULL, /* VDEVs were handled upon registrarion */
  576. };
  577. static rproc_handle_resource_t rproc_vdev_handler[RSC_LAST] = {
  578. [RSC_VDEV] = (rproc_handle_resource_t)rproc_handle_vdev,
  579. };
  580. static rproc_handle_resource_t rproc_count_vrings_handler[RSC_LAST] = {
  581. [RSC_VDEV] = (rproc_handle_resource_t)rproc_count_vrings,
  582. };
  583. /* handle firmware resource entries before booting the remote processor */
  584. static int rproc_handle_resources(struct rproc *rproc,
  585. struct resource_table *table, int len,
  586. rproc_handle_resource_t handlers[RSC_LAST])
  587. {
  588. struct device *dev = &rproc->dev;
  589. rproc_handle_resource_t handler;
  590. int ret = 0, i;
  591. for (i = 0; i < table->num; i++) {
  592. int offset = table->offset[i];
  593. struct fw_rsc_hdr *hdr = (void *)table + offset;
  594. int avail = len - offset - sizeof(*hdr);
  595. void *rsc = (void *)hdr + sizeof(*hdr);
  596. /* make sure table isn't truncated */
  597. if (avail < 0) {
  598. dev_err(dev, "rsc table is truncated\n");
  599. return -EINVAL;
  600. }
  601. dev_dbg(dev, "rsc: type %d\n", hdr->type);
  602. if (hdr->type >= RSC_LAST) {
  603. dev_warn(dev, "unsupported resource %d\n", hdr->type);
  604. continue;
  605. }
  606. handler = handlers[hdr->type];
  607. if (!handler)
  608. continue;
  609. ret = handler(rproc, rsc, avail);
  610. if (ret)
  611. break;
  612. }
  613. return ret;
  614. }
  615. /**
  616. * rproc_resource_cleanup() - clean up and free all acquired resources
  617. * @rproc: rproc handle
  618. *
  619. * This function will free all resources acquired for @rproc, and it
  620. * is called whenever @rproc either shuts down or fails to boot.
  621. */
  622. static void rproc_resource_cleanup(struct rproc *rproc)
  623. {
  624. struct rproc_mem_entry *entry, *tmp;
  625. struct device *dev = &rproc->dev;
  626. /* clean up debugfs trace entries */
  627. list_for_each_entry_safe(entry, tmp, &rproc->traces, node) {
  628. rproc_remove_trace_file(entry->priv);
  629. rproc->num_traces--;
  630. list_del(&entry->node);
  631. kfree(entry);
  632. }
  633. /* clean up carveout allocations */
  634. list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) {
  635. dma_free_coherent(dev->parent, entry->len, entry->va, entry->dma);
  636. list_del(&entry->node);
  637. kfree(entry);
  638. }
  639. /* clean up iommu mapping entries */
  640. list_for_each_entry_safe(entry, tmp, &rproc->mappings, node) {
  641. size_t unmapped;
  642. unmapped = iommu_unmap(rproc->domain, entry->da, entry->len);
  643. if (unmapped != entry->len) {
  644. /* nothing much to do besides complaining */
  645. dev_err(dev, "failed to unmap %u/%zu\n", entry->len,
  646. unmapped);
  647. }
  648. list_del(&entry->node);
  649. kfree(entry);
  650. }
  651. }
  652. /*
  653. * take a firmware and boot a remote processor with it.
  654. */
  655. static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
  656. {
  657. struct device *dev = &rproc->dev;
  658. const char *name = rproc->firmware;
  659. struct resource_table *table;
  660. int ret, tablesz;
  661. ret = rproc_fw_sanity_check(rproc, fw);
  662. if (ret)
  663. return ret;
  664. dev_info(dev, "Booting fw image %s, size %zd\n", name, fw->size);
  665. /*
  666. * if enabling an IOMMU isn't relevant for this rproc, this is
  667. * just a nop
  668. */
  669. ret = rproc_enable_iommu(rproc);
  670. if (ret) {
  671. dev_err(dev, "can't enable iommu: %d\n", ret);
  672. return ret;
  673. }
  674. rproc->bootaddr = rproc_get_boot_addr(rproc, fw);
  675. /* look for the resource table */
  676. table = rproc_find_rsc_table(rproc, fw, &tablesz);
  677. if (!table) {
  678. ret = -EINVAL;
  679. goto clean_up;
  680. }
  681. /* handle fw resources which are required to boot rproc */
  682. ret = rproc_handle_resources(rproc, table, tablesz,
  683. rproc_loading_handlers);
  684. if (ret) {
  685. dev_err(dev, "Failed to process resources: %d\n", ret);
  686. goto clean_up;
  687. }
  688. /* load the ELF segments to memory */
  689. ret = rproc_load_segments(rproc, fw);
  690. if (ret) {
  691. dev_err(dev, "Failed to load program segments: %d\n", ret);
  692. goto clean_up;
  693. }
  694. /* power up the remote processor */
  695. ret = rproc->ops->start(rproc);
  696. if (ret) {
  697. dev_err(dev, "can't start rproc %s: %d\n", rproc->name, ret);
  698. goto clean_up;
  699. }
  700. rproc->state = RPROC_RUNNING;
  701. dev_info(dev, "remote processor %s is now up\n", rproc->name);
  702. return 0;
  703. clean_up:
  704. rproc_resource_cleanup(rproc);
  705. rproc_disable_iommu(rproc);
  706. return ret;
  707. }
  708. /*
  709. * take a firmware and look for virtio devices to register.
  710. *
  711. * Note: this function is called asynchronously upon registration of the
  712. * remote processor (so we must wait until it completes before we try
  713. * to unregister the device. one other option is just to use kref here,
  714. * that might be cleaner).
  715. */
  716. static void rproc_fw_config_virtio(const struct firmware *fw, void *context)
  717. {
  718. struct rproc *rproc = context;
  719. struct resource_table *table;
  720. int ret, tablesz;
  721. if (rproc_fw_sanity_check(rproc, fw) < 0)
  722. goto out;
  723. /* look for the resource table */
  724. table = rproc_find_rsc_table(rproc, fw, &tablesz);
  725. if (!table)
  726. goto out;
  727. /* count the number of notify-ids */
  728. rproc->max_notifyid = -1;
  729. ret = rproc_handle_resources(rproc, table, tablesz,
  730. rproc_count_vrings_handler);
  731. /* look for virtio devices and register them */
  732. ret = rproc_handle_resources(rproc, table, tablesz, rproc_vdev_handler);
  733. if (ret)
  734. goto out;
  735. out:
  736. release_firmware(fw);
  737. /* allow rproc_del() contexts, if any, to proceed */
  738. complete_all(&rproc->firmware_loading_complete);
  739. }
  740. static int rproc_add_virtio_devices(struct rproc *rproc)
  741. {
  742. int ret;
  743. /* rproc_del() calls must wait until async loader completes */
  744. init_completion(&rproc->firmware_loading_complete);
  745. /*
  746. * We must retrieve early virtio configuration info from
  747. * the firmware (e.g. whether to register a virtio device,
  748. * what virtio features does it support, ...).
  749. *
  750. * We're initiating an asynchronous firmware loading, so we can
  751. * be built-in kernel code, without hanging the boot process.
  752. */
  753. ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
  754. rproc->firmware, &rproc->dev, GFP_KERNEL,
  755. rproc, rproc_fw_config_virtio);
  756. if (ret < 0) {
  757. dev_err(&rproc->dev, "request_firmware_nowait err: %d\n", ret);
  758. complete_all(&rproc->firmware_loading_complete);
  759. }
  760. return ret;
  761. }
  762. /**
  763. * rproc_trigger_recovery() - recover a remoteproc
  764. * @rproc: the remote processor
  765. *
  766. * The recovery is done by reseting all the virtio devices, that way all the
  767. * rpmsg drivers will be reseted along with the remote processor making the
  768. * remoteproc functional again.
  769. *
  770. * This function can sleep, so it cannot be called from atomic context.
  771. */
  772. int rproc_trigger_recovery(struct rproc *rproc)
  773. {
  774. struct rproc_vdev *rvdev, *rvtmp;
  775. dev_err(&rproc->dev, "recovering %s\n", rproc->name);
  776. init_completion(&rproc->crash_comp);
  777. /* clean up remote vdev entries */
  778. list_for_each_entry_safe(rvdev, rvtmp, &rproc->rvdevs, node)
  779. rproc_remove_virtio_dev(rvdev);
  780. /* wait until there is no more rproc users */
  781. wait_for_completion(&rproc->crash_comp);
  782. return rproc_add_virtio_devices(rproc);
  783. }
  784. /**
  785. * rproc_crash_handler_work() - handle a crash
  786. *
  787. * This function needs to handle everything related to a crash, like cpu
  788. * registers and stack dump, information to help to debug the fatal error, etc.
  789. */
  790. static void rproc_crash_handler_work(struct work_struct *work)
  791. {
  792. struct rproc *rproc = container_of(work, struct rproc, crash_handler);
  793. struct device *dev = &rproc->dev;
  794. dev_dbg(dev, "enter %s\n", __func__);
  795. mutex_lock(&rproc->lock);
  796. if (rproc->state == RPROC_CRASHED || rproc->state == RPROC_OFFLINE) {
  797. /* handle only the first crash detected */
  798. mutex_unlock(&rproc->lock);
  799. return;
  800. }
  801. rproc->state = RPROC_CRASHED;
  802. dev_err(dev, "handling crash #%u in %s\n", ++rproc->crash_cnt,
  803. rproc->name);
  804. mutex_unlock(&rproc->lock);
  805. if (!rproc->recovery_disabled)
  806. rproc_trigger_recovery(rproc);
  807. }
  808. /**
  809. * rproc_boot() - boot a remote processor
  810. * @rproc: handle of a remote processor
  811. *
  812. * Boot a remote processor (i.e. load its firmware, power it on, ...).
  813. *
  814. * If the remote processor is already powered on, this function immediately
  815. * returns (successfully).
  816. *
  817. * Returns 0 on success, and an appropriate error value otherwise.
  818. */
  819. int rproc_boot(struct rproc *rproc)
  820. {
  821. const struct firmware *firmware_p;
  822. struct device *dev;
  823. int ret;
  824. if (!rproc) {
  825. pr_err("invalid rproc handle\n");
  826. return -EINVAL;
  827. }
  828. dev = &rproc->dev;
  829. ret = mutex_lock_interruptible(&rproc->lock);
  830. if (ret) {
  831. dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret);
  832. return ret;
  833. }
  834. /* loading a firmware is required */
  835. if (!rproc->firmware) {
  836. dev_err(dev, "%s: no firmware to load\n", __func__);
  837. ret = -EINVAL;
  838. goto unlock_mutex;
  839. }
  840. /* prevent underlying implementation from being removed */
  841. if (!try_module_get(dev->parent->driver->owner)) {
  842. dev_err(dev, "%s: can't get owner\n", __func__);
  843. ret = -EINVAL;
  844. goto unlock_mutex;
  845. }
  846. /* skip the boot process if rproc is already powered up */
  847. if (atomic_inc_return(&rproc->power) > 1) {
  848. ret = 0;
  849. goto unlock_mutex;
  850. }
  851. dev_info(dev, "powering up %s\n", rproc->name);
  852. /* load firmware */
  853. ret = request_firmware(&firmware_p, rproc->firmware, dev);
  854. if (ret < 0) {
  855. dev_err(dev, "request_firmware failed: %d\n", ret);
  856. goto downref_rproc;
  857. }
  858. ret = rproc_fw_boot(rproc, firmware_p);
  859. release_firmware(firmware_p);
  860. downref_rproc:
  861. if (ret) {
  862. module_put(dev->parent->driver->owner);
  863. atomic_dec(&rproc->power);
  864. }
  865. unlock_mutex:
  866. mutex_unlock(&rproc->lock);
  867. return ret;
  868. }
  869. EXPORT_SYMBOL(rproc_boot);
  870. /**
  871. * rproc_shutdown() - power off the remote processor
  872. * @rproc: the remote processor
  873. *
  874. * Power off a remote processor (previously booted with rproc_boot()).
  875. *
  876. * In case @rproc is still being used by an additional user(s), then
  877. * this function will just decrement the power refcount and exit,
  878. * without really powering off the device.
  879. *
  880. * Every call to rproc_boot() must (eventually) be accompanied by a call
  881. * to rproc_shutdown(). Calling rproc_shutdown() redundantly is a bug.
  882. *
  883. * Notes:
  884. * - we're not decrementing the rproc's refcount, only the power refcount.
  885. * which means that the @rproc handle stays valid even after rproc_shutdown()
  886. * returns, and users can still use it with a subsequent rproc_boot(), if
  887. * needed.
  888. */
  889. void rproc_shutdown(struct rproc *rproc)
  890. {
  891. struct device *dev = &rproc->dev;
  892. int ret;
  893. ret = mutex_lock_interruptible(&rproc->lock);
  894. if (ret) {
  895. dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret);
  896. return;
  897. }
  898. /* if the remote proc is still needed, bail out */
  899. if (!atomic_dec_and_test(&rproc->power))
  900. goto out;
  901. /* power off the remote processor */
  902. ret = rproc->ops->stop(rproc);
  903. if (ret) {
  904. atomic_inc(&rproc->power);
  905. dev_err(dev, "can't stop rproc: %d\n", ret);
  906. goto out;
  907. }
  908. /* clean up all acquired resources */
  909. rproc_resource_cleanup(rproc);
  910. rproc_disable_iommu(rproc);
  911. /* if in crash state, unlock crash handler */
  912. if (rproc->state == RPROC_CRASHED)
  913. complete_all(&rproc->crash_comp);
  914. rproc->state = RPROC_OFFLINE;
  915. dev_info(dev, "stopped remote processor %s\n", rproc->name);
  916. out:
  917. mutex_unlock(&rproc->lock);
  918. if (!ret)
  919. module_put(dev->parent->driver->owner);
  920. }
  921. EXPORT_SYMBOL(rproc_shutdown);
  922. /**
  923. * rproc_add() - register a remote processor
  924. * @rproc: the remote processor handle to register
  925. *
  926. * Registers @rproc with the remoteproc framework, after it has been
  927. * allocated with rproc_alloc().
  928. *
  929. * This is called by the platform-specific rproc implementation, whenever
  930. * a new remote processor device is probed.
  931. *
  932. * Returns 0 on success and an appropriate error code otherwise.
  933. *
  934. * Note: this function initiates an asynchronous firmware loading
  935. * context, which will look for virtio devices supported by the rproc's
  936. * firmware.
  937. *
  938. * If found, those virtio devices will be created and added, so as a result
  939. * of registering this remote processor, additional virtio drivers might be
  940. * probed.
  941. */
  942. int rproc_add(struct rproc *rproc)
  943. {
  944. struct device *dev = &rproc->dev;
  945. int ret;
  946. ret = device_add(dev);
  947. if (ret < 0)
  948. return ret;
  949. dev_info(dev, "%s is available\n", rproc->name);
  950. dev_info(dev, "Note: remoteproc is still under development and considered experimental.\n");
  951. dev_info(dev, "THE BINARY FORMAT IS NOT YET FINALIZED, and backward compatibility isn't yet guaranteed.\n");
  952. /* create debugfs entries */
  953. rproc_create_debug_dir(rproc);
  954. return rproc_add_virtio_devices(rproc);
  955. }
  956. EXPORT_SYMBOL(rproc_add);
  957. /**
  958. * rproc_type_release() - release a remote processor instance
  959. * @dev: the rproc's device
  960. *
  961. * This function should _never_ be called directly.
  962. *
  963. * It will be called by the driver core when no one holds a valid pointer
  964. * to @dev anymore.
  965. */
  966. static void rproc_type_release(struct device *dev)
  967. {
  968. struct rproc *rproc = container_of(dev, struct rproc, dev);
  969. dev_info(&rproc->dev, "releasing %s\n", rproc->name);
  970. rproc_delete_debug_dir(rproc);
  971. idr_destroy(&rproc->notifyids);
  972. if (rproc->index >= 0)
  973. ida_simple_remove(&rproc_dev_index, rproc->index);
  974. kfree(rproc);
  975. }
  976. static struct device_type rproc_type = {
  977. .name = "remoteproc",
  978. .release = rproc_type_release,
  979. };
  980. /**
  981. * rproc_alloc() - allocate a remote processor handle
  982. * @dev: the underlying device
  983. * @name: name of this remote processor
  984. * @ops: platform-specific handlers (mainly start/stop)
  985. * @firmware: name of firmware file to load
  986. * @len: length of private data needed by the rproc driver (in bytes)
  987. *
  988. * Allocates a new remote processor handle, but does not register
  989. * it yet.
  990. *
  991. * This function should be used by rproc implementations during initialization
  992. * of the remote processor.
  993. *
  994. * After creating an rproc handle using this function, and when ready,
  995. * implementations should then call rproc_add() to complete
  996. * the registration of the remote processor.
  997. *
  998. * On success the new rproc is returned, and on failure, NULL.
  999. *
  1000. * Note: _never_ directly deallocate @rproc, even if it was not registered
  1001. * yet. Instead, when you need to unroll rproc_alloc(), use rproc_put().
  1002. */
  1003. struct rproc *rproc_alloc(struct device *dev, const char *name,
  1004. const struct rproc_ops *ops,
  1005. const char *firmware, int len)
  1006. {
  1007. struct rproc *rproc;
  1008. if (!dev || !name || !ops)
  1009. return NULL;
  1010. rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL);
  1011. if (!rproc) {
  1012. dev_err(dev, "%s: kzalloc failed\n", __func__);
  1013. return NULL;
  1014. }
  1015. rproc->name = name;
  1016. rproc->ops = ops;
  1017. rproc->firmware = firmware;
  1018. rproc->priv = &rproc[1];
  1019. device_initialize(&rproc->dev);
  1020. rproc->dev.parent = dev;
  1021. rproc->dev.type = &rproc_type;
  1022. /* Assign a unique device index and name */
  1023. rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL);
  1024. if (rproc->index < 0) {
  1025. dev_err(dev, "ida_simple_get failed: %d\n", rproc->index);
  1026. put_device(&rproc->dev);
  1027. return NULL;
  1028. }
  1029. dev_set_name(&rproc->dev, "remoteproc%d", rproc->index);
  1030. atomic_set(&rproc->power, 0);
  1031. /* Set ELF as the default fw_ops handler */
  1032. rproc->fw_ops = &rproc_elf_fw_ops;
  1033. mutex_init(&rproc->lock);
  1034. idr_init(&rproc->notifyids);
  1035. INIT_LIST_HEAD(&rproc->carveouts);
  1036. INIT_LIST_HEAD(&rproc->mappings);
  1037. INIT_LIST_HEAD(&rproc->traces);
  1038. INIT_LIST_HEAD(&rproc->rvdevs);
  1039. INIT_WORK(&rproc->crash_handler, rproc_crash_handler_work);
  1040. init_completion(&rproc->crash_comp);
  1041. rproc->state = RPROC_OFFLINE;
  1042. return rproc;
  1043. }
  1044. EXPORT_SYMBOL(rproc_alloc);
  1045. /**
  1046. * rproc_put() - unroll rproc_alloc()
  1047. * @rproc: the remote processor handle
  1048. *
  1049. * This function decrements the rproc dev refcount.
  1050. *
  1051. * If no one holds any reference to rproc anymore, then its refcount would
  1052. * now drop to zero, and it would be freed.
  1053. */
  1054. void rproc_put(struct rproc *rproc)
  1055. {
  1056. put_device(&rproc->dev);
  1057. }
  1058. EXPORT_SYMBOL(rproc_put);
  1059. /**
  1060. * rproc_del() - unregister a remote processor
  1061. * @rproc: rproc handle to unregister
  1062. *
  1063. * This function should be called when the platform specific rproc
  1064. * implementation decides to remove the rproc device. it should
  1065. * _only_ be called if a previous invocation of rproc_add()
  1066. * has completed successfully.
  1067. *
  1068. * After rproc_del() returns, @rproc isn't freed yet, because
  1069. * of the outstanding reference created by rproc_alloc. To decrement that
  1070. * one last refcount, one still needs to call rproc_put().
  1071. *
  1072. * Returns 0 on success and -EINVAL if @rproc isn't valid.
  1073. */
  1074. int rproc_del(struct rproc *rproc)
  1075. {
  1076. struct rproc_vdev *rvdev, *tmp;
  1077. if (!rproc)
  1078. return -EINVAL;
  1079. /* if rproc is just being registered, wait */
  1080. wait_for_completion(&rproc->firmware_loading_complete);
  1081. /* clean up remote vdev entries */
  1082. list_for_each_entry_safe(rvdev, tmp, &rproc->rvdevs, node)
  1083. rproc_remove_virtio_dev(rvdev);
  1084. device_del(&rproc->dev);
  1085. return 0;
  1086. }
  1087. EXPORT_SYMBOL(rproc_del);
  1088. /**
  1089. * rproc_report_crash() - rproc crash reporter function
  1090. * @rproc: remote processor
  1091. * @type: crash type
  1092. *
  1093. * This function must be called every time a crash is detected by the low-level
  1094. * drivers implementing a specific remoteproc. This should not be called from a
  1095. * non-remoteproc driver.
  1096. *
  1097. * This function can be called from atomic/interrupt context.
  1098. */
  1099. void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type)
  1100. {
  1101. if (!rproc) {
  1102. pr_err("NULL rproc pointer\n");
  1103. return;
  1104. }
  1105. dev_err(&rproc->dev, "crash detected in %s: type %s\n",
  1106. rproc->name, rproc_crash_to_string(type));
  1107. /* create a new task to handle the error */
  1108. schedule_work(&rproc->crash_handler);
  1109. }
  1110. EXPORT_SYMBOL(rproc_report_crash);
  1111. static int __init remoteproc_init(void)
  1112. {
  1113. rproc_init_debugfs();
  1114. return 0;
  1115. }
  1116. module_init(remoteproc_init);
  1117. static void __exit remoteproc_exit(void)
  1118. {
  1119. rproc_exit_debugfs();
  1120. }
  1121. module_exit(remoteproc_exit);
  1122. MODULE_LICENSE("GPL v2");
  1123. MODULE_DESCRIPTION("Generic Remote Processor Framework");