Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f82e9f0 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Peter Huewe
Browse files

tpm: Use the ops structure instead of a copy in tpm_vendor_specific



This builds on the last commit to use the ops structure in the core
and reduce the size of tpm_vendor_specific.

Signed-off-by: default avatarJason Gunthorpe <jgunthorpe@obsidianresearch.com>
Reviewed-by: default avatarJoel Schopp <jschopp@linux.vnet.ibm.com>
Reviewed-by: default avatarAshley Lai <adlai@linux.vnet.ibm.com>
Signed-off-by: default avatarPeter Huewe <peterhuewe@gmx.de>
parent 01ad1fa7
Loading
Loading
Loading
Loading
+12 −22
Original line number Original line Diff line number Diff line
@@ -353,7 +353,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,


	mutex_lock(&chip->tpm_mutex);
	mutex_lock(&chip->tpm_mutex);


	rc = chip->vendor.send(chip, (u8 *) buf, count);
	rc = chip->ops->send(chip, (u8 *) buf, count);
	if (rc < 0) {
	if (rc < 0) {
		dev_err(chip->dev,
		dev_err(chip->dev,
			"tpm_transmit: tpm_send: error %zd\n", rc);
			"tpm_transmit: tpm_send: error %zd\n", rc);
@@ -365,12 +365,12 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,


	stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal);
	stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal);
	do {
	do {
		u8 status = chip->vendor.status(chip);
		u8 status = chip->ops->status(chip);
		if ((status & chip->vendor.req_complete_mask) ==
		if ((status & chip->ops->req_complete_mask) ==
		    chip->vendor.req_complete_val)
		    chip->ops->req_complete_val)
			goto out_recv;
			goto out_recv;


		if (chip->vendor.req_canceled(chip, status)) {
		if (chip->ops->req_canceled(chip, status)) {
			dev_err(chip->dev, "Operation Canceled\n");
			dev_err(chip->dev, "Operation Canceled\n");
			rc = -ECANCELED;
			rc = -ECANCELED;
			goto out;
			goto out;
@@ -380,13 +380,13 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
		rmb();
		rmb();
	} while (time_before(jiffies, stop));
	} while (time_before(jiffies, stop));


	chip->vendor.cancel(chip);
	chip->ops->cancel(chip);
	dev_err(chip->dev, "Operation Timed out\n");
	dev_err(chip->dev, "Operation Timed out\n");
	rc = -ETIME;
	rc = -ETIME;
	goto out;
	goto out;


out_recv:
out_recv:
	rc = chip->vendor.recv(chip, (u8 *) buf, bufsiz);
	rc = chip->ops->recv(chip, (u8 *) buf, bufsiz);
	if (rc < 0)
	if (rc < 0)
		dev_err(chip->dev,
		dev_err(chip->dev,
			"tpm_transmit: tpm_recv: error %zd\n", rc);
			"tpm_transmit: tpm_recv: error %zd\n", rc);
@@ -807,12 +807,12 @@ EXPORT_SYMBOL_GPL(tpm_send);
static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
					bool check_cancel, bool *canceled)
					bool check_cancel, bool *canceled)
{
{
	u8 status = chip->vendor.status(chip);
	u8 status = chip->ops->status(chip);


	*canceled = false;
	*canceled = false;
	if ((status & mask) == mask)
	if ((status & mask) == mask)
		return true;
		return true;
	if (check_cancel && chip->vendor.req_canceled(chip, status)) {
	if (check_cancel && chip->ops->req_canceled(chip, status)) {
		*canceled = true;
		*canceled = true;
		return true;
		return true;
	}
	}
@@ -828,7 +828,7 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
	bool canceled = false;
	bool canceled = false;


	/* check current status */
	/* check current status */
	status = chip->vendor.status(chip);
	status = chip->ops->status(chip);
	if ((status & mask) == mask)
	if ((status & mask) == mask)
		return 0;
		return 0;


@@ -855,7 +855,7 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
	} else {
	} else {
		do {
		do {
			msleep(TPM_TIMEOUT);
			msleep(TPM_TIMEOUT);
			status = chip->vendor.status(chip);
			status = chip->ops->status(chip);
			if ((status & mask) == mask)
			if ((status & mask) == mask)
				return 0;
				return 0;
		} while (time_before(jiffies, stop));
		} while (time_before(jiffies, stop));
@@ -1027,9 +1027,6 @@ void tpm_dev_vendor_release(struct tpm_chip *chip)
	if (!chip)
	if (!chip)
		return;
		return;


	if (chip->vendor.release)
		chip->vendor.release(chip->dev);

	clear_bit(chip->dev_num, dev_mask);
	clear_bit(chip->dev_num, dev_mask);
}
}
EXPORT_SYMBOL_GPL(tpm_dev_vendor_release);
EXPORT_SYMBOL_GPL(tpm_dev_vendor_release);
@@ -1073,14 +1070,7 @@ struct tpm_chip *tpm_register_hardware(struct device *dev,
	mutex_init(&chip->tpm_mutex);
	mutex_init(&chip->tpm_mutex);
	INIT_LIST_HEAD(&chip->list);
	INIT_LIST_HEAD(&chip->list);


	chip->vendor.req_complete_mask = ops->req_complete_mask;
	chip->ops = ops;
	chip->vendor.req_complete_val = ops->req_complete_val;
	chip->vendor.req_canceled = ops->req_canceled;
	chip->vendor.recv = ops->recv;
	chip->vendor.send = ops->send;
	chip->vendor.cancel = ops->cancel;
	chip->vendor.status = ops->status;

	chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES);
	chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES);


	if (chip->dev_num >= TPM_NUM_DEVICES) {
	if (chip->dev_num >= TPM_NUM_DEVICES) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -245,7 +245,7 @@ static ssize_t cancel_store(struct device *dev, struct device_attribute *attr,
	if (chip == NULL)
	if (chip == NULL)
		return 0;
		return 0;


	chip->vendor.cancel(chip);
	chip->ops->cancel(chip);
	return count;
	return count;
}
}
static DEVICE_ATTR_WO(cancel);
static DEVICE_ATTR_WO(cancel);
+1 −8
Original line number Original line Diff line number Diff line
@@ -64,9 +64,6 @@ enum tpm_duration {
struct tpm_chip;
struct tpm_chip;


struct tpm_vendor_specific {
struct tpm_vendor_specific {
	u8 req_complete_mask;
	u8 req_complete_val;
	bool (*req_canceled)(struct tpm_chip *chip, u8 status);
	void __iomem *iobase;		/* ioremapped address */
	void __iomem *iobase;		/* ioremapped address */
	unsigned long base;		/* TPM base address */
	unsigned long base;		/* TPM base address */


@@ -76,11 +73,6 @@ struct tpm_vendor_specific {
	int region_size;
	int region_size;
	int have_region;
	int have_region;


	int (*recv) (struct tpm_chip *, u8 *, size_t);
	int (*send) (struct tpm_chip *, u8 *, size_t);
	void (*cancel) (struct tpm_chip *);
	u8 (*status) (struct tpm_chip *);
	void (*release) (struct device *);
	struct miscdevice miscdev;
	struct miscdevice miscdev;
	struct list_head list;
	struct list_head list;
	int locality;
	int locality;
@@ -104,6 +96,7 @@ struct tpm_vendor_specific {


struct tpm_chip {
struct tpm_chip {
	struct device *dev;	/* Device stuff */
	struct device *dev;	/* Device stuff */
	const struct tpm_class_ops *ops;


	int dev_num;		/* /dev/tpm# */
	int dev_num;		/* /dev/tpm# */
	char devname[7];
	char devname[7];
+2 −2
Original line number Original line Diff line number Diff line
@@ -564,7 +564,7 @@ static int tpm_stm_i2c_recv(struct tpm_chip *chip, unsigned char *buf,
	}
	}


out:
out:
	chip->vendor.cancel(chip);
	chip->ops->cancel(chip);
	release_locality(chip);
	release_locality(chip);
	return size;
	return size;
}
}
@@ -807,7 +807,7 @@ static int tpm_st33_i2c_pm_resume(struct device *dev)
	if (power_mgt) {
	if (power_mgt) {
		gpio_set_value(pin_infos->io_lpcpd, 1);
		gpio_set_value(pin_infos->io_lpcpd, 1);
		ret = wait_for_serirq_timeout(chip,
		ret = wait_for_serirq_timeout(chip,
					  (chip->vendor.status(chip) &
					  (chip->ops->status(chip) &
					  TPM_STS_VALID) == TPM_STS_VALID,
					  TPM_STS_VALID) == TPM_STS_VALID,
					  chip->vendor.timeout_b);
					  chip->vendor.timeout_b);
	} else {
	} else {