1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Freescale Management Complex (MC) bus private declarations 4 * 5 * Copyright (C) 2016 Freescale Semiconductor, Inc. 6 * 7 */ 8 #ifndef _FSL_MC_PRIVATE_H_ 9 #define _FSL_MC_PRIVATE_H_ 10 11 #include <linux/fsl/mc.h> 12 #include <linux/mutex.h> 13 14 /* 15 * Data Path Management Complex (DPMNG) General API 16 */ 17 18 /* DPMNG command versioning */ 19 #define DPMNG_CMD_BASE_VERSION 1 20 #define DPMNG_CMD_ID_OFFSET 4 21 22 #define DPMNG_CMD(id) (((id) << DPMNG_CMD_ID_OFFSET) | DPMNG_CMD_BASE_VERSION) 23 24 /* DPMNG command IDs */ 25 #define DPMNG_CMDID_GET_VERSION DPMNG_CMD(0x831) 26 27 struct dpmng_rsp_get_version { 28 __le32 revision; 29 __le32 version_major; 30 __le32 version_minor; 31 }; 32 33 /* 34 * Data Path Management Command Portal (DPMCP) API 35 */ 36 37 /* Minimal supported DPMCP Version */ 38 #define DPMCP_MIN_VER_MAJOR 3 39 #define DPMCP_MIN_VER_MINOR 0 40 41 /* DPMCP command versioning */ 42 #define DPMCP_CMD_BASE_VERSION 1 43 #define DPMCP_CMD_ID_OFFSET 4 44 45 #define DPMCP_CMD(id) (((id) << DPMCP_CMD_ID_OFFSET) | DPMCP_CMD_BASE_VERSION) 46 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) 51 52 struct dpmcp_cmd_open { 53 __le32 dpmcp_id; 54 }; 55 56 /* 57 * Initialization and runtime control APIs for DPMCP 58 */ 59 int dpmcp_open(struct fsl_mc_io *mc_io, 60 u32 cmd_flags, 61 int dpmcp_id, 62 u16 *token); 63 64 int dpmcp_close(struct fsl_mc_io *mc_io, 65 u32 cmd_flags, 66 u16 token); 67 68 int dpmcp_reset(struct fsl_mc_io *mc_io, 69 u32 cmd_flags, 70 u16 token); 71 72 /* 73 * Data Path Resource Container (DPRC) API 74 */ 75 76 /* Minimal supported DPRC Version */ 77 #define DPRC_MIN_VER_MAJOR 6 78 #define DPRC_MIN_VER_MINOR 0 79 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 84 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) 87 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) 92 93 #define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004) 94 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) 100 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) 107 108 struct dprc_cmd_open { 109 __le32 container_id; 110 }; 111 112 struct dprc_cmd_set_irq { 113 /* cmd word 0 */ 114 __le32 irq_val; 115 u8 irq_index; 116 u8 pad[3]; 117 /* cmd word 1 */ 118 __le64 irq_addr; 119 /* cmd word 2 */ 120 __le32 irq_num; 121 }; 122 123 #define DPRC_ENABLE 0x1 124 125 struct dprc_cmd_set_irq_enable { 126 u8 enable; 127 u8 pad[3]; 128 u8 irq_index; 129 }; 130 131 struct dprc_cmd_set_irq_mask { 132 __le32 mask; 133 u8 irq_index; 134 }; 135 136 struct dprc_cmd_get_irq_status { 137 __le32 status; 138 u8 irq_index; 139 }; 140 141 struct dprc_rsp_get_irq_status { 142 __le32 status; 143 }; 144 145 struct dprc_cmd_clear_irq_status { 146 __le32 status; 147 u8 irq_index; 148 }; 149 150 struct dprc_rsp_get_attributes { 151 /* response word 0 */ 152 __le32 container_id; 153 __le16 icid; 154 __le16 pad; 155 /* response word 1 */ 156 __le32 options; 157 __le32 portal_id; 158 }; 159 160 struct dprc_rsp_get_obj_count { 161 __le32 pad; 162 __le32 obj_count; 163 }; 164 165 struct dprc_cmd_get_obj { 166 __le32 obj_index; 167 }; 168 169 struct dprc_rsp_get_obj { 170 /* response word 0 */ 171 __le32 pad0; 172 __le32 id; 173 /* response word 1 */ 174 __le16 vendor; 175 u8 irq_count; 176 u8 region_count; 177 __le32 state; 178 /* response word 2 */ 179 __le16 version_major; 180 __le16 version_minor; 181 __le16 flags; 182 __le16 pad1; 183 /* response word 3-4 */ 184 u8 type[16]; 185 /* response word 5-6 */ 186 u8 label[16]; 187 }; 188 189 struct dprc_cmd_get_obj_region { 190 /* cmd word 0 */ 191 __le32 obj_id; 192 __le16 pad0; 193 u8 region_index; 194 u8 pad1; 195 /* cmd word 1-2 */ 196 __le64 pad2[2]; 197 /* cmd word 3-4 */ 198 u8 obj_type[16]; 199 }; 200 201 struct dprc_rsp_get_obj_region { 202 /* response word 0 */ 203 __le64 pad; 204 /* response word 1 */ 205 __le64 base_offset; 206 /* response word 2 */ 207 __le32 size; 208 __le32 pad2; 209 /* response word 3 */ 210 __le32 flags; 211 __le32 pad3; 212 /* response word 4 */ 213 /* base_addr may be zero if older MC firmware is used */ 214 __le64 base_addr; 215 }; 216 217 struct dprc_cmd_set_obj_irq { 218 /* cmd word 0 */ 219 __le32 irq_val; 220 u8 irq_index; 221 u8 pad[3]; 222 /* cmd word 1 */ 223 __le64 irq_addr; 224 /* cmd word 2 */ 225 __le32 irq_num; 226 __le32 obj_id; 227 /* cmd word 3-4 */ 228 u8 obj_type[16]; 229 }; 230 231 /* 232 * DPRC API for managing and querying DPAA resources 233 */ 234 int dprc_open(struct fsl_mc_io *mc_io, 235 u32 cmd_flags, 236 int container_id, 237 u16 *token); 238 239 int dprc_close(struct fsl_mc_io *mc_io, 240 u32 cmd_flags, 241 u16 token); 242 243 /* DPRC IRQ events */ 244 245 /* IRQ event - Indicates that a new object added to the container */ 246 #define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001 247 /* IRQ event - Indicates that an object was removed from the container */ 248 #define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002 249 /* 250 * IRQ event - Indicates that one of the descendant containers that opened by 251 * this container is destroyed 252 */ 253 #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010 254 255 /* 256 * IRQ event - Indicates that on one of the container's opened object is 257 * destroyed 258 */ 259 #define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020 260 261 /* Irq event - Indicates that object is created at the container */ 262 #define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040 263 264 /** 265 * struct dprc_irq_cfg - IRQ configuration 266 * @paddr: Address that must be written to signal a message-based interrupt 267 * @val: Value to write into irq_addr address 268 * @irq_num: A user defined number associated with this IRQ 269 */ 270 struct dprc_irq_cfg { 271 phys_addr_t paddr; 272 u32 val; 273 int irq_num; 274 }; 275 276 int dprc_set_irq(struct fsl_mc_io *mc_io, 277 u32 cmd_flags, 278 u16 token, 279 u8 irq_index, 280 struct dprc_irq_cfg *irq_cfg); 281 282 int dprc_set_irq_enable(struct fsl_mc_io *mc_io, 283 u32 cmd_flags, 284 u16 token, 285 u8 irq_index, 286 u8 en); 287 288 int dprc_set_irq_mask(struct fsl_mc_io *mc_io, 289 u32 cmd_flags, 290 u16 token, 291 u8 irq_index, 292 u32 mask); 293 294 int dprc_get_irq_status(struct fsl_mc_io *mc_io, 295 u32 cmd_flags, 296 u16 token, 297 u8 irq_index, 298 u32 *status); 299 300 int dprc_clear_irq_status(struct fsl_mc_io *mc_io, 301 u32 cmd_flags, 302 u16 token, 303 u8 irq_index, 304 u32 status); 305 306 /** 307 * struct dprc_attributes - Container attributes 308 * @container_id: Container's ID 309 * @icid: Container's ICID 310 * @portal_id: Container's portal ID 311 * @options: Container's options as set at container's creation 312 */ 313 struct dprc_attributes { 314 int container_id; 315 u16 icid; 316 int portal_id; 317 u64 options; 318 }; 319 320 int dprc_get_attributes(struct fsl_mc_io *mc_io, 321 u32 cmd_flags, 322 u16 token, 323 struct dprc_attributes *attributes); 324 325 int dprc_get_obj_count(struct fsl_mc_io *mc_io, 326 u32 cmd_flags, 327 u16 token, 328 int *obj_count); 329 330 int dprc_get_obj(struct fsl_mc_io *mc_io, 331 u32 cmd_flags, 332 u16 token, 333 int obj_index, 334 struct fsl_mc_obj_desc *obj_desc); 335 336 int dprc_set_obj_irq(struct fsl_mc_io *mc_io, 337 u32 cmd_flags, 338 u16 token, 339 char *obj_type, 340 int obj_id, 341 u8 irq_index, 342 struct dprc_irq_cfg *irq_cfg); 343 344 /* Region flags */ 345 /* Cacheable - Indicates that region should be mapped as cacheable */ 346 #define DPRC_REGION_CACHEABLE 0x00000001 347 #define DPRC_REGION_SHAREABLE 0x00000002 348 349 /** 350 * enum dprc_region_type - Region type 351 * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region 352 * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region 353 */ 354 enum dprc_region_type { 355 DPRC_REGION_TYPE_MC_PORTAL, 356 DPRC_REGION_TYPE_QBMAN_PORTAL, 357 DPRC_REGION_TYPE_QBMAN_MEM_BACKED_PORTAL 358 }; 359 360 /** 361 * struct dprc_region_desc - Mappable region descriptor 362 * @base_offset: Region offset from region's base address. 363 * For DPMCP and DPRC objects, region base is offset from SoC MC portals 364 * base address; For DPIO, region base is offset from SoC QMan portals 365 * base address 366 * @size: Region size (in bytes) 367 * @flags: Region attributes 368 * @type: Portal region type 369 */ 370 struct dprc_region_desc { 371 u32 base_offset; 372 u32 size; 373 u32 flags; 374 enum dprc_region_type type; 375 u64 base_address; 376 }; 377 378 int dprc_get_obj_region(struct fsl_mc_io *mc_io, 379 u32 cmd_flags, 380 u16 token, 381 char *obj_type, 382 int obj_id, 383 u8 region_index, 384 struct dprc_region_desc *region_desc); 385 386 int dprc_get_api_version(struct fsl_mc_io *mc_io, 387 u32 cmd_flags, 388 u16 *major_ver, 389 u16 *minor_ver); 390 391 int dprc_get_container_id(struct fsl_mc_io *mc_io, 392 u32 cmd_flags, 393 int *container_id); 394 395 /* 396 * Data Path Buffer Pool (DPBP) API 397 */ 398 399 /* DPBP Version */ 400 #define DPBP_VER_MAJOR 3 401 #define DPBP_VER_MINOR 2 402 403 /* Command versioning */ 404 #define DPBP_CMD_BASE_VERSION 1 405 #define DPBP_CMD_ID_OFFSET 4 406 407 #define DPBP_CMD(id) (((id) << DPBP_CMD_ID_OFFSET) | DPBP_CMD_BASE_VERSION) 408 409 /* Command IDs */ 410 #define DPBP_CMDID_CLOSE DPBP_CMD(0x800) 411 #define DPBP_CMDID_OPEN DPBP_CMD(0x804) 412 413 #define DPBP_CMDID_ENABLE DPBP_CMD(0x002) 414 #define DPBP_CMDID_DISABLE DPBP_CMD(0x003) 415 #define DPBP_CMDID_GET_ATTR DPBP_CMD(0x004) 416 #define DPBP_CMDID_RESET DPBP_CMD(0x005) 417 418 struct dpbp_cmd_open { 419 __le32 dpbp_id; 420 }; 421 422 #define DPBP_ENABLE 0x1 423 424 struct dpbp_rsp_get_attributes { 425 /* response word 0 */ 426 __le16 pad; 427 __le16 bpid; 428 __le32 id; 429 /* response word 1 */ 430 __le16 version_major; 431 __le16 version_minor; 432 }; 433 434 /* 435 * Data Path Concentrator (DPCON) API 436 */ 437 438 /* DPCON Version */ 439 #define DPCON_VER_MAJOR 3 440 #define DPCON_VER_MINOR 2 441 442 /* Command versioning */ 443 #define DPCON_CMD_BASE_VERSION 1 444 #define DPCON_CMD_ID_OFFSET 4 445 446 #define DPCON_CMD(id) (((id) << DPCON_CMD_ID_OFFSET) | DPCON_CMD_BASE_VERSION) 447 448 /* Command IDs */ 449 #define DPCON_CMDID_CLOSE DPCON_CMD(0x800) 450 #define DPCON_CMDID_OPEN DPCON_CMD(0x808) 451 452 #define DPCON_CMDID_ENABLE DPCON_CMD(0x002) 453 #define DPCON_CMDID_DISABLE DPCON_CMD(0x003) 454 #define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004) 455 #define DPCON_CMDID_RESET DPCON_CMD(0x005) 456 457 #define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100) 458 459 struct dpcon_cmd_open { 460 __le32 dpcon_id; 461 }; 462 463 #define DPCON_ENABLE 1 464 465 struct dpcon_rsp_get_attr { 466 /* response word 0 */ 467 __le32 id; 468 __le16 qbman_ch_id; 469 u8 num_priorities; 470 u8 pad; 471 }; 472 473 struct dpcon_cmd_set_notification { 474 /* cmd word 0 */ 475 __le32 dpio_id; 476 u8 priority; 477 u8 pad[3]; 478 /* cmd word 1 */ 479 __le64 user_ctx; 480 }; 481 482 /** 483 * Maximum number of total IRQs that can be pre-allocated for an MC bus' 484 * IRQ pool 485 */ 486 #define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256 487 488 /** 489 * struct fsl_mc_resource_pool - Pool of MC resources of a given 490 * type 491 * @type: type of resources in the pool 492 * @max_count: maximum number of resources in the pool 493 * @free_count: number of free resources in the pool 494 * @mutex: mutex to serialize access to the pool's free list 495 * @free_list: anchor node of list of free resources in the pool 496 * @mc_bus: pointer to the MC bus that owns this resource pool 497 */ 498 struct fsl_mc_resource_pool { 499 enum fsl_mc_pool_type type; 500 int max_count; 501 int free_count; 502 struct mutex mutex; /* serializes access to free_list */ 503 struct list_head free_list; 504 struct fsl_mc_bus *mc_bus; 505 }; 506 507 /** 508 * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC 509 * @mc_dev: fsl-mc device for the bus device itself. 510 * @resource_pools: array of resource pools (one pool per resource type) 511 * for this MC bus. These resources represent allocatable entities 512 * from the physical DPRC. 513 * @irq_resources: Pointer to array of IRQ objects for the IRQ pool 514 * @scan_mutex: Serializes bus scanning 515 * @dprc_attr: DPRC attributes 516 */ 517 struct fsl_mc_bus { 518 struct fsl_mc_device mc_dev; 519 struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES]; 520 struct fsl_mc_device_irq *irq_resources; 521 struct mutex scan_mutex; /* serializes bus scanning */ 522 struct dprc_attributes dprc_attr; 523 }; 524 525 #define to_fsl_mc_bus(_mc_dev) \ 526 container_of(_mc_dev, struct fsl_mc_bus, mc_dev) 527 528 int __must_check fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc, 529 struct fsl_mc_io *mc_io, 530 struct device *parent_dev, 531 struct fsl_mc_device **new_mc_dev); 532 533 void fsl_mc_device_remove(struct fsl_mc_device *mc_dev); 534 535 int __init dprc_driver_init(void); 536 537 void dprc_driver_exit(void); 538 539 int __init fsl_mc_allocator_driver_init(void); 540 541 void fsl_mc_allocator_driver_exit(void); 542 543 void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev); 544 545 void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev); 546 547 int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, 548 enum fsl_mc_pool_type pool_type, 549 struct fsl_mc_resource 550 **new_resource); 551 552 void fsl_mc_resource_free(struct fsl_mc_resource *resource); 553 554 int fsl_mc_msi_domain_alloc_irqs(struct device *dev, 555 unsigned int irq_count); 556 557 void fsl_mc_msi_domain_free_irqs(struct device *dev); 558 559 int fsl_mc_find_msi_domain(struct device *mc_platform_dev, 560 struct irq_domain **mc_msi_domain); 561 562 int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus, 563 unsigned int irq_count); 564 565 void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus); 566 567 int __must_check fsl_create_mc_io(struct device *dev, 568 phys_addr_t mc_portal_phys_addr, 569 u32 mc_portal_size, 570 struct fsl_mc_device *dpmcp_dev, 571 u32 flags, struct fsl_mc_io **new_mc_io); 572 573 void fsl_destroy_mc_io(struct fsl_mc_io *mc_io); 574 575 bool fsl_mc_is_root_dprc(struct device *dev); 576 577 #endif /* _FSL_MC_PRIVATE_H_ */ 578