Commit ee177984 authored by Jarkko Sakkinen's avatar Jarkko Sakkinen

tpm: drop 'base' from struct tpm_vendor_specific

Dropped the field 'base' from struct tpm_vendor_specific and migrated
it to the private structures of tpm_atmel and tpm_nsc.
Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: default avatarJason Gunthorpe <jgunthorpe@obsidianresearch.com>
parent d4956524
...@@ -132,7 +132,6 @@ struct tpm_chip; ...@@ -132,7 +132,6 @@ struct tpm_chip;
struct tpm_vendor_specific { struct tpm_vendor_specific {
void __iomem *iobase; /* ioremapped address */ void __iomem *iobase; /* ioremapped address */
unsigned long base; /* TPM base address */
int irq; int irq;
......
...@@ -141,8 +141,7 @@ static void atml_plat_remove(void) ...@@ -141,8 +141,7 @@ static void atml_plat_remove(void)
if (chip) { if (chip) {
tpm_chip_unregister(chip); tpm_chip_unregister(chip);
if (priv->have_region) if (priv->have_region)
atmel_release_region(chip->vendor.base, atmel_release_region(priv->base, priv->region_size);
priv->region_size);
atmel_put_base_addr(chip->vendor.iobase); atmel_put_base_addr(chip->vendor.iobase);
platform_device_unregister(pdev); platform_device_unregister(pdev);
} }
...@@ -191,6 +190,7 @@ static int __init init_atmel(void) ...@@ -191,6 +190,7 @@ static int __init init_atmel(void)
goto err_unreg_dev; goto err_unreg_dev;
} }
priv->base = base;
priv->have_region = have_region; priv->have_region = have_region;
priv->region_size = region_size; priv->region_size = region_size;
...@@ -201,7 +201,6 @@ static int __init init_atmel(void) ...@@ -201,7 +201,6 @@ static int __init init_atmel(void)
} }
chip->vendor.iobase = iobase; chip->vendor.iobase = iobase;
chip->vendor.base = base;
chip->vendor.priv = priv; chip->vendor.priv = priv;
rc = tpm_chip_register(chip); rc = tpm_chip_register(chip);
......
...@@ -25,8 +25,14 @@ ...@@ -25,8 +25,14 @@
struct tpm_atmel_priv { struct tpm_atmel_priv {
int region_size; int region_size;
int have_region; int have_region;
unsigned long base;
}; };
static inline struct tpm_atmel_priv *atmel_get_priv(struct tpm_chip *chip)
{
return chip->vendor.priv;
}
#ifdef CONFIG_PPC64 #ifdef CONFIG_PPC64
#include <asm/prom.h> #include <asm/prom.h>
...@@ -83,8 +89,9 @@ static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size) ...@@ -83,8 +89,9 @@ static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
return ioremap(*base, *region_size); return ioremap(*base, *region_size);
} }
#else #else
#define atmel_getb(chip, offset) inb(chip->vendor->base + offset) #define atmel_getb(chip, offset) inb(atmel_get_priv(chip)->base + offset)
#define atmel_putb(val, chip, offset) outb(val, chip->vendor->base + offset) #define atmel_putb(val, chip, offset) \
outb(val, atmel_get_priv(chip)->base + offset)
#define atmel_request_region request_region #define atmel_request_region request_region
#define atmel_release_region release_region #define atmel_release_region release_region
/* Atmel definitions */ /* Atmel definitions */
......
...@@ -64,6 +64,16 @@ enum tpm_nsc_cmd_mode { ...@@ -64,6 +64,16 @@ enum tpm_nsc_cmd_mode {
NSC_COMMAND_EOC = 0x03, NSC_COMMAND_EOC = 0x03,
NSC_COMMAND_CANCEL = 0x22 NSC_COMMAND_CANCEL = 0x22
}; };
struct tpm_nsc_priv {
unsigned long base;
};
static inline struct tpm_nsc_priv *nsc_get_priv(struct tpm_chip *chip)
{
return chip->vendor.priv;
}
/* /*
* Wait for a certain status to appear * Wait for a certain status to appear
*/ */
...@@ -72,7 +82,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data) ...@@ -72,7 +82,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
unsigned long stop; unsigned long stop;
/* status immediately available check */ /* status immediately available check */
*data = inb(chip->vendor.base + NSC_STATUS); *data = inb(nsc_get_priv(chip)->base + NSC_STATUS);
if ((*data & mask) == val) if ((*data & mask) == val)
return 0; return 0;
...@@ -80,7 +90,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data) ...@@ -80,7 +90,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
stop = jiffies + 10 * HZ; stop = jiffies + 10 * HZ;
do { do {
msleep(TPM_TIMEOUT); msleep(TPM_TIMEOUT);
*data = inb(chip->vendor.base + 1); *data = inb(nsc_get_priv(chip)->base + 1);
if ((*data & mask) == val) if ((*data & mask) == val)
return 0; return 0;
} }
...@@ -95,9 +105,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip) ...@@ -95,9 +105,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
unsigned long stop; unsigned long stop;
/* status immediately available check */ /* status immediately available check */
status = inb(chip->vendor.base + NSC_STATUS); status = inb(nsc_get_priv(chip)->base + NSC_STATUS);
if (status & NSC_STATUS_OBF) if (status & NSC_STATUS_OBF)
status = inb(chip->vendor.base + NSC_DATA); status = inb(nsc_get_priv(chip)->base + NSC_DATA);
if (status & NSC_STATUS_RDY) if (status & NSC_STATUS_RDY)
return 0; return 0;
...@@ -105,9 +115,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip) ...@@ -105,9 +115,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
stop = jiffies + 100; stop = jiffies + 100;
do { do {
msleep(TPM_TIMEOUT); msleep(TPM_TIMEOUT);
status = inb(chip->vendor.base + NSC_STATUS); status = inb(nsc_get_priv(chip)->base + NSC_STATUS);
if (status & NSC_STATUS_OBF) if (status & NSC_STATUS_OBF)
status = inb(chip->vendor.base + NSC_DATA); status = inb(nsc_get_priv(chip)->base + NSC_DATA);
if (status & NSC_STATUS_RDY) if (status & NSC_STATUS_RDY)
return 0; return 0;
} }
...@@ -132,8 +142,9 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) ...@@ -132,8 +142,9 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
dev_err(&chip->dev, "F0 timeout\n"); dev_err(&chip->dev, "F0 timeout\n");
return -EIO; return -EIO;
} }
if ((data =
inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_NORMAL) { data = inb(nsc_get_priv(chip)->base + NSC_DATA);
if (data != NSC_COMMAND_NORMAL) {
dev_err(&chip->dev, "not in normal mode (0x%x)\n", dev_err(&chip->dev, "not in normal mode (0x%x)\n",
data); data);
return -EIO; return -EIO;
...@@ -149,7 +160,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) ...@@ -149,7 +160,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
} }
if (data & NSC_STATUS_F0) if (data & NSC_STATUS_F0)
break; break;
*p = inb(chip->vendor.base + NSC_DATA); *p = inb(nsc_get_priv(chip)->base + NSC_DATA);
} }
if ((data & NSC_STATUS_F0) == 0 && if ((data & NSC_STATUS_F0) == 0 &&
...@@ -157,7 +168,9 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) ...@@ -157,7 +168,9 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
dev_err(&chip->dev, "F0 not set\n"); dev_err(&chip->dev, "F0 not set\n");
return -EIO; return -EIO;
} }
if ((data = inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_EOC) {
data = inb(nsc_get_priv(chip)->base + NSC_DATA);
if (data != NSC_COMMAND_EOC) {
dev_err(&chip->dev, dev_err(&chip->dev,
"expected end of command(0x%x)\n", data); "expected end of command(0x%x)\n", data);
return -EIO; return -EIO;
...@@ -183,7 +196,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) ...@@ -183,7 +196,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
* fix it. Not sure why this is needed, we followed the flow * fix it. Not sure why this is needed, we followed the flow
* chart in the manual to the letter. * chart in the manual to the letter.
*/ */
outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND); outb(NSC_COMMAND_CANCEL, nsc_get_priv(chip)->base + NSC_COMMAND);
if (nsc_wait_for_ready(chip) != 0) if (nsc_wait_for_ready(chip) != 0)
return -EIO; return -EIO;
...@@ -193,7 +206,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) ...@@ -193,7 +206,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
return -EIO; return -EIO;
} }
outb(NSC_COMMAND_NORMAL, chip->vendor.base + NSC_COMMAND); outb(NSC_COMMAND_NORMAL, nsc_get_priv(chip)->base + NSC_COMMAND);
if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) { if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
dev_err(&chip->dev, "IBR timeout\n"); dev_err(&chip->dev, "IBR timeout\n");
return -EIO; return -EIO;
...@@ -205,26 +218,26 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) ...@@ -205,26 +218,26 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
"IBF timeout (while writing data)\n"); "IBF timeout (while writing data)\n");
return -EIO; return -EIO;
} }
outb(buf[i], chip->vendor.base + NSC_DATA); outb(buf[i], nsc_get_priv(chip)->base + NSC_DATA);
} }
if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
dev_err(&chip->dev, "IBF timeout\n"); dev_err(&chip->dev, "IBF timeout\n");
return -EIO; return -EIO;
} }
outb(NSC_COMMAND_EOC, chip->vendor.base + NSC_COMMAND); outb(NSC_COMMAND_EOC, nsc_get_priv(chip)->base + NSC_COMMAND);
return count; return count;
} }
static void tpm_nsc_cancel(struct tpm_chip *chip) static void tpm_nsc_cancel(struct tpm_chip *chip)
{ {
outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND); outb(NSC_COMMAND_CANCEL, nsc_get_priv(chip)->base + NSC_COMMAND);
} }
static u8 tpm_nsc_status(struct tpm_chip *chip) static u8 tpm_nsc_status(struct tpm_chip *chip)
{ {
return inb(chip->vendor.base + NSC_STATUS); return inb(nsc_get_priv(chip)->base + NSC_STATUS);
} }
static bool tpm_nsc_req_canceled(struct tpm_chip *chip, u8 status) static bool tpm_nsc_req_canceled(struct tpm_chip *chip, u8 status)
...@@ -249,7 +262,7 @@ static void tpm_nsc_remove(struct device *dev) ...@@ -249,7 +262,7 @@ static void tpm_nsc_remove(struct device *dev)
struct tpm_chip *chip = dev_get_drvdata(dev); struct tpm_chip *chip = dev_get_drvdata(dev);
tpm_chip_unregister(chip); tpm_chip_unregister(chip);
release_region(chip->vendor.base, 2); release_region(nsc_get_priv(chip)->base, 2);
} }
static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume); static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume);
...@@ -268,6 +281,7 @@ static int __init init_nsc(void) ...@@ -268,6 +281,7 @@ static int __init init_nsc(void)
int nscAddrBase = TPM_ADDR; int nscAddrBase = TPM_ADDR;
struct tpm_chip *chip; struct tpm_chip *chip;
unsigned long base; unsigned long base;
struct tpm_nsc_priv *priv;
/* verify that it is a National part (SID) */ /* verify that it is a National part (SID) */
if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) { if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
...@@ -301,6 +315,14 @@ static int __init init_nsc(void) ...@@ -301,6 +315,14 @@ static int __init init_nsc(void)
if ((rc = platform_device_add(pdev)) < 0) if ((rc = platform_device_add(pdev)) < 0)
goto err_put_dev; goto err_put_dev;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv) {
rc = -ENOMEM;
goto err_del_dev;
}
priv->base = base;
if (request_region(base, 2, "tpm_nsc0") == NULL ) { if (request_region(base, 2, "tpm_nsc0") == NULL ) {
rc = -EBUSY; rc = -EBUSY;
goto err_del_dev; goto err_del_dev;
...@@ -312,6 +334,8 @@ static int __init init_nsc(void) ...@@ -312,6 +334,8 @@ static int __init init_nsc(void)
goto err_rel_reg; goto err_rel_reg;
} }
chip->vendor.priv = priv;
rc = tpm_chip_register(chip); rc = tpm_chip_register(chip);
if (rc) if (rc)
goto err_rel_reg; goto err_rel_reg;
...@@ -349,8 +373,6 @@ static int __init init_nsc(void) ...@@ -349,8 +373,6 @@ static int __init init_nsc(void)
"NSC TPM revision %d\n", "NSC TPM revision %d\n",
tpm_read_index(nscAddrBase, 0x27) & 0x1F); tpm_read_index(nscAddrBase, 0x27) & 0x1F);
chip->vendor.base = base;
return 0; return 0;
err_rel_reg: err_rel_reg:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment