Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * AMD Secure Processor driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2017-2018 Advanced Micro Devices, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author: Tom Lendacky <thomas.lendacky@amd.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Author: Gary R Hook <gary.hook@amd.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Author: Brijesh Singh <brijesh.singh@amd.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/spinlock_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/ccp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "ccp-dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "sp-dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) MODULE_AUTHOR("Tom Lendacky <thomas.lendacky@amd.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) MODULE_AUTHOR("Gary R Hook <gary.hook@amd.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) MODULE_VERSION("1.1.0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) MODULE_DESCRIPTION("AMD Secure Processor driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /* List of SPs, SP count, read-write access lock, and access functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * Lock structure: get sp_unit_lock for reading whenever we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * examine the SP list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static DEFINE_RWLOCK(sp_unit_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static LIST_HEAD(sp_units);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) /* Ever-increasing value to produce unique unit numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static atomic_t sp_ordinal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static void sp_add_device(struct sp_device *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	write_lock_irqsave(&sp_unit_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	list_add_tail(&sp->entry, &sp_units);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	write_unlock_irqrestore(&sp_unit_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static void sp_del_device(struct sp_device *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	write_lock_irqsave(&sp_unit_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	list_del(&sp->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	write_unlock_irqrestore(&sp_unit_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static irqreturn_t sp_irq_handler(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct sp_device *sp = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (sp->ccp_irq_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		sp->ccp_irq_handler(irq, sp->ccp_irq_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (sp->psp_irq_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		sp->psp_irq_handler(irq, sp->psp_irq_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) int sp_request_ccp_irq(struct sp_device *sp, irq_handler_t handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		       const char *name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if ((sp->psp_irq == sp->ccp_irq) && sp->dev_vdata->psp_vdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		/* Need a common routine to manage all interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		sp->ccp_irq_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		sp->ccp_irq_handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		if (!sp->irq_registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			ret = request_irq(sp->ccp_irq, sp_irq_handler, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 					  sp->name, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			sp->irq_registered = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		/* Each sub-device can manage it's own interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		ret = request_irq(sp->ccp_irq, handler, 0, name, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int sp_request_psp_irq(struct sp_device *sp, irq_handler_t handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		       const char *name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if ((sp->psp_irq == sp->ccp_irq) && sp->dev_vdata->ccp_vdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		/* Need a common routine to manage all interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		sp->psp_irq_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		sp->psp_irq_handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		if (!sp->irq_registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			ret = request_irq(sp->psp_irq, sp_irq_handler, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 					  sp->name, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			sp->irq_registered = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		/* Each sub-device can manage it's own interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		ret = request_irq(sp->psp_irq, handler, 0, name, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) void sp_free_ccp_irq(struct sp_device *sp, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if ((sp->psp_irq == sp->ccp_irq) && sp->dev_vdata->psp_vdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		/* Using common routine to manage all interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		if (!sp->psp_irq_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			/* Nothing else using it, so free it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			free_irq(sp->ccp_irq, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			sp->irq_registered = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		sp->ccp_irq_handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		sp->ccp_irq_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		/* Each sub-device can manage it's own interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		free_irq(sp->ccp_irq, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) void sp_free_psp_irq(struct sp_device *sp, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if ((sp->psp_irq == sp->ccp_irq) && sp->dev_vdata->ccp_vdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		/* Using common routine to manage all interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		if (!sp->ccp_irq_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			/* Nothing else using it, so free it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			free_irq(sp->psp_irq, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			sp->irq_registered = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		sp->psp_irq_handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		sp->psp_irq_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		/* Each sub-device can manage it's own interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		free_irq(sp->psp_irq, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  * sp_alloc_struct - allocate and initialize the sp_device struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * @dev: device struct of the SP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct sp_device *sp_alloc_struct(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct sp_device *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	sp = devm_kzalloc(dev, sizeof(*sp), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (!sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	sp->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	sp->ord = atomic_inc_return(&sp_ordinal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	snprintf(sp->name, SP_MAX_NAME_LEN, "sp-%u", sp->ord);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	return sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int sp_init(struct sp_device *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	sp_add_device(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (sp->dev_vdata->ccp_vdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		ccp_dev_init(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (sp->dev_vdata->psp_vdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		psp_dev_init(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) void sp_destroy(struct sp_device *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (sp->dev_vdata->ccp_vdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		ccp_dev_destroy(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (sp->dev_vdata->psp_vdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		psp_dev_destroy(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	sp_del_device(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int sp_suspend(struct sp_device *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (sp->dev_vdata->ccp_vdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		ret = ccp_dev_suspend(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int sp_resume(struct sp_device *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (sp->dev_vdata->ccp_vdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		ret = ccp_dev_resume(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct sp_device *sp_get_psp_master_device(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct sp_device *i, *ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	write_lock_irqsave(&sp_unit_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (list_empty(&sp_units))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	list_for_each_entry(i, &sp_units, entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		if (i->psp_data && i->get_psp_master_device) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			ret = i->get_psp_master_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	write_unlock_irqrestore(&sp_unit_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static int __init sp_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	ret = sp_pci_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #ifdef CONFIG_CRYPTO_DEV_SP_PSP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	psp_pci_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #ifdef CONFIG_ARM64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	ret = sp_platform_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static void __exit sp_mod_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) #ifdef CONFIG_CRYPTO_DEV_SP_PSP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	psp_pci_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	sp_pci_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #ifdef CONFIG_ARM64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	sp_platform_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) module_init(sp_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) module_exit(sp_mod_exit);