dprc.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. /* Copyright 2013-2015 Freescale Semiconductor Inc.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are met:
  5. * * Redistributions of source code must retain the above copyright
  6. * notice, this list of conditions and the following disclaimer.
  7. * * Redistributions in binary form must reproduce the above copyright
  8. * notice, this list of conditions and the following disclaimer in the
  9. * documentation and/or other materials provided with the distribution.
  10. * * Neither the name of the above-listed copyright holders nor the
  11. * names of any contributors may be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. *
  15. * ALTERNATIVELY, this software may be distributed under the terms of the
  16. * GNU General Public License ("GPL") as published by the Free Software
  17. * Foundation, either version 2 of that License or (at your option) any
  18. * later version.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  24. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #ifndef _FSL_DPRC_H
  33. #define _FSL_DPRC_H
  34. #include "mc-cmd.h"
  35. /* Data Path Resource Container API
  36. * Contains DPRC API for managing and querying DPAA resources
  37. */
  38. struct fsl_mc_io;
  39. /**
  40. * Set this value as the icid value in dprc_cfg structure when creating a
  41. * container, in case the ICID is not selected by the user and should be
  42. * allocated by the DPRC from the pool of ICIDs.
  43. */
  44. #define DPRC_GET_ICID_FROM_POOL (u16)(~(0))
  45. /**
  46. * Set this value as the portal_id value in dprc_cfg structure when creating a
  47. * container, in case the portal ID is not specifically selected by the
  48. * user and should be allocated by the DPRC from the pool of portal ids.
  49. */
  50. #define DPRC_GET_PORTAL_ID_FROM_POOL (int)(~(0))
  51. int dprc_open(struct fsl_mc_io *mc_io,
  52. u32 cmd_flags,
  53. int container_id,
  54. u16 *token);
  55. int dprc_close(struct fsl_mc_io *mc_io,
  56. u32 cmd_flags,
  57. u16 token);
  58. /**
  59. * Container general options
  60. *
  61. * These options may be selected at container creation by the container creator
  62. * and can be retrieved using dprc_get_attributes()
  63. */
  64. /* Spawn Policy Option allowed - Indicates that the new container is allowed
  65. * to spawn and have its own child containers.
  66. */
  67. #define DPRC_CFG_OPT_SPAWN_ALLOWED 0x00000001
  68. /* General Container allocation policy - Indicates that the new container is
  69. * allowed to allocate requested resources from its parent container; if not
  70. * set, the container is only allowed to use resources in its own pools; Note
  71. * that this is a container's global policy, but the parent container may
  72. * override it and set specific quota per resource type.
  73. */
  74. #define DPRC_CFG_OPT_ALLOC_ALLOWED 0x00000002
  75. /* Object initialization allowed - software context associated with this
  76. * container is allowed to invoke object initialization operations.
  77. */
  78. #define DPRC_CFG_OPT_OBJ_CREATE_ALLOWED 0x00000004
  79. /* Topology change allowed - software context associated with this
  80. * container is allowed to invoke topology operations, such as attach/detach
  81. * of network objects.
  82. */
  83. #define DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED 0x00000008
  84. /* IOMMU bypass - indicates whether objects of this container are permitted
  85. * to bypass the IOMMU.
  86. */
  87. #define DPRC_CFG_OPT_IOMMU_BYPASS 0x00000010
  88. /* AIOP - Indicates that container belongs to AIOP. */
  89. #define DPRC_CFG_OPT_AIOP 0x00000020
  90. /* IRQ Config - Indicates that the container allowed to configure its IRQs. */
  91. #define DPRC_CFG_OPT_IRQ_CFG_ALLOWED 0x00000040
  92. /**
  93. * struct dprc_cfg - Container configuration options
  94. * @icid: Container's ICID; if set to 'DPRC_GET_ICID_FROM_POOL', a free
  95. * ICID value is allocated by the DPRC
  96. * @portal_id: Portal ID; if set to 'DPRC_GET_PORTAL_ID_FROM_POOL', a free
  97. * portal ID is allocated by the DPRC
  98. * @options: Combination of 'DPRC_CFG_OPT_<X>' options
  99. * @label: Object's label
  100. */
  101. struct dprc_cfg {
  102. u16 icid;
  103. int portal_id;
  104. u64 options;
  105. char label[16];
  106. };
  107. int dprc_create_container(struct fsl_mc_io *mc_io,
  108. u32 cmd_flags,
  109. u16 token,
  110. struct dprc_cfg *cfg,
  111. int *child_container_id,
  112. u64 *child_portal_offset);
  113. int dprc_destroy_container(struct fsl_mc_io *mc_io,
  114. u32 cmd_flags,
  115. u16 token,
  116. int child_container_id);
  117. int dprc_reset_container(struct fsl_mc_io *mc_io,
  118. u32 cmd_flags,
  119. u16 token,
  120. int child_container_id);
  121. /* IRQ */
  122. /* IRQ index */
  123. #define DPRC_IRQ_INDEX 0
  124. /* Number of dprc's IRQs */
  125. #define DPRC_NUM_OF_IRQS 1
  126. /* DPRC IRQ events */
  127. /* IRQ event - Indicates that a new object added to the container */
  128. #define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001
  129. /* IRQ event - Indicates that an object was removed from the container */
  130. #define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002
  131. /* IRQ event - Indicates that resources added to the container */
  132. #define DPRC_IRQ_EVENT_RES_ADDED 0x00000004
  133. /* IRQ event - Indicates that resources removed from the container */
  134. #define DPRC_IRQ_EVENT_RES_REMOVED 0x00000008
  135. /* IRQ event - Indicates that one of the descendant containers that opened by
  136. * this container is destroyed
  137. */
  138. #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
  139. /* IRQ event - Indicates that on one of the container's opened object is
  140. * destroyed
  141. */
  142. #define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
  143. /* Irq event - Indicates that object is created at the container */
  144. #define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040
  145. /**
  146. * struct dprc_irq_cfg - IRQ configuration
  147. * @paddr: Address that must be written to signal a message-based interrupt
  148. * @val: Value to write into irq_addr address
  149. * @user_irq_id: A user defined number associated with this IRQ
  150. */
  151. struct dprc_irq_cfg {
  152. u64 paddr;
  153. u32 val;
  154. int user_irq_id;
  155. };
  156. int dprc_set_irq(struct fsl_mc_io *mc_io,
  157. u32 cmd_flags,
  158. u16 token,
  159. u8 irq_index,
  160. struct dprc_irq_cfg *irq_cfg);
  161. int dprc_get_irq(struct fsl_mc_io *mc_io,
  162. u32 cmd_flags,
  163. u16 token,
  164. u8 irq_index,
  165. int *type,
  166. struct dprc_irq_cfg *irq_cfg);
  167. int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
  168. u32 cmd_flags,
  169. u16 token,
  170. u8 irq_index,
  171. u8 en);
  172. int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
  173. u32 cmd_flags,
  174. u16 token,
  175. u8 irq_index,
  176. u8 *en);
  177. int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
  178. u32 cmd_flags,
  179. u16 token,
  180. u8 irq_index,
  181. u32 mask);
  182. int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
  183. u32 cmd_flags,
  184. u16 token,
  185. u8 irq_index,
  186. u32 *mask);
  187. int dprc_get_irq_status(struct fsl_mc_io *mc_io,
  188. u32 cmd_flags,
  189. u16 token,
  190. u8 irq_index,
  191. u32 *status);
  192. int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
  193. u32 cmd_flags,
  194. u16 token,
  195. u8 irq_index,
  196. u32 status);
  197. /**
  198. * struct dprc_attributes - Container attributes
  199. * @container_id: Container's ID
  200. * @icid: Container's ICID
  201. * @portal_id: Container's portal ID
  202. * @options: Container's options as set at container's creation
  203. * @version: DPRC version
  204. */
  205. struct dprc_attributes {
  206. int container_id;
  207. u16 icid;
  208. int portal_id;
  209. u64 options;
  210. /**
  211. * struct version - DPRC version
  212. * @major: DPRC major version
  213. * @minor: DPRC minor version
  214. */
  215. struct {
  216. u16 major;
  217. u16 minor;
  218. } version;
  219. };
  220. int dprc_get_attributes(struct fsl_mc_io *mc_io,
  221. u32 cmd_flags,
  222. u16 token,
  223. struct dprc_attributes *attributes);
  224. int dprc_set_res_quota(struct fsl_mc_io *mc_io,
  225. u32 cmd_flags,
  226. u16 token,
  227. int child_container_id,
  228. char *type,
  229. u16 quota);
  230. int dprc_get_res_quota(struct fsl_mc_io *mc_io,
  231. u32 cmd_flags,
  232. u16 token,
  233. int child_container_id,
  234. char *type,
  235. u16 *quota);
  236. /* Resource request options */
  237. /* Explicit resource ID request - The requested objects/resources
  238. * are explicit and sequential (in case of resources).
  239. * The base ID is given at res_req at base_align field
  240. */
  241. #define DPRC_RES_REQ_OPT_EXPLICIT 0x00000001
  242. /* Aligned resources request - Relevant only for resources
  243. * request (and not objects). Indicates that resources base ID should be
  244. * sequential and aligned to the value given at dprc_res_req base_align field
  245. */
  246. #define DPRC_RES_REQ_OPT_ALIGNED 0x00000002
  247. /* Plugged Flag - Relevant only for object assignment request.
  248. * Indicates that after all objects assigned. An interrupt will be invoked at
  249. * the relevant GPP. The assigned object will be marked as plugged.
  250. * plugged objects can't be assigned from their container
  251. */
  252. #define DPRC_RES_REQ_OPT_PLUGGED 0x00000004
  253. /**
  254. * struct dprc_res_req - Resource request descriptor, to be used in assignment
  255. * or un-assignment of resources and objects.
  256. * @type: Resource/object type: Represent as a NULL terminated string.
  257. * This string may received by using dprc_get_pool() to get resource
  258. * type and dprc_get_obj() to get object type;
  259. * Note: it is not possible to assign/un-assign DPRC objects
  260. * @num: Number of resources
  261. * @options: Request options: combination of DPRC_RES_REQ_OPT_ options
  262. * @id_base_align: In case of explicit assignment (DPRC_RES_REQ_OPT_EXPLICIT
  263. * is set at option), this field represents the required base ID
  264. * for resource allocation; In case of aligned assignment
  265. * (DPRC_RES_REQ_OPT_ALIGNED is set at option), this field
  266. * indicates the required alignment for the resource ID(s) -
  267. * use 0 if there is no alignment or explicit ID requirements
  268. */
  269. struct dprc_res_req {
  270. char type[16];
  271. u32 num;
  272. u32 options;
  273. int id_base_align;
  274. };
  275. int dprc_assign(struct fsl_mc_io *mc_io,
  276. u32 cmd_flags,
  277. u16 token,
  278. int container_id,
  279. struct dprc_res_req *res_req);
  280. int dprc_unassign(struct fsl_mc_io *mc_io,
  281. u32 cmd_flags,
  282. u16 token,
  283. int child_container_id,
  284. struct dprc_res_req *res_req);
  285. int dprc_get_pool_count(struct fsl_mc_io *mc_io,
  286. u32 cmd_flags,
  287. u16 token,
  288. int *pool_count);
  289. int dprc_get_pool(struct fsl_mc_io *mc_io,
  290. u32 cmd_flags,
  291. u16 token,
  292. int pool_index,
  293. char *type);
  294. int dprc_get_obj_count(struct fsl_mc_io *mc_io,
  295. u32 cmd_flags,
  296. u16 token,
  297. int *obj_count);
  298. /* Objects Attributes Flags */
  299. /* Opened state - Indicates that an object is open by at least one owner */
  300. #define DPRC_OBJ_STATE_OPEN 0x00000001
  301. /* Plugged state - Indicates that the object is plugged */
  302. #define DPRC_OBJ_STATE_PLUGGED 0x00000002
  303. /**
  304. * struct dprc_obj_desc - Object descriptor, returned from dprc_get_obj()
  305. * @type: Type of object: NULL terminated string
  306. * @id: ID of logical object resource
  307. * @vendor: Object vendor identifier
  308. * @ver_major: Major version number
  309. * @ver_minor: Minor version number
  310. * @irq_count: Number of interrupts supported by the object
  311. * @region_count: Number of mappable regions supported by the object
  312. * @state: Object state: combination of DPRC_OBJ_STATE_ states
  313. * @label: Object label
  314. */
  315. struct dprc_obj_desc {
  316. char type[16];
  317. int id;
  318. u16 vendor;
  319. u16 ver_major;
  320. u16 ver_minor;
  321. u8 irq_count;
  322. u8 region_count;
  323. u32 state;
  324. char label[16];
  325. };
  326. int dprc_get_obj(struct fsl_mc_io *mc_io,
  327. u32 cmd_flags,
  328. u16 token,
  329. int obj_index,
  330. struct dprc_obj_desc *obj_desc);
  331. int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
  332. u32 cmd_flags,
  333. u16 token,
  334. char *obj_type,
  335. int obj_id,
  336. struct dprc_obj_desc *obj_desc);
  337. int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
  338. u32 cmd_flags,
  339. u16 token,
  340. char *obj_type,
  341. int obj_id,
  342. u8 irq_index,
  343. struct dprc_irq_cfg *irq_cfg);
  344. int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
  345. u32 cmd_flags,
  346. u16 token,
  347. char *obj_type,
  348. int obj_id,
  349. u8 irq_index,
  350. int *type,
  351. struct dprc_irq_cfg *irq_cfg);
  352. int dprc_get_res_count(struct fsl_mc_io *mc_io,
  353. u32 cmd_flags,
  354. u16 token,
  355. char *type,
  356. int *res_count);
  357. /**
  358. * enum dprc_iter_status - Iteration status
  359. * @DPRC_ITER_STATUS_FIRST: Perform first iteration
  360. * @DPRC_ITER_STATUS_MORE: Indicates more/next iteration is needed
  361. * @DPRC_ITER_STATUS_LAST: Indicates last iteration
  362. */
  363. enum dprc_iter_status {
  364. DPRC_ITER_STATUS_FIRST = 0,
  365. DPRC_ITER_STATUS_MORE = 1,
  366. DPRC_ITER_STATUS_LAST = 2
  367. };
  368. /**
  369. * struct dprc_res_ids_range_desc - Resource ID range descriptor
  370. * @base_id: Base resource ID of this range
  371. * @last_id: Last resource ID of this range
  372. * @iter_status: Iteration status - should be set to DPRC_ITER_STATUS_FIRST at
  373. * first iteration; while the returned marker is DPRC_ITER_STATUS_MORE,
  374. * additional iterations are needed, until the returned marker is
  375. * DPRC_ITER_STATUS_LAST
  376. */
  377. struct dprc_res_ids_range_desc {
  378. int base_id;
  379. int last_id;
  380. enum dprc_iter_status iter_status;
  381. };
  382. int dprc_get_res_ids(struct fsl_mc_io *mc_io,
  383. u32 cmd_flags,
  384. u16 token,
  385. char *type,
  386. struct dprc_res_ids_range_desc *range_desc);
  387. /* Region flags */
  388. /* Cacheable - Indicates that region should be mapped as cacheable */
  389. #define DPRC_REGION_CACHEABLE 0x00000001
  390. /**
  391. * enum dprc_region_type - Region type
  392. * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
  393. * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
  394. */
  395. enum dprc_region_type {
  396. DPRC_REGION_TYPE_MC_PORTAL,
  397. DPRC_REGION_TYPE_QBMAN_PORTAL
  398. };
  399. /**
  400. * struct dprc_region_desc - Mappable region descriptor
  401. * @base_offset: Region offset from region's base address.
  402. * For DPMCP and DPRC objects, region base is offset from SoC MC portals
  403. * base address; For DPIO, region base is offset from SoC QMan portals
  404. * base address
  405. * @size: Region size (in bytes)
  406. * @flags: Region attributes
  407. * @type: Portal region type
  408. */
  409. struct dprc_region_desc {
  410. u32 base_offset;
  411. u32 size;
  412. u32 flags;
  413. enum dprc_region_type type;
  414. };
  415. int dprc_get_obj_region(struct fsl_mc_io *mc_io,
  416. u32 cmd_flags,
  417. u16 token,
  418. char *obj_type,
  419. int obj_id,
  420. u8 region_index,
  421. struct dprc_region_desc *region_desc);
  422. int dprc_set_obj_label(struct fsl_mc_io *mc_io,
  423. u32 cmd_flags,
  424. u16 token,
  425. char *obj_type,
  426. int obj_id,
  427. char *label);
  428. /**
  429. * struct dprc_endpoint - Endpoint description for link connect/disconnect
  430. * operations
  431. * @type: Endpoint object type: NULL terminated string
  432. * @id: Endpoint object ID
  433. * @if_id: Interface ID; should be set for endpoints with multiple
  434. * interfaces ("dpsw", "dpdmux"); for others, always set to 0
  435. */
  436. struct dprc_endpoint {
  437. char type[16];
  438. int id;
  439. int if_id;
  440. };
  441. /**
  442. * struct dprc_connection_cfg - Connection configuration.
  443. * Used for virtual connections only
  444. * @committed_rate: Committed rate (Mbits/s)
  445. * @max_rate: Maximum rate (Mbits/s)
  446. */
  447. struct dprc_connection_cfg {
  448. u32 committed_rate;
  449. u32 max_rate;
  450. };
  451. int dprc_connect(struct fsl_mc_io *mc_io,
  452. u32 cmd_flags,
  453. u16 token,
  454. const struct dprc_endpoint *endpoint1,
  455. const struct dprc_endpoint *endpoint2,
  456. const struct dprc_connection_cfg *cfg);
  457. int dprc_disconnect(struct fsl_mc_io *mc_io,
  458. u32 cmd_flags,
  459. u16 token,
  460. const struct dprc_endpoint *endpoint);
  461. int dprc_get_connection(struct fsl_mc_io *mc_io,
  462. u32 cmd_flags,
  463. u16 token,
  464. const struct dprc_endpoint *endpoint1,
  465. struct dprc_endpoint *endpoint2,
  466. int *state);
  467. #endif /* _FSL_DPRC_H */