Skip to content

Commit 51dd43d

Browse files
jgunthorpeJarkko Sakkinen
authored andcommitted
tpm_tis: Use devm_ioremap_resource
This does a request_resource under the covers which means tis holds a lock on the memory range it is using so other drivers cannot grab it. When doing probing it is important to ensure that other drivers are not using the same range before tis starts touching it. To do this flow the actual struct resource from the device right through to devm_ioremap_resource. This ensures all the proper resource meta-data is carried down. Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> Tested-by: Wilck, Martin <martin.wilck@ts.fujitsu.com> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Acked-by: Peter Huewe <peterhuewe@gmx.de>
1 parent 4d627e6 commit 51dd43d

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

drivers/char/tpm/tpm_tis.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ enum tis_defaults {
6666
};
6767

6868
struct tpm_info {
69-
unsigned long start;
70-
unsigned long len;
69+
struct resource res;
7170
/* irq > 0 means: use irq $irq;
7271
* irq = 0 means: autoprobe for an irq;
7372
* irq = -1 means: no irq support
@@ -76,8 +75,11 @@ struct tpm_info {
7675
};
7776

7877
static struct tpm_info tis_default_info = {
79-
.start = TIS_MEM_BASE,
80-
.len = TIS_MEM_LEN,
78+
.res = {
79+
.start = TIS_MEM_BASE,
80+
.end = TIS_MEM_BASE + TIS_MEM_LEN - 1,
81+
.flags = IORESOURCE_MEM,
82+
},
8183
.irq = 0,
8284
};
8385

@@ -691,9 +693,9 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
691693
chip->acpi_dev_handle = acpi_dev_handle;
692694
#endif
693695

694-
chip->vendor.iobase = devm_ioremap(dev, tpm_info->start, tpm_info->len);
695-
if (!chip->vendor.iobase)
696-
return -EIO;
696+
chip->vendor.iobase = devm_ioremap_resource(dev, &tpm_info->res);
697+
if (IS_ERR(chip->vendor.iobase))
698+
return PTR_ERR(chip->vendor.iobase);
697699

698700
/* Maximum timeouts */
699701
chip->vendor.timeout_a = TIS_TIMEOUT_A_MAX;
@@ -874,9 +876,12 @@ static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
874876
{
875877
struct tpm_info tpm_info = {};
876878
acpi_handle acpi_dev_handle = NULL;
879+
struct resource *res;
877880

878-
tpm_info.start = pnp_mem_start(pnp_dev, 0);
879-
tpm_info.len = pnp_mem_len(pnp_dev, 0);
881+
res = pnp_get_resource(pnp_dev, IORESOURCE_MEM, 0);
882+
if (!res)
883+
return -ENODEV;
884+
tpm_info.res = *res;
880885

881886
if (pnp_irq_valid(pnp_dev, 0))
882887
tpm_info.irq = pnp_irq(pnp_dev, 0);
@@ -939,12 +944,10 @@ static int tpm_check_resource(struct acpi_resource *ares, void *data)
939944
struct tpm_info *tpm_info = (struct tpm_info *) data;
940945
struct resource res;
941946

942-
if (acpi_dev_resource_interrupt(ares, 0, &res)) {
947+
if (acpi_dev_resource_interrupt(ares, 0, &res))
943948
tpm_info->irq = res.start;
944-
} else if (acpi_dev_resource_memory(ares, &res)) {
945-
tpm_info->start = res.start;
946-
tpm_info->len = resource_size(&res);
947-
}
949+
else if (acpi_dev_resource_memory(ares, &res))
950+
tpm_info->res = res;
948951

949952
return 1;
950953
}
@@ -977,7 +980,7 @@ static int tpm_tis_acpi_init(struct acpi_device *acpi_dev)
977980

978981
acpi_dev_free_resource_list(&resources);
979982

980-
if (tpm_info.start == 0 && tpm_info.len == 0) {
983+
if (resource_type(&tpm_info.res) != IORESOURCE_MEM) {
981984
dev_err(&acpi_dev->dev,
982985
FW_BUG "TPM2 ACPI table does not define a memory resource\n");
983986
return -EINVAL;

0 commit comments

Comments
 (0)