From 81ec9c0500e4b53440579ffad0011a6b077b6bdb Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Tue, 15 May 2018 14:09:37 +0200 Subject: device: Rename device_simple.c --> device_const.c In early stages (pre ramstage), we have two notions of devices. To access the hardware, "simple device" handles are used. These are plain numbers. To access the static information of the device tree, we use `struct device` pointers. This is referred to as DEVTREE_EARLY in the code. This file is about the latter and its name reflects that the tree remains unmodified. Change-Id: I31aeb118615e86026f7111f83a7866d4e7426170 Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/26293 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber Reviewed-by: Aaron Durbin --- src/device/Makefile.inc | 12 ++--- src/device/device_const.c | 120 +++++++++++++++++++++++++++++++++++++++++++++ src/device/device_simple.c | 120 --------------------------------------------- 3 files changed, 126 insertions(+), 126 deletions(-) create mode 100644 src/device/device_const.c delete mode 100644 src/device/device_simple.c (limited to 'src') diff --git a/src/device/Makefile.inc b/src/device/Makefile.inc index e86aa2cdfd..05dbe742fb 100644 --- a/src/device/Makefile.inc +++ b/src/device/Makefile.inc @@ -21,12 +21,12 @@ ifeq ($(CONFIG_AZALIA_PLUGIN_SUPPORT),y) ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/hda_verb.c endif -bootblock-y += device_simple.c -postcar-y += device_simple.c -smm-y += device_simple.c -verstage-y += device_simple.c -romstage-y += device_simple.c -ramstage-y += device_simple.c +bootblock-y += device_const.c +postcar-y += device_const.c +smm-y += device_const.c +verstage-y += device_const.c +romstage-y += device_const.c +ramstage-y += device_const.c romstage-$(CONFIG_PCI) += pci_early.c subdirs-y += oprom dram diff --git a/src/device/device_const.c b/src/device/device_const.c new file mode 100644 index 0000000000..2cacb4a9ac --- /dev/null +++ b/src/device/device_const.c @@ -0,0 +1,120 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2003-2004 Linux Networx + * (Written by Eric Biederman for Linux Networx) + * Copyright (C) 2003 Greg Watson + * Copyright (C) 2004 Li-Ta Lo + * Copyright (C) 2005-2006 Tyan + * (Written by Yinghai Lu for Tyan) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include + +/** Linked list of ALL devices */ +DEVTREE_CONST struct device * DEVTREE_CONST all_devices = &dev_root; + +/** + * Given a PCI bus and a devfn number, find the device structure. + * + * @param bus The bus number. + * @param devfn A device/function number. + * @return Pointer to the device structure (if found), 0 otherwise. + */ +DEVTREE_CONST struct device *dev_find_slot(unsigned int bus, + unsigned int devfn) +{ + DEVTREE_CONST struct device *dev, *result; + + result = 0; + for (dev = all_devices; dev; dev = dev->next) { + if ((dev->path.type == DEVICE_PATH_PCI) && + (dev->bus->secondary == bus) && + (dev->path.pci.devfn == devfn)) { + result = dev; + break; + } + } + return result; +} + +/** + * Given a device pointer, find the next PCI device. + * + * @param previous_dev A pointer to a PCI device structure. + * @return Pointer to the next device structure (if found), 0 otherwise. + */ +DEVTREE_CONST struct device *dev_find_next_pci_device( + DEVTREE_CONST struct device *previous_dev) +{ + DEVTREE_CONST struct device *dev, *result; + + if (previous_dev == NULL) + previous_dev = all_devices; + + result = 0; + for (dev = previous_dev->next; dev; dev = dev->next) { + if (dev->path.type == DEVICE_PATH_PCI) { + result = dev; + break; + } + } + return result; +} + +/** + * Given an SMBus bus and a device number, find the device structure. + * + * @param bus The bus number. + * @param addr A device number. + * @return Pointer to the device structure (if found), 0 otherwise. + */ +DEVTREE_CONST struct device *dev_find_slot_on_smbus(unsigned int bus, + unsigned int addr) +{ + DEVTREE_CONST struct device *dev, *result; + + result = 0; + for (dev = all_devices; dev; dev = dev->next) { + if ((dev->path.type == DEVICE_PATH_I2C) && + (dev->bus->secondary == bus) && + (dev->path.i2c.device == addr)) { + result = dev; + break; + } + } + return result; +} + +/** + * Given a PnP port and a device number, find the device structure. + * + * @param port The I/O port. + * @param device Logical device number. + * @return Pointer to the device structure (if found), 0 otherwise. + */ +DEVTREE_CONST struct device *dev_find_slot_pnp(u16 port, u16 device) +{ + DEVTREE_CONST struct device *dev; + + for (dev = all_devices; dev; dev = dev->next) { + if ((dev->path.type == DEVICE_PATH_PNP) && + (dev->path.pnp.port == port) && + (dev->path.pnp.device == device)) { + return dev; + } + } + return 0; +} diff --git a/src/device/device_simple.c b/src/device/device_simple.c deleted file mode 100644 index 2cacb4a9ac..0000000000 --- a/src/device/device_simple.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * This file is part of the coreboot project. - * - * Copyright (C) 2003-2004 Linux Networx - * (Written by Eric Biederman for Linux Networx) - * Copyright (C) 2003 Greg Watson - * Copyright (C) 2004 Li-Ta Lo - * Copyright (C) 2005-2006 Tyan - * (Written by Yinghai Lu for Tyan) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include -#include -#include -#include - -/** Linked list of ALL devices */ -DEVTREE_CONST struct device * DEVTREE_CONST all_devices = &dev_root; - -/** - * Given a PCI bus and a devfn number, find the device structure. - * - * @param bus The bus number. - * @param devfn A device/function number. - * @return Pointer to the device structure (if found), 0 otherwise. - */ -DEVTREE_CONST struct device *dev_find_slot(unsigned int bus, - unsigned int devfn) -{ - DEVTREE_CONST struct device *dev, *result; - - result = 0; - for (dev = all_devices; dev; dev = dev->next) { - if ((dev->path.type == DEVICE_PATH_PCI) && - (dev->bus->secondary == bus) && - (dev->path.pci.devfn == devfn)) { - result = dev; - break; - } - } - return result; -} - -/** - * Given a device pointer, find the next PCI device. - * - * @param previous_dev A pointer to a PCI device structure. - * @return Pointer to the next device structure (if found), 0 otherwise. - */ -DEVTREE_CONST struct device *dev_find_next_pci_device( - DEVTREE_CONST struct device *previous_dev) -{ - DEVTREE_CONST struct device *dev, *result; - - if (previous_dev == NULL) - previous_dev = all_devices; - - result = 0; - for (dev = previous_dev->next; dev; dev = dev->next) { - if (dev->path.type == DEVICE_PATH_PCI) { - result = dev; - break; - } - } - return result; -} - -/** - * Given an SMBus bus and a device number, find the device structure. - * - * @param bus The bus number. - * @param addr A device number. - * @return Pointer to the device structure (if found), 0 otherwise. - */ -DEVTREE_CONST struct device *dev_find_slot_on_smbus(unsigned int bus, - unsigned int addr) -{ - DEVTREE_CONST struct device *dev, *result; - - result = 0; - for (dev = all_devices; dev; dev = dev->next) { - if ((dev->path.type == DEVICE_PATH_I2C) && - (dev->bus->secondary == bus) && - (dev->path.i2c.device == addr)) { - result = dev; - break; - } - } - return result; -} - -/** - * Given a PnP port and a device number, find the device structure. - * - * @param port The I/O port. - * @param device Logical device number. - * @return Pointer to the device structure (if found), 0 otherwise. - */ -DEVTREE_CONST struct device *dev_find_slot_pnp(u16 port, u16 device) -{ - DEVTREE_CONST struct device *dev; - - for (dev = all_devices; dev; dev = dev->next) { - if ((dev->path.type == DEVICE_PATH_PNP) && - (dev->path.pnp.port == port) && - (dev->path.pnp.device == device)) { - return dev; - } - } - return 0; -} -- cgit v1.2.3