/* * Attach the hypervisor. */ void hypervisor_attach(device_t parent, device_t self, void *aux) { #if NPCI >0 #ifdef PCI_BUS_FIXUP int pci_maxbus = 0; #endif #endif /* NPCI */ union hypervisor_attach_cookie hac; char xen_extra_version[XEN_EXTRAVERSION_LEN]; static char xen_version_string[20]; int rc; const struct sysctlnode *node = NULL; xenkernfs_init(); xen_version = HYPERVISOR_xen_version(XENVER_version, NULL); memset(xen_extra_version, 0, sizeof(xen_extra_version)); HYPERVISOR_xen_version(XENVER_extraversion, xen_extra_version); rc = snprintf(xen_version_string, 20, "%d.%d%s", XEN_MAJOR(xen_version), XEN_MINOR(xen_version), xen_extra_version); aprint_normal(": Xen version %s\n", xen_version_string); if (rc >= 20) aprint_debug(": xen_version_string truncated\n"); sysctl_createv(NULL, 0, NULL, &node, 0, CTLTYPE_NODE, "xen", SYSCTL_DESCR("Xen top level node"), NULL, 0, NULL, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL); if (node != NULL) { sysctl_createv(NULL, 0, &node, NULL, CTLFLAG_READONLY, CTLTYPE_STRING, "version", SYSCTL_DESCR("Xen hypervisor version"), NULL, 0, xen_version_string, 0, CTL_CREATE, CTL_EOL); } aprint_verbose_dev(self, "features: "); #define XEN_TST_F(n) \ if (xen_feature(XENFEAT_##n)) \ aprint_verbose(" %s", #n); XEN_TST_F(writable_page_tables); XEN_TST_F(writable_descriptor_tables); XEN_TST_F(auto_translated_physmap); XEN_TST_F(supervisor_mode_kernel); XEN_TST_F(pae_pgdir_above_4gb); XEN_TST_F(mmu_pt_update_preserve_ad); XEN_TST_F(highmem_assist); XEN_TST_F(gnttab_map_avail_bits); XEN_TST_F(hvm_callback_vector); XEN_TST_F(hvm_safe_pvclock); XEN_TST_F(hvm_pirqs); #undef XEN_TST_F aprint_verbose("\n"); xengnt_init(); events_init(); memset(&hac, 0, sizeof(hac)); hac.hac_vcaa.vcaa_name = "vcpu"; hac.hac_vcaa.vcaa_caa.cpu_number = 0; hac.hac_vcaa.vcaa_caa.cpu_role = CPU_ROLE_BP; hac.hac_vcaa.vcaa_caa.cpu_func = NULL; /* See xen/x86/cpu.c:vcpu_attach() */ config_found_ia(self, "xendevbus", &hac.hac_vcaa, hypervisor_print); #ifdef MULTIPROCESSOR /* * The xenstore contains the configured number of vcpus. * The xenstore however, is not accessible until much later in * the boot sequence. We therefore bruteforce check for * allocated vcpus (See: cpu.c:vcpu_match()) by iterating * through the maximum supported by NetBSD MP. */ cpuid_t vcpuid; for (vcpuid = 1; vcpuid < maxcpus; vcpuid++) { memset(&hac, 0, sizeof(hac)); hac.hac_vcaa.vcaa_name = "vcpu"; hac.hac_vcaa.vcaa_caa.cpu_number = vcpuid; hac.hac_vcaa.vcaa_caa.cpu_role = CPU_ROLE_AP; hac.hac_vcaa.vcaa_caa.cpu_func = NULL; /* See xen/x86/cpu.c:vcpu_attach() */ if (NULL == config_found_ia(self, "xendevbus", &hac.hac_vcaa, hypervisor_vcpu_print)) { break; } } #endif /* MULTIPROCESSOR */ #if NXENBUS > 0 memset(&hac, 0, sizeof(hac)); hac.hac_xenbus.xa_device = "xenbus"; config_found_ia(self, "xendevbus", &hac.hac_xenbus, hypervisor_print); #endif #if NXENCONS > 0 memset(&hac, 0, sizeof(hac)); hac.hac_xencons.xa_device = "xencons"; config_found_ia(self, "xendevbus", &hac.hac_xencons, hypervisor_print); #endif #ifdef DOM0OPS #if NPCI > 0 #if NACPICA > 0 if (acpi_present) { memset(&hac, 0, sizeof(hac)); hac.hac_acpi.aa_iot = x86_bus_space_io; hac.hac_acpi.aa_memt = x86_bus_space_mem; hac.hac_acpi.aa_pc = NULL; hac.hac_acpi.aa_pciflags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY | PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY; hac.hac_acpi.aa_ic = &x86_isa_chipset; hac.hac_acpi.aa_dmat = &pci_bus_dma_tag; #ifdef _LP64 hac.hac_acpi.aa_dmat64 = &pci_bus_dma64_tag; #else hac.hac_acpi.aa_dmat64 = NULL; #endif /* _LP64 */ config_found_ia(self, "acpibus", &hac.hac_acpi, 0); } #endif /* NACPICA */ memset(&hac, 0, sizeof(hac)); hac.hac_pba.pba_iot = x86_bus_space_io; hac.hac_pba.pba_memt = x86_bus_space_mem; hac.hac_pba.pba_dmat = &pci_bus_dma_tag; #ifdef _LP64 hac.hac_pba.pba_dmat64 = &pci_bus_dma64_tag; #else hac.hac_pba.pba_dmat64 = NULL; #endif /* _LP64 */ hac.hac_pba.pba_flags = PCI_FLAGS_MEM_OKAY | PCI_FLAGS_IO_OKAY; hac.hac_pba.pba_bridgetag = NULL; hac.hac_pba.pba_bus = 0; #if NACPICA > 0 && defined(ACPI_SCANPCI) if (mpacpi_active) mp_pci_scan(self, &hac.hac_pba, pcibusprint); else #endif #if defined(MPBIOS) && defined(MPBIOS_SCANPCI) if (mpbios_scanned != 0) mp_pci_scan(self, &hac.hac_pba, pcibusprint); else #endif config_found_ia(self, "pcibus", &hac.hac_pba, pcibusprint); #if NACPICA > 0 if (mp_verbose) acpi_pci_link_state(); #endif #if NISA > 0 if (isa_has_been_seen == 0) { memset(&hac, 0, sizeof(hac)); hac.hac_iba._iba_busname = "isa"; hac.hac_iba.iba_iot = x86_bus_space_io; hac.hac_iba.iba_memt = x86_bus_space_mem; hac.hac_iba.iba_dmat = &isa_bus_dma_tag; hac.hac_iba.iba_ic = NULL; /* No isa DMA yet */ config_found_ia(self, "isabus", &hac.hac_iba, isabusprint); } #endif /* NISA */ #endif /* NPCI */ if (xendomain_is_privileged()) { xenprivcmd_init(); xen_shm_init(); } #endif /* DOM0OPS */ hypervisor_machdep_attach(); if (!pmf_device_register(self, hypervisor_suspend, hypervisor_resume)) aprint_error_dev(self, "couldn't establish power handler\n"); }
/* * Attach the mainbus. */ void mainbus_attach(device_t parent, device_t self, void *aux) { #if NPCI > 0 union mainbus_attach_args mba; #endif #if NACPI > 0 int acpi_present = 0; #endif #ifdef MPBIOS int mpbios_present = 0; #endif int mpacpi_active = 0; int numcpus = 0; #if NACPI > 0 || defined(MPBIOS) int numioapics = 0; #endif #if defined(PCI_BUS_FIXUP) int pci_maxbus = 0; #endif aprint_naive("\n"); aprint_normal("\n"); #ifdef MPBIOS mpbios_present = mpbios_probe(self); #endif #if NPCI > 0 pci_mode = pci_mode_detect(); #if defined(PCI_BUS_FIXUP) if (pci_mode != 0) { pci_maxbus = pci_bus_fixup(NULL, 0); aprint_debug("PCI bus max, after pci_bus_fixup: %i\n", pci_maxbus); #if defined(PCI_ADDR_FIXUP) pciaddr.extent_port = NULL; pciaddr.extent_mem = NULL; pci_addr_fixup(NULL, pci_maxbus); #endif } #endif #endif #if NACPI > 0 if ((boothowto & RB_MD2) == 0 && acpi_check(self, "acpibus")) acpi_present = acpi_probe(); /* * First, see if the MADT contains CPUs, and possibly I/O APICs. * Building the interrupt routing structures can only * be done later (via a callback). */ if (acpi_present) mpacpi_active = mpacpi_scan_apics(self, &numcpus, &numioapics); #endif if (!mpacpi_active) { #ifdef MPBIOS if (mpbios_present) mpbios_scan(self, &numcpus, &numioapics); else #endif if (numcpus == 0) { struct cpu_attach_args caa; memset(&caa, 0, sizeof(caa)); caa.cpu_number = 0; caa.cpu_role = CPU_ROLE_SP; caa.cpu_func = 0; config_found_ia(self, "cpubus", &caa, mainbus_print); } } #if NISADMA > 0 && NACPI > 0 /* * ACPI needs ISA DMA initialized before they start probing. */ isa_dmainit(&x86_isa_chipset, X86_BUS_SPACE_IO, &isa_bus_dma_tag, self); #endif #if NACPI > 0 if (acpi_present) { mba.mba_acpi.aa_iot = X86_BUS_SPACE_IO; mba.mba_acpi.aa_memt = X86_BUS_SPACE_MEM; mba.mba_acpi.aa_pc = NULL; mba.mba_acpi.aa_pciflags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED | PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY; mba.mba_acpi.aa_ic = &x86_isa_chipset; config_found_ia(self, "acpibus", &mba.mba_acpi, 0); } #endif #if NIPMI > 0 memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi)); mba.mba_ipmi.iaa_iot = X86_BUS_SPACE_IO; mba.mba_ipmi.iaa_memt = X86_BUS_SPACE_MEM; if (ipmi_probe(&mba.mba_ipmi)) config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0); #endif #if NPCI > 0 if (pci_mode != 0) { mba.mba_pba.pba_iot = X86_BUS_SPACE_IO; mba.mba_pba.pba_memt = X86_BUS_SPACE_MEM; mba.mba_pba.pba_dmat = &pci_bus_dma_tag; mba.mba_pba.pba_dmat64 = &pci_bus_dma64_tag; mba.mba_pba.pba_pc = NULL; mba.mba_pba.pba_flags = pci_bus_flags(); mba.mba_pba.pba_bus = 0; mba.mba_pba.pba_bridgetag = NULL; #if NACPI > 0 && defined(ACPI_SCANPCI) if (mpacpi_active) mpacpi_scan_pci(self, &mba.mba_pba, pcibusprint); else #endif #if defined(MPBIOS) && defined(MPBIOS_SCANPCI) if (mpbios_scanned != 0) mpbios_scan_pci(self, &mba.mba_pba, pcibusprint); else #endif config_found_ia(self, "pcibus", &mba.mba_pba, pcibusprint); #if NACPI > 0 if (mp_verbose) acpi_pci_link_state(); #endif } #endif #if NISA > 0 if (isa_has_been_seen == 0) config_found_ia(self, "isabus", &mba_iba, isabusprint); #endif if (!pmf_device_register(self, NULL, NULL)) aprint_error_dev(self, "couldn't establish power handler\n"); }