View | Details | Raw Unified | Return to bug 150517
Collapse All | Expand All

(-)acpi_ec.c (-61 / +54 lines)
Lines 168-174 Link Here
168
#define EC_LOCK_TIMEOUT	1000
168
#define EC_LOCK_TIMEOUT	1000
169
169
170
/* Default delay in microseconds between each run of the status polling loop. */
170
/* Default delay in microseconds between each run of the status polling loop. */
171
#define EC_POLL_DELAY	5
171
#define EC_POLL_DELAY	100
172
172
173
/* Total time in ms spent waiting for a response from EC. */
173
/* Total time in ms spent waiting for a response from EC. */
174
#define EC_TIMEOUT	750
174
#define EC_TIMEOUT	750
Lines 184-196 Link Here
184
SYSCTL_DECL(_debug_acpi);
184
SYSCTL_DECL(_debug_acpi);
185
SYSCTL_NODE(_debug_acpi, OID_AUTO, ec, CTLFLAG_RD, NULL, "EC debugging");
185
SYSCTL_NODE(_debug_acpi, OID_AUTO, ec, CTLFLAG_RD, NULL, "EC debugging");
186
186
187
static int	ec_burst_mode;
187
static int	ec_burst_mode = FALSE;
188
TUNABLE_INT("debug.acpi.ec.burst", &ec_burst_mode);
188
TUNABLE_INT("debug.acpi.ec.burst", &ec_burst_mode);
189
SYSCTL_INT(_debug_acpi_ec, OID_AUTO, burst, CTLFLAG_RW, &ec_burst_mode, 0,
189
SYSCTL_INT(_debug_acpi_ec, OID_AUTO, burst, CTLFLAG_RW, &ec_burst_mode, FALSE,
190
    "Enable use of burst mode (faster for nearly all systems)");
190
    "Enable use of burst mode (faster for nearly all systems)");
191
static int	ec_polled_mode;
191
static int	ec_delay = 0;
192
TUNABLE_INT("debug.acpi.ec.delay", &ec_delay);
193
SYSCTL_INT(_debug_acpi_ec, OID_AUTO, delay, CTLFLAG_RW, &ec_delay, 0,
194
    "Delay after waiting for responce (GPE and polled mode)");
195
static int	ec_gpe_mode = FALSE;
196
TUNABLE_INT("debug.acpi.ec.gpe", &ec_gpe_mode);
197
SYSCTL_INT(_debug_acpi_ec, OID_AUTO, gpe, CTLFLAG_RW, &ec_gpe_mode, FALSE,
198
    "Disable adaptive GPE switching (to polled mode)");
199
static int	ec_polled_mode = FALSE;
192
TUNABLE_INT("debug.acpi.ec.polled", &ec_polled_mode);
200
TUNABLE_INT("debug.acpi.ec.polled", &ec_polled_mode);
193
SYSCTL_INT(_debug_acpi_ec, OID_AUTO, polled, CTLFLAG_RW, &ec_polled_mode, 0,
201
SYSCTL_INT(_debug_acpi_ec, OID_AUTO, polled, CTLFLAG_RW, &ec_polled_mode, FALSE,
194
    "Force use of polled mode (only if interrupt mode doesn't work)");
202
    "Force use of polled mode (only if interrupt mode doesn't work)");
195
static int	ec_timeout = EC_TIMEOUT;
203
static int	ec_timeout = EC_TIMEOUT;
196
TUNABLE_INT("debug.acpi.ec.timeout", &ec_timeout);
204
TUNABLE_INT("debug.acpi.ec.timeout", &ec_timeout);
Lines 794-799 Link Here
794
    EC_STATUS ec_status;
802
    EC_STATUS ec_status;
795
803
796
    status = AE_NO_HARDWARE_RESPONSE;
804
    status = AE_NO_HARDWARE_RESPONSE;
805
797
    ec_status = EC_GET_CSR(sc);
