Commit 7ad6e943 authored by Huang Ying's avatar Huang Ying Committed by Len Brown

ACPI, APEI, Manage GHES as platform devices

Register GHES during HEST initialization as platform devices. And make
GHES driver into platform device driver. So that the GHES driver
module can be loaded automatically when there are GHES available.
Signed-off-by: default avatarHuang Ying <ying.huang@intel.com>
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent ad4ecef2
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/cper.h> #include <linux/cper.h>
#include <linux/kdebug.h> #include <linux/kdebug.h>
#include <linux/platform_device.h>
#include <linux/mutex.h>
#include <acpi/apei.h> #include <acpi/apei.h>
#include <acpi/atomicio.h> #include <acpi/atomicio.h>
#include <acpi/hed.h> #include <acpi/hed.h>
...@@ -87,6 +89,7 @@ struct ghes { ...@@ -87,6 +89,7 @@ struct ghes {
* used for that. * used for that.
*/ */
static LIST_HEAD(ghes_sci); static LIST_HEAD(ghes_sci);
static DEFINE_MUTEX(ghes_list_mutex);
static struct ghes *ghes_new(struct acpi_hest_generic *generic) static struct ghes *ghes_new(struct acpi_hest_generic *generic)
{ {
...@@ -293,18 +296,15 @@ static struct notifier_block ghes_notifier_sci = { ...@@ -293,18 +296,15 @@ static struct notifier_block ghes_notifier_sci = {
.notifier_call = ghes_notify_sci, .notifier_call = ghes_notify_sci,
}; };
static int hest_ghes_parse(struct acpi_hest_header *hest_hdr, void *data) static int __devinit ghes_probe(struct platform_device *ghes_dev)
{ {
struct acpi_hest_generic *generic; struct acpi_hest_generic *generic;
struct ghes *ghes = NULL; struct ghes *ghes = NULL;
int rc = 0; int rc = -EINVAL;
if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR) generic = ghes_dev->dev.platform_data;
return 0;
generic = (struct acpi_hest_generic *)hest_hdr;
if (!generic->enabled) if (!generic->enabled)
return 0; return -ENODEV;
if (generic->error_block_length < if (generic->error_block_length <
sizeof(struct acpi_hest_generic_status)) { sizeof(struct acpi_hest_generic_status)) {
...@@ -327,62 +327,91 @@ static int hest_ghes_parse(struct acpi_hest_header *hest_hdr, void *data) ...@@ -327,62 +327,91 @@ static int hest_ghes_parse(struct acpi_hest_header *hest_hdr, void *data)
ghes = NULL; ghes = NULL;
goto err; goto err;
} }
switch (generic->notify.type) { if (generic->notify.type == ACPI_HEST_NOTIFY_SCI) {
case ACPI_HEST_NOTIFY_POLLED: mutex_lock(&ghes_list_mutex);
pr_warning(GHES_PFX
"Generic hardware error source: %d notified via POLL is not supported!\n",
generic->header.source_id);
break;
case ACPI_HEST_NOTIFY_EXTERNAL:
case ACPI_HEST_NOTIFY_LOCAL:
pr_warning(GHES_PFX
"Generic hardware error source: %d notified via IRQ is not supported!\n",
generic->header.source_id);
break;
case ACPI_HEST_NOTIFY_SCI:
if (list_empty(&ghes_sci)) if (list_empty(&ghes_sci))
register_acpi_hed_notifier(&ghes_notifier_sci); register_acpi_hed_notifier(&ghes_notifier_sci);
list_add_rcu(&ghes->list, &ghes_sci); list_add_rcu(&ghes->list, &ghes_sci);
break; mutex_unlock(&ghes_list_mutex);
case ACPI_HEST_NOTIFY_NMI: } else {
pr_warning(GHES_PFX unsigned char *notify = NULL;
"Generic hardware error source: %d notified via NMI is not supported!\n",
generic->header.source_id); switch (generic->notify.type) {
break; case ACPI_HEST_NOTIFY_POLLED:
default: notify = "POLL";
pr_warning(FW_WARN GHES_PFX break;
"Unknown notification type: %u for generic hardware error source: %d\n", case ACPI_HEST_NOTIFY_EXTERNAL:
generic->notify.type, generic->header.source_id); case ACPI_HEST_NOTIFY_LOCAL:
break; notify = "IRQ";
break;
case ACPI_HEST_NOTIFY_NMI:
notify = "NMI";
break;
}
if (notify) {
pr_warning(GHES_PFX
"Generic hardware error source: %d notified via %s is not supported!\n",
generic->header.source_id, notify);
} else {
pr_warning(FW_WARN GHES_PFX
"Unknown notification type: %u for generic hardware error source: %d\n",
generic->notify.type, generic->header.source_id);
}
rc = -ENODEV;
goto err;
} }
platform_set_drvdata(ghes_dev, ghes);
return 0; return 0;
err: err:
if (ghes) if (ghes) {
ghes_fini(ghes); ghes_fini(ghes);
kfree(ghes);
}
return rc; return rc;
} }
static void ghes_cleanup(void) static int __devexit ghes_remove(struct platform_device *ghes_dev)
{ {
struct ghes *ghes, *nghes; struct ghes *ghes;
struct acpi_hest_generic *generic;
if (!list_empty(&ghes_sci)) ghes = platform_get_drvdata(ghes_dev);
unregister_acpi_hed_notifier(&ghes_notifier_sci); generic = ghes->generic;
switch (generic->notify.type) {
case ACPI_HEST_NOTIFY_SCI:
mutex_lock(&ghes_list_mutex);
list_del_rcu(&ghes->list);
if (list_empty(&ghes_sci))
unregister_acpi_hed_notifier(&ghes_notifier_sci);
mutex_unlock(&ghes_list_mutex);
break;
default:
BUG();
break;
}
synchronize_rcu(); synchronize_rcu();
ghes_fini(ghes);
kfree(ghes);
list_for_each_entry_safe(ghes, nghes, &ghes_sci, list) { platform_set_drvdata(ghes_dev, NULL);
list_del(&ghes->list);
ghes_fini(ghes); return 0;
kfree(ghes);
}
} }
static struct platform_driver ghes_platform_driver = {
.driver = {
.name = "GHES",
.owner = THIS_MODULE,
},
.probe = ghes_probe,
.remove = ghes_remove,
};
static int __init ghes_init(void) static int __init ghes_init(void)
{ {
int rc;
if (acpi_disabled) if (acpi_disabled)
return -ENODEV; return -ENODEV;
...@@ -391,32 +420,12 @@ static int __init ghes_init(void) ...@@ -391,32 +420,12 @@ static int __init ghes_init(void)
return -EINVAL; return -EINVAL;
} }
rc = apei_hest_parse(hest_ghes_parse, NULL); return platform_driver_register(&ghes_platform_driver);
if (rc) {
pr_err(GHES_PFX
"Error during parsing HEST generic hardware error sources.\n");
goto err_cleanup;
}
if (list_empty(&ghes_sci)) {
pr_info(GHES_PFX
"No functional generic hardware error sources.\n");
rc = -ENODEV;
goto err_cleanup;
}
pr_info(GHES_PFX
"Generic Hardware Error Source support is initialized.\n");
return 0;
err_cleanup:
ghes_cleanup();
return rc;
} }
static void __exit ghes_exit(void) static void __exit ghes_exit(void)
{ {
ghes_cleanup(); platform_driver_unregister(&ghes_platform_driver);
} }
module_init(ghes_init); module_init(ghes_init);
...@@ -425,3 +434,4 @@ module_exit(ghes_exit); ...@@ -425,3 +434,4 @@ module_exit(ghes_exit);
MODULE_AUTHOR("Huang Ying"); MODULE_AUTHOR("Huang Ying");
MODULE_DESCRIPTION("APEI Generic Hardware Error Source support"); MODULE_DESCRIPTION("APEI Generic Hardware Error Source support");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:GHES");
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/kdebug.h> #include <linux/kdebug.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/platform_device.h>
#include <acpi/apei.h> #include <acpi/apei.h>
#include "apei-internal.h" #include "apei-internal.h"
...@@ -47,11 +48,6 @@ EXPORT_SYMBOL_GPL(hest_disable); ...@@ -47,11 +48,6 @@ EXPORT_SYMBOL_GPL(hest_disable);
static struct acpi_table_hest *hest_tab; static struct acpi_table_hest *hest_tab;
static int hest_void_parse(struct acpi_hest_header *hest_hdr, void *data)
{
return 0;
}
static int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = { static int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = {
[ACPI_HEST_TYPE_IA32_CHECK] = -1, /* need further calculation */ [ACPI_HEST_TYPE_IA32_CHECK] = -1, /* need further calculation */
[ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1, [ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1,
...@@ -125,6 +121,69 @@ int apei_hest_parse(apei_hest_func_t func, void *data) ...@@ -125,6 +121,69 @@ int apei_hest_parse(apei_hest_func_t func, void *data)
} }
EXPORT_SYMBOL_GPL(apei_hest_parse); EXPORT_SYMBOL_GPL(apei_hest_parse);
struct ghes_arr {
struct platform_device **ghes_devs;
unsigned int count;
};
static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)
{
int *count = data;
if (hest_hdr->type == ACPI_HEST_TYPE_GENERIC_ERROR)
(*count)++;
return 0;
}
static int hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data)
{
struct acpi_hest_generic *generic;
struct platform_device *ghes_dev;
struct ghes_arr *ghes_arr = data;
int rc;
if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR)
return 0;
generic = (struct acpi_hest_generic *)hest_hdr;
if (!generic->enabled)
return 0;
ghes_dev = platform_device_alloc("GHES", hest_hdr->source_id);
if (!ghes_dev)
return -ENOMEM;
ghes_dev->dev.platform_data = generic;
rc = platform_device_add(ghes_dev);
if (rc)
goto err;
ghes_arr->ghes_devs[ghes_arr->count++] = ghes_dev;
return 0;
err:
platform_device_put(ghes_dev);
return rc;
}
static int hest_ghes_dev_register(unsigned int ghes_count)
{
int rc, i;
struct ghes_arr ghes_arr;
ghes_arr.count = 0;
ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL);
if (!ghes_arr.ghes_devs)
return -ENOMEM;
rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
if (rc)
goto err;
out:
kfree(ghes_arr.ghes_devs);
return rc;
err:
for (i = 0; i < ghes_arr.count; i++)
platform_device_unregister(ghes_arr.ghes_devs[i]);
goto out;
}
static int __init setup_hest_disable(char *str) static int __init setup_hest_disable(char *str)
{ {
hest_disable = 1; hest_disable = 1;
...@@ -137,6 +196,7 @@ static int __init hest_init(void) ...@@ -137,6 +196,7 @@ static int __init hest_init(void)
{ {
acpi_status status; acpi_status status;
int rc = -ENODEV; int rc = -ENODEV;
unsigned int ghes_count = 0;
if (acpi_disabled) if (acpi_disabled)
goto err; goto err;
...@@ -158,7 +218,11 @@ static int __init hest_init(void) ...@@ -158,7 +218,11 @@ static int __init hest_init(void)
goto err; goto err;
} }
rc = apei_hest_parse(hest_void_parse, NULL); rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
if (rc)
goto err;
rc = hest_ghes_dev_register(ghes_count);
if (rc) if (rc)
goto err; goto err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment