svn commit: r210977 - head/sys/dev/acpica

Jung-uk Kim jkim at FreeBSD.org
Fri Aug 6 23:35:33 UTC 2010


Author: jkim
Date: Fri Aug  6 23:35:33 2010
New Revision: 210977
URL: http://svn.freebsd.org/changeset/base/210977

Log:
  When EC burst mode is activated and multiple bytes are accessed, do not
  disable and enable repeatedly, just do it once per call.  It also reduces
  code duplication.  Check all parameters early and fail immediately.

Modified:
  head/sys/dev/acpica/acpi_ec.c

Modified: head/sys/dev/acpica/acpi_ec.c
==============================================================================
--- head/sys/dev/acpica/acpi_ec.c	Fri Aug  6 23:11:19 2010	(r210976)
+++ head/sys/dev/acpica/acpi_ec.c	Fri Aug  6 23:35:33 2010	(r210977)
@@ -720,24 +720,19 @@ EcSpaceHandler(UINT32 Function, ACPI_PHY
 	       UINT64 *Value, void *Context, void *RegionContext)
 {
     struct acpi_ec_softc	*sc = (struct acpi_ec_softc *)Context;
-    ACPI_STATUS			Status;
+    ACPI_PHYSICAL_ADDRESS	EcAddr;
     UINT8			*EcData;
-    UINT8			EcAddr;
-    int				bytes, i;
+    ACPI_STATUS			Status;
 
     ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, (UINT32)Address);
 
+    if (Function != ACPI_READ && Function != ACPI_WRITE)
+	return_ACPI_STATUS (AE_BAD_PARAMETER);
     if (Width % 8 != 0 || Value == NULL || Context == NULL)
 	return_ACPI_STATUS (AE_BAD_PARAMETER);
-    bytes = Width / 8;
-    if (Address + bytes - 1 > 0xFF)
+    if (Address + Width / 8 > 256)
 	return_ACPI_STATUS (AE_BAD_ADDRESS);
 
-    if (Function == ACPI_READ)
-	*Value = 0;
-    EcAddr = Address;
-    EcData = (UINT8 *)Value;
-
     /*
      * If booting, check if we need to run the query handler.  If so, we
      * we call it directly here since our thread taskq is not active yet.
@@ -754,8 +749,21 @@ EcSpaceHandler(UINT32 Function, ACPI_PHY
     if (ACPI_FAILURE(Status))
 	return_ACPI_STATUS (Status);
 
+    /* If we can't start burst mode, continue anyway. */
+    Status = EcCommand(sc, EC_COMMAND_BURST_ENABLE);
+    if (ACPI_SUCCESS(Status)) {
+	if (EC_GET_DATA(sc) == EC_BURST_ACK) {
+	    CTR0(KTR_ACPI, "ec burst enabled");
+	    sc->ec_burstactive = TRUE;
+	}
+    }
+
     /* Perform the transaction(s), based on Width. */
-    for (i = 0; i < bytes; i++, EcAddr++, EcData++) {
+    EcAddr = Address;
+    EcData = (UINT8 *)Value;
+    if (Function == ACPI_READ)
+	*Value = 0;
+    do {
 	switch (Function) {
 	case ACPI_READ:
 	    Status = EcRead(sc, EcAddr, EcData);
@@ -763,14 +771,17 @@ EcSpaceHandler(UINT32 Function, ACPI_PHY
 	case ACPI_WRITE:
 	    Status = EcWrite(sc, EcAddr, *EcData);
 	    break;
-	default:
-	    device_printf(sc->ec_dev, "invalid EcSpaceHandler function %d\n",
-			  Function);
-	    Status = AE_BAD_PARAMETER;
-	    break;
 	}
 	if (ACPI_FAILURE(Status))
 	    break;
+	EcAddr++;
+	EcData++;
+    } while (EcAddr < Address + Width / 8);
+
+    if (sc->ec_burstactive) {
+	sc->ec_burstactive = FALSE;
+	if (ACPI_SUCCESS(EcCommand(sc, EC_COMMAND_BURST_DISABLE)))
+	    CTR0(KTR_ACPI, "ec disabled burst ok");
     }
 
     EcUnlock(sc);
@@ -943,22 +954,11 @@ static ACPI_STATUS
 EcRead(struct acpi_ec_softc *sc, UINT8 Address, UINT8 *Data)
 {
     ACPI_STATUS	status;
-    UINT8 data;
     u_int gen_count;
 
     ACPI_SERIAL_ASSERT(ec);
     CTR1(KTR_ACPI, "ec read from %#x", Address);
 
-    /* If we can't start burst mode, continue anyway. */
-    status = EcCommand(sc, EC_COMMAND_BURST_ENABLE);
-    if (status == AE_OK) {
-    	data = EC_GET_DATA(sc);
-	if (data == EC_BURST_ACK) {
-	    CTR0(KTR_ACPI, "ec burst enabled");
-	    sc->ec_burstactive = TRUE;
-	}
-    }
-
     status = EcCommand(sc, EC_COMMAND_READ);
     if (ACPI_FAILURE(status))
 	return (status);
@@ -972,14 +972,6 @@ EcRead(struct acpi_ec_softc *sc, UINT8 A
     }
     *Data = EC_GET_DATA(sc);
 
-    if (sc->ec_burstactive) {
-	sc->ec_burstactive = FALSE;
-	status = EcCommand(sc, EC_COMMAND_BURST_DISABLE);
-	if (ACPI_FAILURE(status))
-	    return (status);
-	CTR0(KTR_ACPI, "ec disabled burst ok");
-    }
-
     return (AE_OK);
 }
 
@@ -987,22 +979,11 @@ static ACPI_STATUS
 EcWrite(struct acpi_ec_softc *sc, UINT8 Address, UINT8 Data)
 {
     ACPI_STATUS	status;
-    UINT8 data;
     u_int gen_count;
 
     ACPI_SERIAL_ASSERT(ec);
     CTR2(KTR_ACPI, "ec write to %#x, data %#x", Address, Data);
 
-    /* If we can't start burst mode, continue anyway. */
-    status = EcCommand(sc, EC_COMMAND_BURST_ENABLE);
-    if (status == AE_OK) {
-    	data = EC_GET_DATA(sc);
-	if (data == EC_BURST_ACK) {
-	    CTR0(KTR_ACPI, "ec burst enabled");
-	    sc->ec_burstactive = TRUE;
-	}
-    }
-
     status = EcCommand(sc, EC_COMMAND_WRITE);
     if (ACPI_FAILURE(status))
 	return (status);
@@ -1023,13 +1004,5 @@ EcWrite(struct acpi_ec_softc *sc, UINT8 
 	return (status);
     }
 
-    if (sc->ec_burstactive) {
-	sc->ec_burstactive = FALSE;
-	status = EcCommand(sc, EC_COMMAND_BURST_DISABLE);
-	if (ACPI_FAILURE(status))
-	    return (status);
-	CTR0(KTR_ACPI, "ec disabled burst ok");
-    }
-
     return (AE_OK);
 }


More information about the svn-src-head mailing list