Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: ccp - Support register differences between PSP devices

In preparation for adding a new PSP device ID that uses different register
offsets, add support to the PSP version data for register offset values.
And then update the code to use these new register offset values.

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Gary R Hook <gary.hook@amd.com>
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Tom Lendacky and committed by
Herbert Xu
ad01a984 03af9124

+24 -23
+12 -12
drivers/crypto/ccp/psp-dev.c
··· 62 62 int reg; 63 63 64 64 /* Read the interrupt status: */ 65 - status = ioread32(psp->io_regs + PSP_P2CMSG_INTSTS); 65 + status = ioread32(psp->io_regs + psp->vdata->intsts_reg); 66 66 67 67 /* Check if it is command completion: */ 68 68 if (!(status & PSP_CMD_COMPLETE)) 69 69 goto done; 70 70 71 71 /* Check if it is SEV command completion: */ 72 - reg = ioread32(psp->io_regs + PSP_CMDRESP); 72 + reg = ioread32(psp->io_regs + psp->vdata->cmdresp_reg); 73 73 if (reg & PSP_CMDRESP_RESP) { 74 74 psp->sev_int_rcvd = 1; 75 75 wake_up(&psp->sev_int_queue); ··· 77 77 78 78 done: 79 79 /* Clear the interrupt status by writing the same value we read. */ 80 - iowrite32(status, psp->io_regs + PSP_P2CMSG_INTSTS); 80 + iowrite32(status, psp->io_regs + psp->vdata->intsts_reg); 81 81 82 82 return IRQ_HANDLED; 83 83 } ··· 85 85 static void sev_wait_cmd_ioc(struct psp_device *psp, unsigned int *reg) 86 86 { 87 87 wait_event(psp->sev_int_queue, psp->sev_int_rcvd); 88 - *reg = ioread32(psp->io_regs + PSP_CMDRESP); 88 + *reg = ioread32(psp->io_regs + psp->vdata->cmdresp_reg); 89 89 } 90 90 91 91 static int sev_cmd_buffer_len(int cmd) ··· 143 143 print_hex_dump_debug("(in): ", DUMP_PREFIX_OFFSET, 16, 2, data, 144 144 sev_cmd_buffer_len(cmd), false); 145 145 146 - iowrite32(phys_lsb, psp->io_regs + PSP_CMDBUFF_ADDR_LO); 147 - iowrite32(phys_msb, psp->io_regs + PSP_CMDBUFF_ADDR_HI); 146 + iowrite32(phys_lsb, psp->io_regs + psp->vdata->cmdbuff_addr_lo_reg); 147 + iowrite32(phys_msb, psp->io_regs + psp->vdata->cmdbuff_addr_hi_reg); 148 148 149 149 psp->sev_int_rcvd = 0; 150 150 151 151 reg = cmd; 152 152 reg <<= PSP_CMDRESP_CMD_SHIFT; 153 153 reg |= PSP_CMDRESP_IOC; 154 - iowrite32(reg, psp->io_regs + PSP_CMDRESP); 154 + iowrite32(reg, psp->io_regs + psp->vdata->cmdresp_reg); 155 155 156 156 /* wait for command completion */ 157 157 sev_wait_cmd_ioc(psp, &reg); ··· 789 789 static int sev_init(struct psp_device *psp) 790 790 { 791 791 /* Check if device supports SEV feature */ 792 - if (!(ioread32(psp->io_regs + PSP_FEATURE_REG) & 1)) { 792 + if (!(ioread32(psp->io_regs + psp->vdata->feature_reg) & 1)) { 793 793 dev_dbg(psp->dev, "device does not support SEV\n"); 794 794 return 1; 795 795 } ··· 817 817 goto e_err; 818 818 } 819 819 820 - psp->io_regs = sp->io_map + psp->vdata->offset; 820 + psp->io_regs = sp->io_map; 821 821 822 822 /* Disable and clear interrupts until ready */ 823 - iowrite32(0, psp->io_regs + PSP_P2CMSG_INTEN); 824 - iowrite32(-1, psp->io_regs + PSP_P2CMSG_INTSTS); 823 + iowrite32(0, psp->io_regs + psp->vdata->inten_reg); 824 + iowrite32(-1, psp->io_regs + psp->vdata->intsts_reg); 825 825 826 826 /* Request an irq */ 827 827 ret = sp_request_psp_irq(psp->sp, psp_irq_handler, psp->name, psp); ··· 838 838 sp->set_psp_master_device(sp); 839 839 840 840 /* Enable interrupt */ 841 - iowrite32(-1, psp->io_regs + PSP_P2CMSG_INTEN); 841 + iowrite32(-1, psp->io_regs + psp->vdata->inten_reg); 842 842 843 843 dev_notice(dev, "psp enabled\n"); 844 844
-9
drivers/crypto/ccp/psp-dev.h
··· 30 30 31 31 #include "sp-dev.h" 32 32 33 - #define PSP_C2PMSG(_num) ((_num) << 2) 34 - #define PSP_CMDRESP PSP_C2PMSG(32) 35 - #define PSP_CMDBUFF_ADDR_LO PSP_C2PMSG(56) 36 - #define PSP_CMDBUFF_ADDR_HI PSP_C2PMSG(57) 37 - #define PSP_FEATURE_REG PSP_C2PMSG(63) 38 - 39 33 #define PSP_CMD_COMPLETE BIT(1) 40 - 41 - #define PSP_P2CMSG_INTEN 0x0110 42 - #define PSP_P2CMSG_INTSTS 0x0114 43 34 44 35 #define PSP_CMDRESP_CMD_SHIFT 16 45 36 #define PSP_CMDRESP_IOC BIT(0)
+6 -1
drivers/crypto/ccp/sp-dev.h
··· 44 44 }; 45 45 46 46 struct psp_vdata { 47 - const unsigned int offset; 47 + const unsigned int cmdresp_reg; 48 + const unsigned int cmdbuff_addr_lo_reg; 49 + const unsigned int cmdbuff_addr_hi_reg; 50 + const unsigned int feature_reg; 51 + const unsigned int inten_reg; 52 + const unsigned int intsts_reg; 48 53 }; 49 54 50 55 /* Structure to hold SP device data */
+6 -1
drivers/crypto/ccp/sp-pci.c
··· 270 270 271 271 #ifdef CONFIG_CRYPTO_DEV_SP_PSP 272 272 static const struct psp_vdata psp_entry = { 273 - .offset = 0x10500, 273 + .cmdresp_reg = 0x10580, 274 + .cmdbuff_addr_lo_reg = 0x105e0, 275 + .cmdbuff_addr_hi_reg = 0x105e4, 276 + .feature_reg = 0x105fc, 277 + .inten_reg = 0x10610, 278 + .intsts_reg = 0x10614, 274 279 }; 275 280 #endif 276 281