iwlwifi: acpi: add common code to read from ACPI

There are many places where the same process of invoking a method from
ACPI is used, causing a lot of duplicate code.  To improve this,
introduce a new function to get an ACPI object by invoking an ACPI
method that can be reused.

Additionally, since this function needs to be called when we only have
the trans, the opmode or the device, introduce a new debug macro that
gets the device as a parameter so it can be used in the new function.

Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
This commit is contained in:
Luca Coelho
2017-09-19 12:35:18 +03:00
parent 417795a3f4
commit 813df5cef3
7 changed files with 211 additions and 141 deletions

View File

@@ -68,13 +68,14 @@
#include <linux/export.h>
#include <linux/etherdevice.h>
#include <linux/pci.h>
#include <linux/acpi.h>
#include "iwl-drv.h"
#include "iwl-modparams.h"
#include "iwl-nvm-parse.h"
#include "iwl-prph.h"
#include "iwl-io.h"
#include "iwl-csr.h"
#include "fw/acpi.h"
/* NVM offsets (in words) definitions */
enum wkp_nvm_offsets {
@@ -990,37 +991,15 @@ static u32 iwl_wrdd_get_mcc(struct device *dev, union acpi_object *wrdd)
int iwl_get_bios_mcc(struct device *dev, char *mcc)
{
acpi_handle root_handle;
acpi_handle handle;
struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
acpi_status status;
union acpi_object *data;
u32 mcc_val;
root_handle = ACPI_HANDLE(dev);
if (!root_handle) {
IWL_DEBUG_EEPROM(dev,
"Could not retrieve root port ACPI handle\n");
return -ENOENT;
}
data = iwl_acpi_get_object(dev, WRDD_METHOD);
if (IS_ERR(data))
return PTR_ERR(data);
/* Get the method's handle */
status = acpi_get_handle(root_handle, (acpi_string)WRDD_METHOD,
&handle);
if (ACPI_FAILURE(status)) {
IWL_DEBUG_EEPROM(dev, "WRD method not found\n");
return -ENOENT;
}
/* Call WRDD with no arguments */
status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
if (ACPI_FAILURE(status)) {
IWL_DEBUG_EEPROM(dev, "WRDC invocation failed (0x%x)\n",
status);
return -ENOENT;
}
mcc_val = iwl_wrdd_get_mcc(dev, wrdd.pointer);
kfree(wrdd.pointer);
mcc_val = iwl_wrdd_get_mcc(dev, data);
kfree(data);
if (!mcc_val)
return -ENOENT;