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

Commit 1e3b73a9 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Peter Huewe
Browse files

tpm: Pull all driver sysfs code into tpm-sysfs.c



The tpm core now sets up and controls all sysfs attributes, instead
of having each driver have a unique take on it.

All drivers now now have a uniform set of attributes, and no sysfs
related entry points are exported from the tpm core module.

This also uses the new method used to declare sysfs attributes
with DEVICE_ATTR_RO and 'struct attribute *'

Signed-off-by: default avatarJason Gunthorpe <jgunthorpe@obsidianresearch.com>
[phuewe: had to apply the tpm_i2c_atmel part manually due to commit
191ffc6bde3fc tpm/tpm_i2c_atmel: fix coccinelle warnings]

Signed-off-by: default avatarPeter Huewe <peterhuewe@gmx.de>
parent 000a07b0
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -879,7 +879,7 @@ void tpm_remove_hardware(struct device *dev)
	synchronize_rcu();

	tpm_dev_del_device(chip);
	sysfs_remove_group(&dev->kobj, chip->vendor.attr_group);
	tpm_sysfs_del_device(chip);
	tpm_remove_ppi(&dev->kobj);
	tpm_bios_log_teardown(chip->bios_dir);

@@ -1095,7 +1095,7 @@ struct tpm_chip *tpm_register_hardware(struct device *dev,
	if (tpm_dev_add_device(chip))
		goto put_device;

	if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group))
	if (tpm_sysfs_add_device(chip))
		goto del_misc;

	if (tpm_add_ppi(&dev->kobj))
+68 −31
Original line number Diff line number Diff line
@@ -6,6 +6,9 @@
 * Reiner Sailer <sailer@watson.ibm.com>
 * Kylene Hall <kjhall@us.ibm.com>
 *
 * Copyright (C) 2013 Obsidian Research Corp
 * Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
 *
 * sysfs filesystem inspection interface to the TPM
 *
 * This program is free software; you can redistribute it and/or
@@ -43,8 +46,7 @@ static struct tpm_input_header tpm_readpubek_header = {
	.length = cpu_to_be32(30),
	.ordinal = TPM_ORD_READPUBEK
};

ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
			  char *buf)
{
	u8 *data;
@@ -99,9 +101,9 @@ out:
	rc = str - buf;
	return rc;
}
EXPORT_SYMBOL_GPL(tpm_show_pubek);
static DEVICE_ATTR_RO(pubek);

ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr,
			 char *buf)
{
	cap_t cap;
@@ -128,9 +130,9 @@ ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
	}
	return str - buf;
}
EXPORT_SYMBOL_GPL(tpm_show_pcrs);
static DEVICE_ATTR_RO(pcrs);

