Browse Source

NFC: driver: use SMEM to getPeripheralStatus at bootup

Updated getPeripheralStatus call to use SMEM, instead of sending a
secure monitor call to QTEE.

Change-Id: Id2be09aa10f00bf4a2373e4056c0e9533c9f3ac2
Mallikarjun S T 2 năm trước cách đây
mục cha
commit
3b1ddde824
4 tập tin đã thay đổi với 23 bổ sung74 xóa
  1. 0 4
      Kbuild
  2. 21 63
      nfc/common.c
  3. 1 6
      nfc/common.h
  4. 1 1
      nfc/i2c_drv.c

+ 0 - 4
Kbuild

@@ -6,10 +6,6 @@ LINUXINCLUDE    += -I$(NFC_ROOT)/include/uapi/linux/nfc
 
 LINUXINCLUDE   += -include $(NFC_ROOT)/config/gki_nfc_conf.h
 
-LINUXINCLUDE   += -I$(NFC_ROOT)/../../../qcom/opensource/securemsm-kernel/smcinvoke/
-LINUXINCLUDE   += -I$(NFC_ROOT)/../../../qcom/opensource/securemsm-kernel/linux/
-LINUXINCLUDE   += -I$(NFC_ROOT)/../../../qcom/opensource/securemsm-kernel/include/linux/
-
 obj-$(CONFIG_NXP_NFC_I2C) += nxp-nci.o
 
 #source files

+ 21 - 63
nfc/common.c

@@ -18,7 +18,7 @@
  *
  ******************************************************************************/
 /*
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  *
  *****************************************************************************/
 #include <linux/gpio.h>
@@ -26,6 +26,9 @@
 #include <linux/delay.h>
 #include <linux/pinctrl/qcom-pinctrl.h>
 #include "common.h"
+
+#include <linux/soc/qcom/smem.h>
+#define PERISEC_SMEM_ID 651
 bool secure_peripheral_not_found = true;
 
 
@@ -141,9 +144,10 @@ void gpio_set_ven(struct nfc_dev *nfc_dev, int value)
 		}
 		else
 		{
-			/*secure peripheral feature is enabled*/
-			if(!nfc_hw_secure_check())
+			if(!nfc_hw_secure_check_smem()) {
+				/*gpio val is set only if nfc is in non-secure zone*/
 				gpio_set_value(nfc_gpio->ven, value);
+			}
 		}
 		/* hardware dependent delay */
 		usleep_range(NFC_GPIO_SET_WAIT_TIME_US,
@@ -508,71 +512,25 @@ int nfc_post_init(struct nfc_dev *nfc_dev)
 }
 
 /**
- * nfc_hw_secure_check() - Checks the NFC secure zone status
+ * nfc_hw_secure_check_smem() - Checks SMEM to get NFC secure zone status
  *
- * Queries the TZ secure libraries if NFC is in secure zone statue or not.
+ * Reads Variable shared between QTEE & HLOS, if NFC is in secure zone statue or not.
  *
- * Return: 0 if FEATURE_NOT_SUPPORTED or PERIPHERAL_NOT_FOUND or nfc_sec_state = 2(non-secure zone) and
- *  return 1 if nfc_sec_state = 1(secure zone) or error otherwise
+ * Return: false - FEATURE_NOT_SUPPORTED/PERIPHERAL_NOT_FOUND/NON-SECURE
+ *         true - SECURE
  */
 
