dev.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Tegra host1x driver
  4. *
  5. * Copyright (c) 2010-2013, NVIDIA Corporation.
  6. */
  7. #include <linux/clk.h>
  8. #include <linux/delay.h>
  9. #include <linux/dma-mapping.h>
  10. #include <linux/io.h>
  11. #include <linux/list.h>
  12. #include <linux/module.h>
  13. #include <linux/of.h>
  14. #include <linux/of_platform.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pm_runtime.h>
  17. #include <linux/slab.h>
  18. #include <soc/tegra/common.h>
  19. #define CREATE_TRACE_POINTS
  20. #include <trace/events/host1x.h>
  21. #undef CREATE_TRACE_POINTS
  22. #if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)
  23. #include <asm/dma-iommu.h>
  24. #endif
  25. #include "bus.h"
  26. #include "channel.h"
  27. #include "context.h"
  28. #include "debug.h"
  29. #include "dev.h"
  30. #include "intr.h"
  31. #include "hw/host1x01.h"
  32. #include "hw/host1x02.h"
  33. #include "hw/host1x04.h"
  34. #include "hw/host1x05.h"
  35. #include "hw/host1x06.h"
  36. #include "hw/host1x07.h"
  37. #include "hw/host1x08.h"
  38. void host1x_common_writel(struct host1x *host1x, u32 v, u32 r)
  39. {
  40. writel(v, host1x->common_regs + r);
  41. }
  42. void host1x_hypervisor_writel(struct host1x *host1x, u32 v, u32 r)
  43. {
  44. writel(v, host1x->hv_regs + r);
  45. }
  46. u32 host1x_hypervisor_readl(struct host1x *host1x, u32 r)
  47. {
  48. return readl(host1x->hv_regs + r);
  49. }
  50. void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
  51. {
  52. void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
  53. writel(v, sync_regs + r);
  54. }
  55. u32 host1x_sync_readl(struct host1x *host1x, u32 r)
  56. {
  57. void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
  58. return readl(sync_regs + r);
  59. }
  60. void host1x_ch_writel(struct host1x_channel *ch, u32 v, u32 r)
  61. {
  62. writel(v, ch->regs + r);
  63. }
  64. u32 host1x_ch_readl(struct host1x_channel *ch, u32 r)
  65. {
  66. return readl(ch->regs + r);
  67. }
  68. static const struct host1x_info host1x01_info = {
  69. .nb_channels = 8,
  70. .nb_pts = 32,
  71. .nb_mlocks = 16,
  72. .nb_bases = 8,
  73. .init = host1x01_init,
  74. .sync_offset = 0x3000,
  75. .dma_mask = DMA_BIT_MASK(32),
  76. .has_wide_gather = false,
  77. .has_hypervisor = false,
  78. .num_sid_entries = 0,
  79. .sid_table = NULL,
  80. .reserve_vblank_syncpts = true,
  81. };
  82. static const struct host1x_info host1x02_info = {
  83. .nb_channels = 9,
  84. .nb_pts = 32,
  85. .nb_mlocks = 16,
  86. .nb_bases = 12,
  87. .init = host1x02_init,
  88. .sync_offset = 0x3000,
  89. .dma_mask = DMA_BIT_MASK(32),
  90. .has_wide_gather = false,
  91. .has_hypervisor = false,
  92. .num_sid_entries = 0,
  93. .sid_table = NULL,
  94. .reserve_vblank_syncpts = true,
  95. };
  96. static const struct host1x_info host1x04_info = {
  97. .nb_channels = 12,
  98. .nb_pts = 192,
  99. .nb_mlocks = 16,
  100. .nb_bases = 64,
  101. .init = host1x04_init,
  102. .sync_offset = 0x2100,
  103. .dma_mask = DMA_BIT_MASK(34),
  104. .has_wide_gather = false,
  105. .has_hypervisor = false,
  106. .num_sid_entries = 0,
  107. .sid_table = NULL,
  108. .reserve_vblank_syncpts = false,
  109. };
  110. static const struct host1x_info host1x05_info = {
  111. .nb_channels = 14,
  112. .nb_pts = 192,
  113. .nb_mlocks = 16,
  114. .nb_bases = 64,
  115. .init = host1x05_init,
  116. .sync_offset = 0x2100,
  117. .dma_mask = DMA_BIT_MASK(34),
  118. .has_wide_gather = false,
  119. .has_hypervisor = false,
  120. .num_sid_entries = 0,
  121. .sid_table = NULL,
  122. .reserve_vblank_syncpts = false,
  123. };
  124. static const struct host1x_sid_entry tegra186_sid_table[] = {
  125. {
  126. /* VIC */
  127. .base = 0x1af0,
  128. .offset = 0x30,
  129. .limit = 0x34
  130. },
  131. {
  132. /* NVDEC */
  133. .base = 0x1b00,
  134. .offset = 0x30,
  135. .limit = 0x34
  136. },
  137. };
  138. static const struct host1x_info host1x06_info = {
  139. .nb_channels = 63,
  140. .nb_pts = 576,
  141. .nb_mlocks = 24,
  142. .nb_bases = 16,
  143. .init = host1x06_init,
  144. .sync_offset = 0x0,
  145. .dma_mask = DMA_BIT_MASK(40),
  146. .has_wide_gather = true,
  147. .has_hypervisor = true,
  148. .num_sid_entries = ARRAY_SIZE(tegra186_sid_table),
  149. .sid_table = tegra186_sid_table,
  150. .reserve_vblank_syncpts = false,
  151. .skip_reset_assert = true,
  152. };
  153. static const struct host1x_sid_entry tegra194_sid_table[] = {
  154. {
  155. /* VIC */
  156. .base = 0x1af0,
  157. .offset = 0x30,
  158. .limit = 0x34
  159. },
  160. {
  161. /* NVDEC */
  162. .base = 0x1b00,
  163. .offset = 0x30,
  164. .limit = 0x34
  165. },
  166. {
  167. /* NVDEC1 */
  168. .base = 0x1bc0,
  169. .offset = 0x30,
  170. .limit = 0x34
  171. },
  172. };
  173. static const struct host1x_info host1x07_info = {
  174. .nb_channels = 63,
  175. .nb_pts = 704,
  176. .nb_mlocks = 32,
  177. .nb_bases = 0,
  178. .init = host1x07_init,
  179. .sync_offset = 0x0,
  180. .dma_mask = DMA_BIT_MASK(40),
  181. .has_wide_gather = true,
  182. .has_hypervisor = true,
  183. .num_sid_entries = ARRAY_SIZE(tegra194_sid_table),
  184. .sid_table = tegra194_sid_table,
  185. .reserve_vblank_syncpts = false,
  186. };
  187. /*
  188. * Tegra234 has two stream ID protection tables, one for setting stream IDs
  189. * through the channel path via SETSTREAMID, and one for setting them via
  190. * MMIO. We program each engine's data stream ID in the channel path table
  191. * and firmware stream ID in the MMIO path table.
  192. */
  193. static const struct host1x_sid_entry tegra234_sid_table[] = {
  194. {
  195. /* SE2 MMIO */
  196. .base = 0x1658,
  197. .offset = 0x90,
  198. .limit = 0x90
  199. },
  200. {
  201. /* SE4 MMIO */
  202. .base = 0x1660,
  203. .offset = 0x90,
  204. .limit = 0x90
  205. },
  206. {
  207. /* SE2 channel */
  208. .base = 0x1738,
  209. .offset = 0x90,
  210. .limit = 0x90
  211. },
  212. {
  213. /* SE4 channel */
  214. .base = 0x1740,
  215. .offset = 0x90,
  216. .limit = 0x90
  217. },
  218. {
  219. /* VIC channel */
  220. .base = 0x17b8,
  221. .offset = 0x30,
  222. .limit = 0x30
  223. },
  224. {
  225. /* VIC MMIO */
  226. .base = 0x1688,
  227. .offset = 0x34,
  228. .limit = 0x34
  229. },
  230. {
  231. /* NVDEC channel */
  232. .base = 0x17c8,
  233. .offset = 0x30,
  234. .limit = 0x30,
  235. },
  236. {
  237. /* NVDEC MMIO */
  238. .base = 0x1698,
  239. .offset = 0x34,
  240. .limit = 0x34,
  241. },
  242. };
  243. static const struct host1x_info host1x08_info = {
  244. .nb_channels = 63,
  245. .nb_pts = 1024,
  246. .nb_mlocks = 24,
  247. .nb_bases = 0,
  248. .init = host1x08_init,
  249. .sync_offset = 0x0,
  250. .dma_mask = DMA_BIT_MASK(40),
  251. .has_wide_gather = true,
  252. .has_hypervisor = true,
  253. .has_common = true,
  254. .num_sid_entries = ARRAY_SIZE(tegra234_sid_table),
  255. .sid_table = tegra234_sid_table,
  256. .streamid_vm_table = { 0x1004, 128 },
  257. .classid_vm_table = { 0x1404, 25 },
  258. .mmio_vm_table = { 0x1504, 25 },
  259. .reserve_vblank_syncpts = false,
  260. };
  261. static const struct of_device_id host1x_of_match[] = {
  262. { .compatible = "nvidia,tegra234-host1x", .data = &host1x08_info, },
  263. { .compatible = "nvidia,tegra194-host1x", .data = &host1x07_info, },
  264. { .compatible = "nvidia,tegra186-host1x", .data = &host1x06_info, },
  265. { .compatible = "nvidia,tegra210-host1x", .data = &host1x05_info, },
  266. { .compatible = "nvidia,tegra124-host1x", .data = &host1x04_info, },
  267. { .compatible = "nvidia,tegra114-host1x", .data = &host1x02_info, },
  268. { .compatible = "nvidia,tegra30-host1x", .data = &host1x01_info, },
  269. { .compatible = "nvidia,tegra20-host1x", .data = &host1x01_info, },
  270. { },
  271. };
  272. MODULE_DEVICE_TABLE(of, host1x_of_match);
  273. static void host1x_setup_virtualization_tables(struct host1x *host)
  274. {
  275. const struct host1x_info *info = host->info;
  276. unsigned int i;
  277. if (!info->has_hypervisor)
  278. return;
  279. for (i = 0; i < info->num_sid_entries; i++) {
  280. const struct host1x_sid_entry *entry = &info->sid_table[i];
  281. host1x_hypervisor_writel(host, entry->offset, entry->base);
  282. host1x_hypervisor_writel(host, entry->limit, entry->base + 4);
  283. }
  284. for (i = 0; i < info->streamid_vm_table.count; i++) {
  285. /* Allow access to all stream IDs to all VMs. */
  286. host1x_hypervisor_writel(host, 0xff, info->streamid_vm_table.base + 4 * i);
  287. }
  288. for (i = 0; i < info->classid_vm_table.count; i++) {
  289. /* Allow access to all classes to all VMs. */
  290. host1x_hypervisor_writel(host, 0xff, info->classid_vm_table.base + 4 * i);
  291. }
  292. for (i = 0; i < info->mmio_vm_table.count; i++) {
  293. /* Use VM1 (that's us) as originator VMID for engine MMIO accesses. */
  294. host1x_hypervisor_writel(host, 0x1, info->mmio_vm_table.base + 4 * i);
  295. }
  296. }
  297. static bool host1x_wants_iommu(struct host1x *host1x)
  298. {
  299. /* Our IOMMU usage policy doesn't currently play well with GART */
  300. if (of_machine_is_compatible("nvidia,tegra20"))
  301. return false;
  302. /*
  303. * If we support addressing a maximum of 32 bits of physical memory
  304. * and if the host1x firewall is enabled, there's no need to enable
  305. * IOMMU support. This can happen for example on Tegra20, Tegra30
  306. * and Tegra114.
  307. *
  308. * Tegra124 and later can address up to 34 bits of physical memory and
  309. * many platforms come equipped with more than 2 GiB of system memory,
  310. * which requires crossing the 4 GiB boundary. But there's a catch: on
  311. * SoCs before Tegra186 (i.e. Tegra124 and Tegra210), the host1x can
  312. * only address up to 32 bits of memory in GATHER opcodes, which means
  313. * that command buffers need to either be in the first 2 GiB of system
  314. * memory (which could quickly lead to memory exhaustion), or command
  315. * buffers need to be treated differently from other buffers (which is
  316. * not possible with the current ABI).
  317. *
  318. * A third option is to use the IOMMU in these cases to make sure all
  319. * buffers will be mapped into a 32-bit IOVA space that host1x can
  320. * address. This allows all of the system memory to be used and works
  321. * within the limitations of the host1x on these SoCs.
  322. *
  323. * In summary, default to enable IOMMU on Tegra124 and later. For any
  324. * of the earlier SoCs, only use the IOMMU for additional safety when
  325. * the host1x firewall is disabled.
  326. */
  327. if (host1x->info->dma_mask <= DMA_BIT_MASK(32)) {
  328. if (IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL))
  329. return false;
  330. }
  331. return true;
  332. }
  333. /*
  334. * Returns ERR_PTR on failure, NULL if the translation is IDENTITY, otherwise a
  335. * valid paging domain.
  336. */
  337. static struct iommu_domain *host1x_iommu_attach(struct host1x *host)
  338. {
  339. struct iommu_domain *domain = iommu_get_domain_for_dev(host->dev);
  340. int err;
  341. #if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)
  342. if (host->dev->archdata.mapping) {
  343. struct dma_iommu_mapping *mapping =
  344. to_dma_iommu_mapping(host->dev);
  345. arm_iommu_detach_device(host->dev);
  346. arm_iommu_release_mapping(mapping);
  347. domain = iommu_get_domain_for_dev(host->dev);
  348. }
  349. #endif
  350. /*
  351. * We may not always want to enable IOMMU support (for example if the
  352. * host1x firewall is already enabled and we don't support addressing
  353. * more than 32 bits of physical memory), so check for that first.
  354. *
  355. * Similarly, if host1x is already attached to an IOMMU (via the DMA
  356. * API), don't try to attach again.
  357. */
  358. if (domain && domain->type == IOMMU_DOMAIN_IDENTITY)
  359. domain = NULL;
  360. if (!host1x_wants_iommu(host) || domain)
  361. return domain;
  362. host->group = iommu_group_get(host->dev);
  363. if (host->group) {
  364. struct iommu_domain_geometry *geometry;
  365. dma_addr_t start, end;
  366. unsigned long order;
  367. err = iova_cache_get();
  368. if (err < 0)
  369. goto put_group;
  370. host->domain = iommu_paging_domain_alloc(host->dev);
  371. if (IS_ERR(host->domain)) {
  372. err = PTR_ERR(host->domain);
  373. host->domain = NULL;
  374. goto put_cache;
  375. }
  376. err = iommu_attach_group(host->domain, host->group);
  377. if (err) {
  378. if (err == -ENODEV)
  379. err = 0;
  380. goto free_domain;
  381. }
  382. geometry = &host->domain->geometry;
  383. start = geometry->aperture_start & host->info->dma_mask;
  384. end = geometry->aperture_end & host->info->dma_mask;
  385. order = __ffs(host->domain->pgsize_bitmap);
  386. init_iova_domain(&host->iova, 1UL << order, start >> order);
  387. host->iova_end = end;
  388. domain = host->domain;
  389. }
  390. return domain;
  391. free_domain:
  392. iommu_domain_free(host->domain);
  393. host->domain = NULL;
  394. put_cache:
  395. iova_cache_put();
  396. put_group:
  397. iommu_group_put(host->group);
  398. host->group = NULL;
  399. return ERR_PTR(err);
  400. }
  401. static int host1x_iommu_init(struct host1x *host)
  402. {
  403. u64 mask = host->info->dma_mask;
  404. struct iommu_domain *domain;
  405. int err;
  406. domain = host1x_iommu_attach(host);
  407. if (IS_ERR(domain)) {
  408. err = PTR_ERR(domain);
  409. dev_err(host->dev, "failed to attach to IOMMU: %d\n", err);
  410. return err;
  411. }
  412. /*
  413. * If we're not behind an IOMMU make sure we don't get push buffers
  414. * that are allocated outside of the range addressable by the GATHER
  415. * opcode.
  416. *
  417. * Newer generations of Tegra (Tegra186 and later) support a wide
  418. * variant of the GATHER opcode that allows addressing more bits.
  419. */
  420. if (!domain && !host->info->has_wide_gather)
  421. mask = DMA_BIT_MASK(32);
  422. err = dma_coerce_mask_and_coherent(host->dev, mask);
  423. if (err < 0) {
  424. dev_err(host->dev, "failed to set DMA mask: %d\n", err);
  425. return err;
  426. }
  427. return 0;
  428. }
  429. static void host1x_iommu_exit(struct host1x *host)
  430. {
  431. if (host->domain) {
  432. put_iova_domain(&host->iova);
  433. iommu_detach_group(host->domain, host->group);
  434. iommu_domain_free(host->domain);
  435. host->domain = NULL;
  436. iova_cache_put();
  437. iommu_group_put(host->group);
  438. host->group = NULL;
  439. }
  440. }
  441. static int host1x_get_resets(struct host1x *host)
  442. {
  443. int err;
  444. host->resets[0].id = "mc";
  445. host->resets[1].id = "host1x";
  446. host->nresets = ARRAY_SIZE(host->resets);
  447. err = devm_reset_control_bulk_get_optional_exclusive_released(
  448. host->dev, host->nresets, host->resets);
  449. if (err) {
  450. dev_err(host->dev, "failed to get reset: %d\n", err);
  451. return err;
  452. }
  453. return 0;
  454. }
  455. static int host1x_probe(struct platform_device *pdev)
  456. {
  457. struct host1x *host;
  458. int err, i;
  459. host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
  460. if (!host)
  461. return -ENOMEM;
  462. host->info = of_device_get_match_data(&pdev->dev);
  463. if (host->info->has_hypervisor) {
  464. host->regs = devm_platform_ioremap_resource_byname(pdev, "vm");
  465. if (IS_ERR(host->regs))
  466. return PTR_ERR(host->regs);
  467. host->hv_regs = devm_platform_ioremap_resource_byname(pdev, "hypervisor");
  468. if (IS_ERR(host->hv_regs))
  469. return PTR_ERR(host->hv_regs);
  470. if (host->info->has_common) {
  471. host->common_regs = devm_platform_ioremap_resource_byname(pdev, "common");
  472. if (IS_ERR(host->common_regs))
  473. return PTR_ERR(host->common_regs);
  474. }
  475. } else {
  476. host->regs = devm_platform_ioremap_resource(pdev, 0);
  477. if (IS_ERR(host->regs))
  478. return PTR_ERR(host->regs);
  479. }
  480. for (i = 0; i < ARRAY_SIZE(host->syncpt_irqs); i++) {
  481. char irq_name[] = "syncptX";
  482. sprintf(irq_name, "syncpt%d", i);
  483. err = platform_get_irq_byname_optional(pdev, irq_name);
  484. if (err == -ENXIO)
  485. break;
  486. if (err < 0)
  487. return err;
  488. host->syncpt_irqs[i] = err;
  489. }
  490. host->num_syncpt_irqs = i;
  491. /* Device tree without irq names */
  492. if (i == 0) {
  493. host->syncpt_irqs[0] = platform_get_irq(pdev, 0);
  494. if (host->syncpt_irqs[0] < 0)
  495. return host->syncpt_irqs[0];
  496. host->num_syncpt_irqs = 1;
  497. }
  498. mutex_init(&host->devices_lock);
  499. INIT_LIST_HEAD(&host->devices);
  500. INIT_LIST_HEAD(&host->list);
  501. host->dev = &pdev->dev;
  502. /* set common host1x device data */
  503. platform_set_drvdata(pdev, host);
  504. host->dev->dma_parms = &host->dma_parms;
  505. dma_set_max_seg_size(host->dev, UINT_MAX);
  506. if (host->info->init) {
  507. err = host->info->init(host);
  508. if (err)
  509. return err;
  510. }
  511. host->clk = devm_clk_get(&pdev->dev, NULL);
  512. if (IS_ERR(host->clk)) {
  513. err = PTR_ERR(host->clk);
  514. if (err != -EPROBE_DEFER)
  515. dev_err(&pdev->dev, "failed to get clock: %d\n", err);
  516. return err;
  517. }
  518. err = host1x_get_resets(host);
  519. if (err)
  520. return err;
  521. host1x_bo_cache_init(&host->cache);
  522. err = host1x_iommu_init(host);
  523. if (err < 0) {
  524. dev_err(&pdev->dev, "failed to setup IOMMU: %d\n", err);
  525. goto destroy_cache;
  526. }
  527. err = host1x_channel_list_init(&host->channel_list,
  528. host->info->nb_channels);
  529. if (err) {
  530. dev_err(&pdev->dev, "failed to initialize channel list\n");
  531. goto iommu_exit;
  532. }
  533. err = host1x_memory_context_list_init(host);
  534. if (err) {
  535. dev_err(&pdev->dev, "failed to initialize context list\n");
  536. goto free_channels;
  537. }
  538. err = host1x_syncpt_init(host);
  539. if (err) {
  540. dev_err(&pdev->dev, "failed to initialize syncpts\n");
  541. goto free_contexts;
  542. }
  543. mutex_init(&host->intr_mutex);
  544. pm_runtime_enable(&pdev->dev);
  545. err = devm_tegra_core_dev_init_opp_table_common(&pdev->dev);
  546. if (err)
  547. goto pm_disable;
  548. /* the driver's code isn't ready yet for the dynamic RPM */
  549. err = pm_runtime_resume_and_get(&pdev->dev);
  550. if (err)
  551. goto pm_disable;
  552. err = host1x_intr_init(host);
  553. if (err) {
  554. dev_err(&pdev->dev, "failed to initialize interrupts\n");
  555. goto pm_put;
  556. }
  557. host1x_debug_init(host);
  558. err = host1x_register(host);
  559. if (err < 0)
  560. goto deinit_debugfs;
  561. err = devm_of_platform_populate(&pdev->dev);
  562. if (err < 0)
  563. goto unregister;
  564. return 0;
  565. unregister:
  566. host1x_unregister(host);
  567. deinit_debugfs:
  568. host1x_debug_deinit(host);
  569. host1x_intr_deinit(host);
  570. pm_put:
  571. pm_runtime_put_sync_suspend(&pdev->dev);
  572. pm_disable:
  573. pm_runtime_disable(&pdev->dev);
  574. host1x_syncpt_deinit(host);
  575. free_contexts:
  576. host1x_memory_context_list_free(&host->context_list);
  577. free_channels:
  578. host1x_channel_list_free(&host->channel_list);
  579. iommu_exit:
  580. host1x_iommu_exit(host);
  581. destroy_cache:
  582. host1x_bo_cache_destroy(&host->cache);
  583. return err;
  584. }
  585. static void host1x_remove(struct platform_device *pdev)
  586. {
  587. struct host1x *host = platform_get_drvdata(pdev);
  588. host1x_unregister(host);
  589. host1x_debug_deinit(host);
  590. pm_runtime_force_suspend(&pdev->dev);
  591. host1x_intr_deinit(host);
  592. host1x_syncpt_deinit(host);
  593. host1x_memory_context_list_free(&host->context_list);
  594. host1x_channel_list_free(&host->channel_list);
  595. host1x_iommu_exit(host);
  596. host1x_bo_cache_destroy(&host->cache);
  597. }
  598. static int __maybe_unused host1x_runtime_suspend(struct device *dev)
  599. {
  600. struct host1x *host = dev_get_drvdata(dev);
  601. int err;
  602. host1x_channel_stop_all(host);
  603. host1x_intr_stop(host);
  604. host1x_syncpt_save(host);
  605. if (!host->info->skip_reset_assert) {
  606. err = reset_control_bulk_assert(host->nresets, host->resets);
  607. if (err) {
  608. dev_err(dev, "failed to assert reset: %d\n", err);
  609. goto resume_host1x;
  610. }
  611. usleep_range(1000, 2000);
  612. }
  613. clk_disable_unprepare(host->clk);
  614. reset_control_bulk_release(host->nresets, host->resets);
  615. return 0;
  616. resume_host1x:
  617. host1x_setup_virtualization_tables(host);
  618. host1x_syncpt_restore(host);
  619. host1x_intr_start(host);
  620. return err;
  621. }
  622. static int __maybe_unused host1x_runtime_resume(struct device *dev)
  623. {
  624. struct host1x *host = dev_get_drvdata(dev);
  625. int err;
  626. err = reset_control_bulk_acquire(host->nresets, host->resets);
  627. if (err) {
  628. dev_err(dev, "failed to acquire reset: %d\n", err);
  629. return err;
  630. }
  631. err = clk_prepare_enable(host->clk);
  632. if (err) {
  633. dev_err(dev, "failed to enable clock: %d\n", err);
  634. goto release_reset;
  635. }
  636. err = reset_control_bulk_deassert(host->nresets, host->resets);
  637. if (err < 0) {
  638. dev_err(dev, "failed to deassert reset: %d\n", err);
  639. goto disable_clk;
  640. }
  641. host1x_setup_virtualization_tables(host);
  642. host1x_syncpt_restore(host);
  643. host1x_intr_start(host);
  644. return 0;
  645. disable_clk:
  646. clk_disable_unprepare(host->clk);
  647. release_reset:
  648. reset_control_bulk_release(host->nresets, host->resets);
  649. return err;
  650. }
  651. static const struct dev_pm_ops host1x_pm_ops = {
  652. SET_RUNTIME_PM_OPS(host1x_runtime_suspend, host1x_runtime_resume,
  653. NULL)
  654. SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
  655. };
  656. static struct platform_driver tegra_host1x_driver = {
  657. .driver = {
  658. .name = "tegra-host1x",
  659. .of_match_table = host1x_of_match,
  660. .pm = &host1x_pm_ops,
  661. },
  662. .probe = host1x_probe,
  663. .remove_new = host1x_remove,
  664. };
  665. static struct platform_driver * const drivers[] = {
  666. &tegra_host1x_driver,
  667. &tegra_mipi_driver,
  668. };
  669. static int __init tegra_host1x_init(void)
  670. {
  671. int err;
  672. err = bus_register(&host1x_bus_type);
  673. if (err < 0)
  674. return err;
  675. err = platform_register_drivers(drivers, ARRAY_SIZE(drivers));
  676. if (err < 0)
  677. bus_unregister(&host1x_bus_type);
  678. return err;
  679. }
  680. module_init(tegra_host1x_init);
  681. static void __exit tegra_host1x_exit(void)
  682. {
  683. platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
  684. bus_unregister(&host1x_bus_type);
  685. }
  686. module_exit(tegra_host1x_exit);
  687. /**
  688. * host1x_get_dma_mask() - query the supported DMA mask for host1x
  689. * @host1x: host1x instance
  690. *
  691. * Note that this returns the supported DMA mask for host1x, which can be
  692. * different from the applicable DMA mask under certain circumstances.
  693. */
  694. u64 host1x_get_dma_mask(struct host1x *host1x)
  695. {
  696. return host1x->info->dma_mask;
  697. }
  698. EXPORT_SYMBOL(host1x_get_dma_mask);
  699. MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
  700. MODULE_AUTHOR("Terje Bergstrom <tbergstrom@nvidia.com>");
  701. MODULE_DESCRIPTION("Host1x driver for Tegra products");
  702. MODULE_LICENSE("GPL");