void bx_pcipnic_c::init(void) { bx_list_c *base; // Read in values from config interface base = (bx_list_c*) SIM->get_param(BXPN_PNIC); memcpy(BX_PNIC_THIS s.macaddr, SIM->get_param_string("macaddr", base)->getptr(), 6); BX_PNIC_THIS s.devfunc = 0x00; DEV_register_pci_handlers(this, &BX_PNIC_THIS s.devfunc, BX_PLUGIN_PCIPNIC, "Experimental PCI Pseudo NIC"); for (unsigned i=0; i<256; i++) { BX_PNIC_THIS s.pci_conf[i] = 0x0; } // This code ripped wholesale from ne2k.cc: // Attach to the simulated ethernet dev char *ethmod = SIM->get_param_enum("ethmod", base)->get_selected(); BX_PNIC_THIS ethdev = eth_locator_c::create(ethmod, SIM->get_param_string("ethdev", base)->getptr(), (const char *) SIM->get_param_string("macaddr", base)->getptr(), rx_handler, this, SIM->get_param_string("script", base)->getptr()); if (BX_PNIC_THIS ethdev == NULL) { BX_PANIC(("could not find eth module %s", ethmod)); // if they continue, use null. BX_INFO(("could not find eth module %s - using null instead", ethmod)); BX_PNIC_THIS ethdev = eth_locator_c::create("null", NULL, (const char *) SIM->get_param_string("macaddr", base)->getptr(), rx_handler, this, ""); if (BX_PNIC_THIS ethdev == NULL) BX_PANIC(("could not locate null module")); } BX_PNIC_THIS s.base_ioaddr = 0; BX_INFO(("PCI Pseudo NIC initialized - I/O base and IRQ assigned by PCI BIOS")); }
void bx_piix3_c::init(void) { unsigned i; // called once when bochs initializes Bit8u devfunc = BX_PCI_DEVICE(1,0); DEV_register_pci_handlers(this, &devfunc, BX_PLUGIN_PCI2ISA, "PIIX3 PCI-to-ISA bridge"); DEV_register_iowrite_handler(this, write_handler, 0x00B2, "PIIX3 PCI-to-ISA bridge", 1); DEV_register_iowrite_handler(this, write_handler, 0x00B3, "PIIX3 PCI-to-ISA bridge", 1); DEV_register_iowrite_handler(this, write_handler, 0x04D0, "PIIX3 PCI-to-ISA bridge", 1); DEV_register_iowrite_handler(this, write_handler, 0x04D1, "PIIX3 PCI-to-ISA bridge", 1); DEV_register_iowrite_handler(this, write_handler, 0x0CF9, "PIIX3 PCI-to-ISA bridge", 1); DEV_register_ioread_handler(this, read_handler, 0x00B2, "PIIX3 PCI-to-ISA bridge", 1); DEV_register_ioread_handler(this, read_handler, 0x00B3, "PIIX3 PCI-to-ISA bridge", 1); DEV_register_ioread_handler(this, read_handler, 0x04D0, "PIIX3 PCI-to-ISA bridge", 1); DEV_register_ioread_handler(this, read_handler, 0x04D1, "PIIX3 PCI-to-ISA bridge", 1); DEV_register_ioread_handler(this, read_handler, 0x0CF9, "PIIX3 PCI-to-ISA bridge", 1); for (i=0; i<256; i++) BX_P2I_THIS s.pci_conf[i] = 0x0; for (i=0; i<16; i++) BX_P2I_THIS s.irq_registry[i] = 0x0; for (i=0; i<16; i++) BX_P2I_THIS s.irq_level[i] = 0x0; // readonly registers BX_P2I_THIS s.pci_conf[0x00] = 0x86; BX_P2I_THIS s.pci_conf[0x01] = 0x80; BX_P2I_THIS s.pci_conf[0x02] = 0x00; BX_P2I_THIS s.pci_conf[0x03] = 0x70; BX_P2I_THIS s.pci_conf[0x04] = 0x07; BX_P2I_THIS s.pci_conf[0x0a] = 0x01; BX_P2I_THIS s.pci_conf[0x0b] = 0x06; BX_P2I_THIS s.pci_conf[0x0e] = 0x80; // irq routing registers BX_P2I_THIS s.pci_conf[0x60] = 0x80; BX_P2I_THIS s.pci_conf[0x61] = 0x80; BX_P2I_THIS s.pci_conf[0x62] = 0x80; BX_P2I_THIS s.pci_conf[0x63] = 0x80; }
void bx_pcipnic_c::init(void) { bx_list_c *base; // Read in values from config interface base = (bx_list_c*) SIM->get_param(BXPN_PNIC); memcpy(BX_PNIC_THIS s.macaddr, SIM->get_param_string("macaddr", base)->getptr(), 6); BX_PNIC_THIS s.devfunc = 0x00; DEV_register_pci_handlers(this, &BX_PNIC_THIS s.devfunc, BX_PLUGIN_PCIPNIC, "Experimental PCI Pseudo NIC"); for (unsigned i=0; i<256; i++) { BX_PNIC_THIS pci_conf[i] = 0x0; } // Attach to the selected ethernet module BX_PNIC_THIS ethdev = DEV_net_init_module(base, rx_handler, this); BX_PNIC_THIS pci_base_address[4] = 0; BX_INFO(("PCI Pseudo NIC initialized - I/O base and IRQ assigned by PCI BIOS")); }
void bx_pcidev_c::init(void) { // called once when bochs initializes BX_PCIDEV_THIS pcidev_fd = -1; int fd; fd = open("/dev/pcidev", O_RDWR); if (fd == -1) { switch(errno) { case ENODEV: BX_PANIC(("The pcidev kernel module is not loaded!")); break; default: BX_PANIC(("open /dev/pcidev: %s", strerror(errno))); break; } return; } BX_PCIDEV_THIS pcidev_fd = fd; struct pcidev_find_struct find; unsigned short vendor = SIM->get_param_num(BXPN_PCIDEV_VENDOR)->get(); unsigned short device = SIM->get_param_num(BXPN_PCIDEV_DEVICE)->get(); find.deviceID = device; find.vendorID = vendor; if (ioctl(fd, PCIDEV_IOCTL_FIND, &find) == -1) { switch (errno) { case ENOENT: BX_PANIC(("PCI device not found on host system.")); break; case EBUSY: BX_PANIC(("PCI device already used by another kernel module.")); break; default: perror("ioctl"); break; } close(fd); BX_PCIDEV_THIS pcidev_fd = -1; return; } BX_INFO(("vendor: %04x; device: %04x @ host %04x:%04x.%d", vendor, device, (unsigned)find.bus, (unsigned)find.device, (unsigned)find.func)); BX_PCIDEV_THIS devfunc = 0x00; DEV_register_pci_handlers(this, &BX_PCIDEV_THIS devfunc, BX_PLUGIN_PCIDEV, pcidev_name); BX_PCIDEV_THIS irq = 0; struct pcidev_io_struct io; io.address = 0x3d; int ret = ioctl(fd, PCIDEV_IOCTL_READ_CONFIG_BYTE, &io); if (ret != -1) { BX_PCIDEV_THIS intpin = io.value; } else { BX_PCIDEV_THIS intpin = 0; } for (int idx = 0; idx < PCIDEV_COUNT_RESOURCES; idx++) { BX_PCIDEV_THIS regions[idx].start = 0; // emulated device not yet initialized if (!find.resources[idx].start) continue; BX_INFO(("PCI resource @ %x-%x (%s)", (unsigned)find.resources[idx].start, (unsigned)find.resources[idx].end, (find.resources[idx].flags & PCIDEV_RESOURCE_IO ? "I/O" : "Mem"))); BX_PCIDEV_THIS regions[idx].size = find.resources[idx].end - find.resources[idx].start + 1; BX_PCIDEV_THIS regions[idx].host_start = find.resources[idx].start; struct pcidev_io_struct io; io.address = PCI_BASE_ADDRESS_0 + idx * 4; if (ioctl(fd, PCIDEV_IOCTL_READ_CONFIG_DWORD, &io) == -1) BX_ERROR(("Error reading a base address config reg")); BX_PCIDEV_THIS regions[idx].config_value = io.value; /* * We will use ®ion[idx] as parameter for our I/O or memory * handler. So we provide a pcidev pointer to the pcidev object * in order for the handle to be able to use its pcidev object */ BX_PCIDEV_THIS regions[idx].pcidev = this; } struct sigaction sa; sa.sa_handler = pcidev_sighandler; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sigaction(SIGUSR1, &sa, NULL); /* * The kernel pcidev will fire SIGUSR1 signals when it receives * interrupts from the host PCI device. */ ioctl(fd, PCIDEV_IOCTL_INTERRUPT, 1); }