Exemple #1
0
int pci_config_write(unsigned char bus, unsigned char dev, unsigned char func,
		    unsigned char cmd, int len, unsigned long val)
{
    int ret;
    
    ret = enable_app_io();
    if (ret != 0)
	return ret;
    switch(len)
    {
	case 4:
	    pci_config_write_long(bus, dev, func, cmd, val);
	    break;
	case 2:
	    pci_config_write_word(bus, dev, func, cmd, val);
	    break;
	case 1:
	    pci_config_write_byte(bus, dev, func, cmd, val);
	    break;
	default:
	    printf("libdha_pci: wrong length to read: %u\n",len);
    }
    disable_app_io();

    return 0;
}
Exemple #2
0
void vbgfxinit(uint8_t bus, uint8_t slot)
{
  char b[64];
  puts("vbgfx: init on PCI bus:slot ");
  puts(itoa(bus, b, 10)); putc(':'); puts(itoa(slot, b, 10));
  putc('\n');
  uint16_t vendor = pci_config_read_word(bus, slot, 0, 0);
  if(vendor == 0xFFFF)
  {
    puts("vbgfx: init failed: device not found on specified bus:slot\n");
    return;
  }
  uint16_t device = pci_config_read_word(bus, slot, 0, 2);
  if(vendor != 0x80ee || (device != 0xBEEF && device != 0x7145))
  {
    puts("vbgfx: init failed: device is not compatible\n");
    return;
  }
  vbgfx_bus = bus;
  vbgfx_slot = slot;
  /*uint32_t bar0, bar1, bar2, bar3, bar4, bar5;
  bar0 = pci_config_read_dword(bus, slot, 0, 0x10);
  bar1 = pci_config_read_dword(bus, slot, 0, 0x14);
  bar2 = pci_config_read_dword(bus, slot, 0, 0x18);
  bar3 = pci_config_read_dword(bus, slot, 0, 0x1C);
  bar4 = pci_config_read_dword(bus, slot, 0, 0x20);
  bar5 = pci_config_read_dword(bus, slot, 0, 0x24);
  uint8_t progif = pci_config_read_word(bus, slot, 0, 0xA) >> 8;
  uint8_t status = pci_config_read_word(bus, slot, 0, 0x4);
  uint8_t cmd = pci_config_read_word(bus, slot, 0, 0x6);*/
  iobase = 0x01CE;
  uint16_t ver;
  outw(iobase + VBGFX_IO_INDEX, VBGFX_INDEX_ID);
  ver = inw(iobase + VBGFX_IO_DATA);
  if(ver < 0xB0C4 ) //check version
  {
    puts("vbgfx: bad id: "); puts(itoa(ver, b, 16)); putc('\n');
    iobase = 0;
    if(!vgetw()) //if grub didn't give us vbe
      pci_config_write_word(bus, slot, 0, 0x06, 0); //disconnect device
    return;
  }
  vga_card* v = graphics_add_card();
  if(v == NULL) return;
  v->vendor = vendor;
  v->device = device;
  strcpy(v->name, "VBoxVideo");
  v->data[0] = iobase;
  v->bus = bus; v->slot = slot;
  v->set_mode = &vbgfx_set_res;
  //vbgfx_set_res(v, 1024, 768, 32);
}
Exemple #3
0
int pci_config_write(unsigned char bus, unsigned char dev, unsigned char func,
		    unsigned char cmd, int len, unsigned long val)
{
    int ret;
    
    int dhahelper_fd;
    if ( (dhahelper_fd = open("/dev/dhahelper",O_RDWR)) > 0)
    {
	int retval;
	dhahelper_pci_config_t pcic;
	pcic.operation = PCI_OP_WRITE;
	pcic.bus = bus;
	pcic.dev = dev;
	pcic.func = func;
	pcic.cmd = cmd;
	pcic.size = len;
	pcic.ret = val;
	retval = ioctl(dhahelper_fd, DHAHELPER_PCI_CONFIG, &pcic);
	close(dhahelper_fd);
	return retval;
    }
    ret = enable_app_io();
    if (ret != 0)
	return ret;
    switch(len)
    {
	case 4:
	    pci_config_write_long(bus, dev, func, cmd, val);
	    break;
	case 2:
	    pci_config_write_word(bus, dev, func, cmd, val);
	    break;
	case 1:
	    pci_config_write_byte(bus, dev, func, cmd, val);
	    break;
	default:
	    printf("libdha_pci: wrong length to read: %u\n",len);
    }
    disable_app_io();

    return 0;
}