Esempio n. 1
0
static int
xhci_pci_port_route(struct xhci_pci_softc *psc)
{
	struct xhci_softc * const sc = &psc->sc_xhci;

	pcireg_t val;

	/*
	 * Check USB3 Port Routing Mask register that indicates the ports
	 * can be changed from OS, and turn on by USB3 Port SS Enable register.
	 */
	val = pci_conf_read(psc->sc_pc, psc->sc_tag, PCI_XHCI_INTEL_USB3PRM);
	aprint_debug_dev(sc->sc_dev,
	    "USB3PRM / USB3.0 configurable ports: 0x%08x\n", val);

	pci_conf_write(psc->sc_pc, psc->sc_tag, PCI_XHCI_INTEL_USB3_PSSEN, val);
	val = pci_conf_read(psc->sc_pc, psc->sc_tag,PCI_XHCI_INTEL_USB3_PSSEN);
	aprint_debug_dev(sc->sc_dev,
	    "USB3_PSSEN / Enabled USB3.0 ports under xHCI: 0x%08x\n", val);

	/*
	 * Check USB2 Port Routing Mask register that indicates the USB2.0
	 * ports to be controlled by xHCI HC, and switch them to xHCI HC.
	 */
	val = pci_conf_read(psc->sc_pc, psc->sc_tag, PCI_XHCI_INTEL_USB2PRM);
	aprint_debug_dev(sc->sc_dev,
	    "XUSB2PRM / USB2.0 ports can switch from EHCI to xHCI:"
	    "0x%08x\n", val);
	pci_conf_write(psc->sc_pc, psc->sc_tag, PCI_XHCI_INTEL_XUSB2PR, val);
	val = pci_conf_read(psc->sc_pc, psc->sc_tag, PCI_XHCI_INTEL_XUSB2PR);
	aprint_debug_dev(sc->sc_dev,
	    "XUSB2PR / USB2.0 ports under xHCI: 0x%08x\n", val);

	return 0;
}
Esempio n. 2
0
/* detach */
int
url_detach(device_t self, int flags)
{
	struct url_softc *sc = device_private(self);
	struct ifnet *ifp = GET_IFP(sc);
	int s;

	DPRINTF(("%s: %s: enter\n", device_xname(sc->sc_dev), __func__));

	/* Detached before attached finished */
	if (!sc->sc_attached)
		return (0);

	callout_stop(&sc->sc_stat_ch);

	/* Remove any pending tasks */
	usb_rem_task(sc->sc_udev, &sc->sc_tick_task);
	usb_rem_task(sc->sc_udev, &sc->sc_stop_task);

	s = splusb();

	if (--sc->sc_refcnt >= 0) {
		/* Wait for processes to go away */
		usb_detach_waitold(sc->sc_dev);
	}

	if (ifp->if_flags & IFF_RUNNING)
		url_stop(GET_IFP(sc), 1);

	rnd_detach_source(&sc->rnd_source);
	mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
	ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY);
	ether_ifdetach(ifp);
	if_detach(ifp);

#ifdef DIAGNOSTIC
	if (sc->sc_pipe_tx != NULL)
		aprint_debug_dev(self, "detach has active tx endpoint.\n");
	if (sc->sc_pipe_rx != NULL)
		aprint_debug_dev(self, "detach has active rx endpoint.\n");
	if (sc->sc_pipe_intr != NULL)
		aprint_debug_dev(self, "detach has active intr endpoint.\n");
#endif

	sc->sc_attached = 0;

	splx(s);

	rw_destroy(&sc->sc_mii_rwlock);
	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
			   sc->sc_dev);

	return (0);
}
Esempio n. 3
0
/* Start transaction. */
int
tpm_tis12_start(struct tpm_softc *sc, int flag)
{
	int rv;

	if (flag == UIO_READ) {
		rv = tpm_waitfor(sc, TPM_STS_DATA_AVAIL | TPM_STS_VALID,
		    TPM_READ_TMO, sc->sc_read);
		return rv;
	}

	/* Own our (0th) locality. */
	if ((rv = tpm_request_locality(sc, 0)) != 0)
		return rv;

	sc->sc_stat = tpm_status(sc);
	if (sc->sc_stat & TPM_STS_CMD_READY) {
#ifdef TPM_DEBUG
		char buf[128];
		snprintb(buf, sizeof(buf), TPM_STS_BITS, sc->sc_stat);
		aprint_debug_dev(sc->sc_dev, "%s: UIO_WRITE status %s\n",
		    __func__, buf);
#endif
		return 0;
	}

#ifdef TPM_DEBUG
	aprint_debug_dev(sc->sc_dev,
	    "%s: UIO_WRITE readying chip\n", __func__);
#endif

	/* Abort previous and restart. */
	bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_STS, TPM_STS_CMD_READY);
	if ((rv = tpm_waitfor(sc, TPM_STS_CMD_READY, TPM_READY_TMO,
	    sc->sc_write))) {
#ifdef TPM_DEBUG
		aprint_debug_dev(sc->sc_dev,
		    "%s: UIO_WRITE readying failed %d\n", __func__, rv);
#endif
		return rv;
	}

