sp-pci.c (b582763721828f6c3fcf94d371623127f0198f3f) sp-pci.c (2e424c33d8e748b65b683988f80e711cd6a7f619)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * AMD Secure Processor device driver
4 *
5 * Copyright (C) 2013,2019 Advanced Micro Devices, Inc.
6 *
7 * Author: Tom Lendacky <thomas.lendacky@amd.com>
8 * Author: Gary R Hook <gary.hook@amd.com>
9 */
10
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * AMD Secure Processor device driver
4 *
5 * Copyright (C) 2013,2019 Advanced Micro Devices, Inc.
6 *
7 * Author: Tom Lendacky <thomas.lendacky@amd.com>
8 * Author: Gary R Hook <gary.hook@amd.com>
9 */
10
11#include <linux/bitfield.h>
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/device.h>
14#include <linux/pci.h>
15#include <linux/pci_ids.h>
16#include <linux/dma-mapping.h>
17#include <linux/kthread.h>
18#include <linux/sched.h>
19#include <linux/interrupt.h>
20#include <linux/spinlock.h>
21#include <linux/delay.h>
22#include <linux/ccp.h>
23
24#include "ccp-dev.h"
25#include "psp-dev.h"
26
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/device.h>
15#include <linux/pci.h>
16#include <linux/pci_ids.h>
17#include <linux/dma-mapping.h>
18#include <linux/kthread.h>
19#include <linux/sched.h>
20#include <linux/interrupt.h>
21#include <linux/spinlock.h>
22#include <linux/delay.h>
23#include <linux/ccp.h>
24
25#include "ccp-dev.h"
26#include "psp-dev.h"
27
28/* used for version string AA.BB.CC.DD */
29#define AA GENMASK(31, 24)
30#define BB GENMASK(23, 16)
31#define CC GENMASK(15, 8)
32#define DD GENMASK(7, 0)
33
27#define MSIX_VECTORS 2
28
29struct sp_pci {
30 int msix_count;
31 struct msix_entry msix_entry[MSIX_VECTORS];
32};
33static struct sp_device *sp_dev_master;
34

--- 48 unchanged lines hidden (view full) ---

83 return 0;
84}
85
86static struct attribute_group psp_security_attr_group = {
87 .attrs = psp_security_attrs,
88 .is_visible = psp_security_is_visible,
89};
90
34#define MSIX_VECTORS 2
35
36struct sp_pci {
37 int msix_count;
38 struct msix_entry msix_entry[MSIX_VECTORS];
39};
40static struct sp_device *sp_dev_master;
41

--- 48 unchanged lines hidden (view full) ---

90 return 0;
91}
92
93static struct attribute_group psp_security_attr_group = {
94 .attrs = psp_security_attrs,
95 .is_visible = psp_security_is_visible,
96};
97
98#define version_attribute_show(name, _offset) \
99static ssize_t name##_show(struct device *d, struct device_attribute *attr, \
100 char *buf) \
101{ \
102 struct sp_device *sp = dev_get_drvdata(d); \
103 struct psp_device *psp = sp->psp_data; \
104 unsigned int val = ioread32(psp->io_regs + _offset); \
105 return sysfs_emit(buf, "%02lx.%02lx.%02lx.%02lx\n", \
106 FIELD_GET(AA, val), \
107 FIELD_GET(BB, val), \
108 FIELD_GET(CC, val), \
109 FIELD_GET(DD, val)); \
110}
111
112version_attribute_show(bootloader_version, psp->vdata->bootloader_info_reg)
113static DEVICE_ATTR_RO(bootloader_version);
114version_attribute_show(tee_version, psp->vdata->tee->info_reg)
115static DEVICE_ATTR_RO(tee_version);
116
117static struct attribute *psp_firmware_attrs[] = {
118 &dev_attr_bootloader_version.attr,
119 &dev_attr_tee_version.attr,
120 NULL,
121};
122
123static umode_t psp_firmware_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
124{
125 struct device *dev = kobj_to_dev(kobj);
126 struct sp_device *sp = dev_get_drvdata(dev);
127 struct psp_device *psp = sp->psp_data;
128 unsigned int val = 0xffffffff;
129
130 if (!psp)
131 return 0;
132
133 if (attr == &dev_attr_bootloader_version.attr &&
134 psp->vdata->bootloader_info_reg)
135 val = ioread32(psp->io_regs + psp->vdata->bootloader_info_reg);
136
137 if (attr == &dev_attr_tee_version.attr &&
138 psp->capability & PSP_CAPABILITY_TEE &&
139 psp->vdata->tee->info_reg)
140 val = ioread32(psp->io_regs + psp->vdata->tee->info_reg);
141
142 /* If platform disallows accessing this register it will be all f's */
143 if (val != 0xffffffff)
144 return 0444;
145
146 return 0;
147}
148
149static struct attribute_group psp_firmware_attr_group = {
150 .attrs = psp_firmware_attrs,
151 .is_visible = psp_firmware_is_visible,
152};
153
91static const struct attribute_group *psp_groups[] = {
92 &psp_security_attr_group,
154static const struct attribute_group *psp_groups[] = {
155 &psp_security_attr_group,
156 &psp_firmware_attr_group,
93 NULL,
94};
95
96static int sp_get_msix_irqs(struct sp_device *sp)
97{
98 struct sp_pci *sp_pci = sp->dev_specific;
99 struct device *dev = sp->dev;
100 struct pci_dev *pdev = to_pci_dev(dev);

--- 434 unchanged lines hidden ---
157 NULL,
158};
159
160static int sp_get_msix_irqs(struct sp_device *sp)
161{
162 struct sp_pci *sp_pci = sp->dev_specific;
163 struct device *dev = sp->dev;
164 struct pci_dev *pdev = to_pci_dev(dev);

--- 434 unchanged lines hidden ---