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.
21 #include <device/device.h>
22 #include <device/path.h>
23 #include <device/pci.h>
24 #include <device/resource.h>
26 /** Linked list of ALL devices */
27 ROMSTAGE_CONST
struct device
* ROMSTAGE_CONST all_devices
= &dev_root
;
30 * Given a PCI bus and a devfn number, find the device structure.
32 * @param bus The bus number.
33 * @param devfn A device/function number.
34 * @return Pointer to the device structure (if found), 0 otherwise.
36 ROMSTAGE_CONST
struct device
*dev_find_slot(unsigned int bus
,
39 ROMSTAGE_CONST
struct device
*dev
, *result
;
42 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
43 if ((dev
->path
.type
== DEVICE_PATH_PCI
) &&
44 (dev
->bus
->secondary
== bus
) &&
45 (dev
->path
.pci
.devfn
== devfn
)) {
54 * Given a device pointer, find the next PCI device.
56 * @param previous_dev A pointer to a PCI device structure.
57 * @return Pointer to the next device structure (if found), 0 otherwise.
59 ROMSTAGE_CONST
struct device
*dev_find_next_pci_device(
60 ROMSTAGE_CONST
struct device
*previous_dev
)
62 ROMSTAGE_CONST
struct device
*dev
, *result
;
64 if (previous_dev
== NULL
)
65 previous_dev
= all_devices
;
68 for (dev
= previous_dev
->next
; dev
; dev
= dev
->next
) {
69 if (dev
->path
.type
== DEVICE_PATH_PCI
) {
78 * Given an SMBus bus and a device number, find the device structure.
80 * @param bus The bus number.
81 * @param addr A device number.
82 * @return Pointer to the device structure (if found), 0 otherwise.
84 ROMSTAGE_CONST
struct device
*dev_find_slot_on_smbus(unsigned int bus
,
87 ROMSTAGE_CONST
struct device
*dev
, *result
;
90 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
91 if ((dev
->path
.type
== DEVICE_PATH_I2C
) &&
92 (dev
->bus
->secondary
== bus
) &&
93 (dev
->path
.i2c
.device
== addr
)) {
102 * Given a PnP port and a device number, find the device structure.
104 * @param port The I/O port.
105 * @param device Logical device number.
106 * @return Pointer to the device structure (if found), 0 otherwise.
108 ROMSTAGE_CONST
struct device
*dev_find_slot_pnp(u16 port
, u16 device
)
110 ROMSTAGE_CONST
struct device
*dev
;
112 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
113 if ((dev
->path
.type
== DEVICE_PATH_PNP
) &&
114 (dev
->path
.pnp
.port
== port
) &&
115 (dev
->path
.pnp
.device
== device
)) {