#ifdef TPM_DEBUG
	aprint_debug_dev(sc->sc_dev,
	    "%s: UIO_WRITE readying done\n", __func__);
#endif

	return 0;
}
Esempio n. 4
0
/* Finish transaction. */
int
tpm_tis12_end(struct tpm_softc *sc, int flag, int err)
{
	int rv = 0;

	if (flag == UIO_READ) {
		if ((rv = tpm_waitfor(sc, TPM_STS_VALID, TPM_READ_TMO,
		    sc->sc_read)))
			return rv;

		/* Still more data? */
		sc->sc_stat = tpm_status(sc);
		if (!err && ((sc->sc_stat & TPM_STS_DATA_AVAIL)
		    == TPM_STS_DATA_AVAIL)) {
#ifdef TPM_DEBUG
			char buf[128];
			snprintb(buf, sizeof(buf), TPM_STS_BITS, sc->sc_stat);
			aprint_debug_dev(sc->sc_dev,
			    "%s: read failed stat=%s\n", __func__, buf);
#endif
			rv = EIO;
		}

		bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_STS,
		    TPM_STS_CMD_READY);

		/* Release our (0th) locality. */
		bus_space_write_1(sc->sc_bt, sc->sc_bh,TPM_ACCESS,
		    TPM_ACCESS_ACTIVE_LOCALITY);
	} else {
		/* Hungry for more? */
		sc->sc_stat = tpm_status(sc);
		if (!err && (sc->sc_stat & TPM_STS_DATA_EXPECT)) {
#ifdef TPM_DEBUG
			char buf[128];
			snprintb(buf, sizeof(buf), TPM_STS_BITS, sc->sc_stat);
			aprint_debug_dev(sc->sc_dev,
			    "%s: write failed stat=%s\n", __func__, buf);
#endif
			rv = EIO;
		}

		bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_STS,
		    err ? TPM_STS_CMD_READY : TPM_STS_GO);
	}

	return rv;
}
Esempio n. 5
0
/*
 * Setup interrupt vector if one is provided and interrupts are know to
 * work on that particular chip.
 */
int
tpm_tis12_irqinit(struct tpm_softc *sc, int irq, int idx)
{
	uint32_t r;

	if ((irq == -1) || (tpm_devs[idx].flags & TPM_DEV_NOINTS)) {
		sc->sc_vector = -1;
		return 0;
	}

	/* Ack and disable all interrupts. */
	r = bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE);
	bus_space_write_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE,
	    r & ~TPM_GLOBAL_INT_ENABLE);
	bus_space_write_4(sc->sc_bt, sc->sc_bh, TPM_INT_STATUS,
	    bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_INT_STATUS));
#ifdef TPM_DEBUG
	char buf[128];
	snprintb(buf, sizeof(buf), TPM_INTERRUPT_ENABLE_BITS, r);
	aprint_debug_dev(sc->sc_dev, "%s: before ien %s\n", __func__, buf);
#endif

	/* Program interrupt vector. */
	bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_INT_VECTOR, irq);
	sc->sc_vector = irq;

	/* Program interrupt type. */
	r &= ~(TPM_INT_EDGE_RISING|TPM_INT_EDGE_FALLING|TPM_INT_LEVEL_HIGH|
	    TPM_INT_LEVEL_LOW);
	r |= TPM_GLOBAL_INT_ENABLE|TPM_CMD_READY_INT|TPM_LOCALITY_CHANGE_INT|
	    TPM_STS_VALID_INT|TPM_DATA_AVAIL_INT;
	if (sc->sc_capabilities & TPM_INTF_INT_EDGE_RISING)
		r |= TPM_INT_EDGE_RISING;
	else if (sc->sc_capabilities & TPM_INTF_INT_EDGE_FALLING)
		r |= TPM_INT_EDGE_FALLING;
	else if (sc->sc_capabilities & TPM_INTF_INT_LEVEL_HIGH)
		r |= TPM_INT_LEVEL_HIGH;
	else
		r |= TPM_INT_LEVEL_LOW;

	bus_space_write_4(sc->sc_bt, sc->sc_bh, TPM_INTERRUPT_ENABLE, r);
#ifdef TPM_DEBUG
	snprintb(buf, sizeof(buf), TPM_INTERRUPT_ENABLE_BITS, r);
	aprint_debug_dev(sc->sc_dev, "%s: after ien %s\n", __func__, buf);
#endif

	return 0;
}
/**
 *	sitara_cm_padconf_set_internal - sets the muxmode and state for a pad/pin
 *	@padconf: pointer to the pad structure
 *	@muxmode: the name of the mode to use for the pin, i.e. "uart1_rx"
 *	@state: the state to put the pad/pin in, i.e. PADCONF_PIN_???
 *	
 *
 *	LOCKING:
 *	Internally locks its own context.
 *
 *	RETURNS:
 *	0 on success.
 *	EINVAL if pin requested is outside valid range or already in use.
 */
static int
sitara_cm_padconf_set_internal(struct sitara_cm_softc *sc,
    const struct sitara_cm_padconf *padconf,
    const char *muxmode, unsigned int state)
{
	unsigned int mode;
	uint16_t reg_val;

	/* populate the new value for the PADCONF register */
	reg_val = (uint16_t)(state & sitara_cm_dev.padconf_sate_mask);

	/* find the new mode requested */
	for (mode = 0; mode < 8; mode++) {
		if ((padconf->muxmodes[mode] != NULL) &&
		    (strcmp(padconf->muxmodes[mode], muxmode) == 0)) {
			break;
		}
	}

	/* couldn't find the mux mode */
	if (mode >= 8) {
		aprint_error_dev(sc->sc_dev, "Invalid mode \"%s\"\n", muxmode);
		return (EINVAL);
	}

	/* set the mux mode */
	reg_val |= (uint16_t)(mode & sitara_cm_dev.padconf_muxmode_mask);
	
	aprint_debug_dev(sc->sc_dev,
	    "setting internal %x for %s\n", reg_val, muxmode);
	/* write the register value (16-bit writes) */
	sitara_cm_write_2(sc, padconf->reg_off, reg_val);
	
	return (0);
}
Esempio n. 7
0
int
acpitimer_init(struct acpi_softc *sc)
{
	ACPI_STATUS rv;
	uint32_t bits;
	int i, j;

	rv = AcpiGetTimerResolution(&bits);

	if (ACPI_FAILURE(rv))
		return -1;

	if (bits == 32)
		acpi_timecounter.tc_counter_mask = 0xffffffff;

	for (i = j = 0; i < 10; i++)
		j += acpitimer_test();

	if (j >= 10) {
		acpi_timecounter.tc_name = "ACPI-Fast";
		acpi_timecounter.tc_get_timecount = acpitimer_read_fast;
		acpi_timecounter.tc_quality = 1000;
	}

	tc_init(&acpi_timecounter);

	aprint_debug_dev(sc->sc_dev, "%s %d-bit timer\n",
	    acpi_timecounter.tc_name, bits);

	return 0;
}
Esempio n. 8
0
int
tpm_getburst(struct tpm_softc *sc)
{
	int burst, to, rv;

	to = tpm_tmotohz(TPM_BURST_TMO);

	burst = 0;
	while (burst == 0 && to--) {
		/*
		 * Burst count has to be read from bits 8 to 23 without
		 * touching any other bits, eg. the actual status bits 0
		 * to 7.
		 */
		burst = bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_STS + 1);
		burst |= bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_STS + 2)
		    << 8;
#ifdef TPM_DEBUG
		aprint_debug_dev(sc->sc_dev, "%s: read %d\n", __func__, burst);
