cdma.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Tegra host1x Command DMA
  3. *
  4. * Copyright (c) 2010-2013, NVIDIA Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __HOST1X_CDMA_H
  19. #define __HOST1X_CDMA_H
  20. #include <linux/sched.h>
  21. #include <linux/semaphore.h>
  22. #include <linux/list.h>
  23. struct host1x_syncpt;
  24. struct host1x_userctx_timeout;
  25. struct host1x_job;
  26. /*
  27. * cdma
  28. *
  29. * This is in charge of a host command DMA channel.
  30. * Sends ops to a push buffer, and takes responsibility for unpinning
  31. * (& possibly freeing) of memory after those ops have completed.
  32. * Producer:
  33. * begin
  34. * push - send ops to the push buffer
  35. * end - start command DMA and enqueue handles to be unpinned
  36. * Consumer:
  37. * update - call to update sync queue and push buffer, unpin memory
  38. */
  39. struct push_buffer {
  40. void *mapped; /* mapped pushbuffer memory */
  41. dma_addr_t phys; /* physical address of pushbuffer */
  42. u32 fence; /* index we've written */
  43. u32 pos; /* index to write to */
  44. u32 size_bytes;
  45. };
  46. struct buffer_timeout {
  47. struct delayed_work wq; /* work queue */
  48. bool initialized; /* timer one-time setup flag */
  49. struct host1x_syncpt *syncpt; /* buffer completion syncpt */
  50. u32 syncpt_val; /* syncpt value when completed */
  51. ktime_t start_ktime; /* starting time */
  52. /* context timeout information */
  53. int client;
  54. };
  55. enum cdma_event {
  56. CDMA_EVENT_NONE, /* not waiting for any event */
  57. CDMA_EVENT_SYNC_QUEUE_EMPTY, /* wait for empty sync queue */
  58. CDMA_EVENT_PUSH_BUFFER_SPACE /* wait for space in push buffer */
  59. };
  60. struct host1x_cdma {
  61. struct mutex lock; /* controls access to shared state */
  62. struct semaphore sem; /* signalled when event occurs */
  63. enum cdma_event event; /* event that sem is waiting for */
  64. unsigned int slots_used; /* pb slots used in current submit */
  65. unsigned int slots_free; /* pb slots free in current submit */
  66. unsigned int first_get; /* DMAGET value, where submit begins */
  67. unsigned int last_pos; /* last value written to DMAPUT */
  68. struct push_buffer push_buffer; /* channel's push buffer */
  69. struct list_head sync_queue; /* job queue */
  70. struct buffer_timeout timeout; /* channel's timeout state/wq */
  71. bool running;
  72. bool torndown;
  73. };
  74. #define cdma_to_channel(cdma) container_of(cdma, struct host1x_channel, cdma)
  75. #define cdma_to_host1x(cdma) dev_get_drvdata(cdma_to_channel(cdma)->dev->parent)
  76. #define pb_to_cdma(pb) container_of(pb, struct host1x_cdma, push_buffer)
  77. int host1x_cdma_init(struct host1x_cdma *cdma);
  78. int host1x_cdma_deinit(struct host1x_cdma *cdma);
  79. void host1x_cdma_stop(struct host1x_cdma *cdma);
  80. int host1x_cdma_begin(struct host1x_cdma *cdma, struct host1x_job *job);
  81. void host1x_cdma_push(struct host1x_cdma *cdma, u32 op1, u32 op2);
  82. void host1x_cdma_end(struct host1x_cdma *cdma, struct host1x_job *job);
  83. void host1x_cdma_update(struct host1x_cdma *cdma);
  84. void host1x_cdma_peek(struct host1x_cdma *cdma, u32 dmaget, int slot,
  85. u32 *out);
  86. unsigned int host1x_cdma_wait_locked(struct host1x_cdma *cdma,
  87. enum cdma_event event);
  88. void host1x_cdma_update_sync_queue(struct host1x_cdma *cdma,
  89. struct device *dev);
  90. #endif