Files
skiboot/hdata/hostservices.c
Thiago Jung Bauermann 5021a037a7 dt: Set new property length in dt_resize_property()
All callers of dt_resize_property() need to set the new property length
after calling it. append_chip_id() wasn't doing it, which caused this
assert when booting my machine:

[  136.387213258,3] Unable to use memory range 0 from MSAREA 0
[  136.387356677,3] Unable to use memory range 0 from MSAREA 2
[  136.387408390,3] ***********************************************
[  136.387454272,3] < assert failed at core/device.c:605 >
[  136.387493225,3]     .
[  136.387512799,3]      .
[  136.387534056,3]       .
[  136.387550294,3]         OO__)
[  136.387579530,3]        <"__/
[  136.387605086,3]         ^ ^
[  136.387719329,3] Fatal TRAP at 0000000030028a18   .dt_property_set_cell+0x34  MSR 9000000000021002
[  136.387801707,3] CFAR : 00000000300bfd3c MSR  : 9000000000001000
[  136.387847032,3] SRR0 : 0000000030028a18 SRR1 : 9000000000021002
[  136.387893119,3] HSRR0: 0000000030012524 HSRR1: 9000000000001000
[  136.387936830,3] DSISR: 40000000         DAR  : 00000002019df000
[  136.387983570,3] LR   : 00000000300bfd40 CTR  : 0000000000000000
[  136.388046031,3] CR   : 20004202         XER  : 00000000
[  136.388094553,3] GPR00: 00000000300bfd40 GPR16: 0000000000000001
[  136.388139862,3] GPR01: 0000000031e536e0 GPR17: 00000000300ca3c9
[  136.388181131,3] GPR02: 0000000030121200 GPR18: 0000000030103e1c
[  136.388224105,3] GPR03: 000000003053fc60 GPR19: 0000000000000008
[  136.388270356,3] GPR04: 0000000000000001 GPR20: 000000003053fba0
[  136.388313950,3] GPR05: 0000000000000008 GPR21: 0000000000000001
[  136.388363021,3] GPR06: 0000000031e50060 GPR22: 0000000000000001
[  136.388416754,3] GPR07: 0000000000000000 GPR23: 0000000000000000
[  136.388465729,3] GPR08: 0000000000000000 GPR24: 0000000000000000
[  136.388508156,3] GPR09: 0000000000000004 GPR25: 0000000031204060
[  136.388556203,3] GPR10: 0000000000000008 GPR26: 000000003120402c
[  136.388599076,3] GPR11: 0000000000000000 GPR27: 0000000030010000
[  136.388642108,3] GPR12: 0000000040004204 GPR28: 0000000000000002
[  136.388694064,3] GPR13: 0000000031e50000 GPR29: 0000000031203ee0
[  136.388743298,3] GPR14: 00000000300cbf03 GPR30: 0000000031202e80
[  136.388797131,3] GPR15: 00000000300cc01c GPR31: 0000000030103a33
CPU 0048 Backtrace:
 S: 0000000031e539e0 R: 0000000030028874   .dt_resize_property+0x28
 S: 0000000031e53a60 R: 00000000300bfd40   .memory_parse+0xd84
 S: 0000000031e53c40 R: 00000000300bc4d8   .parse_hdat+0xed0
 S: 0000000031e53e30 R: 000000003001504c   .main_cpu_entry+0x1ac
 S: 0000000031e53f00 R: 0000000030002760   boot_entry+0x1b0

Avoid further appearances of the unidentified animal of doom by making
dt_resize_property() do the length updating itself, freeing its callers
from that need.

Suggested-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
2020-06-30 12:07:23 +10:00

85 lines
2.0 KiB
C

// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
/* Copyright 2013-2017 IBM Corp. */
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <libfdt/libfdt.h>
#include <skiboot.h>
#include <device.h>
#include <compiler.h>
#include <hostservices.h>
#include "spira.h"
#include "hdata.h"
static void merge_property(const struct dt_node *src_root,
struct dt_node *dst_root,
const char *name)
{
const struct dt_property *src;
struct dt_property *dst;
/* Nothing to merge if old one doesn't exist. */
src = dt_find_property(src_root, name);
if (!src)
return;
/* Just create a new one if there's none in dst. */
dst = __dt_find_property(dst_root, name);
if (!dst) {
dt_add_property(dst_root, name, src->prop, src->len);
return;
}
/* Append src to dst. */
dt_resize_property(&dst, dst->len + src->len);
memcpy(dst->prop + dst->len, src->prop, src->len);
}
static void hservice_parse_dt_tree(const struct dt_node *src)
{
const struct dt_property *sprop;
/* Copy/merge reserved names & ranges properties. */
list_for_each(&src->properties, sprop, list) {
if (streq(sprop->name, "reserved-names") ||
streq(sprop->name, "reserved-ranges") ||
streq(sprop->name, "ibm,enabled-idle-states"))
merge_property(src, dt_root, sprop->name);
}
}
/* Get host services information from hdat. */
bool hservices_from_hdat(const void *fdt, size_t size)
{
int err;
struct dt_node *hservices;
prlog(PR_DEBUG, "HBRT: Found mini-DT at 0x%p size: 0x%08lx\n",
fdt, size);
/* For diagnostic purposes, we copy the whole blob over */
dt_add_property(dt_root, "ibm,hbrt-mini-fdt", fdt, size);
/* Parse & extract relevant properties */
err = fdt_check_header(fdt);
if (err) {
prerror("HBRT: fdt blob %p hdr error %d\n", fdt, err);
return false;
}
hservices = dt_new_root("ibm,hostservices");
err = dt_expand_node(hservices, fdt, 0);
if (err < 0) {
prerror("HBRT: fdt blob %p parse error %d\n", fdt, err);
return false;
}
hservice_parse_dt_tree(hservices);
dt_free(hservices);
return true;
}