Skip to content

Commit

Permalink
From patchwork series 398582
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox Snowpatch committed Mar 11, 2024
1 parent 484dba3 commit 6fa7de5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 36 deletions.
20 changes: 18 additions & 2 deletions Documentation/devicetree/bindings/tpm/ibm,vtpm.yaml
Expand Up @@ -74,8 +74,6 @@ required:
- ibm,my-dma-window
- ibm,my-drc-index
- ibm,loc-code
- linux,sml-base
- linux,sml-size

allOf:
- $ref: tpm-common.yaml#
Expand All @@ -102,3 +100,21 @@ examples:
linux,sml-size = <0xbce10200>;
};
};
- |
soc {
#address-cells = <1>;
#size-cells = <0>;
tpm@30000003 {
compatible = "IBM,vtpm20";
device_type = "IBM,vtpm";
reg = <0x30000003>;
interrupts = <0xa0003 0x0>;
ibm,#dma-address-cells = <0x2>;
ibm,#dma-size-cells = <0x2>;
ibm,my-dma-window = <0x10000003 0x0 0x0 0x0 0x10000000>;
ibm,my-drc-index = <0x30000003>;
ibm,loc-code = "U9080.HEX.134CA08-V7-C3";
linux,sml-log = <00 00 00 00 03 00 00>;
};
};
14 changes: 13 additions & 1 deletion Documentation/devicetree/bindings/tpm/tpm-common.yaml
Expand Up @@ -30,6 +30,11 @@ properties:
size of reserved memory allocated for firmware event log
$ref: /schemas/types.yaml#/definitions/uint32

linux,sml-log:
description:
Content of firmware event log
$ref: /schemas/types.yaml#/definitions/uint8-array

memory-region:
description: reserved memory allocated for firmware event log
maxItems: 1
Expand All @@ -53,15 +58,22 @@ dependentRequired:
linux,sml-base: ['linux,sml-size']
linux,sml-size: ['linux,sml-base']

# must only have either memory-region or linux,sml-base
# must only have either memory-region or linux,sml-base/size or linux,sml-log
# as well as either resets or reset-gpios
dependentSchemas:
memory-region:
properties:
linux,sml-base: false
linux,sml-log: false
linux,sml-base:
properties:
memory-region: false
linux,sml-log: false
linux,sml-log:
properties:
memory-region: false
linux,sml-base: false
linux,sml-size: false
resets:
properties:
reset-gpios: false
Expand Down
27 changes: 19 additions & 8 deletions arch/powerpc/kernel/prom_init.c
Expand Up @@ -211,6 +211,8 @@ static cell_t __prombss regbuf[1024];

static bool __prombss rtas_has_query_cpu_stopped;

static u64 __prombss sml_base;
static u32 __prombss sml_size;

/*
* Error results ... some OF calls will return "-1" on error, some
Expand Down Expand Up @@ -1962,17 +1964,15 @@ static void __init prom_instantiate_sml(void)
}
prom_printf(" done\n");

reserve_mem(base, size);

prom_setprop(ibmvtpm_node, "/vdevice/vtpm", "linux,sml-base",
&base, sizeof(base));
prom_setprop(ibmvtpm_node, "/vdevice/vtpm", "linux,sml-size",
&size, sizeof(size));

prom_debug("sml base = 0x%llx\n", base);
/* Add property now, defer adding log to tree flattening phase */
prom_setprop(ibmvtpm_node, "/vdevice/vtpm", "linux,sml-log",
NULL, 0);
prom_debug("sml size = 0x%x\n", size);

prom_debug("prom_instantiate_sml: end...\n");

sml_base = base;
sml_size = size;
}

/*
Expand Down Expand Up @@ -2653,6 +2653,17 @@ static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start,
}
prev_name = sstart + soff;

if (!prom_strcmp("linux,sml-log", pname)) {
/* push property head */
dt_push_token(OF_DT_PROP, mem_start, mem_end);
dt_push_token(sml_size, mem_start, mem_end);
dt_push_token(soff, mem_start, mem_end);
/* push property content */
valp = make_room(mem_start, mem_end, sml_size, 1);
memcpy(valp, (void *)sml_base, sml_size);

Check failure on line 2663 in arch/powerpc/kernel/prom_init.c

View workflow job for this annotation

GitHub Actions / kernel (pmac32_defconfig, fedora-38, /linux/arch/powerpc/configs/pmac32-qemu.config)

cast to pointer from integer of different size [-Werror=int-to-pointer-cast]

Check failure on line 2663 in arch/powerpc/kernel/prom_init.c

View workflow job for this annotation

GitHub Actions / kernel (pmac32_defconfig, korg-5.5.0, /linux/arch/powerpc/configs/pmac32-qemu.config)

cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
*mem_start = ALIGN(*mem_start, 4);
continue;
}
/* get length */
l = call_prom("getproplen", 2, 1, node, pname);

Expand Down
36 changes: 11 additions & 25 deletions drivers/char/tpm/eventlog/of.c
Expand Up @@ -54,8 +54,8 @@ int tpm_read_log_of(struct tpm_chip *chip)
const u32 *sizep;
const u64 *basep;
struct tpm_bios_log *log;
const void *logp;
u32 size;
u64 base;

log = &chip->log;
if (chip->dev.parent && chip->dev.parent->of_node)
Expand All @@ -66,37 +66,23 @@ int tpm_read_log_of(struct tpm_chip *chip)
if (of_property_read_bool(np, "powered-while-suspended"))
chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED;

sizep = of_get_property(np, "linux,sml-size", NULL);
basep = of_get_property(np, "linux,sml-base", NULL);
if (sizep == NULL && basep == NULL)
return tpm_read_log_memory_region(chip);
if (sizep == NULL || basep == NULL)
return -EIO;

/*
* For both vtpm/tpm, firmware has log addr and log size in big
* endian format. But in case of vtpm, there is a method called
* sml-handover which is run during kernel init even before
* device tree is setup. This sml-handover function takes care
* of endianness and writes to sml-base and sml-size in little
* endian format. For this reason, vtpm doesn't need conversion
* but physical tpm needs the conversion.
*/
if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0 &&
of_property_match_string(np, "compatible", "IBM,vtpm20") < 0) {
logp = of_get_property(np, "linux,sml-log", &size);
if (logp == NULL) {
sizep = of_get_property(np, "linux,sml-size", NULL);
basep = of_get_property(np, "linux,sml-base", NULL);
if (sizep == NULL && basep == NULL)
return tpm_read_log_memory_region(chip);
if (sizep == NULL || basep == NULL)
return -EIO;
size = be32_to_cpup((__force __be32 *)sizep);
base = be64_to_cpup((__force __be64 *)basep);
} else {
size = *sizep;
base = *basep;
logp = __va(be64_to_cpup((__force __be64 *)basep));
}

if (size == 0) {
dev_warn(&chip->dev, "%s: Event log area empty\n", __func__);
return -EIO;
}

log->bios_event_log = devm_kmemdup(&chip->dev, __va(base), size, GFP_KERNEL);
log->bios_event_log = devm_kmemdup(&chip->dev, logp, size, GFP_KERNEL);
if (!log->bios_event_log)
return -ENOMEM;

Expand Down

0 comments on commit 6fa7de5

Please sign in to comment.