Charan Teja Reddy | 35144b0 | 2017-09-05 16:20:46 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/of.h> |
| 16 | #include <soc/qcom/scm.h> |
| 17 | #include <soc/qcom/msm_tz_smmu.h> |
| 18 | |
| 19 | static const char * const device_id_mappings[] = { |
| 20 | [TZ_DEVICE_VIDEO] = "VIDEO", |
| 21 | [TZ_DEVICE_MDSS] = "MDSS", |
| 22 | [TZ_DEVICE_LPASS] = "LPASS", |
| 23 | [TZ_DEVICE_MDSS_BOOT] = "MDSS_BOOT", |
| 24 | [TZ_DEVICE_USB1_HS] = "USB1_HS", |
| 25 | [TZ_DEVICE_OCMEM] = "OCMEM", |
| 26 | [TZ_DEVICE_LPASS_CORE] = "LPASS_CORE", |
| 27 | [TZ_DEVICE_VPU] = "VPU", |
| 28 | [TZ_DEVICE_COPSS_SMMU] = "COPSS_SMMU", |
| 29 | [TZ_DEVICE_USB3_0] = "USB3_0", |
| 30 | [TZ_DEVICE_USB3_1] = "USB3_1", |
| 31 | [TZ_DEVICE_PCIE_0] = "PCIE_0", |
| 32 | [TZ_DEVICE_PCIE_1] = "PCIE_1", |
| 33 | [TZ_DEVICE_BCSS] = "BCSS", |
| 34 | [TZ_DEVICE_VCAP] = "VCAP", |
| 35 | [TZ_DEVICE_PCIE20] = "PCIE20", |
| 36 | [TZ_DEVICE_IPA] = "IPA", |
| 37 | [TZ_DEVICE_APPS] = "APPS", |
| 38 | [TZ_DEVICE_GPU] = "GPU", |
| 39 | [TZ_DEVICE_UFS] = "UFS", |
| 40 | [TZ_DEVICE_ICE] = "ICE", |
| 41 | [TZ_DEVICE_ROT] = "ROT", |
| 42 | [TZ_DEVICE_VFE] = "VFE", |
| 43 | [TZ_DEVICE_ANOC0] = "ANOC0", |
| 44 | [TZ_DEVICE_ANOC1] = "ANOC1", |
| 45 | [TZ_DEVICE_ANOC2] = "ANOC2", |
| 46 | [TZ_DEVICE_CPP] = "CPP", |
| 47 | [TZ_DEVICE_JPEG] = "JPEG", |
| 48 | }; |
| 49 | |
| 50 | #define MAX_DEVICE_ID_NAME_LEN 20 |
| 51 | |
| 52 | #define TZ_SMMU_PREPARE_ATOS_ID 0x21 |
| 53 | #define TZ_SMMU_ATOS_START 1 |
| 54 | #define TZ_SMMU_ATOS_END 0 |
| 55 | |
| 56 | #define SMMU_CHANGE_PAGETABLE_FORMAT 0X01 |
| 57 | |
| 58 | enum tz_smmu_device_id msm_dev_to_device_id(struct device *dev) |
| 59 | { |
| 60 | const char *device_id; |
| 61 | enum tz_smmu_device_id iter; |
| 62 | |
| 63 | if (of_property_read_string(dev->of_node, "qcom,tz-device-id", |
| 64 | &device_id)) { |
| 65 | dev_err(dev, "no qcom,device-id property\n"); |
| 66 | return TZ_DEVICE_MAX; |
| 67 | } |
| 68 | |
| 69 | for (iter = TZ_DEVICE_START; iter < TZ_DEVICE_MAX; iter++) |
| 70 | if (!strcmp(device_id_mappings[iter], device_id)) |
| 71 | return iter; |
| 72 | |
| 73 | return TZ_DEVICE_MAX; |
| 74 | } |
| 75 | |
| 76 | static int __msm_tz_smmu_atos(struct device *dev, int cb_num, int operation) |
| 77 | { |
| 78 | int ret; |
| 79 | struct scm_desc desc = {0}; |
| 80 | enum tz_smmu_device_id devid = msm_dev_to_device_id(dev); |
| 81 | |
| 82 | if (devid == TZ_DEVICE_MAX) |
| 83 | return -ENODEV; |
| 84 | |
| 85 | desc.args[0] = devid; |
| 86 | desc.args[1] = cb_num; |
| 87 | desc.args[2] = operation; |
| 88 | desc.arginfo = SCM_ARGS(3, SCM_VAL, SCM_VAL, SCM_VAL); |
| 89 | |
| 90 | ret = scm_call2(SCM_SIP_FNID(SCM_SVC_MP, TZ_SMMU_PREPARE_ATOS_ID), |
| 91 | &desc); |
| 92 | if (ret) |
| 93 | pr_info("%s: TZ SMMU ATOS %s failed, ret = %d\n", |
| 94 | __func__, |
| 95 | operation == TZ_SMMU_ATOS_START ? "start" : "end", |
| 96 | ret); |
| 97 | return ret; |
| 98 | } |
| 99 | |
| 100 | int msm_tz_smmu_atos_start(struct device *dev, int cb_num) |
| 101 | { |
| 102 | return __msm_tz_smmu_atos(dev, cb_num, TZ_SMMU_ATOS_START); |
| 103 | } |
| 104 | |
| 105 | int msm_tz_smmu_atos_end(struct device *dev, int cb_num) |
| 106 | { |
| 107 | return __msm_tz_smmu_atos(dev, cb_num, TZ_SMMU_ATOS_END); |
| 108 | } |
| 109 | |
| 110 | int msm_tz_set_cb_format(enum tz_smmu_device_id sec_id, int cbndx) |
| 111 | { |
| 112 | struct scm_desc desc = {0}; |
| 113 | int ret = 0; |
| 114 | |
| 115 | desc.args[0] = sec_id; |
| 116 | desc.args[1] = cbndx; |
| 117 | desc.args[2] = 1; /* Enable */ |
| 118 | desc.arginfo = SCM_ARGS(3, SCM_VAL, SCM_VAL, SCM_VAL); |
| 119 | |
| 120 | ret = scm_call2(SCM_SIP_FNID(SCM_SVC_SMMU_PROGRAM, |
| 121 | SMMU_CHANGE_PAGETABLE_FORMAT), &desc); |
| 122 | |
| 123 | if (ret) { |
| 124 | WARN(1, "Format change failed for CB %d with ret %d\n", |
| 125 | cbndx, ret); |
| 126 | return ret; |
| 127 | } |
| 128 | |
| 129 | return 0; |
| 130 | } |