Linux Audio

Check our new training course

Loading...
v5.4
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * ACPI watchdog table parsing support.
  4 *
  5 * Copyright (C) 2016, Intel Corporation
  6 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
 
 
 
 
  7 */
  8
  9#define pr_fmt(fmt) "ACPI: watchdog: " fmt
 10
 11#include <linux/acpi.h>
 
 12#include <linux/ioport.h>
 13#include <linux/platform_device.h>
 14
 15#include "internal.h"
 16
 17#ifdef CONFIG_RTC_MC146818_LIB
 18#include <linux/mc146818rtc.h>
 19
 20/*
 21 * There are several systems where the WDAT table is accessing RTC SRAM to
 22 * store persistent information. This does not work well with the Linux RTC
 23 * driver so on those systems we skip WDAT driver and prefer iTCO_wdt
 24 * instead.
 25 *
 26 * See also https://bugzilla.kernel.org/show_bug.cgi?id=199033.
 27 */
 28static bool acpi_watchdog_uses_rtc(const struct acpi_table_wdat *wdat)
 29{
 30	const struct acpi_wdat_entry *entries;
 31	int i;
 32
 33	entries = (struct acpi_wdat_entry *)(wdat + 1);
 34	for (i = 0; i < wdat->entries; i++) {
 35		const struct acpi_generic_address *gas;
 36
 37		gas = &entries[i].register_region;
 38		if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
 39			switch (gas->address) {
 40			case RTC_PORT(0):
 41			case RTC_PORT(1):
 42			case RTC_PORT(2):
 43			case RTC_PORT(3):
 44				return true;
 45			}
 46		}
 47	}
 48
 49	return false;
 50}
 51#else
 52static bool acpi_watchdog_uses_rtc(const struct acpi_table_wdat *wdat)
 53{
 54	return false;
 55}
 56#endif
 57
 58static const struct acpi_table_wdat *acpi_watchdog_get_wdat(void)
 59{
 60	const struct acpi_table_wdat *wdat = NULL;
 61	acpi_status status;
 62
 63	if (acpi_disabled)
 64		return NULL;
 65
 
 
 
 66	status = acpi_get_table(ACPI_SIG_WDAT, 0,
 67				(struct acpi_table_header **)&wdat);
 68	if (ACPI_FAILURE(status)) {
 69		/* It is fine if there is no WDAT */
 70		return NULL;
 71	}
 72
 73	if (acpi_watchdog_uses_rtc(wdat)) {
 74		pr_info("Skipping WDAT on this system because it uses RTC SRAM\n");
 75		return NULL;
 76	}
 77
 78	return wdat;
 79}
 80
 81/**
 82 * Returns true if this system should prefer ACPI based watchdog instead of
 83 * the native one (which are typically the same hardware).
 84 */
 85bool acpi_has_watchdog(void)
 86{
 87	return !!acpi_watchdog_get_wdat();
 88}
 89EXPORT_SYMBOL_GPL(acpi_has_watchdog);
 90
 91void __init acpi_watchdog_init(void)
 92{
 93	const struct acpi_wdat_entry *entries;
 94	const struct acpi_table_wdat *wdat;
 95	struct list_head resource_list;
 96	struct resource_entry *rentry;
 97	struct platform_device *pdev;
 98	struct resource *resources;
 99	size_t nresources = 0;
100	int i;
101
102	wdat = acpi_watchdog_get_wdat();
103	if (!wdat) {
104		/* It is fine if there is no WDAT */
105		return;
106	}
107
108	/* Watchdog disabled by BIOS */
109	if (!(wdat->flags & ACPI_WDAT_ENABLED))
110		return;
111
112	/* Skip legacy PCI WDT devices */
113	if (wdat->pci_segment != 0xff || wdat->pci_bus != 0xff ||
114	    wdat->pci_device != 0xff || wdat->pci_function != 0xff)
115		return;
116
117	INIT_LIST_HEAD(&resource_list);
118
119	entries = (struct acpi_wdat_entry *)(wdat + 1);
120	for (i = 0; i < wdat->entries; i++) {
121		const struct acpi_generic_address *gas;
122		struct resource_entry *rentry;
123		struct resource res = {};
124		bool found;
125
126		gas = &entries[i].register_region;
127
128		res.start = gas->address;
129		if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
130			res.flags = IORESOURCE_MEM;
131			res.end = res.start + ALIGN(gas->access_width, 4) - 1;
132		} else if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
133			res.flags = IORESOURCE_IO;
134			res.end = res.start + gas->access_width - 1;
135		} else {
136			pr_warn("Unsupported address space: %u\n",
137				gas->space_id);
138			goto fail_free_resource_list;
139		}
140
141		found = false;
142		resource_list_for_each_entry(rentry, &resource_list) {
143			if (rentry->res->flags == res.flags &&
144			    resource_overlaps(rentry->res, &res)) {
145				if (res.start < rentry->res->start)
146					rentry->res->start = res.start;
147				if (res.end > rentry->res->end)
148					rentry->res->end = res.end;
149				found = true;
150				break;
151			}
152		}
153
154		if (!found) {
155			rentry = resource_list_create_entry(NULL, 0);
156			if (!rentry)
157				goto fail_free_resource_list;
158
159			*rentry->res = res;
160			resource_list_add_tail(rentry, &resource_list);
161			nresources++;
162		}
163	}
164
165	resources = kcalloc(nresources, sizeof(*resources), GFP_KERNEL);
166	if (!resources)
167		goto fail_free_resource_list;
168
169	i = 0;
170	resource_list_for_each_entry(rentry, &resource_list)
171		resources[i++] = *rentry->res;
172
173	pdev = platform_device_register_simple("wdat_wdt", PLATFORM_DEVID_NONE,
174					       resources, nresources);
175	if (IS_ERR(pdev))
176		pr_err("Device creation failed: %ld\n", PTR_ERR(pdev));
177
178	kfree(resources);
179
180fail_free_resource_list:
181	resource_list_free(&resource_list);
182}
v4.17
 
  1/*
  2 * ACPI watchdog table parsing support.
  3 *
  4 * Copyright (C) 2016, Intel Corporation
  5 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
  6 *
  7 * This program is free software; you can redistribute it and/or modify
  8 * it under the terms of the GNU General Public License version 2 as
  9 * published by the Free Software Foundation.
 10 */
 11
 12#define pr_fmt(fmt) "ACPI: watchdog: " fmt
 13
 14#include <linux/acpi.h>
 15#include <linux/dmi.h>
 16#include <linux/ioport.h>
 17#include <linux/platform_device.h>
 18
 19#include "internal.h"
 20
 21static const struct dmi_system_id acpi_watchdog_skip[] = {
 22	{
 23		/*
 24		 * On Lenovo Z50-70 there are two issues with the WDAT
 25		 * table. First some of the instructions use RTC SRAM
 26		 * to store persistent information. This does not work well
 27		 * with Linux RTC driver. Second, more important thing is
 28		 * that the instructions do not actually reset the system.
 29		 *
 30		 * On this particular system iTCO_wdt seems to work just
 31		 * fine so we prefer that over WDAT for now.
 32		 *
 33		 * See also https://bugzilla.kernel.org/show_bug.cgi?id=199033.
 34		 */
 35		.ident = "Lenovo Z50-70",
 36		.matches = {
 37			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 38			DMI_MATCH(DMI_PRODUCT_NAME, "20354"),
 39			DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Z50-70"),
 40		},
 41	},
 42	{}
 43};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 44
 45static const struct acpi_table_wdat *acpi_watchdog_get_wdat(void)
 46{
 47	const struct acpi_table_wdat *wdat = NULL;
 48	acpi_status status;
 49
 50	if (acpi_disabled)
 51		return NULL;
 52
 53	if (dmi_check_system(acpi_watchdog_skip))
 54		return NULL;
 55
 56	status = acpi_get_table(ACPI_SIG_WDAT, 0,
 57				(struct acpi_table_header **)&wdat);
 58	if (ACPI_FAILURE(status)) {
 59		/* It is fine if there is no WDAT */
 
 
 
 
 
 60		return NULL;
 61	}
 62
 63	return wdat;
 64}
 65
 66/**
 67 * Returns true if this system should prefer ACPI based watchdog instead of
 68 * the native one (which are typically the same hardware).
 69 */
 70bool acpi_has_watchdog(void)
 71{
 72	return !!acpi_watchdog_get_wdat();
 73}
 74EXPORT_SYMBOL_GPL(acpi_has_watchdog);
 75
 76void __init acpi_watchdog_init(void)
 77{
 78	const struct acpi_wdat_entry *entries;
 79	const struct acpi_table_wdat *wdat;
 80	struct list_head resource_list;
 81	struct resource_entry *rentry;
 82	struct platform_device *pdev;
 83	struct resource *resources;
 84	size_t nresources = 0;
 85	int i;
 86
 87	wdat = acpi_watchdog_get_wdat();
 88	if (!wdat) {
 89		/* It is fine if there is no WDAT */
 90		return;
 91	}
 92
 93	/* Watchdog disabled by BIOS */
 94	if (!(wdat->flags & ACPI_WDAT_ENABLED))
 95		return;
 96
 97	/* Skip legacy PCI WDT devices */
 98	if (wdat->pci_segment != 0xff || wdat->pci_bus != 0xff ||
 99	    wdat->pci_device != 0xff || wdat->pci_function != 0xff)
100		return;
101
102	INIT_LIST_HEAD(&resource_list);
103
104	entries = (struct acpi_wdat_entry *)(wdat + 1);
105	for (i = 0; i < wdat->entries; i++) {
106		const struct acpi_generic_address *gas;
107		struct resource_entry *rentry;
108		struct resource res = {};
109		bool found;
110
111		gas = &entries[i].register_region;
112
113		res.start = gas->address;
114		if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
115			res.flags = IORESOURCE_MEM;
116			res.end = res.start + ALIGN(gas->access_width, 4) - 1;
117		} else if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
118			res.flags = IORESOURCE_IO;
119			res.end = res.start + gas->access_width - 1;
120		} else {
121			pr_warn("Unsupported address space: %u\n",
122				gas->space_id);
123			goto fail_free_resource_list;
124		}
125
126		found = false;
127		resource_list_for_each_entry(rentry, &resource_list) {
128			if (rentry->res->flags == res.flags &&
129			    resource_overlaps(rentry->res, &res)) {
130				if (res.start < rentry->res->start)
131					rentry->res->start = res.start;
132				if (res.end > rentry->res->end)
133					rentry->res->end = res.end;
134				found = true;
135				break;
136			}
137		}
138
139		if (!found) {
140			rentry = resource_list_create_entry(NULL, 0);
141			if (!rentry)
142				goto fail_free_resource_list;
143
144			*rentry->res = res;
145			resource_list_add_tail(rentry, &resource_list);
146			nresources++;
147		}
148	}
149
150	resources = kcalloc(nresources, sizeof(*resources), GFP_KERNEL);
151	if (!resources)
152		goto fail_free_resource_list;
153
154	i = 0;
155	resource_list_for_each_entry(rentry, &resource_list)
156		resources[i++] = *rentry->res;
157
158	pdev = platform_device_register_simple("wdat_wdt", PLATFORM_DEVID_NONE,
159					       resources, nresources);
160	if (IS_ERR(pdev))
161		pr_err("Device creation failed: %ld\n", PTR_ERR(pdev));
162
163	kfree(resources);
164
165fail_free_resource_list:
166	resource_list_free(&resource_list);
167}