| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. |
|---|
| 3 | 4 | * Copyright (C) 2017 Linaro Ltd. |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License version 2 and |
|---|
| 7 | | - * only version 2 as published by the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | | - * GNU General Public License for more details. |
|---|
| 13 | | - * |
|---|
| 14 | 5 | */ |
|---|
| 15 | 6 | |
|---|
| 16 | 7 | #include <linux/delay.h> |
|---|
| .. | .. |
|---|
| 19 | 10 | #include <linux/interrupt.h> |
|---|
| 20 | 11 | #include <linux/iopoll.h> |
|---|
| 21 | 12 | #include <linux/kernel.h> |
|---|
| 22 | | -#include <linux/qcom_scm.h> |
|---|
| 23 | 13 | #include <linux/slab.h> |
|---|
| 24 | 14 | |
|---|
| 25 | 15 | #include "core.h" |
|---|
| .. | .. |
|---|
| 27 | 17 | #include "hfi_msgs.h" |
|---|
| 28 | 18 | #include "hfi_venus.h" |
|---|
| 29 | 19 | #include "hfi_venus_io.h" |
|---|
| 20 | +#include "firmware.h" |
|---|
| 30 | 21 | |
|---|
| 31 | 22 | #define HFI_MASK_QHDR_TX_TYPE 0xff000000 |
|---|
| 32 | 23 | #define HFI_MASK_QHDR_RX_TYPE 0x00ff0000 |
|---|
| .. | .. |
|---|
| 54 | 45 | #define IFACEQ_VAR_SMALL_PKT_SIZE 100 |
|---|
| 55 | 46 | #define IFACEQ_VAR_LARGE_PKT_SIZE 512 |
|---|
| 56 | 47 | #define IFACEQ_VAR_HUGE_PKT_SIZE (1024 * 12) |
|---|
| 57 | | - |
|---|
| 58 | | -enum tzbsp_video_state { |
|---|
| 59 | | - TZBSP_VIDEO_STATE_SUSPEND = 0, |
|---|
| 60 | | - TZBSP_VIDEO_STATE_RESUME |
|---|
| 61 | | -}; |
|---|
| 62 | 48 | |
|---|
| 63 | 49 | struct hfi_queue_table_header { |
|---|
| 64 | 50 | u32 version; |
|---|
| .. | .. |
|---|
| 144 | 130 | }; |
|---|
| 145 | 131 | |
|---|
| 146 | 132 | static bool venus_pkt_debug; |
|---|
| 147 | | -static int venus_fw_debug = HFI_DEBUG_MSG_ERROR | HFI_DEBUG_MSG_FATAL; |
|---|
| 133 | +int venus_fw_debug = HFI_DEBUG_MSG_ERROR | HFI_DEBUG_MSG_FATAL; |
|---|
| 148 | 134 | static bool venus_sys_idle_indicator; |
|---|
| 149 | 135 | static bool venus_fw_low_power_mode = true; |
|---|
| 150 | 136 | static int venus_hw_rsp_timeout = 1000; |
|---|
| .. | .. |
|---|
| 491 | 477 | minor = minor >> WRAPPER_HW_VERSION_MINOR_VERSION_SHIFT; |
|---|
| 492 | 478 | step = ver & WRAPPER_HW_VERSION_STEP_VERSION_MASK; |
|---|
| 493 | 479 | |
|---|
| 494 | | - dev_dbg(dev, "venus hw version %x.%x.%x\n", major, minor, step); |
|---|
| 480 | + dev_dbg(dev, VDBGL "venus hw version %x.%x.%x\n", major, minor, step); |
|---|
| 495 | 481 | |
|---|
| 496 | 482 | return major; |
|---|
| 497 | 483 | } |
|---|
| .. | .. |
|---|
| 575 | 561 | if (!hdev->power_enabled) |
|---|
| 576 | 562 | return 0; |
|---|
| 577 | 563 | |
|---|
| 578 | | - ret = qcom_scm_set_remote_state(TZBSP_VIDEO_STATE_SUSPEND, 0); |
|---|
| 564 | + ret = venus_set_hw_state_suspend(hdev->core); |
|---|
| 579 | 565 | if (ret) |
|---|
| 580 | 566 | return ret; |
|---|
| 581 | 567 | |
|---|
| .. | .. |
|---|
| 595 | 581 | if (hdev->power_enabled) |
|---|
| 596 | 582 | return 0; |
|---|
| 597 | 583 | |
|---|
| 598 | | - ret = qcom_scm_set_remote_state(TZBSP_VIDEO_STATE_RESUME, 0); |
|---|
| 584 | + ret = venus_set_hw_state_resume(hdev->core); |
|---|
| 599 | 585 | if (ret) |
|---|
| 600 | 586 | goto err; |
|---|
| 601 | 587 | |
|---|
| .. | .. |
|---|
| 608 | 594 | return 0; |
|---|
| 609 | 595 | |
|---|
| 610 | 596 | err_suspend: |
|---|
| 611 | | - qcom_scm_set_remote_state(TZBSP_VIDEO_STATE_SUSPEND, 0); |
|---|
| 597 | + venus_set_hw_state_suspend(hdev->core); |
|---|
| 612 | 598 | err: |
|---|
| 613 | 599 | hdev->power_enabled = false; |
|---|
| 614 | 600 | return ret; |
|---|
| .. | .. |
|---|
| 920 | 906 | if (pkt->hdr.pkt_type != HFI_MSG_SYS_COV) { |
|---|
| 921 | 907 | struct hfi_msg_sys_debug_pkt *pkt = packet; |
|---|
| 922 | 908 | |
|---|
| 923 | | - dev_dbg(dev, "%s", pkt->msg_data); |
|---|
| 909 | + dev_dbg(dev, VDBGFW "%s", pkt->msg_data); |
|---|
| 924 | 910 | } |
|---|
| 925 | 911 | } |
|---|
| 926 | 912 | } |
|---|
| .. | .. |
|---|
| 1000 | 986 | |
|---|
| 1001 | 987 | venus_set_state(hdev, VENUS_STATE_DEINIT); |
|---|
| 1002 | 988 | |
|---|
| 1003 | | - /* |
|---|
| 1004 | | - * Once SYS_ERROR received from HW, it is safe to halt the AXI. |
|---|
| 1005 | | - * With SYS_ERROR, Venus FW may have crashed and HW might be |
|---|
| 1006 | | - * active and causing unnecessary transactions. Hence it is |
|---|
| 1007 | | - * safe to stop all AXI transactions from venus subsystem. |
|---|
| 1008 | | - */ |
|---|
| 1009 | | - venus_halt_axi(hdev); |
|---|
| 1010 | 989 | venus_sfr_print(hdev); |
|---|
| 1011 | 990 | } |
|---|
| 1012 | 991 | |
|---|
| .. | .. |
|---|
| 1023 | 1002 | res = hdev->core->res; |
|---|
| 1024 | 1003 | pkt = hdev->pkt_buf; |
|---|
| 1025 | 1004 | |
|---|
| 1026 | | - if (hdev->irq_status & WRAPPER_INTR_STATUS_A2HWD_MASK) { |
|---|
| 1027 | | - venus_sfr_print(hdev); |
|---|
| 1028 | | - hfi_process_watchdog_timeout(core); |
|---|
| 1029 | | - } |
|---|
| 1030 | 1005 | |
|---|
| 1031 | 1006 | while (!venus_iface_msgq_read(hdev, pkt)) { |
|---|
| 1032 | 1007 | msg_ret = hfi_process_msg_packet(core, pkt); |
|---|
| .. | .. |
|---|
| 1146 | 1121 | struct venus_hfi_device *hdev = to_hfi_priv(inst->core); |
|---|
| 1147 | 1122 | struct hfi_session_init_pkt pkt; |
|---|
| 1148 | 1123 | int ret; |
|---|
| 1124 | + |
|---|
| 1125 | + ret = venus_sys_set_debug(hdev, venus_fw_debug); |
|---|
| 1126 | + if (ret) |
|---|
| 1127 | + goto err; |
|---|
| 1149 | 1128 | |
|---|
| 1150 | 1129 | ret = pkt_session_init(&pkt, inst, session_type, codec); |
|---|
| 1151 | 1130 | if (ret) |
|---|
| .. | .. |
|---|
| 1355 | 1334 | pkt = (struct hfi_session_set_property_pkt *)packet; |
|---|
| 1356 | 1335 | |
|---|
| 1357 | 1336 | ret = pkt_session_set_property(pkt, inst, ptype, pdata); |
|---|
| 1337 | + if (ret == -ENOTSUPP) |
|---|
| 1338 | + return 0; |
|---|
| 1358 | 1339 | if (ret) |
|---|
| 1359 | 1340 | return ret; |
|---|
| 1360 | 1341 | |
|---|
| .. | .. |
|---|
| 1626 | 1607 | core->ops = NULL; |
|---|
| 1627 | 1608 | return ret; |
|---|
| 1628 | 1609 | } |
|---|
| 1610 | + |
|---|
| 1611 | +void venus_hfi_queues_reinit(struct venus_core *core) |
|---|
| 1612 | +{ |
|---|
| 1613 | + struct venus_hfi_device *hdev = to_hfi_priv(core); |
|---|
| 1614 | + struct hfi_queue_table_header *tbl_hdr; |
|---|
| 1615 | + struct iface_queue *queue; |
|---|
| 1616 | + struct hfi_sfr *sfr; |
|---|
| 1617 | + unsigned int i; |
|---|
| 1618 | + |
|---|
| 1619 | + mutex_lock(&hdev->lock); |
|---|
| 1620 | + |
|---|
| 1621 | + for (i = 0; i < IFACEQ_NUM; i++) { |
|---|
| 1622 | + queue = &hdev->queues[i]; |
|---|
| 1623 | + queue->qhdr = |
|---|
| 1624 | + IFACEQ_GET_QHDR_START_ADDR(hdev->ifaceq_table.kva, i); |
|---|
| 1625 | + |
|---|
| 1626 | + venus_set_qhdr_defaults(queue->qhdr); |
|---|
| 1627 | + |
|---|
| 1628 | + queue->qhdr->start_addr = queue->qmem.da; |
|---|
| 1629 | + |
|---|
| 1630 | + if (i == IFACEQ_CMD_IDX) |
|---|
| 1631 | + queue->qhdr->type |= HFI_HOST_TO_CTRL_CMD_Q; |
|---|
| 1632 | + else if (i == IFACEQ_MSG_IDX) |
|---|
| 1633 | + queue->qhdr->type |= HFI_CTRL_TO_HOST_MSG_Q; |
|---|
| 1634 | + else if (i == IFACEQ_DBG_IDX) |
|---|
| 1635 | + queue->qhdr->type |= HFI_CTRL_TO_HOST_DBG_Q; |
|---|
| 1636 | + } |
|---|
| 1637 | + |
|---|
| 1638 | + tbl_hdr = hdev->ifaceq_table.kva; |
|---|
| 1639 | + tbl_hdr->version = 0; |
|---|
| 1640 | + tbl_hdr->size = IFACEQ_TABLE_SIZE; |
|---|
| 1641 | + tbl_hdr->qhdr0_offset = sizeof(struct hfi_queue_table_header); |
|---|
| 1642 | + tbl_hdr->qhdr_size = sizeof(struct hfi_queue_header); |
|---|
| 1643 | + tbl_hdr->num_q = IFACEQ_NUM; |
|---|
| 1644 | + tbl_hdr->num_active_q = IFACEQ_NUM; |
|---|
| 1645 | + |
|---|
| 1646 | + /* |
|---|
| 1647 | + * Set receive request to zero on debug queue as there is no |
|---|
| 1648 | + * need of interrupt from video hardware for debug messages |
|---|
| 1649 | + */ |
|---|
| 1650 | + queue = &hdev->queues[IFACEQ_DBG_IDX]; |
|---|
| 1651 | + queue->qhdr->rx_req = 0; |
|---|
| 1652 | + |
|---|
| 1653 | + sfr = hdev->sfr.kva; |
|---|
| 1654 | + sfr->buf_size = ALIGNED_SFR_SIZE; |
|---|
| 1655 | + |
|---|
| 1656 | + /* ensure table and queue header structs are settled in memory */ |
|---|
| 1657 | + wmb(); |
|---|
| 1658 | + |
|---|
| 1659 | + mutex_unlock(&hdev->lock); |
|---|
| 1660 | +} |
|---|