Clean up BAR setting code.

--HG--
extra : convert_revision : 8378be6cd6f55af7a199296cb2ff61ee94849bf7
This commit is contained in:
Steve Reinhardt 2006-08-28 11:17:49 -07:00
parent b77da23e1a
commit 72eb4f5f12

View file

@ -252,40 +252,33 @@ PciDev::writeConfig(Packet *pkt)
case PCI0_BASE_ADDR3: case PCI0_BASE_ADDR3:
case PCI0_BASE_ADDR4: case PCI0_BASE_ADDR4:
case PCI0_BASE_ADDR5: case PCI0_BASE_ADDR5:
{
int barnum = BAR_NUMBER(offset);
uint32_t barnum, bar_mask; // convert BAR values to host endianness
Addr base_addr, base_size, space_base; uint32_t he_old_bar = letoh(config.baseAddr[barnum]);
uint32_t he_new_bar = letoh(pkt->get<uint32_t>());
barnum = BAR_NUMBER(offset); uint32_t bar_mask =
BAR_IO_SPACE(he_old_bar) ? BAR_IO_MASK : BAR_MEM_MASK;
if (BAR_IO_SPACE(letoh(config.baseAddr[barnum]))) { // Writing 0xffffffff to a BAR tells the card to set the
bar_mask = BAR_IO_MASK; // value of the bar to a bitmask indicating the size of
space_base = TSUNAMI_PCI0_IO; // memory it needs
} else { if (he_new_bar == 0xffffffff) {
bar_mask = BAR_MEM_MASK; he_new_bar = ~(BARSize[barnum] - 1);
space_base = TSUNAMI_PCI0_MEMORY; } else {
} // does it mean something special to write 0 to a BAR?
he_new_bar &= ~bar_mask;
// Writing 0xffffffff to a BAR tells the card to set the if (he_new_bar) {
// value of the bar to size of memory it needs Addr space_base = BAR_IO_SPACE(he_old_bar) ?
if (letoh(pkt->get<uint32_t>()) == 0xffffffff) { TSUNAMI_PCI0_IO : TSUNAMI_PCI0_MEMORY;
// This is I/O Space, bottom two bits are read only BARAddrs[barnum] = he_new_bar + space_base;
pioPort->sendStatusChange(Port::RangeChange);
config.baseAddr[barnum] = letoh( }
(~(BARSize[barnum] - 1) & ~bar_mask) |
(letoh(config.baseAddr[barnum]) & bar_mask));
} else {
config.baseAddr[barnum] = letoh(
(letoh(pkt->get<uint32_t>()) & ~bar_mask) |
(letoh(config.baseAddr[barnum]) & bar_mask));
if (letoh(config.baseAddr[barnum]) & ~bar_mask) {
base_addr = (letoh(pkt->get<uint32_t>()) & ~bar_mask) + space_base;
base_size = BARSize[barnum];
BARAddrs[barnum] = base_addr;
pioPort->sendStatusChange(Port::RangeChange);
} }
config.baseAddr[barnum] = htole((he_new_bar & ~bar_mask) |
(he_old_bar & bar_mask));
} }
break; break;