ssize_t tpm_show_enabled(struct device *dev, struct device_attribute *attr,
static ssize_t enabled_show(struct device *dev, struct device_attribute *attr,
		     char *buf)
{
	cap_t cap;
@@ -144,9 +146,9 @@ ssize_t tpm_show_enabled(struct device *dev, struct device_attribute *attr,
	rc = sprintf(buf, "%d\n", !cap.perm_flags.disable);
	return rc;
}
EXPORT_SYMBOL_GPL(tpm_show_enabled);
static DEVICE_ATTR_RO(enabled);

ssize_t tpm_show_active(struct device *dev, struct device_attribute *attr,
ssize_t active_show(struct device *dev, struct device_attribute *attr,
		    char *buf)
{
	cap_t cap;
@@ -160,9 +162,9 @@ ssize_t tpm_show_active(struct device *dev, struct device_attribute *attr,
	rc = sprintf(buf, "%d\n", !cap.perm_flags.deactivated);
	return rc;
}
EXPORT_SYMBOL_GPL(tpm_show_active);
static DEVICE_ATTR_RO(active);

ssize_t tpm_show_owned(struct device *dev, struct device_attribute *attr,
static ssize_t owned_show(struct device *dev, struct device_attribute *attr,
			  char *buf)
{
	cap_t cap;
@@ -176,9 +178,9 @@ ssize_t tpm_show_owned(struct device *dev, struct device_attribute *attr,
	rc = sprintf(buf, "%d\n", cap.owned);
	return rc;
}
EXPORT_SYMBOL_GPL(tpm_show_owned);
static DEVICE_ATTR_RO(owned);

ssize_t tpm_show_temp_deactivated(struct device *dev,
static ssize_t temp_deactivated_show(struct device *dev,
				     struct device_attribute *attr, char *buf)
{
	cap_t cap;
@@ -192,9 +194,9 @@ ssize_t tpm_show_temp_deactivated(struct device *dev,
	rc = sprintf(buf, "%d\n", cap.stclear_flags.deactivated);
	return rc;
}
EXPORT_SYMBOL_GPL(tpm_show_temp_deactivated);
static DEVICE_ATTR_RO(temp_deactivated);

ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,
static ssize_t caps_show(struct device *dev, struct device_attribute *attr,
			 char *buf)
{
	cap_t cap;
@@ -234,9 +236,9 @@ ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,

	return str - buf;
}
EXPORT_SYMBOL_GPL(tpm_show_caps);
static DEVICE_ATTR_RO(caps);

ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr,
static ssize_t cancel_store(struct device *dev, struct device_attribute *attr,
			    const char *buf, size_t count)
{
	struct tpm_chip *chip = dev_get_drvdata(dev);
@@ -246,9 +248,9 @@ ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr,
	chip->vendor.cancel(chip);
	return count;
}
EXPORT_SYMBOL_GPL(tpm_store_cancel);
static DEVICE_ATTR_WO(cancel);

ssize_t tpm_show_durations(struct device *dev, struct device_attribute *attr,
static ssize_t durations_show(struct device *dev, struct device_attribute *attr,
			      char *buf)
{
	struct tpm_chip *chip = dev_get_drvdata(dev);
@@ -263,9 +265,9 @@ ssize_t tpm_show_durations(struct device *dev, struct device_attribute *attr,
		       chip->vendor.duration_adjusted
		       ? "adjusted" : "original");
}
EXPORT_SYMBOL_GPL(tpm_show_durations);
static DEVICE_ATTR_RO(durations);

ssize_t tpm_show_timeouts(struct device *dev, struct device_attribute *attr,
static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr,
			     char *buf)
{
	struct tpm_chip *chip = dev_get_drvdata(dev);
@@ -278,4 +280,39 @@ ssize_t tpm_show_timeouts(struct device *dev, struct device_attribute *attr,
		       chip->vendor.timeout_adjusted
		       ? "adjusted" : "original");
}
EXPORT_SYMBOL_GPL(tpm_show_timeouts);
static DEVICE_ATTR_RO(timeouts);

static struct attribute *tpm_dev_attrs[] = {
	&dev_attr_pubek.attr,
	&dev_attr_pcrs.attr,
	&dev_attr_enabled.attr,
	&dev_attr_active.attr,
	&dev_attr_owned.attr,
	&dev_attr_temp_deactivated.attr,
	&dev_attr_caps.attr,
	&dev_attr_cancel.attr,
	&dev_attr_durations.attr,
	&dev_attr_timeouts.attr,
	NULL,
};

static const struct attribute_group tpm_dev_group = {
	.attrs = tpm_dev_attrs,
};

int tpm_sysfs_add_device(struct tpm_chip *chip)
{
	int err;
	err = sysfs_create_group(&chip->dev->kobj,
				 &tpm_dev_group);

	if (err)
		dev_err(chip->dev,
			"failed to create sysfs attributes, %d\n", err);
	return err;
}

void tpm_sysfs_del_device(struct tpm_chip *chip)
{
	sysfs_remove_group(&chip->dev->kobj, &tpm_dev_group);
}
+2 −22
Original line number Diff line number Diff line
@@ -61,27 +61,6 @@ enum tpm_duration {
#define TPM_ERR_INVALID_POSTINIT 38

#define TPM_HEADER_SIZE		10
extern ssize_t tpm_show_pubek(struct device *, struct device_attribute *attr,
				char *);
extern ssize_t tpm_show_pcrs(struct device *, struct device_attribute *attr,
				char *);
extern ssize_t tpm_show_caps(struct device *, struct device_attribute *attr,
				char *);
extern ssize_t tpm_store_cancel(struct device *, struct device_attribute *attr,
				const char *, size_t);
extern ssize_t tpm_show_enabled(struct device *, struct device_attribute *attr,
				char *);
extern ssize_t tpm_show_active(struct device *, struct device_attribute *attr,
				char *);
extern ssize_t tpm_show_owned(struct device *, struct device_attribute *attr,
				char *);
extern ssize_t tpm_show_temp_deactivated(struct device *,
					 struct device_attribute *attr, char *);
extern ssize_t tpm_show_durations(struct device *,
				  struct device_attribute *attr, char *);
extern ssize_t tpm_show_timeouts(struct device *,
				 struct device_attribute *attr, char *);

struct tpm_chip;

struct tpm_vendor_specific {
@@ -103,7 +82,6 @@ struct tpm_vendor_specific {
	u8 (*status) (struct tpm_chip *);
	void (*release) (struct device *);
	struct miscdevice miscdev;
	struct attribute_group *attr_group;
	struct list_head list;
	int locality;
	unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* jiffies */
@@ -368,6 +346,8 @@ extern int wait_for_tpm_stat(struct tpm_chip *, u8, unsigned long,

int tpm_dev_add_device(struct tpm_chip *chip);
void tpm_dev_del_device(struct tpm_chip *chip);
int tpm_sysfs_add_device(struct tpm_chip *chip);
void tpm_sysfs_del_device(struct tpm_chip *chip);

int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);

+0 −16
Original line number Diff line number Diff line
@@ -121,21 +121,6 @@ static bool tpm_atml_req_canceled(struct tpm_chip *chip, u8 status)
	return (status == ATML_STATUS_READY);
}

static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
static DEVICE_ATTR(cancel, S_IWUSR |S_IWGRP, NULL, tpm_store_cancel);

static struct attribute* atmel_attrs[] = {
	&dev_attr_pubek.attr,
	&dev_attr_pcrs.attr,
	&dev_attr_caps.attr,
	&dev_attr_cancel.attr,
	NULL,
};

static struct attribute_group atmel_attr_grp = { .attrs = atmel_attrs };

static const struct tpm_vendor_specific tpm_atmel = {
	.recv = tpm_atml_recv,
	.send = tpm_atml_send,
@@ -144,7 +129,6 @@ static const struct tpm_vendor_specific tpm_atmel = {
	.req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL,
	.req_complete_val = ATML_STATUS_DATA_AVAIL,
	.req_canceled = tpm_atml_req_canceled,
	.attr_group = &atmel_attr_grp,
};

static struct platform_device *pdev;
+0 −30
Original line number Diff line number Diff line
@@ -135,35 +135,6 @@ static u8 i2c_atmel_read_status(struct tpm_chip *chip)
	return ATMEL_STS_OK;
}

static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
static DEVICE_ATTR(active, S_IRUGO, tpm_show_active, NULL);
static DEVICE_ATTR(owned, S_IRUGO, tpm_show_owned, NULL);
static DEVICE_ATTR(temp_deactivated, S_IRUGO, tpm_show_temp_deactivated, NULL);
static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
static DEVICE_ATTR(cancel, S_IWUSR | S_IWGRP, NULL, tpm_store_cancel);
static DEVICE_ATTR(durations, S_IRUGO, tpm_show_durations, NULL);
static DEVICE_ATTR(timeouts, S_IRUGO, tpm_show_timeouts, NULL);

static struct attribute *i2c_atmel_attrs[] = {
	&dev_attr_pubek.attr,
	&dev_attr_pcrs.attr,
	&dev_attr_enabled.attr,
	&dev_attr_active.attr,
	&dev_attr_owned.attr,
	&dev_attr_temp_deactivated.attr,
	&dev_attr_caps.attr,
	&dev_attr_cancel.attr,
	&dev_attr_durations.attr,
	&dev_attr_timeouts.attr,
	NULL,
};

static struct attribute_group i2c_atmel_attr_grp = {
	.attrs = i2c_atmel_attrs
};

static bool i2c_atmel_req_canceled(struct tpm_chip *chip, u8 status)
{
	return false;
@@ -177,7 +148,6 @@ static const struct tpm_vendor_specific i2c_atmel = {
	.req_complete_mask = ATMEL_STS_OK,
	.req_complete_val = ATMEL_STS_OK,
	.req_canceled = i2c_atmel_req_canceled,
	.attr_group = &i2c_atmel_attr_grp,
};

static int i2c_atmel_probe(struct i2c_client *client,
Loading