2020-04-02 23:48:16 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2010-11-05 00:23:47 +01:00
|
|
|
|
|
|
|
/*
|
2019-09-16 05:57:18 +02:00
|
|
|
* Originally based on the Linux kernel (arch/i386/kernel/pci-pc.c).
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <console/console.h>
|
2003-04-24 08:25:08 +02:00
|
|
|
#include <device/device.h>
|
2014-02-12 13:18:50 +01:00
|
|
|
#include <device/pci_def.h>
|
2004-05-14 19:20:29 +02:00
|
|
|
#include <device/pci_ids.h>
|
2020-01-04 15:15:50 +01:00
|
|
|
#include <post.h>
|
2003-09-02 05:36:25 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2004-10-14 23:25:53 +02:00
|
|
|
#include <smp/spinlock.h>
|
2020-06-08 05:05:03 +02:00
|
|
|
#if ENV_X86
|
2012-01-17 18:03:11 +01:00
|
|
|
#include <arch/ebda.h>
|
|
|
|
#endif
|
2013-04-30 22:41:13 +02:00
|
|
|
#include <timer.h>
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/** Pointer to the last device */
|
2010-09-01 23:03:03 +02:00
|
|
|
extern struct device *last_dev;
|
2010-05-21 16:33:48 +02:00
|
|
|
/** Linked list of free resources */
|
|
|
|
struct resource *free_resources = NULL;
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2012-07-25 10:33:05 +02:00
|
|
|
/**
|
|
|
|
* Initialize all chips of statically known devices.
|
|
|
|
*
|
|
|
|
* Will be called before bus enumeration to initialize chips stated in the
|
|
|
|
* device tree.
|
|
|
|
*/
|
|
|
|
void dev_initialize_chips(void)
|
|
|
|
{
|
2018-04-26 00:00:22 +02:00
|
|
|
const struct device *dev;
|
2012-07-25 10:33:05 +02:00
|
|
|
|
|
|
|
for (dev = all_devices; dev; dev = dev->next) {
|
|
|
|
/* Initialize chip if we haven't yet. */
|
|
|
|
if (dev->chip_ops && dev->chip_ops->init &&
|
|
|
|
!dev->chip_ops->initialized) {
|
2013-06-10 19:34:20 +02:00
|
|
|
post_log_path(dev);
|
2012-07-25 10:33:05 +02:00
|
|
|
dev->chip_ops->init(dev->chip_info);
|
|
|
|
dev->chip_ops->initialized = 1;
|
|
|
|
}
|
|
|
|
}
|
2013-06-10 19:34:20 +02:00
|
|
|
post_log_clear();
|
2012-07-25 10:33:05 +02:00
|
|
|
}
|
|
|
|
|
2013-10-30 00:32:00 +01:00
|
|
|
/**
|
|
|
|
* Finalize all chips of statically known devices.
|
|
|
|
*
|
|
|
|
* This is the last call before calling the payload. This is a good place
|
|
|
|
* to lock registers or other final cleanup.
|
|
|
|
*/
|
|
|
|
void dev_finalize_chips(void)
|
|
|
|
{
|
2018-04-26 00:00:22 +02:00
|
|
|
const struct device *dev;
|
2013-10-30 00:32:00 +01:00
|
|
|
|
|
|
|
for (dev = all_devices; dev; dev = dev->next) {
|
|
|
|
/* Initialize chip if we haven't yet. */
|
|
|
|
if (dev->chip_ops && dev->chip_ops->final &&
|
|
|
|
!dev->chip_ops->finalized) {
|
|
|
|
dev->chip_ops->final(dev->chip_info);
|
|
|
|
dev->chip_ops->finalized = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-17 21:01:48 +02:00
|
|
|
DECLARE_SPIN_LOCK(dev_lock)
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2019-03-06 01:53:33 +01:00
|
|
|
#if CONFIG(GFXUMA)
|
2012-07-11 06:55:21 +02:00
|
|
|
/* IGD UMA memory */
|
|
|
|
uint64_t uma_memory_base = 0;
|
|
|
|
uint64_t uma_memory_size = 0;
|
2012-08-01 07:05:22 +02:00
|
|
|
#endif
|
2012-07-11 06:55:21 +02:00
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Allocate a new device structure.
|
2009-05-12 00:24:53 +02:00
|
|
|
*
|
2013-07-09 00:24:19 +02:00
|
|
|
* Allocate a new device structure and attach it to the device tree as a
|
2004-05-10 18:05:16 +02:00
|
|
|
* child of the parent bus.
|
2004-03-23 22:28:05 +01:00
|
|
|
*
|
2010-10-17 21:01:48 +02:00
|
|
|
* @param parent Parent bus the newly created device should be attached to.
|
|
|
|
* @param path Path to the device to be created.
|
|
|
|
* @return Pointer to the newly created device structure.
|
2004-03-23 22:28:05 +01:00
|
|
|
*
|
|
|
|
* @see device_path
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
2018-09-17 10:44:14 +02:00
|
|
|
static struct device *__alloc_dev(struct bus *parent, struct device_path *path)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
2018-05-06 20:32:23 +02:00
|
|
|
struct device *dev, *child;
|
2004-03-23 22:28:05 +01:00
|
|
|
|
2009-07-02 20:56:24 +02:00
|
|
|
/* Find the last child of our parent. */
|
2018-10-17 10:56:26 +02:00
|
|
|
for (child = parent->children; child && child->sibling; /* */)
|
2003-09-02 05:36:25 +02:00
|
|
|
child = child->sibling;
|
2004-12-03 23:39:34 +01:00
|
|
|
|
2003-09-02 05:36:25 +02:00
|
|
|
dev = malloc(sizeof(*dev));
|
2009-07-02 20:56:24 +02:00
|
|
|
if (dev == 0)
|
2010-11-05 00:23:47 +01:00
|
|
|
die("alloc_dev(): out of memory.\n");
|
2009-07-02 20:56:24 +02:00
|
|
|
|
2003-09-02 05:36:25 +02:00
|
|
|
memset(dev, 0, sizeof(*dev));
|
|
|
|
memcpy(&dev->path, path, sizeof(*path));
|
|
|
|
|
2009-07-02 20:56:24 +02:00
|
|
|
/* By default devices are enabled. */
|
2004-10-14 23:25:53 +02:00
|
|
|
dev->enabled = 1;
|
2003-09-02 05:36:25 +02:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
/* Add the new device to the list of children of the bus. */
|
2003-09-02 05:36:25 +02:00
|
|
|
dev->bus = parent;
|
2010-11-05 00:23:47 +01:00
|
|
|
if (child)
|
2003-09-02 05:36:25 +02:00
|
|
|
child->sibling = dev;
|
2010-11-05 00:23:47 +01:00
|
|
|
else
|
2003-09-02 05:36:25 +02:00
|
|
|
parent->children = dev;
|
2004-03-23 22:28:05 +01:00
|
|
|
|
2004-10-14 23:25:53 +02:00
|
|
|
/* Append a new device to the global device list.
|
|
|
|
* The list is used to find devices once everything is set up.
|
|
|
|
*/
|
2010-09-01 23:03:03 +02:00
|
|
|
last_dev->next = dev;
|
|
|
|
last_dev = dev;
|
2004-10-14 23:25:53 +02:00
|
|
|
|
2012-07-07 16:15:51 +02:00
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2018-09-17 10:44:14 +02:00
|
|
|
struct device *alloc_dev(struct bus *parent, struct device_path *path)
|
2012-07-07 16:15:51 +02:00
|
|
|
{
|
2018-05-06 20:32:23 +02:00
|
|
|
struct device *dev;
|
2012-07-07 16:15:51 +02:00
|
|
|
spin_lock(&dev_lock);
|
|
|
|
dev = __alloc_dev(parent, path);
|
2004-10-14 23:25:53 +02:00
|
|
|
spin_unlock(&dev_lock);
|
2003-09-02 05:36:25 +02:00
|
|
|
return dev;
|
|
|
|
}
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2012-07-07 16:15:51 +02:00
|
|
|
/**
|
|
|
|
* See if a device structure already exists and if not allocate it.
|
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*/
|
2018-09-17 10:44:14 +02:00
|
|
|
struct device *alloc_find_dev(struct bus *parent, struct device_path *path)
|
2012-07-07 16:15:51 +02:00
|
|
|
{
|
2018-05-06 20:32:23 +02:00
|
|
|
struct device *child;
|
2012-07-07 16:15:51 +02:00
|
|
|
spin_lock(&dev_lock);
|
|
|
|
child = find_dev_path(parent, path);
|
|
|
|
if (!child)
|
|
|
|
child = __alloc_dev(parent, path);
|
|
|
|
spin_unlock(&dev_lock);
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
2010-10-17 21:01:48 +02:00
|
|
|
/**
|
|
|
|
* Read the resources on all devices of a given bus.
|
|
|
|
*
|
|
|
|
* @param bus Bus to read the resources on.
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
2003-09-02 05:36:25 +02:00
|
|
|
static void read_resources(struct bus *bus)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
|
|
|
struct device *curdev;
|
|
|
|
|
2010-10-17 21:01:48 +02:00
|
|
|
printk(BIOS_SPEW, "%s %s bus %x link: %d\n", dev_path(bus->dev),
|
|
|
|
__func__, bus->secondary, bus->link_num);
|
2004-10-15 00:52:15 +02:00
|
|
|
|
2009-07-02 20:56:24 +02:00
|
|
|
/* Walk through all devices and find which resources they need. */
|
|
|
|
for (curdev = bus->children; curdev; curdev = curdev->sibling) {
|
2010-06-10 00:41:35 +02:00
|
|
|
struct bus *link;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
|
|
|
if (!curdev->enabled)
|
2003-04-22 21:02:15 +02:00
|
|
|
continue;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2003-09-02 05:36:25 +02:00
|
|
|
if (!curdev->ops || !curdev->ops->read_resources) {
|
2015-11-19 04:23:02 +01:00
|
|
|
if (curdev->path.type != DEVICE_PATH_APIC)
|
2021-02-01 11:44:37 +01:00
|
|
|
printk(BIOS_ERR, "%s missing %s\n",
|
|
|
|
dev_path(curdev), __func__);
|
2003-09-02 05:36:25 +02:00
|
|
|
continue;
|
|
|
|
}
|
2013-07-09 19:46:52 +02:00
|
|
|
post_log_path(curdev);
|
2003-04-22 21:02:15 +02:00
|
|
|
curdev->ops->read_resources(curdev);
|
2009-07-02 20:56:24 +02:00
|
|
|
|
|
|
|
/* Read in the resources behind the current device's links. */
|
2010-06-10 00:41:35 +02:00
|
|
|
for (link = curdev->link_list; link; link = link->next)
|
|
|
|
read_resources(link);
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
2013-07-09 19:46:52 +02:00
|
|
|
post_log_clear();
|
2021-02-01 11:44:37 +01:00
|
|
|
printk(BIOS_SPEW, "%s %s bus %d link: %d done\n",
|
|
|
|
dev_path(bus->dev), __func__, bus->secondary, bus->link_num);
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2018-05-06 20:32:23 +02:00
|
|
|
struct device *vga_pri = NULL;
|
2009-07-02 21:02:33 +02:00
|
|
|
static void set_vga_bridge_bits(void)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
2009-10-27 22:49:33 +01:00
|
|
|
/*
|
2013-07-09 00:24:19 +02:00
|
|
|
* FIXME: Modify set_vga_bridge() so it is less PCI-centric!
|
2009-10-27 22:49:33 +01:00
|
|
|
* This function knows too much about PCI stuff, it should be just
|
|
|
|
* an iterator/visitor.
|
|
|
|
*/
|
2004-03-23 22:28:05 +01:00
|
|
|
|
2009-07-02 20:56:24 +02:00
|
|
|
/* FIXME: Handle the VGA palette snooping. */
|
2012-07-20 12:16:17 +02:00
|
|
|
struct device *dev, *vga, *vga_onboard;
|
2004-10-14 22:54:17 +02:00
|
|
|
struct bus *bus;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
bus = 0;
|
|
|
|
vga = 0;
|
2005-01-17 22:37:12 +01:00
|
|
|
vga_onboard = 0;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2012-07-20 12:16:17 +02:00
|
|
|
dev = NULL;
|
|
|
|
while ((dev = dev_find_class(PCI_CLASS_DISPLAY_VGA << 8, dev))) {
|
2009-07-02 20:56:24 +02:00
|
|
|
if (!dev->enabled)
|
|
|
|
continue;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2012-07-20 12:16:17 +02:00
|
|
|
printk(BIOS_DEBUG, "found VGA at %s\n", dev_path(dev));
|
device/pci: Enable full 16-bit VGA port i/o decoding
So, the PCI to PCI bridge specification had a pitfall for us:
Originally, when decoding i/o ports for legacy VGA cycles, bridges
should only consider the 10 least significant bits of the port address.
This means all VGA registers were aliased every 1024 ports!
e.g. 0x3b0 was also decoded as 0x7b0, 0xbb0 etc.
However, it seems, we never reserved the aliased ports, resulting in
silent conflicts we preallocated resources. We neither use much
external VGA nor many i/o ports these days, so nobody noticed.
To avoid this mess, a bridge control bit (VGA16) was introduced in
2003 to enable decoding of 16-bit port addresses. As older systems
seem rather safe and well tested, and newer systems should support
this bit, we'll use it if possible and only warn if not.
With old (AGP era) hardware one will likely encounter a warning like
this:
found VGA at PCI: 06:00.0
A bridge on the path doesn't support 16-bit VGA decoding!
This is not generally fatal, but makes unnoticed resource conflicts
more likely.
Change-Id: Id7a07f069dd54331df79f605c6bcda37882a602d
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/35516
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-by: Michael Niewöhner
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2019-09-21 15:58:23 +02:00
|
|
|
if (dev->bus->no_vga16) {
|
|
|
|
printk(BIOS_WARNING,
|
|
|
|
"A bridge on the path doesn't support 16-bit VGA decoding!");
|
|
|
|
}
|
2009-07-02 20:56:24 +02:00
|
|
|
|
2021-02-01 11:44:37 +01:00
|
|
|
if (dev->on_mainboard)
|
2012-07-20 12:16:17 +02:00
|
|
|
vga_onboard = dev;
|
2021-02-01 11:44:37 +01:00
|
|
|
else
|
2012-07-20 12:16:17 +02:00
|
|
|
vga = dev;
|
2009-05-12 00:24:53 +02:00
|
|
|
|
2012-07-20 12:16:17 +02:00
|
|
|
/* It isn't safe to enable all VGA cards. */
|
|
|
|
dev->command &= ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
|
2012-07-25 08:55:53 +02:00
|
|
|
}
|
2005-12-02 22:52:30 +01:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
if (!vga)
|
2012-07-20 12:16:17 +02:00
|
|
|
vga = vga_onboard;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2019-03-08 02:07:26 +01:00
|
|
|
if (CONFIG(ONBOARD_VGA_IS_PRIMARY) && vga_onboard)
|
2009-07-02 20:56:24 +02:00
|
|
|
vga = vga_onboard;
|
2009-05-12 00:24:53 +02:00
|
|
|
|
2012-07-20 12:29:33 +02:00
|
|
|
/* If we prefer plugin VGA over chipset VGA, the chipset might
|
|
|
|
want to know. */
|
2019-03-08 02:07:26 +01:00
|
|
|
if (!CONFIG(ONBOARD_VGA_IS_PRIMARY) && (vga != vga_onboard) &&
|
2012-07-20 12:29:33 +02:00
|
|
|
vga_onboard && vga_onboard->ops && vga_onboard->ops->disable) {
|
|
|
|
printk(BIOS_DEBUG, "Use plugin graphics over integrated.\n");
|
|
|
|
vga_onboard->ops->disable(vga_onboard);
|
|
|
|
}
|
|
|
|
|
2005-07-06 19:16:09 +02:00
|
|
|
if (vga) {
|
2010-11-05 00:23:47 +01:00
|
|
|
/* VGA is first add-on card or the only onboard VGA. */
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "Setting up VGA for %s\n", dev_path(vga));
|
2009-07-02 20:56:24 +02:00
|
|
|
/* All legacy VGA cards have MEM & I/O space registers. */
|
2005-01-17 22:37:12 +01:00
|
|
|
vga->command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
|
|
|
|
vga_pri = vga;
|
2003-04-22 21:02:15 +02:00
|
|
|
bus = vga->bus;
|
|
|
|
}
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2009-07-02 20:56:24 +02:00
|
|
|
/* Now walk up the bridges setting the VGA enable. */
|
|
|
|
while (bus) {
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "Setting PCI_BRIDGE_CTL_VGA for bridge %s\n",
|
2010-11-05 00:23:47 +01:00
|
|
|
dev_path(bus->dev));
|
device/pci: Enable full 16-bit VGA port i/o decoding
So, the PCI to PCI bridge specification had a pitfall for us:
Originally, when decoding i/o ports for legacy VGA cycles, bridges
should only consider the 10 least significant bits of the port address.
This means all VGA registers were aliased every 1024 ports!
e.g. 0x3b0 was also decoded as 0x7b0, 0xbb0 etc.
However, it seems, we never reserved the aliased ports, resulting in
silent conflicts we preallocated resources. We neither use much
external VGA nor many i/o ports these days, so nobody noticed.
To avoid this mess, a bridge control bit (VGA16) was introduced in
2003 to enable decoding of 16-bit port addresses. As older systems
seem rather safe and well tested, and newer systems should support
this bit, we'll use it if possible and only warn if not.
With old (AGP era) hardware one will likely encounter a warning like
this:
found VGA at PCI: 06:00.0
A bridge on the path doesn't support 16-bit VGA decoding!
This is not generally fatal, but makes unnoticed resource conflicts
more likely.
Change-Id: Id7a07f069dd54331df79f605c6bcda37882a602d
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/35516
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-by: Michael Niewöhner
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2019-09-21 15:58:23 +02:00
|
|
|
bus->bridge_ctrl |= PCI_BRIDGE_CTL_VGA | PCI_BRIDGE_CTL_VGA16;
|
2009-07-02 20:56:24 +02:00
|
|
|
bus = (bus == bus->dev->bus) ? 0 : bus->dev->bus;
|
2009-05-12 00:24:53 +02:00
|
|
|
}
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
2005-12-02 22:52:30 +01:00
|
|
|
|
2004-11-25 18:37:19 +01:00
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Assign the computed resources to the devices on the bus.
|
2004-11-25 18:37:19 +01:00
|
|
|
*
|
2010-11-05 00:23:47 +01:00
|
|
|
* Use the device specific set_resources() method to store the computed
|
2004-11-25 18:37:19 +01:00
|
|
|
* resources to hardware. For bridge devices, the set_resources() method
|
|
|
|
* has to recurse into every down stream buses.
|
|
|
|
*
|
|
|
|
* Mutual recursion:
|
|
|
|
* assign_resources() -> device_operation::set_resources()
|
|
|
|
* device_operation::set_resources() -> assign_resources()
|
2010-10-17 21:01:48 +02:00
|
|
|
*
|
|
|
|
* @param bus Pointer to the structure for this bus.
|
2004-11-25 18:37:19 +01:00
|
|
|
*/
|
2003-09-02 05:36:25 +02:00
|
|
|
void assign_resources(struct bus *bus)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
|
|
|
struct device *curdev;
|
|
|
|
|
2021-02-01 11:44:37 +01:00
|
|
|
printk(BIOS_SPEW, "%s %s, bus %d link: %d\n",
|
|
|
|
dev_path(bus->dev), __func__, bus->secondary, bus->link_num);
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2009-07-02 20:56:24 +02:00
|
|
|
for (curdev = bus->children; curdev; curdev = curdev->sibling) {
|
2010-11-05 00:23:47 +01:00
|
|
|
if (!curdev->enabled || !curdev->resource_list)
|
2004-10-14 23:25:53 +02:00
|
|
|
continue;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2003-09-02 05:36:25 +02:00
|
|
|
if (!curdev->ops || !curdev->ops->set_resources) {
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_ERR, "%s missing set_resources\n",
|
2010-11-05 00:23:47 +01:00
|
|
|
dev_path(curdev));
|
2003-09-02 05:36:25 +02:00
|
|
|
continue;
|
|
|
|
}
|
2013-06-10 19:34:20 +02:00
|
|
|
post_log_path(curdev);
|
2003-04-22 21:02:15 +02:00
|
|
|
curdev->ops->set_resources(curdev);
|
|
|
|
}
|
2013-06-10 19:34:20 +02:00
|
|
|
post_log_clear();
|
2021-02-01 11:52:51 +01:00
|
|
|
printk(BIOS_SPEW, "%s %s, bus %d link: %d done\n",
|
2021-02-01 11:44:37 +01:00
|
|
|
dev_path(bus->dev), __func__, bus->secondary, bus->link_num);
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2004-04-26 19:51:20 +02:00
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Enable the resources for devices on a link.
|
2004-04-26 19:51:20 +02:00
|
|
|
*
|
|
|
|
* Enable resources of the device by calling the device specific
|
|
|
|
* enable_resources() method.
|
|
|
|
*
|
|
|
|
* The parent's resources should be enabled first to avoid having enabling
|
|
|
|
* order problem. This is done by calling the parent's enable_resources()
|
2013-07-09 00:24:19 +02:00
|
|
|
* method before its children's enable_resources() methods.
|
2004-05-10 18:05:16 +02:00
|
|
|
*
|
2010-10-17 21:01:48 +02:00
|
|
|
* @param link The link whose devices' resources are to be enabled.
|
2004-04-26 19:51:20 +02:00
|
|
|
*/
|
2010-06-17 18:16:56 +02:00
|
|
|
static void enable_resources(struct bus *link)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
2010-06-17 18:16:56 +02:00
|
|
|
struct device *dev;
|
|
|
|
struct bus *c_link;
|
|
|
|
|
|
|
|
for (dev = link->children; dev; dev = dev->sibling) {
|
2013-06-10 19:34:20 +02:00
|
|
|
if (dev->enabled && dev->ops && dev->ops->enable_resources) {
|
|
|
|
post_log_path(dev);
|
2010-06-17 18:16:56 +02:00
|
|
|
dev->ops->enable_resources(dev);
|
2013-06-10 19:34:20 +02:00
|
|
|
}
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
2010-06-17 18:16:56 +02:00
|
|
|
|
|
|
|
for (dev = link->children; dev; dev = dev->sibling) {
|
2010-11-05 00:23:47 +01:00
|
|
|
for (c_link = dev->link_list; c_link; c_link = c_link->next)
|
2010-06-17 18:16:56 +02:00
|
|
|
enable_resources(c_link);
|
2003-10-11 08:20:25 +02:00
|
|
|
}
|
2013-06-10 19:34:20 +02:00
|
|
|
post_log_clear();
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2009-05-12 00:24:53 +02:00
|
|
|
/**
|
2005-07-08 04:49:49 +02:00
|
|
|
* Reset all of the devices on a bus and clear the bus's reset_needed flag.
|
|
|
|
*
|
2010-10-17 21:01:48 +02:00
|
|
|
* @param bus Pointer to the bus structure.
|
2005-07-08 04:49:49 +02:00
|
|
|
* @return 1 if the bus was successfully reset, 0 otherwise.
|
|
|
|
*/
|
|
|
|
int reset_bus(struct bus *bus)
|
|
|
|
{
|
2009-07-02 20:56:24 +02:00
|
|
|
if (bus && bus->dev && bus->dev->ops && bus->dev->ops->reset_bus) {
|
2005-07-08 04:49:49 +02:00
|
|
|
bus->dev->ops->reset_bus(bus);
|
|
|
|
bus->reset_needed = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-12 00:24:53 +02:00
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Scan for devices on a bus.
|
2005-07-08 04:49:49 +02:00
|
|
|
*
|
2009-07-02 20:56:24 +02:00
|
|
|
* If there are bridges on the bus, recursively scan the buses behind the
|
|
|
|
* bridges. If the setting up and tuning of the bus causes a reset to be
|
|
|
|
* required, reset the bus and scan it again.
|
2005-07-08 04:49:49 +02:00
|
|
|
*
|
2009-07-02 20:56:24 +02:00
|
|
|
* @param busdev Pointer to the bus device.
|
2005-07-08 04:49:49 +02:00
|
|
|
*/
|
2015-03-19 20:04:23 +01:00
|
|
|
static void scan_bus(struct device *busdev)
|
2005-07-08 04:49:49 +02:00
|
|
|
{
|
|
|
|
int do_scan_bus;
|
2015-10-20 10:21:08 +02:00
|
|
|
struct stopwatch sw;
|
2019-12-01 11:27:44 +01:00
|
|
|
long scan_time;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2015-02-20 20:28:31 +01:00
|
|
|
if (!busdev->enabled)
|
2015-03-19 20:04:23 +01:00
|
|
|
return;
|
2015-02-20 20:28:31 +01:00
|
|
|
|
2019-12-01 11:27:44 +01:00
|
|
|
printk(BIOS_DEBUG, "%s scanning...\n", dev_path(busdev));
|
2009-07-02 20:56:24 +02:00
|
|
|
|
2013-06-10 19:34:20 +02:00
|
|
|
post_log_path(busdev);
|
|
|
|
|
2019-12-01 11:27:44 +01:00
|
|
|
stopwatch_init(&sw);
|
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
do_scan_bus = 1;
|
2009-07-02 20:56:24 +02:00
|
|
|
while (do_scan_bus) {
|
2010-06-10 00:41:35 +02:00
|
|
|
struct bus *link;
|
2015-03-19 20:04:23 +01:00
|
|
|
busdev->ops->scan_bus(busdev);
|
2005-07-08 04:49:49 +02:00
|
|
|
do_scan_bus = 0;
|
2010-06-10 00:41:35 +02:00
|
|
|
for (link = busdev->link_list; link; link = link->next) {
|
|
|
|
if (link->reset_needed) {
|
2010-11-05 00:23:47 +01:00
|
|
|
if (reset_bus(link))
|
2005-07-08 04:49:49 +02:00
|
|
|
do_scan_bus = 1;
|
2010-11-05 00:23:47 +01:00
|
|
|
else
|
2009-07-02 20:56:24 +02:00
|
|
|
busdev->bus->reset_needed = 1;
|
2005-07-08 04:49:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-20 10:21:08 +02:00
|
|
|
|
2019-12-01 11:27:44 +01:00
|
|
|
scan_time = stopwatch_duration_msecs(&sw);
|
|
|
|
printk(BIOS_DEBUG, "%s: bus %s finished in %ld msecs\n", __func__,
|
|
|
|
dev_path(busdev), scan_time);
|
2005-07-08 04:49:49 +02:00
|
|
|
}
|
|
|
|
|
2015-02-20 20:28:31 +01:00
|
|
|
void scan_bridges(struct bus *bus)
|
|
|
|
{
|
|
|
|
struct device *child;
|
|
|
|
|
|
|
|
for (child = bus->children; child; child = child->sibling) {
|
|
|
|
if (!child->ops || !child->ops->scan_bus)
|
|
|
|
continue;
|
2015-03-19 20:04:23 +01:00
|
|
|
scan_bus(child);
|
2015-02-20 20:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Determine the existence of devices and extend the device tree.
|
2004-11-25 18:37:19 +01:00
|
|
|
*
|
2010-11-05 00:23:47 +01:00
|
|
|
* Most of the devices in the system are listed in the mainboard devicetree.cb
|
2004-11-25 18:37:19 +01:00
|
|
|
* file. The device structures for these devices are generated at compile
|
|
|
|
* time by the config tool and are organized into the device tree. This
|
|
|
|
* function determines if the devices created at compile time actually exist
|
|
|
|
* in the physical system.
|
|
|
|
*
|
2010-11-05 00:23:47 +01:00
|
|
|
* For devices in the physical system but not listed in devicetree.cb,
|
2004-11-25 18:37:19 +01:00
|
|
|
* the device structures have to be created at run time and attached to the
|
2004-03-23 22:28:05 +01:00
|
|
|
* device tree.
|
|
|
|
*
|
2010-11-05 00:23:47 +01:00
|
|
|
* This function starts from the root device 'dev_root', scans the buses in
|
|
|
|
* the system recursively, and modifies the device tree according to the
|
|
|
|
* result of the probe.
|
2004-03-23 22:28:05 +01:00
|
|
|
*
|
2004-04-26 19:51:20 +02:00
|
|
|
* This function has no idea how to scan and probe buses and devices at all.
|
|
|
|
* It depends on the bus/device specific scan_bus() method to do it. The
|
2004-11-25 18:37:19 +01:00
|
|
|
* scan_bus() method also has to create the device structure and attach
|
2009-05-12 00:24:53 +02:00
|
|
|
* it to the device tree.
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
|
|
|
void dev_enumerate(void)
|
|
|
|
{
|
|
|
|
struct device *root;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_INFO, "Enumerating buses...\n");
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
root = &dev_root;
|
2009-05-12 15:43:34 +02:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
show_all_devs(BIOS_SPEW, "Before device enumeration.");
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_SPEW, "Compare with tree...\n");
|
2016-08-15 09:04:21 +02:00
|
|
|
show_devs_tree(root, BIOS_SPEW, 0);
|
2009-05-12 15:43:34 +02:00
|
|
|
|
2012-08-07 23:50:47 +02:00
|
|
|
if (root->chip_ops && root->chip_ops->enable_dev)
|
|
|
|
root->chip_ops->enable_dev(root);
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
if (!root->ops || !root->ops->scan_bus) {
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_ERR, "dev_root missing scan_bus operation");
|
2004-10-14 22:54:17 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-03-19 20:04:23 +01:00
|
|
|
scan_bus(root);
|
2013-06-10 19:34:20 +02:00
|
|
|
post_log_clear();
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_INFO, "done\n");
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Configure devices on the devices tree.
|
2009-05-12 00:24:53 +02:00
|
|
|
*
|
2004-11-25 18:37:19 +01:00
|
|
|
* Starting at the root of the device tree, travel it recursively in two
|
|
|
|
* passes. In the first pass, we compute and allocate resources (ranges)
|
2013-07-09 00:24:19 +02:00
|
|
|
* required by each device. In the second pass, the resources ranges are
|
2004-11-25 18:37:19 +01:00
|
|
|
* relocated to their final position and stored to the hardware.
|
2004-04-26 19:51:20 +02:00
|
|
|
*
|
2009-07-02 20:56:24 +02:00
|
|
|
* I/O resources grow upward. MEM resources grow downward.
|
2004-04-26 19:51:20 +02:00
|
|
|
*
|
|
|
|
* Since the assignment is hierarchical we set the values into the dev_root
|
2009-05-12 00:24:53 +02:00
|
|
|
* struct.
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
|
|
|
void dev_configure(void)
|
|
|
|
{
|
2018-04-26 00:00:22 +02:00
|
|
|
const struct device *root;
|
2004-03-23 22:28:05 +01:00
|
|
|
|
2012-02-21 17:44:35 +01:00
|
|
|
set_vga_bridge_bits();
|
|
|
|
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_INFO, "Allocating resources...\n");
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
root = &dev_root;
|
2009-05-12 15:43:34 +02:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
/*
|
|
|
|
* Each domain should create resources which contain the entire address
|
2009-07-02 20:56:24 +02:00
|
|
|
* space for IO, MEM, and PREFMEM resources in the domain. The
|
|
|
|
* allocation of device resources will be done from this address space.
|
|
|
|
*/
|
2009-05-12 15:43:34 +02:00
|
|
|
|
2009-07-02 20:56:24 +02:00
|
|
|
/* Read the resources for the entire tree. */
|
2004-11-25 18:37:19 +01:00
|
|
|
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_INFO, "Reading resources...\n");
|
2010-06-10 00:41:35 +02:00
|
|
|
read_resources(root->link_list);
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_INFO, "Done reading resources.\n");
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2009-10-26 17:47:05 +01:00
|
|
|
print_resource_tree(root, BIOS_SPEW, "After reading.");
|
2009-05-12 15:43:34 +02:00
|
|
|
|
2020-05-16 00:43:15 +02:00
|
|
|
allocate_resources(root);
|
2009-07-02 20:56:24 +02:00
|
|
|
|
2010-06-10 00:41:35 +02:00
|
|
|
assign_resources(root->link_list);
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_INFO, "Done setting resources.\n");
|
2009-10-26 17:47:05 +01:00
|
|
|
print_resource_tree(root, BIOS_SPEW, "After assigning values.");
|
2004-10-14 23:25:53 +02:00
|
|
|
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_INFO, "Done allocating resources.\n");
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Enable devices on the device tree.
|
2004-03-23 22:28:05 +01:00
|
|
|
*
|
|
|
|
* Starting at the root, walk the tree and enable all devices/bridges by
|
|
|
|
* calling the device's enable_resources() method.
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
|
|
|
void dev_enable(void)
|
|
|
|
{
|
2010-06-17 18:16:56 +02:00
|
|
|
struct bus *link;
|
|
|
|
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_INFO, "Enabling resources...\n");
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
/* Now enable everything. */
|
2010-06-17 18:16:56 +02:00
|
|
|
for (link = dev_root.link_list; link; link = link->next)
|
|
|
|
enable_resources(link);
|
2004-03-23 22:28:05 +01:00
|
|
|
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_INFO, "done.\n");
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Initialize a specific device.
|
2010-06-17 18:16:56 +02:00
|
|
|
*
|
2010-11-05 00:23:47 +01:00
|
|
|
* The parent should be initialized first to avoid having an ordering problem.
|
2013-07-09 00:24:19 +02:00
|
|
|
* This is done by calling the parent's init() method before its children's
|
2010-11-05 00:23:47 +01:00
|
|
|
* init() methods.
|
2004-03-23 22:28:05 +01:00
|
|
|
*
|
2010-10-17 21:01:48 +02:00
|
|
|
* @param dev The device to be initialized.
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
2010-06-17 18:16:56 +02:00
|
|
|
static void init_dev(struct device *dev)
|
|
|
|
{
|
2010-11-05 00:23:47 +01:00
|
|
|
if (!dev->enabled)
|
2010-06-17 18:16:56 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!dev->initialized && dev->ops && dev->ops->init) {
|
2014-09-23 23:34:40 +02:00
|
|
|
struct stopwatch sw;
|
2019-12-01 11:27:44 +01:00
|
|
|
long init_time;
|
|
|
|
|
2010-06-17 18:16:56 +02:00
|
|
|
if (dev->path.type == DEVICE_PATH_I2C) {
|
|
|
|
printk(BIOS_DEBUG, "smbus: %s[%d]->",
|
|
|
|
dev_path(dev->bus->dev), dev->bus->link_num);
|
|
|
|
}
|
|
|
|
|
2019-12-01 11:27:44 +01:00
|
|
|
printk(BIOS_DEBUG, "%s init\n", dev_path(dev));
|
|
|
|
|
|
|
|
stopwatch_init(&sw);
|
2010-06-17 18:16:56 +02:00
|
|
|
dev->initialized = 1;
|
|
|
|
dev->ops->init(dev);
|
2019-12-01 11:27:44 +01:00
|
|
|
|
|
|
|
init_time = stopwatch_duration_msecs(&sw);
|
|
|
|
printk(BIOS_DEBUG, "%s init finished in %ld msecs\n", dev_path(dev),
|
|
|
|
init_time);
|
2010-06-17 18:16:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_link(struct bus *link)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
|
|
|
struct device *dev;
|
2010-06-17 18:16:56 +02:00
|
|
|
struct bus *c_link;
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2013-06-10 19:34:20 +02:00
|
|
|
for (dev = link->children; dev; dev = dev->sibling) {
|
2013-06-10 19:41:04 +02:00
|
|
|
post_code(POST_BS_DEV_INIT);
|
2013-06-10 19:34:20 +02:00
|
|
|
post_log_path(dev);
|
2010-06-17 18:16:56 +02:00
|
|
|
init_dev(dev);
|
2013-06-10 19:34:20 +02:00
|
|
|
}
|
2010-06-17 18:16:56 +02:00
|
|
|
|
|
|
|
for (dev = link->children; dev; dev = dev->sibling) {
|
2010-11-05 00:23:47 +01:00
|
|
|
for (c_link = dev->link_list; c_link; c_link = c_link->next)
|
2010-06-17 18:16:56 +02:00
|
|
|
init_link(c_link);
|
2005-07-08 04:49:49 +02:00
|
|
|
}
|
2010-06-17 18:16:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Initialize all devices in the global device tree.
|
2010-06-17 18:16:56 +02:00
|
|
|
*
|
2010-10-17 21:01:48 +02:00
|
|
|
* Starting at the root device, call the device's init() method to do
|
|
|
|
* device-specific setup, then call each child's init() method.
|
2010-06-17 18:16:56 +02:00
|
|
|
*/
|
|
|
|
void dev_initialize(void)
|
|
|
|
{
|
|
|
|
struct bus *link;
|
|
|
|
|
|
|
|
printk(BIOS_INFO, "Initializing devices...\n");
|
|
|
|
|
2020-06-08 05:05:03 +02:00
|
|
|
#if ENV_X86
|
2019-10-26 20:31:41 +02:00
|
|
|
/* Ensure EBDA is prepared before Option ROMs. */
|
|
|
|
setup_default_ebda();
|
2012-01-17 18:03:11 +01:00
|
|
|
#endif
|
|
|
|
|
2010-08-16 18:25:23 +02:00
|
|
|
/* First call the mainboard init. */
|
|
|
|
init_dev(&dev_root);
|
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
/* Now initialize everything. */
|
2010-06-17 18:16:56 +02:00
|
|
|
for (link = dev_root.link_list; link; link = link->next)
|
|
|
|
init_link(link);
|
2013-06-10 19:34:20 +02:00
|
|
|
post_log_clear();
|
2010-06-17 18:16:56 +02:00
|
|
|
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_INFO, "Devices initialized\n");
|
2009-10-26 17:47:05 +01:00
|
|
|
show_all_devs(BIOS_SPEW, "After init.");
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
2013-10-30 00:32:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finalize a specific device.
|
|
|
|
*
|
|
|
|
* The parent should be finalized first to avoid having an ordering problem.
|
|
|
|
* This is done by calling the parent's final() method before its childrens'
|
|
|
|
* final() methods.
|
|
|
|
*
|
|
|
|
* @param dev The device to be initialized.
|
|
|
|
*/
|
|
|
|
static void final_dev(struct device *dev)
|
|
|
|
{
|
|
|
|
if (!dev->enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (dev->ops && dev->ops->final) {
|
|
|
|
printk(BIOS_DEBUG, "%s final\n", dev_path(dev));
|
|
|
|
dev->ops->final(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void final_link(struct bus *link)
|
|
|
|
{
|
|
|
|
struct device *dev;
|
|
|
|
struct bus *c_link;
|
|
|
|
|
|
|
|
for (dev = link->children; dev; dev = dev->sibling)
|
|
|
|
final_dev(dev);
|
|
|
|
|
|
|
|
for (dev = link->children; dev; dev = dev->sibling) {
|
|
|
|
for (c_link = dev->link_list; c_link; c_link = c_link->next)
|
|
|
|
final_link(c_link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Finalize all devices in the global device tree.
|
|
|
|
*
|
|
|
|
* Starting at the root device, call the device's final() method to do
|
|
|
|
* device-specific cleanup, then call each child's final() method.
|
|
|
|
*/
|
|
|
|
void dev_finalize(void)
|
|
|
|
{
|
|
|
|
struct bus *link;
|
|
|
|
|
|
|
|
printk(BIOS_INFO, "Finalize devices...\n");
|
|
|
|
|
|
|
|
/* First call the mainboard finalize. */
|
|
|
|
final_dev(&dev_root);
|
|
|
|
|
|
|
|
/* Now finalize everything. */
|
|
|
|
for (link = dev_root.link_list; link; link = link->next)
|
|
|
|
final_link(link);
|
|
|
|
|
|
|
|
printk(BIOS_INFO, "Devices finalized\n");
|
|
|
|
}
|