| .. | .. |
|---|
| 3 | 3 | * Copyright (C) 2014-2018 Etnaviv Project |
|---|
| 4 | 4 | */ |
|---|
| 5 | 5 | |
|---|
| 6 | +#include <drm/drm_drv.h> |
|---|
| 7 | + |
|---|
| 6 | 8 | #include "etnaviv_cmdbuf.h" |
|---|
| 7 | 9 | #include "etnaviv_gpu.h" |
|---|
| 8 | 10 | #include "etnaviv_gem.h" |
|---|
| .. | .. |
|---|
| 10 | 12 | |
|---|
| 11 | 13 | #include "common.xml.h" |
|---|
| 12 | 14 | #include "state.xml.h" |
|---|
| 15 | +#include "state_blt.xml.h" |
|---|
| 13 | 16 | #include "state_hi.xml.h" |
|---|
| 14 | 17 | #include "state_3d.xml.h" |
|---|
| 15 | 18 | #include "cmdstream.xml.h" |
|---|
| .. | .. |
|---|
| 116 | 119 | u32 *ptr = buf->vaddr + off; |
|---|
| 117 | 120 | |
|---|
| 118 | 121 | dev_info(gpu->dev, "virt %p phys 0x%08x free 0x%08x\n", |
|---|
| 119 | | - ptr, etnaviv_cmdbuf_get_va(buf) + off, size - len * 4 - off); |
|---|
| 122 | + ptr, etnaviv_cmdbuf_get_va(buf, |
|---|
| 123 | + &gpu->mmu_context->cmdbuf_mapping) + |
|---|
| 124 | + off, size - len * 4 - off); |
|---|
| 120 | 125 | |
|---|
| 121 | 126 | print_hex_dump(KERN_INFO, "cmd ", DUMP_PREFIX_OFFSET, 16, 4, |
|---|
| 122 | 127 | ptr, len * 4, 0); |
|---|
| .. | .. |
|---|
| 149 | 154 | if (buffer->user_size + cmd_dwords * sizeof(u64) > buffer->size) |
|---|
| 150 | 155 | buffer->user_size = 0; |
|---|
| 151 | 156 | |
|---|
| 152 | | - return etnaviv_cmdbuf_get_va(buffer) + buffer->user_size; |
|---|
| 157 | + return etnaviv_cmdbuf_get_va(buffer, |
|---|
| 158 | + &gpu->mmu_context->cmdbuf_mapping) + |
|---|
| 159 | + buffer->user_size; |
|---|
| 153 | 160 | } |
|---|
| 154 | 161 | |
|---|
| 155 | 162 | u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu) |
|---|
| .. | .. |
|---|
| 162 | 169 | buffer->user_size = 0; |
|---|
| 163 | 170 | |
|---|
| 164 | 171 | CMD_WAIT(buffer); |
|---|
| 165 | | - CMD_LINK(buffer, 2, etnaviv_cmdbuf_get_va(buffer) + |
|---|
| 166 | | - buffer->user_size - 4); |
|---|
| 172 | + CMD_LINK(buffer, 2, |
|---|
| 173 | + etnaviv_cmdbuf_get_va(buffer, &gpu->mmu_context->cmdbuf_mapping) |
|---|
| 174 | + + buffer->user_size - 4); |
|---|
| 167 | 175 | |
|---|
| 168 | 176 | return buffer->user_size / 8; |
|---|
| 169 | 177 | } |
|---|
| .. | .. |
|---|
| 203 | 211 | return buffer->user_size / 8; |
|---|
| 204 | 212 | } |
|---|
| 205 | 213 | |
|---|
| 206 | | -u16 etnaviv_buffer_config_pta(struct etnaviv_gpu *gpu) |
|---|
| 214 | +u16 etnaviv_buffer_config_pta(struct etnaviv_gpu *gpu, unsigned short id) |
|---|
| 207 | 215 | { |
|---|
| 208 | 216 | struct etnaviv_cmdbuf *buffer = &gpu->buffer; |
|---|
| 209 | 217 | |
|---|
| .. | .. |
|---|
| 212 | 220 | buffer->user_size = 0; |
|---|
| 213 | 221 | |
|---|
| 214 | 222 | CMD_LOAD_STATE(buffer, VIVS_MMUv2_PTA_CONFIG, |
|---|
| 215 | | - VIVS_MMUv2_PTA_CONFIG_INDEX(0)); |
|---|
| 223 | + VIVS_MMUv2_PTA_CONFIG_INDEX(id)); |
|---|
| 216 | 224 | |
|---|
| 217 | 225 | CMD_END(buffer); |
|---|
| 218 | 226 | |
|---|
| .. | .. |
|---|
| 226 | 234 | struct etnaviv_cmdbuf *buffer = &gpu->buffer; |
|---|
| 227 | 235 | unsigned int waitlink_offset = buffer->user_size - 16; |
|---|
| 228 | 236 | u32 link_target, flush = 0; |
|---|
| 237 | + bool has_blt = !!(gpu->identity.minor_features5 & |
|---|
| 238 | + chipMinorFeatures5_BLT_ENGINE); |
|---|
| 229 | 239 | |
|---|
| 230 | 240 | lockdep_assert_held(&gpu->lock); |
|---|
| 231 | 241 | |
|---|
| .. | .. |
|---|
| 241 | 251 | if (flush) { |
|---|
| 242 | 252 | unsigned int dwords = 7; |
|---|
| 243 | 253 | |
|---|
| 254 | + if (has_blt) |
|---|
| 255 | + dwords += 10; |
|---|
| 256 | + |
|---|
| 244 | 257 | link_target = etnaviv_buffer_reserve(gpu, buffer, dwords); |
|---|
| 245 | 258 | |
|---|
| 246 | 259 | CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE); |
|---|
| 247 | 260 | CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE); |
|---|
| 261 | + if (has_blt) { |
|---|
| 262 | + CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1); |
|---|
| 263 | + CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT); |
|---|
| 264 | + CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT); |
|---|
| 265 | + CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0); |
|---|
| 266 | + } |
|---|
| 248 | 267 | CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_CACHE, flush); |
|---|
| 249 | | - if (gpu->exec_state == ETNA_PIPE_3D) |
|---|
| 250 | | - CMD_LOAD_STATE(buffer, VIVS_TS_FLUSH_CACHE, |
|---|
| 251 | | - VIVS_TS_FLUSH_CACHE_FLUSH); |
|---|
| 268 | + if (gpu->exec_state == ETNA_PIPE_3D) { |
|---|
| 269 | + if (has_blt) { |
|---|
| 270 | + CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1); |
|---|
| 271 | + CMD_LOAD_STATE(buffer, VIVS_BLT_SET_COMMAND, 0x1); |
|---|
| 272 | + CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0); |
|---|
| 273 | + } else { |
|---|
| 274 | + CMD_LOAD_STATE(buffer, VIVS_TS_FLUSH_CACHE, |
|---|
| 275 | + VIVS_TS_FLUSH_CACHE_FLUSH); |
|---|
| 276 | + } |
|---|
| 277 | + } |
|---|
| 252 | 278 | CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE); |
|---|
| 253 | 279 | CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE); |
|---|
| 280 | + if (has_blt) { |
|---|
| 281 | + CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1); |
|---|
| 282 | + CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT); |
|---|
| 283 | + CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT); |
|---|
| 284 | + CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0); |
|---|
| 285 | + } |
|---|
| 254 | 286 | CMD_END(buffer); |
|---|
| 255 | 287 | |
|---|
| 256 | 288 | etnaviv_buffer_replace_wait(buffer, waitlink_offset, |
|---|
| .. | .. |
|---|
| 289 | 321 | |
|---|
| 290 | 322 | /* Append waitlink */ |
|---|
| 291 | 323 | CMD_WAIT(buffer); |
|---|
| 292 | | - CMD_LINK(buffer, 2, etnaviv_cmdbuf_get_va(buffer) + |
|---|
| 293 | | - buffer->user_size - 4); |
|---|
| 324 | + CMD_LINK(buffer, 2, |
|---|
| 325 | + etnaviv_cmdbuf_get_va(buffer, &gpu->mmu_context->cmdbuf_mapping) |
|---|
| 326 | + + buffer->user_size - 4); |
|---|
| 294 | 327 | |
|---|
| 295 | 328 | /* |
|---|
| 296 | 329 | * Kick off the 'sync point' command by replacing the previous |
|---|
| .. | .. |
|---|
| 304 | 337 | |
|---|
| 305 | 338 | /* Append a command buffer to the ring buffer. */ |
|---|
| 306 | 339 | void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state, |
|---|
| 307 | | - unsigned int event, struct etnaviv_cmdbuf *cmdbuf) |
|---|
| 340 | + struct etnaviv_iommu_context *mmu_context, unsigned int event, |
|---|
| 341 | + struct etnaviv_cmdbuf *cmdbuf) |
|---|
| 308 | 342 | { |
|---|
| 309 | 343 | struct etnaviv_cmdbuf *buffer = &gpu->buffer; |
|---|
| 310 | 344 | unsigned int waitlink_offset = buffer->user_size - 16; |
|---|
| 311 | 345 | u32 return_target, return_dwords; |
|---|
| 312 | 346 | u32 link_target, link_dwords; |
|---|
| 313 | 347 | bool switch_context = gpu->exec_state != exec_state; |
|---|
| 314 | | - unsigned int new_flush_seq = READ_ONCE(gpu->mmu->flush_seq); |
|---|
| 315 | | - bool need_flush = gpu->flush_seq != new_flush_seq; |
|---|
| 348 | + bool switch_mmu_context = gpu->mmu_context != mmu_context; |
|---|
| 349 | + unsigned int new_flush_seq = READ_ONCE(gpu->mmu_context->flush_seq); |
|---|
| 350 | + bool need_flush = switch_mmu_context || gpu->flush_seq != new_flush_seq; |
|---|
| 351 | + bool has_blt = !!(gpu->identity.minor_features5 & |
|---|
| 352 | + chipMinorFeatures5_BLT_ENGINE); |
|---|
| 316 | 353 | |
|---|
| 317 | 354 | lockdep_assert_held(&gpu->lock); |
|---|
| 318 | 355 | |
|---|
| 319 | | - if (drm_debug & DRM_UT_DRIVER) |
|---|
| 356 | + if (drm_debug_enabled(DRM_UT_DRIVER)) |
|---|
| 320 | 357 | etnaviv_buffer_dump(gpu, buffer, 0, 0x50); |
|---|
| 321 | 358 | |
|---|
| 322 | | - link_target = etnaviv_cmdbuf_get_va(cmdbuf); |
|---|
| 359 | + link_target = etnaviv_cmdbuf_get_va(cmdbuf, |
|---|
| 360 | + &gpu->mmu_context->cmdbuf_mapping); |
|---|
| 323 | 361 | link_dwords = cmdbuf->size / 8; |
|---|
| 324 | 362 | |
|---|
| 325 | 363 | /* |
|---|
| 326 | | - * If we need maintanence prior to submitting this buffer, we will |
|---|
| 364 | + * If we need maintenance prior to submitting this buffer, we will |
|---|
| 327 | 365 | * need to append a mmu flush load state, followed by a new |
|---|
| 328 | 366 | * link to this buffer - a total of four additional words. |
|---|
| 329 | 367 | */ |
|---|
| .. | .. |
|---|
| 335 | 373 | |
|---|
| 336 | 374 | /* flush command */ |
|---|
| 337 | 375 | if (need_flush) { |
|---|
| 338 | | - if (gpu->mmu->version == ETNAVIV_IOMMU_V1) |
|---|
| 376 | + if (gpu->mmu_context->global->version == ETNAVIV_IOMMU_V1) |
|---|
| 339 | 377 | extra_dwords += 1; |
|---|
| 340 | 378 | else |
|---|
| 341 | 379 | extra_dwords += 3; |
|---|
| .. | .. |
|---|
| 345 | 383 | if (switch_context) |
|---|
| 346 | 384 | extra_dwords += 4; |
|---|
| 347 | 385 | |
|---|
| 386 | + /* PTA load command */ |
|---|
| 387 | + if (switch_mmu_context && gpu->sec_mode == ETNA_SEC_KERNEL) |
|---|
| 388 | + extra_dwords += 1; |
|---|
| 389 | + |
|---|
| 348 | 390 | target = etnaviv_buffer_reserve(gpu, buffer, extra_dwords); |
|---|
| 391 | + /* |
|---|
| 392 | + * Switch MMU context if necessary. Must be done after the |
|---|
| 393 | + * link target has been calculated, as the jump forward in the |
|---|
| 394 | + * kernel ring still uses the last active MMU context before |
|---|
| 395 | + * the switch. |
|---|
| 396 | + */ |
|---|
| 397 | + if (switch_mmu_context) { |
|---|
| 398 | + struct etnaviv_iommu_context *old_context = gpu->mmu_context; |
|---|
| 399 | + |
|---|
| 400 | + gpu->mmu_context = etnaviv_iommu_context_get(mmu_context); |
|---|
| 401 | + etnaviv_iommu_context_put(old_context); |
|---|
| 402 | + } |
|---|
| 349 | 403 | |
|---|
| 350 | 404 | if (need_flush) { |
|---|
| 351 | 405 | /* Add the MMU flush */ |
|---|
| 352 | | - if (gpu->mmu->version == ETNAVIV_IOMMU_V1) { |
|---|
| 406 | + if (gpu->mmu_context->global->version == ETNAVIV_IOMMU_V1) { |
|---|
| 353 | 407 | CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_MMU, |
|---|
| 354 | 408 | VIVS_GL_FLUSH_MMU_FLUSH_FEMMU | |
|---|
| 355 | 409 | VIVS_GL_FLUSH_MMU_FLUSH_UNK1 | |
|---|
| .. | .. |
|---|
| 357 | 411 | VIVS_GL_FLUSH_MMU_FLUSH_PEMMU | |
|---|
| 358 | 412 | VIVS_GL_FLUSH_MMU_FLUSH_UNK4); |
|---|
| 359 | 413 | } else { |
|---|
| 414 | + u32 flush = VIVS_MMUv2_CONFIGURATION_MODE_MASK | |
|---|
| 415 | + VIVS_MMUv2_CONFIGURATION_FLUSH_FLUSH; |
|---|
| 416 | + |
|---|
| 417 | + if (switch_mmu_context && |
|---|
| 418 | + gpu->sec_mode == ETNA_SEC_KERNEL) { |
|---|
| 419 | + unsigned short id = |
|---|
| 420 | + etnaviv_iommuv2_get_pta_id(gpu->mmu_context); |
|---|
| 421 | + CMD_LOAD_STATE(buffer, |
|---|
| 422 | + VIVS_MMUv2_PTA_CONFIG, |
|---|
| 423 | + VIVS_MMUv2_PTA_CONFIG_INDEX(id)); |
|---|
| 424 | + } |
|---|
| 425 | + |
|---|
| 426 | + if (gpu->sec_mode == ETNA_SEC_NONE) |
|---|
| 427 | + flush |= etnaviv_iommuv2_get_mtlb_addr(gpu->mmu_context); |
|---|
| 428 | + |
|---|
| 360 | 429 | CMD_LOAD_STATE(buffer, VIVS_MMUv2_CONFIGURATION, |
|---|
| 361 | | - VIVS_MMUv2_CONFIGURATION_MODE_MASK | |
|---|
| 362 | | - VIVS_MMUv2_CONFIGURATION_ADDRESS_MASK | |
|---|
| 363 | | - VIVS_MMUv2_CONFIGURATION_FLUSH_FLUSH); |
|---|
| 430 | + flush); |
|---|
| 364 | 431 | CMD_SEM(buffer, SYNC_RECIPIENT_FE, |
|---|
| 365 | 432 | SYNC_RECIPIENT_PE); |
|---|
| 366 | 433 | CMD_STALL(buffer, SYNC_RECIPIENT_FE, |
|---|
| .. | .. |
|---|
| 376 | 443 | } |
|---|
| 377 | 444 | |
|---|
| 378 | 445 | /* And the link to the submitted buffer */ |
|---|
| 446 | + link_target = etnaviv_cmdbuf_get_va(cmdbuf, |
|---|
| 447 | + &gpu->mmu_context->cmdbuf_mapping); |
|---|
| 379 | 448 | CMD_LINK(buffer, link_dwords, link_target); |
|---|
| 380 | 449 | |
|---|
| 381 | 450 | /* Update the link target to point to above instructions */ |
|---|
| .. | .. |
|---|
| 390 | 459 | * 2 semaphore stall + 1 event + 1 wait + 1 link. |
|---|
| 391 | 460 | */ |
|---|
| 392 | 461 | return_dwords = 7; |
|---|
| 462 | + |
|---|
| 463 | + /* |
|---|
| 464 | + * When the BLT engine is present we need 6 more dwords in the return |
|---|
| 465 | + * target: 3 enable/flush/disable + 4 enable/semaphore stall/disable, |
|---|
| 466 | + * but we don't need the normal TS flush state. |
|---|
| 467 | + */ |
|---|
| 468 | + if (has_blt) |
|---|
| 469 | + return_dwords += 6; |
|---|
| 470 | + |
|---|
| 393 | 471 | return_target = etnaviv_buffer_reserve(gpu, buffer, return_dwords); |
|---|
| 394 | 472 | CMD_LINK(cmdbuf, return_dwords, return_target); |
|---|
| 395 | 473 | |
|---|
| .. | .. |
|---|
| 404 | 482 | CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_CACHE, |
|---|
| 405 | 483 | VIVS_GL_FLUSH_CACHE_DEPTH | |
|---|
| 406 | 484 | VIVS_GL_FLUSH_CACHE_COLOR); |
|---|
| 407 | | - CMD_LOAD_STATE(buffer, VIVS_TS_FLUSH_CACHE, |
|---|
| 408 | | - VIVS_TS_FLUSH_CACHE_FLUSH); |
|---|
| 485 | + if (has_blt) { |
|---|
| 486 | + CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1); |
|---|
| 487 | + CMD_LOAD_STATE(buffer, VIVS_BLT_SET_COMMAND, 0x1); |
|---|
| 488 | + CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0); |
|---|
| 489 | + } else { |
|---|
| 490 | + CMD_LOAD_STATE(buffer, VIVS_TS_FLUSH_CACHE, |
|---|
| 491 | + VIVS_TS_FLUSH_CACHE_FLUSH); |
|---|
| 492 | + } |
|---|
| 409 | 493 | } |
|---|
| 410 | 494 | CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE); |
|---|
| 411 | 495 | CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE); |
|---|
| 496 | + |
|---|
| 497 | + if (has_blt) { |
|---|
| 498 | + CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1); |
|---|
| 499 | + CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT); |
|---|
| 500 | + CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT); |
|---|
| 501 | + CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0); |
|---|
| 502 | + } |
|---|
| 503 | + |
|---|
| 412 | 504 | CMD_LOAD_STATE(buffer, VIVS_GL_EVENT, VIVS_GL_EVENT_EVENT_ID(event) | |
|---|
| 413 | 505 | VIVS_GL_EVENT_FROM_PE); |
|---|
| 414 | 506 | CMD_WAIT(buffer); |
|---|
| 415 | | - CMD_LINK(buffer, 2, etnaviv_cmdbuf_get_va(buffer) + |
|---|
| 416 | | - buffer->user_size - 4); |
|---|
| 507 | + CMD_LINK(buffer, 2, |
|---|
| 508 | + etnaviv_cmdbuf_get_va(buffer, &gpu->mmu_context->cmdbuf_mapping) |
|---|
| 509 | + + buffer->user_size - 4); |
|---|
| 417 | 510 | |
|---|
| 418 | | - if (drm_debug & DRM_UT_DRIVER) |
|---|
| 511 | + if (drm_debug_enabled(DRM_UT_DRIVER)) |
|---|
| 419 | 512 | pr_info("stream link to 0x%08x @ 0x%08x %p\n", |
|---|
| 420 | | - return_target, etnaviv_cmdbuf_get_va(cmdbuf), |
|---|
| 513 | + return_target, |
|---|
| 514 | + etnaviv_cmdbuf_get_va(cmdbuf, &gpu->mmu_context->cmdbuf_mapping), |
|---|
| 421 | 515 | cmdbuf->vaddr); |
|---|
| 422 | 516 | |
|---|
| 423 | | - if (drm_debug & DRM_UT_DRIVER) { |
|---|
| 517 | + if (drm_debug_enabled(DRM_UT_DRIVER)) { |
|---|
| 424 | 518 | print_hex_dump(KERN_INFO, "cmd ", DUMP_PREFIX_OFFSET, 16, 4, |
|---|
| 425 | 519 | cmdbuf->vaddr, cmdbuf->size, 0); |
|---|
| 426 | 520 | |
|---|
| .. | .. |
|---|
| 439 | 533 | VIV_FE_LINK_HEADER_PREFETCH(link_dwords), |
|---|
| 440 | 534 | link_target); |
|---|
| 441 | 535 | |
|---|
| 442 | | - if (drm_debug & DRM_UT_DRIVER) |
|---|
| 536 | + if (drm_debug_enabled(DRM_UT_DRIVER)) |
|---|
| 443 | 537 | etnaviv_buffer_dump(gpu, buffer, 0, 0x50); |
|---|
| 444 | | - |
|---|
| 445 | | - gpu->lastctx = cmdbuf->ctx; |
|---|
| 446 | 538 | } |
|---|