fsl-mc-private.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Freescale Management Complex (MC) bus private declarations
  4. *
  5. * Copyright (C) 2016 Freescale Semiconductor, Inc.
  6. *
  7. */
  8. #ifndef _FSL_MC_PRIVATE_H_
  9. #define _FSL_MC_PRIVATE_H_
  10. #include <linux/fsl/mc.h>
  11. #include <linux/mutex.h>
  12. /*
  13. * Data Path Management Complex (DPMNG) General API
  14. */
  15. /* DPMNG command versioning */
  16. #define DPMNG_CMD_BASE_VERSION 1
  17. #define DPMNG_CMD_ID_OFFSET 4
  18. #define DPMNG_CMD(id) (((id) << DPMNG_CMD_ID_OFFSET) | DPMNG_CMD_BASE_VERSION)
  19. /* DPMNG command IDs */
  20. #define DPMNG_CMDID_GET_VERSION DPMNG_CMD(0x831)
  21. struct dpmng_rsp_get_version {
  22. __le32 revision;
  23. __le32 version_major;
  24. __le32 version_minor;
  25. };
  26. /*
  27. * Data Path Management Command Portal (DPMCP) API
  28. */
  29. /* Minimal supported DPMCP Version */
  30. #define DPMCP_MIN_VER_MAJOR 3
  31. #define DPMCP_MIN_VER_MINOR 0
  32. /* DPMCP command versioning */
  33. #define DPMCP_CMD_BASE_VERSION 1
  34. #define DPMCP_CMD_ID_OFFSET 4
  35. #define DPMCP_CMD(id) (((id) << DPMCP_CMD_ID_OFFSET) | DPMCP_CMD_BASE_VERSION)
  36. /* DPMCP command IDs */
  37. #define DPMCP_CMDID_CLOSE DPMCP_CMD(0x800)
  38. #define DPMCP_CMDID_OPEN DPMCP_CMD(0x80b)
  39. #define DPMCP_CMDID_RESET DPMCP_CMD(0x005)
  40. struct dpmcp_cmd_open {
  41. __le32 dpmcp_id;
  42. };
  43. /*
  44. * Initialization and runtime control APIs for DPMCP
  45. */
  46. int dpmcp_open(struct fsl_mc_io *mc_io,
  47. u32 cmd_flags,
  48. int dpmcp_id,
  49. u16 *token);
  50. int dpmcp_close(struct fsl_mc_io *mc_io,
  51. u32 cmd_flags,
  52. u16 token);
  53. int dpmcp_reset(struct fsl_mc_io *mc_io,
  54. u32 cmd_flags,
  55. u16 token);
  56. /*
  57. * Data Path Resource Container (DPRC) API
  58. */
  59. /* Minimal supported DPRC Version */
  60. #define DPRC_MIN_VER_MAJOR 6
  61. #define DPRC_MIN_VER_MINOR 0
  62. /* DPRC command versioning */
  63. #define DPRC_CMD_BASE_VERSION 1
  64. #define DPRC_CMD_ID_OFFSET 4
  65. #define DPRC_CMD(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
  66. /* DPRC command IDs */
  67. #define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
  68. #define DPRC_CMDID_OPEN DPRC_CMD(0x805)
  69. #define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
  70. #define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
  71. #define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
  72. #define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
  73. #define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
  74. #define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
  75. #define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
  76. #define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
  77. #define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
  78. #define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
  79. #define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
  80. #define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
  81. struct dprc_cmd_open {
  82. __le32 container_id;
  83. };
  84. struct dprc_cmd_set_irq {
  85. /* cmd word 0 */
  86. __le32 irq_val;
  87. u8 irq_index;
  88. u8 pad[3];
  89. /* cmd word 1 */
  90. __le64 irq_addr;
  91. /* cmd word 2 */
  92. __le32 irq_num;
  93. };
  94. #define DPRC_ENABLE 0x1
  95. struct dprc_cmd_set_irq_enable {
  96. u8 enable;
  97. u8 pad[3];
  98. u8 irq_index;
  99. };
  100. struct dprc_cmd_set_irq_mask {
  101. __le32 mask;
  102. u8 irq_index;
  103. };
  104. struct dprc_cmd_get_irq_status {
  105. __le32 status;
  106. u8 irq_index;
  107. };
  108. struct dprc_rsp_get_irq_status {
  109. __le32 status;
  110. };
  111. struct dprc_cmd_clear_irq_status {
  112. __le32 status;
  113. u8 irq_index;
  114. };
  115. struct dprc_rsp_get_attributes {
  116. /* response word 0 */
  117. __le32 container_id;
  118. __le16 icid;
  119. __le16 pad;
  120. /* response word 1 */
  121. __le32 options;
  122. __le32 portal_id;
  123. };
  124. struct dprc_rsp_get_obj_count {
  125. __le32 pad;
  126. __le32 obj_count;
  127. };
  128. struct dprc_cmd_get_obj {
  129. __le32 obj_index;
  130. };
  131. struct dprc_rsp_get_obj {
  132. /* response word 0 */
  133. __le32 pad0;
  134. __le32 id;
  135. /* response word 1 */
  136. __le16 vendor;
  137. u8 irq_count;
  138. u8 region_count;
  139. __le32 state;
  140. /* response word 2 */
  141. __le16 version_major;
  142. __le16 version_minor;
  143. __le16 flags;
  144. __le16 pad1;
  145. /* response word 3-4 */
  146. u8 type[16];
  147. /* response word 5-6 */
  148. u8 label[16];
  149. };
  150. struct dprc_cmd_get_obj_region {
  151. /* cmd word 0 */
  152. __le32 obj_id;
  153. __le16 pad0;
  154. u8 region_index;
  155. u8 pad1;
  156. /* cmd word 1-2 */
  157. __le64 pad2[2];
  158. /* cmd word 3-4 */
  159. u8 obj_type[16];
  160. };
  161. struct dprc_rsp_get_obj_region {
  162. /* response word 0 */
  163. __le64 pad;
  164. /* response word 1 */
  165. __le64 base_addr;
  166. /* response word 2 */
  167. __le32 size;
  168. };
  169. struct dprc_cmd_set_obj_irq {
  170. /* cmd word 0 */
  171. __le32 irq_val;
  172. u8 irq_index;
  173. u8 pad[3];
  174. /* cmd word 1 */
  175. __le64 irq_addr;
  176. /* cmd word 2 */
  177. __le32 irq_num;
  178. __le32 obj_id;
  179. /* cmd word 3-4 */
  180. u8 obj_type[16];
  181. };
  182. /*
  183. * DPRC API for managing and querying DPAA resources
  184. */
  185. int dprc_open(struct fsl_mc_io *mc_io,
  186. u32 cmd_flags,
  187. int container_id,
  188. u16 *token);
  189. int dprc_close(struct fsl_mc_io *mc_io,
  190. u32 cmd_flags,
  191. u16 token);
  192. /* DPRC IRQ events */
  193. /* IRQ event - Indicates that a new object added to the container */
  194. #define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001
  195. /* IRQ event - Indicates that an object was removed from the container */
  196. #define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002
  197. /*
  198. * IRQ event - Indicates that one of the descendant containers that opened by
  199. * this container is destroyed
  200. */
  201. #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
  202. /*
  203. * IRQ event - Indicates that on one of the container's opened object is
  204. * destroyed
  205. */
  206. #define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
  207. /* Irq event - Indicates that object is created at the container */
  208. #define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040
  209. /**
  210. * struct dprc_irq_cfg - IRQ configuration
  211. * @paddr: Address that must be written to signal a message-based interrupt
  212. * @val: Value to write into irq_addr address
  213. * @irq_num: A user defined number associated with this IRQ
  214. */
  215. struct dprc_irq_cfg {
  216. phys_addr_t paddr;
  217. u32 val;
  218. int irq_num;
  219. };
  220. int dprc_set_irq(struct fsl_mc_io *mc_io,
  221. u32 cmd_flags,
  222. u16 token,
  223. u8 irq_index,
  224. struct dprc_irq_cfg *irq_cfg);
  225. int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
  226. u32 cmd_flags,
  227. u16 token,
  228. u8 irq_index,
  229. u8 en);
  230. int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
  231. u32 cmd_flags,
  232. u16 token,
  233. u8 irq_index,
  234. u32 mask);
  235. int dprc_get_irq_status(struct fsl_mc_io *mc_io,
  236. u32 cmd_flags,
  237. u16 token,
  238. u8 irq_index,
  239. u32 *status);
  240. int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
  241. u32 cmd_flags,
  242. u16 token,
  243. u8 irq_index,
  244. u32 status);
  245. /**
  246. * struct dprc_attributes - Container attributes
  247. * @container_id: Container's ID
  248. * @icid: Container's ICID
  249. * @portal_id: Container's portal ID
  250. * @options: Container's options as set at container's creation
  251. */
  252. struct dprc_attributes {
  253. int container_id;
  254. u16 icid;
  255. int portal_id;
  256. u64 options;
  257. };
  258. int dprc_get_attributes(struct fsl_mc_io *mc_io,
  259. u32 cmd_flags,
  260. u16 token,
  261. struct dprc_attributes *attributes);
  262. int dprc_get_obj_count(struct fsl_mc_io *mc_io,
  263. u32 cmd_flags,
  264. u16 token,
  265. int *obj_count);
  266. int dprc_get_obj(struct fsl_mc_io *mc_io,
  267. u32 cmd_flags,
  268. u16 token,
  269. int obj_index,
  270. struct fsl_mc_obj_desc *obj_desc);
  271. int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
  272. u32 cmd_flags,
  273. u16 token,
  274. char *obj_type,
  275. int obj_id,
  276. u8 irq_index,
  277. struct dprc_irq_cfg *irq_cfg);
  278. /* Region flags */
  279. /* Cacheable - Indicates that region should be mapped as cacheable */
  280. #define DPRC_REGION_CACHEABLE 0x00000001
  281. /**
  282. * enum dprc_region_type - Region type
  283. * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
  284. * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
  285. */
  286. enum dprc_region_type {
  287. DPRC_REGION_TYPE_MC_PORTAL,
  288. DPRC_REGION_TYPE_QBMAN_PORTAL
  289. };
  290. /**
  291. * struct dprc_region_desc - Mappable region descriptor
  292. * @base_offset: Region offset from region's base address.
  293. * For DPMCP and DPRC objects, region base is offset from SoC MC portals
  294. * base address; For DPIO, region base is offset from SoC QMan portals
  295. * base address
  296. * @size: Region size (in bytes)
  297. * @flags: Region attributes
  298. * @type: Portal region type
  299. */
  300. struct dprc_region_desc {
  301. u32 base_offset;
  302. u32 size;
  303. u32 flags;
  304. enum dprc_region_type type;
  305. };
  306. int dprc_get_obj_region(struct fsl_mc_io *mc_io,
  307. u32 cmd_flags,
  308. u16 token,
  309. char *obj_type,
  310. int obj_id,
  311. u8 region_index,
  312. struct dprc_region_desc *region_desc);
  313. int dprc_get_api_version(struct fsl_mc_io *mc_io,
  314. u32 cmd_flags,
  315. u16 *major_ver,
  316. u16 *minor_ver);
  317. int dprc_get_container_id(struct fsl_mc_io *mc_io,
  318. u32 cmd_flags,
  319. int *container_id);
  320. /*
  321. * Data Path Buffer Pool (DPBP) API
  322. */
  323. /* DPBP Version */
  324. #define DPBP_VER_MAJOR 3
  325. #define DPBP_VER_MINOR 2
  326. /* Command versioning */
  327. #define DPBP_CMD_BASE_VERSION 1
  328. #define DPBP_CMD_ID_OFFSET 4
  329. #define DPBP_CMD(id) (((id) << DPBP_CMD_ID_OFFSET) | DPBP_CMD_BASE_VERSION)
  330. /* Command IDs */
  331. #define DPBP_CMDID_CLOSE DPBP_CMD(0x800)
  332. #define DPBP_CMDID_OPEN DPBP_CMD(0x804)
  333. #define DPBP_CMDID_ENABLE DPBP_CMD(0x002)
  334. #define DPBP_CMDID_DISABLE DPBP_CMD(0x003)
  335. #define DPBP_CMDID_GET_ATTR DPBP_CMD(0x004)
  336. #define DPBP_CMDID_RESET DPBP_CMD(0x005)
  337. struct dpbp_cmd_open {
  338. __le32 dpbp_id;
  339. };
  340. #define DPBP_ENABLE 0x1
  341. struct dpbp_rsp_get_attributes {
  342. /* response word 0 */
  343. __le16 pad;
  344. __le16 bpid;
  345. __le32 id;
  346. /* response word 1 */
  347. __le16 version_major;
  348. __le16 version_minor;
  349. };
  350. /*
  351. * Data Path Concentrator (DPCON) API
  352. */
  353. /* DPCON Version */
  354. #define DPCON_VER_MAJOR 3
  355. #define DPCON_VER_MINOR 2
  356. /* Command versioning */
  357. #define DPCON_CMD_BASE_VERSION 1
  358. #define DPCON_CMD_ID_OFFSET 4
  359. #define DPCON_CMD(id) (((id) << DPCON_CMD_ID_OFFSET) | DPCON_CMD_BASE_VERSION)
  360. /* Command IDs */
  361. #define DPCON_CMDID_CLOSE DPCON_CMD(0x800)
  362. #define DPCON_CMDID_OPEN DPCON_CMD(0x808)
  363. #define DPCON_CMDID_ENABLE DPCON_CMD(0x002)
  364. #define DPCON_CMDID_DISABLE DPCON_CMD(0x003)
  365. #define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004)
  366. #define DPCON_CMDID_RESET DPCON_CMD(0x005)
  367. #define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100)
  368. struct dpcon_cmd_open {
  369. __le32 dpcon_id;
  370. };
  371. #define DPCON_ENABLE 1
  372. struct dpcon_rsp_get_attr {
  373. /* response word 0 */
  374. __le32 id;
  375. __le16 qbman_ch_id;
  376. u8 num_priorities;
  377. u8 pad;
  378. };
  379. struct dpcon_cmd_set_notification {
  380. /* cmd word 0 */
  381. __le32 dpio_id;
  382. u8 priority;
  383. u8 pad[3];
  384. /* cmd word 1 */
  385. __le64 user_ctx;
  386. };
  387. /**
  388. * Maximum number of total IRQs that can be pre-allocated for an MC bus'
  389. * IRQ pool
  390. */
  391. #define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256
  392. /**
  393. * struct fsl_mc_resource_pool - Pool of MC resources of a given
  394. * type
  395. * @type: type of resources in the pool
  396. * @max_count: maximum number of resources in the pool
  397. * @free_count: number of free resources in the pool
  398. * @mutex: mutex to serialize access to the pool's free list
  399. * @free_list: anchor node of list of free resources in the pool
  400. * @mc_bus: pointer to the MC bus that owns this resource pool
  401. */
  402. struct fsl_mc_resource_pool {
  403. enum fsl_mc_pool_type type;
  404. int max_count;
  405. int free_count;
  406. struct mutex mutex; /* serializes access to free_list */
  407. struct list_head free_list;
  408. struct fsl_mc_bus *mc_bus;
  409. };
  410. /**
  411. * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC
  412. * @mc_dev: fsl-mc device for the bus device itself.
  413. * @resource_pools: array of resource pools (one pool per resource type)
  414. * for this MC bus. These resources represent allocatable entities
  415. * from the physical DPRC.
  416. * @irq_resources: Pointer to array of IRQ objects for the IRQ pool
  417. * @scan_mutex: Serializes bus scanning
  418. * @dprc_attr: DPRC attributes
  419. */
  420. struct fsl_mc_bus {
  421. struct fsl_mc_device mc_dev;
  422. struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
  423. struct fsl_mc_device_irq *irq_resources;
  424. struct mutex scan_mutex; /* serializes bus scanning */
  425. struct dprc_attributes dprc_attr;
  426. };
  427. #define to_fsl_mc_bus(_mc_dev) \
  428. container_of(_mc_dev, struct fsl_mc_bus, mc_dev)
  429. int __must_check fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
  430. struct fsl_mc_io *mc_io,
  431. struct device *parent_dev,
  432. struct fsl_mc_device **new_mc_dev);
  433. void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
  434. int __init dprc_driver_init(void);
  435. void dprc_driver_exit(void);
  436. int __init fsl_mc_allocator_driver_init(void);
  437. void fsl_mc_allocator_driver_exit(void);
  438. void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
  439. void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
  440. int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
  441. enum fsl_mc_pool_type pool_type,
  442. struct fsl_mc_resource
  443. **new_resource);
  444. void fsl_mc_resource_free(struct fsl_mc_resource *resource);
  445. int fsl_mc_msi_domain_alloc_irqs(struct device *dev,
  446. unsigned int irq_count);
  447. void fsl_mc_msi_domain_free_irqs(struct device *dev);
  448. int fsl_mc_find_msi_domain(struct device *mc_platform_dev,
  449. struct irq_domain **mc_msi_domain);
  450. int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus,
  451. unsigned int irq_count);
  452. void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus);
  453. int __must_check fsl_create_mc_io(struct device *dev,
  454. phys_addr_t mc_portal_phys_addr,
  455. u32 mc_portal_size,
  456. struct fsl_mc_device *dpmcp_dev,
  457. u32 flags, struct fsl_mc_io **new_mc_io);
  458. void fsl_destroy_mc_io(struct fsl_mc_io *mc_io);
  459. bool fsl_mc_is_root_dprc(struct device *dev);
  460. #endif /* _FSL_MC_PRIVATE_H_ */