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 Platform Security Processor (PSP) interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2016,2019 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: Brijesh Singh <brijesh.singh@amd.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/irqreturn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "sp-dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "psp-dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "sev-dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "tee-dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) struct psp_device *psp_master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static struct psp_device *psp_alloc_struct(struct sp_device *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct device *dev = sp->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct psp_device *psp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	psp = devm_kzalloc(dev, sizeof(*psp), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	if (!psp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	psp->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	psp->sp = sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	snprintf(psp->name, sizeof(psp->name), "psp-%u", sp->ord);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	return psp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static irqreturn_t psp_irq_handler(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct psp_device *psp = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	unsigned int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	/* Read the interrupt status: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	status = ioread32(psp->io_regs + psp->vdata->intsts_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	/* invoke subdevice interrupt handlers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		if (psp->sev_irq_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			psp->sev_irq_handler(irq, psp->sev_irq_data, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		if (psp->tee_irq_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			psp->tee_irq_handler(irq, psp->tee_irq_data, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	/* Clear the interrupt status by writing the same value we read. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	iowrite32(status, psp->io_regs + psp->vdata->intsts_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static unsigned int psp_get_capability(struct psp_device *psp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	unsigned int val = ioread32(psp->io_regs + psp->vdata->feature_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	 * Check for a access to the registers.  If this read returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	 * 0xffffffff, it's likely that the system is running a broken
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	 * BIOS which disallows access to the device. Stop here and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	 * fail the PSP initialization (but not the load, as the CCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 * could get properly initialized).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (val == 0xffffffff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		dev_notice(psp->dev, "psp: unable to access the device: you might be running a broken BIOS.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static int psp_check_sev_support(struct psp_device *psp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 				 unsigned int capability)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	/* Check if device supports SEV feature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (!(capability & 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		dev_dbg(psp->dev, "psp does not support SEV\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static int psp_check_tee_support(struct psp_device *psp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 				 unsigned int capability)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	/* Check if device supports TEE feature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (!(capability & 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		dev_dbg(psp->dev, "psp does not support TEE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int psp_check_support(struct psp_device *psp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			     unsigned int capability)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	int sev_support = psp_check_sev_support(psp, capability);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	int tee_support = psp_check_tee_support(psp, capability);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	/* Return error if device neither supports SEV nor TEE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (sev_support && tee_support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static int psp_init(struct psp_device *psp, unsigned int capability)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (!psp_check_sev_support(psp, capability)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		ret = sev_dev_init(psp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (!psp_check_tee_support(psp, capability)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		ret = tee_dev_init(psp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int psp_dev_init(struct sp_device *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct device *dev = sp->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct psp_device *psp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	unsigned int capability;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	psp = psp_alloc_struct(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!psp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		goto e_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	sp->psp_data = psp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	psp->vdata = (struct psp_vdata *)sp->dev_vdata->psp_vdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (!psp->vdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		dev_err(dev, "missing driver data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		goto e_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	psp->io_regs = sp->io_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	capability = psp_get_capability(psp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (!capability)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		goto e_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	ret = psp_check_support(psp, capability);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		goto e_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/* Disable and clear interrupts until ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	iowrite32(0, psp->io_regs + psp->vdata->inten_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	iowrite32(-1, psp->io_regs + psp->vdata->intsts_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	/* Request an irq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	ret = sp_request_psp_irq(psp->sp, psp_irq_handler, psp->name, psp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		dev_err(dev, "psp: unable to allocate an IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		goto e_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	ret = psp_init(psp, capability);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		goto e_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (sp->set_psp_master_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		sp->set_psp_master_device(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	/* Enable interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	iowrite32(-1, psp->io_regs + psp->vdata->inten_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	dev_notice(dev, "psp enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) e_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	sp_free_psp_irq(psp->sp, psp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) e_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	sp->psp_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	dev_notice(dev, "psp initialization failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) e_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	sp->psp_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) void psp_dev_destroy(struct sp_device *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct psp_device *psp = sp->psp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (!psp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	sev_dev_destroy(psp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	tee_dev_destroy(psp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	sp_free_psp_irq(sp, psp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (sp->clear_psp_master_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		sp->clear_psp_master_device(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) void psp_set_sev_irq_handler(struct psp_device *psp, psp_irq_handler_t handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			     void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	psp->sev_irq_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	psp->sev_irq_handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) void psp_clear_sev_irq_handler(struct psp_device *psp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	psp_set_sev_irq_handler(psp, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) void psp_set_tee_irq_handler(struct psp_device *psp, psp_irq_handler_t handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			     void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	psp->tee_irq_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	psp->tee_irq_handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) void psp_clear_tee_irq_handler(struct psp_device *psp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	psp_set_tee_irq_handler(psp, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct psp_device *psp_get_master_device(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	struct sp_device *sp = sp_get_psp_master_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return sp ? sp->psp_data : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) void psp_pci_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	psp_master = psp_get_master_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (!psp_master)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	sev_pci_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) void psp_pci_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (!psp_master)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	sev_pci_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }