xref: /openbmc/linux/drivers/acpi/arm64/gtdt.c (revision 596143e3)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
25f1ae4ebSFu Wei /*
35f1ae4ebSFu Wei  * ARM Specific GTDT table Support
45f1ae4ebSFu Wei  *
55f1ae4ebSFu Wei  * Copyright (C) 2016, Linaro Ltd.
65f1ae4ebSFu Wei  * Author: Daniel Lezcano <daniel.lezcano@linaro.org>
75f1ae4ebSFu Wei  *         Fu Wei <fu.wei@linaro.org>
85f1ae4ebSFu Wei  *         Hanjun Guo <hanjun.guo@linaro.org>
95f1ae4ebSFu Wei  */
105f1ae4ebSFu Wei 
115f1ae4ebSFu Wei #include <linux/acpi.h>
125f1ae4ebSFu Wei #include <linux/init.h>
13a712c3edSFu Wei #include <linux/irqdomain.h>
145f1ae4ebSFu Wei #include <linux/kernel.h>
15ca9ae5ecSFu Wei #include <linux/platform_device.h>
165f1ae4ebSFu Wei 
175f1ae4ebSFu Wei #include <clocksource/arm_arch_timer.h>
185f1ae4ebSFu Wei 
195f1ae4ebSFu Wei #undef pr_fmt
205f1ae4ebSFu Wei #define pr_fmt(fmt) "ACPI GTDT: " fmt
215f1ae4ebSFu Wei 
225f1ae4ebSFu Wei /**
235f1ae4ebSFu Wei  * struct acpi_gtdt_descriptor - Store the key info of GTDT for all functions
245f1ae4ebSFu Wei  * @gtdt:	The pointer to the struct acpi_table_gtdt of GTDT table.
255f1ae4ebSFu Wei  * @gtdt_end:	The pointer to the end of GTDT table.
265f1ae4ebSFu Wei  * @platform_timer:	The pointer to the start of Platform Timer Structure
275f1ae4ebSFu Wei  *
285f1ae4ebSFu Wei  * The struct store the key info of GTDT table, it should be initialized by
295f1ae4ebSFu Wei  * acpi_gtdt_init.
305f1ae4ebSFu Wei  */
315f1ae4ebSFu Wei struct acpi_gtdt_descriptor {
325f1ae4ebSFu Wei 	struct acpi_table_gtdt *gtdt;
335f1ae4ebSFu Wei 	void *gtdt_end;
345f1ae4ebSFu Wei 	void *platform_timer;
355f1ae4ebSFu Wei };
365f1ae4ebSFu Wei 
375f1ae4ebSFu Wei static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
385f1ae4ebSFu Wei 
next_platform_timer(void * platform_timer)39*596143e3SJackie Liu static inline __init void *next_platform_timer(void *platform_timer)
40a712c3edSFu Wei {
41a712c3edSFu Wei 	struct acpi_gtdt_header *gh = platform_timer;
42a712c3edSFu Wei 
43a712c3edSFu Wei 	platform_timer += gh->length;
44a712c3edSFu Wei 	if (platform_timer < acpi_gtdt_desc.gtdt_end)
45a712c3edSFu Wei 		return platform_timer;
46a712c3edSFu Wei 
47a712c3edSFu Wei 	return NULL;
48a712c3edSFu Wei }
49a712c3edSFu Wei 
50a712c3edSFu Wei #define for_each_platform_timer(_g)				\
51a712c3edSFu Wei 	for (_g = acpi_gtdt_desc.platform_timer; _g;	\
52a712c3edSFu Wei 	     _g = next_platform_timer(_g))
53a712c3edSFu Wei 
is_timer_block(void * platform_timer)54a712c3edSFu Wei static inline bool is_timer_block(void *platform_timer)
55a712c3edSFu Wei {
56a712c3edSFu Wei 	struct acpi_gtdt_header *gh = platform_timer;
57a712c3edSFu Wei 
58a712c3edSFu Wei 	return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
59a712c3edSFu Wei }
60a712c3edSFu Wei 
is_non_secure_watchdog(void * platform_timer)61ca9ae5ecSFu Wei static inline bool is_non_secure_watchdog(void *platform_timer)
62ca9ae5ecSFu Wei {
63ca9ae5ecSFu Wei 	struct acpi_gtdt_header *gh = platform_timer;
64ca9ae5ecSFu Wei 	struct acpi_gtdt_watchdog *wd = platform_timer;
65ca9ae5ecSFu Wei 
66ca9ae5ecSFu Wei 	if (gh->type != ACPI_GTDT_TYPE_WATCHDOG)
67ca9ae5ecSFu Wei 		return false;
68ca9ae5ecSFu Wei 
69ca9ae5ecSFu Wei 	return !(wd->timer_flags & ACPI_GTDT_WATCHDOG_SECURE);
70ca9ae5ecSFu Wei }
71ca9ae5ecSFu Wei 
map_gt_gsi(u32 interrupt,u32 flags)725f1ae4ebSFu Wei static int __init map_gt_gsi(u32 interrupt, u32 flags)
735f1ae4ebSFu Wei {
745f1ae4ebSFu Wei 	int trigger, polarity;
755f1ae4ebSFu Wei 
765f1ae4ebSFu Wei 	trigger = (flags & ACPI_GTDT_INTERRUPT_MODE) ? ACPI_EDGE_SENSITIVE
775f1ae4ebSFu Wei 			: ACPI_LEVEL_SENSITIVE;
785f1ae4ebSFu Wei 
795f1ae4ebSFu Wei 	polarity = (flags & ACPI_GTDT_INTERRUPT_POLARITY) ? ACPI_ACTIVE_LOW
805f1ae4ebSFu Wei 			: ACPI_ACTIVE_HIGH;
815f1ae4ebSFu Wei 
825f1ae4ebSFu Wei 	return acpi_register_gsi(NULL, interrupt, trigger, polarity);
835f1ae4ebSFu Wei }
845f1ae4ebSFu Wei 
855f1ae4ebSFu Wei /**
865f1ae4ebSFu Wei  * acpi_gtdt_map_ppi() - Map the PPIs of per-cpu arch_timer.
875f1ae4ebSFu Wei  * @type:	the type of PPI.
885f1ae4ebSFu Wei  *
895f1ae4ebSFu Wei  * Note: Secure state is not managed by the kernel on ARM64 systems.
905f1ae4ebSFu Wei  * So we only handle the non-secure timer PPIs,
915f1ae4ebSFu Wei  * ARCH_TIMER_PHYS_SECURE_PPI is treated as invalid type.
925f1ae4ebSFu Wei  *
935f1ae4ebSFu Wei  * Return: the mapped PPI value, 0 if error.
945f1ae4ebSFu Wei  */
acpi_gtdt_map_ppi(int type)955f1ae4ebSFu Wei int __init acpi_gtdt_map_ppi(int type)
965f1ae4ebSFu Wei {
975f1ae4ebSFu Wei 	struct acpi_table_gtdt *gtdt = acpi_gtdt_desc.gtdt;
985f1ae4ebSFu Wei 
995f1ae4ebSFu Wei 	switch (type) {
1005f1ae4ebSFu Wei 	case ARCH_TIMER_PHYS_NONSECURE_PPI:
1015f1ae4ebSFu Wei 		return map_gt_gsi(gtdt->non_secure_el1_interrupt,
1025f1ae4ebSFu Wei 				  gtdt->non_secure_el1_flags);
1035f1ae4ebSFu Wei 	case ARCH_TIMER_VIRT_PPI:
1045f1ae4ebSFu Wei 		return map_gt_gsi(gtdt->virtual_timer_interrupt,
1055f1ae4ebSFu Wei 				  gtdt->virtual_timer_flags);
1065f1ae4ebSFu Wei 
1075f1ae4ebSFu Wei 	case ARCH_TIMER_HYP_PPI:
1085f1ae4ebSFu Wei 		return map_gt_gsi(gtdt->non_secure_el2_interrupt,
1095f1ae4ebSFu Wei 				  gtdt->non_secure_el2_flags);
1105f1ae4ebSFu Wei 	default:
1115f1ae4ebSFu Wei 		pr_err("Failed to map timer interrupt: invalid type.\n");
1125f1ae4ebSFu Wei 	}
1135f1ae4ebSFu Wei 
1145f1ae4ebSFu Wei 	return 0;
1155f1ae4ebSFu Wei }
1165f1ae4ebSFu Wei 
1175f1ae4ebSFu Wei /**
1185f1ae4ebSFu Wei  * acpi_gtdt_c3stop() - Got c3stop info from GTDT according to the type of PPI.
1195f1ae4ebSFu Wei  * @type:	the type of PPI.
1205f1ae4ebSFu Wei  *
1215f1ae4ebSFu Wei  * Return: true if the timer HW state is lost when a CPU enters an idle state,
1225f1ae4ebSFu Wei  * false otherwise
1235f1ae4ebSFu Wei  */
acpi_gtdt_c3stop(int type)1245f1ae4ebSFu Wei bool __init acpi_gtdt_c3stop(int type)
1255f1ae4ebSFu Wei {
1265f1ae4ebSFu Wei 	struct acpi_table_gtdt *gtdt = acpi_gtdt_desc.gtdt;
1275f1ae4ebSFu Wei 
1285f1ae4ebSFu Wei 	switch (type) {
1295f1ae4ebSFu Wei 	case ARCH_TIMER_PHYS_NONSECURE_PPI:
1305f1ae4ebSFu Wei 		return !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
1315f1ae4ebSFu Wei 
1325f1ae4ebSFu Wei 	case ARCH_TIMER_VIRT_PPI:
1335f1ae4ebSFu Wei 		return !(gtdt->virtual_timer_flags & ACPI_GTDT_ALWAYS_ON);
1345f1ae4ebSFu Wei 
1355f1ae4ebSFu Wei 	case ARCH_TIMER_HYP_PPI:
1365f1ae4ebSFu Wei 		return !(gtdt->non_secure_el2_flags & ACPI_GTDT_ALWAYS_ON);
1375f1ae4ebSFu Wei 
1385f1ae4ebSFu Wei 	default:
1395f1ae4ebSFu Wei 		pr_err("Failed to get c3stop info: invalid type.\n");
1405f1ae4ebSFu Wei 	}
1415f1ae4ebSFu Wei 
1425f1ae4ebSFu Wei 	return false;
1435f1ae4ebSFu Wei }
1445f1ae4ebSFu Wei 
1455f1ae4ebSFu Wei /**
1465f1ae4ebSFu Wei  * acpi_gtdt_init() - Get the info of GTDT table to prepare for further init.
1475f1ae4ebSFu Wei  * @table:			The pointer to GTDT table.
1485f1ae4ebSFu Wei  * @platform_timer_count:	It points to a integer variable which is used
1495f1ae4ebSFu Wei  *				for storing the number of platform timers.
1505f1ae4ebSFu Wei  *				This pointer could be NULL, if the caller
1515f1ae4ebSFu Wei  *				doesn't need this info.
1525f1ae4ebSFu Wei  *
1535f1ae4ebSFu Wei  * Return: 0 if success, -EINVAL if error.
1545f1ae4ebSFu Wei  */
acpi_gtdt_init(struct acpi_table_header * table,int * platform_timer_count)1555f1ae4ebSFu Wei int __init acpi_gtdt_init(struct acpi_table_header *table,
1565f1ae4ebSFu Wei 			  int *platform_timer_count)
1575f1ae4ebSFu Wei {
1585f1ae4ebSFu Wei 	void *platform_timer;
1595f1ae4ebSFu Wei 	struct acpi_table_gtdt *gtdt;
1605f1ae4ebSFu Wei 
1615f1ae4ebSFu Wei 	gtdt = container_of(table, struct acpi_table_gtdt, header);
1625f1ae4ebSFu Wei 	acpi_gtdt_desc.gtdt = gtdt;
1635f1ae4ebSFu Wei 	acpi_gtdt_desc.gtdt_end = (void *)table + table->length;
1645f1ae4ebSFu Wei 	acpi_gtdt_desc.platform_timer = NULL;
1655f1ae4ebSFu Wei 	if (platform_timer_count)
1665f1ae4ebSFu Wei 		*platform_timer_count = 0;
1675f1ae4ebSFu Wei 
1685f1ae4ebSFu Wei 	if (table->revision < 2) {
1695f1ae4ebSFu Wei 		pr_warn("Revision:%d doesn't support Platform Timers.\n",
1705f1ae4ebSFu Wei 			table->revision);
1715f1ae4ebSFu Wei 		return 0;
1725f1ae4ebSFu Wei 	}
1735f1ae4ebSFu Wei 
1745f1ae4ebSFu Wei 	if (!gtdt->platform_timer_count) {
1755f1ae4ebSFu Wei 		pr_debug("No Platform Timer.\n");
1765f1ae4ebSFu Wei 		return 0;
1775f1ae4ebSFu Wei 	}
1785f1ae4ebSFu Wei 
1795f1ae4ebSFu Wei 	platform_timer = (void *)gtdt + gtdt->platform_timer_offset;
1805f1ae4ebSFu Wei 	if (platform_timer < (void *)table + sizeof(struct acpi_table_gtdt)) {
1815f1ae4ebSFu Wei 		pr_err(FW_BUG "invalid timer data.\n");
1825f1ae4ebSFu Wei 		return -EINVAL;
1835f1ae4ebSFu Wei 	}
1845f1ae4ebSFu Wei 	acpi_gtdt_desc.platform_timer = platform_timer;
1855f1ae4ebSFu Wei 	if (platform_timer_count)
1865f1ae4ebSFu Wei 		*platform_timer_count = gtdt->platform_timer_count;
1875f1ae4ebSFu Wei 
1885f1ae4ebSFu Wei 	return 0;
1895f1ae4ebSFu Wei }
190a712c3edSFu Wei 
gtdt_parse_timer_block(struct acpi_gtdt_timer_block * block,struct arch_timer_mem * timer_mem)191a712c3edSFu Wei static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *block,
192a712c3edSFu Wei 					 struct arch_timer_mem *timer_mem)
193a712c3edSFu Wei {
194a712c3edSFu Wei 	int i;
195a712c3edSFu Wei 	struct arch_timer_mem_frame *frame;
196a712c3edSFu Wei 	struct acpi_gtdt_timer_entry *gtdt_frame;
197a712c3edSFu Wei 
198a712c3edSFu Wei 	if (!block->timer_count) {
199ee10b9c9SArvind Yadav 		pr_err(FW_BUG "GT block present, but frame count is zero.\n");
200a712c3edSFu Wei 		return -ENODEV;
201a712c3edSFu Wei 	}
202a712c3edSFu Wei 
203a712c3edSFu Wei 	if (block->timer_count > ARCH_TIMER_MEM_MAX_FRAMES) {
204a712c3edSFu Wei 		pr_err(FW_BUG "GT block lists %d frames, ACPI spec only allows 8\n",
205a712c3edSFu Wei 		       block->timer_count);
206a712c3edSFu Wei 		return -EINVAL;
207a712c3edSFu Wei 	}
208a712c3edSFu Wei 
209a712c3edSFu Wei 	timer_mem->cntctlbase = (phys_addr_t)block->block_address;
210a712c3edSFu Wei 	/*
211a712c3edSFu Wei 	 * The CNTCTLBase frame is 4KB (register offsets 0x000 - 0xFFC).
212a712c3edSFu Wei 	 * See ARM DDI 0487A.k_iss10775, page I1-5129, Table I1-3
213a712c3edSFu Wei 	 * "CNTCTLBase memory map".
214a712c3edSFu Wei 	 */
215a712c3edSFu Wei 	timer_mem->size = SZ_4K;
216a712c3edSFu Wei 
217a712c3edSFu Wei 	gtdt_frame = (void *)block + block->timer_offset;
218a712c3edSFu Wei 	if (gtdt_frame + block->timer_count != (void *)block + block->header.length)
219a712c3edSFu Wei 		return -EINVAL;
220a712c3edSFu Wei 
221a712c3edSFu Wei 	/*
222a712c3edSFu Wei 	 * Get the GT timer Frame data for every GT Block Timer
223a712c3edSFu Wei 	 */
224a712c3edSFu Wei 	for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
225a712c3edSFu Wei 		if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
226a712c3edSFu Wei 			continue;
227a712c3edSFu Wei 		if (gtdt_frame->frame_number >= ARCH_TIMER_MEM_MAX_FRAMES ||
228a712c3edSFu Wei 		    !gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
229a712c3edSFu Wei 			goto error;
230a712c3edSFu Wei 
231a712c3edSFu Wei 		frame = &timer_mem->frame[gtdt_frame->frame_number];
232a712c3edSFu Wei 
233a712c3edSFu Wei 		/* duplicate frame */
234a712c3edSFu Wei 		if (frame->valid)
235a712c3edSFu Wei 			goto error;
236a712c3edSFu Wei 
237a712c3edSFu Wei 		frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
238a712c3edSFu Wei 					     gtdt_frame->timer_flags);
239a712c3edSFu Wei 		if (frame->phys_irq <= 0) {
240a712c3edSFu Wei 			pr_warn("failed to map physical timer irq in frame %d.\n",
241a712c3edSFu Wei 				gtdt_frame->frame_number);
242a712c3edSFu Wei 			goto error;
243a712c3edSFu Wei 		}
244a712c3edSFu Wei 
245a712c3edSFu Wei 		if (gtdt_frame->virtual_timer_interrupt) {
246a712c3edSFu Wei 			frame->virt_irq =
247a712c3edSFu Wei 				map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
248a712c3edSFu Wei 					   gtdt_frame->virtual_timer_flags);
249a712c3edSFu Wei 			if (frame->virt_irq <= 0) {
250a712c3edSFu Wei 				pr_warn("failed to map virtual timer irq in frame %d.\n",
251a712c3edSFu Wei 					gtdt_frame->frame_number);
252a712c3edSFu Wei 				goto error;
253a712c3edSFu Wei 			}
254a712c3edSFu Wei 		} else {
255a712c3edSFu Wei 			pr_debug("virtual timer in frame %d not implemented.\n",
256a712c3edSFu Wei 				 gtdt_frame->frame_number);
257a712c3edSFu Wei 		}
258a712c3edSFu Wei 
259a712c3edSFu Wei 		frame->cntbase = gtdt_frame->base_address;
260a712c3edSFu Wei 		/*
261a712c3edSFu Wei 		 * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
262a712c3edSFu Wei 		 * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
263a712c3edSFu Wei 		 * "CNTBaseN memory map".
264a712c3edSFu Wei 		 */
265a712c3edSFu Wei 		frame->size = SZ_4K;
266a712c3edSFu Wei 		frame->valid = true;
267a712c3edSFu Wei 	}
268a712c3edSFu Wei 
269a712c3edSFu Wei 	return 0;
270a712c3edSFu Wei 
271a712c3edSFu Wei error:
272a712c3edSFu Wei 	do {
273a712c3edSFu Wei 		if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER ||
274a712c3edSFu Wei 		    gtdt_frame->frame_number >= ARCH_TIMER_MEM_MAX_FRAMES)
275a712c3edSFu Wei 			continue;
276a712c3edSFu Wei 
277a712c3edSFu Wei 		frame = &timer_mem->frame[gtdt_frame->frame_number];
278a712c3edSFu Wei 
279a712c3edSFu Wei 		if (frame->phys_irq > 0)
280a712c3edSFu Wei 			acpi_unregister_gsi(gtdt_frame->timer_interrupt);
281a712c3edSFu Wei 		frame->phys_irq = 0;
282a712c3edSFu Wei 
283a712c3edSFu Wei 		if (frame->virt_irq > 0)
284a712c3edSFu Wei 			acpi_unregister_gsi(gtdt_frame->virtual_timer_interrupt);
285a712c3edSFu Wei 		frame->virt_irq = 0;
286a712c3edSFu Wei 	} while (i-- >= 0 && gtdt_frame--);
287a712c3edSFu Wei 
288a712c3edSFu Wei 	return -EINVAL;
289a712c3edSFu Wei }
290a712c3edSFu Wei 
291a712c3edSFu Wei /**
292a712c3edSFu Wei  * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
293a712c3edSFu Wei  * @timer_mem:	The pointer to the array of struct arch_timer_mem for returning
294a712c3edSFu Wei  *		the result of parsing. The element number of this array should
295a712c3edSFu Wei  *		be platform_timer_count(the total number of platform timers).
296a712c3edSFu Wei  * @timer_count: It points to a integer variable which is used for storing the
297a712c3edSFu Wei  *		number of GT blocks we have parsed.
298a712c3edSFu Wei  *
299a712c3edSFu Wei  * Return: 0 if success, -EINVAL/-ENODEV if error.
300a712c3edSFu Wei  */
acpi_arch_timer_mem_init(struct arch_timer_mem * timer_mem,int * timer_count)301a712c3edSFu Wei int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
302a712c3edSFu Wei 				    int *timer_count)
303a712c3edSFu Wei {
304a712c3edSFu Wei 	int ret;
305a712c3edSFu Wei 	void *platform_timer;
306a712c3edSFu Wei 
307a712c3edSFu Wei 	*timer_count = 0;
308a712c3edSFu Wei 	for_each_platform_timer(platform_timer) {
309a712c3edSFu Wei 		if (is_timer_block(platform_timer)) {
310a712c3edSFu Wei 			ret = gtdt_parse_timer_block(platform_timer, timer_mem);
311a712c3edSFu Wei 			if (ret)
312a712c3edSFu Wei 				return ret;
313a712c3edSFu Wei 			timer_mem++;
314a712c3edSFu Wei 			(*timer_count)++;
315a712c3edSFu Wei 		}
316a712c3edSFu Wei 	}
317a712c3edSFu Wei 
318a712c3edSFu Wei 	if (*timer_count)
319a712c3edSFu Wei 		pr_info("found %d memory-mapped timer block(s).\n",
320a712c3edSFu Wei 			*timer_count);
321a712c3edSFu Wei 
322a712c3edSFu Wei 	return 0;
323a712c3edSFu Wei }
324ca9ae5ecSFu Wei 
325ca9ae5ecSFu Wei /*
326ca9ae5ecSFu Wei  * Initialize a SBSA generic Watchdog platform device info from GTDT
327ca9ae5ecSFu Wei  */
gtdt_import_sbsa_gwdt(struct acpi_gtdt_watchdog * wd,int index)328ca9ae5ecSFu Wei static int __init gtdt_import_sbsa_gwdt(struct acpi_gtdt_watchdog *wd,
329ca9ae5ecSFu Wei 					int index)
330ca9ae5ecSFu Wei {
331ca9ae5ecSFu Wei 	struct platform_device *pdev;
3321ecd5b12SMarc Zyngier 	int irq;
333ca9ae5ecSFu Wei 
334ca9ae5ecSFu Wei 	/*
335ca9ae5ecSFu Wei 	 * According to SBSA specification the size of refresh and control
336ca9ae5ecSFu Wei 	 * frames of SBSA Generic Watchdog is SZ_4K(Offset 0x000 – 0xFFF).
337ca9ae5ecSFu Wei 	 */
338ca9ae5ecSFu Wei 	struct resource res[] = {
339ca9ae5ecSFu Wei 		DEFINE_RES_MEM(wd->control_frame_address, SZ_4K),
340ca9ae5ecSFu Wei 		DEFINE_RES_MEM(wd->refresh_frame_address, SZ_4K),
3411ecd5b12SMarc Zyngier 		{},
342ca9ae5ecSFu Wei 	};
343ca9ae5ecSFu Wei 	int nr_res = ARRAY_SIZE(res);
344ca9ae5ecSFu Wei 
345ca9ae5ecSFu Wei 	pr_debug("found a Watchdog (0x%llx/0x%llx gsi:%u flags:0x%x).\n",
346ca9ae5ecSFu Wei 		 wd->refresh_frame_address, wd->control_frame_address,
347ca9ae5ecSFu Wei 		 wd->timer_interrupt, wd->timer_flags);
348ca9ae5ecSFu Wei 
349ca9ae5ecSFu Wei 	if (!(wd->refresh_frame_address && wd->control_frame_address)) {
350ca9ae5ecSFu Wei 		pr_err(FW_BUG "failed to get the Watchdog base address.\n");
351ca9ae5ecSFu Wei 		return -EINVAL;
352ca9ae5ecSFu Wei 	}
353ca9ae5ecSFu Wei 
3541ecd5b12SMarc Zyngier 	irq = map_gt_gsi(wd->timer_interrupt, wd->timer_flags);
3551ecd5b12SMarc Zyngier 	res[2] = (struct resource)DEFINE_RES_IRQ(irq);
356ca9ae5ecSFu Wei 	if (irq <= 0) {
357ca9ae5ecSFu Wei 		pr_warn("failed to map the Watchdog interrupt.\n");
358ca9ae5ecSFu Wei 		nr_res--;
359ca9ae5ecSFu Wei 	}
360ca9ae5ecSFu Wei 
361ca9ae5ecSFu Wei 	/*
362ca9ae5ecSFu Wei 	 * Add a platform device named "sbsa-gwdt" to match the platform driver.
363ca9ae5ecSFu Wei 	 * "sbsa-gwdt": SBSA(Server Base System Architecture) Generic Watchdog
364ca9ae5ecSFu Wei 	 * The platform driver can get device info below by matching this name.
365ca9ae5ecSFu Wei 	 */
366ca9ae5ecSFu Wei 	pdev = platform_device_register_simple("sbsa-gwdt", index, res, nr_res);
367ca9ae5ecSFu Wei 	if (IS_ERR(pdev)) {
3681ecd5b12SMarc Zyngier 		if (irq > 0)
369ca9ae5ecSFu Wei 			acpi_unregister_gsi(wd->timer_interrupt);
370ca9ae5ecSFu Wei 		return PTR_ERR(pdev);
371ca9ae5ecSFu Wei 	}
372ca9ae5ecSFu Wei 
373ca9ae5ecSFu Wei 	return 0;
374ca9ae5ecSFu Wei }
375ca9ae5ecSFu Wei 
gtdt_sbsa_gwdt_init(void)376ca9ae5ecSFu Wei static int __init gtdt_sbsa_gwdt_init(void)
377ca9ae5ecSFu Wei {
378ca9ae5ecSFu Wei 	void *platform_timer;
379ca9ae5ecSFu Wei 	struct acpi_table_header *table;
380ca9ae5ecSFu Wei 	int ret, timer_count, gwdt_count = 0;
381ca9ae5ecSFu Wei 
382ca9ae5ecSFu Wei 	if (acpi_disabled)
383ca9ae5ecSFu Wei 		return 0;
384ca9ae5ecSFu Wei 
385ca9ae5ecSFu Wei 	if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_GTDT, 0, &table)))
386ca9ae5ecSFu Wei 		return -EINVAL;
387ca9ae5ecSFu Wei 
388ca9ae5ecSFu Wei 	/*
389ca9ae5ecSFu Wei 	 * Note: Even though the global variable acpi_gtdt_desc has been
390ca9ae5ecSFu Wei 	 * initialized by acpi_gtdt_init() while initializing the arch timers,
391ca9ae5ecSFu Wei 	 * when we call this function to get SBSA watchdogs info from GTDT, the
392ca9ae5ecSFu Wei 	 * pointers stashed in it are stale (since they are early temporary
393ca9ae5ecSFu Wei 	 * mappings carried out before acpi_permanent_mmap is set) and we need
394ca9ae5ecSFu Wei 	 * to re-initialize them with permanent mapped pointer values to let the
395ca9ae5ecSFu Wei 	 * GTDT parsing possible.
396ca9ae5ecSFu Wei 	 */
397ca9ae5ecSFu Wei 	ret = acpi_gtdt_init(table, &timer_count);
398ca9ae5ecSFu Wei 	if (ret || !timer_count)
3995ec60510SHanjun Guo 		goto out_put_gtdt;
400ca9ae5ecSFu Wei 
401ca9ae5ecSFu Wei 	for_each_platform_timer(platform_timer) {
402ca9ae5ecSFu Wei 		if (is_non_secure_watchdog(platform_timer)) {
403ca9ae5ecSFu Wei 			ret = gtdt_import_sbsa_gwdt(platform_timer, gwdt_count);
404ca9ae5ecSFu Wei 			if (ret)
405ca9ae5ecSFu Wei 				break;
406ca9ae5ecSFu Wei 			gwdt_count++;
407ca9ae5ecSFu Wei 		}
408ca9ae5ecSFu Wei 	}
409ca9ae5ecSFu Wei 
410ca9ae5ecSFu Wei 	if (gwdt_count)
411ca9ae5ecSFu Wei 		pr_info("found %d SBSA generic Watchdog(s).\n", gwdt_count);
412ca9ae5ecSFu Wei 
4135ec60510SHanjun Guo out_put_gtdt:
4145ec60510SHanjun Guo 	acpi_put_table(table);
415ca9ae5ecSFu Wei 	return ret;
416ca9ae5ecSFu Wei }
417ca9ae5ecSFu Wei 
418ca9ae5ecSFu Wei device_initcall(gtdt_sbsa_gwdt_init);
419