#endif
		if (burst)
			return burst;

		rv = tsleep(sc, PRIBIO | PCATCH, "tpm_getburst", 1);
		if (rv && rv != EWOULDBLOCK) {
			return 0;
		}
	}

	return 0;
}
Esempio n. 9
0
static void
apm_standby(struct apm_softc *sc)
{
	int error;

	if (sc->sc_power_state == PWR_STANDBY) {
#ifdef APMDEBUG
		aprint_debug_dev(sc->sc_dev,
		    "apm_standby: already standing by?\n");
#endif
		return;
	}
	sc->sc_power_state = PWR_STANDBY;

	if (!(sc->sc_hwflags & APM_F_DONT_RUN_HOOKS)) {
		pmf_system_suspend(PMF_Q_NONE);
		apm_spl = splhigh();
	}
	error = (*sc->sc_ops->aa_set_powstate)(sc->sc_cookie, APM_DEV_ALLDEVS,
	    APM_SYS_STANDBY);
	if (error)
		apm_resume(sc, 0, 0);
	else
		apm_resume(sc, APM_SYS_STANDBY_RESUME, 0);
}
Esempio n. 10
0
static void
apm_resume(struct apm_softc *sc, u_int event_type, u_int event_info)
{
	if (sc->sc_power_state == PWR_RESUME) {
#ifdef APMDEBUG
		aprint_debug_dev(sc->sc_dev, "apm_resume: already running?\n");
#endif
		return;
	}
	sc->sc_power_state = PWR_RESUME;

#ifdef TIMER_FREQ
	/*
	 * Some system requires its clock to be initialized after hybernation.
	 */
	initrtclock(TIMER_FREQ);
#endif

	inittodr(time_second);
	if (!(sc->sc_hwflags & APM_F_DONT_RUN_HOOKS)) {
		splx(apm_spl);
		pmf_system_resume(PMF_Q_NONE);
	}

	apm_record_event(sc, event_type);
}
Esempio n. 11
0
/* Start transaction. */
int
tpm_legacy_start(struct tpm_softc *sc, int flag)
{
	struct timeval tv;
	uint8_t bits, r;
	int to, rv;

	bits = flag == UIO_READ ? TPM_LEGACY_DA : 0;
	tv.tv_sec = TPM_LEGACY_TMO;
	tv.tv_usec = 0;
	to = tvtohz(&tv) / TPM_LEGACY_SLEEP;
	while (((r = bus_space_read_1(sc->sc_batm, sc->sc_bahm, 1)) &
	    (TPM_LEGACY_BUSY|bits)) != bits && to--) {
		rv = tsleep(sc, PRIBIO | PCATCH, "legacy_tpm_start",
		    TPM_LEGACY_SLEEP);
		if (rv && rv != EWOULDBLOCK)
			return rv;
	}

#if defined(TPM_DEBUG) && !defined(__FreeBSD__)
	char buf[128];
	snprintb(buf, sizeof(buf), TPM_LEGACY_BITS, r);
	aprint_debug_dev(sc->sc_dev, "%s: bits %s\n", device_xname(sc->sc_dev),
	    buf);
#endif
	if ((r & (TPM_LEGACY_BUSY|bits)) != bits)
		return EIO;

	return 0;
}
Esempio n. 12
0
static void
sony_acpi_notify_handler(ACPI_HANDLE hdl, UINT32 notify, void *opaque)
{
	device_t dv = opaque;
	struct sony_acpi_softc *sc = device_private(dv);
	ACPI_STATUS rv;
	ACPI_INTEGER arg;
	int s;

	if (notify == SONY_NOTIFY_FnKeyEvent) {
		rv = sony_acpi_eval_set_integer(hdl, "SN07", 0x202, &arg);
		if (ACPI_FAILURE(rv))
			return;

		notify = arg & 0xff;
	}

	s = spltty();
	switch (notify) {
	case SONY_NOTIFY_BrightnessDownPressed:
		sony_acpi_brightness_down(dv);
		break;
	case SONY_NOTIFY_BrightnessUpPressed:
		sony_acpi_brightness_up(dv);
		break;
	case SONY_NOTIFY_BrightnessDownReleased:
	case SONY_NOTIFY_BrightnessUpReleased:
		break;
	case SONY_NOTIFY_SuspendPressed:
		if (!sc->sc_smpsw_valid)
			break;
		sysmon_pswitch_event(&sc->sc_smpsw[SONY_PSW_SLEEP],
		    PSWITCH_EVENT_PRESSED);
		break;
	case SONY_NOTIFY_SuspendReleased:
		break;
	case SONY_NOTIFY_DisplaySwitchPressed:
		if (!sc->sc_smpsw_valid)
			break;
		sysmon_pswitch_event(&sc->sc_smpsw[SONY_PSW_DISPLAY_CYCLE],
		    PSWITCH_EVENT_PRESSED);
		break;
	case SONY_NOTIFY_DisplaySwitchReleased:
		break;
	case SONY_NOTIFY_ZoomPressed:
		if (!sc->sc_smpsw_valid)
			break;
		sysmon_pswitch_event(&sc->sc_smpsw[SONY_PSW_ZOOM],
		    PSWITCH_EVENT_PRESSED);
		break;
	case SONY_NOTIFY_ZoomReleased:
		break;
	default:
		aprint_debug_dev(dv, "unknown notify event 0x%x\n",
		    notify);
		break;
	}
	splx(s);
}
Esempio n. 13
0
static void
acpi_dalb_init(device_t dev)
{
	struct acpi_dalb_softc *sc = device_private(dev);
	ACPI_OBJECT *obj;
	ACPI_STATUS rv;
	ACPI_BUFFER ret;

	rv = acpi_eval_struct(sc->sc_node->ad_handle, "GHID", &ret);

	if (ACPI_FAILURE(rv) || ret.Pointer == NULL) {
		aprint_error_dev(dev,
			"couldn't enable notify handler: (%s)\n",
			AcpiFormatException(rv));
		return;
	}

	obj = ret.Pointer;

	if (obj->Type != ACPI_TYPE_BUFFER) {
		sc->sc_usageid = DALB_ID_INVALID;
		aprint_debug_dev(dev, "invalid ACPI type: %u\n", obj->Type);
		goto out;
	}

	switch (obj->Buffer.Length) {
	case 1:
		sc->sc_usageid = *(uint8_t *)obj->Buffer.Pointer;
		break;
	case 2:
		sc->sc_usageid = le16toh(*(uint16_t *)obj->Buffer.Pointer);
		break;
	case 4:
		sc->sc_usageid = le32toh(*(uint32_t *)obj->Buffer.Pointer);
		break;
	default:
		aprint_debug_dev(dev, "unhandled ret.Length: 0x%lx\n",
			(unsigned long)obj->Buffer.Length);
		sc->sc_usageid = DALB_ID_INVALID;
		break;
	}

out:
	ACPI_FREE(ret.Pointer);
}
Esempio n. 14
0
void
x86_errata(void)
{
	struct cpu_info *ci;
	uint32_t descs[4];
	errata_t *e, *ex;
	cpurev_t rev;
	int i, j, upgrade;
	static int again;

	if (cpu_vendor != CPUVENDOR_AMD)
		return;

	ci = curcpu();

	x86_cpuid(0x80000001, descs);

	for (i = 0;; i += 2) {
		if ((rev = cpurevs[i]) == OINK)
			return;
		if (cpurevs[i + 1] == descs[0])
			break;
	}

	ex = errata + sizeof(errata) / sizeof(errata[0]);
	for (upgrade = 0, e = errata; e < ex; e++) {
		if (e->e_reported)
			continue;
		if (e->e_set != NULL) {
			for (j = 0; e->e_set[j] != OINK; j++)
				if (e->e_set[j] == rev)
					break;
			if (e->e_set[j] == OINK)
				continue;
		}

		aprint_debug_dev(ci->ci_dev, "testing for erratum %d\n",
		    e->e_num);

		if (e->e_act == NULL)
			e->e_reported = TRUE;
		else if ((*e->e_act)(ci, e) == FALSE)
			continue;

		aprint_verbose_dev(ci->ci_dev, "erratum %d present\n",
		    e->e_num);
		upgrade = 1;
	}

	if (upgrade && !again) {
		again = 1;
		aprint_normal_dev(ci->ci_dev, "WARNING: errata present, BIOS upgrade "
		    "may be\n");
		aprint_normal_dev(ci->ci_dev, "WARNING: necessary to ensure reliable "
		    "operation\n");
	}
}
Esempio n. 15
0
/*
 * Handle resume event.  Actually nothing to do as the BIOS is supposed
 * to restore the previously saved state.
 */