-bool nfc_hw_secure_check(void)
+bool nfc_hw_secure_check_smem(void)
 {
-	struct Object client_env;
-	struct Object app_object;
-	u32 nfc_uid = HW_NFC_UID;
-	union ObjectArg obj_arg[2] = {{{0, 0}}};
-	int ret;
-	bool retstat = 1;
-	u8 nfc_sec_state = 0;
-	/* get rootObj */
-	ret = get_client_env_object(&client_env);
-	if (ret) {
-		pr_err("Failed to get client_env_object, ret: %d\n", ret);
-		return retstat;
-	}
-
-	ret = IClientEnv_open(client_env, HW_STATE_UID, &app_object);
-	if (ret) {
-		pr_debug("Failed to get app_object, ret: %d\n",  ret);
-		if (ret == FEATURE_NOT_SUPPORTED) {
-			retstat = 0; /* Do not Assert */
-			pr_debug("Secure HW feature not supported\n");
-		}
-		goto exit_release_clientenv;
-	}
+	uint32_t * peripheralStateInfo = NULL;
+	size_t size = 0;
 
-	obj_arg[0].b = (struct ObjectBuf) {&nfc_uid, sizeof(u32)};
-	obj_arg[1].b = (struct ObjectBuf) {&nfc_sec_state, sizeof(u8)};
-	ret = Object_invoke(app_object, HW_OP_GET_STATE, obj_arg,
-			ObjectCounts_pack(1, 1, 0, 0));
-
-	pr_info("TZ ret: %d nfc_sec_state: %d\n", ret, nfc_sec_state);
-	if (ret) {
-		if (ret == PERIPHERAL_NOT_FOUND) {
-			retstat = 0; /* Do not Assert */
-			pr_debug("Secure HW mode is not updated. Peripheral not found\n");
-		}
-		goto exit_release_app_obj;
+	peripheralStateInfo = qcom_smem_get(QCOM_SMEM_HOST_ANY, PERISEC_SMEM_ID, &size);
+	if (peripheralStateInfo) {
+		secure_peripheral_not_found = false;
+		return ((*peripheralStateInfo >> (HW_NFC_UID - 0x500)) & 0x1);
 	}
-
-	secure_peripheral_not_found = false;
-
-	/* Refer peripheral state utilities for different states of NFC peripherals */
-	if (nfc_sec_state == 1) {
-		/*Secure Zone*/
-		retstat = 1;
-	} else {
-		/*Non-Secure Zone*/
-		retstat = 0;
-	}
-
-	exit_release_app_obj:
-		Object_release(app_object);
-	exit_release_clientenv:
-		Object_release(client_env);
-
-	return  retstat;
+	return false;
 }
 
 /**
@@ -662,7 +620,7 @@ long nfc_dev_ioctl(struct file *pfile, unsigned int cmd, unsigned long arg)
 		return -ENODEV;
 	if( nfc_dev->configs.CNSS_NFC_HW_SECURE_ENABLE == true) {
 	    /*Avoiding ioctl call in secure zone*/
-	    if(nfc_dev->secure_zone) {
+	    if(nfc_hw_secure_check_smem()) {
 		    if(cmd!=NFC_SECURE_ZONE) {
 			   pr_debug("nfc_dev_ioctl failed\n");
 			   return -1;
@@ -805,7 +763,7 @@ int nfc_dev_close(struct inode *inode, struct file *filp)
 int validate_nfc_state_nci(struct nfc_dev *nfc_dev)
 {
 	struct platform_gpio *nfc_gpio = &nfc_dev->configs.gpio;
-	if(!nfc_dev->secure_zone) {
+	if(!nfc_hw_secure_check_smem()) {
 		if (!gpio_get_value(nfc_gpio->ven)) {
 			pr_err("%s: ven low - nfcc powered off\n", __func__);
 			return -ENODEV;

+ 1 - 6
nfc/common.h

@@ -33,11 +33,6 @@
 #include "i2c_drv.h"
 #include "ese_cold_reset.h"
 
-/*secure library headers*/
-#include "smcinvoke.h"
-#include "smcinvoke_object.h"
-#include "IClientEnv.h"
-
 /* Max device count for this driver */
 #define DEV_COUNT			1
 /* i2c device class */
@@ -324,5 +319,5 @@ int is_nfc_data_available_for_read(struct nfc_dev *nfc_dev);
 int validate_nfc_state_nci(struct nfc_dev *nfc_dev);
 int nfc_post_init(struct nfc_dev *nfc_dev);
 int nfc_dynamic_protection_ioctl(struct nfc_dev *nfc_dev, unsigned long sec_zone_trans);
-bool nfc_hw_secure_check(void);
+bool nfc_hw_secure_check_smem(void);
 #endif /* _COMMON_H_ */

+ 1 - 1
nfc/i2c_drv.c

@@ -420,7 +420,7 @@ int nfc_i2c_dev_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
 	if( nfc_dev->configs.CNSS_NFC_HW_SECURE_ENABLE == true) {
 	    /*Check NFC Secure Zone status*/
-	    if(!nfc_hw_secure_check()) {
+	    if(!nfc_hw_secure_check_smem()) {
 		   nfc_post_init(nfc_dev);
 		   nfc_dev->secure_zone = false;
 	    }