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_ID_OFFSET 4
85 #define DPRC_CMD(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
86 #define DPRC_CMD_V2(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_2ND_VERSION)
88 /* DPRC command IDs */
89 #define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
90 #define DPRC_CMDID_OPEN DPRC_CMD(0x805)
91 #define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
93 #define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
95 #define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
96 #define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
97 #define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
98 #define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
99 #define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
101 #define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
102 #define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
103 #define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
104 #define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
105 #define DPRC_CMDID_GET_OBJ_REG_V2 DPRC_CMD_V2(0x15E)
106 #define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
108 #define DPRC_CMDID_GET_CONNECTION DPRC_CMD(0x16C)
110 struct dprc_cmd_open
{
114 struct dprc_cmd_set_irq
{
125 #define DPRC_ENABLE 0x1
127 struct dprc_cmd_set_irq_enable
{
133 struct dprc_cmd_set_irq_mask
{
138 struct dprc_cmd_get_irq_status
{
143 struct dprc_rsp_get_irq_status
{
147 struct dprc_cmd_clear_irq_status
{
152 struct dprc_rsp_get_attributes
{
153 /* response word 0 */
157 /* response word 1 */
162 struct dprc_rsp_get_obj_count
{
167 struct dprc_cmd_get_obj
{
171 struct dprc_rsp_get_obj
{
172 /* response word 0 */
175 /* response word 1 */
180 /* response word 2 */
181 __le16 version_major
;
182 __le16 version_minor
;
185 /* response word 3-4 */
187 /* response word 5-6 */
191 struct dprc_cmd_get_obj_region
{
203 struct dprc_rsp_get_obj_region
{
204 /* response word 0 */
206 /* response word 1 */
208 /* response word 2 */
211 /* response word 3 */
214 /* response word 4 */
215 /* base_addr may be zero if older MC firmware is used */
219 struct dprc_cmd_set_obj_irq
{
233 struct dprc_cmd_get_connection
{
235 __le16 ep1_interface_id
;
240 struct dprc_rsp_get_connection
{
243 __le16 ep2_interface_id
;
250 * DPRC API for managing and querying DPAA resources
252 int dprc_open(struct fsl_mc_io
*mc_io
,
257 int dprc_close(struct fsl_mc_io
*mc_io
,
261 /* DPRC IRQ events */
263 /* IRQ event - Indicates that a new object added to the container */
264 #define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001
265 /* IRQ event - Indicates that an object was removed from the container */
266 #define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002
268 * IRQ event - Indicates that one of the descendant containers that opened by
269 * this container is destroyed
271 #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
274 * IRQ event - Indicates that on one of the container's opened object is
277 #define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
279 /* Irq event - Indicates that object is created at the container */
280 #define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040
283 * struct dprc_irq_cfg - IRQ configuration
284 * @paddr: Address that must be written to signal a message-based interrupt
285 * @val: Value to write into irq_addr address
286 * @irq_num: A user defined number associated with this IRQ
288 struct dprc_irq_cfg
{
294 int dprc_set_irq(struct fsl_mc_io
*mc_io
,
298 struct dprc_irq_cfg
*irq_cfg
);
300 int dprc_set_irq_enable(struct fsl_mc_io
*mc_io
,
306 int dprc_set_irq_mask(struct fsl_mc_io
*mc_io
,
312 int dprc_get_irq_status(struct fsl_mc_io
*mc_io
,
318 int dprc_clear_irq_status(struct fsl_mc_io
*mc_io
,
325 * struct dprc_attributes - Container attributes
326 * @container_id: Container's ID
327 * @icid: Container's ICID
328 * @portal_id: Container's portal ID
329 * @options: Container's options as set at container's creation
331 struct dprc_attributes
{
338 int dprc_get_attributes(struct fsl_mc_io
*mc_io
,
341 struct dprc_attributes
*attributes
);
343 int dprc_get_obj_count(struct fsl_mc_io
*mc_io
,
348 int dprc_get_obj(struct fsl_mc_io
*mc_io
,
352 struct fsl_mc_obj_desc
*obj_desc
);
354 int dprc_set_obj_irq(struct fsl_mc_io
*mc_io
,
360 struct dprc_irq_cfg
*irq_cfg
);
363 /* Cacheable - Indicates that region should be mapped as cacheable */
364 #define DPRC_REGION_CACHEABLE 0x00000001
365 #define DPRC_REGION_SHAREABLE 0x00000002
368 * enum dprc_region_type - Region type
369 * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
370 * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
372 enum dprc_region_type
{
373 DPRC_REGION_TYPE_MC_PORTAL
,
374 DPRC_REGION_TYPE_QBMAN_PORTAL
,
375 DPRC_REGION_TYPE_QBMAN_MEM_BACKED_PORTAL
379 * struct dprc_region_desc - Mappable region descriptor
380 * @base_offset: Region offset from region's base address.
381 * For DPMCP and DPRC objects, region base is offset from SoC MC portals
382 * base address; For DPIO, region base is offset from SoC QMan portals
384 * @size: Region size (in bytes)
385 * @flags: Region attributes
386 * @type: Portal region type
388 struct dprc_region_desc
{
392 enum dprc_region_type type
;
396 int dprc_get_obj_region(struct fsl_mc_io
*mc_io
,
402 struct dprc_region_desc
*region_desc
);
404 int dprc_get_api_version(struct fsl_mc_io
*mc_io
,
409 int dprc_get_container_id(struct fsl_mc_io
*mc_io
,
414 * struct dprc_endpoint - Endpoint description for link connect/disconnect
416 * @type: Endpoint object type: NULL terminated string
417 * @id: Endpoint object ID
418 * @if_id: Interface ID; should be set for endpoints with multiple
419 * interfaces ("dpsw", "dpdmux"); for others, always set to 0
421 struct dprc_endpoint
{
427 int dprc_get_connection(struct fsl_mc_io
*mc_io
,
430 const struct dprc_endpoint
*endpoint1
,
431 struct dprc_endpoint
*endpoint2
,
435 * Data Path Buffer Pool (DPBP) API
439 #define DPBP_VER_MAJOR 3
440 #define DPBP_VER_MINOR 2
442 /* Command versioning */
443 #define DPBP_CMD_BASE_VERSION 1
444 #define DPBP_CMD_ID_OFFSET 4
446 #define DPBP_CMD(id) (((id) << DPBP_CMD_ID_OFFSET) | DPBP_CMD_BASE_VERSION)
449 #define DPBP_CMDID_CLOSE DPBP_CMD(0x800)
450 #define DPBP_CMDID_OPEN DPBP_CMD(0x804)
452 #define DPBP_CMDID_ENABLE DPBP_CMD(0x002)
453 #define DPBP_CMDID_DISABLE DPBP_CMD(0x003)
454 #define DPBP_CMDID_GET_ATTR DPBP_CMD(0x004)
455 #define DPBP_CMDID_RESET DPBP_CMD(0x005)
457 struct dpbp_cmd_open
{
461 #define DPBP_ENABLE 0x1
463 struct dpbp_rsp_get_attributes
{
464 /* response word 0 */
468 /* response word 1 */
469 __le16 version_major
;
470 __le16 version_minor
;
474 * Data Path Concentrator (DPCON) API
478 #define DPCON_VER_MAJOR 3
479 #define DPCON_VER_MINOR 2
481 /* Command versioning */
482 #define DPCON_CMD_BASE_VERSION 1
483 #define DPCON_CMD_ID_OFFSET 4
485 #define DPCON_CMD(id) (((id) << DPCON_CMD_ID_OFFSET) | DPCON_CMD_BASE_VERSION)
488 #define DPCON_CMDID_CLOSE DPCON_CMD(0x800)
489 #define DPCON_CMDID_OPEN DPCON_CMD(0x808)
491 #define DPCON_CMDID_ENABLE DPCON_CMD(0x002)
492 #define DPCON_CMDID_DISABLE DPCON_CMD(0x003)
493 #define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004)
494 #define DPCON_CMDID_RESET DPCON_CMD(0x005)
496 #define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100)
498 struct dpcon_cmd_open
{
502 #define DPCON_ENABLE 1
504 struct dpcon_rsp_get_attr
{
505 /* response word 0 */
512 struct dpcon_cmd_set_notification
{
522 * Maximum number of total IRQs that can be pre-allocated for an MC bus'
525 #define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256
528 * struct fsl_mc_resource_pool - Pool of MC resources of a given
530 * @type: type of resources in the pool
531 * @max_count: maximum number of resources in the pool
532 * @free_count: number of free resources in the pool
533 * @mutex: mutex to serialize access to the pool's free list
534 * @free_list: anchor node of list of free resources in the pool
535 * @mc_bus: pointer to the MC bus that owns this resource pool
537 struct fsl_mc_resource_pool
{
538 enum fsl_mc_pool_type type
;
541 struct mutex mutex
; /* serializes access to free_list */
542 struct list_head free_list
;
543 struct fsl_mc_bus
*mc_bus
;
547 * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC
548 * @mc_dev: fsl-mc device for the bus device itself.
549 * @resource_pools: array of resource pools (one pool per resource type)
550 * for this MC bus. These resources represent allocatable entities
551 * from the physical DPRC.
552 * @irq_resources: Pointer to array of IRQ objects for the IRQ pool
553 * @scan_mutex: Serializes bus scanning
554 * @dprc_attr: DPRC attributes
557 struct fsl_mc_device mc_dev
;
558 struct fsl_mc_resource_pool resource_pools
[FSL_MC_NUM_POOL_TYPES
];
559 struct fsl_mc_device_irq
*irq_resources
;
560 struct mutex scan_mutex
; /* serializes bus scanning */
561 struct dprc_attributes dprc_attr
;
564 #define to_fsl_mc_bus(_mc_dev) \
565 container_of(_mc_dev, struct fsl_mc_bus, mc_dev)
567 int __must_check
fsl_mc_device_add(struct fsl_mc_obj_desc
*obj_desc
,
568 struct fsl_mc_io
*mc_io
,
569 struct device
*parent_dev
,
570 struct fsl_mc_device
**new_mc_dev
);
572 void fsl_mc_device_remove(struct fsl_mc_device
*mc_dev
);
574 int __init
dprc_driver_init(void);
576 void dprc_driver_exit(void);
578 int __init
fsl_mc_allocator_driver_init(void);
580 void fsl_mc_allocator_driver_exit(void);
582 void fsl_mc_init_all_resource_pools(struct fsl_mc_device
*mc_bus_dev
);
584 void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device
*mc_bus_dev
);
586 int __must_check
fsl_mc_resource_allocate(struct fsl_mc_bus
*mc_bus
,
587 enum fsl_mc_pool_type pool_type
,
588 struct fsl_mc_resource
591 void fsl_mc_resource_free(struct fsl_mc_resource
*resource
);
593 int fsl_mc_msi_domain_alloc_irqs(struct device
*dev
,
594 unsigned int irq_count
);
596 void fsl_mc_msi_domain_free_irqs(struct device
*dev
);
598 int fsl_mc_find_msi_domain(struct device
*mc_platform_dev
,
599 struct irq_domain
**mc_msi_domain
);
601 int fsl_mc_populate_irq_pool(struct fsl_mc_bus
*mc_bus
,
602 unsigned int irq_count
);
604 void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus
*mc_bus
);
606 int __must_check
fsl_create_mc_io(struct device
*dev
,
607 phys_addr_t mc_portal_phys_addr
,
609 struct fsl_mc_device
*dpmcp_dev
,
610 u32 flags
, struct fsl_mc_io
**new_mc_io
);
612 void fsl_destroy_mc_io(struct fsl_mc_io
*mc_io
);
614 bool fsl_mc_is_root_dprc(struct device
*dev
);
616 struct fsl_mc_device
*fsl_mc_device_lookup(struct fsl_mc_obj_desc
*obj_desc
,
617 struct fsl_mc_device
*mc_bus_dev
);
619 #endif /* _FSL_MC_PRIVATE_H_ */