Skip to content

Commit 6c50634

Browse files
tlendackyherbertx
authored andcommitted
crypto: ccp - Add ACPI support
Add support for ACPI to the CCP platform driver. Signed-off-by: Tom Lendacky <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent be03a3a commit 6c50634

File tree

2 files changed

+93
-5
lines changed

2 files changed

+93
-5
lines changed

drivers/crypto/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ config CRYPTO_DEV_ATMEL_SHA
391391

392392
config CRYPTO_DEV_CCP
393393
bool "Support for AMD Cryptographic Coprocessor"
394-
depends on ((X86 && PCI) || ARM64) && HAS_IOMEM
394+
depends on ((X86 && PCI) || (ARM64 && (OF_ADDRESS || ACPI))) && HAS_IOMEM
395395
default n
396396
help
397397
The AMD Cryptographic Coprocessor provides hardware support

drivers/crypto/ccp/ccp-platform.c

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@
2323
#include <linux/delay.h>
2424
#include <linux/ccp.h>
2525
#include <linux/of.h>
26+
#include <linux/of_address.h>
27+
#include <linux/acpi.h>
2628

2729
#include "ccp-dev.h"
2830

31+
struct ccp_platform {
32+
int use_acpi;
33+
int coherent;
34+
};
35+
2936
static int ccp_get_irq(struct ccp_device *ccp)
3037
{
3138
struct device *dev = ccp->dev;
@@ -83,10 +90,64 @@ static struct resource *ccp_find_mmio_area(struct ccp_device *ccp)
8390
return NULL;
8491
}
8592

93+
#ifdef CONFIG_ACPI
94+
static int ccp_acpi_support(struct ccp_device *ccp)
95+
{
96+
struct ccp_platform *ccp_platform = ccp->dev_specific;
97+
struct acpi_device *adev = ACPI_COMPANION(ccp->dev);
98+
acpi_handle handle;
99+
acpi_status status;
100+
unsigned long long data;
101+
int cca;
102+
103+
/* Retrieve the device cache coherency value */
104+
handle = adev->handle;
105+
do {
106+
status = acpi_evaluate_integer(handle, "_CCA", NULL, &data);
107+
if (!ACPI_FAILURE(status)) {
108+
cca = data;
109+
break;
110+
}
111+
} while (!ACPI_FAILURE(status));
112+
113+
if (ACPI_FAILURE(status)) {
114+
dev_err(ccp->dev, "error obtaining acpi coherency value\n");
115+
return -EINVAL;
116+
}
117+
118+
ccp_platform->coherent = !!cca;
119+
120+
return 0;
121+
}
122+
#else /* CONFIG_ACPI */
123+
static int ccp_acpi_support(struct ccp_device *ccp)
124+
{
125+
return -EINVAL;
126+
}
127+
#endif
128+
129+
#ifdef CONFIG_OF
130+
static int ccp_of_support(struct ccp_device *ccp)
131+
{
132+
struct ccp_platform *ccp_platform = ccp->dev_specific;
133+
134+
ccp_platform->coherent = of_dma_is_coherent(ccp->dev->of_node);
135+
136+
return 0;
137+
}
138+
#else
139+
static int ccp_of_support(struct ccp_device *ccp)
140+
{
141+
return -EINVAL;
142+
}
143+
#endif
144+
86145
static int ccp_platform_probe(struct platform_device *pdev)
87146
{
88147
struct ccp_device *ccp;
148+
struct ccp_platform *ccp_platform;
89149
struct device *dev = &pdev->dev;
150+
struct acpi_device *adev = ACPI_COMPANION(dev);
90151
struct resource *ior;
91152
int ret;
92153

@@ -95,10 +156,16 @@ static int ccp_platform_probe(struct platform_device *pdev)
95156
if (!ccp)
96157
goto e_err;
97158

98-
ccp->dev_specific = NULL;
159+
ccp_platform = devm_kzalloc(dev, sizeof(*ccp_platform), GFP_KERNEL);
160+
if (!ccp_platform)
161+
goto e_err;
162+
163+
ccp->dev_specific = ccp_platform;
99164
ccp->get_irq = ccp_get_irqs;
100165
ccp->free_irq = ccp_free_irqs;
101166

167+
ccp_platform->use_acpi = (!adev || acpi_disabled) ? 0 : 1;
168+
102169
ior = ccp_find_mmio_area(ccp);
103170
ccp->io_map = devm_ioremap_resource(dev, ior);
104171
if (IS_ERR(ccp->io_map)) {
@@ -115,7 +182,14 @@ static int ccp_platform_probe(struct platform_device *pdev)
115182
goto e_err;
116183
}
117184

118-
if (of_property_read_bool(dev->of_node, "dma-coherent"))
185+
if (ccp_platform->use_acpi)
186+
ret = ccp_acpi_support(ccp);
187+
else
188+
ret = ccp_of_support(ccp);
189+
if (ret)
190+
goto e_err;
191+
192+
if (ccp_platform->coherent)
119193
ccp->axcache = CACHE_WB_NO_ALLOC;
120194
else
121195
ccp->axcache = CACHE_NONE;
@@ -197,15 +271,29 @@ static int ccp_platform_resume(struct platform_device *pdev)
197271
}
198272
#endif
199273

200-
static const struct of_device_id ccp_platform_ids[] = {
274+
#ifdef CONFIG_ACPI
275+
static const struct acpi_device_id ccp_acpi_match[] = {
276+
{ "AMDI0C00", 0 },
277+
{ },
278+
};
279+
#endif
280+
281+
#ifdef CONFIG_OF
282+
static const struct of_device_id ccp_of_match[] = {
201283
{ .compatible = "amd,ccp-seattle-v1a" },
202284
{ },
203285
};
286+
#endif
204287

205288
static struct platform_driver ccp_platform_driver = {
206289
.driver = {
207290
.name = "AMD Cryptographic Coprocessor",
208-
.of_match_table = ccp_platform_ids,
291+
#ifdef CONFIG_ACPI
292+
.acpi_match_table = ccp_acpi_match,
293+
#endif
294+
#ifdef CONFIG_OF
295+
.of_match_table = ccp_of_match,
296+
#endif
209297
},
210298
.probe = ccp_platform_probe,
211299
.remove = ccp_platform_remove,

0 commit comments

Comments
 (0)