2 * This file is part of the coreboot project.
4 * Copyright (C) 2003-2004 Linux Networx
5 * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
6 * Copyright (C) 2003 Greg Watson <jarrah@users.sourceforge.net>
7 * Copyright (C) 2004 Li-Ta Lo <ollie@lanl.gov>
8 * Copyright (C) 2005-2006 Tyan
9 * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
25 #include <device/device.h>
26 #include <device/path.h>
27 #include <device/pci.h>
28 #include <device/resource.h>
30 /** Linked list of ALL devices */
31 ROMSTAGE_CONST
struct device
* ROMSTAGE_CONST all_devices
= &dev_root
;
34 * Given a PCI bus and a devfn number, find the device structure.
36 * @param bus The bus number.
37 * @param devfn A device/function number.
38 * @return Pointer to the device structure (if found), 0 otherwise.
40 ROMSTAGE_CONST
struct device
*dev_find_slot(unsigned int bus
,
43 ROMSTAGE_CONST
struct device
*dev
, *result
;
46 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
47 if ((dev
->path
.type
== DEVICE_PATH_PCI
) &&
48 (dev
->bus
->secondary
== bus
) &&
49 (dev
->path
.pci
.devfn
== devfn
)) {
58 * Given a device pointer, find the next PCI device.
60 * @param previous_dev A pointer to a PCI device structure.
61 * @return Pointer to the next device structure (if found), 0 otherwise.
63 ROMSTAGE_CONST
struct device
*dev_find_next_pci_device(
64 ROMSTAGE_CONST
struct device
*previous_dev
)
66 ROMSTAGE_CONST
struct device
*dev
, *result
;
68 if (previous_dev
== NULL
)
69 previous_dev
= all_devices
;
72 for (dev
= previous_dev
->next
; dev
; dev
= dev
->next
) {
73 if (dev
->path
.type
== DEVICE_PATH_PCI
) {
82 * Given an SMBus bus and a device number, find the device structure.
84 * @param bus The bus number.
85 * @param addr A device number.
86 * @return Pointer to the device structure (if found), 0 otherwise.
88 ROMSTAGE_CONST
struct device
*dev_find_slot_on_smbus(unsigned int bus
,
91 ROMSTAGE_CONST
struct device
*dev
, *result
;
94 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
95 if ((dev
->path
.type
== DEVICE_PATH_I2C
) &&
96 (dev
->bus
->secondary
== bus
) &&
97 (dev
->path
.i2c
.device
== addr
)) {
106 * Given a PnP port and a device number, find the device structure.
108 * @param port The I/O port.
109 * @param device Logical device number.
110 * @return Pointer to the device structure (if found), 0 otherwise.
112 ROMSTAGE_CONST
struct device
*dev_find_slot_pnp(u16 port
, u16 device
)
114 ROMSTAGE_CONST
struct device
*dev
;
116 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
117 if ((dev
->path
.type
== DEVICE_PATH_PNP
) &&
118 (dev
->path
.pnp
.port
== port
) &&
119 (dev
->path
.pnp
.device
== device
)) {