bool
tpm_resume(device_t dev, const pmf_qual_t *qual)
{
#ifdef TPM_DEBUG
	struct tpm_softc *sc = device_private(dev);
	aprint_debug_dev(sc->sc_dev, "%s: resume\n", __func__);
#endif
	return true;
}
Esempio n. 16
0
int
tpm_request_locality(struct tpm_softc *sc, int l)
{
	uint32_t r;
	int to, rv;

	if (l != 0)
		return EINVAL;

	if ((bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_ACCESS) &
	    (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY)) ==
	    (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY))
		return 0;

	bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_ACCESS,
	    TPM_ACCESS_REQUEST_USE);

	to = tpm_tmotohz(TPM_ACCESS_TMO);

	while ((r = bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_ACCESS) &
	    (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY)) !=
	    (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY) && to--) {
		rv = tsleep(sc->sc_init, PRIBIO | PCATCH, "tpm_locality", 1);
		if (rv &&  rv != EWOULDBLOCK) {
#ifdef TPM_DEBUG
			aprint_debug_dev(sc->sc_dev, "%s: interrupted %d\n",
			    __func__, rv);
#endif
			return rv;
		}
	}

	if ((r & (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY)) !=
	    (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY)) {
#ifdef TPM_DEBUG
		char buf[128];
		snprintb(buf, sizeof(buf), TPM_ACCESS_BITS, r);
		aprint_debug_dev(sc->sc_dev, "%s: access %s\n", __func__, buf);
#endif
		return EBUSY;
	}

	return 0;
}
/*
 * acpitz_attach: autoconf(9) attach routine
 */
