[Skiboot] [PATCH v2 10/31] libstb: add tpm_chip interface

Stewart Smith stewart at linux.vnet.ibm.com
Wed Oct 5 15:50:29 AEDT 2016


Claudio Carvalho <cclaudio at linux.vnet.ibm.com> writes:
> This adds the TPM chip interface for libstb:
>
> - tpm_init(): call drivers' probe to find TPM devices that are
>   compatible with them.
>
> - tpm_register_chip(): register a TPM chip which includes pointers to
>   the TPM device and TPM driver structures.
>
> - tpm_add_status_property(): add the status device tree property for
>   each registered TPM device.
>
> The TPM chip interface is documented in 'libstb/tpm_chip.h' and the tpm device
> tree node is documented in 'doc/device-tree/tpm.rst'
>
> Signed-off-by: Claudio Carvalho <cclaudio at linux.vnet.ibm.com>
> ---
>  libstb/Makefile.inc   |   2 +-
>  libstb/status_codes.h |  23 ++++++++++
>  libstb/tpm_chip.c     | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  libstb/tpm_chip.h     |  73 ++++++++++++++++++++++++++++++
>  4 files changed, 220 insertions(+), 1 deletion(-)
>  create mode 100644 libstb/status_codes.h
>  create mode 100644 libstb/tpm_chip.c
>  create mode 100644 libstb/tpm_chip.h
>
> diff --git a/libstb/Makefile.inc b/libstb/Makefile.inc
> index 3beafba..8b057de 100644
> --- a/libstb/Makefile.inc
> +++ b/libstb/Makefile.inc
> @@ -4,7 +4,7 @@ LIBSTB_DIR = libstb
>  
>  SUBDIRS += $(LIBSTB_DIR)
>  
> -LIBSTB_SRCS = container.c rom.c
> +LIBSTB_SRCS = container.c rom.c tpm_chip.c
>  LIBSTB_OBJS = $(LIBSTB_SRCS:%.c=%.o)
>  LIBSTB = $(LIBSTB_DIR)/built-in.o
>  
> diff --git a/libstb/status_codes.h b/libstb/status_codes.h
> new file mode 100644
> index 0000000..240cd95
> --- /dev/null
> +++ b/libstb/status_codes.h
> @@ -0,0 +1,23 @@
> +/* Copyright 2013-2016 IBM Corp.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> + * implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +#ifndef __STB_STATUS_CODES_H
> +#define __STB_STATUS_CODES_H
> +
> +/*  general return codes */
> +#define STB_ERROR		-1
> +
> +#endif /* __STB_STATUS_CODES_H */
> diff --git a/libstb/tpm_chip.c b/libstb/tpm_chip.c
> new file mode 100644
> index 0000000..72d15b5
> --- /dev/null
> +++ b/libstb/tpm_chip.c
> @@ -0,0 +1,123 @@
> +/* Copyright 2013-2016 IBM Corp.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> + * implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +#include <skiboot.h>
> +#include <device.h>
> +#include <string.h>
> +
> +#include "status_codes.h"
> +#include "container.h"
> +#include "tpm_chip.h"
> +
> +static struct list_head tpm_list = LIST_HEAD_INIT(tpm_list);
> +
> +int tpm_register_chip(struct dt_node *node, struct tpm_dev *dev,
> +		       struct tpm_driver *driver)
> +{
> +	int i, rc;

libstb/tpm_chip.c:30:9: error: unused variable ‘rc’ [-Werror=unused-variable]
  int i, rc;
         ^~
cc1: all warnings being treated as errors
/home/stewart/skiboot/Makefile.rules:56: recipe for target 'libstb/tpm_chip.o' failed
make: *** [libstb/tpm_chip.o] Error 1

> +	struct tpm_chip *tpm;
> +
> +	i = 0;
> +	list_for_each(&tpm_list, tpm, link) {
> +		if (tpm->node == node) {
> +			/**
> +			 * @fwts-label TPMAlreadyRegistered
> +			 * @fwts-advice TPM node already registered. The same
> +			 * node is being registered twice or there is a
> +			 * tpm node duplicate in the device tree
> +			 */
> +			prlog(PR_WARNING, "TPM: tpm%d already registered\n",
> +			      tpm->id);
> +			return STB_ERROR;
> +		}
> +		i++;
> +	}
> +
> +	tpm = (struct tpm_chip*) malloc(sizeof(struct tpm_chip));
> +	assert(tpm);
> +	tpm->id = i;
> +
> +	tpm->enabled = true;
> +	tpm->node = node;
> +	tpm->dev = dev;
> +	tpm->driver = driver;
> +
> +	list_add_tail(&tpm_list, &tpm->link);
> +
> +	prlog(PR_NOTICE, "TPM: tpm%d registered: driver=%s\n",
> +	      tpm->id, tpm->driver->name);
> +
> +	return 0;
> +
> +disable:
> +	dt_add_property_string(node, "status", "disabled");
> +	prlog(PR_NOTICE, "TPM: tpm node %p disabled\n", node);
> +	free(tpm);
> +	return STB_ERROR;
> +}

Label is unused, so build fails:

	[CC]  libstb/tpm_chip.o
libstb/tpm_chip.c: In function ‘tpm_register_chip’:
libstb/tpm_chip.c:65:1: error: label ‘disable’ defined but not used [-Werror=unused-label]
 disable:
 ^~~~~~~

I have a patch for these two, which will mean they need to be
reintroduced elsewhere, also patch coming.


-- 
Stewart Smith
OPAL Architect, IBM.



More information about the Skiboot mailing list