Commit 84d25940 authored by Jerry Snitselaar's avatar Jerry Snitselaar Committed by Jarkko Sakkinen

tpm: make check_locality return bool

Since check_locality is checking to see if a certain
locality is active, return true if active otherwise
return false.

Cc: Christophe Ricard <christophe.ricard@gmail.com>
Cc: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Cc: Marcel Selhorst <tpmdd@selhorst.net>
Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: default avatarJerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
parent 67c2f3d3
...@@ -117,9 +117,9 @@ static u8 st33zp24_status(struct tpm_chip *chip) ...@@ -117,9 +117,9 @@ static u8 st33zp24_status(struct tpm_chip *chip)
/* /*
* check_locality if the locality is active * check_locality if the locality is active
* @param: chip, the tpm chip description * @param: chip, the tpm chip description
* @return: the active locality or -EACCESS. * @return: true if LOCALITY0 is active, otherwise false
*/ */
static int check_locality(struct tpm_chip *chip) static bool check_locality(struct tpm_chip *chip)
{ {
struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev); struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
u8 data; u8 data;
...@@ -129,9 +129,9 @@ static int check_locality(struct tpm_chip *chip) ...@@ -129,9 +129,9 @@ static int check_locality(struct tpm_chip *chip)
if (status && (data & if (status && (data &
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) == (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
return tpm_dev->locality; return true;
return -EACCES; return false;
} /* check_locality() */ } /* check_locality() */
/* /*
...@@ -146,7 +146,7 @@ static int request_locality(struct tpm_chip *chip) ...@@ -146,7 +146,7 @@ static int request_locality(struct tpm_chip *chip)
long ret; long ret;
u8 data; u8 data;
if (check_locality(chip) == tpm_dev->locality) if (check_locality(chip))
return tpm_dev->locality; return tpm_dev->locality;
data = TPM_ACCESS_REQUEST_USE; data = TPM_ACCESS_REQUEST_USE;
...@@ -158,7 +158,7 @@ static int request_locality(struct tpm_chip *chip) ...@@ -158,7 +158,7 @@ static int request_locality(struct tpm_chip *chip)
/* Request locality is usually effective after the request */ /* Request locality is usually effective after the request */
do { do {
if (check_locality(chip) >= 0) if (check_locality(chip))
return tpm_dev->locality; return tpm_dev->locality;
msleep(TPM_TIMEOUT); msleep(TPM_TIMEOUT);
} while (time_before(jiffies, stop)); } while (time_before(jiffies, stop));
......
...@@ -278,22 +278,22 @@ enum tis_defaults { ...@@ -278,22 +278,22 @@ enum tis_defaults {
#define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4)) #define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4))
#define TPM_DID_VID(l) (0x0006 | ((l) << 4)) #define TPM_DID_VID(l) (0x0006 | ((l) << 4))
static int check_locality(struct tpm_chip *chip, int loc) static bool check_locality(struct tpm_chip *chip, int loc)
{ {
u8 buf; u8 buf;
int rc; int rc;
rc = iic_tpm_read(TPM_ACCESS(loc), &buf, 1); rc = iic_tpm_read(TPM_ACCESS(loc), &buf, 1);
if (rc < 0) if (rc < 0)
return rc; return false;
if ((buf & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) == if ((buf & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) { (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) {
tpm_dev.locality = loc; tpm_dev.locality = loc;
return loc; return true;
} }
return -EIO; return false;
} }
/* implementation similar to tpm_tis */ /* implementation similar to tpm_tis */
...@@ -315,7 +315,7 @@ static int request_locality(struct tpm_chip *chip, int loc) ...@@ -315,7 +315,7 @@ static int request_locality(struct tpm_chip *chip, int loc)
unsigned long stop; unsigned long stop;
u8 buf = TPM_ACCESS_REQUEST_USE; u8 buf = TPM_ACCESS_REQUEST_USE;
if (check_locality(chip, loc) >= 0) if (check_locality(chip, loc))
return loc; return loc;
iic_tpm_write(TPM_ACCESS(loc), &buf, 1); iic_tpm_write(TPM_ACCESS(loc), &buf, 1);
...@@ -323,7 +323,7 @@ static int request_locality(struct tpm_chip *chip, int loc) ...@@ -323,7 +323,7 @@ static int request_locality(struct tpm_chip *chip, int loc)
/* wait for burstcount */ /* wait for burstcount */
stop = jiffies + chip->timeout_a; stop = jiffies + chip->timeout_a;
do { do {
if (check_locality(chip, loc) >= 0) if (check_locality(chip, loc))
return loc; return loc;
usleep_range(TPM_TIMEOUT_US_LOW, TPM_TIMEOUT_US_HI); usleep_range(TPM_TIMEOUT_US_LOW, TPM_TIMEOUT_US_HI);
} while (time_before(jiffies, stop)); } while (time_before(jiffies, stop));
......
...@@ -56,7 +56,7 @@ static int wait_startup(struct tpm_chip *chip, int l) ...@@ -56,7 +56,7 @@ static int wait_startup(struct tpm_chip *chip, int l)
return -1; return -1;
} }
static int check_locality(struct tpm_chip *chip, int l) static bool check_locality(struct tpm_chip *chip, int l)
{ {
struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
int rc; int rc;
...@@ -64,13 +64,15 @@ static int check_locality(struct tpm_chip *chip, int l) ...@@ -64,13 +64,15 @@ static int check_locality(struct tpm_chip *chip, int l)
rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access); rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access);
if (rc < 0) if (rc < 0)
return rc; return false;
if ((access & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) == if ((access & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) {
return priv->locality = l; priv->locality = l;
return true;
}
return -1; return false;
} }
static void release_locality(struct tpm_chip *chip, int l, int force) static void release_locality(struct tpm_chip *chip, int l, int force)
...@@ -96,7 +98,7 @@ static int request_locality(struct tpm_chip *chip, int l) ...@@ -96,7 +98,7 @@ static int request_locality(struct tpm_chip *chip, int l)
unsigned long stop, timeout; unsigned long stop, timeout;
long rc; long rc;
if (check_locality(chip, l) >= 0) if (check_locality(chip, l))
return l; return l;
rc = tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_REQUEST_USE); rc = tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_REQUEST_USE);
...@@ -112,7 +114,7 @@ static int request_locality(struct tpm_chip *chip, int l) ...@@ -112,7 +114,7 @@ static int request_locality(struct tpm_chip *chip, int l)
return -1; return -1;
rc = wait_event_interruptible_timeout(priv->int_queue, rc = wait_event_interruptible_timeout(priv->int_queue,
(check_locality (check_locality
(chip, l) >= 0), (chip, l)),
timeout); timeout);
if (rc > 0) if (rc > 0)
return l; return l;
...@@ -123,7 +125,7 @@ static int request_locality(struct tpm_chip *chip, int l) ...@@ -123,7 +125,7 @@ static int request_locality(struct tpm_chip *chip, int l)
} else { } else {
/* wait for burstcount */ /* wait for burstcount */
do { do {
if (check_locality(chip, l) >= 0) if (check_locality(chip, l))
return l; return l;
msleep(TPM_TIMEOUT); msleep(TPM_TIMEOUT);
} while (time_before(jiffies, stop)); } while (time_before(jiffies, stop));
...@@ -535,7 +537,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) ...@@ -535,7 +537,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id)
wake_up_interruptible(&priv->read_queue); wake_up_interruptible(&priv->read_queue);
if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT)
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
if (check_locality(chip, i) >= 0) if (check_locality(chip, i))
break; break;
if (interrupt & if (interrupt &
(TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT | (TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT |
......
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