static void
acpitz_attach(device_t parent, device_t self, void *aux)
{
    struct acpitz_softc *sc = device_private(self);
    struct acpi_attach_args *aa = aux;
    ACPI_INTEGER val;
    ACPI_STATUS rv;

    sc->sc_first = true;
    sc->sc_have_fan = false;
    sc->sc_node = aa->aa_node;
    sc->sc_zone.tzp = ATZ_TZP_RATE;

    aprint_naive("\n");
    acpitz_print_processor_list(self);
    aprint_normal("\n");

    /*
     * The _TZP (ACPI 4.0, p. 430) defines the recommended
     * polling interval (in tenths of seconds). A value zero
     * means that polling "should not be necessary".
     */
    rv = acpi_eval_integer(sc->sc_node->ad_handle, "_TZP", &val);

    if (ACPI_SUCCESS(rv) && val != 0)
        sc->sc_zone.tzp = val;

    aprint_debug_dev(self, "polling interval %d.%d seconds\n",
                     sc->sc_zone.tzp / 10, sc->sc_zone.tzp % 10);

    sc->sc_zone_expire = ATZ_ZONE_EXPIRE / sc->sc_zone.tzp;

    /*
     * XXX: The fan controls seen here are available on
     *	some HP laptops. Arguably these should not
     *	appear in a generic device driver like this.
     */
    if (acpitz_get_fanspeed(self, &sc->sc_zone.fanmin,
                            &sc->sc_zone.fanmax, &sc->sc_zone.fancurrent) == 0)
        sc->sc_have_fan = true;

    acpitz_get_zone(self, 1);
    acpitz_get_status(self);

    (void)pmf_device_register(self, NULL, NULL);
    (void)acpi_power_register(sc->sc_node->ad_handle);
    (void)acpi_register_notify(sc->sc_node, acpitz_notify_handler);

    callout_init(&sc->sc_callout, CALLOUT_MPSAFE);
    callout_setfunc(&sc->sc_callout, acpitz_tick, self);

    acpitz_init_envsys(self);

    callout_schedule(&sc->sc_callout, sc->sc_zone.tzp * hz / 10);
}
Esempio n. 18
0
void
flashstrategy(struct buf * const bp)
{
	struct flash_softc *sc;
	const struct flash_interface *flash_if;
	const struct flash_partition *part;
	int unit, device_blks;

	unit = minor(bp->b_dev);
	sc = device_lookup_private(&flash_cd, unit);
	if (sc == NULL) {
		bp->b_error = ENXIO;
		goto done;
	}

	flash_if = sc->flash_if;
	part = &sc->sc_partinfo;

	/* divider */
	KASSERT(flash_if->writesize != 0);

	aprint_debug_dev(sc->sc_dev, "flash_strategy()\n");

	if (!(bp->b_flags & B_READ) && sc->sc_readonly) {
		bp->b_error = EACCES;
		goto done;
	}

	/* check if length is not negative */
	if (bp->b_blkno < 0) {
		bp->b_error = EINVAL;
		goto done;
	}

	/* zero lenght i/o */
	if (bp->b_bcount == 0) {
		goto done;
	}

	device_blks = sc->sc_partinfo.part_size / DEV_BSIZE;
	KASSERT(part->part_offset % DEV_BSIZE == 0);
	bp->b_rawblkno = bp->b_blkno + (part->part_offset / DEV_BSIZE);

	if (bounds_check_with_mediasize(bp, DEV_BSIZE, device_blks) <= 0) {
		goto done;
	}

	bp->b_resid = bp->b_bcount;
	flash_if->submit(sc->sc_parent_dev, bp);

	return;
done:
	bp->b_resid = bp->b_bcount;
	biodone(bp);
}
void
nextdisplay_attach(device_t parent, device_t self, void *aux)
{
	struct nextdisplay_softc *sc = device_private(self);
	struct wsemuldisplaydev_attach_args waa;
	int isconsole;
	int iscolor;
	paddr_t addr;

	if (rom_machine_type == NeXT_WARP9C ||
	    rom_machine_type == NeXT_TURBO_COLOR) {
		iscolor = 1;
		addr = colorbase;
	} else {
		iscolor = 0;
		addr = monobase;
	}

	isconsole = nextdisplay_is_console(addr);
				
	if (isconsole) {
		sc->sc_dc = &nextdisplay_console_dc;
		sc->nscreens = 1;
	} else {
		sc->sc_dc = (struct nextdisplay_config *)
				malloc(sizeof(struct nextdisplay_config), M_DEVBUF, M_WAITOK);
		nextdisplay_init(sc->sc_dc, iscolor);
	}

	printf(": %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
	       sc->sc_dc->dc_depth);

	if (iscolor) {
#if 0
		uint8_t x;

		x = *(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG);
		aprint_debug_dev(sc->sc_dev, "cmd=%02x\n", x);
#endif
		*(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG) = 0x05;
		isrlink_autovec(nextdisplay_intr, sc, NEXT_I_IPL(NEXT_I_C16_VIDEO), 1, NULL);
		INTR_ENABLE(NEXT_I_C16_VIDEO);
	}

	/* initialize the raster */
	waa.console = isconsole;
	waa.scrdata = iscolor ? &nextdisplay_screenlist_color : &nextdisplay_screenlist_mono;
	waa.accessops = &nextdisplay_accessops;
	waa.accesscookie = sc;
#if 0
	printf("nextdisplay: access cookie is %p\n", sc);
#endif
	config_found(self, &waa, wsemuldisplaydevprint);
}
Esempio n. 20
0
int
tpm_tis12_read(struct tpm_softc *sc, void *buf, size_t len, size_t *count,
    int flags)
{
	uint8_t *p = buf;
	size_t cnt;
	int rv, n, bcnt;

#ifdef TPM_DEBUG
	aprint_debug_dev(sc->sc_dev, "%s: len %zu\n", __func__, len);
#endif
	cnt = 0;
	while (len > 0) {
		if ((rv = tpm_waitfor(sc, TPM_STS_DATA_AVAIL | TPM_STS_VALID,
		    TPM_READ_TMO, sc->sc_read)))
			return rv;

		bcnt = tpm_getburst(sc);
		n = MIN(len, bcnt);
#ifdef TPM_DEBUG
		aprint_debug_dev(sc->sc_dev,
		    "%s: fetching %d, burst is %d\n", __func__, n, bcnt);
#endif
		for (; n--; len--) {
			*p++ = bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_DATA);
			cnt++;
		}

		if ((flags & TPM_PARAM_SIZE) == 0 && cnt >= 6)
			break;
	}
#ifdef TPM_DEBUG
	aprint_debug_dev(sc->sc_dev,
	    "%s: read %zu bytes, len %zu\n", __func__, cnt, len);
