mc-private.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Freescale Management Complex (MC) bus private declarations
  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_PRIVATE_H_
  12. #define _FSL_MC_PRIVATE_H_
  13. #include "../include/mc.h"
  14. #include <linux/mutex.h>
  15. #include <linux/stringify.h>
  16. #define FSL_MC_DPRC_DRIVER_NAME "fsl_mc_dprc"
  17. #define FSL_MC_DEVICE_MATCH(_mc_dev, _obj_desc) \
  18. (strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \
  19. (_mc_dev)->obj_desc.id == (_obj_desc)->id)
  20. #define FSL_MC_IS_ALLOCATABLE(_obj_type) \
  21. (strcmp(_obj_type, "dpbp") == 0 || \
  22. strcmp(_obj_type, "dpmcp") == 0 || \
  23. strcmp(_obj_type, "dpcon") == 0)
  24. /**
  25. * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
  26. * @root_mc_bus_dev: MC object device representing the root DPRC
  27. * @num_translation_ranges: number of entries in addr_translation_ranges
  28. * @translation_ranges: array of bus to system address translation ranges
  29. */
  30. struct fsl_mc {
  31. struct fsl_mc_device *root_mc_bus_dev;
  32. u8 num_translation_ranges;
  33. struct fsl_mc_addr_translation_range *translation_ranges;
  34. };
  35. /**
  36. * struct fsl_mc_addr_translation_range - bus to system address translation
  37. * range
  38. * @mc_region_type: Type of MC region for the range being translated
  39. * @start_mc_offset: Start MC offset of the range being translated
  40. * @end_mc_offset: MC offset of the first byte after the range (last MC
  41. * offset of the range is end_mc_offset - 1)
  42. * @start_phys_addr: system physical address corresponding to start_mc_addr
  43. */
  44. struct fsl_mc_addr_translation_range {
  45. enum dprc_region_type mc_region_type;
  46. u64 start_mc_offset;
  47. u64 end_mc_offset;
  48. phys_addr_t start_phys_addr;
  49. };
  50. /**
  51. * struct fsl_mc_resource_pool - Pool of MC resources of a given
  52. * type
  53. * @type: type of resources in the pool
  54. * @max_count: maximum number of resources in the pool
  55. * @free_count: number of free resources in the pool
  56. * @mutex: mutex to serialize access to the pool's free list
  57. * @free_list: anchor node of list of free resources in the pool
  58. * @mc_bus: pointer to the MC bus that owns this resource pool
  59. */
  60. struct fsl_mc_resource_pool {
  61. enum fsl_mc_pool_type type;
  62. int16_t max_count;
  63. int16_t free_count;
  64. struct mutex mutex; /* serializes access to free_list */
  65. struct list_head free_list;
  66. struct fsl_mc_bus *mc_bus;
  67. };
  68. /**
  69. * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC
  70. * @mc_dev: fsl-mc device for the bus device itself.
  71. * @resource_pools: array of resource pools (one pool per resource type)
  72. * for this MC bus. These resources represent allocatable entities
  73. * from the physical DPRC.
  74. * @scan_mutex: Serializes bus scanning
  75. */
  76. struct fsl_mc_bus {
  77. struct fsl_mc_device mc_dev;
  78. struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
  79. struct mutex scan_mutex; /* serializes bus scanning */
  80. };
  81. #define to_fsl_mc_bus(_mc_dev) \
  82. container_of(_mc_dev, struct fsl_mc_bus, mc_dev)
  83. int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
  84. struct fsl_mc_io *mc_io,
  85. struct device *parent_dev,
  86. struct fsl_mc_device **new_mc_dev);
  87. void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
  88. int dprc_scan_container(struct fsl_mc_device *mc_bus_dev);
  89. int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev);
  90. int __init dprc_driver_init(void);
  91. void dprc_driver_exit(void);
  92. int __init fsl_mc_allocator_driver_init(void);
  93. void __exit fsl_mc_allocator_driver_exit(void);
  94. int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
  95. enum fsl_mc_pool_type pool_type,
  96. struct fsl_mc_resource
  97. **new_resource);
  98. void fsl_mc_resource_free(struct fsl_mc_resource *resource);
  99. #endif /* _FSL_MC_PRIVATE_H_ */