fsl-mc-private.h 13 KB

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