#endif

	if (count)
		*count = cnt;

	return 0;
}
Esempio n. 21
0
int
tpmwrite(dev_t dev, struct uio *uio, int flags)
{
	struct tpm_softc *sc = device_lookup_private(&tpm_cd, TPMUNIT(dev));
	uint8_t buf[TPM_BUFSIZ];
	int n, rv, s;

	if (!sc)
		return ENXIO;

	s = spltty();

#ifdef TPM_DEBUG
	aprint_debug_dev(sc->sc_dev, "%s: io count %zu\n", __func__,
	    uio->uio_resid);
#endif

	n = MIN(sizeof(buf), uio->uio_resid);
	if ((rv = uiomove(buf, n, uio))) {
#ifdef TPM_DEBUG
		aprint_debug_dev(sc->sc_dev,
		    "%s: uiomove failed %d\n", __func__, rv);
#endif
		splx(s);
		return rv;
	}

	if ((rv = (*sc->sc_start)(sc, UIO_WRITE))) {
		splx(s);
		return rv;
	}

	if ((rv = (*sc->sc_write)(sc, buf, n))) {
		splx(s);
		return rv;
	}

	rv = (*sc->sc_end)(sc, UIO_WRITE, rv);
	splx(s);
	return rv;
}
static int
exynos_wdt_tickle(struct sysmon_wdog *smw)
{
	struct exynos_wdt_softc * const sc = smw->smw_cookie;

	/*
	 * Cause the WDOG to restart counting.
	 */
	exynos_wdt_wdog_write(sc, EXYNOS_WDT_WTCNT, sc->sc_wdog_wtdat);
	aprint_debug_dev(sc->sc_dev, "tickle\n");
	return 0;
}
Esempio n. 23
0
static void
asus_notify_handler(ACPI_HANDLE hdl, uint32_t notify, void *opaque)
{
	struct asus_softc *sc;
	device_t self = opaque;

	sc = device_private(self);

	if (notify >= ASUS_NOTIFY_BrightnessLow &&
	    notify <= ASUS_NOTIFY_BrightnessHigh) {
		aprint_debug_dev(sc->sc_dev, "brightness %d percent\n",
		    (notify & 0xf) * 100 / 0xf);
		return;
	}

	switch (notify) {
	case ASUS_NOTIFY_WirelessSwitch:	/* handled by AML */
	case ASUS_NOTIFY_WindowSwitch:		/* XXXJDM what is this? */
		break;
	case ASUS_NOTIFY_DisplayCycle:
		if (sc->sc_smpsw_valid == false)
			break;
		sysmon_pswitch_event(&sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE],
		    PSWITCH_EVENT_PRESSED);
		break;
	case ASUS_NOTIFY_VolumeMute:
		pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_TOGGLE);
		break;
	case ASUS_NOTIFY_VolumeDown:
		pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN);
		break;
	case ASUS_NOTIFY_VolumeUp:
		pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP);
		break;
	default:
		aprint_debug_dev(sc->sc_dev, "unknown event 0x%02x\n", notify);
		break;
	}
}
Esempio n. 24
0
/* Setup TPM using legacy interface. */
int
tpm_legacy_init(struct tpm_softc *sc, int irq, const char *name)
{
	char id[8];
	int i;

	if ((i = bus_space_map(sc->sc_batm, tpm_enabled, 2, 0, &sc->sc_bahm))) {
		aprint_debug_dev(sc->sc_dev, "cannot map tpm registers (%d)\n",
		    i);
		tpm_enabled = 0;
		return 1;
	}

	for (i = sizeof(id); i--; )
		id[i] = tpm_legacy_in(sc->sc_bt, sc->sc_bh, TPM_ID + i);

	aprint_debug_dev(sc->sc_dev, "%.4s %d.%d @0x%x\n", &id[4], id[0],
	    id[1], tpm_enabled);
	tpm_enabled = 0;

	return 0;
}
Esempio n. 25
0
static void
thinkpad_notify_handler(ACPI_HANDLE hdl, uint32_t notify, void *opaque)
{
	device_t self = opaque;
	thinkpad_softc_t *sc;

	sc = device_private(self);

	if (notify != 0x80) {
		aprint_debug_dev(self, "unknown notify 0x%02x\n", notify);
		return;
	}

	(void)AcpiOsExecute(OSL_NOTIFY_HANDLER, thinkpad_get_hotkeys, sc);
}
Esempio n. 26
0
static void
tda_adjust(void *v)
{
	struct tda_softc *sc = v;
	u_int64_t ctemp, stemp;
	u_int16_t cspeed, sspeed;

	/* Default to running the fans at maximum speed. */
	sspeed = cspeed = TDA_FANSPEED_MAX;

	/* fetch maximum current temperature */
	ctemp = sysmon_envsys_get_max_value(is_cpu_sensor, true);
	stemp = sysmon_envsys_get_max_value(is_system_sensor, true);

	/* the predicates for selecting sensors must have gone wrong */
	if (ctemp == 0 || stemp == 0) {
		aprint_error_dev(sc->sc_dev, "skipping temp adjustment"
			" - no sensor values\n");
		return;
	}

	aprint_debug_dev(sc->sc_dev, "current temperature: cpu %" PRIu64
		" system %" PRIu64 "\n",
		ctemp, stemp);

	if (ctemp < CPU_TEMP_MIN)
		cspeed = TDA_FANSPEED_MIN;
	else if (ctemp < CPU_TEMP_MAX)
		cspeed = TDA_FANSPEED_MIN +
			(ctemp - CPU_TEMP_MIN) * 
			(TDA_FANSPEED_MAX - TDA_FANSPEED_MIN) / 
			(CPU_TEMP_MAX - CPU_TEMP_MIN);

	if (stemp < SYS_TEMP_MIN)
		sspeed = TDA_FANSPEED_MIN;
	else if (stemp < SYS_TEMP_MAX)
		sspeed = TDA_FANSPEED_MIN +
			(stemp - SYS_TEMP_MIN) * 
			(TDA_FANSPEED_MAX - TDA_FANSPEED_MIN) / 
			(SYS_TEMP_MAX - SYS_TEMP_MIN);

	if (sspeed == sc->sc_sfan_speed && cspeed == sc->sc_cfan_speed)
		return;

	sc->sc_sfan_speed = sspeed;
	sc->sc_cfan_speed = cspeed;
	tda_setspeed(sc);
}
Esempio n. 27
0
static void
fujitsu_hk_notify_handler(ACPI_HANDLE handle, uint32_t evt, void *context)
{
    struct fujitsu_hk_softc *sc = device_private(context);
    static const int handler = OSL_NOTIFY_HANDLER;

    switch (evt) {

    case FUJITSU_HK_NOTIFY:
        (void)AcpiOsExecute(handler, fujitsu_hk_event_callback, sc);
        break;

    default:
        aprint_debug_dev(sc->sc_dev, "unknown notify 0x%02X\n", evt);
    }
}
Esempio n. 28
0
static bool 
x86_errata_setmsr(struct cpu_info *ci, errata_t *e)
{
	uint64_t val;

	(void)ci;

	val = rdmsr_locked(e->e_data1, OPTERON_MSR_PASSCODE);
	if ((val & e->e_data2) != 0)
		return FALSE;
	wrmsr_locked(e->e_data1, OPTERON_MSR_PASSCODE, val | e->e_data2);
	aprint_debug_dev(ci->ci_dev, "erratum %d patched\n",
	    e->e_num);

	return FALSE;
}
Esempio n. 29
0
/* Setup TPM using TIS 1.2 interface. */
int
tpm_tis12_init(struct tpm_softc *sc, int irq, const char *name)
{
	uint32_t r;
	int i;

	r = bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_INTF_CAPABILITIES);
