static int nexus_attach(device_t dev) { device_t child; /* * First, let our child driver's identify any child devices that * they can find. Once that is done attach any devices that we * found. */ #if 0 /* FUTURE */ bus_generic_probe(dev); #endif bus_generic_attach(dev); /* * And if we didn't see EISA or ISA on a pci bridge, create some * connection points now so they show up "on motherboard". */ if (!devclass_get_device(devclass_find("eisa"), 0)) { child = BUS_ADD_CHILD(dev, dev, 0, "eisa", 0); if (child == NULL) panic("nexus_attach eisa"); device_probe_and_attach(child); } if (!devclass_get_device(devclass_find("isa"), 0)) { child = BUS_ADD_CHILD(dev, dev, 0, "isa", 0); if (child == NULL) panic("nexus_attach isa"); device_probe_and_attach(child); } return 0; }
/* The backend is now connected so complete the connection process on our side */ static int pcifront_connect(struct pcifront_device *pdev) { device_t nexus; devclass_t nexus_devclass; /* We will add our device as a child of the nexus0 device */ if (!(nexus_devclass = devclass_find("nexus")) || !(nexus = devclass_get_device(nexus_devclass, 0))) { WPRINTF("could not find nexus0!\n"); return -1; } /* Create a newbus device representing this frontend instance */ pdev->ndev = BUS_ADD_CHILD(nexus, 0, "xpcife", pdev->unit); if (!pdev->ndev) { WPRINTF("could not create xpcife%d!\n", pdev->unit); return -EFAULT; } get_pdev(pdev); device_set_ivars(pdev->ndev, pdev); /* Good to go connected now */ xenbus_switch_state(pdev->xdev, NULL, XenbusStateConnected); printf("pcifront: connected to %s\n", pdev->xdev->nodename); mtx_lock(&Giant); device_probe_and_attach(pdev->ndev); mtx_unlock(&Giant); return 0; }
/*------------------------------------------------------------------------* * usb_attach_sub * * This function creates a thread which runs the USB attach code. *------------------------------------------------------------------------*/ static void usb_attach_sub(device_t dev, struct usb_bus *bus) { const char *pname = device_get_nameunit(dev); mtx_lock(&Giant); if (usb_devclass_ptr == NULL) usb_devclass_ptr = devclass_find("usbus"); mtx_unlock(&Giant); #if USB_HAVE_PF usbpf_attach(bus); #endif /* Initialise USB process messages */ bus->explore_msg[0].hdr.pm_callback = &usb_bus_explore; bus->explore_msg[0].bus = bus; bus->explore_msg[1].hdr.pm_callback = &usb_bus_explore; bus->explore_msg[1].bus = bus; bus->detach_msg[0].hdr.pm_callback = &usb_bus_detach; bus->detach_msg[0].bus = bus; bus->detach_msg[1].hdr.pm_callback = &usb_bus_detach; bus->detach_msg[1].bus = bus; bus->attach_msg[0].hdr.pm_callback = &usb_bus_attach; bus->attach_msg[0].bus = bus; bus->attach_msg[1].hdr.pm_callback = &usb_bus_attach; bus->attach_msg[1].bus = bus; /* Create USB explore and callback processes */ if (usb_proc_create(&bus->giant_callback_proc, &bus->bus_mtx, pname, USB_PRI_MED)) { device_printf(dev, "WARNING: Creation of USB Giant " "callback process failed.\n"); } else if (usb_proc_create(&bus->non_giant_callback_proc, &bus->bus_mtx, pname, USB_PRI_HIGH)) { device_printf(dev, "WARNING: Creation of USB non-Giant " "callback process failed.\n"); } else if (usb_proc_create(&bus->explore_proc, &bus->bus_mtx, pname, USB_PRI_MED)) { device_printf(dev, "WARNING: Creation of USB explore " "process failed.\n"); } else if (usb_proc_create(&bus->control_xfer_proc, &bus->bus_mtx, pname, USB_PRI_MED)) { device_printf(dev, "WARNING: Creation of USB control transfer " "process failed.\n"); } else { /* Get final attach going */ USB_BUS_LOCK(bus); if (usb_proc_msignal(&bus->explore_proc, &bus->attach_msg[0], &bus->attach_msg[1])) { /* ignore */ } USB_BUS_UNLOCK(bus); /* Do initial explore */ usb_needs_explore(bus, 1); } }
static int legacy_attach(device_t dev) { device_t child; /* * Let our child drivers identify any child devices that they * can find. Once that is done attach any devices that we * found. */ bus_generic_probe(dev); bus_generic_attach(dev); /* * If we didn't see ISA on a pci bridge, create some * connection points now so it shows up "on motherboard". */ if (!devclass_get_device(devclass_find("isa"), 0)) { child = BUS_ADD_CHILD(dev, 0, "isa", 0); if (child == NULL) panic("legacy_attach isa"); device_probe_and_attach(child); } return 0; }
/* * When cpufreq levels change, find out about the (new) max frequency. We * use this to update CPU accounting in case it got a lower estimate at boot. */ static void tsc_levels_changed(void *arg, int unit) { device_t cf_dev; struct cf_level *levels; int count, error; uint64_t max_freq; /* Only use values from the first CPU, assuming all are equal. */ if (unit != 0) return; /* Find the appropriate cpufreq device instance. */ cf_dev = devclass_get_device(devclass_find("cpufreq"), unit); if (cf_dev == NULL) { printf("tsc_levels_changed() called but no cpufreq device?\n"); return; } /* Get settings from the device and find the max frequency. */ count = 64; levels = malloc(count * sizeof(*levels), M_TEMP, M_NOWAIT); if (levels == NULL) return; error = CPUFREQ_LEVELS(cf_dev, levels, &count); if (error == 0 && count != 0) { max_freq = (uint64_t)levels[0].total_set.freq * 1000000; set_cputicker(rdtsc, max_freq, 1); } else printf("tsc_levels_changed: no max freq found\n"); free(levels, M_TEMP); }
static void acpi_pci_update_device(ACPI_HANDLE handle, device_t pci_child) { ACPI_STATUS status; device_t child; /* * Occasionally a PCI device may show up as an ACPI device * with a _HID. (For example, the TabletPC TC1000 has a * second PCI-ISA bridge that has a _HID for an * acpi_sysresource device.) In that case, leave ACPI-CA's * device data pointing at the ACPI-enumerated device. */ child = acpi_get_device(handle); if (child != NULL) { KASSERT(device_get_parent(child) == devclass_get_device(devclass_find("acpi"), 0), ("%s: child (%s)'s parent is not acpi0", __func__, acpi_name(handle))); return; } /* * Update ACPI-CA to use the PCI enumerated device_t for this handle. */ status = AcpiAttachData(handle, acpi_fake_objhandler, pci_child); if (ACPI_FAILURE(status)) printf("WARNING: Unable to attach object data to %s - %s\n", acpi_name(handle), AcpiFormatException(status)); }
ACPI_STATUS AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber, ACPI_OSD_HANDLER ServiceRoutine) { struct acpi_softc *sc; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); if (!acpi_sci_enabled()) return_ACPI_STATUS (AE_OK); if (InterruptNumber > 255 || ServiceRoutine == NULL) return_ACPI_STATUS (AE_BAD_PARAMETER); if ((sc = devclass_get_softc(devclass_find("acpi"), 0)) == NULL) panic("can't find ACPI device to deregister interrupt"); if (sc->acpi_irq == NULL) return_ACPI_STATUS (AE_NOT_EXIST); bus_teardown_intr(sc->acpi_dev, sc->acpi_irq, sc->acpi_irq_handle); bus_release_resource(sc->acpi_dev, SYS_RES_IRQ, 0, sc->acpi_irq); bus_delete_resource(sc->acpi_dev, SYS_RES_IRQ, 0); sc->acpi_irq = NULL; InterruptHandler = NULL; return_ACPI_STATUS (AE_OK); }
static int acpi_smbat_attach(device_t dev) { struct acpi_smbat_softc *sc; uint32_t base; sc = device_get_softc(dev); if (ACPI_FAILURE(acpi_GetInteger(acpi_get_handle(dev), "_EC", &base))) { device_printf(dev, "cannot get EC base address\n"); return (ENXIO); } sc->sb_base_addr = (base >> 8) & 0xff; /* XXX Only works with one EC, but nearly all systems only have one. */ sc->ec_dev = devclass_get_device(devclass_find("acpi_ec"), 0); if (sc->ec_dev == NULL) { device_printf(dev, "cannot find EC device\n"); return (ENXIO); } timespecclear(&sc->bif_lastupdated); timespecclear(&sc->bst_lastupdated); if (acpi_battery_register(dev) != 0) { device_printf(dev, "cannot register battery\n"); return (ENXIO); } return (0); }
int acpi_machdep_init(device_t dev) { struct acpi_softc *acpi_sc; acpi_sc = devclass_get_softc(devclass_find("acpi"), 0); /* Create a clone for /dev/acpi also. */ STAILQ_INIT(&acpi_sc->apm_cdevs); acpi_sc->acpi_clone = apm_create_clone(acpi_sc->acpi_dev_t, acpi_sc); clone_setup(&apm_clones); EVENTHANDLER_REGISTER(dev_clone, apm_clone, 0, 1000); acpi_install_wakeup_handler(acpi_sc); if (intr_model == ACPI_INTR_PIC) BUS_CONFIG_INTR(dev, AcpiGbl_FADT.SciInterrupt, INTR_TRIGGER_LEVEL, INTR_POLARITY_LOW); else acpi_SetIntrModel(intr_model); SYSCTL_ADD_UINT(&acpi_sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO, "reset_video", CTLFLAG_RW, &acpi_reset_video, 0, "Call the VESA reset BIOS vector on the resume path"); return (0); }
/* * Print the command queue states for controller 0 (callable from DDB) */ void aac_printstate0(void) { struct aac_softc *sc; sc = devclass_get_softc(devclass_find("aac"), 0); aac_print_queues(sc); switch (sc->aac_hwif) { case AAC_HWIF_I960RX: case AAC_HWIF_NARK: device_printf(sc->aac_dev, "IDBR 0x%08x IIMR 0x%08x " "IISR 0x%08x\n", AAC_MEM0_GETREG4(sc, AAC_RX_IDBR), AAC_MEM0_GETREG4(sc, AAC_RX_IIMR), AAC_MEM0_GETREG4(sc, AAC_RX_IISR)); device_printf(sc->aac_dev, "ODBR 0x%08x OIMR 0x%08x " "OISR 0x%08x\n", AAC_MEM0_GETREG4(sc, AAC_RX_ODBR), AAC_MEM0_GETREG4(sc, AAC_RX_OIMR), AAC_MEM0_GETREG4(sc, AAC_RX_OISR)); AAC_MEM0_SETREG4(sc, AAC_RX_OIMR, 0/*~(AAC_DB_COMMAND_READY | AAC_DB_RESPONSE_READY | AAC_DB_PRINTF)*/); device_printf(sc->aac_dev, "ODBR 0x%08x OIMR 0x%08x " "OISR 0x%08x\n", AAC_MEM0_GETREG4(sc, AAC_RX_ODBR), AAC_MEM0_GETREG4(sc, AAC_RX_OIMR), AAC_MEM0_GETREG4(sc, AAC_RX_OISR)); break; case AAC_HWIF_STRONGARM: /* XXX implement */ break; } }
static int nandsim_stop_ctrl(int num) { device_t nexus; devclass_t nexus_devclass; int ret = 0; nand_debug(NDBG_SIM,"stop controller num:%d", num); if (num >= MAX_SIM_DEV) { return (EINVAL); } if (!ctrls[num].created || !ctrls[num].running) { return (ENODEV); } /* We will add our device as a child of the nexus0 device */ if (!(nexus_devclass = devclass_find("nexus")) || !(nexus = devclass_get_device(nexus_devclass, 0))) { return (ENODEV); } mtx_lock(&Giant); if (ctrls[num].sim_ctrl_dev) { ret = device_delete_child(nexus, ctrls[num].sim_ctrl_dev); ctrls[num].sim_ctrl_dev = NULL; } mtx_unlock(&Giant); ctrls[num].running = 0; return (ret); }
static int fdc_acpi_probe_children(device_t bus, device_t dev, void *fde) { struct fdc_walk_ctx *ctx; devclass_t fd_dc; int i; /* Setup the context and walk all child devices. */ ctx = malloc(sizeof(struct fdc_walk_ctx), M_TEMP, M_NOWAIT); if (ctx == NULL) { device_printf(dev, "no memory for walking children\n"); return (ENOMEM); } bcopy(fde, ctx->fd_present, sizeof(ctx->fd_present)); ctx->index = 0; ctx->dev = dev; ctx->acpi_dev = bus; ACPI_SCAN_CHILDREN(ctx->acpi_dev, dev, 1, fdc_acpi_probe_child, ctx); /* Add any devices not represented by an AML Device handle/node. */ fd_dc = devclass_find("fd"); for (i = 0; i < ACPI_FDC_MAXDEVS; i++) if (ctx->fd_present[i] == ACPI_FD_PRESENT && devclass_get_device(fd_dc, i) == NULL) { if (fdc_add_child(dev, "fd", i) == NULL) device_printf(dev, "fd add failed\n"); } free(ctx, M_TEMP); /* Attach any children found during the probe. */ return (bus_generic_attach(dev)); }
static int reset_hsic_hub(struct exynos_ehci_softc *esc, phandle_t hub) { device_t gpio_dev; pcell_t pin; /* TODO: check that hub is compatible with "smsc,usb3503" */ if (!OF_hasprop(hub, "freebsd,reset-gpio")) { return (1); } if (OF_getencprop(hub, "freebsd,reset-gpio", &pin, sizeof(pin)) < 0) { device_printf(esc->dev, "failed to decode reset GPIO pin number for HSIC hub\n"); return (1); } /* Get the GPIO device, we need this to give power to USB */ gpio_dev = devclass_get_device(devclass_find("gpio"), 0); if (gpio_dev == NULL) { device_printf(esc->dev, "Cant find gpio device\n"); return (1); } GPIO_PIN_SET(gpio_dev, pin, GPIO_PIN_LOW); DELAY(100); GPIO_PIN_SET(gpio_dev, pin, GPIO_PIN_HIGH); return (0); }
static void usbpf_uninit(void *arg) { int devlcnt; device_t *devlp; devclass_t dc; struct usb_bus *ubus; int error; int i; if_clone_detach(usbpf_cloner); dc = devclass_find(usbusname); if (dc == NULL) return; error = devclass_get_devices(dc, &devlp, &devlcnt); if (error) return; for (i = 0; i < devlcnt; i++) { ubus = device_get_softc(devlp[i]); if (ubus != NULL && ubus->ifp != NULL) usbpf_clone_destroy(usbpf_cloner, ubus->ifp); } free(devlp, M_TEMP); }
/** * Default bhndb_pci implementation of device_probe(). * * Verifies that the parent is a PCI/PCIe device. */ static int bhndb_pci_probe(device_t dev) { struct bhndb_pci_probe *probe; struct bhndb_pci_core *entry; bhnd_devclass_t hostb_devclass; device_t parent, parent_bus; devclass_t pci, bus_devclass; int error; probe = NULL; /* Our parent must be a PCI/PCIe device. */ pci = devclass_find("pci"); parent = device_get_parent(dev); parent_bus = device_get_parent(parent); if (parent_bus == NULL) return (ENXIO); /* The bus device class may inherit from 'pci' */ for (bus_devclass = device_get_devclass(parent_bus); bus_devclass != NULL; bus_devclass = devclass_get_parent(bus_devclass)) { if (bus_devclass == pci) break; } if (bus_devclass != pci) return (ENXIO); /* Enable clocks */ if ((error = bhndb_enable_pci_clocks(dev))) return (error); /* Identify the chip and enumerate the bridged cores */ hostb_devclass = bhndb_expected_pci_devclass(dev); if ((error = bhndb_pci_probe_alloc(&probe, dev, hostb_devclass))) goto cleanup; /* Look for a matching core table entry */ if ((entry = bhndb_pci_find_core(&probe->hostb_core)) == NULL) { error = ENXIO; goto cleanup; } device_set_desc(dev, "PCI-BHND bridge"); /* fall-through */ error = BUS_PROBE_DEFAULT; cleanup: if (probe != NULL) bhndb_pci_probe_free(probe); bhndb_disable_pci_clocks(dev); return (error); }
int acpi_pcib_power_for_sleep(device_t pcib, device_t dev, int *pstate) { device_t acpi_dev; acpi_dev = devclass_get_device(devclass_find("acpi"), 0); acpi_device_pwr_for_sleep(acpi_dev, dev, pstate); return (0); }
ACPI_STATUS AcpiOsInstallInterruptHandler(UINT32 InterruptNumber, ACPI_OSD_HANDLER ServiceRoutine, void *Context) { struct acpi_softc *sc; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); if ((sc = devclass_get_softc(devclass_find("acpi"), 0)) == NULL) panic("can't find ACPI device to register interrupt"); if (sc->acpi_dev == NULL) panic("acpi softc has invalid device"); if (InterruptNumber < 0 || InterruptNumber > 255) return_ACPI_STATUS (AE_BAD_PARAMETER); if (ServiceRoutine == NULL) return_ACPI_STATUS (AE_BAD_PARAMETER); /* * If the MADT contained an interrupt override directive for the SCI, * we use that value instead of the one from the FADT. */ if (InterruptOverride != 0) { device_printf(sc->acpi_dev, "Overriding SCI Interrupt from IRQ %u to IRQ %u\n", InterruptNumber, InterruptOverride); InterruptNumber = InterruptOverride; } /* Set up the interrupt resource. */ sc->acpi_irq_rid = 0; bus_set_resource(sc->acpi_dev, SYS_RES_IRQ, 0, InterruptNumber, 1); sc->acpi_irq = bus_alloc_resource_any(sc->acpi_dev, SYS_RES_IRQ, &sc->acpi_irq_rid, RF_SHAREABLE | RF_ACTIVE); if (sc->acpi_irq == NULL) { device_printf(sc->acpi_dev, "could not allocate interrupt\n"); goto error; } if (bus_setup_intr(sc->acpi_dev, sc->acpi_irq, INTR_TYPE_MISC|INTR_MPSAFE, NULL, (driver_intr_t *)ServiceRoutine, Context, &sc->acpi_irq_handle)) { device_printf(sc->acpi_dev, "could not set up interrupt\n"); goto error; } return_ACPI_STATUS (AE_OK); error: if (sc->acpi_irq_handle) bus_teardown_intr(sc->acpi_dev, sc->acpi_irq, sc->acpi_irq_handle); sc->acpi_irq_handle = NULL; if (sc->acpi_irq) bus_release_resource(sc->acpi_dev, SYS_RES_IRQ, 0, sc->acpi_irq); sc->acpi_irq = NULL; bus_delete_resource(sc->acpi_dev, SYS_RES_IRQ, 0); return_ACPI_STATUS (AE_ALREADY_EXISTS); }
static int phy_init(struct vybrid_ehci_softc *esc) { device_t sc_gpio_dev; int reg; /* Reset phy */ reg = PHY_READ4(esc, USBPHY_CTRL); reg |= (USBPHY_CTRL_SFTRST); PHY_WRITE4(esc, USBPHY_CTRL, reg); /* Minimum reset time */ DELAY(10000); reg &= ~(USBPHY_CTRL_SFTRST | USBPHY_CTRL_CLKGATE); PHY_WRITE4(esc, USBPHY_CTRL, reg); reg = (ENUTMILEVEL2 | ENUTMILEVEL3); PHY_WRITE4(esc, USBPHY_CTRL_SET, reg); /* Get the GPIO device, we need this to give power to USB */ sc_gpio_dev = devclass_get_device(devclass_find("gpio"), 0); if (sc_gpio_dev == NULL) { device_printf(esc->dev, "Error: failed to get the GPIO dev\n"); return (1); } /* Give power to USB */ GPIO_PIN_SETFLAGS(sc_gpio_dev, GPIO_USB_PWR, GPIO_PIN_OUTPUT); GPIO_PIN_SET(sc_gpio_dev, GPIO_USB_PWR, GPIO_PIN_HIGH); /* Power up PHY */ PHY_WRITE4(esc, USBPHY_PWD, 0x00); /* Ungate clocks */ reg = PHY_READ4(esc, USBPHY_DEBUG); reg &= ~(USBPHY_DEBUG_CLKGATE); PHY_WRITE4(esc, USBPHY_DEBUG, reg); #if 0 printf("USBPHY_CTRL == 0x%08x\n", PHY_READ4(esc, USBPHY_CTRL)); printf("USBPHY_IP == 0x%08x\n", PHY_READ4(esc, USBPHY_IP)); printf("USBPHY_STATUS == 0x%08x\n", PHY_READ4(esc, USBPHY_STATUS)); printf("USBPHY_DEBUG == 0x%08x\n", PHY_READ4(esc, USBPHY_DEBUG)); printf("USBPHY_DEBUG0_STATUS == 0x%08x\n", PHY_READ4(esc, USBPHY_DEBUG0_STATUS)); printf("USBPHY_DEBUG1 == 0x%08x\n", PHY_READ4(esc, USBPHY_DEBUG1)); #endif return (0); }
int vga_pci_is_boot_display(device_t dev) { int unit; device_t pcib; uint16_t config; /* Check that the given device is a video card */ if ((pci_get_class(dev) != PCIC_DISPLAY && (pci_get_class(dev) != PCIC_OLD || pci_get_subclass(dev) != PCIS_OLD_VGA))) return (0); unit = device_get_unit(dev); if (vga_pci_default_unit >= 0) { /* * The boot display device was determined by a previous * call to this function, or the user forced it using * the hw.pci.default_vgapci_unit tunable. */ return (vga_pci_default_unit == unit); } /* * The primary video card used as a boot display must have the * "I/O" and "Memory Address Space Decoding" bits set in its * Command register. * * Furthermore, if the card is attached to a bridge, instead of * the root PCI bus, the bridge must have the "VGA Enable" bit * set in its Control register. */ pcib = device_get_parent(device_get_parent(dev)); if (device_get_devclass(device_get_parent(pcib)) == devclass_find("pci")) { /* * The parent bridge is a PCI-to-PCI bridge: check the * value of the "VGA Enable" bit. */ config = pci_read_config(pcib, PCIR_BRIDGECTL_1, 2); if ((config & PCIB_BCR_VGA_ENABLE) == 0) return (0); } config = pci_read_config(dev, PCIR_COMMAND, 2); if ((config & (PCIM_CMD_PORTEN | PCIM_CMD_MEMEN)) == 0) return (0); /* This video card is the boot display: record its unit number. */ vga_pci_default_unit = unit; device_set_flags(dev, 1); return (1); }
void bcm_mbox_write(int channel, uint32_t data) { device_t mbox; mbox = devclass_get_device(devclass_find("mbox"), 0); if (mbox) MBOX_WRITE(mbox, channel, data); }
int acpi_battery_get_units(void) { devclass_t batt_dc; batt_dc = devclass_find("battery"); if (batt_dc == NULL) return (0); return (devclass_get_count(batt_dc)); }
static int legacy_attach(device_t dev) { device_t child; /* * Let our child drivers identify any child devices that they * can find. Once that is done attach any devices that we * found. */ bus_generic_probe(dev); bus_generic_attach(dev); #ifndef PC98 /* * If we didn't see EISA or ISA on a pci bridge, create some * connection points now so they show up "on motherboard". */ if (!devclass_get_device(devclass_find("eisa"), 0)) { child = BUS_ADD_CHILD(dev, 0, "eisa", 0); if (child == NULL) panic("legacy_attach eisa"); device_probe_and_attach(child); } #endif #ifdef DEV_MCA if (MCA_system && !devclass_get_device(devclass_find("mca"), 0)) { child = BUS_ADD_CHILD(dev, 0, "mca", 0); if (child == 0) panic("legacy_probe mca"); device_probe_and_attach(child); } #endif if (!devclass_get_device(devclass_find("isa"), 0)) { child = BUS_ADD_CHILD(dev, 0, "isa", 0); if (child == NULL) panic("legacy_attach isa"); device_probe_and_attach(child); } return 0; }
static int eisab_attach(device_t dev) { /* * Attach an EISA bus. Note that we can only have one EISA bus. */ if (!devclass_get_device(devclass_find("eisa"), 0)) device_add_child(dev, "eisa", -1); /* * Attach an ISA bus as well, since the EISA bus may have ISA * cards installed, and we may have no EISA support in the system. */ if (!devclass_get_device(devclass_find("isa"), 0)) device_add_child(dev, "isa", -1); bus_generic_attach(dev); return(0); }
static int ntb_setup_interface(void) { struct ifnet *ifp; struct ntb_queue_handlers handlers = { ntb_net_rx_handler, ntb_net_tx_handler, ntb_net_event_handler }; int rc; net_softc.ntb = devclass_get_softc(devclass_find("ntb_hw"), 0); if (net_softc.ntb == NULL) { printf("ntb: Cannot find devclass\n"); return (ENXIO); } ifp = net_softc.ifp = if_alloc(IFT_ETHER); if (ifp == NULL) { ntb_transport_free(&net_softc); printf("ntb: Cannot allocate ifnet structure\n"); return (ENOMEM); } if_initname(ifp, "ntb", 0); rc = ntb_transport_probe(net_softc.ntb); if (rc != 0) { printf("ntb: Cannot init transport: %d\n", rc); if_free(net_softc.ifp); return (rc); } net_softc.qp = ntb_transport_create_queue(ifp, net_softc.ntb, &handlers); ifp->if_init = ntb_net_init; ifp->if_softc = &net_softc; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; ifp->if_ioctl = ntb_ioctl; ifp->if_start = ntb_start; IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN; IFQ_SET_READY(&ifp->if_snd); create_random_local_eui48(net_softc.eaddr); ether_ifattach(ifp, net_softc.eaddr); ifp->if_capabilities = IFCAP_HWCSUM | IFCAP_JUMBO_MTU; ifp->if_capenable = ifp->if_capabilities; ifp->if_mtu = ntb_transport_max_size(net_softc.qp) - ETHER_HDR_LEN - ETHER_CRC_LEN; ntb_transport_link_up(net_softc.qp); net_softc.bufsize = ntb_transport_max_size(net_softc.qp) + sizeof(struct ether_header); return (0); }
int acpi_pci_suspend(device_t dev) { int dstate, error, i, numdevs; device_t acpi_dev, child, *devlist; struct pci_devinfo *dinfo; acpi_dev = devclass_get_device(devclass_find("acpi"), 0); device_get_children(dev, &devlist, &numdevs); /* * Save the PCI configuration space for each child and set the * device in the appropriate power state for this sleep state. */ for (i = 0; i < numdevs; i++) { child = devlist[i]; dinfo = (struct pci_devinfo *)device_get_ivars(child); pci_cfg_save(child, dinfo, 0); } /* * Suspend devices before potentially powering them down. */ error = bus_generic_suspend(dev); if (error) { kfree(devlist, M_TEMP); return (error); } /* * Always set the device to D3. If ACPI suggests a different * power state, use it instead. If ACPI is not present, the * firmware is responsible for managing device power. Skip * children who aren't attached since they are powered down * separately. Only manage type 0 devices for now. */ for (i = 0; acpi_dev && i < numdevs; i++) { child = devlist[i]; dinfo = (struct pci_devinfo *)device_get_ivars(child); if (device_is_attached(child) && dinfo->cfg.hdrtype == 0) { dstate = PCI_POWERSTATE_D3; ACPI_PWR_FOR_SLEEP(acpi_dev, child, &dstate); pci_set_powerstate(child, dstate); } } kfree(devlist, M_TEMP); return (0); }
static int nexus_attach(device_t dev) { device_t child; /* * First, deal with the children we know about already */ bus_generic_attach(dev); /* * And if we didn't see EISA or ISA on a pci bridge, create some * connection points now so they show up "on motherboard". */ if (!devclass_get_device(devclass_find("eisa"), 0)) { child = device_add_child(dev, "eisa", 0); if (child == NULL) panic("nexus_attach eisa"); device_probe_and_attach(child); } #if NMCA > 0 if (!devclass_get_device(devclass_find("mca"), 0)) { child = device_add_child(dev, "mca", 0); if (child == 0) panic("nexus_probe mca"); device_probe_and_attach(child); } #endif if (!devclass_get_device(devclass_find("isa"), 0)) { child = device_add_child(dev, "isa", 0); if (child == NULL) panic("nexus_attach isa"); device_probe_and_attach(child); } return 0; }
static int nandsim_start_ctrl(int num) { device_t nexus, ndev; devclass_t nexus_devclass; int ret = 0; nand_debug(NDBG_SIM,"start ctlr num:%d", num); if (num >= MAX_SIM_DEV) return (EINVAL); if (!ctrls[num].created) return (ENODEV); if (ctrls[num].running) return (EBUSY); /* We will add our device as a child of the nexus0 device */ if (!(nexus_devclass = devclass_find("nexus")) || !(nexus = devclass_get_device(nexus_devclass, 0))) return (EFAULT); /* * Create a newbus device representing this frontend instance * * XXX powerpc nexus doesn't implement bus_add_child, so child * must be added by device_add_child(). */ #if defined(__powerpc__) ndev = device_add_child(nexus, "nandsim", num); #else ndev = BUS_ADD_CHILD(nexus, 0, "nandsim", num); #endif if (!ndev) return (EFAULT); mtx_lock(&Giant); ret = device_probe_and_attach(ndev); mtx_unlock(&Giant); if (ret == 0) { ctrls[num].sim_ctrl_dev = ndev; ctrls[num].running = 1; } return (ret); }
static int apmopen(struct cdev *dev, int flag, int fmt, struct thread *td) { struct acpi_softc *acpi_sc; struct apm_clone_data *clone; acpi_sc = devclass_get_softc(devclass_find("acpi"), 0); clone = apm_create_clone(dev, acpi_sc); dev->si_drv1 = clone; /* If the device is opened for write, record that. */ if ((flag & FWRITE) != 0) clone->flags |= ACPI_EVF_WRITE; return (0); }
static int clkrun_hack(int run) { #ifdef __i386__ devclass_t pci_devclass; device_t *pci_devices, *pci_children, *busp, *childp; int pci_count = 0, pci_childcount = 0; int i, j, port; u_int16_t control; bus_space_tag_t btag; if ((pci_devclass = devclass_find("pci")) == NULL) { return ENXIO; } devclass_get_devices(pci_devclass, &pci_devices, &pci_count); for (i = 0, busp = pci_devices; i < pci_count; i++, busp++) { pci_childcount = 0; if (device_get_children(*busp, &pci_children, &pci_childcount)) continue; for (j = 0, childp = pci_children; j < pci_childcount; j++, childp++) { if (pci_get_vendor(*childp) == 0x8086 && pci_get_device(*childp) == 0x7113) { port = (pci_read_config(*childp, 0x41, 1) << 8) + 0x10; /* XXX */ btag = X86_BUS_SPACE_IO; control = bus_space_read_2(btag, 0x0, port); control &= ~0x2000; control |= run? 0 : 0x2000; bus_space_write_2(btag, 0x0, port, control); free(pci_devices, M_TEMP); free(pci_children, M_TEMP); return 0; } } free(pci_children, M_TEMP); } free(pci_devices, M_TEMP); return ENXIO; #else return 0; #endif }
static int acpi_tz_cpufreq_restore(struct acpi_tz_softc *sc) { device_t dev; int error; if (!sc->tz_cooling_updated) return (0); if ((dev = devclass_get_device(devclass_find("cpufreq"), 0)) == NULL) return (ENXIO); ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev), "temperature %d.%dC: resuming previous clock speed (%d MHz)\n", TZ_KELVTOC(sc->tz_temperature), sc->tz_cooling_saved_freq); error = CPUFREQ_SET(dev, NULL, CPUFREQ_PRIO_KERN); if (error == 0) sc->tz_cooling_updated = FALSE; return (error); }