]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
acpi, nfit: rework NVDIMM leaf method detection
authorDan Williams <dan.j.williams@intel.com>
Wed, 28 Mar 2018 17:44:50 +0000 (10:44 -0700)
committerKhalid Elmously <khalid.elmously@canonical.com>
Wed, 6 Jun 2018 15:50:00 +0000 (11:50 -0400)
BugLink: http://bugs.launchpad.net/bugs/1773233
commit 466d1493ea830789a2f063f478aaed2e324f0d3d upstream.

Some BIOSen do not handle 0-byte transfer lengths for the _LSR and _LSW
(label storage read/write) methods. This causes Linux to fallback to the
deprecated _DSM path, or otherwise disable label support.

Introduce acpi_nvdimm_has_method() to detect whether a method is
available rather than calling the method, require _LSI and _LSR to be
paired, and require read support before enabling write support.

Cc: <stable@vger.kernel.org>
Fixes: 4b27db7e26cd ("acpi, nfit: add support for the _LS...")
Suggested-by: Erik Schmauss <erik.schmauss@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Acked-by: Khalid Elmously <khalid.elmously@canonical.com>
Acked-by: Brad Figg <brad.figg@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/acpi/nfit/core.c
drivers/acpi/nfit/nfit.h

index fb80dbf80e4b793badfca089a11e3ad314ddb749..984ec6b288df3ad291afe79b5220b0ed0d33bbe4 100644 (file)
@@ -196,7 +196,7 @@ static int xlat_nvdimm_status(struct nvdimm *nvdimm, void *buf, unsigned int cmd
                 * In the _LSI, _LSR, _LSW case the locked status is
                 * communicated via the read/write commands
                 */
-               if (nfit_mem->has_lsi)
+               if (nfit_mem->has_lsr)
                        break;
 
                if (status >> 16 & ND_CONFIG_LOCKED)
@@ -483,7 +483,7 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
                        min_t(u32, 256, in_buf.buffer.length), true);
 
        /* call the BIOS, prefer the named methods over _DSM if available */
-       if (nvdimm && cmd == ND_CMD_GET_CONFIG_SIZE && nfit_mem->has_lsi)
+       if (nvdimm && cmd == ND_CMD_GET_CONFIG_SIZE && nfit_mem->has_lsr)
                out_obj = acpi_label_info(handle);
        else if (nvdimm && cmd == ND_CMD_GET_CONFIG_DATA && nfit_mem->has_lsr) {
                struct nd_cmd_get_config_data_hdr *p = buf;
@@ -1657,12 +1657,23 @@ static void acpi_nvdimm_notify(acpi_handle handle, u32 event, void *data)
        device_unlock(dev->parent);
 }
 
+static bool acpi_nvdimm_has_method(struct acpi_device *adev, char *method)
+{
+       acpi_handle handle;
+       acpi_status status;
+
+       status = acpi_get_handle(adev->handle, method, &handle);
+
+       if (ACPI_SUCCESS(status))
+               return true;
+       return false;
+}
+
 static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc,
                struct nfit_mem *nfit_mem, u32 device_handle)
 {
        struct acpi_device *adev, *adev_dimm;
        struct device *dev = acpi_desc->dev;
-       union acpi_object *obj;
        unsigned long dsm_mask;
        const guid_t *guid;
        int i;
@@ -1735,25 +1746,15 @@ static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc,
                                        1ULL << i))
                        set_bit(i, &nfit_mem->dsm_mask);
 
-       obj = acpi_label_info(adev_dimm->handle);
-       if (obj) {
-               ACPI_FREE(obj);
-               nfit_mem->has_lsi = 1;
-               dev_dbg(dev, "%s: has _LSI\n", dev_name(&adev_dimm->dev));
-       }
-
-       obj = acpi_label_read(adev_dimm->handle, 0, 0);
-       if (obj) {
-               ACPI_FREE(obj);
-               nfit_mem->has_lsr = 1;
+       if (acpi_nvdimm_has_method(adev_dimm, "_LSI")
+                       && acpi_nvdimm_has_method(adev_dimm, "_LSR")) {
                dev_dbg(dev, "%s: has _LSR\n", dev_name(&adev_dimm->dev));
+               nfit_mem->has_lsr = true;
        }
 
-       obj = acpi_label_write(adev_dimm->handle, 0, 0, NULL);
-       if (obj) {
-               ACPI_FREE(obj);
-               nfit_mem->has_lsw = 1;
+       if (nfit_mem->has_lsr && acpi_nvdimm_has_method(adev_dimm, "_LSW")) {
                dev_dbg(dev, "%s: has _LSW\n", dev_name(&adev_dimm->dev));
+               nfit_mem->has_lsw = true;
        }
 
        return 0;
@@ -1842,10 +1843,10 @@ static int acpi_nfit_register_dimms(struct acpi_nfit_desc *acpi_desc)
                        cmd_mask |= nfit_mem->dsm_mask & NVDIMM_STANDARD_CMDMASK;
                }
 
-               if (nfit_mem->has_lsi)
+               if (nfit_mem->has_lsr) {
                        set_bit(ND_CMD_GET_CONFIG_SIZE, &cmd_mask);
-               if (nfit_mem->has_lsr)
                        set_bit(ND_CMD_GET_CONFIG_DATA, &cmd_mask);
+               }
                if (nfit_mem->has_lsw)
                        set_bit(ND_CMD_SET_CONFIG_DATA, &cmd_mask);
 
index 50d36e166d7011dbc0bcb29ccbd9166c128fc995..ac9c49463731b93e2f39b287eb55cbfdb29dee49 100644 (file)
@@ -171,9 +171,8 @@ struct nfit_mem {
        struct resource *flush_wpq;
        unsigned long dsm_mask;
        int family;
-       u32 has_lsi:1;
-       u32 has_lsr:1;
-       u32 has_lsw:1;
+       bool has_lsr;
+       bool has_lsw;
 };
 
 struct acpi_nfit_desc {