mc.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Freescale Management Complex (MC) bus public interface
  3. *
  4. * Copyright (C) 2014 Freescale Semiconductor, Inc.
  5. * Author: German Rivera <German.Rivera@freescale.com>
  6. *
  7. * This file is licensed under the terms of the GNU General Public
  8. * License version 2. This program is licensed "as is" without any
  9. * warranty of any kind, whether express or implied.
  10. */
  11. #ifndef _FSL_MC_H_
  12. #define _FSL_MC_H_
  13. #include <linux/device.h>
  14. #include <linux/mod_devicetable.h>
  15. #include <linux/list.h>
  16. #include "../include/dprc.h"
  17. #define FSL_MC_VENDOR_FREESCALE 0x1957
  18. struct fsl_mc_device;
  19. struct fsl_mc_io;
  20. /**
  21. * struct fsl_mc_driver - MC object device driver object
  22. * @driver: Generic device driver
  23. * @match_id_table: table of supported device matching Ids
  24. * @probe: Function called when a device is added
  25. * @remove: Function called when a device is removed
  26. * @shutdown: Function called at shutdown time to quiesce the device
  27. * @suspend: Function called when a device is stopped
  28. * @resume: Function called when a device is resumed
  29. *
  30. * Generic DPAA device driver object for device drivers that are registered
  31. * with a DPRC bus. This structure is to be embedded in each device-specific
  32. * driver structure.
  33. */
  34. struct fsl_mc_driver {
  35. struct device_driver driver;
  36. const struct fsl_mc_device_match_id *match_id_table;
  37. int (*probe)(struct fsl_mc_device *dev);
  38. int (*remove)(struct fsl_mc_device *dev);
  39. void (*shutdown)(struct fsl_mc_device *dev);
  40. int (*suspend)(struct fsl_mc_device *dev, pm_message_t state);
  41. int (*resume)(struct fsl_mc_device *dev);
  42. };
  43. #define to_fsl_mc_driver(_drv) \
  44. container_of(_drv, struct fsl_mc_driver, driver)
  45. /**
  46. * struct fsl_mc_device_match_id - MC object device Id entry for driver matching
  47. * @vendor: vendor ID
  48. * @obj_type: MC object type
  49. * @ver_major: MC object version major number
  50. * @ver_minor: MC object version minor number
  51. *
  52. * Type of entries in the "device Id" table for MC object devices supported by
  53. * a MC object device driver. The last entry of the table has vendor set to 0x0
  54. */
  55. struct fsl_mc_device_match_id {
  56. u16 vendor;
  57. const char obj_type[16];
  58. u32 ver_major;
  59. u32 ver_minor;
  60. };
  61. /**
  62. * enum fsl_mc_pool_type - Types of allocatable MC bus resources
  63. *
  64. * Entries in these enum are used as indices in the array of resource
  65. * pools of an fsl_mc_bus object.
  66. */
  67. enum fsl_mc_pool_type {
  68. FSL_MC_POOL_DPMCP = 0x0, /* corresponds to "dpmcp" in the MC */
  69. FSL_MC_POOL_DPBP, /* corresponds to "dpbp" in the MC */
  70. FSL_MC_POOL_DPCON, /* corresponds to "dpcon" in the MC */
  71. /*
  72. * NOTE: New resource pool types must be added before this entry
  73. */
  74. FSL_MC_NUM_POOL_TYPES
  75. };
  76. /**
  77. * struct fsl_mc_resource - MC generic resource
  78. * @type: type of resource
  79. * @id: unique MC resource Id within the resources of the same type
  80. * @data: pointer to resource-specific data if the resource is currently
  81. * allocated, or NULL if the resource is not currently allocated.
  82. * @parent_pool: pointer to the parent resource pool from which this
  83. * resource is allocated from.
  84. * @node: Node in the free list of the corresponding resource pool
  85. *
  86. * NOTE: This structure is to be embedded as a field of specific
  87. * MC resource structures.
  88. */
  89. struct fsl_mc_resource {
  90. enum fsl_mc_pool_type type;
  91. int32_t id;
  92. void *data;
  93. struct fsl_mc_resource_pool *parent_pool;
  94. struct list_head node;
  95. };
  96. /**
  97. * Bit masks for a MC object device (struct fsl_mc_device) flags
  98. */
  99. #define FSL_MC_IS_DPRC 0x0001
  100. /**
  101. * Default DMA mask for devices on a fsl-mc bus
  102. */
  103. #define FSL_MC_DEFAULT_DMA_MASK (~0ULL)
  104. /**
  105. * struct fsl_mc_device - MC object device object
  106. * @dev: Linux driver model device object
  107. * @dma_mask: Default DMA mask
  108. * @flags: MC object device flags
  109. * @icid: Isolation context ID for the device
  110. * @mc_handle: MC handle for the corresponding MC object opened
  111. * @mc_io: Pointer to MC IO object assigned to this device or
  112. * NULL if none.
  113. * @obj_desc: MC description of the DPAA device
  114. * @regions: pointer to array of MMIO region entries
  115. * @resource: generic resource associated with this MC object device, if any.
  116. *
  117. * Generic device object for MC object devices that are "attached" to a
  118. * MC bus.
  119. *
  120. * NOTES:
  121. * - For a non-DPRC object its icid is the same as its parent DPRC's icid.
  122. * - The SMMU notifier callback gets invoked after device_add() has been
  123. * called for an MC object device, but before the device-specific probe
  124. * callback gets called.
  125. * - DP_OBJ_DPRC objects are the only MC objects that have built-in MC
  126. * portals. For all other MC objects, their device drivers are responsible for
  127. * allocating MC portals for them by calling fsl_mc_portal_allocate().
  128. * - Some types of MC objects (e.g., DP_OBJ_DPBP, DP_OBJ_DPCON) are
  129. * treated as resources that can be allocated/deallocated from the
  130. * corresponding resource pool in the object's parent DPRC, using the
  131. * fsl_mc_object_allocate()/fsl_mc_object_free() functions. These MC objects
  132. * are known as "allocatable" objects. For them, the corresponding
  133. * fsl_mc_device's 'resource' points to the associated resource object.
  134. * For MC objects that are not allocatable (e.g., DP_OBJ_DPRC, DP_OBJ_DPNI),
  135. * 'resource' is NULL.
  136. */
  137. struct fsl_mc_device {
  138. struct device dev;
  139. u64 dma_mask;
  140. u16 flags;
  141. u16 icid;
  142. u16 mc_handle;
  143. struct fsl_mc_io *mc_io;
  144. struct dprc_obj_desc obj_desc;
  145. struct resource *regions;
  146. struct fsl_mc_resource *resource;
  147. };
  148. #define to_fsl_mc_device(_dev) \
  149. container_of(_dev, struct fsl_mc_device, dev)
  150. /*
  151. * module_fsl_mc_driver() - Helper macro for drivers that don't do
  152. * anything special in module init/exit. This eliminates a lot of
  153. * boilerplate. Each module may only use this macro once, and
  154. * calling it replaces module_init() and module_exit()
  155. */
  156. #define module_fsl_mc_driver(__fsl_mc_driver) \
  157. module_driver(__fsl_mc_driver, fsl_mc_driver_register, \
  158. fsl_mc_driver_unregister)
  159. /*
  160. * Macro to avoid include chaining to get THIS_MODULE
  161. */
  162. #define fsl_mc_driver_register(drv) \
  163. __fsl_mc_driver_register(drv, THIS_MODULE)
  164. int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
  165. struct module *owner);
  166. void fsl_mc_driver_unregister(struct fsl_mc_driver *driver);
  167. bool fsl_mc_bus_exists(void);
  168. int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
  169. u16 mc_io_flags,
  170. struct fsl_mc_io **new_mc_io);
  171. void fsl_mc_portal_free(struct fsl_mc_io *mc_io);
  172. int fsl_mc_portal_reset(struct fsl_mc_io *mc_io);
  173. int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
  174. enum fsl_mc_pool_type pool_type,
  175. struct fsl_mc_device **new_mc_adev);
  176. void fsl_mc_object_free(struct fsl_mc_device *mc_adev);
  177. extern struct bus_type fsl_mc_bus_type;
  178. #endif /* _FSL_MC_H_ */