tpm_crb: Fix AMD Zen on-chip fTPM detection
Quoted 8 lines · Manuel Lauss
This RFC patch fixes 2 issues which prevent the fTPM device from being initialized by the
tpm_crbdriver:1) use
devm_ioremap()instead ofdevm_ioremap_resource()to fix the following error due to it not allowing overlapping resources:
tpm_crbMSFT0101:00: can't request region for resource [mem 0xdd84f000-0xdd84ffff]tpm_crb: probe of MSFT0101:00 failed with error -16
No, we can't do this, it breaks other situations that rely on request_resource.
We already put a work around for a very similar problem on a different system, do you have commit?
commit b4e2eb0651ac3180a942d378b040c5cc045113ee
Author: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> Date: Tue Feb 21 14:14:24 2017 -0700
tpm crb: Work around BIOS's that report the wrong ACPI region size
Quoted 3 lines
2) The fTPM uses different buffer addresses for command and response, so the
priv->cmd_sizemember never gets initialized. Move this initialization to right after succesfully mapping the cmd buffer.
Yes for this though, can you prepare a seperate patch and include a proper Fixes line refering to aa77ea0e43dc5bb0c1dcc9bad76afaa7faca8cab ?
Jason
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Quoted 28 lines · Manuel Lauss
Quoted 13 lines · Jason Gunthorpe
Quoted 8 lines · Manuel Lauss
This RFC patch fixes 2 issues which prevent the fTPM device from being initialized by the
tpm_crbdriver:1) use
devm_ioremap()instead ofdevm_ioremap_resource()to fix the following error due to it not allowing overlapping resources:
tpm_crbMSFT0101:00: can't request region for resource [mem 0xdd84f000-0xdd84ffff]tpm_crb: probe of MSFT0101:00 failed with error -16No, we can't do this, it breaks other situations that rely on
request_resource.Quoted 9 lines
We already put a work around for a very similar problem on a different system, do you have commit?
commit
b4e2eb0651ac3180a942d378b040c5cc045113eeAuthor: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> Date: Tue Feb 21 14:14:24 2017 -0700tpm crb: Work around BIOS's that report the wrong ACPI region size
Yes, that was actually the third problem I encountered on 4.11.5, but this patch does not fix point 1) above.
Quoted 8 lines
/proc/iomemlooks like this before the probe attempt:
dd759000-dd868fff : ACPI Non-volatile Storage
dd84b000-dd84bfff : MSFT0101:00 dd84f000-dd84ffff : MSFT0101:00I have no idea yet why
devm_request_mem_region()fails here. Is it because the ACPI NVS parent is already marked busy by the previous mapping of b000-bfff?
Hum. I wonder what does
static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
struct acpi_table_tpm2 *buf)
{
ret = acpi_dev_get_resources(device, &resources, crb_check_resource,
&io_res);
return in io_res for this arrangment? I'm guessing it isn't dd759000-dd868fff ?
The issue might be that crb_check_resource/iomem assumes that there is a single contiguous io region, while this device seems to have two of them..
If so then the required patch is to iomap all of the io regsions that crb_check_resource finds, and search all of them in crb_map_res. Currently it only does the first one.
Jason
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Quoted 48 lines · Manuel Lauss
Quoted 46 lines · Jason Gunthorpe
Quoted 28 lines · Manuel Lauss
Quoted 13 lines · Jason Gunthorpe
Quoted 8 lines · Manuel Lauss
This RFC patch fixes 2 issues which prevent the fTPM device from being initialized by the
tpm_crbdriver:1) use
devm_ioremap()instead ofdevm_ioremap_resource()to fix the following error due to it not allowing overlapping resources:
tpm_crbMSFT0101:00: can't request region for resource [mem 0xdd84f000-0xdd84ffff]tpm_crb: probe of MSFT0101:00 failed with error -16No, we can't do this, it breaks other situations that rely on
request_resource.Quoted 9 lines
We already put a work around for a very similar problem on a different system, do you have commit?
commit
b4e2eb0651ac3180a942d378b040c5cc045113eeAuthor: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> Date: Tue Feb 21 14:14:24 2017 -0700tpm crb: Work around BIOS's that report the wrong ACPI region size
Yes, that was actually the third problem I encountered on 4.11.5, but this patch does not fix point 1) above.
Quoted 8 lines
/proc/iomemlooks like this before the probe attempt:
dd759000-dd868fff : ACPI Non-volatile Storage
dd84b000-dd84bfff : MSFT0101:00 dd84f000-dd84ffff : MSFT0101:00I have no idea yet why
devm_request_mem_region()fails here. Is it because the ACPI NVS parent is already marked busy by the previous mapping of b000-bfff?Hum. I wonder what does
static int crb_map_io(struct
acpi_device*device, structcrb_priv*priv,
structacpi_table_tpm2*buf)
{
ret = acpi_dev_get_resources(device, &resources,crb_check_resource,
&io_res);
Quoted 4 lines
Quoted 2 lines
return in
io_resfor this arrangment? I'm guessing it isn't dd759000-dd868fff ?It returns dd84b000-dd84bfff. mapping that fails already.
Erm, okay, that is what guessed.
What do you mean 'mapping that fails already' ? The report you gave above shows the failure is on the other region:
tpm_crb MSFT0101:00: can't request region for resource [mem 0xdd84f000-0xdd84ffff]
Which supports my guess that the problem here is the multiple regions and the fix is to map them all, as I described.
Jason
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Quoted 10 lines · Manuel Lauss
Quoted 4 lines
What do you mean 'mapping that fails already' ? The report you gave above shows the failure is on the other region:
tpm_crbMSFT0101:00: can't request region for resource [mem 0xdd84f000-0xdd84ffff]the address seems to change every boot (it's one of the two MSFT0101 devices) but it's always the first call to
devm_ioremap_resource()intpm_crb.c
line 454 that fails:priv->iobase = devm_ioremap_resource(dev, &io_res);
I have no idea why that would fail, based on your proc file it should not, you need to figure out what is going on..
Jason
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
I'll look into this after it has been properly split.
/Jarkko
Quoted 52 lines · Manuel Lauss
This RFC patch fixes 2 issues which prevent the fTPM device from being initialized by the
tpm_crbdriver:1) use
devm_ioremap()instead ofdevm_ioremap_resource()to fix the following error due to it not allowing overlapping resources:
tpm_crbMSFT0101:00: can't request region for resource [mem 0xdd84f000-0xdd84ffff]tpm_crb: probe of MSFT0101:00 failed with error -162) The fTPM uses different buffer addresses for command and response, so the
priv->cmd_sizemember never gets initialized. Move this initialization to right after succesfully mapping the cmd buffer.With these 2 issues fixed, the AMD Zen fTPM is detected correctly.
---
RFC, should probably be split into 2 parts.drivers/char/tpm/tpm_crb.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/char/tpm/tpm_crb.c +3
-2@@ -400,7 +400,7 @@ static void __iomem *crb_map_res(struct device *dev, struct crb_priv *priv,return (void __iomem *)ERR_PTR (-EINVAL );if (!resource_contains (io_res, &new_res)) -return devm_ioremap_resource (dev, &new_res); +return devm_ioremap (dev, new_res.start,resource_size (&new_res));return priv->iobase + (new_res.start - io_res->start); }@@ -451,7 +451,7 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,return -EINVAL ; } - priv->iobase =devm_ioremap_resource (dev, &io_res); + priv->iobase =devm_ioremap (dev, io_res.start,resource_size (&io_res));if (IS_ERR (priv->iobase))return PTR_ERR (priv->iobase);@@ -494,6 +494,7 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv, ret =PTR_ERR (priv->cmd); goto out; } + priv->cmd_size = cmd_size;memcpy_fromio (&rsp_pa, &priv->regs_t->ctrl_rsp_pa,8 ); rsp_pa =le64_to_cpu (rsp_pa);
drivers/char/tpm/tpm_crb.c static int crb_map_io(struct acpi_device *device, struct crb_priv *priv, · line 521
Quoted 8 lines
drivers/char/tpm/tpm_crb.c +0
-2@@ -515,8 +516,6 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv, goto out; } - priv->cmd_size = cmd_size; - priv->rsp = priv->cmd; out:
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot