osal_result os_pci_find_next_device_by_class(
        os_pci_dev_t cur_pci_dev,
        os_pci_dev_t* next_pci_dev)
{
    pci_dev_t *     pdev;
    unsigned int    tempData;
    unsigned char   subclass, baseclass, pi;

    *next_pci_dev = NULL;

    if(cur_pci_dev == NULL) {
        return OSAL_INVALID_PARAM;
    }

    if(OSAL_SUCCESS != os_pci_read_config_32((pci_dev_t*) cur_pci_dev, 0x8, &tempData)) {
        return OSAL_ERROR;
    }

    pi        = (tempData & 0xFF00) >> 8;
    subclass  = (tempData & 0xFF0000) >> 16;
    baseclass = (tempData & 0xFF000000) >> 24;

    pdev = pci_find_device_by_class(subclass, baseclass, pi, (pci_dev_t*)cur_pci_dev);

    if(pdev == NULL) {
        return OSAL_NOT_FOUND;
    }

    *next_pci_dev = (os_pci_dev_t*) pdev;
    return OSAL_SUCCESS;
}
Exemple #2
0
int
main(uint32_t magic, struct mbi *mbi)
{
  if (magic == MBI_MAGIC) {
    if ((mbi->flags & MBI_FLAG_CMDLINE) != 0)
      parse_cmdline((const char *)mbi->cmdline);
  } else {
    printf("Not loaded by Multiboot-compliant loader. Bye.\n");
    return 1;
  }

  printf("\nBender %s\n", version_str);
  printf("Blame Julian Stecklina <*****@*****.**> for bugs.\n\n");

  printf("Looking for serial controllers on the PCI bus...\n");

  struct pci_device serial_ctrl;

  printf("Promisc is %s.\n", be_promisc ? "on" : "off");
  if (pci_find_device_by_class(PCI_CLASS_SIMPLE_COMM,
			       be_promisc ? PCI_SUBCLASS_ANY : PCI_SUBCLASS_SERIAL_CTRL,
			       &serial_ctrl)) {
    printf("  found at %x.\n", serial_ctrl.cfg_address);
  } else {
    printf("  none found.\n");
    goto boot_next;
  }

  uint16_t iobase = 0;
  for (unsigned bar_no = 0; bar_no < 6; bar_no++) {
    uint32_t bar = pci_cfg_read_uint32(&serial_ctrl, PCI_CFG_BAR0 + 4*bar_no);
    if ((bar & PCI_BAR_TYPE_MASK) == PCI_BAR_TYPE_IO) {
      iobase = bar & PCI_BAR_IO_MASK;
      break;
    }
  }

  iobase = apply_quirks(&serial_ctrl, iobase);

  uint16_t *com0_port      = (uint16_t *)(get_bios_data_area());
  uint16_t *equipment_word = &get_bios_data_area()->equipment;

  if (iobase != 0) {
    printf("Patching BDA with I/O port 0x%x.\n", iobase);
    *com0_port      = iobase;
    *equipment_word = (*equipment_word & ~(0xF << 9)) | (1 << 9); /* One COM port available */
  } else {
    printf("I/O ports for controller not found.\n");
  }

 boot_next:

  if (serial_ports(get_bios_data_area()))
    serial_init();

  printf("Bender: Hello World.\n");

  return start_module(mbi, false, phys_max_relocate);
}
osal_result os_pci_find_first_device_by_class(
        unsigned char subclass,
        unsigned char baseclass,
        unsigned char pi,
        os_pci_dev_t* pci_device)
{
    pci_dev_t *pdev;

    pdev = pci_find_device_by_class(subclass, baseclass, pi, NULL);

    if(pdev == NULL) {
        *pci_device = NULL;
        return OSAL_NOT_FOUND;
    }

    *pci_device = (os_pci_dev_t*) pdev;
    return OSAL_SUCCESS;
}