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>
13 #include <linux/ioctl.h>
14 #include <linux/miscdevice.h>
17 * Data Path Management Complex (DPMNG) General API
20 /* DPMNG command versioning */
21 #define DPMNG_CMD_BASE_VERSION 1
22 #define DPMNG_CMD_ID_OFFSET 4
24 #define DPMNG_CMD(id) (((id) << DPMNG_CMD_ID_OFFSET) | DPMNG_CMD_BASE_VERSION)
26 /* DPMNG command IDs */
27 #define DPMNG_CMDID_GET_VERSION DPMNG_CMD(0x831)
29 struct dpmng_rsp_get_version {
36 * Data Path Management Command Portal (DPMCP) API
39 /* Minimal supported DPMCP Version */
40 #define DPMCP_MIN_VER_MAJOR 3
41 #define DPMCP_MIN_VER_MINOR 0
43 /* DPMCP command versioning */
44 #define DPMCP_CMD_BASE_VERSION 1
45 #define DPMCP_CMD_ID_OFFSET 4
47 #define DPMCP_CMD(id) (((id) << DPMCP_CMD_ID_OFFSET) | DPMCP_CMD_BASE_VERSION)
49 /* DPMCP command IDs */
50 #define DPMCP_CMDID_CLOSE DPMCP_CMD(0x800)
51 #define DPMCP_CMDID_OPEN DPMCP_CMD(0x80b)
52 #define DPMCP_CMDID_RESET DPMCP_CMD(0x005)
54 struct dpmcp_cmd_open {
59 * Initialization and runtime control APIs for DPMCP
61 int dpmcp_open(struct fsl_mc_io *mc_io,
66 int dpmcp_close(struct fsl_mc_io *mc_io,
70 int dpmcp_reset(struct fsl_mc_io *mc_io,
75 * Data Path Resource Container (DPRC) API
78 /* Minimal supported DPRC Version */
79 #define DPRC_MIN_VER_MAJOR 6
80 #define DPRC_MIN_VER_MINOR 0
82 /* DPRC command versioning */
83 #define DPRC_CMD_BASE_VERSION 1
84 #define DPRC_CMD_2ND_VERSION 2
85 #define DPRC_CMD_3RD_VERSION 3
86 #define DPRC_CMD_ID_OFFSET 4
88 #define DPRC_CMD(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
89 #define DPRC_CMD_V2(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_2ND_VERSION)
90 #define DPRC_CMD_V3(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_3RD_VERSION)
92 /* DPRC command IDs */
93 #define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
94 #define DPRC_CMDID_OPEN DPRC_CMD(0x805)
95 #define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
97 #define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
98 #define DPRC_CMDID_RESET_CONT DPRC_CMD(0x005)
99 #define DPRC_CMDID_RESET_CONT_V2 DPRC_CMD_V2(0x005)
101 #define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
102 #define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
103 #define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
104 #define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
105 #define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
107 #define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
108 #define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
109 #define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
110 #define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
111 #define DPRC_CMDID_GET_OBJ_REG_V2 DPRC_CMD_V2(0x15E)
112 #define DPRC_CMDID_GET_OBJ_REG_V3 DPRC_CMD_V3(0x15E)
113 #define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
115 #define DPRC_CMDID_GET_CONNECTION DPRC_CMD(0x16C)
117 struct dprc_cmd_open {
121 struct dprc_cmd_reset_container {
122 __le32 child_container_id;
126 struct dprc_cmd_set_irq {
137 #define DPRC_ENABLE 0x1
139 struct dprc_cmd_set_irq_enable {
145 struct dprc_cmd_set_irq_mask {
150 struct dprc_cmd_get_irq_status {
155 struct dprc_rsp_get_irq_status {
159 struct dprc_cmd_clear_irq_status {
164 struct dprc_rsp_get_attributes {
165 /* response word 0 */
168 /* response word 1 */
173 struct dprc_rsp_get_obj_count {
178 struct dprc_cmd_get_obj {
182 struct dprc_rsp_get_obj {
183 /* response word 0 */
186 /* response word 1 */
191 /* response word 2 */
192 __le16 version_major;
193 __le16 version_minor;
196 /* response word 3-4 */
198 /* response word 5-6 */
202 struct dprc_cmd_get_obj_region {
214 struct dprc_rsp_get_obj_region {
215 /* response word 0 */
217 /* response word 1 */
219 /* response word 2 */
223 /* response word 3 */
226 /* response word 4 */
227 /* base_addr may be zero if older MC firmware is used */
231 struct dprc_cmd_set_obj_irq {
245 struct dprc_cmd_get_connection {
247 __le16 ep1_interface_id;
252 struct dprc_rsp_get_connection {
255 __le16 ep2_interface_id;
262 * DPRC API for managing and querying DPAA resources
264 int dprc_open(struct fsl_mc_io *mc_io,
269 int dprc_close(struct fsl_mc_io *mc_io,
273 /* DPRC IRQ events */
275 /* IRQ event - Indicates that a new object added to the container */
276 #define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001
277 /* IRQ event - Indicates that an object was removed from the container */
278 #define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002
280 * IRQ event - Indicates that one of the descendant containers that opened by
281 * this container is destroyed
283 #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
286 * IRQ event - Indicates that on one of the container's opened object is
289 #define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
291 /* Irq event - Indicates that object is created at the container */
292 #define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040
295 * struct dprc_irq_cfg - IRQ configuration
296 * @paddr: Address that must be written to signal a message-based interrupt
297 * @val: Value to write into irq_addr address
298 * @irq_num: A user defined number associated with this IRQ
300 struct dprc_irq_cfg {
306 int dprc_set_irq(struct fsl_mc_io *mc_io,
310 struct dprc_irq_cfg *irq_cfg);
312 int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
318 int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
324 int dprc_get_irq_status(struct fsl_mc_io *mc_io,
330 int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
337 * struct dprc_attributes - Container attributes
338 * @container_id: Container's ID
339 * @icid: Container's ICID
340 * @portal_id: Container's portal ID
341 * @options: Container's options as set at container's creation
343 struct dprc_attributes {
350 int dprc_get_attributes(struct fsl_mc_io *mc_io,
353 struct dprc_attributes *attributes);
355 int dprc_get_obj_count(struct fsl_mc_io *mc_io,
360 int dprc_get_obj(struct fsl_mc_io *mc_io,
364 struct fsl_mc_obj_desc *obj_desc);
366 int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
372 struct dprc_irq_cfg *irq_cfg);
374 * enum dprc_region_type - Region type
375 * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
376 * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
378 enum dprc_region_type {
379 DPRC_REGION_TYPE_MC_PORTAL,
380 DPRC_REGION_TYPE_QBMAN_PORTAL,
381 DPRC_REGION_TYPE_QBMAN_MEM_BACKED_PORTAL
385 * struct dprc_region_desc - Mappable region descriptor
386 * @base_offset: Region offset from region's base address.
387 * For DPMCP and DPRC objects, region base is offset from SoC MC portals
388 * base address; For DPIO, region base is offset from SoC QMan portals
390 * @size: Region size (in bytes)
391 * @flags: Region attributes
392 * @type: Portal region type
394 struct dprc_region_desc {
398 enum dprc_region_type type;
402 int dprc_get_obj_region(struct fsl_mc_io *mc_io,
408 struct dprc_region_desc *region_desc);
410 int dprc_get_api_version(struct fsl_mc_io *mc_io,
415 int dprc_get_container_id(struct fsl_mc_io *mc_io,
420 * struct dprc_endpoint - Endpoint description for link connect/disconnect
422 * @type: Endpoint object type: NULL terminated string
423 * @id: Endpoint object ID
424 * @if_id: Interface ID; should be set for endpoints with multiple
425 * interfaces ("dpsw", "dpdmux"); for others, always set to 0
427 struct dprc_endpoint {
433 int dprc_get_connection(struct fsl_mc_io *mc_io,
436 const struct dprc_endpoint *endpoint1,
437 struct dprc_endpoint *endpoint2,
441 * Data Path Buffer Pool (DPBP) API
445 #define DPBP_VER_MAJOR 3
446 #define DPBP_VER_MINOR 2
448 /* Command versioning */
449 #define DPBP_CMD_BASE_VERSION 1
450 #define DPBP_CMD_ID_OFFSET 4
452 #define DPBP_CMD(id) (((id) << DPBP_CMD_ID_OFFSET) | DPBP_CMD_BASE_VERSION)
455 #define DPBP_CMDID_CLOSE DPBP_CMD(0x800)
456 #define DPBP_CMDID_OPEN DPBP_CMD(0x804)
458 #define DPBP_CMDID_ENABLE DPBP_CMD(0x002)
459 #define DPBP_CMDID_DISABLE DPBP_CMD(0x003)
460 #define DPBP_CMDID_GET_ATTR DPBP_CMD(0x004)
461 #define DPBP_CMDID_RESET DPBP_CMD(0x005)
463 struct dpbp_cmd_open {
467 #define DPBP_ENABLE 0x1
469 struct dpbp_rsp_get_attributes {
470 /* response word 0 */
474 /* response word 1 */
475 __le16 version_major;
476 __le16 version_minor;
480 * Data Path Concentrator (DPCON) API
484 #define DPCON_VER_MAJOR 3
485 #define DPCON_VER_MINOR 2
487 /* Command versioning */
488 #define DPCON_CMD_BASE_VERSION 1
489 #define DPCON_CMD_ID_OFFSET 4
491 #define DPCON_CMD(id) (((id) << DPCON_CMD_ID_OFFSET) | DPCON_CMD_BASE_VERSION)
494 #define DPCON_CMDID_CLOSE DPCON_CMD(0x800)
495 #define DPCON_CMDID_OPEN DPCON_CMD(0x808)
497 #define DPCON_CMDID_ENABLE DPCON_CMD(0x002)
498 #define DPCON_CMDID_DISABLE DPCON_CMD(0x003)
499 #define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004)
500 #define DPCON_CMDID_RESET DPCON_CMD(0x005)
502 #define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100)
504 struct dpcon_cmd_open {
508 #define DPCON_ENABLE 1
510 struct dpcon_rsp_get_attr {
511 /* response word 0 */
518 struct dpcon_cmd_set_notification {
529 * struct fsl_mc_resource_pool - Pool of MC resources of a given
531 * @type: type of resources in the pool
532 * @max_count: maximum number of resources in the pool
533 * @free_count: number of free resources in the pool
534 * @mutex: mutex to serialize access to the pool's free list
535 * @free_list: anchor node of list of free resources in the pool
536 * @mc_bus: pointer to the MC bus that owns this resource pool
538 struct fsl_mc_resource_pool {
539 enum fsl_mc_pool_type type;
542 struct mutex mutex; /* serializes access to free_list */
543 struct list_head free_list;
544 struct fsl_mc_bus *mc_bus;
548 * struct fsl_mc_uapi - information associated with a device file
549 * @misc: struct miscdevice linked to the root dprc
550 * @device: newly created device in /dev
551 * @mutex: mutex lock to serialize the open/release operations
552 * @local_instance_in_use: local MC I/O instance in use or not
553 * @static_mc_io: pointer to the static MC I/O object
556 struct miscdevice misc;
557 struct device *device;
558 struct mutex mutex; /* serialize open/release operations */
559 u32 local_instance_in_use;
560 struct fsl_mc_io *static_mc_io;
564 * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC
565 * @mc_dev: fsl-mc device for the bus device itself.
566 * @resource_pools: array of resource pools (one pool per resource type)
567 * for this MC bus. These resources represent allocatable entities
568 * from the physical DPRC.
569 * @irq_resources: Pointer to array of IRQ objects for the IRQ pool
570 * @scan_mutex: Serializes bus scanning
571 * @dprc_attr: DPRC attributes
572 * @uapi_misc: struct that abstracts the interaction with userspace
575 struct fsl_mc_device mc_dev;
576 struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
577 struct fsl_mc_device_irq *irq_resources;
578 struct mutex scan_mutex; /* serializes bus scanning */
579 struct dprc_attributes dprc_attr;
580 struct fsl_mc_uapi uapi_misc;
584 #define to_fsl_mc_bus(_mc_dev) \
585 container_of(_mc_dev, struct fsl_mc_bus, mc_dev)
587 int __must_check fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
588 struct fsl_mc_io *mc_io,
589 struct device *parent_dev,
590 struct fsl_mc_device **new_mc_dev);
592 void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
594 int __init dprc_driver_init(void);
596 void dprc_driver_exit(void);
598 int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
599 bool alloc_interrupts);
601 int __init fsl_mc_allocator_driver_init(void);
603 void fsl_mc_allocator_driver_exit(void);
605 void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
607 void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
609 int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
610 enum fsl_mc_pool_type pool_type,
611 struct fsl_mc_resource
614 void fsl_mc_resource_free(struct fsl_mc_resource *resource);
616 int fsl_mc_msi_domain_alloc_irqs(struct device *dev,
617 unsigned int irq_count);
619 void fsl_mc_msi_domain_free_irqs(struct device *dev);
621 struct irq_domain *fsl_mc_find_msi_domain(struct device *dev);
623 int __must_check fsl_create_mc_io(struct device *dev,
624 phys_addr_t mc_portal_phys_addr,
626 struct fsl_mc_device *dpmcp_dev,
627 u32 flags, struct fsl_mc_io **new_mc_io);
629 void fsl_destroy_mc_io(struct fsl_mc_io *mc_io);
631 bool fsl_mc_is_root_dprc(struct device *dev);
633 void fsl_mc_get_root_dprc(struct device *dev,
634 struct device **root_dprc_dev);
636 struct fsl_mc_device *fsl_mc_device_lookup(struct fsl_mc_obj_desc *obj_desc,
637 struct fsl_mc_device *mc_bus_dev);
639 u16 mc_cmd_hdr_read_cmdid(struct fsl_mc_command *cmd);
641 #ifdef CONFIG_FSL_MC_UAPI_SUPPORT
643 int fsl_mc_uapi_create_device_file(struct fsl_mc_bus *mc_bus);
645 void fsl_mc_uapi_remove_device_file(struct fsl_mc_bus *mc_bus);
649 static inline int fsl_mc_uapi_create_device_file(struct fsl_mc_bus *mc_bus)
654 static inline void fsl_mc_uapi_remove_device_file(struct fsl_mc_bus *mc_bus)
660 int disable_dprc_irq(struct fsl_mc_device *mc_dev);
661 int enable_dprc_irq(struct fsl_mc_device *mc_dev);
662 int get_dprc_irq_state(struct fsl_mc_device *mc_dev);
664 #endif /* _FSL_MC_PRIVATE_H_ */