2007-04-22 21:08:13 +02:00
|
|
|
/*
|
2008-01-18 11:35:56 +01:00
|
|
|
* This file is part of the coreboot project.
|
2007-04-22 21:08:13 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Linux Networx
|
|
|
|
* (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
|
|
|
|
* Copyright (C) 2005 Ronald G. Minnich <rminnich@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
Remove address from GPLv2 headers
As per discussion with lawyers[tm], it's not a good idea to
shorten the license header too much - not for legal reasons
but because there are tools that look for them, and giving
them a standard pattern simplifies things.
However, we got confirmation that we don't have to update
every file ever added to coreboot whenever the FSF gets a
new lease, but can drop the address instead.
util/kconfig is excluded because that's imported code that
we may want to synchronize every now and then.
$ find * -type f -exec sed -i "s:Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *MA[, ]*02110-1301[, ]*USA:Foundation, Inc.:" {} +
$ find * -type f -exec sed -i "s:Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA:Foundation, Inc.:" {} +
$ find * -type f -exec sed -i "s:Foundation, Inc., 59 Temple Place[-, ]*Suite 330, Boston, MA *02111-1307[, ]*USA:Foundation, Inc.:" {} +
$ find * -type f -exec sed -i "s:Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.:Foundation, Inc.:" {} +
$ find * -type f
-a \! -name \*.patch \
-a \! -name \*_shipped \
-a \! -name LICENSE_GPL \
-a \! -name LGPL.txt \
-a \! -name COPYING \
-a \! -name DISCLAIMER \
-exec sed -i "/Foundation, Inc./ N;s:Foundation, Inc.* USA\.* *:Foundation, Inc. :;s:Foundation, Inc. $:Foundation, Inc.:" {} +
Change-Id: Icc968a5a5f3a5df8d32b940f9cdb35350654bef9
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-on: http://review.coreboot.org/9233
Tested-by: build bot (Jenkins)
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
2015-03-26 15:17:45 +01:00
|
|
|
* Foundation, Inc.
|
2007-04-22 21:08:13 +02:00
|
|
|
*/
|
2005-07-08 04:56:47 +02:00
|
|
|
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/pci.h>
|
|
|
|
#include <device/pci_ids.h>
|
|
|
|
#include <device/cardbus.h>
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/*
|
|
|
|
* I don't think this code is quite correct but it is close.
|
2005-07-08 04:56:47 +02:00
|
|
|
* Anyone with a cardbus bridge and a little time should be able
|
|
|
|
* to make it usable quickly. -- Eric Biederman 24 March 2005
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2010-10-18 02:00:57 +02:00
|
|
|
* IO should be max 256 bytes. However, since we may have a P2P bridge below
|
|
|
|
* a cardbus bridge, we need 4K.
|
2005-07-08 04:56:47 +02:00
|
|
|
*/
|
2010-10-18 02:00:57 +02:00
|
|
|
#define CARDBUS_IO_SIZE 4096
|
|
|
|
#define CARDBUS_MEM_SIZE (32 * 1024 * 1024)
|
2005-07-08 04:56:47 +02:00
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
static void cardbus_record_bridge_resource(device_t dev, resource_t moving,
|
|
|
|
resource_t min_size, unsigned int index, unsigned long type)
|
2005-07-08 04:56:47 +02:00
|
|
|
{
|
|
|
|
struct resource *resource;
|
2010-11-05 00:23:47 +01:00
|
|
|
unsigned long gran;
|
|
|
|
resource_t step;
|
2010-10-18 02:00:57 +02:00
|
|
|
|
|
|
|
/* Initialize the constraints on the current bus. */
|
2010-06-07 18:51:11 +02:00
|
|
|
resource = NULL;
|
2010-11-05 00:23:47 +01:00
|
|
|
if (!moving)
|
|
|
|
return;
|
2010-10-18 02:00:57 +02:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
resource = new_resource(dev, index);
|
|
|
|
resource->size = 0;
|
|
|
|
gran = 0;
|
|
|
|
step = 1;
|
|
|
|
while ((moving & step) == 0) {
|
|
|
|
gran += 1;
|
|
|
|
step <<= 1;
|
|
|
|
}
|
|
|
|
resource->gran = gran;
|
|
|
|
resource->align = gran;
|
|
|
|
resource->limit = moving | (step - 1);
|
|
|
|
resource->flags = type;
|
2010-10-18 02:00:57 +02:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
/* Don't let the minimum size exceed what we can put in the resource. */
|
|
|
|
if ((min_size - 1) > resource->limit)
|
|
|
|
min_size = resource->limit + 1;
|
2010-10-18 02:00:57 +02:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
resource->size = min_size;
|
2005-07-08 04:56:47 +02:00
|
|
|
}
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
static void cardbus_size_bridge_resource(device_t dev, unsigned int index)
|
2005-07-08 04:56:47 +02:00
|
|
|
{
|
|
|
|
struct resource *resource;
|
|
|
|
resource_t min_size;
|
2010-10-18 02:00:57 +02:00
|
|
|
|
2005-07-08 04:56:47 +02:00
|
|
|
resource = find_resource(dev, index);
|
|
|
|
if (resource) {
|
|
|
|
min_size = resource->size;
|
2010-10-18 02:00:57 +02:00
|
|
|
/*
|
|
|
|
* Always allocate at least the miniumum size to a
|
2005-07-08 04:56:47 +02:00
|
|
|
* cardbus bridge in case a new card is plugged in.
|
|
|
|
*/
|
2010-10-18 02:00:57 +02:00
|
|
|
if (resource->size < min_size)
|
2005-07-08 04:56:47 +02:00
|
|
|
resource->size = min_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cardbus_read_resources(device_t dev)
|
|
|
|
{
|
|
|
|
resource_t moving_base, moving_limit, moving;
|
|
|
|
unsigned long type;
|
2010-10-18 02:00:57 +02:00
|
|
|
u16 ctl;
|
2005-11-22 01:07:02 +01:00
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/* See if needs a card control registers base address. */
|
2005-11-22 01:07:02 +01:00
|
|
|
|
|
|
|
pci_get_resource(dev, PCI_BASE_ADDRESS_0);
|
|
|
|
|
|
|
|
compact_resources(dev);
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/* See which bridge I/O resources are implemented. */
|
|
|
|
moving_base = pci_moving_config32(dev, PCI_CB_IO_BASE_0);
|
2005-07-08 04:56:47 +02:00
|
|
|
moving_limit = pci_moving_config32(dev, PCI_CB_IO_LIMIT_0);
|
|
|
|
moving = moving_base & moving_limit;
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/* Initialize the I/O space constraints on the current bus. */
|
2005-07-08 04:56:47 +02:00
|
|
|
cardbus_record_bridge_resource(dev, moving, CARDBUS_IO_SIZE,
|
2010-10-18 02:00:57 +02:00
|
|
|
PCI_CB_IO_BASE_0, IORESOURCE_IO);
|
2005-07-08 04:56:47 +02:00
|
|
|
cardbus_size_bridge_resource(dev, PCI_CB_IO_BASE_0);
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/* See which bridge I/O resources are implemented. */
|
|
|
|
moving_base = pci_moving_config32(dev, PCI_CB_IO_BASE_1);
|
2005-07-08 04:56:47 +02:00
|
|
|
moving_limit = pci_moving_config32(dev, PCI_CB_IO_LIMIT_1);
|
|
|
|
moving = moving_base & moving_limit;
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/* Initialize the I/O space constraints on the current bus. */
|
2005-07-08 04:56:47 +02:00
|
|
|
cardbus_record_bridge_resource(dev, moving, CARDBUS_IO_SIZE,
|
2010-10-18 02:00:57 +02:00
|
|
|
PCI_CB_IO_BASE_1, IORESOURCE_IO);
|
2005-07-08 04:56:47 +02:00
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/* If I can, enable prefetch for mem0. */
|
2005-07-08 04:56:47 +02:00
|
|
|
ctl = pci_read_config16(dev, PCI_CB_BRIDGE_CONTROL);
|
|
|
|
ctl &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM0;
|
|
|
|
ctl &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM1;
|
|
|
|
ctl |= PCI_CB_BRIDGE_CTL_PREFETCH_MEM0;
|
|
|
|
pci_write_config16(dev, PCI_CB_BRIDGE_CONTROL, ctl);
|
|
|
|
ctl = pci_read_config16(dev, PCI_CB_BRIDGE_CONTROL);
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/* See which bridge memory resources are implemented. */
|
|
|
|
moving_base = pci_moving_config32(dev, PCI_CB_MEMORY_BASE_0);
|
2005-07-08 04:56:47 +02:00
|
|
|
moving_limit = pci_moving_config32(dev, PCI_CB_MEMORY_LIMIT_0);
|
|
|
|
moving = moving_base & moving_limit;
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/* Initialize the memory space constraints on the current bus. */
|
2005-07-08 04:56:47 +02:00
|
|
|
type = IORESOURCE_MEM;
|
2010-10-18 02:00:57 +02:00
|
|
|
if (ctl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0)
|
2005-07-08 04:56:47 +02:00
|
|
|
type |= IORESOURCE_PREFETCH;
|
|
|
|
cardbus_record_bridge_resource(dev, moving, CARDBUS_MEM_SIZE,
|
2010-10-18 02:00:57 +02:00
|
|
|
PCI_CB_MEMORY_BASE_0, type);
|
|
|
|
if (type & IORESOURCE_PREFETCH)
|
2005-07-08 04:56:47 +02:00
|
|
|
cardbus_size_bridge_resource(dev, PCI_CB_MEMORY_BASE_0);
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/* See which bridge memory resources are implemented. */
|
|
|
|
moving_base = pci_moving_config32(dev, PCI_CB_MEMORY_BASE_1);
|
2005-07-08 04:56:47 +02:00
|
|
|
moving_limit = pci_moving_config32(dev, PCI_CB_MEMORY_LIMIT_1);
|
|
|
|
moving = moving_base & moving_limit;
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/* Initialize the memory space constraints on the current bus. */
|
2005-07-08 04:56:47 +02:00
|
|
|
cardbus_record_bridge_resource(dev, moving, CARDBUS_MEM_SIZE,
|
2010-10-18 02:00:57 +02:00
|
|
|
PCI_CB_MEMORY_BASE_1, IORESOURCE_MEM);
|
2005-07-08 04:56:47 +02:00
|
|
|
cardbus_size_bridge_resource(dev, PCI_CB_MEMORY_BASE_1);
|
|
|
|
|
|
|
|
compact_resources(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cardbus_enable_resources(device_t dev)
|
|
|
|
{
|
2010-10-18 02:00:57 +02:00
|
|
|
u16 ctrl;
|
|
|
|
|
2005-07-08 04:56:47 +02:00
|
|
|
ctrl = pci_read_config16(dev, PCI_CB_BRIDGE_CONTROL);
|
2010-06-10 00:41:35 +02:00
|
|
|
ctrl |= (dev->link_list->bridge_ctrl & (
|
2010-04-27 08:56:47 +02:00
|
|
|
PCI_BRIDGE_CTL_PARITY |
|
|
|
|
PCI_BRIDGE_CTL_SERR |
|
2005-07-08 04:56:47 +02:00
|
|
|
PCI_BRIDGE_CTL_NO_ISA |
|
|
|
|
PCI_BRIDGE_CTL_VGA |
|
|
|
|
PCI_BRIDGE_CTL_MASTER_ABORT |
|
|
|
|
PCI_BRIDGE_CTL_BUS_RESET));
|
2010-10-18 02:00:57 +02:00
|
|
|
/* Error check */
|
|
|
|
ctrl |= (PCI_CB_BRIDGE_CTL_PARITY + PCI_CB_BRIDGE_CTL_SERR);
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "%s bridge ctrl <- %04x\n", dev_path(dev), ctrl);
|
2005-07-08 04:56:47 +02:00
|
|
|
pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl);
|
|
|
|
|
|
|
|
pci_dev_enable_resources(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct device_operations default_cardbus_ops_bus = {
|
|
|
|
.read_resources = cardbus_read_resources,
|
|
|
|
.set_resources = pci_dev_set_resources,
|
|
|
|
.enable_resources = cardbus_enable_resources,
|
2010-10-18 02:00:57 +02:00
|
|
|
.init = 0,
|
|
|
|
.scan_bus = pci_scan_bridge,
|
2005-07-08 04:56:47 +02:00
|
|
|
.enable = 0,
|
|
|
|
.reset_bus = pci_bus_reset,
|
|
|
|
};
|