Commit 6e383728 authored by Niclas Zeising's avatar Niclas Zeising
Browse files

freebsd_pci: remove old probe method



Remove the old probe method.  The PCIOCGETBAR ioctl has been in FreeBSD
since 8.0 release, if not earlier.  Remove the old way of doing it.
This is done using unifdef -DPCIOCGETBAR and cleaning up whitespace.
Signed-off-by: Niclas Zeising's avatarNiclas Zeising <zeising@daemonic.se>
parent e8c7e461
......@@ -362,8 +362,6 @@ pci_device_freebsd_get_num_regions( struct pci_device * dev )
}
}
#ifdef PCIOCGETBAR
static int
pci_device_freebsd_probe( struct pci_device * dev )
{
......@@ -415,167 +413,6 @@ pci_device_freebsd_probe( struct pci_device * dev )
return 0;
}
#else
/** Masks out the flag bigs of the base address register value */
static uint32_t
get_map_base( uint32_t val )
{
if (val & 0x01)
return val & ~0x03;
else
return val & ~0x0f;
}
/** Returns the size of a region based on the all-ones test value */
static int
get_test_val_size( uint32_t testval )
{
if (testval == 0)
return 0;
/* Mask out the flag bits */
testval = get_map_base( testval );
return 1 << (ffs(testval) - 1);
}
/**
* Sets the address and size information for the region from config space
* registers.
*
* This would be much better provided by a kernel interface.
*
* \return 0 on success, or an errno value.
*/
static int
pci_device_freebsd_get_region_info( struct pci_device * dev, int region,
int bar )
{
uint32_t addr, testval;
uint16_t cmd;
int err;
/* Get the base address */
err = pci_device_cfg_read_u32( dev, &addr, bar );
if (err != 0)
return err;
/*
* We are going to be doing evil things to the registers here
* so disable them via the command register first.
*/
err = pci_device_cfg_read_u16( dev, &cmd, PCIR_COMMAND );
if (err != 0)
return err;
err = pci_device_cfg_write_u16( dev,
cmd & ~(PCI_BAR_MEM(addr) ? PCIM_CMD_MEMEN : PCIM_CMD_PORTEN),
PCIR_COMMAND );
if (err != 0)
return err;
/* Test write all ones to the register, then restore it. */
err = pci_device_cfg_write_u32( dev, 0xffffffff, bar );
if (err != 0)
return err;
err = pci_device_cfg_read_u32( dev, &testval, bar );
if (err != 0)
return err;
err = pci_device_cfg_write_u32( dev, addr, bar );
if (err != 0)
return err;
/* Restore the command register */
err = pci_device_cfg_write_u16( dev, cmd, PCIR_COMMAND );
if (err != 0)
return err;
if (addr & 0x01)
dev->regions[region].is_IO = 1;
if (addr & 0x04)
dev->regions[region].is_64 = 1;
if (addr & 0x08)
dev->regions[region].is_prefetchable = 1;
/* Set the size */
dev->regions[region].size = get_test_val_size( testval );
printf("size = 0x%lx\n", (long)dev->regions[region].size);
/* Set the base address value */
if (dev->regions[region].is_64) {
uint32_t top;
err = pci_device_cfg_read_u32( dev, &top, bar + 4 );
if (err != 0)
return err;
dev->regions[region].base_addr = ((uint64_t)top << 32) |
get_map_base(addr);
} else {
dev->regions[region].base_addr = get_map_base(addr);
}
return 0;
}
static int
pci_device_freebsd_probe( struct pci_device * dev )
{
struct pci_device_private *priv = (struct pci_device_private *) dev;
uint32_t reg, size;
uint8_t irq;
int err, i, bar;
/* Many of the fields were filled in during initial device enumeration.
* At this point, we need to fill in regions, rom_size, and irq.
*/
err = pci_device_cfg_read_u8( dev, &irq, 60 );
if (err)
return errno;
dev->irq = irq;
bar = 0x10;
for (i = 0; i < pci_device_freebsd_get_num_regions( dev ); i++) {
pci_device_freebsd_get_region_info( dev, i, bar );
if (dev->regions[i].is_64) {
bar += 0x08;
i++;
} else
bar += 0x04;
}
/* If it's a VGA device, set up the rom size for read_rom */
if ((dev->device_class & 0x00ffff00) ==
((PCIC_DISPLAY << 16) | (PCIS_DISPLAY_VGA << 8)))
{
err = pci_device_cfg_read_u32( dev, &reg, PCIR_BIOS );
if (err)
return errno;
if (reg == 0) {
dev->rom_size = 0x10000;
return 0;
}
err = pci_device_cfg_write_u32( dev, ~PCIM_BIOS_ENABLE, PCIR_BIOS );
if (err)
return errno;
pci_device_cfg_read_u32( dev, &size, PCIR_BIOS );
pci_device_cfg_write_u32( dev, reg, PCIR_BIOS );
if ((reg & PCIM_BIOS_ADDR_MASK) != 0) {
priv->rom_base = (reg & PCIM_BIOS_ADDR_MASK);
dev->rom_size = -(size & PCIM_BIOS_ADDR_MASK);
}
}
return 0;
}
#endif
static void
pci_system_freebsd_destroy( void )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment