dma.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * include/asm-sh/dma.h
  4. *
  5. * Copyright (C) 2003, 2004 Paul Mundt
  6. */
  7. #ifndef __ASM_SH_DMA_H
  8. #define __ASM_SH_DMA_H
  9. #include <linux/spinlock.h>
  10. #include <linux/wait.h>
  11. #include <linux/sched.h>
  12. #include <linux/device.h>
  13. #include <asm-generic/dma.h>
  14. /*
  15. * Read and write modes can mean drastically different things depending on the
  16. * channel configuration. Consult your DMAC documentation and module
  17. * implementation for further clues.
  18. */
  19. #define DMA_MODE_READ 0x00
  20. #define DMA_MODE_WRITE 0x01
  21. #define DMA_MODE_MASK 0x01
  22. #define DMA_AUTOINIT 0x10
  23. /*
  24. * DMAC (dma_info) flags
  25. */
  26. enum {
  27. DMAC_CHANNELS_CONFIGURED = 0x01,
  28. DMAC_CHANNELS_TEI_CAPABLE = 0x02, /* Transfer end interrupt */
  29. };
  30. /*
  31. * DMA channel capabilities / flags
  32. */
  33. enum {
  34. DMA_CONFIGURED = 0x01,
  35. /*
  36. * Transfer end interrupt, inherited from DMAC.
  37. * wait_queue used in dma_wait_for_completion.
  38. */
  39. DMA_TEI_CAPABLE = 0x02,
  40. };
  41. extern spinlock_t dma_spin_lock;
  42. struct dma_channel;
  43. struct dma_ops {
  44. int (*request)(struct dma_channel *chan);
  45. void (*free)(struct dma_channel *chan);
  46. int (*get_residue)(struct dma_channel *chan);
  47. int (*xfer)(struct dma_channel *chan);
  48. int (*configure)(struct dma_channel *chan, unsigned long flags);
  49. int (*extend)(struct dma_channel *chan, unsigned long op, void *param);
  50. };
  51. struct dma_channel {
  52. char dev_id[16]; /* unique name per DMAC of channel */
  53. unsigned int chan; /* DMAC channel number */
  54. unsigned int vchan; /* Virtual channel number */
  55. unsigned int mode;
  56. unsigned int count;
  57. unsigned long sar;
  58. unsigned long dar;
  59. const char **caps;
  60. unsigned long flags;
  61. atomic_t busy;
  62. wait_queue_head_t wait_queue;
  63. struct device dev;
  64. void *priv_data;
  65. };
  66. struct dma_info {
  67. struct platform_device *pdev;
  68. const char *name;
  69. unsigned int nr_channels;
  70. unsigned long flags;
  71. struct dma_ops *ops;
  72. struct dma_channel *channels;
  73. struct list_head list;
  74. int first_channel_nr;
  75. int first_vchannel_nr;
  76. };
  77. struct dma_chan_caps {
  78. int ch_num;
  79. const char **caplist;
  80. };
  81. #define to_dma_channel(channel) container_of(channel, struct dma_channel, dev)
  82. /* arch/sh/drivers/dma/dma-api.c */
  83. extern int dma_xfer(unsigned int chan, unsigned long from,
  84. unsigned long to, size_t size, unsigned int mode);
  85. #define dma_write(chan, from, to, size) \
  86. dma_xfer(chan, from, to, size, DMA_MODE_WRITE)
  87. #define dma_write_page(chan, from, to) \
  88. dma_write(chan, from, to, PAGE_SIZE)
  89. #define dma_read(chan, from, to, size) \
  90. dma_xfer(chan, from, to, size, DMA_MODE_READ)
  91. #define dma_read_page(chan, from, to) \
  92. dma_read(chan, from, to, PAGE_SIZE)
  93. extern int request_dma_bycap(const char **dmac, const char **caps,
  94. const char *dev_id);
  95. extern int get_dma_residue(unsigned int chan);
  96. extern struct dma_info *get_dma_info(unsigned int chan);
  97. extern struct dma_channel *get_dma_channel(unsigned int chan);
  98. extern void dma_wait_for_completion(unsigned int chan);
  99. extern void dma_configure_channel(unsigned int chan, unsigned long flags);
  100. extern int register_dmac(struct dma_info *info);
  101. extern void unregister_dmac(struct dma_info *info);
  102. extern struct dma_info *get_dma_info_by_name(const char *dmac_name);
  103. extern int dma_extend(unsigned int chan, unsigned long op, void *param);
  104. extern int register_chan_caps(const char *dmac, struct dma_chan_caps *capslist);
  105. /* arch/sh/drivers/dma/dma-sysfs.c */
  106. extern int dma_create_sysfs_files(struct dma_channel *, struct dma_info *);
  107. extern void dma_remove_sysfs_files(struct dma_channel *, struct dma_info *);
  108. #endif /* __ASM_SH_DMA_H */