cdma.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Tegra host1x Command DMA
  4. *
  5. * Copyright (c) 2010-2013, NVIDIA Corporation.
  6. */
  7. #ifndef __HOST1X_CDMA_H
  8. #define __HOST1X_CDMA_H
  9. #include <linux/sched.h>
  10. #include <linux/completion.h>
  11. #include <linux/list.h>
  12. struct host1x_syncpt;
  13. struct host1x_userctx_timeout;
  14. struct host1x_job;
  15. /*
  16. * cdma
  17. *
  18. * This is in charge of a host command DMA channel.
  19. * Sends ops to a push buffer, and takes responsibility for unpinning
  20. * (& possibly freeing) of memory after those ops have completed.
  21. * Producer:
  22. * begin
  23. * push - send ops to the push buffer
  24. * end - start command DMA and enqueue handles to be unpinned
  25. * Consumer:
  26. * update - call to update sync queue and push buffer, unpin memory
  27. */
  28. struct push_buffer {
  29. void *mapped; /* mapped pushbuffer memory */
  30. dma_addr_t dma; /* device address of pushbuffer */
  31. dma_addr_t phys; /* physical address of pushbuffer */
  32. u32 fence; /* index we've written */
  33. u32 pos; /* index to write to */
  34. u32 size;
  35. u32 alloc_size;
  36. };
  37. struct buffer_timeout {
  38. struct delayed_work wq; /* work queue */
  39. bool initialized; /* timer one-time setup flag */
  40. struct host1x_syncpt *syncpt; /* buffer completion syncpt */
  41. u32 syncpt_val; /* syncpt value when completed */
  42. ktime_t start_ktime; /* starting time */
  43. /* context timeout information */
  44. struct host1x_client *client;
  45. };
  46. enum cdma_event {
  47. CDMA_EVENT_NONE, /* not waiting for any event */
  48. CDMA_EVENT_SYNC_QUEUE_EMPTY, /* wait for empty sync queue */
  49. CDMA_EVENT_PUSH_BUFFER_SPACE /* wait for space in push buffer */
  50. };
  51. struct host1x_cdma {
  52. struct mutex lock; /* controls access to shared state */
  53. struct completion complete; /* signalled when event occurs */
  54. enum cdma_event event; /* event that complete is waiting for */
  55. unsigned int slots_used; /* pb slots used in current submit */
  56. unsigned int slots_free; /* pb slots free in current submit */
  57. unsigned int first_get; /* DMAGET value, where submit begins */
  58. unsigned int last_pos; /* last value written to DMAPUT */
  59. struct push_buffer push_buffer; /* channel's push buffer */
  60. struct list_head sync_queue; /* job queue */
  61. struct buffer_timeout timeout; /* channel's timeout state/wq */
  62. bool running;
  63. bool torndown;
  64. };
  65. #define cdma_to_channel(cdma) container_of(cdma, struct host1x_channel, cdma)
  66. #define cdma_to_host1x(cdma) dev_get_drvdata(cdma_to_channel(cdma)->dev->parent)
  67. #define pb_to_cdma(pb) container_of(pb, struct host1x_cdma, push_buffer)
  68. int host1x_cdma_init(struct host1x_cdma *cdma);
  69. int host1x_cdma_deinit(struct host1x_cdma *cdma);
  70. int host1x_cdma_begin(struct host1x_cdma *cdma, struct host1x_job *job);
  71. void host1x_cdma_push(struct host1x_cdma *cdma, u32 op1, u32 op2);
  72. void host1x_cdma_push_wide(struct host1x_cdma *cdma, u32 op1, u32 op2,
  73. u32 op3, u32 op4);
  74. void host1x_cdma_end(struct host1x_cdma *cdma, struct host1x_job *job);
  75. void host1x_cdma_update(struct host1x_cdma *cdma);
  76. void host1x_cdma_peek(struct host1x_cdma *cdma, u32 dmaget, int slot,
  77. u32 *out);
  78. unsigned int host1x_cdma_wait_locked(struct host1x_cdma *cdma,
  79. enum cdma_event event);
  80. void host1x_cdma_update_sync_queue(struct host1x_cdma *cdma,
  81. struct device *dev);
  82. #endif