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_ID_OFFSET 4
84 #define DPRC_CMD(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
86 /* DPRC command IDs */
87 #define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
88 #define DPRC_CMDID_OPEN DPRC_CMD(0x805)
89 #define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
91 #define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
93 #define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
94 #define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
95 #define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
96 #define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
97 #define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
99 #define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
100 #define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
101 #define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
102 #define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
103 #define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
105 struct dprc_cmd_open
{
109 struct dprc_cmd_set_irq
{
120 #define DPRC_ENABLE 0x1
122 struct dprc_cmd_set_irq_enable
{
128 struct dprc_cmd_set_irq_mask
{
133 struct dprc_cmd_get_irq_status
{
138 struct dprc_rsp_get_irq_status
{
142 struct dprc_cmd_clear_irq_status
{
147 struct dprc_rsp_get_attributes
{
148 /* response word 0 */
152 /* response word 1 */
157 struct dprc_rsp_get_obj_count
{
162 struct dprc_cmd_get_obj
{
166 struct dprc_rsp_get_obj
{
167 /* response word 0 */
170 /* response word 1 */
175 /* response word 2 */
176 __le16 version_major
;
177 __le16 version_minor
;
180 /* response word 3-4 */
182 /* response word 5-6 */
186 struct dprc_cmd_get_obj_region
{
198 struct dprc_rsp_get_obj_region
{
199 /* response word 0 */
201 /* response word 1 */
203 /* response word 2 */
207 struct dprc_cmd_set_obj_irq
{
222 * DPRC API for managing and querying DPAA resources
224 int dprc_open(struct fsl_mc_io
*mc_io
,
229 int dprc_close(struct fsl_mc_io
*mc_io
,
233 /* DPRC IRQ events */
235 /* IRQ event - Indicates that a new object added to the container */
236 #define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001
237 /* IRQ event - Indicates that an object was removed from the container */
238 #define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002
240 * IRQ event - Indicates that one of the descendant containers that opened by
241 * this container is destroyed
243 #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
246 * IRQ event - Indicates that on one of the container's opened object is
249 #define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
251 /* Irq event - Indicates that object is created at the container */
252 #define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040
255 * struct dprc_irq_cfg - IRQ configuration
256 * @paddr: Address that must be written to signal a message-based interrupt
257 * @val: Value to write into irq_addr address
258 * @irq_num: A user defined number associated with this IRQ
260 struct dprc_irq_cfg
{
266 int dprc_set_irq(struct fsl_mc_io
*mc_io
,
270 struct dprc_irq_cfg
*irq_cfg
);
272 int dprc_set_irq_enable(struct fsl_mc_io
*mc_io
,
278 int dprc_set_irq_mask(struct fsl_mc_io
*mc_io
,
284 int dprc_get_irq_status(struct fsl_mc_io
*mc_io
,
290 int dprc_clear_irq_status(struct fsl_mc_io
*mc_io
,
297 * struct dprc_attributes - Container attributes
298 * @container_id: Container's ID
299 * @icid: Container's ICID
300 * @portal_id: Container's portal ID
301 * @options: Container's options as set at container's creation
303 struct dprc_attributes
{
310 int dprc_get_attributes(struct fsl_mc_io
*mc_io
,
313 struct dprc_attributes
*attributes
);
315 int dprc_get_obj_count(struct fsl_mc_io
*mc_io
,
320 int dprc_get_obj(struct fsl_mc_io
*mc_io
,
324 struct fsl_mc_obj_desc
*obj_desc
);
326 int dprc_set_obj_irq(struct fsl_mc_io
*mc_io
,
332 struct dprc_irq_cfg
*irq_cfg
);
335 /* Cacheable - Indicates that region should be mapped as cacheable */
336 #define DPRC_REGION_CACHEABLE 0x00000001
339 * enum dprc_region_type - Region type
340 * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
341 * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
343 enum dprc_region_type
{
344 DPRC_REGION_TYPE_MC_PORTAL
,
345 DPRC_REGION_TYPE_QBMAN_PORTAL
349 * struct dprc_region_desc - Mappable region descriptor
350 * @base_offset: Region offset from region's base address.
351 * For DPMCP and DPRC objects, region base is offset from SoC MC portals
352 * base address; For DPIO, region base is offset from SoC QMan portals
354 * @size: Region size (in bytes)
355 * @flags: Region attributes
356 * @type: Portal region type
358 struct dprc_region_desc
{
362 enum dprc_region_type type
;
365 int dprc_get_obj_region(struct fsl_mc_io
*mc_io
,
371 struct dprc_region_desc
*region_desc
);
373 int dprc_get_api_version(struct fsl_mc_io
*mc_io
,
378 int dprc_get_container_id(struct fsl_mc_io
*mc_io
,
383 * Data Path Buffer Pool (DPBP) API
387 #define DPBP_VER_MAJOR 3
388 #define DPBP_VER_MINOR 2
390 /* Command versioning */
391 #define DPBP_CMD_BASE_VERSION 1
392 #define DPBP_CMD_ID_OFFSET 4
394 #define DPBP_CMD(id) (((id) << DPBP_CMD_ID_OFFSET) | DPBP_CMD_BASE_VERSION)
397 #define DPBP_CMDID_CLOSE DPBP_CMD(0x800)
398 #define DPBP_CMDID_OPEN DPBP_CMD(0x804)
400 #define DPBP_CMDID_ENABLE DPBP_CMD(0x002)
401 #define DPBP_CMDID_DISABLE DPBP_CMD(0x003)
402 #define DPBP_CMDID_GET_ATTR DPBP_CMD(0x004)
403 #define DPBP_CMDID_RESET DPBP_CMD(0x005)
405 struct dpbp_cmd_open
{
409 #define DPBP_ENABLE 0x1
411 struct dpbp_rsp_get_attributes
{
412 /* response word 0 */
416 /* response word 1 */
417 __le16 version_major
;
418 __le16 version_minor
;
422 * Data Path Concentrator (DPCON) API
426 #define DPCON_VER_MAJOR 3
427 #define DPCON_VER_MINOR 2
429 /* Command versioning */
430 #define DPCON_CMD_BASE_VERSION 1
431 #define DPCON_CMD_ID_OFFSET 4
433 #define DPCON_CMD(id) (((id) << DPCON_CMD_ID_OFFSET) | DPCON_CMD_BASE_VERSION)
436 #define DPCON_CMDID_CLOSE DPCON_CMD(0x800)
437 #define DPCON_CMDID_OPEN DPCON_CMD(0x808)
439 #define DPCON_CMDID_ENABLE DPCON_CMD(0x002)
440 #define DPCON_CMDID_DISABLE DPCON_CMD(0x003)
441 #define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004)
442 #define DPCON_CMDID_RESET DPCON_CMD(0x005)
444 #define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100)
446 struct dpcon_cmd_open
{
450 #define DPCON_ENABLE 1
452 struct dpcon_rsp_get_attr
{
453 /* response word 0 */
460 struct dpcon_cmd_set_notification
{
470 * Maximum number of total IRQs that can be pre-allocated for an MC bus'
473 #define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256
476 * struct fsl_mc_resource_pool - Pool of MC resources of a given
478 * @type: type of resources in the pool
479 * @max_count: maximum number of resources in the pool
480 * @free_count: number of free resources in the pool
481 * @mutex: mutex to serialize access to the pool's free list
482 * @free_list: anchor node of list of free resources in the pool
483 * @mc_bus: pointer to the MC bus that owns this resource pool
485 struct fsl_mc_resource_pool
{
486 enum fsl_mc_pool_type type
;
489 struct mutex mutex
; /* serializes access to free_list */
490 struct list_head free_list
;
491 struct fsl_mc_bus
*mc_bus
;
495 * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC
496 * @mc_dev: fsl-mc device for the bus device itself.
497 * @resource_pools: array of resource pools (one pool per resource type)
498 * for this MC bus. These resources represent allocatable entities
499 * from the physical DPRC.
500 * @irq_resources: Pointer to array of IRQ objects for the IRQ pool
501 * @scan_mutex: Serializes bus scanning
502 * @dprc_attr: DPRC attributes
505 struct fsl_mc_device mc_dev
;
506 struct fsl_mc_resource_pool resource_pools
[FSL_MC_NUM_POOL_TYPES
];
507 struct fsl_mc_device_irq
*irq_resources
;
508 struct mutex scan_mutex
; /* serializes bus scanning */
509 struct dprc_attributes dprc_attr
;
512 #define to_fsl_mc_bus(_mc_dev) \
513 container_of(_mc_dev, struct fsl_mc_bus, mc_dev)
515 int __must_check
fsl_mc_device_add(struct fsl_mc_obj_desc
*obj_desc
,
516 struct fsl_mc_io
*mc_io
,
517 struct device
*parent_dev
,
518 struct fsl_mc_device
**new_mc_dev
);
520 void fsl_mc_device_remove(struct fsl_mc_device
*mc_dev
);
522 int __init
dprc_driver_init(void);
524 void dprc_driver_exit(void);
526 int __init
fsl_mc_allocator_driver_init(void);
528 void fsl_mc_allocator_driver_exit(void);
530 void fsl_mc_init_all_resource_pools(struct fsl_mc_device
*mc_bus_dev
);
532 void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device
*mc_bus_dev
);
534 int __must_check
fsl_mc_resource_allocate(struct fsl_mc_bus
*mc_bus
,
535 enum fsl_mc_pool_type pool_type
,
536 struct fsl_mc_resource
539 void fsl_mc_resource_free(struct fsl_mc_resource
*resource
);
541 int fsl_mc_msi_domain_alloc_irqs(struct device
*dev
,
542 unsigned int irq_count
);
544 void fsl_mc_msi_domain_free_irqs(struct device
*dev
);
546 int fsl_mc_find_msi_domain(struct device
*mc_platform_dev
,
547 struct irq_domain
**mc_msi_domain
);
549 int fsl_mc_populate_irq_pool(struct fsl_mc_bus
*mc_bus
,
550 unsigned int irq_count
);
552 void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus
*mc_bus
);
554 int __must_check
fsl_create_mc_io(struct device
*dev
,
555 phys_addr_t mc_portal_phys_addr
,
557 struct fsl_mc_device
*dpmcp_dev
,
558 u32 flags
, struct fsl_mc_io
**new_mc_io
);
560 void fsl_destroy_mc_io(struct fsl_mc_io
*mc_io
);
562 bool fsl_mc_is_root_dprc(struct device
*dev
);
564 #endif /* _FSL_MC_PRIVATE_H_ */