device: Move find_dev_path() to device_const.c
Change-Id: I8a27aa7157b5706623272ba9354ed8dff9b8184f Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: https://review.coreboot.org/26446 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
parent
f6a4344c5b
commit
2df1c124c4
|
@ -18,6 +18,7 @@
|
|||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <console/console.h>
|
||||
#include <device/device.h>
|
||||
#include <device/path.h>
|
||||
#include <device/pci.h>
|
||||
|
@ -89,6 +90,88 @@ DEVTREE_CONST struct device *dev_find_next_pci_device(
|
|||
return dev_find_path(previous_dev, DEVICE_PATH_PCI);
|
||||
}
|
||||
|
||||
static int path_eq(const struct device_path *path1,
|
||||
const struct device_path *path2)
|
||||
{
|
||||
int equal = 0;
|
||||
|
||||
if (path1->type != path2->type)
|
||||
return 0;
|
||||
|
||||
switch (path1->type) {
|
||||
case DEVICE_PATH_NONE:
|
||||
break;
|
||||
case DEVICE_PATH_ROOT:
|
||||
equal = 1;
|
||||
break;
|
||||
case DEVICE_PATH_PCI:
|
||||
equal = (path1->pci.devfn == path2->pci.devfn);
|
||||
break;
|
||||
case DEVICE_PATH_PNP:
|
||||
equal = (path1->pnp.port == path2->pnp.port) &&
|
||||
(path1->pnp.device == path2->pnp.device);
|
||||
break;
|
||||
case DEVICE_PATH_I2C:
|
||||
equal = (path1->i2c.device == path2->i2c.device) &&
|
||||
(path1->i2c.mode_10bit == path2->i2c.mode_10bit);
|
||||
break;
|
||||
case DEVICE_PATH_APIC:
|
||||
equal = (path1->apic.apic_id == path2->apic.apic_id);
|
||||
break;
|
||||
case DEVICE_PATH_DOMAIN:
|
||||
equal = (path1->domain.domain == path2->domain.domain);
|
||||
break;
|
||||
case DEVICE_PATH_CPU_CLUSTER:
|
||||
equal = (path1->cpu_cluster.cluster
|
||||
== path2->cpu_cluster.cluster);
|
||||
break;
|
||||
case DEVICE_PATH_CPU:
|
||||
equal = (path1->cpu.id == path2->cpu.id);
|
||||
break;
|
||||
case DEVICE_PATH_CPU_BUS:
|
||||
equal = (path1->cpu_bus.id == path2->cpu_bus.id);
|
||||
break;
|
||||
case DEVICE_PATH_GENERIC:
|
||||
equal = (path1->generic.id == path2->generic.id) &&
|
||||
(path1->generic.subid == path2->generic.subid);
|
||||
break;
|
||||
case DEVICE_PATH_SPI:
|
||||
equal = (path1->spi.cs == path2->spi.cs);
|
||||
break;
|
||||
case DEVICE_PATH_USB:
|
||||
equal = (path1->usb.port_type == path2->usb.port_type) &&
|
||||
(path1->usb.port_id == path2->usb.port_id);
|
||||
break;
|
||||
case DEVICE_PATH_MMIO:
|
||||
equal = (path1->mmio.addr == path2->mmio.addr);
|
||||
break;
|
||||
default:
|
||||
printk(BIOS_ERR, "Unknown device type: %d\n", path1->type);
|
||||
break;
|
||||
}
|
||||
|
||||
return equal;
|
||||
}
|
||||
|
||||
/**
|
||||
* See if a device structure exists for path.
|
||||
*
|
||||
* @param parent The bus to find the device on.
|
||||
* @param path The relative path from the bus to the appropriate device.
|
||||
* @return Pointer to a device structure for the device on bus at path
|
||||
* or 0/NULL if no device is found.
|
||||
*/
|
||||
DEVTREE_CONST struct device *find_dev_path(
|
||||
const struct bus *parent, const struct device_path *path)
|
||||
{
|
||||
DEVTREE_CONST struct device *child;
|
||||
for (child = parent->children; child; child = child->sibling) {
|
||||
if (path_eq(path, &child->path))
|
||||
break;
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an SMBus bus and a device number, find the device structure.
|
||||
*
|
||||
|
|
|
@ -25,24 +25,6 @@
|
|||
#include <device/resource.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* See if a device structure exists for path.
|
||||
*
|
||||
* @param parent The bus to find the device on.
|
||||
* @param path The relative path from the bus to the appropriate device.
|
||||
* @return Pointer to a device structure for the device on bus at path
|
||||
* or 0/NULL if no device is found.
|
||||
*/
|
||||
struct device *find_dev_path(struct bus *parent, struct device_path *path)
|
||||
{
|
||||
struct device *child;
|
||||
for (child = parent->children; child; child = child->sibling) {
|
||||
if (path_eq(path, &child->path))
|
||||
break;
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a Local APIC ID, find the device structure.
|
||||
*
|
||||
|
@ -277,68 +259,6 @@ const char *bus_path(struct bus *bus)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
int path_eq(struct device_path *path1, struct device_path *path2)
|
||||
{
|
||||
int equal = 0;
|
||||
|
||||
if (path1->type != path2->type)
|
||||
return 0;
|
||||
|
||||
switch (path1->type) {
|
||||
case DEVICE_PATH_NONE:
|
||||
break;
|
||||
case DEVICE_PATH_ROOT:
|
||||
equal = 1;
|
||||
break;
|
||||
case DEVICE_PATH_PCI:
|
||||
equal = (path1->pci.devfn == path2->pci.devfn);
|
||||
break;
|
||||
case DEVICE_PATH_PNP:
|
||||
equal = (path1->pnp.port == path2->pnp.port) &&
|
||||
(path1->pnp.device == path2->pnp.device);
|
||||
break;
|
||||
case DEVICE_PATH_I2C:
|
||||
equal = (path1->i2c.device == path2->i2c.device) &&
|
||||
(path1->i2c.mode_10bit == path2->i2c.mode_10bit);
|
||||
break;
|
||||
case DEVICE_PATH_APIC:
|
||||
equal = (path1->apic.apic_id == path2->apic.apic_id);
|
||||
break;
|
||||
case DEVICE_PATH_DOMAIN:
|
||||
equal = (path1->domain.domain == path2->domain.domain);
|
||||
break;
|
||||
case DEVICE_PATH_CPU_CLUSTER:
|
||||
equal = (path1->cpu_cluster.cluster
|
||||
== path2->cpu_cluster.cluster);
|
||||
break;
|
||||
case DEVICE_PATH_CPU:
|
||||
equal = (path1->cpu.id == path2->cpu.id);
|
||||
break;
|
||||
case DEVICE_PATH_CPU_BUS:
|
||||
equal = (path1->cpu_bus.id == path2->cpu_bus.id);
|
||||
break;
|
||||
case DEVICE_PATH_GENERIC:
|
||||
equal = (path1->generic.id == path2->generic.id) &&
|
||||
(path1->generic.subid == path2->generic.subid);
|
||||
break;
|
||||
case DEVICE_PATH_SPI:
|
||||
equal = (path1->spi.cs == path2->spi.cs);
|
||||
break;
|
||||
case DEVICE_PATH_USB:
|
||||
equal = (path1->usb.port_type == path2->usb.port_type) &&
|
||||
(path1->usb.port_id == path2->usb.port_id);
|
||||
break;
|
||||
case DEVICE_PATH_MMIO:
|
||||
equal = (path1->mmio.addr == path2->mmio.addr);
|
||||
break;
|
||||
default:
|
||||
printk(BIOS_ERR, "Unknown device type: %d\n", path1->type);
|
||||
break;
|
||||
}
|
||||
|
||||
return equal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate 64 more resources to the free list.
|
||||
*
|
||||
|
|
|
@ -196,7 +196,9 @@ bool dev_is_active_bridge(struct device *dev);
|
|||
void run_bios(struct device *dev, unsigned long addr);
|
||||
|
||||
/* Helper functions */
|
||||
struct device *find_dev_path(struct bus *parent, struct device_path *path);
|
||||
DEVTREE_CONST struct device *find_dev_path(
|
||||
const struct bus *parent,
|
||||
const struct device_path *path);
|
||||
struct device *alloc_find_dev(struct bus *parent, struct device_path *path);
|
||||
struct device *dev_find_device(u16 vendor, u16 device, struct device *from);
|
||||
struct device *dev_find_class(unsigned int class, struct device *from);
|
||||
|
|
|
@ -125,7 +125,6 @@ struct device_path {
|
|||
#define DEVICE_PATH_MAX 30
|
||||
#define BUS_PATH_MAX (DEVICE_PATH_MAX+10)
|
||||
|
||||
extern int path_eq(struct device_path *path1, struct device_path *path2);
|
||||
extern const char *dev_path_name(enum device_path_type type);
|
||||
|
||||
#endif /* DEVICE_PATH_H */
|
||||
|
|
Loading…
Reference in New Issue