diff options
author | njl <njl@FreeBSD.org> | 2004-05-06 17:25:23 +0000 |
---|---|---|
committer | njl <njl@FreeBSD.org> | 2004-05-06 17:25:23 +0000 |
commit | d33cf3a8dd4e576e88618e7a15c1ef1ae48603eb (patch) | |
tree | accd09f66d911e3c1faf94797f832cb26090446a /sys/dev/acpica | |
parent | e9ec8dbd49497bfd0f0aa4fc21655418394cd009 (diff) | |
download | FreeBSD-src-d33cf3a8dd4e576e88618e7a15c1ef1ae48603eb.zip FreeBSD-src-d33cf3a8dd4e576e88618e7a15c1ef1ae48603eb.tar.gz |
Rename acpi_cpu to cpu. Change the probe routine to early on reject
devices it cannot attach to. This gets rid of extraneous but harmless
device_probe_and_attach() errors. While I'm here, make the device
description more useful. The !acpi case for cpu is handled by legacy0.
Diffstat (limited to 'sys/dev/acpica')
-rw-r--r-- | sys/dev/acpica/acpi_cpu.c | 132 |
1 files changed, 90 insertions, 42 deletions
diff --git a/sys/dev/acpica/acpi_cpu.c b/sys/dev/acpica/acpi_cpu.c index f5c2f8a..3a9279c 100644 --- a/sys/dev/acpica/acpi_cpu.c +++ b/sys/dev/acpica/acpi_cpu.c @@ -176,59 +176,47 @@ static device_method_t acpi_cpu_methods[] = { }; static driver_t acpi_cpu_driver = { - "acpi_cpu", + "cpu", acpi_cpu_methods, sizeof(struct acpi_cpu_softc), }; static devclass_t acpi_cpu_devclass; -DRIVER_MODULE(acpi_cpu, acpi, acpi_cpu_driver, acpi_cpu_devclass, 0, 0); -MODULE_DEPEND(acpi_cpu, acpi, 1, 1, 1); +DRIVER_MODULE(cpu, acpi, acpi_cpu_driver, acpi_cpu_devclass, 0, 0); +MODULE_DEPEND(cpu, acpi, 1, 1, 1); static int acpi_cpu_probe(device_t dev) { - if (!acpi_disabled("cpu") && acpi_get_type(dev) == ACPI_TYPE_PROCESSOR) { - device_set_desc(dev, "CPU"); - if (cpu_softc == NULL) - cpu_softc = malloc(sizeof(struct acpi_cpu_softc *) * - (mp_maxid + 1), M_TEMP /* XXX */, M_WAITOK | M_ZERO); - return (0); - } - - return (ENXIO); -} - -static int -acpi_cpu_attach(device_t dev) -{ - struct acpi_cpu_softc *sc; - struct acpi_softc *acpi_sc; - ACPI_OBJECT pobj; + int acpi_id, cpu_id, cx_count; ACPI_BUFFER buf; + ACPI_HANDLE handle; + char msg[32]; + ACPI_OBJECT *obj; ACPI_STATUS status; - int thr_ret, cx_ret, cpu_id; - - ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); - ACPI_ASSERTLOCK; + if (acpi_disabled("cpu") || acpi_get_type(dev) != ACPI_TYPE_PROCESSOR) + return (ENXIO); - sc = device_get_softc(dev); - sc->cpu_dev = dev; - sc->cpu_handle = acpi_get_handle(dev); + handle = acpi_get_handle(dev); + if (cpu_softc == NULL) + cpu_softc = malloc(sizeof(struct acpi_cpu_softc *) * + (mp_maxid + 1), M_TEMP /* XXX */, M_WAITOK | M_ZERO); /* Get our Processor object. */ - buf.Pointer = &pobj; - buf.Length = sizeof(pobj); - status = AcpiEvaluateObject(sc->cpu_handle, NULL, NULL, &buf); + buf.Pointer = NULL; + buf.Length = ACPI_ALLOCATE_BUFFER; + status = AcpiEvaluateObject(handle, NULL, NULL, &buf); if (ACPI_FAILURE(status)) { - device_printf(dev, "Couldn't get Processor object - %s\n", + device_printf(dev, "probe failed to get Processor obj - %s\n", AcpiFormatException(status)); - return_VALUE (ENXIO); + return (ENXIO); } - if (pobj.Type != ACPI_TYPE_PROCESSOR) { - device_printf(dev, "Processor object has bad type %d\n", pobj.Type); - return_VALUE (ENXIO); + obj = (ACPI_OBJECT *)buf.Pointer; + if (obj->Type != ACPI_TYPE_PROCESSOR) { + device_printf(dev, "Processor object has bad type %d\n", obj->Type); + AcpiOsFree(obj); + return (ENXIO); } /* @@ -236,9 +224,10 @@ acpi_cpu_attach(device_t dev) * ProcId as a key, however, some boxes do not have the same values * in their Processor object as the ProcId values in the MADT. */ - sc->acpi_id = pobj.Processor.ProcId; - if (acpi_pcpu_get_id(device_get_unit(dev), &sc->acpi_id, &cpu_id) != 0) - return_VALUE (ENXIO); + acpi_id = obj->Processor.ProcId; + AcpiOsFree(obj); + if (acpi_pcpu_get_id(device_get_unit(dev), &acpi_id, &cpu_id) != 0) + return (ENXIO); /* * Check if we already probed this processor. We scan the bus twice @@ -246,11 +235,70 @@ acpi_cpu_attach(device_t dev) */ if (cpu_softc[cpu_id] != NULL) return (ENXIO); - cpu_softc[cpu_id] = sc; - /* Get various global values from the Processor object. */ - sc->cpu_p_blk = pobj.Processor.PblkAddress; - sc->cpu_p_blk_len = pobj.Processor.PblkLength; + /* Get a count of Cx states for our device string. */ + cx_count = 0; + buf.Pointer = NULL; + buf.Length = ACPI_ALLOCATE_BUFFER; + status = AcpiEvaluateObject(handle, "_CST", NULL, &buf); + if (ACPI_SUCCESS(status)) { + obj = (ACPI_OBJECT *)buf.Pointer; + if (ACPI_PKG_VALID(obj, 2)) + acpi_PkgInt32(obj, 0, &cx_count); + AcpiOsFree(obj); + } else { + if (AcpiGbl_FADT->Plvl2Lat <= 100) + cx_count++; + if (AcpiGbl_FADT->Plvl3Lat <= 1000) + cx_count++; + if (cx_count > 0) + cx_count++; + } + if (cx_count > 0) + snprintf(msg, sizeof(msg), "ACPI CPU (%d Cx states)", cx_count); + else + strlcpy(msg, "ACPI CPU", sizeof(msg)); + device_set_desc_copy(dev, msg); + + /* Mark this processor as in-use and save our derived id for attach. */ + cpu_softc[cpu_id] = (void *)1; + acpi_set_magic(dev, cpu_id); + + return (0); +} + +static int +acpi_cpu_attach(device_t dev) +{ + ACPI_BUFFER buf; + ACPI_OBJECT *obj; + struct acpi_cpu_softc *sc; + struct acpi_softc *acpi_sc; + ACPI_STATUS status; + int thr_ret, cx_ret; + + ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); + + ACPI_ASSERTLOCK; + + sc = device_get_softc(dev); + sc->cpu_dev = dev; + sc->cpu_handle = acpi_get_handle(dev); + cpu_softc[acpi_get_magic(dev)] = sc; + + buf.Pointer = NULL; + buf.Length = ACPI_ALLOCATE_BUFFER; + status = AcpiEvaluateObject(sc->cpu_handle, NULL, NULL, &buf); + if (ACPI_FAILURE(status)) { + device_printf(dev, "attach failed to get Processor obj - %s\n", + AcpiFormatException(status)); + return (ENXIO); + } + obj = (ACPI_OBJECT *)buf.Pointer; + sc->cpu_p_blk = obj->Processor.PblkAddress; + sc->cpu_p_blk_len = obj->Processor.PblkLength; + sc->acpi_id = obj->Processor.ProcId; + AcpiOsFree(obj); ACPI_DEBUG_PRINT((ACPI_DB_INFO, "acpi_cpu%d: P_BLK at %#x/%d\n", device_get_unit(dev), sc->cpu_p_blk, sc->cpu_p_blk_len)); |