<p>Duncan Laurie has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/26487">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">acpi: device: Walk up the tree to find identifier<br><br>Instead of just checking the immediate parent for an device name,<br>walk up the tree to check if any parent can identify the device.<br><br>This allows devices to be nested more than one level deep and<br>still have them identified in one place by the SOC.<br><br>The recursive method calling this function has been changed to<br>handle a null return from acpi_device_name and abort instead of<br>continuing and perhaps forming an invalid ACPI path.<br><br>Change-Id: Ic17c5b6facdcb1a0ac696912867d62652b2bf18e<br>Signed-off-by: Duncan Laurie <dlaurie@google.com><br>---<br>M src/arch/x86/acpi_device.c<br>1 file changed, 22 insertions(+), 7 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/87/26487/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/arch/x86/acpi_device.c b/src/arch/x86/acpi_device.c</span><br><span>index c8d313e..c838015 100644</span><br><span>--- a/src/arch/x86/acpi_device.c</span><br><span>+++ b/src/arch/x86/acpi_device.c</span><br><span>@@ -55,6 +55,9 @@</span><br><span> /* Locate and return the ACPI name for this device */</span><br><span> const char *acpi_device_name(struct device *dev)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct device *pdev = dev;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *name;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (!dev)</span><br><span> return NULL;</span><br><span> </span><br><span>@@ -62,30 +65,42 @@</span><br><span> if (dev->ops->acpi_name)</span><br><span> return dev->ops->acpi_name(dev);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- /* Check parent device in case it has a global handler */</span><br><span style="color: hsl(0, 100%, 40%);">- if (dev->bus && dev->bus->dev->ops->acpi_name)</span><br><span style="color: hsl(0, 100%, 40%);">- return dev->bus->dev->ops->acpi_name(dev);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Walk up the tree to find if any parent can identify this device */</span><br><span style="color: hsl(120, 100%, 40%);">+ while (pdev->bus) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (pdev->path.type == DEVICE_PATH_ROOT)</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (pdev->bus->dev->ops && pdev->bus->dev->ops->acpi_name)</span><br><span style="color: hsl(120, 100%, 40%);">+ name = pdev->bus->dev->ops->acpi_name(dev);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (name)</span><br><span style="color: hsl(120, 100%, 40%);">+ return name;</span><br><span style="color: hsl(120, 100%, 40%);">+ pdev = pdev->bus->dev;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span> /* Recursive function to find the root device and print a path from there */</span><br><span style="color: hsl(0, 100%, 40%);">-static size_t acpi_device_path_fill(struct device *dev, char *buf,</span><br><span style="color: hsl(0, 100%, 40%);">- size_t buf_len, size_t cur)</span><br><span style="color: hsl(120, 100%, 40%);">+static ssize_t acpi_device_path_fill(struct device *dev, char *buf,</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t buf_len, size_t cur)</span><br><span> {</span><br><span> const char *name = acpi_device_name(dev);</span><br><span style="color: hsl(0, 100%, 40%);">- size_t next = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ ssize_t next = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!name)</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span> </span><br><span> /*</span><br><span> * Make sure this name segment will fit, including the path segment</span><br><span> * separator and possible NUL terminator if this is the last segment.</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">- if (!dev || !name || (cur + strlen(name) + 2) > buf_len)</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!dev || (cur + strlen(name) + 2) > buf_len)</span><br><span> return cur;</span><br><span> </span><br><span> /* Walk up the tree to the root device */</span><br><span> if (dev->path.type != DEVICE_PATH_ROOT && dev->bus && dev->bus->dev)</span><br><span> next = acpi_device_path_fill(dev->bus->dev, buf, buf_len, cur);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (next < 0)</span><br><span style="color: hsl(120, 100%, 40%);">+ return next;</span><br><span> </span><br><span> /* Fill in the path from the root device */</span><br><span> next += snprintf(buf + next, buf_len - next, "%s%s",</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/26487">change 26487</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/26487"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ic17c5b6facdcb1a0ac696912867d62652b2bf18e </div>
<div style="display:none"> Gerrit-Change-Number: 26487 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Duncan Laurie <dlaurie@chromium.org> </div>