Use the BAR value returned by pcidev_init which automatically uses the correct BAR mask. Truncate flash chip addresses to fit into the 128 kB memory window.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-drkaiser_pcibar_mask_mem_bounds_checking/drkaiser.c =================================================================== --- flashrom-drkaiser_pcibar_mask_mem_bounds_checking/drkaiser.c (Revision 946) +++ flashrom-drkaiser_pcibar_mask_mem_bounds_checking/drkaiser.c (Arbeitskopie) @@ -40,16 +40,13 @@ uint32_t addr;
get_io_perms(); - pcidev_init(PCI_VENDOR_ID_DRKAISER, PCI_BASE_ADDRESS_2, - drkaiser_pcidev, programmer_param); + addr = pcidev_init(PCI_VENDOR_ID_DRKAISER, PCI_BASE_ADDRESS_2, + drkaiser_pcidev, programmer_param);
/* Write magic register to enable flash write. */ pci_write_word(pcidev_dev, PCI_MAGIC_DRKAISER_ADDR, PCI_MAGIC_DRKAISER_VALUE);
- /* TODO: Mask lower bits? How many? 3? 7? */ - addr = pci_read_long(pcidev_dev, PCI_BASE_ADDRESS_2) & ~0x03; - /* Map 128KB flash memory window. */ drkaiser_bar = physmap("Dr. Kaiser PC-Waechter flash memory", addr, 128 * 1024); @@ -70,10 +67,12 @@
void drkaiser_chip_writeb(uint8_t val, chipaddr addr) { - mmio_writeb(val, drkaiser_bar + addr); + /* Restrict flash accesses to the 128kB memory window. */ + mmio_writeb(val, drkaiser_bar + (addr & ((1 << 17) - 1))); }
uint8_t drkaiser_chip_readb(const chipaddr addr) { - return mmio_readb(drkaiser_bar + addr); + /* Restrict flash accesses to the 128kB memory window. */ + return mmio_readb(drkaiser_bar + (addr & ((1 << 17) - 1))); }