Bandit: implement address mask register.

This commit is contained in:
Maxim Poliakovski 2022-04-13 22:38:51 +02:00
parent 883aac2d05
commit d64f901f85
2 changed files with 71 additions and 0 deletions

View File

@ -57,6 +57,41 @@ Bandit::Bandit(int bridge_num, std::string name) : PCIHost(), PCIDevice(name)
this->pci_wr_cache_lnsz = [](uint8_t val) {}; // cache line size register
}
uint32_t Bandit::pci_cfg_read(uint32_t reg_offs, uint32_t size)
{
if (reg_offs < 64) {
return PCIDevice::pci_cfg_read(reg_offs, size);
}
switch (reg_offs) {
case BANDIT_ADDR_MASK:
return BYTESWAP_32(this->addr_mask);
default:
LOG_F(WARNING, "%s: reading from unimplemented config register at 0x%X",
this->pci_name.c_str(), reg_offs);
}
return 0;
}
void Bandit::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
{
if (reg_offs < 64) {
PCIDevice::pci_cfg_write(reg_offs, value, size);
return;
}
switch (reg_offs) {
case BANDIT_ADDR_MASK:
this->addr_mask = BYTESWAP_32(value);
this->verbose_address_space();
break;
default:
LOG_F(WARNING, "%s: writing to unimplemented config register at 0x%X",
this->pci_name.c_str(), reg_offs);
}
}
uint32_t Bandit::read(uint32_t reg_start, uint32_t offset, int size)
{
int fun_num;
@ -147,3 +182,27 @@ void Bandit::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size
LOG_F(WARNING, "%s: I/O space write not implemented yet", this->name.c_str());
}
}
void Bandit::verbose_address_space()
{
uint32_t mask;
int bit_pos;
LOG_F(INFO, "%s address spaces:", this->pci_name.c_str());
// verbose coarse aka 256MB memory regions
for (mask = 0x10000, bit_pos = 0; mask != 0x80000000UL; mask <<= 1, bit_pos++) {
if (this->addr_mask & mask) {
uint32_t start_addr = bit_pos << 28;
LOG_F(INFO, "- 0x%X ... 0x%X", start_addr, start_addr + 0x0FFFFFFFU);
}
}
// verbose fine aka 16MB memory regions
for (mask = 0x1, bit_pos = 0; mask != 0x10000UL; mask <<= 1, bit_pos++) {
if (this->addr_mask & mask) {
uint32_t start_addr = (bit_pos << 24) + 0xF0000000UL;
LOG_F(INFO, "- 0x%X ... 0x%X", start_addr, start_addr + 0x00FFFFFFU);
}
}
}

View File

@ -40,6 +40,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define BANDIT_CAR_TYPE (1 << 0) // Bandit config address type bit
#define BANDIT_CONFIG_SPACE 0x00800000 // Bandit Config Space bit
/** Bandit specific configuration registers. */
enum {
BANDIT_ADDR_MASK = 0x48,
};
/** checks if one bit is set at time, return 0 if not */
#define SINGLE_BIT_SET(val) ((val) && !((val) & ((val)-1)))
@ -52,13 +57,20 @@ public:
return (type == HWCompType::PCI_HOST || type == HWCompType::PCI_DEV);
};
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
// MMIODevice methods
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
protected:
void verbose_address_space();
private:
uint32_t base_addr;
uint32_t config_addr;
uint32_t addr_mask;
};
#endif // BANDIT_PCI_H