#ifdef TPM_DEBUG
	char cbuf[128];
	snprintb(cbuf, sizeof(cbuf), TPM_CAPBITS, r);
	aprint_debug_dev(sc->sc_dev, "%s: caps=%s ", __func__, cbuf);
#endif
	if ((r & TPM_CAPSREQ) != TPM_CAPSREQ ||
	    !(r & (TPM_INTF_INT_EDGE_RISING | TPM_INTF_INT_LEVEL_LOW))) {
		char buf[128];
		snprintb(buf, sizeof(buf), TPM_CAPBITS, r);
		aprint_error_dev(sc->sc_dev, "capabilities too low (caps=%s)\n",
		    buf);
		return 1;
	}
	sc->sc_capabilities = r;

	sc->sc_devid = bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_ID);
	sc->sc_rev = bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_REV);

	for (i = 0; tpm_devs[i].devid; i++)
		if (tpm_devs[i].devid == sc->sc_devid)
			break;

	if (tpm_devs[i].devid)
		aprint_normal(": %s rev 0x%x\n",
		    tpm_devs[i].name, sc->sc_rev);
	else
		aprint_normal(": device 0x%08x rev 0x%x\n",
		    sc->sc_devid, sc->sc_rev);

	if (tpm_tis12_irqinit(sc, irq, i))
		return 1;

	if (tpm_request_locality(sc, 0))
		return 1;

	/* Abort whatever it thought it was doing. */
	bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_STS, TPM_STS_CMD_READY);

	return 0;
}
Esempio n. 30
0
static void
thinkpad_notify_handler(ACPI_HANDLE hdl, UINT32 notify, void *opaque)
{
	thinkpad_softc_t *sc = (thinkpad_softc_t *)opaque;
	device_t self = sc->sc_dev;
	ACPI_STATUS rv;
 
	if (notify != 0x80) {
		aprint_debug_dev(self, "unknown notify 0x%02x\n", notify);
		return;
	}

	rv = AcpiOsExecute(OSL_NOTIFY_HANDLER, thinkpad_get_hotkeys, sc);
	if (ACPI_FAILURE(rv))
		aprint_error_dev(self, "couldn't queue hotkey handler: %s\n",
		    AcpiFormatException(rv));
}