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; }
/* for debugging, print out all the data about the status of devices */ void wds_print(void) { int unit; int i; struct wds_req *r; struct wds *wp; for (unit = 0; unit < devclass_get_maxunit(wds_devclass); unit++) { wp = (struct wds *) devclass_get_device(wds_devclass, unit); if (wp == NULL) continue; printf("wds%d: want_wdsr=0x%x stat=0x%x irq=%s irqstat=0x%x\n", unit, wp->want_wdsr, inb(wp->addr + WDS_STAT) & 0xff, (inb(wp->addr + WDS_STAT) & WDS_IRQ) ? "ready" : "no", inb(wp->addr + WDS_IRQSTAT) & 0xff); for (i = 0; i < MAXSIMUL; i++) { r = &wp->dx->req[i]; if( wp->wdsr_free & (1 << r->id) ) { printf("req=%d flg=0x%x ombn=%d ombstat=%d " "mask=0x%x targ=%d lun=%d cmd=0x%x\n", i, r->flags, r->ombn, wp->dx->ombs[r->ombn].stat, r->mask, r->cmd.targ >> 5, r->cmd.targ & 7, r->cmd.scb[0]); } } }
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); }
/* * 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); }
/* * The back door to the keyboard driver! * This function is called by the console driver, via the kbdio module, * to tickle keyboard drivers when the low-level console is being initialized. * Almost nothing in the kernel has been initialied yet. Try to probe * keyboards if possible. * NOTE: because of the way the low-level conole is initialized, this routine * may be called more than once!! */ static int ukbd_configure(int flags) { return 0; #if 0 /* not yet */ keyboard_t *kbd; device_t device; struct usb_attach_arg *uaa; void *arg[2]; device = devclass_get_device(ukbd_devclass, UKBD_DEFAULT); if (device == NULL) return 0; uaa = (struct usb_attach_arg *)device_get_ivars(device); if (uaa == NULL) return 0; /* probe the default keyboard */ arg[0] = (void *)uaa; arg[1] = (void *)ukbd_intr; kbd = NULL; if (ukbd_probe(UKBD_DEFAULT, arg, flags)) return 0; if (ukbd_init(UKBD_DEFAULT, &kbd, arg, flags)) return 0; /* return the number of found keyboards */ return 1; #endif }
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; }
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)); }
/* 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; }
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 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 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)); }
static int acpi_cmbat_ioctl(u_long cmd, caddr_t addr, void *arg) { device_t dev; union acpi_battery_ioctl_arg *ioctl_arg; struct acpi_cmbat_softc *sc; struct acpi_bif *bifp; struct acpi_bst *bstp; ioctl_arg = (union acpi_battery_ioctl_arg *)addr; if ((dev = devclass_get_device(acpi_cmbat_devclass, ioctl_arg->unit)) == NULL) { return (ENXIO); } if ((sc = device_get_softc(dev)) == NULL) { return (ENXIO); } /* * No security check required: information retrieval only. If * new functions are added here, a check might be required. */ switch (cmd) { case ACPIIO_CMBAT_GET_BIF: acpi_cmbat_get_bif(dev); bifp = &ioctl_arg->bif; bifp->unit = sc->bif.unit; bifp->dcap = sc->bif.dcap; bifp->lfcap = sc->bif.lfcap; bifp->btech = sc->bif.btech; bifp->dvol = sc->bif.dvol; bifp->wcap = sc->bif.wcap; bifp->lcap = sc->bif.lcap; bifp->gra1 = sc->bif.gra1; bifp->gra2 = sc->bif.gra2; strncpy(bifp->model, sc->bif.model, sizeof(sc->bif.model)); strncpy(bifp->serial, sc->bif.serial, sizeof(sc->bif.serial)); strncpy(bifp->type, sc->bif.type, sizeof(sc->bif.type)); strncpy(bifp->oeminfo, sc->bif.oeminfo, sizeof(sc->bif.oeminfo)); break; case ACPIIO_CMBAT_GET_BST: bstp = &ioctl_arg->bst; if (acpi_BatteryIsPresent(dev)) { acpi_cmbat_get_bst(dev); bstp->state = sc->bst.state; bstp->rate = sc->bst.rate; bstp->cap = sc->bst.cap; bstp->volt = sc->bst.volt; } else bstp->state = ACPI_BATT_STAT_NOT_PRESENT; break; } return (0); }
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); }
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); }
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); }
/* * Locate the ACPI timer using the FADT, set up and allocate the I/O resources * we will be using. */ static int acpi_hpet_identify(driver_t *driver, device_t parent) { ACPI_TABLE_HPET *hpet; ACPI_TABLE_HEADER *hdr; ACPI_STATUS status; device_t child; /* * Just try once, do nothing if the 'acpi' bus is rescanned. */ if (device_get_state(parent) == DS_ATTACHED) return 0; ACPI_FUNCTION_TRACE((char *)(uintptr_t) __func__); /* Only one HPET device can be added. */ if (devclass_get_device(acpi_hpet_devclass, 0)) return ENXIO; /* Currently, ID and minimum clock tick info is unused. */ status = AcpiGetTable(ACPI_SIG_HPET, 1, &hdr); if (ACPI_FAILURE(status)) return ENXIO; /* * The unit number could be derived from hdr->Sequence but we only * support one HPET device. */ hpet = (ACPI_TABLE_HPET *)hdr; if (hpet->Sequence != 0) { kprintf("ACPI HPET table warning: Sequence is non-zero (%d)\n", hpet->Sequence); } child = BUS_ADD_CHILD(parent, parent, 0, "acpi_hpet", 0); if (child == NULL) { device_printf(parent, "%s: can't add acpi_hpet0\n", __func__); return ENXIO; } /* Record a magic value so we can detect this device later. */ acpi_set_magic(child, (uintptr_t)&acpi_hpet_devclass); acpi_hpet_res_start = hpet->Address.Address; if (bus_set_resource(child, SYS_RES_MEMORY, 0, hpet->Address.Address, HPET_MEM_WIDTH, -1)) { device_printf(child, "could not set iomem resources: " "0x%jx, %d\n", (uintmax_t)hpet->Address.Address, HPET_MEM_WIDTH); return ENOMEM; } return 0; }
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); }
int ata_pci_attach(device_t dev) { struct ata_pci_controller *ctlr = device_get_softc(dev); u_int32_t cmd; int unit; /* do chipset specific setups only needed once */ ctlr->legacy = ata_legacy(dev); if (ctlr->legacy || pci_read_config(dev, PCIR_BAR(2), 4) & IOMASK) ctlr->channels = 2; else ctlr->channels = 1; ctlr->allocate = ata_pci_allocate; ctlr->dev = dev; /* if needed try to enable busmastering */ cmd = pci_read_config(dev, PCIR_COMMAND, 2); if (!(cmd & PCIM_CMD_BUSMASTEREN)) { pci_write_config(dev, PCIR_COMMAND, cmd | PCIM_CMD_BUSMASTEREN, 2); cmd = pci_read_config(dev, PCIR_COMMAND, 2); } /* if busmastering mode "stuck" use it */ if ((cmd & PCIM_CMD_BUSMASTEREN) == PCIM_CMD_BUSMASTEREN) { ctlr->r_type1 = SYS_RES_IOPORT; ctlr->r_rid1 = ATA_BMADDR_RID; ctlr->r_res1 = bus_alloc_resource_any(dev, ctlr->r_type1, &ctlr->r_rid1, RF_ACTIVE); /* Only set a dma init function if the device actually supports it. */ ctlr->dmainit = ata_pci_dmainit; } if (ctlr->chipinit(dev)) return ENXIO; /* attach all channels on this controller */ for (unit = 0; unit < ctlr->channels; unit++) { int freeunit = 2; if ((unit == 0 || unit == 1) && ctlr->legacy) { device_add_child(dev, "ata", unit); continue; } /* XXX TGEN devclass_find_free_unit() implementation */ if (ata_devclass) { while (freeunit < devclass_get_maxunit(ata_devclass) && devclass_get_device(ata_devclass, freeunit) != NULL) freeunit++; } device_add_child(dev, "ata", freeunit); } bus_generic_attach(dev); return 0; }
static int vgapm_resume(device_t dev) { device_t vga_dev; vga_dev = devclass_get_device(isavga_devclass, 0); if (vga_dev != NULL) vga_resume(vga_dev); return (bus_generic_resume(dev)); }
/* * Allocate a physical address range from our mmio region. */ int xenpci_alloc_space(size_t sz, vm_paddr_t *pa) { device_t dev = devclass_get_device(xenpci_devclass, 0); if (dev) { return (xenpci_alloc_space_int(device_get_softc(dev), sz, pa)); } else { return (ENOMEM); } }
static int acpi_isab_probe(device_t dev) { static char *isa_ids[] = { "PNP0A05", "PNP0A06", NULL }; if (acpi_disabled("isab") || ACPI_ID_PROBE(device_get_parent(dev), dev, isa_ids) == NULL || devclass_get_device(isab_devclass, 0) != dev) return (ENXIO); device_set_desc(dev, "ACPI Generic ISA bridge"); 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 void pmtimer_identify(driver_t *driver, device_t parent) { device_t child; /* * Only add a child if one doesn't exist already. */ child = devclass_get_device(pmtimer_devclass, 0); if (child == NULL) { child = BUS_ADD_CHILD(parent, 0, "pmtimer", 0); if (child == NULL) panic("pmtimer_identify"); } }
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); }
/* * Public interfaces. */ int acpi_acad_get_acline(int *status) { struct acpi_acad_softc *sc; device_t dev; dev = devclass_get_device(acpi_acad_devclass, 0); if (dev == NULL) return (ENXIO); sc = device_get_softc(dev); acpi_acad_get_status(dev); *status = sc->status; return (0); }
static int vgapm_suspend(device_t dev) { device_t vga_dev; int error; error = bus_generic_suspend(dev); if (error != 0) return (error); vga_dev = devclass_get_device(isavga_devclass, 0); if (vga_dev == NULL) return (0); vga_suspend(vga_dev); return (0); }
int acpi_cmbat_get_battinfo(int unit, struct acpi_battinfo *battinfo) { int error; device_t dev; struct acpi_cmbat_softc *sc; if (unit == -1) { return (acpi_cmbat_get_total_battinfo(battinfo)); } if (acpi_cmbat_info_expired(&acpi_cmbat_info_lastupdated)) { error = acpi_cmbat_get_total_battinfo(battinfo); if (error) { goto out; } } error = 0; if (unit >= acpi_cmbat_units) { error = ENXIO; goto out; } if ((dev = devclass_get_device(acpi_cmbat_devclass, unit)) == NULL) { error = ENXIO; goto out; } if ((sc = device_get_softc(dev)) == NULL) { error = ENXIO; goto out; } if (!sc->present) { battinfo->cap = -1; battinfo->min = -1; battinfo->state = ACPI_BATT_STAT_NOT_PRESENT; } else { battinfo->cap = sc->cap; battinfo->min = sc->min; battinfo->state = sc->bst.state; } out: return (error); }
static void xenpv_identify(driver_t *driver, device_t parent) { if (!xen_domain()) return; /* Make sure there's only one xenpv device. */ if (devclass_get_device(xenpv_devclass, 0)) return; /* * The xenpv bus should be the last to attach in order * to properly detect if an ISA bus has already been added. */ if (BUS_ADD_CHILD(parent, UINT_MAX, "xenpv", 0) == NULL) panic("Unable to attach xenpv bus."); }