1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Freescale Management Complex (MC) bus private declarations
5 * Copyright (C) 2016 Freescale Semiconductor, Inc.
8 #ifndef _FSL_MC_PRIVATE_H_
9 #define _FSL_MC_PRIVATE_H_
11 #include <linux/fsl/mc.h>
12 #include <linux/mutex.h>
15 * Data Path Management Complex (DPMNG) General API
18 /* DPMNG command versioning */
19 #define DPMNG_CMD_BASE_VERSION 1
20 #define DPMNG_CMD_ID_OFFSET 4
22 #define DPMNG_CMD(id) (((id) << DPMNG_CMD_ID_OFFSET) | DPMNG_CMD_BASE_VERSION)
24 /* DPMNG command IDs */
25 #define DPMNG_CMDID_GET_VERSION DPMNG_CMD(0x831)
27 struct dpmng_rsp_get_version {
34 * Data Path Management Command Portal (DPMCP) API
37 /* Minimal supported DPMCP Version */
38 #define DPMCP_MIN_VER_MAJOR 3
39 #define DPMCP_MIN_VER_MINOR 0
41 /* DPMCP command versioning */
42 #define DPMCP_CMD_BASE_VERSION 1
43 #define DPMCP_CMD_ID_OFFSET 4
45 #define DPMCP_CMD(id) (((id) << DPMCP_CMD_ID_OFFSET) | DPMCP_CMD_BASE_VERSION)
47 /* DPMCP command IDs */
48 #define DPMCP_CMDID_CLOSE DPMCP_CMD(0x800)
49 #define DPMCP_CMDID_OPEN DPMCP_CMD(0x80b)
50 #define DPMCP_CMDID_RESET DPMCP_CMD(0x005)
52 struct dpmcp_cmd_open {
57 * Initialization and runtime control APIs for DPMCP
59 int dpmcp_open(struct fsl_mc_io *mc_io,
64 int dpmcp_close(struct fsl_mc_io *mc_io,
68 int dpmcp_reset(struct fsl_mc_io *mc_io,
73 * Data Path Resource Container (DPRC) API
76 /* Minimal supported DPRC Version */
77 #define DPRC_MIN_VER_MAJOR 6
78 #define DPRC_MIN_VER_MINOR 0
80 /* DPRC command versioning */
81 #define DPRC_CMD_BASE_VERSION 1
82 #define DPRC_CMD_2ND_VERSION 2
83 #define DPRC_CMD_3RD_VERSION 3
84 #define DPRC_CMD_ID_OFFSET 4
86 #define DPRC_CMD(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
87 #define DPRC_CMD_V2(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_2ND_VERSION)
88 #define DPRC_CMD_V3(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_3RD_VERSION)
90 /* DPRC command IDs */
91 #define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
92 #define DPRC_CMDID_OPEN DPRC_CMD(0x805)
93 #define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
95 #define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
96 #define DPRC_CMDID_RESET_CONT DPRC_CMD(0x005)
97 #define DPRC_CMDID_RESET_CONT_V2 DPRC_CMD_V2(0x005)
99 #define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
100 #define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
101 #define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
102 #define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
103 #define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
105 #define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
106 #define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
107 #define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
108 #define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
109 #define DPRC_CMDID_GET_OBJ_REG_V2 DPRC_CMD_V2(0x15E)
110 #define DPRC_CMDID_GET_OBJ_REG_V3 DPRC_CMD_V3(0x15E)
111 #define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
113 #define DPRC_CMDID_GET_CONNECTION DPRC_CMD(0x16C)
115 struct dprc_cmd_open {
119 struct dprc_cmd_reset_container {
120 __le32 child_container_id;
124 struct dprc_cmd_set_irq {
135 #define DPRC_ENABLE 0x1
137 struct dprc_cmd_set_irq_enable {
143 struct dprc_cmd_set_irq_mask {
148 struct dprc_cmd_get_irq_status {
153 struct dprc_rsp_get_irq_status {
157 struct dprc_cmd_clear_irq_status {
162 struct dprc_rsp_get_attributes {
163 /* response word 0 */
166 /* response word 1 */
171 struct dprc_rsp_get_obj_count {
176 struct dprc_cmd_get_obj {
180 struct dprc_rsp_get_obj {
181 /* response word 0 */
184 /* response word 1 */
189 /* response word 2 */
190 __le16 version_major;
191 __le16 version_minor;
194 /* response word 3-4 */
196 /* response word 5-6 */
200 struct dprc_cmd_get_obj_region {
212 struct dprc_rsp_get_obj_region {
213 /* response word 0 */
215 /* response word 1 */
217 /* response word 2 */
220 /* response word 3 */
223 /* response word 4 */
224 /* base_addr may be zero if older MC firmware is used */
228 struct dprc_cmd_set_obj_irq {
242 struct dprc_cmd_get_connection {
244 __le16 ep1_interface_id;
249 struct dprc_rsp_get_connection {
252 __le16 ep2_interface_id;
259 * DPRC API for managing and querying DPAA resources
261 int dprc_open(struct fsl_mc_io *mc_io,
266 int dprc_close(struct fsl_mc_io *mc_io,
270 /* DPRC IRQ events */
272 /* IRQ event - Indicates that a new object added to the container */
273 #define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001
274 /* IRQ event - Indicates that an object was removed from the container */
275 #define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002
277 * IRQ event - Indicates that one of the descendant containers that opened by
278 * this container is destroyed
280 #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
283 * IRQ event - Indicates that on one of the container's opened object is
286 #define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
288 /* Irq event - Indicates that object is created at the container */
289 #define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040
292 * struct dprc_irq_cfg - IRQ configuration
293 * @paddr: Address that must be written to signal a message-based interrupt
294 * @val: Value to write into irq_addr address
295 * @irq_num: A user defined number associated with this IRQ
297 struct dprc_irq_cfg {
303 int dprc_set_irq(struct fsl_mc_io *mc_io,
307 struct dprc_irq_cfg *irq_cfg);
309 int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
315 int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
321 int dprc_get_irq_status(struct fsl_mc_io *mc_io,
327 int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
334 * struct dprc_attributes - Container attributes
335 * @container_id: Container's ID
336 * @icid: Container's ICID
337 * @portal_id: Container's portal ID
338 * @options: Container's options as set at container's creation
340 struct dprc_attributes {
347 int dprc_get_attributes(struct fsl_mc_io *mc_io,
350 struct dprc_attributes *attributes);
352 int dprc_get_obj_count(struct fsl_mc_io *mc_io,
357 int dprc_get_obj(struct fsl_mc_io *mc_io,
361 struct fsl_mc_obj_desc *obj_desc);
363 int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
369 struct dprc_irq_cfg *irq_cfg);
371 * enum dprc_region_type - Region type
372 * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
373 * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
375 enum dprc_region_type {
376 DPRC_REGION_TYPE_MC_PORTAL,
377 DPRC_REGION_TYPE_QBMAN_PORTAL,
378 DPRC_REGION_TYPE_QBMAN_MEM_BACKED_PORTAL
382 * struct dprc_region_desc - Mappable region descriptor
383 * @base_offset: Region offset from region's base address.
384 * For DPMCP and DPRC objects, region base is offset from SoC MC portals
385 * base address; For DPIO, region base is offset from SoC QMan portals
387 * @size: Region size (in bytes)
388 * @flags: Region attributes
389 * @type: Portal region type
391 struct dprc_region_desc {
395 enum dprc_region_type type;
399 int dprc_get_obj_region(struct fsl_mc_io *mc_io,
405 struct dprc_region_desc *region_desc);
407 int dprc_get_api_version(struct fsl_mc_io *mc_io,
412 int dprc_get_container_id(struct fsl_mc_io *mc_io,
417 * struct dprc_endpoint - Endpoint description for link connect/disconnect
419 * @type: Endpoint object type: NULL terminated string
420 * @id: Endpoint object ID
421 * @if_id: Interface ID; should be set for endpoints with multiple
422 * interfaces ("dpsw", "dpdmux"); for others, always set to 0
424 struct dprc_endpoint {
430 int dprc_get_connection(struct fsl_mc_io *mc_io,
433 const struct dprc_endpoint *endpoint1,
434 struct dprc_endpoint *endpoint2,
438 * Data Path Buffer Pool (DPBP) API
442 #define DPBP_VER_MAJOR 3
443 #define DPBP_VER_MINOR 2
445 /* Command versioning */
446 #define DPBP_CMD_BASE_VERSION 1
447 #define DPBP_CMD_ID_OFFSET 4
449 #define DPBP_CMD(id) (((id) << DPBP_CMD_ID_OFFSET) | DPBP_CMD_BASE_VERSION)
452 #define DPBP_CMDID_CLOSE DPBP_CMD(0x800)
453 #define DPBP_CMDID_OPEN DPBP_CMD(0x804)
455 #define DPBP_CMDID_ENABLE DPBP_CMD(0x002)
456 #define DPBP_CMDID_DISABLE DPBP_CMD(0x003)
457 #define DPBP_CMDID_GET_ATTR DPBP_CMD(0x004)
458 #define DPBP_CMDID_RESET DPBP_CMD(0x005)
460 struct dpbp_cmd_open {
464 #define DPBP_ENABLE 0x1
466 struct dpbp_rsp_get_attributes {
467 /* response word 0 */
471 /* response word 1 */
472 __le16 version_major;
473 __le16 version_minor;
477 * Data Path Concentrator (DPCON) API
481 #define DPCON_VER_MAJOR 3
482 #define DPCON_VER_MINOR 2
484 /* Command versioning */
485 #define DPCON_CMD_BASE_VERSION 1
486 #define DPCON_CMD_ID_OFFSET 4
488 #define DPCON_CMD(id) (((id) << DPCON_CMD_ID_OFFSET) | DPCON_CMD_BASE_VERSION)
491 #define DPCON_CMDID_CLOSE DPCON_CMD(0x800)
492 #define DPCON_CMDID_OPEN DPCON_CMD(0x808)
494 #define DPCON_CMDID_ENABLE DPCON_CMD(0x002)
495 #define DPCON_CMDID_DISABLE DPCON_CMD(0x003)
496 #define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004)
497 #define DPCON_CMDID_RESET DPCON_CMD(0x005)
499 #define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100)
501 struct dpcon_cmd_open {
505 #define DPCON_ENABLE 1
507 struct dpcon_rsp_get_attr {
508 /* response word 0 */
515 struct dpcon_cmd_set_notification {
526 * struct fsl_mc_resource_pool - Pool of MC resources of a given
528 * @type: type of resources in the pool
529 * @max_count: maximum number of resources in the pool
530 * @free_count: number of free resources in the pool
531 * @mutex: mutex to serialize access to the pool's free list
532 * @free_list: anchor node of list of free resources in the pool
533 * @mc_bus: pointer to the MC bus that owns this resource pool
535 struct fsl_mc_resource_pool {
536 enum fsl_mc_pool_type type;
539 struct mutex mutex; /* serializes access to free_list */
540 struct list_head free_list;
541 struct fsl_mc_bus *mc_bus;
545 * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC
546 * @mc_dev: fsl-mc device for the bus device itself.
547 * @resource_pools: array of resource pools (one pool per resource type)
548 * for this MC bus. These resources represent allocatable entities
549 * from the physical DPRC.
550 * @irq_resources: Pointer to array of IRQ objects for the IRQ pool
551 * @scan_mutex: Serializes bus scanning
552 * @dprc_attr: DPRC attributes
555 struct fsl_mc_device mc_dev;
556 struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
557 struct fsl_mc_device_irq *irq_resources;
558 struct mutex scan_mutex; /* serializes bus scanning */
559 struct dprc_attributes dprc_attr;
562 #define to_fsl_mc_bus(_mc_dev) \
563 container_of(_mc_dev, struct fsl_mc_bus, mc_dev)
565 int __must_check fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
566 struct fsl_mc_io *mc_io,
567 struct device *parent_dev,
568 struct fsl_mc_device **new_mc_dev);
570 void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
572 int __init dprc_driver_init(void);
574 void dprc_driver_exit(void);
576 int __init fsl_mc_allocator_driver_init(void);
578 void fsl_mc_allocator_driver_exit(void);
580 void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
582 void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
584 int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
585 enum fsl_mc_pool_type pool_type,
586 struct fsl_mc_resource
589 void fsl_mc_resource_free(struct fsl_mc_resource *resource);
591 int fsl_mc_msi_domain_alloc_irqs(struct device *dev,
592 unsigned int irq_count);
594 void fsl_mc_msi_domain_free_irqs(struct device *dev);
596 struct irq_domain *fsl_mc_find_msi_domain(struct device *dev);
598 int __must_check fsl_create_mc_io(struct device *dev,
599 phys_addr_t mc_portal_phys_addr,
601 struct fsl_mc_device *dpmcp_dev,
602 u32 flags, struct fsl_mc_io **new_mc_io);
604 void fsl_destroy_mc_io(struct fsl_mc_io *mc_io);
606 bool fsl_mc_is_root_dprc(struct device *dev);
608 void fsl_mc_get_root_dprc(struct device *dev,
609 struct device **root_dprc_dev);
611 struct fsl_mc_device *fsl_mc_device_lookup(struct fsl_mc_obj_desc *obj_desc,
612 struct fsl_mc_device *mc_bus_dev);
614 #endif /* _FSL_MC_PRIVATE_H_ */