coreboot-kgpe-d16/util/sconfig
Furquan Shaikh bbade24241 util/sconfig: Drop use of ref_count for chip_instance
chip_instance structure currently uses a ref_count to determine how
many devices hold reference to that instance. If the count drops to
zero, then it is assumed that the chip instance is a duplicate in
override tree and has a similar instance that is already overriden in
base device tree.

ref_count is currently decremented whenever a device in override tree
matches the one in base device tree and the registers from the
override tree instance are copied over to the base tree instance. On
the other hand, if a device in override tree does not match any device
in base tree under a given parent, then the device is added to base
tree and all the devices in its subtree that hold pointers to its
parent chip instance are updated to point to the parent's chip
instance in base tree. This is done as part of update_chip_pointers.

However, there are a couple of issues that this suffers from:
a) If a device is present only in override tree and it does not have
its own chip (i.e. pointing to parent's chip instance), then it
results in sconfig emiiting parent's chip instance (which can be the
SoC chip instance) in static.c even though it is unused. This is
because update_chip_pointers() does not call delete_chip_instance()
before reassigning the chip instance pointer.
b) If a device is added under root device only in the override tree
and it does not have its own chip instance (i.e. uses SoC chip
instance), then it results in sconfig emitting a copy of the SoC chip
instance and setting that as chip_ops for this new device in the
override tree.

In order to fix the above issues, this change drops the ref_count
field from chip_instance structure and instead adds a forwarding
pointer `base_chip_instance`. This is setup as per the following
rules:
1. If the instance belongs to base devicetree, base_chip_instance is
set to NULL.
2. If the instance belongs to override tree, then it is set to its
corresponding chip instance in base tree (if present), else set to
NULL.

State of base_chip_instance is then used when emitting chips and
devices using the following rules:
1. If a chip_instance has non-NULL base_chip_instance, then that chip
instance is not emitted to static.c
2. When emitting chip_ops for a device, base_chip_instance is used to
determine the correct chip instance name to emit.

BUG=b:155549176
TEST=Verified that the static.c file generated for base/override tree
combination is correct when new devices without chips are added only
to override tree.

Change-Id: Idbb5b34f49bf874da3f30ebb6a6a0e2d8d091fe5
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41007
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-05-07 11:55:55 +00:00
..
Makefile.inc commonlib: Add commonlib/bsd 2020-01-28 06:36:13 +00:00
description.md util: Add description.md to each util 2018-07-26 13:26:50 +00:00
lex.yy.c_shipped Add configurable ramstage support for minimal PCI scanning 2020-02-08 18:57:36 +00:00
main.c util/sconfig: Drop use of ref_count for chip_instance 2020-05-07 11:55:55 +00:00
sconfig.h util/sconfig: Drop use of ref_count for chip_instance 2020-05-07 11:55:55 +00:00
sconfig.l Add configurable ramstage support for minimal PCI scanning 2020-02-08 18:57:36 +00:00
sconfig.tab.c_shipped sconfig: Allow `register` entries below devices, too 2020-05-05 13:03:29 +00:00
sconfig.tab.h_shipped sconfig: Allow `register` entries below devices, too 2020-05-05 13:03:29 +00:00
sconfig.y sconfig: Allow `register` entries below devices, too 2020-05-05 13:03:29 +00:00