806
    ec_status = EC_GET_CSR(sc);
798
    if (sc->ec_burstactive && !(ec_status & EC_FLAG_BURST_MODE)) {
807
    if (sc->ec_burstactive && !(ec_status & EC_FLAG_BURST_MODE)) {
799
	CTR1(KTR_ACPI, "ec burst disabled in waitevent (%s)", msg);
808
	CTR1(KTR_ACPI, "ec burst disabled in waitevent (%s)", msg);
Lines 810-865 Link Here
810
EcWaitEvent(struct acpi_ec_softc *sc, EC_EVENT Event, u_int gen_count)
819
EcWaitEvent(struct acpi_ec_softc *sc, EC_EVENT Event, u_int gen_count)
811
{
820
{
812
    ACPI_STATUS	Status;
821
    ACPI_STATUS	Status;
813
    int		count, i, slp_ival;
822
    int		count, i, req_ticks, cur_ticks;
814
823
815
    ACPI_SERIAL_ASSERT(ec);
824
    ACPI_SERIAL_ASSERT(ec);
816
    Status = AE_NO_HARDWARE_RESPONSE;
825
    Status = AE_NO_HARDWARE_RESPONSE;
817
    int need_poll = cold || rebooting || ec_polled_mode || sc->ec_suspending;
826
    int need_poll = cold || rebooting || ec_polled_mode || sc->ec_suspending;
818
    /*
819
     * The main CPU should be much faster than the EC.  So the status should
820
     * be "not ready" when we start waiting.  But if the main CPU is really
821
     * slow, it's possible we see the current "ready" response.  Since that
822
     * can't be distinguished from the previous response in polled mode,
823
     * this is a potential issue.  We really should have interrupts enabled
824
     * during boot so there is no ambiguity in polled mode.
825
     *
826
     * If this occurs, we add an additional delay before actually entering
827
     * the status checking loop, hopefully to allow the EC to go to work
828
     * and produce a non-stale status.
829
     */
830
    if (need_poll) {
831
	static int	once;
832
833
	if (EcCheckStatus(sc, "pre-check", Event) == AE_OK) {
834
	    if (!once) {
835
		device_printf(sc->ec_dev,
836
		    "warning: EC done before starting event wait\n");
837
		once = 1;
838
	    }
839
	    AcpiOsStall(10);
840
	}
841
    }
842
827
843
    /* Wait for event by polling or GPE (interrupt). */
828
    /* Wait for event by polling or GPE (interrupt). */
844
    if (need_poll) {
829
    if (need_poll) {
845
	count = (ec_timeout * 1000) / EC_POLL_DELAY;
830
	count = (ec_timeout * 1000) / EC_POLL_DELAY;
846
	if (count == 0)
831
	if (count == 0)
847
	    count = 1;
832
	    count = 1;
833
834
	/* The EC is slow, give it some time to catch up to us */
835
	AcpiOsStall(100);
848
	for (i = 0; i < count; i++) {
836
	for (i = 0; i < count; i++) {
849
	    Status = EcCheckStatus(sc, "poll", Event);
837
	    Status = EcCheckStatus(sc, "poll", Event);
850
	    if (Status == AE_OK)
838
	    if (Status == AE_OK)
851
		break;
839
		break;
852
	    AcpiOsStall(EC_POLL_DELAY);
840
	    AcpiOsStall(EC_POLL_DELAY);
853
	}
841
	}
842
843
	if (Status != AE_OK)
844
	    device_printf(sc->ec_dev, "wait timed out [polling mode]\n");
854
    } else {
845
    } else {
855
	slp_ival = hz / 1000;
846
	/* How many ticks should we sleep for (max) */
856
	if (slp_ival != 0) {
847
	req_ticks = hz < 1000 ? (ec_timeout * hz) / 1000
857
	    count = ec_timeout;
848
	    : (ec_timeout * 1000) / hz;
858
	} else {
849
	/* Make sure we sleep for at least one tick, from now */
859
	    /* hz has less than 1 ms resolution so scale timeout. */
850
	cur_ticks = (volatile int)ticks;
860
	    slp_ival = 1;
851
	req_ticks = cur_ticks + (req_ticks ? req_ticks : 1) + 1;
861
	    count = ec_timeout / (1000 / hz);
862
	}
863
852
864
	/*
853
	/*
865
	 * Wait for the GPE to signal the status changed, checking the
854
	 * Wait for the GPE to signal the status changed, checking the
Lines 867-904 Link Here
867
	 * GPE for an event we're not interested in here (i.e., SCI for
856
	 * GPE for an event we're not interested in here (i.e., SCI for
868
	 * EC query).
857
	 * EC query).
869
	 */
858
	 */
870
	for (i = 0; i < count; i++) {
859
	while ((int)(req_ticks - cur_ticks) > 0) {
871
	    if (gen_count != sc->ec_gencount) {
860
	    /* If we have not received a signal then wait for one */
872
		/*
861
	    if (gen_count == sc->ec_gencount)
873
		 * Record new generation count.  It's possible the GPE was
862
		tsleep(&sc->ec_gencount, PZERO, "ecgpe", req_ticks - cur_ticks);
874
		 * just to notify us that a query is needed and we need to
863
875
		 * wait for a second GPE to signal the completion of the
864
	    /*
876
		 * event we are actually waiting for.
865
	     * Record new generation count.  It's possible the GPE was
877
		 */
866
	     * just to notify us that a query is needed and we need to
878
		gen_count = sc->ec_gencount;
867
	     * wait for a second GPE to signal the completion of the
879
		Status = EcCheckStatus(sc, "sleep", Event);
868
	     * event we are actually waiting for.
880
		if (Status == AE_OK)
869
	     */
881
		    break;
870
	    gen_count = sc->ec_gencount;
882
	    }
871
	    Status = EcCheckStatus(sc, "sleep", Event);
883
	    tsleep(&sc->ec_gencount, PZERO, "ecgpe", slp_ival);
872
	    if (Status == AE_OK)
873
	        break;
874
875
	    /* Update current tick (so we always have a consistant value */
876
	    cur_ticks = (volatile int)ticks;
884
	}
877
	}
885
878
886
	/*
879
	/*
887
	 * We finished waiting for the GPE and it never arrived.  Try to
880
	 * We finished waiting for the GPE and it never arrived.  The register
888
	 * read the register once and trust whatever value we got.  This is
881
	 * has been read on a timeout so no need to re-read it.  Force polled
889
	 * the best we can do at this point.  Then, force polled mode on
882
	 * mode on since this system doesn't appear to generate GPEs.
890
	 * since this system doesn't appear to generate GPEs.
891
	 */
883
	 */
892
	if (Status != AE_OK) {
884
	if (Status != AE_OK) {
893
	    Status = EcCheckStatus(sc, "sleep_end", Event);
885
	    device_printf(sc->ec_dev, "wait timed out [GPE mode]%s\n",
894
	    device_printf(sc->ec_dev,
886
		ec_gpe_mode ? "" : ", forcing polled mode");
895
		"wait timed out (%sresponse), forcing polled mode\n",
887
	    ec_polled_mode = TRUE && !ec_gpe_mode;
896
		Status == AE_OK ? "" : "no ");
897
	    ec_polled_mode = TRUE;
898
	}
888
	}
899
    }
889
    }
900
    if (Status != AE_OK)
890
    if (Status != AE_OK)
901
	    CTR0(KTR_ACPI, "error: ec wait timed out");
891
	    CTR0(KTR_ACPI, "error: ec wait timed out");
892
    else if (ec_delay);
893
	/* Give the EC a chance to recover from all its hard work!!! */
894
	AcpiOsStall(ec_delay);
902
    return (Status);
895
    return (Status);
903
}
896
}

Return to bug 150517