switch-coreboot/arch/x86/resourcemap.c
Ronald G. Minnich da9286b479 State of the tree for K8
Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Acked-by: Peter Stuge <peter@stuge.se>



git-svn-id: svn://coreboot.org/repository/coreboot-v3@722 f3766cd6-281f-0410-b1cd-43a5c92072e9
2008-08-05 02:48:54 +00:00

121 lines
4.3 KiB
C

/*
* This file is part of the coreboot project.
*
* Copyright (C) 2007 Advanced Micro Devices, Inc.
* Copyright (C) 2008 Ronald G. Minnich
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* setup a resource map.
* for PCRM entries, add a pci device offset, and a pci "OR value offset"
* for IO8 and IO32 entries, add an io base offset.
* This function combines a bunch of seperate functions that were scattered
* throughout v2. It may be awkward but it does allow for one rmap for
* all settings, which is handy. See include/arch/x86/cpu.h for usage on
* how to set up a resource map.
*
* @param rm The resource map
* @param max The map size
* @param offset_bdf pci device offset. Note this is a u32 in
* busdevfn format. See PCI_BDF macro if you are not sure what that is.
* @param offset_pciio added to the OR value for setting up PCI IO
* @param offset_io offset from the io base in the resource map
*/
/* NOTE: By doing the config write in this manner we guarantee that this
* will work in stage1 or stage2.
*/
#define pci_read_config32(bus, dev, where) pci_cf8_conf1.read32(NULL, r->pcm.bus, dev, where)
#define pci_write_config32(bus, dev, where, what) pci_cf8_conf1.write32(NULL, r->pcm.bus, dev, where, what)
void setup_resource_map_x_offset(const rmap *rm, u32 max,
u32 offset_bdf, u32 offset_pciio,
u32 offset_io)
{
u32 i;
printk(BIOS_DEBUG, "setting up resource map ex offset....\n");
for(i = 0; i < max; i++, rm++) {
switch (rm->type){
case TPCIRM:
{
u32 dev;
unsigned where;
unsigned long reg;
u8 offset_devfn = offset_bdf;
#warning make sure offset_bus is right for extended PCI addressing
u32 offset_bus = offset_bdf >> 8;
printk(BIOS_DEBUG, "(%x+%x,%x+%x,%x+%x,%x) & %08x | %08x+%08x\n", rm->pcm.bus,
offset_bus, rm->pcm.dev+offset_devfn>>3,
rm->pcm.fn, offset_devfn&3, rm->pcm.reg,
rm->pcm.and,rm->pcm.or, offset_pciio);
dev = rm->pcm.dev;
where = rm->pcm.reg;
dev <<= 3;
dev |= rm->pcm.fn;
dev += offset_devfn;
reg = pci_read_config32(rm->pcm.bus + offset_bus, dev, where);
reg &= rm->pcm.and;
reg |= rm->pcm.or + offset_pciio;
pci_write_config32(rm->pcm.bus, dev, where, reg);
}
break;
case TIO8:
{
u32 where;
u8 reg;
printk(BIOS_DEBUG, "(%04x+%04x) & %02x | %02xx\n", rm->port, offset_io, rm->pcm.and,rm->pcm.or);
where = rm->port + offset_io;
reg = inb(where);
reg &= rm->and;
reg |= rm->or;
outb(reg, where);
}
break;
case TIO32:
{
u32 where;
u32 reg;
printk(BIOS_DEBUG, "(%04x+%04x) & %02x | %02xx\n", rm->port, offset_io, rm->pcm.and,rm->pcm.or);
where = rm->port + offset_io;
reg = inl(where);
reg &= rm->and;
reg |= rm->or;
outl(reg, where);
}
break;
} // switch
}
printk(BIOS_DEBUG, "done.\n");
}
/**
* setup a resource map
* @param rm The resource map
* @param max The map size
*/
void setup_resource_map(const struct rmap *rm, u32 max)
{
setup_resource_map_x_offset(rm, max);
}