mc-sys.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* Copyright 2013-2014 Freescale Semiconductor Inc.
  2. *
  3. * Interface of the I/O services to send MC commands to the MC hardware
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the above-listed copyright holders nor the
  13. * names of any contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. *
  17. * ALTERNATIVELY, this software may be distributed under the terms of the
  18. * GNU General Public License ("GPL") as published by the Free Software
  19. * Foundation, either version 2 of that License or (at your option) any
  20. * later version.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_MC_SYS_H
  35. #define _FSL_MC_SYS_H
  36. #include <linux/types.h>
  37. #include <linux/errno.h>
  38. #include <linux/io.h>
  39. #include <linux/dma-mapping.h>
  40. #include <linux/mutex.h>
  41. #include <linux/spinlock.h>
  42. /**
  43. * Bit masks for a MC I/O object (struct fsl_mc_io) flags
  44. */
  45. #define FSL_MC_IO_ATOMIC_CONTEXT_PORTAL 0x0001
  46. struct fsl_mc_resource;
  47. struct mc_command;
  48. /**
  49. * struct fsl_mc_io - MC I/O object to be passed-in to mc_send_command()
  50. * @dev: device associated with this Mc I/O object
  51. * @flags: flags for mc_send_command()
  52. * @portal_size: MC command portal size in bytes
  53. * @portal_phys_addr: MC command portal physical address
  54. * @portal_virt_addr: MC command portal virtual address
  55. * @dpmcp_dev: pointer to the DPMCP device associated with the MC portal.
  56. *
  57. * Fields are only meaningful if the FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is not
  58. * set:
  59. * @mutex: Mutex to serialize mc_send_command() calls that use the same MC
  60. * portal, if the fsl_mc_io object was created with the
  61. * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag off. mc_send_command() calls for this
  62. * fsl_mc_io object must be made only from non-atomic context.
  63. *
  64. * Fields are only meaningful if the FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is
  65. * set:
  66. * @spinlock: Spinlock to serialize mc_send_command() calls that use the same MC
  67. * portal, if the fsl_mc_io object was created with the
  68. * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag on. mc_send_command() calls for this
  69. * fsl_mc_io object can be made from atomic or non-atomic context.
  70. */
  71. struct fsl_mc_io {
  72. struct device *dev;
  73. u16 flags;
  74. u16 portal_size;
  75. phys_addr_t portal_phys_addr;
  76. void __iomem *portal_virt_addr;
  77. struct fsl_mc_device *dpmcp_dev;
  78. union {
  79. /*
  80. * This field is only meaningful if the
  81. * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is not set
  82. */
  83. struct mutex mutex; /* serializes mc_send_command() */
  84. /*
  85. * This field is only meaningful if the
  86. * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is set
  87. */
  88. spinlock_t spinlock; /* serializes mc_send_command() */
  89. };
  90. };
  91. int __must_check fsl_create_mc_io(struct device *dev,
  92. phys_addr_t mc_portal_phys_addr,
  93. u32 mc_portal_size,
  94. struct fsl_mc_device *dpmcp_dev,
  95. u32 flags, struct fsl_mc_io **new_mc_io);
  96. void fsl_destroy_mc_io(struct fsl_mc_io *mc_io);
  97. int fsl_mc_io_set_dpmcp(struct fsl_mc_io *mc_io,
  98. struct fsl_mc_device *dpmcp_dev);
  99. void fsl_mc_io_unset_dpmcp(struct fsl_mc_io *mc_io);
  100. int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd);
  101. #endif /* _FSL_MC_SYS_H */